From b189fe9252593264332f808f207c4314e6cfcea6 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Sat, 22 Jul 2023 04:21:05 +0200 Subject: [PATCH] HOOK_STEAL: ret1 to override experience for successful stealing --- artifacts/scripting/hooks.yml | 1 + artifacts/scripting/hookscripts.md | 1 + sfall/Modules/HookScripts/MiscHs.cpp | 29 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/artifacts/scripting/hooks.yml b/artifacts/scripting/hooks.yml index 3c3f5886..8388a9b2 100644 --- a/artifacts/scripting/hooks.yml +++ b/artifacts/scripting/hooks.yml @@ -378,6 +378,7 @@ int arg4 - quantity of items being stolen int ret0 - overrides hard-coded handler (1 - force success, 0 - force fail, -1 - use engine handler) + int ret1 - overrides experience points gained for stealing this item ``` - name: WithinPerception diff --git a/artifacts/scripting/hookscripts.md b/artifacts/scripting/hookscripts.md index 7d011563..73ff145f 100644 --- a/artifacts/scripting/hookscripts.md +++ b/artifacts/scripting/hookscripts.md @@ -481,6 +481,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 ret1 - overrides experience points gained for stealing this item ``` ------------------------------------------- diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index 54afa7c8..06fa8b21 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -202,6 +202,28 @@ defaultHandler: } } +static long stealExpOverride; + +static void __declspec(naked) StealHook_ExpOverrideHack() { + __asm { + mov ecx, [esp + 316]; // total exp + cmp stealExpOverride, -1; + jz vanillaExp; + mov eax, stealExpOverride; + add ecx, eax; // 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 + mov ecx, [esp]; + add ecx, 14; // shift return address + mov [esp], ecx; + retn; + } +} + static void __declspec(naked) StealCheckHook() { __asm { HookBegin; @@ -214,6 +236,7 @@ static void __declspec(naked) StealCheckHook() { } argCount = 5; + stealExpOverride = -1; RunHookScript(HOOK_STEAL); __asm { @@ -222,6 +245,11 @@ static void __declspec(naked) StealCheckHook() { jl defaultHandler; cmp rets[0], -1; je defaultHandler; + cmp cRet, 2; + jl hookEnd; + mov eax, rets[4]; + mov stealExpOverride, eax; +hookEnd: mov eax, rets[0]; HookEnd; retn; @@ -708,6 +736,7 @@ void Inject_UseSkillHook() { void Inject_StealCheckHook() { HookCalls(StealCheckHook, { 0x4749A2, 0x474A69 }); + MakeCalls(StealHook_ExpOverrideHack, { 0x4742C5, 0x4743E1 }); } void Inject_SneakCheckHook() {