Skip to content

Commit

Permalink
Add hidpi support for GameConsole.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 13, 2024
1 parent 0a363ad commit a682c88
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 62 deletions.
49 changes: 14 additions & 35 deletions Plugins/CaptionMod/BaseUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ extern IEngineSurface_HL25 *staticSurface_HL25;

extern CreateInterfaceFn* g_pClientFactory;

#if 1
void __fastcall EngineVGUI2_Panel_Init(vgui::Panel* pthis, int dummy, int x, int y, int w, int h)
{
gPrivateFuncs.EngineVGUI2_Panel_Init(pthis, 0, x, y, w, h);

if (s_LoadingBaseUI)
//if (s_LoadingBaseUI)
{
if (dpimanager()->IsHighDpiSupportEnabled())
{
Expand All @@ -84,7 +83,6 @@ void __fastcall EngineVGUI2_Panel_Init(vgui::Panel* pthis, int dummy, int x, int
}
}
}
#endif

void CBaseUIProxy::Initialize(CreateInterfaceFn *factories, int count)
{
Expand Down Expand Up @@ -123,22 +121,19 @@ void CBaseUIProxy::Initialize(CreateInterfaceFn *factories, int count)

void CBaseUIProxy::Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion)
{
Install_InlineHook(EngineVGUI2_Panel_Init);

s_LoadingBaseUI = true;

m_pfnCBaseUI_Start(this, 0, engineFuncs, interfaceVersion);

s_LoadingBaseUI = false;

Uninstall_Hook(EngineVGUI2_Panel_Init);
}

void CBaseUIProxy::Shutdown(void)
{
ClientVGUI_Shutdown();

if (g_iEngineType != ENGINE_GOLDSRC_HL25)
//TODO: why???
//if (g_iEngineType != ENGINE_GOLDSRC_HL25)
GameUI_UninstallHooks();

//GameUI.dll and vgui2.dll will be unloaded by engine!CBaseUI::Shutdown
Expand Down Expand Up @@ -192,34 +187,18 @@ void BaseUI_InstallHook(void)
gameuifuncs = (IGameUIFuncs *)fnCreateInterface(VENGINE_GAMEUIFUNCS_VERSION, NULL);

//Search CBaseUI::Initialize for ClientFactory
if (g_iEngineType == ENGINE_SVENGINE)
{
PVOID*ProxyVFTable = *(PVOID**)&s_BaseUIProxy;
PVOID* ProxyVFTable = *(PVOID**)&s_BaseUIProxy;

g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 1, ProxyVFTable[1], (void **)&m_pfnCBaseUI_Initialize);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 2, ProxyVFTable[2], (void**)&m_pfnCBaseUI_Start);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 3, ProxyVFTable[3], (void **)&m_pfnCBaseUI_Shutdown);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 4, ProxyVFTable[4], (void **)&m_pfnCBaseUI_Key_Event);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 6, ProxyVFTable[6], (void**)&m_pfnCBaseUI_Paint);
}
else if (g_iEngineType == ENGINE_GOLDSRC_HL25)
{
PVOID* ProxyVFTable = *(PVOID**)&s_BaseUIProxy;
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 1, ProxyVFTable[1], (void**)&m_pfnCBaseUI_Initialize);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 2, ProxyVFTable[2], (void**)&m_pfnCBaseUI_Start);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 3, ProxyVFTable[3], (void**)&m_pfnCBaseUI_Shutdown);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 4, ProxyVFTable[4], (void **)&m_pfnCBaseUI_Key_Event);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 6, ProxyVFTable[6], (void**)&m_pfnCBaseUI_Paint);

g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 1, ProxyVFTable[1], (void **)&m_pfnCBaseUI_Initialize);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 2, ProxyVFTable[2], (void**)&m_pfnCBaseUI_Start);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 3, ProxyVFTable[3], (void **)&m_pfnCBaseUI_Shutdown);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 4, (void *)ProxyVFTable[4], (void **)&m_pfnCBaseUI_Key_Event);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 6, ProxyVFTable[6], (void**)&m_pfnCBaseUI_Paint);
}
else
{
PVOID* ProxyVFTable = *(PVOID **)&s_BaseUIProxy;
Install_InlineHook(EngineVGUI2_Panel_Init);
}

g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 1, ProxyVFTable[1], (void **)&m_pfnCBaseUI_Initialize);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 2, ProxyVFTable[2], (void**)&m_pfnCBaseUI_Start);
g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 3, ProxyVFTable[3], (void **)&m_pfnCBaseUI_Shutdown);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 4, ProxyVFTable[4], (void **)&m_pfnCBaseUI_Key_Event);
//g_pMetaHookAPI->VFTHook(baseuifuncs, 0, 6, ProxyVFTable[6], (void**)&m_pfnCBaseUI_Paint);
}
void BaseUI_UninstallHook(void)
{
Uninstall_Hook(EngineVGUI2_Panel_Init);
}
39 changes: 31 additions & 8 deletions Plugins/CaptionMod/GameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <capstone.h>

