Skip to content

Commit

Permalink
Cycle taskbar buttons with mouse wheel v1.1.4
Browse files Browse the repository at this point in the history
* Fixed compatibility with update KB5040527.
  • Loading branch information
m417z committed Jul 30, 2024
1 parent 8c10530 commit 94d3f10
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions mods/taskbar-wheel-cycle.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// @id taskbar-wheel-cycle
// @name Cycle taskbar buttons with mouse wheel
// @description Use the mouse wheel while hovering over the taskbar to cycle between taskbar buttons (Windows 11 only)
// @version 1.1.3
// @version 1.1.4
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
// @homepage https://m417z.com/
// @include explorer.exe
// @architecture x86-64
// @compilerOptions -lcomctl32 -loleaut32 -lole32 -lwininet
// @compilerOptions -lcomctl32 -loleaut32 -lole32 -lruntimeobject -lwininet
// ==/WindhawkMod==

// Source code is published under The GNU General Public License v3.0.
Expand Down Expand Up @@ -67,7 +67,6 @@ Taskbar Tweaker](https://tweaker.ramensoftware.com/).
#include <winrt/Windows.UI.Xaml.Input.h>

#include <algorithm>
#include <atomic>
#include <memory>
#include <regex>
#include <string>
Expand Down Expand Up @@ -125,7 +124,7 @@ CTaskBand_SwitchTo_t CTaskBand_SwitchTo_Original;

#pragma region offsets

void* CTaskListWnd__GetRequiredCols;
void* CTaskListWnd_GetFocusedBtn;
void* CTaskListWnd__FixupTaskIndicies;

size_t OffsetFromAssembly(void* func,
Expand Down Expand Up @@ -163,8 +162,7 @@ size_t OffsetFromAssembly(void* func,
}

HDPA* EV_MM_TASKLIST_BUTTON_GROUPS_HDPA(LONG_PTR lp) {
static size_t offset =
OffsetFromAssembly(CTaskListWnd__GetRequiredCols, 0xE0);
static size_t offset = OffsetFromAssembly(CTaskListWnd_GetFocusedBtn, 0xE0);

return (HDPA*)(lp + offset);
}
Expand Down Expand Up @@ -1095,7 +1093,8 @@ struct SYMBOL_HOOK {

bool HookSymbols(HMODULE module,
const SYMBOL_HOOK* symbolHooks,
size_t symbolHooksCount) {
size_t symbolHooksCount,
bool cacheOnly = false) {
const WCHAR cacheVer = L'1';
const WCHAR cacheSep = L'#';
constexpr size_t cacheMaxSize = 10240;
Expand Down Expand Up @@ -1249,6 +1248,10 @@ bool HookSymbols(HMODULE module,

Wh_Log(L"Couldn't resolve all symbols from cache");

if (cacheOnly) {
return false;
}

WH_FIND_SYMBOL findSymbol;
HANDLE findSymbolHandle = Wh_FindFirstSymbol(module, nullptr, &findSymbol);
if (!findSymbolHandle) {
Expand Down Expand Up @@ -1366,11 +1369,12 @@ bool HookSymbolsWithOnlineCacheFallback(HMODULE module,
size_t symbolHooksCount) {
constexpr WCHAR kModIdForCache[] = L"taskbar-wheel-cycle";

if (HookSymbols(module, symbolHooks, symbolHooksCount)) {
if (HookSymbols(module, symbolHooks, symbolHooksCount,
/*cacheOnly=*/true)) {
return true;
}

Wh_Log(L"HookSymbols() failed, trying to get an online cache");
Wh_Log(L"HookSymbols() from cache failed, trying to get an online cache");

WCHAR moduleFilePath[MAX_PATH];
DWORD moduleFilePathLen =
Expand Down Expand Up @@ -1425,13 +1429,12 @@ bool HookSymbolsWithOnlineCacheFallback(HMODULE module,
Wh_Log(L"Looking for an online cache at %s", onlineCacheUrl.c_str());

auto onlineCache = GetUrlContent(onlineCacheUrl.c_str());
if (!onlineCache) {
if (onlineCache) {
Wh_SetStringValue(cacheStrKey.c_str(), onlineCache->c_str());
} else {
Wh_Log(L"Failed to get online cache");
return false;
}

Wh_SetStringValue(cacheStrKey.c_str(), onlineCache->c_str());

return HookSymbols(module, symbolHooks, symbolHooksCount);
}

Expand Down Expand Up @@ -1489,6 +1492,7 @@ bool HookTaskbarViewDllSymbols() {
return false;
}

// Taskbar.View.dll, ExplorerExtensions.dll
SYMBOL_HOOK symbolHooks[] = {
{
{LR"(public: virtual int __cdecl winrt::impl::produce<struct winrt::Taskbar::implementation::TaskbarFrame,struct winrt::Windows::UI::Xaml::Controls::IControlOverrides>::OnPointerWheelChanged(void *))"},
Expand All @@ -1508,7 +1512,7 @@ BOOL HookTaskbarDllSymbols() {
return FALSE;
}

SYMBOL_HOOK symbolHooks[] = {
SYMBOL_HOOK taskbarDllHooks[] = {
{
{LR"(public: virtual struct HWND__ * __cdecl CWindowTaskItem::GetWindow(void))"},
(void**)&CWindowTaskItem_GetWindow_Original,
Expand All @@ -1527,17 +1531,17 @@ BOOL HookTaskbarDllSymbols() {
},
// For offsets:
{
{LR"(protected: int __cdecl CTaskListWnd::_GetRequiredCols(int))"},
(void**)&CTaskListWnd__GetRequiredCols,
{LR"(public: virtual long __cdecl CTaskListWnd::GetFocusedBtn(struct ITaskGroup * *,int *))"},
(void**)&CTaskListWnd_GetFocusedBtn,
},
{
{LR"(protected: void __cdecl CTaskListWnd::_FixupTaskIndicies(struct ITaskBtnGroup *,int,int))"},
(void**)&CTaskListWnd__FixupTaskIndicies,
},
};

return HookSymbolsWithOnlineCacheFallback(module, symbolHooks,
ARRAYSIZE(symbolHooks));
return HookSymbolsWithOnlineCacheFallback(module, taskbarDllHooks,
ARRAYSIZE(taskbarDllHooks));
}

BOOL Wh_ModInit() {
Expand Down

0 comments on commit 94d3f10

Please sign in to comment.