From 569bde5fabfcc0f6a227356368386653e23d8257 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 2 Sep 2021 11:23:24 +0800 Subject: [PATCH] Code changes to the previous commit Changed HOOK_CANUSEWEAPON to run for both the player and NPCs. Updated gl_npcarmor script. --- artifacts/mods/gl_npcarmor.int | Bin 5200 -> 5284 bytes artifacts/mods/gl_npcarmor.ssl | 6 +-- artifacts/scripting/headers/sfall.h | 8 +-- artifacts/scripting/hookscripts.md | 9 ++-- sfall/FalloutEngine/FunctionOffsets_def.h | 1 + sfall/Modules/HookScripts/CombatHs.cpp | 29 +++++++++-- sfall/Modules/Inventory.cpp | 24 --------- sfall/Modules/SubModules/CombatBlock.cpp | 58 ++++++++++++++++++++++ 8 files changed, 96 insertions(+), 39 deletions(-) diff --git a/artifacts/mods/gl_npcarmor.int b/artifacts/mods/gl_npcarmor.int index 23bfdaa7d4c76d42f598945b1571029563379213..6bc7c7caee39397bcfe11c4088fdcc9209a29ddc 100644 GIT binary patch delta 1261 zcmcbhu|!j#f$0Dv0|SFl122eXo-|Rwu>KGO1V}(A7|9G1H-d>kXx0J<&Cmm-p%m*M z1_lOZ1_p*jPyr~#9s?EM0TqB!oLLME42%p6Q4D9GB2bF!4V3W+N<%50FHpueC=I3f z;vfu0J_rpX`Exc)G0HPChD^3%>J|`4Pc4bhPs&P7E{RV`EJ>VvnCTT`&g6B>p^Ooe zSy+5Ut3V;bz|dgSu)o2$K_A3pwV0g7A}?qGVlyx{7(ql?&P|@iVr(q|7G-KMI>7k< z|Ns9D#tqUS5mvqii3ZmO{RSxzkAbPdsHp_ZVn8yLh1H%>Z1M#Tk;xZWMJDI4@{2x! zssY(<0L!{aI%5bvVi=;z`(%P zVANy|^AE?T1__XFCV zmIMWx0f@!bHaU({QnC%iW?*R$0@I*C0S6lw!{iB^N=#gOlc%vLPkznE&&1U>`30vt z5ZRm`y&zEz6iP`4zV|(lgXQSwYd1)pzeDz`5A9ueF&;CAkF+>*Mia`h{wPPix0jFDCvs<hGjQDyQvepkk#$zS+em;{3+R|zySo}2tfK#ohm1L8?Wp~)(O zE=)pBld}XH8TU+9M1yWrwgT=Ol<45wFS5g#8&UCV$|S0swC19*h70 delta 1088 zcmZ3Yc|k*S^$ z0|Nsy0|Ub%r~s5=H-n1rfC@khMz_ggEWV-{pa5WCXfSHn-(cLJ z58|<^O|D>(7gPhW85kRkAfhaLCg*XBPu|ZWBgqDqVQMfs!1(|F|Njlf4bmVHmOqof zuqZOBO%`LdXJ%<&nS6&wZE_teKjWOqi&*;wA0+*qTF4Wep|``i)P(hB7x8f@ofW$rilMj6suYc+Hr2KTY1k8^FZ- zU@{w@78ma)sQWHWw&DvEWk59sq?w;#@&Z0_#+u1H_~e-Q_DsG3p?-jQg~ 0) result = rets[0] ? true : false; + if (cRet > 0) result = (rets[0]) ? true : false; EndHook(); return result; // only 0 and 1 } -static void __declspec(naked) CanUseWeaponHook() { +static void __declspec(naked) AICanUseWeaponHook() { __asm { push ecx; push ebx; // hitMode @@ -645,7 +645,25 @@ static void __declspec(naked) CanUseWeaponHook() { call fo::funcoffs::ai_can_use_weapon_; push eax; // result call CanUseWeaponHook_Script; - and eax, 1; + //and eax, 1; + pop ecx; + retn; + } +} + +static void __declspec(naked) CanUseWeaponHook() { + __asm { + push ecx; + push edx; + push -1; // hitMode (indefinite) + push eax; // weapon + push ds:[FO_VAR_obj_dude]; // source + call fo::funcoffs::can_use_weapon_; // 1 - can't use + xor al, 1; + push eax; // result + call CanUseWeaponHook_Script; + xor al, 1; // invert + pop edx; pop ecx; retn; } @@ -750,11 +768,12 @@ void Inject_BestWeaponHook() { } void Inject_CanUseWeaponHook() { - HookCalls(CanUseWeaponHook, { + HookCalls(AICanUseWeaponHook, { 0x429A1B, // ai_search_inven_weap_ 0x429CF2, // ai_search_environ_ 0x429E1C // ai_pick_hit_mode_ }); + HookCalls(CanUseWeaponHook, { 0x45F05E, 0x45F1C1, 0x45F203, 0x45F36A }); // intface_update_items_ } void InitCombatHookScripts() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index d474b0fa..afed09e1 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -595,25 +595,6 @@ static void __declspec(naked) do_move_timer_hack() { } } -static void __declspec(naked) can_use_weapon_hook() { - static const DWORD can_use_weapon_Ret = 0x477F9F; - using namespace fo; - using namespace fo::Fields; - __asm { - call fo::funcoffs::item_get_type_; - cmp eax, item_type_weapon; - je checkFlag; - retn; // eax - type -checkFlag: - test dword ptr [edx + miscFlags], CantUse; - jnz cantUse; - retn; // eax - type -cantUse: - add esp, 4; - jmp can_use_weapon_Ret; - } -} - static int invenApCost, invenApCostDef; static char invenApQPReduction; @@ -758,11 +739,6 @@ void Inventory::init() { // Note: the flag is not checked for the metarule(METARULE_INVEN_UNWIELD_WHO, x) function HookCall(0x45B0CE, op_inven_unwield_hook); // with fix to update interface slot after unwielding HookCall(0x45693C, op_wield_obj_critter_hook); - - // Add an additional "Can't Use" flag to the misc flags of item objects (offset 0x0038) - // Misc Flags: - // 0x00000010 - Can't Use (makes the weapon object unusable in combat) - HookCall(0x477F4C, can_use_weapon_hook); } void Inventory::InvokeAdjustFid(long fid) { diff --git a/sfall/Modules/SubModules/CombatBlock.cpp b/sfall/Modules/SubModules/CombatBlock.cpp index bc69bb28..f3309de2 100644 --- a/sfall/Modules/SubModules/CombatBlock.cpp +++ b/sfall/Modules/SubModules/CombatBlock.cpp @@ -60,6 +60,57 @@ end: } } +static void __declspec(naked) ai_can_use_weapon_hack() { + using namespace fo; + using namespace Fields; + __asm { + test dword ptr [esi + miscFlags], CantUse; + jnz cantUse; + mov eax, [edi + damageFlags]; + retn; +cantUse: + mov al, 0xFF; + retn; + } +} + +static void __declspec(naked) can_use_weapon_hook() { + static const DWORD cant_use_weapon_Ret = 0x477F9F; + using namespace fo; + using namespace Fields; + __asm { + call fo::funcoffs::item_get_type_; + cmp eax, item_type_weapon; + je checkFlag; + retn; // eax - type +checkFlag: + test dword ptr [edx + miscFlags], CantUse; + jnz cantUse; + retn; // eax - type +cantUse: + add esp, 4; + jmp cant_use_weapon_Ret; + } +} + +// Note: in ai_try_attack_, the attacker will not be able to change unusable weapon, as it happens with crippled arms +static void __declspec(naked) combat_check_bad_shot_hack() { + static const DWORD combat_check_bad_shot_Ret = 0x42673A; + using namespace fo; + using namespace Fields; + __asm { + test dword ptr [ecx + miscFlags], CantUse; + jnz cantUse; + mov eax, [esi + damageFlags]; + test al, DAM_CRIP_ARM_LEFT; + retn; +cantUse: + mov eax, 4; // result same as TargetDead + add esp, 4; + jmp combat_check_bad_shot_Ret; + } +} + void __stdcall CombatBlock::SetBlockCombat(long toggle) { combatDisabled = toggle != 0; } @@ -67,6 +118,13 @@ void __stdcall CombatBlock::SetBlockCombat(long toggle) { void CombatBlock::init() { HookCall(0x45F626, intface_use_item_hook); // jnz hook HookCall(0x4432A6, game_handle_input_hook); + + // Add an additional "Can't Use" flag to the misc flags of item objects (offset 0x0038) + // Misc Flags: + // 0x00000010 - Can't Use (makes the weapon object unusable in combat) + HookCall(0x477F4C, can_use_weapon_hook); + MakeCall(0x4298F4, ai_can_use_weapon_hack); + MakeCall(0x426669, combat_check_bad_shot_hack); } }