Rewrote NPC fleeing fix.

Removed DialogOptions9Lines option from ddraw.ini.
This commit is contained in:
NovaRain
2019-05-22 10:41:37 +08:00
parent 119b0afacd
commit f5317ad5ee
3 changed files with 29 additions and 24 deletions
-3
View File
@@ -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
+21 -10
View File
@@ -36,25 +36,36 @@ static std::unordered_map<DWORD, DWORD> 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;
}
}
+8 -11
View File
@@ -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);