请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站

ESFKAMI

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

ESFX

ESF: Xenoverse

ESF123

ESF1.2.3

EVM2.1

EVM2.1

ECXSSJ

ECX: TeamSSJ

ECX2.2

ECX RC2

ECX2.3

ECX RC3

查看: 335|回复: 0

[MetaHook]BaseUI Hook

[复制链接]

206

主题

211

帖子

975

积分

ESFKAMI

Rank: 8Rank: 8

积分
975
发表于 2017-7-14 16:45:18 | 显示全部楼层 |阅读模式

Thanks to Akatsuki

Remember to call "BaseUI_InstallHook" while loading client


IBaseUI.h

  1. #ifndef IBASEUI_H
  2. #define IBASEUI_H

  3. #ifdef _WIN32
  4. #pragma once
  5. #endif

  6. #include "interface.h"

  7. struct cl_enginefuncs_s;
  8. class IBaseSystem;

  9. namespace vgui2
  10. {
  11. class Panel;
  12. }

  13. class IBaseUI : public IBaseInterface
  14. {
  15. public:
  16.         virtual void Initialize(CreateInterfaceFn *factories, int count) = 0;
  17.         virtual void Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion) = 0;
  18.         virtual void Shutdown(void) = 0;
  19.         virtual int Key_Event(int down, int keynum, const char *pszCurrentBinding) = 0;
  20.         virtual void CallEngineSurfaceProc(void *hwnd, unsigned int msg, unsigned int wparam, long lparam) = 0;
  21.         virtual void Paint(int x, int y, int right, int bottom) = 0;
  22.         virtual void HideGameUI(void) = 0;
  23.         virtual void ActivateGameUI(void) = 0;
  24.         virtual bool IsGameUIVisible(void) = 0;
  25.         virtual void HideConsole(void) = 0;
  26.         virtual void ShowConsole(void) = 0;
  27. };

  28. #define BASEUI_INTERFACE_VERSION "BaseUI001"
  29. #endif

  30. void BaseUI_InstallHook(void);
