Guest User

Untitled

a guest
Jul 13th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. #include <windows.h>
  2. #include <TlHelp32.h>
  3. #include <cstdio>
  4. #include <windows.h>
  5. #include <conio.h>
  6. #include <FCNTL.H>
  7. #include <io.h>
  8. #include <iostream>
  9. #include <string>
  10. #include <sstream>
  11. #include <random>
  12. #include <stdint.h>
  13. #include <cmath>
  14.  
  15. using namespace std;
  16.  
  17. const DWORD DwEntityList = 0x4A4EC04;
  18. const DWORD DwEnginePointer = 0x00667ABC;
  19. const DWORD DwLocalPlayer = 0x00A33504;
  20.  
  21. const DWORD DwCrosshairId = 0x0000AA44;
  22. const DWORD DwViewAngle = 0x00004D0C;
  23. const DWORD DwVecViewOrigin = 0x104;
  24. const DWORD DwVecOrigin = 0x134;
  25. const DWORD DwVecPunch = 0x00003018;
  26. const DWORD DwTeamNumber = 0xF0;
  27. const DWORD DwShotsFired = 0xA2B0;
  28. const DWORD DwFlags = 0x100;
  29. const DWORD DwBoneMatrix = 0x00002698;
  30. const DWORD DwEntitySize = 0x10;
  31. const DWORD DwHealth = 0xFC;
  32. const DWORD DwLifeState = 0x25B;
  33. const DWORD DwVecVelocity = 0x110;
  34.  
  35.  
  36. int targetBone = 10;
  37. float PitchMinPunch = 2.f;
  38. float PitchMaxPunch = 2.f;
  39. float YawMinPunch = 2.f;
  40. float YawMaxPunch = 2.f;
  41. float smoothAmount = 20.f;
  42.  
  43. typedef struct Vector_
  44. {
  45. float x;
  46. float y;
  47. float z;
  48. }Vector;
  49.  
  50. template <class type>
  51. type ReadMem(HANDLE hProc, DWORD address)
  52. {
  53. type val;
  54. ReadProcessMemory(hProc, (LPCVOID)(address), &val, sizeof(val), NULL);
  55. return val;
  56. }
  57.  
  58. template <class type>
  59. void WriteMem(HANDLE hProc, DWORD address, type val)
  60. {
  61. WriteProcessMemory(hProc, (LPVOID)(address), &val, sizeof(val), NULL);
  62. }
  63.  
  64. DWORD getDll(DWORD pId, char* NAME)
  65. {
  66. DWORD clientDll = 0x0;
  67. MODULEENTRY32 moduleEntry;
  68. moduleEntry.dwSize = sizeof(MODULEENTRY32);
  69. HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId);
  70.  
  71. do
  72. {
  73. if (!strcmp(moduleEntry.szModule, NAME))
  74. {
  75. clientDll = (DWORD)moduleEntry.modBaseAddr;
  76. break;
  77. }
  78. } while (Module32Next(hSnap, &moduleEntry));
  79. CloseHandle(hSnap);
  80. return clientDll;
  81. }
  82.  
  83. struct
  84. {
  85. DWORD getBaseEntity(int playerNumber, DWORD clientDll, HANDLE hProc)
  86. {
  87. return ReadMem<DWORD>(hProc, (clientDll + DwEntityList + (DwEntitySize * playerNumber)));
  88. }
  89.  
  90. bool isDead(int playerNumber, DWORD clientDll, HANDLE hProc)
  91. {
  92. DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
  93. if (baseEntity)
  94. {
  95. return ReadMem<bool>(hProc, (baseEntity + DwLifeState));
  96. }
  97. }
  98.  
  99. int getTeam(int playerNumber, DWORD clientDll, HANDLE hProc)
  100. {
  101. DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
  102. if (baseEntity)
  103. {
  104. return ReadMem<int>(hProc, (baseEntity + DwTeamNumber));
  105. }
  106. }
  107.  
  108. void getVelocity(int playerNumber, Vector buffer, DWORD clientDll, HANDLE hProc)
  109. {
  110. DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
  111. if (baseEntity)
  112. {
  113. ReadMem<Vector>(hProc, (baseEntity + DwVecVelocity));
  114. }
  115. }
  116.  
  117. void getBonePosition(int playerNumber, Vector bonePosition, DWORD clientDll, HANDLE hProc)
  118. {
  119. DWORD baseEntity = getBaseEntity(playerNumber, clientDll, hProc);
  120. if (baseEntity)
  121. {
  122. DWORD boneMatrix = ReadMem<DWORD>(hProc, (baseEntity + DwBoneMatrix));
  123. if (boneMatrix)
  124. {
  125. ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x0C), &bonePosition.x, sizeof(bonePosition), NULL);
  126. ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x1C), &bonePosition.y, sizeof(bonePosition), NULL);
  127. ReadProcessMemory(hProc, (LPCVOID)(boneMatrix + 0x30 * targetBone + 0x2C), &bonePosition.z, sizeof(bonePosition), NULL);
  128. }
  129. }
  130. }
  131. }Entity;
  132.  
  133. struct
  134. {
  135. DWORD getPlayerBase(DWORD clientDll, HANDLE hProc)
  136. {
  137. return ReadMem<DWORD>(hProc, (clientDll + DwLocalPlayer));
  138. }
  139.  
  140. void setAngles(Vector angles, DWORD engineDll, HANDLE hProc)
  141. {
  142. DWORD anglePointer = ReadMem<DWORD>(hProc, (engineDll + DwEnginePointer));
  143. if (anglePointer)
  144. {
  145. WriteMem<Vector>(hProc, (anglePointer + DwViewAngle), angles);
  146. }
  147. }
  148.  
  149. void getVelocity(Vector buffer, DWORD clientDll, HANDLE hProc)
  150. {
  151. DWORD playerBase = getPlayerBase(clientDll, hProc);
  152. if (playerBase)
  153. {
  154. ReadMem<Vector>(hProc, (playerBase + DwVecVelocity));
  155. }
  156. }
  157.  
  158. void getAngles(Vector angles, DWORD engineDll, HANDLE hProc)
  159. {
  160. DWORD anglePointer = ReadMem<DWORD>(hProc, (engineDll + DwEnginePointer));
  161. if (anglePointer)
  162. {
  163. ReadMem<Vector>(hProc, (anglePointer + DwViewAngle));
  164. }
  165. }
  166.  
  167. int getTeam(DWORD clientDll, HANDLE hProc)
  168. {
  169. DWORD playerBase = getPlayerBase(clientDll, hProc);
  170. if (playerBase)
  171. {
  172. return ReadMem<int>(hProc, (playerBase + DwTeamNumber));
  173. }
  174. }
  175.  
  176. int getCrosshairId(DWORD clientDll, HANDLE hProc)
  177. {
  178. DWORD playerBase = getPlayerBase(clientDll, hProc);
  179. if (playerBase)
  180. {
  181. return ReadMem<int>(hProc, ((playerBase + DwCrosshairId) - 1));
  182. }
  183. }
  184.  
  185. void getPunch(Vector punch, DWORD clientDll, HANDLE hProc)
  186. {
  187. DWORD playerBase = getPlayerBase(clientDll, hProc);
  188. if (playerBase)
  189. {
  190. ReadMem<Vector>(hProc, (playerBase + DwVecPunch));
  191. }
  192. }
  193.  
  194. float getViewOrigin(DWORD clientDll, HANDLE hProc)
  195. {
  196. DWORD playerBase = getPlayerBase(clientDll, hProc);
  197. if (playerBase)
  198. {
  199. float vecView[3];
  200. ReadProcessMemory(hProc, (LPCVOID)(playerBase + DwVecViewOrigin), &vecView, sizeof(vecView), NULL);
  201. return vecView[2];
  202. }
  203. }
  204.  
  205. void getPosition(Vector position, DWORD clientDll, HANDLE hProc)
  206. {
  207. DWORD playerBase = getPlayerBase(clientDll, hProc);
  208. if (playerBase)
  209. {
  210. ReadMem<Vector>(hProc, (playerBase + DwVecOrigin));
  211. }
  212. }
  213.  
  214. int getShotsFired(DWORD clientDll, HANDLE hProc)
  215. {
  216. DWORD playerBase = getPlayerBase(clientDll, hProc);
  217. if (playerBase)
  218. {
  219. return ReadMem<int>(hProc, (playerBase + DwShotsFired));
  220. }
  221. }
  222. }Player;
  223.  
  224. void Normalize(Vector vec)
  225. {
  226. if (vec.y > 180.f)
  227. vec.y -= 360.f;
  228. else if (vec.y < -180.f)
  229. vec.y += 360.f;
  230. if (vec.x > 89.f)
  231. vec.x = 89.f;
  232. else if (vec.y < -89.f)
  233. vec.x = -89.f;
  234.  
  235. vec.z = 0.f;
  236. }
  237.  
  238. void calcAngle(Vector src, Vector dst, Vector angles, DWORD clientDll, HANDLE hProc)
  239. {
  240. random_device Random;
  241. mt19937 RandomGen(Random());
  242. uniform_real<float> RandomXdistrib(PitchMinPunch, PitchMaxPunch);
  243. uniform_real<float> RandomYdistrib(YawMinPunch, YawMaxPunch);
  244. Vector myPunch{};
  245. Player.getPunch(myPunch, clientDll, hProc);
  246. float pitchReduction = RandomXdistrib(RandomGen);
  247. float yawReduction = RandomYdistrib(RandomGen);
  248. Vector delta;
  249. delta.x = (src.x - dst.x);
  250. delta.y = (src.y - dst.y);
  251. delta.z = ((src.z + Player.getViewOrigin(clientDll, hProc) - dst.z));
  252. float hyp = sqrt(delta.x * delta.x + delta.y * delta.y);
  253. angles.x = atanf(delta.z / hyp) * 57.295779513082f - myPunch.x * pitchReduction;
  254. angles.y = atanf(delta.y / delta.x) * 57.295779513082f - myPunch.y * yawReduction;
  255. angles.z = 0.0f;
  256. if (delta.x >= 0.0)
  257. {
  258. angles.y += 180.0f;
  259. }
  260. }
  261.  
  262. void smoothAngleFunc(Vector dest, Vector orig, DWORD engineDll, HANDLE hProc)
  263. {
  264. Vector smoothAngles;
  265. smoothAngles.x = dest.x - orig.x;
  266. smoothAngles.y = dest.y - orig.y;
  267. smoothAngles.z = 0.0f;
  268. Normalize(smoothAngles);
  269. smoothAngles.x = orig.x + smoothAngles.x / 100.0f * smoothAmount;
  270. smoothAngles.y = orig.y + smoothAngles.y / 100.0f * smoothAmount;
  271. smoothAngles.z = 0.0f;
  272. Normalize(smoothAngles);
  273. Player.setAngles(smoothAngles, engineDll, hProc);
  274. Sleep(1);
  275. }
  276.  
  277. void velocityCompensation(int playerNumber, Vector enemyPos, DWORD clientDll, HANDLE hProc)
  278. {
  279. Vector enemyVel{};
  280. Vector myVel{};
  281. Entity.getVelocity(playerNumber, enemyVel, clientDll, hProc);
  282. Player.getVelocity(myVel, clientDll, hProc);
  283. enemyPos.x = enemyPos.x + (enemyVel.x / 100.0f) * (40.0f / smoothAmount);
  284. enemyPos.y = enemyPos.y + (enemyVel.y / 100.0f) * (40.0f / smoothAmount);
  285. enemyPos.z = enemyPos.z + (enemyVel.z / 100.0f) * (40.0f / smoothAmount);
  286. enemyPos.x = enemyPos.x - (myVel.x / 100.0f) * (40.0f / smoothAmount);
  287. enemyPos.y = enemyPos.y - (myVel.y / 100.0f) * (40.0f / smoothAmount);
  288. enemyPos.z = enemyPos.z - (myVel.z / 100.0f) * (40.0f / smoothAmount);
  289. }
  290.  
  291. int main()
  292. {
  293. DWORD pId;
  294. HANDLE hProc;
  295. DWORD clientDll = NULL;
  296. DWORD engineDll = NULL;
  297. HWND hwnd = FindWindow(NULL, "Counter-Strike: Global Offensive");
  298. GetWindowThreadProcessId(hwnd, &pId);
  299. clientDll = getDll(pId, "client.dll");
  300. engineDll = getDll(pId, "engine.dll");
  301. hProc = OpenProcess(PROCESS_ALL_ACCESS, NULL, pId);
  302.  
  303. while (true)
  304. {
  305. int playerNumber = Player.getCrosshairId(clientDll, hProc);
  306. 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)
  307. {
  308. int tempPlayerNumber = Player.getCrosshairId(clientDll, hProc);
  309. if (tempPlayerNumber < 64 && tempPlayerNumber >= 0 && Entity.getTeam(tempPlayerNumber, clientDll, hProc) != Player.getTeam(clientDll, hProc) && Entity.isDead(tempPlayerNumber, clientDll, hProc) != true)
  310. {
  311. playerNumber = tempPlayerNumber;
  312. }
  313. Vector playerPos{};
  314. Vector enemyPos{};
  315. Vector aimAngle{};
  316. Vector currentAngle{};
  317. Player.getPosition(playerPos, clientDll, hProc);
  318. Entity.getBonePosition(playerNumber, enemyPos, clientDll, hProc);
  319. velocityCompensation(playerNumber, enemyPos, clientDll, hProc);
  320. calcAngle(playerPos, enemyPos, aimAngle, clientDll, hProc);
  321. Normalize(aimAngle);
  322. smoothAngleFunc(aimAngle, currentAngle, engineDll, hProc);
  323. Sleep(1);
  324. }
  325. }
  326. }
Advertisement
Add Comment
Please, Sign In to add comment