Hook GameUI function.
1 #include <metahook.h> 2 3 #include <IGameUI.h> 4 5 IGameUI *g_pGameUI = 0; 6 7 void (__fastcall *g_pfnCGameUI_Initialize)(void *pthis, int edx, CreateInterfaceFn *factories, int count) = 0; 8 void (__fastcall *g_pfnCGameUI_Start)(void *pthis, int edx, struct cl_enginefuncs_s *engineFuncs, int interfaceVersion, void *system) = 0; 9 void (__fastcall *g_pfnCGameUI_Shutdown)(void *pthis, int edx) = 0; 10 int (__fastcall *g_pfnCGameUI_ActivateGameUI)(void *pthis, int edx) = 0; 11 int (__fastcall *g_pfnCGameUI_ActivateDemoUI)(void *pthis, int edx) = 0; 12 int (__fastcall *g_pfnCGameUI_HasExclusiveInput)(void *pthis, int edx) = 0; 13 void (__fastcall *g_pfnCGameUI_RunFrame)(void *pthis, int edx) = 0; 14 void (__fastcall *g_pfnCGameUI_ConnectToServer)(void *pthis, int edx, const char *game, int IP, int port) = 0; 15 void (__fastcall *g_pfnCGameUI_DisconnectFromServer)(void *pthis, int edx) = 0; 16 void (__fastcall *g_pfnCGameUI_HideGameUI)(void *pthis, int edx) = 0; 17 bool (__fastcall *g_pfnCGameUI_IsGameUIActive)(void *pthis, int edx) = 0; 18 void (__fastcall *g_pfnCGameUI_LoadingStarted)(void *pthis, int edx, const char *resourceType, const char *resourceName) = 0; 19 void (__fastcall *g_pfnCGameUI_LoadingFinished)(void *pthis, int edx, const char *resourceType, const char *resourceName) = 0; 20 void (__fastcall *g_pfnCGameUI_StartProgressBar)(void *pthis, int edx, const char *progressType, int progressSteps) = 0; 21 int (__fastcall *g_pfnCGameUI_ContinueProgressBar)(void *pthis, int edx, int progressPoint, float progressFraction) = 0; 22 void (__fastcall *g_pfnCGameUI_StopProgressBar)(void *pthis, int edx, bool bError, const char *failureReason, const char *extendedReason) = 0; 23 int (__fastcall *g_pfnCGameUI_SetProgressBarStatusText)(void *pthis, int edx, const char *statusText) = 0; 24 void (__fastcall *g_pfnCGameUI_SetSecondaryProgressBar)(void *pthis, int edx, float progress) = 0; 25 void (__fastcall *g_pfnCGameUI_SetSecondaryProgressBarText)(void *pthis, int edx, const char *statusText) = 0; 26 27 class CGameUI : public IGameUI 28 { 29 public: 30 void Initialize(CreateInterfaceFn *factories, int count); 31 void Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion, void *system); 32 void Shutdown(void); 33 int ActivateGameUI(void); 34 int ActivateDemoUI(void); 35 int HasExclusiveInput(void); 36 void RunFrame(void); 37 void ConnectToServer(const char *game, int IP, int port); 38 void DisconnectFromServer(void); 39 void HideGameUI(void); 40 bool IsGameUIActive(void); 41 void LoadingStarted(const char *resourceType, const char *resourceName); 42 void LoadingFinished(const char *resourceType, const char *resourceName); 43 void StartProgressBar(const char *progressType, int progressSteps); 44 int ContinueProgressBar(int progressPoint, float progressFraction); 45 void StopProgressBar(bool bError, const char *failureReason, const char *extendedReason = NULL); 46 int SetProgressBarStatusText(const char *statusText); 47 void SetSecondaryProgressBar(float progress); 48 void SetSecondaryProgressBarText(const char *statusText); 49 }; 50 51 void CGameUI::Initialize(CreateInterfaceFn *factories, int count) 52 { 53 return g_pfnCGameUI_Initialize(this, 0, factories, count); 54 } 55 56 void CGameUI::Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion, void *system) 57 { 58 return g_pfnCGameUI_Start(this, 0, engineFuncs, interfaceVersion, system); 59 } 60 61 void CGameUI::Shutdown(void) 62 { 63 return g_pfnCGameUI_Shutdown(this, 0); 64 } 65 66 int CGameUI::ActivateGameUI(void) 67 { 68 return g_pfnCGameUI_ActivateGameUI(this, 0); 69 } 70 71 int CGameUI::ActivateDemoUI(void) 72 { 73 return g_pfnCGameUI_ActivateDemoUI(this, 0); 74 } 75 76 int CGameUI::HasExclusiveInput(void) 77 { 78 return g_pfnCGameUI_HasExclusiveInput(this, 0); 79 } 80 81 void CGameUI::RunFrame(void) 82 { 83 return g_pfnCGameUI_RunFrame(this, 0); 84 } 85 86 void CGameUI::ConnectToServer(const char *game, int IP, int port) 87 { 88 return g_pfnCGameUI_ConnectToServer(this, 0, game, IP, port); 89 } 90 91 void CGameUI::DisconnectFromServer(void) 92 { 93 return g_pfnCGameUI_DisconnectFromServer(this, 0); 94 } 95 96 void CGameUI::HideGameUI(void) 97 { 98 return g_pfnCGameUI_HideGameUI(this, 0); 99 } 100 101 bool CGameUI::IsGameUIActive(void) 102 { 103 return g_pfnCGameUI_IsGameUIActive(this, 0); 104 } 105 106 void CGameUI::LoadingStarted(const char *resourceType, const char *resourceName) 107 { 108 return g_pfnCGameUI_LoadingStarted(this, 0, resourceType, resourceName); 109 } 110 111 void CGameUI::LoadingFinished(const char *resourceType, const char *resourceName) 112 { 113 return g_pfnCGameUI_LoadingFinished(this, 0, resourceType, resourceName); 114 } 115 116 void CGameUI::StartProgressBar(const char *progressType, int progressSteps) 117 { 118 return g_pfnCGameUI_StartProgressBar(this, 0, progressType, progressSteps); 119 } 120 121 int CGameUI::ContinueProgressBar(int progressPoint, float progressFraction) 122 { 123 return g_pfnCGameUI_ContinueProgressBar(this, 0, progressPoint, progressFraction); 124 } 125 126 void CGameUI::StopProgressBar(bool bError, const char *failureReason, const char *extendedReason) 127 { 128 return g_pfnCGameUI_StopProgressBar(this, 0, bError, failureReason, extendedReason); 129 } 130 131 int CGameUI::SetProgressBarStatusText(const char *statusText) 132 { 133 return g_pfnCGameUI_SetProgressBarStatusText(this, 0, statusText); 134 } 135 136 void CGameUI::SetSecondaryProgressBar(float progress) 137 { 138 return g_pfnCGameUI_SetSecondaryProgressBar(this, 0, progress); 139 } 140 141 void CGameUI::SetSecondaryProgressBarText(const char *statusText) 142 { 143 return g_pfnCGameUI_SetSecondaryProgressBarText(this, 0, statusText); 144 } 145 146 void GameUI_InstallHook(void) 147 { 148 CreateInterfaceFn GameUICreateInterface = Sys_GetFactory((HINTERFACEMODULE)GetModuleHandleA("GameUI.dll")); 149 g_pGameUI = (IGameUI *)GameUICreateInterface(GAMEUI_INTERFACE_VERSION, 0); 150 151 CGameUI GameUI; 152 DWORD *pVFTable = *(DWORD **)&GameUI; 153 154 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 1, (void *)pVFTable[ 1], (void *&)g_pfnCGameUI_Initialize); 155 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 2, (void *)pVFTable[ 2], (void *&)g_pfnCGameUI_Start); 156 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 3, (void *)pVFTable[ 3], (void *&)g_pfnCGameUI_Shutdown); 157 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 4, (void *)pVFTable[ 4], (void *&)g_pfnCGameUI_ActivateGameUI); 158 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 5, (void *)pVFTable[ 5], (void *&)g_pfnCGameUI_ActivateDemoUI); 159 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 6, (void *)pVFTable[ 6], (void *&)g_pfnCGameUI_HasExclusiveInput); 160 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 7, (void *)pVFTable[ 7], (void *&)g_pfnCGameUI_RunFrame); 161 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 8, (void *)pVFTable[ 8], (void *&)g_pfnCGameUI_ConnectToServer); 162 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 9, (void *)pVFTable[ 9], (void *&)g_pfnCGameUI_DisconnectFromServer); 163 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 10, (void *)pVFTable[10], (void *&)g_pfnCGameUI_HideGameUI); 164 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 11, (void *)pVFTable[11], (void *&)g_pfnCGameUI_IsGameUIActive); 165 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 12, (void *)pVFTable[12], (void *&)g_pfnCGameUI_LoadingStarted); 166 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 13, (void *)pVFTable[13], (void *&)g_pfnCGameUI_LoadingFinished); 167 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 14, (void *)pVFTable[14], (void *&)g_pfnCGameUI_StartProgressBar); 168 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 15, (void *)pVFTable[15], (void *&)g_pfnCGameUI_ContinueProgressBar); 169 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 16, (void *)pVFTable[16], (void *&)g_pfnCGameUI_StopProgressBar); 170 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 17, (void *)pVFTable[17], (void *&)g_pfnCGameUI_SetProgressBarStatusText); 171 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 18, (void *)pVFTable[18], (void *&)g_pfnCGameUI_SetSecondaryProgressBar); 172 g_pMetaHookAPI->VFTHook(g_pGameUI, 0, 19, (void *)pVFTable[19], (void *&)g_pfnCGameUI_SetSecondaryProgressBarText); 173 }