Advertisement
chrondog

Untitled

Jan 3rd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.37 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <TlHelp32.h>
  5. #include <ModuleProcess.h>
  6. #include <math.h>
  7. using namespace std;
  8.  
  9.  
  10. HANDLE hl2Handle;
  11. DWORD hl2Process;
  12.  
  13. ULONG Client;
  14. ULONG Engine;
  15.  
  16. int Offset_base = 0,
  17. Offset_name = 0x38,
  18. Offset_team = 0x58,
  19. Offset_health = 0x5c,
  20. Offset_xpos = 0x60,
  21. Offset_ypos = 0x64,
  22. Offset_zpos = 0x68,
  23. Offset_anghor = 0x34,
  24. Offset_angvert = 0x38,
  25. Offset_playerid = 0x168,
  26. Offset_interval = 0x140;
  27.  
  28. void GetAngleToEnemy(float MyPos[3], float EnemyPos[3], float& Horizontal, float& Vertical);
  29. void GetEnemyPosition(int PlayerID, float& X_POS, float& Y_POS, float& Z_POS);
  30. void GetEnemyAngles(int PlayerID, float& Horizontal, float& Vertical);
  31. void GetMyPosition(float& X_POS, float& Y_POS, float& Z_POS);
  32. void GetMyAngles(float& Vertical, float& Horizontal);
  33. void SetAngles(float HorizontalAngleToEnemy, float VerticalAngleToEnemy);
  34.  
  35. int main()
  36. {
  37.     hl2Handle = GetProcessHandle("hl2.exe", hl2Process);
  38.     Client = GetModuleAddress("client.dll", hl2Process);
  39.     Engine = GetModuleAddress("engine.dll", hl2Process);
  40.     ReadProcessMemory(hl2Handle, LPCVOID(Client+0x791240), &Offset_base, sizeof(Offset_base), 0);
  41.     float MyPos[3], EnemyPos[3], MyAngles[2], EnemyAngles[2];
  42.     while(1)
  43.     {
  44.         if(GetKeyState(VK_SPACE) & (1 << 15))
  45.         {
  46.             GetMyPosition(MyPos[0], MyPos[1], MyPos[2]);
  47.             GetEnemyPosition(2, EnemyPos[0], EnemyPos[1], EnemyPos[2]);
  48.             GetAngleToEnemy(MyPos, EnemyPos, Horizontal, Vertical);
  49.             SetAngles(Horizontal, Vertical);
  50.             Sleep(1);
  51.         }
  52.         else
  53.             Sleep(1);
  54.     }
  55.     cin.get();
  56. }
  57.  
  58. void SetAngles(float HorizontalAngleToEnemy, float VerticalAngleToEnemy)
  59. {
  60.     int X_Change = 0, Y_Change = 0;
  61.     POINT CursorPos;
  62.     GetCursorPos(&CursorPos);
  63.     float MyAngles[2];
  64.     GetMyAngles(MyAngles[0], MyAngles[1]);
  65.     float DifferenceHor = HorizontalAngleToEnemy-MyAngles[0];
  66.     float DifferenceVert = VerticalAngleToEnemy-MyAngles[1];
  67.     cout << DifferenceHor << endl;
  68.     if(DifferenceHor <= 0.5 && DifferenceHor >= -0.5 && DifferenceVert >= -0.5 && DifferenceVert <= 0.5)
  69.         PressKey(0x25, 300);
  70.     else
  71.     {
  72.         if(DifferenceHor < 0)
  73.             X_Change = 10;
  74.         else if(DifferenceHor > 0)
  75.             X_Change = -10;
  76.         if(DifferenceVert < 0)
  77.             Y_Change = -10;
  78.         else if(DifferenceVert > 0)
  79.             Y_Change = 10;
  80.         //SetCursorPos(CursorPos.x + X_Change, CursorPos.y + Y_Change);
  81.     }
  82. }
  83.  
  84. void GetAngleToEnemy(float MyPos[3], float EnemyPos[3], float& Horizontal, float& Vertical)
  85. {
  86.     float PI = 3.141592654;
  87.     float deltaX = EnemyPos[0] - MyPos[0];
  88.     float deltaY = EnemyPos[1] - MyPos[1];
  89.     float deltaZ = EnemyPos[2] - MyPos[2];
  90.     Horizontal = atan2(deltaY, deltaX) * (180 / PI);
  91.     if (Horizontal < 0)
  92.         Horizontal = 360 - abs(Horizontal);
  93.     float Distance = sqrtf((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
  94.     Vertical = -(asin(deltaZ/Distance) * 180/PI);
  95. }
  96.  
  97. void GetEnemyPosition(int PlayerID, float& X_POS, float& Y_POS, float& Z_POS)
  98. {
  99.     PlayerID-=1;
  100.     ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_xpos + (PlayerID * Offset_interval))), &X_POS, sizeof(X_POS), NULL);
  101.     ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_ypos + (PlayerID * Offset_interval))), &Y_POS, sizeof(Y_POS), NULL);
  102.     ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_zpos + (PlayerID * Offset_interval))), &Z_POS, sizeof(Z_POS), NULL);
  103. }
  104.  
  105. void GetEnemyAngles(int PlayerID, float& Horizontal, float& Vertical)
  106. {
  107.     PlayerID-=1;
  108.     ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_anghor + (PlayerID * Offset_interval))), &Horizontal, sizeof(Horizontal), NULL);
  109.     ReadProcessMemory(hl2Handle, LPCVOID(Offset_base + (Offset_angvert + (PlayerID * Offset_interval))), &Horizontal, sizeof(Horizontal), NULL);
  110. }
  111.  
  112. void GetMyPosition(float& X_POS, float& Y_POS, float& Z_POS)
  113. {
  114.     ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841960), &X_POS, sizeof(X_POS), NULL);
  115.     ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841964), &Y_POS, sizeof(Y_POS), NULL);
  116.     ReadProcessMemory(hl2Handle, LPCVOID(Client + 0x3841968), &Z_POS, sizeof(Z_POS), NULL);
  117. }
  118.  
  119. void GetMyAngles(float& Horizontal, float& Vertical)
  120. {
  121.     #define HORIZONTAL_OFFSET 0x431410
  122.     #define VERTICAL_OFFSET 0x43140C
  123.     ReadProcessMemory(hl2Handle, LPCVOID(Engine + HORIZONTAL_OFFSET), &Horizontal, sizeof(Horizontal), NULL);
  124.     if (Horizontal < 0)
  125.         Horizontal = 360 - abs(Horizontal);
  126.     ReadProcessMemory(hl2Handle, LPCVOID(Engine + VERTICAL_OFFSET), &Vertical, sizeof(Vertical), NULL);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement