From 085b3dd9f7062dc4bde720a0f8fd1f27442e8300 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 4 Oct 2023 02:33:55 +0300 Subject: [PATCH 1/8] Taskbar11: Fixed a bug that reset the "never combine" setting on OS builds 22621.2361+ --- ExplorerPatcher/dllmain.c | 51 ++++++++----------------------------- ExplorerPatcher/lvt.h | 1 + ExplorerPatcher/osutility.h | 7 +++++ 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 2c96e07..ae18d82 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -11506,51 +11506,20 @@ DWORD Inject(BOOL bIsExplorer) ResetEvent(hEvent); }*/ - if (bOldTaskbar) - { - if (IsWindows11()) - { - CreateThread( - 0, - 0, - PlayStartupSound, - 0, - 0, - 0 - ); + if (IsWindows11()) { + if (bOldTaskbar) { + CreateThread(0, 0, PlayStartupSound, 0, 0, 0); printf("Play startup sound thread...\n"); - } - } - - - if (bOldTaskbar) - { - if (IsWindows11()) - { - CreateThread( - 0, - 0, - SignalShellReady, - dwExplorerReadyDelay, - 0, - 0 - ); + CreateThread(0, 0, SignalShellReady, dwExplorerReadyDelay, 0, 0); printf("Signal shell ready...\n"); + } else { + CreateThread(0, 0, FixTaskbarAutohide, 0, 0, 0); + if (!IsWindows11Version22H2Build2361OrHigher()) { + RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"TaskbarGlomLevel"); + RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"MMTaskbarGlomLevel"); + } } } - else - { - CreateThread( - 0, - 0, - FixTaskbarAutohide, - 0, - 0, - 0 - ); - RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"TaskbarGlomLevel"); - RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"MMTaskbarGlomLevel"); - } if (IsWindows11Version22H2OrHigher() && bOldTaskbar) { diff --git a/ExplorerPatcher/lvt.h b/ExplorerPatcher/lvt.h index 49691b6..4cd1515 100644 --- a/ExplorerPatcher/lvt.h +++ b/ExplorerPatcher/lvt.h @@ -7,6 +7,7 @@ #include #include #include +#include "osutility.h" #define LVT_LOC_NONE 0 #define LVT_LOC_BOTTOMLEFT 1 diff --git a/ExplorerPatcher/osutility.h b/ExplorerPatcher/osutility.h index affc78c..833b648 100644 --- a/ExplorerPatcher/osutility.h +++ b/ExplorerPatcher/osutility.h @@ -87,4 +87,11 @@ inline BOOL IsWindows11Version22H2Build2134OrHigher() if (global_rovi.dwBuildNumber > 22621) return TRUE; return global_rovi.dwBuildNumber == 22621 && global_ubr >= 2134; } + +inline BOOL IsWindows11Version22H2Build2361OrHigher() +{ + if (!global_rovi.dwMajorVersion) global_ubr = VnGetOSVersionAndUBR(&global_rovi); + if (global_rovi.dwBuildNumber > 22621) return TRUE; + return global_rovi.dwBuildNumber == 22621 && global_ubr >= 2361; +} #endif From fbaad56b22178772dec80eb86c5821a06295a098 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 4 Oct 2023 03:12:50 +0300 Subject: [PATCH 2/8] Version: 22621.2361.58.2 --- CHANGELOG.md | 8 ++++++++ version.h | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c03c7b..53702b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,14 @@ Tested on OS builds 22000.2416, 22621.1, 22621.2134, 22621.2361, 22631.2338, and * File Explorer: EP now tries to avoid crashes related to the new Windows App SDK views. (b426d2c) * On OS builds 22621+, fixed a bug that crashed `explorer.exe` when required functions in `twinui.pcshell.dll` (for Win+X and Windows 10 Alt+Tab) could not be found using the fallback method. (6023718) +##### 2 + +* Taskbar11: Fixed a bug that reset the "never combine" setting on OS builds 22621.2361+ (#2207) (085b3dd) +* Taskbar10: Fixed Wi-Fi flyout buttons on OS build 22621 (0706393) +* Start10: Fixed start menu folders, show recently added, and show frequently used apps settings not being applied on OS builds 22621.2134+ (e28940d) + +Many thanks to @Amrsatrio for sustained efforts in maintaining and improving ExplorerPatcher. + ## 22621.2283.57 Tested on OS build 22621.2283. Installer requires Internet connectivity. diff --git a/version.h b/version.h index 3144e74..b7769ea 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22621 #define VER_MINOR 2361 #define VER_BUILD_HI 58 -#define VER_BUILD_LO 1 +#define VER_BUILD_LO 2 #define VER_FLAGS VS_FF_PRERELEASE @@ -11,6 +11,10 @@ #define VER_STR(arg) #arg +#define STRINGIFYVER2(X) #X +#define STRINGIFYVER(X) STRINGIFYVER2(X) +#define VER_WITH_DOTS STRINGIFYVER(VER_MAJOR) "." STRINGIFYVER(VER_MINOR) "." STRINGIFYVER(VER_BUILD_HI) "." STRINGIFYVER(VER_BUILD_LO) + // The String form of the version numbers -#define VER_FILE_STRING VALUE "FileVersion", "22621.2361.58.1" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22621.2361.58.1" +#define VER_FILE_STRING VALUE "FileVersion", VER_WITH_DOTS +#define VER_PRODUCT_STRING VALUE "ProductVersion", VER_WITH_DOTS From 001e8d8d1d9447e4b1e603a5bd0db413654decf5 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 02:50:22 +0700 Subject: [PATCH 3/8] FIle Explorer: Fix Pin to Start/Unpin from Start from Explorer and fix command bar option not being applied to non-primary Explorer instances --- ExplorerPatcher/ExplorerPatcher.vcxproj | 16 +- .../ExplorerPatcher.vcxproj.filters | 3 +- ExplorerPatcher/StartMenuSettings.cpp | 220 +++++++++++++++++- ExplorerPatcher/dllmain.c | 175 +++++++++++--- 4 files changed, 374 insertions(+), 40 deletions(-) diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj b/ExplorerPatcher/ExplorerPatcher.vcxproj index b2212a3..f602e31 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj @@ -29,26 +29,26 @@ DynamicLibrary true - v142 + v143 Unicode DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode DynamicLibrary false - v142 + v143 true Unicode @@ -343,10 +343,18 @@ + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters index d78f2d1..1cb4c14 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters @@ -225,5 +225,6 @@ Settings + - + \ No newline at end of file diff --git a/ExplorerPatcher/StartMenuSettings.cpp b/ExplorerPatcher/StartMenuSettings.cpp index 9f8b569..a95da1e 100644 --- a/ExplorerPatcher/StartMenuSettings.cpp +++ b/ExplorerPatcher/StartMenuSettings.cpp @@ -2,7 +2,24 @@ #include #include #include -#include +#include + +extern "C" extern DWORD dwStartShowClassicMode; + +static void EPWilLogCallback(wil::FailureInfo const &failure) noexcept +{ + wchar_t message[2048]; + HRESULT hr = GetFailureLogString(message, ARRAYSIZE(message), failure); + if (SUCCEEDED(hr)) + { + wprintf(L"%s", message); // message includes newline + } +} + +extern "C" void InitializeWilLogCallback() +{ + SetResultLoggingCallback(EPWilLogCallback); +} static std::vector GlobalStartData_GetPlacesFromRegistry() { @@ -137,3 +154,204 @@ extern "C" BOOL NeedsRo_SyncSettingsFromRegToCDS() return TRUE; } + +namespace ABI::WindowsInternal::Shell::UnifiedTile +{ + MIDL_INTERFACE("d3653510-4fff-4bfa-905b-ea038b142fa5") + IUnifiedTileIdentifier : public IInspectable + { + }; + + MIDL_INTERFACE("0e7735be-a965-44a6-a75f-54b8bcd67bec") + IWin32UnifiedTileIdentifierFactory : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE Create(HSTRING, IUnifiedTileIdentifier**) = 0; + }; +} + +namespace ABI::WindowsInternal::Shell::UnifiedTile::Private +{ + MIDL_INTERFACE("0083831c-82d6-4e8f-bcc2-a8ac2691be49") + IUnifiedTileUserPinHelperStatics : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE CreateUserPinnedShortcutTile(IUnifiedTileIdentifier*) = 0; + }; +} + +namespace ABI::WindowsInternal::Shell::UnifiedTile::CuratedTileCollections +{ + enum class CollectionAttributes {}; + enum class PackageStatusChangeType {}; + enum class StartCollectionCustomizationRestrictionType {}; + enum class TilePinSize {}; + + namespace DataStoreCache::CuratedTileCollectionTransformer + { + class CuratedTile; + } + + MIDL_INTERFACE("ffffffff-ffff-ffff-ffff-ffffffffffff") + ICuratedTileGroup : public IInspectable + { + }; + + MIDL_INTERFACE("ffffffff-ffff-ffff-ffff-ffffffffffff") + ICuratedTile : public IInspectable + { + }; + + MIDL_INTERFACE("51a07090-3a1f-49ef-9932-a971b8154790") + ICuratedTileCollection : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE get_CollectionName(HSTRING*) = 0; + virtual HRESULT STDMETHODCALLTYPE get_Attributes(CollectionAttributes*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_Attributes(CollectionAttributes) = 0; + virtual HRESULT STDMETHODCALLTYPE get_Version(unsigned int*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_Version(unsigned int) = 0; + virtual HRESULT STDMETHODCALLTYPE GetGroups(Windows::Foundation::Collections::IMapView**) = 0; + virtual HRESULT STDMETHODCALLTYPE GetTiles(Windows::Foundation::Collections::IMapView**) = 0; + virtual HRESULT STDMETHODCALLTYPE GetAllTilesInCollection(Windows::Foundation::Collections::IMapView**) = 0; + virtual HRESULT STDMETHODCALLTYPE DoesCollectionContainTile(IUnifiedTileIdentifier*, ICuratedTile**, unsigned char*) = 0; + virtual HRESULT STDMETHODCALLTYPE FindTileAndParentGroup(IUnifiedTileIdentifier*, ICuratedTile**, ICuratedTileGroup**, unsigned char*) = 0; + virtual HRESULT STDMETHODCALLTYPE MoveExistingGroupToNewParent(ICuratedTileGroup*, ICuratedTileGroup*) = 0; + virtual HRESULT STDMETHODCALLTYPE CreateNewGroup(ICuratedTileGroup**) = 0; + virtual HRESULT STDMETHODCALLTYPE GetGroup(GUID, ICuratedTileGroup**) = 0; + virtual HRESULT STDMETHODCALLTYPE DeleteGroup(GUID) = 0; + virtual HRESULT STDMETHODCALLTYPE RemoveGroup(GUID) = 0; + virtual HRESULT STDMETHODCALLTYPE MoveExistingTileToNewParent(ICuratedTile*, ICuratedTileGroup*) = 0; + virtual HRESULT STDMETHODCALLTYPE AddTile(IUnifiedTileIdentifier*, ICuratedTile**) = 0; + virtual HRESULT STDMETHODCALLTYPE AddTileWithId(IUnifiedTileIdentifier*, GUID, ICuratedTile**) = 0; + virtual HRESULT STDMETHODCALLTYPE GetTile(GUID, ICuratedTile**) = 0; + virtual HRESULT STDMETHODCALLTYPE DeleteTile(GUID) = 0; + virtual HRESULT STDMETHODCALLTYPE RemoveTile(GUID) = 0; + virtual HRESULT STDMETHODCALLTYPE Commit() = 0; + virtual HRESULT STDMETHODCALLTYPE CommitAsync(Windows::Foundation::IAsyncAction**) = 0; + virtual HRESULT STDMETHODCALLTYPE CommitAsyncWithTimerBypass(Windows::Foundation::IAsyncAction**) = 0; + virtual HRESULT STDMETHODCALLTYPE ResetToDefault() = 0; + virtual HRESULT STDMETHODCALLTYPE ResetToDefaultAsync(Windows::Foundation::IAsyncAction**) = 0; + virtual HRESULT STDMETHODCALLTYPE CheckForUpdate() = 0; + virtual HRESULT STDMETHODCALLTYPE GetCustomProperty(const HSTRING, HSTRING*) = 0; + virtual HRESULT STDMETHODCALLTYPE HasCustomProperty(const HSTRING, unsigned char*) = 0; + virtual HRESULT STDMETHODCALLTYPE RemoveCustomProperty(const HSTRING) = 0; + virtual HRESULT STDMETHODCALLTYPE SetCustomProperty(const HSTRING, HSTRING) = 0; + virtual HRESULT STDMETHODCALLTYPE EnsureTileRegistration() = 0; + virtual HRESULT STDMETHODCALLTYPE ResurrectTile(std::shared_ptr, const GUID&) = 0; + virtual HRESULT STDMETHODCALLTYPE OnTileAddedWithinCollection(IUnifiedTileIdentifier*) = 0; + virtual HRESULT STDMETHODCALLTYPE OnTileRemovedWithinCollection(IUnifiedTileIdentifier*) = 0; + }; + + MIDL_INTERFACE("adbf8965-6056-4126-ab26-6660af4661ce") + IStartTileCollection : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE PinToStart(IUnifiedTileIdentifier*, TilePinSize); + virtual HRESULT STDMETHODCALLTYPE PinToStartAtLocation(IUnifiedTileIdentifier*, ICuratedTileGroup*, Windows::Foundation::Point, Windows::Foundation::Size); + virtual HRESULT STDMETHODCALLTYPE UnpinFromStart(IUnifiedTileIdentifier*); + virtual HRESULT STDMETHODCALLTYPE ReplaceTinyOrMediumTile(IUnifiedTileIdentifier*, IUnifiedTileIdentifier*); + virtual HRESULT STDMETHODCALLTYPE get_LastGroupId(GUID*); + virtual HRESULT STDMETHODCALLTYPE put_LastGroupId(GUID); + virtual HRESULT STDMETHODCALLTYPE get_CustomizationRestriction(StartCollectionCustomizationRestrictionType*); + virtual HRESULT STDMETHODCALLTYPE put_CustomizationRestriction(StartCollectionCustomizationRestrictionType); + virtual HRESULT STDMETHODCALLTYPE get_GroupCellWidth(unsigned int*); + virtual HRESULT STDMETHODCALLTYPE put_GroupCellWidth(unsigned int); + virtual HRESULT STDMETHODCALLTYPE get_PreferredColumnCount(unsigned int*); + virtual HRESULT STDMETHODCALLTYPE put_PreferredColumnCount(unsigned int); + virtual HRESULT STDMETHODCALLTYPE get_CurrentColumnCount(unsigned int*); + virtual HRESULT STDMETHODCALLTYPE put_CurrentColumnCount(unsigned int); + }; + + MIDL_INTERFACE("ffffffff-ffff-ffff-ffff-ffffffffffff") + ICuratedTileCollectionOptions : public IInspectable + { + }; + + MIDL_INTERFACE("ffffffff-ffff-ffff-ffff-ffffffffffff") + ICuratedTileCollectionManager : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE NotifyPackageStatusChanged(HSTRING, PackageStatusChangeType) = 0; + virtual HRESULT STDMETHODCALLTYPE GetCollection(HSTRING, ICuratedTileCollection**) = 0; + virtual HRESULT STDMETHODCALLTYPE GetCollectionWithOptions(HSTRING, ICuratedTileCollectionOptions*, ICuratedTileCollection**) = 0; + virtual HRESULT STDMETHODCALLTYPE DeleteCollection(HSTRING) = 0; + virtual HRESULT STDMETHODCALLTYPE CollectionExists(HSTRING, unsigned char*) = 0; + virtual HRESULT STDMETHODCALLTYPE InitializeCollection(HSTRING) = 0; + }; + + MIDL_INTERFACE("15f254ac-49b3-4e6e-9c62-806ffaf554f9") + ICuratedTileCollectionManagerStatics : public IInspectable + { + virtual HRESULT STDMETHODCALLTYPE CreateWithUser(Windows::System::IUser*, ICuratedTileCollectionManager**) = 0; + }; +} + +struct CCacheShortcut +{ +public: + const wchar_t* GetAppID(const void* a2) const + { + DWORD dwOffset = *((DWORD*)this + 11); // Same offset in Windows 10 and 11 + return dwOffset != -1 ? (wchar_t*)((char*)a2 + dwOffset) : nullptr; + } +}; + +extern "C" +{ +HRESULT(*AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc)(const CCacheShortcut* a2, const void* a3); +HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const CCacheShortcut* a2, const void* a3) +{ + using namespace ABI::WindowsInternal::Shell::UnifiedTile; + using namespace ABI::WindowsInternal::Shell::UnifiedTile::Private; + using namespace ABI::WindowsInternal::Shell::UnifiedTile::CuratedTileCollections; + + if (dwStartShowClassicMode) + { + return AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc(a2, a3); + } + + Microsoft::WRL::ComPtr pTileIdentifierFactory; + RETURN_IF_FAILED(Windows::Foundation::GetActivationFactory( + Microsoft::WRL::Wrappers::HStringReference(L"WindowsInternal.Shell.UnifiedTile.UnifiedTileIdentifier").Get(), + pTileIdentifierFactory.GetAddressOf() + )); + + Microsoft::WRL::ComPtr pTileIdentifier; + const wchar_t* pwszAppId = a2->GetAppID(a3); + RETURN_IF_FAILED(pTileIdentifierFactory->Create( + Microsoft::WRL::Wrappers::HStringReference(pwszAppId).Get(), + pTileIdentifier.GetAddressOf() + )); + + Microsoft::WRL::ComPtr pTileUserPinHelper; + RETURN_IF_FAILED(Windows::Foundation::GetActivationFactory( + Microsoft::WRL::Wrappers::HStringReference(L"WindowsInternal.Shell.UnifiedTile.Private.UnifiedTileUserPinHelper").Get(), + pTileUserPinHelper.GetAddressOf() + )); + + RETURN_IF_FAILED(pTileUserPinHelper->CreateUserPinnedShortcutTile( + pTileIdentifier.Get() + )); + + // At this point, on Windows 11 the Windows 10 code doesn't exist anymore, so we'll add them here + Microsoft::WRL::ComPtr pTileCollectionManager; + RETURN_IF_FAILED(RoActivateInstance( + Microsoft::WRL::Wrappers::HStringReference(L"WindowsInternal.Shell.UnifiedTile.CuratedTileCollections.CuratedTileCollectionManager").Get(), + (IInspectable**)pTileCollectionManager.GetAddressOf() + )); + + Microsoft::WRL::ComPtr pTileCollection; + RETURN_IF_FAILED(pTileCollectionManager->GetCollection( + Microsoft::WRL::Wrappers::HStringReference(L"Start.TileGrid").Get(), + pTileCollection.GetAddressOf() + )); + + Microsoft::WRL::ComPtr pStartTileCollection; + RETURN_IF_FAILED(pTileCollection.As(&pStartTileCollection)); + + RETURN_IF_FAILED(pStartTileCollection->PinToStart( + pTileIdentifier.Get(), + static_cast(0) + )); + + RETURN_IF_FAILED(pTileCollection->Commit()); + + return S_OK; +} +} diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index ae18d82..81b50a0 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9811,6 +9811,7 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } VnPatchIAT(hExplorerFrame, "API-MS-WIN-CORE-STRING-L1-1-0.DLL", "CompareStringOrdinal", ExplorerFrame_CompareStringOrdinal); VnPatchIAT(hExplorerFrame, "user32.dll", "GetSystemMetricsForDpi", explorerframe_GetSystemMetricsForDpi); + VnPatchIAT(hExplorerFrame, "api-ms-win-core-com-l1-1-0.dll", "CoCreateInstance", ExplorerFrame_CoCreateInstanceHook); } else { @@ -9824,6 +9825,7 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } VnPatchIAT(hExplorerFrame, "API-MS-WIN-CORE-STRING-L1-1-0.DLL", "CompareStringOrdinal", CompareStringOrdinal); VnPatchIAT(hExplorerFrame, "user32.dll", "GetSystemMetricsForDpi", GetSystemMetricsForDpi); + VnPatchIAT(hExplorerFrame, "api-ms-win-core-com-l1-1-0.dll", "CoCreateInstance", CoCreateInstance); FreeLibrary(hExplorerFrame); FreeLibrary(hExplorerFrame); } @@ -9904,8 +9906,28 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } } } + +#ifdef _WIN64 + // As of writing this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now + RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); + int rv = -1; + if (RtlQueryFeatureConfigurationFunc) + { + rv = funchook_prepare( + funchook, + (void**)&RtlQueryFeatureConfigurationFunc, + RtlQueryFeatureConfigurationHook + ); + } + if (rv != 0) + { + printf("Failed to hook RtlQueryFeatureConfiguration(). rv = %d\n", rv); + } +#endif } + +#pragma region "Enable old Alt+Tab" 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) { @@ -9936,7 +9958,11 @@ INT64 twinui_pcshell_CMultitaskingViewManager__CreateXamlMTVHostHook(INT64 _this return twinui_pcshell_CMultitaskingViewManager__CreateDCompMTVHostFunc(_this, a2, a3, a4, a5); return twinui_pcshell_CMultitaskingViewManager__CreateXamlMTVHostFunc(_this, a2, a3, a4, a5); } +#pragma endregion + +#pragma region "Fixes related to the removal of STTest feature flag (22621.2134+)" +#ifdef _WIN64 HRESULT(*twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMonitorFunc)(IInspectable* _this, HMONITOR hMonitor, float* outHeight); HRESULT twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMonitorHook(IInspectable* _this, HMONITOR hMonitor, float* outHeight) { @@ -9951,7 +9977,6 @@ HRESULT twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMo return twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMonitorFunc(_this, hMonitor, outHeight); } -#ifdef _WIN64 static struct { int coroInstance_rcOut; // 22621.1992: 0x10 @@ -10426,12 +10451,11 @@ BOOL Moment2PatchHardwareConfirmator(LPMODULEINFO mi) return TRUE; } #endif +#pragma endregion -BOOL IsDebuggerPresentHook() -{ - return FALSE; -} +#pragma region "Enable EP weather on Windows Server SKUs" +#ifdef _WIN64 BOOL PeopleBand_IsOS(DWORD dwOS) { if (dwOS == OS_ANYSERVER) return FALSE; @@ -10461,7 +10485,12 @@ BOOL explorer_IsOS(DWORD dwOS) } return IsOS(dwOS); } +#endif +#pragma endregion + +#pragma region "Find offsets of needed functions when symbols are not available" +#ifdef _WIN64 void TryToFindTwinuiPCShellOffsets(DWORD* pOffsets) { // We read from the file instead of from memory because other tweak software might've modified the functions we're looking for @@ -10634,6 +10663,88 @@ void TryToFindTwinuiPCShellOffsets(DWORD* pOffsets) free(pFile); CloseHandle(hFile); } +#endif +#pragma endregion + + +#pragma region "Fix Pin to Start from Explorer not working when using Windows 10 start menu" +#ifdef _WIN64 +HRESULT(*AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc)(void** out); +HRESULT AppResolver_StartDocked_GetStartScreenManagerExtensionStatics(void** out) +{ + if (dwStartShowClassicMode) + { + // Keep the value of out as NULL and return S_OK to execute the old code + return S_OK; + } + return AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc(out); +} + +typedef struct CCacheShortcut CCacheShortcut; +extern HRESULT(*AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc)(const CCacheShortcut* a2, const void* a3); +extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const CCacheShortcut* a2, const void* a3); + +void PatchAppResolver() +{ + HANDLE hAppResolver = LoadLibraryW(L"AppResolver.dll"); + MODULEINFO miAppResolver; + GetModuleInformation(GetCurrentProcess(), hAppResolver, &miAppResolver, sizeof(MODULEINFO)); + + // StartDocked::GetStartScreenManagerExtensionStatics + // 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 37 ?? 8B F1 48 83 21 00 + PBYTE match = FindPattern( + hAppResolver, + miAppResolver.SizeOfImage, + "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x55\x57\x41\x56\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x37\x00\x8B\xF1\x48\x83\x21\x00", + "xxxx?xxxx?xxxxxxxx?xxx????xxx????xxxxxxx?xxxxxx" + ); + int rv = -1; + if (match) + { + AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc = match; + printf("StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", match - (PBYTE)hAppResolver); + rv = funchook_prepare( + funchook, + (void**)&AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc, + AppResolver_StartDocked_GetStartScreenManagerExtensionStatics + ); + } + if (rv != 0) + { + printf("Failed to hook StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv); + } + + // CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart() + // 8B ? 48 8B D3 E8 ? ? ? ? 48 8B 8D + // ^^^^^^^ + match = FindPattern( + hAppResolver, + miAppResolver.SizeOfImage, + "\x8B\x00\x48\x8B\xD3\xE8\x00\x00\x00\x00\x48\x8B\x8D", + "x?xxxx????xxx" + ); + rv = -1; + if (match) + { + match += 5; + match = match + 5 + *(int*)(match + 1); + AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc = match; + printf("CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart() = %llX\n", match - (PBYTE)hAppResolver); + extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const void* a2, const void* a3); + rv = funchook_prepare( + funchook, + (void**)&AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc, + AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart + ); + } + if (rv != 0) + { + printf("Failed to hook CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart(). rv = %d\n", rv); + } +} +#endif +#pragma endregion + DWORD Inject(BOOL bIsExplorer) { @@ -10663,10 +10774,10 @@ DWORD Inject(BOOL bIsExplorer) Explorer_RefreshUI(99); #ifdef _WIN64 - if (bIsExplorer) + // if (bIsExplorer) { funchook = funchook_create(); - printf("funchook create %d\n", funchook != 0); + // printf("funchook create %d\n", funchook != 0); } #endif @@ -10847,10 +10958,19 @@ DWORD Inject(BOOL bIsExplorer) if (!bIsExplorer) { - return; +#ifdef _WIN64 + rv = funchook_install(funchook, 0); + if (rv != 0) + { + printf("Failed to install hooks. rv = %d\n", rv); + } +#endif + return 0; } #ifdef _WIN64 + extern void InitializeWilLogCallback(); + InitializeWilLogCallback(); wprintf(L"Running on Windows %d, OS Build %d.%d.%d.%d.\n", IsWindows11() ? 11 : 10, global_rovi.dwMajorVersion, global_rovi.dwMinorVersion, global_rovi.dwBuildNumber, global_ubr); #endif @@ -10930,21 +11050,6 @@ DWORD Inject(BOOL bIsExplorer) printf("Loaded symbols\n"); } - RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); - if (RtlQueryFeatureConfigurationFunc) { - rv = funchook_prepare( - funchook, - (void**)&RtlQueryFeatureConfigurationFunc, - RtlQueryFeatureConfigurationHook - ); - if (rv != 0) - { - FreeLibraryAndExitThread(hModule, rv); - return FALSE; - } - } - printf("Setup ntdll functions done\n"); - HANDLE hUser32 = LoadLibraryW(L"user32.dll"); CreateWindowInBand = GetProcAddress(hUser32, "CreateWindowInBand"); @@ -10985,10 +11090,13 @@ DWORD Inject(BOOL bIsExplorer) VnPatchIAT(hExplorer, "uxtheme.dll", "OpenThemeDataForDpi", explorer_OpenThemeDataForDpi); VnPatchIAT(hExplorer, "uxtheme.dll", "DrawThemeBackground", explorer_DrawThemeBackground); VnPatchIAT(hExplorer, "uxtheme.dll", "CloseThemeData", explorer_CloseThemeData); - // Fix Windows 10 taskbar high DPI button width bug if (IsWindows11()) { + // Fix Windows 10 taskbar high DPI button width bug VnPatchIAT(hExplorer, "api-ms-win-ntuser-sysparams-l1-1-0.dll", "GetSystemMetrics", patched_GetSystemMetrics); + + // Fix Pin to Start/Unpin from Start + PatchAppResolver(); } //VnPatchIAT(hExplorer, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadStringW", explorer_LoadStringWHook); if (bClassicThemeMitigations) @@ -11270,7 +11378,6 @@ DWORD Inject(BOOL bIsExplorer) #endif 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"); @@ -11432,11 +11539,6 @@ DWORD Inject(BOOL bIsExplorer) printf("Setup shell32 functions done\n"); - HANDLE hExplorerFrame = GetModuleHandleW(L"ExplorerFrame.dll"); - VnPatchIAT(hExplorerFrame, "api-ms-win-core-com-l1-1-0.dll", "CoCreateInstance", ExplorerFrame_CoCreateInstanceHook); - printf("Setup explorerframe functions done\n"); - - HANDLE hWindowsStorage = LoadLibraryW(L"windows.storage.dll"); SHELL32_CanDisplayWin8CopyDialogFunc = GetProcAddress(hShell32, "SHELL32_CanDisplayWin8CopyDialog"); if (SHELL32_CanDisplayWin8CopyDialogFunc) VnPatchDelayIAT(hWindowsStorage, "ext-ms-win-shell-exports-internal-l1-1-0.dll", "SHELL32_CanDisplayWin8CopyDialog", SHELL32_CanDisplayWin8CopyDialogHook); @@ -11506,15 +11608,20 @@ DWORD Inject(BOOL bIsExplorer) ResetEvent(hEvent); }*/ - if (IsWindows11()) { - if (bOldTaskbar) { + if (IsWindows11()) + { + if (bOldTaskbar) + { CreateThread(0, 0, PlayStartupSound, 0, 0, 0); printf("Play startup sound thread...\n"); CreateThread(0, 0, SignalShellReady, dwExplorerReadyDelay, 0, 0); printf("Signal shell ready...\n"); - } else { + } + else + { CreateThread(0, 0, FixTaskbarAutohide, 0, 0, 0); - if (!IsWindows11Version22H2Build2361OrHigher()) { + if (IsWindows11Version23H2OrHigher()) + { RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"TaskbarGlomLevel"); RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"MMTaskbarGlomLevel"); } From ce7e170ee190d13bf4c6fa0ff470ef6914fe6519 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 03:20:51 +0700 Subject: [PATCH 4/8] Build: Add ExplorerPatcher\packages.config --- ExplorerPatcher/packages.config | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ExplorerPatcher/packages.config diff --git a/ExplorerPatcher/packages.config b/ExplorerPatcher/packages.config new file mode 100644 index 0000000..14c6321 --- /dev/null +++ b/ExplorerPatcher/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 89b2f3f8cfa65ea16d72d3d7e72edb35dc284b3f Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 03:29:39 +0700 Subject: [PATCH 5/8] Start10: Fix AddUserPinnedShortcutToStart hook --- ExplorerPatcher/StartMenuSettings.cpp | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ExplorerPatcher/StartMenuSettings.cpp b/ExplorerPatcher/StartMenuSettings.cpp index a95da1e..ab4acb3 100644 --- a/ExplorerPatcher/StartMenuSettings.cpp +++ b/ExplorerPatcher/StartMenuSettings.cpp @@ -243,20 +243,20 @@ namespace ABI::WindowsInternal::Shell::UnifiedTile::CuratedTileCollections MIDL_INTERFACE("adbf8965-6056-4126-ab26-6660af4661ce") IStartTileCollection : public IInspectable { - virtual HRESULT STDMETHODCALLTYPE PinToStart(IUnifiedTileIdentifier*, TilePinSize); - virtual HRESULT STDMETHODCALLTYPE PinToStartAtLocation(IUnifiedTileIdentifier*, ICuratedTileGroup*, Windows::Foundation::Point, Windows::Foundation::Size); - virtual HRESULT STDMETHODCALLTYPE UnpinFromStart(IUnifiedTileIdentifier*); - virtual HRESULT STDMETHODCALLTYPE ReplaceTinyOrMediumTile(IUnifiedTileIdentifier*, IUnifiedTileIdentifier*); - virtual HRESULT STDMETHODCALLTYPE get_LastGroupId(GUID*); - virtual HRESULT STDMETHODCALLTYPE put_LastGroupId(GUID); - virtual HRESULT STDMETHODCALLTYPE get_CustomizationRestriction(StartCollectionCustomizationRestrictionType*); - virtual HRESULT STDMETHODCALLTYPE put_CustomizationRestriction(StartCollectionCustomizationRestrictionType); - virtual HRESULT STDMETHODCALLTYPE get_GroupCellWidth(unsigned int*); - virtual HRESULT STDMETHODCALLTYPE put_GroupCellWidth(unsigned int); - virtual HRESULT STDMETHODCALLTYPE get_PreferredColumnCount(unsigned int*); - virtual HRESULT STDMETHODCALLTYPE put_PreferredColumnCount(unsigned int); - virtual HRESULT STDMETHODCALLTYPE get_CurrentColumnCount(unsigned int*); - virtual HRESULT STDMETHODCALLTYPE put_CurrentColumnCount(unsigned int); + virtual HRESULT STDMETHODCALLTYPE PinToStart(IUnifiedTileIdentifier*, TilePinSize) = 0; + virtual HRESULT STDMETHODCALLTYPE PinToStartAtLocation(IUnifiedTileIdentifier*, ICuratedTileGroup*, Windows::Foundation::Point, Windows::Foundation::Size) = 0; + virtual HRESULT STDMETHODCALLTYPE UnpinFromStart(IUnifiedTileIdentifier*) = 0; + virtual HRESULT STDMETHODCALLTYPE ReplaceTinyOrMediumTile(IUnifiedTileIdentifier*, IUnifiedTileIdentifier*) = 0; + virtual HRESULT STDMETHODCALLTYPE get_LastGroupId(GUID*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_LastGroupId(GUID) = 0; + virtual HRESULT STDMETHODCALLTYPE get_CustomizationRestriction(StartCollectionCustomizationRestrictionType*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_CustomizationRestriction(StartCollectionCustomizationRestrictionType) = 0; + virtual HRESULT STDMETHODCALLTYPE get_GroupCellWidth(unsigned int*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_GroupCellWidth(unsigned int) = 0; + virtual HRESULT STDMETHODCALLTYPE get_PreferredColumnCount(unsigned int*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_PreferredColumnCount(unsigned int) = 0; + virtual HRESULT STDMETHODCALLTYPE get_CurrentColumnCount(unsigned int*) = 0; + virtual HRESULT STDMETHODCALLTYPE put_CurrentColumnCount(unsigned int) = 0; }; MIDL_INTERFACE("ffffffff-ffff-ffff-ffff-ffffffffffff") @@ -301,7 +301,7 @@ HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const using namespace ABI::WindowsInternal::Shell::UnifiedTile::Private; using namespace ABI::WindowsInternal::Shell::UnifiedTile::CuratedTileCollections; - if (dwStartShowClassicMode) + if (!dwStartShowClassicMode) { return AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc(a2, a3); } From a4f5bd0ceb071d6cb1262dce30a6cc3cedf10cf8 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 04:39:04 +0700 Subject: [PATCH 6/8] Start10: Fixed non-UWP apps disappearing on Dev channel builds 23545+ --- ExplorerPatcher/dllmain.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 81b50a0..c9ba8f7 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9304,6 +9304,9 @@ BOOL twinui_RegisterHotkeyHook(HWND hWnd, int id, UINT fsModifiers, UINT vk) #pragma region "Redirect certain library loads to other versions" HMODULE patched_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) { + if (IsWindows11Version22H2OrHigher()) + return LoadLibraryExW(lpLibFileName, hFile, dwFlags); + WCHAR path[MAX_PATH]; GetSystemDirectoryW(path, MAX_PATH); wcscat_s(path, MAX_PATH, L"\\AppResolver.dll"); @@ -9313,7 +9316,6 @@ HMODULE patched_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlag wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\AppResolverLegacy.dll"); return LoadLibraryExW(path, hFile, dwFlags); } - if (IsWindows11Version22H2Build1413OrHigher()) return LoadLibraryExW(lpLibFileName, hFile, dwFlags); GetSystemDirectoryW(path, MAX_PATH); wcscat_s(path, MAX_PATH, L"\\StartTileData.dll"); if (!_wcsicmp(path, lpLibFileName)) From 15c07a05308e02e2ec6491c99587bbb3213fd242 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 06:33:58 +0700 Subject: [PATCH 7/8] Start10: Implemented proper fix for Pin to Start/Unpin from Start --- ExplorerPatcher/GUI.c | 120 ------------------------- ExplorerPatcher/GUI.h | 2 - ExplorerPatcher/dllmain.c | 169 ++++++++++++++--------------------- ExplorerPatcher/settings.reg | 2 - ep_setup/ep_setup.c | 24 ++--- 5 files changed, 83 insertions(+), 234 deletions(-) diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 14e0a3f..c4e7b2b 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -2239,126 +2239,6 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) } } } - else if (!strncmp(line + 1, "pin_tiles", 9)) - { - BOOL bFirst = TRUE; - DWORD dwPermitOldStartTileData = TRUE; - DWORD dwSize = sizeof(DWORD); - RegSetKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", REG_DWORD, &dwPermitOldStartTileData, dwSize); - /* - LPCWSTR csPath = L"::{26EE0668-A00A-44D7-9371-BEB064C98683}"; - SFGAOF stSFGAOFIn = 0; - SFGAOF stSFGAOFOut = 0; - SHParseDisplayName(csPath, NULL, &pidl, stSFGAOFIn, &stSFGAOFOut); - */ - WCHAR wszOrigPath[MAX_PATH], wszCurPath[MAX_PATH]; - IShellFolder* psfDesktop = NULL; - hr = SHGetDesktopFolder(&psfDesktop); - if (psfDesktop) - { - LPITEMIDLIST pidl; - hr = SHGetFolderLocation(NULL, CSIDL_CONTROLS, (HANDLE)-1, 0, &pidl); - if (pidl) - { - STRRET strret; - hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pidl, SHGDN_FORPARSING, &strret); - StrRetToBufW(&strret, pidl, wszOrigPath, MAX_PATH); - SHOpenFolderAndSelectItems(pidl, 0, NULL, 0); - VARIANT vt; - HRESULT hr = E_FAIL; - IShellWindows* pShellWindows = NULL; - hr = CoCreateInstance(&CLSID_ShellWindows, NULL, CLSCTX_ALL, &IID_IShellWindows, &pShellWindows); - if (pShellWindows) - { - long k = 0; - pShellWindows->lpVtbl->get_Count(pShellWindows, &k); - for (int i = 0; i < k; ++i) - { - vt.vt = VT_I4; - vt.intVal = i; - IDispatch* pDispatch = NULL; - hr = pShellWindows->lpVtbl->Item(pShellWindows, vt, &pDispatch); - if (pDispatch) - { - IWebBrowserApp* pWebBrowserApp = NULL; - hr = pDispatch->lpVtbl->QueryInterface(pDispatch, &IID_IWebBrowserApp, &pWebBrowserApp); - if (pWebBrowserApp) - { - IServiceProvider* pServiceProvider = NULL; - hr = pWebBrowserApp->lpVtbl->QueryInterface(pWebBrowserApp, &IID_IServiceProvider, &pServiceProvider); - if (pServiceProvider) - { - IShellBrowser* pShellBrowser = NULL; - hr = pServiceProvider->lpVtbl->QueryService(pServiceProvider, &SID_STopLevelBrowser, &IID_IShellBrowser, &pShellBrowser); - if (pShellBrowser) - { - IShellView* pShellView = NULL; - hr = pShellBrowser->lpVtbl->QueryActiveShellView(pShellBrowser, &pShellView); - if (pShellView) - { - IFolderView* pFolderView = NULL; - hr = pShellView->lpVtbl->QueryInterface(pShellView, &IID_IFolderView, &pFolderView); - if (pFolderView) - { - IPersistFolder2* pPersistFolder2 = NULL; - hr = pFolderView->lpVtbl->GetFolder(pFolderView, &IID_IPersistFolder2, &pPersistFolder2); - if (pPersistFolder2) - { - LPITEMIDLIST pCur = NULL; - hr = pPersistFolder2->lpVtbl->GetCurFolder(pPersistFolder2, &pCur); - if (pCur) - { - hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pCur, SHGDN_FORPARSING, &strret); - StrRetToBufW(&strret, pidl, wszCurPath, MAX_PATH); - if (!_wcsnicmp(wszOrigPath, wszCurPath, 40) && wcslen(wszCurPath) == 40 && bFirst) - { - LPITEMIDLIST pNew = NULL; - hr = SHGetFolderLocation(NULL, CSIDL_DRIVES, (HANDLE)-1, 0, &pNew); - if (pNew) - { - hr = pShellBrowser->lpVtbl->BrowseObject(pShellBrowser, pNew, SBSP_SAMEBROWSER); - if (SUCCEEDED(hr)) - { - HWND hWndExp = NULL; - pWebBrowserApp->lpVtbl->get_HWND(pWebBrowserApp, &hWndExp); - if (hWndExp) - { - INPUT input; - ZeroMemory(&input, sizeof(INPUT)); - input.type = INPUT_KEYBOARD; - input.ki.wVk = VK_F5; - SetForegroundWindow(hWndExp); - SendInput(1, &input, sizeof(INPUT)); - bFirst = FALSE; - } - } - CoTaskMemFree(pNew); - } - } - CoTaskMemFree(pCur); - } - pPersistFolder2->lpVtbl->Release(pPersistFolder2); - } - pFolderView->lpVtbl->Release(pFolderView); - } - pShellView->lpVtbl->Release(pShellView); - } - pShellBrowser->lpVtbl->Release(pShellBrowser); - } - pServiceProvider->lpVtbl->Release(pServiceProvider); - } - pWebBrowserApp->lpVtbl->Release(pWebBrowserApp); - } - pDispatch->lpVtbl->Release(pDispatch); - } - } - pShellWindows->lpVtbl->Release(pShellWindows); - } - CoTaskMemFree(pidl); - } - psfDesktop->lpVtbl->Release(psfDesktop); - } - } else if (!strncmp(line + 1, "spotlight_menu", 14)) { POINT p; diff --git a/ExplorerPatcher/GUI.h b/ExplorerPatcher/GUI.h index 2b14a88..78d9b38 100644 --- a/ExplorerPatcher/GUI.h +++ b/ExplorerPatcher/GUI.h @@ -26,8 +26,6 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include "utility.h" #include "../ep_weather_host/ep_weather.h" #include "../ep_weather_host/ep_weather_host_h.h" -#include -#include #define MAX_LINE_LENGTH 2000 extern HMODULE hModule; diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index c9ba8f7..0deffc1 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9301,34 +9301,6 @@ BOOL twinui_RegisterHotkeyHook(HWND hWnd, int id, UINT fsModifiers, UINT vk) #pragma endregion -#pragma region "Redirect certain library loads to other versions" -HMODULE patched_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) -{ - if (IsWindows11Version22H2OrHigher()) - return LoadLibraryExW(lpLibFileName, hFile, dwFlags); - - WCHAR path[MAX_PATH]; - GetSystemDirectoryW(path, MAX_PATH); - wcscat_s(path, MAX_PATH, L"\\AppResolver.dll"); - if (!_wcsicmp(path, lpLibFileName)) - { - GetWindowsDirectoryW(path, MAX_PATH); - wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\AppResolverLegacy.dll"); - return LoadLibraryExW(path, hFile, dwFlags); - } - GetSystemDirectoryW(path, MAX_PATH); - wcscat_s(path, MAX_PATH, L"\\StartTileData.dll"); - if (!_wcsicmp(path, lpLibFileName)) - { - GetWindowsDirectoryW(path, MAX_PATH); - wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartTileDataLegacy.dll"); - return LoadLibraryExW(path, hFile, dwFlags); - } - return LoadLibraryExW(lpLibFileName, hFile, dwFlags); -} -#pragma endregion - - #pragma region "Fix taskbar thumbnails and acrylic in newer OS builds (22572+)" #ifdef _WIN64 unsigned int (*GetTaskbarColor)(INT64 u1, INT64 u2) = NULL; @@ -9862,53 +9834,6 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } } - DWORD dwPermitOldStartTileData = FALSE; - DWORD dwSize = sizeof(DWORD); - if (bInstall) - { - dwSize = sizeof(DWORD); - RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"Start_ShowClassicMode", RRF_RT_DWORD, NULL, &dwStartShowClassicMode, &dwSize); - dwSize = sizeof(DWORD); - RegGetValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", RRF_RT_DWORD, NULL, &dwPermitOldStartTileData, &dwSize); - } - if (dwStartShowClassicMode && dwPermitOldStartTileData) - { - HANDLE hCombase = LoadLibraryW(L"combase.dll"); - if (hCombase) - { - if (bInstall) - { - WCHAR wszPath[MAX_PATH], wszExpectedPath[MAX_PATH]; - ZeroMemory(wszPath, MAX_PATH); - ZeroMemory(wszExpectedPath, MAX_PATH); - DWORD dwLength = MAX_PATH; - HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); - if (hProcess) - { - QueryFullProcessImageNameW(hProcess, 0, wszPath, &dwLength); - CloseHandle(hProcess); - } - if (GetWindowsDirectoryW(wszExpectedPath, MAX_PATH)) - { - wcscat_s(wszExpectedPath, MAX_PATH, L"\\explorer.exe"); - if (!_wcsicmp(wszPath, wszExpectedPath)) - { - dwPermitOldStartTileData = FALSE; - dwSize = sizeof(DWORD); - RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot"); - VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", patched_LoadLibraryExW); - } - } - else - { - VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", LoadLibraryExW); - FreeLibrary(hCombase); - FreeLibrary(hCombase); - } - } - } - } - #ifdef _WIN64 // As of writing this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); @@ -10672,7 +10597,8 @@ void TryToFindTwinuiPCShellOffsets(DWORD* pOffsets) #pragma region "Fix Pin to Start from Explorer not working when using Windows 10 start menu" #ifdef _WIN64 HRESULT(*AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc)(void** out); -HRESULT AppResolver_StartDocked_GetStartScreenManagerExtensionStatics(void** out) +HRESULT(*StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc)(void** out); +HRESULT StartDocked_GetStartScreenManagerExtensionStaticsHook(void** out) { if (dwStartShowClassicMode) { @@ -10686,53 +10612,54 @@ typedef struct CCacheShortcut CCacheShortcut; extern HRESULT(*AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc)(const CCacheShortcut* a2, const void* a3); extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const CCacheShortcut* a2, const void* a3); -void PatchAppResolver() +static void FindGetStartScreenManagerExtensionStatics(const MODULEINFO* pModuleInfo, HRESULT(**ppfnOut)(void**)) { - HANDLE hAppResolver = LoadLibraryW(L"AppResolver.dll"); - MODULEINFO miAppResolver; - GetModuleInformation(GetCurrentProcess(), hAppResolver, &miAppResolver, sizeof(MODULEINFO)); - // StartDocked::GetStartScreenManagerExtensionStatics // 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 37 ?? 8B F1 48 83 21 00 PBYTE match = FindPattern( - hAppResolver, - miAppResolver.SizeOfImage, + pModuleInfo->lpBaseOfDll, + pModuleInfo->SizeOfImage, "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x55\x57\x41\x56\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x37\x00\x8B\xF1\x48\x83\x21\x00", "xxxx?xxxx?xxxxxxxx?xxx????xxx????xxxxxxx?xxxxxx" ); - int rv = -1; if (match) { - AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc = match; - printf("StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", match - (PBYTE)hAppResolver); - rv = funchook_prepare( - funchook, - (void**)&AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc, - AppResolver_StartDocked_GetStartScreenManagerExtensionStatics - ); + *ppfnOut = match; } - if (rv != 0) +} + +static void PatchAppResolver() +{ + HANDLE hAppResolver = LoadLibraryW(L"AppResolver.dll"); + MODULEINFO miAppResolver; + GetModuleInformation(GetCurrentProcess(), hAppResolver, &miAppResolver, sizeof(MODULEINFO)); + + FindGetStartScreenManagerExtensionStatics(&miAppResolver, &AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc); + if (AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc) { - printf("Failed to hook StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv); + printf("AppResolver.dll!StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", (PBYTE)AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc - (PBYTE)hAppResolver); } // CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart() // 8B ? 48 8B D3 E8 ? ? ? ? 48 8B 8D // ^^^^^^^ - match = FindPattern( + PBYTE match = FindPattern( hAppResolver, miAppResolver.SizeOfImage, "\x8B\x00\x48\x8B\xD3\xE8\x00\x00\x00\x00\x48\x8B\x8D", "x?xxxx????xxx" ); - rv = -1; if (match) { match += 5; match = match + 5 + *(int*)(match + 1); AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc = match; printf("CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart() = %llX\n", match - (PBYTE)hAppResolver); - extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const void* a2, const void* a3); + } + + int rv = -1; + if (AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc) + { rv = funchook_prepare( funchook, (void**)&AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc, @@ -10742,6 +10669,48 @@ void PatchAppResolver() if (rv != 0) { printf("Failed to hook CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart(). rv = %d\n", rv); + return; // Must be hooked properly otherwise our GetStartScreenManagerExtensionStatics hook will make it crash + } + + rv = -1; + if (AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc) + { + rv = funchook_prepare( + funchook, + (void**)&AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc, + StartDocked_GetStartScreenManagerExtensionStaticsHook + ); + } + if (rv != 0) + { + printf("Failed to hook AppResolver.dll!StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv); + } +} + +static void PatchStartTileData() +{ + HANDLE hStartTileData = LoadLibraryW(L"StartTileData.dll"); + MODULEINFO miStartTileData; + GetModuleInformation(GetCurrentProcess(), hStartTileData, &miStartTileData, sizeof(MODULEINFO)); + + FindGetStartScreenManagerExtensionStatics(&miStartTileData, &StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc); + if (StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc) + { + printf("StartTileData.dll!StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", (PBYTE)StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc - (PBYTE)hStartTileData); + } + + int rv = -1; + if (StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc) + { + rv = funchook_prepare( + funchook, + (void**)&StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc, + StartDocked_GetStartScreenManagerExtensionStaticsHook + ); + } + if (rv != 0) + { + printf("Failed to hook StartTileData.dll!StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv); } } #endif @@ -11099,6 +11068,7 @@ DWORD Inject(BOOL bIsExplorer) // Fix Pin to Start/Unpin from Start PatchAppResolver(); + PatchStartTileData(); } //VnPatchIAT(hExplorer, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadStringW", explorer_LoadStringWHook); if (bClassicThemeMitigations) @@ -12855,10 +12825,9 @@ void InjectStartMenu() if (IsWindows11()) { - // Redirects to StartTileData from 22000.51 which works with the legacy menu - LoadLibraryW(L"combase.dll"); - HANDLE hCombase = GetModuleHandleW(L"combase.dll"); - VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", patched_LoadLibraryExW); + // Fixes Pin to Start/Unpin from Start + PatchAppResolver(); + PatchStartTileData(); // Redirects to pri files from 22000.51 which work with the legacy menu LoadLibraryW(L"MrmCoreR.dll"); diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index c8338b9..0fde220 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -326,8 +326,6 @@ ;x 3 Hide ;x 1 Disable ;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_NoStartMenuMorePrograms"=dword:00000000 -;u Pin tiles to Windows 10 Start menu from File Explorer -;pin_tiles ;y IMPORTANT, MUST READ: Notice regarding this feature (online) ;https://github.com/valinet/ExplorerPatcher/discussions/1679 ;g StartMenu_Windows10 diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index 5428470..1d31236 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -951,18 +951,18 @@ int WINAPI wWinMain( { GetWindowsDirectoryW(wszPath, MAX_PATH); wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\AppResolverLegacy.dll"); - if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "BAD744C69B92BBD508D3950B41822683") && IsConnectedToInternet() == TRUE) + if (FileExistsW(wszPath)) { - DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8148997/AppResolverLegacy.dll.txt", 10 * 1024 * 1024, wszPath); + bOk = DeleteFileW(wszPath); } } if (bOk && IsWindows11()) { GetWindowsDirectoryW(wszPath, MAX_PATH); wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartTileDataLegacy.dll"); - if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "aa36a082e3b33297b6930eea6e98f8cf") && IsConnectedToInternet() == TRUE) + if (FileExistsW(wszPath)) { - DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8136435/StartTileDataLegacy.pri.txt", 10 * 1024 * 1024, wszPath); + bOk = DeleteFileW(wszPath); } } if (bOk && IsWindows11()) @@ -977,12 +977,16 @@ int WINAPI wWinMain( if (bOk && IsWindows11()) { GetWindowsDirectoryW(wszPath, MAX_PATH); - wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US"); - CreateDirectoryW(wszPath, NULL); - wcscat_s(wszPath, MAX_PATH, L"\\StartTileDataLegacy.dll.mui"); - if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "0ed61f384c39116f424eb2fa6b3b9ef8") && IsConnectedToInternet() == TRUE) + wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US\\StartTileDataLegacy.dll.mui"); + if (FileExistsW(wszPath)) { - DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8136433/StartTileDataLegacy.dll.mui.txt", 10 * 1024 * 1024, wszPath); + bOk = DeleteFileW(wszPath); + if (bOk) + { + GetWindowsDirectoryW(wszPath, MAX_PATH); + wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US"); + bOk = RemoveDirectoryW(wszPath); + } } } if (bOk && IsWindows11()) @@ -1244,4 +1248,4 @@ int WINAPI wWinMain( } return GetLastError(); -} \ No newline at end of file +} From dca40576547537b59fac94c5c30b683cc66289db Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Fri, 6 Oct 2023 07:04:46 +0700 Subject: [PATCH 8/8] Start10: Restored the Start_ShowClassicMode registry query that I accidentally removed --- ExplorerPatcher/dllmain.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 0deffc1..89f832c 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9834,8 +9834,14 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } } + if (bInstall) + { + DWORD dwSize = sizeof(DWORD); + RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"Start_ShowClassicMode", RRF_RT_DWORD, NULL, &dwStartShowClassicMode, &dwSize); + } + #ifdef _WIN64 - // As of writing this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now + // As of writing, this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); int rv = -1; if (RtlQueryFeatureConfigurationFunc)