Advertisement
Guest User

Ai irmao

a guest
Nov 28th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.04 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Threading;
  10. //Our DirectX libs
  11. using Microsoft.DirectX;
  12. using Microsoft.DirectX.Direct3D;
  13. using ProcessMemoryReaderLib;
  14. using System.Diagnostics;
  15.  
  16. namespace External_ESP_Aimbot
  17. {
  18. public partial class DirectXOverlayFRM : Form
  19. {
  20.  
  21. //the variables that decide our crosshair information
  22. string WindowName;
  23.  
  24. bool _StopThread; //used to stop the crosshair thread from outside
  25. public bool threadOver;
  26. int _Scale = 0;
  27.  
  28. //ESP Vars
  29. float ScreenX, ScreenY;
  30. int[] resolution;
  31. int[] screencenter;
  32. float[] fov;
  33. Vect3d viewAngles;
  34. Vect3d vForward, vRight, vUpward;
  35. ProcessMemoryReader Mem;
  36. IntPtr handle;//Window handle
  37. RECT windowRectangle; // stores our window's data
  38. int _ScaleESP = 1;// Draw all ESP's at medium size
  39.  
  40. //Aimbot m Esp Vars
  41. //Used to ensure we stay focused on an enemy as long as we hold the HOT KEY, if we let go of it then when pressing again we find a new enemy
  42. bool FocusingOnEnemy = false;
  43. int FocusTarget = -1;
  44. int EspChoice;
  45. const int MAXPLAYERS = 64;
  46.  
  47.  
  48. public DirectXOverlayFRM(string windowName, int espChoice, ProcessMemoryReader mem)
  49. {
  50. Mem = mem;
  51. //grab our information
  52. threadOver = false;
  53. _StopThread = false;
  54. WindowName = windowName;
  55. EspChoice = espChoice;
  56. SetupVars();
  57. InitializeComponent();
  58. SetupDX();
  59. }
  60.  
  61. private void SetupVars()
  62. {
  63. resolution = new int[2];
  64. screencenter = new int[2];
  65. fov = new float[2];
  66. viewAngles = new Vect3d();
  67. vForward = new Vect3d();
  68. vRight = new Vect3d();
  69. vUpward = new Vect3d();
  70.  
  71. //FIND WINDOW SIZES ETC,. CORE
  72.  
  73. //Find the resolution from our game, you can also use something like
  74. //resolution[0] = 1280
  75. //resolution[1] = 720
  76. //Although if you can find the values from memory then you can adapt to any res
  77. resolution[0] = Mem.ReadInt(0xD573F34);
  78. resolution[1] = Mem.ReadInt(0xD573F38);
  79.  
  80. screencenter[0] = resolution[0] / 2;
  81. screencenter[1] = resolution[1] / 2;
  82.  
  83. handle = FindWindow(null, WindowName); //Call of duty 4 Multiplayer
  84. //only draw if our window is valid
  85. if (handle != IntPtr.Zero)
  86. {
  87. windowRectangle = GetWindowRect(handle);
  88. }
  89.  
  90. }
  91.  
  92. private void SetupDX()
  93. {
  94. //Make the window's border completely transparant
  95. SetWindowLong(this.Handle, GWL_EXSTYLE,
  96. (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED ^ WS_EX_TRANSPARENT));
  97.  
  98. //Set the Alpha on the Whole Window to 255 (solid)
  99. SetLayeredWindowAttributes(this.Handle, 0, 255, LWA_ALPHA);
  100.  
  101. //Init DirectX
  102. //This initializes the DirectX device. It needs to be done once.
  103. //The alpha channel in the backbuffer is critical.
  104. PresentParameters presentParameters = new PresentParameters();
  105. presentParameters.Windowed = true;
  106. presentParameters.SwapEffect = SwapEffect.Discard;
  107. presentParameters.BackBufferFormat = Format.A8R8G8B8;
  108.  
  109. this.device = new Device(0, DeviceType.Hardware, this.Handle,
  110. CreateFlags.HardwareVertexProcessing, presentParameters);
  111.  
  112. Thread dx = new Thread(new ThreadStart(this.dxThread));
  113. dx.IsBackground = true;
  114. dx.Start();
  115. }
  116.  
  117. public void StopThread()
  118. {
  119. _StopThread = true;
  120. }
  121.  
  122. private void Form1_Load(object sender, EventArgs e)
  123. {
  124.  
  125. }
  126.  
  127. #region OVERLAY
  128. private Margins marg;
  129.  
  130. //this is used to specify the boundaries of the transparent area
  131. internal struct Margins
  132. {
  133. public int Left, Right, Top, Bottom;
  134. }
  135.  
  136. [StructLayout(LayoutKind.Sequential)]
  137. public struct RECT
  138. {
  139. public int left, top, right, bottom;
  140. }
  141.  
  142. [DllImport("user32.dll", SetLastError = true)]
  143.  
  144. private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
  145.  
  146. [DllImport("user32.dll")]
  147.  
  148. static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
  149.  
  150. [DllImport("user32.dll")]
  151. static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
  152.  
  153. [DllImport("user32.dll")]
  154. static extern bool SetCursorPos(int X, int Y);
  155.  
  156. public const int GWL_EXSTYLE = -20;
  157.  
  158. public const int WS_EX_LAYERED = 0x80000;
  159.  
  160. public const int WS_EX_TRANSPARENT = 0x20;
  161.  
  162. public const int LWA_ALPHA = 0x2;
  163.  
  164. public const int LWA_COLORKEY = 0x1;
  165.  
  166. [DllImport("dwmapi.dll")]
  167. static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);
  168.  
  169. [DllImport("user32.dll")]
  170. [return: MarshalAs(UnmanagedType.Bool)]
  171. public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
  172.  
  173. [DllImport("user32.dll", SetLastError = true)]
  174. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  175.  
  176.  
  177. private Device device = null;
  178.  
  179.  
  180. public static RECT GetWindowRect(IntPtr hWnd)
  181. {
  182. RECT result = new RECT();
  183. GetWindowRect(hWnd, out result);
  184. return result;
  185. }
  186. #endregion
  187.  
  188. //----------------------DX THREAD---------------------------------
  189. private void dxThread()
  190. {
  191. while (!_StopThread)
  192. {
  193. #region device work
  194. //Place your update logic here
  195. device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
  196. device.RenderState.ZBufferEnable = false;
  197. device.RenderState.Lighting = false;
  198. device.RenderState.CullMode = Cull.None;
  199. device.Transform.Projection = Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1);
  200. device.BeginScene();
  201. #endregion
  202.  
  203. #region Drawing and rendering
  204. //Place your rendering logic here
  205.  
  206. IntPtr handle = FindWindow(null, WindowName); //Call of duty 4 Multiplayer
  207. //only draw if our window is valid
  208. if (handle != IntPtr.Zero)
  209. {
  210. RECT windowRectangle = GetWindowRect(handle);
  211. ESP_Aimbot();
  212. }
  213. #endregion
  214.  
  215. #region Finish rendering
  216. device.EndScene();
  217. device.Present();
  218. #endregion
  219. }
  220. this.device.Dispose();
  221. threadOver = true;
  222.  
  223. }
  224.  
  225. public void FillRect(float x, float y, float w, float h, int r, int g, int b)
  226. {
  227. CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[4];
  228.  
  229. verts[0].Position = new Vector4(x, y + h, 0, 0.5f);
  230. verts[1].Position = new Vector4(x, y, 0, 0.5f);
  231. verts[2].Position = new Vector4(x + w, y + h, 0, 0.5f);
  232. verts[3].Position = new Vector4(x + w, y, 0, 0.5f);
  233. //or make it with for(int i = 0; i < 4; i++) to write less code
  234. verts[0].Color = System.Drawing.Color.FromArgb(r, g, b).ToArgb();
  235. verts[1].Color = System.Drawing.Color.FromArgb(r, g, b).ToArgb();
  236. verts[2].Color = System.Drawing.Color.FromArgb(r, g, b).ToArgb();
  237. verts[3].Color = System.Drawing.Color.FromArgb(r, g, b).ToArgb();
  238.  
  239. device.VertexFormat = CustomVertex.TransformedColored.Format;
  240. device.DrawUserPrimitives(PrimitiveType.TriangleSt rip, 2, verts);
  241. }
  242.  
  243.  
  244.  
  245. public void DrawRectangle(float x, float y, float w, float h, Color color)
  246. {
  247. float thickness = (w / 25);
  248. //Vertical bar 1
  249. FillRect(x - (w / 2), y - (h / 2), thickness/*just to keep our width consistent*/, h, color.R, color.G, color.B);
  250. ////Horiz 1
  251. FillRect(x - (w / 2), y - (h / 2), w, thickness, color.R, color.G, color.B);
  252. ////Horizontal bar 2, -50 because we want the exact center of the crosshair to be
  253. ////at our X,Y coords and not the far left on crosshair on them
  254. FillRect(x - (w / 2), y + (h / 2), w, thickness, color.R, color.G, color.B);
  255. ////Vertical bar 2
  256. FillRect(x + (w / 2), y - (h / 2), thickness, h, color.R, color.G, color.B);
  257. }
  258.  
  259.  
  260. public void DrawCircle(int X, int Y, float radius, int slices, Color color, string typeofCircle)
  261. {
  262. CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[slices + 2];
  263. int[] indices = new int[slices * 3];
  264. int col1;
  265. float x, y;
  266. x = X;
  267. y = Y;
  268. col1 = color.ToArgb();
  269.  
  270. float deltaRad = DegreeToRadian(360) / slices;
  271. float delta = 0;
  272.  
  273. vertices[0] = new CustomVertex.TransformedColored(x, y, 0, 1, col1);
  274.  
  275. for (int i = 1; i < slices + 2; i++)
  276. {
  277. vertices[i] = new CustomVertex.TransformedColored(
  278. (float)Math.Cos(delta) * radius + x,
  279. (float)Math.Sin(delta) * radius + y,
  280. 0, 1, col1);
  281. delta += deltaRad;
  282. }
  283.  
  284. indices[0] = 0;
  285. indices[1] = 1;
  286.  
  287. for (int i = 0; i < slices; i++)
  288. {
  289. indices[3 * i] = 0;
  290. indices[(3 * i) + 1] = i + 1;
  291. indices[(3 * i) + 2] = i + 2;
  292. }
  293.  
  294.  
  295. //either draw a filled circle or a hollow one
  296. device.VertexFormat = CustomVertex.TransformedColored.Format;
  297. if (typeofCircle == "Solid")
  298. device.DrawUserPrimitives(PrimitiveType.TriangleFa n, slices, vertices);
  299. else
  300. device.DrawUserPrimitives(PrimitiveType.PointList, slices, vertices);
  301.  
  302. }
  303.  
  304. private float DegreeToRadian(double angle)
  305. {
  306. return (float)(Math.PI * angle / 180.0);
  307. }
  308.  
  309.  
  310. private void DrawESP(int x, int y, Color color, int crosshairChoice)
  311. {
  312. if (crosshairChoice == (int)CrosshairTypes.normal)
  313. NormalCrosshair(x, y, color);
  314.  
  315. else if (crosshairChoice == (int)CrosshairTypes.square)
  316. SquareCrosshair(x, y, color);
  317.  
  318. else if (crosshairChoice == (int)CrosshairTypes.dot)
  319. {
  320. float size = 6.0f;
  321. if (_ScaleESP == 1)
  322. size = 12.0f;
  323. else if (_ScaleESP == 2)
  324. size = 24.0f;
  325. DrawCircle(x, y, size, 500, color, "Solid");
  326. }
  327. else if (crosshairChoice == (int)CrosshairTypes.smiley)
  328. {
  329. if (_ScaleESP == 0)
  330. {
  331. //Face
  332. DrawCircle(x, y, 16.0f, 500, color, "Clear");
  333. //Left eye
  334. DrawCircle(x, y, 3.0f, 500, color, "Clear");
  335. //Right eye
  336. DrawCircle((x), (y) - 4, 3.0f, 500, color, "Clear");
  337. //Mouth
  338. DrawCircle(x, y + 6, 4.0f, 500, color, "Clear");
  339. }
  340. if (_ScaleESP == 1)
  341. {
  342. //Face
  343. DrawCircle(x, y, 32.0f, 500, color, "Clear");
  344. //Left eye
  345. DrawCircle(x, y, 6.0f, 500, color, "Clear");
  346. //Right eye
  347. DrawCircle(x, y, 6.0f, 500, color, "Clear");
  348. //Mouth
  349. DrawCircle(x, y + 15, 7.0f, 500, color, "Clear");
  350. }
  351. if (_ScaleESP == 2)
  352. {
  353. //Face
  354. DrawCircle(x, y, 64.0f, 500, color, "Clear");
  355. //Left eye
  356. DrawCircle(x, y, 9.0f, 500, color, "Clear");
  357. //Right eye
  358. DrawCircle(x, y, 9.0f, 500, color, "Clear");
  359. //Mouth
  360. DrawCircle(x, y, 10.0f, 500, color, "Clear");
  361. }
  362. }
  363.  
  364. else if (crosshairChoice == (int)CrosshairTypes.predator)
  365. {
  366. CrosshairPredator(x, y, color);
  367. }
  368.  
  369. else if (crosshairChoice == (int)CrosshairTypes.circleDot)
  370. {
  371. float radiusMain = 16.0f;
  372. float radiusDot = 2.0f;
  373. //medium
  374. if (_ScaleESP == 1)
  375. {
  376. radiusMain = 32.0f;
  377. radiusDot = 4.0f;
  378. }
  379. //large
  380. else if (_ScaleESP == 2)
  381. {
  382. radiusMain = 62.0f;
  383. radiusDot = 8.0f;
  384. }
  385.  
  386. //Main Circle
  387. DrawCircle(x, y, radiusMain, 500, color, "Clear");
  388. //Dot in center
  389. DrawCircle(x, y, radiusDot, 500, color, "Solid");
  390. }
  391. else if (crosshairChoice == (int)CrosshairTypes.clearSquare)
  392. {
  393. CrosshairSquareClear(x, y, color);
  394. }
  395. }
  396.  
  397. #region ESP DRAWING
  398.  
  399.  
  400.  
  401. private void NormalCrosshair(int x, int y, Color color)
  402. {
  403. if (_Scale == 0)
  404. {
  405. //Horizontal bar, -50 because we want the exact center of the crosshair to be
  406. //at our X,Y coords and not the far left on crosshair on them
  407. FillRect(x - 25, y - 2, 50, 2, color.R, color.G, color.B);
  408. //Vertical bar
  409. FillRect(x, y - 28, 2, 50, color.R, color.G, color.B);
  410. }
  411. //medium
  412. if (_Scale == 1)
  413. {
  414. //Horizontal bar
  415. FillRect(x - 49, y - 2, 100, 2, color.R, color.G, color.B);
  416. //Vertical bar
  417. FillRect(x + 1, y - 54, 2, 100, color.R, color.G, color.B);
  418. }
  419. //large
  420. if (_Scale == 2)
  421. {
  422. //Horizontal bar
  423. FillRect(x - 100, y - 2, 200, 2, color.R, color.G, color.B);
  424. //Vertical bar
  425. FillRect(x + 1, y - 100, 2, 200, color.R, color.G, color.B);
  426. }
  427. }
  428. private void SquareCrosshair(int x, int y, Color color)
  429. {
  430. if (_Scale == 0)
  431. {
  432. FillRect(x - 4, y - 7, 10, 10, color.R, color.G, color.B);
  433. }
  434. //medium
  435. if (_Scale == 1)
  436. {
  437. FillRect(x - 8, y - 14, 20, 20, color.R, color.G, color.B);
  438. }
  439. if (_Scale == 2)
  440. {
  441. FillRect(x - 18, y - 25, 40, 40, color.R, color.G, color.B);
  442. }
  443. }
  444.  
  445.  
  446. private void CrosshairPredator(int x, int y, Color color)
  447. {
  448. if (_Scale == 0)
  449. {
  450. //Main Circle
  451. DrawCircle(x+ 1, y- 8, 2.5f, 500, color, "Solid");
  452. //2nd Left
  453. DrawCircle(x-8, y + 6, 2.5f, 500, color, "Solid");
  454. //3rd right
  455. DrawCircle(x+8, y+ 6, 2.5f, 500, color, "Solid");
  456. }
  457. else if (_Scale == 1)
  458. {
  459. //Main Circle
  460. DrawCircle(x + 1, y - 12, 2.5f, 500, color, "Solid");
  461. //2nd Left
  462. DrawCircle(x- 12, y + 10, 2.5f, 500, color, "Solid");
  463. //3rd right
  464. DrawCircle(x+ 12, y + 10, 2.5f, 500, color, "Solid");
  465. }
  466. else if (_Scale == 2)
  467. {
  468. //Main Circle
  469. DrawCircle(x+ 1, y - 16, 2.5f, 500, color, "Solid");
  470. //2nd Left
  471. DrawCircle(x- 16, y + 14, 2.5f, 500, color, "Solid");
  472. //3rd right
  473. DrawCircle(x+ 16, y + 14, 2.5f, 500, color, "Solid");
  474. }
  475. }
  476.  
  477. private void CrosshairSquareClear(int x, int y, Color color)
  478. {
  479. if (_Scale == 0)
  480. {
  481. //Vertical bar 2
  482. FillRect(x - 14, y - 14, 2, 25, color.R, color.G, color.B);
  483. //Horiz 1
  484. FillRect(x - 11, y - 14, 25, 2, color.R, color.G, color.B);
  485. //Horizontal bar 2, -50 because we want the exact center of the crosshair to be
  486. //at our X,Y coords and not the far left on crosshair on them
  487. FillRect(x - 11, y + 9, 25, 2, color.R, color.G, color.B);
  488. //Vertical bar 1
  489. FillRect(x + 13, y - 14, 2, 25, color.R, color.G, color.B);
  490. }
  491. if (_Scale == 1)
  492. {
  493. //at our X,Y coords and not the far left on crosshair on them
  494. FillRect(x - 24, y + 20, 50, 2, color.R, color.G, color.B);
  495. //Vertical bar
  496. FillRect(x - 25, y - 28, 2, 50, color.R, color.G, color.B);
  497. //Vertical bar
  498. FillRect(x + 25, y - 28, 2, 50, color.R, color.G, color.B);
  499. //Horiz 2
  500. FillRect(x - 24, y - 28, 50, 2, color.R, color.G, color.B);
  501. }
  502. //large
  503. if (_Scale == 2)
  504. {
  505. //at our X,Y coords and not the far left on crosshair on them
  506. FillRect(x - 50, y + 50, 100, 2, color.R, color.G, color.B);
  507. //Vertical bar
  508. FillRect(x - 50, y - 50, 2, 100, color.R, color.G, color.B);
  509. //Vertical bar
  510. FillRect(x + 50, y - 50, 2, 102, color.R, color.G, color.B);
  511. //Horiz 2
  512. FillRect(x - 50, y - 50, 100, 2, color.R, color.G, color.B);
  513.  
  514. }
  515. }
  516.  
  517.  
  518. #endregion
  519.  
  520. private void Form1_Paint(object sender, PaintEventArgs e)
  521. {
  522. //Create a margin (the whole form)
  523. marg.Left = 0;
  524. marg.Top = 0;
  525. marg.Right = this.Width;
  526. marg.Bottom = this.Height;
  527.  
  528. //Expand the Aero Glass Effect Border to the WHOLE form.
  529. // since we have already had the border invisible we now
  530. // have a completely invisible window - apart from the DirectX
  531. // renders NOT in black.
  532. DwmExtendFrameIntoClientArea(this.Handle, ref marg);
  533. }
  534.  
  535. #region ESP and Aimbot
  536.  
  537. //By using our PlayerData pointers and memory addresses we grab all information from the player including:
  538. //Xmouse(YAW), Ymouse(PITCH) coordinates, player's position on the game x,y and z as well as the player's health
  539. //with that we can ignore dead enemies and not aim when OUR player is dead
  540. private PlayerDataVec GetPlayerVecData()
  541. {
  542. PlayerDataVec playerRet = new PlayerDataVec();
  543. //int playerBase = Mem.ReadMultiLevelPointer(updatePlayer.baseAddress , 4, updatePlayer.multiLevel);
  544.  
  545.  
  546. playerRet.isInGame = Mem.ReadInt(0x74E35C);
  547. //Get our client number
  548. playerRet.clientNum = Mem.ReadInt(0x74E338);
  549. playerRet.team = Mem.ReadInt(0x83928C); //GET OUR current team so we don't shoot at team mates
  550. //INITIATE THIS ARRAY SOMEWHERE ELSE
  551. //GET OUR FIELD OF VIEW
  552. fov[0] = Mem.ReadFloat(0x797610);
  553. fov[1] = Mem.ReadFloat(0x797614);
  554.  
  555. viewAngles.x = Mem.ReadFloat(0x79B698);
  556. viewAngles.y = Mem.ReadFloat(0x79B69C);
  557. viewAngles.z = Mem.ReadFloat(0x79B6A0);
  558. playerRet.xPos = Mem.ReadFloat(0x797618);
  559. playerRet.yPos = Mem.ReadFloat(0x79761C);
  560. playerRet.zPos = Mem.ReadFloat(0x797620);
  561. playerRet.clientNum = Mem.ReadInt(0x74E338);
  562.  
  563. //playerRet.isAlive = Mem.ReadInt(playerBase + updatePlayer.offsets.alive);
  564. return playerRet;
  565. }
  566.  
  567. private void ESP_Aimbot()
  568. {
  569. //if our window has been moved we update our ESP pos
  570. //only draw if our window is valid
  571. if (handle != IntPtr.Zero)
  572. {
  573. windowRectangle = GetWindowRect(handle);
  574. }
  575.  
  576. //Grab our player's information
  577. PlayerDataVec playerDataVec = GetPlayerVecData();
  578. //this will store every enemy that we have information
  579. List<PlayerDataVec> enemiesDataVec = new List<PlayerDataVec>();
  580. List<PlayerDataVec> viableAimbBotEnemies = new List<PlayerDataVec>();
  581. //Clear our LIST of enemies
  582.  
  583. if (playerDataVec.isInGame > 0)
  584. {
  585. for (int i = 0; i < MAXPLAYERS; i++)
  586. {
  587. //Using our pointer we grab all the enemies information e.g. health, coordinates etc and we compare
  588. //it in order to get our mouse on the enemy and shoot at them
  589. PlayerDataVec enemyDataVector = new PlayerDataVec();
  590.  
  591. enemyDataVector.isValid = Mem.ReadInt(0x839270 + i * 0x4CC);
  592.  
  593. enemyDataVector.isAlive = Mem.ReadInt(0x84F2D8 + i * 0x1DC + 0x1C0);
  594.  
  595. enemyDataVector.clientNum = Mem.ReadInt(0x84F2D8 + i * 0x1DC + 0xCC);
  596.  
  597. //read our player's name , i believe it has up to 16 chars
  598. for (int x = 0; x < 16; x++)
  599. enemyDataVector.name += (char)Mem.ReadByte(0x839270 + i * 0x4CC + (0xC + x));
  600.  
  601. //get our enemy's team
  602. enemyDataVector.team = Mem.ReadInt(0x839270 + i * 0x4CC + 0x1C);
  603.  
  604. //if player is alive, valid and is NOT US and NOT on our team then we add him to the list of possible victims and ESP targets
  605. if (enemyDataVector.isValid == 1 && enemyDataVector.clientNum != playerDataVec.clientNum)
  606. {
  607. //Same team as us
  608. if (enemyDataVector.team == playerDataVec.team)
  609. enemyDataVector.color = Color.Green;
  610. //Enemy
  611. else
  612. enemyDataVector.color = Color.Red;
  613.  
  614. //grab enemy's pos
  615. enemyDataVector.xPos = Mem.ReadFloat(0x839270 + i * 0x4CC + 0x398); // 0x4CC size of struct
  616. enemyDataVector.yPos = Mem.ReadFloat(0x839270 + i * 0x4CC + 0x39C);
  617. enemyDataVector.zPos = Mem.ReadFloat(0x839270 + i * 0x4CC + 0x3A0);
  618. //grab the enemy's pose, we need this incase the enemy is prone that way we move the ESP box down and aimbot lower
  619. enemyDataVector.pose = Mem.ReadInt(0x839270 + i * 0x4CC + 0x470);
  620.  
  621. //Add our new player info to our [array/list]
  622. //add our enemy information to the list if hes alive otherwise ignore them
  623. enemiesDataVec.Add(enemyDataVector);
  624. }
  625. }
  626. //COLLECTED ALL OUR DATA regarding enemies
  627. playerDataVec = GetPlayerVecData();
  628.  
  629.  
  630. float dist;
  631. float drawx;
  632. float drawy;
  633. //Now we have all our enemies stored and we need to display the ESP on them
  634. for (int i = 0; i < enemiesDataVec.Count; i++)
  635. {
  636. dist = SubVectorDist(playerDataVec, enemiesDataVec[i]).length() / 48;
  637.  
  638. //converts our 3d Coordinates to 2d
  639. if (WorldToScreen(enemiesDataVec[i].VecCoords(), playerDataVec.VecCoords()))
  640. {
  641. //say that our enemy is ok to aim at
  642. enemiesDataVec[i].visible = true;
  643.  
  644. if ((((enemiesDataVec[i].pose & 0x08) != 0)) ||
  645. ((enemiesDataVec[i].pose & 0x100) != 0) ||
  646. ((enemiesDataVec[i].pose & 0x200) != 0))
  647. {
  648. drawx = 700.0f / dist;
  649. drawy = 400.0f / dist;
  650. ScreenY += 4.6f;
  651. }
  652. else
  653. {
  654. drawx = 400.0f / dist;
  655. drawy = 700.0f / dist;
  656. }
  657. //We find exacly where to draw including from our Window's e.g.
  658. //if the window has been moved since our last loop
  659. //add an extra bit to our screenX depending on our pos in relation to the en
  660. //int x = windowRectangle.left + (int)(ScreenX);
  661. //take away any height based on our own position e.g. if were crawling the ESP needs to be slightly adjusted
  662. //int y = windowRectangle.top + (int)(ScreenY - drawy);
  663.  
  664. //DRAW OUR DAMN ESP
  665. DrawESP(windowRectangle.left + (int)(ScreenX), windowRectangle.top + (int)(ScreenY - drawy),
  666. enemiesDataVec[i].color,
  667. EspChoice);
  668. }
  669. else enemiesDataVec[i].visible = false;
  670. }
  671.  
  672.  
  673. #region AimbotAim
  674. //Get only valid player's for our aimbot to use
  675. enemiesDataVec = GetValidPlayers(enemiesDataVec, playerDataVec.team);
  676. //---------------------------------AIMBOT PART-------------------------------
  677. //check if our hot key is being pressed
  678. //Mouse 2, if you want to use other hot keys Google Virtual Key Codes
  679. int keyInput = KeyInputApi.GetKeyState(0x02);
  680. if ((keyInput & 0x8000) != 0)
  681. {
  682. FocusingOnEnemy = true;
  683. int target = 0;
  684. if (FocusingOnEnemy && FocusTarget != -1)
  685. {
  686. //If our previous target is still alive we focus on them otherwise go after someone else
  687. if (enemiesDataVec[FocusTarget].isAlive > 0)
  688. target = FocusTarget;
  689. else target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
  690. }
  691. else//By default aim at the first guy that appears, with this we focus on whos closest to us
  692. target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
  693.  
  694. //if there are more enemies we find the closest one to us then aim
  695. if (target != -1) //-1 means something went wrong
  696. {
  697. dist = SubVectorDist(playerDataVec, enemiesDataVec[target]).length() / 48;
  698. //needs to be called so certain vars are set for our aimsys
  699. WorldToScreen(enemiesDataVec[target].VecCoords(), playerDataVec.VecCoords());
  700.  
  701. FocusTarget = target;
  702. if ((((enemiesDataVec[target].pose & 0x08) != 0)) ||
  703. ((enemiesDataVec[target].pose & 0x100) != 0) ||
  704. ((enemiesDataVec[target].pose & 0x200) != 0))
  705. {
  706. drawx = 700.0f / dist;
  707. drawy = 400.0f / dist;
  708. ScreenY += 4.6f;
  709. }
  710. else
  711. {
  712. drawx = 400.0f / dist;
  713. drawy = 700.0f / dist;
  714. }
  715.  
  716. //We find exacly where to draw including from our Window's e.g.
  717. //if the window has been moved since our last loop
  718. int x = windowRectangle.left + (int)(ScreenX);
  719. int y = windowRectangle.top + (int)(ScreenY - drawy);
  720.  
  721. //this condition is only here in case all enemies are dead to aim at NO one
  722. //previously if all were dead it would aim at the last guy killed
  723. if (enemiesDataVec[target].isAlive > 0)
  724. {
  725. //put our mouse on the enemy
  726. SetCursorPos(x, y);
  727. }
  728. }
  729.  
  730. }
  731. //stopped pressing Hotkey aimbot, therefore we look for a new target as soon as its pressed again
  732. //if player leaves key held we keep aiming at the same target until hes dead or invalid
  733. else
  734. {
  735. //otherwise we stop staring at them and change targets
  736. FocusingOnEnemy = false;
  737. FocusTarget = -1;
  738. }
  739. }
  740. }
  741.  
  742. //Returns only player's that are ok to aimbot at, e.g. enemies and only alive players
  743. private List<PlayerDataVec> GetValidPlayers(List<PlayerDataVec> allPlayers, int myTeam)
  744. {
  745. List<PlayerDataVec> validPlayers = new List<PlayerDataVec>();
  746. for (int i = 0; i < allPlayers.Count; i++)
  747. {
  748. if (allPlayers[i].team != myTeam)// && allPlayers[i].isAlive > 0
  749. {
  750. validPlayers.Add(allPlayers[i]);
  751. }
  752. }
  753. return validPlayers;
  754. }
  755.  
  756.  
  757.  
  758. //With this we see which enemy is closest to OUR player, we return their index that way we aim directly
  759. //at our closest enemy
  760. private int FindClosestEnemyIndex(PlayerDataVec[] enemiesDataVec, PlayerDataVec myPosition)
  761. {
  762. float[] distances = new float[enemiesDataVec.Length];
  763. //store all our distances between us and the enemies to see which is closest
  764. for (int i = 0; i < enemiesDataVec.Length; i++)
  765. {
  766. //only store their distance if they are ALIVE
  767. if (enemiesDataVec[i].isAlive > 0 && enemiesDataVec[i].visible)
  768. distances[i] = Get3dDistance(enemiesDataVec[i], myPosition);
  769. //This is kind of a cheat here and im not really proud of it :/ but it was done in a rush
  770. //in theory it just sets these as very high floats and ensures that DEAD enemies dont get
  771. //aimed at
  772. else
  773. {
  774. distances[i] = float.MaxValue;
  775. }
  776. }
  777. //Make a copy of our array so we dont lose track of which position our closest enemy is
  778. float[] newDistances = new float[distances.Length];
  779. Array.Copy(distances, newDistances, distances.Length);
  780.  
  781. //sorts our array from LOWEST TO HIGHEST
  782. Array.Sort(newDistances);
  783.  
  784. //See which enemy was closest and return that Index for us to aim at them
  785. for (int i = 0; i < distances.Length; i++)
  786. {
  787. if (distances[i] == newDistances[0]) //0 BEING THE CLOSEST
  788. {
  789. return i;
  790. }
  791. }
  792. return -1;
  793. }
  794.  
  795. #endregion
  796.  
  797.  
  798. //Use the well known 3d distance formula to see how 2 players are from each other
  799. //i didnt make this myself its just FACT. Almost every 3D game uses this formula. 2D games use a simpler variation
  800. private float Get3dDistance(PlayerDataVec to, PlayerDataVec from)
  801. {
  802. return (float)
  803. (Math.Sqrt(
  804. ((to.xPos - from.xPos) * (to.xPos - from.xPos)) +
  805. ((to.yPos - from.yPos) * (to.yPos - from.yPos)) +
  806. ((to.zPos - from.zPos) * (to.zPos - from.zPos))
  807. ));
  808. }
  809.  
  810. Vect3d SubVectorDist(PlayerDataVec playerFrom, PlayerDataVec playerTo)
  811. {
  812. return new Vect3d(playerFrom.xPos - playerTo.xPos, playerFrom.yPos - playerTo.yPos, playerFrom.zPos - playerTo.zPos);
  813. }
  814.  
  815. Vect3d SubVectorDist(Vect3d playerFrom, Vect3d playerTo)
  816. {
  817. return new Vect3d(playerFrom.x - playerTo.x, playerFrom.y - playerTo.y, playerFrom.z - playerTo.z);
  818. }
  819.  
  820. //Grabs our 3d Coordinates and changes them to 2d for us to player with
  821. //---------------------------------------------------------------------------
  822. bool WorldToScreen(Vect3d WorldLocation, Vect3d mypos)
  823. {
  824. Vect3d vLocal, vTransForm;
  825. vTransForm = new Vect3d();
  826. vForward = new Vect3d();
  827. vRight = new Vect3d();
  828. vUpward = new Vect3d();
  829.  
  830. AngleVectors();
  831. vLocal = SubVectorDist(WorldLocation, mypos);
  832.  
  833. vTransForm.x = vLocal.dotproduct(vRight);
  834. vTransForm.y = vLocal.dotproduct(vUpward);
  835. vTransForm.z = vLocal.dotproduct(vForward);
  836.  
  837. if (vTransForm.z < 0.01)
  838. return false;
  839.  
  840. ScreenX = screencenter[0] + (screencenter[0] / vTransForm.z * (1 / fov[0])) * vTransForm.x;
  841. ScreenY = screencenter[1] - (screencenter[1] / vTransForm.z * (1 / fov[1])) * vTransForm.y;
  842.  
  843. return true;
  844. }
  845.  
  846. /// <summary>
  847. /// One of Kn4cker's functions, this beauty does all our complex maths
  848. /// if you want to know more about it get very comfortable with Pythagora
  849. /// </summary>
  850. private void AngleVectors()
  851. {
  852. float angle;
  853. float sr, sp, sy, cr, cp, cy,
  854. cpi = (3.141f * 2 / 360);
  855.  
  856. angle = viewAngles.y * cpi;
  857. //cpi = same view angles.x isn't
  858.  
  859. sy = (float)Math.Sin(angle);
  860. cy = (float)Math.Cos(angle);
  861. angle = viewAngles.x * cpi;
  862. sp = (float)Math.Sin(angle);
  863. cp = (float)Math.Cos(angle);
  864. angle = viewAngles.z * cpi;
  865. sr = (float)Math.Sin(angle);
  866. cr = (float)Math.Cos(angle);
  867.  
  868. vForward.x = cp * cy;
  869. vForward.y = cp * sy;
  870. vForward.z = -sp;
  871.  
  872. vRight.x = (-1 * sr * sp * cy + -1 * cr * -sy);
  873. vRight.y = (-1 * sr * sp * sy + -1 * cr * cy);
  874. vRight.z = -1 * sr * cp;
  875.  
  876. vUpward.x = (cr * sp * cy + -sr * -sy);
  877. vUpward.y = (cr * sp * sy + -sr * cy);
  878. vUpward.z = cr * cp;
  879. }
  880. #endregion
  881.  
  882.  
  883. }
  884. }
  885.  
  886. Veja mais: http://www.cheatsbrasil.org/local/c-c-c-/175121-source-code-aimbot-em-c.html#ixzz3spIsVO5h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement