Advertisement
Guest User

Untitled

a guest
Dec 8th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. #include "Hook.h"
  2.  
  3. //[enc_string_enable /]
  4. //[junk_enable /]
  5.  
  6. namespace Engine
  7. {
  8. namespace Hook
  9. {
  10. vfunc_hook panel;
  11. vfunc_hook client;
  12. vfunc_hook clientmode;
  13. vfunc_hook modelrender;
  14. vfunc_hook sound;
  15. vfunc_hook surface;
  16. vfunc_hook eventmanager;
  17. vfunc_hook device;
  18. IDirect3DDevice9* g_pDevice = nullptr;
  19.  
  20. typedef HRESULT(WINAPI* Present_t)(IDirect3DDevice9* pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion);
  21. Present_t Present_o;
  22.  
  23. typedef HRESULT(WINAPI* Reset_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
  24. Reset_t Reset_o;
  25.  
  26. HRESULT WINAPI Hook_Present(IDirect3DDevice9* pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
  27. {
  28. Client::OnRender();
  29.  
  30. return Present_o(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
  31. }
  32. void __stdcall Hook_Reset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
  33. {
  34. static auto ofunc = device.get_original<ResetHook>(D3D9::TABLE::Reset);
  35. ofunc(pDevice, pPresentationParameters);
  36. Client::OnLostDevice();
  37. HRESULT hRes = Reset_o(pDevice, pPresentationParameters);
  38. Client::OnResetDevice();
  39. }
  40.  
  41. void __stdcall Hook_CreateMove(float flInputSampleTime, CUserCmd* pCmd)
  42. {
  43. static auto ofunc = clientmode.get_original<CreateMove>(TABLE::IClientMode::CreateMove);
  44. ofunc(Interfaces::ClientMode(), flInputSampleTime, pCmd);
  45. Client::OnCreateMove(pCmd);
  46. }
  47.  
  48. void __fastcall Hook_OverrideView(CViewSetup* pSetup)
  49. {
  50. static auto ofunc = clientmode.get_original<GetFov>(TABLE::IClientMode::OverrideView);
  51. Client::OnOverrideView(pSetup);
  52. ofunc(pSetup);
  53. }
  54. float __stdcall Hook_GetViewModelFOV()
  55. {
  56. //i dont need that
  57. return 0;
  58. }
  59.  
  60. bool __fastcall Hook_FireEventClientSideThink(void* ecx, void* edx, IGameEvent* pEvent)
  61. {
  62. static auto ofunc = eventmanager.get_original<GameEvent>(TABLE::IGameEventManager2::FireEventClientSide);
  63. if (!pEvent)
  64. return ofunc(ecx, pEvent);
  65. Client::OnFireEventClientSideThink(pEvent);
  66. return ofunc(ecx, pEvent);
  67. }
  68.  
  69. void __stdcall Hook_FrameStageNotify(ClientFrameStage_t stage)
  70. {
  71. static auto ofunc = client.get_original<FrameStageNotify>(TABLE::IBaseClientDLL::FrameStageNotify);
  72. ofunc(Interfaces::Client(), stage);
  73. Skin_OnFrameStageNotify(stage);
  74. Gloves_OnFrameStageNotify(stage);
  75. }
  76.  
  77. void __stdcall Hook_EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSoundEntry, unsigned int nSoundEntryHash, const char *pSample,
  78. float flVolume, soundlevel_t iSoundlevel, int nSeed, int iFlags = 0, int iPitch = PITCH_NORM,
  79. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1, int test = 0)
  80. {
  81. auto oEmitsound = sound.get_original<EmitsoundXD>(TABLE::IEngineSound::EmitSound1);
  82. if (pSample && Client::g_pPlayers->GetPlayer(iEntIndex)->Team != Client::g_pPlayers->GetLocal()->Team)
  83. {
  84. Client::OnPlaySound(pOrigin, pSample);
  85. }
  86. return oEmitsound(filter, iEntIndex, iChannel, pSoundEntry, nSoundEntryHash, pSample,
  87. flVolume, iSoundlevel, nSeed, iFlags, iPitch,
  88. pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity, 0);
  89.  
  90.  
  91. }
  92. void __stdcall Hook_EmitSound2(IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSoundEntry, unsigned int nSoundEntryHash, const char *pSample,
  93. float flVolume, soundlevel_t iSoundlevel, int nSeed, int iFlags = 0, int iPitch = PITCH_NORM,
  94. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1, int test = 0)
  95. {
  96. auto oEmitsound = sound.get_original<EmitsoundXD>(TABLE::IEngineSound::EmitSound2);
  97. if (pSample && Client::g_pPlayers->GetPlayer(iEntIndex)->Team != Client::g_pPlayers->GetLocal()->Team)
  98. {
  99. Client::OnPlaySound(pOrigin, pSample);
  100. }
  101. return oEmitsound(filter, iEntIndex, iChannel, pSoundEntry, nSoundEntryHash, pSample,
  102. flVolume, iSoundlevel, nSeed, iFlags, iPitch,
  103. pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity, 0);
  104.  
  105.  
  106. }
  107.  
  108. void __fastcall Hook_DrawModelExecute(IMatRenderContext* ctx, const DrawModelState_t &state, const ModelRenderInfo_t &pInfo, matrix3x4_t *pCustomBoneToWorld)
  109. {
  110. // you need to rewrite chams or find some online
  111. }
  112.  
  113. void __stdcall Hook_PlaySound(const char* pszSoundName)
  114. {
  115. static auto ofunc = surface.get_original<PlaySound>(TABLE::ISurface::PlaySound);
  116. ofunc(Interfaces::Surface(), pszSoundName);
  117. if (pszSoundName)
  118. Client::OnPlaySound(pszSoundName);
  119. }
  120. bool Initialize()
  121. {
  122. if (!CSX::Utils::IsModuleLoad(D3D9_DLL))
  123. return false;
  124.  
  125. if (!CSX::Utils::IsModuleLoad(SHADERPIDX9_DLL))
  126. return false;
  127.  
  128. if (!CSX::Utils::IsModuleLoad(GAMEOVERLAYRENDERER_DLL))
  129. return false;
  130.  
  131. DWORD d3d9TablePtrPtr = CSX::Memory::FindPattern(SHADERPIDX9_DLL, D3D9_PATTERN, D3D9_MASK, 1);
  132. DWORD_PTR** dwPresent_o = (DWORD_PTR**)CSX::Memory::FindPattern(GAMEOVERLAYRENDERER_DLL, GMOR_PATTERN, GMOR_MASK, 1);
  133.  
  134. if (d3d9TablePtrPtr && dwPresent_o)
  135. {
  136. g_pDevice = (IDirect3DDevice9*)(**(PDWORD*)d3d9TablePtrPtr);
  137.  
  138. if (device.setup(g_pDevice))
  139. {
  140. //all undetect and rewrite
  141. DWORD_PTR* dwAddress = *dwPresent_o;
  142. Present_o = (Present_t)(*dwAddress);
  143. *dwAddress = (DWORD_PTR)(&Hook_Present);
  144.  
  145. device.hook_index(D3D9::TABLE::Reset, Hook_Reset);
  146. //Reset_o = (Reset_t)device.get_original(D3D9::TABLE::Reset);
  147.  
  148. if (!clientmode.setup(Interfaces::ClientMode()))
  149. return false;
  150.  
  151. clientmode.hook_index(TABLE::IClientMode::CreateMove, Hook_CreateMove);
  152. clientmode.hook_index(TABLE::IClientMode::OverrideView, Hook_OverrideView);
  153. clientmode.hook_index(TABLE::IClientMode::GetViewModelFOV, Hook_GetViewModelFOV);
  154.  
  155. if (!eventmanager.setup(Interfaces::GameEvent()))
  156. return false;
  157.  
  158. eventmanager.hook_index(TABLE::IGameEventManager2::FireEventClientSide, Hook_FireEventClientSideThink);
  159.  
  160. if (!client.setup(Interfaces::Client()))
  161. return false;
  162.  
  163. client.hook_index(TABLE::IBaseClientDLL::FrameStageNotify, Hook_FrameStageNotify);
  164.  
  165. if (!sound.setup(Interfaces::Sound()))
  166. return false;
  167.  
  168. sound.hook_index(TABLE::IEngineSound::EmitSound1, Hook_EmitSound);
  169.  
  170. //if (!modelrender.setup(Interfaces::ModelRender()))
  171. // return false;
  172. // dont like chams so shit
  173. //modelrender.hook_index(TABLE::IVModelRender::DrawModelExecute, Hook_DrawModelExecute);
  174.  
  175. if (!surface.setup(Interfaces::Surface()))
  176. return false;
  177.  
  178. surface.hook_index(TABLE::ISurface::PlaySound, Hook_PlaySound);
  179.  
  180. if (Client::Initialize(g_pDevice))
  181. return true;
  182. //all works
  183. }
  184. }
  185.  
  186. return false;
  187. }
  188.  
  189. void Shutdown()
  190. {
  191. device.unhook_all();
  192. sound.unhook_all();
  193. clientmode.unhook_all();
  194. eventmanager.unhook_all();
  195. modelrender.unhook_all();
  196. client.unhook_all();
  197. }
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement