From df027f4423a9e534cdc672edc74779dfac9f261b Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 17 Jul 2026 08:52:00 +0800 Subject: [PATCH] Added extra error handling for canceling elevator selection (ref. fallout2-ce/fallout2-ce#546) * Usually it shouldn't happen, just in case someone's messing with their elevators.ini and caused a map/level mismatch to their savegames. --- sfall/Modules/Elevators.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sfall/Modules/Elevators.cpp b/sfall/Modules/Elevators.cpp index 61a56862..da9e0b74 100644 --- a/sfall/Modules/Elevators.cpp +++ b/sfall/Modules/Elevators.cpp @@ -141,7 +141,7 @@ static long __fastcall Check4EscKey(long type, long map) { return i; // exit index } } - return 0; + return -1; // fail-safe } static __declspec(naked) void elevator_select_hack() { @@ -162,9 +162,25 @@ escKey: } } +static __declspec(naked) void scripts_check_state_hook() { + __asm { + call fo::funcoffs::elevator_select_; + cmp eax, -1; + je end; + cmp dword ptr [esp + 0x30 - 0x20 + 4], -1; // tile (-1 - invalid) + jne end; + mov eax, -1; // force error +end: + retn; + } +} + void Elevators::init() { - // Allow pressing the Esc key to close the elevator panel + // Allow pressing the Esc key to cancel the elevator selection MakeCall(0x43F113, elevator_select_hack, 2); + // Additional error handling + SafeWrite32(0x43F2D7, 0x78DB8590); // cmp ebx, 27; jz > test ebx, ebx; js + HookCalls(scripts_check_state_hook, {0x4A40C9, 0x4A43EA}); auto elevPath = IniReader::GetConfigString("Misc", "ElevatorsFile", ""); if (!elevPath.empty()) {