From 584e0266242854d8cdc1dff04cb479d22934bf45 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 14 Nov 2023 21:48:36 +0800 Subject: [PATCH] Fixed create_object_sid when passing 0 as the script index number * would result in a crash. Now it allows creating an object with no script (different from -1, which just doesn't touch default script). --- sfall/Modules/BugFixes.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 0d87d87c..2b7b76c9 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -3216,6 +3216,23 @@ noObject: } } +static void __declspec(naked) op_create_object_sid_hack1() { + static const DWORD create_object_sid_Ret = 0x4551C0; + __asm { + cmp dword ptr [esp + 0x50 - 0x40 + 4], 0; // scriptIndex + jne end; + mov ebx, [esp + 0x50 - 0x20 + 4]; // createObj + mov eax, [ebx + scriptId]; + call fo::funcoffs::scr_remove_; + mov dword ptr [ebx + scriptId], -1; + add esp, 4; + jmp create_object_sid_Ret; +end: + cmp dword ptr [esp + 0x50 - 0x40 + 4], -1; // overwritten engine code + retn; + } +} + // returns 0 (allows adding) if the critter has the "barter" flag set or its body type is "biped" static long __fastcall CheckBarterAndBodyType(fo::GameObject* critter) { fo::Proto* proto; @@ -4025,6 +4042,8 @@ void BugFixes::init() { MakeCall(0x4551C0, op_create_object_sid_hack, 1); // Fix the error handling in create_object_sid function to prevent a crash when the proto is missing SafeWrite8(0x45507B, 0x51); // jz 0x4550CD + // Fix to allow creating an object with no script correctly when passing 0 as the script index number (also prevent a crash) + MakeCall(0x4550C8, op_create_object_sid_hack1); // Fix to prevent the main menu music from stopping when entering the load game screen BlockCall(0x480B25);