From f088c9bb70c31c265b19d71a754d306e2f1f2921 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 30 Sep 2018 16:24:15 +0800 Subject: [PATCH] Fixed the mood argument of start_gdialog function being ignored for talking heads. (from Crafty) Simplified the code of disabling losing unused perks. --- artifacts/ddraw.ini | 4 ++++ sfall/Modules/BugFixes.cpp | 28 ++++++++++++++++++++++++++++ sfall/Modules/Perks.cpp | 11 ++++------- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 86dbaf43..51bb1468 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -506,6 +506,10 @@ ObjCanSeeObj_ShootThru_Fix=0 ;Set to 1 to fix the broken obj_can_hear_obj script function ObjCanHearObjFix=0 +;Set to 1 to fix the mood argument of start_gdialog script function to be available for talking heads +;If the argument value is -1, the mood will be determined by the local variable 0 of the script (vanilla behavior) +StartGDialogFix=0 + ;Set to 1 to enable the balanced bullet distribution formula for burst attacks ComputeSprayMod=0 diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 82a62712..207ad023 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -1498,6 +1498,27 @@ fix: } } +static DWORD op_start_gdialog_ret = 0x456F4B; +static void __declspec(naked) op_start_gdialog_hack() { + __asm { + mov ebx, ds:[FO_VAR_dialog_target]; + mov ebx, [ebx + protoId]; + shr ebx, 0x18; + cmp ebx, OBJ_TYPE_CRITTER; + jz fix; + cmp edx, -1; + jz skip; + retn; +fix: + cmp eax, -1; + jnz skip; + retn; +skip: + add esp, 4; // Destroy the return address + jmp op_start_gdialog_ret; + } +} + void BugFixes::init() { @@ -1904,6 +1925,13 @@ void BugFixes::init() HookCall(0x429D7B, ai_retrieve_object_hook); MakeCall(0x472708, inven_find_id_hack); dlogr(" Done", DL_INIT); + + // Fix for the "mood" argument of start_gdialog function being ignored for talking heads + if (GetConfigInt("Misc", "StartGDialogFix", 0)) { + dlog("Applying start_gdialog argument fix.", DL_INIT); + MakeCall(0x456F03, op_start_gdialog_hack); + dlogr(" Done", DL_INIT); + } } } diff --git a/sfall/Modules/Perks.cpp b/sfall/Modules/Perks.cpp index 169c6d0e..10a3298a 100644 --- a/sfall/Modules/Perks.cpp +++ b/sfall/Modules/Perks.cpp @@ -728,17 +728,14 @@ static void PerkSetup() { } //perk_owed hooks - MakeCall(0x4AFB2F, LevelUpHook);//replaces 'mov edx, ds:[PlayerLevel] + MakeCall(0x4AFB2F, LevelUpHook); //replaces 'mov edx, ds:[PlayerLevel] SafeWrite8(0x4AFB34, 0x90); SafeWrite8(0x43C2EC, 0xEB); //skip the block of code which checks if the player has gained a perk (now handled in level up code) - SafeWrite8(0x43C362, 0xE8); //call sub_43401C, dec byte ptr ds:[0x570A29] - SafeWrite32(0x43C363, 0x43410C - 0x43C367); //replaces call sub_43401C, mov byte ptr ds:[0x570A29], 0 - SafeWrite8(0x43C367, 0x3E); - SafeWrite16(0x43C368, 0x0DFE); - SafeWrite32(0x43C36A, 0x00570A29); - SafeWrite8(0x43C36e, 0x90); + //Disable losing unused perks + SafeWrite16(0x43C369, 0x0DFE); // dec byte ptr ds:_free_perk + SafeWrite8(0x43C370, 0xB1); // jmp 0x43C322 } static int _stdcall stat_get_base_direct(DWORD statID) {