Skip to content

Commit

Permalink
All: Added option to enable UI sounds on explorer.exe's XAML views
Browse files Browse the repository at this point in the history
Please treat this feature as a novelty or proof of concept, quirks related to this will never be mitigated.
  • Loading branch information
Amrsatrio committed Nov 13, 2023
1 parent 3b902d0 commit d6cdb5d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
81 changes: 78 additions & 3 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,43 @@ DWORD FixTaskbarAutohide(DWORD unused)
#pragma endregion


#pragma region "Allow enabling XAML sounds"
void ForceEnableXamlSounds(HMODULE hWindowsUIXaml)
{
MODULEINFO mi;
if (!hWindowsUIXaml || !GetModuleInformation(GetCurrentProcess(), hWindowsUIXaml, &mi, sizeof(MODULEINFO)))
return;

// Patch DirectUI::ElementSoundPlayerService::ShouldPlaySound() to disregard XboxUtility::IsOnXbox() check
// 74 ?? 39 59 ?? 75 ?? E8 ?? ?? ?? ?? 84 C0 75
// ^^ change jnz to jmp
PBYTE match = FindPattern(
mi.lpBaseOfDll,
mi.SizeOfImage,
"\x74\x00\x39\x59\x00\x75\x00\xE8\x00\x00\x00\x00\x84\xC0\x75",
"x?xx?x?x????xxx"
);
if (match)
{
PBYTE jnz = match + 14;
DWORD flOldProtect = 0;
if (VirtualProtect(jnz, 1, PAGE_EXECUTE_READWRITE, &flOldProtect))
{
*jnz = 0xEB;
VirtualProtect(jnz, 1, flOldProtect, &flOldProtect);
}
}
}

BOOL IsXamlSoundsEnabled()
{
DWORD dwRes = 0, dwSize = sizeof(DWORD);
RegGetValueW(HKEY_CURRENT_USER, TEXT(REGPATH_OLD), L"XamlSounds", RRF_RT_DWORD, NULL, &dwRes, &dwSize);
return dwRes != 0;
}
#pragma endregion


#pragma region "EnsureXAML on OS builds 22621+"
#ifdef _WIN64
DEFINE_GUID(uuidof_Windows_Internal_Shell_XamlExplorerHost_IXamlApplicationStatics,
Expand Down Expand Up @@ -2032,8 +2069,12 @@ HRESULT WINAPI ICoreWindow5_get_DispatcherQueueHook(void* _this, void** ppValue)
HMODULE __fastcall Windows11v22H2_combase_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
HMODULE hModule = LoadLibraryExW(lpLibFileName, hFile, dwFlags);
if (hModule && hModule == GetModuleHandleW(L"Windows.Ui.Xaml.dll"))
if (hModule && hModule == GetModuleHandleW(L"Windows.UI.Xaml.dll"))
{
if (IsXamlSoundsEnabled())
{
ForceEnableXamlSounds(hModule);
}
DWORD flOldProtect = 0;
IActivationFactory* pWindowsXamlManagerFactory = NULL;
HSTRING_HEADER hstringHeaderWindowsXamlManager;
Expand Down Expand Up @@ -2071,6 +2112,16 @@ HMODULE __fastcall Windows11v22H2_combase_LoadLibraryExW(LPCWSTR lpLibFileName,
}
return hModule;
}

HMODULE __fastcall combase_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
HMODULE hModule = LoadLibraryExW(lpLibFileName, hFile, dwFlags);
if (hModule && hModule == GetModuleHandleW(L"Windows.UI.Xaml.dll"))
{
ForceEnableXamlSounds(hModule);
}
return hModule;
}
#endif
#pragma endregion

Expand Down Expand Up @@ -9898,6 +9949,12 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall)
{
printf("Failed to hook RtlQueryFeatureConfiguration(). rv = %d\n", rv);
}

