Skip to content

Commit

Permalink
Fix a bug that outlined fonts are corrupted in HL25 engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 19, 2024
1 parent 6f0eca8 commit b3f3338
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 69 deletions.
11 changes: 0 additions & 11 deletions Plugins/CaptionMod/GameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ void __fastcall RichText_InsertStringW(void* pthis, int dummy, wchar_t *ch)
}
}

//TextEntry doesn't have such issue
#if 0
void __fastcall TextEntry_InsertChar(void* pthis, int dummy, wchar_t ch)
{
if (ch == L'\r')
return;

gPrivateFuncs.TextEntry_InsertChar(pthis, 0, ch);
}
#endif

void __fastcall RichText_OnThink(void* pthis, int dummy)
{
vgui::Panel* pPanel = (vgui::Panel*)pthis;
Expand Down
18 changes: 11 additions & 7 deletions Plugins/CaptionMod/SubtitlePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void CSubLine::Draw(int x, int w, int align)
int nTextAlign = ALIGN_DEFAULT;

float flFraction = GetYPosOutRate();

if(flFraction != 0)
{
nAlpha = (float)nAlpha * (1 - flFraction);
Expand Down Expand Up @@ -623,6 +624,8 @@ void SubtitlePanel::VidInit(void)
ClearSubtitle();
}

//#include <gl/gl.h>

void SubtitlePanel::Paint(void)
{
//if (SCR_IsLoadingVisible())
Expand All @@ -644,13 +647,13 @@ void SubtitlePanel::Paint(void)

iPanelWidth -= x << 1;

//Draw lines and get how large the panel suppose to be.
//Draw lines and calculate the size of panel.

surface()->DrawSetTextFont(m_hTextFont);

for(int i = 0; i < m_Lines.Count(); ++i)
{
CSubLine *Line = m_Lines[i];
auto Line = m_Lines[i];

Line->Draw(x, iPanelWidth, m_iTextAlign);

Expand All @@ -664,18 +667,18 @@ void SubtitlePanel::Paint(void)
m_iPanelAlpha = Line->m_Alpha;
}

//If the panel try to fade in when it's fully hidden
//Check if the panel is trying to fade in when it's fully hidden
if(m_iCurPanelY > m_iCurPanelYEnd && m_iPanelY < m_iPanelYEnd)
{
m_iCurPanelY = m_iPanelY;
m_iCurPanelYEnd = m_iPanelYEnd;
}

//the panel's top won't be higher than m_iPanelTop
//The panel's top won't be higher than m_iPanelTop
if(m_iPanelY < m_iPanelTop)
m_iPanelY = m_iPanelTop;

//do not go away too far
//Do not go away too far
if(m_iPanelY > iPanelHeight)
m_iPanelY = iPanelHeight;

Expand All @@ -692,6 +695,7 @@ void SubtitlePanel::Paint(void)
else if(sign == -1 && m_iCurPanelY < m_iPanelY)
m_iCurPanelY = m_iPanelY;
}

if(m_iCurPanelYEnd != m_iPanelYEnd)
{
int sign = (m_iPanelYEnd - m_iCurPanelYEnd) ? 1 : -1;
Expand Down Expand Up @@ -735,7 +739,7 @@ void SubtitlePanel::PaintBackground(void)

surface()->DrawSetColor(clr);

//Draw 4 side rectangle
//Draw 4 side rectangles
surface()->DrawFilledRect(x+r, y, x+w-r, y+r);
surface()->DrawFilledRect(x+w-r, y+r, x+w, y+h-r);
surface()->DrawFilledRect(x+r, y+h-r, x+w-r, y+h);
Expand All @@ -744,7 +748,7 @@ void SubtitlePanel::PaintBackground(void)
//Draw the central rectangle
surface()->DrawFilledRect(x+r, y+r, x+w-r, y+h-r);

//draw 4 round cornor
//Draw 4 round cornors
surface()->DrawSetTexture(m_iRoundCornorMaterial[0]);
surface()->DrawTexturedRect(x, y, x+r, y+r);

Expand Down
56 changes: 40 additions & 16 deletions Plugins/CaptionMod/SurfaceHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void CSurfaceProxy::DrawUnicodeChar(wchar_t wch)
return;

int x, y;
g_pSurface->DrawGetTextPos(x, y);
DrawGetTextPos(x, y);

int a, b, c;
FontManager().GetCharABCwide(g_hCurrentFont, wch, a, b, c);
Expand All @@ -330,18 +330,26 @@ void CSurfaceProxy::DrawUnicodeChar(wchar_t wch)
rgbaWide = b;
}

int textureID;
int textureID = 0;
float *texCoords = NULL;

if (!g_FontTextureCache.GetTextureForChar(g_hCurrentFont, wch, &textureID, &texCoords))
return;

g_pSurface->DrawSetTexture(textureID);

int iSavedColor[4];

iSavedColor[0] = g_iCurrentTextR;
iSavedColor[1] = g_iCurrentTextG;
iSavedColor[2] = g_iCurrentTextB;
iSavedColor[3] = g_iCurrentTextA;

if (FontManager().GetFontOutlined(g_hCurrentFont))
{
int OutlineColor = (g_iCurrentTextR <= 10 && g_iCurrentTextG <= 10 && g_iCurrentTextB <= 10) ? 255 : 0;
m_pfnDrawSetTextColor(this, 0, OutlineColor, OutlineColor, OutlineColor, g_iCurrentTextA);

DrawSetTextColor(OutlineColor, OutlineColor, OutlineColor, g_iCurrentTextA);

if (staticSurface)
{
Expand All @@ -367,15 +375,14 @@ void CSurfaceProxy::DrawUnicodeChar(wchar_t wch)
}
}

m_pfnDrawSetTextColor(this, 0, g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
DrawSetTextColor(iSavedColor[0], iSavedColor[1], iSavedColor[2], iSavedColor[3]);

if (staticSurface)
staticSurface->drawPrintChar(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);
else
staticSurface_HL25->drawPrintChar(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);

m_pfnDrawSetTextColor(this, 0, g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
g_pSurface->DrawSetTextPos(x + b + c, y);
DrawSetTextPos(x + b + c, y);
}

void CSurfaceProxy::DrawUnicodeCharAdd(wchar_t wch)
Expand Down Expand Up @@ -410,10 +417,18 @@ void CSurfaceProxy::DrawUnicodeCharAdd(wchar_t wch)

g_pSurface->DrawSetTexture(textureID);

int iSavedColor[4];

iSavedColor[0] = g_iCurrentTextR;
iSavedColor[1] = g_iCurrentTextG;
iSavedColor[2] = g_iCurrentTextB;
iSavedColor[3] = g_iCurrentTextA;

if (FontManager().GetFontOutlined(g_hCurrentFont))
{
int OutlineColor = (g_iCurrentTextR <= 10 && g_iCurrentTextG <= 10 && g_iCurrentTextB <= 10) ? 255 : 0;
m_pfnDrawSetTextColor(this, 0, OutlineColor, OutlineColor, OutlineColor, g_iCurrentTextA);

DrawSetTextColor(OutlineColor, OutlineColor, OutlineColor, g_iCurrentTextA);

if (staticSurface)
{
Expand All @@ -439,15 +454,14 @@ void CSurfaceProxy::DrawUnicodeCharAdd(wchar_t wch)
}
}

m_pfnDrawSetTextColor(this, 0, g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
DrawSetTextColor(iSavedColor[0], iSavedColor[1], iSavedColor[2], iSavedColor[3]);

if (staticSurface)
staticSurface->drawPrintCharAdd(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);
else
staticSurface_HL25->drawPrintCharAdd(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);

m_pfnDrawSetTextColor(this, 0, g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
g_pSurface->DrawSetTextPos(x + b + c, y);
DrawSetTextPos(x + b + c, y);
}

void CSurfaceProxy::DrawFlushText(void)
Expand Down Expand Up @@ -1177,6 +1191,13 @@ void CSurfaceProxy_HL25::DrawUnicodeChar(wchar_t wch)

DrawSetTexture(textureID);

int iSavedColor[4];

iSavedColor[0] = g_iCurrentTextR;
iSavedColor[1] = g_iCurrentTextG;
iSavedColor[2] = g_iCurrentTextB;
iSavedColor[3] = g_iCurrentTextA;

if (FontManager().GetFontOutlined(g_hCurrentFont))
{
int OutlineColor = (g_iCurrentTextR <= 10 && g_iCurrentTextG <= 10 && g_iCurrentTextB <= 10) ? 255 : 0;
Expand Down Expand Up @@ -1207,15 +1228,13 @@ void CSurfaceProxy_HL25::DrawUnicodeChar(wchar_t wch)
}
}

DrawSetTextColor(g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
DrawSetTextColor(iSavedColor[0], iSavedColor[1], iSavedColor[2], iSavedColor[3]);

if (staticSurface_HL25)
staticSurface_HL25->drawPrintChar(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);
else
staticSurface->drawPrintChar(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);

DrawSetTextColor(g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);

DrawSetTextPos(x + b + c, y);
}

Expand Down Expand Up @@ -1251,6 +1270,13 @@ void CSurfaceProxy_HL25::DrawUnicodeCharAdd(wchar_t wch)

DrawSetTexture(textureID);

int iSavedColor[4];

iSavedColor[0] = g_iCurrentTextR;
iSavedColor[1] = g_iCurrentTextG;
iSavedColor[2] = g_iCurrentTextB;
iSavedColor[3] = g_iCurrentTextA;

if (FontManager().GetFontOutlined(g_hCurrentFont))
{
int OutlineColor = (g_iCurrentTextR <= 10 && g_iCurrentTextG <= 10 && g_iCurrentTextB <= 10) ? 255 : 0;
Expand Down Expand Up @@ -1281,15 +1307,13 @@ void CSurfaceProxy_HL25::DrawUnicodeCharAdd(wchar_t wch)
}
}

DrawSetTextColor(g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);
DrawSetTextColor(iSavedColor[0], iSavedColor[1], iSavedColor[2], iSavedColor[3]);

if (staticSurface_HL25)
staticSurface_HL25->drawPrintCharAdd(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);
else
staticSurface->drawPrintCharAdd(x, y, rgbaWide, rgbaTall, texCoords[0], texCoords[1], texCoords[2], texCoords[3]);

DrawSetTextColor(g_iCurrentTextR, g_iCurrentTextG, g_iCurrentTextB, g_iCurrentTextA);

DrawSetTextPos(x + b + c, y);
}

