From f5317ad5ee735f94487b5b110040f2eadcbf1935 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 22 May 2019 10:41:37 +0800 Subject: [PATCH] Rewrote NPC fleeing fix. Removed DialogOptions9Lines option from ddraw.ini. --- artifacts/ddraw.ini | 3 --- sfall/Modules/AI.cpp | 31 +++++++++++++++++++++---------- sfall/Modules/BugFixes.cpp | 19 ++++++++----------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 64a4b048..b98ca32c 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -617,9 +617,6 @@ ReloadReserve=-1 ;Set to 1 to change the counter in the 'Move Items' window to start at the maximum number of items ItemCounterDefaultMax=0 -;Allows 9 options (lines of text) to be displayed correctly in a dialog window -DialogOptions9Lines=1 - ;Set to 1 to leave the music playing in dialogue with talking heads EnableMusicInDialogue=0 diff --git a/sfall/Modules/AI.cpp b/sfall/Modules/AI.cpp index bf4f27bf..988f4f78 100644 --- a/sfall/Modules/AI.cpp +++ b/sfall/Modules/AI.cpp @@ -36,25 +36,36 @@ static std::unordered_map sources; static void __declspec(naked) ai_try_attack_hook_FleeFix() { __asm { - call fo::funcoffs::ai_run_away_; - mov dword ptr [esi + whoHitMe], 0; - and byte ptr [esi + combatState], ~4; // unset flee flag - retn; + or byte ptr [esi + combatState], 8; // set new 'ReTarget' flag + jmp fo::funcoffs::ai_run_away_; } } static const DWORD combat_ai_hook_flee_Ret = 0x42B22F; static void __declspec(naked) combat_ai_hook_FleeFix() { __asm { - call fo::funcoffs::ai_check_drugs_; // try to heal + test byte ptr [ebp], 8; // 'ReTarget' flag + jnz reTarget; test byte ptr [ebp], 4; // flee flag? (critter.combat_state) - jnz flee; + jz tryHeal; +flee: + jmp fo::funcoffs::critter_name_; +tryHeal: + call fo::funcoffs::ai_check_drugs_; // try to heal + mov eax, esi; + mov edx, STAT_current_hp; + call fo::funcoffs::stat_level_; + cmp eax, [ebx + 0x10]; // minimum hp, below which NPC will run away + mov eax, esi; + jl flee; + add esp, 4; + jmp combat_ai_hook_flee_Ret; +reTarget: + and byte ptr [ebp], ~(4 | 8); // unset Flee/ReTarget flags + xor edi, edi; + mov dword ptr [esi + whoHitMe], edi; add esp, 4; jmp combat_ai_hook_flee_Ret; -flee: - mov eax, esi - call fo::funcoffs::critter_name_; - retn; } } diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 43e366c8..d2ee6b0f 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -449,15 +449,12 @@ end: static void __declspec(naked) gdProcessUpdate_hack() { __asm { - add eax, esi - cmp eax, dword ptr ds:[FO_VAR_optionRect + 0xC] // _optionRect.offy - jge skip - add eax, 2 - push 0x44702D - retn + lea edx, [eax - 2]; + cmp edx, dword ptr ds:[FO_VAR_optionRect + 0xC]; // _optionRect.offy + jl skip; + mov eax, edx; skip: - push 0x4470DB - retn + retn; } } @@ -2215,11 +2212,11 @@ void BugFixes::init() dlogr(" Done", DL_INIT); // Allow 9 options (lines of text) to be displayed correctly in a dialog window - if (GetConfigInt("Misc", "DialogOptions9Lines", 1)) { + //if (GetConfigInt("Misc", "DialogOptions9Lines", 1)) { dlog("Applying 9 dialog options patch.", DL_INIT); - MakeJump(0x44701C, gdProcessUpdate_hack); + MakeCall(0x447021, gdProcessUpdate_hack, 1); dlogr(" Done", DL_INIT); - } + //} // Fix for "Unlimited Ammo" exploit dlog("Applying fix for Unlimited Ammo exploit.", DL_INIT);