From 520f939afae3cb3c74b7df9a1c384c11fd8f4334 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 18 May 2019 11:09:04 +0800 Subject: [PATCH] Improved the fix in previous commit. * now ignoring the inv capacity only happens in combat for preventing AI inf loop. The vanilla behavior still applies outside of combat. * added a correct message for NPC not being able to pick up an item. --- artifacts/config_files/Translations.ini | 1 + sfall/BugFixes.cpp | 36 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/artifacts/config_files/Translations.ini b/artifacts/config_files/Translations.ini index 756ec925..6471fc09 100644 --- a/artifacts/config_files/Translations.ini +++ b/artifacts/config_files/Translations.ini @@ -10,6 +10,7 @@ SaveSfallDataFail=ERROR saving extended savegame information! Check if other pro PartyLvlMsg=Lvl: PartyACMsg=AC: PartyAddictMsg=Addict +NPCPickupFail=%s cannot pick up the item. [AppearanceMod] RaceText=Race diff --git a/sfall/BugFixes.cpp b/sfall/BugFixes.cpp index 87f91103..c12bf13c 100644 --- a/sfall/BugFixes.cpp +++ b/sfall/BugFixes.cpp @@ -2057,14 +2057,41 @@ bad: static void __declspec(naked) obj_pickup_hook() { __asm { - cmp dword ptr ds:[_obj_dude], edi; + cmp edi, dword ptr ds:[_obj_dude]; je dude; + test byte ptr ds:[_combat_state], 1; // in combat? + jz dude; jmp item_add_force_; dude: jmp item_add_mult_; } } +static char pickupMessageBuf[65] = {0}; +static const char* __fastcall GetPickupMessage(const char* name) { + if (pickupMessageBuf[0] == 0) { + GetPrivateProfileString("sfall", "NPCPickupFail", "%s cannot pick up the item.", pickupMessageBuf, 64, translationIni); + } + sprintf(textBuf, pickupMessageBuf, name); + return textBuf; +} + +static void __declspec(naked) obj_pickup_hook_message() { + __asm { + cmp edi, dword ptr ds:[_obj_dude]; + je dude; + mov eax, edi; + call critter_name_; + mov ecx, eax; + call GetPickupMessage; + mov [esp + 0x34 - 0x28 + 4], eax; + mov eax, 1; + retn; +dude: + jmp message_search_; + } +} + void BugFixesInit() { #ifndef NDEBUG @@ -2081,7 +2108,7 @@ void BugFixesInit() SafeWrite16(0x46A566, 0x04DB); SafeWrite16(0x46A4E7, 0x04DB); - //if(GetPrivateProfileIntA("Misc", "SpecialUnarmedAttacksFix", 1, ini)) { + //if (GetPrivateProfileIntA("Misc", "SpecialUnarmedAttacksFix", 1, ini)) { dlog("Applying Special Unarmed Attacks fix.", DL_INIT); MakeJump(0x42394D, UnarmedAttacksFix); dlogr(" Done", DL_INIT); @@ -2609,7 +2636,8 @@ void BugFixesInit() // Fix the argument value of dialogue_reaction function HookCall(0x456FFA, op_dialogue_reaction_hook); - // Fix for the incorrect message being displayed and NPC stuck in a loop in combat when the NPC cannot pick up an item - // due to not enough space in the inventory + // Fix for NPC stuck in a loop of picking up items in combat and the incorrect message being displayed when the NPC cannot pick + // up an item due to not enough space in the inventory HookCall(0x49B6E7, obj_pickup_hook); + HookCall(0x49B71C, obj_pickup_hook_message); }