From 2985c2866b89288dea5c223ddfb0709a3e2cb2db Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 4 May 2021 12:39:07 +0800 Subject: [PATCH] Added additional code to "duplicate obj_dude script data" fix --- artifacts/ddraw.ini | 7 ++++--- sfall/Modules/BugFixes.cpp | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index b3768725..95ecc5b0 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -599,7 +599,7 @@ ObjCanSeeObj_ShootThru_Fix=0 ;Set to 1 to fix the broken obj_can_hear_obj script function ObjCanHearObjFix=0 -;Set to 1 to enable the mood argument of start_gdialog script function to be available for talking heads +;Set to 1 to enable the mood argument of start_gdialog script function 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 @@ -609,8 +609,9 @@ StartGDialogFix=0 ;num_attacks - the number of free action points on the first turn only AttackComplexFix=0 -;Set to 1 to enable the create_object_sid script function to run the 'start' script procedure when creating an object -;It is recommended to enable this option only if you are developing a new project (TC), otherwise it may affect some existing game scripts +;Set to 1 to make the create_object_sid script function run the 'start' procedure of attached script upon object creation +;By default, the 'start' procedure of attached script is executed after the current script procedure is finished +;Note that enabling this option may cause unexpected results with some existing game scripts CreateObjectSidFix=0 ;Set to 1 to fix the issue with the division operator treating negative integers as unsigned diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index da971ec4..6995c7b3 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2297,7 +2297,16 @@ skip: } } -static DWORD dudeScriptID; +static void __declspec(naked) map_load_file_hook() { + __asm { + mov eax, 0x04004650; // dude script ID + call fo::funcoffs::scr_remove_; + jmp fo::funcoffs::partyMemberRecoverLoad_; + } +} + +static DWORD dudeScriptID; // usually equal to 0x04004650 + static void __declspec(naked) obj_load_dude_hook0() { __asm { mov eax, ds:[FO_VAR_obj_dude]; @@ -2309,8 +2318,10 @@ static void __declspec(naked) obj_load_dude_hook0() { static void __declspec(naked) obj_load_dude_hook1() { __asm { - mov ebx, dudeScriptID; - mov [eax + scriptId], ebx; + call fo::funcoffs::scr_clear_dude_script_; + mov ebx, ds:[FO_VAR_obj_dude]; + mov eax, dudeScriptID; + mov [ebx + scriptId], eax; retn; } } @@ -3648,6 +3659,7 @@ void BugFixes::init() HookCall(0x499240, PrintAMList_hook); // Fix for a duplicate obj_dude script being created when loading a saved game + HookCall(0x48306E, map_load_file_hook); // removes the redundant saved dude script data from the scripts block HookCall(0x48D63E, obj_load_dude_hook0); HookCall(0x48D666, obj_load_dude_hook1); BlockCall(0x48D675);