Expand Down
18 changes: 11 additions & 7 deletions Plugins/CaptionMod/Win32Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ CWin32Font::CWin32Font(void): m_ExtendedABCWidthsCache(256, 0, &ExtendedABCWidth
m_hDIB = NULL;
m_bAntiAliased = false;
m_bUnderlined = false;
m_bOutlined = false;
m_iDropShadowOffset = 0;
m_iFxpHeight = 0;
m_iOutlineSize = 0;
m_pBuf = NULL;
m_iBlur = 0;
m_iScanLines = 0;
m_bRotary = false;
Expand Down Expand Up @@ -71,6 +76,11 @@ CWin32Font::~CWin32Font(void)

if (m_hDIB)
::DeleteObject(m_hDIB);

if (m_pGaussianDistribution)
{
delete[]m_pGaussianDistribution;
}
}

bool g_bFontFound = false;
Expand Down Expand Up @@ -196,7 +206,7 @@ bool CWin32Font::Create(const char *windowsFontName, int tall, int weight, int b
m_ABCWidthsCache[i].b = (char)tm.tmAveCharWidth;
}

if (m_iBlur > 1)
if (m_iBlur > 1 && !m_pGaussianDistribution)
{
m_pGaussianDistribution = new float[m_iBlur * 2 + 1];
double sigma = 0.683 * m_iBlur;
Expand Down Expand Up @@ -659,10 +669,4 @@ bool CWin32Font::GetAdditive(void)
int CWin32Font::GetAscent(void)
{
return m_iAscent;
}

void __fastcall CWin32Font_GetCharRGBA(void *pthis, int, int ch, int rgbaX, int rgbaY, int rgbaWide, int rgbaTall, unsigned char *rgba)
{
CWin32Font *pFont = (CWin32Font *)pthis;
pFont->GetCharRGBA(ch, rgbaX, rgbaY, rgbaWide, rgbaTall, rgba);
}
2 changes: 0 additions & 2 deletions Plugins/CaptionMod/Win32Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,4 @@ class CWin32Font
public:
static bool ms_bSetFriendlyNameCacheLessFunc;
};

