From 1e4a11b6bc608e4c7db8bbba706ed793fc03638d Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Sun, 5 Dec 2021 01:36:00 +0200 Subject: [PATCH] Added posibility to use the original Windows 10 Alt-Tab switcher --- ExplorerPatcher/dllmain.c | 85 ++++++++++++++++++++++++++++++++++-- ExplorerPatcher/settings.reg | 9 ++-- ExplorerPatcher/symbols.c | 16 +++++-- ExplorerPatcher/symbols.h | 5 ++- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 85d3c75..8508a21 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -72,6 +72,7 @@ DWORD bToolbarSeparators = FALSE; DWORD bTaskbarAutohideOnDoubleClick = FALSE; DWORD dwOrbStyle = 0; DWORD bEnableSymbolDownload = TRUE; +DWORD dwAltTabSettings = 0; HMODULE hModule = NULL; HANDLE hDelayedInjectionThread = NULL; HANDLE hIsWinXShown = NULL; @@ -3845,6 +3846,36 @@ void WINAPI LoadSettings(BOOL bIsExplorer) RegCloseKey(hKey); } + RegCreateKeyExW( + HKEY_CURRENT_USER, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ | KEY_WOW64_64KEY, + NULL, + &hKey, + NULL + ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } + if (hKey) + { + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("AltTabSettings"), + 0, + NULL, + &dwAltTabSettings, + &dwSize + ); + RegCloseKey(hKey); + } + + RegCreateKeyExW( HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartPage", @@ -4920,14 +4951,14 @@ LSTATUS twinuipcshell_RegGetValueW( { LSTATUS lRes = RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData); - if (!bOldTaskbar && !lstrcmpW(lpValue, L"AltTabSettings")) + if (!lstrcmpW(lpValue, L"AltTabSettings")) { - if (*(DWORD*)pvData) + if (lRes == ERROR_SUCCESS && *(DWORD*)pvData) { *(DWORD*)pvData = 1; } - if (hWin11AltTabInitialized) + if (!bOldTaskbar && hWin11AltTabInitialized) { SetEvent(hWin11AltTabInitialized); CloseHandle(hWin11AltTabInitialized); @@ -5243,6 +5274,24 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } } +INT64(*twinui_pcshell_IsUndockedAssetAvailableFunc)(INT a1, INT64 a2, INT64 a3, const char* a4); +INT64 twinui_pcshell_IsUndockedAssetAvailableHook(INT a1, INT64 a2, INT64 a3, const char* a4) +{ + if (dwAltTabSettings == 3) + { + return 0; + } + else + { + return twinui_pcshell_IsUndockedAssetAvailableFunc(a1, a2, a3, a4); + } +} + +BOOL IsDebuggerPresentHook() +{ + return FALSE; +} + DWORD Inject(BOOL bIsExplorer) { #if defined(DEBUG) | defined(_DEBUG) @@ -5274,7 +5323,7 @@ DWORD Inject(BOOL bIsExplorer) hSwsOpacityMaybeChanged = CreateEventW(NULL, FALSE, FALSE, NULL); } - unsigned int numSettings = bIsExplorer ? 11 : 2; + unsigned int numSettings = bIsExplorer ? 12 : 2; Setting* settings = calloc(numSettings, sizeof(Setting)); if (settings) { @@ -5401,6 +5450,17 @@ DWORD Inject(BOOL bIsExplorer) cs++; } + if (cs < numSettings) + { + settings[cs].callback = LoadSettings; + settings[cs].data = bIsExplorer; + settings[cs].hEvent = NULL; + settings[cs].hKey = NULL; + wcscpy_s(settings[cs].name, MAX_PATH, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer"); + settings[cs].origin = HKEY_CURRENT_USER; + cs++; + } + SettingsChangeParameters* settingsParams = calloc(1, sizeof(SettingsChangeParameters)); if (settingsParams) { @@ -5641,6 +5701,22 @@ DWORD Inject(BOOL bIsExplorer) } } + if (symbols_PTRS.twinui_pcshell_PTRS[7] && symbols_PTRS.twinui_pcshell_PTRS[7] != 0xFFFFFFFF) + { + twinui_pcshell_IsUndockedAssetAvailableFunc = (INT64(*)(void*, POINT*)) + ((uintptr_t)hTwinuiPcshell + symbols_PTRS.twinui_pcshell_PTRS[7]); + rv = funchook_prepare( + funchook, + (void**)&twinui_pcshell_IsUndockedAssetAvailableFunc, + twinui_pcshell_IsUndockedAssetAvailableHook + ); + if (rv != 0) + { + FreeLibraryAndExitThread(hModule, rv); + return rv; + } + } + if (symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] && symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] != 0xFFFFFFFF) { winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageFunc = (INT64(*)(void*, POINT*)) @@ -5657,6 +5733,7 @@ DWORD Inject(BOOL bIsExplorer) } } VnPatchIAT(hTwinuiPcshell, "API-MS-WIN-CORE-REGISTRY-L1-1-0.DLL", "RegGetValueW", twinuipcshell_RegGetValueW); + //VnPatchIAT(hTwinuiPcshell, "api-ms-win-core-debug-l1-1-0.dll", "IsDebuggerPresent", IsDebuggerPresentHook); printf("Setup twinui.pcshell functions done\n"); diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 2b23c27..caebb91 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -197,12 +197,13 @@ ;T Window switcher [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer] -;z 3 Window switcher (Alt+Tab) style * -;x 0 Windows 11 -;x 2 Windows 10 +;z 4 Window switcher (Alt+Tab) style * +;x 0 Windows 11 (default) +;x 3 Windows 10 ;x 1 Windows NT +;x 2 Simple Window Switcher "AltTabSettings"=dword:00000000 -;t The following settings only apply to the Windows 10 window switcher: +;t The following settings only apply to the Simple Window Switcher: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher\sws] ;b Include desktop "IncludeWallpaper"=dword:00000001 diff --git a/ExplorerPatcher/symbols.c b/ExplorerPatcher/symbols.c index cb53421..e7d85d2 100644 --- a/ExplorerPatcher/symbols.c +++ b/ExplorerPatcher/symbols.c @@ -237,7 +237,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) DWORD dwZero = 0; RegSetValueExW( hKey, - TEXT(TWINUI_PCSHELL_SB_7), + TEXT(TWINUI_PCSHELL_SB_8), 0, REG_DWORD, &dwZero, @@ -325,6 +325,14 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &(symbols_PTRS.twinui_pcshell_PTRS[7]), sizeof(DWORD) ); + RegSetValueExW( + hKey, + TEXT(TWINUI_PCSHELL_SB_8), + 0, + REG_DWORD, + &(symbols_PTRS.twinui_pcshell_PTRS[8]), + sizeof(DWORD) + ); if (hKey) RegCloseKey(hKey); @@ -598,7 +606,8 @@ BOOL LoadSymbols(symbols_addr* symbols_PTRS, HMODULE hModule) symbols_PTRS->twinui_pcshell_PTRS[4] = 0x5DAC08; symbols_PTRS->twinui_pcshell_PTRS[5] = 0x5DA8C4; symbols_PTRS->twinui_pcshell_PTRS[6] = 0x5CD9C0; - symbols_PTRS->twinui_pcshell_PTRS[7] = 0x52980; + symbols_PTRS->twinui_pcshell_PTRS[7] = 0x5f744c; + symbols_PTRS->twinui_pcshell_PTRS[8] = 0x52980; bIsTwinuiPcshellHardcoded = TRUE; } else if (!_stricmp(hash, "03487ccd5bc5a194fad61b616b0a2b28") || !_stricmp(hash, "3f6ef12a59a2f84a3296771ea7753e01")) // 346, 348 @@ -610,7 +619,8 @@ BOOL LoadSymbols(symbols_addr* symbols_PTRS, HMODULE hModule) symbols_PTRS->twinui_pcshell_PTRS[4] = 0x5DBDD8; symbols_PTRS->twinui_pcshell_PTRS[5] = 0x5DBA94; symbols_PTRS->twinui_pcshell_PTRS[6] = 0x5CEB90; - symbols_PTRS->twinui_pcshell_PTRS[7] = 0x4D780; + symbols_PTRS->twinui_pcshell_PTRS[7] = 0x5f861c; + symbols_PTRS->twinui_pcshell_PTRS[8] = 0x4D780; bIsTwinuiPcshellHardcoded = TRUE; } if (bIsTwinuiPcshellHardcoded) diff --git a/ExplorerPatcher/symbols.h b/ExplorerPatcher/symbols.h index 62e8ebd..5f10320 100644 --- a/ExplorerPatcher/symbols.h +++ b/ExplorerPatcher/symbols.h @@ -17,8 +17,9 @@ #define TWINUI_PCSHELL_SB_4 "CLauncherTipContextMenu::_ExecuteShutdownCommand" #define TWINUI_PCSHELL_SB_5 "CLauncherTipContextMenu::_ExecuteCommand" #define TWINUI_PCSHELL_SB_6 "CLauncherTipContextMenu::ShowLauncherTipContextMenu" -#define TWINUI_PCSHELL_SB_7 "winrt::Windows::Internal::Shell::implementation::MeetAndChatManager::OnMessage" // should be always last -#define TWINUI_PCSHELL_SB_CNT 8 +#define TWINUI_PCSHELL_SB_7 "IsUndockedAssetAvailable" +#define TWINUI_PCSHELL_SB_8 "winrt::Windows::Internal::Shell::implementation::MeetAndChatManager::OnMessage" // should be always last +#define TWINUI_PCSHELL_SB_CNT 9 #define STARTDOCKED_SB_NAME "StartDocked" #define STARTDOCKED_SB_0 "StartDocked::LauncherFrame::ShowAllApps" // UNUSED #define STARTDOCKED_SB_1 "StartDocked::LauncherFrame::ShowAllApps"