diff --git a/iw3sp_mod_ff_src/raw/ui/hud.menu b/iw3sp_mod_ff_src/raw/ui/hud.menu index 1b223f0..f2775b8 100644 --- a/iw3sp_mod_ff_src/raw/ui/hud.menu +++ b/iw3sp_mod_ff_src/raw/ui/hud.menu @@ -198,6 +198,21 @@ visible 1 decoration } + + itemDef + { + name "lowammowarning" + rect -10 15 150 30 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER + textfont UI_FONT_DEFAULT + textscale TEXTSIZE_SMALL + textalign (ITEM_ALIGN_CENTER | ITEM_ALIGN_MIDDLE) + textstyle ITEM_TEXTSTYLE_SHADOWED + forecolor 1 1 1 1 + //background "white" + ownerdraw CG_PLAYER_WEAPON_LOW_AMMO_WARNING + visible when ( dvarInt( g_gameskill ) == 0 || dvarInt( g_gameskill ) == 1 /*&& dvarBool ( gpad_in_use ) == 1*/ ); + decoration + } } #define COMPASS_OFFSET 0 -10 diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 9c0091c..9ae27c7 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -148,6 +148,32 @@ namespace Components Game::UI_FilterStringForButtonAnimation(text, 1024); } + const char* TextRenderer::CG_DrawPlayerWeaponLowAmmoKey(const char* pszInputBuffer, const char* pszMessageType, int errType) + { + char binding[256]; + Game::UI_GetKeyBindingLocalizedString(0, "+usereload", binding, 0); + const char* displayString = Game::UI_SafeTranslateString(pszInputBuffer); + const char* localizedString = Game::UI_ReplaceConversionString(displayString, binding); + + return localizedString; + } + + __declspec(naked) void TextRenderer::CG_DrawPlayerWeaponLowAmmoWarningStub() + { + const static uint32_t jump_offset = 0x040A1F0; + static const char* messageType = "low ammo warning"; + __asm + { + push 0; + push messageType; + push esi; + call CG_DrawPlayerWeaponLowAmmoKey; + add esp, 0xC; + + jmp jump_offset; + } + } + __declspec(naked) void TextRenderer::R_TextWidth_Stub01() { const static uint32_t jump_offset = 0x56E618; @@ -238,5 +264,8 @@ namespace Components // GetHudelemDirective Utils::Hook::Nop(0x41AA8B, 7); Utils::Hook(0x41AA8B, UI_GetKeyBindingLocalizedStringStub, HOOK_JUMP).install()->quick(); + + // Converting a simple 'reload' text to a text with keybind localized + Utils::Hook(0x40A1EB, CG_DrawPlayerWeaponLowAmmoWarningStub, 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 1e0503f..3f628c7 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -22,6 +22,8 @@ namespace Components static void DrawHudIconStub(); static void UI_ReplaceConversionStringStub(); static void ButtonAnimation(char* text); + static void CG_DrawPlayerWeaponLowAmmoWarningStub(); + static const char* CG_DrawPlayerWeaponLowAmmoKey(const char* pszInputBuffer, const char* pszMessageType, int errType); static void UI_GetKeyBindingLocalizedStringStub(); static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 7d28f2f..dde48ba 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -1317,4 +1317,23 @@ namespace Game } return result; } + + int UI_GetKeyBindingLocalizedString/*eax*/(int localClientNum/*eax*/, const char* command/*ecx*/, char* keys, int bindNum) + { + int result; + const uint32_t UI_GetKeyBindingLocalizedString_func = 0x56F1E0; + __asm + { + pushad; + mov eax, [localClientNum]; + mov ecx, [command]; + push bindNum; + push keys; + call UI_GetKeyBindingLocalizedString_func; + add esp, 8; + mov result, eax; + popad; + } + return result; + } } \ No newline at end of file diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 9e49f94..49ea6d0 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -259,4 +259,6 @@ namespace Game void SV_ShutdownGameVM(int clearScripts/*edi*/); void UI_DrawTextWithGlow(int vertAlign/*eax*/, int horzAlign/*ecx*/, const Game::ScreenPlacement* ScrPlace, const char* text, Game::Font_s* font, float x, float y, float scale, const float* color, int style, const float* glowColor, int subtitle, int cinematic); int String_Parse/*eax*/(const char** p/*eax*/, char* char_out, int len); + + int UI_GetKeyBindingLocalizedString/*eax*/(int localClientNum/*eax*/, const char* command/*ecx*/, char* keys, int bindNum); } \ No newline at end of file