mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
all of these changes were done MONTHS ago, but i'll try to list them out: - simplified input library switching & implementation - implemented makcu binary, which is their new communication, have NOT tested - renamed existing makcu implementation to makcuLegacy since they've changed their communication format - overall simplification of code - formatted code via csharpier - minimal optimizations
1263 lines
60 KiB
C#
1263 lines
60 KiB
C#
using ClickableTransparentOverlay;
|
|
using ImGuiNET;
|
|
using OpenCvSharp;
|
|
using SixLabors.ImageSharp;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using Spectrum.Detection;
|
|
using Spectrum.Input;
|
|
using Spectrum.Input.InputLibraries;
|
|
using Spectrum.Utilities;
|
|
using System.Collections.Concurrent;
|
|
using System.Diagnostics;
|
|
using System.Numerics;
|
|
|
|
namespace Spectrum
|
|
{
|
|
partial class Renderer : Overlay
|
|
{
|
|
static (int width, int height) screenSize = (0, 0);
|
|
private List<Action<ImDrawListPtr>> detectionDrawCommands = [];
|
|
private List<Action<ImDrawListPtr>> activeDrawCommands = [];
|
|
private readonly object detectionDrawLock = new();
|
|
private readonly CaptureManager _captureManager;
|
|
|
|
private bool _vsync = true;
|
|
private int _fpsLimit = 240;
|
|
private readonly Dictionary<string, bool> _waitingForKeybind = [];
|
|
private readonly Dictionary<string, Keys> _pendingKeybind = [];
|
|
private readonly Dictionary<string, Task?> _keybindTask = [];
|
|
private readonly ConcurrentQueue<Keys> _keybindResults = new();
|
|
private readonly ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
|
private readonly ColorConfigManager colorConfig = Program.colorConfig;
|
|
private string ColorName = "New Color";
|
|
private static bool scrollToBottom = true;
|
|
private ColorInfo? selectedColor = null;
|
|
private int _colorConfigVersion = -1;
|
|
private string configName = "New Config";
|
|
private string? selectedConfigName = null;
|
|
private bool _windowPositioned = false;
|
|
private Image<Rgba32>? _copyIconImage = null;
|
|
private IntPtr _copyIconTextureId = IntPtr.Zero;
|
|
private readonly InputLibraryManager _inputManager = Program.InputLibraryManager;
|
|
|
|
private static Vector2 ToOverlay(Vector2 point)
|
|
{
|
|
var bounds = Program.MonitorBounds;
|
|
return new Vector2(point.X - bounds.X, point.Y - bounds.Y);
|
|
}
|
|
|
|
private static string? ResolveAssetPath(string fileName)
|
|
{
|
|
string basePath = AppContext.BaseDirectory;
|
|
string basePathCandidate = Path.Combine(basePath, fileName);
|
|
if (File.Exists(basePathCandidate))
|
|
return basePathCandidate;
|
|
string cwdCandidate = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
|
if (File.Exists(cwdCandidate))
|
|
return cwdCandidate;
|
|
return null;
|
|
}
|
|
|
|
private bool TryLoadImageTexture(string key, string fileName, ref Image<Rgba32>? image, ref IntPtr textureId)
|
|
{
|
|
if (textureId != IntPtr.Zero)
|
|
return true;
|
|
|
|
string? imagePath = ResolveAssetPath(fileName);
|
|
if (string.IsNullOrEmpty(imagePath))
|
|
return false;
|
|
|
|
image?.Dispose();
|
|
image = SixLabors.ImageSharp.Image.Load<Rgba32>(imagePath);
|
|
AddOrGetImagePointer(key, image, false, out textureId);
|
|
return textureId != IntPtr.Zero;
|
|
}
|
|
|
|
public Renderer(CaptureManager captureManager) : base("Spectrum", Program.MonitorBounds.Width, Program.MonitorBounds.Height)
|
|
{
|
|
screenSize = (Program.MonitorBounds.Width, Program.MonitorBounds.Height);
|
|
_captureManager = captureManager;
|
|
VSync = _vsync;
|
|
FPSLimit = _fpsLimit;
|
|
|
|
ImGui.CreateContext();
|
|
|
|
var io = ImGui.GetIO();
|
|
io.Fonts.Clear();
|
|
io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\Arial.ttf", 16.0f);
|
|
|
|
var bounds = Program.MonitorBounds;
|
|
if (window != null)
|
|
Win32.SetWindowBounds(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
|
|
|
LogManager.Log($"Renderer monitor bounds: {bounds.X},{bounds.Y} {bounds.Width}x{bounds.Height}", LogManager.LogLevel.Debug);
|
|
LogManager.Log($"Renderer screen size: {screenSize.width}x{screenSize.height}", LogManager.LogLevel.Debug);
|
|
|
|
}
|
|
override protected void Render()
|
|
{
|
|
if (!_windowPositioned && window != null)
|
|
{
|
|
var bounds = Program.MonitorBounds;
|
|
Win32.SetWindowBounds(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
|
screenSize = (bounds.Width, bounds.Height);
|
|
_windowPositioned = true;
|
|
LogManager.Log($"Renderer window positioned: {bounds.X},{bounds.Y} {bounds.Width}x{bounds.Height}", LogManager.LogLevel.Debug);
|
|
}
|
|
var config = mainConfig.Data;
|
|
if (config.DrawDetections || config.DrawCaptureFov || config.DebugMode || config.DrawAimPoint)
|
|
RenderOverlay();
|
|
if (!config.ShowMenu)
|
|
return;
|
|
|
|
AddStyling();
|
|
|
|
ImGui.SetNextWindowSize(new Vector2(700, 500), ImGuiCond.FirstUseEver);
|
|
ImGui.SetNextWindowPos(new Vector2(screenSize.width / 2 - 350, screenSize.height / 2 - 250), ImGuiCond.FirstUseEver);
|
|
ImGui.SetNextWindowSizeConstraints(new Vector2(700, 500), new Vector2(float.MaxValue, float.MaxValue));
|
|
|
|
ImGui.Begin("Spectrum", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar);
|
|
ImGui.Text("Spectrum");
|
|
ImGui.SameLine();
|
|
float currentWidth = ImGui.GetWindowWidth();
|
|
ImGui.SetCursorPosX(currentWidth - 30);
|
|
if (ImGui.Button("X", new Vector2(22, 22)))
|
|
{
|
|
Close();
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
int ImageWidth = config.ImageWidth;
|
|
int ImageHeight = config.ImageHeight;
|
|
|
|
ImGui.BeginTabBar("##tabs");
|
|
if (ImGui.BeginTabItem("Aiming"))
|
|
{
|
|
ImGuiExtensions.BeginPaneGroup("Aiming Panes", 2, 12f, new Vector2(12, 10), ImGuiChildFlags.AlwaysUseWindowPadding, ImGuiWindowFlags.None, 0f);
|
|
|
|
if (ImGuiExtensions.BeginPane("Aim Assist"))
|
|
{
|
|
bool enableAiming = config.EnableAim;
|
|
if (ImGui.Checkbox("##Enable Aiming", ref enableAiming))
|
|
config.EnableAim = enableAiming;
|
|
|
|
ImGui.SameLine();
|
|
ImGui.TextUnformatted("Enable Aiming");
|
|
ImGuiExtensions.KeybindInput("Aim Keybind", ref config.Keybind, true);
|
|
|
|
bool closestToMouse = config.ClosestToMouse;
|
|
if (ImGui.Checkbox(" Closest to Mouse", ref closestToMouse))
|
|
config.ClosestToMouse = closestToMouse;
|
|
|
|
bool enableAimFov = config.EnableAimFov;
|
|
if (ImGui.Checkbox(" Enable Aim Fov", ref enableAimFov))
|
|
config.EnableAimFov = enableAimFov;
|
|
|
|
if (enableAimFov)
|
|
{
|
|
bool drawAimFov = config.DrawAimFov;
|
|
if (ImGui.Checkbox(" Draw Aim FOV", ref drawAimFov))
|
|
config.DrawAimFov = drawAimFov;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 11);
|
|
|
|
Vector4 aimFovColor = config.AimFovColor;
|
|
if (ImGui.ColorEdit4("Aim FOV Color", ref aimFovColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.AimFovColor = aimFovColor;
|
|
|
|
int aimFovWidth = config.AimFovWidth;
|
|
int aimFovHeight = config.AimFovHeight;
|
|
FovType aimFovType = config.AimFovType;
|
|
ImGui.TextUnformatted("Aim FOV Type");
|
|
ImGui.SetNextItemWidth(-1);
|
|
if (ImGui.BeginCombo("##Aim FOV Type", aimFovType.ToString()))
|
|
{
|
|
foreach (FovType type in Enum.GetValues(typeof(FovType)))
|
|
{
|
|
bool isSelected = (type == aimFovType);
|
|
if (ImGui.Selectable(type.ToString(), isSelected))
|
|
config.AimFovType = type;
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
|
|
if (aimFovType == FovType.Circle)
|
|
{
|
|
int aimFovRadius = Math.Min(aimFovWidth, aimFovHeight) / 2;
|
|
if (ImGuiExtensions.SliderFill("Aim FOV Radius (px)", ref aimFovRadius, 1, Math.Min(ImageWidth, ImageHeight) / 2))
|
|
{
|
|
aimFovWidth = aimFovRadius * 2;
|
|
aimFovHeight = aimFovRadius * 2;
|
|
config.AimFovWidth = aimFovWidth;
|
|
config.AimFovHeight = aimFovHeight;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ImGuiExtensions.SliderFill("Aim FOV Width (px)", ref aimFovWidth, 1, ImageWidth))
|
|
config.AimFovWidth = aimFovWidth;
|
|
if (ImGuiExtensions.SliderFill("Aim FOV Height (px)", ref aimFovHeight, 1, ImageHeight))
|
|
config.AimFovHeight = aimFovHeight;
|
|
}
|
|
}
|
|
|
|
float sensitivity = (float)config.Sensitivity;
|
|
if (ImGuiExtensions.SliderFill("Sensitivity", ref sensitivity, 0.1f, 2.0f, "%.1f", false))
|
|
config.Sensitivity = Math.Clamp(sensitivity, 0.1, float.MaxValue);
|
|
|
|
float EmaSmootheningFactor = (float)config.EmaSmootheningFactor;
|
|
bool EmaSmoothening = config.EmaSmoothening;
|
|
if (ImGui.Checkbox("Ema Smoothening", ref EmaSmoothening))
|
|
config.EmaSmoothening = EmaSmoothening;
|
|
|
|
if (EmaSmoothening)
|
|
{
|
|
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 Path");
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 9);
|
|
if (ImGui.Button(_showMovementPreview ? "X" : "?", new Vector2(20, 20)))
|
|
_showMovementPreview = !_showMovementPreview;
|
|
ImGui.SetNextItemWidth(-1);
|
|
MovementType AimPath = config.AimMovementType;
|
|
if (ImGui.BeginCombo("##Movement Type", FormatText(AimPath.ToString())))
|
|
{
|
|
foreach (MovementType type in Enum.GetValues(typeof(MovementType)))
|
|
{
|
|
bool isSelected = (type == AimPath);
|
|
if (ImGui.Selectable(FormatText(type.ToString()), isSelected))
|
|
config.AimMovementType = type;
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
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;
|
|
if (ImGui.Checkbox("Pixel Based Offset (Y)", ref YPixelOffset))
|
|
config.YPixelOffset = YPixelOffset;
|
|
bool XPixelOffset = config.XPixelOffset;
|
|
if (ImGui.Checkbox("Pixel Based Offset (X)", ref XPixelOffset))
|
|
config.XPixelOffset = XPixelOffset;
|
|
|
|
if (!YPixelOffset)
|
|
{
|
|
float YOffset = (int)(config.YOffsetPercent * 100);
|
|
if (ImGuiExtensions.SliderFill("Y Offset (%)", ref YOffset, 0, 100, "%d%%"))
|
|
{
|
|
config.YOffsetPercent = ((double)YOffset / 100);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int YOffset = config.YOffsetPixels;
|
|
if (ImGuiExtensions.SliderFill("Y Offset (px)", ref YOffset, -200, 200))
|
|
config.YOffsetPixels = Math.Max(-200, YOffset);
|
|
}
|
|
|
|
if (!XPixelOffset)
|
|
{
|
|
float XOffset = (int)(config.XOffsetPercent * 100);
|
|
if (ImGuiExtensions.SliderFill("X Offset (%)", ref XOffset, 0, 100, "%d%%"))
|
|
{
|
|
config.XOffsetPercent = ((double)XOffset / 100);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int XOffset = config.XOffsetPixels;
|
|
if (ImGuiExtensions.SliderFill("X Offset (px)", ref XOffset, -200, 200))
|
|
config.XOffsetPixels = Math.Max(-200, XOffset);
|
|
}
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
if (ImGuiExtensions.BeginPane("Triggerbot"))
|
|
{
|
|
bool triggerBot = config.TriggerBot;
|
|
if (ImGui.Checkbox(" Enabled", ref triggerBot))
|
|
config.TriggerBot = triggerBot;
|
|
ImGuiExtensions.KeybindInput("Trigger Keybind", ref config.TriggerKeybind, true);
|
|
|
|
if (triggerBot)
|
|
{
|
|
bool BoundingBoxOnly = config.TriggerInBoundsOnly;
|
|
bool TriggerSpray = config.TriggerSpray;
|
|
|
|
int triggerDelay = config.TriggerDelay;
|
|
if (ImGuiExtensions.SliderFill("Trigger Delay (ms)", ref triggerDelay, 1, 1000))
|
|
config.TriggerDelay = triggerDelay;
|
|
|
|
if (TriggerSpray)
|
|
ImGui.BeginDisabled();
|
|
int triggerDuration = config.TriggerDuration;
|
|
if (ImGuiExtensions.SliderFill("Trigger Duration (ms)", ref triggerDuration, 1, 1000))
|
|
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;
|
|
if (ImGui.Checkbox("##Draw Trigger FOV", ref DrawTriggerFov))
|
|
config.DrawTriggerFov = DrawTriggerFov;
|
|
ImGui.SameLine();
|
|
ImGui.TextUnformatted("Draw Trigger FOV");
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 12);
|
|
Vector4 RadiusColor = config.TriggerRadiusColor;
|
|
if (ImGui.ColorEdit4("Trigger Color", ref RadiusColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.TriggerRadiusColor = RadiusColor;
|
|
|
|
if (BoundingBoxOnly)
|
|
ImGui.EndDisabled();
|
|
|
|
bool RandomDelay = config.TriggerRandomDelay;
|
|
if (ImGui.Checkbox(" Random Delay", ref RandomDelay))
|
|
config.TriggerRandomDelay = RandomDelay;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 10);
|
|
ImGui.TextDisabled("(?)");
|
|
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;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 10);
|
|
ImGui.TextDisabled("(?)");
|
|
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;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 10);
|
|
ImGui.TextDisabled("(?)");
|
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.None))
|
|
ImGui.SetTooltip("Only triggers when the detected object is within the bounding box.");
|
|
}
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
ImGuiExtensions.EndPaneGroup();
|
|
|
|
ImGui.EndTabItem();
|
|
}
|
|
|
|
if (ImGui.BeginTabItem("Overlay"))
|
|
{
|
|
ImGuiExtensions.BeginPaneGroup("Overlay Panes", 1, 12f, new Vector2(12, 10), ImGuiChildFlags.AlwaysUseWindowPadding, ImGuiWindowFlags.None, 0f);
|
|
if (ImGuiExtensions.BeginPane("Overlay"))
|
|
{
|
|
bool DrawFOV = config.DrawCaptureFov;
|
|
if (ImGui.Checkbox(" Draw FOV", ref DrawFOV))
|
|
config.DrawCaptureFov = DrawFOV;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 11);
|
|
Vector4 FOVColor = config.CaptureFOVColor;
|
|
if (ImGui.ColorEdit4("FOV Color", ref FOVColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.CaptureFOVColor = FOVColor;
|
|
|
|
bool DrawDetections = config.DrawDetections;
|
|
if (ImGui.Checkbox(" Draw Detections", ref DrawDetections))
|
|
config.DrawDetections = DrawDetections;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 11);
|
|
Vector4 DetectionColor = config.DetectionColor;
|
|
if (ImGui.ColorEdit4("Draw Color", ref DetectionColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.DetectionColor = DetectionColor;
|
|
if (DrawDetections)
|
|
{
|
|
bool HighlightTarget = config.HighlightTarget;
|
|
if (ImGui.Checkbox(" Highlight Target", ref HighlightTarget))
|
|
config.HighlightTarget = HighlightTarget;
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 11);
|
|
Vector4 HighlightColor = config.TargetColor;
|
|
if (ImGui.ColorEdit4("Highlight Color", ref HighlightColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.TargetColor = HighlightColor;
|
|
}
|
|
|
|
bool DrawAimPoint = config.DrawAimPoint;
|
|
if (ImGui.Checkbox(" Draw Aim Point", ref DrawAimPoint))
|
|
config.DrawAimPoint = DrawAimPoint;
|
|
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 11);
|
|
|
|
Vector4 AimPointColor = config.AimPointColor;
|
|
if (ImGui.ColorEdit4("Aim Point Color", ref AimPointColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
|
config.AimPointColor = AimPointColor;
|
|
|
|
if (DrawFOV)
|
|
{
|
|
ImGui.TextUnformatted("FOV Type");
|
|
ImGui.SetNextItemWidth(-1);
|
|
FovType fovType = config.CaptureFOVType;
|
|
if (ImGui.BeginCombo("##FOV Type", fovType.ToString()))
|
|
{
|
|
foreach (FovType type in Enum.GetValues(typeof(FovType)))
|
|
{
|
|
bool isSelected = (type == fovType);
|
|
if (ImGui.Selectable(type.ToString(), isSelected))
|
|
config.CaptureFOVType = type;
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
}
|
|
if (DrawAimPoint)
|
|
{
|
|
AimpointType aimpointType = config.AimPointType;
|
|
ImGui.TextUnformatted("Aimpoint Type");
|
|
ImGui.SetNextItemWidth(-1);
|
|
if (ImGui.BeginCombo("##Aimpoint Type", aimpointType.ToString()))
|
|
{
|
|
foreach (AimpointType type in Enum.GetValues(typeof(AimpointType)))
|
|
{
|
|
bool isSelected = (type == aimpointType);
|
|
if (ImGui.Selectable(type.ToString(), isSelected))
|
|
config.AimPointType = type;
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
}
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
ImGuiExtensions.EndPaneGroup();
|
|
ImGui.EndTabItem();
|
|
}
|
|
|
|
if (ImGui.BeginTabItem("Detection"))
|
|
{
|
|
ImGuiExtensions.BeginPaneGroup("Detection Panes", 2, 12f, new Vector2(12, 10), ImGuiChildFlags.AlwaysUseWindowPadding, ImGuiWindowFlags.None, 0f);
|
|
|
|
if (ImGuiExtensions.BeginPane("Detection Settings"))
|
|
{
|
|
ImGui.TextUnformatted("Image Width");
|
|
ImGui.SetNextItemWidth(-1);
|
|
|
|
if (ImGui.InputInt("##Image Width", ref ImageWidth, 1, screenSize.width))
|
|
{
|
|
if (ImageWidth < 1)
|
|
ImageWidth = 1;
|
|
else if (ImageWidth > screenSize.width)
|
|
ImageWidth = screenSize.width;
|
|
config.ImageWidth = ImageWidth;
|
|
}
|
|
|
|
ImGui.TextUnformatted("Image Height");
|
|
ImGui.SetNextItemWidth(-1);
|
|
|
|
if (ImGui.InputInt("##Image Height", ref ImageHeight, 1, screenSize.height))
|
|
{
|
|
if (ImageHeight < 1)
|
|
ImageHeight = 1;
|
|
else if (ImageHeight > screenSize.height)
|
|
ImageHeight = screenSize.height;
|
|
config.ImageHeight = ImageHeight;
|
|
}
|
|
|
|
ImGui.SetNextItemWidth(-1);
|
|
Scalar upperHSV = config.UpperHSV;
|
|
if (ImGuiExtensions.ColorEditHSV3("Upper HSV", ref upperHSV))
|
|
config.UpperHSV = upperHSV;
|
|
Scalar lowerHSV = config.LowerHSV;
|
|
if (ImGuiExtensions.ColorEditHSV3("Lower HSV", ref lowerHSV))
|
|
config.LowerHSV = lowerHSV;
|
|
|
|
int minAreaPx = config.MinAreaPx;
|
|
if (ImGuiExtensions.SliderFill("Min Area (px)", ref minAreaPx, 1, 10000))
|
|
config.MinAreaPx = minAreaPx;
|
|
|
|
if (ImGui.Button("Open HSV Range Selector"))
|
|
_showHSVRangeWindow = true;
|
|
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
if (ImGuiExtensions.BeginPane("Color Configs"))
|
|
{
|
|
if (colorConfig.Version != _colorConfigVersion)
|
|
{
|
|
_colorConfigVersion = colorConfig.Version;
|
|
if (!string.IsNullOrWhiteSpace(config.SelectedColor))
|
|
{
|
|
var updatedColor = colorConfig.GetColor(config.SelectedColor);
|
|
if (updatedColor != null)
|
|
{
|
|
selectedColor = updatedColor;
|
|
ColorName = updatedColor.Name;
|
|
config.UpperHSV = updatedColor.Upper;
|
|
config.LowerHSV = updatedColor.Lower;
|
|
}
|
|
}
|
|
}
|
|
|
|
List<ColorInfo> colors = [.. colorConfig.Colors];
|
|
if (selectedColor != null)
|
|
selectedColor = colors.Find(c => c.Name.Equals(selectedColor.Name, StringComparison.OrdinalIgnoreCase));
|
|
ImGui.PushStyleColor(ImGuiCol.ChildBg, new Vector4(0.110f, 0.110f, 0.125f, 1.000f));
|
|
ImGui.BeginChild("##DColorConfigsChild", new Vector2(0, ImGui.GetContentRegionAvail().Y / 2), ImGuiChildFlags.None);
|
|
ImGui.Dummy(new Vector2(0, 4));
|
|
foreach (var color in colors)
|
|
{
|
|
if (ImGui.Selectable(" " + color.Name, selectedColor != null && color.Name.Equals(selectedColor.Name, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
selectedColor = color;
|
|
ColorName = color.Name;
|
|
config.SelectedColor = selectedColor.Name;
|
|
}
|
|
}
|
|
ImGui.EndChild();
|
|
ImGui.PopStyleColor();
|
|
|
|
ImGui.SetNextItemWidth(-1);
|
|
ImGui.InputTextWithHint("##ColorName", "Color Name", ref ColorName, 100);
|
|
|
|
Vector2 size = new((ImGui.GetContentRegionAvail().X / 3) - 5.7f, 22);
|
|
if (ImGui.Button("Load Color", size))
|
|
{
|
|
if (selectedColor != null)
|
|
{
|
|
config.SelectedColor = selectedColor.Name;
|
|
config.UpperHSV = selectedColor.Upper;
|
|
config.LowerHSV = selectedColor.Lower;
|
|
ColorName = selectedColor.Name;
|
|
}
|
|
}
|
|
|
|
ImGui.SameLine();
|
|
if (ImGui.Button("Save Color", size))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(ColorName))
|
|
{
|
|
var colorToSave = new ColorInfo(ColorName, config.UpperHSV, config.LowerHSV);
|
|
if (colorConfig.SaveColor(colorToSave))
|
|
selectedColor = colorConfig.GetColor(ColorName);
|
|
}
|
|
}
|
|
ImGui.SameLine();
|
|
if (ImGui.Button("Delete Color", size))
|
|
{
|
|
if (selectedColor != null)
|
|
{
|
|
var deletedName = selectedColor.Name;
|
|
int currentIndex = colors.FindIndex(c => c.Name.Equals(deletedName, StringComparison.OrdinalIgnoreCase));
|
|
if (colorConfig.DeleteColor(deletedName))
|
|
{
|
|
colors = [.. colorConfig.Colors];
|
|
if (colors.Count > 0)
|
|
{
|
|
int nextIndex = Math.Clamp(currentIndex - 1, 0, colors.Count - 1);
|
|
selectedColor = colors[nextIndex];
|
|
config.SelectedColor = selectedColor.Name;
|
|
config.UpperHSV = selectedColor.Upper;
|
|
config.LowerHSV = selectedColor.Lower;
|
|
ColorName = selectedColor.Name;
|
|
}
|
|
else
|
|
{
|
|
selectedColor = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
|
|
ImGui.EndTabItem();
|
|
}
|
|
|
|
if (ImGui.BeginTabItem("Configs"))
|
|
{
|
|
ImGuiExtensions.BeginPaneGroup("Config Panes", 2, 12f, new Vector2(12, 10), ImGuiChildFlags.AlwaysUseWindowPadding, ImGuiWindowFlags.None, 0f);
|
|
|
|
if (ImGuiExtensions.BeginPane("Config Management"))
|
|
{
|
|
ImGui.TextUnformatted("Available Configs");
|
|
ImGui.PushStyleColor(ImGuiCol.ChildBg, new Vector4(0.110f, 0.110f, 0.125f, 1.000f));
|
|
ImGui.BeginChild("##ConfigListChild", new Vector2(0, ImGui.GetContentRegionAvail().Y / 2), ImGuiChildFlags.None);
|
|
ImGui.Dummy(new Vector2(0, 4));
|
|
|
|
var availableConfigs = mainConfig.AvailableConfigs;
|
|
foreach (var _config in availableConfigs)
|
|
{
|
|
if (ImGui.Selectable(" " + _config, selectedConfigName == _config))
|
|
{
|
|
selectedConfigName = _config;
|
|
configName = _config;
|
|
}
|
|
}
|
|
|
|
ImGui.EndChild();
|
|
ImGui.PopStyleColor();
|
|
|
|
ImGui.SetNextItemWidth(-1);
|
|
ImGui.InputTextWithHint("##ConfigName", "Config Name", ref configName, 100);
|
|
|
|
Vector2 size = new((ImGui.GetContentRegionAvail().X / 3) - 5.7f, 22);
|
|
|
|
if (ImGui.Button("Load Config", size))
|
|
{
|
|
if (!string.IsNullOrEmpty(selectedConfigName))
|
|
{
|
|
bool success = mainConfig.LoadConfigFromDirectory(selectedConfigName);
|
|
if (success)
|
|
configName = selectedConfigName;
|
|
}
|
|
}
|
|
|
|
ImGui.SameLine();
|
|
if (ImGui.Button("Save Config", size))
|
|
{
|
|
if (!string.IsNullOrEmpty(configName))
|
|
{
|
|
mainConfig.SaveConfigToDirectory(configName);
|
|
selectedConfigName = configName;
|
|
}
|
|
}
|
|
|
|
ImGui.SameLine();
|
|
if (ImGui.Button("Delete Config", size))
|
|
{
|
|
if (!string.IsNullOrEmpty(selectedConfigName))
|
|
{
|
|
bool success = mainConfig.DeleteConfigFromDirectory(selectedConfigName);
|
|
if (success)
|
|
{
|
|
selectedConfigName = null;
|
|
configName = "New Config";
|
|
}
|
|
}
|
|
}
|
|
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
if (ImGuiExtensions.BeginPane("Current Config"))
|
|
{
|
|
ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0.110f, 0.110f, 0.125f, 1.000f));
|
|
ImGui.SetNextItemWidth(-1);
|
|
string currentConfig = mainConfig.CurrentConfigName;
|
|
ImGui.InputText("##CurrentConfig", ref currentConfig, 256, ImGuiInputTextFlags.ReadOnly);
|
|
ImGui.PopStyleColor();
|
|
|
|
Vector2 fullSize = new(ImGui.GetContentRegionAvail().X, 22);
|
|
|
|
if (ImGui.Button("Save Current to Default", fullSize))
|
|
mainConfig.SaveConfig();
|
|
|
|
if (ImGui.Button("Save Current Config", fullSize))
|
|
if (!string.IsNullOrEmpty(configName))
|
|
mainConfig.SaveConfigToDirectory(configName);
|
|
|
|
if (ImGui.Button("Open Configs Folder", fullSize))
|
|
{
|
|
string configDir = Path.Combine(Directory.GetCurrentDirectory(), "bin", "configs");
|
|
if (Directory.Exists(configDir))
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = "explorer.exe",
|
|
Arguments = configDir,
|
|
UseShellExecute = true
|
|
});
|
|
}
|
|
else
|
|
{
|
|
LogManager.Log($"Directory doesn't exist: {configDir}", LogManager.LogLevel.Error);
|
|
}
|
|
}
|
|
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
ImGui.EndTabItem();
|
|
}
|
|
|
|
if (ImGui.BeginTabItem("Settings"))
|
|
{
|
|
ImGuiExtensions.BeginPaneGroup("Settings Panes", 2, 12f, new Vector2(12, 10), ImGuiChildFlags.AlwaysUseWindowPadding, ImGuiWindowFlags.None, 0f);
|
|
|
|
if (ImGuiExtensions.BeginPane("Settings"))
|
|
{
|
|
ImGui.TextUnformatted("Movement Method");
|
|
ImGui.SetNextItemWidth(-1);
|
|
InputLibraryType movementMethod = config.InputLibraryType;
|
|
if (ImGui.BeginCombo("##Movement Method", movementMethod != InputLibraryType.HID
|
|
? FormatText(movementMethod.ToString()) : movementMethod.ToString()))
|
|
{
|
|
foreach (InputLibraryType method in Enum.GetValues(typeof(InputLibraryType)))
|
|
{
|
|
bool isSelected = method == movementMethod;
|
|
if (ImGui.Selectable(method != InputLibraryType.HID ? FormatText(method.ToString()) : method.ToString(), isSelected))
|
|
{
|
|
config.InputLibraryType = method;
|
|
bool success = _inputManager.Switch(method);
|
|
if (!success)
|
|
config.InputLibraryType = _inputManager.CurrentType;
|
|
}
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
|
|
ImGui.TextUnformatted("Capture Method");
|
|
ImGui.SetNextItemWidth(-1);
|
|
CaptureMethod captureMethod = config.CaptureMethod;
|
|
if (ImGui.BeginCombo("##Capture Method", captureMethod.ToString()))
|
|
{
|
|
foreach (CaptureMethod method in Enum.GetValues(typeof(CaptureMethod)))
|
|
{
|
|
bool isSelected = (method == captureMethod);
|
|
if (ImGui.Selectable(method.ToString(), isSelected))
|
|
{
|
|
CaptureMethod _method = method;
|
|
if (method == CaptureMethod.DirectX)
|
|
{
|
|
bool dxOk = _captureManager.TryInitializeDirectX();
|
|
if (!dxOk)
|
|
{
|
|
LogManager.Log("DirectX capture failed to initialize. Falling back to GDI.", LogManager.LogLevel.Warning);
|
|
_method = CaptureMethod.GDI;
|
|
}
|
|
}
|
|
config.CaptureMethod = _method;
|
|
}
|
|
if (isSelected)
|
|
ImGui.SetItemDefaultFocus();
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
|
|
bool CollectData = config.CollectData;
|
|
if (ImGui.Checkbox("Collect Data", ref CollectData))
|
|
config.CollectData = CollectData;
|
|
|
|
bool AutoLabel = config.AutoLabel;
|
|
if (ImGui.Checkbox("Auto Label", ref AutoLabel))
|
|
{
|
|
if (!CollectData && AutoLabel)
|
|
config.CollectData = true;
|
|
|
|
config.AutoLabel = AutoLabel;
|
|
}
|
|
|
|
if (ImGui.Checkbox("VSync", ref _vsync))
|
|
VSync = _vsync;
|
|
|
|
bool DebugMode = config.DebugMode;
|
|
if (ImGui.Checkbox("Debug Mode", ref DebugMode))
|
|
config.DebugMode = DebugMode;
|
|
|
|
if (!VSync)
|
|
if (ImGuiExtensions.SliderFill("FPS Limit", ref _fpsLimit, 30, 480))
|
|
FPSLimit = _fpsLimit;
|
|
|
|
bool AntiCapture = config.AntiCapture;
|
|
if (ImGui.Checkbox("Anti-Capture", ref AntiCapture))
|
|
{
|
|
config.AntiCapture = AntiCapture;
|
|
if (AntiCapture && window != null)
|
|
Win32.EnableAntiCapture(window.Handle);
|
|
else if (window != null)
|
|
Win32.DisableAntiCapture(window.Handle);
|
|
}
|
|
|
|
ImGui.TextUnformatted("Background Image Interval");
|
|
ImGui.SetNextItemWidth(-1);
|
|
int BackgroundImageInterval = config.BackgroundImageInterval;
|
|
if (ImGui.InputInt("##Background Image Interval", ref BackgroundImageInterval, 1, 1000))
|
|
{
|
|
if (BackgroundImageInterval < 1)
|
|
BackgroundImageInterval = 1;
|
|
else if (BackgroundImageInterval > 1000)
|
|
BackgroundImageInterval = 1000;
|
|
|
|
config.BackgroundImageInterval = BackgroundImageInterval;
|
|
}
|
|
ImGui.TextUnformatted("Labeled Image Interval");
|
|
ImGui.SetNextItemWidth(-1);
|
|
int LabeledImageInterval = config.LabeledImageInterval;
|
|
if (ImGui.InputInt("##Labeled Image Interval", ref LabeledImageInterval, 1, 1000))
|
|
{
|
|
if (LabeledImageInterval < 1)
|
|
LabeledImageInterval = 1;
|
|
else if (LabeledImageInterval > 1000)
|
|
LabeledImageInterval = 1000;
|
|
config.LabeledImageInterval = LabeledImageInterval;
|
|
}
|
|
|
|
if (!_waitingForKeybind.GetValueOrDefault("Menu Key", false))
|
|
{
|
|
if (ImGui.Button(config.MenuKey.ToString()))
|
|
{
|
|
_waitingForKeybind["Menu Key"] = true;
|
|
_pendingKeybind["Menu Key"] = Keys.None;
|
|
_keybindTask["Menu Key"] = Task.Run(async () =>
|
|
{
|
|
var key = await InputManager.ListenForNextKeyOrMouseAsync();
|
|
_pendingKeybind["Menu Key"] = key;
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ImGui.Button("Listening...");
|
|
if (_pendingKeybind.GetValueOrDefault("Menu Key", Keys.None) != Keys.None)
|
|
{
|
|
config.MenuKey = _pendingKeybind["Menu Key"];
|
|
_pendingKeybind["Menu Key"] = Keys.None;
|
|
_waitingForKeybind["Menu Key"] = false;
|
|
}
|
|
}
|
|
ImGui.SameLine();
|
|
ImGui.Text("Menu Keybind");
|
|
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
List<LogManager.LogEntry?> logs;
|
|
|
|
try
|
|
{
|
|
logs = [.. LogManager.LogEntries];
|
|
}
|
|
catch
|
|
{
|
|
logs = [];
|
|
}
|
|
|
|
|
|
if (ImGuiExtensions.BeginPane("Logs", true, 16f, () =>
|
|
{
|
|
bool copyClicked = false;
|
|
if (TryLoadImageTexture("copy_icon", "assets/copy.png", ref _copyIconImage, ref _copyIconTextureId))
|
|
{
|
|
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
|
|
copyClicked = ImGui.ImageButton("##CopyLogs", _copyIconTextureId, new Vector2(16, 16));
|
|
ImGui.PopStyleVar();
|
|
if (ImGui.IsItemHovered())
|
|
ImGui.SetTooltip("Copy Logs");
|
|
}
|
|
else
|
|
{
|
|
copyClicked = ImGui.Button("Copy");
|
|
}
|
|
if (copyClicked)
|
|
{
|
|
var logText = new System.Text.StringBuilder();
|
|
foreach (var log in logs)
|
|
{
|
|
logText.AppendLine(log?.ToString());
|
|
}
|
|
ImGui.SetClipboardText(logText.ToString());
|
|
}
|
|
}))
|
|
{
|
|
ImGui.BeginChild("Logs", new Vector2(0, -34), ImGuiChildFlags.None, ImGuiWindowFlags.HorizontalScrollbar);
|
|
|
|
float scrollY = ImGui.GetScrollY();
|
|
float scrollMaxY = ImGui.GetScrollMaxY();
|
|
bool isAtBottom = scrollY >= scrollMaxY - 1.0f;
|
|
bool debugEnabled = LogManager.IsDebugEnabled();
|
|
foreach (var log in logs)
|
|
{
|
|
if (log == null)
|
|
continue;
|
|
if (log.Level == LogManager.LogLevel.Debug && !debugEnabled)
|
|
continue;
|
|
var color = log.Level switch
|
|
{
|
|
LogManager.LogLevel.Debug => new Vector4(0.5f, 0.5f, 0.5f, 1f),
|
|
LogManager.LogLevel.Info => new Vector4(1f, 1f, 1f, 1f),
|
|
LogManager.LogLevel.Warning => new Vector4(1f, 1f, 0.5f, 1f),
|
|
LogManager.LogLevel.Error => new Vector4(1f, 0.5f, 0.5f, 1f),
|
|
_ => new Vector4(1f, 1f, 1f, 1f),
|
|
};
|
|
ImGui.TextColored(color, log.ToString());
|
|
}
|
|
|
|
if (scrollToBottom || isAtBottom)
|
|
{
|
|
ImGui.SetScrollHereY(1.0f);
|
|
scrollToBottom = false;
|
|
}
|
|
|
|
ImGui.EndChild();
|
|
ImGui.Dummy(new Vector2(0, 1));
|
|
|
|
if (ImGui.Button("Save Logs"))
|
|
LogManager.SaveLog($"bin\\logs\\{DateTime.Now:MM-dd_HH-mm-ss}_spectrum_log.txt");
|
|
|
|
ImGui.SameLine();
|
|
|
|
if (ImGui.Button("Clear Logs"))
|
|
LogManager.ClearLog();
|
|
|
|
ImGui.SameLine();
|
|
|
|
if (ImGui.Button("Open Log Folder"))
|
|
LogManager.OpenLogFolder();
|
|
ImGuiExtensions.EndPane();
|
|
}
|
|
|
|
ImGui.EndTabItem();
|
|
}
|
|
|
|
ImGui.EndTabBar();
|
|
|
|
ImGui.End();
|
|
|
|
RenderHSVRangeWindow();
|
|
RenderMovementPreview();
|
|
}
|
|
|
|
protected void RenderOverlay()
|
|
{
|
|
ImGui.SetNextWindowSize(new Vector2(screenSize.width, screenSize.height), ImGuiCond.Always);
|
|
ImGui.SetNextWindowPos(new Vector2(0, 0), ImGuiCond.Always);
|
|
ImGui.Begin("Overlay", ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNavFocus);
|
|
var drawList = ImGui.GetWindowDrawList();
|
|
var config = mainConfig.Data;
|
|
|
|
if (config.DrawCaptureFov || (config.DrawAimFov && config.EnableAimFov))
|
|
{
|
|
InputManager.GetCursorPos(out System.Drawing.Point mousePos);
|
|
if (config.DrawCaptureFov)
|
|
{
|
|
if (config.CaptureFOVType == FovType.Rectangle)
|
|
{
|
|
Vector2 topLeft;
|
|
Vector2 bottomRight;
|
|
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
|
|
{
|
|
var local = ToOverlay(new Vector2(mousePos.X, mousePos.Y));
|
|
topLeft = new(local.X - (config.ImageWidth / 2), local.Y - (config.ImageHeight / 2));
|
|
bottomRight = new(local.X + (config.ImageWidth / 2), local.Y + (config.ImageHeight / 2));
|
|
}
|
|
|
|
drawList.AddRect(topLeft, bottomRight, ImGui.GetColorU32(config.CaptureFOVColor), 0.0f, ImDrawFlags.None, 1.0f);
|
|
}
|
|
else if (config.CaptureFOVType == FovType.Circle)
|
|
{
|
|
Vector2 center;
|
|
if (!config.ClosestToMouse)
|
|
center = new(screenSize.width / 2, screenSize.height / 2);
|
|
else
|
|
center = ToOverlay(new Vector2(mousePos.X, mousePos.Y));
|
|
|
|
drawList.AddCircle(center, Math.Min(config.ImageHeight, config.ImageWidth) / 2, ImGui.GetColorU32(config.CaptureFOVColor), 100, 1.0f);
|
|
}
|
|
}
|
|
if (config.DrawAimFov)
|
|
{
|
|
if (config.AimFovType == FovType.Rectangle)
|
|
{
|
|
Vector2 topLeft;
|
|
Vector2 bottomRight;
|
|
if (!config.ClosestToMouse)
|
|
{
|
|
topLeft = new((screenSize.width - config.AimFovWidth) / 2, (screenSize.height - config.AimFovHeight) / 2);
|
|
bottomRight = new((screenSize.width + config.AimFovWidth) / 2, (screenSize.height + config.AimFovHeight) / 2);
|
|
}
|
|
else
|
|
{
|
|
var local = ToOverlay(new Vector2(mousePos.X, mousePos.Y));
|
|
topLeft = new(local.X - (config.AimFovWidth / 2), local.Y - (config.AimFovHeight / 2));
|
|
bottomRight = new(local.X + (config.AimFovWidth / 2), local.Y + (config.AimFovHeight / 2));
|
|
}
|
|
|
|
drawList.AddRect(topLeft, bottomRight, ImGui.GetColorU32(config.AimFovColor), 0.0f, ImDrawFlags.None, 1.0f);
|
|
}
|
|
else
|
|
{
|
|
Vector2 center;
|
|
if (!config.ClosestToMouse)
|
|
center = new(screenSize.width / 2, screenSize.height / 2);
|
|
else
|
|
center = ToOverlay(new Vector2(mousePos.X, mousePos.Y));
|
|
drawList.AddCircle(center, Math.Min(config.AimFovWidth, config.AimFovHeight) / 2, ImGui.GetColorU32(config.AimFovColor), 100, 1.0f);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
if (config.DebugMode)
|
|
{
|
|
var frameStats = Program.Timings.GetSnapshot(["Frame"]).FirstOrDefault();
|
|
double avgTime = frameStats == null ? 0 : Math.Round(frameStats.AverageTicks / Stopwatch.Frequency * 1000.0, 2);
|
|
int fps = frameStats == null || frameStats.AverageTicks <= 0 ? 0 : (int)Math.Round(Stopwatch.Frequency / frameStats.AverageTicks);
|
|
var lines = new List<string>
|
|
{
|
|
$"FPS: {fps} | AVG Process Time: {avgTime}ms"
|
|
};
|
|
|
|
var bitmapToMat = Program.Timings.GetSnapshot(["Bitmap to Mat"]).FirstOrDefault();
|
|
var screenCapture = Program.Timings.GetSnapshot(["Screen Capture"]).FirstOrDefault();
|
|
|
|
long skippedFrames = (screenCapture?.Count ?? 0L) - (bitmapToMat?.Count ?? 0L);
|
|
|
|
lines.Add($"Skipped Frames: {skippedFrames}/{(screenCapture?.Count ?? 0L)}");
|
|
|
|
var stats = Program.Timings.GetSnapshot();
|
|
stats = [.. stats.OrderByDescending(s => s.AverageTicks)];
|
|
stats = [.. stats.Where(s => s.Name != "Frame")];
|
|
foreach (var stat in stats)
|
|
lines.Add($"{stat.Name}: {TimingStats.FormatDuration(stat.AverageTicks)}");
|
|
|
|
float maxWidth = 0;
|
|
float totalHeight = 0;
|
|
foreach (var line in lines)
|
|
{
|
|
var size = ImGui.CalcTextSize(line);
|
|
if (size.X > maxWidth)
|
|
maxWidth = size.X;
|
|
totalHeight += size.Y + 4;
|
|
}
|
|
|
|
drawList.AddRectFilled(new Vector2(10, 10), new Vector2(10 + maxWidth + 10, 10 + totalHeight + 10), ImGui.GetColorU32(new Vector4(0, 0, 0, 0.8f)), 5.0f);
|
|
ImGui.SetCursorPos(new Vector2(15, 15));
|
|
foreach (var line in lines)
|
|
{
|
|
ImGui.SetCursorPosX(15);
|
|
ImGui.TextUnformatted(line);
|
|
}
|
|
}
|
|
|
|
List<Action<ImDrawListPtr>> _drawCommands;
|
|
lock (detectionDrawLock)
|
|
{
|
|
_drawCommands = [.. activeDrawCommands];
|
|
}
|
|
|
|
foreach (var cmd in _drawCommands)
|
|
{
|
|
cmd?.Invoke(drawList);
|
|
}
|
|
|
|
ImGui.End();
|
|
}
|
|
private static void AddStyling()
|
|
{
|
|
var style = ImGui.GetStyle();
|
|
var colors = style.Colors;
|
|
|
|
style.WindowRounding = 4.0f;
|
|
style.FrameRounding = 3.0f;
|
|
style.ScrollbarRounding = 3.0f;
|
|
style.GrabRounding = 3.0f;
|
|
style.FrameBorderSize = 1.0f;
|
|
style.WindowBorderSize = 1.0f;
|
|
style.PopupRounding = 4.0f;
|
|
style.TabRounding = 3.0f;
|
|
style.ChildRounding = 3.0f;
|
|
style.PopupBorderSize = 1.0f;
|
|
style.GrabMinSize = 20.0f;
|
|
style.WindowPadding = new Vector2(8, 8);
|
|
style.FramePadding = new Vector2(6, 3);
|
|
style.ItemSpacing = new Vector2(8, 4);
|
|
style.ScrollbarRounding = 6.0f;
|
|
style.ScrollbarSize = 12.0f;
|
|
|
|
colors[(int)ImGuiCol.WindowBg] = new Vector4(0.10f, 0.10f, 0.12f, 1.0f);
|
|
colors[(int)ImGuiCol.ChildBg] = new Vector4(0.12f, 0.12f, 0.14f, 1.0f);
|
|
colors[(int)ImGuiCol.PopupBg] = new Vector4(0.11f, 0.11f, 0.12f, 1.0f);
|
|
colors[(int)ImGuiCol.Border] = new Vector4(0.23f, 0.23f, 0.25f, 0.50f);
|
|
colors[(int)ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
|
|
colors[(int)ImGuiCol.FrameBg] = new Vector4(0.17f, 0.17f, 0.20f, 1.0f);
|
|
colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.22f, 0.22f, 0.26f, 1.0f);
|
|
colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.22f, 0.22f, 0.27f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.TitleBg] = new Vector4(0.10f, 0.10f, 0.12f, 1.0f);
|
|
colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.15f, 0.15f, 0.18f, 1.0f);
|
|
colors[(int)ImGuiCol.TitleBgCollapsed] = new Vector4(0.12f, 0.12f, 0.14f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.MenuBarBg] = new Vector4(0.15f, 0.15f, 0.17f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.CheckMark] = new Vector4(0.80f, 0.80f, 0.80f, 1.0f);
|
|
colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.31f, 0.31f, 0.34f, 1.0f);
|
|
colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.43f, 0.43f, 0.45f, 1.0f);
|
|
colors[(int)ImGuiCol.Button] = new Vector4(0.17f, 0.17f, 0.20f, 1.0f);
|
|
colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.24f, 0.24f, 0.28f, 1.0f);
|
|
colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.29f, 0.29f, 0.33f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.Header] = new Vector4(0.14f, 0.14f, 0.16f, 1.0f);
|
|
colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.20f, 0.20f, 0.22f, 1.0f);
|
|
colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.24f, 0.24f, 0.26f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.Separator] = new Vector4(0.23f, 0.23f, 0.25f, 0.5f);
|
|
colors[(int)ImGuiCol.SeparatorHovered] = new Vector4(0.33f, 0.33f, 0.35f, 0.78f);
|
|
colors[(int)ImGuiCol.SeparatorActive] = new Vector4(0.32f, 0.32f, 0.35f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.ResizeGrip] = new Vector4(0.23f, 0.23f, 0.25f, 0.2f);
|
|
colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.33f, 0.33f, 0.36f, 0.7f);
|
|
colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.36f, 0.36f, 0.39f, 0.9f);
|
|
|
|
colors[(int)ImGuiCol.Tab] = new Vector4(0.13f, 0.13f, 0.15f, 1.0f);
|
|
colors[(int)ImGuiCol.TabHovered] = new Vector4(0.18f, 0.18f, 0.20f, 1.0f);
|
|
colors[(int)ImGuiCol.TabSelected] = new Vector4(0.22f, 0.22f, 0.25f, 1.0f);
|
|
colors[(int)ImGuiCol.TabDimmed] = new Vector4(0.13f, 0.13f, 0.15f, 1.0f);
|
|
colors[(int)ImGuiCol.TabDimmedSelected] = new Vector4(0.18f, 0.18f, 0.20f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.Text] = new Vector4(0.85f, 0.85f, 0.88f, 1.0f);
|
|
colors[(int)ImGuiCol.TextDisabled] = new Vector4(0.48f, 0.48f, 0.52f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.62f, 1.0f);
|
|
colors[(int)ImGuiCol.PlotLinesHovered] = new Vector4(0.80f, 0.80f, 0.81f, 1.0f);
|
|
colors[(int)ImGuiCol.PlotHistogram] = new Vector4(0.61f, 0.61f, 0.62f, 1.0f);
|
|
colors[(int)ImGuiCol.PlotHistogramHovered] = new Vector4(0.80f, 0.80f, 0.81f, 1.0f);
|
|
|
|
colors[(int)ImGuiCol.DragDropTarget] = new Vector4(0.90f, 0.90f, 0.90f, 0.90f);
|
|
|
|
colors[(int)ImGuiCol.NavWindowingHighlight] = new Vector4(0.70f, 0.70f, 0.70f, 0.70f);
|
|
colors[(int)ImGuiCol.NavWindowingDimBg] = new Vector4(0.20f, 0.20f, 0.20f, 0.20f);
|
|
colors[(int)ImGuiCol.ModalWindowDimBg] = new Vector4(0.10f, 0.10f, 0.10f, 0.35f);
|
|
|
|
colors[(int)ImGuiCol.ScrollbarBg] = new Vector4(0.15f, 0.15f, 0.18f, 1.0f);
|
|
colors[(int)ImGuiCol.ScrollbarGrab] = new Vector4(0.31f, 0.31f, 0.34f, 1.0f);
|
|
colors[(int)ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.43f, 0.43f, 0.45f, 1.0f);
|
|
colors[(int)ImGuiCol.ScrollbarGrabActive] = new Vector4(0.50f, 0.50f, 0.52f, 1.0f);
|
|
}
|
|
public void AddRect(Rect rect, Vector4 color, float thickness = 1.0f, System.Drawing.Rectangle? bounds = null)
|
|
{
|
|
lock (detectionDrawLock)
|
|
{
|
|
var mb = Program.MonitorBounds;
|
|
detectionDrawCommands.Add(drawList => drawList.AddRect(
|
|
new Vector2(
|
|
rect.Left + (bounds?.X ?? 0) - mb.X,
|
|
rect.Top + (bounds?.Y ?? 0) - mb.Y),
|
|
new Vector2(
|
|
rect.Right + (bounds?.X ?? 0) - mb.X,
|
|
rect.Bottom + (bounds?.Y ?? 0) - mb.Y),
|
|
ImGui.GetColorU32(color),
|
|
0, 0, thickness
|
|
));
|
|
}
|
|
}
|
|
|
|
public void AddLine(Vector2 p1, Vector2 p2, Vector4 color, float thickness = 1.0f)
|
|
{
|
|
lock (detectionDrawLock)
|
|
{
|
|
var p1Local = ToOverlay(p1);
|
|
var p2Local = ToOverlay(p2);
|
|
detectionDrawCommands.Add(drawList => drawList.AddLine(p1Local, p2Local, ImGui.GetColorU32(color), thickness));
|
|
}
|
|
}
|
|
|
|
public void AddCircle(Vector2 center, float radius, Vector4 color, int numSegments = 0, float thickness = 1.0f)
|
|
{
|
|
if (numSegments <= 0)
|
|
numSegments = (int)(Math.Max(1, radius / 2.0f));
|
|
|
|
lock (detectionDrawLock)
|
|
{
|
|
var local = ToOverlay(center);
|
|
detectionDrawCommands.Add(drawList => drawList.AddCircle(local, radius, ImGui.GetColorU32(color), numSegments, thickness));
|
|
}
|
|
}
|
|
public void AddCircleFilled(Vector2 center, float radius, Vector4 color, int numSegments = 0)
|
|
{
|
|
if (numSegments <= 0)
|
|
numSegments = (int)(Math.Max(1, radius / 2.0f));
|
|
lock (detectionDrawLock)
|
|
{
|
|
var local = ToOverlay(center);
|
|
detectionDrawCommands.Add(drawList => drawList.AddCircleFilled(local, radius, ImGui.GetColorU32(color), numSegments));
|
|
}
|
|
}
|
|
|
|
public void AddText(Vector2 pos, Vector4 color, string text, int fontSize = 16)
|
|
{
|
|
if (string.IsNullOrEmpty(text))
|
|
return;
|
|
lock (detectionDrawLock)
|
|
{
|
|
var local = ToOverlay(pos);
|
|
detectionDrawCommands.Add(drawList => drawList.AddText(ImGui.GetFont(), fontSize, local, ImGui.GetColorU32(color), text));
|
|
}
|
|
}
|
|
|
|
public void CommitDetectionDrawCommands()
|
|
{
|
|
lock (detectionDrawLock)
|
|
{
|
|
activeDrawCommands = detectionDrawCommands;
|
|
detectionDrawCommands = [];
|
|
}
|
|
}
|
|
|
|
public void ClearDetectionDrawCommands()
|
|
{
|
|
lock (detectionDrawLock)
|
|
{
|
|
detectionDrawCommands.Clear();
|
|
}
|
|
}
|
|
|
|
public static Vector2 GetTextWidth(string text, int fontSize = 16)
|
|
{
|
|
if (string.IsNullOrEmpty(text))
|
|
return new Vector2(0, 0);
|
|
return ImGui.CalcTextSize(text, 0, text.Length, fontSize);
|
|
}
|
|
|
|
public static string FormatText(string text)
|
|
{
|
|
return string.Concat(text.Select((x, i) => i > 0 && char.IsUpper(x) ? " " + x : x.ToString()));
|
|
}
|
|
}
|
|
} |