//static hook_t* g_phook_QueryBox_ctor = NULL;
static hook_t* g_phook_GameUI_Panel_Init = NULL;
static hook_t* g_phook_CGameConsoleDialog_ctor = NULL;
static hook_t* g_phook_CCreateMultiplayerGameDialog_ctor = NULL;
static hook_t* g_phook_COptionsDialog_ctor = NULL;
static hook_t *g_phook_COptionsSubVideo_ctor = NULL;
Expand All @@ -35,6 +37,18 @@ namespace vgui
bool VGui_InitInterfacesList(const char *moduleName, CreateInterfaceFn *factoryList, int numFactories);
}

void __fastcall GameUI_Panel_Init(vgui::Panel* pthis, int dummy, int x, int y, int w, int h)
{
gPrivateFuncs.GameUI_Panel_Init(pthis, 0, x, y, w, h);

if (dpimanager()->IsHighDpiSupportEnabled())
{
PVOID* PanelVFTable = *(PVOID**)pthis;
void(__fastcall * pfnSetProportional)(vgui::Panel * pthis, int dummy, bool state) = (decltype(pfnSetProportional))PanelVFTable[113];
pfnSetProportional(pthis, 0, true);
}
}

IGameUI *g_pGameUI = NULL;

void (__fastcall *g_pfnCGameUI_Initialize)(void *pthis, int edx, CreateInterfaceFn *factories, int count) = 0;
Expand Down Expand Up @@ -136,6 +150,7 @@ void CGameUI::ConnectToServer(const char *game, int IP, int port)
if(gEngfuncs.GetMaxClients() > 1)
return g_pfnCGameUI_ConnectToServer(this, 0, game, IP, port);

//This just stop GameUI from sending "mp3 stop" on level transition
return g_pfnCGameUI_ConnectToServer(this, 0, "valve", IP, port);
}

Expand Down Expand Up @@ -672,6 +687,16 @@ void* __fastcall CCreateMultiplayerGameDialog_ctor(vgui::Panel* pthis, int dummy
return result;
}

void* __fastcall CGameConsoleDialog_ctor(vgui::Panel* pthis, int dummy)
{
auto result = gPrivateFuncs.CGameConsoleDialog_ctor(pthis, dummy);

//Load res to make it proportional
gPrivateFuncs.GameUI_LoadControlSettings(pthis, 0, "Resource\\GameConsoleDialog.res", NULL);

return result;
}

#if 0
void* __fastcall QueryBox_ctor(vgui::Panel* pthis, int dummy, const char* title, const char* queryText, vgui::Panel* parent)
{
Expand Down Expand Up @@ -1039,14 +1064,8 @@ void GameUI_InstallHooks(void)
}
}

//TODO the vpanel of staticPanel?
/*if (1)
{
const char sigs1[] = "\x68\x2C\x01\x00\x00\x68\x90\x01\x00\x00\x2A\x2A\x8B\xC8\xA3";
auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(hGameUI, g_pMetaHookAPI->GetModuleSize(hGameUI), sigs1, sizeof(sigs1) - 1);
Sig_AddrNotFound(staticPanel);
staticPanel = *(decltype(staticPanel) *)(addr + sizeof(sigs1) - 1);
}*/
gPrivateFuncs.GameUI_Panel_Init = (decltype(gPrivateFuncs.GameUI_Panel_Init))VGUI2_FindPanelInit(GameUITextBase, GameUITextSize);
Sig_FuncNotFound(GameUI_Panel_Init);

DWORD *pVFTable = *(DWORD **)&s_GameUI;

Expand All @@ -1057,6 +1076,8 @@ void GameUI_InstallHooks(void)
g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 10, (void *)pVFTable[10], (void **)&g_pfnCGameUI_HideGameUI);

