Skip to content

Commit

Permalink
Fix a bug that ClientUI layout in CounterStrike was broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 17, 2024
1 parent dbd6707 commit 42ffb0b
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 104 deletions.
92 changes: 76 additions & 16 deletions Plugins/VGUI2Extension/ClientVGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern vgui::ISurface* g_pSurface;
extern vgui::ISurface_HL25* g_pSurface_HL25;

bool g_IsNativeClientVGUI2 = false;
bool g_IsNativeClientUIHDProportional = false;

IClientVGUI* g_pClientVGUI = NULL;
CounterStrikeViewport* g_pCounterStrikeViewport = NULL;

Expand Down Expand Up @@ -162,31 +164,56 @@ void __fastcall ClientVGUI_Panel_Init(vgui::Panel* pthis, int dummy, int x, int
}
}

void CSBuyMenu_ActivateInternal(vgui::Panel* pthis)
{
pthis->MoveToFront();
pthis->RequestFocus();
pthis->SetVisible(true);
pthis->SetEnabled(true);
vgui::surface()->SetMinimized(pthis->GetVPanel(), false);

int screenW, screenH;
vgui::surface()->GetScreenSize(screenW, screenH);

pthis->SetPos(0, 0);
pthis->SetSize(screenW, screenH);

int wide2 = vgui::scheme()->GetAlteredProportionalScaledValue(640);
int tall2 = vgui::scheme()->GetAlteredProportionalScaledValue(480);

int offsetX = (screenW - wide2) / 2;
int offsetY = (screenH - tall2) / 2;

int offset = min(offsetX, offsetY);

pthis->SetPos(offset, offset);
}

void __fastcall CSBuyMenu_Activate(vgui::Panel* pthis, int dummy)
{
if (DpiManagerInternal()->IsHighDpiSupportEnabled())
{
pthis->MoveToFront();
pthis->RequestFocus();
pthis->SetVisible(true);
pthis->SetEnabled(true);
vgui::surface()->SetMinimized(pthis->GetVPanel(), false);
if (g_IsNativeClientUIHDProportional)
{
auto original = g_pVGuiSurface2->IsForcingHDProportional();

int screenW, screenH;
vgui::surface()->GetScreenSize(screenW, screenH);
g_pVGuiSurface2->SetForcingHDProportional(true);

pthis->SetPos(0, 0);
pthis->SetSize(screenW, screenH);
CSBuyMenu_ActivateInternal(pthis);

int wide2 = vgui::scheme()->GetAlteredProportionalScaledValue(640);
int tall2 = vgui::scheme()->GetAlteredProportionalScaledValue(480);
g_pVGuiSurface2->SetForcingHDProportional(original);

int offsetX = (screenW - wide2) / 2;
int offsetY = (screenH - tall2) / 2;
}
else
{
auto original = g_pVGuiSurface2->IsForcingHDProportional();

int offset = min(offsetX, offsetY);
g_pVGuiSurface2->SetForcingHDProportional(false);

pthis->SetPos(offset, offset);
CSBuyMenu_ActivateInternal(pthis);

g_pVGuiSurface2->SetForcingHDProportional(original);
}
}
else
{
Expand Down Expand Up @@ -401,7 +428,7 @@ void __fastcall ClientVGUI_LoadControlSettings(vgui::Panel* pthis, int dummy, co
gPrivateFuncs.ClientVGUI_LoadControlSettings(pthis, 0, controlResourceName, pathID);
}

void ClientVGUI_KeyValues_FitToFullScreen(KeyValues* pControlKeyValues)
void ClientVGUI_KeyValues_FitToFullScreenInternal(KeyValues* pControlKeyValues)
{
int xpos = pControlKeyValues->GetInt("xpos");
int ypos = pControlKeyValues->GetInt("ypos");
Expand All @@ -422,6 +449,30 @@ void ClientVGUI_KeyValues_FitToFullScreen(KeyValues* pControlKeyValues)
pControlKeyValues->SetInt("ypos", ypos);
}

void ClientVGUI_KeyValues_FitToFullScreen(KeyValues* pControlKeyValues)
{
if (g_IsNativeClientUIHDProportional)
{
auto original = g_pVGuiSurface2->IsForcingHDProportional();

g_pVGuiSurface2->SetForcingHDProportional(true);

ClientVGUI_KeyValues_FitToFullScreenInternal(pControlKeyValues);

g_pVGuiSurface2->SetForcingHDProportional(original);
}
else
{
auto original = g_pVGuiSurface2->IsForcingHDProportional();

g_pVGuiSurface2->SetForcingHDProportional(false);

ClientVGUI_KeyValues_FitToFullScreenInternal(pControlKeyValues);

g_pVGuiSurface2->SetForcingHDProportional(original);
}
}

void ClientVGUI_KeyValues_LoadFromFile_CounterStrike(KeyValues* pthis, const char* resourceName, const char* pathId)
{
if (DpiManagerInternal()->IsHighDpiSupportEnabled())
Expand Down Expand Up @@ -687,6 +738,15 @@ void CClientVGUIProxy::Initialize(CreateInterfaceFn *factories, int count)
return;
}

if (gEngfuncs.CheckParm("clientui_use_hdp", NULL))
{
g_IsNativeClientUIHDProportional = true;
}
else if (gEngfuncs.CheckParm("clientui_no_hdp", NULL))
{
g_IsNativeClientUIHDProportional = false;
}

VGUI2ExtensionInternal()->ClientVGUI_Initialize(factories, count);
}

Expand Down
97 changes: 30 additions & 67 deletions Plugins/VGUI2Extension/SchemeHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using namespace vgui;

#define CLIENTUI_USE_640_480_PROPBASE

extern bool g_IsNativeClientUIHDProportional;

extern vgui::ISurface2* g_pVGuiSurface2;
extern vgui::ISchemeManager2 * g_pVGuiSchemeManager2;
extern vgui::ISchemeManager * g_pSchemeManager;
Expand Down Expand Up @@ -88,52 +90,40 @@ void CSchemeManagerProxy::Shutdown(bool full)

int CSchemeManagerProxy::GetProportionalScaledValue(int normalizedValue)
{
bool bNoHDProportional = false;

#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif

if (bNoHDProportional)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);
}

