mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55bc1e9c3a
|
||
|
|
859e2e1b43 | ||
|
|
dd13b99249 | ||
|
|
f8b90d7b63 | ||
|
|
8b529af9c4 | ||
|
|
aed83ebacd | ||
|
|
206135368a | ||
|
|
77d4b5d21b | ||
|
|
6a6fb2e2ee | ||
|
|
6bb49b90b7 |
@@ -1,159 +1,63 @@
|
||||
# Spectrum
|
||||
|
||||
A real-time computer vision application for object detection and automated targeting using OpenCV and C#. Spectrum captures screen regions, detects objects based on HSV color filtering, and can automatically move the mouse cursor to target detected objects.
|
||||
Spectrum is a semi-universal colorbot that uses C# and OpenCV for image processing.
|
||||
|
||||
## Features
|
||||
|
||||
- **Real-time Screen Capture**: Captures specific screen regions for processing
|
||||
- **HSV Color-based Detection**: Uses HSV color space filtering to detect objects
|
||||
- **Automated Targeting**: Automatically moves mouse cursor to detected targets
|
||||
- **Dataset Collection**: Automatically generates labeled datasets for machine learning
|
||||
- **Configurable Parameters**: Extensive configuration options via JSON file
|
||||
- **Visual Feedback**: Optional detection window showing real-time results
|
||||
- **Hotkey Support**: Configurable keybinding for activation
|
||||
|
||||
## Requirements
|
||||
|
||||
- .NET 8.0 or later
|
||||
- Windows operating system
|
||||
- OpenCV 4.11.0+
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```powershell
|
||||
git clone https://github.com/whoswhip/Spectrum.git
|
||||
cd Spectrum
|
||||
```
|
||||
|
||||
2. Build the project:
|
||||
```powershell
|
||||
dotnet build
|
||||
```
|
||||
|
||||
3. Run the application:
|
||||
```powershell
|
||||
dotnet run --project Spectrum
|
||||
```
|
||||
- Extensive configuration file
|
||||
- Dataset collection
|
||||
- Multiple mouse movement paths
|
||||
|
||||
## Configuration
|
||||
On first run, a default configuration file is created.
|
||||
### Parameters
|
||||
| Parameter | Range/Options | Default Value | Description |
|
||||
|---------------|-----------------------|---------------|---------------------------------|
|
||||
| `ImageWidth` | 1 - ScreenSize | 640 | Defines the width of the image |
|
||||
| `ImageHeight` | 1 - ScreenSize | 640 | Defines the height of the image|
|
||||
|
||||
The application uses a `config.json` file for configuration. On first run, a default configuration file will be created. You can modify the following parameters:
|
||||
| Parameter | Range/Options | Default Value | Description |
|
||||
|-------------------|---------------|---------------|---------------------------------|
|
||||
| `YOffsetPercent` | 0.0 - 1 | 0.8 | Sets the vertical offset |
|
||||
| `XOffsetPercent` | 0.0 - 1 | 0.5 | Sets the horizontal offset |
|
||||
|
||||
### Display Settings
|
||||
- `ImageWidth`: Width of the capture region (default: 640)
|
||||
- `ImageHeight`: Height of the capture region (default: 640)
|
||||
- `ShowDetectionWindow`: Show real-time detection window (default: true)
|
||||
| Parameter | Range/Options | Default Value | Description |
|
||||
|--------------------|-------------------------------|---------------|---------------------------------------------------------|
|
||||
| `EnableAim` | true or false | true | Enables or disables aim functionality |
|
||||
| `ClosestToMouse` | true or false | true | Determines aiming at the closest target to the mouse |
|
||||
| `Keybind` | 1 - 254 | 6 | Virtual key codes are used for keybinding |
|
||||
| `Sensitivity` | 0.1 - 2 | 0.5 | Defines the sensitivity of the aim |
|
||||
| `AimMovementType` | CubicBezier, Linear, Adaptive| CubicBezier | Specifies the type of aim movement |
|
||||
|
||||
### Detection Settings
|
||||
- `UpperHSV`: Upper HSV color bounds for detection
|
||||
- `LowerHSV`: Lower HSV color bounds for detection
|
||||
- `YOffsetPercent`: Y-axis offset percentage for targeting (default: 0.8)
|
||||
- `XOffsetPercent`: X-axis offset percentage for targeting (default: 0.5)
|
||||
| Parameter | Range/Options | Default Value | Description |
|
||||
|-----------------------|---------------|---------------|---------------------------------|
|
||||
| `ShowDetectionWindow` | true or false | true | Displays the detection window |
|
||||
|
||||
### Control Settings
|
||||
- `EnableAim`: Enable automatic mouse movement (default: true)
|
||||
- `ClosestToMouse`: Target closest object to mouse cursor (default: true)
|
||||
- `Keybind`: Activation key code (default: 6 - mouse side button)
|
||||
- `Sensitivity`: Mouse movement sensitivity (default: 0.5)
|
||||
| Parameter | Range/Options | Default Value | Description |
|
||||
|---------------------------|---------------|---------------|-----------------------------------------------|
|
||||
| `CollectData` | true or false | false | Enables or disables data collection |
|
||||
| `AutoLabel` | true or false | false | Depends on `CollectData`; auto-labels data |
|
||||
| `BackgroundImageInterval` | 1 - 100 | 10 | Sets interval for background image collection|
|
||||
|
||||
### Data Collection
|
||||
- `CollectData`: Enable dataset collection (default: false)
|
||||
- `AutoLabel`: Enable automatic labeling for YOLO format (default: false)
|
||||
- `BackgroundImageInterval`: Interval for background image collection (default: 10)
|
||||
|
||||
### Example Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"ImageWidth": 640,
|
||||
"ImageHeight": 640,
|
||||
"YOffsetPercent": 0.8,
|
||||
"XOffsetPercent": 0.5,
|
||||
"EnableAim": true,
|
||||
"ClosestToMouse": true,
|
||||
"Keybind": 6,
|
||||
"Sensitivity": 0.1,
|
||||
"ShowDetectionWindow": true,
|
||||
"CollectData": false,
|
||||
"AutoLabel": false,
|
||||
"BackgroundImageInterval": 10,
|
||||
"UpperHSV": {
|
||||
"Val0": 150.0,
|
||||
"Val1": 255.0,
|
||||
"Val2": 229.0,
|
||||
"Val3": 0.0
|
||||
},
|
||||
"LowerHSV": {
|
||||
"Val0": 150.0,
|
||||
"Val1": 255.0,
|
||||
"Val2": 229.0,
|
||||
"Val3": 0.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
1. **Start the application**: Run the executable or use `dotnet run`
|
||||
2. **Configure detection**: Adjust HSV values in `config.json` for your target objects
|
||||
3. **Activate detection**: Press the configured keybind (default: mouse side button)
|
||||
4. **Real-time targeting**: The application will automatically detect and target objects
|
||||
5. **Reload configuration**: Press F5 or R to reload configuration without restarting
|
||||
|
||||
### Keyboard Controls
|
||||
|
||||
- **Escape**: Exit the application
|
||||
- **F5/R**: Reload configuration from file
|
||||
- **Configured Keybind**: Activate detection and targeting
|
||||
| Parameter | Sub-Parameter | Range/Options | Default Value | Description |
|
||||
|-------------|---------------|---------------|---------------|---------------------------------|
|
||||
| **UpperHSV**| `Val0` | 0 - 255 | 150 | Hue |
|
||||
| | `Val1` | 0 - 255 | 255 | Saturation |
|
||||
| | `Val2` | 0 - 255 | 229 | Value |
|
||||
| | `Val3` | 0 | 0 | |
|
||||
| **LowerHSV**| `Val0` | 0 - 255 | 150 | Hue |
|
||||
| | `Val1` | 0 - 255 | 255 | Saturation |
|
||||
| | `Val2` | 0 - 255 | 229 | Value |
|
||||
| | `Val3` | 0 | 0 | |
|
||||
|
||||
## Dataset Collection
|
||||
|
||||
When `CollectData` and `AutoLabel` are enabled, Spectrum automatically generates:
|
||||
|
||||
- **Images**: Captured screenshots saved to `dataset/images/`
|
||||
- **Labels**: YOLO format annotation files saved to `dataset/labels/`
|
||||
- **Background Images**: Non-detection samples for training balance
|
||||
|
||||
This feature is useful for creating training datasets for machine learning models.
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Dependencies
|
||||
|
||||
- **OpenCvSharp4**: OpenCV bindings for .NET
|
||||
- **Newtonsoft.Json**: JSON configuration handling
|
||||
- **System.Drawing.Common**: Screen capture and image processing
|
||||
|
||||
### Architecture
|
||||
|
||||
- **Program.cs**: Main application loop and screen capture
|
||||
- **Config.cs**: Configuration management and validation
|
||||
- **AutoLabeling.cs**: Dataset generation and YOLO labeling
|
||||
- **InputManager.cs**: Mouse input simulation
|
||||
|
||||
### Detection Pipeline
|
||||
|
||||
1. **Screen Capture**: Captures specified screen region
|
||||
2. **Color Space Conversion**: Converts BGR to HSV
|
||||
3. **Color Filtering**: Applies HSV range mask
|
||||
4. **Morphological Operations**: Dilates image to fill gaps
|
||||
5. **Contour Detection**: Finds object boundaries
|
||||
6. **Filtering**: Removes small contours (area < 100)
|
||||
7. **Target Selection**: Chooses closest target to reference point
|
||||
8. **Mouse Movement**: Moves cursor to calculated target position
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make your changes
|
||||
4. Test thoroughly
|
||||
5. Submit a pull request
|
||||
- **Images**: Captured screenshots saved to `dataset/images`
|
||||
- **Labels**: YOLO format annotation files saved to `dataset/labels`
|
||||
- **Background Images**: Screenshots without any labels, helps training balance
|
||||
This feature is very useful for creating training datasets for machine learning models.
|
||||
|
||||
## License
|
||||
|
||||
See LICENSE.txt for license information.
|
||||
See [LICENSE.txt](LICENSE.txt) for license information.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
|
||||
+16
-18
@@ -1,11 +1,7 @@
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LogLevel = Spectrum.LogManager.LogLevel;
|
||||
|
||||
namespace Spectrum
|
||||
{
|
||||
@@ -18,6 +14,7 @@ namespace Spectrum
|
||||
private static Task? backgroundTask;
|
||||
private static readonly ConcurrentQueue<LabelingData> labelingQueue = new ConcurrentQueue<LabelingData>();
|
||||
private static readonly ConcurrentQueue<BackgroundImageData> backgroundQueue = new ConcurrentQueue<BackgroundImageData>();
|
||||
private static ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
||||
|
||||
private static List<YoloBoundingBox> GetBoundingBoxes(OpenCvSharp.Point[][] contours, int imageWidth, int imageHeight)
|
||||
{
|
||||
@@ -61,9 +58,7 @@ namespace Spectrum
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Failed to save labels to " + path);
|
||||
Console.ResetColor();
|
||||
LogManager.Log("[ERROR] Failed to save labels.", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
private static void SaveMatAsImage(Mat mat, string path)
|
||||
@@ -74,7 +69,7 @@ namespace Spectrum
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error saving image: {ex.Message}");
|
||||
LogManager.Log($"[ERROR] Failed to save image: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +85,7 @@ namespace Spectrum
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Failed to process labeling data.");
|
||||
Console.ResetColor();
|
||||
LogManager.Log("[ERROR] Failed to process labeling data.", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,9 +97,7 @@ namespace Spectrum
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Failed to process background image data.");
|
||||
Console.ResetColor();
|
||||
LogManager.Log("[ERROR] Failed to process background image data.", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +105,13 @@ namespace Spectrum
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void AddToQueue(Mat mat, Rectangle bounds, OpenCvSharp.Point[][] filteredContours)
|
||||
{
|
||||
if (!Config.AutoLabel || filteredContours.Length == 0)
|
||||
if (!mainConfig.Data.AutoLabel || filteredContours.Length == 0)
|
||||
return;
|
||||
|
||||
if (labelingQueue.Count > 250)
|
||||
return;
|
||||
|
||||
Mat clone = mat.Clone();
|
||||
@@ -130,12 +125,15 @@ namespace Spectrum
|
||||
|
||||
public static void AddBackgroundImage(Mat mat, bool detected)
|
||||
{
|
||||
if (!Config.AutoLabel)
|
||||
if (!mainConfig.Data.AutoLabel)
|
||||
return;
|
||||
|
||||
detectionAttemps++;
|
||||
|
||||
if (detectionAttemps < Config.BackgroundImageInterval || detected)
|
||||
if (detectionAttemps < mainConfig.Data.BackgroundImageInterval || detected)
|
||||
return;
|
||||
|
||||
if (backgroundQueue.Count > 250)
|
||||
return;
|
||||
|
||||
Mat clone = mat.Clone();
|
||||
|
||||
+126
-120
@@ -1,148 +1,154 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenCvSharp;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using LogLevel = Spectrum.LogManager.LogLevel;
|
||||
|
||||
namespace Spectrum
|
||||
{
|
||||
public static class Config
|
||||
public class ConfigManager<T> where T : new()
|
||||
{
|
||||
#region Variables
|
||||
public static int ImageWidth { get; set; } = 640;
|
||||
public static int ImageHeight { get; set; } = 640;
|
||||
private readonly string _fileName;
|
||||
private FileSystemWatcher? _watcher;
|
||||
private T _data;
|
||||
|
||||
public static double YOffsetPercent { get; set; } = 0.8;
|
||||
public static double XOffsetPercent { get; set; } = 0.5;
|
||||
public static bool EnableAim { get; set; } = true;
|
||||
public static bool ClosestToMouse { get; set; } = true; // if false it will use the center of the screen
|
||||
public static int Keybind { get; set; } = 0x06; // first side button on mouse
|
||||
public static double Sensitivity { get; set; } = 0.5;
|
||||
public T Data => _data;
|
||||
|
||||
public static bool ShowDetectionWindow { get; set; } = true;
|
||||
|
||||
public static bool CollectData { get; set; } = false;
|
||||
public static bool AutoLabel { get; set; } = false; // collect data needs to be enabled
|
||||
public static int BackgroundImageInterval { get; set; } = 10; // after 10 loops with no detection, save a background image
|
||||
|
||||
public static Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229);
|
||||
public static Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229);
|
||||
#endregion
|
||||
|
||||
public static void LoadConfig(bool silent = false)
|
||||
public ConfigManager(string fileName)
|
||||
{
|
||||
if (File.Exists("config.json"))
|
||||
_fileName = fileName;
|
||||
_data = new T();
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
public void LoadConfig(bool silent = false)
|
||||
{
|
||||
if (File.Exists(_fileName))
|
||||
{
|
||||
string config_content = File.ReadAllText("config.json");
|
||||
try
|
||||
{
|
||||
var config = JObject.Parse(config_content);
|
||||
ImageWidth = config["ImageWidth"]?.Value<int>() ?? ImageWidth;
|
||||
ImageHeight = config["ImageHeight"]?.Value<int>() ?? ImageHeight;
|
||||
|
||||
YOffsetPercent = config["YOffsetPercent"]?.Value<double>() ?? YOffsetPercent;
|
||||
XOffsetPercent = config["XOffsetPercent"]?.Value<double>() ?? XOffsetPercent;
|
||||
EnableAim = config["EnableAim"]?.Value<bool>() ?? EnableAim;
|
||||
ClosestToMouse = config["ClosestToMouse"]?.Value<bool>() ?? ClosestToMouse;
|
||||
Keybind = config["Keybind"]?.Value<int>() ?? Keybind;
|
||||
Sensitivity = config["Sensitivity"]?.Value<double>() ?? Sensitivity;
|
||||
|
||||
ShowDetectionWindow = config["ShowDetectionWindow"]?.Value<bool>() ?? ShowDetectionWindow;
|
||||
|
||||
CollectData = config["CollectData"]?.Value<bool>() ?? CollectData;
|
||||
AutoLabel = config["AutoLabel"]?.Value<bool>() ?? AutoLabel;
|
||||
BackgroundImageInterval = config["BackgroundImageInterval"]?.Value<int>() ?? BackgroundImageInterval;
|
||||
|
||||
UpperHSV = config["UpperHSV"]?.ToObject<Scalar>() ?? UpperHSV;
|
||||
LowerHSV = config["LowerHSV"]?.ToObject<Scalar>() ?? LowerHSV;
|
||||
|
||||
if (ImageWidth <= 0 || ImageHeight <= 0)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Invalid image dimensions in config.json, using default values.");
|
||||
Console.ResetColor();
|
||||
ImageWidth = 640;
|
||||
ImageHeight = 640;
|
||||
}
|
||||
if (YOffsetPercent < 0 || YOffsetPercent > 1 || XOffsetPercent < 0 || XOffsetPercent > 1)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Invalid offset percentages in config.json, using default values.");
|
||||
Console.ResetColor();
|
||||
YOffsetPercent = 0.8;
|
||||
XOffsetPercent = 0.5;
|
||||
}
|
||||
if (Keybind < 0 || Keybind > 255)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Invalid keybind in config.json, using default value.");
|
||||
Console.ResetColor();
|
||||
Keybind = 0x06;
|
||||
}
|
||||
if (Sensitivity < 0 || Sensitivity > 1)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Invalid sensitivity in config.json, using default value.");
|
||||
Console.ResetColor();
|
||||
Sensitivity = 0.5;
|
||||
}
|
||||
if (AutoLabel && !CollectData )
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("[WARNING] AutoLabel is enabled but CollectData is not. Disabling AutoLabel.");
|
||||
Console.ResetColor();
|
||||
AutoLabel = false;
|
||||
}
|
||||
if (BackgroundImageInterval <= 0)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Invalid BackgroundImageInterval in config.json, using default value.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
SaveConfig();
|
||||
if (!silent)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("[INFO] Configuration loaded successfully.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
var json = File.ReadAllText(_fileName);
|
||||
_data = JsonConvert.DeserializeObject<T>(json) ?? new T();
|
||||
if (!silent) LogManager.Log($"Loaded config {_fileName}.", LogLevel.Info);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] Error parsing config.json, using default values.");
|
||||
Console.ResetColor();
|
||||
LogManager.Log($"Failed to parse {_fileName}, using default values.", LogLevel.Error);
|
||||
_data = new T();
|
||||
SaveConfig();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("[WARNING] config.json not found, using default values.");
|
||||
Console.ResetColor();
|
||||
LogManager.Log($"{_fileName} not found, creating a new one with default values.", LogLevel.Error);
|
||||
_data = new T();
|
||||
SaveConfig();
|
||||
}
|
||||
}
|
||||
public static void SaveConfig()
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
var config = new JObject
|
||||
{
|
||||
["ImageWidth"] = ImageWidth,
|
||||
["ImageHeight"] = ImageHeight,
|
||||
["YOffsetPercent"] = YOffsetPercent,
|
||||
["XOffsetPercent"] = XOffsetPercent,
|
||||
["EnableAim"] = EnableAim,
|
||||
["ClosestToMouse"] = ClosestToMouse,
|
||||
["Keybind"] = Keybind,
|
||||
["Sensitivity"] = Sensitivity,
|
||||
["ShowDetectionWindow"] = ShowDetectionWindow,
|
||||
["CollectData"] = CollectData,
|
||||
["AutoLabel"] = AutoLabel,
|
||||
["BackgroundImageInterval"] = BackgroundImageInterval,
|
||||
["UpperHSV"] = JToken.FromObject(UpperHSV),
|
||||
["LowerHSV"] = JToken.FromObject(LowerHSV)
|
||||
};
|
||||
File.WriteAllText("config.json", config.ToString(Formatting.Indented));
|
||||
File.WriteAllText(_fileName, JsonConvert.SerializeObject(_data, Formatting.Indented));
|
||||
}
|
||||
|
||||
public void StartFileWatcher()
|
||||
{
|
||||
if (_watcher != null) return;
|
||||
|
||||
_watcher = new FileSystemWatcher(Directory.GetCurrentDirectory(), _fileName)
|
||||
{
|
||||
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size
|
||||
};
|
||||
_watcher.Changed += OnConfigFileChanged;
|
||||
_watcher.EnableRaisingEvents = true;
|
||||
LogManager.Log($"File watcher started for {_fileName}.", LogLevel.Info);
|
||||
}
|
||||
|
||||
public void StopFileWatcher()
|
||||
{
|
||||
if (_watcher == null) return;
|
||||
_watcher.EnableRaisingEvents = false;
|
||||
_watcher.Changed -= OnConfigFileChanged;
|
||||
_watcher.Dispose();
|
||||
_watcher = null;
|
||||
LogManager.Log($"File watcher stopped for {_fileName}.", LogLevel.Info);
|
||||
}
|
||||
|
||||
private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
try
|
||||
{
|
||||
LoadConfig(true);
|
||||
LogManager.Log($"Configuration reloaded successfully for {_fileName}.", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log($"Failed to reload configuration for {_fileName}: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum MovementType
|
||||
{
|
||||
Linear,
|
||||
CubicBezier,
|
||||
QuadraticBezier,
|
||||
Adaptive
|
||||
}
|
||||
public class ConfigData
|
||||
{
|
||||
|
||||
// Image settings
|
||||
public int ImageWidth { get; set; } = 640;
|
||||
public int ImageHeight { get; set; } = 640;
|
||||
|
||||
// Offset settings
|
||||
public double YOffsetPercent { get; set; } = 0.8;
|
||||
public double XOffsetPercent { get; set; } = 0.5;
|
||||
|
||||
// Aim settings
|
||||
public bool EnableAim { get; set; } = true;
|
||||
public bool ClosestToMouse { get; set; } = true;
|
||||
public Keys Keybind { get; set; } = Keys.XButton2;
|
||||
public double Sensitivity { get; set; } = 0.5;
|
||||
public MovementType AimMovementType { get; set; } = MovementType.Adaptive;
|
||||
public bool EmaSmoothening { get; set; } = true;
|
||||
public double EmaSmootheningFactor { get; set; } = 0.1;
|
||||
|
||||
// Display settings
|
||||
public bool ShowDetectionWindow { get; set; } = true;
|
||||
public bool DrawDetections { get; set; } = true;
|
||||
public Vector4 DetectionColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
public bool ShowMenu { get; set; } = true;
|
||||
public bool DrawFOV { get; set; } = false;
|
||||
public Vector4 FOVColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
// Data collection settings
|
||||
public bool CollectData { get; set; } = false;
|
||||
public bool AutoLabel { get; set; } = false;
|
||||
public int BackgroundImageInterval { get; set; } = 10;
|
||||
|
||||
// Color settings
|
||||
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]";
|
||||
}
|
||||
public class ColorData
|
||||
{
|
||||
public List<ColorInfo> Colors { get; set; } = new List<ColorInfo>();
|
||||
}
|
||||
|
||||
public class ColorInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Scalar Upper { get; set; }
|
||||
public Scalar Lower { get; set; }
|
||||
public ColorInfo(string name, Scalar upper, Scalar lower)
|
||||
{
|
||||
Name = name;
|
||||
Upper = upper;
|
||||
Lower = lower;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Costura />
|
||||
</Weavers>
|
||||
+109
-7
@@ -1,5 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Spectrum
|
||||
{
|
||||
@@ -10,13 +9,14 @@ namespace Spectrum
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool GetCursorPos(out POINT lpPoint);
|
||||
private static ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
||||
|
||||
private struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
}
|
||||
// AIMMY V2 CODE - https://github.com/babyhamsta/Aimmy/blob/Aimmy-V2/Aimmy2/InputLogic/MouseManager.cs Line 34 - 50
|
||||
// AIMMY V2 CODE - https://github.com/Babyhamsta/Aimmy/blob/2e906552673e359ded90383c5e97d79c8f38a2f2/Aimmy2/InputLogic/MouseManager.cs#L34-L50
|
||||
private static Point CubicBezier(Point start, Point end, Point control1, Point control2, double t)
|
||||
{
|
||||
double u = 1 - t;
|
||||
@@ -28,11 +28,53 @@ namespace Spectrum
|
||||
|
||||
return new Point((int)x, (int)y);
|
||||
}
|
||||
private static Point CubicBezierMovement(Point start, Point end, double t)
|
||||
{
|
||||
Point control1 = new Point(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
|
||||
Point control2 = new Point(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
|
||||
return CubicBezier(start, end, control1, control2, t);
|
||||
}
|
||||
|
||||
private static Point LinearInterpolation(Point start, Point end, double t)
|
||||
{
|
||||
int x = (int)(start.X + t * (end.X - start.X));
|
||||
int y = (int)(start.Y + t * (end.Y - start.Y));
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
private static Point CurvedMovement(Point start, Point end, double t)
|
||||
{
|
||||
Point control = new Point((start.X + end.X) / 2, (start.Y + end.Y) / 2 - 200);
|
||||
return QuadraticBezier(start, end, control, t);
|
||||
}
|
||||
private static Point QuadraticBezier(Point start, Point end, Point control, double t)
|
||||
{
|
||||
double u = 1 - t;
|
||||
double tt = t * t;
|
||||
double uu = u * u;
|
||||
double x = uu * start.X + 2 * u * t * control.X + tt * end.X;
|
||||
double y = uu * start.Y + 2 * u * t * control.Y + tt * end.Y;
|
||||
return new Point((int)x, (int)y);
|
||||
}
|
||||
|
||||
private static Point AdaptiveMovement(Point start, Point end, double sensitivity)
|
||||
{
|
||||
double distance = Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2));
|
||||
double stepSize = distance * sensitivity;
|
||||
|
||||
double directionX = (end.X - start.X) / distance;
|
||||
double directionY = (end.Y - start.Y) / distance;
|
||||
|
||||
int newX = (int)(start.X + directionX * stepSize);
|
||||
int newY = (int)(start.Y + directionY * stepSize);
|
||||
return new Point(newX, newY);
|
||||
}
|
||||
private static double EmaSmoothing(double previousValue, double currentValue, double smoothingFactor) => (currentValue * smoothingFactor) + (previousValue * (1 - smoothingFactor));
|
||||
|
||||
public static void MoveMouse(Point target)
|
||||
{
|
||||
POINT reference = new POINT();
|
||||
if (Config.ClosestToMouse)
|
||||
if (mainConfig.Data.ClosestToMouse)
|
||||
{
|
||||
GetCursorPos(out reference);
|
||||
}
|
||||
@@ -47,15 +89,75 @@ namespace Spectrum
|
||||
|
||||
Point start = new Point(reference.X, reference.Y);
|
||||
Point end = new Point(target.X, target.Y);
|
||||
Point control1 = new(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
|
||||
Point control2 = new(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
|
||||
Point newPosition = CubicBezier(start, end, control1, control2, Config.Sensitivity);
|
||||
Point newPosition = mainConfig.Data.AimMovementType switch
|
||||
{
|
||||
MovementType.CubicBezier => CubicBezierMovement(start, end, mainConfig.Data.Sensitivity),
|
||||
MovementType.Linear => LinearInterpolation(start, end, mainConfig.Data.Sensitivity),
|
||||
MovementType.Adaptive => AdaptiveMovement(start, end, mainConfig.Data.Sensitivity),
|
||||
MovementType.QuadraticBezier => CurvedMovement(start, end, mainConfig.Data.Sensitivity),
|
||||
_ => end
|
||||
};
|
||||
|
||||
if (mainConfig.Data.EmaSmoothening)
|
||||
{
|
||||
newPosition.X = (int)EmaSmoothing(reference.X, newPosition.X, mainConfig.Data.EmaSmootheningFactor);
|
||||
newPosition.Y = (int)EmaSmoothing(reference.Y, newPosition.Y, mainConfig.Data.EmaSmootheningFactor);
|
||||
}
|
||||
|
||||
int deltaX = newPosition.X - reference.X;
|
||||
int deltaY = newPosition.Y - reference.Y;
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
|
||||
mouse_event(0x0001, (uint)(deltaX), (uint)(deltaY), 0, 0);
|
||||
}
|
||||
[DllImport("user32.dll")]
|
||||
private static extern short GetAsyncKeyState(int vKey);
|
||||
|
||||
private static readonly Keys[] MouseKeys =
|
||||
{
|
||||
Keys.LButton, Keys.RButton, Keys.MButton, Keys.XButton1, Keys.XButton2
|
||||
};
|
||||
|
||||
public static Task<Keys> ListenForNextKeyOrMouseAsync(CancellationToken? cancellationToken = null)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<Keys>();
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
for (int key = 0x08; key <= 0xFE; key++)
|
||||
{
|
||||
if ((GetAsyncKeyState(key) & 0x8000) != 0)
|
||||
{
|
||||
tcs.TrySetResult((Keys)key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (var mouseKey in MouseKeys)
|
||||
{
|
||||
if ((GetAsyncKeyState((int)mouseKey) & 0x8000) != 0)
|
||||
{
|
||||
tcs.TrySetResult(mouseKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (cancellationToken?.IsCancellationRequested == true)
|
||||
{
|
||||
tcs.TrySetCanceled();
|
||||
return;
|
||||
}
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
})
|
||||
{
|
||||
IsBackground = true
|
||||
};
|
||||
thread.Start();
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Spectrum
|
||||
{
|
||||
public class LogManager
|
||||
{
|
||||
public enum LogLevel
|
||||
{
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Critical
|
||||
}
|
||||
public class LogEntry
|
||||
{
|
||||
public DateTime Timestamp { get; set; }
|
||||
public LogLevel Level { get; set; }
|
||||
public string Message { get; set; }
|
||||
public LogEntry(LogLevel level, string message)
|
||||
{
|
||||
Timestamp = DateTime.Now;
|
||||
Level = level;
|
||||
Message = message;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{Timestamp:yyyy-MM-dd HH:mm:ss}] [{Level}] {Message}";
|
||||
}
|
||||
}
|
||||
private static List<LogEntry> _logEntries = new List<LogEntry>();
|
||||
public static IReadOnlyList<LogEntry> LogEntries => _logEntries.AsReadOnly();
|
||||
public static void Log(string message, LogLevel level = LogLevel.Info)
|
||||
{
|
||||
string logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}";
|
||||
Debug.WriteLine(logMessage);
|
||||
_logEntries.Add(new LogEntry(level, message));
|
||||
}
|
||||
public static void SaveLog(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var logContent = new StringBuilder();
|
||||
foreach (var entry in _logEntries)
|
||||
{
|
||||
logContent.AppendLine(entry.ToString());
|
||||
}
|
||||
File.WriteAllText(filePath, logContent.ToString());
|
||||
Log($"Log saved to {filePath}", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Failed to save log: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
public static void ClearLog()
|
||||
{
|
||||
_logEntries.Clear();
|
||||
Log("Log cleared.", LogLevel.Info);
|
||||
}
|
||||
|
||||
public static void OpenLogFolder()
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "explorer.exe",
|
||||
Arguments = Directory.GetCurrentDirectory(),
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+207
-54
@@ -1,6 +1,4 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Internal.Vectors;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -9,75 +7,94 @@ namespace Spectrum
|
||||
class Program
|
||||
{
|
||||
static Rectangle bounds = new Rectangle(0, 0, 0, 0);
|
||||
static Renderer? renderer = null;
|
||||
private static DateTime lastMenuToggle = DateTime.MinValue;
|
||||
public static ConfigManager<ConfigData> mainConfig = new ConfigManager<ConfigData>("bin\\configs\\config.json");
|
||||
public static ConfigManager<ColorData> colorConfig = new ConfigManager<ColorData>("bin\\configs\\colors.json");
|
||||
static void Main()
|
||||
{
|
||||
Config.LoadConfig();
|
||||
var screenSize = SystemHelper.GetPrimaryScreenSize();
|
||||
bounds = new Rectangle(
|
||||
(screenSize.Width - Config.ImageWidth) / 2,
|
||||
(screenSize.Height - Config.ImageHeight) / 2,
|
||||
Config.ImageWidth,
|
||||
Config.ImageHeight
|
||||
);
|
||||
Thread renderThread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
renderer = new Renderer();
|
||||
renderer.Run();
|
||||
LogManager.Log("Renderer started successfully.", LogManager.LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log($"Failed to start renderer: {ex.Message}", LogManager.LogLevel.Error);
|
||||
}
|
||||
});
|
||||
renderThread.Start();
|
||||
|
||||
if (Config.ShowDetectionWindow)
|
||||
mainConfig.LoadConfig();
|
||||
mainConfig.StartFileWatcher();
|
||||
|
||||
var screenSize = SystemHelper.GetPrimaryScreenSize();
|
||||
|
||||
if (mainConfig.Data.ShowDetectionWindow)
|
||||
{
|
||||
Cv2.NamedWindow("Spectrum Detection", WindowFlags.AutoSize);
|
||||
Cv2.WaitKey(1);
|
||||
}
|
||||
if (Config.AutoLabel)
|
||||
if (mainConfig.Data.AutoLabel)
|
||||
{
|
||||
AutoLabeling.StartLabeling();
|
||||
}
|
||||
|
||||
Directory.CreateDirectory("dataset");
|
||||
Directory.CreateDirectory("dataset/images");
|
||||
Directory.CreateDirectory("dataset/labels");
|
||||
Directory.CreateDirectory("bin");
|
||||
Directory.CreateDirectory("bin/dataset");
|
||||
Directory.CreateDirectory("bin/dataset/images");
|
||||
Directory.CreateDirectory("bin/dataset/labels");
|
||||
Directory.CreateDirectory("bin/logs");
|
||||
Directory.CreateDirectory("bin/configs");
|
||||
|
||||
if (colorConfig.Data.Colors.Count == 0)
|
||||
{
|
||||
colorConfig.Data.Colors.Add(new ColorInfo("Arsenal [Magenta]", new Scalar(150, 255, 229), new Scalar(150, 255, 229)));
|
||||
colorConfig.Data.Colors.Add(new ColorInfo("Combat Surf [Red]", new Scalar(0, 255, 255), new Scalar(0, 255, 255)));
|
||||
colorConfig.SaveConfig();
|
||||
colorConfig.LoadConfig(true);
|
||||
mainConfig.LoadConfig(true);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (Console.KeyAvailable)
|
||||
{
|
||||
var key = Console.ReadKey(true).Key;
|
||||
if (key == ConsoleKey.Escape)
|
||||
{
|
||||
if (Config.ShowDetectionWindow)
|
||||
{
|
||||
Cv2.DestroyAllWindows();
|
||||
}
|
||||
}
|
||||
else if (key == ConsoleKey.F5 || key == ConsoleKey.R)
|
||||
{
|
||||
Config.LoadConfig(true);
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("[INFO] Configuration reloaded.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
if (SystemHelper.GetAsyncKeyState(Config.Keybind) < 0)
|
||||
if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.Keybind) < 0)
|
||||
{
|
||||
bounds = new Rectangle(
|
||||
(screenSize.Width - mainConfig.Data.ImageWidth) / 2,
|
||||
(screenSize.Height - mainConfig.Data.ImageHeight) / 2,
|
||||
mainConfig.Data.ImageWidth,
|
||||
mainConfig.Data.ImageHeight
|
||||
);
|
||||
var screenshot = CaptureScreenshot(bounds);
|
||||
Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(screenshot);
|
||||
Mat drawing = mat.Clone(); // clone for drawing
|
||||
Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2HSV); // convert to hsv
|
||||
Cv2.InRange(mat, Config.LowerHSV, Config.UpperHSV, mat); // apply mask
|
||||
Cv2.Dilate(mat, mat, null, iterations: 2); // dilate to fill gaps
|
||||
Cv2.Threshold(mat, mat, 127, 255, ThresholdTypes.Binary); // threshold to binary
|
||||
Mat drawing = mat.Clone();
|
||||
Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2HSV);
|
||||
Cv2.InRange(mat, mainConfig.Data.LowerHSV, mainConfig.Data.UpperHSV, mat);
|
||||
Cv2.Dilate(mat, mat, null, iterations: 2);
|
||||
Cv2.Threshold(mat, mat, 127, 255, ThresholdTypes.Binary);
|
||||
|
||||
Cv2.FindContours(mat, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
|
||||
|
||||
var filteredContours = contours.Where(c => Cv2.ContourArea(c) >= 100).ToArray();
|
||||
if (filteredContours.Length > 0)
|
||||
|
||||
var mergedContours = MergeOverlappingContours(filteredContours);
|
||||
|
||||
var processedContours = mergedContours.Select(ShrinkWideContour).ToArray();
|
||||
|
||||
if (processedContours.Length > 0)
|
||||
{
|
||||
int refX = bounds.X + bounds.Width / 2;
|
||||
int refY = bounds.Y + (int)(bounds.Height * Config.YOffsetPercent);
|
||||
int refY = bounds.Y + (int)(bounds.Height * mainConfig.Data.YOffsetPercent);
|
||||
|
||||
double minDist = double.MaxValue;
|
||||
OpenCvSharp.Point[]? closestContour = null;
|
||||
int bestMinX = 0, bestMinY = 0, bestMaxX = 0, bestMaxY = 0;
|
||||
|
||||
foreach (var contour in filteredContours)
|
||||
foreach (var contour in processedContours)
|
||||
{
|
||||
int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
|
||||
foreach (var point in contour)
|
||||
@@ -103,55 +120,191 @@ namespace Spectrum
|
||||
bestMaxX = maxX;
|
||||
bestMaxY = maxY;
|
||||
}
|
||||
|
||||
if (renderer != null && mainConfig.Data.DrawDetections)
|
||||
{
|
||||
var _rect = new Rectangle(
|
||||
minX + bounds.X,
|
||||
minY + bounds.Y,
|
||||
(maxX - minX + 1),
|
||||
(maxY - minY + 1)
|
||||
);
|
||||
renderer.AddRect(_rect, mainConfig.Data.DetectionColor, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (closestContour != null)
|
||||
{
|
||||
int groupX = (int)(bestMinX + (bestMaxX - bestMinX) * (1.0 - Config.XOffsetPercent));
|
||||
int groupY = (int)(bestMinY + (bestMaxY - bestMinY) * (1.0 - Config.YOffsetPercent));
|
||||
int groupX = (int)(bestMinX + (bestMaxX - bestMinX) * (1.0 - mainConfig.Data.XOffsetPercent));
|
||||
int groupY = (int)(bestMinY + (bestMaxY - bestMinY) * (1.0 - mainConfig.Data.YOffsetPercent));
|
||||
int targetX = groupX + bounds.X;
|
||||
int targetY = groupY + bounds.Y;
|
||||
|
||||
if (Config.AutoLabel)
|
||||
if (mainConfig.Data.AutoLabel)
|
||||
{
|
||||
AutoLabeling.AddToQueue(drawing, bounds, filteredContours);
|
||||
AutoLabeling.AddToQueue(drawing, bounds, processedContours);
|
||||
AutoLabeling.AddBackgroundImage(drawing, true);
|
||||
}
|
||||
if (!mainConfig.Data.AutoLabel && mainConfig.Data.CollectData)
|
||||
{
|
||||
AutoLabeling.AddBackgroundImage(drawing, false);
|
||||
}
|
||||
|
||||
if (Config.EnableAim)
|
||||
if (mainConfig.Data.EnableAim)
|
||||
{
|
||||
InputManager.MoveMouse(new System.Drawing.Point(targetX, targetY));
|
||||
}
|
||||
|
||||
if (Config.ShowDetectionWindow)
|
||||
if (mainConfig.Data.ShowDetectionWindow)
|
||||
{
|
||||
Cv2.DrawContours(drawing, filteredContours, -1, Scalar.Red, 2);
|
||||
Cv2.Rectangle(drawing, new OpenCvSharp.Point(bestMinX, bestMinY), new OpenCvSharp.Point(bestMaxX, bestMaxY), Scalar.Blue, 2);
|
||||
Cv2.ImShow("Spectrum Detection", drawing);
|
||||
Cv2.WaitKey(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Config.ShowDetectionWindow)
|
||||
else if (mainConfig.Data.ShowDetectionWindow || mainConfig.Data.CollectData)
|
||||
{
|
||||
Cv2.ImShow("Spectrum Detection", drawing);
|
||||
Cv2.WaitKey(1);
|
||||
if (mainConfig.Data.CollectData)
|
||||
AutoLabeling.AddBackgroundImage(drawing, false);
|
||||
}
|
||||
screenshot?.Dispose();
|
||||
mat.Dispose();
|
||||
drawing.Dispose();
|
||||
}
|
||||
else if (SystemHelper.GetAsyncKeyState(0x2D) < 0)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
if ((now - lastMenuToggle).TotalMilliseconds > 200)
|
||||
{
|
||||
mainConfig.Data.ShowMenu = !mainConfig.Data.ShowMenu;
|
||||
lastMenuToggle = now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Config.ShowDetectionWindow)
|
||||
if (mainConfig.Data.ShowDetectionWindow)
|
||||
{
|
||||
Cv2.WaitKey(1);
|
||||
}
|
||||
else
|
||||
else if (!mainConfig.Data.ShowDetectionWindow)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
if (Cv2.GetWindowProperty("Spectrum Detection", WindowPropertyFlags.Visible) >= 0)
|
||||
{
|
||||
Cv2.DestroyAllWindows();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static OpenCvSharp.Point[][] MergeOverlappingContours(OpenCvSharp.Point[][] contours)
|
||||
{
|
||||
var contourRects = new List<(Rect rect, List<int> indices)>();
|
||||
for (int i = 0; i < contours.Length; i++)
|
||||
{
|
||||
var rect = Cv2.BoundingRect(contours[i]);
|
||||
contourRects.Add((rect, new List<int> { i }));
|
||||
}
|
||||
bool merged;
|
||||
do
|
||||
{
|
||||
merged = false;
|
||||
for (int i = 0; i < contourRects.Count; i++)
|
||||
{
|
||||
var (rectA, indicesA) = contourRects[i];
|
||||
for (int j = i + 1; j < contourRects.Count; j++)
|
||||
{
|
||||
var (rectB, indicesB) = contourRects[j];
|
||||
if (rectA.IntersectsWith(rectB))
|
||||
{
|
||||
var newRect = new Rect(
|
||||
Math.Min(rectA.X, rectB.X),
|
||||
Math.Min(rectA.Y, rectB.Y),
|
||||
Math.Max(rectA.X + rectA.Width, rectB.X + rectB.Width) - Math.Min(rectA.X, rectB.X),
|
||||
Math.Max(rectA.Y + rectA.Height, rectB.Y + rectB.Height) - Math.Min(rectA.Y, rectB.Y)
|
||||
);
|
||||
var newIndices = new List<int>();
|
||||
newIndices.AddRange(indicesA);
|
||||
newIndices.AddRange(indicesB);
|
||||
contourRects[i] = (newRect, newIndices);
|
||||
contourRects.RemoveAt(j);
|
||||
merged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (merged) break;
|
||||
}
|
||||
} while (merged);
|
||||
|
||||
var mergedContours = new List<OpenCvSharp.Point[]>();
|
||||
foreach (var (rect, indices) in contourRects)
|
||||
{
|
||||
var points = new List<OpenCvSharp.Point>();
|
||||
foreach (var idx in indices)
|
||||
{
|
||||
points.AddRange(contours[idx]);
|
||||
}
|
||||
var hull = Cv2.ConvexHull(points);
|
||||
mergedContours.Add(hull);
|
||||
}
|
||||
return mergedContours.ToArray();
|
||||
}
|
||||
|
||||
static OpenCvSharp.Point[] ShrinkWideContour(OpenCvSharp.Point[] contour)
|
||||
{
|
||||
var rect = Cv2.BoundingRect(contour);
|
||||
double aspect = rect.Width / (double)rect.Height;
|
||||
if (aspect <= 1.2)
|
||||
return contour;
|
||||
|
||||
int[] xs = contour.Select(p => p.X).ToArray();
|
||||
int minX = xs.Min();
|
||||
int maxX = xs.Max();
|
||||
|
||||
int binCount = Math.Max(10, (maxX - minX + 1) / 5);
|
||||
int[] bins = new int[binCount];
|
||||
int binWidth = (int)Math.Ceiling((maxX - minX + 1) / (double)binCount);
|
||||
|
||||
foreach (var pt in contour)
|
||||
{
|
||||
int binIdx = (pt.X - minX) / binWidth;
|
||||
if (binIdx < 0) binIdx = 0;
|
||||
if (binIdx >= binCount) binIdx = binCount - 1;
|
||||
bins[binIdx]++;
|
||||
}
|
||||
|
||||
int maxMass = bins.Max();
|
||||
int left = 0, right = binCount - 1;
|
||||
for (int i = 0; i < binCount; i++)
|
||||
{
|
||||
if (bins[i] == maxMass)
|
||||
{
|
||||
left = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = binCount - 1; i >= 0; i--)
|
||||
{
|
||||
if (bins[i] == maxMass)
|
||||
{
|
||||
right = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int cropMinX = minX + left * binWidth;
|
||||
int cropMaxX = minX + (right + 1) * binWidth - 1;
|
||||
|
||||
var shrunken = contour.Where(p => p.X >= cropMinX && p.X <= cropMaxX).ToArray();
|
||||
if (shrunken.Length < 3)
|
||||
return contour;
|
||||
|
||||
return Cv2.ConvexHull(shrunken);
|
||||
}
|
||||
|
||||
public static Bitmap CaptureScreenshot(Rectangle bounds)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
|
||||
|
||||
@@ -0,0 +1,510 @@
|
||||
using ClickableTransparentOverlay;
|
||||
using ImGuiNET;
|
||||
using OpenCvSharp;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Spectrum
|
||||
{
|
||||
class Renderer : Overlay
|
||||
{
|
||||
static (int width, int height) screenSize = SystemHelper.GetPrimaryScreenSize();
|
||||
private List<Action<ImDrawListPtr>> drawCommands = new List<Action<ImDrawListPtr>>();
|
||||
private readonly object drawCommandsLock = new object();
|
||||
|
||||
private bool _vsync = true;
|
||||
private int _fpsLimit = 240;
|
||||
private Keys _pendingKeybind = Keys.None;
|
||||
private bool _waitingForKeybind = false;
|
||||
private Task? _keybindTask = null;
|
||||
private readonly ConcurrentQueue<Keys> _keybindResults = new();
|
||||
private ConfigManager<ConfigData> mainConfig = Program.mainConfig;
|
||||
private ConfigManager<ColorData> colorConfig = Program.colorConfig;
|
||||
|
||||
public Renderer() : base("Spectrum", screenSize.width, screenSize.width)
|
||||
{
|
||||
VSync = _vsync;
|
||||
FPSLimit = _fpsLimit;
|
||||
ImGui.CreateContext();
|
||||
var io = ImGui.GetIO();
|
||||
io.Fonts.Clear();
|
||||
io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\Arial.ttf", 16.0f);
|
||||
}
|
||||
override protected void Render()
|
||||
{
|
||||
if (mainConfig.Data.DrawDetections || mainConfig.Data.DrawFOV)
|
||||
RenderOverlay();
|
||||
if (!mainConfig.Data.ShowMenu)
|
||||
return;
|
||||
|
||||
AddStyling();
|
||||
|
||||
ImGui.SetNextWindowSize(new Vector2(600, 500), ImGuiCond.FirstUseEver);
|
||||
ImGui.SetNextWindowPos(new Vector2(screenSize.width / 2 - 300, screenSize.height / 2 - 250), ImGuiCond.FirstUseEver);
|
||||
ImGui.SetNextWindowSizeConstraints(new Vector2(600, 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);
|
||||
}
|
||||
|
||||
ImGui.BeginTabBar("##tabs");
|
||||
if (ImGui.BeginTabItem("Aiming"))
|
||||
{
|
||||
bool enableAiming = mainConfig.Data.EnableAim;
|
||||
if (ImGui.Checkbox("##Enable Aiming", ref enableAiming))
|
||||
{
|
||||
mainConfig.Data.EnableAim = enableAiming;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (!_waitingForKeybind)
|
||||
{
|
||||
if (ImGui.Button(mainConfig.Data.Keybind.ToString()))
|
||||
{
|
||||
_waitingForKeybind = true;
|
||||
_pendingKeybind = Keys.None;
|
||||
_keybindTask = Task.Run(async () =>
|
||||
{
|
||||
var key = await InputManager.ListenForNextKeyOrMouseAsync();
|
||||
_pendingKeybind = key;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.Button("Listening...");
|
||||
if (_pendingKeybind != Keys.None)
|
||||
{
|
||||
mainConfig.Data.Keybind = _pendingKeybind;
|
||||
_pendingKeybind = Keys.None;
|
||||
_waitingForKeybind = false;
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.Text("Enable Aiming");
|
||||
|
||||
bool closestToMouse = mainConfig.Data.ClosestToMouse;
|
||||
if (ImGui.Checkbox("Closest to Mouse", ref closestToMouse))
|
||||
{
|
||||
mainConfig.Data.ClosestToMouse = closestToMouse;
|
||||
}
|
||||
|
||||
float sensitivity = (float)mainConfig.Data.Sensitivity;
|
||||
if (ImGui.SliderFloat("Sensitivity", ref sensitivity, 0.1f, 2.0f, "%.1f"))
|
||||
{
|
||||
mainConfig.Data.Sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
float EmaSmootheningFactor = (float)mainConfig.Data.EmaSmootheningFactor;
|
||||
bool EmaSmoothening = mainConfig.Data.EmaSmoothening;
|
||||
if (ImGui.Checkbox("Ema Smoothening", ref EmaSmoothening))
|
||||
{
|
||||
mainConfig.Data.EmaSmoothening = EmaSmoothening;
|
||||
}
|
||||
|
||||
if (ImGui.SliderFloat("Ema Smoothening Factor", ref EmaSmootheningFactor, 0.01f, 1.0f, "%.2f"))
|
||||
{
|
||||
mainConfig.Data.EmaSmootheningFactor = EmaSmootheningFactor;
|
||||
}
|
||||
|
||||
MovementType AimPath = mainConfig.Data.AimMovementType;
|
||||
if (ImGui.BeginCombo("Movement Type", AimPath.ToString()))
|
||||
{
|
||||
foreach (MovementType type in Enum.GetValues(typeof(MovementType)))
|
||||
{
|
||||
bool isSelected = (type == AimPath);
|
||||
if (ImGui.Selectable(type.ToString(), isSelected))
|
||||
{
|
||||
mainConfig.Data.AimMovementType = type;
|
||||
}
|
||||
if (isSelected)
|
||||
{
|
||||
ImGui.SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
int YOffset = (int)(mainConfig.Data.YOffsetPercent * 100);
|
||||
if (ImGui.SliderInt("Y Offset (%)", ref YOffset, 0, 100, "%d%%"))
|
||||
{
|
||||
mainConfig.Data.YOffsetPercent = ((double)YOffset / 100);
|
||||
}
|
||||
|
||||
int XOffset = (int)(mainConfig.Data.XOffsetPercent * 100);
|
||||
if (ImGui.SliderInt("X Offset (%)", ref XOffset, 0, 100, "%d%%"))
|
||||
{
|
||||
mainConfig.Data.XOffsetPercent = ((double)XOffset / 100);
|
||||
}
|
||||
|
||||
ImGui.SeparatorText("Overlay Settings");
|
||||
|
||||
bool DrawFOV = mainConfig.Data.DrawFOV;
|
||||
if (ImGui.Checkbox("##Draw FOV", ref DrawFOV))
|
||||
{
|
||||
mainConfig.Data.DrawFOV = DrawFOV;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
Vector4 FOVColor = mainConfig.Data.FOVColor;
|
||||
if (ImGui.ColorEdit4("FOV Color", ref FOVColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
||||
{
|
||||
mainConfig.Data.FOVColor = FOVColor;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.Text("Draw FOV");
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Detection"))
|
||||
{
|
||||
int ImageWidth = mainConfig.Data.ImageWidth;
|
||||
if (ImGui.InputInt("Image Width", ref ImageWidth, 1, screenSize.width))
|
||||
{
|
||||
if (ImageWidth < 1)
|
||||
ImageWidth = 1;
|
||||
else if (ImageWidth > screenSize.width)
|
||||
ImageWidth = screenSize.width;
|
||||
mainConfig.Data.ImageWidth = ImageWidth;
|
||||
}
|
||||
|
||||
int ImageHeight = mainConfig.Data.ImageHeight;
|
||||
if (ImGui.InputInt("Image Height", ref ImageHeight, 1, screenSize.height))
|
||||
{
|
||||
if (ImageHeight < 1)
|
||||
ImageHeight = 1;
|
||||
else if (ImageHeight > screenSize.height)
|
||||
ImageHeight = screenSize.height;
|
||||
mainConfig.Data.ImageHeight = ImageHeight;
|
||||
}
|
||||
|
||||
Scalar UpperHSV = mainConfig.Data.UpperHSV;
|
||||
Vector3 UpperHSVVec3 = new Vector3((float)UpperHSV.Val0, (float)UpperHSV.Val1, (float)UpperHSV.Val2);
|
||||
if (ImGui.InputFloat3("Upper HSV", ref UpperHSVVec3, "%.0f", ImGuiInputTextFlags.CharsDecimal))
|
||||
{
|
||||
mainConfig.Data.UpperHSV = new Scalar(UpperHSVVec3.X, UpperHSVVec3.Y, UpperHSVVec3.Z);
|
||||
}
|
||||
|
||||
|
||||
Scalar LowerHSV = mainConfig.Data.LowerHSV;
|
||||
Vector3 LowerHSVVec3 = new Vector3((float)LowerHSV.Val0, (float)LowerHSV.Val1, (float)LowerHSV.Val2);
|
||||
if (ImGui.InputFloat3("Lower HSV", ref LowerHSVVec3, "%.0f", ImGuiInputTextFlags.CharsDecimal))
|
||||
{
|
||||
mainConfig.Data.LowerHSV = new Scalar(LowerHSVVec3.X, LowerHSVVec3.Y, LowerHSVVec3.Z);
|
||||
}
|
||||
|
||||
List<ColorInfo> colors = colorConfig.Data.Colors;
|
||||
if (colors.Count != 0)
|
||||
{
|
||||
if (ImGui.BeginCombo("Colors", mainConfig.Data.SelectedColor))
|
||||
{
|
||||
foreach (ColorInfo color in colors)
|
||||
{
|
||||
bool isSelected = (color.Name == mainConfig.Data.SelectedColor);
|
||||
if (ImGui.Selectable(color.Name, isSelected))
|
||||
{
|
||||
mainConfig.Data.SelectedColor = color.Name;
|
||||
mainConfig.Data.UpperHSV = color.Upper;
|
||||
mainConfig.Data.LowerHSV = color.Lower;
|
||||
}
|
||||
if (isSelected)
|
||||
{
|
||||
ImGui.SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
}
|
||||
|
||||
bool DrawDetections = mainConfig.Data.DrawDetections;
|
||||
if (ImGui.Checkbox("##Draw Detections", ref DrawDetections))
|
||||
{
|
||||
mainConfig.Data.DrawDetections = DrawDetections;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
Vector4 DetectionColor = mainConfig.Data.DetectionColor;
|
||||
if (ImGui.ColorEdit4("Draw Color", ref DetectionColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoLabel))
|
||||
{
|
||||
mainConfig.Data.DetectionColor = DetectionColor;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.Text("Draw Detections");
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Misc."))
|
||||
{
|
||||
bool ShowDetectionWindow = mainConfig.Data.ShowDetectionWindow;
|
||||
if (ImGui.Checkbox("Show Detection Window", ref ShowDetectionWindow))
|
||||
{
|
||||
mainConfig.Data.ShowDetectionWindow = ShowDetectionWindow;
|
||||
}
|
||||
|
||||
bool CollectData = mainConfig.Data.CollectData;
|
||||
if (ImGui.Checkbox("Collect Data", ref CollectData))
|
||||
{
|
||||
mainConfig.Data.CollectData = CollectData;
|
||||
}
|
||||
|
||||
bool AutoLabel = mainConfig.Data.AutoLabel;
|
||||
if (ImGui.Checkbox("Auto Label", ref AutoLabel))
|
||||
{
|
||||
if (!CollectData && AutoLabel)
|
||||
mainConfig.Data.CollectData = true;
|
||||
|
||||
mainConfig.Data.AutoLabel = AutoLabel;
|
||||
}
|
||||
|
||||
int BackgroundImageInterval = mainConfig.Data.BackgroundImageInterval;
|
||||
if (ImGui.InputInt("Background Image Interval", ref BackgroundImageInterval, 1, 500))
|
||||
{
|
||||
if (BackgroundImageInterval < 1)
|
||||
BackgroundImageInterval = 1;
|
||||
else if (BackgroundImageInterval > 500)
|
||||
BackgroundImageInterval = 500;
|
||||
|
||||
mainConfig.Data.BackgroundImageInterval = BackgroundImageInterval;
|
||||
}
|
||||
|
||||
|
||||
if (ImGui.Checkbox("VSync", ref _vsync))
|
||||
{
|
||||
VSync = _vsync;
|
||||
}
|
||||
|
||||
if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d"))
|
||||
{
|
||||
FPSLimit = _fpsLimit;
|
||||
}
|
||||
|
||||
if (ImGui.Button("Save Configs"))
|
||||
{
|
||||
mainConfig.SaveConfig();
|
||||
colorConfig.SaveConfig();
|
||||
}
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Open Folder"))
|
||||
{
|
||||
string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "bin\\configs");
|
||||
if (Directory.Exists(folderPath))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "explorer.exe",
|
||||
Arguments = folderPath,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Log($"Directory doesnt exist: {folderPath}", LogManager.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
ImGui.SeparatorText("Logs");
|
||||
|
||||
ImGui.BeginChild("Logs", new Vector2(0, -34));
|
||||
ImGui.Dummy(new Vector2(0, 4));
|
||||
|
||||
var _LogEntries = LogManager.LogEntries.ToList();
|
||||
foreach (var log in _LogEntries)
|
||||
{
|
||||
ImGui.Indent(8);
|
||||
ImGui.Text(log.ToString());
|
||||
ImGui.Unindent(8);
|
||||
}
|
||||
|
||||
ImGui.Dummy(new Vector2(0, 4));
|
||||
ImGui.EndChild();
|
||||
ImGui.Dummy(new Vector2(0, 1));
|
||||
|
||||
if (ImGui.Button("Save Logs"))
|
||||
{
|
||||
LogManager.SaveLog($"bin\\logs\\{DateTime.Now.ToString("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();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
ImGui.EndTabBar();
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (mainConfig.Data.DrawFOV)
|
||||
{
|
||||
AddRect(new Rectangle(
|
||||
((screenSize.width - mainConfig.Data.ImageWidth) / 2) - 1,
|
||||
((screenSize.height - mainConfig.Data.ImageHeight) / 2) - 1,
|
||||
mainConfig.Data.ImageWidth + 2,
|
||||
mainConfig.Data.ImageHeight + 2
|
||||
), mainConfig.Data.FOVColor);
|
||||
}
|
||||
|
||||
List<Action<ImDrawListPtr>> _drawCommands;
|
||||
lock (drawCommandsLock)
|
||||
{
|
||||
_drawCommands = drawCommands.ToList();
|
||||
drawCommands.Clear();
|
||||
}
|
||||
|
||||
foreach (var cmd in _drawCommands)
|
||||
{
|
||||
cmd?.Invoke(drawList);
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
private 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);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
public void AddRect(Rectangle rect, Vector4 color, float thickness = 1.0f)
|
||||
{
|
||||
lock (drawCommandsLock)
|
||||
{
|
||||
drawCommands.Add(drawList => drawList.AddRect(new Vector2(rect.Left, rect.Top), new Vector2(rect.Right, rect.Bottom), ColorFromVector4(color), 0, 0, thickness));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLine(Vector2 p1, Vector2 p2, Vector4 color, float thickness = 1.0f)
|
||||
{
|
||||
lock (drawCommandsLock)
|
||||
{
|
||||
drawCommands.Add(drawList => drawList.AddLine(p1, p2, ColorFromVector4(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 (drawCommandsLock)
|
||||
{
|
||||
drawCommands.Add(drawList => drawList.AddCircle(center, radius, ColorFromVector4(color), numSegments, thickness));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddText(Vector2 pos, Vector4 color, string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return;
|
||||
lock (drawCommandsLock)
|
||||
{
|
||||
drawCommands.Add(drawList => drawList.AddText(pos, ColorFromVector4(color), text));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<PublishAot>False</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<UseWindowsForms>True</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ClickableTransparentOverlay" Version="11.1.0" />
|
||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="OpenCvSharp4" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.6" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.10" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.2.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectrum", "Spectrum.csproj", "{C33459B7-8D67-9FB2-0CDB-25002B06AE60}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {44E9592E-6BC3-403A-9503-398EC3EFC57C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user