From 98508a9c761f0b2c89d1c2546f8aaf802984e4e0 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 27 May 2016 10:37:12 +0800 Subject: [PATCH] Added a bug fix for incorrect initialization of action points at the beginning of each turn (from Crafty's mod) Removed unused code in Bugs.cpp. --- sfall/Bugs.cpp | 61 +++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/sfall/Bugs.cpp b/sfall/Bugs.cpp index 38749d91..90d249e3 100644 --- a/sfall/Bugs.cpp +++ b/sfall/Bugs.cpp @@ -163,26 +163,6 @@ skip: } } -/* -static void __declspec(naked) item_wd_process_hook() { - __asm { - cmp esi, PERK_add_jet - je itsJet - retn -itsJet: - pop edx // Destroying the return address - xor edx, edx // edx=init - mov ecx, dword ptr [ebx+0x4] // ecx=drug_pid - push ecx - mov ecx, esi // ecx=perk - mov ebx, 2880 // ebx=time - call insert_withdrawal_ - mov eax, 0x47A3FB - jmp eax - } -} -*/ - static void __declspec(naked) item_d_load_hack() { __asm { sub esp, 4 @@ -700,6 +680,38 @@ static void __declspec(naked) item_m_turn_off_hook() { } } +static void __declspec(naked) combat_hack() { + __asm { + mov eax, [ecx+eax] // eax = source + test eax, eax + jz end + push eax + mov edx, STAT_max_move_points + call stat_level_ + mov edx, ds:[_gcsd] + test edx, edx + jz skip + add eax, [edx+0x8] // gcsd.free_move +skip: + pop edx + xchg edx, eax // eax = source, edx = Max action points + mov [eax+0x40], edx // pobj.curr_mp + test byte ptr ds:[_combat_state], 1 // in combat? + jz end // No + mov edx, [eax+0x68] // pobj.cid + cmp edx, -1 + je end + push eax + mov eax, ds:[_aiInfoList] + shl edx, 4 + mov dword ptr [edx+eax+0xC], 0 // aiInfo.lastMove + pop eax +end: + mov edx, edi // dude_turn + retn + } +} + void BugsInit() { @@ -739,9 +751,6 @@ void BugsInit() dlogr(" Done.", DL_INIT); } - // makes jet addiction eternal.. why? - //MakeCall(0x47A3A4, &item_wd_process_hook, false); - // Fix for gaining stats from more than two doses of a specific chem after save-load dlog("Applying fix for save-load unlimited drug use exploit.", DL_INIT); MakeCall(0x47A243, &item_d_load_hack, false); @@ -885,4 +894,10 @@ void BugsInit() HookCall(0x4798B1, &item_m_turn_off_hook); dlogr(" Done", DL_INIT); } + + // Fix for incorrect initialization of action points at the beginning of each turn + dlog("Applying Action Points initialization fix.", DL_INIT); + BlockCall(0x422E02); + MakeCall(0x422E1B, &combat_hack, false); + dlogr(" Done", DL_INIT); }