From 8a226b3139ddd37328640fda2377a9270050802b Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 8 Jun 2021 07:07:27 +0800 Subject: [PATCH] Fixed infinite loop in combat with AIDrugUsePerfFix --- sfall/BugFixes.cpp | 15 ++++++++------- sfall/ddraw.vcxproj | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sfall/BugFixes.cpp b/sfall/BugFixes.cpp index a69358e7..aee57940 100644 --- a/sfall/BugFixes.cpp +++ b/sfall/BugFixes.cpp @@ -1998,35 +1998,36 @@ skip: static DWORD firstItemDrug = -1; +// when there are no more items in the inventory static void __declspec(naked) ai_check_drugs_hack_break() { static const DWORD ai_check_drugs_hack_Ret = 0x42878B; __asm { mov eax, -1; cmp firstItemDrug, eax; - jne firstDrugs; // pid != -1 + jne useDrugs; // pid != -1 add esp, 4; jmp ai_check_drugs_hack_Ret; // break loop -firstDrugs: +useDrugs: // use the first found item mov dword ptr [esp + 4], eax; // slot set -1 mov edi, firstItemDrug; mov ebx, edi; mov firstItemDrug, eax; // set -1 - retn; // use drug + retn; // goto check (use drug) } } static void __declspec(naked) ai_check_drugs_hack_check() { __asm { - test [esp + 0x34 - 0x30 + 4], 0; // check NoInvenItem != 0 - jnz skip; + test [esp + 0x34 - 0x30 + 4], 1; // check NoInvenItem != 0 + jnz skip; // there are no more drugs in inventory cmp dword ptr [edx + 0xAC], -1; // cap.chem_primary_desire (Chemical Preference Number) jnz checkDrugs; skip: xor ebx, ebx; // set ZF for skipping preference list check retn; checkDrugs: - cmp ebx, [edx + 0xAC]; // check item.pid against cap.chem_primary_desire - retn; + cmp ebx, [edx + 0xAC]; // item.pid == cap.chem_primary_desire? + retn; // if yes, use it (jz 0x4286C7); otherwise, check the other values of chem_primary_desire } } diff --git a/sfall/ddraw.vcxproj b/sfall/ddraw.vcxproj index f6632b42..2e153eec 100644 --- a/sfall/ddraw.vcxproj +++ b/sfall/ddraw.vcxproj @@ -82,7 +82,7 @@ d3d9.lib;d3dx9.lib;dinput.lib;Strmiids.lib;ws2_32.lib;%(AdditionalDependencies) exports.def - ws2_32.dll;d3d9.dll;d3dx9d_43.dll;%(DelayLoadDLLs) + ws2_32.dll;d3d9.dll;d3dx9d_42.dll;%(DelayLoadDLLs) true Console false @@ -147,8 +147,8 @@ MachineX86 false - 5.00 $(DXSDK_DIR)lib\x86\ + 5.00 "$(ProjectDir)postbuild.cmd" release "$(TargetPath)"