void __fastcall CWin32Font_GetCharRGBA(void *pthis, int, int ch, int rgbaX, int rgbaY, int rgbaWide, int rgbaTall, unsigned char *rgba);
#endif
2 changes: 0 additions & 2 deletions Plugins/CaptionMod/exportfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ void S_StartDynamicSound(int entnum, int entchannel, sfx_t *sfx, float *origin,
void S_StartStaticSound(int entnum, int entchannel, sfx_t *sfx, float *origin, float fvol, float attenuation, int flags, int pitch);
sfx_t *S_FindName(char *name, int *pfInCache);

void __fastcall CWin32Font_GetCharRGBA(void *pthis, int, int ch, int rgbaX, int rgbaY, int rgbaWide, int rgbaTall, unsigned char *rgba);

void MessageMode_f(void);
void MessageMode2_f(void);
void Cap_Version_f(void);
Expand Down
21 changes: 0 additions & 21 deletions Plugins/CaptionMod/privatefuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static hook_t *g_phook_S_StartDynamicSound = NULL;
static hook_t *g_phook_S_StartStaticSound = NULL;
static hook_t *g_phook_ScClient_FindSoundEx = NULL;
static hook_t *g_phook_pfnTextMessageGet = NULL;
static hook_t *g_phook_CWin32Font_GetCharRGBA = NULL;
static hook_t *g_phook_WeaponsResource_SelectSlot = NULL;
//hook_t *g_phook_FileSystem_SetGameDirectory = NULL;

Expand Down Expand Up @@ -1188,26 +1187,6 @@ void Engine_FillAddress(void)
}
}
}

