Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Install the depots a demo takes from its game

Leonardo Lobatoc3bdd8e49020
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cpp
index edd8a43..dcefc30 100644
--- a/src/steam/backend/app_info.cpp
+++ b/src/steam/backend/app_info.cpp
@@ -382,6 +382,8 @@ std::optional<AppInfo> ParseAppInfo(std::uint32_t app_id, std::string_view buffe
if ((!game || !*game) && LowerString(app.type) == "dlc") game = ChildU32(common, "parent");
if (game && *game != 0 && *game != app_id) app.dlc_for_app_id = *game;
}
+ if (LowerString(app.type) == "demo")
+ if (const auto game = ChildU32(common, "parent"); game && *game != 0 && *game != app_id) app.demo_of_app_id = *game;
app.cloud = ParseCloudSaves(root->Find("ufs"));
if (config != nullptr) {
@@ -470,6 +472,22 @@ bool InLanguage(const DepotInfo& depot, const std::string& language) {
} // namespace
+void KeepDepotsDemoBorrows(const AppInfo& demo, AppInfo* game) {
+ std::vector<DepotInfo> kept;
+ for (DepotInfo& depot : game->depots) {
+ const bool borrowed = std::any_of(demo.depots.begin(), demo.depots.end(), [&](const DepotInfo& listed) {
+ return listed.id == depot.id && listed.depot_from_app == game->app_id && !listed.manifest_gid &&
+ listed.branches.empty();
+ });
+ if (!borrowed) continue;
+ // Still borrowed: an account that doesn't get its key installs the demo without it.
+ depot.depot_from_app = game->app_id;
+ kept.push_back(std::move(depot));
+ }
+ game->depots = std::move(kept);
+ game->dlc_app_ids.clear();
+}
+
bool SelectDepots(const AppInfo& app, const std::vector<AppInfo>& dlc_apps, const std::set<std::uint32_t>& owned_apps,
const std::optional<std::set<std::uint32_t>>& owned_depots, const DepotSelection& selection,
SelectionResult* result) {
diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.h
index 4ba178e..1b5d454 100644
--- a/src/steam/backend/app_info.h
+++ b/src/steam/backend/app_info.h
@@ -105,6 +105,8 @@ struct AppInfo {
std::vector<std::uint32_t> dlc_app_ids; // extended/listofdlc, which Steam cuts at 64 entries
// A DLC's game: extended/dlcforappid, else a DLC's common/parent. 0 for anything else.
std::uint32_t dlc_for_app_id = 0;
+ // A demo's game: common/parent when the type is demo. 0 for anything else.
+ std::uint32_t demo_of_app_id = 0;
bool free_app = false; // extended/isfreeapp: anyone who owns the game can claim this DLC for free
std::vector<AppLaunch> launches; // sorted by id
std::string controller_support;
@@ -115,6 +117,11 @@ struct AppInfo {
// Parses a PICS app buffer (text VDF with optional trailing NULs) whose root is "appinfo".
std::optional<AppInfo> ParseAppInfo(std::uint32_t app_id, std::string_view buffer);
+// A demo can take its content from its game: its appinfo lists the depot with depotfromapp and no manifest on any branch, and the
+// game's appinfo holds the manifest. Trims the game's appinfo to those depots, for SelectDepots' dlc_apps, which
+// installs the listing that has a manifest. The rest of the game stays out, even for an account that owns it.
+void KeepDepotsDemoBorrows(const AppInfo& demo, AppInfo* game);
+
// Steam `oslist`: empty means every platform; otherwise a comma list that must name windows.
bool OsListMatchesWindows(std::string_view os_list);
diff --git a/src/steam/backend/cm_app_details.cpp b/src/steam/backend/cm_app_details.cpp
index 83df2cb..3d3d5b3 100644
--- a/src/steam/backend/cm_app_details.cpp
+++ b/src/steam/backend/cm_app_details.cpp
@@ -200,6 +200,7 @@ std::vector<AppInfo> CmAppDetailsSource::FetchDlcApps(CmClient& client, const St
std::vector<std::uint32_t> dlc_ids;
for (const auto dlc : app->dlc_app_ids)
if (dlc != id && std::find(dlc_ids.begin(), dlc_ids.end(), dlc) == dlc_ids.end()) dlc_ids.push_back(dlc);
+ if (app->demo_of_app_id != 0) dlc_ids.push_back(app->demo_of_app_id);
for (std::size_t start = 0; start < dlc_ids.size() && !cancel.load(); start += kMaxAppInfoBatch) {
const std::vector<std::uint32_t> batch(
dlc_ids.begin() + static_cast<std::ptrdiff_t>(start),
@@ -208,7 +209,10 @@ std::vector<AppInfo> CmAppDetailsSource::FetchDlcApps(CmClient& client, const St
if (!dlc_info.ok()) continue;
for (const auto dlc : batch)
if (const auto found = dlc_info.buffers.find(dlc); found != dlc_info.buffers.end())
- if (auto parsed = ParseAppInfo(dlc, found->second)) dlc_apps.push_back(std::move(*parsed));
+ if (auto parsed = ParseAppInfo(dlc, found->second)) {
+ if (dlc == app->demo_of_app_id) KeepDepotsDemoBorrows(*app, &*parsed);
+ dlc_apps.push_back(std::move(*parsed));
+ }
}
return dlc_apps;
}
diff --git a/src/steam/backend/steam_install_runner.cpp b/src/steam/backend/steam_install_runner.cpp
index d3f4e84..d98f9b7 100644
--- a/src/steam/backend/steam_install_runner.cpp
+++ b/src/steam/backend/steam_install_runner.cpp
@@ -331,6 +331,7 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
std::vector<std::uint32_t> dlc_ids;
for (const auto dlc : app->dlc_app_ids)
if (dlc != id && std::find(dlc_ids.begin(), dlc_ids.end(), dlc) == dlc_ids.end()) dlc_ids.push_back(dlc);
+ if (app->demo_of_app_id != 0) dlc_ids.push_back(app->demo_of_app_id);
for (std::size_t start = 0; start < dlc_ids.size(); start += kMaxAppInfoBatch) {
const std::vector<std::uint32_t> batch(
dlc_ids.begin() + static_cast<std::ptrdiff_t>(start),
@@ -348,8 +349,14 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
}
for (const auto dlc : batch) {
const auto found = dlc_info.buffers.find(dlc);
- if (found == dlc_info.buffers.end()) continue;
- if (auto parsed = ParseAppInfo(dlc, found->second)) dlc_apps.push_back(std::move(*parsed));
+ auto parsed = found == dlc_info.buffers.end() ? std::nullopt : ParseAppInfo(dlc, found->second);
+ if (!parsed) {
+ // Without its game's appinfo a demo's update would select only its own depots and delete the borrowed ones.
+ if (dlc == app->demo_of_app_id) unfetched.insert(dlc);
+ continue;
+ }
+ if (dlc == app->demo_of_app_id) KeepDepotsDemoBorrows(*app, &*parsed);
+ dlc_apps.push_back(std::move(*parsed));
}
}
}
diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cpp
index 99e7ed7..7565775 100644
--- a/tests/steam_app_info_test.cpp
+++ b/tests/steam_app_info_test.cpp
@@ -1062,6 +1062,72 @@ void TestOsList() {
CHECK(!OsListMatchesWindows("windows10"));
}
+// The Evil Within 2 Demo takes its game files from the full game: two depots with depotfromapp and no manifest,
+// whose manifests only the game's appinfo holds. The rest of the game stays out, even for an account that owns it.
+void TestDemoInstallsTheDepotsItBorrows() {
+ const auto demo = ParseAppInfo(7000, R"("appinfo"
+{
+ "appid" "7000"
+ "common" { "name" "Game Demo" "type" "Demo" "parent" "6000" }
+ "config" { "launch" { "0" { "executable" "game.exe" "config" { "oslist" "windows" } } } }
+ "depots"
+ {
+ "6001" { "depotfromapp" "6000" "sharedinstall" "2" }
+ "7001" { "manifests" { "public" { "gid" "71" "size" "10" "download" "5" } } }
+ }
+})");
+ auto game = ParseAppInfo(6000, R"("appinfo"
+{
+ "appid" "6000"
+ "common" { "name" "Game" "type" "Game" }
+ "extended" { "listofdlc" "6500" }
+ "depots"
+ {
+ "6001" { "manifests" { "public" { "gid" "61" "size" "20" "download" "9" } } }
+ "6002" { "manifests" { "public" { "gid" "62" "size" "9000" "download" "8000" } } }
+ }
+})");
+ CHECK(demo && game);
+ CHECK(demo->demo_of_app_id == 6000 && game->demo_of_app_id == 0);
+ SelectionResult result;
+ // Without the game's appinfo the borrowed depot has no manifest, the case that left the demo without its files.
+ CHECK(SelectDepots(*demo, {}, {7000}, std::nullopt, DepotSelection{}, &result));
+ CHECK((Ids(result.depots) == U32s{7001}));
+ CHECK(RejectedAs(result, 6001) == "branch");
+ KeepDepotsDemoBorrows(*demo, &*game);
+ CHECK(game->depots.size() == 1 && game->depots[0].id == 6001 && game->dlc_app_ids.empty());
+ // An account with only the demo: the depot comes under the game's app and stays optional.
+ const std::vector<AppInfo> listings{*game};
+ CHECK(SelectDepots(*demo, listings, {7000}, std::set<std::uint32_t>{7001}, DepotSelection{}, &result));
+ CHECK((Ids(result.depots) == U32s{6001, 7001}));
+ CHECK(result.depots[0].manifest_gid == 61u && result.depots[0].source_app == 6000);
+ CHECK(result.depots[0].owner_app == 7000 && result.depots[0].depot_from_app == 6000u);
+ CHECK(OfferedDlc(*demo, listings, {7000}, std::set<std::uint32_t>{7001}, DepotSelection{}, {}).empty());
+ // An account that also owns the game: still only what the demo lists.
+ CHECK(SelectDepots(*demo, listings, {7000, 6000}, std::nullopt, DepotSelection{}, &result));
+ CHECK((Ids(result.depots) == U32s{6001, 7001}));
+ // A depot the demo has a manifest for on some branch isn't taken from the game: two manifests would conflict.
+ AppInfo own_beta = *demo;
+ own_beta.depots[0].branches["beta"] = BranchManifest{81, 5, 5, false};
+ auto whole_game = ParseAppInfo(6000, R"("appinfo"
+{
+ "appid" "6000"
+ "common" { "name" "Game" "type" "Game" }
+ "depots" { "6001" { "manifests" { "public" { "gid" "61" "size" "20" "download" "9" } } } }
+})");
+ CHECK(whole_game);
+ KeepDepotsDemoBorrows(own_beta, &*whole_game);
+ CHECK(whole_game->depots.empty());
+ // Another app that borrows a depot, here Half-Life 2's episode depot, is not a demo: nothing changes for it.
+ const auto other = ParseAppInfo(220, R"("appinfo"
+{
+ "appid" "220"
+ "common" { "name" "Half-Life 2" "type" "Game" "parent" "380" }
+ "depots" { "389" { "depotfromapp" "380" "sharedinstall" "2" } }
+})");
+ CHECK(other && other->demo_of_app_id == 0);
+}
+
} // namespace
int main(int argc, char** argv) {
@@ -1071,6 +1137,7 @@ int main(int argc, char** argv) {
}
g_fixtures = argv[1];
TestParse();
+ TestDemoInstallsTheDepotsItBorrows();
TestParseDefaultsAndFailures();
TestDlcForApp();
TestSelect();