Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.55 KB | None | 0 0
  1. /*
  2. Departed Framework 2015
  3. */
  4.  
  5. #include "Hooks.h"
  6. #include "Hacks.h"
  7. #include "Chams.h"
  8. #include "Menu.h"
  9.  
  10. #include "Interfaces.h"
  11. #include "RenderManager.h"
  12. #include "MiscHacks.h"
  13. #include "CRC32.h"
  14. // Funtion Typedefs
  15. typedef void(__thiscall* DrawModelEx_)(void*, void*, void*, const ModelRenderInfo_t&, matrix3x4*);
  16. typedef void(__thiscall* PaintTraverse_)(PVOID, unsigned int, bool, bool);
  17. typedef bool(__thiscall* InPrediction_)(PVOID);
  18. typedef void(__stdcall *FrameStageNotifyFn)(ClientFrameStage_t);
  19.  
  20. // Function Pointers to the originals
  21. PaintTraverse_ oPaintTraverse;
  22. DrawModelEx_ oDrawModelExecute;
  23. FrameStageNotifyFn oFrameStageNotify;
  24.  
  25. // Hook function prototypes
  26. void __fastcall PaintTraverse_Hooked(PVOID pPanels, int edx, unsigned int vguiPanel, bool forceRepaint, bool allowForce);
  27. bool __stdcall Hooked_InPrediction();
  28. void __fastcall Hooked_DrawModelExecute(void* thisptr, int edx, void* ctx, void* state, const ModelRenderInfo_t &pInfo, matrix3x4 *pCustomBoneToWorld);
  29. bool __fastcall CreateMoveClient_Hooked(void* self, int edx, float frametime, CUserCmd* pCmd);
  30. bool __stdcall CreateMoveClient_Hooks(int sequence_number, float input_sample_frametime, bool active);
  31. void __stdcall Hooked_FrameStageNotify(ClientFrameStage_t curStage);
  32.  
  33. // VMT Managers
  34. namespace Hooks
  35. {
  36. // VMT Managers
  37. Utilities::Memory::VMTManager VMTPanel; // Hooking drawing functions
  38. Utilities::Memory::VMTManager VMTClient; // Maybe CreateMove
  39. Utilities::Memory::VMTManager VMTClientMode; // CreateMove for functionality
  40. Utilities::Memory::VMTManager VMTModelRender; // DrawModelEx for chams
  41. Utilities::Memory::VMTManager VMTPrediction; // InPrediction for no vis recoil
  42. };
  43.  
  44. // Initialise all our hooks
  45. void Hooks::Initialise()
  46. {
  47. // Panel hooks for drawing to the screen via surface functions
  48. VMTPanel.Initialise((DWORD*)Interfaces::Panels);
  49. oPaintTraverse = (PaintTraverse_)VMTPanel.HookMethod((DWORD)&PaintTraverse_Hooked, Offsets::VMT::Panel_PaintTraverse);
  50. //Utilities::Log("Paint Traverse Hooked");
  51.  
  52. // No Visual Recoil
  53. VMTPrediction.Initialise((DWORD*)Interfaces::Prediction);
  54. VMTPrediction.HookMethod((DWORD)&Hooked_InPrediction, 14);
  55. //Utilities::Log("InPrediction Hooked");
  56.  
  57. // Chams
  58. VMTModelRender.Initialise((DWORD*)Interfaces::ModelRender);
  59. oDrawModelExecute = (DrawModelEx_)VMTModelRender.HookMethod((DWORD)&Hooked_DrawModelExecute, Offsets::VMT::ModelRender_DrawModelExecute);
  60. //Utilities::Log("DrawModelExecute Hooked");
  61.  
  62. // Setup ClientMode Hooks
  63. VMTClientMode.Initialise((DWORD*)Interfaces::ClientMode);
  64. VMTClientMode.HookMethod((DWORD)&CreateMoveClient_Hooked, 24);
  65. //Utilities::Log("ClientMode CreateMove Hooked");
  66.  
  67. // Setup client hooks
  68. //VMTClient.Initialise((DWORD*)Interfaces::Client);
  69. //oFrameStageNotify = (FrameStageNotifyFn)VMTClient.HookMethod( (DWORD)&Hooked_FrameStageNotify, 36);
  70. }
  71.  
  72. // Undo our hooks
  73. void Hooks::UndoHooks()
  74. {
  75. VMTPanel.RestoreOriginal();
  76. VMTPrediction.RestoreOriginal();
  77. VMTModelRender.RestoreOriginal();
  78. VMTClientMode.RestoreOriginal();
  79. //VMTClient.RestoreOriginal();
  80. }
  81.  
  82. void MovementCorrection(CUserCmd* pCmd)
  83. {
  84.  
  85. }
  86.  
  87. //---------------------------------------------------------------------------------------------------------
  88. // Hooked Functions
  89. //---------------------------------------------------------------------------------------------------------
  90.  
  91. // Paint Traverse Hooked function
  92. void __fastcall PaintTraverse_Hooked(PVOID pPanels, int edx, unsigned int vguiPanel, bool forceRepaint, bool allowForce)
  93. {
  94. oPaintTraverse(pPanels, vguiPanel, forceRepaint, allowForce);
  95.  
  96. static unsigned int FocusOverlayPanel = 0;
  97. static bool FoundPanel = false;
  98.  
  99. if (!FoundPanel)
  100. {
  101. PCHAR szPanelName = (PCHAR)Interfaces::Panels->GetName(vguiPanel);
  102. if (strstr(szPanelName, "MatSystemTopPanel"))
  103. {
  104. FocusOverlayPanel = vguiPanel;
  105. FoundPanel = true;
  106. }
  107. }
  108. else if (FocusOverlayPanel == vguiPanel)
  109. {
  110. //Render::GradientV(8, 8, 160, 18, Color(0, 0, 0, 0), Color(7, 39, 17, 255));
  111. //Render::Text(10, 10, Color(255, 255, 255, 220), Render::Fonts::Menu, "AyyWare New Meme of 2015");
  112. if (Interfaces::Engine->IsConnected() && Interfaces::Engine->IsInGame())
  113. Hacks::DrawHacks();
  114.  
  115. // Update and draw the menu
  116. Menu::DoUIFrame();
  117. }
  118. }
  119.  
  120. // InPrediction Hooked Function
  121. bool __stdcall Hooked_InPrediction()
  122. {
  123. bool result;
  124. static InPrediction_ origFunc = (InPrediction_)Hooks::VMTPrediction.GetOriginalFunction(14);
  125. static DWORD *ecxVal = Interfaces::Prediction;
  126. result = origFunc(ecxVal);
  127.  
  128. // If we are in the right place where the player view is calculated
  129. // Calculate the change in the view and get rid of it
  130. if (Menu::Window.VisualsTab.OtherNoVisualRecoil.GetState() && (DWORD)(_ReturnAddress()) == Offsets::Functions::dwCalcPlayerView)
  131. {
  132. IClientEntity* pLocalEntity = NULL;
  133.  
  134. float* m_LocalViewAngles = NULL;
  135.  
  136. __asm
  137. {
  138. MOV pLocalEntity, ESI
  139. MOV m_LocalViewAngles, EBX
  140. }
  141.  
  142. Vector viewPunch = pLocalEntity->localPlayerExclusive()->GetViewPunchAngle();
  143. Vector aimPunch = pLocalEntity->localPlayerExclusive()->GetAimPunchAngle();
  144.  
  145. m_LocalViewAngles[0] -= (viewPunch[0] + (aimPunch[0] * 2 * 0.4499999f));
  146. m_LocalViewAngles[1] -= (viewPunch[1] + (aimPunch[1] * 2 * 0.4499999f));
  147. m_LocalViewAngles[2] -= (viewPunch[2] + (aimPunch[2] * 2 * 0.4499999f));
  148. return true;
  149. }
  150.  
  151. return result;
  152. }
  153.  
  154. // DrawModelExec for chams and shit
  155. void __fastcall Hooked_DrawModelExecute(void* thisptr, int edx, void* ctx, void* state, const ModelRenderInfo_t &pInfo, matrix3x4 *pCustomBoneToWorld)
  156. {
  157. Color color;
  158. float flColor[3] = { 0.f };
  159. static IMaterial* CoveredLit = CreateMaterial(true);
  160. static IMaterial* OpenLit = CreateMaterial(false);
  161. static IMaterial* CoveredFlat = CreateMaterial(true, false);
  162. static IMaterial* OpenFlat = CreateMaterial(false, false);
  163. bool DontDraw = false;
  164.  
  165. const char* ModelName = Interfaces::ModelInfo->GetModelName((model_t*)pInfo.pModel);
  166. IClientEntity* pModelEntity = (IClientEntity*)Interfaces::EntList->GetClientEntity(pInfo.entity_index);
  167. IClientEntity* pLocal = (IClientEntity*)Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  168.  
  169. if (Menu::Window.VisualsTab.Active.GetState())
  170. {
  171. // Player Chams
  172. int ChamsStyle = Menu::Window.VisualsTab.OptionsChams.GetIndex();
  173. int HandsStyle = Menu::Window.VisualsTab.OtherNoHands.GetIndex();
  174. if (ChamsStyle != 0 && Menu::Window.VisualsTab.FiltersPlayers.GetState() && strstr(ModelName, "models/player"))
  175. {
  176. if (pLocal && (!Menu::Window.VisualsTab.FiltersEnemiesOnly.GetState() ||
  177. pModelEntity->GetTeamNum() != pLocal->GetTeamNum()))
  178. {
  179. IMaterial *covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  180. IMaterial *open = ChamsStyle == 1 ? OpenLit : OpenFlat;
  181.  
  182. IClientEntity* pModelEntity = (IClientEntity*)Interfaces::EntList->GetClientEntity(pInfo.entity_index);
  183. if (pModelEntity)
  184. {
  185. IClientEntity *local = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  186. if (local)
  187. {
  188. if (pModelEntity->IsAlive() && pModelEntity->GetHealth() > 0 /*&& pModelEntity->GetTeamNum() != local->GetTeamNum()*/)
  189. {
  190. float alpha = 1.f;
  191.  
  192. if (pModelEntity->HasGunGameImmunity())
  193. alpha = 0.5f;
  194.  
  195. if (pModelEntity->GetTeamNum() == 2)
  196. {
  197. flColor[0] = 240.f / 255.f;
  198. flColor[1] = 30.f / 255.f;
  199. flColor[2] = 35.f / 255.f;
  200. }
  201. else
  202. {
  203. flColor[0] = 63.f / 255.f;
  204. flColor[1] = 72.f / 255.f;
  205. flColor[2] = 205.f / 255.f;
  206. }
  207.  
  208. Interfaces::RenderView->SetColorModulation(flColor);
  209. Interfaces::RenderView->SetBlend(alpha);
  210. Interfaces::ModelRender->ForcedMaterialOverride(covered);
  211. oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  212.  
  213. if (pModelEntity->GetTeamNum() == 2)
  214. {
  215. flColor[0] = 247.f / 255.f;
  216. flColor[1] = 180.f / 255.f;
  217. flColor[2] = 20.f / 255.f;
  218. }
  219. else
  220. {
  221. flColor[0] = 32.f / 255.f;
  222. flColor[1] = 180.f / 255.f;
  223. flColor[2] = 57.f / 255.f;
  224. }
  225.  
  226. Interfaces::RenderView->SetColorModulation(flColor);
  227. Interfaces::RenderView->SetBlend(alpha);
  228. Interfaces::ModelRender->ForcedMaterialOverride(open);
  229. }
  230. else
  231. {
  232. color.SetColor(255, 255, 255, 255);
  233. ForceMaterial(color, open);
  234. }
  235. }
  236. }
  237. }
  238. }
  239. else if (HandsStyle != 0 && strstr(ModelName, "arms"))
  240. {
  241. if (HandsStyle == 1)
  242. {
  243. DontDraw = true;
  244. }
  245. else if (HandsStyle == 2)
  246. {
  247. Interfaces::RenderView->SetBlend(0.3);
  248. }
  249. else if (HandsStyle == 3)
  250. {
  251. IMaterial *covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  252. IMaterial *open = ChamsStyle == 1 ? OpenLit : OpenFlat;
  253. if (pLocal)
  254. {
  255. if (pLocal->IsAlive())
  256. {
  257. int alpha = pLocal->HasGunGameImmunity() ? 150 : 255;
  258.  
  259. if (pLocal->GetTeamNum() == 2)
  260. color.SetColor(240, 30, 35, alpha);
  261. else
  262. color.SetColor(63, 72, 205, alpha);
  263.  
  264. ForceMaterial(color, covered);
  265. oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  266.  
  267. if (pLocal->GetTeamNum() == 2)
  268. color.SetColor(247, 180, 20, alpha);
  269. else
  270. color.SetColor(32, 180, 57, alpha);
  271. }
  272. else
  273. {
  274. color.SetColor(255, 255, 255, 255);
  275. }
  276.  
  277. ForceMaterial(color, open);
  278. }
  279. }
  280. else
  281. {
  282. static int counter = 0;
  283. static float colors[3] = { 1.f, 0.f, 0.f };
  284.  
  285. if (colors[counter] >= 1.0f)
  286. {
  287. colors[counter] = 1.0f;
  288. counter += 1;
  289. if (counter > 2)
  290. counter = 0;
  291. }
  292. else
  293. {
  294. int prev = counter - 1;
  295. if (prev < 0) prev = 2;
  296. colors[prev] -= 0.05f;
  297. colors[counter] += 0.05f;
  298. }
  299.  
  300. Interfaces::RenderView->SetColorModulation(colors);
  301. Interfaces::RenderView->SetBlend(0.3);
  302. Interfaces::ModelRender->ForcedMaterialOverride(OpenLit);
  303. }
  304. }
  305. else if (ChamsStyle != 0 && Menu::Window.VisualsTab.FiltersWeapons.GetState() && strstr(ModelName, "_dropped.mdl"))
  306. {
  307. IMaterial *covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  308. color.SetColor(255, 255, 255, 255);
  309. ForceMaterial(color, covered);
  310. }
  311. }
  312.  
  313. if (!DontDraw)
  314. oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  315. Interfaces::ModelRender->ForcedMaterialOverride(NULL);
  316. }
  317.  
  318. // ClientMode CreateMove
  319. bool __fastcall CreateMoveClient_Hooked(void* self, int edx, float frametime, CUserCmd* pCmd)
  320. {
  321. // Backup for safety
  322. Vector origView = pCmd->viewangles;
  323. Vector viewforward, viewright, viewup, aimforward, aimright, aimup;
  324. Vector qAimAngles;
  325. qAimAngles.Init(0.0f, pCmd->viewangles.y, 0.0f);
  326. AngleVectors(qAimAngles, &viewforward, &viewright, &viewup);
  327.  
  328. // Do da hacks
  329. IClientEntity *pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  330. if (Interfaces::Engine->IsConnected() && Interfaces::Engine->IsInGame() && pLocal && pLocal->IsAlive())
  331. Hacks::MoveHacks(pCmd);
  332.  
  333. //Movement Fix
  334. //GameUtils::CL_FixMove(pCmd, origView);
  335. qAimAngles.Init(0.0f, GetAutostrafeView().y, 0.0f);
  336. AngleVectors(qAimAngles, &viewforward, &viewright, &viewup);
  337. qAimAngles.Init(0.0f, pCmd->viewangles.y, 0.0f);
  338. AngleVectors(qAimAngles, &aimforward, &aimright, &aimup);
  339. Vector vForwardNorm; Normalize(viewforward, vForwardNorm);
  340. Vector vRightNorm; Normalize(viewright, vRightNorm);
  341. Vector vUpNorm; Normalize(viewup, vUpNorm);
  342.  
  343. // Original shit for movement correction
  344. float forward = pCmd->forwardmove;
  345. float right = pCmd->sidemove;
  346. float up = pCmd->upmove;
  347. if (forward > 450) forward = 450;
  348. if (right > 450) right = 450;
  349. if (up > 450) up = 450;
  350. if (forward < -450) forward = -450;
  351. if (right < -450) right = -450;
  352. if (up < -450) up = -450;
  353. pCmd->forwardmove = DotProduct(forward * vForwardNorm, aimforward) + DotProduct(right * vRightNorm, aimforward) + DotProduct(up * vUpNorm, aimforward);
  354. pCmd->sidemove = DotProduct(forward * vForwardNorm, aimright) + DotProduct(right * vRightNorm, aimright) + DotProduct(up * vUpNorm, aimright);
  355. pCmd->upmove = DotProduct(forward * vForwardNorm, aimup) + DotProduct(right * vRightNorm, aimup) + DotProduct(up * vUpNorm, aimup);
  356.  
  357. // Angle normalisation
  358. if (Menu::Window.MiscTab.OtherSafeMode.GetState())
  359. {
  360. GameUtils::NormaliseViewAngle(pCmd->viewangles);
  361.  
  362. if (pCmd->viewangles.z != 0.0f)
  363. {
  364. pCmd->viewangles.z = 0.00;
  365. }
  366.  
  367. if (pCmd->viewangles.x < -89 || pCmd->viewangles.x > 89 || pCmd->viewangles.y < -180 || pCmd->viewangles.y > 180)
  368. {
  369. Utilities::Log("Having to re-normalise!");
  370. GameUtils::NormaliseViewAngle(pCmd->viewangles);
  371. Beep(750, 800);
  372. if (pCmd->viewangles.x < -89 || pCmd->viewangles.x > 89 || pCmd->viewangles.y < -180 || pCmd->viewangles.y > 180)
  373. {
  374. pCmd->viewangles = origView;
  375. pCmd->sidemove = right;
  376. pCmd->forwardmove = forward;
  377. }
  378. }
  379. }
  380.  
  381. return false;
  382. }
  383.  
  384. bool bSendPacket;
  385. bool __declspec(naked) __stdcall CreateMoveClient_Hooks(int sequence_number, float input_sample_frametime, bool active)
  386. {
  387. __asm
  388. {
  389. MOV bSendPacket, BL
  390. PUSH EBP
  391. MOV EBP, ESP
  392. SUB ESP, 8
  393. PUSHAD
  394. PUSH active
  395. PUSH input_sample_frametime
  396. PUSH sequence_number
  397. CALL oCreateMove
  398. }
  399.  
  400. CUserCmd* cmdlist = *(CUserCmd**)((DWORD)g_pInput + 0xEC);
  401. CUserCmd* pCmd = &cmdlist[sequence_number % 150];
  402.  
  403. HookedCreateMove(pCmd, bSendPacket);
  404.  
  405. CVerifiedUserCmd* verifiedlist = *(CVerifiedUserCmd**)((DWORD)g_pInput + 0xF0);
  406. CVerifiedUserCmd* verified = &verifiedlist[sequence_number % 150];
  407. verified->m_cmd = *pCmd;
  408. verified->m_crc = CRC32(pCmd, sizeof(pCmd));
  409.  
  410. __asm
  411. {
  412. POPAD
  413. MOV BL, bSendPacket
  414. MOV ESP, EBP
  415. POP EBP
  416. RETN 0x0C
  417. }
  418.  
  419. }
  420.  
  421. // Hooked FrameStageNotify for removing visual recoil
  422. void __stdcall Hooked_FrameStageNotify(ClientFrameStage_t curStage)
  423. {
  424.  
  425.  
  426. if (curStage == FRAME_NET_UPDATE_POSTDATAUPDATE_START)
  427. {
  428. IClientEntity *pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  429. if (Menu::Window.MiscTab.KnifeEnable.GetState() && pLocal)
  430. {
  431. IClientEntity* WeaponEnt = Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  432. CBaseCombatWeapon* Weapon = (CBaseCombatWeapon*)WeaponEnt;
  433. if (Weapon)
  434. {
  435. static bool LastItemWasKnife = false;
  436. if (WeaponEnt->GetClientClass()->m_ClassID == (int)CSGOClassID::CKnife)
  437. {
  438. *Weapon->FallbackStatTrak() = 1337;
  439. int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  440. if (Skin == 0) *Weapon->FallbackPaintKit() = 416;
  441. if (Skin == 1) *Weapon->FallbackPaintKit() = 415;
  442. if (Skin == 3) *Weapon->FallbackPaintKit() = 409;
  443. if (Skin == 4) *Weapon->FallbackPaintKit() = 0;
  444. *Weapon->FallbackWear() = 0.0001;
  445.  
  446. //*Weapon->m_AttributeManager()->m_Item()->ItemIDHigh() = 0xFFFFF;
  447. //*Weapon->m_AttributeManager()->m_Item()->ItemIDLow() = 0xFFFFF;
  448.  
  449. if (LastItemWasKnife == false)
  450. {
  451.  
  452. //Meme->nFlags &= ~FCVAR_CHEAT;
  453. //Interfaces::Engine->ClientCmd_Unrestricted("cl_fullupdate");
  454.  
  455. //Meme->nFlags |= FCVAR_CHEAT;
  456.  
  457. LastItemWasKnife = true;
  458. }
  459.  
  460. *Weapon->m_AttributeManager()->m_Item()->ItemIDLow() = 7;
  461. int Model = Menu::Window.MiscTab.KnifeModel.GetIndex();
  462. *Weapon->m_AttributeManager()->m_Item()->ItemIDHigh() = (Model==0) ? 507 : 500;
  463. *Weapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = (Model == 0) ? 507 : 500;
  464.  
  465. if (GUI.GetKeyState(VK_END))
  466. ForceUpdate();
  467. }
  468. }
  469. }
  470. }
  471.  
  472. oFrameStageNotify(curStage);
  473. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement