game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_suggestion_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// game_suggestion_service.h
4// ==============================================================================
5// Smart game settings recommendation service
6// ==============================================================================
7// This service provides intelligent game launch setting recommendations based on:
8// - ProtonDB community reports and compatibility data
9// - Detected system hardware (GPU vendor, CPU, etc.)
10// - CachyOS-specific optimizations (if running on CachyOS)
11// - Known game-specific fixes and tweaks
12//
13// ## Data Sources
14// - ProtonDB API (protondb.com) - Community compatibility reports
15// - System detection (via SystemInfoService)
16// - Built-in game fix database
17//
18// ## Thread Safety
19// All methods are thread-safe.
20//
21// ## Usage Example
22// @code
23// auto suggestions = GameSuggestionService::getSuggestions(game);
24// if (suggestions.hasRecommendations()) {
25// // Show suggestions to user or auto-apply
26// }
27// @endcode
28// ==============================================================================
29
30#pragma once
31
32#include <chrono>
33#include <functional>
34#include <string>
35#include <unordered_map>
36#include <vector>
37
38// Forward declarations
39class Game;
41
42// ==============================================================================
43// Data Structures
44// ==============================================================================
45
46/**
47 * @enum SuggestionPriority
48 * @brief Priority level for suggestions
49 */
51{
52 Critical, // Required for the game to work
53 Recommended, // Strongly recommended for best experience
54 Optional, // Nice to have, may improve experience
55 Informational // Just FYI, no action needed
56};
57
58/**
59 * @enum SuggestionCategory
60 * @brief Category of the suggestion
61 */
63{
64 Runner, // Proton/Wine version recommendation
65 Environment, // Environment variable
66 Performance, // Performance optimization (MangoHud, GameMode, etc.)
67 Compatibility, // Compatibility fix
68 Graphics, // Graphics settings (FSR, VKBasalt, etc.)
69 Audio, // Audio fixes
70 Input, // Controller/input fixes
71 General // General advice
72};
73
74/**
75 * @struct GameSuggestion
76 * @brief A single setting recommendation
77 */
79{
82
83 std::string title; // Short title (e.g., "Use Proton GE")
84 std::string description; // Detailed description
85 std::string reason; // Why this is suggested (e.g., "Fixes cutscene playback")
86
87 // For environment variables
88 std::string envKey; // e.g., "PROTON_USE_WINED3D"
89 std::string envValue; // e.g., "1"
90
91 // For runner suggestions
92 std::string recommendedRunner; // e.g., "GE-Proton8-25"
93
94 // For DLL overrides
95 std::string dllOverrides; // e.g., "d3d11=native,builtin"
96
97 // For launch arguments
98 std::string launchArgs; // e.g., "-dx11"
99
100 // Source of the suggestion
101 std::string source; // e.g., "ProtonDB", "CachyOS Wiki", "Built-in"
102 int reportCount = 0; // Number of reports supporting this (from ProtonDB)
103
104 // Is this automatically applicable?
105 bool canAutoApply = false;
106};
107
108/**
109 * @enum ConfidenceLevel
110 * @brief How confident we are that our recommendations will work
111 */
113{
114 VeryHigh, // Native Linux, or Deck Verified with ProtonDB Platinum
115 High, // Deck Verified/Playable + ProtonDB Gold/Platinum
116 Medium, // ProtonDB Gold with good report count, or Lutris tested
117 Low, // Limited data, few reports, or known issues
118 Unknown // No data available
119};
120
121/**
122 * @struct GameSuggestions
123 * @brief Collection of suggestions for a game
124 */
126{
127 int steamAppId = 0;
128 std::string gameName;
129
130 // ProtonDB info
131 std::string protondbTier; // "platinum", "gold", etc.
133 float protondbScore = 0.0f;
135
136 // Steam Deck compatibility (from Valve testing)
137 std::string steamDeckStatus; // "Verified", "Playable", "Unsupported", "Unknown"
138
139 // Native Linux support
140 bool hasNativeLinux = false;
141
142 // Lutris data
143 bool hasLutrisInstaller = false;
145
146 // System-specific recommendations
147 std::string detectedGPU;
148 bool isCachyOS = false;
149
150 // Anti-cheat status (populated from Lutris installer flags)
151 bool needsEACRuntime = false; // EAC runtime should be engaged
152 bool needsBattleyeRuntime = false; // BattlEye runtime should be engaged
153
154 // Confidence scoring (higher = more reliable recommendations)
155 float confidenceBoost = 0.0f; // Boost from official sources like Steam Deck Verified
156 bool hasBlockingIssue = false; // True if there's a known blocking issue (anti-cheat, etc.)
157
158 // All suggestions
159 std::vector<GameSuggestion> suggestions;
160
161 // Quick checks
163 {
164 return !suggestions.empty();
165 }
166 bool hasCritical() const;
167 bool hasRunnerSuggestion() const;
168
169 // Get suggestions by category
170 std::vector<GameSuggestion> getByCategory(SuggestionCategory category) const;
171 std::vector<GameSuggestion> getByPriority(SuggestionPriority priority) const;
172
173 // Get the top recommended runner
174 std::string getRecommendedRunner() const;
175
176 // Get environment variables to apply
177 std::vector<std::pair<std::string, std::string>> getEnvironmentVariables() const;
178
179 // Get all DLL overrides combined
180 std::string getCombinedDLLOverrides() const;
181
182 // Confidence assessment
184 float getConfidenceScore() const; // 0.0-1.0 numeric confidence
185 std::string getConfidenceSummary() const; // Human-readable explanation
186};
187
188// ==============================================================================
189// GameSuggestionService Class
190// ==============================================================================
191
192/**
193 * @class GameSuggestionService
194 * @brief Service for generating smart game setting recommendations
195 */
197{
198 public:
199 // Callback types
200 using SuggestionsCallback = std::function<void(const GameSuggestions&)>;
201
202 // ==========================================================================
203 // Synchronous API
204 // ==========================================================================
205
206 /**
207 * @brief Get suggestions for a game
208 * @param game The game to get suggestions for
209 * @return GameSuggestions with all recommendations
210 *
211 * This may make network requests to ProtonDB. For UI updates,
212 * prefer getSuggestionsAsync().
213 */
214 static GameSuggestions getSuggestions(const Game& game);
215
216 /**
217 * @brief Get suggestions by Steam App ID
218 * @param steamAppId Steam App ID
219 * @param gameName Game name (for display)
220 * @return GameSuggestions with all recommendations
221 */
222 static GameSuggestions getSuggestions(int steamAppId, const std::string& gameName);
223
224 // ==========================================================================
225 // Asynchronous API
226 // ==========================================================================
227
228 /**
229 * @brief Get suggestions asynchronously
230 * @param game The game to get suggestions for
231 * @param callback Function to call with results
232 */
233 static void getSuggestionsAsync(const Game& game, SuggestionsCallback callback);
234
235 /**
236 * @brief Get suggestions by Steam App ID asynchronously
237 * @param steamAppId Steam App ID
238 * @param gameName Game name
239 * @param callback Function to call with results
240 */
241 static void getSuggestionsAsync(int steamAppId, const std::string& gameName,
242 SuggestionsCallback callback);
243
244 // ==========================================================================
245 // Utility Methods
246 // ==========================================================================
247
248 /**
249 * @brief Apply suggestions to a game's runner config
250 * @param game Game to modify (in-place)
251 * @param suggestions Suggestions to apply
252 * @param applyLevel What priority level to auto-apply
253 * @return Number of suggestions applied
254 */
255 static int applySuggestions(Game& game, const GameSuggestions& suggestions,
257
258 /**
259 * @brief Get priority as human-readable string
260 */
261 static std::string priorityToString(SuggestionPriority priority);
262
263 /**
264 * @brief Get category as human-readable string
265 */
266 static std::string categoryToString(SuggestionCategory category);
267
268 /**
269 * @brief Validate a suggestion before applying
270 * @param suggestion The suggestion to validate
271 * @param reason Output: reason if invalid
272 * @return true if the suggestion can be safely applied
273 *
274 * Validation checks:
275 * - Runner exists on the system
276 * - Environment variable keys are valid
277 * - No known conflicting combinations
278 * - Values are within expected ranges
279 */
280 static bool validateSuggestion(const GameSuggestion& suggestion, std::string& reason);
281
282 /**
283 * @brief Check if a runner exists on the system
284 * @param runnerName The runner name to check
285 * @return true if the runner is available
286 */
287 static bool isRunnerAvailable(const std::string& runnerName);
288
289 /**
290 * @brief Check for conflicting environment variables
291 * @param suggestions All suggestions being applied
292 * @return Vector of conflict descriptions (empty if no conflicts)
293 */
294 static std::vector<std::string> checkConflicts(const GameSuggestions& suggestions);
295
296 /**
297 * @brief Get local-only suggestions (no network requests)
298 * @param game The game to get suggestions for
299 * @return GameSuggestions based on system detection only (GPU, kernel, CachyOS)
300 *
301 * Safe to call from the UI thread. Skips ProtonDB lookups.
302 */
303 static GameSuggestions getLocalSuggestions(const Game& game);
304
305 // ==========================================================================
306 // Test-only injection
307 // ==========================================================================
308
309 /**
310 * @brief Override the SystemCapabilities consulted by suggestion
311 * generation. Intended for unit tests that need to exercise
312 * platform-dependent branches deterministically (e.g., NTSync
313 * available, CachyOS detected, AMD vs NVIDIA GPU).
314 *
315 * When set to non-null, every internal capabilities read returns the
316 * override instead of calling SystemInfoService::instance(). Reset to
317 * nullptr to restore normal behaviour.
318 *
319 * Not thread-safe — intended for single-threaded test code.
320 */
322
323 private:
324 // Build suggestions from various sources
325 static void addProtonDBSuggestions(GameSuggestions& suggestions, int steamAppId);
326 static void addSystemSuggestions(GameSuggestions& suggestions);
327 static void addRunnerSuggestions(GameSuggestions& suggestions);
328 static void addGPUSuggestions(GameSuggestions& suggestions);
329 static void addSyncSuggestions(GameSuggestions& suggestions);
330 static void addShaderCacheSuggestions(GameSuggestions& suggestions);
331 static void addKernelParamSuggestions(GameSuggestions& suggestions);
332 static void addDisplaySuggestions(GameSuggestions& suggestions);
333 static void addMemorySuggestions(GameSuggestions& suggestions);
334 static void addPowerSuggestions(GameSuggestions& suggestions);
335 static void addControllerSuggestions(GameSuggestions& suggestions);
336 static void addAudioSuggestions(GameSuggestions& suggestions);
337 static void addCachyOSSuggestions(GameSuggestions& suggestions);
338 static void addBuiltinFixes(GameSuggestions& suggestions, int steamAppId,
339 const std::string& gameName);
340
341 // Known game fixes database (built-in or loaded from JSON)
342 static void initBuiltinFixes();
343 static bool loadFixesFromJSON(const std::string& jsonPath);
344 static bool hasLoadedExternalFixes_;
345
346 // GE-Proton version checking
347 static std::string getLatestGEProtonVersion();
348 static std::string cachedGEProtonVersion_;
349 static std::chrono::steady_clock::time_point geProtonCacheTime_;
350
351 // Loaded fixes storage
352 struct GameFixEntry
353 {
354 int steamAppId;
355 std::string name;
356 std::vector<GameSuggestion> suggestions;
357 };
358 static std::vector<GameFixEntry> loadedFixes_;
359 static std::unordered_map<int, const GameFixEntry*> fixesByAppId_; ///< O(1) lookup index
360
361 // Test-only capabilities override. See setCapabilitiesOverrideForTesting.
362 static const SystemCapabilities* capabilitiesOverride_;
363
364 // Returns the effective capabilities — either the test override (if
365 // set) or the live singleton's cached struct. All internal code paths
366 // must read capabilities through this accessor so the test hook works
367 // uniformly.
368 static const SystemCapabilities& effectiveCapabilities();
369
370 // Returns the effective GPU vendor name (uses override's GPU vendor
371 // enum when set; otherwise calls SystemInfoService::getGPUVendorName()).
372 static std::string effectiveGPUVendorName();
373};
Service for generating smart game setting recommendations.
static GameSuggestions getLocalSuggestions(const Game &game)
Get local-only suggestions (no network requests).
static bool validateSuggestion(const GameSuggestion &suggestion, std::string &reason)
Validate a suggestion before applying.
static std::string categoryToString(SuggestionCategory category)
Get category as human-readable string.
static void setCapabilitiesOverrideForTesting(const SystemCapabilities *caps)
Override the SystemCapabilities consulted by suggestion generation.
static int applySuggestions(Game &game, const GameSuggestions &suggestions, SuggestionPriority applyLevel=SuggestionPriority::Recommended)
Apply suggestions to a game's runner config.
static bool isRunnerAvailable(const std::string &runnerName)
Check if a runner exists on the system.
static std::string priorityToString(SuggestionPriority priority)
Get priority as human-readable string.
static void getSuggestionsAsync(const Game &game, SuggestionsCallback callback)
Get suggestions asynchronously.
static GameSuggestions getSuggestions(const Game &game)
Get suggestions for a game.
std::function< void(const GameSuggestions &)> SuggestionsCallback
static std::vector< std::string > checkConflicts(const GameSuggestions &suggestions)
Check for conflicting environment variables.
Complete representation of a game in the library.
Definition game.h:767
ConfidenceLevel
How confident we are that our recommendations will work.
SuggestionCategory
Category of the suggestion.
SuggestionPriority
Priority level for suggestions.
A single setting recommendation.
SuggestionCategory category
SuggestionPriority priority
Collection of suggestions for a game.
std::vector< GameSuggestion > getByPriority(SuggestionPriority priority) const
std::string getCombinedDLLOverrides() const
std::string getRecommendedRunner() const
ConfidenceLevel getConfidenceLevel() const
std::vector< std::pair< std::string, std::string > > getEnvironmentVariables() const
std::vector< GameSuggestion > getByCategory(SuggestionCategory category) const
std::string getConfidenceSummary() const
std::vector< GameSuggestion > suggestions
Complete system capabilities summary.