From 0fbc91fde47a8aa226031a4d459cafc46ecf0ece Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 19 Jul 2025 07:57:48 -0400 Subject: [PATCH] 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`. --- Spectrum/Config.cs | 4 ++++ Spectrum/Program.cs | 23 ++++++++++++++++++++++- Spectrum/Renderer.cs | 7 ++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Spectrum/Config.cs b/Spectrum/Config.cs index a9d288a..693bf96 100644 --- a/Spectrum/Config.cs +++ b/Spectrum/Config.cs @@ -115,6 +115,7 @@ namespace Spectrum public MovementType AimMovementType { get; set; } = MovementType.Adaptive; public bool EmaSmoothening { get; set; } = true; public double EmaSmootheningFactor { get; set; } = 0.1; + public bool TriggerBot { get; set; } = false; // Display settings public bool ShowDetectionWindow { get; set; } = true; @@ -134,6 +135,9 @@ namespace Spectrum public Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229); public Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229); public string SelectedColor { get; set; } = "Arsenal [Magenta]"; + + // Misc + public bool DebugMode { get; set; } = false; } public class ColorData { diff --git a/Spectrum/Program.cs b/Spectrum/Program.cs index 6170e80..5f3877e 100644 --- a/Spectrum/Program.cs +++ b/Spectrum/Program.cs @@ -1,4 +1,5 @@ using OpenCvSharp; +using System.Diagnostics; using System.Drawing.Imaging; using System.Runtime.InteropServices; @@ -11,8 +12,13 @@ namespace Spectrum private static DateTime lastMenuToggle = DateTime.MinValue; public static ConfigManager mainConfig = new ConfigManager("bin\\configs\\config.json"); public static ConfigManager colorConfig = new ConfigManager("bin\\configs\\colors.json"); + public static long iterationCount = 0; + public static long totalTime = 0; + private static Stopwatch stopwatch = new Stopwatch(); + static void Main() { + Thread renderThread = new Thread(() => { try @@ -62,6 +68,7 @@ namespace Spectrum { if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.Keybind) < 0) { + stopwatch.Restart(); bounds = new Rectangle( (screenSize.Width - mainConfig.Data.ImageWidth) / 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); - var filteredContours = contours.Where(c => Cv2.ContourArea(c) >= 100).ToArray(); + var filteredContours = contours.Where(c => Cv2.ContourArea(c) >= 50).ToArray(); var mergedContours = MergeOverlappingContours(filteredContours); @@ -161,6 +168,11 @@ namespace Spectrum Cv2.WaitKey(1); } } + if (mainConfig.Data.DebugMode) + { + iterationCount++; + totalTime += stopwatch.ElapsedMilliseconds; + } } else if (mainConfig.Data.ShowDetectionWindow || mainConfig.Data.CollectData) { @@ -172,6 +184,15 @@ namespace Spectrum screenshot?.Dispose(); mat.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) { diff --git a/Spectrum/Renderer.cs b/Spectrum/Renderer.cs index d2bf435..f5315c5 100644 --- a/Spectrum/Renderer.cs +++ b/Spectrum/Renderer.cs @@ -2,7 +2,6 @@ using ImGuiNET; using OpenCvSharp; using System.Collections.Concurrent; -using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Numerics; @@ -310,6 +309,12 @@ namespace Spectrum 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")) { FPSLimit = _fpsLimit;