From 6e5b41c958fb906caea0f210b050d291183c0fdb Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 28 Oct 2024 19:27:26 +0100 Subject: [PATCH] SA: Fix focus issues with the resolution selection dialog Now requests focus the proper way from WM_INITDIALOG, instead of a manual SetFocus call. Fixes #49 --- SilentPatchSA/SilentPatchSA.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 4a629b5..76f01a9 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2730,14 +2730,15 @@ namespace NewResolutionSelectionDialog // The game inits the selected resolution weirdly, and corrects it in the IDOK handler // so let's invoke it manually (bleh) data->lpDialogFunc(window, WM_COMMAND, IDOK, 0); - return TRUE; + return FALSE; } HMODULE hGameModule = GetModuleHandle(nullptr); SendMessage(window, WM_SETICON, ICON_SMALL, reinterpret_cast(LoadIcon(hGameModule, MAKEINTRESOURCE(100)))); CreateNewButtonTooltip(hGameModule, window); - // Return TRUE instead of FALSE on init, we want keyboard focus + // Return TRUE instead of FALSE on init, as we removed a manual SetFocus from the init function + // and we want to rely on Windows to give us focus. return TRUE; } @@ -2820,6 +2821,12 @@ namespace NewResolutionSelectionDialog return result; } static auto* const pDialogBoxParamA_New = &DialogBoxParamA_New; + + static HWND WINAPI SetFocus_NOP(HWND) + { + return nullptr; + } + static auto* const pSetFocus_NOP = &SetFocus_NOP; } @@ -6164,6 +6171,7 @@ void Patch_SA_10(HINSTANCE hInstance) orgGetDocumentsPath = AddressByRegion_10(0x744FB0); Patch(AddressByRegion_10(0x746241 + 2), &pDialogBoxParamA_New); + Patch(AddressByRegion_10(0x745DB3 + 2), &pSetFocus_NOP); InterceptCall(AddressByRegion_10(0x7461D8), orgRwEngineGetSubSystemInfo, RwEngineGetSubSystemInfo_GetFriendlyNames); InterceptCall(AddressByRegion_10(0x7461ED), orgRwEngineGetCurrentSubSystem, RwEngineGetCurrentSubSystem_FromSettings); @@ -8326,6 +8334,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) return get_pattern("53 FF 15 ? ? ? ? 85 C0", 1 + 2); } }(); + auto setFocus = get_pattern("53 FF 15 ? ? ? ? 5F", 1 + 2); auto rRwEngineGetSubSystemInfo = get_pattern("E8 ? ? ? ? 46 83 C4 08 83 C7 50"); auto rwEngineGetCurrentSubSystem = get_pattern("7C EA E8 ? ? ? ? A3", 2); @@ -8337,6 +8346,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) orgGetDocumentsPath = static_cast(get_pattern( "8D 45 FC 50 68 19 00 02 00", -6 )); Patch(dialogBoxParam, &pDialogBoxParamA_New); + Patch(setFocus, &pSetFocus_NOP); InterceptCall(rRwEngineGetSubSystemInfo, orgRwEngineGetSubSystemInfo, RwEngineGetSubSystemInfo_GetFriendlyNames); InterceptCall(rwEngineGetCurrentSubSystem, orgRwEngineGetCurrentSubSystem, RwEngineGetCurrentSubSystem_FromSettings);