15 Commits
Author SHA1 Message Date
whoswhip 4e3f39a323 fix: closest to mouse not clamped 2025-10-17 20:45:02 -04:00
whoswhip cce3b91be8 feat: closest to mouse fov and bounds move based off of position of mouse 2025-10-17 19:03:35 -04:00
whoswhip f1ca1ee9ee refactor: simplify & optimize wind mouse movement 2025-10-17 16:27:10 -04:00
whoswhip f0014bc65d feat: add bounding box to movement preview 2025-10-17 16:26:41 -04:00
whoswhip a6f65b1f17 refactor: remove useless conversion code 2025-10-17 16:25:26 -04:00
whoswhip 3f220c7de9 chore: remove configuration for now 2025-10-17 03:13:54 -04:00
whoswhip b556351010 chore: run code cleanup 2025-10-17 03:12:34 -04:00
whoswhip f1d376174b refactor: use Random.Shared for permutation generation 2025-10-17 02:12:50 -04:00
whoswhip 4a0af6bb1b chore(readme): update image 2025-10-17 01:17:03 -04:00
whoswhip bdf3be13ab feat: make points draggable
refactor: move movement preview window into it's own file
2025-10-16 23:02:14 -04:00
whoswhip 2fa0b4ac2d feat:
- wind mouse
- code optimizations
- mouse movement path preview
2025-10-16 20:32:31 -04:00
whoswhip ab0ca784f4 refactor: add support for larger sensitivity values 2025-10-15 21:11:27 -04:00
whoswhip 86d7e3ffbd feat: (2) implement better keybind system 2025-10-15 21:09:22 -04:00
whoswhip c14427bf81 refactor: simplify code 2025-10-15 21:08:42 -04:00
whoswhip 5832f92edc feat: implement better keybind system 2025-10-15 21:06:13 -04:00
12 changed files with 597 additions and 176 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# Spectrum # Spectrum
Spectrum is a semi-universal colorbot that uses C# and OpenCV for image processing. Spectrum is a semi-universal colorbot that uses C# and OpenCV for image processing.
<img width="600" height="502" alt="Spectrum Menu" src="https://upld.zip/d9Z8Evjm.png" /> <img width="700" height="603" alt="Spectrum Menu" src="https://upld.zip/PYRXWN5Y.png" />
## Features ## Features
- Extensive configuration file - Extensive configuration file
- Dataset collection - Dataset collection
+30 -16
View File
@@ -25,7 +25,7 @@ namespace Spectrum
_configDirectory = configDirectory; _configDirectory = configDirectory;
_currentConfigName = Path.GetFileNameWithoutExtension(fileName); _currentConfigName = Path.GetFileNameWithoutExtension(fileName);
_data = new T(); _data = new T();
_availableConfigs = new List<string>(); _availableConfigs = [];
if (!Directory.Exists(_configDirectory)) if (!Directory.Exists(_configDirectory))
{ {
@@ -37,7 +37,7 @@ namespace Spectrum
LoadConfig(); LoadConfig();
} }
public void LoadConfig(bool silent = false, string filename = "") public void LoadConfig(string filename = "")
{ {
if (string.IsNullOrEmpty(filename)) if (string.IsNullOrEmpty(filename))
filename = _defaultFilename; filename = _defaultFilename;
@@ -51,7 +51,6 @@ namespace Spectrum
var json = File.ReadAllText(filename); var json = File.ReadAllText(filename);
_data = JsonConvert.DeserializeObject<T>(json) ?? new T(); _data = JsonConvert.DeserializeObject<T>(json) ?? new T();
_currentConfigName = Path.GetFileNameWithoutExtension(filename); _currentConfigName = Path.GetFileNameWithoutExtension(filename);
if (!silent) LogManager.Log($"Loaded config {filename}.", LogLevel.Info);
} }
catch catch
{ {
@@ -83,7 +82,6 @@ namespace Spectrum
{ {
File.WriteAllText(filename, JsonConvert.SerializeObject(_data, Formatting.Indented)); File.WriteAllText(filename, JsonConvert.SerializeObject(_data, Formatting.Indented));
_currentConfigName = Path.GetFileNameWithoutExtension(filename); _currentConfigName = Path.GetFileNameWithoutExtension(filename);
LogManager.Log($"Saved config to {filename}.", LogLevel.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -119,7 +117,7 @@ namespace Spectrum
return false; return false;
} }
LoadConfig(false, filePath); LoadConfig(filePath);
return true; return true;
} }
@@ -165,7 +163,6 @@ namespace Spectrum
_directoryWatcher.Changed += OnDirectoryChanged; _directoryWatcher.Changed += OnDirectoryChanged;
_directoryWatcher.EnableRaisingEvents = true; _directoryWatcher.EnableRaisingEvents = true;
LogManager.Log($"Directory watcher started for {_configDirectory}.", LogLevel.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -185,7 +182,6 @@ namespace Spectrum
_directoryWatcher.Dispose(); _directoryWatcher.Dispose();
_directoryWatcher = null; _directoryWatcher = null;
LogManager.Log($"Directory watcher stopped for {_configDirectory}.", LogLevel.Info);
} }
private void OnDirectoryChanged(object sender, FileSystemEventArgs e) private void OnDirectoryChanged(object sender, FileSystemEventArgs e)
@@ -213,7 +209,6 @@ namespace Spectrum
try try
{ {
File.Delete(filePath); File.Delete(filePath);
LogManager.Log($"Deleted config {configName}.", LogLevel.Info);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
@@ -251,7 +246,6 @@ namespace Spectrum
File.Move(oldPath, newPath); File.Move(oldPath, newPath);
if (_currentConfigName == oldName) if (_currentConfigName == oldName)
_currentConfigName = newName; _currentConfigName = newName;
LogManager.Log($"Renamed config from {oldName} to {newName}.", LogLevel.Info);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
@@ -271,7 +265,6 @@ namespace Spectrum
}; };
_fileWatcher.Changed += OnConfigFileChanged; _fileWatcher.Changed += OnConfigFileChanged;
_fileWatcher.EnableRaisingEvents = true; _fileWatcher.EnableRaisingEvents = true;
LogManager.Log($"File watcher started for {_defaultFilename}.", LogLevel.Info);
} }
public void StopFileWatcher() public void StopFileWatcher()
@@ -281,7 +274,6 @@ namespace Spectrum
_fileWatcher.Changed -= OnConfigFileChanged; _fileWatcher.Changed -= OnConfigFileChanged;
_fileWatcher.Dispose(); _fileWatcher.Dispose();
_fileWatcher = null; _fileWatcher = null;
LogManager.Log($"File watcher stopped for {_defaultFilename}.", LogLevel.Info);
} }
private void OnConfigFileChanged(object sender, FileSystemEventArgs e) private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
@@ -289,8 +281,7 @@ namespace Spectrum
Thread.Sleep(100); Thread.Sleep(100);
try try
{ {
LoadConfig(true); LoadConfig();
LogManager.Log($"Configuration reloaded successfully for {_defaultFilename}.", LogLevel.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -312,7 +303,8 @@ namespace Spectrum
CubicBezier, CubicBezier,
QuadraticBezier, QuadraticBezier,
Adaptive, Adaptive,
PerlinNoise PerlinNoise,
WindMouse
} }
public enum MovementMethod public enum MovementMethod
{ {
@@ -330,6 +322,12 @@ namespace Spectrum
GDI, GDI,
DirectX DirectX
} }
public enum KeybindType
{
Hold,
Toggle,
Always
}
#endregion #endregion
public class ConfigData public class ConfigData
{ {
@@ -353,18 +351,23 @@ namespace Spectrum
#region Aim Settings #region Aim Settings
public bool EnableAim { get; set; } = true; public bool EnableAim { get; set; } = true;
public bool ClosestToMouse { get; set; } = true; public bool ClosestToMouse { get; set; } = true;
public Keys Keybind { get; set; } = Keys.XButton2; public Keybind Keybind = new(Keys.XButton2, KeybindType.Hold);
public double Sensitivity { get; set; } = 0.5; public double Sensitivity { get; set; } = 0.5;
public MovementType AimMovementType { get; set; } = MovementType.Adaptive; public MovementType AimMovementType { get; set; } = MovementType.Adaptive;
public bool EmaSmoothening { get; set; } = true; public bool EmaSmoothening { get; set; } = true;
public double EmaSmootheningFactor { get; set; } = 0.1; public double EmaSmootheningFactor { get; set; } = 0.1;
public MovementMethod MovementMethod { get; set; } = MovementMethod.MouseEvent; public MovementMethod MovementMethod { get; set; } = MovementMethod.MouseEvent;
public double WindMouseGravity { get; set; } = 9.0;
public double WindMouseWind { get; set; } = 3.0;
public double WindMouseMaxStep { get; set; } = 10.0;
public bool WindMouseOvershoot { get; set; } = false;
#endregion #endregion
#region Trigger Settings #region Trigger Settings
public bool TriggerBot { get; set; } = false; public bool TriggerBot { get; set; } = false;
public Keys TriggerKey { get; set; } = Keys.XButton2; public Keybind TriggerKeybind = new(Keys.XButton1, KeybindType.Hold);
public int TriggerDelay { get; set; } = 50; // milliseconds public int TriggerDelay { get; set; } = 50; // milliseconds
public int TriggerFov { get; set; } = 15; // pixels public int TriggerFov { get; set; } = 15; // pixels
public int TriggerDuration { get; set; } = 100; // milliseconds public int TriggerDuration { get; set; } = 100; // milliseconds
@@ -413,4 +416,15 @@ namespace Spectrum
public Scalar Upper { get; set; } = upper; public Scalar Upper { get; set; } = upper;
public Scalar Lower { get; set; } = lower; public Scalar Lower { get; set; } = lower;
} }
public class Keybind
{
public Keys Key { get; set; }
public KeybindType Type { get; set; }
public Keybind(Keys key, KeybindType type)
{
Key = key;
Type = type;
}
}
} }
+2 -2
View File
@@ -2,9 +2,9 @@
using Vortice.Direct3D; using Vortice.Direct3D;
using Vortice.Direct3D11; using Vortice.Direct3D11;
using Vortice.DXGI; using Vortice.DXGI;
using Size = System.Drawing.Size;
using Rectangle = System.Drawing.Rectangle;
using Point = System.Drawing.Point; using Point = System.Drawing.Point;
using Rectangle = System.Drawing.Rectangle;
using Size = System.Drawing.Size;
namespace Spectrum.Detection namespace Spectrum.Detection
{ {
+49 -18
View File
@@ -1,5 +1,4 @@
using ImGuiNET; using OpenCvSharp;
using OpenCvSharp;
using Spectrum.Input; using Spectrum.Input;
using System.Diagnostics; using System.Diagnostics;
@@ -40,7 +39,7 @@ namespace Spectrum.Detection
{ {
try try
{ {
if (InputManager.IsKeyOrMouseDown(mainConfig.Data.Keybind) || InputManager.IsKeyOrMouseDown(mainConfig.Data.TriggerKey)) if (InputManager.IsKeyOrMouseDown(mainConfig.Data.Keybind) || InputManager.IsKeyOrMouseDown(mainConfig.Data.TriggerKeybind))
{ {
var config = mainConfig.Data; var config = mainConfig.Data;
if (config.DebugMode) if (config.DebugMode)
@@ -48,15 +47,40 @@ namespace Spectrum.Detection
renderer?.ClearDetectionDrawCommands(); renderer?.ClearDetectionDrawCommands();
bounds = new Rectangle( if (!config.ClosestToMouse)
(screenSize.Width - config.ImageWidth) / 2, {
(screenSize.Height - config.ImageHeight) / 2, bounds = new Rectangle(
config.ImageWidth, (screenSize.Width - config.ImageWidth) / 2,
config.ImageHeight (screenSize.Height - config.ImageHeight) / 2,
); config.ImageWidth,
var screenshot = null as Bitmap; config.ImageHeight
);
}
else
{
_ = InputManager.GetCursorPos(out System.Drawing.Point mousePos);
bounds = new Rectangle(
mousePos.X - (config.ImageWidth / 2),
mousePos.Y - (config.ImageHeight / 2),
config.ImageWidth,
config.ImageHeight
);
}
var screenRect = new Rectangle(0, 0, screenSize.Width, screenSize.Height);
bounds = Rectangle.Intersect(bounds, screenRect);
if (bounds.Width <= 0 || bounds.Height <= 0)
{
renderer?.CommitDetectionDrawCommands();
Thread.Sleep(2);
continue;
}
Bitmap? screenshot = null;
if (config.CaptureMethod == CaptureMethod.DirectX && _captureManager.IsDirectXAvailable) if (config.CaptureMethod == CaptureMethod.DirectX && _captureManager.IsDirectXAvailable)
{
screenshot = _captureManager.CaptureScreenshotDirectX(bounds); screenshot = _captureManager.CaptureScreenshotDirectX(bounds);
}
else else
{ {
if (_captureManager.IsInitialized) if (_captureManager.IsInitialized)
@@ -141,7 +165,7 @@ namespace Spectrum.Detection
bestRect.Width, bestRect.Width,
bestRect.Height bestRect.Height
); );
renderer!.AddRect(_rect, config.TargetColor, 2.0f); renderer!.AddRect(_rect, config.TargetColor, 1.0f);
} }
int groupX; int groupX;
@@ -176,6 +200,11 @@ namespace Spectrum.Detection
} }
InputManager.SetLastDetection(new System.Drawing.Point(targetX, targetY)); InputManager.SetLastDetection(new System.Drawing.Point(targetX, targetY));
InputManager.SetLastDetectionBox(new Rectangle(
bestRect.X + bounds.X,
bestRect.Y + bounds.Y,
bestRect.Width,
bestRect.Height));
if (config.EnableAim) if (config.EnableAim)
{ {
@@ -194,6 +223,7 @@ namespace Spectrum.Detection
else if (config.CollectData && drawing != null) else if (config.CollectData && drawing != null)
{ {
AutoLabeling.AddBackgroundImage(drawing, false); AutoLabeling.AddBackgroundImage(drawing, false);
MovementPaths.ResetWindMouse();
} }
renderer?.CommitDetectionDrawCommands(); renderer?.CommitDetectionDrawCommands();
@@ -231,7 +261,14 @@ namespace Spectrum.Detection
} }
} }
} }
else if (InputManager.IsKeyOrMouseDown(mainConfig.Data.MenuKey)) else
{
renderer?.ClearDetectionDrawCommands();
renderer?.CommitDetectionDrawCommands();
MovementPaths.ResetWindMouse();
Thread.Sleep(5);
}
if (InputManager.IsKeyOrMouseDown(mainConfig.Data.MenuKey))
{ {
var now = DateTime.Now; var now = DateTime.Now;
if ((now - lastMenuToggle).TotalMilliseconds > 175) if ((now - lastMenuToggle).TotalMilliseconds > 175)
@@ -240,12 +277,6 @@ namespace Spectrum.Detection
lastMenuToggle = now; lastMenuToggle = now;
} }
} }
else
{
renderer?.ClearDetectionDrawCommands();
renderer?.CommitDetectionDrawCommands();
Thread.Sleep(5);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
+70 -25
View File
@@ -12,6 +12,7 @@ namespace Spectrum.Input
public static extern bool GetCursorPos(out Point lpPoint); public static extern bool GetCursorPos(out Point lpPoint);
private static ConfigManager<ConfigData> mainConfig = Program.mainConfig; private static ConfigManager<ConfigData> mainConfig = Program.mainConfig;
private static Point lastDetection = new Point(); private static Point lastDetection = new Point();
private static Rectangle lastDetectionBox = new Rectangle();
private static long _lastMoveTicks = 0; private static long _lastMoveTicks = 0;
private static readonly double _dtRef = 1.0 / 120.0; private static readonly double _dtRef = 1.0 / 120.0;
@@ -35,15 +36,20 @@ namespace Spectrum.Input
private static double TimeScaleFactor(double baseFactor, double deltaSeconds) private static double TimeScaleFactor(double baseFactor, double deltaSeconds)
{ {
if (baseFactor <= 0) return 0; if (baseFactor <= 0) return 0;
if (baseFactor >= 1) return 1; if (baseFactor >= 1)
double k = deltaSeconds / _dtRef; {
return 1 - Math.Pow(1 - baseFactor, k); double k = deltaSeconds / _dtRef;
return baseFactor * k;
}
double kLow = deltaSeconds / _dtRef;
return 1 - Math.Pow(1 - baseFactor, kLow);
} }
public static void MoveMouse() public static void MoveMouse()
{ {
var config = mainConfig.Data;
Point reference = new Point(); Point reference = new Point();
if (mainConfig.Data.ClosestToMouse) if (config.ClosestToMouse)
{ {
GetCursorPos(out reference); GetCursorPos(out reference);
} }
@@ -57,21 +63,30 @@ namespace Spectrum.Input
Point end = new Point(lastDetection.X, lastDetection.Y); Point end = new Point(lastDetection.X, lastDetection.Y);
double dt = GetDeltaSeconds(); double dt = GetDeltaSeconds();
double effSensitivity = TimeScaleFactor(mainConfig.Data.Sensitivity, dt); double effSensitivity = TimeScaleFactor(config.Sensitivity, dt);
Point newPosition = mainConfig.Data.AimMovementType switch bool insideBoundingBox = lastDetectionBox.Contains(start);
Point newPosition = config.AimMovementType switch
{ {
MovementType.CubicBezier => MovementPaths.CubicBezierMovement(start, end, effSensitivity), MovementType.CubicBezier => MovementPaths.CubicBezierCurvedMovement(start, end, effSensitivity),
MovementType.Linear => MovementPaths.LinearInterpolation(start, end, effSensitivity), MovementType.Linear => MovementPaths.LinearInterpolation(start, end, effSensitivity),
MovementType.Adaptive => MovementPaths.AdaptiveMovement(start, end, effSensitivity), MovementType.Adaptive => MovementPaths.AdaptiveMovement(start, end, effSensitivity),
MovementType.QuadraticBezier => MovementPaths.CurvedMovement(start, end, effSensitivity), MovementType.QuadraticBezier => MovementPaths.CurvedMovement(start, end, effSensitivity),
MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(start, end, effSensitivity), MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(start, end, effSensitivity),
_ => end MovementType.WindMouse => MovementPaths.WindMouse(start, end,
config.WindMouseGravity,
config.WindMouseWind,
config.WindMouseMaxStep,
effSensitivity,
config.WindMouseOvershoot,
insideBoundingBox),
_ => MovementPaths.LinearInterpolation(start, end, effSensitivity),
}; };
if (mainConfig.Data.EmaSmoothening) if (config.EmaSmoothening)
{ {
double emaAlpha = TimeScaleFactor(mainConfig.Data.EmaSmootheningFactor, dt); double emaAlpha = TimeScaleFactor(config.EmaSmootheningFactor, dt);
newPosition.X = (int)Math.Round(MovementPaths.EmaSmoothing(reference.X, newPosition.X, emaAlpha)); newPosition.X = (int)Math.Round(MovementPaths.EmaSmoothing(reference.X, newPosition.X, emaAlpha));
newPosition.Y = (int)Math.Round(MovementPaths.EmaSmoothing(reference.Y, newPosition.Y, emaAlpha)); newPosition.Y = (int)Math.Round(MovementPaths.EmaSmoothing(reference.Y, newPosition.Y, emaAlpha));
} }
@@ -80,10 +95,10 @@ namespace Spectrum.Input
int deltaY = newPosition.Y - reference.Y; int deltaY = newPosition.Y - reference.Y;
if (Math.Abs(deltaX) < 1 && Math.Abs(deltaY) < 1) return; if (Math.Abs(deltaX) < 1 && Math.Abs(deltaY) < 1) return;
if (deltaX > mainConfig.Data.ImageWidth || deltaX < -mainConfig.Data.ImageWidth || deltaY > mainConfig.Data.ImageHeight || deltaY < -mainConfig.Data.ImageHeight) if (deltaX > config.ImageWidth || deltaX < -config.ImageWidth || deltaY > config.ImageHeight || deltaY < -config.ImageHeight)
return; return;
switch (mainConfig.Data.MovementMethod) switch (config.MovementMethod)
{ {
case MovementMethod.MouseEvent: case MovementMethod.MouseEvent:
MouseEvent.Move(deltaX, deltaY); MouseEvent.Move(deltaX, deltaY);
@@ -105,13 +120,14 @@ namespace Spectrum.Input
public static async Task ClickMouse() public static async Task ClickMouse()
{ {
if (!mainConfig.Data.TriggerBot) var config = mainConfig.Data;
if (!config.TriggerBot)
return; return;
if (!IsKeyOrMouseDown(mainConfig.Data.TriggerKey) || mainConfig.Data.TriggerKey == Keys.None) if (!IsKeyOrMouseDown(config.TriggerKeybind) || config.TriggerKeybind.Key == Keys.None)
return; return;
var currentPosition = new Point(); var currentPosition = new Point();
if (mainConfig.Data.ClosestToMouse) if (config.ClosestToMouse)
{ {
GetCursorPos(out currentPosition); GetCursorPos(out currentPosition);
} }
@@ -121,14 +137,14 @@ namespace Spectrum.Input
currentPosition.Y = SystemHelper.GetPrimaryScreenSize().Height / 2; currentPosition.Y = SystemHelper.GetPrimaryScreenSize().Height / 2;
} }
if (mainConfig.Data.TriggerDelay > 0) if (config.TriggerDelay > 0)
await Task.Delay(mainConfig.Data.TriggerDelay); await Task.Delay(config.TriggerDelay);
int radius = mainConfig.Data.TriggerFov; int radius = config.TriggerFov;
if (Math.Abs(currentPosition.X - lastDetection.X) < radius && Math.Abs(currentPosition.Y - lastDetection.Y) < radius) if (Math.Abs(currentPosition.X - lastDetection.X) < radius && Math.Abs(currentPosition.Y - lastDetection.Y) < radius)
{ {
switch (mainConfig.Data.MovementMethod) switch (config.MovementMethod)
{ {
case MovementMethod.MouseEvent: case MovementMethod.MouseEvent:
MouseEvent.ClickDown(); MouseEvent.ClickDown();
@@ -146,8 +162,8 @@ namespace Spectrum.Input
MouseEvent.ClickDown(); MouseEvent.ClickDown();
break; break;
} }
await Task.Delay(mainConfig.Data.TriggerDuration); await Task.Delay(config.TriggerDuration);
switch (mainConfig.Data.MovementMethod) switch (config.MovementMethod)
{ {
case MovementMethod.MouseEvent: case MovementMethod.MouseEvent:
MouseEvent.ClickUp(); MouseEvent.ClickUp();
@@ -172,10 +188,9 @@ namespace Spectrum.Input
} }
} }
public static void SetLastDetection(Point point) public static void SetLastDetection(Point point) { lastDetection = point; }
{
lastDetection = point; public static void SetLastDetectionBox(Rectangle box) { lastDetectionBox = box; }
}
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vKey); private static extern short GetAsyncKeyState(int vKey);
@@ -318,6 +333,36 @@ namespace Spectrum.Input
return (GetAsyncKeyState((int)key) & 0x8000) != 0; ; return (GetAsyncKeyState((int)key) & 0x8000) != 0; ;
} }
private static readonly Dictionary<string, bool> _keybindToggleStates = new();
public static bool IsKeyOrMouseDown(Keybind keybind)
{
if (keybind.Type == KeybindType.Always)
return true;
bool isKeyDown = IsKeyOrMouseDown(keybind.Key);
if (keybind.Type == KeybindType.Hold)
return isKeyDown;
string toggleKey = keybind.Key.ToString();
if (!_keybindToggleStates.ContainsKey(toggleKey))
_keybindToggleStates[toggleKey] = false;
if (isKeyDown && !_keybindToggleStates.ContainsKey($"{toggleKey}_pressed"))
{
_keybindToggleStates[$"{toggleKey}_pressed"] = true;
_keybindToggleStates[toggleKey] = !_keybindToggleStates[toggleKey];
}
else if (!isKeyDown)
{
_keybindToggleStates.Remove($"{toggleKey}_pressed");
}
return _keybindToggleStates[toggleKey];
}
private static MakcuMouseButton? MapKeysToMakcuButton(Keys key) private static MakcuMouseButton? MapKeysToMakcuButton(Keys key)
{ {
return key switch return key switch
+91 -6
View File
@@ -1,5 +1,4 @@
namespace Spectrum.Input
namespace Spectrum.Input
{ {
public class MovementPaths public class MovementPaths
{ {
@@ -8,6 +7,12 @@ namespace Spectrum.Input
private static readonly int[] _p; private static readonly int[] _p;
private static double _perlinTime = 0.0; private static double _perlinTime = 0.0;
private static Point _lastMove = new Point(0, 0);
private static double _windX = 0.0;
private static double _windY = 0.0;
private static double _velocityX = 0.0;
private static double _velocityY = 0.0;
static MovementPaths() static MovementPaths()
{ {
_p = new int[512]; _p = new int[512];
@@ -150,16 +155,96 @@ namespace Spectrum.Input
int y = (int)Math.Round(EmaSmoothing(previous.Y, current.Y, smoothingFactor)); int y = (int)Math.Round(EmaSmoothing(previous.Y, current.Y, smoothingFactor));
return new Point(x, y); return new Point(x, y);
} }
public static Point WindMouse(Point start, Point end, double gravity = 9.0, double wind = 3.0,
double maxStep = 10.0, double sensitivity = 1.0, bool enableOvershoot = false, bool insideBoundingBox = false)
{
double dx = end.X - start.X;
double dy = end.Y - start.Y;
double d = Math.Sqrt(dx * dx + dy * dy);
if (d <= 0) return start;
double inv = 1.0 / d;
double dirX = dx * inv;
double dirY = dy * inv;
if (insideBoundingBox)
{
double s = Math.Min(d * 0.35, maxStep * sensitivity * 0.6);
_perlinTime += 0.03;
double n = Math.Sin(_perlinTime * 1.1) * 0.3 + Math.Cos(_perlinTime * 0.9) * 0.2;
int x = (int)Math.Round(start.X + dirX * s + n);
int y = (int)Math.Round(start.Y + dirY * s + n * 0.7);
_windX *= 0.15;
_windY *= 0.15;
_velocityX *= 0.3;
_velocityY *= 0.3;
return _lastMove = new Point(x, y);
}
double distScale = Math.Min(d / 100.0, 3.0);
double sens = Math.Max(0.1, sensitivity);
double dyn = maxStep * sens * (1.0 + distScale);
double g = gravity * (1.0 + distScale * 0.3) * sens * (enableOvershoot ? 1.15 : 1.0);
double prox = insideBoundingBox ? 0.0 : 1.0;
double w = wind * Math.Pow(prox, 4.0) * (enableOvershoot ? 1.2 : 1.0);
if (insideBoundingBox)
{
double damp = 0.25;
_velocityX *= damp;
_velocityY *= damp;
double wd = Math.Pow(damp, 4.0);
_windX *= wd;
_windY *= wd;
}
_windX = _windX / Math.Sqrt(3) + (Random.Shared.NextDouble() * 2 - 1) * w;
_windY = _windY / Math.Sqrt(3) + (Random.Shared.NextDouble() * 2 - 1) * w;
_velocityX += _windX + g * dirX;
_velocityY += _windY + g * dirY;
double vm = Math.Sqrt(_velocityX * _velocityX + _velocityY * _velocityY);
if (vm > dyn)
{
double r = dyn / vm;
_velocityX *= r;
_velocityY *= r;
vm = dyn;
}
if (!enableOvershoot && insideBoundingBox)
{
double limit = d * 0.4;
if (vm > limit && vm > 0)
{
double r = limit / vm;
_velocityX *= r;
_velocityY *= r;
}
}
int nx = (int)Math.Round(start.X + _velocityX);
int ny = (int)Math.Round(start.Y + _velocityY);
return _lastMove = new Point(nx, ny);
}
public static void ResetWindMouse()
{
_windX = 0.0;
_windY = 0.0;
_velocityX = 0.0;
_velocityY = 0.0;
_lastMove = new Point(0, 0);
}
private static int[] GeneratePermutation() private static int[] GeneratePermutation()
{ {
int[] perm = new int[256]; int[] perm = new int[256];
for (int i = 0; i < 256; i++) perm[i] = i; for (int i = 0; i < 256; i++) perm[i] = i;
string user = Environment.UserName;
int seed = Environment.TickCount + user.GetHashCode();
Random rand = new(seed);
for (int i = 255; i > 0; i--) for (int i = 255; i > 0; i--)
{ {
int j = rand.Next(i + 1); int j = Random.Shared.Next(i + 1);
(perm[i], perm[j]) = (perm[j], perm[i]); (perm[i], perm[j]) = (perm[j], perm[i]);
} }
return perm; return perm;
-1
View File
@@ -88,7 +88,6 @@ namespace Spectrum
public static void ClearLog() public static void ClearLog()
{ {
_logEntries.Clear(); _logEntries.Clear();
Log("Log cleared.", LogLevel.Info);
} }
public static void OpenLogFolder() public static void OpenLogFolder()
+2 -6
View File
@@ -28,7 +28,6 @@ namespace Spectrum
mainConfig.Data.CaptureMethod = CaptureMethod.GDI; mainConfig.Data.CaptureMethod = CaptureMethod.GDI;
} }
renderer.Run(); renderer.Run();
LogManager.Log("Renderer started successfully.", LogManager.LogLevel.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -41,10 +40,7 @@ namespace Spectrum
foreach (var dir in dirs) foreach (var dir in dirs)
{ {
if (!Directory.Exists(dir)) if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
LogManager.Log($"Created directory: {dir}", LogManager.LogLevel.Info);
}
} }
mainConfig.LoadConfig(); mainConfig.LoadConfig();
@@ -60,8 +56,8 @@ namespace Spectrum
colorConfig.Data.Colors.Add(new ColorInfo("Arsenal [Magenta]", new Scalar(179, 255, 255), new Scalar(150, 255, 255))); colorConfig.Data.Colors.Add(new ColorInfo("Arsenal [Magenta]", new Scalar(179, 255, 255), new Scalar(150, 255, 255)));
colorConfig.Data.Colors.Add(new ColorInfo("Combat Surf [Red]", new Scalar(0, 255, 255), new Scalar(0, 255, 255))); colorConfig.Data.Colors.Add(new ColorInfo("Combat Surf [Red]", new Scalar(0, 255, 255), new Scalar(0, 255, 255)));
colorConfig.SaveConfig(); colorConfig.SaveConfig();
colorConfig.LoadConfig(true); colorConfig.LoadConfig();
mainConfig.LoadConfig(true); mainConfig.LoadConfig();
} }
Thread.Sleep(1000); Thread.Sleep(1000);
-1
View File
@@ -216,7 +216,6 @@ namespace Spectrum
else else
{ {
Program.colorConfig.Data.Colors.Add(new ColorInfo(_colorName, _upperHSV, _lowerHSV)); Program.colorConfig.Data.Colors.Add(new ColorInfo(_colorName, _upperHSV, _lowerHSV));
LogManager.Log($"Created new color: {_colorName}", LogManager.LogLevel.Info);
} }
Program.colorConfig.SaveConfig(); Program.colorConfig.SaveConfig();
_colorName = ""; _colorName = "";
+81 -2
View File
@@ -1,5 +1,6 @@
using ImGuiNET; using ImGuiNET;
using OpenCvSharp; using OpenCvSharp;
using Spectrum.Input;
using System.Globalization; using System.Globalization;
using System.Numerics; using System.Numerics;
@@ -198,7 +199,7 @@ namespace Spectrum
return new Scalar(h, s, v); return new Scalar(h, s, v);
} }
public static bool SliderFill(string label, ref float value, float min, float max, string format = "%.2f") public static bool SliderFill(string label, ref float value, float min, float max, string format = "%.2f", bool enforceRange = true)
{ {
bool changed = false; bool changed = false;
@@ -313,7 +314,11 @@ namespace Spectrum
if (parseStr.EndsWith("%")) parseStr = parseStr.TrimEnd('%'); if (parseStr.EndsWith("%")) parseStr = parseStr.TrimEnd('%');
if (float.TryParse(parseStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float typed)) if (float.TryParse(parseStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float typed))
{ {
float clamped = Math.Clamp(typed, min, max); float clamped;
if (enforceRange)
clamped = Math.Clamp(typed, min, max);
else
clamped = typed;
if (Math.Abs(clamped - value) > float.Epsilon) if (Math.Abs(clamped - value) > float.Epsilon)
{ {
value = clamped; value = clamped;
@@ -340,6 +345,7 @@ namespace Spectrum
drawList.AddRectFilled(p0, p1, ImGui.GetColorU32(ImGuiCol.FrameBg), 4f); drawList.AddRectFilled(p0, p1, ImGui.GetColorU32(ImGuiCol.FrameBg), 4f);
float fillWidth = ((value - min) / (max - min)) * (p1.X - p0.X); float fillWidth = ((value - min) / (max - min)) * (p1.X - p0.X);
fillWidth = Math.Clamp(fillWidth, 0f, p1.X - p0.X);
drawList.AddRectFilled(p0, new Vector2(p0.X + fillWidth, p1.Y), ImGui.GetColorU32(ImGuiCol.SliderGrabActive), 4f); drawList.AddRectFilled(p0, new Vector2(p0.X + fillWidth, p1.Y), ImGui.GetColorU32(ImGuiCol.SliderGrabActive), 4f);
ImGui.PopStyleVar(); ImGui.PopStyleVar();
@@ -466,5 +472,78 @@ namespace Spectrum
var g = _paneGroups.Pop(); var g = _paneGroups.Pop();
g.Index = g.Count; g.Index = g.Count;
} }
private static readonly Dictionary<string, bool> _keybindListening = [];
private static readonly Dictionary<string, Keys> _keybindPending = [];
private static readonly Dictionary<string, Task?> _keybindTasks = [];
public static bool KeybindInput(string label, ref Keybind keybind, bool inline = false)
{
bool changed = false;
ImGui.PushID(label);
if (!inline)
ImGui.TextUnformatted(label);
string buttonText = _keybindListening.GetValueOrDefault(label)
? "Listening..."
: keybind.Key.ToString();
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(buttonText).X);
if (!_keybindListening.GetValueOrDefault(label, false))
{
if (ImGui.Button($"{buttonText}###{label}_Button"))
{
_keybindListening[label] = true;
_keybindPending[label] = Keys.None;
_keybindTasks[label] = Task.Run(async () =>
{
var key = await InputManager.ListenForNextKeyOrMouseAsync();
_keybindPending[label] = key;
});
}
if (ImGui.BeginPopupContextItem($"###{label}_Context"))
{
bool isHold = keybind.Type == KeybindType.Hold;
if (ImGui.MenuItem("Hold", null, isHold))
{
keybind.Type = KeybindType.Hold;
changed = true;
}
bool isToggle = keybind.Type == KeybindType.Toggle;
if (ImGui.MenuItem("Toggle", null, isToggle))
{
keybind.Type = KeybindType.Toggle;
changed = true;
}
bool isAlways = keybind.Type == KeybindType.Always;
if (ImGui.MenuItem("Always", null, isAlways))
{
keybind.Type = KeybindType.Always;
changed = true;
}
ImGui.EndPopup();
}
}
else
{
ImGui.Button($"{buttonText}###{label}_Listening");
if (_keybindPending.GetValueOrDefault(label, Keys.None) != Keys.None)
{
keybind.Key = _keybindPending[label];
_keybindPending[label] = Keys.None;
_keybindListening[label] = false;
changed = true;
}
}
ImGui.PopID();
return changed;
}
} }
} }
+182
View File
@@ -0,0 +1,182 @@
using ImGuiNET;
using Spectrum.Input;
using System.Numerics;
namespace Spectrum
{
partial class Renderer
{
private bool _showMovementPreview = false;
private Point _previewStartPoint = new(100, 100);
private Point _previewEndPoint = new(400, 300);
private List<(Point point, double speed)> _previewPath = [];
private int UpdatePreviewInterval = 10; // ms
private DateTime _lastPreviewUpdate = DateTime.MinValue;
private bool _isDragging = false;
private bool _isMovingStart = false;
private void RenderMovementPreview()
{
if (!_showMovementPreview)
return;
var config = mainConfig.Data;
ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.Always);
ImGui.SetNextWindowPos(new Vector2(screenSize.width / 2 - 300, screenSize.height / 2 - 250), ImGuiCond.FirstUseEver);
if (!ImGui.Begin("Movement Path Preview", ref _showMovementPreview, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoTitleBar))
{
ImGui.End();
return;
}
ImGui.TextUnformatted("Movement Path Preview");
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 14);
if (ImGui.Button("X", new Vector2(22, 22)))
{
_showMovementPreview = false;
ImGui.End();
return;
}
var boundingBox = new Rectangle(_previewEndPoint.X - 20, _previewEndPoint.Y - 40, 40, 80);
if ((DateTime.Now - _lastPreviewUpdate).TotalMilliseconds > UpdatePreviewInterval)
{
_lastPreviewUpdate = DateTime.Now;
_previewPath.Clear();
MovementPaths.ResetWindMouse();
double progress = 0.0;
double increment = config.Sensitivity * 0.02;
Point current = _previewStartPoint;
int steps = 0;
int maxSteps = 10000;
while (true)
{
double distance = Math.Sqrt(Math.Pow(_previewEndPoint.X - current.X, 2) + Math.Pow(_previewEndPoint.Y - current.Y, 2));
if (steps++ >= maxSteps)
break;
bool isInBox = boundingBox.Contains(current);
Point nextPoint = config.AimMovementType switch
{
MovementType.Linear => MovementPaths.LinearInterpolation(current, _previewEndPoint, progress),
MovementType.CubicBezier => MovementPaths.CubicBezierCurvedMovement(current, _previewEndPoint, progress),
MovementType.Adaptive => MovementPaths.AdaptiveMovement(current, _previewEndPoint, progress),
MovementType.QuadraticBezier => MovementPaths.CurvedMovement(current, _previewEndPoint, progress),
MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(current, _previewEndPoint, progress),
MovementType.WindMouse => MovementPaths.WindMouse(current, _previewEndPoint,
config.WindMouseGravity,
config.WindMouseWind,
config.WindMouseMaxStep,
config.Sensitivity,
config.WindMouseOvershoot,
isInBox),
_ => MovementPaths.LinearInterpolation(current, _previewEndPoint, progress),
};
if (config.EmaSmoothening)
nextPoint = MovementPaths.EmaSmoothing(current, nextPoint, config.EmaSmootheningFactor);
double speed = Math.Sqrt(Math.Pow(nextPoint.X - current.X, 2) + Math.Pow(nextPoint.Y - current.Y, 2));
_previewPath.Add((nextPoint, speed));
current = nextPoint;
progress += increment;
}
}
var drawList = ImGui.GetWindowDrawList();
Vector2 canvasPos = ImGui.GetCursorScreenPos();
canvasPos.Y += 5;
Vector2 canvasSize = ImGui.GetContentRegionAvail();
Vector2 size = new Vector2(canvasSize.X, canvasSize.Y - 60);
drawList.AddRectFilled(canvasPos, size + canvasPos, ImGui.GetColorU32(new Vector4(0.12f, 0.12f, 0.14f, 1.0f)), 3f);
drawList.AddRect(canvasPos, size + canvasPos, ImGui.GetColorU32(new Vector4(0.17f, 0.17f, 0.20f, 1.0f)), 3f);
drawList.AddRect(
new Vector2(boundingBox.X + canvasPos.X, boundingBox.Top + canvasPos.Y),
new Vector2(boundingBox.X + boundingBox.Width + canvasPos.X, boundingBox.Y + boundingBox.Height + canvasPos.Y),
ImGui.GetColorU32(new Vector4(0, 0, 1, 1)), 0.0f, ImDrawFlags.None, 2.0f);
if (_previewPath.Count > 1)
{
double maxSpeed = _previewPath.Max(p => p.speed);
for (int i = 1; i < _previewPath.Count; i++)
{
var (prevPoint, _) = _previewPath[i - 1];
var (currPoint, speed) = _previewPath[i];
Vector2 p1 = new Vector2(canvasPos.X + prevPoint.X, canvasPos.Y + prevPoint.Y);
Vector2 p2 = new Vector2(canvasPos.X + currPoint.X, canvasPos.Y + currPoint.Y);
Vector4 color = speed < maxSpeed / 2 ?
Vector4.Lerp(new Vector4(0, 1, 0, 1), new Vector4(1, 1, 0, 1), (float)(speed / (maxSpeed / 2))) :
Vector4.Lerp(new Vector4(1, 1, 0, 1), new Vector4(1, 0, 0, 1), (float)((speed - (maxSpeed / 2)) / (maxSpeed / 2)));
drawList.AddLine(p1, p2, ImGui.GetColorU32(color), 2.0f);
}
}
drawList.AddCircleFilled(new Vector2(canvasPos.X + _previewStartPoint.X, canvasPos.Y + _previewStartPoint.Y), 5.0f, ImGui.GetColorU32(new Vector4(0, 1, 0, 1)));
drawList.AddCircleFilled(new Vector2(canvasPos.X + _previewEndPoint.X, canvasPos.Y + _previewEndPoint.Y), 5.0f, ImGui.GetColorU32(new Vector4(1, 0, 0, 1)));
ImGui.InvisibleButton("canvas", size);
var io = ImGui.GetIO();
var mousePos = io.MousePos;
bool isMouseInCanvas = mousePos.X >= canvasPos.X && mousePos.X <= canvasPos.X + size.X &&
mousePos.Y >= canvasPos.Y && mousePos.Y <= canvasPos.Y + size.Y;
bool isMouseDown = ImGui.IsMouseDown(ImGuiMouseButton.Left);
bool isMouseClicked = ImGui.IsMouseClicked(ImGuiMouseButton.Left);
bool isMouseReleased = ImGui.IsMouseReleased(ImGuiMouseButton.Left);
if (!_isDragging && isMouseInCanvas && isMouseClicked)
{
Vector2 localMousePos = mousePos - canvasPos;
float distToStart = Vector2.Distance(localMousePos, new Vector2(_previewStartPoint.X, _previewStartPoint.Y));
float distToEnd = Vector2.Distance(localMousePos, new Vector2(_previewEndPoint.X, _previewEndPoint.Y));
if (distToStart < 10.0f)
{
_isMovingStart = true;
_isDragging = true;
}
else if (distToEnd < 10.0f)
{
_isMovingStart = false;
_isDragging = true;
}
else
{
_isDragging = false;
_isMovingStart = false;
}
}
if (_isDragging && isMouseDown)
{
Vector2 localMousePos = mousePos - canvasPos;
if (localMousePos.X < 0) localMousePos.X = 0;
if (localMousePos.Y < 0) localMousePos.Y = 0;
if (localMousePos.X > size.X) localMousePos.X = size.X;
if (localMousePos.Y > size.Y) localMousePos.Y = size.Y;
if (_isMovingStart)
{
_previewStartPoint = new Point((int)localMousePos.X, (int)localMousePos.Y);
}
else
{
_previewEndPoint = new Point((int)localMousePos.X, (int)localMousePos.Y);
}
}
if (_isDragging && isMouseReleased)
{
_isDragging = false;
}
ImGui.Dummy(new(ImGui.GetContentRegionAvail().X, 10));
int interval = UpdatePreviewInterval;
if (ImGuiExtensions.SliderFill("Update Interval (ms)", ref interval, 1, 100))
UpdatePreviewInterval = interval;
ImGui.End();
}
}
}
+72 -81
View File
@@ -81,39 +81,15 @@ namespace Spectrum
ImGui.SameLine(); ImGui.SameLine();
ImGui.TextUnformatted("Enable Aiming"); ImGui.TextUnformatted("Enable Aiming");
ImGuiExtensions.KeybindInput("Aim Keybind", ref config.Keybind, true);
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(_waitingForKeybind.GetValueOrDefault("Aiming") ? "Listening..." : config.Keybind.ToString()).X);
if (!_waitingForKeybind.GetValueOrDefault("Aiming", false))
{
if (ImGui.Button($"{config.Keybind.ToString()}###AimKeybind"))
{
_waitingForKeybind["Aiming"] = true;
_pendingKeybind["Aiming"] = Keys.None;
_keybindTask["Aiming"] = Task.Run(async () =>
{
var key = await InputManager.ListenForNextKeyOrMouseAsync();
_pendingKeybind["Aiming"] = key;
});
}
}
else
{
ImGui.Button("Listening... ###AimListening");
if (_pendingKeybind.GetValueOrDefault("Aiming", Keys.None) != Keys.None)
{
config.Keybind = _pendingKeybind["Aiming"];
_pendingKeybind["Aiming"] = Keys.None;
_waitingForKeybind["Aiming"] = false;
}
}
bool closestToMouse = config.ClosestToMouse; bool closestToMouse = config.ClosestToMouse;
if (ImGui.Checkbox(" Closest to Mouse", ref closestToMouse)) if (ImGui.Checkbox(" Closest to Mouse", ref closestToMouse))
config.ClosestToMouse = closestToMouse; config.ClosestToMouse = closestToMouse;
float sensitivity = (float)config.Sensitivity; float sensitivity = (float)config.Sensitivity;
if (ImGuiExtensions.SliderFill("Sensitivity", ref sensitivity, 0.1f, 2.0f, "%.1f")) if (ImGuiExtensions.SliderFill("Sensitivity", ref sensitivity, 0.1f, 2.0f, "%.1f", false))
config.Sensitivity = sensitivity; config.Sensitivity = Math.Clamp(sensitivity, 0.1, float.MaxValue);
float EmaSmootheningFactor = (float)config.EmaSmootheningFactor; float EmaSmootheningFactor = (float)config.EmaSmootheningFactor;
bool EmaSmoothening = config.EmaSmoothening; bool EmaSmoothening = config.EmaSmoothening;
@@ -121,10 +97,18 @@ namespace Spectrum
config.EmaSmoothening = EmaSmoothening; config.EmaSmoothening = EmaSmoothening;
if (EmaSmoothening) if (EmaSmoothening)
if (ImGuiExtensions.SliderFill("Ema Smoothening Factor", ref EmaSmootheningFactor, 0.01f, 1.0f)) {
config.EmaSmootheningFactor = EmaSmootheningFactor; float smoothingPercentage = (float)((1.0 - config.EmaSmootheningFactor) * 100.0);
if (ImGuiExtensions.SliderFill("Ema Smoothening (%)", ref smoothingPercentage, 0f, 99f, "%.0f%%"))
{
config.EmaSmootheningFactor = 1.0 - (smoothingPercentage / 100.0);
}
}
ImGui.TextUnformatted("Movement Type"); ImGui.TextUnformatted("Movement Path");
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 9);
if (ImGui.Button(_showMovementPreview ? "X" : "?", new Vector2(20, 20)))
_showMovementPreview = !_showMovementPreview;
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
MovementType AimPath = config.AimMovementType; MovementType AimPath = config.AimMovementType;
if (ImGui.BeginCombo("##Movement Type", AimPath.ToString())) if (ImGui.BeginCombo("##Movement Type", AimPath.ToString()))
@@ -141,6 +125,25 @@ namespace Spectrum
ImGui.EndCombo(); ImGui.EndCombo();
} }
if (AimPath == MovementType.WindMouse)
{
float windMouseGravity = (float)config.WindMouseGravity;
if (ImGuiExtensions.SliderFill("Gravity", ref windMouseGravity, 1.0f, 20.0f, "%.1f"))
config.WindMouseGravity = windMouseGravity;
float windMouseWind = (float)config.WindMouseWind;
if (ImGuiExtensions.SliderFill("Wind", ref windMouseWind, 0.5f, 10.0f, "%.1f"))
config.WindMouseWind = windMouseWind;
float windMouseMaxStep = (float)config.WindMouseMaxStep;
if (ImGuiExtensions.SliderFill("Max Step", ref windMouseMaxStep, 1.0f, 50.0f, "%.1f"))
config.WindMouseMaxStep = windMouseMaxStep;
bool enableOvershoot = config.WindMouseOvershoot;
if (ImGui.Checkbox("Enable Overshoot", ref enableOvershoot))
config.WindMouseOvershoot = enableOvershoot;
}
bool YPixelOffset = config.YPixelOffset; bool YPixelOffset = config.YPixelOffset;
if (ImGui.Checkbox("Pixel Based Offset (Y)", ref YPixelOffset)) if (ImGui.Checkbox("Pixel Based Offset (Y)", ref YPixelOffset))
config.YPixelOffset = YPixelOffset; config.YPixelOffset = YPixelOffset;
@@ -249,30 +252,7 @@ namespace Spectrum
bool triggerBot = config.TriggerBot; bool triggerBot = config.TriggerBot;
if (ImGui.Checkbox(" Enabled", ref triggerBot)) if (ImGui.Checkbox(" Enabled", ref triggerBot))
config.TriggerBot = triggerBot; config.TriggerBot = triggerBot;
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(_waitingForKeybind.GetValueOrDefault("Trigger Key") ? "Listening..." : config.TriggerKey.ToString()).X); ImGuiExtensions.KeybindInput("Trigger Keybind", ref config.TriggerKeybind, true);
if (!_waitingForKeybind.GetValueOrDefault("Trigger Key", false))
{
if (ImGui.Button($"{config.TriggerKey}###TriggerKeybind"))
{
_waitingForKeybind["Trigger Key"] = true;
_pendingKeybind["Trigger Key"] = Keys.None;
_keybindTask["Trigger Key"] = Task.Run(async () =>
{
var key = await InputManager.ListenForNextKeyOrMouseAsync();
_pendingKeybind["Trigger Key"] = key;
});
}
}
else
{
ImGui.Button("Listening... ###TriggerListening");
if (_pendingKeybind.GetValueOrDefault("Trigger Key", Keys.None) != Keys.None)
{
config.TriggerKey = _pendingKeybind["Trigger Key"];
_pendingKeybind["Trigger Key"] = Keys.None;
_waitingForKeybind["Trigger Key"] = false;
}
}
if (triggerBot) if (triggerBot)
{ {
@@ -355,11 +335,11 @@ namespace Spectrum
ImGuiExtensions.EndPane(); ImGuiExtensions.EndPane();
} }
if (ImGuiExtensions.BeginPane("Detection Configs")) if (ImGuiExtensions.BeginPane("Color Configs"))
{ {
List<ColorInfo> colors = colorConfig.Data.Colors; List<ColorInfo> colors = colorConfig.Data.Colors;
ImGui.PushStyleColor(ImGuiCol.ChildBg, new Vector4(0.110f, 0.110f, 0.125f, 1.000f)); ImGui.PushStyleColor(ImGuiCol.ChildBg, new Vector4(0.110f, 0.110f, 0.125f, 1.000f));
ImGui.BeginChild("##DetectionConfigsChild", new Vector2(0, ImGui.GetContentRegionAvail().Y / 2), ImGuiChildFlags.None); ImGui.BeginChild("##DColorConfigsChild", new Vector2(0, ImGui.GetContentRegionAvail().Y / 2), ImGuiChildFlags.None);
ImGui.Dummy(new Vector2(0, 4)); ImGui.Dummy(new Vector2(0, 4));
foreach (var color in colors) foreach (var color in colors)
{ {
@@ -718,7 +698,7 @@ namespace Spectrum
ImGui.Dummy(new Vector2(0, 1)); ImGui.Dummy(new Vector2(0, 1));
if (ImGui.Button("Save Logs")) if (ImGui.Button("Save Logs"))
LogManager.SaveLog($"bin\\logs\\{DateTime.Now.ToString("MM-dd_HH-mm-ss")}_spectrum_log.txt"); LogManager.SaveLog($"bin\\logs\\{DateTime.Now:MM-dd_HH-mm-ss}_spectrum_log.txt");
ImGui.SameLine(); ImGui.SameLine();
@@ -732,20 +712,17 @@ namespace Spectrum
ImGuiExtensions.EndPane(); ImGuiExtensions.EndPane();
} }
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
ImGui.EndTabBar(); ImGui.EndTabBar();
ImGui.End(); ImGui.End();
RenderHSVRangeWindow(); RenderHSVRangeWindow();
RenderMovementPreview();
} }
protected void RenderOverlay() protected void RenderOverlay()
{ {
ImGui.SetNextWindowSize(new Vector2(screenSize.width, screenSize.height), ImGuiCond.Always); ImGui.SetNextWindowSize(new Vector2(screenSize.width, screenSize.height), ImGuiCond.Always);
@@ -758,14 +735,37 @@ namespace Spectrum
{ {
if (config.FOVType == FovType.Rectangle) if (config.FOVType == FovType.Rectangle)
{ {
drawList.AddRect(new Vector2((screenSize.width - config.ImageWidth) / 2, (screenSize.height - config.ImageHeight) / 2), Vector2 topLeft;
new Vector2((screenSize.width + config.ImageWidth) / 2, (screenSize.height + config.ImageHeight) / 2), Vector2 bottomRight;
ImGui.GetColorU32(config.FOVColor), 0.0f, ImDrawFlags.None, 1.0f); if (!config.ClosestToMouse)
{
topLeft = new((screenSize.width - config.ImageWidth) / 2, (screenSize.height - config.ImageHeight) / 2);
bottomRight = new((screenSize.width + config.ImageWidth) / 2, (screenSize.height + config.ImageHeight) / 2);
}
else
{
InputManager.GetCursorPos(out System.Drawing.Point mousePos);
topLeft = new(mousePos.X - (config.ImageWidth / 2), mousePos.Y - (config.ImageHeight / 2));
bottomRight = new(mousePos.X + (config.ImageWidth / 2), mousePos.Y + (config.ImageHeight / 2));
}
drawList.AddRect(topLeft, bottomRight, ImGui.GetColorU32(config.FOVColor), 0.0f, ImDrawFlags.None, 1.0f);
} }
else if (config.FOVType == FovType.Circle) else if (config.FOVType == FovType.Circle)
{ {
drawList.AddCircle(new Vector2(screenSize.width / 2, screenSize.height / 2), config.ImageWidth / 2, Vector2 center;
ImGui.GetColorU32(config.FOVColor), 100, 1.0f); if (!config.ClosestToMouse)
{
center = new(screenSize.width / 2, screenSize.height / 2);
}
else
{
_ = InputManager.GetCursorPos(out System.Drawing.Point mousePos);
center = new(mousePos.X, mousePos.Y);
}
drawList.AddCircle(center, config.ImageWidth / 2, ImGui.GetColorU32(config.FOVColor), 100, 1.0f);
} // added straight to drawlist to prevent caching/flickering } // added straight to drawlist to prevent caching/flickering
} }
@@ -782,7 +782,7 @@ namespace Spectrum
List<Action<ImDrawListPtr>> _drawCommands; List<Action<ImDrawListPtr>> _drawCommands;
lock (detectionDrawLock) lock (detectionDrawLock)
{ {
_drawCommands = activeDrawCommands.ToList(); _drawCommands = [.. activeDrawCommands];
} }
foreach (var cmd in _drawCommands) foreach (var cmd in _drawCommands)
@@ -792,7 +792,7 @@ namespace Spectrum
ImGui.End(); ImGui.End();
} }
private void AddStyling() private static void AddStyling()
{ {
var style = ImGui.GetStyle(); var style = ImGui.GetStyle();
var colors = style.Colors; var colors = style.Colors;
@@ -878,7 +878,7 @@ namespace Spectrum
{ {
lock (detectionDrawLock) lock (detectionDrawLock)
{ {
detectionDrawCommands.Add(drawList => drawList.AddRect(new Vector2(rect.Left, rect.Top), new Vector2(rect.Right, rect.Bottom), ColorFromVector4(color), 0, 0, thickness)); detectionDrawCommands.Add(drawList => drawList.AddRect(new Vector2(rect.Left, rect.Top), new Vector2(rect.Right, rect.Bottom), ImGui.GetColorU32(color), 0, 0, thickness));
} }
} }
@@ -886,7 +886,7 @@ namespace Spectrum
{ {
lock (detectionDrawLock) lock (detectionDrawLock)
{ {
detectionDrawCommands.Add(drawList => drawList.AddLine(p1, p2, ColorFromVector4(color), thickness)); detectionDrawCommands.Add(drawList => drawList.AddLine(p1, p2, ImGui.GetColorU32(color), thickness));
} }
} }
@@ -897,7 +897,7 @@ namespace Spectrum
lock (detectionDrawLock) lock (detectionDrawLock)
{ {
detectionDrawCommands.Add(drawList => drawList.AddCircle(center, radius, ColorFromVector4(color), numSegments, thickness)); detectionDrawCommands.Add(drawList => drawList.AddCircle(center, radius, ImGui.GetColorU32(color), numSegments, thickness));
} }
} }
@@ -907,7 +907,7 @@ namespace Spectrum
return; return;
lock (detectionDrawLock) lock (detectionDrawLock)
{ {
detectionDrawCommands.Add(drawList => drawList.AddText(ImGui.GetFont(), fontSize, pos, ColorFromVector4(color), text)); detectionDrawCommands.Add(drawList => drawList.AddText(ImGui.GetFont(), fontSize, pos, ImGui.GetColorU32(color), text));
} }
} }
@@ -934,14 +934,5 @@ namespace Spectrum
return new Vector2(0, 0); return new Vector2(0, 0);
return ImGui.CalcTextSize(text, 0, text.Length, fontSize); return ImGui.CalcTextSize(text, 0, text.Length, fontSize);
} }
private static uint ColorFromVector4(Vector4 color)
{
int r = (int)(Math.Clamp(color.X, 0f, 1f) * 255.0f);
int g = (int)(Math.Clamp(color.Y, 0f, 1f) * 255.0f);
int b = (int)(Math.Clamp(color.Z, 0f, 1f) * 255.0f);
int a = (int)(Math.Clamp(color.W, 0f, 1f) * 255.0f);
return (uint)((a << 24) | (b << 16) | (g << 8) | r);
}
} }
} }