Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.48 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <TlHelp32.h>
  3. #include <iostream>
  4. #include "math.h"
  5.  
  6. //-----------------Addresses------------------
  7. static DWORD  localPlayer = 0x4C6708;       //
  8. static DWORD  PlayerCount = 0x5D39BC;       //
  9. static DWORD  EntityPlayerBase = 0x4D3904;  //
  10. static DWORD  dw_attack = 0x4F3B48;         //
  11. static DWORD dw_angRotation = 0x4632D4;     //
  12. //-----------------Offsets------------------//
  13. static DWORD dw_TeamOff = 0x9C;             //
  14. static DWORD dw_HealthOff = 0x94;           //
  15. static DWORD dw_PosOff = 0x260;             //
  16. static DWORD dw_CrossHair = 0x14F0;         //
  17. static DWORD dw_lifeState = 0x93;           //
  18. static DWORD dw_bdormant = 0x17E;           //
  19. static DWORD dw_loopD = 0x10;               //
  20. static DWORD dw_VecOrigin = 0x518;          //
  21. //--------------------------------------------
  22. DWORD clientDll;                            //
  23. DWORD engineDll;                            //
  24. HANDLE hProc;                               //
  25. //--------------------------------------------
  26.  
  27. #define PI 3.1415927f
  28.  
  29. vec3_t CalcAngle(vec3_t src, vec3_t dst);
  30. HANDLE getHandle(char procname[]);
  31. UINT_PTR GetModuleBaseA(const char * szModule, HANDLE hProc);
  32. void Aimbot();
  33.  
  34.  
  35. //My Player Structure
  36. struct MyPlayer__
  37. {
  38.     DWORD cLocalPlayer;
  39.     int team;
  40.     int health;
  41.     vec3_t position;
  42.     //vec3_t angle;
  43.  
  44.  
  45.     void getinfo(HANDLE handleProcess,DWORD clientDLL, DWORD engineDLL) {
  46.         // Reading CLocalPlayer Pointer to our "CLocalPlayer" DWORD.
  47.         ReadProcessMemory(handleProcess, (PBYTE*)(clientDLL + localPlayer), &cLocalPlayer, sizeof(DWORD), 0);
  48.         // Reading out our Team to our "Team" Varible.
  49.         ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_TeamOff), &team, sizeof(int), 0);
  50.         // Reading out our Health to our "Health" Varible.    
  51.         ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_HealthOff), &health, sizeof(int), 0);
  52.         // Reading out our Position to our "Position" Variable.
  53.         ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_PosOff), &position, sizeof(position), 0);
  54.         // Get my own angles
  55.        
  56.  
  57.         //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
  58.         //when grabbing player data
  59.         //Note that this call could be even better at a regular 15 or so seconds timer but performance shouldn't vary a great deal
  60.         //ReadProcessMemory(handleProcess, (PBYTE*)(engineDLL + PlayerCount), &numberOfPLayers, sizeof(int), 0);
  61.     }
  62. }myPlayer;
  63.  
  64. //Enemy player structure
  65. struct PlayerList__
  66. {
  67.     DWORD cBaseEntity;
  68.     int team;
  69.     int health;
  70.     vec3_t position;
  71.     char name[39];;
  72.     float dist;
  73.     float angleDiff;
  74.     vec3_t angleTo;
  75.     vec3_t angle;
  76.  
  77.  
  78.  
  79.     void getInfo(int Player, HANDLE handleProcess, DWORD clientDLL, DWORD engineDLL)
  80.     {
  81.         // Reading CBaseEntity Pointer to our "CBaseEntity" DWORD + Current Player in the loop. 0x10 is the CBaseEntity List Size
  82.         //"client.dll"+00545204 //0x571A5204
  83.         ReadProcessMemory(handleProcess, (PBYTE*)(clientDLL + EntityPlayerBase + (Player * dw_loopD)), &cBaseEntity, sizeof(DWORD), 0);
  84.         // Reading out our Team to our "Team" Varible.
  85.         ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_TeamOff), &team, sizeof(int), 0);
  86.         // Reading out our Health to our "Health" Varible.    
  87.         ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_HealthOff), &health, sizeof(int), 0);
  88.         // Reading out our Position to our "Position" Varible.
  89.         ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_PosOff), &position, sizeof(vec3_t), 0);
  90.     }
  91.  
  92.     void Calculate(MyPlayer__ localPlayer)
  93.     {
  94.         dist = Distance(localPlayer.position, position);
  95.         angleTo = CalcAngle(localPlayer.position, position);
  96.         //angleDiff = Distance(localPlayer.angle, angleTo);
  97.     }
  98.  
  99. };
  100.  
  101.  
  102.  
  103. int main()
  104. {
  105.     std::cout << "Looking for process..." << std::endl;
  106.     char gameName[] = "hl2.exe";//name of the process
  107.     hProc = getHandle(gameName);//set proc to the Handle gained by get Handle
  108.     std::cout << "Process Retrieved" << std::endl;
  109.     clientDll = GetModuleBaseA("client.dll", hProc);
  110.     engineDll = GetModuleBaseA("engine.dll", hProc);
  111.     std::cout << "Dlls retrieved." << std::endl;
  112.    
  113.     int NumOfPlayers = 64;
  114.  
  115.     if (hProc != 0)//check if proc was retrieved
  116.     {
  117.         while (!GetAsyncKeyState(VK_F6)) // or for(;;)
  118.         {
  119.             while (GetAsyncKeyState(VK_XBUTTON2) & 1)
  120.             {
  121.                 std::cout << "Aiming!" << std::endl;
  122.                 Aimbot();
  123.             }
  124.         }
  125.     }
  126.  
  127. }
  128.  
  129. //------------------------------------Aimbot Function-------------------------------------
  130. void Aimbot()
  131. {
  132.  
  133.     UINT Count = 0;
  134.     ReadProcessMemory(hProc, (UINT*)(engineDll + PlayerCount), &Count, sizeof(Count), 0);
  135.  
  136.     //MyPlayer__ LocalPlayer;
  137.     myPlayer.getinfo(hProc, clientDll, engineDll);
  138.  
  139.  
  140.     PlayerList__ playerList[64];
  141.  
  142.     PlayerList__ * ClosestEnemy = nullptr;
  143.     for (UINT i = 0; i != Count; ++i)
  144.     {
  145.         playerList[i].Calculate(myPlayer);
  146.         std::cout << playerList[i].dist << std::endl;
  147.         playerList[i].getInfo(i, hProc, clientDll, engineDll);
  148.         if (playerList[i].team != myPlayer.team && playerList[i].health > 2)
  149.         {
  150.             auto Delta = playerList[i].position - myPlayer.position;
  151.             if (playerList[i].dist > Delta.len())
  152.             {
  153.                 ClosestEnemy = &(playerList[i]);
  154.             }
  155.         }
  156.     }
  157.     std::cout << ClosestEnemy->angleTo.x << ClosestEnemy->angleTo.y << ClosestEnemy->angleTo.z << std::endl;
  158.     //Write Angles
  159.     WriteProcessMemory(hProc, (PBYTE*)(engineDll + dw_angRotation), &(ClosestEnemy->angleTo), sizeof(float), 0);;
  160. }
  161. //-------------------------------------------------------------------------------------------------------------
  162. //----------------------------------CalcAngle Function---------------------------------------------------------
  163. vec3_t CalcAngle(vec3_t src, vec3_t dst)
  164. {  
  165.     vec3_t angle;
  166.     angle.x = (-(float)atan2(dst.x - src.x, dst.y - src.y)) / PI * 180.0f + 180.0f;
  167.     angle.y = (atan2(dst.z - src.z, Distance(src, dst))) * 180.0f / PI;
  168.     angle.z = 0.0f;
  169.     return angle;
  170. }
  171. //-------------------------------------------------------------------------------------------------------------
  172.  
  173.  
  174.  
  175. //**--------------------------------------MEMORY RELATED API SHITS-------------------------------------------------------------------------
  176. //----------GET THE HANDLE PROCESS----------------
  177. HANDLE getHandle(char procname[])
  178. {
  179.     DWORD processId = 0;
  180.     while (!processId)
  181.     {
  182.         HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  183.  
  184.         PROCESSENTRY32 pe32 = { 0 };
  185.         pe32.dwSize = sizeof(PROCESSENTRY32);
  186.         if (Process32First(hSnap, &pe32))// place process in pe32
  187.         {
  188.             do
  189.             {
  190.                 if (!strcmp(pe32.szExeFile, procname))//compare pe32 procname to the procname
  191.                 {
  192.                     processId = pe32.th32ProcessID;//set pid to the pid of the process if the process names matched
  193.                     break;
  194.                 }
  195.             } while (Process32Next(hSnap, &pe32));//Move to next process
  196.         }
  197.         CloseHandle(hSnap);
  198.         Sleep(10);
  199.     }
  200.  
  201.     return OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);//Open process Handle
  202. }
  203.  
  204.  
  205. //------------Get The module base---- EX clientdll-------------
  206. UINT_PTR GetModuleBaseA(const char * szModule, HANDLE hProc)
  207. {
  208.     DWORD ProcID = GetProcessId(hProc);
  209.  
  210.     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcID);
  211.     MODULEENTRY32 ME32 = { 0 };
  212.     ME32.dwSize = sizeof(MODULEENTRY32);
  213.  
  214.     if (!szModule || !hSnap)
  215.         return 0;
  216.  
  217.     BOOL Ret = Module32First(hSnap, &ME32);
  218.     while (Ret)
  219.     {
  220.         if (ME32.th32ProcessID == ProcID && !strcmp(szModule, ME32.szModule))
  221.         {
  222.             CloseHandle(hSnap);
  223.             return reinterpret_cast<UINT_PTR>(ME32.hModule);
  224.         }
  225.         Ret = Module32Next(hSnap, &ME32);
  226.     }
  227.  
  228.     CloseHandle(hSnap);
  229.  
  230.     return 0;
  231. }
  232.  
  233. //**-----------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement