Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. #include "Hook.h"
  2. #include "intrin.h"
  3. //[enc_string_enable /]
  4. //[junk_enable /]
  5.  
  6. CAimbot* g_Aim;
  7.  
  8. namespace Engine
  9. {
  10. namespace Hook
  11. {
  12. vfunc_hook panel;
  13. vfunc_hook client;
  14. vfunc_hook clientmode;
  15. vfunc_hook modelrender;
  16. vfunc_hook sound;
  17. vfunc_hook surface;
  18. vfunc_hook eventmanager;
  19. vfunc_hook device;
  20. vfunc_hook SteamGameCoordinatorTable;
  21. IDirect3DDevice9* g_pDevice = nullptr;
  22.  
  23.  
  24.  
  25. typedef HRESULT(WINAPI* Present_t)(IDirect3DDevice9* pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion);
  26. Present_t Present_o;
  27.  
  28. typedef HRESULT(WINAPI* Reset_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
  29. Reset_t Reset_o;
  30.  
  31. HRESULT WINAPI Hook_Present(IDirect3DDevice9* pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
  32. {
  33. Client::OnRender();
  34.  
  35. return Present_o(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
  36. }
  37.  
  38. void __stdcall Hook_Reset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
  39. {
  40. static auto ofunc = device.get_original<ResetHook>(D3D9::TABLE::Reset);
  41. ofunc(pDevice, pPresentationParameters);
  42. Client::OnLostDevice();
  43. HRESULT hRes = Reset_o(pDevice, pPresentationParameters);
  44. Client::OnResetDevice();
  45. }
  46.  
  47.  
  48. void __stdcall Hook_CreateMove(float flInputSampleTime, CUserCmd* pCmd)
  49. {
  50. static auto ofunc = clientmode.get_original<CreateMove>(TABLE::IClientMode::CreateMove);
  51. ofunc(Interfaces::ClientMode(), flInputSampleTime, pCmd);
  52. Client::OnCreateMove(pCmd);
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59. EGCResults __fastcall Hook_RetrieveMessage(void* ecx, void* edx, uint32_t *punMsgType, void *pubDest, uint32_t cubDest, uint32_t *pcubMsgSize)
  60. {
  61.  
  62. EGCResults status = Interfaces::SteamGameCoordinator()->RetrieveMessage(punMsgType, pubDest, cubDest, pcubMsgSize);
  63.  
  64.  
  65. if (status != k_EGCResultOK)
  66. return status;
  67.  
  68. Client::OnRetrieveMessage(ecx, edx, punMsgType, pubDest, cubDest, pcubMsgSize);
  69.  
  70. return status;
  71. }
  72.  
  73. EGCResults __fastcall Hook_SendMessage(void* ecx, void* edx, uint32_t unMsgType, const void* pubData, uint32_t cubData)
  74. {
  75. uint32_t messageType = unMsgType & 0x7FFFFFFF;
  76. void* pubDataMutable = const_cast<void*>(pubData);
  77.  
  78.  
  79. Client::OnSendMessage(ecx, edx, unMsgType, pubData, cubData);
  80.  
  81.  
  82. EGCResults status = Interfaces::SteamGameCoordinator()->SendMessage(unMsgType, pubData, cubData);
  83.  
  84.  
  85. return status;
  86. }
  87.  
  88.  
  89.  
  90. void __fastcall Hook_OverrideView(CViewSetup* pSetup)
  91. {
  92. static auto ofunc = clientmode.get_original<GetFov>(TABLE::IClientMode::OverrideView);
  93. Client::OnOverrideView(pSetup);
  94. ofunc(pSetup);
  95. }
  96.  
  97.  
  98.  
  99.  
  100. float __stdcall Hook_GetViewModelFOV()
  101. {
  102. //i dont need that
  103. return 0;
  104. }
  105.  
  106.  
  107.  
  108.  
  109. bool __fastcall Hook_FireEventClientSideThink(void* ecx, void* edx, IGameEvent* pEvent)
  110. {
  111. static auto ofunc = eventmanager.get_original<GameEvent>(TABLE::IGameEventManager2::FireEventClientSide);
  112. if (!pEvent)
  113. return ofunc(ecx, pEvent);
  114. Client::OnFireEventClientSideThink(pEvent);
  115. return ofunc(ecx, pEvent);
  116. }
  117.  
  118. void __stdcall Hook_FrameStageNotify(ClientFrameStage_t stage)
  119. {
  120. static auto ofunc = client.get_original<FrameStageNotify>(TABLE::IBaseClientDLL::FrameStageNotify);
  121. ofunc(Interfaces::Client(), stage);
  122. Skin_OnFrameStageNotify(stage);
  123. Gloves_OnFrameStageNotify(stage);
  124. }
  125.  
  126. void __stdcall Hook_EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSoundEntry, unsigned int nSoundEntryHash, const char *pSample,
  127. float flVolume, soundlevel_t iSoundlevel, int nSeed, int iFlags = 0, int iPitch = PITCH_NORM,
  128. 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)
  129. {
  130. auto oEmitsound = sound.get_original<EmitsoundXD>(TABLE::IEngineSound::EmitSound1);
  131. if (pSample && Client::g_pPlayers->GetPlayer(iEntIndex)->Team != Client::g_pPlayers->GetLocal()->Team)
  132. {
  133. Client::OnPlaySound(pOrigin, pSample);
  134. }
  135. return oEmitsound(filter, iEntIndex, iChannel, pSoundEntry, nSoundEntryHash, pSample,
  136. flVolume, iSoundlevel, nSeed, iFlags, iPitch,
  137. pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity, 0);
  138.  
  139.  
  140. }
  141. void __stdcall Hook_EmitSound2(IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSoundEntry, unsigned int nSoundEntryHash, const char *pSample,
  142. float flVolume, soundlevel_t iSoundlevel, int nSeed, int iFlags = 0, int iPitch = PITCH_NORM,
  143. 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)
  144. {
  145. auto oEmitsound = sound.get_original<EmitsoundXD>(TABLE::IEngineSound::EmitSound2);
  146. if (pSample && Client::g_pPlayers->GetPlayer(iEntIndex)->Team != Client::g_pPlayers->GetLocal()->Team)
  147. {
  148. Client::OnPlaySound(pOrigin, pSample);
  149. }
  150. return oEmitsound(filter, iEntIndex, iChannel, pSoundEntry, nSoundEntryHash, pSample,
  151. flVolume, iSoundlevel, nSeed, iFlags, iPitch,
  152. pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity, 0);
  153.  
  154.  
  155. }
  156.  
  157. void __fastcall Hook_DrawModelExecute(IMatRenderContext* ctx, const DrawModelState_t &state, const ModelRenderInfo_t &pInfo, matrix3x4_t *pCustomBoneToWorld)
  158. {
  159. // i dont like chams and other shit, use box or maybe you can write this forself... THIS IS FROM AZOR. WRITE YOUR OWN MODELS
  160. }
  161.  
  162. void __stdcall Hook_PlaySound(const char* pszSoundName)
  163. {
  164. static auto ofunc = surface.get_original<PlaySound>(TABLE::ISurface::PlaySound);
  165. ofunc(Interfaces::Surface(), pszSoundName);
  166. if (pszSoundName)
  167. Client::OnPlaySound(pszSoundName);
  168. }
  169.  
  170. bool SendClientHello()
  171. {
  172. CMsgClientHello Message;
  173.  
  174. Message.set_client_session_need(1);
  175. Message.clear_socache_have_versions();
  176.  
  177. void* ptr = malloc(Message.ByteSize() + 8);
  178.  
  179. if (!ptr)
  180. return false;
  181.  
  182. ((uint32_t*)ptr)[0] = k_EMsgGCClientHello | ((DWORD)1 << 31);
  183. ((uint32_t*)ptr)[1] = 0;
  184.  
  185. Message.SerializeToArray((void*)((DWORD)ptr + 8), Message.ByteSize());
  186.  
  187. bool result = Interfaces::SteamGameCoordinator()->SendMessage(k_EMsgGCClientHello | ((DWORD)1 << 31), ptr, Message.ByteSize() + 8) == k_EGCResultOK;
  188.  
  189. free(ptr);
  190.  
  191. return result;
  192. }
  193.  
  194. void Hook_LockCursor()
  195. {
  196.  
  197. Interfaces::Surface()->LockCursor();
  198.  
  199. if (bIsGuiVisible)
  200. Interfaces::Surface()->UnlockCursor();
  201. }
  202.  
  203. bool Initialize()
  204. {
  205. if (!CSX::Utils::IsModuleLoad(D3D9_DLL))
  206. return false;
  207.  
  208. if (!CSX::Utils::IsModuleLoad(SHADERPIDX9_DLL))
  209. return false;
  210.  
  211. if (!CSX::Utils::IsModuleLoad(GAMEOVERLAYRENDERER_DLL))
  212. return false;
  213.  
  214. DWORD d3d9TablePtrPtr = CSX::Memory::FindPattern(SHADERPIDX9_DLL, D3D9_PATTERN, D3D9_MASK, 1);
  215. DWORD_PTR** dwPresent_o = (DWORD_PTR**)CSX::Memory::FindPattern(GAMEOVERLAYRENDERER_DLL, GMOR_PATTERN, GMOR_MASK, 1);
  216.  
  217. if (d3d9TablePtrPtr && dwPresent_o)
  218. {
  219. g_pDevice = (IDirect3DDevice9*)(**(PDWORD*)d3d9TablePtrPtr);
  220.  
  221. if (device.setup(g_pDevice))
  222. {
  223. //all undetect and rewrite
  224. DWORD_PTR* dwAddress = *dwPresent_o;
  225. Present_o = (Present_t)(*dwAddress);
  226. *dwAddress = (DWORD_PTR)(&Hook_Present);
  227.  
  228. device.hook_index(D3D9::TABLE::Reset, Hook_Reset);
  229.  
  230. if (!clientmode.setup(Interfaces::ClientMode()))
  231. return false;
  232.  
  233. clientmode.hook_index(TABLE::IClientMode::CreateMove, Hook_CreateMove);
  234. clientmode.hook_index(TABLE::IClientMode::OverrideView, Hook_OverrideView);
  235. //clientmode.hook_index(TABLE::IClientMode::GetViewModelFOV, Hook_GetViewModelFOV);
  236.  
  237.  
  238. if (!panel.setup(Interfaces::VPanel()))
  239. return false;
  240. //panel.hook_index(41, hkPaintTraverse); //crashs game - someone update this
  241.  
  242. if (!client.setup(Interfaces::Client()))
  243. return false;
  244. client.hook_index(TABLE::IBaseClientDLL::FrameStageNotify, Hook_FrameStageNotify);
  245.  
  246.  
  247. if (!SteamGameCoordinatorTable.setup(Interfaces::SteamGameCoordinator()))
  248. return false;
  249.  
  250. SteamGameCoordinatorTable.hook_index(0, Hook_SendMessage);
  251. SteamGameCoordinatorTable.hook_index(2, Hook_RetrieveMessage);
  252.  
  253. if (!eventmanager.setup(Interfaces::GameEvent()))
  254. return false;
  255.  
  256.  
  257. eventmanager.hook_index(TABLE::IGameEventManager2::FireEventClientSide, Hook_FireEventClientSideThink);
  258.  
  259. if (!client.setup(Interfaces::Client()))
  260. return false;
  261.  
  262. client.hook_index(TABLE::IBaseClientDLL::FrameStageNotify, Hook_FrameStageNotify);
  263.  
  264. if (!sound.setup(Interfaces::Sound()))
  265. return false;
  266.  
  267. sound.hook_index(TABLE::IEngineSound::EmitSound1, Hook_EmitSound2);
  268.  
  269. /* THIS IS FOR CHAMS ETC! YOU CAN INCLUDE IT WITHOUT VAC BAN! IT IS VMT UNDETECTED!
  270.  
  271. if (!modelrender.setup(Interfaces::ModelRender()))
  272. return false;
  273.  
  274. modelrender.hook_index(TABLE::IVModelRender::DrawModelExecute, Hook_DrawModelExecute);
  275. */
  276.  
  277. if (!surface.setup(Interfaces::Surface()))
  278. return false;
  279.  
  280. surface.hook_index(TABLE::ISurface::PlaySound, Hook_PlaySound);
  281. surface.hook_index(TABLE::ISurface::LockCursor, Hook_LockCursor);
  282.  
  283. if (Client::Initialize(g_pDevice))
  284. SendClientHello();
  285. return true;
  286. }
  287. }
  288.  
  289. return false;
  290. }
  291.  
  292. void Shutdown()
  293. {
  294. device.unhook_all();
  295. sound.unhook_all();
  296. clientmode.unhook_all();
  297. eventmanager.unhook_all();
  298. modelrender.unhook_all();
  299. client.unhook_all();
  300. SteamGameCoordinatorTable.unhook_all();
  301. }
  302. }
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement