Edited ASM code and documents for HOOK_STEAL

This commit is contained in:
NovaRain
2023-07-22 20:46:26 +08:00
parent 5394352bf0
commit 53c294cf98
3 changed files with 28 additions and 31 deletions
+4 -4
View File
@@ -227,7 +227,7 @@
Critter arg1 - the critter being bartered with Critter arg1 - the critter being bartered with
int arg2 - the default value of the goods int arg2 - the default value of the goods
Critter arg3 - table of requested goods (being bought from NPC) 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 int arg5 - the value of all goods being traded before skill modifications
Critter arg6 - table of offered goods (being sold to NPC) Critter arg6 - table of offered goods (being sold to NPC)
int arg7 - the total cost of the goods offered by the player int arg7 - the total cost of the goods offered by the player
@@ -373,12 +373,12 @@
``` ```
Critter arg0 - Thief Critter arg0 - Thief
Obj arg1 - The target 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 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 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 - name: WithinPerception
+4 -4
View File
@@ -322,7 +322,7 @@ Critter arg0 - the critter doing the bartering (either dude_obj or inven_dude)
Critter arg1 - the critter being bartered with Critter arg1 - the critter being bartered with
int arg2 - the default value of the goods int arg2 - the default value of the goods
Critter arg3 - table of requested goods (being bought from NPC) 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 int arg5 - the value of all goods being traded before skill modifications
Critter arg6 - table of offered goods (being sold to NPC) Critter arg6 - table of offered goods (being sold to NPC)
int arg7 - the total cost of the goods offered by the player int arg7 - the total cost of the goods offered by the player
@@ -476,12 +476,12 @@ Example message (vanilla behavior):\
``` ```
Critter arg0 - Thief Critter arg0 - Thief
Obj arg1 - The target 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 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 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)
``` ```
------------------------------------------- -------------------------------------------
+9 -12
View File
@@ -206,17 +206,16 @@ static long stealExpOverride;
static void __declspec(naked) StealHook_ExpOverrideHack() { static void __declspec(naked) StealHook_ExpOverrideHack() {
__asm { __asm {
mov ecx, [esp + 316]; // total exp mov ecx, [esp + 0x150 - 0x18 + 4]; // total exp
cmp stealExpOverride, -1; cmp stealExpOverride, -1;
jle vanillaExp; jle vanillaExp;
mov eax, stealExpOverride; add ecx, stealExpOverride; // add overridden exp value
add ecx, eax; // add overridden exp value
jmp end; jmp end;
vanillaExp: vanillaExp:
add ecx, edi; // add vanilla exp value add ecx, edi; // add vanilla exp value
end: end:
add edi, 10; // increment vanilla exp value add edi, 10; // vanilla exp increment for next success
mov [esp + 316], ecx; // set total exp mov [esp + 0x150 - 0x18 + 4], ecx; // set total exp
mov ecx, [esp]; mov ecx, [esp];
add ecx, 14; // shift return address add ecx, 14; // shift return address
mov [esp], ecx; mov [esp], ecx;
@@ -225,7 +224,7 @@ end:
} }
static void __declspec(naked) StealCheckHook() { static void __declspec(naked) StealCheckHook() {
static const unsigned long StealSkip_addr = 0x474B18; static const DWORD StealSkipRet = 0x474B18;
__asm { __asm {
HookBegin; HookBegin;
mov args[0], eax; // thief mov args[0], eax; // thief
@@ -237,7 +236,6 @@ static void __declspec(naked) StealCheckHook() {
} }
argCount = 5; argCount = 5;
stealExpOverride = -1;
RunHookScript(HOOK_STEAL); RunHookScript(HOOK_STEAL);
__asm { __asm {
@@ -245,19 +243,18 @@ static void __declspec(naked) StealCheckHook() {
cmp cRet, 1; cmp cRet, 1;
jl defaultHandler; // no return values, use vanilla path jl defaultHandler; // no return values, use vanilla path
cmp cRet, 2; cmp cRet, 2;
jl skipExpOverride;
push eax; push eax;
mov eax, rets[4]; // override experience points for steal mov eax, -1;
cmovge eax, rets[4]; // override experience points for steal
mov stealExpOverride, eax; mov stealExpOverride, eax;
pop eax; pop eax;
skipExpOverride:
cmp rets[0], -1; // if <= -1, use vanilla path cmp rets[0], -1; // if <= -1, use vanilla path
jle defaultHandler; jle defaultHandler;
cmp rets[0], 2; // 2 - steal failed but didn't get cought cmp rets[0], 2; // 2 - steal failed but didn't get cought
jnz normalReturn; jnz normalReturn;
HookEnd; HookEnd;
pop eax; add esp, 4;
jmp StealSkip_addr; jmp StealSkipRet;
normalReturn: normalReturn:
mov eax, rets[0]; mov eax, rets[0];
HookEnd; HookEnd;