Hook IBaseUI function.
1 #include <metahook.h> 2 3 #include <IBaseUI.h> 4 5 IBaseUI *g_pBaseUI = 0; 6 7 void (__fastcall *g_pfnCBaseUI_Initialize)(void *pthis, int edx, CreateInterfaceFn *factories, int count) = 0; 8 void (__fastcall *g_pfnCBaseUI_Start)(void *pthis, int edx, struct cl_enginefuncs_s *engineFuncs, int interfaceVersion) = 0; 9 void (__fastcall *g_pfnCBaseUI_Shutdown)(void *pthis, int edx) = 0; 10 int (__fastcall *g_pfnCBaseUI_Key_Event)(void *pthis, int edx, int down, int keynum, const char *pszCurrentBinding) = 0; 11 void (__fastcall *g_pfnCBaseUI_CallEngineSurfaceProc)(void *pthis, int edx, void *hwnd, unsigned int msg, unsigned int wparam, long lparam) = 0; 12 void (__fastcall *g_pfnCBaseUI_Paint)(void *pthis, int edx, int x, int y, int right, int bottom) = 0; 13 void (__fastcall *g_pfnCBaseUI_HideGameUI)(void *pthis, int edx) = 0; 14 void (__fastcall *g_pfnCBaseUI_ActivateGameUI)(void *pthis, int edx) = 0; 15 bool (__fastcall *g_pfnCBaseUI_IsGameUIVisible)(void *pthis, int edx) = 0; 16 void (__fastcall *g_pfnCBaseUI_HideConsole)(void *pthis, int edx) = 0; 17 void (__fastcall *g_pfnCBaseUI_ShowConsole)(void *pthis, int edx) = 0; 18 19 class CBaseUI : public IBaseUI 20 { 21 public: 22 void Initialize(CreateInterfaceFn *factories, int count); 23 void Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion); 24 void Shutdown(void); 25 int Key_Event(int down, int keynum, const char *pszCurrentBinding); 26 void CallEngineSurfaceProc(void *hwnd, unsigned int msg, unsigned int wparam, long lparam); 27 void Paint(int x, int y, int right, int bottom); 28 void HideGameUI(void); 29 void ActivateGameUI(void); 30 bool IsGameUIVisible(void); 31 void HideConsole(void); 32 void ShowConsole(void); 33 }; 34 35 void CBaseUI::Initialize(CreateInterfaceFn *factories, int count) 36 { 37 return g_pfnCBaseUI_Initialize(this, 0, factories, count); 38 } 39 40 void CBaseUI::Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion) 41 { 42 return g_pfnCBaseUI_Start(this, 0, engineFuncs, interfaceVersion); 43 } 44 45 void CBaseUI::Shutdown(void) 46 { 47 return g_pfnCBaseUI_Shutdown(this, 0); 48 } 49 50 int CBaseUI::Key_Event(int down, int keynum, const char *pszCurrentBinding) 51 { 52 return g_pfnCBaseUI_Key_Event(this, 0, down, keynum, pszCurrentBinding); 53 } 54 55 void CBaseUI::CallEngineSurfaceProc(void *hwnd, unsigned int msg, unsigned int wparam, long lparam) 56 { 57 return g_pfnCBaseUI_CallEngineSurfaceProc(this, 0, hwnd, msg, wparam, lparam); 58 } 59 60 void CBaseUI::Paint(int x, int y, int right, int bottom) 61 { 62 return g_pfnCBaseUI_Paint(this, 0, x, y, right, bottom); 63 } 64 65 void CBaseUI::HideGameUI(void) 66 { 67 return g_pfnCBaseUI_HideGameUI(this, 0); 68 } 69 70 void CBaseUI::ActivateGameUI(void) 71 { 72 return g_pfnCBaseUI_ActivateGameUI(this, 0); 73 } 74 75 bool CBaseUI::IsGameUIVisible(void) 76 { 77 return g_pfnCBaseUI_IsGameUIVisible(this, 0); 78 } 79 80 void CBaseUI::HideConsole(void) 81 { 82 return g_pfnCBaseUI_HideConsole(this, 0); 83 } 84 85 void CBaseUI::ShowConsole(void) 86 { 87 return g_pfnCBaseUI_ShowConsole(this, 0); 88 } 89 90 void BaseUI_InstallHook(void) 91 { 92 CreateInterfaceFn EngineCreateInterface = g_pMetaHookAPI->GetEngineFactory(); 93 g_pBaseUI = (IBaseUI *)EngineCreateInterface(BASEUI_INTERFACE_VERSION, 0); 94 95 CBaseUI BaseUI; 96 DWORD *pVFTable = *(DWORD **)&BaseUI; 97 98 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 1, (void *)pVFTable[ 1], (void *&)g_pfnCBaseUI_Initialize); 99 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 2, (void *)pVFTable[ 2], (void *&)g_pfnCBaseUI_Start); 100 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 3, (void *)pVFTable[ 3], (void *&)g_pfnCBaseUI_Shutdown); 101 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 4, (void *)pVFTable[ 4], (void *&)g_pfnCBaseUI_Key_Event); 102 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 5, (void *)pVFTable[ 5], (void *&)g_pfnCBaseUI_CallEngineSurfaceProc); 103 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 6, (void *)pVFTable[ 6], (void *&)g_pfnCBaseUI_Paint); 104 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 7, (void *)pVFTable[ 7], (void *&)g_pfnCBaseUI_HideGameUI); 105 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 8, (void *)pVFTable[ 8], (void *&)g_pfnCBaseUI_ActivateGameUI); 106 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 9, (void *)pVFTable[ 9], (void *&)g_pfnCBaseUI_IsGameUIVisible); 107 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 10, (void *)pVFTable[10], (void *&)g_pfnCBaseUI_HideConsole); 108 g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 11, (void *)pVFTable[11], (void *&)g_pfnCBaseUI_ShowConsole); 109 }
时间: 2024-10-12 02:21:15