This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
284 lines (243 loc) · 11.9 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using ProcessMemoryReaderLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
namespace Aimbot_cSharp
{
public partial class CustomAimbot : Form
{
private Process[] MyProcess;
private ProcessModule mainModule;
private ProcessMemoryReader Mem = new ProcessMemoryReader();
private PlayerData MainPlayer = new PlayerData();
private PlayerDataAddr MainPlayerOffsets = new PlayerDataAddr();
private List<PlayerData> EnemyAddresses = new List<PlayerData>();
private float PI = 3.14159265F; // ALTHOUGH WE CAN ALWAYS use Math.PI, I prefer to use our own as a float
private bool GameFound = false;
private bool FocusingOnEnemy = false;
private int FocusTarget = -1;
#region TESTING MOUSE X AND MOUSE Y(THIS CAN BE IGNORED)
private void upBTN_Click(object sender, EventArgs e)
{
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch, Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch) + 10.0f);
}
private void rightBTN_Click(object sender, EventArgs e)
{
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw, Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw) + 10.0f);
}
private void leftBTN_Click(object sender, EventArgs e)
{
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw, Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw) - 10.0f);
}
private void downBTN_Click(object sender, EventArgs e)
{
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch, Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch) - 10.0f);
}
#endregion TESTING MOUSE X AND MOUSE Y(THIS CAN BE IGNORED)
public CustomAimbot()
{
InitializeComponent();
}
private void gameChoiceCB_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
for (int i = 0; i < MyProcess.Length; i++)
{
if (gameChoiceCB.SelectedItem.ToString().Contains(MyProcess[i].ProcessName))
{
MyProcess[0] = Process.GetProcessById(int.Parse(gameChoiceCB.Text.Replace(MyProcess[i].ProcessName + "-", "")));
mainModule = MyProcess[0].MainModule;
Mem.ReadProcess = MyProcess[0];
Mem.OpenProcess();
GameFound = true;
//create our player with the corresponding memory addresses
MainPlayer.baseAddress = Mem.ReadInt(0x50f4f4);
//GETS US TO THE BEGINNING OF OUR STRUCT
MainPlayer.offsets = new PlayerDataAddr();
SetupEnemyVars();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Could not connect to process " + ex.Message, "Error");
}
}
private void gameChoiceCB_MouseClick(object sender, MouseEventArgs e)
{
gameChoiceCB.Items.Clear();
MyProcess = Process.GetProcesses();
for (int i = 0; i < MyProcess.Length; i++)
{
gameChoiceCB.Items.Add(MyProcess[i].ProcessName + "-" + MyProcess[i].Id);
}
}
private void CustomAimbot_Load(object sender, EventArgs e)
{
ProcessTMR.Enabled = true;
}
private void ProcessTMR_Tick(object sender, EventArgs e)
{
if (GameFound)
{
mouseXValueLBL.Text = Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw).ToString();
mouseYValueLBL.Text = Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch).ToString();
//DISPLAY OUR XYZ MAIN PLAYER'S POS
xPosValueLBL.Text = Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.xPos).ToString();
yPosValueLBL.Text = Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.yPos).ToString();
zPosValueLBL.Text = Mem.ReadFloat(MainPlayer.baseAddress + MainPlayer.offsets.zPos).ToString();
//SHOW OUR ENEMY VARIABLES
HealthMineLBL.Text = Mem.ReadInt(MainPlayer.baseAddress + MainPlayer.offsets.health).ToString();
EnHealthValueLBL.Text = Mem.ReadInt(EnemyAddresses[2].baseAddress + MainPlayer.offsets.health).ToString();
xPosEnValueLBL.Text = Mem.ReadFloat(EnemyAddresses[2].baseAddress + MainPlayer.offsets.xPos).ToString();
yPosEnValueLBL.Text = Mem.ReadFloat(EnemyAddresses[2].baseAddress + MainPlayer.offsets.yPos).ToString();
zPosEnValueLBL.Text = Mem.ReadFloat(EnemyAddresses[2].baseAddress + MainPlayer.offsets.zPos).ToString();
//RIGHT MOUSE
int res = ProcessMemoryReaderApi.GetKeyState(02);
if ((res & 0x8000) != 0)
{
//if enemy is holding AIMBOT btn or key we focus on that person until they are dead
FocusingOnEnemy = true;
AimBot();
}
else
{
//otherwise we stop staring at them and change targets
FocusingOnEnemy = false;
FocusTarget = -1;
}
}
try
{
if (MyProcess != null)
{
if (MyProcess[0].HasExited)
{
GameFound = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show("There was an error " + ex.Message);
}
}
private void AimBot()
{
//Grab our player's information
PlayerDataVec playerDataVec = GetPlayerVecData(MainPlayer);
//this will store every enemy that we have information
List<PlayerDataVec> enemiesDataVec = new List<PlayerDataVec>();
for (int i = 0; i < EnemyAddresses.Count; i++)
{
//Using our pointer we grab all the enemies information
PlayerDataVec enemyDataVector = GetPlayerVecData(EnemyAddresses[i]);
//add our enemy information to the list if hes alive otherwise ignore them
enemiesDataVec.Add(enemyDataVector);
}
//only aim if we are ALIVE
if (playerDataVec.health > 0)
{
int target = 0;
if (FocusingOnEnemy && FocusTarget != -1)
{
//If our previous target is still alive we focus on them otherwise go after someone else
if (enemiesDataVec[FocusTarget].health > 0)
target = FocusTarget;
else target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
}
else//By default aim at the first guy that appears, with this we focus on whos closest to us
target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
//if there are more enemies we find the closest one to us then aim
if (target != -1) //-1 means something went wrong
{
FocusTarget = target;
//this condition is only here in case all enemies are dead to aim at NO one
//previously if all were dead it would aim at the last guy killed
if (enemiesDataVec[target].health > 0)
AimAtTarget(enemiesDataVec[target], playerDataVec);
}
}
}
//With this we see which enemy is closest to OUR player, we return their index that way we aim directly
private int FindClosestEnemyIndex(PlayerDataVec[] enemiesDataVec, PlayerDataVec myPosition)
{
float[] distances = new float[enemiesDataVec.Length];
//store all our distances between us and the enemies to see which is closest
for (int i = 0; i < enemiesDataVec.Length; i++)
{
//only store their distance if they are ALIVE
if (enemiesDataVec[i].health > 0)
distances[i] = Get3dDistance(enemiesDataVec[i], myPosition);
else
// sets these as very high floats
distances[i] = float.MaxValue;
}
//Make a copy of our array so we dont lose track of which position our closest enemy is
float[] newDistances = new float[distances.Length];
Array.Copy(distances, newDistances, distances.Length);
//sorts our array from LOWEST TO HIGHEST
Array.Sort(newDistances);
//See which enemy was closest and return that Index for us to aim at them
for (int i = 0; i < distances.Length; i++)
{
if (distances[i] == newDistances[0])
{
return i;
}
}
return -1;
}
private float Get3dDistance(PlayerDataVec to, PlayerDataVec from)
{
return (float)
(Math.Sqrt(
((to.xPos - from.xPos) * (to.xPos - from.xPos)) +
((to.yPos - from.yPos) * (to.yPos - from.yPos)) +
((to.zPos - from.zPos) * (to.zPos - from.zPos))
));
}
private void AimAtTarget(PlayerDataVec enemyDataVector, PlayerDataVec playerDataVector)
{
float yaw = -(float)Math.Atan2(enemyDataVector.xPos - playerDataVector.xPos, enemyDataVector.yPos - playerDataVector.yPos)
/ PI * 180 + 180;
float pitch = (float)Math.Asin((enemyDataVector.zPos - playerDataVector.zPos) /
Get3dDistance(enemyDataVector, playerDataVector))
* 180 / PI;
//Set our mouse values with our new YAW and PITCH
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.yaw, yaw);
Mem.WriteFloat(MainPlayer.baseAddress + MainPlayer.offsets.pitch, pitch);
}
//get all the data and store it
private PlayerDataVec GetPlayerVecData(PlayerData updatePlayer)
{
PlayerDataVec playerRet = new PlayerDataVec();
playerRet.yaw = Mem.ReadFloat(updatePlayer.baseAddress + updatePlayer.offsets.yaw);
playerRet.pitch = Mem.ReadFloat(updatePlayer.baseAddress + updatePlayer.offsets.pitch);
playerRet.xPos = Mem.ReadFloat(updatePlayer.baseAddress + updatePlayer.offsets.xPos);
playerRet.yPos = Mem.ReadFloat(updatePlayer.baseAddress + updatePlayer.offsets.yPos);
playerRet.zPos = Mem.ReadFloat(updatePlayer.baseAddress + updatePlayer.offsets.zPos);
playerRet.health = Mem.ReadInt(updatePlayer.baseAddress + updatePlayer.offsets.health);
return playerRet;
}
//DECLARE ALL our variables regarding enemies, we later use this information to go through enemies and aim at them
private void SetupEnemyVars()
{
PlayerData En1 = new PlayerData();
//SETUP ENEMY VARIABLES
En1.baseAddress = Mem.ReadInt(Mem.ReadInt(0x50f4f8) + 0x4);
En1.offsets = MainPlayer.offsets;
EnemyAddresses.Add(En1);
PlayerData En2 = new PlayerData();
En2.baseAddress = Mem.ReadInt(Mem.ReadInt(0x50f4f8) + 0x8);
En2.offsets = MainPlayer.offsets;
EnemyAddresses.Add(En2);
PlayerData En3 = new PlayerData();
En3.baseAddress = Mem.ReadInt(Mem.ReadInt(0x50f4f8) + 0xc);
En3.offsets = MainPlayer.offsets;
EnemyAddresses.Add(En3);
}
}
}