if (!bIsExplorer && IsXamlSoundsEnabled())
{
HANDLE hCombase = LoadLibraryW(L"combase.dll");
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", combase_LoadLibraryExW);
}
}
#endif

Expand Down Expand Up @@ -12005,9 +12062,9 @@ DWORD Inject(BOOL bIsExplorer)
printf("Setup twinui.pcshell functions done\n");


HANDLE hCombase = LoadLibraryW(L"combase.dll");
if (IsWindows11())
{
HANDLE hCombase = LoadLibraryW(L"combase.dll");
/*if (bOldTaskbar) // TODO Pulled back for now, crashes on 22621.2428
{
// Hook RoGetActivationFactory() for old taskbar
Expand All @@ -12030,8 +12087,12 @@ DWORD Inject(BOOL bIsExplorer)
// Fixed a bug that crashed Explorer when a folder window was opened after a first one was closed on OS builds 22621+
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", Windows11v22H2_combase_LoadLibraryExW);
}
printf("Setup combase functions done\n");
}
if (!IsWindows11Version22H2OrHigher() && IsXamlSoundsEnabled())
{
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", combase_LoadLibraryExW);
}
printf("Setup combase functions done\n");


HANDLE hTwinui = LoadLibraryW(L"twinui.dll");
Expand Down Expand Up @@ -14030,6 +14091,13 @@ HRESULT EntryPoint(DWORD dwMethod)
else if (bIsThisStartMEH)
{
InjectStartMenu();
#ifdef _WIN64
if (IsXamlSoundsEnabled())
{
HMODULE hWindowsUIXaml = LoadLibraryW(L"Windows.UI.Xaml.dll");
ForceEnableXamlSounds(hWindowsUIXaml);
}
#endif
IncrementDLLReferenceCount(hModule);
bInstanced = TRUE;
}
Expand All @@ -14043,6 +14111,13 @@ HRESULT EntryPoint(DWORD dwMethod)
{
InjectShellExperienceHost();
}
#ifdef _WIN64
if (IsXamlSoundsEnabled())
{
HMODULE hWindowsUIXaml = LoadLibraryW(L"Windows.UI.Xaml.dll");
ForceEnableXamlSounds(hWindowsUIXaml);
}
#endif
IncrementDLLReferenceCount(hModule);
bInstanced = TRUE;
}
Expand Down
1 change: 1 addition & 0 deletions ep_gui/resources/EPSettingsResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
#define IDS_ADV_DELAY_6000 1924
#define IDS_ADV_DELAY_8000 1925
#define IDS_ADV_DELAY_10000 1926
#define IDS_ADV_XAMLSOUNDS 1927

#define IDS_ABOUT 2001
#define IDS_ABOUT_VERSION 2002
Expand Down
1 change: 1 addition & 0 deletions ep_gui/resources/lang/ep_gui.en-US.rc
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ BEGIN
IDS_ADV_DELAY_6000 "6 seconds"
IDS_ADV_DELAY_8000 "8 seconds"
IDS_ADV_DELAY_10000 "10 seconds"
IDS_ADV_XAMLSOUNDS "Enable UI sounds in Explorer's XAML views"

IDS_ABOUT "About"

Expand Down
3 changes: 3 additions & 0 deletions ep_gui/resources/settings.reg
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@
;x 8000 %R:1925%
;x 10000 %R:1926%
"ExplorerReadyDelay"=dword:00000000
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher]
;b %R:1927% *
"XamlSounds"=dword:00000000



Expand Down
3 changes: 3 additions & 0 deletions ep_gui/resources/settings10.reg
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@
"PinnedItemsActAsQuickLaunch"=dword:00000000
;b %R:1913% *
"RemoveExtraGapAroundPinnedItems"=dword:00000000
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher]
;b %R:1927% *
"XamlSounds"=dword:00000000


;T %R:2001%
Expand Down

0 comments on commit d6cdb5d

Please sign in to comment.