int CSchemeManagerProxy::GetProportionalNormalizedValue(int scaledValue)
{
bool bNoHDProportional = false;
#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);
}
Expand Down Expand Up @@ -210,127 +200,100 @@ void CSchemeManagerProxy_HL25::Shutdown(bool full)

int CSchemeManagerProxy_HL25::GetProportionalScaledValue(int normalizedValue)
{
bool bNoHDProportional = false;
#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);
}

int CSchemeManagerProxy_HL25::GetProportionalNormalizedValue(int scaledValue)
{
bool bNoHDProportional = false;

#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif

if (bNoHDProportional)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);
}

float CSchemeManagerProxy_HL25::GetProportionalScale(void)
{
bool bNoHDProportional = false;
#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScale();

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetProportionalScale();
}

int CSchemeManagerProxy_HL25::GetHDProportionalScaledValue(int normalizedValue)
{
bool bNoHDProportional = false;
#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetHDProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetHDProportionalScaledValue(normalizedValue);
}

int CSchemeManagerProxy_HL25::GetHDProportionalNormalizedValue(int normalizedValue)
{
bool bNoHDProportional = false;
#ifdef CLIENTUI_USE_640_480_PROPBASE
auto retaddr = (PUCHAR)_ReturnAddress();

if (retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
if (g_pVGuiSurface2->IsForcingHDProportional() && !g_IsNativeClientUIHDProportional && retaddr > g_dwClientTextBase && retaddr < (PUCHAR)g_dwClientTextBase + g_dwClientTextSize)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetHDProportionalNormalizedValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
g_pVGuiSurface2->SetForcingHDProportional(true);

return r;
}
#endif

return g_pVGuiSchemeManager2->GetHDProportionalNormalizedValue(normalizedValue);
}
Expand Down
Loading

0 comments on commit 42ffb0b

Please sign in to comment.