Skip to content

Commit bb1bcc4

Browse files
committed
Merge branch 'master' of https://github.com/sfall-team/sfall into better-docs
2 parents 741a4dd + df027f4 commit bb1bcc4

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

sfall/Modules/Elevators.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static long __fastcall Check4EscKey(long type, long map) {
141141
return i; // exit index
142142
}
143143
}
144-
return 0;
144+
return -1; // fail-safe
145145
}
146146

147147
static __declspec(naked) void elevator_select_hack() {
@@ -162,9 +162,25 @@ static __declspec(naked) void elevator_select_hack() {
162162
}
163163
}
164164

165+
static __declspec(naked) void scripts_check_state_hook() {
166+
__asm {
167+
call fo::funcoffs::elevator_select_;
168+
cmp eax, -1;
169+
je end;
170+
cmp dword ptr [esp + 0x30 - 0x20 + 4], -1; // tile (-1 - invalid)
171+
jne end;
172+
mov eax, -1; // force error
173+
end:
174+
retn;
175+
}
176+
}
177+
165178
void Elevators::init() {
166-
// Allow pressing the Esc key to close the elevator panel
179+
// Allow pressing the Esc key to cancel the elevator selection
167180
MakeCall(0x43F113, elevator_select_hack, 2);
181+
// Additional error handling
182+
SafeWrite32(0x43F2D7, 0x78DB8590); // cmp ebx, 27; jz > test ebx, ebx; js
183+
HookCalls(scripts_check_state_hook, {0x4A40C9, 0x4A43EA});
168184

169185
auto elevPath = IniReader::GetConfigString("Misc", "ElevatorsFile", "");
170186
if (!elevPath.empty()) {

0 commit comments

Comments
 (0)