mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
feat:
- random trigger delay - random trigger duration - trigger spray mode - trigger in bounds only - anti capture refactor: - move system helper into Win32.cs fix: - only move mouse when holding the aim button - load existing images on auto labeling start
This commit is contained in:
+6
-1
@@ -368,9 +368,13 @@ namespace Spectrum
|
|||||||
#region Trigger Settings
|
#region Trigger Settings
|
||||||
public bool TriggerBot { get; set; } = false;
|
public bool TriggerBot { get; set; } = false;
|
||||||
public Keybind TriggerKeybind = new(Keys.XButton1, KeybindType.Hold);
|
public Keybind TriggerKeybind = new(Keys.XButton1, KeybindType.Hold);
|
||||||
|
public bool TriggerRandomDelay { get; set; } = false;
|
||||||
public int TriggerDelay { get; set; } = 50; // milliseconds
|
public int TriggerDelay { get; set; } = 50; // milliseconds
|
||||||
public int TriggerFov { get; set; } = 15; // pixels
|
public bool TriggerSpray = false; // if true ignore duration
|
||||||
|
public bool TriggerRandomDuration { get; set; } = false;
|
||||||
public int TriggerDuration { get; set; } = 100; // milliseconds
|
public int TriggerDuration { get; set; } = 100; // milliseconds
|
||||||
|
public bool TriggerInBoundsOnly { get; set; } = false;
|
||||||
|
public int TriggerFov { get; set; } = 15; // pixels
|
||||||
public bool DrawTriggerFov { get; set; } = false;
|
public bool DrawTriggerFov { get; set; } = false;
|
||||||
public Vector4 TriggerRadiusColor { get; set; } = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
|
public Vector4 TriggerRadiusColor { get; set; } = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -403,6 +407,7 @@ namespace Spectrum
|
|||||||
|
|
||||||
#region Misc
|
#region Misc
|
||||||
public bool DebugMode { get; set; } = false;
|
public bool DebugMode { get; set; } = false;
|
||||||
|
public bool AntiCapture { get; set; } = false;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
public class ColorData
|
public class ColorData
|
||||||
|
|||||||
@@ -206,6 +206,9 @@ namespace Spectrum.Detection
|
|||||||
if (cancellationTokenSource != null)
|
if (cancellationTokenSource != null)
|
||||||
return;
|
return;
|
||||||
LogManager.Log("Starting auto labeling...", LogLevel.Info);
|
LogManager.Log("Starting auto labeling...", LogLevel.Info);
|
||||||
|
int existingImages = Directory.Exists("bin/dataset/images") ?
|
||||||
|
Directory.GetFiles("bin/dataset/images", "image_*.jpg").Length : 0;
|
||||||
|
imageCount = existingImages;
|
||||||
Started = true;
|
Started = true;
|
||||||
cancellationTokenSource = new CancellationTokenSource();
|
cancellationTokenSource = new CancellationTokenSource();
|
||||||
backgroundTask = Task.Run(() => LabelingLoop(cancellationTokenSource.Token));
|
backgroundTask = Task.Run(() => LabelingLoop(cancellationTokenSource.Token));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Spectrum.Detection
|
|||||||
{
|
{
|
||||||
private readonly Stopwatch stopwatch = new Stopwatch();
|
private readonly Stopwatch stopwatch = new Stopwatch();
|
||||||
private Rectangle bounds = new Rectangle(0, 0, 0, 0);
|
private Rectangle bounds = new Rectangle(0, 0, 0, 0);
|
||||||
private readonly (int Width, int Height) screenSize = SystemHelper.GetPrimaryScreenSize();
|
private readonly (int Width, int Height) screenSize = Win32.GetPrimaryScreenSize();
|
||||||
private readonly int minArea;
|
private readonly int minArea;
|
||||||
private readonly ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
private readonly ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
||||||
private readonly Renderer? renderer;
|
private readonly Renderer? renderer;
|
||||||
@@ -206,7 +206,7 @@ namespace Spectrum.Detection
|
|||||||
bestRect.Width,
|
bestRect.Width,
|
||||||
bestRect.Height));
|
bestRect.Height));
|
||||||
|
|
||||||
if (config.EnableAim)
|
if (config.EnableAim && InputManager.IsKeyOrMouseDown(config.Keybind))
|
||||||
{
|
{
|
||||||
InputManager.MoveMouse();
|
InputManager.MoveMouse();
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ namespace Spectrum.Detection
|
|||||||
{
|
{
|
||||||
var _ = InputManager.ClickMouse();
|
var _ = InputManager.ClickMouse();
|
||||||
}
|
}
|
||||||
if (renderer != null && config.DrawTriggerFov && config.TriggerBot)
|
if (renderer != null && config.DrawTriggerFov && config.TriggerBot && !config.TriggerInBoundsOnly)
|
||||||
{
|
{
|
||||||
renderer.AddCircle(new System.Numerics.Vector2(targetX, targetY), config.TriggerFov, config.TriggerRadiusColor, 100);
|
renderer.AddCircle(new System.Numerics.Vector2(targetX, targetY), config.TriggerFov, config.TriggerRadiusColor, 100);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Spectrum.Input
|
|||||||
private static Rectangle lastDetectionBox = new Rectangle();
|
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;
|
||||||
|
private static bool isSpraying = false;
|
||||||
|
|
||||||
private static double GetDeltaSeconds()
|
private static double GetDeltaSeconds()
|
||||||
{
|
{
|
||||||
@@ -48,15 +49,15 @@ namespace Spectrum.Input
|
|||||||
public static void MoveMouse()
|
public static void MoveMouse()
|
||||||
{
|
{
|
||||||
var config = mainConfig.Data;
|
var config = mainConfig.Data;
|
||||||
Point reference = new Point();
|
Point reference = new();
|
||||||
if (config.ClosestToMouse)
|
if (config.ClosestToMouse)
|
||||||
{
|
{
|
||||||
GetCursorPos(out reference);
|
GetCursorPos(out reference);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reference.X = SystemHelper.GetPrimaryScreenSize().Width / 2;
|
reference.X = Win32.GetPrimaryScreenSize().Width / 2;
|
||||||
reference.Y = SystemHelper.GetPrimaryScreenSize().Height / 2;
|
reference.Y = Win32.GetPrimaryScreenSize().Height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point start = new Point(reference.X, reference.Y);
|
Point start = new Point(reference.X, reference.Y);
|
||||||
@@ -133,18 +134,56 @@ namespace Spectrum.Input
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentPosition.X = SystemHelper.GetPrimaryScreenSize().Width / 2;
|
currentPosition.X = Win32.GetPrimaryScreenSize().Width / 2;
|
||||||
currentPosition.Y = SystemHelper.GetPrimaryScreenSize().Height / 2;
|
currentPosition.Y = Win32.GetPrimaryScreenSize().Height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.TriggerDelay > 0)
|
if (config.TriggerDelay > 0 && !config.TriggerRandomDelay)
|
||||||
await Task.Delay(config.TriggerDelay);
|
await Task.Delay(config.TriggerDelay);
|
||||||
|
else if (config.TriggerRandomDelay)
|
||||||
|
await Task.Delay(Random.Shared.Next(10, config.TriggerDelay + 1));
|
||||||
|
|
||||||
int radius = config.TriggerFov;
|
int radius = config.TriggerFov;
|
||||||
|
bool shouldClick;
|
||||||
|
if (config.TriggerInBoundsOnly)
|
||||||
|
shouldClick = lastDetectionBox.Contains(currentPosition);
|
||||||
|
else
|
||||||
|
shouldClick = 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)
|
|
||||||
|
if (shouldClick)
|
||||||
{
|
{
|
||||||
switch (config.MovementMethod)
|
if (config.TriggerSpray && !isSpraying)
|
||||||
|
{
|
||||||
|
isSpraying = true;
|
||||||
|
ClickDown(config.MovementMethod);
|
||||||
|
}
|
||||||
|
else if (!config.TriggerSpray)
|
||||||
|
{
|
||||||
|
ClickDown(config.MovementMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.TriggerRandomDuration && !config.TriggerSpray)
|
||||||
|
await Task.Delay(config.TriggerDuration);
|
||||||
|
else if (!config.TriggerSpray)
|
||||||
|
await Task.Delay(Random.Shared.Next(20, config.TriggerDuration));
|
||||||
|
|
||||||
|
if (!config.TriggerSpray)
|
||||||
|
ClickUp(config.MovementMethod);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isSpraying)
|
||||||
|
{
|
||||||
|
isSpraying = false;
|
||||||
|
ClickUp(config.MovementMethod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ClickDown(MovementMethod movementMethod)
|
||||||
|
{
|
||||||
|
switch (movementMethod)
|
||||||
{
|
{
|
||||||
case MovementMethod.MouseEvent:
|
case MovementMethod.MouseEvent:
|
||||||
MouseEvent.ClickDown();
|
MouseEvent.ClickDown();
|
||||||
@@ -162,8 +201,10 @@ namespace Spectrum.Input
|
|||||||
MouseEvent.ClickDown();
|
MouseEvent.ClickDown();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await Task.Delay(config.TriggerDuration);
|
}
|
||||||
switch (config.MovementMethod)
|
private static void ClickUp(MovementMethod movementMethod)
|
||||||
|
{
|
||||||
|
switch (movementMethod)
|
||||||
{
|
{
|
||||||
case MovementMethod.MouseEvent:
|
case MovementMethod.MouseEvent:
|
||||||
MouseEvent.ClickUp();
|
MouseEvent.ClickUp();
|
||||||
@@ -182,11 +223,6 @@ namespace Spectrum.Input
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
var dist = Math.Sqrt(Math.Pow(currentPosition.X - lastDetection.X, 2) + Math.Pow(currentPosition.Y - lastDetection.Y, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetLastDetection(Point point) { lastDetection = point; }
|
public static void SetLastDetection(Point point) { lastDetection = point; }
|
||||||
|
|
||||||
|
|||||||
@@ -71,34 +71,4 @@ namespace Spectrum
|
|||||||
detectionManager = new DetectionManager(renderer);
|
detectionManager = new DetectionManager(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class SystemHelper
|
|
||||||
{
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern int GetSystemMetrics(int nIndex);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
public static extern short GetAsyncKeyState(int vKey);
|
|
||||||
|
|
||||||
private const int SM_CXSCREEN = 0;
|
|
||||||
private const int SM_CYSCREEN = 1;
|
|
||||||
private const int SM_XVIRTUALSCREEN = 76;
|
|
||||||
private const int SM_YVIRTUALSCREEN = 77;
|
|
||||||
private const int SM_CXVIRTUALSCREEN = 78;
|
|
||||||
private const int SM_CYVIRTUALSCREEN = 79;
|
|
||||||
|
|
||||||
public static (int Width, int Height) GetPrimaryScreenSize()
|
|
||||||
{
|
|
||||||
return (GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (int X, int Y, int Width, int Height) GetVirtualScreenBounds()
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
GetSystemMetrics(SM_XVIRTUALSCREEN),
|
|
||||||
GetSystemMetrics(SM_YVIRTUALSCREEN),
|
|
||||||
GetSystemMetrics(SM_CXVIRTUALSCREEN),
|
|
||||||
GetSystemMetrics(SM_CYVIRTUALSCREEN)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+50
-5
@@ -13,7 +13,7 @@ namespace Spectrum
|
|||||||
{
|
{
|
||||||
partial class Renderer : Overlay
|
partial class Renderer : Overlay
|
||||||
{
|
{
|
||||||
static (int width, int height) screenSize = SystemHelper.GetPrimaryScreenSize();
|
static (int width, int height) screenSize = Win32.GetPrimaryScreenSize();
|
||||||
private List<Action<ImDrawListPtr>> detectionDrawCommands = new List<Action<ImDrawListPtr>>();
|
private List<Action<ImDrawListPtr>> detectionDrawCommands = new List<Action<ImDrawListPtr>>();
|
||||||
private List<Action<ImDrawListPtr>> activeDrawCommands = new List<Action<ImDrawListPtr>>();
|
private List<Action<ImDrawListPtr>> activeDrawCommands = new List<Action<ImDrawListPtr>>();
|
||||||
private readonly object detectionDrawLock = new object();
|
private readonly object detectionDrawLock = new object();
|
||||||
@@ -191,17 +191,27 @@ namespace Spectrum
|
|||||||
|
|
||||||
if (triggerBot)
|
if (triggerBot)
|
||||||
{
|
{
|
||||||
|
bool BoundingBoxOnly = config.TriggerInBoundsOnly;
|
||||||
|
bool TriggerSpray = config.TriggerSpray;
|
||||||
|
|
||||||
int triggerDelay = config.TriggerDelay;
|
int triggerDelay = config.TriggerDelay;
|
||||||
if (ImGuiExtensions.SliderFill("Trigger Delay (ms)", ref triggerDelay, 1, 1000))
|
if (ImGuiExtensions.SliderFill("Trigger Delay (ms)", ref triggerDelay, 1, 1000))
|
||||||
config.TriggerDelay = triggerDelay;
|
config.TriggerDelay = triggerDelay;
|
||||||
|
|
||||||
int triggerFov = config.TriggerFov;
|
if (TriggerSpray)
|
||||||
if (ImGuiExtensions.SliderFill("Trigger FOV (px)", ref triggerFov, 1, 100))
|
ImGui.BeginDisabled();
|
||||||
config.TriggerFov = triggerFov;
|
|
||||||
|
|
||||||
int triggerDuration = config.TriggerDuration;
|
int triggerDuration = config.TriggerDuration;
|
||||||
if (ImGuiExtensions.SliderFill("Trigger Duration (ms)", ref triggerDuration, 1, 1000))
|
if (ImGuiExtensions.SliderFill("Trigger Duration (ms)", ref triggerDuration, 1, 1000))
|
||||||
config.TriggerDuration = triggerDuration;
|
config.TriggerDuration = triggerDuration;
|
||||||
|
if (TriggerSpray)
|
||||||
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
|
if (BoundingBoxOnly)
|
||||||
|
ImGui.BeginDisabled();
|
||||||
|
|
||||||
|
int triggerFov = config.TriggerFov;
|
||||||
|
if (ImGuiExtensions.SliderFill("Trigger FOV (px)", ref triggerFov, 1, 100))
|
||||||
|
config.TriggerFov = triggerFov;
|
||||||
|
|
||||||
bool DrawTriggerFov = config.DrawTriggerFov;
|
bool DrawTriggerFov = config.DrawTriggerFov;
|
||||||
if (ImGui.Checkbox("##Draw Trigger FOV", ref DrawTriggerFov))
|
if (ImGui.Checkbox("##Draw Trigger FOV", ref DrawTriggerFov))
|
||||||
@@ -213,6 +223,31 @@ namespace Spectrum
|
|||||||
if (ImGui.ColorEdit4("Trigger Color", ref RadiusColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
if (ImGui.ColorEdit4("Trigger Color", ref RadiusColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
||||||
config.TriggerRadiusColor = RadiusColor;
|
config.TriggerRadiusColor = RadiusColor;
|
||||||
|
|
||||||
|
if (BoundingBoxOnly)
|
||||||
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
|
bool RandomDelay = config.TriggerRandomDelay;
|
||||||
|
if (ImGui.Checkbox(" Random Delay", ref RandomDelay))
|
||||||
|
config.TriggerRandomDelay = RandomDelay;
|
||||||
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.None))
|
||||||
|
ImGui.SetTooltip("Randomizes the trigger delay between 10 and the set Trigger Delay.");
|
||||||
|
|
||||||
|
if (TriggerSpray)
|
||||||
|
ImGui.BeginDisabled();
|
||||||
|
|
||||||
|
bool RandomDuration = config.TriggerRandomDuration;
|
||||||
|
if (ImGui.Checkbox(" Random Duration", ref RandomDuration))
|
||||||
|
config.TriggerRandomDuration = RandomDuration;
|
||||||
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.None))
|
||||||
|
ImGui.SetTooltip("Randomizes the trigger duration between 20 and the set Trigger Duration.");
|
||||||
|
|
||||||
|
if (TriggerSpray)
|
||||||
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
|
if (ImGui.Checkbox(" Trigger Spray", ref TriggerSpray))
|
||||||
|
config.TriggerSpray = TriggerSpray;
|
||||||
|
if (ImGui.Checkbox(" Bounding Box Only", ref BoundingBoxOnly))
|
||||||
|
config.TriggerInBoundsOnly = BoundingBoxOnly;
|
||||||
}
|
}
|
||||||
ImGuiExtensions.EndPane();
|
ImGuiExtensions.EndPane();
|
||||||
}
|
}
|
||||||
@@ -636,6 +671,16 @@ namespace Spectrum
|
|||||||
if (ImGuiExtensions.SliderFill("FPS Limit", ref _fpsLimit, 30, 480))
|
if (ImGuiExtensions.SliderFill("FPS Limit", ref _fpsLimit, 30, 480))
|
||||||
FPSLimit = _fpsLimit;
|
FPSLimit = _fpsLimit;
|
||||||
|
|
||||||
|
bool AntiCapture = config.AntiCapture;
|
||||||
|
if (ImGui.Checkbox("Anti-Capture", ref AntiCapture))
|
||||||
|
{
|
||||||
|
config.AntiCapture = AntiCapture;
|
||||||
|
if (AntiCapture)
|
||||||
|
Win32.EnableAntiCapture(window.Handle);
|
||||||
|
else
|
||||||
|
Win32.DisableAntiCapture(window.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.TextUnformatted("Background Image Interval");
|
ImGui.TextUnformatted("Background Image Interval");
|
||||||
ImGui.SetNextItemWidth(-1);
|
ImGui.SetNextItemWidth(-1);
|
||||||
int BackgroundImageInterval = config.BackgroundImageInterval;
|
int BackgroundImageInterval = config.BackgroundImageInterval;
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Spectrum
|
||||||
|
{
|
||||||
|
class Win32
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int GetSystemMetrics(int nIndex);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern short GetAsyncKeyState(int vKey);
|
||||||
|
|
||||||
|
private const int SM_CXSCREEN = 0;
|
||||||
|
private const int SM_CYSCREEN = 1;
|
||||||
|
private const int SM_XVIRTUALSCREEN = 76;
|
||||||
|
private const int SM_YVIRTUALSCREEN = 77;
|
||||||
|
private const int SM_CXVIRTUALSCREEN = 78;
|
||||||
|
private const int SM_CYVIRTUALSCREEN = 79;
|
||||||
|
|
||||||
|
public static (int Width, int Height) GetPrimaryScreenSize()
|
||||||
|
{
|
||||||
|
return (GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (int X, int Y, int Width, int Height) GetVirtualScreenBounds()
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
GetSystemMetrics(SM_XVIRTUALSCREEN),
|
||||||
|
GetSystemMetrics(SM_YVIRTUALSCREEN),
|
||||||
|
GetSystemMetrics(SM_CXVIRTUALSCREEN),
|
||||||
|
GetSystemMetrics(SM_CYVIRTUALSCREEN)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);
|
||||||
|
|
||||||
|
private const uint WDA_NONE = 0x00000000;
|
||||||
|
private const uint WDA_MONITOR = 0x00000001;
|
||||||
|
private const uint WDA_EXCLUDEFROMCAPTURE = 0x00000011;
|
||||||
|
|
||||||
|
public static bool EnableAntiCapture(IntPtr windowHandle)
|
||||||
|
{
|
||||||
|
return SetWindowDisplayAffinity(windowHandle, WDA_EXCLUDEFROMCAPTURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool DisableAntiCapture(IntPtr windowHandle)
|
||||||
|
{
|
||||||
|
return SetWindowDisplayAffinity(windowHandle, WDA_NONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user