feat(config): add TriggerBot and DebugMode properties

- Added `TriggerBot` and `DebugMode` properties to the `Config` class.
- Introduced performance tracking with `iterationCount`, `totalTime`, and `stopwatch` in `Program.cs`.
- Modified key state check to restart the stopwatch for accurate timing.
- Adjusted contour area threshold from `100` to `50` for better processing.
- Implemented logging for iterations and average FPS when `DebugMode` is enabled.
- Added UI checkbox in the `Renderer` class to toggle `DebugMode`.
This commit is contained in:
whoswhip
2025-07-19 07:57:48 -04:00
parent d8a71f9d91
commit 0fbc91fde4
3 changed files with 32 additions and 2 deletions
+4
View File
@@ -115,6 +115,7 @@ namespace Spectrum
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 bool TriggerBot { get; set; } = false;
// Display settings // Display settings
public bool ShowDetectionWindow { get; set; } = true; public bool ShowDetectionWindow { get; set; } = true;
@@ -134,6 +135,9 @@ namespace Spectrum
public Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229); public Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229);
public Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229); public Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229);
public string SelectedColor { get; set; } = "Arsenal [Magenta]"; public string SelectedColor { get; set; } = "Arsenal [Magenta]";
// Misc
public bool DebugMode { get; set; } = false;
} }
public class ColorData public class ColorData
{ {
+22 -1
View File
@@ -1,4 +1,5 @@
using OpenCvSharp; using OpenCvSharp;
using System.Diagnostics;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -11,8 +12,13 @@ namespace Spectrum
private static DateTime lastMenuToggle = DateTime.MinValue; private static DateTime lastMenuToggle = DateTime.MinValue;
public static ConfigManager<ConfigData> mainConfig = new ConfigManager<ConfigData>("bin\\configs\\config.json"); public static ConfigManager<ConfigData> mainConfig = new ConfigManager<ConfigData>("bin\\configs\\config.json");
public static ConfigManager<ColorData> colorConfig = new ConfigManager<ColorData>("bin\\configs\\colors.json"); public static ConfigManager<ColorData> colorConfig = new ConfigManager<ColorData>("bin\\configs\\colors.json");
public static long iterationCount = 0;
public static long totalTime = 0;
private static Stopwatch stopwatch = new Stopwatch();
static void Main() static void Main()
{ {
Thread renderThread = new Thread(() => Thread renderThread = new Thread(() =>
{ {
try try
@@ -62,6 +68,7 @@ namespace Spectrum
{ {
if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.Keybind) < 0) if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.Keybind) < 0)
{ {
stopwatch.Restart();
bounds = new Rectangle( bounds = new Rectangle(
(screenSize.Width - mainConfig.Data.ImageWidth) / 2, (screenSize.Width - mainConfig.Data.ImageWidth) / 2,
(screenSize.Height - mainConfig.Data.ImageHeight) / 2, (screenSize.Height - mainConfig.Data.ImageHeight) / 2,
@@ -78,7 +85,7 @@ namespace Spectrum
Cv2.FindContours(mat, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple); Cv2.FindContours(mat, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
var filteredContours = contours.Where(c => Cv2.ContourArea(c) >= 100).ToArray(); var filteredContours = contours.Where(c => Cv2.ContourArea(c) >= 50).ToArray();
var mergedContours = MergeOverlappingContours(filteredContours); var mergedContours = MergeOverlappingContours(filteredContours);
@@ -161,6 +168,11 @@ namespace Spectrum
Cv2.WaitKey(1); Cv2.WaitKey(1);
} }
} }
if (mainConfig.Data.DebugMode)
{
iterationCount++;
totalTime += stopwatch.ElapsedMilliseconds;
}
} }
else if (mainConfig.Data.ShowDetectionWindow || mainConfig.Data.CollectData) else if (mainConfig.Data.ShowDetectionWindow || mainConfig.Data.CollectData)
{ {
@@ -172,6 +184,15 @@ namespace Spectrum
screenshot?.Dispose(); screenshot?.Dispose();
mat.Dispose(); mat.Dispose();
drawing.Dispose(); drawing.Dispose();
if (iterationCount >= 1000 && mainConfig.Data.DebugMode)
{
LogManager.Log($"Processed {iterationCount} iterations in {totalTime} ms.", LogManager.LogLevel.Info);
int fps = (int)(iterationCount * 1000 / totalTime);
LogManager.Log($"Average FPS: {fps}", LogManager.LogLevel.Info);
iterationCount = 0;
totalTime = 0;
}
} }
else if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.MenuKey) < 0) else if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.MenuKey) < 0)
{ {
+6 -1
View File
@@ -2,7 +2,6 @@
using ImGuiNET; using ImGuiNET;
using OpenCvSharp; using OpenCvSharp;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics; using System.Diagnostics;
using System.Numerics; using System.Numerics;
@@ -310,6 +309,12 @@ namespace Spectrum
VSync = _vsync; VSync = _vsync;
} }
bool DebugMode = mainConfig.Data.DebugMode;
if (ImGui.Checkbox("Debug Mode", ref DebugMode))
{
mainConfig.Data.DebugMode = DebugMode;
}
if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d")) if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d"))
{ {
FPSLimit = _fpsLimit; FPSLimit = _fpsLimit;