-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDetector.cs
278 lines (253 loc) · 12.5 KB
/
Detector.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LeagueSharp;
using LeagueSharp.Common;
using SharpDX;
namespace SAwareness
{
internal class RecallDetector
{
public readonly List<RecallInfo> Recalls = new List<RecallInfo>();
public RecallDetector()
{
foreach (Obj_AI_Hero enemy in ObjectManager.Get<Obj_AI_Hero>())
{
if (enemy.IsEnemy)
{
Recalls.Add(new RecallInfo(enemy.NetworkId));
}
}
Game.OnGameProcessPacket += Game_OnGameProcessPacket;
}
~RecallDetector()
{
Game.OnGameProcessPacket -= Game_OnGameProcessPacket;
}
public bool IsActive()
{
return Menu.Detector.GetActive() && Menu.RecallDetector.GetActive();
}
private void Game_OnGameProcessPacket(GamePacketEventArgs args)
{
if (!IsActive())
return;
try
{
var reader = new BinaryReader(new MemoryStream(args.PacketData));
byte packetId = reader.ReadByte(); //PacketId
if (packetId != Packet.S2C.Recall.Header) //OLD 215
return;
//Log.LogPacket(args.PacketData);
Packet.S2C.Recall.Struct recall = RecallDecode(args.PacketData);//Packet.S2C.Recall.Decoded(args.PacketData);
HandleRecall(recall);
}
catch (Exception ex)
{
Console.WriteLine("RecallProcess: " + ex);
}
}
private void HandleRecall(Packet.S2C.Recall.Struct recallEx)
{
int time = Environment.TickCount - Game.Ping;
foreach (RecallInfo recall in Recalls)
{
if (recall == null) continue;
if (recallEx.Type == Packet.S2C.Recall.ObjectType.Player)
{
var obj = ObjectManager.GetUnitByNetworkId<Obj_AI_Hero>(recall.NetworkId);
var objEx = ObjectManager.GetUnitByNetworkId<Obj_AI_Hero>(recallEx.UnitNetworkId);
if (obj == null)
continue;
if (obj.NetworkId == objEx.NetworkId) //already existing
{
recall.Recall = recallEx;
recall.Recall2 = new Packet.S2C.Recall.Struct();
var t = Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorMode").GetValue<StringList>();
if (t.SelectedIndex == 0 || t.SelectedIndex == 2)
{
var percentHealth = (int) ((obj.Health/obj.MaxHealth)*100);
String sColor = "<font color='#FFFFFF'>";
String color = (percentHealth > 50
? "<font color='#00FF00'>"
: (percentHealth > 30 ? "<font color='#FFFF00'>" : "<font color='#FF0000'>"));
if (recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportStart ||
recallEx.Status == Packet.S2C.Recall.RecallStatus.RecallStarted)
{
String text = (recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportStart
? "porting"
: "recalling");
recall.StartTime = (int) Game.Time;
if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 1)
{
Game.PrintChat(obj.ChampionName + " {0} with {1} hp {2}({3})", text,
(int) obj.Health, color, percentHealth);
}
else if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 2 &&
Menu.GlobalSettings.GetMenuItem("SAwarenessGlobalSettingsServerChatPingActive")
.GetValue<bool>())
{
Game.Say(obj.ChampionName + " {0} with {1} hp {2}({3})", text, (int) obj.Health,
color, percentHealth);
}
}
else if (recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportEnd ||
recallEx.Status == Packet.S2C.Recall.RecallStatus.RecallFinished)
{
String text = (recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportStart
? "ported"
: "recalled");
if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 1)
{
Game.PrintChat(obj.ChampionName + " {0} with {1} hp {2}({3})", text,
(int) obj.Health, color, percentHealth);
}
else if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 2 &&
Menu.GlobalSettings.GetMenuItem(
"SAwarenessGlobalSettingsServerChatPingActive").GetValue<bool>())
{
Game.Say(obj.ChampionName + " {0} with {1} hp {2}({3})", text,
(int) obj.Health, color, percentHealth);
}
}
else
{
if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 1)
{
Game.PrintChat(obj.ChampionName + " canceled with {0} hp", (int) obj.Health);
}
else if (
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorChatChoice")
.GetValue<StringList>()
.SelectedIndex == 2 &&
Menu.GlobalSettings.GetMenuItem(
"SAwarenessGlobalSettingsServerChatPingActive").GetValue<bool>())
{
Game.Say(obj.ChampionName + " canceled with {0} hp", (int) obj.Health);
}
}
}
return;
}
}
else if (recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportStart ||
recallEx.Status == Packet.S2C.Recall.RecallStatus.TeleportEnd)
{
if (recall.Recall.Status == Packet.S2C.Recall.RecallStatus.TeleportStart)
recall.Recall2 = recallEx;
var obj = ObjectManager.GetUnitByNetworkId<GameObject>(recallEx.UnitNetworkId);
Vector3 pos = obj.Position;
for (int i = 0;
i <
Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorPingTimes")
.GetValue<Slider>()
.Value;
i++)
{
GamePacket gPacketT;
if (Menu.RecallDetector.GetMenuItem("SAwarenessRecallDetectorLocalPing").GetValue<bool>())
{
gPacketT =
Packet.S2C.Ping.Encoded(new Packet.S2C.Ping.Struct(pos[0], pos[1], 0, 0,
Packet.PingType.Danger));
gPacketT.Process();
}
else
{
gPacketT =
Packet.C2S.Ping.Encoded(new Packet.C2S.Ping.Struct(pos.X, pos.Y, 0,
Packet.PingType.Danger));
//gPacketT.Send();
}
}
}
}
}
//By Lexxes
public static Dictionary<int, int> RecallT = new Dictionary<int, int>();
public static Packet.S2C.Recall.Struct RecallDecode(byte[] data)
{
var reader = new BinaryReader(new MemoryStream(data));
var recall = new Packet.S2C.Recall.Struct();
reader.ReadByte(); //PacketId
reader.ReadInt32();
recall.UnitNetworkId = reader.ReadInt32();
reader.ReadBytes(66);
recall.Status = Packet.S2C.Recall.RecallStatus.Unknown;
var teleport = false;
if (BitConverter.ToString(reader.ReadBytes(6)) != "00-00-00-00-00-00")
{
if (BitConverter.ToString(reader.ReadBytes(3)) != "00-00-00")
{
recall.Status = Packet.S2C.Recall.RecallStatus.TeleportStart;
teleport = true;
}
else
recall.Status = Packet.S2C.Recall.RecallStatus.RecallStarted;
}
reader.Close();
var champ = ObjectManager.GetUnitByNetworkId<Obj_AI_Hero>(recall.UnitNetworkId);
if (champ == null)
return recall;
if (teleport)
recall.Duration = 3500;
else
//use masteries to detect recall duration, because spelldata is not initialized yet when enemy has not been seen
{
recall.Duration = Utility.Map.GetMap()._MapType == Utility.Map.MapType.CrystalScar ? 4500 : 8000;
if (champ.Masteries.Any(x => x.Page == MasteryPage.Utility && x.Id == 65 && x.Points == 1))
recall.Duration -= Utility.Map.GetMap()._MapType == Utility.Map.MapType.CrystalScar ? 500 : 1000;
//phasewalker mastery
}
var time = Environment.TickCount - Game.Ping;
if (!RecallT.ContainsKey(recall.UnitNetworkId))
RecallT.Add(recall.UnitNetworkId, time);
//will result in status RecallStarted, which would be wrong if the assembly was to be loaded while somebody recalls
else
{
if (RecallT[recall.UnitNetworkId] == 0)
RecallT[recall.UnitNetworkId] = time;
else
{
if (time - RecallT[recall.UnitNetworkId] > recall.Duration - 175)
recall.Status = teleport
? Packet.S2C.Recall.RecallStatus.TeleportEnd
: Packet.S2C.Recall.RecallStatus.RecallFinished;
else
recall.Status = teleport
? Packet.S2C.Recall.RecallStatus.TeleportAbort
: Packet.S2C.Recall.RecallStatus.RecallAborted;
RecallT[recall.UnitNetworkId] = 0; //recall aborted or finished, reset status
}
}
return recall;
}
public class RecallInfo
{
public int NetworkId;
public Packet.S2C.Recall.Struct Recall;
public Packet.S2C.Recall.Struct Recall2;
public int StartTime;
public RecallInfo(int networkId)
{
NetworkId = networkId;
}
}
}
}