-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundESP.cs
More file actions
287 lines (243 loc) · 11.7 KB
/
SoundESP.cs
File metadata and controls
287 lines (243 loc) · 11.7 KB
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
using System;
using System.Collections.Generic;
using System.Numerics;
using ImGuiNET;
namespace FutaZone
{
public class SoundEffect
{
public Vector3 origin;
public double spawnTime;
public Entity entity;
}
public static class SoundESP
{
public static int Style = 0; // 0: Expanding Circle, 1: Connected Circles, 2: Arrows
public static float MaxDistance = 2000.0f;
public static float EffectSpeed = 200.0f;
public static float MaxRadius = 60.0f;
public static float MinMovementSpeed = 15.0f;
public static double MinSpawnInterval = 0.2f;
private static List<SoundEffect> soundEffects = new List<SoundEffect>();
private static Dictionary<long, float> lastSoundTimes = new Dictionary<long, float>();
private static Dictionary<long, double> lastSpawnTimes = new Dictionary<long, double>();
public static void RenderSound(Vector3 origin, float radius, Vector4 color, float[] viewMatrix, Vector2 screenSize, ImDrawListPtr drawList)
{
const float PI = 3.14159265358979323846f;
const float STEP = PI * 2.0f / 60;
List<Vector2> points = new List<Vector2>();
for (float angle = 0.0f; angle <= PI * 2.0f; angle += STEP)
{
Vector3 worldPoint = origin + new Vector3((float)Math.Sin(angle) * radius, (float)Math.Cos(angle) * radius, 0.0f);
Vector2 screenPoint = Calculate.WorldToScreen(viewMatrix, worldPoint, screenSize);
if (screenPoint.X != -99 && screenPoint.Y != -99)
{
points.Add(screenPoint);
}
}
if (points.Count > 1)
{
for (int i = 0; i < points.Count - 1; i++)
{
drawList.AddLine(points[i], points[i + 1], ImGui.ColorConvertFloat4ToU32(color), 1.0f);
}
// Close the circle if we have enough points
if (points.Count > 50)
{
drawList.AddLine(points[points.Count - 1], points[0], ImGui.ColorConvertFloat4ToU32(color), 1.0f);
}
}
}
public static void RenderSolidCircle3D(Vector3 origin, float radius, Vector4 color, float[] viewMatrix, Vector2 screenSize, ImDrawListPtr drawList)
{
const float PI = 3.14159265358979323846f;
const float STEP = PI * 2.0f / 30;
List<Vector2> points = new List<Vector2>();
for (float angle = 0.0f; angle <= PI * 2.0f; angle += STEP)
{
Vector3 worldPoint = origin + new Vector3((float)Math.Sin(angle) * radius, (float)Math.Cos(angle) * radius, 0.0f);
Vector2 screenPoint = Calculate.WorldToScreen(viewMatrix, worldPoint, screenSize);
if (screenPoint.X != -99 && screenPoint.Y != -99)
{
points.Add(screenPoint);
}
}
if (points.Count > 2)
{
var pointsArray = points.ToArray();
drawList.AddConvexPolyFilled(ref pointsArray[0], points.Count, ImGui.ColorConvertFloat4ToU32(color));
}
}
public static void DrawArrow3D(Vector3 start, Vector3 end, Vector4 color, float[] viewMatrix, Vector2 screenSize, ImDrawListPtr drawList)
{
Vector2 screenStart = Calculate.WorldToScreen(viewMatrix, start, screenSize);
Vector2 screenEnd = Calculate.WorldToScreen(viewMatrix, end, screenSize);
if (screenStart.X != -99 && screenStart.Y != -99 && screenEnd.X != -99 && screenEnd.Y != -99)
{
drawList.AddLine(screenStart, screenEnd, ImGui.ColorConvertFloat4ToU32(color), 2.0f);
Vector3 dir = end - start;
if (dir.LengthSquared() > 0.001f)
{
dir = Vector3.Normalize(dir);
Vector3 right = new Vector3(-dir.Y, dir.X, 0);
if (right.LengthSquared() < 0.001f)
{
right = new Vector3(1, 0, 0);
}
else
{
right = Vector3.Normalize(right);
}
float arrowLength = 15.0f;
float arrowWidth = 8.0f;
Vector3 arrowBase = end - dir * arrowLength;
Vector3 p1 = arrowBase + right * arrowWidth;
Vector3 p2 = arrowBase - right * arrowWidth;
Vector2 screenP1 = Calculate.WorldToScreen(viewMatrix, p1, screenSize);
Vector2 screenP2 = Calculate.WorldToScreen(viewMatrix, p2, screenSize);
if (screenP1.X != -99 && screenP1.Y != -99 && screenP2.X != -99 && screenP2.Y != -99)
{
Vector2[] arrowPoints = new Vector2[] { screenEnd, screenP1, screenP2 };
drawList.AddConvexPolyFilled(ref arrowPoints[0], 3, ImGui.ColorConvertFloat4ToU32(color));
}
}
}
}
public static void ProcessSound(Entity entity, Entity localEntity)
{
if (Vector3.Distance(entity.position, localEntity.position) > MaxDistance)
return;
float currentSoundTime = entity.emitSoundTime;
bool Jumped = (entity.flags & (1 << 0)) == 0; // ON_GROUND flag is 1<<0
if (!lastSoundTimes.ContainsKey(entity.controllerAddress))
{
lastSoundTimes[entity.controllerAddress] = currentSoundTime;
return;
}
if (lastSoundTimes[entity.controllerAddress] == currentSoundTime)
return;
if (entity.velocity < MinMovementSpeed && !Jumped)
{
lastSoundTimes[entity.controllerAddress] = currentSoundTime;
return;
}
lastSoundTimes[entity.controllerAddress] = currentSoundTime;
double currentTime = ImGui.GetTime();
if (!lastSpawnTimes.ContainsKey(entity.controllerAddress))
{
lastSpawnTimes[entity.controllerAddress] = 0;
}
if (currentTime - lastSpawnTimes[entity.controllerAddress] < MinSpawnInterval)
return;
lastSpawnTimes[entity.controllerAddress] = currentTime;
bool updated = false;
if (Style == 0)
{
foreach (var soundEffect in soundEffects)
{
if (soundEffect.entity.controllerAddress == entity.controllerAddress)
{
soundEffect.origin = entity.position;
soundEffect.spawnTime = currentTime;
soundEffect.entity = entity;
updated = true;
break;
}
}
}
if (!updated)
{
soundEffects.Add(new SoundEffect
{
origin = entity.position,
spawnTime = currentTime,
entity = entity
});
}
}
public static void Render(float[] viewMatrix, Vector2 screenSize, ImDrawListPtr drawList, Vector4 baseColor, bool enableSoundEspGradient = false, Vector4 soundESPColor2 = default)
{
if (soundEffects.Count == 0)
return;
double currentTime = ImGui.GetTime();
float duration = Style == 0 ? MaxRadius / EffectSpeed : 2.0f;
Dictionary<long, List<SoundEffect>> entitySounds = new Dictionary<long, List<SoundEffect>>();
for (int i = soundEffects.Count - 1; i >= 0; i--)
{
var soundEffect = soundEffects[i];
float elapsed = (float)(currentTime - soundEffect.spawnTime);
if (elapsed > duration)
{
soundEffects.RemoveAt(i);
continue;
}
if (Style == 0)
{
float progress = Math.Clamp(elapsed / duration, 0.0f, 1.0f);
float startRadius = MaxRadius * 0.1f;
float radius = startRadius + (MaxRadius - startRadius) * progress;
Vector4 color = baseColor;
if (enableSoundEspGradient)
{
color.X += (soundESPColor2.X - baseColor.X) * progress;
color.Y += (soundESPColor2.Y - baseColor.Y) * progress;
color.Z += (soundESPColor2.Z - baseColor.Z) * progress;
}
color.W *= (1.0f - progress);
RenderSound(soundEffect.origin, radius, color, viewMatrix, screenSize, drawList);
}
else
{
if (!entitySounds.ContainsKey(soundEffect.entity.controllerAddress))
{
entitySounds[soundEffect.entity.controllerAddress] = new List<SoundEffect>();
}
entitySounds[soundEffect.entity.controllerAddress].Add(soundEffect);
}
}
if (Style == 1 || Style == 2)
{
foreach (var kvp in entitySounds)
{
var sounds = kvp.Value;
sounds.Sort((a, b) => a.spawnTime.CompareTo(b.spawnTime));
for (int i = 0; i < sounds.Count; i++)
{
var sound = sounds[i];
float elapsed = (float)(currentTime - sound.spawnTime);
float progress = Math.Clamp(elapsed / duration, 0.0f, 1.0f);
Vector4 color = baseColor;
if (enableSoundEspGradient)
{
color.X += (soundESPColor2.X - baseColor.X) * progress;
color.Y += (soundESPColor2.Y - baseColor.Y) * progress;
color.Z += (soundESPColor2.Z - baseColor.Z) * progress;
}
color.W *= (1.0f - progress);
if (Style == 1)
{
RenderSolidCircle3D(sound.origin, 15.0f, color, viewMatrix, screenSize, drawList);
}
if (i < sounds.Count - 1)
{
var nextSound = sounds[i + 1];
if (Style == 1)
{
Vector2 screenStart = Calculate.WorldToScreen(viewMatrix, sound.origin, screenSize);
Vector2 screenEnd = Calculate.WorldToScreen(viewMatrix, nextSound.origin, screenSize);
if (screenStart.X != -99 && screenStart.Y != -99 && screenEnd.X != -99 && screenEnd.Y != -99)
{
drawList.AddLine(screenStart, screenEnd, ImGui.ColorConvertFloat4ToU32(color), 2.0f);
}
}
else if (Style == 2)
{
DrawArrow3D(sound.origin, nextSound.origin, color, viewMatrix, screenSize, drawList);
}
}
}
}
}
}
}
}