Play your Steam library's Windows games on a jailbroken PS5.
C++
Install games granted by Steam's package 0 license
Leonardo Lobato9896a6419817
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cppindex fc1dae9..e084c2f 100644--- a/src/steam/backend/app_info.cpp+++ b/src/steam/backend/app_info.cpp@@ -430,6 +430,26 @@ bool SelectDepots(const AppInfo& app, const std::set<std::uint32_t>& owned_apps,return true;}+std::vector<std::uint32_t> MissingBaseDepots(const AppInfo& app,+ const std::optional<std::set<std::uint32_t>>& owned_depots,+ const std::vector<DepotInfo>& selected) {+ if (!owned_depots) return {};+ std::uint64_t selected_size = 0;+ for (const DepotInfo& depot : selected) selected_size += depot.size;+ std::vector<std::uint32_t> missing;+ std::uint64_t missing_size = 0;+ for (const DepotInfo& depot : app.depots) {+ if (owned_depots->count(depot.id) != 0 || depot.depot_from_app || depot.shared_install || depot.is_dlc ||+ !depot.os_list.empty() || !depot.language.empty() || !depot.manifest_gid || *depot.manifest_gid == 0)+ continue;+ missing.push_back(depot.id);+ missing_size += depot.size;+ }+ // An unowned extra (a bonus or edition depot) is smaller than the game; old appinfo has no sizes.+ if (missing_size == 0 || missing_size <= selected_size) return {};+ return missing;+}+bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_apps,std::vector<AppLaunch>* launches, std::string* reason) {std::vector<AppLaunch> eligible;diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.hindex 309b191..4f98a23 100644--- a/src/steam/backend/app_info.h+++ b/src/steam/backend/app_info.h@@ -94,6 +94,14 @@ bool SelectDepots(const AppInfo& app, const std::set<std::uint32_t>& owned_apps,const std::optional<std::set<std::uint32_t>>& owned_depots,std::vector<DepotInfo>* selected, std::string* reason);+// Depots that look like the game itself but the account's licenses do not grant: no oslist, no+// language, not DLC, with a public manifest, and together larger than the selected depots. Empty+// when nothing is missing or the licenses are unknown. Installing the rest would look complete+// but not start (issue #58).+std::vector<std::uint32_t> MissingBaseDepots(const AppInfo& app,+ const std::optional<std::set<std::uint32_t>>& owned_depots,+ const std::vector<DepotInfo>& selected);+// Windows launch entries usable on the public branch, default type first, then by id.bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_apps,std::vector<AppLaunch>* launches, std::string* reason);diff --git a/src/steam/backend/cm_client.cpp b/src/steam/backend/cm_client.cppindex 9140131..61640e7 100644--- a/src/steam/backend/cm_client.cpp+++ b/src/steam/backend/cm_client.cpp@@ -60,8 +60,10 @@ bool ValidEndpoint(const std::string& endpoint) {});}+// Package 0 counts: older accounts hold Valve's games there (Team Fortress 2's content, issue #58), and the+// reference reads every package in the license list.bool OwnedActiveLicense(const cm::License& license, std::uint32_t account_id) {- return license.package_id != 0 && (license.flags & kUnavailableLicense) == 0 &&+ return (license.flags & kUnavailableLicense) == 0 &&(license.owner_id == 0 || license.owner_id == account_id) &&(license.minute_limit <= 0 || license.minutes_used < license.minute_limit);}diff --git a/src/steam/backend/steam_install_runner.cpp b/src/steam/backend/steam_install_runner.cppindex 7153240..3365770 100644--- a/src/steam/backend/steam_install_runner.cpp+++ b/src/steam/backend/steam_install_runner.cpp@@ -124,12 +124,22 @@ InstallRunner::Result SteamInstallRunner::Install(const StoredSession& session,result.failure = "No Windows content to install.";return result;}+ if (const auto missing = MissingBaseDepots(*app, entitlements.owned_depots, target.depots); !missing.empty()) {+ std::string ids;+ for (const auto depot : missing) ids += (ids.empty() ? "" : " ") + std::to_string(depot);+ log("depots", "partial", ("unowned=" + ids).c_str());+ result.failure = "Steam didn't grant access to part of this game.";+ return result;+ }// Keep Steam's listing order: it is the depot mounting order.std::vector<DepotInfo> ordered;for (const auto& depot : app->depots)for (const auto& selected : target.depots)if (selected.id == depot.id) ordered.push_back(selected);target.depots = ordered;+ std::string selected_ids;+ for (const auto& depot : target.depots) selected_ids += (selected_ids.empty() ? "" : " ") + std::to_string(depot.id);+ log("depots", "selected", selected_ids.c_str());if (step) step(InstallStep::kDownloading);const auto outcome = installer_.Run(session, target, cancel, [&](const InstallProgress& state) {if (progress) progress(state.download_done, state.download_total, state.held_bytes);diff --git a/tests/cm_client_test.cpp b/tests/cm_client_test.cppindex d10e0cd..3de3ba3 100644--- a/tests/cm_client_test.cpp+++ b/tests/cm_client_test.cpp@@ -15,6 +15,7 @@#include <mutex>#include <string>#include <thread>+#include <tuple>#include <vector>using namespace playden;@@ -306,6 +307,69 @@ void EveryPackageBatchGetsItsOwnDeadline() {}) == 3);}+// Package 0 is the base license on older accounts and holds Valve's games (issue #58): its apps and depots count.+std::vector<std::uint8_t> PackageBuffer(std::uint32_t package_id, const std::vector<std::uint32_t>& apps,+ const std::vector<std::uint32_t>& depots) {+ std::vector<std::uint8_t> kv = {1, 0, 0, 0};+ auto text = [&](const std::string& value) {+ kv.insert(kv.end(), value.begin(), value.end());+ kv.push_back(0);+ };+ auto section = [&](const std::string& name) {+ kv.push_back(0);+ text(name);+ };+ auto ids = [&](const char* name, const std::vector<std::uint32_t>& values) {+ section(name);+ for (std::size_t index = 0; index < values.size(); ++index) {+ kv.push_back(2);+ text(std::to_string(index));+ for (int shift = 0; shift < 32; shift += 8) kv.push_back(static_cast<std::uint8_t>(values[index] >> shift));+ }+ kv.push_back(8);+ };+ section(std::to_string(package_id));+ ids("appids", apps);+ ids("depotids", depots);+ kv.push_back(8); // ends the package section+ kv.push_back(8); // and the root+ return kv;+}++void PackageZeroCounts() {+ auto script = std::make_shared<Script>();+ proto::Writer licenses;+ licenses.AddVarint(1, 1);+ for (const auto& [id, created] : {std::pair<std::uint32_t, std::uint32_t>{0, 1240000000}, {8538, 1300000000}}) {+ proto::Writer license;+ license.AddVarint(1, id);+ license.AddFixed32(2, created);+ license.AddVarint(7, 0x200);+ licenses.AddMessage(2, license);+ }+ script->on_logon = {ServerFrame(cm::kEMsgClientLogOnResponse, LogonResponseBody(1, 9)),+ ServerFrame(cm::kEMsgClientLicenseList, licenses.bytes())};+ script->pics_reply = [](const cm::Frame& request) {+ proto::Writer body;+ for (const auto& [id, apps, depots] :+ {std::tuple<std::uint32_t, std::vector<std::uint32_t>, std::vector<std::uint32_t>>{0, {440, 220}, {441, 232251}},+ {8538, {440}, {232251, 232253}}}) {+ proto::Writer package;+ package.AddVarint(1, id);+ package.AddBytes(5, PackageBuffer(id, apps, depots));+ body.AddMessage(3, package);+ }+ return ServerFrame(cm::kEMsgClientPICSProductInfoResponse, body.bytes(), std::nullopt, request.header.jobid_source);+ };+ auto client = MakeClient(script);+ std::atomic<bool> cancel{false};+ const auto result = client.FetchAcquisitionDates(Session(), cancel);+ assert(result.ok() && result.skipped_packages == 0);+ assert(result.owned_apps == (std::set<std::uint32_t>{220, 440}));+ assert(result.owned_depots == (std::set<std::uint32_t>{441, 232251, 232253}));+ assert(result.acquired_at.at(440) == 1240000000u && result.acquired_at.at(220) == 1240000000u);+}+void CancelStopsWaiting() {auto script = std::make_shared<Script>();auto client = MakeClient(script, 5000);@@ -689,6 +753,7 @@ int main(int argc, char** argv) {// A token one test refused stays refused for the process, so every test starts clean.ResetCmBackoff();AcquisitionDatesFromGzipMultiLicensesAndMultipartPics();+ PackageZeroCounts();ResetCmBackoff();RejectedLogonIsReportedWithoutDates();ResetCmBackoff();diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cppindex f326189..3b4625f 100644--- a/tests/steam_app_info_test.cpp+++ b/tests/steam_app_info_test.cpp@@ -290,6 +290,44 @@ void TestSelectDepots() {CHECK((Ids(selected) == U32s{101, 106}));}+// A partial grant must not install as if complete (issue #58): Team Fortress 2's content depot has+// no oslist or language and comes from a license the account's other one lacks.+void TestMissingBaseDepots() {+ AppInfo app;+ app.app_id = 440;+ DepotInfo content;+ content.id = 441;+ content.manifest_gid = 1;+ content.size = 31'000'000'000ull;+ DepotInfo binaries = content;+ binaries.id = 232251;+ binaries.os_list = "windows";+ binaries.size = 584'000'000ull;+ DepotInfo extra = content;+ extra.id = 450;+ extra.size = 100'000'000ull;+ app.depots = {content, binaries, extra};+ std::vector<DepotInfo> selected;+ std::string reason;++ const std::set<std::uint32_t> partial{232251};+ CHECK(SelectDepots(app, {440}, partial, &selected, &reason));+ CHECK((Ids(selected) == U32s{232251}));+ CHECK((MissingBaseDepots(app, partial, selected) == U32s{441, 450}));++ const std::set<std::uint32_t> full{441, 232251};+ CHECK(SelectDepots(app, {440}, full, &selected, &reason));+ CHECK((Ids(selected) == U32s{441, 232251}));+ // An unowned depot smaller than the game is an extra, not the game.+ CHECK(MissingBaseDepots(app, full, selected).empty());+ // Unknown licenses, or appinfo without sizes, never block an install.+ CHECK(MissingBaseDepots(app, std::nullopt, selected).empty());+ AppInfo sizeless = app;+ for (DepotInfo& depot : sizeless.depots) depot.size = 0;+ CHECK(SelectDepots(sizeless, {440}, partial, &selected, &reason));+ CHECK(MissingBaseDepots(sizeless, partial, selected).empty());+}+void TestEligibleLaunches() {const auto app = ParseAppInfo(kApp, Buffer());CHECK(app);@@ -375,6 +413,7 @@ int main() {TestParse();TestParseDefaultsAndFailures();TestSelectDepots();+ TestMissingBaseDepots();TestEligibleLaunches();TestWindowsArguments();TestRelativeGamePath();