From 6cce07991eeb1350419b8679d4f9dbc948cd83d3 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 25 Dec 2018 09:28:30 +0800 Subject: [PATCH] Added missing return values for HOOK_INVENWIELD. Updated NPC armor appearance mod. --- artifacts/mods/gl_npcarmor.int | Bin 4006 -> 4238 bytes artifacts/mods/gl_npcarmor.ssl | 21 ++++++++++++++++----- sfall/Modules/HookScripts/InventoryHs.cpp | 21 +++++++++++++++++---- sfall/Modules/Inventory.cpp | 10 +++++----- sfall/Modules/Inventory.h | 2 ++ sfall/Modules/LoadGameHook.cpp | 2 +- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/artifacts/mods/gl_npcarmor.int b/artifacts/mods/gl_npcarmor.int index 03589cca6e284cbd7425deddda876daa22cb1cb9..45aa8ae4cbdeb20e9614876cfefffcc6358e065c 100644 GIT binary patch delta 932 zcmZ1`-=`?hz;u9-fq_A&ffqzGy_hIqP|qyE00B`D3Pys(nHd-u3Sc4-nx&3`fdM4m z2I0dentXu8 zgNco6G8d~py9GA2zv$0{blz`&*gF^z$-!Kje|WG(|sgYaZK7Nf}` zY%&?_Gr&TO4Mq(HAQpQBhy*EaI0dR7#{~|p$p^SZCR?%Vs$T%>U}!LcIE=%fK?3e9khx&za`;W|W0zs# zsGA(ep(@DOzzWvH)L;mrIrdF{#BMhE3afw?0|Vy{kPrjHyf4_y;}n|gz#${X=>S&D z3=JKSb;b?)lP|D}urM%i=1q>{uw&xfF?k+`7!&8V$=f(wn7HC5|KU(!;xd`+!KFUg zlan7L62+My#+}o!e*!4E-f1d>1t53Mh($ delta 853 zcmeBETqZBjz;u9-fq_A&ffqzGotY?LP|x&%0RrqG6pRFmGczzSgup}~G)ou*0|Q7r z3&MwytiKo-7(k}i!9*Z5y9k74m;$At6vqoN!8ASIg44B)2@L94U3=PH&(jXR#z+?rMJ|@;jVEwF*Ccj|u0P&1i^%*ZruH%uMT+M32 zxMA`JR##3dh_MU|lcQMdCWo=f=&=0(nZdx=VANm$VzKQ3kzoEwFpIgtxIrJpVr!aw zi_M6MZO>#rcJaxk?1D^eeW^3={j6$zdF(j3SeJILtISE`Zg*b#ho>)5#Gw`45K- z6Gz)*H%>b#s2*_0{Qv*|e}f6c#T@4*&*OAq;w+o|gj0oy(`T{)x4Ix>11r=9LlDhb zHra_QA&;x2VgCeB0=Uyu2Gh>f0#X1DiW6WKJjl72&>V#bDzL}69FXK0pb^Fhi!d&S z$pYMROk72i4Y+sl@b@*QKmv(dZt^$oHYOga$#pypOx)8Z@kTK5&Y2v=+rq?KGx-5; zgA&gVX#8=(&9nr&jH?0c8J?m^yrPq*^I0?T_f5XS*T=-KGC76cmyu=iCjKxczM9Eg N0vRm4Z@}>-0RY9Nx|{$2 diff --git a/artifacts/mods/gl_npcarmor.ssl b/artifacts/mods/gl_npcarmor.ssl index 01ac9a87..548a2485 100644 --- a/artifacts/mods/gl_npcarmor.ssl +++ b/artifacts/mods/gl_npcarmor.ssl @@ -22,7 +22,9 @@ variable modIni := "npcarmor.ini", defaultFids, armorPidMap, // maps armor PID to it's "type" - leather armor, metal, power armor, etc. - npcMap; + npcMap, + altWeapon, + unWieldWeapon; procedure check_armor_change(variable critter, variable item, variable isWorn) begin variable npc, armorType, fid; @@ -55,6 +57,8 @@ procedure check_weapon_change(variable critter, variable item, variable isWield) end return 0; end + end else begin + unWieldWeapon := obj_pid(item); end end return -1; @@ -65,15 +69,20 @@ procedure search_alt_weapon(variable critter) begin obj := inven_ptr(critter, 0); while (obj) do begin if (obj_item_subtype(obj) == item_type_weapon) then begin - res := check_weapon_change(critter, obj, 1); - if (res == -1) then begin - wield_obj_critter(critter, obj); - break; + if (unWieldWeapon == 0 or unWieldWeapon != obj_pid(obj)) then begin + res := check_weapon_change(critter, obj, 1); + if (res == -1) then begin + altWeapon := obj; + wield_obj_critter(critter, obj); + altWeapon := 0; + break; + end end end i++; obj := inven_ptr(critter, i); end + unWieldWeapon := 0; end // for NPCs when they change armor/weapon themselves @@ -89,9 +98,11 @@ procedure invenwield_handler begin if (fid != -1) then begin art_change_fid_num(critter, fid); end + return; end if (critter and item and slot == INVEN_TYPE_RIGHT_HAND) then begin + if (altWeapon == item) then return; canWield := check_weapon_change(critter, item, isWorn); set_sfall_return(canWield); if (canWield != -1) then begin diff --git a/sfall/Modules/HookScripts/InventoryHs.cpp b/sfall/Modules/HookScripts/InventoryHs.cpp index af3d3657..c9e2893c 100644 --- a/sfall/Modules/HookScripts/InventoryHs.cpp +++ b/sfall/Modules/HookScripts/InventoryHs.cpp @@ -288,7 +288,7 @@ static bool InvenWieldHook_Script(int flag) { bool result = (cRet == 0 || rets[0] == -1); EndHook(); - return result; + return result; // True - use engine handler } static void _declspec(naked) InvenWieldFuncHook() { @@ -314,6 +314,7 @@ static void _declspec(naked) InvenWieldFuncHook() { jz skip; jmp funcoffs::invenWieldFunc_; skip: + mov eax, -1; retn; } } @@ -341,6 +342,7 @@ static void _declspec(naked) InvenUnwieldFuncHook() { jz skip; jmp fo::funcoffs::invenUnwieldFunc_; skip: + mov eax, -1; retn; } } @@ -371,6 +373,7 @@ static void _declspec(naked) CorrectFidForRemovedItemHook() { jz skip; jmp fo::funcoffs::correctFidForRemovedItem_; skip: + mov eax, -1; retn; } } @@ -419,9 +422,19 @@ void Inject_InventoryMoveHook() { } void Inject_InvenWieldHook() { - HookCalls(InvenWieldFuncHook, { 0x47275E, 0x495FDF }); - HookCalls(InvenUnwieldFuncHook, { 0x45967D, 0x472A5A, 0x495F0B }); - HookCalls(CorrectFidForRemovedItemHook, { 0x45680C, 0x45C4EA }); + HookCalls(InvenWieldFuncHook, { + 0x47275E, // inven_wield_ + 0x495FDF // partyMemberCopyLevelInfo_ + }); + HookCalls(InvenUnwieldFuncHook, { + 0x45967D, // op_metarule_ + 0x472A5A, // inven_unwield_ + 0x495F0B // partyMemberCopyLevelInfo_ + }); + HookCalls(CorrectFidForRemovedItemHook, { + 0x45680C, // op_rm_obj_from_inven_ + 0x45C4EA // op_move_obj_inven_to_obj_ + }); } void InitInventoryHookScripts() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index c01f660d..c0ebbb68 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -345,7 +345,7 @@ static int __fastcall SuperStimFix2(fo::GameObject* item, fo::GameObject* target return 0; } - DWORD curr_hp, max_hp; + long curr_hp, max_hp; curr_hp = fo::func::stat_level(target, fo::STAT_current_hp); max_hp = fo::func::stat_level(target, fo::STAT_max_hit_points); if (curr_hp < max_hp) return 0; @@ -646,7 +646,7 @@ end: // Differences from vanilla: // - doesn't use art_vault_guy_num as default art, uses current critter FID instead // - invokes onAdjustFid delegate that allows to hook into FID calculation -DWORD __stdcall adjust_fid_replacement2() { +DWORD __stdcall Inventory::adjust_fid_replacement() { using namespace fo; DWORD fid; @@ -693,11 +693,11 @@ DWORD __stdcall adjust_fid_replacement2() { return var::i_fid; } -static void __declspec(naked) adjust_fid_replacement() { +static void __declspec(naked) adjust_fid_hack_replacement() { __asm { push ecx; push edx; - call adjust_fid_replacement2; // return fid + call Inventory::adjust_fid_replacement; // return fid pop edx; pop ecx; retn; @@ -740,7 +740,7 @@ void Inventory::init() { OnKeyPressed() += InventoryKeyPressedHook; LoadGameHook::OnGameReset() += InventoryReset; - MakeJump(fo::funcoffs::adjust_fid_, adjust_fid_replacement); + MakeJump(fo::funcoffs::adjust_fid_, adjust_fid_hack_replacement); sizeLimitMode = GetConfigInt("Misc", "CritterInvSizeLimitMode", 0); if (sizeLimitMode > 0 && sizeLimitMode <= 7) { diff --git a/sfall/Modules/Inventory.h b/sfall/Modules/Inventory.h index ca89fd97..c7ce19e1 100644 --- a/sfall/Modules/Inventory.h +++ b/sfall/Modules/Inventory.h @@ -31,6 +31,8 @@ public: // Called after game calculated dude FID for displaying on inventory screen static Delegate& OnAdjustFid(); + + static DWORD __stdcall adjust_fid_replacement(); }; void _stdcall SetInvenApCost(int cost); diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index aa1b6489..92865b62 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -176,7 +176,7 @@ static void __declspec(naked) SaveGame_hook() { call CombatSaveTest; test eax, eax; pop edx; // recall Mode parameter (pop eax) - jz end; + jz end; push edx; _InLoop2(1, SAVEGAME); pop eax;