From 9e2d44ef73edbf85e86f5605ae0ad90f7a64a4b4 Mon Sep 17 00:00:00 2001 From: Michael Maltsev <4129781+m417z@users.noreply.github.com> Date: Sat, 19 Oct 2024 02:56:28 +0300 Subject: [PATCH] Classic Explorer navigation bar v1.0.5 * Fixed incorrect height if the `FileExplorerTabLineFix` (51960011) Windows flag is set. --- mods/explorer-frame-classic.wh.cpp | 52 +++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/mods/explorer-frame-classic.wh.cpp b/mods/explorer-frame-classic.wh.cpp index 156caa62e..d8e7c3647 100644 --- a/mods/explorer-frame-classic.wh.cpp +++ b/mods/explorer-frame-classic.wh.cpp @@ -2,7 +2,7 @@ // @id explorer-frame-classic // @name Classic Explorer navigation bar // @description Restores the classic Explorer navigation bar to the version before the Windows 11 "Moments 4" update -// @version 1.0.4 +// @version 1.0.5 // @author m417z // @github https://github.com/m417z // @twitter https://twitter.com/m417z @@ -537,6 +537,26 @@ bool HandleNavigationBarControl(IUnknown* navigationBarControl) { return true; } +using XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_t = + int(WINAPI*)(PVOID pThis); +XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_t + XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_Original; +int WINAPI +XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_Hook(PVOID pThis) { + Wh_Log(L">"); + + int ret = + XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_Original(pThis); + + if (g_settings.explorerStyle == ExplorerStyle::classicNavigationBar) { + int retNew = MulDiv(ret, 96, 136); + Wh_Log(L"%d -> %d", ret, retNew); + return retNew; + } + + return ret; +} + using Feature_NavigationBarControl_OnApplyTemplate_t = HRESULT(WINAPI*)(PVOID pThis); Feature_NavigationBarControl_OnApplyTemplate_t @@ -607,8 +627,6 @@ HRESULT WINAPI CoCreateInstance_Hook(REFCLSID rclsid, DWORD dwClsContext, REFIID riid, LPVOID* ppv) { - Wh_Log(L">"); - constexpr winrt::guid CLSID_XamlIslandViewAdapter{ 0x6480100B, 0x5A83, @@ -617,6 +635,8 @@ HRESULT WINAPI CoCreateInstance_Hook(REFCLSID rclsid, if (IsEqualCLSID(rclsid, CLSID_XamlIslandViewAdapter) && g_settings.explorerStyle == ExplorerStyle::classicRibbonUI) { + Wh_Log(L">"); + return REGDB_E_CLASSNOTREG; } @@ -628,7 +648,7 @@ bool HookExplorerFrameSymbols() { HMODULE module = LoadLibrary(L"explorerframe.dll"); if (!module) { Wh_Log(L"Couldn't load explorerframe.dll"); - return FALSE; + return false; } WindhawkUtils::SYMBOL_HOOK explorerFrameDllHooks[] = { @@ -650,6 +670,26 @@ bool HookExplorerFrameSymbols() { ARRAYSIZE(explorerFrameDllHooks)); } +bool HookWindowsUIFileExplorerSymbols() { + HMODULE module = LoadLibrary(L"Windows.UI.FileExplorer.dll"); + if (!module) { + Wh_Log(L"Couldn't load Windows.UI.FileExplorer.dll"); + return false; + } + + // Windows.UI.FileExplorer.dll + WindhawkUtils::SYMBOL_HOOK hooks[] = { + { + {LR"(private: int __cdecl XamlIslandViewAdapter::GetScaledXamlIslandLogicalHeight(void))"}, + (void**)&XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_Original, + (void*)XamlIslandViewAdapter_GetScaledXamlIslandLogicalHeight_Hook, + true, + }, + }; + + return HookSymbols(module, hooks, ARRAYSIZE(hooks)); +} + bool HookFileExplorerExtensionsSymbols() { WCHAR path[MAX_PATH]; if (!GetWindowsDirectory(path, ARRAYSIZE(path))) { @@ -702,6 +742,10 @@ BOOL Wh_ModInit() { return FALSE; } + if (!HookWindowsUIFileExplorerSymbols()) { + return FALSE; + } + if (!HookFileExplorerExtensionsSymbols()) { return FALSE; }