From f4942e9c7cba28ea5fa515307e4dd843969a7902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aubrey/=E3=82=AA=E3=83=BC=E3=83=96=E3=83=AA=E3=83=BC?= <44238627+aubymori@users.noreply.github.com> Date: Sat, 2 Sep 2023 12:41:46 -0500 Subject: [PATCH] Message Box Font Fix 1.1: Use built-in WindhawkUtils (#284) * Use built-in WindhawkUtils --- mods/msg-box-font-fix.wh.cpp | 111 ++++------------------------------- 1 file changed, 13 insertions(+), 98 deletions(-) diff --git a/mods/msg-box-font-fix.wh.cpp b/mods/msg-box-font-fix.wh.cpp index d00c2bc7a..e37929731 100644 --- a/mods/msg-box-font-fix.wh.cpp +++ b/mods/msg-box-font-fix.wh.cpp @@ -2,7 +2,7 @@ // @id msg-box-font-fix // @name Message Box Font Fix // @description Fixes the MessageBox font size in 1709+ -// @version 1.0 +// @version 1.1 // @author aubymori // @github https://github.com/aubymori // @include * @@ -32,97 +32,7 @@ instead of just using `SystemParametersInfoW` like a normal person.* */ // ==/WindhawkModReadme== -#pragma region "WindhawkUtils" -#include -namespace YukisCoffee::WindhawkUtils -{ - struct SymbolHooks - { - PCWSTR symbolName; - void *hookFunction; - void **pOriginalFunction; - }; - - bool hookWithSymbols(HMODULE module, std::initializer_list hooks, PCWSTR server = NULL) - { - WH_FIND_SYMBOL symbol; - HANDLE findSymbol; - - if (!module) - { - Wh_Log(L"Loaded invalid module"); - return false; - } - - // These functions are terribly named, which is why I wrote this wrapper - // in the first place. - findSymbol = Wh_FindFirstSymbol(module, server, &symbol); - - if (findSymbol) - { - do - { - for (SymbolHooks hook : hooks) - { - // If the symbol is unknown, then learn it. - if (!*hook.pOriginalFunction && 0 == wcscmp(symbol.symbol, hook.symbolName)) - { - if (hook.hookFunction) - { - // This is unsafe if you make any typo at all. - Wh_SetFunctionHook( - symbol.address, - hook.hookFunction, - hook.pOriginalFunction - ); - - Wh_Log( - L"Installed hook for symbol %s at %p.", - hook.symbolName, - symbol.address - ); - } - else - { - *hook.pOriginalFunction = symbol.address; - - Wh_Log( - L"Found symbol %s for %p.", - hook.symbolName, - symbol.address - ); - } - } - } - } - while (Wh_FindNextSymbol(findSymbol, &symbol)); - - Wh_FindCloseSymbol(findSymbol); - } - else - { - Wh_Log(L"Unable to find symbols for module."); - return false; - } - - // If a requested symbol is not found at all, then error as such. - for (SymbolHooks hook : hooks) - { - if (!*hook.pOriginalFunction) - { - Wh_Log( - L"Original function for symbol hook %s not found.", - hook.symbolName - ); - - return false; - } - } - - return true; - } -} -#pragma endregion // "WindhawkUtils" +#include typedef HFONT (*GetMessageBoxFontForDpi_t)(UINT); GetMessageBoxFontForDpi_t GetMessageBoxFontForDpi_orig; @@ -160,15 +70,20 @@ BOOL Wh_ModInit() return FALSE; } - bool bHookSuccess = YukisCoffee::WindhawkUtils::hookWithSymbols( - hUser32, + WindhawkUtils::SYMBOL_HOOK symbolHooks[] = { { { - L"struct HFONT__ * __cdecl GetMessageBoxFontForDpi(unsigned int)", - (void *)GetMessageBoxFontForDpi_hook, - (void **)&GetMessageBoxFontForDpi_orig - } + L"struct HFONT__ * __cdecl GetMessageBoxFontForDpi(unsigned int)" + }, + (void **)&GetMessageBoxFontForDpi_orig, + (void *)GetMessageBoxFontForDpi_hook } + }; + + bool bHookSuccess = HookSymbols( + hUser32, + symbolHooks, + ARRAYSIZE(symbolHooks) ); if (!bHookSuccess)