From 24569ee4bf3945352f1c225e7519ad9ed6b16914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=BE=D0=B2?= <22411953+Vladislav4KZ@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:28:31 +0000 Subject: [PATCH 1/2] client: hud: fix money HUD overlapping for amounts over 99999 --- cl_dll/hud/money.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cl_dll/hud/money.cpp b/cl_dll/hud/money.cpp index d02ee2dc6..cb08918af 100644 --- a/cl_dll/hud/money.cpp +++ b/cl_dll/hud/money.cpp @@ -102,6 +102,14 @@ int CHudMoney::Draw(float flTime) int iDeltaR, iDeltaG, iDeltaB; int iDollarHeight = m_hDollar.rect.Height(); int iDeltaAlpha = 255 - interpolate * (255); + int iDeltaAbs = m_iDelta < 0 ? -m_iDelta : m_iDelta; + + // the layout is designed for 5 digits, longer numbers grow to the left + // together with the sign, so they never overlap it + int iDeltaDigits = 5; + for( int n = iDeltaAbs / 100000; n > 0; n /= 10 ) + iDeltaDigits++; + int xDelta = x - ( iDeltaDigits - 5 ) * gHUD.m_iFontWidth; DrawUtils::UnpackRGB (iDeltaR, iDeltaG, iDeltaB, m_iDelta < 0 ? RGB_REDISH : RGB_GREENISH); DrawUtils::ScaleColors(iDeltaR, iDeltaG, iDeltaB, iDeltaAlpha); @@ -114,7 +122,7 @@ int CHudMoney::Draw(float flTime) // draw delta SPR_Set(m_hPlus.spr, iDeltaR, iDeltaG, iDeltaB ); - SPR_DrawAdditive(0, x, y - iDollarHeight * 1.5, &m_hPlus.rect ); + SPR_DrawAdditive(0, xDelta, y - iDollarHeight * 1.5, &m_hPlus.rect ); } else if( m_iDelta < 0) { @@ -123,13 +131,13 @@ int CHudMoney::Draw(float flTime) b = (RGB_REDISH & 0xFF) - interpolate * (RGB_REDISH & 0xFF); SPR_Set(m_hMinus.spr, iDeltaR, iDeltaG, iDeltaB ); - SPR_DrawAdditive(0, x, y - iDollarHeight * 1.5, &m_hMinus.rect ); + SPR_DrawAdditive(0, xDelta, y - iDollarHeight * 1.5, &m_hMinus.rect ); } - DrawUtils::DrawHudNumber2( x + iDollarWidth, y - iDollarHeight * 1.5 , false, 5, - m_iDelta < 0 ? -m_iDelta : m_iDelta, + DrawUtils::DrawHudNumber2( xDelta + iDollarWidth, y - iDollarHeight * 1.5 , false, iDeltaDigits, + iDeltaAbs, iDeltaR, iDeltaG, iDeltaB); - FillRGBA(x + iDollarWidth / 4, y - iDollarHeight * 1.5 + gHUD.m_iFontHeight / 4, 2, 2, iDeltaR, iDeltaG, iDeltaB, iDeltaAlpha ); + FillRGBA(xDelta + iDollarWidth / 4, y - iDollarHeight * 1.5 + gHUD.m_iFontHeight / 4, 2, 2, iDeltaR, iDeltaG, iDeltaB, iDeltaAlpha ); } else DrawUtils::UnpackRGB( r, g, b, gHUD.m_iDefaultHUDColor ); } @@ -139,10 +147,15 @@ int CHudMoney::Draw(float flTime) DrawUtils::ScaleColors( r, g, b, alphaBalance ); + int iDigits = 5; + for( int n = m_iMoneyCount / 100000; n > 0; n /= 10 ) + iDigits++; + x -= ( iDigits - 5 ) * gHUD.m_iFontWidth; + SPR_Set(m_hDollar.spr, r, g, b); SPR_DrawAdditive(0, x, y, &m_hDollar.rect); - DrawUtils::DrawHudNumber2( x + iDollarWidth, y, false, 5, m_iMoneyCount, r, g, b ); + DrawUtils::DrawHudNumber2( x + iDollarWidth, y, false, iDigits, m_iMoneyCount, r, g, b ); FillRGBA(x + iDollarWidth / 4, y + gHUD.m_iFontHeight / 4, 2, 2, r, g, b, alphaBalance ); return 1; } From c45699abbee4332623f8c4f727f5a838cf7e8fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=BE=D0=B2?= <22411953+Vladislav4KZ@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:47:40 +0000 Subject: [PATCH 2/2] client: hud: clamp money HUD values and guard digit sprites --- cl_dll/draw_util.cpp | 8 ++++++++ cl_dll/hud/money.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cl_dll/draw_util.cpp b/cl_dll/draw_util.cpp index c585f3c11..dcd392f9e 100644 --- a/cl_dll/draw_util.cpp +++ b/cl_dll/draw_util.cpp @@ -324,6 +324,10 @@ int DrawUtils::DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int int DrawUtils::DrawHudNumber2( int x, int y, bool DrawZero, int iDigits, int iNumber, int r, int g, int b ) { + // Negative remainders would produce invalid digit sprite indices + if( iNumber < 0 ) + iNumber = 0; + int iWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).Width(); x += ( iDigits - 1 ) * iWidth; @@ -343,6 +347,10 @@ int DrawUtils::DrawHudNumber2( int x, int y, bool DrawZero, int iDigits, int iNu int DrawUtils::DrawHudNumber2( int x, int y, int iNumber, int r, int g, int b ) { + // Negative remainders would produce invalid digit sprite indices + if( iNumber < 0 ) + iNumber = 0; + int iWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).Width(); int iDigits = 0; diff --git a/cl_dll/hud/money.cpp b/cl_dll/hud/money.cpp index cb08918af..c4acdf305 100644 --- a/cl_dll/hud/money.cpp +++ b/cl_dll/hud/money.cpp @@ -40,6 +40,9 @@ version. #include "draw_util.h" #include "pm_shared.h" +// Taken from MAX_MONEY_THRESHOLD in ReGameDLL's regamedll/dlls/gamerules.h +constexpr int MAX_HUD_MONEY = 999999; + int CHudMoney::Init( ) { HOOK_MESSAGE( gHUD.m_Money, Money ); @@ -164,7 +167,12 @@ int CHudMoney::MsgFunc_Money(const char *pszName, int iSize, void *pbuf) { BufferReader buf( pszName, pbuf, iSize ); int iOldCount = m_iMoneyCount; - m_iMoneyCount = buf.ReadLong(); + int iNewCount = buf.ReadLong(); + if( iNewCount < 0 ) + iNewCount = 0; + else if( iNewCount > MAX_HUD_MONEY ) + iNewCount = MAX_HUD_MONEY; + m_iMoneyCount = iNewCount; gEngfuncs.Cvar_SetValue( gHUD.cscl_currentmoney->name, m_iMoneyCount ); m_iDelta = m_iMoneyCount - iOldCount; m_fFade = 5.0f; //fade for 5 seconds