From 7b92d0f9397912d94a800279564ff9e07b15d20f Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 30 Dec 2018 09:59:39 +0800 Subject: [PATCH] Corrected/improved code of some hooks. Changed critical table to be loaded before global scripts. Updated version number and year. --- artifacts/ddraw.ini | 2 +- sfall/Modules/HookScripts/InventoryHs.cpp | 52 +++++++++++------------ sfall/Modules/HookScripts/MiscHs.cpp | 44 +++++++++---------- sfall/Modules/HookScripts/ObjectHs.cpp | 6 +-- sfall/Modules/MiscPatches.cpp | 18 ++++---- sfall/main.cpp | 2 +- sfall/version.h | 6 +-- 7 files changed, 63 insertions(+), 67 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 63648ff0..910ce848 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v4.1.3 +;v4.1.4 [Main] ;Change to 1 if you want to use command line args to tell sfall to use another ini file. diff --git a/sfall/Modules/HookScripts/InventoryHs.cpp b/sfall/Modules/HookScripts/InventoryHs.cpp index c9e2893c..000a0472 100644 --- a/sfall/Modules/HookScripts/InventoryHs.cpp +++ b/sfall/Modules/HookScripts/InventoryHs.cpp @@ -174,12 +174,12 @@ static void __declspec(naked) InvenActionCursorObjDropHook() { goto skipHook; } else { __asm { - pushad; + pushadc; xor ecx, ecx; // no itemReplace push 6; // event: item drop ground call InventoryMoveHook_Script; // edx - item mov dropResult, eax; // ret value - popad; + popadc; cmp dword ptr [esp], 0x47379A + 5; // caps call address jz capsMultiDrop; } @@ -204,19 +204,19 @@ capsMultiDrop: static void __declspec(naked) InvenActionExplosiveDropHack() { __asm { - pushad; + pushadc; xor ecx, ecx; // no itemReplace push 6; // event: item drop ground call InventoryMoveHook_Script; // edx - item cmp eax, -1; // ret value - popad; - jnz noDrop; - mov dword ptr ds:[FO_VAR_dropped_explosive], ebp; // overwritten engine code (ebp = 1) - mov nextHookDropSkip, ebp; + popadc; + jnz noDrop; + mov dword ptr ds:[FO_VAR_dropped_explosive], ebp; // overwritten engine code (ebp = 1) + mov nextHookDropSkip, ebp; retn; noDrop: - add esp, 4; - jmp InvenActionObjDropRet; // no drop + add esp, 4; + jmp InvenActionObjDropRet; // no drop } } @@ -234,19 +234,19 @@ static const DWORD DropIntoContainer_back = 0x47649D; // normal operation static const DWORD DropIntoContainer_skip = 0x476503; static void __declspec(naked) DropIntoContainerHack() { __asm { - pushad; - mov ecx, ebp; // contaner ptr - mov edx, esi; // item - mov eax, [esp + 0x10 + 32]; // call address + pushadc; + mov ecx, ebp; // contaner ptr + mov edx, esi; // item + mov eax, [esp + 0x10 + 32]; // call address push eax; call DropIntoContainer; cmp eax, -1; // ret value - popad; + popadc; jne skipdrop; - jmp DropIntoContainer_back; + jmp DropIntoContainer_back; skipdrop: - mov eax, -1; - jmp DropIntoContainer_skip; + mov eax, -1; + jmp DropIntoContainer_skip; } } @@ -254,7 +254,7 @@ static const DWORD DropIntoContainerRet = 0x471481; static void __declspec(naked) DropIntoContainerHandSlotHack() { __asm { call fo::funcoffs::drop_into_container_; - jmp DropIntoContainerRet; + jmp DropIntoContainerRet; } } @@ -262,19 +262,19 @@ static const DWORD DropAmmoIntoWeaponHack_back = 0x47658D; // proceed with reloa static const DWORD DropAmmoIntoWeaponHack_return = 0x476643; static void _declspec(naked) DropAmmoIntoWeaponHack() { __asm { - pushad; - mov ecx, ebp; // weapon ptr - mov edx, [esp + 32]; // item var: ammo_ + pushadc; + mov ecx, ebp; // weapon ptr + mov edx, [esp + 32]; // item var: ammo_ push 4; // event: weapon reloading call InventoryMoveHook_Script; cmp eax, -1; // ret value - popad; + popadc; jne donothing; - mov ebx, 1; // overwritten code - jmp DropAmmoIntoWeaponHack_back; + mov ebx, 1; // overwritten code + jmp DropAmmoIntoWeaponHack_back; donothing: - xor eax, eax; // result 0 - jmp DropAmmoIntoWeaponHack_return; + xor eax, eax; // result 0 + jmp DropAmmoIntoWeaponHack_return; } } diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index 6c4e5d04..60820fe2 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -369,50 +369,48 @@ skip: } } -static int __fastcall ExplosiveTimerHook_Script(DWORD type, DWORD item, DWORD time) { +static int __fastcall ExplosiveTimerHook_Script(DWORD* type, DWORD item, DWORD time) { BeginHook(); argCount = 3; args[0] = time; args[1] = item; - args[2] = (type == 11) ? fo::ROLL_FAILURE : fo::ROLL_SUCCESS; + args[2] = (*type == 11) ? fo::ROLL_FAILURE : fo::ROLL_SUCCESS; RunHookScript(HOOK_EXPLOSIVETIMER); - int result = 0; - if (cRet > 0 && rets[0] >= 0) { - if (rets[0] > 18000) rets[0] = 18000; // max 30 minutes - if (cRet < 2 || (rets[1] < fo::ROLL_CRITICAL_FAILURE || rets[1] > fo::ROLL_CRITICAL_SUCCESS)) { - result--; // use vanilla type - } else { - result++; // use returned type + time = -1; + if (cRet > 0 && (long)rets[0] >= 0) { + time = min(rets[0], 18000); // max 30 minutes + if (cRet > 1) { + int typeRet = rets[1]; + if (typeRet >= fo::ROLL_CRITICAL_FAILURE && typeRet <= fo::ROLL_CRITICAL_SUCCESS) { + *type = (typeRet > fo::ROLL_FAILURE) ? 8 : 11; // returned new type (8 = SUCCESS, 11 = FAILURE) + } } } - return result; + EndHook(); + return time; } static void _declspec(naked) ExplosiveTimerHook() { - using namespace fo; __asm { - push eax; + push eax; // time in ticks for queue_add_ push edx; - push ecx; //------- - push edi; // time in ticks + push ecx; + mov ecx, esp; // ptr to type + push edi; // time in ticks (w/o failure penalty) call ExplosiveTimerHook_Script; // ecx - type, edx - item - cmp eax, 0; pop ecx; pop edx; + cmp eax, -1; // return new time in ticks + jne skip; pop eax; - jz end; - mov eax, rets[0]; // time in ticks - jl end; - mov ecx, 8; // type SUCCESS - cmp rets[4], ROLL_FAILURE; - jg end; - add ecx, 3; // type FAILURE (11) + jmp end; +skip: + add esp, 4; end: - HookEnd; jmp fo::funcoffs::queue_add_; } } diff --git a/sfall/Modules/HookScripts/ObjectHs.cpp b/sfall/Modules/HookScripts/ObjectHs.cpp index d526b9d4..62268cec 100644 --- a/sfall/Modules/HookScripts/ObjectHs.cpp +++ b/sfall/Modules/HookScripts/ObjectHs.cpp @@ -102,10 +102,8 @@ static DWORD __fastcall UseAnimateObjHook_Script(DWORD critter, DWORD animCode, RunHookScript(HOOK_USEANIMOBJ); - if (cRet > 0) { - if (static_cast(rets[0]) <= 64) { - animCode = rets[0]; // new anim code - } + if (cRet > 0 && static_cast(rets[0]) <= 64) { + animCode = rets[0]; // new anim code } EndHook(); diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index 0962d4e4..640b575d 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -916,6 +916,15 @@ void InterfaceDontMoveOnTopPatch() { } } +void UseWalkDistancePatch() { + int distance = GetConfigInt("Misc", "UseWalkDistance", 3) + 2; + if (distance > 1 && distance < 5) { + dlog("Applying walk distance for using objects patch.", DL_INIT); + SafeWriteBatch(distance, walkDistanceAddr); // default is 5 + dlogr(" Done", DL_INIT); + } +} + void BodypartHitChances() { using fo::var::hit_location_penalty; hit_location_penalty[0] = static_cast(GetConfigInt("Misc", "BodyHit_Head", -40)); @@ -929,15 +938,6 @@ void BodypartHitChances() { hit_location_penalty[8] = static_cast(GetConfigInt("Misc", "BodyHit_Torso_Uncalled", 0)); } -void UseWalkDistancePatch() { - int distance = GetConfigInt("Misc", "UseWalkDistance", 3) + 2; - if (distance > 1 && distance < 5) { - dlog("Applying walk distance for using objects patch.", DL_INIT); - SafeWriteBatch(distance, walkDistanceAddr); // default is 5 - dlogr(" Done", DL_INIT); - } -} - void MiscPatches::init() { mapName[64] = 0; if (GetConfigString("Misc", "StartingMap", "", mapName, 64)) { diff --git a/sfall/main.cpp b/sfall/main.cpp index 83000602..70358763 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -140,6 +140,7 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); + manager.add(); manager.add(); manager.add(); manager.add(); @@ -148,7 +149,6 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); - manager.add(); manager.add(); manager.add(); manager.add(); diff --git a/sfall/version.h b/sfall/version.h index 664c8793..8c39e831 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -20,14 +20,14 @@ #define TARGETVERSION "Fallout 2 v1.02 US" -#define LEGAL_COPYRIGHT "Copyright (C) 2006-2018, sfall team" +#define LEGAL_COPYRIGHT "Copyright (C) 2006-2019, sfall team" #define VERSION_MAJOR 4 #define VERSION_MINOR 1 -#define VERSION_BUILD 3 +#define VERSION_BUILD 4 #define VERSION_REV 0 -#define VERSION_STRING "4.1.3" +#define VERSION_STRING "4.1.4" #define CHECK_VAL (4)