Added new hook script for controlling FID of character figure on inventory screen

This commit is contained in:
phobos2077
2017-04-01 02:12:20 +07:00
parent 203dcdf6be
commit 6e0fe881df
4 changed files with 63 additions and 0 deletions
+1
View File
@@ -46,6 +46,7 @@
#define HOOK_WITHINPERCEPTION (23)
#define HOOK_INVENTORYMOVE (24)
#define HOOK_INVENWIELD (25)
#define HOOK_ADJUSTFID (26)
//Valid arguments to list_begin
#define LIST_CRITTERS (0)
+14
View File
@@ -436,3 +436,17 @@ int arg3 - slot (INVEN_TYPE_*)
int arg4 - 1 when wielding, 0 when unwielding
int ret1 - overrides hard-coded handler (-1 - use engine handler, any other value - override) - NOT RECOMMENDED
-------------------------------------------
HOOK_ADJUSTFID (hs_adjustfid.int)
Runs after calculating character figure FID on the inventory screen, whenever the game decides that character appearance might change.
Also happens on other screens, like barter.
NOTE: FID has following format: 0x0ABBCDDD, where A is object type, BB - animation code (always 0 in this case), C - weapon code, DDD - FRM index in LST file.
int arg1 - the vanilla fid calculated by the engine according to critter base FID and armor/weapon being used
int ret1 - overrides the calculated FID with provided value
+47
View File
@@ -979,6 +979,35 @@ skipcall:
}
}
// Hooks into dropping item from inventory to ground
// - allows to prevent item being dropped if 0 is returned with set_sfall_return
// - called for every item when dropping multiple items in stack (except caps)
// - when dropping caps it called always once
// - if 0 is returned while dropping caps, selected amount - 1 will still disappear from inventory
/*
static void __declspec(naked) InvenActionCursor_ObjDrop_Hook() {
__asm {
hookbegin(3);
mov args[0], 5;
mov args[4], edx; // item being dropped
mov args[8], 0; // no item being replaced here..
pushad;
push HOOK_INVENTORYMOVE;
call RunHookScript;
popad;
cmp cRet, 1;
jl skipcheck;
cmp rets[0], -1;
jne skipcall;
skipcheck:
call fo::funcoffs::obj_drop_;
skipcall:
hookend;
retn;
}
}
*/
static void _declspec(naked) invenWieldFunc_Hook() {
using namespace fo;
__asm {
@@ -1101,6 +1130,19 @@ donothing:
}
}
void AdjustFidHook(DWORD vanillaFid) {
BeginHook();
argCount = 1;
args[0] = vanillaFid;
RunHookScript(HOOK_ADJUSTFID);
if (cRet > 0) {
fo::var::i_fid = rets[0];
}
EndHook();
}
// END HOOKS
DWORD _stdcall GetHSArgCount() {
return argCount;
}
@@ -1316,12 +1358,17 @@ static void HookScriptInit2() {
//HookCall(0x4712C7, &DropAmmoIntoWeaponHook);
//HookCall(0x471351, &DropAmmoIntoWeaponHook);
MakeJump(0x476588, DropAmmoIntoWeaponHack);
// TODO: consider adding item drop event into INVENTORYMOVE or different hook
//HookCalls(InvenActionCursor_ObjDrop_Hook, { 0x473851, 0x47386F });
LoadHookScript("hs_invenwield", HOOK_INVENWIELD);
HookCalls(invenWieldFunc_Hook, { 0x47275E, 0x495FDF });
HookCalls(invenUnwieldFunc_Hook, { 0x45967D, 0x472A5A, 0x495F0B});
HookCalls(correctFidForRemovedItem_Hook, { 0x45680C, 0x45C4EA });
LoadHookScript("hs_adjustfid", HOOK_ADJUSTFID);
Inventory::OnAdjustFid() += AdjustFidHook;
dlogr("Finished loading hook scripts", DL_HOOK|DL_INIT);
}
+1
View File
@@ -52,6 +52,7 @@ enum HookType
HOOK_WITHINPERCEPTION = 23,
HOOK_INVENTORYMOVE = 24,
HOOK_INVENWIELD = 25,
HOOK_ADJUSTFID = 26,
HOOK_COUNT
};