Added missing return values for HOOK_INVENWIELD.

Updated NPC armor appearance mod.
This commit is contained in:
NovaRain
2018-12-25 09:28:30 +08:00
parent 9813d4ae74
commit 6cce07991e
6 changed files with 41 additions and 15 deletions
Binary file not shown.
+16 -5
View File
@@ -22,7 +22,9 @@ variable
modIni := "npcarmor.ini", modIni := "npcarmor.ini",
defaultFids, defaultFids,
armorPidMap, // maps armor PID to it's "type" - leather armor, metal, power armor, etc. 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 procedure check_armor_change(variable critter, variable item, variable isWorn) begin
variable npc, armorType, fid; variable npc, armorType, fid;
@@ -55,6 +57,8 @@ procedure check_weapon_change(variable critter, variable item, variable isWield)
end end
return 0; return 0;
end end
end else begin
unWieldWeapon := obj_pid(item);
end end
end end
return -1; return -1;
@@ -65,15 +69,20 @@ procedure search_alt_weapon(variable critter) begin
obj := inven_ptr(critter, 0); obj := inven_ptr(critter, 0);
while (obj) do begin while (obj) do begin
if (obj_item_subtype(obj) == item_type_weapon) then begin if (obj_item_subtype(obj) == item_type_weapon) then begin
res := check_weapon_change(critter, obj, 1); if (unWieldWeapon == 0 or unWieldWeapon != obj_pid(obj)) then begin
if (res == -1) then begin res := check_weapon_change(critter, obj, 1);
wield_obj_critter(critter, obj); if (res == -1) then begin
break; altWeapon := obj;
wield_obj_critter(critter, obj);
altWeapon := 0;
break;
end
end end
end end
i++; i++;
obj := inven_ptr(critter, i); obj := inven_ptr(critter, i);
end end
unWieldWeapon := 0;
end end
// for NPCs when they change armor/weapon themselves // for NPCs when they change armor/weapon themselves
@@ -89,9 +98,11 @@ procedure invenwield_handler begin
if (fid != -1) then begin if (fid != -1) then begin
art_change_fid_num(critter, fid); art_change_fid_num(critter, fid);
end end
return;
end end
if (critter and item and slot == INVEN_TYPE_RIGHT_HAND) then begin if (critter and item and slot == INVEN_TYPE_RIGHT_HAND) then begin
if (altWeapon == item) then return;
canWield := check_weapon_change(critter, item, isWorn); canWield := check_weapon_change(critter, item, isWorn);
set_sfall_return(canWield); set_sfall_return(canWield);
if (canWield != -1) then begin if (canWield != -1) then begin
+17 -4
View File
@@ -288,7 +288,7 @@ static bool InvenWieldHook_Script(int flag) {
bool result = (cRet == 0 || rets[0] == -1); bool result = (cRet == 0 || rets[0] == -1);
EndHook(); EndHook();
return result; return result; // True - use engine handler
} }
static void _declspec(naked) InvenWieldFuncHook() { static void _declspec(naked) InvenWieldFuncHook() {
@@ -314,6 +314,7 @@ static void _declspec(naked) InvenWieldFuncHook() {
jz skip; jz skip;
jmp funcoffs::invenWieldFunc_; jmp funcoffs::invenWieldFunc_;
skip: skip:
mov eax, -1;
retn; retn;
} }
} }
@@ -341,6 +342,7 @@ static void _declspec(naked) InvenUnwieldFuncHook() {
jz skip; jz skip;
jmp fo::funcoffs::invenUnwieldFunc_; jmp fo::funcoffs::invenUnwieldFunc_;
skip: skip:
mov eax, -1;
retn; retn;
} }
} }
@@ -371,6 +373,7 @@ static void _declspec(naked) CorrectFidForRemovedItemHook() {
jz skip; jz skip;
jmp fo::funcoffs::correctFidForRemovedItem_; jmp fo::funcoffs::correctFidForRemovedItem_;
skip: skip:
mov eax, -1;
retn; retn;
} }
} }
@@ -419,9 +422,19 @@ void Inject_InventoryMoveHook() {
} }
void Inject_InvenWieldHook() { void Inject_InvenWieldHook() {
HookCalls(InvenWieldFuncHook, { 0x47275E, 0x495FDF }); HookCalls(InvenWieldFuncHook, {
HookCalls(InvenUnwieldFuncHook, { 0x45967D, 0x472A5A, 0x495F0B }); 0x47275E, // inven_wield_
HookCalls(CorrectFidForRemovedItemHook, { 0x45680C, 0x45C4EA }); 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() { void InitInventoryHookScripts() {
+5 -5
View File
@@ -345,7 +345,7 @@ static int __fastcall SuperStimFix2(fo::GameObject* item, fo::GameObject* target
return 0; return 0;
} }
DWORD curr_hp, max_hp; long curr_hp, max_hp;
curr_hp = fo::func::stat_level(target, fo::STAT_current_hp); curr_hp = fo::func::stat_level(target, fo::STAT_current_hp);
max_hp = fo::func::stat_level(target, fo::STAT_max_hit_points); max_hp = fo::func::stat_level(target, fo::STAT_max_hit_points);
if (curr_hp < max_hp) return 0; if (curr_hp < max_hp) return 0;
@@ -646,7 +646,7 @@ end:
// Differences from vanilla: // Differences from vanilla:
// - doesn't use art_vault_guy_num as default art, uses current critter FID instead // - 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 // - invokes onAdjustFid delegate that allows to hook into FID calculation
DWORD __stdcall adjust_fid_replacement2() { DWORD __stdcall Inventory::adjust_fid_replacement() {
using namespace fo; using namespace fo;
DWORD fid; DWORD fid;
@@ -693,11 +693,11 @@ DWORD __stdcall adjust_fid_replacement2() {
return var::i_fid; return var::i_fid;
} }
static void __declspec(naked) adjust_fid_replacement() { static void __declspec(naked) adjust_fid_hack_replacement() {
__asm { __asm {
push ecx; push ecx;
push edx; push edx;
call adjust_fid_replacement2; // return fid call Inventory::adjust_fid_replacement; // return fid
pop edx; pop edx;
pop ecx; pop ecx;
retn; retn;
@@ -740,7 +740,7 @@ void Inventory::init() {
OnKeyPressed() += InventoryKeyPressedHook; OnKeyPressed() += InventoryKeyPressedHook;
LoadGameHook::OnGameReset() += InventoryReset; 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); sizeLimitMode = GetConfigInt("Misc", "CritterInvSizeLimitMode", 0);
if (sizeLimitMode > 0 && sizeLimitMode <= 7) { if (sizeLimitMode > 0 && sizeLimitMode <= 7) {
+2
View File
@@ -31,6 +31,8 @@ public:
// Called after game calculated dude FID for displaying on inventory screen // Called after game calculated dude FID for displaying on inventory screen
static Delegate<DWORD>& OnAdjustFid(); static Delegate<DWORD>& OnAdjustFid();
static DWORD __stdcall adjust_fid_replacement();
}; };
void _stdcall SetInvenApCost(int cost); void _stdcall SetInvenApCost(int cost);
+1 -1
View File
@@ -176,7 +176,7 @@ static void __declspec(naked) SaveGame_hook() {
call CombatSaveTest; call CombatSaveTest;
test eax, eax; test eax, eax;
pop edx; // recall Mode parameter (pop eax) pop edx; // recall Mode parameter (pop eax)
jz end; jz end;
push edx; push edx;
_InLoop2(1, SAVEGAME); _InLoop2(1, SAVEGAME);
pop eax; pop eax;