game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
protondb_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// protondb_service.h
4// ==============================================================================
5// ProtonDB integration for fetching game compatibility data and recommendations
6// ==============================================================================
7// This service fetches game compatibility information from ProtonDB to help
8// configure non-Steam games with optimal settings.
9//
10// ## Features
11// - Fetch compatibility tier (Platinum, Gold, Silver, Bronze, Borked)
12// - Parse user reports for recommended tweaks
13// - Extract environment variables, DLL overrides, launch options
14// - Search by Steam App ID or game name
15//
16// ## Data Sources
17// - Primary API: protondb.max-p.me (community API)
18// - Summary API: www.protondb.com/api/v1/reports/summaries/
19//
20// ## Thread Safety
21// All methods are thread-safe and can be called from any thread.
22// ==============================================================================
23
24#pragma once
25
26#include <functional>
27#include <map>
28#include <mutex>
29#include <string>
30#include <unordered_map>
31#include <vector>
32
33// ==============================================================================
34// ProtonDB Data Structures
35// ==============================================================================
36
37/**
38 * @struct ProtonDBTweaks
39 * @brief Recommended tweaks extracted from ProtonDB reports
40 *
41 * Contains parsed recommendations from user reports including
42 * environment variables, DLL overrides, and launch options.
43 */
45{
46 /// Environment variables to set (e.g., PROTON_USE_WINED3D=1)
47 std::map<std::string, std::string> environmentVariables;
48
49 /// DLL overrides (e.g., "d3d11=native,builtin")
50 std::string dllOverrides;
51
52 /// Launch arguments to add
53 std::string launchArguments;
54
55 /// Recommended Proton version (e.g., "GE-Proton8-25")
57
58 /// Notes/warnings from reports
59 std::vector<std::string> notes;
60
61 /// Number of reports these tweaks were extracted from
62 int reportCount = 0;
63};
64
65/**
66 * @struct ProtonDBGameInfo
67 * @brief Complete ProtonDB information for a game
68 */
70{
71 // Basic info
72 int steamAppId = 0;
73 std::string gameName;
74
75 // Compatibility rating
76 std::string tier; // "platinum", "gold", "silver", "bronze", "borked", "native"
77 std::string trendingTier; // Most recent tier
78 float score = 0.0f; // 0.0-1.0 compatibility score
79 std::string confidence; // "strong", "good", "weak"
80 int totalReports = 0;
81
82 // Extracted recommendations
84
85 // Status
86 bool found = false;
87 std::string errorMessage;
88};
89
90/**
91 * @struct ProtonDBSearchResult
92 * @brief Result from searching ProtonDB by game name
93 */
95{
96 int steamAppId = 0;
97 std::string gameName;
98 std::string tier;
99 int reportCount = 0;
100};
101
102// ==============================================================================
103// Steam Deck Compatibility Data
104// ==============================================================================
105
106/**
107 * @enum SteamDeckCompatibility
108 * @brief Steam Deck verification status from Valve's testing
109 */
111{
112 Unknown = 0, // Not tested
113 Unsupported = 1, // Does not work
114 Playable = 2, // Works with some configuration
115 Verified = 3 // Works out of the box
116};
117
118/**
119 * @struct SteamDeckInfo
120 * @brief Steam Deck compatibility information from Valve
121 */
123{
125 std::string compatibilityString; // "Verified", "Playable", etc.
126
127 // Specific test results from Valve
128 bool controllerSupport = false; // Full controller support
129 bool nativeResolution = false; // Supports 1280x800
130 bool seamlessLaunch = false; // No launcher issues
131 bool protonCompatible = false; // Works with Proton
132
133 // Notes from Valve testing
134 std::vector<std::string> notes;
135
136 bool found = false;
137};
138
139// ==============================================================================
140// Steam App Details
141// ==============================================================================
142
143/**
144 * @struct SteamAppInfo
145 * @brief Basic Steam store information for a game
146 */
148{
149 int steamAppId = 0;
150 std::string name;
151
152 // Platform support
153 bool supportsLinux = false; // Native Linux build available
154 bool supportsWindows = true;
155 bool supportsMac = false;
156
157 // Features
158 std::string controllerSupport; // "full", "partial", ""
159 bool hasCloudSaves = false;
160 bool hasMultiplayer = false;
161 bool hasSinglePlayer = true;
162
163 // Categorization
164 std::vector<std::string> genres;
165 std::vector<std::string> categories;
166 std::string developer;
167 std::string publisher;
168
169 // DRM info
170 std::string drmNotice; // Third-party DRM warning
171
172 bool found = false;
173};
174
175// ==============================================================================
176// Lutris Integration
177// ==============================================================================
178
179/**
180 * @struct LutrisInstaller
181 * @brief Installation script from Lutris with working configurations
182 */
184{
185 std::string slug; // Unique installer ID
186 std::string name; // Display name
187 std::string runner; // wine, linux, etc.
188 std::string version; // Runner version
189
190 // Configuration from working installs
191 std::map<std::string, std::string> environmentVariables;
192 std::string dllOverrides;
193 std::string launchArguments;
194 std::string workingDirectory;
195
196 // Wine/Proton specific
197 std::string wineVersion;
198 std::string winePrefixArch; // win32 or win64
199
200 // Anti-cheat runtime requirements (from installer script flags).
201 // Surfaced so the suggestion engine can emit PROTON_EAC_RUNTIME=1 /
202 // PROTON_BATTLEYE_RUNTIME=1 and prefer proton-cachyos-slr.
203 bool eac = false;
204 bool battleye = false;
205
206 // Metadata
207 int downloadCount = 0; // Popularity indicator
208 std::string createdAt;
209 std::string updatedAt;
210
211 bool found = false;
212};
213
214/**
215 * @struct LutrisGameInfo
216 * @brief Lutris database entry for a game
217 */
219{
220 std::string slug;
221 std::string name;
222 int steamId = 0;
223 int gogId = 0;
224
225 // Available installers (sorted by popularity)
226 std::vector<LutrisInstaller> installers;
227
228 bool found = false;
229};
230
231// ==============================================================================
232// ProtonDB Service Class
233// ==============================================================================
234
235/**
236 * @class ProtonDBService
237 * @brief Service for fetching game compatibility data from ProtonDB
238 *
239 * Provides methods to look up game compatibility information and extract
240 * recommended settings from user reports.
241 *
242 * ## Usage Example
243 * @code
244 * // Look up by Steam App ID
245 * auto info = ProtonDBService::getGameInfo(292030); // Witcher 3
246 * if (info.found) {
247 * Logger::info("Tier: {}, Score: {}", info.tier, info.score);
248 * // Apply tweaks...
249 * }
250 *
251 * // Async lookup
252 * ProtonDBService::getGameInfoAsync(292030, [](const ProtonDBGameInfo& info) {
253 * if (info.found) {
254 * // Update UI with results
255 * }
256 * });
257 * @endcode
258 */
260{
261 public:
262 // ==========================================================================
263 // Synchronous API (blocks until complete)
264 // ==========================================================================
265
266 /**
267 * @brief Get game info by Steam App ID
268 * @param steamAppId Steam App ID to look up
269 * @return ProtonDBGameInfo with compatibility data and recommendations
270 *
271 * Makes HTTP requests to ProtonDB APIs. May block for several seconds.
272 * For UI updates, prefer getGameInfoAsync().
273 */
274 static ProtonDBGameInfo getGameInfo(int steamAppId);
275
276 /**
277 * @brief Search for games by name
278 * @param gameName Name to search for (partial match supported)
279 * @param maxResults Maximum results to return
280 * @return Vector of search results
281 */
282 static std::vector<ProtonDBSearchResult> searchByName(const std::string& gameName,
283 int maxResults = 10);
284
285 /**
286 * @brief Get compatibility tier for a game (quick lookup)
287 * @param steamAppId Steam App ID
288 * @return Tier string ("platinum", "gold", etc.) or empty if not found
289 */
290 static std::string getTier(int steamAppId);
291
292 // ==========================================================================
293 // Asynchronous API (non-blocking, callbacks on completion)
294 // ==========================================================================
295
296 using GameInfoCallback = std::function<void(const ProtonDBGameInfo&)>;
297 using SearchCallback = std::function<void(const std::vector<ProtonDBSearchResult>&)>;
298
299 /**
300 * @brief Get game info asynchronously
301 * @param steamAppId Steam App ID to look up
302 * @param callback Function to call with results (called from background thread)
303 *
304 * Returns immediately. Callback is invoked when data is available.
305 * Callback may be invoked from a different thread.
306 */
307 static void getGameInfoAsync(int steamAppId, const GameInfoCallback& callback);
308
309 /**
310 * @brief Search for games by name asynchronously
311 * @param gameName Name to search for
312 * @param callback Function to call with results
313 * @param maxResults Maximum results to return
314 */
315 static void searchByNameAsync(const std::string& gameName, const SearchCallback& callback,
316 int maxResults = 10);
317
318 /**
319 * @brief Find game info by name (searches for matching game, returns full info)
320 * @param gameName Name of the game to search for
321 * @return ProtonDBGameInfo with compatibility data if found
322 *
323 * This method searches for the game by name, finds the best match,
324 * and returns full compatibility information including tweaks.
325 * Useful when you don't know the Steam App ID.
326 */
327 static ProtonDBGameInfo findGameByName(const std::string& gameName);
328
329 /**
330 * @brief Find game info by name asynchronously
331 * @param gameName Name of the game to search for
332 * @param callback Function to call with results
333 */
334 static void findGameByNameAsync(const std::string& gameName, const GameInfoCallback& callback);
335
336 // ==========================================================================
337 // Utility Methods
338 // ==========================================================================
339
340 /**
341 * @brief Get human-readable tier description
342 * @param tier Tier string (e.g., "platinum")
343 * @return Description (e.g., "Works perfectly out of the box")
344 */
345 static std::string getTierDescription(const std::string& tier);
346
347 /**
348 * @brief Get tier color for UI display (RGBA).
349 * @param tier Tier string (e.g., "platinum", "gold", "silver", "bronze", "borked").
350 * @param[out] r Red channel in [0.0, 1.0].
351 * @param[out] g Green channel in [0.0, 1.0].
352 * @param[out] b Blue channel in [0.0, 1.0].
353 * @param[out] a Alpha channel in [0.0, 1.0].
354 */
355 static void getTierColor(const std::string& tier, float& r, float& g, float& b, float& a);
356
357 /**
358 * @brief Clear cached data
359 *
360 * Clears any cached API responses to force fresh lookups.
361 */
362 static void clearCache();
363
364 // ==========================================================================
365 // Steam Deck Compatibility API
366 // ==========================================================================
367
368 /**
369 * @brief Get Steam Deck compatibility status from Valve's testing
370 * @param steamAppId Steam App ID
371 * @return SteamDeckInfo with verification status and notes
372 *
373 * Uses Steam's official Deck compatibility API. Results indicate whether
374 * Valve has tested and verified the game for Steam Deck.
375 */
376 static SteamDeckInfo getSteamDeckInfo(int steamAppId);
377
378 /**
379 * @brief Get Steam Deck compatibility asynchronously
380 */
381 static void getSteamDeckInfoAsync(int steamAppId,
382 const std::function<void(const SteamDeckInfo&)>& callback);
383
384 // ==========================================================================
385 // Steam Store API
386 // ==========================================================================
387
388 /**
389 * @brief Get Steam store information (native Linux, genres, DRM, etc.)
390 * @param steamAppId Steam App ID
391 * @return SteamAppInfo with store metadata
392 *
393 * Checks if game has native Linux support, controller support, genres, etc.
394 * Essential for determining if Proton is even needed.
395 */
396 static SteamAppInfo getSteamAppInfo(int steamAppId);
397
398 /**
399 * @brief Get Steam app info asynchronously
400 */
401 static void getSteamAppInfoAsync(int steamAppId,
402 const std::function<void(const SteamAppInfo&)>& callback);
403
404 // ==========================================================================
405 // Lutris API
406 // ==========================================================================
407
408 /**
409 * @brief Get Lutris game info and installers
410 * @param steamAppId Steam App ID to search for
411 * @return LutrisGameInfo with available install scripts
412 *
413 * Fetches community-tested installation scripts from Lutris database.
414 * These contain working configurations for many games.
415 */
416 static LutrisGameInfo getLutrisInfo(int steamAppId);
417
418 /**
419 * @brief Get Lutris info by game slug
420 * @param gameSlug Lutris game slug (e.g., "counter-strike-2")
421 */
422 static LutrisGameInfo getLutrisInfoBySlug(const std::string& gameSlug);
423
424 /**
425 * @brief Get Lutris info asynchronously
426 */
427 static void getLutrisInfoAsync(int steamAppId,
428 const std::function<void(const LutrisGameInfo&)>& callback);
429
430 private:
431 // ==========================================================================
432 // Internal Methods
433 // ==========================================================================
434
435 // HTTP helpers
436 static std::string httpGet(const std::string& url);
437 static std::string urlEncode(const std::string& str);
438
439 // JSON parsing (simple implementation without external dependency)
440 static ProtonDBGameInfo parseSummaryJson(const std::string& json, int steamAppId);
441 static std::vector<ProtonDBSearchResult> parseSearchJson(const std::string& json);
442 static ProtonDBTweaks parseReportsJson(const std::string& json);
443
444 // Tweak extraction from report notes
445 static void extractTweaksFromNote(const std::string& note, ProtonDBTweaks& tweaks);
446
447 // Cache - use unordered_map for O(1) lookup instead of O(log n)
448 static std::unordered_map<int, ProtonDBGameInfo> cache_;
449 static std::mutex cacheMutex_;
450};
Service for fetching game compatibility data from ProtonDB.
static SteamAppInfo getSteamAppInfo(int steamAppId)
Get Steam store information (native Linux, genres, DRM, etc.).
std::function< void(const ProtonDBGameInfo &)> GameInfoCallback
static std::vector< ProtonDBSearchResult > searchByName(const std::string &gameName, int maxResults=10)
Search for games by name.
static LutrisGameInfo getLutrisInfoBySlug(const std::string &gameSlug)
Get Lutris info by game slug.
static void findGameByNameAsync(const std::string &gameName, const GameInfoCallback &callback)
Find game info by name asynchronously.
static void searchByNameAsync(const std::string &gameName, const SearchCallback &callback, int maxResults=10)
Search for games by name asynchronously.
static void clearCache()
Clear cached data.
static ProtonDBGameInfo findGameByName(const std::string &gameName)
Find game info by name (searches for matching game, returns full info).
static std::string getTier(int steamAppId)
Get compatibility tier for a game (quick lookup).
static void getSteamDeckInfoAsync(int steamAppId, const std::function< void(const SteamDeckInfo &)> &callback)
Get Steam Deck compatibility asynchronously.
std::function< void(const std::vector< ProtonDBSearchResult > &)> SearchCallback
static LutrisGameInfo getLutrisInfo(int steamAppId)
Get Lutris game info and installers.
static ProtonDBGameInfo getGameInfo(int steamAppId)
Get game info by Steam App ID.
static void getTierColor(const std::string &tier, float &r, float &g, float &b, float &a)
Get tier color for UI display (RGBA).
static void getLutrisInfoAsync(int steamAppId, const std::function< void(const LutrisGameInfo &)> &callback)
Get Lutris info asynchronously.
static std::string getTierDescription(const std::string &tier)
Get human-readable tier description.
static void getSteamAppInfoAsync(int steamAppId, const std::function< void(const SteamAppInfo &)> &callback)
Get Steam app info asynchronously.
static SteamDeckInfo getSteamDeckInfo(int steamAppId)
Get Steam Deck compatibility status from Valve's testing.
static void getGameInfoAsync(int steamAppId, const GameInfoCallback &callback)
Get game info asynchronously.
nlohmann::json json
SteamDeckCompatibility
Steam Deck verification status from Valve's testing.
Lutris database entry for a game.
std::vector< LutrisInstaller > installers
Installation script from Lutris with working configurations.
std::string wineVersion
std::string dllOverrides
std::string updatedAt
std::string winePrefixArch
std::string launchArguments
std::string createdAt
std::string workingDirectory
std::map< std::string, std::string > environmentVariables
Complete ProtonDB information for a game.
std::string confidence
std::string trendingTier
ProtonDBTweaks tweaks
std::string errorMessage
Result from searching ProtonDB by game name.
Recommended tweaks extracted from ProtonDB reports.
std::string dllOverrides
DLL overrides (e.g., "d3d11=native,builtin").
std::map< std::string, std::string > environmentVariables
Environment variables to set (e.g., PROTON_USE_WINED3D=1).
std::string recommendedProtonVersion
Recommended Proton version (e.g., "GE-Proton8-25").
int reportCount
Number of reports these tweaks were extracted from.
std::string launchArguments
Launch arguments to add.
std::vector< std::string > notes
Notes/warnings from reports.
Basic Steam store information for a game.
std::string name
std::vector< std::string > genres
std::string publisher
std::string developer
std::string drmNotice
std::vector< std::string > categories
std::string controllerSupport
Steam Deck compatibility information from Valve.
SteamDeckCompatibility compatibility
std::vector< std::string > notes
std::string compatibilityString