Skip to content

Commit

Permalink
Disable grouping on the taskbar v1.3.7 (#1063)
Browse files Browse the repository at this point in the history
* Fixed support for the ExplorerPatcher taskbar.
  • Loading branch information
m417z authored Oct 11, 2024
1 parent d190ad2 commit b2f3b38
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions mods/taskbar-grouping.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id taskbar-grouping
// @name Disable grouping on the taskbar
// @description Causes a separate button to be created on the taskbar for each new window
// @version 1.3.6
// @version 1.3.7
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
Expand Down Expand Up @@ -171,6 +171,9 @@ constexpr size_t kCustomGroupPrefixLen = ARRAYSIZE(kCustomGroupPrefix) - 1;

WinVersion g_winVersion;

std::atomic<bool> g_initialized;
std::atomic<bool> g_explorerPatcherInitialized;

bool g_inTaskBandLaunch;
bool g_inUpdateItemIcon;
bool g_inTaskBtnGroupGetIcon;
Expand Down Expand Up @@ -1689,15 +1692,19 @@ bool HookSymbolsWithOnlineCacheFallback(HMODULE module,
return HookSymbols(module, symbolHooks, symbolHooksCount);
}

bool HookExplorerPatcherSymbols(HMODULE epModule) {
struct EP_HOOK {
bool HookExplorerPatcherSymbols(HMODULE explorerPatcherModule) {
if (g_explorerPatcherInitialized.exchange(true)) {
return true;
}

struct EXPLORER_PATCHER_HOOK {
PCSTR symbol;
void** pOriginalFunction;
void* hookFunction = nullptr;
bool optional = false;
};

EP_HOOK hooks[] = {
EXPLORER_PATCHER_HOOK hooks[] = {
{R"(?GetNumItems@CTaskGroup@@UEAAHXZ)",
(void**)&CTaskGroup_GetNumItems_Original},
{R"(?SetAppID@CTaskGroup@@UEAAJPEBG@Z)",
Expand Down Expand Up @@ -1797,9 +1804,9 @@ bool HookExplorerPatcherSymbols(HMODULE epModule) {
bool succeeded = true;

for (const auto& hook : hooks) {
void* ptr = (void*)GetProcAddress(epModule, hook.symbol);
void* ptr = (void*)GetProcAddress(explorerPatcherModule, hook.symbol);
if (!ptr) {
Wh_Log(L"EP symbol%s doesn't exist: %S",
Wh_Log(L"ExplorerPatcher symbol%s doesn't exist: %S",
hook.optional ? L" (optional)" : L"", hook.symbol);
if (!hook.optional) {
succeeded = false;
Expand All @@ -1814,6 +1821,10 @@ bool HookExplorerPatcherSymbols(HMODULE epModule) {
}
}

if (g_initialized) {
Wh_ApplyHookOperations();
}

return succeeded;
}

Expand Down Expand Up @@ -1859,7 +1870,7 @@ HMODULE WINAPI LoadLibraryExW_Hook(LPCWSTR lpLibFileName,
HANDLE hFile,
DWORD dwFlags) {
HMODULE module = LoadLibraryExW_Original(lpLibFileName, hFile, dwFlags);
if (module && !((ULONG_PTR)module & 3)) {
if (module && !((ULONG_PTR)module & 3) && !g_explorerPatcherInitialized) {
HandleModuleIfExplorerPatcher(module);
}

Expand Down Expand Up @@ -2174,7 +2185,7 @@ bool HookTaskbarSymbols() {
module = LoadLibrary(L"taskbar.dll");
if (!module) {
Wh_Log(L"Couldn't load taskbar.dll");
return FALSE;
return false;
}
}

Expand Down Expand Up @@ -2284,19 +2295,23 @@ BOOL Wh_ModInit() {
}

if (g_settings.oldTaskbarOnWin11) {
bool hasWin10Taskbar = g_winVersion < WinVersion::Win11_24H2;

if (g_winVersion >= WinVersion::Win11) {
g_winVersion = WinVersion::Win10;
}

if (g_winVersion < WinVersion::Win11_24H2) {
if (!HookTaskbarSymbols()) {
return FALSE;
}
if (hasWin10Taskbar && !HookTaskbarSymbols()) {
return FALSE;
}

HandleLoadedExplorerPatcher();

Wh_SetFunctionHook((void*)LoadLibraryExW, (void*)LoadLibraryExW_Hook,
HMODULE kernelBaseModule = GetModuleHandle(L"kernelbase.dll");
FARPROC pKernelBaseLoadLibraryExW =
GetProcAddress(kernelBaseModule, "LoadLibraryExW");
Wh_SetFunctionHook((void*)pKernelBaseLoadLibraryExW,
(void*)LoadLibraryExW_Hook,
(void**)&LoadLibraryExW_Original);
} else {
if (!HookTaskbarSymbols()) {
Expand All @@ -2320,6 +2335,16 @@ BOOL Wh_ModInit() {
return TRUE;
}

void Wh_ModAfterInit() {
Wh_Log(L">");

// Try again in case there's a race between the previous attempt and the
// LoadLibraryExW hook.
if (g_settings.oldTaskbarOnWin11 && !g_explorerPatcherInitialized) {
HandleLoadedExplorerPatcher();
}
}

void Wh_ModUninit() {
Wh_Log(L">");
}
Expand Down

0 comments on commit b2f3b38

Please sign in to comment.