Added support for closing the game by Alt+F4 (#457)

This commit is contained in:
NovaRain
2023-03-15 12:09:52 +08:00
parent c4efe78661
commit 254473cf1c
2 changed files with 38 additions and 4 deletions
+1
View File
@@ -139,6 +139,7 @@
#define FO_VAR_GNW95_hDDrawLib 0x51E44C
#define FO_VAR_GNW95_hwnd 0x51E434 // main hwnd window
#define FO_VAR_GNW95_isActive 0x51E444
#define FO_VAR_GNW95_keyboardHandle 0x6AC758
#define FO_VAR_GNW95_repeat_delay 0x51E240
#define FO_VAR_GNW95_repeat_rate 0x51E23C
#define FO_VAR_GNWWin 0x5195B8
+37 -4
View File
@@ -53,13 +53,11 @@ void __stdcall WinProc::WaitMessageWindow() {
MessageWindow();
}
static int __stdcall WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static long __stdcall WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
RECT rect;
//POINT point;
switch (msg) {
//case WM_CREATE:
// break;
case WM_DESTROY:
__asm xor eax, eax;
__asm call fo::funcoffs::exit_;
@@ -149,7 +147,39 @@ static int __stdcall WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
}
static long __stdcall main_menu_loop_hook() {
return (!reqGameQuit) ? fo::func::get_input() : 27; // ESC code
return (!reqGameQuit) ? fo::func::get_input() : VK_ESCAPE;
}
static long __stdcall GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode < 0) {
goto callNext;
}
switch (wParam) {
case VK_DELETE:
if (!(lParam & 0x20000000)) {
break;
}
case VK_ESCAPE:
if (GetAsyncKeyState(VK_CONTROL) < 0) {
return 0;
}
break;
case VK_TAB:
if ((lParam & 0x20000000)) {
return 0;
}
break;
case VK_NUMLOCK:
case VK_CAPITAL:
case VK_SCROLL:
case VK_F4:
callNext:
return CallNextHookEx((HHOOK)fo::var::getInt(FO_VAR_GNW95_keyboardHandle), nCode, wParam, lParam);
default:
break;
}
return 1;
}
void WinProc::SetWindowProc() {
@@ -299,6 +329,9 @@ void WinProc::init() {
// Replace the engine WindowProc_ with sfall implementation
MakeJump(0x4DE9FC, WindowProc); // WindowProc_
// Replace the engine GNW95_keyboard_hook_ with sfall implementation
SafeWrite32(0x4C9BD9, (DWORD)&GNW95_keyboard_hook); // GNW95_hook_keyboard_
HookCall(0x481B2A, main_menu_loop_hook);
}