Skip to content

Commit

Permalink
1. Fix a bug that class CMenu_Legacy not working for HL25 engine.
Browse files Browse the repository at this point in the history
2. Force ClientUI to be 640x480 based.
  • Loading branch information
hzqst committed Feb 17, 2024
1 parent adeb3a3 commit dbd6707
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 41 deletions.
41 changes: 15 additions & 26 deletions Plugins/VGUI2Extension/ClientVGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,6 @@ bool VGUI2_IsFitToScreen(PVOID Candidate)

void __fastcall ClientVGUI_LoadControlSettings(vgui::Panel* pthis, int dummy, const char* controlResourceName, const char* pathID)
{
//if (!gPrivateFuncs.ClientVGUI_BuildGroup_vftable)
//{
//auto BuildGroup = GetLegacyBuildGroup(pthis);
//gPrivateFuncs.ClientVGUI_BuildGroup_vftable = *(PVOID**)BuildGroup;
//g_pMetaHookAPI->VFTHookEx(gPrivateFuncs.ClientVGUI_BuildGroup_vftable, 3, ClientVGUI_BuildGroup_LoadControlSettings, (void**)&gPrivateFuncs.ClientVGUI_BuildGroup_LoadControlSettings);
//g_pMetaHookAPI->VFTHookEx(gPrivateFuncs.ClientVGUI_BuildGroup_vftable, 5, ClientVGUI_BuildGroup_ApplySettings, (void**)&gPrivateFuncs.ClientVGUI_BuildGroup_ApplySettings);
//}

if (!strcmp(controlResourceName, "Resource/UI/BuyMenu.res"))
{
if (!gPrivateFuncs.CSBuyMenu_vftable)
Expand Down Expand Up @@ -702,22 +694,25 @@ void CClientVGUIProxy::Start(void)
{
m_pfnCClientVGUI_Start(this, 0);

const int offset_CSBackGroundPanel = 0x72C;
if (g_bIsCounterStrike)
{
const int offset_CSBackGroundPanel = 0x72C;

g_pCSBackGroundPanel = *(vgui::Panel**)((PUCHAR)this + offset_CSBackGroundPanel);
g_pCSBackGroundPanel = *(vgui::Panel**)((PUCHAR)this + offset_CSBackGroundPanel);

gPrivateFuncs.CCSBackGroundPanel_vftable = *(PVOID**)g_pCSBackGroundPanel;
gPrivateFuncs.CCSBackGroundPanel_vftable = *(PVOID**)g_pCSBackGroundPanel;

for (int index = 159; index <= 160; ++index)
{
if (VGUI2_IsCSBackGroundPanelActivate(gPrivateFuncs.CCSBackGroundPanel_vftable[index], &gPrivateFuncs.CCSBackGroundPanel_XOffsetBase))
for (int index = 159; index <= 160; ++index)
{
gPrivateFuncs.ClientVGUI_Frame_Activate_vftable_index = index;
g_pMetaHookAPI->VFTHook(g_pCSBackGroundPanel, 0, index, CCSBackGroundPanel_Activate, (void**)&gPrivateFuncs.CCSBackGroundPanel_Activate);
break;
if (VGUI2_IsCSBackGroundPanelActivate(gPrivateFuncs.CCSBackGroundPanel_vftable[index], &gPrivateFuncs.CCSBackGroundPanel_XOffsetBase))
{
gPrivateFuncs.ClientVGUI_Frame_Activate_vftable_index = index;
g_pMetaHookAPI->VFTHook(g_pCSBackGroundPanel, 0, index, CCSBackGroundPanel_Activate, (void**)&gPrivateFuncs.CCSBackGroundPanel_Activate);
break;
}
}
Sig_FuncNotFound(CCSBackGroundPanel_Activate);
}
Sig_FuncNotFound(CCSBackGroundPanel_Activate);

VGUI2ExtensionInternal()->ClientVGUI_Start();
}
Expand Down Expand Up @@ -1137,14 +1132,8 @@ void NativeClientUI_RichText_Search(PVOID Candidate, bool bIsUnicode)

void NativeClientUI_FillAddress(void)
{
ULONG ClientTextSize = 0;
PVOID ClientTextBase = ClientTextBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".text\0\0\0", &ClientTextSize);

if (!ClientTextBase)
{
Sys_Error("Failed to locate section \".text\" in client.dll!");
return;
}
ULONG ClientTextSize = g_dwClientTextSize;
PVOID ClientTextBase = g_dwClientTextBase;

ULONG ClientDataSize = 0;
auto ClientDataBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".data\0\0\0", &ClientDataSize);
Expand Down
28 changes: 26 additions & 2 deletions Plugins/VGUI2Extension/GameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,30 @@ class CMenu_Legacy
int m_iFixedWidth;
int m_iMinimumWidth; // a minimum width the menu has to be if it is not fixed width
int m_iNumVisibleLines; // number of items in menu before scroll bar adds on
CScrollBar_Legacy* m_pScroller;

CUtlLinkedList<vgui::Panel*, int> m_MenuItems;
CUtlVector<int> m_SortedItems;
};

class CMenu_HL25
{
public:
int m_iMenuItemHeight;
int m_iFixedWidth;
int m_iMinimumWidth; // a minimum width the menu has to be if it is not fixed width
int m_iNumVisibleLines; // number of items in menu before scroll bar adds on
int m_iMenuItemBlurOffset;
CScrollBar_Legacy* m_pScroller;

CUtlLinkedList<vgui::Panel*, int> m_MenuItems;
CUtlVector<int> m_SortedItems;
};

void __fastcall GameUI_Menu_MakeItemsVisibleInScrollRange(vgui::Panel* pthis, int dummy)
template<class T>
void GameUI_Menu_MakeItemsVisibleInScrollRange_Template(vgui::Panel* pthis)
{
CMenu_Legacy* pMenu = (CMenu_Legacy*)((PUCHAR)pthis + gPrivateFuncs.offset_ScrollBar - 4 * sizeof(int));
T* pMenu = (T*)((PUCHAR)pthis + gPrivateFuncs.offset_ScrollBar - offsetof(T, m_pScroller));

for (int i = 0; i < pMenu->m_MenuItems.Count(); i++)
{
Expand Down Expand Up @@ -695,6 +709,16 @@ void __fastcall GameUI_Menu_MakeItemsVisibleInScrollRange(vgui::Panel* pthis, in
} while (count < pMenu->m_iNumVisibleLines - 1);
}

void __fastcall GameUI_Menu_MakeItemsVisibleInScrollRange(vgui::Panel* pthis, int dummy)
{
if (g_iEngineType == ENGINE_GOLDSRC_HL25)
{
return GameUI_Menu_MakeItemsVisibleInScrollRange_Template<CMenu_HL25>(pthis);
}

return GameUI_Menu_MakeItemsVisibleInScrollRange_Template<CMenu_Legacy>(pthis);
}

/*
====================================================================
GameUI control hooks
Expand Down
149 changes: 149 additions & 0 deletions Plugins/VGUI2Extension/SchemeHook.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include <metahook.h>
#include <vgui/IScheme.h>
#include <vgui/ISurface2.h>
#include "Scheme2.h"
#include "plugins.h"
#include <intrin.h>

using namespace vgui;

#define CLIENTUI_USE_640_480_PROPBASE

extern vgui::ISurface2* g_pVGuiSurface2;
extern vgui::ISchemeManager2 * g_pVGuiSchemeManager2;
extern vgui::ISchemeManager * g_pSchemeManager;
extern vgui::ISchemeManager_HL25* g_pSchemeManager_HL25;
Expand Down Expand Up @@ -83,11 +88,53 @@ 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)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

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)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

return g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);
}

Expand Down Expand Up @@ -163,26 +210,128 @@ 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)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

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)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalNormalizedValue(scaledValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

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)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetProportionalScale();

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

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)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetHDProportionalScaledValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

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)
{
bNoHDProportional = true;
}
#endif
if (bNoHDProportional)
{
auto originalHDProportional = g_pVGuiSurface2->IsForcingHDProportional();
g_pVGuiSurface2->SetForcingHDProportional(false);

auto r = g_pVGuiSchemeManager2->GetHDProportionalNormalizedValue(normalizedValue);

g_pVGuiSurface2->SetForcingHDProportional(originalHDProportional);
return r;
}

return g_pVGuiSchemeManager2->GetHDProportionalNormalizedValue(normalizedValue);
}

Expand Down
30 changes: 27 additions & 3 deletions Plugins/VGUI2Extension/SurfaceHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#include "exportfuncs.h"
#include "DpiManagerInternal.h"
#include "Cursor.h"
#include <intrin.h>

#define CLIENTUI_USE_640_480_PROPBASE

extern IEngineSurface *staticSurface;
extern IEngineSurface_HL25 *staticSurface_HL25;

extern vgui::ISurface *g_pSurface;
extern vgui::ISurface_HL25* g_pSurface_HL25;

Expand Down Expand Up @@ -811,7 +813,18 @@ void CSurfaceProxy::GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall

void CSurfaceProxy::GetProportionalBase(int &width, int &height)
{
if (g_bIsForcingHDProportional && g_iProportionalBaseWidthHD && g_iProportionalBaseHeightHD)
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 && g_bIsForcingHDProportional && g_iProportionalBaseWidthHD && g_iProportionalBaseHeightHD)
{
width = g_iProportionalBaseWidthHD;
height = g_iProportionalBaseHeightHD;
Expand Down Expand Up @@ -1673,7 +1686,18 @@ void CSurfaceProxy_HL25::GetAbsoluteWindowBounds(int &x, int &y, int &wide, int

void CSurfaceProxy_HL25::GetProportionalBase(int &width, int &height)
{
if (g_bIsForcingHDProportional && g_iProportionalBaseWidthHD && g_iProportionalBaseHeightHD)
bool bNoHDProportional = false;

auto retaddr = (PUCHAR)_ReturnAddress();

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

if (!bNoHDProportional && g_bIsForcingHDProportional && g_iProportionalBaseWidthHD && g_iProportionalBaseHeightHD)
{
width = g_iProportionalBaseWidthHD;
height = g_iProportionalBaseHeightHD;
Expand Down
10 changes: 10 additions & 0 deletions Plugins/VGUI2Extension/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ IFileSystem_HL25 *g_pFileSystem_HL25 = NULL;
HMODULE g_hClientDll = NULL;
PVOID g_dwClientBase = 0;
DWORD g_dwClientSize = 0;
PVOID g_dwClientTextBase = 0;
DWORD g_dwClientTextSize = 0;
int g_iVideoWidth = 0;
int g_iVideoHeight = 0;

Expand Down Expand Up @@ -118,6 +120,14 @@ void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc)
g_dwClientBase = g_pMetaHookAPI->GetClientBase();
g_dwClientSize = g_pMetaHookAPI->GetClientSize();

g_dwClientTextBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".text\0\0\0", &g_dwClientTextSize);

if (!g_dwClientTextBase)
{
Sys_Error("Failed to locate section \".text\" in client.dll!");
return;
}

Client_FillAddress();
Client_InstallHooks();

Expand Down
Loading

0 comments on commit dbd6707

Please sign in to comment.