//TODO: Remove this? Looks like not used anymore?
#if 0
if (g_iEngineType == ENGINE_SVENGINE)
{
#define CWIN32FONT_GETCHARABCWIDTHS_SIG_SVENGINE "\x55\x8B\xEC\x83\xEC\x2A\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\x2A\x45\x0C\x2A\x2A\x5D\x14"

gPrivateFuncs.CWin32Font_GetCharRGBA = (decltype(gPrivateFuncs.CWin32Font_GetCharRGBA))Search_Pattern(CWIN32FONT_GETCHARABCWIDTHS_SIG_SVENGINE);
Sig_FuncNotFound(CWin32Font_GetCharRGBA);
}
else
{
#define CWIN32FONT_GETCHARABCWIDTHS_SIG "\x55\x8B\xEC\x83\xEC\x70\x53\x56\x8B\xF1\x8D\x45\xD0\x57\x8D\x4D\xE4\x50\x8B\x45\x08\x8D\x55\xD4\x51\x52\x50\x8B\xCE"

gPrivateFuncs.CWin32Font_GetCharRGBA = (decltype(gPrivateFuncs.CWin32Font_GetCharRGBA))Search_Pattern(CWIN32FONT_GETCHARABCWIDTHS_SIG);
Sig_FuncNotFound(CWin32Font_GetCharRGBA);
}
#endif


}

void Client_FillAddress(void)
Expand Down
3 changes: 0 additions & 3 deletions Plugins/CaptionMod/privatefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ typedef struct
sfxcache_t *(*S_LoadSound)(sfx_t *s, channel_t *ch);
sentenceEntry_s*(*SequenceGetSentenceByIndex)(unsigned int);

//Engine Surface
void(__fastcall *CWin32Font_GetCharRGBA)(void *pthis, int, int ch, int rgbaX, int rgbaY, int rgbaWide, int rgbaTall, unsigned char *rgba);

//SC ClientDLL

int(__fastcall *ScClient_FindSoundEx)(void *pthis, int, const char *soundName);
Expand Down

0 comments on commit b3f3338

Please sign in to comment.