forked from LeagueSharp/LeagueSharp.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFakeClicks.cs
297 lines (257 loc) · 8.8 KB
/
FakeClicks.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
285
286
287
288
289
290
291
292
293
294
295
296
297
namespace LeagueSharp.Common
{
using System;
using System.Linq;
using SharpDX;
/// <summary>
/// Simulates clicks.
/// </summary>
internal static class FakeClicks
{
#region Static Fields
/// <summary>
/// The delta t for click frequency
/// </summary>
private static readonly float deltaT = 0.15f;
/// <summary>
/// The Random number generator
/// </summary>
private static readonly Random r = new Random();
/// <summary>
/// The root menu.
/// </summary>
private static readonly Menu root = new Menu("FakeClicks", "Fake Clicks");
/// <summary>
/// If the user is attacking
/// Currently used for the second style of fake clicks
/// </summary>
private static bool attacking;
/// <summary>
/// The last direction of the player
/// </summary>
private static Vector3 direction;
/// <summary>
/// The last endpoint the player was moving to.
/// </summary>
private static Vector3 lastEndpoint;
/// <summary>
/// The last order the player had.
/// </summary>
private static GameObjectOrder lastOrder;
/// <summary>
/// The time of the last order the player had.
/// </summary>
private static float lastOrderTime;
/// <summary>
/// The last time a click was done.
/// </summary>
private static float lastTime;
/// <summary>
/// The Player.
/// </summary>
private static Obj_AI_Hero player;
#endregion
#region Public Properties
/// <summary>
/// Gets a value indicating whether this <see cref="FakeClicks" /> is enabled.
/// </summary>
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
public static bool Enabled
{
get
{
return root.Item("Enable").IsActive();
}
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Initializes this instance.
/// </summary>
public static void Initialize()
{
CustomEvents.Game.OnGameLoad += Game_OnGameLoad;
}
public static void Shutdown()
{
CustomEvents.Game.OnGameLoad -= Game_OnGameLoad;
Obj_AI_Base.OnNewPath -= DrawFake;
/*
Orbwalking.BeforeAttack -= BeforeAttackFake;
Spellbook.OnCastSpell -= BeforeSpellCast;
*/
Orbwalking.AfterAttack -= AfterAttack;
Obj_AI_Base.OnIssueOrder -= OnIssueOrder;
Menu.Remove(root);
}
#endregion
#region Methods
/// <summary>
/// The move fake click after attacking
/// </summary>
/// <param name="unit">
/// The unit.
/// </param>
/// <param name="target">
/// The target.
/// </param>
private static void AfterAttack(AttackableUnit unit, AttackableUnit target)
{
attacking = false;
var t = target as Obj_AI_Hero;
if (t != null && unit.IsMe)
{
ShowClick(RandomizePosition(t.Position), ClickType.Move);
}
}
/*
/// <summary>
/// The before attack fake click.
/// Currently used for the second style of fake clicks
/// </summary>
/// <param name="args">
/// The args.
/// </param>
private static void BeforeAttackFake(Orbwalking.BeforeAttackEventArgs args)
{
if (root.Item("Click Mode").GetValue<StringList>().SelectedIndex == 1)
{
ShowClick(RandomizePosition(args.Target.Position), ClickType.Attack);
attacking = true;
}
}
/// <summary>
/// The fake click before you cast a spell
/// </summary>
/// <param name="s">
/// The Spell Book.
/// </param>
/// <param name="args">
/// The args.
/// </param>
private static void BeforeSpellCast(Spellbook s, SpellbookCastSpellEventArgs args)
{
var target = args.Target;
if (target == null)
{
return;
}
if (target.Position.Distance(player.Position) >= 5f)
{
ShowClick(args.Target.Position, ClickType.Attack);
}
}
*/
/// <summary>
/// The on new path fake.
/// Currently used for the second style of fake clicks
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="args">
/// The args.
/// </param>
private static void DrawFake(Obj_AI_Base sender, GameObjectNewPathEventArgs args)
{
if (sender.IsMe && lastTime + deltaT < Game.Time && args.Path.LastOrDefault() != lastEndpoint
&& args.Path.LastOrDefault().Distance(player.ServerPosition) >= 5f && root.Item("Enable").IsActive()
&& root.Item("Click Mode").GetValue<StringList>().SelectedIndex == 1)
{
lastEndpoint = args.Path.LastOrDefault();
if (!attacking)
{
ShowClick(Game.CursorPos, ClickType.Move);
}
else
{
ShowClick(Game.CursorPos, ClickType.Attack);
}
lastTime = Game.Time;
}
}
/// <summary>
/// Fired when the game loads.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Game_OnGameLoad(EventArgs args)
{
root.AddItem(new MenuItem("Enable", "Enable").SetValue(false));
root.AddItem(new MenuItem("Click Mode", "Click Mode"))
.SetValue(new StringList(new[] { "Evade, No Cursor Position", "Cursor Position, No Evade" }));
CommonMenu.Instance.AddSubMenu(root);
player = ObjectManager.Player;
Obj_AI_Base.OnNewPath += DrawFake;
/*
Orbwalking.BeforeAttack += BeforeAttackFake;
Spellbook.OnCastSpell += BeforeSpellCast;
*/
Orbwalking.AfterAttack += AfterAttack;
Obj_AI_Base.OnIssueOrder += OnIssueOrder;
}
/// <summary>
/// The OnIssueOrder event delegate.
/// Currently used for the first style of fake clicks
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="args">
/// The args.
/// </param>
private static void OnIssueOrder(Obj_AI_Base sender, GameObjectIssueOrderEventArgs args)
{
if (sender.IsMe
&& (args.Order == GameObjectOrder.MoveTo || args.Order == GameObjectOrder.AttackUnit
|| args.Order == GameObjectOrder.AttackTo)
&& lastOrderTime + r.NextFloat(deltaT, deltaT + .2f) < Game.Time && root.Item("Enable").IsActive()
&& root.Item("Click Mode").GetValue<StringList>().SelectedIndex == 0)
{
var vect = args.TargetPosition;
vect.Z = player.Position.Z;
if (args.Order != GameObjectOrder.AttackUnit && args.Order != GameObjectOrder.AttackTo)
{
ShowClick(vect, ClickType.Move);
}
lastOrderTime = Game.Time;
}
}
/// <summary>
/// The RandomizePosition function to randomize click location.
/// </summary>
/// <param name="input">
/// The input Vector3.
/// </param>
/// <returns>
/// A Vector within 100 units of the unit
/// </returns>
private static Vector3 RandomizePosition(Vector3 input)
{
if (r.Next(2) == 0)
{
input.X += r.Next(100);
}
else
{
input.Y += r.Next(100);
}
return input;
}
/// <summary>
/// Shows the click.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="type">The type.</param>
private static void ShowClick(Vector3 position, ClickType type)
{
if (!Enabled)
{
return;
}
Hud.ShowClick(type, position);
}
#endregion
}
}