Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #include <iostream>
- #include <TlHelp32.h>
- #include <ModuleProcess.h>
- #include <math.h>
- using namespace std;
- HANDLE hl2Handle;
- DWORD hl2Process;
- ULONG Client;
- ULONG Engine;
- int Offset_base = 0,
- Offset_name = 0x38,
- Offset_team = 0x58,
- Offset_health = 0x5c,
- Offset_xpos = 0x60,
- Offset_ypos = 0x64,
- Offset_zpos = 0x68,
- Offset_anghor = 0x34,
- Offset_angvert = 0x38,
- Offset_playerid = 0x168,
- Offset_interval = 0x140;
- void GetAngleToEnemy(float MyPos[3], float EnemyPos[3], float& Horizontal, float& Vertical);
- void GetEnemyPosition(int PlayerID, float& X_POS, float& Y_POS, float& Z_POS);
- void GetEnemyAngles(int PlayerID, float& Horizontal, float& Vertical);
- void GetMyPosition(float& X_POS, float& Y_POS, float& Z_POS);
- void GetMyAngles(float& Vertical, float& Horizontal);
- void SetAngles(float HorizontalAngleToEnemy, float VerticalAngleToEnemy);
- int main()
- {
- hl2Handle = GetProcessHandle("hl2.exe", hl2Process);
- Client = GetModuleAddress("client.dll", hl2Process);
- Engine = GetModuleAddress("engine.dll", hl2Process);
- ReadProcessMemory(hl2Handle, LPCVOID(Client+0x791240), &Offset_base, sizeof(Offset_base), 0);
- float MyPos[3], EnemyPos[3], MyAngles[2], EnemyAngles[2];
- while(1)
- {
- if(GetKeyState(VK_SPACE) & (1 << 15))
- {
- GetMyPosition(MyPos[0], MyPos[1], MyPos[2]);
- GetEnemyPosition(2, EnemyPos[0], EnemyPos[1], EnemyPos[2]);
- GetAngleToEnemy(MyPos, EnemyPos, Horizontal, Vertical);
- SetAngles(Horizontal, Vertical);
- Sleep(1);
- }
- else
- Sleep(1);
- }
- cin.get();
- }
- void SetAngles(float HorizontalAngleToEnemy, float VerticalAngleToEnemy)
- {
- int X_Change = 0, Y_Change = 0;
- POINT CursorPos;
- GetCursorPos(&CursorPos);
- float MyAngles[2];
- GetMyAngles(MyAngles[0], MyAngles[1]);
- float DifferenceHor = HorizontalAngleToEnemy-MyAngles[0];
- float DifferenceVert = VerticalAngleToEnemy-MyAngles[1];
- cout << DifferenceHor << endl;
- if(DifferenceHor <= 0.5 && DifferenceHor >= -0.5 && DifferenceVert >= -0.5 && DifferenceVert <= 0.5)
- PressKey(0x25, 300);
- else
- {
- if(DifferenceHor < 0)
- X_Change = 10;
- else if(DifferenceHor > 0)
- X_Change = -10;
- if(DifferenceVert < 0)
- Y_Change = -10;
- else if(DifferenceVert > 0)
- Y_Change = 10;
- //SetCursorPos(CursorPos.x + X_Change, CursorPos.y + Y_Change);
- }
- }
- void GetAngleToEnemy(float MyPos[3], float EnemyPos[3], float& Horizontal, float& Vertical)
- {
- float PI = 3.141592654;
- float deltaX = EnemyPos[0] - MyPos[0];
- float deltaY = EnemyPos[1] - MyPos[1];
- float deltaZ = EnemyPos[2] - MyPos[2];
- Horizontal = atan2(deltaY, deltaX) * (180 / PI);
- if (Horizontal < 0)
- Horizontal = 360 - abs(Horizontal);
- float Distance = sqrtf((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
- Vertical = -(asin(deltaZ/Distance) * 180/PI);
- }
- void GetEnemyPosition(int PlayerID, float& X_POS, float& Y_POS, float& Z_POS)
- {
- PlayerID-=1;
- ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_xpos + (PlayerID * Offset_interval))), &X_POS, sizeof(X_POS), NULL);
- ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_ypos + (PlayerID * Offset_interval))), &Y_POS, sizeof(Y_POS), NULL);
- ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_zpos + (PlayerID * Offset_interval))), &Z_POS, sizeof(Z_POS), NULL);
- }
- void GetEnemyAngles(int PlayerID, float& Horizontal, float& Vertical)
- {
- PlayerID-=1;
- ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_anghor + (PlayerID * Offset_interval))), &Horizontal, sizeof(Horizontal), NULL);
- ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_angvert + (PlayerID * Offset_interval))), &Horizontal, sizeof(Horizontal), NULL);
- }
- void GetMyPosition(float& X_POS, float& Y_POS, float& Z_POS)
- {
- ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841960), &X_POS, sizeof(X_POS), NULL);
- ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841964), &Y_POS, sizeof(Y_POS), NULL);
- ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841968), &Z_POS, sizeof(Z_POS), NULL);
- }
- void GetMyAngles(float& Horizontal, float& Vertical)
- {
- #define HORIZONTAL_OFFSET 0x431410
- #define VERTICAL_OFFSET 0x43140C
- ReadProcessMemory(hl2Handle, LPCVOID(Engine + HORIZONTAL_OFFSET), &Horizontal, sizeof(Horizontal), NULL);
- if (Horizontal < 0)
- Horizontal = 360 - abs(Horizontal);
- ReadProcessMemory(hl2Handle, LPCVOID(Engine + VERTICAL_OFFSET), &Vertical, sizeof(Vertical), NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement