Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.03 KB | None | 0 0
  1. //MAIN.CPP
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. #include <Windows.h>
  10. #include <sstream>
  11. #include <iostream>
  12. #include <math.h>  
  13. #include "HackProcess.h"
  14. #include <vector>
  15. #include <algorithm>  
  16.  
  17. //Proc manage
  18. CHackProcess fProcess;  
  19. using namespace std;  
  20. #define F6_Key 0x75
  21. #define RIGHT_MOUSE 0x02
  22. int NumOfPlayers = 32;
  23.  
  24. //Declaring Offsets
  25. const DWORD LocalPlayer = 0xAABFFC;
  26. const DWORD dw_mTeamOffset = 0x98;
  27. const DWORD dw_Health = 0x90;
  28. const DWORD dw_Pos = 0x25C;
  29. const DWORD EntityList = 0x4A87504;
  30. //How far in memory is each enemy data
  31. const DWORD EntityLoopDistance = 0x10;
  32. //const DWORD dw_m_angRotation = 0x461A9C;
  33. RECT m_Rect;
  34. //Set of initial variables
  35. //Our desktop handle
  36. HDC HDC_Desktop;
  37. //Brush to paint ESP
  38. HBRUSH EnemyBrush;
  39. HFONT Font;
  40.  
  41. //ESP VARS
  42. const DWORD dw_vMatrix = 0x4A79FD4;
  43. HWND TargetWnd;
  44. HWND Handle;
  45. DWORD DwProcID;
  46. COLORREF SnapLineCOLOR;
  47. COLORREF TextCOLOR;
  48.  
  49. typedef struct
  50. {
  51.     float flMatrix[4][4];
  52. }WorldToScreenMatrix_t;
  53.  
  54. float Get3dDistance(float * myCoords, float * enemyCoords)
  55. {
  56.     return sqrt(
  57.         pow(double(enemyCoords[0] - myCoords[0]), 2.0) +
  58.         pow(double(enemyCoords[1] - myCoords[1]), 2.0) +
  59.         pow(double(enemyCoords[2] - myCoords[2]), 2.0));
  60. }
  61.  
  62. void SetupDrawing(HDC hDesktop, HWND handle)
  63. {
  64.     HDC_Desktop = hDesktop;
  65.     Handle = handle;
  66.     EnemyBrush = CreateSolidBrush(RGB(220, 20, 20));
  67.     //Color
  68.     SnapLineCOLOR = RGB(20, 20, 240);
  69.     TextCOLOR = RGB(10, 190, 50);
  70. };
  71.  
  72. struct MyPlayer_t  
  73. {
  74.     DWORD CLocalPlayer;
  75.     int Team;
  76.     int Health;
  77.     WorldToScreenMatrix_t WorldToScreenMatrix;
  78.     float Position[3];
  79.     int flickerCheck;
  80.     void ReadInformation()
  81.     {
  82.         // Reading CLocalPlayer Pointer to our "CLocalPlayer" DWORD.
  83.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + LocalPlayer), &CLocalPlayer, sizeof(DWORD), 0);
  84.         // Reading out our Team to our "Team" Varible.
  85.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_mTeamOffset), &Team, sizeof(int), 0);
  86.         // Reading out our Health to our "Health" Varible.    
  87.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_Health), &Health, sizeof(int), 0);
  88.         // Reading out our Position to our "Position" Varible.
  89.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_Pos), &Position, sizeof(float[3]), 0);
  90.  
  91.         //Here we find how many player entities exist in our game, through this we make sure to only loop the amount of times we need
  92.         //when grabbing player data
  93.         //Note that this call could be even better at a regular 15 or so seconds timer but performance shouldn't vary a great deal
  94.         //ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dw_PlayerCountOffs), &NumOfPlayers, sizeof(int), 0);
  95.         //ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dw_antiFlick), &flickerCheck, sizeof(int), 0);
  96.         //VMatrix
  97.             ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dw_vMatrix), &WorldToScreenMatrix, sizeof(WorldToScreenMatrix), 0);
  98.     }
  99. }MyPlayer;    
  100.  
  101.  
  102.  
  103. //ENemy struct
  104. struct PlayerList_t
  105. {
  106.     DWORD CBaseEntity;
  107.     int Team;
  108.     int Health;
  109.     float Position[3];
  110.     float AimbotAngle[3];
  111.     char Name[39];
  112.  
  113.     void ReadInformation(int Player)
  114.     {
  115.         // Reading CBaseEntity Pointer to our "CBaseEntity" DWORD + Current Player in the loop. 0x10 is the CBaseEntity List Size
  116.         //"client.dll"+00545204 //0x571A5204
  117.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + EntityList  + (Player * EntityLoopDistance)),&CBaseEntity, sizeof(DWORD), 0);
  118.         // Reading out our Team to our "Team" Varible.
  119.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_mTeamOffset), &Team, sizeof(int), 0);
  120.         // Reading out our Health to our "Health" Varible.    
  121.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Health), &Health, sizeof(int), 0);
  122.         // Reading out our Position to our "Position" Varible.
  123.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Pos), &Position, sizeof(float[3]), 0);
  124.     }
  125. }PlayerList[32];  
  126.  
  127. bool WorldToScreen(float * from, float * to)
  128. {
  129.     float w = 0.0f;
  130.  
  131.     to[0] = MyPlayer.WorldToScreenMatrix.flMatrix[0][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[0][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[0][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[0][3];
  132.         to[1] = MyPlayer.WorldToScreenMatrix.flMatrix[1][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[0][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[1][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[1][3];
  133.         w = to[1] = MyPlayer.WorldToScreenMatrix.flMatrix[1][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[3][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[3][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[3][3];
  134.  
  135.         if (w < 0.01f)
  136.             return false;
  137.  
  138.     float invw = 1.0f / w;
  139.     to[0] *= invw;
  140.     to[1] *= invw;
  141.    
  142.     int width = (int)(m_Rect.right - m_Rect.left);
  143.     int height = (int)(m_Rect.bottom - m_Rect.top);
  144.  
  145.     float x = width / 2;
  146.     float y = height / 2;
  147.  
  148.     x += 0.5 * to[0] * width + 0.5;
  149.     y -= 0.5 * to[1] * height + 0.5;
  150.  
  151.     to[0] = x + m_Rect.left;
  152.     to[1] = y + m_Rect.top;
  153.  
  154.     return true;
  155.  
  156. }
  157.  
  158. //We receive the 2-D Coordinates the colour and the device we want to use to draw those colours with
  159. //HDC so we know where to draw and brush because we need it to draw
  160. void DrawFilledRect(int x, int y, int w, int h)
  161. {
  162.     //We create our rectangle to draw on screen
  163.     RECT rect = { x, y, x + w, y + h };
  164.     //We clear that portion of the screen and display our rectangle
  165.     FillRect(HDC_Desktop, &rect, EnemyBrush);
  166. }
  167.  
  168.  
  169. void DrawBorderBox(int x, int y, int w, int h, int thickness)
  170. {
  171.     //Top horiz line
  172.     DrawFilledRect(x, y, w, thickness);
  173.     //Left vertical line
  174.     DrawFilledRect( x, y, thickness, h);
  175.     //right vertical line
  176.     DrawFilledRect((x + w), y, thickness, h);
  177.     //bottom horiz line
  178.     DrawFilledRect(x, y + h, w+thickness, thickness);
  179. }
  180.  
  181.  
  182. //Here is where we draw our line from point A to Point B
  183. void DrawLine(float StartX, float StartY, float EndX, float EndY, COLORREF Pen)
  184. {
  185.     int a,b=0;
  186.     HPEN hOPen;
  187.     // penstyle, width, color
  188.     HPEN hNPen = CreatePen(PS_SOLID, 2, Pen);
  189.     hOPen = (HPEN)SelectObject(HDC_Desktop, hNPen);
  190.     // starting point of line
  191.     MoveToEx(HDC_Desktop, StartX, StartY, NULL);
  192.     // ending point of line
  193.     a = LineTo(HDC_Desktop, EndX, EndY);
  194.     DeleteObject(SelectObject(HDC_Desktop, hOPen));
  195. }
  196.  
  197. //Draw our text with this function
  198. void DrawString(int x, int y, COLORREF color, const char* text)
  199. {  
  200.     SetTextAlign(HDC_Desktop,TA_CENTER|TA_NOUPDATECP);
  201.  
  202.     SetBkColor(HDC_Desktop,RGB(0,0,0));
  203.     SetBkMode(HDC_Desktop,TRANSPARENT);
  204.  
  205.     SetTextColor(HDC_Desktop,color);
  206.  
  207.     SelectObject(HDC_Desktop,Font);
  208.  
  209.     TextOutA(HDC_Desktop,x,y,text,strlen(text));
  210.  
  211.     DeleteObject(Font);
  212. }
  213.  
  214. void DrawESP(int x, int y, float distance)
  215. {
  216.     int width = 18100 / distance;
  217.     int height = 36000 / distance;
  218.     DrawBorderBox(x - (width / 2), y - height, width, height, 2);
  219.  
  220.     DrawLine((m_Rect.right - m_Rect.left) / 2,
  221.         m_Rect.bottom - m_Rect.top, x, y,
  222.         SnapLineCOLOR);
  223.  
  224.     std::stringstream ss;
  225.     ss << (int)distance;
  226.  
  227.     char * distanceInfo = new char[ss.str().size() + 1];
  228.     strcpy(distanceInfo, ss.str().c_str());
  229.  
  230.     DrawString(x, y, TextCOLOR, distanceInfo);
  231.     delete[] distanceInfo;
  232. }
  233.  
  234. void ESP()
  235. {
  236.     GetWindowRect(FindWindow(NULL, "Counter-Strike: Global Offensive"), &m_Rect);
  237.  
  238.     for (int i = 0; i < NumOfPlayers; i++)
  239.     {
  240.         PlayerList[i].ReadInformation(i);
  241.  
  242.         //Show ded peepz
  243.         if (PlayerList[i].Health < 2)
  244.             continue;
  245.  
  246.         //Don't show team
  247.         //if (PlayerList[i].Team == MyPlayer.Team)
  248.             //continue;
  249.  
  250.         float EnemyXY[3];
  251.         if (WorldToScreen(PlayerList[i].Position, EnemyXY))
  252.         {
  253.             DrawESP(EnemyXY[0] - m_Rect.left, EnemyXY[1] - m_Rect.top, Get3dDistance(MyPlayer.Position, PlayerList[i].Position));
  254.  
  255.         }
  256.     }
  257. }
  258.  
  259. int main()
  260. {
  261.     fProcess.RunProcess();
  262.  
  263.     ShowWindow(FindWindow("ConsoleWindowClass", NULL), false);
  264.     TargetWnd = FindWindow(0, "Counter-Strike: Global Offensive");
  265.     HDC HDC_Desktop = GetDC(TargetWnd);
  266.     SetupDrawing(HDC_Desktop, TargetWnd);
  267.    
  268.     //infinite loop
  269.     for (;;)
  270.     {
  271.         MyPlayer.ReadInformation();
  272.         ESP();
  273.     }
  274.  
  275.     return 0;
  276. }
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289. //HACKPROCESS.H
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. #pragma once
  302.  
  303. #include <Windows.h>
  304. #include <TlHelp32.h>
  305.  
  306. class CHackProcess
  307. {
  308. public:
  309.  
  310.     PROCESSENTRY32 __gameProcess;
  311.     HANDLE __HandleProcess;
  312.     HWND __HWNDCss;
  313.     DWORD __dwordClient;
  314.     DWORD __dwordEngine;
  315.     DWORD __dwordOverlay;
  316.     DWORD __dwordVGui;
  317.     DWORD __dwordLibCef;
  318.     DWORD __dwordSteam;
  319.     DWORD FindProcessName(const char *__ProcessName, PROCESSENTRY32 *pEntry)
  320.     {    
  321.         PROCESSENTRY32 __ProcessEntry;
  322.         __ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
  323.         HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  324.         if (hSnapshot == INVALID_HANDLE_VALUE) return 0;        if (!Process32First(hSnapshot, &__ProcessEntry))
  325.         {
  326.             CloseHandle(hSnapshot);
  327.             return 0;
  328.         }
  329.         do{if (!_strcmpi(__ProcessEntry.szExeFile, __ProcessName))
  330.         {
  331.             memcpy((void *)pEntry, (void *)&__ProcessEntry, sizeof(PROCESSENTRY32));
  332.             CloseHandle(hSnapshot);
  333.             return __ProcessEntry.th32ProcessID;
  334.         }} while (Process32Next(hSnapshot, &__ProcessEntry));
  335.         CloseHandle(hSnapshot);
  336.         return 0;
  337. }
  338.  
  339.  
  340. DWORD getThreadByProcess(DWORD __DwordProcess)
  341. {    
  342.         THREADENTRY32 __ThreadEntry;
  343.         __ThreadEntry.dwSize = sizeof(THREADENTRY32);
  344.         HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
  345.         if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
  346.  
  347.         if (!Thread32First(hSnapshot, &__ThreadEntry)) {CloseHandle(hSnapshot); return 0; }
  348.  
  349.         do {if (__ThreadEntry.th32OwnerProcessID == __DwordProcess)
  350.         {
  351.             CloseHandle(hSnapshot);
  352.             return __ThreadEntry.th32ThreadID;
  353.         }} while (Thread32Next(hSnapshot, &__ThreadEntry));
  354.         CloseHandle(hSnapshot);      
  355.         return 0;
  356. }
  357.  
  358. DWORD GetModuleNamePointer(LPSTR LPSTRModuleName, DWORD __DwordProcessId)
  359. {
  360.         MODULEENTRY32 lpModuleEntry = {0};
  361.         HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, __DwordProcessId);
  362.         if(!hSnapShot)
  363.             return NULL;  
  364.         lpModuleEntry.dwSize = sizeof(lpModuleEntry);
  365.         BOOL __RunModule = Module32First( hSnapShot, &lpModuleEntry );
  366.         while(__RunModule)
  367.         {
  368.             if(!strcmp(lpModuleEntry.szModule, LPSTRModuleName ) )
  369.             {CloseHandle( hSnapShot );
  370.             return (DWORD)lpModuleEntry.modBaseAddr;
  371.             }
  372.             __RunModule = Module32Next( hSnapShot, &lpModuleEntry );
  373.         }
  374.         CloseHandle( hSnapShot );
  375.         return NULL;
  376. }
  377.  
  378.  
  379. void runSetDebugPrivs()
  380. {
  381.     HANDLE __HandleProcess=GetCurrentProcess(), __HandleToken;
  382.     TOKEN_PRIVILEGES priv;
  383.     LUID __LUID;
  384.     OpenProcessToken(__HandleProcess, TOKEN_ADJUST_PRIVILEGES, &__HandleToken);
  385.     LookupPrivilegeValue(0, "seDebugPrivilege", &__LUID);
  386.     priv.PrivilegeCount = 1;
  387.     priv.Privileges[0].Luid = __LUID;
  388.     priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  389.     AdjustTokenPrivileges(__HandleToken, false, &priv, 0, 0, 0);
  390.     CloseHandle(__HandleToken);
  391.     CloseHandle(__HandleProcess);
  392. }
  393.    
  394.    
  395.    
  396. void RunProcess()
  397. {
  398.     //commented lines are for non steam versions of the game
  399.     runSetDebugPrivs();
  400.     while (!FindProcessName("csgo.exe", &__gameProcess)) Sleep(12);
  401.     while (!(getThreadByProcess(__gameProcess.th32ProcessID))) Sleep(12);
  402.     __HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, false, __gameProcess.th32ProcessID);
  403.     while(__dwordClient == 0x0) __dwordClient = GetModuleNamePointer("client.dll", __gameProcess.th32ProcessID);
  404.     while(__dwordEngine == 0x0) __dwordEngine = GetModuleNamePointer("engine.dll", __gameProcess.th32ProcessID);
  405.     //while(__dwordOverlay == 0x0) __dwordOverlay = GetModuleNamePointer("gameoverlayrenderer.dll", __gameProcess.th32ProcessID);
  406.     while(__dwordVGui == 0x0) __dwordVGui = GetModuleNamePointer("vguimatsurface.dll", __gameProcess.th32ProcessID);
  407.     //while(__dwordLibCef == 0x0) __dwordLibCef = GetModuleNamePointer("libcef.dll", __gameProcess.th32ProcessID);
  408. //  while(__dwordSteam == 0x0) __dwordSteam = GetModuleNamePointer("steam.dll", __gameProcess.th32ProcessID);
  409.     __HWNDCss = FindWindow(NULL, "Counter-Strike: Global Offensive");
  410. }
  411. };
  412.  
  413. extern CHackProcess fProcess;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement