using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using ThreadPilot.Models;
namespace ThreadPilot.Services
{
///
/// Game classification confidence levels
///
public enum GameConfidenceLevel
{
VeryLow = 0, // 0-20%
Low = 1, // 20-40%
Medium = 2, // 40-60%
High = 3, // 60-80%
VeryHigh = 4 // 80-100%
}
///
/// Game detection result with confidence scoring
///
public class GameDetectionResult
{
public bool IsGame { get; set; }
public float Confidence { get; set; }
public GameConfidenceLevel ConfidenceLevel => Confidence switch
{
>= 0.8f => GameConfidenceLevel.VeryHigh,
>= 0.6f => GameConfidenceLevel.High,
>= 0.4f => GameConfidenceLevel.Medium,
>= 0.2f => GameConfidenceLevel.Low,
_ => GameConfidenceLevel.VeryLow
};
public string GameName { get; set; } = string.Empty;
public string DetectionMethod { get; set; } = string.Empty;
public Dictionary Features { get; set; } = new();
public DateTime DetectionTime { get; set; } = DateTime.UtcNow;
}
///
/// Real-time game performance metrics
///
public class GamePerformanceMetrics
{
public int ProcessId { get; set; }
public string GameName { get; set; } = string.Empty;
public float FrameRate { get; set; }
public double CpuUsage { get; set; }
public long MemoryUsage { get; set; }
public double GpuUsage { get; set; }
public long GpuMemoryUsage { get; set; }
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public bool IsFullscreen { get; set; }
public string Resolution { get; set; } = string.Empty;
}
///
/// Process features for ML classification
///
public class ProcessFeatures
{
public string ProcessName { get; set; } = string.Empty;
public string ExecutablePath { get; set; } = string.Empty;
public bool HasVisibleWindow { get; set; }
public bool IsFullscreen { get; set; }
public double CpuUsage { get; set; }
public long MemoryUsage { get; set; }
public int ThreadCount { get; set; }
public int HandleCount { get; set; }
public bool HasDirectXDlls { get; set; }
public bool HasOpenGLDlls { get; set; }
public bool HasVulkanDlls { get; set; }
public bool HasAudioDlls { get; set; }
public bool HasNetworkActivity { get; set; }
public string FileDescription { get; set; } = string.Empty;
public string CompanyName { get; set; } = string.Empty;
public bool IsInGamesFolder { get; set; }
public bool HasGameKeywords { get; set; }
public float WindowAspectRatio { get; set; }
public bool IsElevated { get; set; }
}
///
/// Service for detecting running games and applying optimal performance profiles
///
public interface IGameDetectionService
{
///
/// Detect if a process is a known game
///
Task DetectGameAsync(ProcessModel process);
///
/// Detect if a process is a game using ML classification
///
Task DetectGameWithMLAsync(ProcessModel process);
///
/// Extract features from a process for ML classification
///
Task ExtractProcessFeaturesAsync(ProcessModel process);
///
/// Get real-time performance metrics for a game
///
Task GetGamePerformanceAsync(ProcessModel process);
///
/// Get all currently running games
///
Task> GetRunningGamesAsync();
///
/// Apply optimal settings for a detected game
///
Task ApplyGameOptimizationsAsync(ProcessModel process, GameProfile gameProfile);
///
/// Check if a process is running through Steam
///
Task IsSteamGameAsync(ProcessModel process);
///
/// Check if a process is running through Epic Games Launcher
///
Task IsEpicGameAsync(ProcessModel process);
///
/// Get game profile for a Steam game
///
Task GetSteamGameProfileAsync(ProcessModel process);
///
/// Get game profile for an Epic Games game
///
Task GetEpicGameProfileAsync(ProcessModel process);
///
/// Add or update a custom game profile
///
Task AddCustomGameProfileAsync(string processName, GameProfile profile);
///
/// Remove a custom game profile
///
Task RemoveCustomGameProfileAsync(string processName);
///
/// Get all available game profiles
///
Task> GetAllGameProfilesAsync();
///
/// Event raised when a new game is detected
///
event EventHandler? GameDetected;
///
/// Event raised when a game stops running
///
event EventHandler? GameStopped;
}
///
/// Represents a game profile with optimal settings
///
public class GameProfile
{
public string Name { get; set; } = string.Empty;
public string ProcessName { get; set; } = string.Empty;
public string OptimalCores { get; set; } = "All"; // "All", "Physical", "P-Cores", "E-Cores", "Custom"
public ProcessPriorityClass Priority { get; set; } = ProcessPriorityClass.High;
public string? PowerPlan { get; set; }
public bool DisableFullscreenOptimizations { get; set; } = true;
public bool HighDpiAware { get; set; } = true;
public string? CustomAffinityMask { get; set; }
public Dictionary CustomSettings { get; set; } = new();
public DateTime LastDetected { get; set; }
public int DetectionCount { get; set; }
public string? SteamAppId { get; set; }
public string? EpicAppId { get; set; }
public GameCategory Category { get; set; } = GameCategory.Unknown;
public string? Description { get; set; }
}
///
/// Game categories for better organization
///
public enum GameCategory
{
Unknown,
FPS,
MOBA,
RTS,
RPG,
Racing,
Sports,
Simulation,
Strategy,
Action,
Adventure,
Indie
}
///
/// Event args for game profile detection
///
public class GameProfileDetectedEventArgs : EventArgs
{
public ProcessModel Process { get; }
public GameProfile GameProfile { get; }
public DateTime DetectedAt { get; }
public GameProfileDetectedEventArgs(ProcessModel process, GameProfile gameProfile)
{
Process = process;
GameProfile = gameProfile;
DetectedAt = DateTime.UtcNow;
}
}
///
/// Event args for game stopped
///
public class GameStoppedEventArgs : EventArgs
{
public string ProcessName { get; }
public GameProfile GameProfile { get; }
public DateTime StoppedAt { get; }
public TimeSpan PlayDuration { get; }
public GameStoppedEventArgs(string processName, GameProfile gameProfile, TimeSpan playDuration)
{
ProcessName = processName;
GameProfile = gameProfile;
StoppedAt = DateTime.UtcNow;
PlayDuration = playDuration;
}
}
}