//Install_InlineHook(QueryBox_ctor);
Install_InlineHook(GameUI_Panel_Init);
Install_InlineHook(CGameConsoleDialog_ctor);
Install_InlineHook(CCreateMultiplayerGameDialog_ctor);
Install_InlineHook(COptionsDialog_ctor);
Install_InlineHook(COptionsSubVideo_ctor);
Expand All @@ -1067,6 +1088,8 @@ void GameUI_InstallHooks(void)
void GameUI_UninstallHooks(void)
{
//Uninstall_Hook(QueryBox_ctor);
Uninstall_Hook(GameUI_Panel_Init);
Uninstall_Hook(CGameConsoleDialog_ctor);
Uninstall_Hook(CCreateMultiplayerGameDialog_ctor);
Uninstall_Hook(COptionsDialog_ctor);
Uninstall_Hook(COptionsSubVideo_ctor);
Expand Down
18 changes: 0 additions & 18 deletions Plugins/CaptionMod/exportfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ void IN_Accumulate(void);
void CL_CreateMove(float frametime, struct usercmd_s *cmd, int active);

client_textmessage_t *pfnTextMessageGet(const char *pName);
void Client_FillAddress(void);
void Client_InstallHooks(void);
void Client_UninstallHooks(void);
void SDL2_FillAddress(void);
void Engine_FillAddress(void);
void Engine_InstallHooks(void);
void Engine_UninstallHooks(void);
void BaseUI_InstallHook(void);
void GameUI_InstallHooks(void);
void GameUI_UninstallHooks(void);
void ClientVGUI_InstallHook(cl_exportfuncs_t* pExportFunc);
void ClientVGUI_Shutdown(void);
void VGUI1_InstallHook(void);
void VGUI1_Shutdown(void);
void Surface_InstallHooks(void);
void Surface_UninstallHooks(void);
void Scheme_InstallHooks(void);
void KeyValuesSystem_InstallHook(void);

void *NewClientFactory(void);

Expand Down
1 change: 1 addition & 0 deletions Plugins/CaptionMod/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void IPluginsV4::ExitGame(int iResult)
{
VGUI1_Shutdown();

BaseUI_UninstallHook();
Engine_UninstallHooks();
}

Expand Down
23 changes: 22 additions & 1 deletion Plugins/CaptionMod/privatefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ typedef struct
PVOID (*VGUIClient001_CreateInterface)(HINTERFACEMODULE hModule);

//GameUI
void(__fastcall* GameUI_Panel_Init)(void* pthis, int dummy, int x, int y, int w, int h);
void(__fastcall* GameUI_LoadControlSettings)(void* pthis, int dummy, const char* controlResourceName, const char* pathID);
void * (__fastcall* QueryBox_ctor)(void* pthis, int dummy, const char* title, const char* queryText, void* parent);
void* (__fastcall* CCreateMultiplayerGameDialog_ctor)(void* pthis, int dummy, void* parent);
void* (__fastcall* CGameConsoleDialog_ctor)(void* pthis, int dummy);
void *(__fastcall*COptionsDialog_ctor)(void *pthis, int dummy, void *parent);
void *(__fastcall*COptionsSubVideo_ctor)(void *pthis, int dummy, void *parent);
void(__fastcall *COptionsSubVideo_ApplyVidSettings)(void *pthis, int dummy, bool bForceRestart);
Expand Down Expand Up @@ -119,4 +121,23 @@ cl_entity_t *EngineGetViewEntity(void);

bool SCR_IsLoadingVisible(void);

PVOID VGUI2_FindPanelInit(PVOID TextBase, ULONG TextSize);
PVOID VGUI2_FindPanelInit(PVOID TextBase, ULONG TextSize);
void Client_FillAddress(void);
void Client_InstallHooks(void);
void Client_UninstallHooks(void);
void SDL2_FillAddress(void);
void Engine_FillAddress(void);
void Engine_InstallHooks(void);
void Engine_UninstallHooks(void);
void BaseUI_InstallHook(void);
void BaseUI_UninstallHook(void);
void GameUI_InstallHooks(void);
void GameUI_UninstallHooks(void);
void ClientVGUI_InstallHook(cl_exportfuncs_t* pExportFunc);
void ClientVGUI_Shutdown(void);
void VGUI1_InstallHook(void);
void VGUI1_Shutdown(void);
void Surface_InstallHooks(void);
void Surface_UninstallHooks(void);
void Scheme_InstallHooks(void);
void KeyValuesSystem_InstallHook(void);
2 changes: 2 additions & 0 deletions scripts/install-helper-CopyBuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ if "%LauncherMod%"=="svencoop" (
if "%GameSDL2_fileVersion%"=="2, 0, 20, 0" (

mkdir "%GameDir%\%LauncherMod%_hidpi\"
xcopy "%SolutionDir%Build\svencoop_hidpi" "%GameDir%\%LauncherMod%_hidpi\" /y /e
xcopy "%SolutionDir%Build\valve_hl25_hidpi" "%GameDir%\%LauncherMod%_hidpi\" /y /e

) else (

mkdir "%GameDir%\%LauncherMod%_hidpi\"
xcopy "%SolutionDir%Build\svencoop_hidpi" "%GameDir%\%LauncherMod%_hidpi\" /y /e
xcopy "%SolutionDir%Build\valve_hidpi" "%GameDir%\%LauncherMod%_hidpi\" /y /e

)
Expand Down

0 comments on commit a682c88

Please sign in to comment.