Play your Steam library's Windows games on a jailbroken PS5.
C++
Show a game's size from the depots its license grants
Leonardo Lobato140c12d2cab8
diff --git a/src/homebrew/host.cpp b/src/homebrew/host.cppindex f1fcf04..3098c70 100644--- a/src/homebrew/host.cpp+++ b/src/homebrew/host.cpp@@ -410,6 +410,7 @@ int main(int argc, char** argv) {std::unique_ptr<playden::Storage> library_storage;std::unique_ptr<playden::steam::CmClient> cm_client;std::unique_ptr<playden::steam::EntitledLibraryBackend> library_backend;+ playden::steam::LicensedDepots licensed_depots;std::unique_ptr<playden::LibraryCache> library_cache;std::unique_ptr<playden::LibraryService> library_service;std::unique_ptr<playden::PreferencesStore> preferences;@@ -491,6 +492,7 @@ int main(int argc, char** argv) {library_storage = std::make_unique<playden::Storage>(options->data_directory.string());cm_client = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);library_backend = std::make_unique<playden::steam::EntitledLibraryBackend>(*owned_library, *cm_client);+ library_backend->SetLicensedDepots(&licensed_depots);library_cache = std::make_unique<playden::LibraryCache>(*library_storage);library_service = std::make_unique<playden::LibraryService>(*library_backend,*library_sessions,library_cache.get());preferences=std::make_unique<playden::PreferencesStore>(*library_storage);@@ -498,6 +500,7 @@ int main(int argc, char** argv) {persistence=std::make_unique<playden::app::PersistenceService>(*preferences,*organization);details_cm = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);details_source = std::make_unique<playden::steam::CmAppDetailsSource>(*details_cm);+ details_source->SetLicensedDepots(&licensed_depots);details_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string());app_details = std::make_unique<playden::steam::AppDetailsService>(*details_source, *details_sessions);install_cm = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cppindex 932d81f..63d4ea8 100644--- a/src/homebrew/ps5.cpp+++ b/src/homebrew/ps5.cpp@@ -311,6 +311,8 @@ int main() {cm_client.SetOwner("library");cm_client.SetSharedSession(steam_cm);playden::steam::EntitledLibraryBackend library_backend(owned_library, cm_client);+ playden::steam::LicensedDepots licensed_depots;+ library_backend.SetLicensedDepots(&licensed_depots);playden::LibraryCache library_cache(library_storage);playden::LibraryService library_service(library_backend,library_sessions,&library_cache);playden::PreferencesStore preferences(library_storage);@@ -320,6 +322,7 @@ int main() {details_cm.SetOwner("details");details_cm.SetSharedSession(steam_cm);playden::steam::CmAppDetailsSource details_source(details_cm);+ details_source.SetLicensedDepots(&licensed_depots);playden::LocalSessionRepository details_sessions(user_root);playden::steam::AppDetailsService app_details(details_source, details_sessions);playden::steam::CmClient install_cm(paths.trust_store, library_storage);diff --git a/src/steam/backend/cm_app_details.cpp b/src/steam/backend/cm_app_details.cppindex ced05bd..9205f79 100644--- a/src/steam/backend/cm_app_details.cpp+++ b/src/steam/backend/cm_app_details.cpp@@ -4,7 +4,8 @@namespace playden::steam {-AppDetails DetailsFromAppInfo(GameId id, const std::string& buffer) {+AppDetails DetailsFromAppInfo(GameId id, const std::string& buffer,+ const std::optional<LicensedDepots::Grant>& licensed) {AppDetails details;details.id = id;const auto app = ParseAppInfo(id, buffer);@@ -16,7 +17,14 @@ AppDetails DetailsFromAppInfo(GameId id, const std::string& buffer) {std::vector<DepotInfo> depots;std::string reason;const std::set<std::uint32_t> owned{id};- if (!SelectDepots(*app, owned, std::nullopt, &depots, &reason)) {+ // As an install selects them; without licenses, or when they grant none of it, every eligible depot.+ bool selected = false;+ if (licensed) {+ auto apps = licensed->apps;+ apps.insert(id);+ selected = SelectDepots(*app, apps, licensed->depots, &depots, &reason);+ }+ if (!selected && !SelectDepots(*app, owned, std::nullopt, &depots, &reason)) {details.reason = "No Windows content to install.";return details;}@@ -55,7 +63,7 @@ std::vector<AppDetails> CmAppDetailsSource::Fetch(const StoredSession& session,result.push_back(std::move(missing));continue;}- result.push_back(DetailsFromAppInfo(id, found->second));+ result.push_back(DetailsFromAppInfo(id, found->second, licensed_ ? licensed_->Get() : std::nullopt));}return result;}diff --git a/src/steam/backend/cm_app_details.h b/src/steam/backend/cm_app_details.hindex a4d8807..c088e4e 100644--- a/src/steam/backend/cm_app_details.h+++ b/src/steam/backend/cm_app_details.h@@ -11,14 +11,19 @@ namespace playden::steam {class CmAppDetailsSource final : public AppDetailsSource {public:explicit CmAppDetailsSource(CmClient& client) : client_(client) {}+ // The licenses the library last read: sizes then count only the depots they grant.+ void SetLicensedDepots(const LicensedDepots* licensed) { licensed_ = licensed; }std::vector<AppDetails> Fetch(const StoredSession& session, const std::vector<GameId>& ids,const std::atomic<bool>& cancel) override;private:CmClient& client_;+ const LicensedDepots* licensed_ = nullptr;};-// Pure part, for tests: turns one parsed app buffer into details.-AppDetails DetailsFromAppInfo(GameId id, const std::string& buffer);+// Pure part, for tests: turns one parsed app buffer into details. With `licensed`, sizes count+// only the depots those licenses grant, as an install selects them.+AppDetails DetailsFromAppInfo(GameId id, const std::string& buffer,+ const std::optional<LicensedDepots::Grant>& licensed = std::nullopt);} // namespace playden::steamdiff --git a/src/steam/backend/cm_client.h b/src/steam/backend/cm_client.hindex 7364647..5887654 100644--- a/src/steam/backend/cm_client.h+++ b/src/steam/backend/cm_client.h@@ -60,6 +60,28 @@ struct AcquisitionResult {bool ok() const { return error == CmError::kNone; }};+// What the account's licenses granted at the last library load, shared with size estimates so a+// game's page counts only the depots an install would download. Safe from any thread.+class LicensedDepots {+ public:+ struct Grant {+ std::set<std::uint32_t> apps;+ std::set<std::uint32_t> depots;+ };+ void Set(const AcquisitionResult& result) {+ std::lock_guard<std::mutex> lock(mutex_);+ grant_ = Grant{result.owned_apps, result.owned_depots};+ }+ std::optional<Grant> Get() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return grant_;+ }++ private:+ mutable std::mutex mutex_;+ std::optional<Grant> grant_;+};+struct TokenRenewal {CmError error = CmError::kProtocol;std::string access_token;diff --git a/src/steam/backend/entitled_library.cpp b/src/steam/backend/entitled_library.cppindex cc8adb4..dad1daf 100644--- a/src/steam/backend/entitled_library.cpp+++ b/src/steam/backend/entitled_library.cpp@@ -31,6 +31,7 @@ LibraryResult EntitledLibraryBackend::Fetch(const StoredSession& session,last_error_.store(acquisitions.error);if (result.error != LibraryError::kNone || !acquisitions.ok()) return result;+ if (licensed_) licensed_->Set(acquisitions);for (auto& game : result.games) {const auto found = acquisitions.acquired_at.find(game.id);if (found != acquisitions.acquired_at.end()) game.added_at_unix_seconds = found->second;diff --git a/src/steam/backend/entitled_library.h b/src/steam/backend/entitled_library.hindex be1efdc..a9225e0 100644--- a/src/steam/backend/entitled_library.h+++ b/src/steam/backend/entitled_library.h@@ -20,6 +20,8 @@ class EntitledLibraryBackend final : public LibraryBackend {: owned_(owned), acquisitions_(acquisitions) {}LibraryResult Fetch(const StoredSession& session, const std::atomic<bool>& cancel) override;+ // Receives each successful license read, for size estimates.+ void SetLicensedDepots(LicensedDepots* licensed) { licensed_ = licensed; }// Category of the most recent CM attempt, for diagnostics without identifiers.CmError last_acquisition_error() const { return last_error_.load(); }@@ -30,6 +32,7 @@ class EntitledLibraryBackend final : public LibraryBackend {LibraryBackend& owned_;AcquisitionSource& acquisitions_;+ LicensedDepots* licensed_ = nullptr;std::atomic<CmError> last_error_{CmError::kNone};// App ID -> its name when PICS calls it a game, empty when it is something else or undescribed.std::mutex looked_up_mutex_;diff --git a/tests/app_details_test.cpp b/tests/app_details_test.cppindex 20e9a65..5e095ff 100644--- a/tests/app_details_test.cpp+++ b/tests/app_details_test.cpp@@ -184,9 +184,36 @@ void ImpossibleDownloadSizeFallsBackToInstallSize() {assert(details.download_bytes == 30738676601ull + 61851360699ull + 400u);}+// Marvel Rivals lists two copies of its content and a third content depot; the free license grants+// one copy. The page showed 168.5 GB, the sum of all three, for a 74 GB install.+void SizesCountOnlyLicensedDepots() {+ const std::string buffer = R"("appinfo"+{+ "appid" "2767030"+ "common" { "name" "Synthetic Rivals" "type" "Game" }+ "config" { "launch" { "0" { "executable" "Rivals.exe" "config" { "oslist" "windows" } } } }+ "depots"+ {+ "2767031" { "manifests" { "public" { "gid" "1" "size" "74083193346" "download" "67000000000" } } }+ "2767032" { "manifests" { "public" { "gid" "2" "size" "74083193346" "download" "67000000000" } } }+ "2767033" { "manifests" { "public" { "gid" "3" "size" "20311069758" "download" "18000000000" } } }+ }+})";+ const auto unlicensed = DetailsFromAppInfo(2767030, buffer);+ assert(unlicensed.install_bytes == 2 * 74083193346ull + 20311069758ull);+ LicensedDepots::Grant grant{{2767030}, {2767031}};+ const auto licensed = DetailsFromAppInfo(2767030, buffer, grant);+ assert(licensed.available && licensed.windows_installable);+ assert(licensed.install_bytes == 74083193346ull && licensed.download_bytes == 67000000000ull);+ // Licenses that grant none of it (not loaded for this game yet) keep the full estimate.+ const auto none = DetailsFromAppInfo(2767030, buffer, LicensedDepots::Grant{{}, {}});+ assert(none.install_bytes == unlicensed.install_bytes);+}+} // namespaceint main() {+ SizesCountOnlyLicensedDepots();RequestsAreDeduplicatedPerGeneration();NewGenerationDropsResultsAndRefetches();FailuresAreRetryable();