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

ESFKAMI

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

ESFX

ESF: Xenoverse

ESF123

ESF1.2.3

EVM2.1

EVM2.1

ECXSSJ

ECX: TeamSSJ

ECX2.2

ECX RC2

ECX2.3

ECX RC3

查看: 334|回复: 0

[MetaHook]Input Hook

[复制链接]

206

主题

211

帖子

975

积分

ESFKAMI

Rank: 8Rank: 8

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

From CSBTE

Input.h:

  1. #include <VGUI\IInput.h>
  2. #include <VGUI\IInputInternal.h>

  3. extern vgui::IInputInternal *g_pInput;
  4. void Input_InstallHook(vgui::IInputInternal *pInput);
复制代码
Input.cpp:

  1. #include <metahook.h>
  2. #include "Input.h"
  3. #include "plugins.h"

  4. using namespace vgui;

  5. void (__fastcall *g_pfnInternalKeyTyped)(void *pthis, int, wchar_t unichar);

  6. class CInput : public IInputInternal
  7. {
  8. public:
  9.         virtual void SetMouseFocus(VPANEL newMouseFocus);
  10.         virtual void SetMouseCapture(VPANEL panel);
  11.         virtual void GetKeyCodeText(KeyCode code, char *buf, int buflen);
  12.         virtual VPANEL GetFocus(void);
  13.         virtual VPANEL GetMouseOver(void);
  14.         virtual void SetCursorPos(int x, int y);
  15.         virtual void GetCursorPos(int &x, int &y);
  16.         virtual bool WasMousePressed(MouseCode code);
  17.         virtual bool WasMouseDoublePressed(MouseCode code);
  18.         virtual bool IsMouseDown(MouseCode code);
  19.         virtual void SetCursorOveride(HCursor cursor);
  20.         virtual HCursor GetCursorOveride(void);
  21.         virtual bool WasMouseReleased(MouseCode code);
  22.         virtual bool WasKeyPressed(KeyCode code);
  23.         virtual bool IsKeyDown(KeyCode code);
  24.         virtual bool WasKeyTyped(KeyCode code);
  25.         virtual bool WasKeyReleased(KeyCode code);
  26.         virtual VPANEL GetAppModalSurface(void);
  27.         virtual void SetAppModalSurface(VPANEL panel);
  28.         virtual void ReleaseAppModalSurface(void);
  29.         virtual void GetCursorPosition(int &x, int &y);
  30.         virtual void RunFrame(void);
  31.         virtual void UpdateMouseFocus(int x, int y);
  32.         virtual void PanelDeleted(VPANEL panel);
  33.         virtual bool InternalCursorMoved(int x, int y);
  34.         virtual bool InternalMousePressed(MouseCode code);
  35.         virtual bool InternalMouseDoublePressed(MouseCode code);
  36.         virtual bool InternalMouseReleased(MouseCode code);
  37.         virtual bool InternalMouseWheeled(int delta);
  38.         virtual bool InternalKeyCodePressed(KeyCode code);
  39.         virtual void InternalKeyCodeTyped(KeyCode code);
  40.         virtual void InternalKeyTyped(wchar_t unichar);
  41.         virtual bool InternalKeyCodeReleased(KeyCode code);
  42.         virtual HInputContext CreateInputContext(void);
  43.         virtual void DestroyInputContext(HInputContext context);
  44.         virtual void AssociatePanelWithInputContext(HInputContext context, VPANEL pRoot);
  45.         virtual void ActivateInputContext(HInputContext context);
  46.         virtual VPANEL GetMouseCapture(void);
  47.         virtual bool IsChildOfModalPanel(VPANEL panel);
  48.         virtual void ResetInputContext(HInputContext context);
  49. };

  50. CInput g_Input;
  51. IInputInternal *g_pInput;

  52. void CInput::SetMouseFocus(VPANEL newMouseFocus)
  53. {
  54.         g_pInput->SetMouseFocus(newMouseFocus);
  55. }

  56. void CInput::SetMouseCapture(VPANEL panel)
  57. {
  58.         g_pInput->SetMouseCapture(panel);
  59. }

  60. void CInput::GetKeyCodeText(KeyCode code, char *buf, int buflen)
  61. {
  62.         g_pInput->GetKeyCodeText(code, buf, buflen);
  63. }

  64. VPANEL CInput::GetFocus(void)
  65. {
  66.         return g_pInput->GetFocus();
  67. }

  68. VPANEL CInput::GetMouseOver(void)
  69. {
  70.         return g_pInput->GetMouseOver();
  71. }

  72. void CInput::SetCursorPos(int x, int y)
  73. {
  74.         g_pInput->SetCursorPos(x, y);
  75. }

  76. void CInput::GetCursorPos(int &x, int &y)
  77. {
  78.         g_pInput->GetCursorPos(x, y);
  79. }

  80. bool CInput::WasMousePressed(MouseCode code)
  81. {
  82.         return g_pInput->WasMousePressed(code);
  83. }

  84. bool CInput::WasMouseDoublePressed(MouseCode code)
  85. {
  86.         return g_pInput->WasMouseDoublePressed(code);
  87. }

  88. bool CInput::IsMouseDown(MouseCode code)
  89. {
  90.         return g_pInput->IsMouseDown(code);
  91. }

  92. void CInput::SetCursorOveride(HCursor cursor)
  93. {
  94.         return g_pInput->SetCursorOveride(cursor);
  95. }

  96. HCursor CInput::GetCursorOveride(void)
  97. {
  98.         return g_pInput->GetCursorOveride();
  99. }

  100. bool CInput::WasMouseReleased(MouseCode code)
  101. {
  102.         return g_pInput->WasMouseReleased(code);
  103. }

  104. bool CInput::WasKeyPressed(KeyCode code)
  105. {
  106.         return g_pInput->WasKeyPressed(code);
  107. }

  108. bool CInput::IsKeyDown(KeyCode code)
  109. {
  110.         return g_pInput->IsKeyDown(code);
  111. }

  112. bool CInput::WasKeyTyped(KeyCode code)
  113. {
  114.         return g_pInput->WasKeyTyped(code);
  115. }

  116. bool CInput::WasKeyReleased(KeyCode code)
  117. {
  118.         return g_pInput->WasKeyReleased(code);
  119. }

  120. VPANEL CInput::GetAppModalSurface(void)
  121. {
  122.         return g_pInput->GetAppModalSurface();
  123. }

  124. void CInput::SetAppModalSurface(VPANEL panel)
  125. {
  126.         g_pInput->SetAppModalSurface(panel);
  127. }

  128. void CInput::ReleaseAppModalSurface(void)
  129. {
  130.         g_pInput->ReleaseAppModalSurface();
  131. }

  132. void CInput::GetCursorPosition(int &x, int &y)
  133. {
  134.         g_pInput->GetCursorPosition(x, y);
  135. }

  136. void CInput::RunFrame(void)
  137. {
  138.         g_pInput->RunFrame();
  139. }

  140. void CInput::UpdateMouseFocus(int x, int y)
  141. {
  142.         g_pInput->UpdateMouseFocus(x, y);
  143. }

  144. void CInput::PanelDeleted(VPANEL panel)
  145. {
  146.         g_pInput->PanelDeleted(panel);
  147. }

  148. bool CInput::InternalCursorMoved(int x, int y)
  149. {
  150.         return g_pInput->InternalCursorMoved(x, y);
  151. }

  152. bool CInput::InternalMousePressed(MouseCode code)
  153. {
  154.         return g_pInput->InternalMousePressed(code);
  155. }

  156. bool CInput::InternalMouseDoublePressed(MouseCode code)
  157. {
  158.         return g_pInput->InternalMouseDoublePressed(code);
  159. }

  160. bool CInput::InternalMouseReleased(MouseCode code)
  161. {
  162.         return g_pInput->InternalMouseReleased(code);
  163. }

  164. bool CInput::InternalMouseWheeled(int delta)
  165. {
  166.         return g_pInput->InternalMouseWheeled(delta);
  167. }

  168. bool CInput::InternalKeyCodePressed(KeyCode code)
  169. {
  170.         return g_pInput->InternalKeyCodePressed(code);
  171. }

  172. void CInput::InternalKeyCodeTyped(KeyCode code)
  173. {
  174.         g_pInput->InternalKeyCodeTyped(code);
  175. }

  176. void CInput::InternalKeyTyped(wchar_t unichar)
  177. {
  178.         g_pfnInternalKeyTyped(this, 0, unichar);
  179. }

  180. bool CInput::InternalKeyCodeReleased(KeyCode code)
  181. {
  182.         return g_pInput->InternalKeyCodeReleased(code);
  183. }

  184. HInputContext CInput::CreateInputContext(void)
  185. {
  186.         return g_pInput->CreateInputContext();
  187. }

  188. void CInput::DestroyInputContext(HInputContext context)
  189. {
  190.         g_pInput->DestroyInputContext(context);
  191. }

  192. void CInput::AssociatePanelWithInputContext(HInputContext context, VPANEL pRoot)
  193. {
  194.         g_pInput->AssociatePanelWithInputContext(context, pRoot);
  195. }

  196. void CInput::ActivateInputContext(HInputContext context)
  197. {
  198.         g_pInput->ActivateInputContext(context);
  199. }

  200. VPANEL CInput::GetMouseCapture(void)
  201. {
  202.         return g_pInput->GetMouseCapture();
  203. }

  204. bool CInput::IsChildOfModalPanel(VPANEL panel)
  205. {
  206.         return g_pInput->IsChildOfModalPanel(panel);
  207. }

  208. void CInput::ResetInputContext(HInputContext context)
  209. {
  210.         return g_pInput->ResetInputContext(context);
  211. }

  212. void Input_InstallHook(vgui::IInputInternal *pInput)
  213. {
  214.         DWORD *pVFTable = *(DWORD **)&g_Input;

  215.         g_pInput = pInput;

  216.         if (g_dwEngineBuildnum < 5953)
  217.         {
  218.                 g_pMetaHookAPI->VFTHook(pInput, 0, 32, (void *)pVFTable[32], (void *&)g_pfnInternalKeyTyped);
  219.         }
  220. }
复制代码
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|ESFKAMI    

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

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

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