From d4f49fd75cd1835266a0dc444da4ca03f76b9565 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 12 Jul 2026 21:55:04 +0800 Subject: [PATCH] Fixed division by zero error in obj_examine_func_ (ref. fallout2-ce/fallout2-ce#541) --- sfall/Modules/BugFixes.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index f33871bb..e17a4527 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -1873,6 +1873,22 @@ skip: } } +static __declspec(naked) void obj_examine_func_hack_checkhp() { + static const DWORD ObjExamineFuncCheckHP_Ret = 0x49AF26; + __asm { // eax - maximum hp, ecx - current hp + test eax, eax; + jle dead; + // overwritten engine code + mov edx, eax; + test ecx, ecx; + jle dead; + retn; +dead: + add esp, 4; + jmp ObjExamineFuncCheckHP_Ret; + } +} + static DWORD expSwiftLearner; // experience points for print static __declspec(naked) void statPCAddExperienceCheckPMs_hack() { @@ -4074,6 +4090,9 @@ void BugFixes::init() { // Supplementary fix for hacks in Game\GUI\Text.cpp MakeCall(0x49AE33, obj_examine_func_hack_objdesc, 1); + // Fix division by zero error in obj_examine_func_ engine function (when a critter's max HP <= 0 for any reason) + MakeCall(0x49AF15, obj_examine_func_hack_checkhp, 1); + // Display experience points with the bonus from Swift Learner perk when gained from non-scripted situations //if (IniReader::GetConfigInt("Misc", "DisplaySwiftLearnerExp", 1)) { dlogr("Applying Swift Learner exp display patch.", DL_FIX);