@@ -33,20 +33,18 @@ static fo::ElevatorExit elevatorExits[elevatorCount][exitsPerElevator] = {0}; //
3333static fo::ElevatorFrms elevatorsFrms[elevatorCount] = {0 }; // _intotal
3434static DWORD elevatorsBtnCount[elevatorCount] = {0 }; // _btncount
3535
36+ static bool Inited = false ;
37+
3638static __declspec (naked) void GetMenuHook() {
3739 __asm {
38- lea edx, elevatorType;
39- shl eax, 2 ;
40- mov eax, [edx + eax];
40+ mov eax, elevatorType[eax * 4 ];
4141 jmp fo::funcoffs::elevator_start_;
4242 }
4343}
4444
4545static __declspec (naked) void CheckHotKeysHook() {
4646 __asm {
47- lea ebx, elevatorType;
48- shl eax, 2 ;
49- mov eax, [ebx + eax];
47+ mov eax, elevatorType[eax * 4 ];
5048 cmp eax, vanillaElevatorCount;
5149 jge skip; // skip hotkeys data (prevent array out of bounds error)
5250 call fo::funcoffs::Check4Keys_;
@@ -60,37 +58,16 @@ static __declspec(naked) void CheckHotKeysHook() {
6058/*
6159static __declspec(naked) void UnknownHook2() {
6260 __asm {
63- lea edx, elevatorType;
64- shl eax, 2;
65- mov eax, [edx + eax];
61+ mov eax, elevatorType[eax * 4];
6662 jmp fo::funcoffs::elevator_end_;
6763 }
6864}
6965*/
7066
71- static __declspec (naked) void GetNumButtonsHook1() {
72- __asm {
73- lea esi, elevatorType;
74- mov eax, [esi + edi * 4 ];
75- mov eax, [elevatorsBtnCount + eax * 4 ];
76- retn;
77- }
78- }
79-
80- static __declspec (naked) void GetNumButtonsHook2() {
81- __asm {
82- lea edx, elevatorType;
83- mov eax, [edx + edi * 4 ];
84- mov eax, [elevatorsBtnCount + eax * 4 ];
85- retn;
86- }
87- }
88-
89- static __declspec (naked) void GetNumButtonsHook3() {
67+ static __declspec (naked) void GetNumButtonsHack() {
9068 __asm {
91- lea eax, elevatorType;
92- mov eax, [eax + edi * 4 ];
93- mov eax, [elevatorsBtnCount + eax * 4 ];
69+ mov eax, elevatorType[edi * 4 ];
70+ mov eax, elevatorsBtnCount[eax * 4 ];
9471 retn;
9572 }
9673}
@@ -149,12 +126,46 @@ static void ElevatorsInit() {
149126
150127 // _btncnt
151128 SafeWriteBatch<DWORD >((DWORD )elevatorsBtnCount, {0x43F65E , 0x43F6BB });
152- MakeCall (0x43F05D , GetNumButtonsHook1, 2 );
153- MakeCall (0x43F184 , GetNumButtonsHook2, 2 );
154- MakeCall (0x43F1E4 , GetNumButtonsHook3, 2 );
129+ MakeCall (0x43F05D , GetNumButtonsHack, 2 );
130+ MakeCall (0x43F184 , GetNumButtonsHack, 2 );
131+ MakeCall (0x43F1E4 , GetNumButtonsHack, 2 );
132+
133+ Inited = true ;
134+ }
135+
136+ static long __fastcall Check4EscKey (long type, long map) {
137+ fo::ElevatorExit* exits = (Inited) ? elevatorExits[type] : fo::var::retvals[type];
138+ long elev = fo::var::map_elevation;
139+ long i = 0 ;
140+ do {
141+ if (exits[i].id == map && exits[i].elevation == elev) break ;
142+ } while (++i < exitsPerElevator);
143+
144+ return i; // exit index
145+ }
146+
147+ static __declspec (naked) void elevator_select_hack() {
148+ static const DWORD elevator_select_Ret = 0x43F2CC ;
149+ __asm {
150+ cmp eax, VK_ESCAPE ;
151+ je escKey;
152+ retn;
153+ escKey:
154+ // push ecx;
155+ mov edx, [ebp]; // map number
156+ mov ecx, edi; // elevator type
157+ call Check4EscKey;
158+ // pop ecx;
159+ mov [esp + 0x30 - 0x14 + 4 ], eax;
160+ add esp, 4 ;
161+ jmp elevator_select_Ret;
162+ }
155163}
156164
157165void Elevators::init () {
166+ // Allow pressing the Esc key to close the elevator panel
167+ MakeCall (0x43F113 , elevator_select_hack, 2 );
168+
158169 auto elevPath = IniReader::GetConfigString (" Misc" , " ElevatorsFile" , " " );
159170 if (!elevPath.empty ()) {
160171 const char * elevFile = elevPath.insert (0 , " .\\ " ).c_str ();
0 commit comments