复制代码
BaseUI.cpp

  1. #include <metahook.h>

  2. #include <IBaseUI.h>

  3. IBaseUI *g_pBaseUI = 0;

  4. void (__fastcall *g_pfnCBaseUI_Initialize)(void *pthis, int edx, CreateInterfaceFn *factories, int count) = 0;
  5. void (__fastcall *g_pfnCBaseUI_Start)(void *pthis, int edx, struct cl_enginefuncs_s *engineFuncs, int interfaceVersion) = 0;
  6. void (__fastcall *g_pfnCBaseUI_Shutdown)(void *pthis, int edx) = 0;
  7. int (__fastcall *g_pfnCBaseUI_Key_Event)(void *pthis, int edx, int down, int keynum, const char *pszCurrentBinding) = 0;
  8. void (__fastcall *g_pfnCBaseUI_CallEngineSurfaceProc)(void *pthis, int edx, void *hwnd, unsigned int msg, unsigned int wparam, long lparam) = 0;
  9. void (__fastcall *g_pfnCBaseUI_Paint)(void *pthis, int edx, int x, int y, int right, int bottom) = 0;
  10. void (__fastcall *g_pfnCBaseUI_HideGameUI)(void *pthis, int edx) = 0;
  11. void (__fastcall *g_pfnCBaseUI_ActivateGameUI)(void *pthis, int edx) = 0;
  12. bool (__fastcall *g_pfnCBaseUI_IsGameUIVisible)(void *pthis, int edx) = 0;
  13. void (__fastcall *g_pfnCBaseUI_HideConsole)(void *pthis, int edx) = 0;
  14. void (__fastcall *g_pfnCBaseUI_ShowConsole)(void *pthis, int edx) = 0;

  15. class CBaseUI : public IBaseUI
  16. {
  17. public:
  18.     void Initialize(CreateInterfaceFn *factories, int count);
  19.     void Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion);
  20.     void Shutdown(void);
  21.     int Key_Event(int down, int keynum, const char *pszCurrentBinding);
  22.     void CallEngineSurfaceProc(void *hwnd, unsigned int msg, unsigned int wparam, long lparam);
  23.     void Paint(int x, int y, int right, int bottom);
  24.     void HideGameUI(void);
  25.     void ActivateGameUI(void);
  26.     bool IsGameUIVisible(void);
  27.     void HideConsole(void);
  28.     void ShowConsole(void);
  29. };

  30. void CBaseUI::Initialize(CreateInterfaceFn *factories, int count)
  31. {
  32.     return g_pfnCBaseUI_Initialize(this, 0, factories, count);
  33. }

  34. void CBaseUI::Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion)
  35. {
  36.     return g_pfnCBaseUI_Start(this, 0, engineFuncs, interfaceVersion);
  37. }

  38. void CBaseUI::Shutdown(void)
  39. {
  40.     return g_pfnCBaseUI_Shutdown(this, 0);
  41. }

  42. int CBaseUI::Key_Event(int down, int keynum, const char *pszCurrentBinding)
  43. {
  44.     return g_pfnCBaseUI_Key_Event(this, 0, down, keynum, pszCurrentBinding);
  45. }

  46. void CBaseUI::CallEngineSurfaceProc(void *hwnd, unsigned int msg, unsigned int wparam, long lparam)
  47. {
  48.     return g_pfnCBaseUI_CallEngineSurfaceProc(this, 0, hwnd, msg, wparam, lparam);
  49. }

  50. void CBaseUI::Paint(int x, int y, int right, int bottom)
  51. {
  52.     return g_pfnCBaseUI_Paint(this, 0, x, y, right, bottom);
  53. }

  54. void CBaseUI::HideGameUI(void)
  55. {
  56.     return g_pfnCBaseUI_HideGameUI(this, 0);
  57. }

  58. void CBaseUI::ActivateGameUI(void)
  59. {
  60.     return g_pfnCBaseUI_ActivateGameUI(this, 0);
  61. }

  62. bool CBaseUI::IsGameUIVisible(void)
  63. {
  64.     return g_pfnCBaseUI_IsGameUIVisible(this, 0);
  65. }

  66. void CBaseUI::HideConsole(void)
  67. {
  68.     return g_pfnCBaseUI_HideConsole(this, 0);
  69. }

  70. void CBaseUI::ShowConsole(void)
  71. {
  72.     return g_pfnCBaseUI_ShowConsole(this, 0);
  73. }

  74. void BaseUI_InstallHook(void)
  75. {
  76.     CreateInterfaceFn EngineCreateInterface = g_pMetaHookAPI->GetEngineFactory();
  77.     g_pBaseUI = (IBaseUI *)EngineCreateInterface(BASEUI_INTERFACE_VERSION, 0);

  78.     CBaseUI BaseUI;
  79.     DWORD *pVFTable = *(DWORD **)&BaseUI;

  80.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  1, (void *)pVFTable[ 1], (void *&)g_pfnCBaseUI_Initialize);
  81.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  2, (void *)pVFTable[ 2], (void *&)g_pfnCBaseUI_Start);
  82.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  3, (void *)pVFTable[ 3], (void *&)g_pfnCBaseUI_Shutdown);
  83.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  4, (void *)pVFTable[ 4], (void *&)g_pfnCBaseUI_Key_Event);
  84.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  5, (void *)pVFTable[ 5], (void *&)g_pfnCBaseUI_CallEngineSurfaceProc);
  85.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  6, (void *)pVFTable[ 6], (void *&)g_pfnCBaseUI_Paint);
  86.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  7, (void *)pVFTable[ 7], (void *&)g_pfnCBaseUI_HideGameUI);
  87.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  8, (void *)pVFTable[ 8], (void *&)g_pfnCBaseUI_ActivateGameUI);
  88.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0,  9, (void *)pVFTable[ 9], (void *&)g_pfnCBaseUI_IsGameUIVisible);
  89.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 10, (void *)pVFTable[10], (void *&)g_pfnCBaseUI_HideConsole);
  90.     g_pMetaHookAPI->VFTHook(g_pBaseUI, 0, 11, (void *)pVFTable[11], (void *&)g_pfnCBaseUI_ShowConsole);
  91. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|ESFKAMI    

GMT+8, 2018-1-20 07:03 , Processed in 0.233085 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表