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.
This commit is contained in:
NovaRain
2026-07-17 08:52:21 +08:00
parent e7337befb4
commit df027f4423
+18 -2
View File
@@ -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()) {