From 165207239195dc24310d4c3cb375f8b4bacc7a5d Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 2 Jun 2018 18:15:53 +0800 Subject: [PATCH] Fixed a bug that critters killed in combat by scripting still being able to move in their combat turn if the distance parameter in their AI packages is set to stay_close/charge, or NPCsTryToSpendExtraAP is enabled (from Mr.Stalin) --- sfall/Modules/BugFixes.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index c51df11f..65e1584c 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -1109,6 +1109,18 @@ map_leave: } } +static void __declspec(naked) ai_move_steps_closer_hook() { + __asm { + call fo::funcoffs::combat_turn_run_; + movzx dx, word ptr [esi + 0x44]; // combat_data.results + test dx, DAM_DEAD or DAM_KNOCKED_OUT or DAM_LOSE_TURN; + jz end; + mov [esi + 0x40], 0; // pobj.curr_mp (source reset ap) +end: + retn; + } +} + void BugFixes::init() { @@ -1420,6 +1432,10 @@ void BugFixes::init() // Fix for being at incorrect hex after map change when the exit hex in source map is at the same position as // some exit hex in destination map MakeCall(0x48A704, obj_move_to_tile_hack); + + // Fix for critters killed in combat by scripting still being able to move in their combat turn if the distance parameter + // in their AI packages is set to stay_close/charge, or NPCsTryToSpendExtraAP is enabled + HookCall(0x42A1A8, ai_move_steps_closer_hook); // 0x42B24D } }