game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
steam_appinfo_parser.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// steam_appinfo_parser.h
4// ==============================================================================
5// Parser for Steam's binary appinfo.vdf file
6// ==============================================================================
7// Steam's appinfo.vdf is a binary cache containing metadata for every app
8// in the Steam catalog that the user owns or has installed. It contains
9// launch configurations (executable paths, arguments, OS requirements),
10// app type classification, and other metadata not available in ACF manifests.
11//
12// This parser extracts the minimum information needed for direct game launching:
13// - Game executable path and launch arguments
14// - App type (game, tool, dlc, etc.)
15// - OS compatibility information
16// ==============================================================================
17
18#pragma once
19
20#include <cstdint>
21#include <filesystem>
22#include <map>
23#include <optional>
24#include <string>
25#include <vector>
26
27// ==============================================================================
28// Steam App Launch Configuration
29// ==============================================================================
30
31/**
32 * @struct SteamLaunchEntry
33 * @brief A single launch configuration from appinfo.vdf
34 *
35 * Steam games can have multiple launch entries (e.g., main game, DX12 mode,
36 * dedicated server, legacy version). Each entry specifies an executable,
37 * arguments, OS compatibility, and a type that determines its role.
38 */
40{
41 int index = -1; ///< Launch entry index (0, 1, 2, ...)
42 std::string executable; ///< Executable path relative to install dir (e.g., "game.exe")
43 std::string arguments; ///< Default launch arguments
44 std::string description; ///< User-facing description (e.g., "DirectX 12 mode")
45 std::string type; ///< Launch type: "default", "none", "option1", "option2", etc.
46 std::string oslist; ///< Comma-separated OS list: "windows", "linux", "macos"
47 std::string osarch; ///< Architecture: "32", "64", or empty
48
49 bool isDefault() const
50 {
51 return type.empty() || type == "default" || type == "none";
52 }
53 bool supportsWindows() const
54 {
55 return oslist.empty() || oslist.find("windows") != std::string::npos;
56 }
57 bool supportsLinux() const
58 {
59 return oslist.find("linux") != std::string::npos;
60 }
61};
62
63/**
64 * @struct SteamAppVdfInfo
65 * @brief Parsed metadata for a single Steam app from appinfo.vdf
66 */
68{
69 uint32_t appId = 0;
70 std::string name; ///< App name from common section
71 std::string type; ///< App type: "Game", "Tool", "DLC", "Demo", etc.
72 std::vector<SteamLaunchEntry> launchEntries; ///< All launch configurations
73
74 /**
75 * @brief Get the best launch entry for running under Proton
76 *
77 * Selection priority:
78 * 1. Default Windows entry (type="default" or "", oslist contains "windows")
79 * 2. Any Windows entry with type="none" (some games use this for the main exe)
80 * 3. First Windows entry as fallback
81 *
82 * @return Best launch entry for Proton, or nullopt if none found
83 */
84 std::optional<SteamLaunchEntry> getProtonLaunchEntry() const;
85
86 /**
87 * @brief Get the best launch entry for native Linux execution
88 * @return Best native Linux launch entry, or nullopt if none found
89 */
90 std::optional<SteamLaunchEntry> getNativeLaunchEntry() const;
91
92 bool isGame() const
93 {
94 return type == "Game" || type == "game";
95 }
96 bool isTool() const
97 {
98 return type == "Tool" || type == "tool";
99 }
100};
101
102// ==============================================================================
103// AppInfo VDF Parser
104// ==============================================================================
105
106/**
107 * @class SteamAppInfoParser
108 * @brief Parses Steam's binary appinfo.vdf cache file
109 *
110 * Supports appinfo.vdf format version 29 (0x07564429), which uses a string
111 * table at the end of the file for key names (introduced by Steam in
112 * June 2024). Older versions 27 (0x07564427) and 28 (0x07564428) use inline
113 * key names and are recognised but not fully parsed; load() returns false
114 * with an actionable message prompting the user to update their Steam client.
115 *
116 * Usage:
117 * SteamAppInfoParser parser;
118 * if (parser.load("/path/to/appinfo.vdf")) {
119 * auto info = parser.getAppInfo(730); // CS2
120 * if (info) {
121 * auto launch = info->getProtonLaunchEntry();
122 * }
123 * }
124 *
125 * Performance: The parser indexes all app record offsets on load (~5ms for
126 * typical files) but only fully parses individual app records on demand.
127 */
129{
130 public:
131 /**
132 * @brief Load and index an appinfo.vdf file
133 * @param path Path to appinfo.vdf
134 * @return true if the file was loaded and indexed successfully
135 */
136 bool load(const std::filesystem::path& path);
137
138 /**
139 * @brief Get parsed app info for a specific app ID
140 * @param appId Steam App ID
141 * @return Parsed app info, or nullopt if not found
142 */
143 std::optional<SteamAppVdfInfo> getAppInfo(uint32_t appId) const;
144
145 /**
146 * @brief Check if a specific app ID exists in the cache
147 */
148 bool hasApp(uint32_t appId) const;
149
150 /**
151 * @brief Get the number of indexed apps
152 */
153 size_t appCount() const
154 {
155 return appOffsets_.size();
156 }
157
158 private:
159 // Binary VDF value types
160 enum class VdfType : uint8_t
161 {
162 Nested = 0x00,
163 String = 0x01,
164 Int32 = 0x02,
165 Float32 = 0x03,
166 Color = 0x04,
167 Pointer = 0x05,
168 Int64 = 0x06,
169 Int64Unsigned = 0x0A,
170 End = 0x08,
171 };
172
173 // Recursive key-value map for binary VDF data
174 struct VdfValue;
175 using VdfMap = std::map<std::string, VdfValue>;
176
177 struct VdfValue
178 {
179 enum Type
180 {
181 MAP,
182 STRING,
183 INT32,
184 INT64
185 } type = STRING;
186 std::string strVal;
187 uint32_t intVal = 0;
188 uint64_t int64Val = 0;
189 VdfMap mapVal;
190
191 const VdfMap* asMap() const
192 {
193 return type == MAP ? &mapVal : nullptr;
194 }
195 const std::string& asString() const
196 {
197 return strVal;
198 }
199 uint32_t asInt() const
200 {
201 return intVal;
202 }
203 };
204
205 bool loadStringTable(size_t offset);
206 bool indexAppRecords();
207 VdfMap parseVdfBinary(size_t offset, size_t endOffset) const;
208 VdfMap parseVdfBinaryRecursive(size_t& offset, size_t endOffset, int depth) const;
209
210 SteamAppVdfInfo parseAppRecord(size_t offset, size_t size) const;
211 SteamLaunchEntry parseLaunchEntry(const VdfMap& data, int index) const;
212
213 // Helper to navigate nested VDF maps
214 const VdfMap* getNestedMap(const VdfMap& root, const std::string& key) const;
215 std::string getNestedString(const VdfMap& map, const std::string& key) const;
216 uint32_t getNestedInt(const VdfMap& map, const std::string& key) const;
217
218 std::string getStringByIndex(uint32_t index) const;
219
220 std::vector<uint8_t> data_; ///< Raw file contents
221 std::vector<std::string> stringTable_; ///< String table (v29+)
222 std::map<uint32_t, std::pair<size_t, size_t>> appOffsets_; ///< appId -> (offset, size)
223 uint32_t version_ = 0;
224
225 static constexpr uint32_t MAGIC_V27 = 0x07564427; ///< Pre-June-2024 clients (no string table)
226 static constexpr uint32_t MAGIC_V28 = 0x07564428; ///< Pre-June-2024 clients (no string table)
227 static constexpr uint32_t MAGIC_V29 = 0x07564429; ///< June 2024+ clients (string table)
228 static constexpr size_t APP_RECORD_HEADER_SIZE =
229 60; // info_state(4) + last_updated(4) + access_token(8) + sha1(20) + change_number(4) +
230 // sha1_data(20)
231};
Parses Steam's binary appinfo.vdf cache file.
std::optional< SteamAppVdfInfo > getAppInfo(uint32_t appId) const
Get parsed app info for a specific app ID.
bool load(const std::filesystem::path &path)
Load and index an appinfo.vdf file.
size_t appCount() const
Get the number of indexed apps.
bool hasApp(uint32_t appId) const
Check if a specific app ID exists in the cache.
Parsed metadata for a single Steam app from appinfo.vdf.
std::string name
App name from common section.
std::optional< SteamLaunchEntry > getProtonLaunchEntry() const
Get the best launch entry for running under Proton.
std::vector< SteamLaunchEntry > launchEntries
All launch configurations.
std::string type
App type: "Game", "Tool", "DLC", "Demo", etc.
std::optional< SteamLaunchEntry > getNativeLaunchEntry() const
Get the best launch entry for native Linux execution.
A single launch configuration from appinfo.vdf.
int index
Launch entry index (0, 1, 2, ...).
std::string description
User-facing description (e.g., "DirectX 12 mode").
std::string osarch
Architecture: "32", "64", or empty.
std::string executable
Executable path relative to install dir (e.g., "game.exe").
std::string type
Launch type: "default", "none", "option1", "option2", etc.
bool supportsWindows() const
std::string arguments
Default launch arguments.
std::string oslist
Comma-separated OS list: "windows", "linux", "macos".