Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <TlHelp32.h>
- #include <cstdio>
- #include <windows.h>
- #include <conio.h>
- #include <FCNTL.H>
- #include <io.h>
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <random>
- #include <stdint.h>
- #include <cmath>
- using namespace std;
- const DWORD DwEntityList = 0x4A4EC04;
- const DWORD DwEnginePointer = 0x00667ABC;
- const DWORD DwLocalPlayer = 0x00A33504;
- const DWORD DwCrosshairId = 0x0000AA44;
- const DWORD DwViewAngle = 0x00004D0C;
- const DWORD DwVecViewOrigin = 0x104;
- const DWORD DwVecOrigin = 0x134;
- const DWORD DwVecPunch = 0x00003018;
- const DWORD DwTeamNumber = 0xF0;
- const DWORD DwShotsFired = 0xA2B0;
- const DWORD DwFlags = 0x100;
- const DWORD DwBoneMatrix = 0x00002698;
- const DWORD DwEntitySize = 0x10;
- const DWORD DwHealth = 0xFC;
- const DWORD DwLifeState = 0x25B;
- const DWORD DwVecVelocity = 0x110;
- int targetBone = 10;
- float PitchMinPunch = 2.f;
- float PitchMaxPunch = 2.f;
- float YawMinPunch = 2.f;
- float YawMaxPunch = 2.f;
- float smoothAmount = 20.f;
- typedef struct Vector_
- {
- float x;
- float y;
- float z;
- }Vector;
- template <class type>
- type ReadMem(HANDLE hProc, DWORD address)
- {
- type val;
- ReadProcessMemory(hProc, (LPCVOID)(address), &val, sizeof(val), NULL);
- return val;
- }
- template <class type>
- void WriteMem(HANDLE hProc, DWORD address, type val)
- {
- WriteProcessMemory(hProc, (LPVOID)(address), &val, sizeof(val), NULL);
- }
- DWORD getDll(DWORD pId, char* NAME)
- {
- DWORD clientDll = 0x0;
- MODULEENTRY32 moduleEntry;
- moduleEntry.dwSize = sizeof(MODULEENTRY32);
- HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId);
- do
- {
- if (!strcmp(moduleEntry.szModule, NAME))
- {
- clientDll = (DWORD)moduleEntry.modBaseAddr;
- break;
- }
- } while (Module32Next(hSnap, &moduleEntry));
- CloseHandle(hSnap);
- return clientDll;
- }
- struct
- {
- DWORD getBaseEntity(int playerNumber, DWORD clientDll, HANDLE hProc)
- {
- return ReadMem<DWORD>(hProc, (clientDll + DwEntityList + (DwEntitySize * playerNumber)));
- }
- bool isDead(int playerNumber, DWORD clientDll, HANDLE hProc)
- {
- DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
- if (baseEntity)
- {
- return ReadMem<bool>(hProc, (baseEntity + DwLifeState));
- }
- }
- int getTeam(int playerNumber, DWORD clientDll, HANDLE hProc)
- {
- DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
- if (baseEntity)
- {
- return ReadMem<int>(hProc, (baseEntity + DwTeamNumber));
- }
- }
- void getVelocity(int playerNumber, Vector buffer, DWORD clientDll, HANDLE hProc)
- {
- DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
- if (baseEntity)
- {
- ReadMem<Vector>(hProc, (baseEntity + DwVecVelocity));
- }
- }
- void getBonePosition(int playerNumber, Vector bonePosition, DWORD clientDll, HANDLE hProc)
- {
- DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
- if (baseEntity)
- {
- DWORD boneMatrix = ReadMem<DWORD>(hProc, (baseEntity + DwBoneMatrix));
- if (boneMatrix)
- {
- ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x0C), &bonePosition.x, sizeof(bonePosition), NULL);
- ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x1C), &bonePosition.y, sizeof(bonePosition), NULL);
- ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x2C), &bonePosition.z, sizeof(bonePosition), NULL);
- }
- }
- }
- }Entity;
- struct
- {
- DWORD getPlayerBase(DWORD clientDll, HANDLE hProc)
- {
- return ReadMem<DWORD>(hProc, (clientDll + DwLocalPlayer));
- }
- void setAngles(Vector angles, DWORD engineDll, HANDLE hProc)
- {
- DWORD anglePointer = ReadMem<DWORD>(hProc, (engineDll + DwEnginePointer));
- if (anglePointer)
- {
- WriteMem<Vector>(hProc, (anglePointer + DwViewAngle), angles);
- }
- }
- void getVelocity(Vector buffer, DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- ReadMem<Vector>(hProc, (playerBase + DwVecVelocity));
- }
- }
- void getAngles(Vector angles, DWORD engineDll, HANDLE hProc)
- {
- DWORD anglePointer = ReadMem<DWORD>(hProc, (engineDll + DwEnginePointer));
- if (anglePointer)
- {
- ReadMem<Vector>(hProc, (anglePointer + DwViewAngle));
- }
- }
- int getTeam(DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- return ReadMem<int>(hProc, (playerBase + DwTeamNumber));
- }
- }
- int getCrosshairId(DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- return ReadMem<int>(hProc, ((playerBase + DwCrosshairId) - 1));
- }
- }
- void getPunch(Vector punch, DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- ReadMem<Vector>(hProc, (playerBase + DwVecPunch));
- }
- }
- float getViewOrigin(DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- float vecView[3];
- ReadProcessMemory(hProc, (LPCVOID)(playerBase + DwVecViewOrigin), &vecView, sizeof(vecView), NULL);
- return vecView[2];
- }
- }
- void getPosition(Vector position, DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- ReadMem<Vector>(hProc, (playerBase + DwVecOrigin));
- }
- }
- int getShotsFired(DWORD clientDll, HANDLE hProc)
- {
- DWORD playerBase = getPlayerBase(clientDll, hProc);
- if (playerBase)
- {
- return ReadMem<int>(hProc, (playerBase + DwShotsFired));
- }
- }
- }Player;
- void Normalize(Vector vec)
- {
- if (vec.y > 180.f)
- vec.y -= 360.f;
- else if (vec.y < -180.f)
- vec.y += 360.f;
- if (vec.x > 89.f)
- vec.x = 89.f;
- else if (vec.y < -89.f)
- vec.x = -89.f;
- vec.z = 0.f;
- }
- void calcAngle(Vector src, Vector dst, Vector angles, DWORD clientDll, HANDLE hProc)
- {
- random_device Random;
- mt19937 RandomGen(Random());
- uniform_real<float> RandomXdistrib(PitchMinPunch, PitchMaxPunch);
- uniform_real<float> RandomYdistrib(YawMinPunch, YawMaxPunch);
- Vector myPunch{};
- Player.getPunch(myPunch, clientDll, hProc);
- float pitchReduction = RandomXdistrib(RandomGen);
- float yawReduction = RandomYdistrib(RandomGen);
- Vector delta;
- delta.x = (src.x - dst.x);
- delta.y = (src.y - dst.y);
- delta.z = ((src.z + Player.getViewOrigin(clientDll, hProc) - dst.z));
- float hyp = sqrt(delta.x * delta.x + delta.y * delta.y);
- angles.x = atanf(delta.z / hyp) * 57.295779513082f - myPunch.x * pitchReduction;
- angles.y = atanf(delta.y / delta.x) * 57.295779513082f - myPunch.y * yawReduction;
- angles.z = 0.0f;
- if (delta.x >= 0.0)
- {
- angles.y += 180.0f;
- }
- }
- void smoothAngleFunc(Vector dest, Vector orig, DWORD engineDll, HANDLE hProc)
- {
- Vector smoothAngles;
- smoothAngles.x = dest.x - orig.x;
- smoothAngles.y = dest.y - orig.y;
- smoothAngles.z = 0.0f;
- Normalize(smoothAngles);
- smoothAngles.x = orig.x + smoothAngles.x / 100.0f * smoothAmount;
- smoothAngles.y = orig.y + smoothAngles.y / 100.0f * smoothAmount;
- smoothAngles.z = 0.0f;
- Normalize(smoothAngles);
- Player.setAngles(smoothAngles, engineDll, hProc);
- Sleep(1);
- }
- void velocityCompensation(int playerNumber, Vector enemyPos, DWORD clientDll, HANDLE hProc)
- {
- Vector enemyVel{};
- Vector myVel{};
- Entity.getVelocity(playerNumber, enemyVel, clientDll, hProc);
- Player.getVelocity(myVel, clientDll, hProc);
- enemyPos.x = enemyPos.x + (enemyVel.x / 100.0f) * (40.0f / smoothAmount);
- enemyPos.y = enemyPos.y + (enemyVel.y / 100.0f) * (40.0f / smoothAmount);
- enemyPos.z = enemyPos.z + (enemyVel.z / 100.0f) * (40.0f / smoothAmount);
- enemyPos.x = enemyPos.x - (myVel.x / 100.0f) * (40.0f / smoothAmount);
- enemyPos.y = enemyPos.y - (myVel.y / 100.0f) * (40.0f / smoothAmount);
- enemyPos.z = enemyPos.z - (myVel.z / 100.0f) * (40.0f / smoothAmount);
- }
- int main()
- {
- DWORD pId;
- HANDLE hProc;
- DWORD clientDll = NULL;
- DWORD engineDll = NULL;
- HWND hwnd = FindWindow(NULL, "Counter-Strike: Global Offensive");
- GetWindowThreadProcessId(hwnd, &pId);
- clientDll = getDll(pId, "client.dll");
- engineDll = getDll(pId, "engine.dll");
- hProc = OpenProcess(PROCESS_ALL_ACCESS, NULL, pId);
- while (true)
- {
- int playerNumber = Player.getCrosshairId(clientDll, hProc);
- while (GetAsyncKeyState(0x02) < 0 && Player.getShotsFired(clientDll, hProc) > 1 && playerNumber < 64 && playerNumber >= 0 && Entity.getTeam(playerNumber, clientDll, hProc) != Player.getTeam(clientDll, hProc) && Entity.isDead(playerNumber, clientDll, hProc) != true)
- {
- int tempPlayerNumber = Player.getCrosshairId(clientDll, hProc);
- if (tempPlayerNumber < 64 && tempPlayerNumber >= 0 && Entity.getTeam(tempPlayerNumber, clientDll, hProc) != Player.getTeam(clientDll, hProc) && Entity.isDead(tempPlayerNumber, clientDll, hProc) != true)
- {
- playerNumber = tempPlayerNumber;
- }
- Vector playerPos{};
- Vector enemyPos{};
- Vector aimAngle{};
- Vector currentAngle{};
- Player.getPosition(playerPos, clientDll, hProc);
- Entity.getBonePosition(playerNumber, enemyPos, clientDll, hProc);
- velocityCompensation(playerNumber, enemyPos, clientDll, hProc);
- calcAngle(playerPos, enemyPos, aimAngle, clientDll, hProc);
- Normalize(aimAngle);
- smoothAngleFunc(aimAngle, currentAngle, engineDll, hProc);
- Sleep(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment