Advertisement
Guest User

CS:GO SetCursorPos aimbot

a guest
Jan 23rd, 2020
1,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <TlHelp32.h>
  4.  
  5. /*         _____              ____   ____ ____                  __            _____         __ __        
  6.           / ___/ ___   _  __ / __ \ / __// __/___   ____   ____/ /___   _____/ ___/ ____ _ / // /__  __  
  7.           \__ \ / _ \ | |/_// / / // /_ / /_ / _ \ / __ \ / __  // _ \ / ___/\__ \ / __ `// // // / / /  
  8.          ___/ //  __/_>  < / /_/ // __// __//  __// / / // /_/ //  __// /   ___/ // /_/ // // // /_/ /    (and cyborg)
  9.         /____/ \___//_/|_| \____//_/  /_/   \___//_/ /_/ \__,_/ \___//_/   /____/ \__,_//_//_/ \__, /    
  10.                                                                                               /____/      
  11. Make sure character set is 'Multi-Byte' in project settings! And game must be windowed fullscreen.
  12. Updated offsets: https://github.com/frk1/hazedumper/blob/master/csgo.hpp                    */
  13.  
  14. //Offsets
  15. #define m_dwBoneMatrix 0x26A8
  16. #define m_iHealth 0x100
  17. #define m_iTeamNum 0xF4
  18. #define m_vecOrigin 0x138
  19. #define dwEntityList 0x4D3D5DC
  20. #define dwLocalPlayer 0xD29B1C
  21. #define dwViewMatrix 0x4D2EFF4
  22. #define m_bDormant 0xED
  23.  
  24. //Consts for resoloution
  25. const int SCREEN_WIDTH = GetSystemMetrics(SM_CXSCREEN);  const int xhairx = SCREEN_WIDTH / 2;
  26. const int SCREEN_HEIGHT = GetSystemMetrics(SM_CYSCREEN); const int xhairy = SCREEN_HEIGHT / 2;
  27.  
  28. //Globals
  29. HWND hwnd;
  30. DWORD procId;
  31. HANDLE hProcess;
  32. uintptr_t moduleBase;
  33. HDC hdc;
  34. int closest; //For thread
  35.  
  36. uintptr_t GetModuleBaseAddress(const char* modName) {
  37.     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procId);
  38.     if (hSnap != INVALID_HANDLE_VALUE) {
  39.         MODULEENTRY32 modEntry;
  40.         modEntry.dwSize = sizeof(modEntry);
  41.         if (Module32First(hSnap, &modEntry)) {
  42.             do {
  43.                 if (!strcmp(modEntry.szModule, modName)) {
  44.                     CloseHandle(hSnap);
  45.                     return (uintptr_t)modEntry.modBaseAddr;
  46.                 }
  47.             } while (Module32Next(hSnap, &modEntry));
  48.         }
  49.     }
  50. }
  51.  
  52. template<typename T> T RPM(SIZE_T address) {
  53.     T buffer;
  54.     ReadProcessMemory(hProcess, (LPCVOID)address, &buffer, sizeof(T), NULL);
  55.     return buffer;
  56. }
  57.  
  58. class Vector3 {
  59. public:
  60.     float x, y, z;
  61.     Vector3() : x(0.f), y(0.f), z(0.f) {}
  62.     Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
  63. };
  64.  
  65. int getTeam(uintptr_t player) {
  66.     return RPM<int>(player + m_iTeamNum);
  67. }
  68.  
  69. uintptr_t GetLocalPlayer() {
  70.     return RPM<uintptr_t>(moduleBase + dwLocalPlayer);
  71. }
  72.  
  73. uintptr_t GetPlayer(int index) {
  74.     return RPM<uintptr_t>(moduleBase + dwEntityList + index * 0x10);
  75. }
  76.  
  77. int GetPlayerHealth(uintptr_t player) {
  78.     return RPM<int>(player + m_iHealth);
  79. }
  80.  
  81. Vector3 PlayerLocation(uintptr_t player) {
  82.     return RPM<Vector3>(player + m_vecOrigin);
  83. }
  84.  
  85. bool DormantCheck(uintptr_t player) {
  86.     return RPM<int>(player + m_bDormant);
  87. }
  88.  
  89. Vector3 get_head(uintptr_t pEnt) {
  90.     struct boneMatrix_t {
  91.         byte pad3[12];
  92.         float x;
  93.         byte pad1[12];
  94.         float y;
  95.         byte pad2[12];
  96.         float z;
  97.     };
  98.     uintptr_t boneBase = RPM<uintptr_t>(pEnt + m_dwBoneMatrix);
  99.     boneMatrix_t boneMatrix = RPM<boneMatrix_t>(boneBase + (sizeof(boneMatrix) * 8 /*boneid for head*/));
  100.     return Vector3(boneMatrix.x, boneMatrix.y, boneMatrix.z);
  101. }
  102.  
  103. struct view_matrix_t {
  104.     float matrix[16];
  105. } vm;
  106.  
  107. struct Vector3 WorldToScreen(const struct Vector3 pos, struct view_matrix_t matrix) {
  108.     struct Vector3 out;
  109.     float _x = matrix.matrix[0] * pos.x + matrix.matrix[1] * pos.y + matrix.matrix[2] * pos.z + matrix.matrix[3];
  110.     float _y = matrix.matrix[4] * pos.x + matrix.matrix[5] * pos.y + matrix.matrix[6] * pos.z + matrix.matrix[7];
  111.     out.z = matrix.matrix[12] * pos.x + matrix.matrix[13] * pos.y + matrix.matrix[14] * pos.z + matrix.matrix[15];
  112.  
  113.     _x *= 1.f / out.z;
  114.     _y *= 1.f / out.z;
  115.  
  116.     out.x = SCREEN_WIDTH * .5f;
  117.     out.y = SCREEN_HEIGHT * .5f;
  118.  
  119.     out.x += 0.5f * _x * SCREEN_WIDTH + 0.5f;
  120.     out.y -= 0.5f * _y * SCREEN_HEIGHT + 0.5f;
  121.  
  122.     return out;
  123. }
  124.  
  125. float pythag(int x1, int y1, int x2, int y2) {
  126.     return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  127. }
  128.  
  129. int FindClosestEnemy() {
  130.     float Finish;
  131.     int ClosestEntity = 1;
  132.     Vector3 Calc = { 0 ,0 ,0 };
  133.     float Closest = FLT_MAX;
  134.     int localTeam = getTeam(GetLocalPlayer());
  135.     for (int i = 1; i < 32; i++) {
  136.         DWORD Entity = GetPlayer(i);
  137.         int EnmTeam = getTeam(Entity); if (EnmTeam == localTeam) continue;
  138.         int Enmhealth = GetPlayerHealth(Entity);  if (Enmhealth < 1 || Enmhealth > 100) continue;
  139.         int Dormant = DormantCheck(Entity); if (Dormant) continue;
  140.  
  141.         Vector3 headbone = WorldToScreen(get_head(Entity), vm);
  142.         Finish = pythag(headbone.x, headbone.y, xhairx, xhairy);
  143.  
  144.         if (Finish < Closest) {
  145.             Closest = Finish;
  146.             ClosestEntity = i;
  147.         }
  148.     }
  149.     return ClosestEntity;
  150. }
  151.  
  152. void DrawLine(float StartX, float StartY, float EndX, float EndY) {
  153.     int a, b = 0;
  154.     HPEN hOPen;
  155.     HPEN hNPen = CreatePen(PS_SOLID, 2, 0x0000FF /*red*/);// penstyle, width, color
  156.     hOPen = (HPEN)SelectObject(hdc, hNPen);
  157.     MoveToEx(hdc, StartX, StartY, NULL); //start
  158.     a = LineTo(hdc, EndX, EndY); //end
  159.     DeleteObject(SelectObject(hdc, hOPen));
  160. }
  161.  
  162. void FindClosestEnemyThread() {
  163.     while (1) {
  164.         closest = FindClosestEnemy();
  165.     }
  166. }
  167.  
  168. void main() {
  169.     hwnd = FindWindowA(NULL, "Counter-Strike: Global Offensive");
  170.     GetWindowThreadProcessId(hwnd, &procId);
  171.     moduleBase = GetModuleBaseAddress("client_panorama.dll");
  172.     hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, procId);
  173.     hdc = GetDC(hwnd);
  174.  
  175.     CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)FindClosestEnemyThread, NULL, NULL, NULL);
  176.  
  177.     while (!GetAsyncKeyState(VK_END)) {
  178.         vm = RPM<view_matrix_t>(moduleBase + dwViewMatrix);
  179.         Vector3 closestw2shead = WorldToScreen(get_head(GetPlayer(closest)), vm);
  180.         DrawLine(xhairx, xhairy, closestw2shead.x, closestw2shead.y);
  181.  
  182.         if (GetAsyncKeyState(VK_MENU) /*alt*/ && closestw2shead.z >= 0.001f /*onscreen check*/)
  183.             SetCursorPos(closestw2shead.x, closestw2shead.y);
  184.     }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement