Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using ProcessMemoryReaderLib;
  11. using System.Globalization;
  12.  
  13. namespace Aimbot_cSharp
  14. {
  15. public partial class CustomAimbot : Form
  16. {
  17. Process[] MyProcess;
  18. ProcessModule mainModule;
  19. ProcessMemoryReader Mem = new ProcessMemoryReader();
  20. PlayerData MainPlayer = new PlayerData();
  21.  
  22. #region -----Addresses-----
  23. int MainPlayerBase = 0x0050F4F4;
  24. int[] MainPlayerMultiLevel = new int[] { 0x4 };
  25. PlayerDataAddr MainPlayerOffsets = new PlayerDataAddr(0x3C, 0x40, 0x0, 0x4, 0x8, 0xF4);
  26.  
  27.  
  28. #region -----EnemyAddresses-----
  29. List<PlayerData> EnemyAddresses = new List<PlayerData>();
  30. int[] enONEMultiLevel = new int[] { 0xF4, 0x4 };///*was F4 insatead of 30 BUT went back C4 so I can calculate everyteaing e.g. xpos etc*/
  31. int[] enTWOMultiLevel = new int[] { 0x4, 0xF8, 0x4, 0x4 };
  32. int[] enTHREEMultiLevel = new int[] { 0x8, 0x35C, 0x8, 0x30 };
  33. #endregion
  34.  
  35. float PI = 3.14159265F; // ALTHOUGH WE CAN ALWAYS use Math.PI, I prefer to use our own as a float
  36.  
  37. #endregion
  38.  
  39. bool GameFound = false;
  40. //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
  41. bool FocusingOnEnemy = false;
  42. int FocusTarget = -1;
  43.  
  44. public CustomAimbot()
  45. {
  46. InitializeComponent();
  47. }
  48.  
  49. private void gameChoiceCB_SelectedIndexChanged(object sender, EventArgs e)
  50. {
  51. try
  52. {
  53. for (int i = 0; i < MyProcess.Length; i++)
  54. {
  55. if (gameChoiceCB.SelectedItem.ToString().Contains(MyProcess[i].ProcessName))
  56. {
  57. MyProcess[0] = Process.GetProcessById(int.Parse(gameChoiceCB.Text.Replace(MyProcess[i].ProcessName + "-", "")));
  58. mainModule = MyProcess[0].MainModule;
  59. Mem.ReadProcess = MyProcess[0];
  60. Mem.OpenProcess();
  61. GameFound = true;
  62.  
  63. //create our player with the corresponding memory addresses
  64. MainPlayer.baseAddress = MainPlayerBase;
  65. //GETS US TO THE BEGINNING OF OUR STRUCT
  66. MainPlayer.multiLevel = MainPlayerMultiLevel;
  67. MainPlayer.offsets = new PlayerDataAddr(MainPlayerOffsets.xMouse, MainPlayerOffsets.yMouse, MainPlayerOffsets.xPos, MainPlayerOffsets.zPos, MainPlayerOffsets.yPos, MainPlayerOffsets.health);
  68. SetupEnemyVars();
  69. }
  70. }
  71. }
  72. catch (Exception ex)
  73. {
  74. MessageBox.Show("Could not connect to process " + ex.Message, "Error");
  75. }
  76. }
  77.  
  78.  
  79. private void gameChoiceCB_MouseClick(object sender, MouseEventArgs e)
  80. {
  81. gameChoiceCB.Items.Clear();
  82. MyProcess = Process.GetProcesses();
  83. for (int i = 0; i < MyProcess.Length; i++)
  84. {
  85. gameChoiceCB.Items.Add(MyProcess[i].ProcessName + "-" + MyProcess[i].Id);
  86. }
  87. }
  88.  
  89. private void CustomAimbot_Load(object sender, EventArgs e)
  90. {
  91. ProcessTMR.Enabled = true;
  92. }
  93.  
  94. #region TESTING MOUSE X AND MOUSE Y(THIS CAN BE IGNORED)
  95. private void upBTN_Click(object sender, EventArgs e)
  96. {
  97. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  98. Mem.WriteFloat(playerBase + MainPlayer.offsets.yMouse, Mem.ReadFloat(playerBase + MainPlayer.offsets.yMouse) + 10.0f);
  99. }
  100.  
  101. private void rightBTN_Click(object sender, EventArgs e)
  102. {
  103. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  104. Mem.WriteFloat(playerBase + MainPlayer.offsets.xMouse, Mem.ReadFloat(playerBase + MainPlayer.offsets.xMouse) + 10.0f);
  105. }
  106.  
  107. private void leftBTN_Click(object sender, EventArgs e)
  108. {
  109. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  110. Mem.WriteFloat(playerBase + MainPlayer.offsets.xMouse, Mem.ReadFloat(playerBase + MainPlayer.offsets.xMouse) - 10.0f);
  111. }
  112.  
  113. private void downBTN_Click(object sender, EventArgs e)
  114. {
  115. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  116. Mem.WriteFloat(playerBase + MainPlayer.offsets.yMouse, Mem.ReadFloat(playerBase + MainPlayer.offsets.yMouse) - 10.0f);
  117. }
  118. #endregion
  119.  
  120.  
  121. private void ProcessTMR_Tick(object sender, EventArgs e)
  122. {
  123. if (GameFound)
  124. {
  125. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  126. mouseXValueLBL.Text = Mem.ReadFloat(playerBase + MainPlayer.offsets.xMouse).ToString();
  127. mouseYValueLBL.Text = Mem.ReadFloat(playerBase + MainPlayer.offsets.yMouse).ToString();
  128. //DISPLAY OUR XYZ MAIN PLAYER'S POS
  129. xPosValueLBL.Text = Mem.ReadFloat(playerBase + MainPlayer.offsets.xPos).ToString();
  130. yPosValueLBL.Text = Mem.ReadFloat(playerBase + MainPlayer.offsets.yPos).ToString();
  131. zPosValueLBL.Text = Mem.ReadFloat(playerBase + MainPlayer.offsets.zPos).ToString();
  132.  
  133. //SHOW OUR ENEMY VARIABLES
  134. int EnemyHealthAddy = Mem.ReadMultiLevelPointer(EnemyAddresses[2].baseAddress, 4, EnemyAddresses[2].multiLevel);
  135.  
  136. HealthMineLBL.Text = Mem.ReadInt(playerBase + MainPlayer.offsets.health).ToString();
  137.  
  138. EnHealthValueLBL.Text = Mem.ReadInt((EnemyHealthAddy) + MainPlayer.offsets.health).ToString();
  139. xPosEnValueLBL.Text = Mem.ReadFloat((EnemyHealthAddy) + MainPlayer.offsets.xPos).ToString();
  140. yPosEnValueLBL.Text = Mem.ReadFloat((EnemyHealthAddy) + MainPlayer.offsets.yPos).ToString();
  141. zPosEnValueLBL.Text = Mem.ReadFloat((EnemyHealthAddy) + MainPlayer.offsets.zPos).ToString();
  142.  
  143. //RIGHT MOUSE
  144. int res = ProcessMemoryReaderApi.GetKeyState(02);
  145. if ((res & 0x8000) != 0)
  146. {
  147. //if enemy is holding AIMBOT btn or key we focus on that person until they are dead
  148. FocusingOnEnemy = true;
  149. AimBot();
  150. }
  151. else
  152. {
  153. //otherwise we stop staring at them and change targets
  154. FocusingOnEnemy = false;
  155. FocusTarget = -1;
  156. }
  157. }
  158.  
  159.  
  160. try
  161. {
  162. if (MyProcess != null)
  163. {
  164. if (MyProcess[0].HasExited)
  165. {
  166. GameFound = false;
  167. }
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. MessageBox.Show("There was an error " + ex.Message);
  173. }
  174. }
  175.  
  176.  
  177. private void AimBot()
  178. {
  179. //Grab our player's information
  180. PlayerDataVec playerDataVec = GetPlayerVecData(MainPlayer);
  181. //this will store every enemy that we have information
  182. List<PlayerDataVec> enemiesDataVec = new List<PlayerDataVec>();
  183.  
  184. for (int i = 0; i < EnemyAddresses.Count; i++)
  185. {
  186. //Using our pointer we grab all the enemies information e.g. health, coordinates etc and we compare
  187. //it in order to get our mouse on the enemy and shoot at them
  188. PlayerDataVec enemyDataVector = GetPlayerVecData(EnemyAddresses[i]);
  189. //add our enemy information to the list if hes alive otherwise ignore them
  190. // if (enemyDataVector.health > 0)
  191. enemiesDataVec.Add(enemyDataVector);
  192. }
  193.  
  194. //only aim if we are ALIVE
  195. if (playerDataVec.health > 0)
  196. {
  197. int target = 0;
  198. if (FocusingOnEnemy && FocusTarget != -1)
  199. {
  200. //If our previous target is still alive we focus on them otherwise go after someone else
  201. if (enemiesDataVec[FocusTarget].health > 0)
  202. target = FocusTarget;
  203. else target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
  204. }
  205. else//By default aim at the first guy that appears, with this we focus on whos closest to us
  206. target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
  207.  
  208. //if there are more enemies we find the closest one to us then aim
  209. if (target != -1) //-1 means something went wrong
  210. {
  211. FocusTarget = target;
  212. //this condition is only here in case all enemies are dead to aim at NO one
  213. //previously if all were dead it would aim at the last guy killed
  214. if (enemiesDataVec[target].health > 0)
  215. AimAtTarget(enemiesDataVec[target], playerDataVec);
  216. }
  217. }
  218. }
  219.  
  220.  
  221. //With this we see which enemy is closest to OUR player, we return their index that way we aim directly
  222. //at our closest enemy
  223. private int FindClosestEnemyIndex(PlayerDataVec[] enemiesDataVec, PlayerDataVec myPosition)
  224. {
  225. float[] distances = new float[enemiesDataVec.Length];
  226. //store all our distances between us and the enemies to see which is closest
  227. for (int i = 0; i < enemiesDataVec.Length; i++)
  228. {
  229. //only store their distance if they are ALIVE
  230. if (enemiesDataVec[i].health > 0)
  231. distances[i] = Get3dDistance(enemiesDataVec[i], myPosition);
  232. //This is kind of a cheat here and im not really proud of it :/ but it was done in a rush
  233. //in theory it just sets these as very high floats and ensures that DEAD enemies dont get
  234. //aimed at
  235. else
  236. distances[i] = float.MaxValue;
  237. }
  238. //Make a copy of our array so we dont lose track of which position our closest enemy is
  239. float[] newDistances = new float[distances.Length];
  240. Array.Copy(distances, newDistances, distances.Length);
  241.  
  242. //sorts our array from LOWEST TO HIGHEST
  243. Array.Sort(newDistances);
  244.  
  245. //See which enemy was closest and return that Index for us to aim at them
  246. for (int i = 0; i < distances.Length; i++)
  247. {
  248. if (distances[i] == newDistances[0]) //0 BEING THE CLOSEST
  249. {
  250. return i;
  251. }
  252. }
  253. return -1;
  254. }
  255.  
  256. //Use the well known 3d distance formula to see how 2 players are from each other
  257. //i didnt make this myself its just FACT. Almost every 3D game uses this formula. 2D games use a simpler variation
  258. private float Get3dDistance(PlayerDataVec to, PlayerDataVec from)
  259. {
  260. return (float)
  261. (Math.Sqrt(
  262. ((to.xPos - from.xPos) * (to.xPos - from.xPos)) +
  263. ((to.yPos - from.yPos) * (to.yPos - from.yPos)) +
  264. ((to.zPos - from.zPos) * (to.zPos - from.zPos))
  265. ));
  266. }
  267.  
  268. private void AimAtTarget(PlayerDataVec enemyDataVector, PlayerDataVec playerDataVector)
  269. {
  270. float pitchX = (float)Math.Atan2(enemyDataVector.zPos - playerDataVector.zPos,
  271. Get3dDistance(enemyDataVector, playerDataVector))
  272. * 180 / PI;
  273.  
  274. float yawY = -(float)Math.Atan2(enemyDataVector.xPos - playerDataVector.xPos, enemyDataVector.yPos - playerDataVector.yPos)
  275. / PI * 180 + 180;
  276.  
  277. int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
  278.  
  279. //Set our mouse values with our new YAW and PITCH
  280. Mem.WriteFloat(playerBase + MainPlayer.offsets.yMouse, yawY);
  281. Mem.WriteFloat(playerBase + MainPlayer.offsets.xMouse, pitchX);
  282. }
  283.  
  284. //By using our PlayerData pointers and memory addresses we grab all information from the player including:
  285. //Xmouse(YAW), Ymouse(PITCH) coordinates, player's position on the game x,y and z as well as the player's health
  286. //with that we can ignore dead enemies and not aim when OUR player is dead
  287. private PlayerDataVec GetPlayerVecData(PlayerData updatePlayer)
  288. {
  289. PlayerDataVec playerRet = new PlayerDataVec();
  290. int playerBase = Mem.ReadMultiLevelPointer(updatePlayer.baseAddress, 4, updatePlayer.multiLevel);
  291.  
  292. playerRet.xMouse = Mem.ReadFloat(playerBase + updatePlayer.offsets.xMouse);
  293. playerRet.yMouse = Mem.ReadFloat(playerBase + updatePlayer.offsets.yMouse);
  294. playerRet.xPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.xPos);
  295.  
  296. playerRet.yPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.yPos);
  297. playerRet.zPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.zPos);
  298.  
  299. playerRet.health = Mem.ReadInt(playerBase + updatePlayer.offsets.health);
  300. return playerRet;
  301. }
  302.  
  303.  
  304. //DECLARE ALL our variables regarding enemies, we later use this information to go through enemies and aim at them
  305. private void SetupEnemyVars()
  306. {
  307. PlayerData En1 = new PlayerData();
  308. //SETUP ENEMY VARIABLES
  309. En1.baseAddress = MyProcess[0].MainModule.BaseAddress.ToInt32() + 0x0010F4F8;
  310. En1.multiLevel = enONEMultiLevel;
  311. En1.offsets = MainPlayer.offsets;
  312. EnemyAddresses.Add(En1);
  313.  
  314. PlayerData En2 = new PlayerData();
  315. En2.baseAddress = MyProcess[0].MainModule.BaseAddress.ToInt32() + 0x000E5F00;
  316. En2.multiLevel = enTWOMultiLevel;
  317. En2.offsets = MainPlayer.offsets;
  318. EnemyAddresses.Add(En2);
  319.  
  320. PlayerData En3 = new PlayerData();
  321. En3.baseAddress = MyProcess[0].MainModule.BaseAddress.ToInt32() + 0x000E5F00;
  322. En3.multiLevel = enTHREEMultiLevel;
  323. En3.offsets = MainPlayer.offsets;
  324. EnemyAddresses.Add(En3);
  325. }
  326.  
  327. private void HealthMineLBL_Click(object sender, EventArgs e)
  328. {
  329.  
  330. }
  331. }
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement