From 53c294cf98ccfca61f4ac0d6ed55ce65a1646b06 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 22 Jul 2023 20:46:26 +0800 Subject: [PATCH] Edited ASM code and documents for HOOK_STEAL --- artifacts/scripting/hooks.yml | 8 +++--- artifacts/scripting/hookscripts.md | 8 +++--- sfall/Modules/HookScripts/MiscHs.cpp | 43 +++++++++++++--------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/artifacts/scripting/hooks.yml b/artifacts/scripting/hooks.yml index d5cafd84..a618b418 100644 --- a/artifacts/scripting/hooks.yml +++ b/artifacts/scripting/hooks.yml @@ -227,7 +227,7 @@ Critter arg1 - the critter being bartered with int arg2 - the default value of the goods Critter arg3 - table of requested goods (being bought from NPC) - int arg4 - the amount of actual caps in the barter stack (as opposed to goods) + int arg4 - the number of actual caps in the barter stack (as opposed to goods) int arg5 - the value of all goods being traded before skill modifications Critter arg6 - table of offered goods (being sold to NPC) int arg7 - the total cost of the goods offered by the player @@ -373,12 +373,12 @@ ``` Critter arg0 - Thief Obj arg1 - The target - Item arg2 - Item being stolen/planted + Item arg2 - The item being stolen/planted int arg3 - 0 when stealing, 1 when planting - int arg4 - quantity of items being stolen + int arg4 - quantity of the item being stolen/planted int ret0 - overrides hard-coded handler (2 - force fail without closing window, 1 - force success, 0 - force fail, -1 - use engine handler) - int ret1 - overrides experience points gained for stealing this item + int ret1 - overrides experience points gained for stealing this item (must be greater than or equal to 0) ``` - name: WithinPerception diff --git a/artifacts/scripting/hookscripts.md b/artifacts/scripting/hookscripts.md index 63e290e3..092be156 100644 --- a/artifacts/scripting/hookscripts.md +++ b/artifacts/scripting/hookscripts.md @@ -322,7 +322,7 @@ Critter arg0 - the critter doing the bartering (either dude_obj or inven_dude) Critter arg1 - the critter being bartered with int arg2 - the default value of the goods Critter arg3 - table of requested goods (being bought from NPC) -int arg4 - the amount of actual caps in the barter stack (as opposed to goods) +int arg4 - the number of actual caps in the barter stack (as opposed to goods) int arg5 - the value of all goods being traded before skill modifications Critter arg6 - table of offered goods (being sold to NPC) int arg7 - the total cost of the goods offered by the player @@ -476,12 +476,12 @@ Example message (vanilla behavior):\ ``` Critter arg0 - Thief Obj arg1 - The target -Item arg2 - Item being stolen/planted +Item arg2 - The item being stolen/planted int arg3 - 0 when stealing, 1 when planting -int arg4 - quantity of items being stolen +int arg4 - quantity of the item being stolen/planted int ret0 - overrides hard-coded handler (2 - force fail without closing window, 1 - force success, 0 - force fail, -1 - use engine handler) -int ret1 - overrides experience points gained for stealing this item +int ret1 - overrides experience points gained for stealing this item (must be greater than or equal to 0) ``` ------------------------------------------- diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index 6febd909..b085e9b7 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -206,17 +206,16 @@ static long stealExpOverride; static void __declspec(naked) StealHook_ExpOverrideHack() { __asm { - mov ecx, [esp + 316]; // total exp + mov ecx, [esp + 0x150 - 0x18 + 4]; // total exp cmp stealExpOverride, -1; jle vanillaExp; - mov eax, stealExpOverride; - add ecx, eax; // add overridden exp value + add ecx, stealExpOverride; // add overridden exp value jmp end; vanillaExp: add ecx, edi; // add vanilla exp value end: - add edi, 10; // increment vanilla exp value - mov [esp + 316], ecx; // set total exp + add edi, 10; // vanilla exp increment for next success + mov [esp + 0x150 - 0x18 + 4], ecx; // set total exp mov ecx, [esp]; add ecx, 14; // shift return address mov [esp], ecx; @@ -225,7 +224,7 @@ end: } static void __declspec(naked) StealCheckHook() { - static const unsigned long StealSkip_addr = 0x474B18; + static const DWORD StealSkipRet = 0x474B18; __asm { HookBegin; mov args[0], eax; // thief @@ -237,34 +236,32 @@ static void __declspec(naked) StealCheckHook() { } argCount = 5; - stealExpOverride = -1; RunHookScript(HOOK_STEAL); __asm { popadc; - cmp cRet, 1; - jl defaultHandler; // no return values, use vanilla path - cmp cRet, 2; - jl skipExpOverride; + cmp cRet, 1; + jl defaultHandler; // no return values, use vanilla path + cmp cRet, 2; push eax; - mov eax, rets[4]; // override experience points for steal - mov stealExpOverride, eax; - pop eax; -skipExpOverride: - cmp rets[0], -1; // if <= -1, use vanilla path - jle defaultHandler; - cmp rets[0], 2; // 2 - steal failed but didn't get cought - jnz normalReturn; + mov eax, -1; + cmovge eax, rets[4]; // override experience points for steal + mov stealExpOverride, eax; + pop eax; + cmp rets[0], -1; // if <= -1, use vanilla path + jle defaultHandler; + cmp rets[0], 2; // 2 - steal failed but didn't get cought + jnz normalReturn; HookEnd; - pop eax; - jmp StealSkip_addr; + add esp, 4; + jmp StealSkipRet; normalReturn: - mov eax, rets[0]; + mov eax, rets[0]; HookEnd; retn; defaultHandler: HookEnd; - jmp fo::funcoffs::skill_check_stealing_; + jmp fo::funcoffs::skill_check_stealing_; } }