Skip to content

Commit ad785c3

Browse files
committed
Enhance model loading and improve mouse handling
- Added `ClassesUpdated` event in `ModelManager.cs`. - Renamed `LastAntiRecoilClickTime` to `LastAntiRecoilClickTick` in `MouseManager.cs` and changed its type for performance. - Refactored methods in `MovementPaths.cs` for clarity and efficiency, including updates to `Exponential`, `Adaptive`, and `PerlinNoise`. - Simplified `Fade` and `Lerp` methods using expression-bodied syntax.
1 parent 2126d6b commit ad785c3

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

Aimmy2/AILogic/ModelManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public class ModelManager
3333

3434
public bool isModelLoaded => onnxModel != null && outputNames != null && outputNames.Count > 0;
3535

36-
37-
3836
public async Task LoadModelAsync(string modelPath, int IMAGE_SIZE, bool failure = false) // default value for failure is false, obviously
3937
{
4038
try

Aimmy2/InputLogic/MouseManager.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class MouseManager
1515
private static readonly double ScreenHeight = WinAPICaller.ScreenHeight;
1616

1717
private static DateTime LastClickTime = DateTime.MinValue;
18-
private static int LastAntiRecoilClickTime = 0;
18+
private static int LastAntiRecoilClickTick = Environment.TickCount;
1919
private static bool isSpraying = false;
2020

2121
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
@@ -140,9 +140,12 @@ public static void ResetSprayState()
140140
}
141141
}
142142
#endregion
143+
143144
public static void DoAntiRecoil()
144145
{
145-
int timeSinceLastClick = Math.Abs(DateTime.UtcNow.Millisecond - LastAntiRecoilClickTime);
146+
int now = Environment.TickCount;
147+
int timeSinceLastClick = now - LastAntiRecoilClickTick;
148+
146149

147150
if (timeSinceLastClick < Dictionary.AntiRecoilSettings["Fire Rate"])
148151
{
@@ -175,7 +178,7 @@ public static void DoAntiRecoil()
175178
break;
176179
}
177180

178-
LastAntiRecoilClickTime = DateTime.UtcNow.Millisecond;
181+
LastAntiRecoilClickTick = now;
179182
}
180183

181184
public static void MoveCrosshair(int detectedX, int detectedY)

Aimmy2/InputLogic/MovementPaths.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,51 @@ internal static Point Lerp(Point start, Point end, double t)
2525
return new Point(x, y);
2626
}
2727

28+
2829
internal static Point Exponential(Point start, Point end, double t, double exponent = 2.0)
2930
{
30-
double x = start.X + (end.X - start.X) * Math.Pow(t, exponent);
31-
double y = start.Y + (end.Y - start.Y) * Math.Pow(t, exponent);
32-
return new Point((int)x, (int)y);
31+
double factor = Math.Pow(t, exponent);
32+
double x = start.X + (end.X - start.X) * factor;
33+
double y = start.Y + (end.Y - start.Y) * factor;
34+
return new Point((int) x, (int) y);
3335
}
3436

3537
internal static Point Adaptive(Point start, Point end, double t, double threshold = 100.0)
3638
{
37-
double distance = Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2));
38-
if (distance < threshold)
39+
int dx = end.X - start.X;
40+
int dy = end.Y - start.Y;
41+
double distanceSq = dx * dx + dy * dy;
42+
43+
//double distance = Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2));
44+
if (distanceSq < threshold * threshold)
3945
{
4046
return Lerp(start, end, t);
4147
}
4248
else
4349
{
44-
Point control1 = new Point(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
45-
Point control2 = new Point(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
50+
Point control1 = new Point(start.X + dx / 3, start.Y + dy / 3);
51+
Point control2 = new Point(start.X + 2 * dx / 3, start.Y + 2 * dy / 3);
52+
4653
return CubicBezier(start, end, control1, control2, t);
4754
}
4855
}
4956

5057
internal static Point PerlinNoise(Point start, Point end, double t, double amplitude = 10.0, double frequency = 0.1)
5158
{
52-
double baseX = start.X + (end.X - start.X) * t;
53-
double baseY = start.Y + (end.Y - start.Y) * t;
59+
double dx = end.X - start.X;
60+
double dy = end.Y - start.Y;
61+
62+
double baseX = start.X + dx * t;
63+
double baseY = start.Y + dy * t;
5464

5565
double noiseX = Noise(t * frequency, 0) * amplitude;
5666
double noiseY = Noise(t * frequency, 100) * amplitude;
5767

58-
double perpX = -(end.Y - start.Y);
59-
double perpY = end.X - start.X;
68+
double perpX = -dy;
69+
double perpY = dx;
6070
double perpLength = Math.Sqrt(perpX * perpX + perpY * perpY);
6171

62-
if (perpLength > 0)
72+
if (perpLength > 1e-6)
6373
{
6474
perpX /= perpLength;
6575
perpY /= perpLength;
@@ -71,15 +81,9 @@ internal static Point PerlinNoise(Point start, Point end, double t, double ampli
7181
return new Point((int)finalX, (int)finalY);
7282
}
7383

74-
private static double Fade(double t)
75-
{
76-
return t * t * t * (t * (t * 6 - 15) + 10);
77-
}
84+
private static double Fade(double t) => t * t * t * (t * (t * 6 - 15) + 10);
7885

79-
private static double Lerp(double a, double b, double t)
80-
{
81-
return a + t * (b - a);
82-
}
86+
private static double Lerp(double a, double b, double t) => a + t * (b - a);
8387

8488
private static double Grad(int hash, double x, double y)
8589
{

0 commit comments

Comments
 (0)