From 2c353466efd774e7cb28a8efd1f197dc278f40fa Mon Sep 17 00:00:00 2001 From: JerryALT Date: Fri, 29 Mar 2024 20:03:24 +0300 Subject: [PATCH] [TextRenderer]: Added hooks for UI_GetFontHandle function --- src/Components/Modules/TextRenderer.cpp | 144 ++++++++++++++++++++++++ src/Components/Modules/TextRenderer.hpp | 11 ++ 2 files changed, 155 insertions(+) diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 9ae27c7..06f927c 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -252,6 +252,137 @@ namespace Components } } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub1() + { + const static uint32_t retn_addr = 0x410E3A; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub2() + { + const static uint32_t retn_addr = 0x41B649; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub3() + { + const static uint32_t retn_addr = 0x43A21D; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub4() + { + const static uint32_t retn_addr = 0x56DFAF; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub5() + { + const static uint32_t retn_addr = 0x56E813; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub6() + { + const static uint32_t retn_addr = 0x56ED1B; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub7() + { + const static uint32_t retn_addr = 0x56EFCF; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub8() + { + const static uint32_t retn_addr = 0x56F911; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub9() + { + const static uint32_t retn_addr = 0x57056F; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + + void __declspec(naked) TextRenderer::UI_GetFontHandleStub10() + { + const static uint32_t retn_addr = 0x570805; + __asm + { + push ecx; //scrPlace + push eax; //fontEnum + call Game::UI_GetFontHandle; + add esp, 8; + jmp retn_addr; + } + } + TextRenderer::TextRenderer() { Utils::Hook(0x56E613, R_TextWidth_Stub01, HOOK_JUMP).install()->quick(); @@ -267,5 +398,18 @@ namespace Components // Converting a simple 'reload' text to a text with keybind localized Utils::Hook(0x40A1EB, CG_DrawPlayerWeaponLowAmmoWarningStub, HOOK_JUMP).install()->quick(); + + // Replacing the original function on custom. + // P.S: Very bad hooks + Utils::Hook(0x410E35, UI_GetFontHandleStub1, HOOK_JUMP).install()->quick(); + Utils::Hook(0x41B644, UI_GetFontHandleStub2, HOOK_JUMP).install()->quick(); + Utils::Hook(0x43A218, UI_GetFontHandleStub3, HOOK_JUMP).install()->quick(); + Utils::Hook(0x56DFAA, UI_GetFontHandleStub4, HOOK_JUMP).install()->quick(); + Utils::Hook(0x56E80E, UI_GetFontHandleStub5, HOOK_JUMP).install()->quick(); + Utils::Hook(0x56ED16, UI_GetFontHandleStub6, HOOK_JUMP).install()->quick(); + Utils::Hook(0x56EFCA, UI_GetFontHandleStub7, HOOK_JUMP).install()->quick(); + Utils::Hook(0x56F90C, UI_GetFontHandleStub8, HOOK_JUMP).install()->quick(); + Utils::Hook(0x57056A, UI_GetFontHandleStub9, HOOK_JUMP).install()->quick(); + Utils::Hook(0x570800, UI_GetFontHandleStub10, HOOK_JUMP).install()->quick(); } } \ No newline at end of file diff --git a/src/Components/Modules/TextRenderer.hpp b/src/Components/Modules/TextRenderer.hpp index 3f628c7..f858415 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -26,6 +26,17 @@ namespace Components static const char* CG_DrawPlayerWeaponLowAmmoKey(const char* pszInputBuffer, const char* pszMessageType, int errType); static void UI_GetKeyBindingLocalizedStringStub(); + static void UI_GetFontHandleStub1(); + static void UI_GetFontHandleStub2(); + static void UI_GetFontHandleStub3(); + static void UI_GetFontHandleStub4(); + static void UI_GetFontHandleStub5(); + static void UI_GetFontHandleStub6(); + static void UI_GetFontHandleStub7(); + static void UI_GetFontHandleStub8(); + static void UI_GetFontHandleStub9(); + static void UI_GetFontHandleStub10(); + static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font); static float DrawHudIcon(const char* text, const Game::Font_s* font, const float x, const float y, const float sinAngle, const float cosAngle, const float xScale, const float yScale, Game::GfxColor color); };