From 7d0cdde356b02020a9905326f246abd3e3bb09cc Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Sat, 18 Nov 2023 17:43:33 +0700 Subject: [PATCH] Taskbar10: Fixed start menu/search flyout positioning code crashing Explorer when the display resolution changes --- ExplorerPatcher-L10N | 2 +- ExplorerPatcher/dllmain.c | 47 ++++++++++++++++++++++++++++++++++----- ExplorerPatcher/utility.h | 4 ++-- ep_gui/GUI.c | 8 ++++--- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/ExplorerPatcher-L10N b/ExplorerPatcher-L10N index 6012fe3..d09fb37 160000 --- a/ExplorerPatcher-L10N +++ b/ExplorerPatcher-L10N @@ -1 +1 @@ -Subproject commit 6012fe38c9220ebfc685e3a2f65ea6d8262717a5 +Subproject commit d09fb3722cda34c082a1bb2645224a85af1d27e8 diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 7ce4dc7..181f817 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -1079,6 +1079,13 @@ HRESULT WINAPI windowsudkshellcommon_SLGetWindowsInformationDWORDHook(PCWSTR pws return hr; } +static BOOL(*windowsudkshellcommon_TaskbarMultiMonIsEnabledFunc)(void* _this) = NULL; + +bool windowsudkshellcommon_TaskbarMultiMonIsEnabledHook(void* _this) +{ + return bOldTaskbar ? false : windowsudkshellcommon_TaskbarMultiMonIsEnabledFunc(_this); +} + #pragma endregion @@ -12264,14 +12271,42 @@ DWORD Inject(BOOL bIsExplorer) } HANDLE hWindowsudkShellcommon = LoadLibraryW(L"windowsudk.shellcommon.dll"); - HANDLE hSLC = LoadLibraryW(L"slc.dll"); - if (hWindowsudkShellcommon && hSLC) + if (hWindowsudkShellcommon) { - SLGetWindowsInformationDWORDFunc = GetProcAddress(hSLC, "SLGetWindowsInformationDWORD"); - - if (SLGetWindowsInformationDWORDFunc) + HANDLE hSLC = LoadLibraryW(L"slc.dll"); + if (hSLC) { - VnPatchDelayIAT(hWindowsudkShellcommon, "ext-ms-win-security-slc-l1-1-0.dll", "SLGetWindowsInformationDWORD", windowsudkshellcommon_SLGetWindowsInformationDWORDHook); + SLGetWindowsInformationDWORDFunc = GetProcAddress(hSLC, "SLGetWindowsInformationDWORD"); + + if (SLGetWindowsInformationDWORDFunc) + { + VnPatchDelayIAT(hWindowsudkShellcommon, "ext-ms-win-security-slc-l1-1-0.dll", "SLGetWindowsInformationDWORD", windowsudkshellcommon_SLGetWindowsInformationDWORDHook); + } + } + + MODULEINFO mi; + GetModuleInformation(GetCurrentProcess(), hWindowsudkShellcommon, &mi, sizeof(MODULEINFO)); + + // Fix ReportMonitorRemoved in UpdateStartMenuPositioning crashing, *for now* + // We can't use our RtlQueryFeatureConfiguration() hook because our function didn't get called with the feature ID + // TODO Need to check again later after this feature flag has been removed + // E8 ?? ?? ?? ?? 48 8B 7D FF 84 C0 74 1F 48 8D 4F 08 + PBYTE match = FindPattern( + hWindowsudkShellcommon, + mi.SizeOfImage, + "\xE8\x00\x00\x00\x00\x48\x8B\x7D\xFF\x84\xC0\x74\x1F\x48\x8D\x4F\x08", + "x????xxxxxxxxxxxx" + ); + if (match) + { + match += 5 + *(int*)(match + 1); + windowsudkshellcommon_TaskbarMultiMonIsEnabledFunc = match; + printf("wil::details::FeatureImpl<__WilFeatureTraits_Feature_Servicing_TaskbarMultiMon_38545217>::__private_IsEnabled() = %llX\n", match - (PBYTE)hWindowsudkShellcommon); + rv = funchook_prepare( + funchook, + (void**)&windowsudkshellcommon_TaskbarMultiMonIsEnabledFunc, + windowsudkshellcommon_TaskbarMultiMonIsEnabledHook + ); } printf("Setup windowsudk.shellcommon functions done\n"); diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index d77afbe..7f082ce 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -368,9 +368,9 @@ BOOL(WINAPI* SetWindowBand)(HWND hWnd, HWND hwndInsertAfter, DWORD dwBand); INT64(*SetWindowCompositionAttribute)(HWND, void*); -static void(*SetPreferredAppMode)(bool bAllowDark); +static void(*SetPreferredAppMode)(BOOL bAllowDark); -static void(*AllowDarkModeForWindow)(HWND hWnd, bool bAllowDark); +static void(*AllowDarkModeForWindow)(HWND hWnd, BOOL bAllowDark); static bool(*ShouldAppsUseDarkMode)(); diff --git a/ep_gui/GUI.c b/ep_gui/GUI.c index 4e37365..115914a 100644 --- a/ep_gui/GUI.c +++ b/ep_gui/GUI.c @@ -1002,7 +1002,9 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) DttOpts.crText = g_darkModeEnabled ? GUI_TEXTCOLOR_DARK : GUI_TEXTCOLOR; DWORD dwTextFlags = DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; RECT rcText; - DWORD dwMaxHeight = 0, dwMaxWidth = (DWORD)(480 * (_this->dpi.x / 96.0)); + DWORD dwMinWidthDp = 480; + if (!wcscmp(wszLanguage, L"nl-NL")) dwMinWidthDp = 600; + DWORD dwMaxHeight = 0, dwMaxWidth = (DWORD)(dwMinWidthDp * (_this->dpi.x / 96.0)); BOOL bTabOrderHit = FALSE; DWORD dwLeftPad = _this->padding.left + _this->sidebarWidth + _this->padding.right; DWORD dwInitialLeftPad = dwLeftPad; @@ -3841,11 +3843,11 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin ULONG ulNumLanguages = 0; LPCWSTR wszLanguagesBuffer = NULL; ULONG cchLanguagesBuffer = 0; - if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, NULL, &cchLanguagesBuffer)) + if (GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, NULL, &cchLanguagesBuffer)) { if (wszLanguagesBuffer = malloc(cchLanguagesBuffer * sizeof(WCHAR))) { - if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, wszLanguagesBuffer, &cchLanguagesBuffer)) + if (GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, wszLanguagesBuffer, &cchLanguagesBuffer)) { wcscpy_s(wszLanguage, MAX_PATH, wszLanguagesBuffer); bOk = TRUE;