Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <TlHelp32.h>
- #include <iostream>
- #include "math.h"
- //-----------------Addresses------------------
- static DWORD localPlayer = 0x4C6708; //
- static DWORD PlayerCount = 0x5D39BC; //
- static DWORD EntityPlayerBase = 0x4D3904; //
- static DWORD dw_attack = 0x4F3B48; //
- static DWORD dw_angRotation = 0x4632D4; //
- //-----------------Offsets------------------//
- static DWORD dw_TeamOff = 0x9C; //
- static DWORD dw_HealthOff = 0x94; //
- static DWORD dw_PosOff = 0x260; //
- static DWORD dw_CrossHair = 0x14F0; //
- static DWORD dw_lifeState = 0x93; //
- static DWORD dw_bdormant = 0x17E; //
- static DWORD dw_loopD = 0x10; //
- static DWORD dw_VecOrigin = 0x518; //
- //--------------------------------------------
- DWORD clientDll; //
- DWORD engineDll; //
- HANDLE hProc; //
- //--------------------------------------------
- #define PI 3.1415927f
- vec3_t CalcAngle(vec3_t src, vec3_t dst);
- HANDLE getHandle(char procname[]);
- UINT_PTR GetModuleBaseA(const char * szModule, HANDLE hProc);
- void Aimbot();
- //My Player Structure
- struct MyPlayer__
- {
- DWORD cLocalPlayer;
- int team;
- int health;
- vec3_t position;
- //vec3_t angle;
- void getinfo(HANDLE handleProcess,DWORD clientDLL, DWORD engineDLL) {
- // Reading CLocalPlayer Pointer to our "CLocalPlayer" DWORD.
- ReadProcessMemory(handleProcess, (PBYTE*)(clientDLL + localPlayer), &cLocalPlayer, sizeof(DWORD), 0);
- // Reading out our Team to our "Team" Varible.
- ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_TeamOff), &team, sizeof(int), 0);
- // Reading out our Health to our "Health" Varible.
- ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_HealthOff), &health, sizeof(int), 0);
- // Reading out our Position to our "Position" Variable.
- ReadProcessMemory(handleProcess, (PBYTE*)(cLocalPlayer + dw_PosOff), &position, sizeof(position), 0);
- // Get my own angles
- //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
- //when grabbing player data
- //Note that this call could be even better at a regular 15 or so seconds timer but performance shouldn't vary a great deal
- //ReadProcessMemory(handleProcess, (PBYTE*)(engineDLL + PlayerCount), &numberOfPLayers, sizeof(int), 0);
- }
- }myPlayer;
- //Enemy player structure
- struct PlayerList__
- {
- DWORD cBaseEntity;
- int team;
- int health;
- vec3_t position;
- char name[39];;
- float dist;
- float angleDiff;
- vec3_t angleTo;
- vec3_t angle;
- void getInfo(int Player, HANDLE handleProcess, DWORD clientDLL, DWORD engineDLL)
- {
- // Reading CBaseEntity Pointer to our "CBaseEntity" DWORD + Current Player in the loop. 0x10 is the CBaseEntity List Size
- //"client.dll"+00545204 //0x571A5204
- ReadProcessMemory(handleProcess, (PBYTE*)(clientDLL + EntityPlayerBase + (Player * dw_loopD)), &cBaseEntity, sizeof(DWORD), 0);
- // Reading out our Team to our "Team" Varible.
- ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_TeamOff), &team, sizeof(int), 0);
- // Reading out our Health to our "Health" Varible.
- ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_HealthOff), &health, sizeof(int), 0);
- // Reading out our Position to our "Position" Varible.
- ReadProcessMemory(handleProcess, (PBYTE*)(cBaseEntity + dw_PosOff), &position, sizeof(vec3_t), 0);
- }
- void Calculate(MyPlayer__ localPlayer)
- {
- dist = Distance(localPlayer.position, position);
- angleTo = CalcAngle(localPlayer.position, position);
- //angleDiff = Distance(localPlayer.angle, angleTo);
- }
- };
- int main()
- {
- std::cout << "Looking for process..." << std::endl;
- char gameName[] = "hl2.exe";//name of the process
- hProc = getHandle(gameName);//set proc to the Handle gained by get Handle
- std::cout << "Process Retrieved" << std::endl;
- clientDll = GetModuleBaseA("client.dll", hProc);
- engineDll = GetModuleBaseA("engine.dll", hProc);
- std::cout << "Dlls retrieved." << std::endl;
- int NumOfPlayers = 64;
- if (hProc != 0)//check if proc was retrieved
- {
- while (!GetAsyncKeyState(VK_F6)) // or for(;;)
- {
- while (GetAsyncKeyState(VK_XBUTTON2) & 1)
- {
- std::cout << "Aiming!" << std::endl;
- Aimbot();
- }
- }
- }
- }
- //------------------------------------Aimbot Function-------------------------------------
- void Aimbot()
- {
- UINT Count = 0;
- ReadProcessMemory(hProc, (UINT*)(engineDll + PlayerCount), &Count, sizeof(Count), 0);
- //MyPlayer__ LocalPlayer;
- myPlayer.getinfo(hProc, clientDll, engineDll);
- PlayerList__ playerList[64];
- PlayerList__ * ClosestEnemy = nullptr;
- for (UINT i = 0; i != Count; ++i)
- {
- playerList[i].Calculate(myPlayer);
- std::cout << playerList[i].dist << std::endl;
- playerList[i].getInfo(i, hProc, clientDll, engineDll);
- if (playerList[i].team != myPlayer.team && playerList[i].health > 2)
- {
- auto Delta = playerList[i].position - myPlayer.position;
- if (playerList[i].dist > Delta.len())
- {
- ClosestEnemy = &(playerList[i]);
- }
- }
- }
- std::cout << ClosestEnemy->angleTo.x << ClosestEnemy->angleTo.y << ClosestEnemy->angleTo.z << std::endl;
- //Write Angles
- WriteProcessMemory(hProc, (PBYTE*)(engineDll + dw_angRotation), &(ClosestEnemy->angleTo), sizeof(float), 0);;
- }
- //-------------------------------------------------------------------------------------------------------------
- //----------------------------------CalcAngle Function---------------------------------------------------------
- vec3_t CalcAngle(vec3_t src, vec3_t dst)
- {
- vec3_t angle;
- angle.x = (-(float)atan2(dst.x - src.x, dst.y - src.y)) / PI * 180.0f + 180.0f;
- angle.y = (atan2(dst.z - src.z, Distance(src, dst))) * 180.0f / PI;
- angle.z = 0.0f;
- return angle;
- }
- //-------------------------------------------------------------------------------------------------------------
- //**--------------------------------------MEMORY RELATED API SHITS-------------------------------------------------------------------------
- //----------GET THE HANDLE PROCESS----------------
- HANDLE getHandle(char procname[])
- {
- DWORD processId = 0;
- while (!processId)
- {
- HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- PROCESSENTRY32 pe32 = { 0 };
- pe32.dwSize = sizeof(PROCESSENTRY32);
- if (Process32First(hSnap, &pe32))// place process in pe32
- {
- do
- {
- if (!strcmp(pe32.szExeFile, procname))//compare pe32 procname to the procname
- {
- processId = pe32.th32ProcessID;//set pid to the pid of the process if the process names matched
- break;
- }
- } while (Process32Next(hSnap, &pe32));//Move to next process
- }
- CloseHandle(hSnap);
- Sleep(10);
- }
- return OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);//Open process Handle
- }
- //------------Get The module base---- EX clientdll-------------
- UINT_PTR GetModuleBaseA(const char * szModule, HANDLE hProc)
- {
- DWORD ProcID = GetProcessId(hProc);
- HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcID);
- MODULEENTRY32 ME32 = { 0 };
- ME32.dwSize = sizeof(MODULEENTRY32);
- if (!szModule || !hSnap)
- return 0;
- BOOL Ret = Module32First(hSnap, &ME32);
- while (Ret)
- {
- if (ME32.th32ProcessID == ProcID && !strcmp(szModule, ME32.szModule))
- {
- CloseHandle(hSnap);
- return reinterpret_cast<UINT_PTR>(ME32.hModule);
- }
- Ret = Module32Next(hSnap, &ME32);
- }
- CloseHandle(hSnap);
- return 0;
- }
- //**-----------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement