Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. #ifndef TRIGGERBOT_H
  2. #define TRIGGERBOT_H
  3.  
  4. #include <iostream>
  5. #include <Windows.h>
  6. #include "Engine.h"
  7. #include "Settings.h"
  8. #include "Vector.h"
  9. #include "PMemory.h"
  10. #include "Offsets.h"
  11. #include "Weapon.h"
  12. #include "Utils.h"
  13.  
  14. using namespace std;
  15.  
  16. bool b_true = true;
  17. bool b_false = false;
  18.  
  19. bool attackState = false;
  20.  
  21. bool useCoords = false;
  22. bool useCeid = true;
  23. bool msgSent = false;
  24.  
  25. RECT m_Rect;
  26.  
  27. typedef struct
  28. {
  29. float flMatrix[4][4];
  30. }
  31.  
  32. WorldToScreenMatrix;
  33.  
  34. struct MyPlayer
  35. {
  36. DWORD CLocalPlayer;
  37. DWORD CViewMatrix;
  38. DWORD CWeaponBase;
  39. int CrosshairEntityId;
  40. int Team;
  41. Vector Position;
  42. int WeaponID;
  43. Vector Velocity;
  44. WorldToScreenMatrix WorldToScreenMatrix;
  45.  
  46. void ReadInfo()
  47. {
  48. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwLocalPlayer);
  49. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwInCross);
  50. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwTeam);
  51.  
  52. ReadViewMatrix();
  53. ReadWeaponId();
  54. }
  55.  
  56. void ReadViewMatrix()
  57. {
  58. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dw_local_view_offset);
  59. Engine()->Memory()->Read<BYTE>(CViewMatrix, WorldToScreenMatrix + (sizeof(WorldToScreenMatrix)));
  60.  
  61. }
  62.  
  63. void ReadWeaponId()
  64. {
  65. int WeaponHandle;
  66. int WeaponIDFirst;
  67.  
  68. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwActiveWeapon);
  69. WeaponIDFirst = WeaponHandle & 0xFFF;
  70. Engine()->Memory()->Read<BYTE>(Engine()->me.dwBase + Engine()->Offsets()->dwEntityList + (-0x10 + (WeaponIDFirst * 0x10)) &CWeaponBase, 4, NULL);
  71. Engine()->Memory()->Read<BYTE>(Engine()->me.dwBase + Engine()->Offsets()->dwWeaponId + CWeaponBase, &WeaponID, 4, NULL);
  72. }
  73. }MyPlayer;
  74.  
  75. struct PlayerList_t
  76. {
  77. DWORD CBaseEntity;
  78. int Team;
  79. Vector Position;
  80.  
  81. void ReadInformation(int ceid)
  82. {
  83. DWORD offset = Engine()->Offsets()->dwEntityList + ((ceid - 1) * Engine()->Offsets()->dw_entity_size);
  84. ReadProcessMemory(fProcess.__HandleProcess,
  85. (PBYTE*)(fProcess.__dwordClient + offset),
  86. &CBaseEntity, sizeof(DWORD), 0);
  87. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwTeam);
  88. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwVecOrigin);
  89. }
  90. }PlayerList[32];
  91.  
  92. FLOAT fScreenx, fScreeny;
  93. BOOL ScreenTransform(CONST Vector& point, OUT Vector& screen)
  94. {
  95. float worldToScreen[4][4];
  96. memcpy(worldToScreen, MyPlayer.WorldToScreenMatrix.flMatrix,
  97. sizeof(worldToScreen));
  98.  
  99. screen.x = worldToScreen[0][0]
  100. * point.x + worldToScreen[0][1]
  101. * point.y + worldToScreen[0][2]
  102. * point.z + worldToScreen[0][3];
  103. screen.y = worldToScreen[1][0]
  104. * point.x + worldToScreen[1][1]
  105. * point.y + worldToScreen[1][2]
  106. * point.z + worldToScreen[1][3];
  107.  
  108. FLOAT w;
  109. w = worldToScreen[3][0]
  110. * point.x + worldToScreen[3][1]
  111. * point.y + worldToScreen[3][2]
  112. * point.z + worldToScreen[3][3];
  113. screen.z = 0.0f;
  114.  
  115. BOOL behind = FALSE;
  116. if (w < 0.001f)
  117. {
  118. behind = TRUE;
  119. screen.x *= 100000;
  120. screen.y *= 100000;
  121. }
  122. else
  123. {
  124. FLOAT invw = 1.0f / w;
  125. screen.x *= invw;
  126. screen.y *= invw;
  127. }
  128.  
  129. return behind;
  130. }
  131.  
  132. BOOL WorldToScreen(CONST Vector &origin, OUT Vector &screen)
  133. {
  134. BOOL bRet = FALSE;
  135.  
  136. if (!ScreenTransform(origin, screen))
  137. {
  138. INT width = (int)(m_Rect.right - m_Rect.left);
  139. INT height = (int)(m_Rect.bottom - m_Rect.top);
  140.  
  141. fScreenx = width / 2.0f;
  142. fScreeny = height / 2.0f;
  143.  
  144. fScreenx += 0.5f * screen.x * width + 0.5f;
  145. fScreeny -= 0.5f * screen.y * height + 0.5f;
  146.  
  147. screen.x = fScreenx;
  148. screen.y = fScreeny;
  149.  
  150. bRet = TRUE;
  151. }
  152.  
  153. return bRet;
  154. }
  155.  
  156. int mp_playerid()
  157. {
  158. if (!useCeid)
  159. return 1;
  160.  
  161. int out;
  162. Engine()->Memory()->Read<int>(Engine()->me.dwBase + Engine()->Offsets()->dwActiveWeapon, &out, <int>, 0);
  163. if (!msgSent && out > 0)
  164. {
  165. cout << "WARNING: mp_playerid is nonzero. "
  166. << "This may affect triggerbot accuracy, as boundingbox will be used"
  167. << endl;
  168. msgSent = true;
  169. }
  170. return out;
  171. }
  172.  
  173. int NumberOfPlayers()
  174. {
  175. return 32;
  176. }
  177.  
  178. void Attack()
  179. {
  180. if (!attackState)
  181. {
  182. attackState = true;
  183. Engine()->Memory()->Write<int>(Engine()->getClientModule()->dwBase + Engine()->Offsets()->dwAttack, 1);
  184. }
  185. else
  186. {
  187. attackState = false;
  188. Engine()->Memory()->Write<int>(Engine()->getClientModule()->dwBase + Engine()->Offsets()->dwAttack, 0);
  189. }
  190. Sleep(1);
  191. }
  192.  
  193. int halfWidth = (int)(m_Rect.right - m_Rect.left) / 2;
  194. int halfHeight = (int)(m_Rect.bottom - m_Rect.top) / 2;
  195.  
  196. class Triggerbot
  197. {
  198.  
  199. public:
  200. void run()
  201. {
  202. bool attackState = false;
  203. while (true)
  204. if (attackState && IsWeaponSemiAuto(MyPlayer.WeaponID))
  205. Attack();
  206.  
  207. if (Settings()->triggerEnabled || GetAsyncKeyState(Settings()->trigger_holdkey))
  208. {
  209. if (attackState)
  210. Attack();
  211. }
  212.  
  213. MyPlayer.ReadInfo();
  214. if (IsWeaponNonAim(MyPlayer.WeaponID))
  215.  
  216. bool hit = false;
  217. for (int i = 1; i <= NumberOfPlayers(); ++i)
  218. {
  219. PlayerList[i].ReadInformation(i);
  220. if (!((MyPlayer.CrosshairEntityId > 0
  221. && MyPlayer.CrosshairEntityId <= NumberOfPlayers())
  222. || mp_playerid() > 0))
  223. {
  224. if (attackState && !IsWeaponSemiAuto(MyPlayer.WeaponID))
  225. Attack();
  226. continue;
  227. }
  228.  
  229. PlayerList[i].ReadInformation(i);
  230. if (MyPlayer.Team == PlayerList[i].Team && Settings()->ALLOW_FRIENDLYFIRE)
  231. continue;
  232.  
  233. bool shouldShoot = true;
  234. if (useCoords && !IsWeaponScoped(MyPlayer.WeaponID))
  235. {
  236. shouldShoot = false;
  237. Vector ScreenPos;
  238. if (WorldToScreen(PlayerList[i].Position, ScreenPos))
  239. {
  240. double distance = Get3dDistance(MyPlayer, Position, PlayerList[i].Position);
  241. int playerWidth = (int)max(Settings()->PLAYER_WIDTH / distance, 11);
  242. int playerHeight = (int)max(Settings()->PLAYER_HEIGHT / distance, 5);
  243. int halfPlayerWidth = (int)(playerWidth / 2);
  244. int heightOffset = (int)(Settings()->PLAYER_HEIGHT_OFFSET / distance);
  245.  
  246. if (ScreenPos.x > halfWidth - halfPlayerWidth
  247. && ScreenPos.x < halfWidth + halfPlayerWidth
  248. && ScreenPos.y > halfHeight + heightOffset
  249. && ScreenPos.y < halfHeight + playerHeight + heightOffset)
  250. shouldShoot = true;
  251. }
  252. }
  253. if (shouldShoot)
  254. {
  255. bool hit = true;
  256. if (Settings()->DELAY > 0)
  257. {
  258. Sleep(Settings()->DELAY);
  259. }
  260. if (!attackState)
  261. Attack();
  262. Sleep(35);
  263. break;
  264. }
  265. }
  266. Sleep(1);
  267. }
  268. };
  269.  
  270. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement