From 5394352bf091db04b8fc81ac9e41114da6719380 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Sat, 22 Jul 2023 13:43:23 +0200 Subject: [PATCH] HOOK_STEAL: add ret0 value 2 to fail "silently" --- artifacts/scripting/hooks.yml | 2 +- artifacts/scripting/hookscripts.md | 2 +- sfall/Modules/HookScripts/MiscHs.cpp | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/artifacts/scripting/hooks.yml b/artifacts/scripting/hooks.yml index 8388a9b2..d5cafd84 100644 --- a/artifacts/scripting/hooks.yml +++ b/artifacts/scripting/hooks.yml @@ -377,7 +377,7 @@ int arg3 - 0 when stealing, 1 when planting int arg4 - quantity of items being stolen - int ret0 - overrides hard-coded handler (1 - force success, 0 - force fail, -1 - use engine handler) + 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 ``` diff --git a/artifacts/scripting/hookscripts.md b/artifacts/scripting/hookscripts.md index 73ff145f..63e290e3 100644 --- a/artifacts/scripting/hookscripts.md +++ b/artifacts/scripting/hookscripts.md @@ -480,7 +480,7 @@ Item arg2 - Item being stolen/planted int arg3 - 0 when stealing, 1 when planting int arg4 - quantity of items being stolen -int ret0 - overrides hard-coded handler (1 - force success, 0 - force fail, -1 - use engine handler) +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 ``` diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index d2962831..6febd909 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -225,6 +225,7 @@ end: } static void __declspec(naked) StealCheckHook() { + static const unsigned long StealSkip_addr = 0x474B18; __asm { HookBegin; mov args[0], eax; // thief @@ -242,16 +243,22 @@ static void __declspec(naked) StealCheckHook() { __asm { popadc; cmp cRet, 1; - jl defaultHandler; + jl defaultHandler; // no return values, use vanilla path cmp cRet, 2; jl skipExpOverride; push eax; - mov eax, rets[4]; + mov eax, rets[4]; // override experience points for steal mov stealExpOverride, eax; pop eax; skipExpOverride: - cmp rets[0], -1; + 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; +normalReturn: mov eax, rets[0]; HookEnd; retn;