From dcbe6c9c7e9f3a850f49414ae03e6013883f1f9e Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 15 Dec 2023 09:17:19 +0800 Subject: [PATCH] Fixed 0 dmg instadeath crits with HOOK_COMBATDAMAGE --- sfall/Modules/BugFixes.cpp | 6 +++--- sfall/Modules/HookScripts/CombatHs.cpp | 4 ++++ sfall/Modules/LoadGameHook.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index a551f7d5..fcf91ab6 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -1686,7 +1686,7 @@ end: } } -//zero damage insta death criticals fix (moved from compute_damage hook) +// fix for zero damage instadeath criticals (moved from compute_damage hook) static void __fastcall InstantDeathFix(fo::ComputeAttackResult &ctd) { if (ctd.targetDamage == 0 && (ctd.targetFlags & fo::DamageFlag::DAM_DEAD)) { ctd.targetDamage++; // set 1 hp damage @@ -3649,7 +3649,7 @@ void BugFixes::init() { 0x428AB3 // ai_move_away_ (potential fix) }); - // Fix instant death critical + // Fix instant death critical hits dlogr("Applying instant death fix.", DL_FIX); MakeJump(0x424BA2, compute_damage_hack); @@ -3929,7 +3929,7 @@ void BugFixes::init() { // Fix the placement of multihex critters in the player's party when entering a map or elevation MakeCall(0x494E33, partyMemberSyncPosition_hack, 1); - // Fix for critter_add/rm_trait functions ignoring the value of the "amount" argument + // Fix for critter_add/rm_trait functions ignoring the "amount" argument // Note: pass negative amount values to critter_rm_trait to remove all ranks of the perk (vanilla behavior) HookCall(0x458CDB, op_critter_rm_trait_hook); HookCall(0x458B3D, op_critter_add_trait_hook); diff --git a/sfall/Modules/HookScripts/CombatHs.cpp b/sfall/Modules/HookScripts/CombatHs.cpp index 66ba4d2f..4ceef06f 100644 --- a/sfall/Modules/HookScripts/CombatHs.cpp +++ b/sfall/Modules/HookScripts/CombatHs.cpp @@ -195,6 +195,10 @@ static void __fastcall ComputeDamageHook_Script(fo::ComputeAttackResult &ctd, DW } } } + // prevent hook from setting zero damage for instadeath criticals (bug fix) + if (ctd.targetDamage == 0 && (ctd.targetFlags & fo::DamageFlag::DAM_DEAD)) { + ctd.targetDamage++; // set 1 hp damage + } } EndHook(); } diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index 33fa9575..79453540 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -807,7 +807,7 @@ void LoadGameHook::init() { 0x481028, // main_selfrun_record_ 0x481062, // main_selfrun_record_ 0x48110B, // main_selfrun_play_ - 0x481145 // main_selfrun_play_ + 0x481145 // main_selfrun_play_ }); HookCalls(game_reset_on_load_hook, { 0x47F491, // PrepLoad_ (the very first step during save game loading)