Skip to content

Commit d4f49fd

Browse files
committed
Fixed division by zero error in obj_examine_func_
(ref. fallout2-ce/fallout2-ce#541)
1 parent 249adde commit d4f49fd

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

sfall/Modules/BugFixes.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,22 @@ static __declspec(naked) void obj_examine_func_hack_objdesc() {
18731873
}
18741874
}
18751875

1876+
static __declspec(naked) void obj_examine_func_hack_checkhp() {
1877+
static const DWORD ObjExamineFuncCheckHP_Ret = 0x49AF26;
1878+
__asm { // eax - maximum hp, ecx - current hp
1879+
test eax, eax;
1880+
jle dead;
1881+
// overwritten engine code
1882+
mov edx, eax;
1883+
test ecx, ecx;
1884+
jle dead;
1885+
retn;
1886+
dead:
1887+
add esp, 4;
1888+
jmp ObjExamineFuncCheckHP_Ret;
1889+
}
1890+
}
1891+
18761892
static DWORD expSwiftLearner; // experience points for print
18771893

18781894
static __declspec(naked) void statPCAddExperienceCheckPMs_hack() {
@@ -4074,6 +4090,9 @@ void BugFixes::init() {
40744090
// Supplementary fix for hacks in Game\GUI\Text.cpp
40754091
MakeCall(0x49AE33, obj_examine_func_hack_objdesc, 1);
40764092

4093+
// Fix division by zero error in obj_examine_func_ engine function (when a critter's max HP <= 0 for any reason)
4094+
MakeCall(0x49AF15, obj_examine_func_hack_checkhp, 1);
4095+
40774096
// Display experience points with the bonus from Swift Learner perk when gained from non-scripted situations
40784097
//if (IniReader::GetConfigInt("Misc", "DisplaySwiftLearnerExp", 1)) {
40794098
dlogr("Applying Swift Learner exp display patch.", DL_FIX);

0 commit comments

Comments
 (0)