Play your Steam library's Windows games on a jailbroken PS5.
C++
List free games added to the library from their licenses
Leonardo Lobatocf84216996c5
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cppindex e084c2f..080b779 100644--- a/src/steam/backend/app_info.cpp+++ b/src/steam/backend/app_info.cpp@@ -327,6 +327,7 @@ std::optional<AppInfo> ParseAppInfo(std::uint32_t app_id, std::string_view buffeapp.type = type ? std::string(*type) : "?";app.install_dir = ChildString(config, "installdir");app.controller_support = ChildString(common, "controller_support");+ app.icon = ChildString(common, "icon");std::optional<std::string_view> dlc_list;if (const VdfNode* extended = root->Find("extended")) dlc_list = extended->String("listofdlc");diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.hindex 4f98a23..4f86ef9 100644--- a/src/steam/backend/app_info.h+++ b/src/steam/backend/app_info.h@@ -78,6 +78,7 @@ struct AppInfo {std::vector<std::uint32_t> dlc_app_ids;std::vector<AppLaunch> launches; // sorted by idstd::string controller_support;+ std::string icon; // common/icon: the hash of the library icon, as GetOwnedGames img_icon_urlCloudSaveInfo cloud;};diff --git a/src/steam/backend/cm_client.cpp b/src/steam/backend/cm_client.cppindex 4015aaa..8d0ef33 100644--- a/src/steam/backend/cm_client.cpp+++ b/src/steam/backend/cm_client.cpp@@ -960,6 +960,7 @@ AcquisitionResult CmClient::FetchAcquisitionDates(const StoredSession& stored,result.acquired_at.clear();result.owned_apps.clear();result.owned_depots.clear();+ result.package_apps.clear();}return result;};@@ -1030,6 +1031,7 @@ AcquisitionResult CmClient::FetchAcquisitionDates(const StoredSession& stored,if (!inserted) entry->second = std::min(entry->second, license->time_created);}}+ result.package_apps = std::move(package_apps);return finish(CmError::kNone);}diff --git a/src/steam/backend/cm_client.h b/src/steam/backend/cm_client.hindex 6a8c5fe..af85b49 100644--- a/src/steam/backend/cm_client.h+++ b/src/steam/backend/cm_client.h@@ -52,6 +52,8 @@ struct AcquisitionResult {// Apps and depots granted by those licenses' packages, for depot selection.std::set<std::uint32_t> owned_apps;std::set<std::uint32_t> owned_depots;+ // The apps of each active licensed package, for games the owned list leaves out.+ std::map<std::uint32_t, std::vector<std::uint32_t>> package_apps;// Licensed packages Steam left out, sent without a token, or sent unreadable; their apps are not owned here.std::uint32_t skipped_packages = 0;bool ok() const { return error == CmError::kNone; }@@ -99,6 +101,11 @@ class AcquisitionSource {virtual ~AcquisitionSource() = default;virtual AcquisitionResult FetchAcquisitionDates(const StoredSession& session,const std::atomic<bool>& cancel) = 0;+ // PICS app info, to name licensed games the owned list leaves out. None by default.+ virtual AppInfoBuffers FetchAppInfo(const StoredSession&, const std::vector<std::uint32_t>&,+ const std::atomic<bool>&) {+ return {};+ }};// Derives the stable logon device fields from a per-install seed, as the reference@@ -158,7 +165,7 @@ class CmClient final : public AcquisitionSource {const std::atomic<bool>& cancel);AppInfoBuffers FetchAppInfo(const StoredSession& session, const std::vector<std::uint32_t>& app_ids,- const std::atomic<bool>& cancel);+ const std::atomic<bool>& cancel) override;// A unified service call on an open session. When Steam refuses it, the result is kRejected and// `eresult` (optional) holds Steam's EResult.diff --git a/src/steam/backend/entitled_library.cpp b/src/steam/backend/entitled_library.cppindex 71c1a41..cc8adb4 100644--- a/src/steam/backend/entitled_library.cpp+++ b/src/steam/backend/entitled_library.cpp@@ -1,6 +1,11 @@#include "steam/backend/entitled_library.h"+#include "steam/backend/app_info.h"++#include <algorithm>+#include <cctype>#include <chrono>+#include <set>#include <thread>namespace playden::steam {@@ -30,7 +35,59 @@ LibraryResult EntitledLibraryBackend::Fetch(const StoredSession& session,const auto found = acquisitions.acquired_at.find(game.id);if (found != acquisitions.acquired_at.end()) game.added_at_unix_seconds = found->second;}+ AddLicensedGames(session, acquisitions, cancel, &result);return result;}+void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,+ const AcquisitionResult& acquisitions,+ const std::atomic<bool>& cancel, LibraryResult* result) {+ std::set<std::uint32_t> listed;+ for (const auto& game : result->games) listed.insert(game.id);+ // A package with a listed app is a bought game (with its DLC) the owned list already covers.+ // Package 0 is Steam's basic free package, which GetOwnedGames leaves out on purpose.+ std::set<std::uint32_t> candidates;+ for (const auto& [package, apps] : acquisitions.package_apps) {+ if (package == 0 || std::any_of(apps.begin(), apps.end(), [&](auto app) { return listed.count(app); })) continue;+ candidates.insert(apps.begin(), apps.end());+ }+ if (candidates.empty()) return;++ std::lock_guard<std::mutex> lock(looked_up_mutex_);+ std::vector<std::uint32_t> unknown;+ for (const auto app : candidates)+ if (!looked_up_.count(app)) unknown.push_back(app);+ for (std::size_t start = 0; start < unknown.size() && !cancel.load(); start += kMaxAppInfoBatch) {+ const std::vector<std::uint32_t> batch(+ unknown.begin() + static_cast<std::ptrdiff_t>(start),+ unknown.begin() + static_cast<std::ptrdiff_t>(std::min(start + kMaxAppInfoBatch, unknown.size())));+ const auto fetched = acquisitions_.FetchAppInfo(session, batch, cancel);+ // Unanswered apps are asked again on the next refresh.+ if (!fetched.ok()) break;+ for (const auto app : batch) {+ std::string name;+ const auto found = fetched.buffers.find(app);+ if (found != fetched.buffers.end()) {+ const auto info = ParseAppInfo(app, found->second);+ std::string type = info ? info->type : std::string();+ std::transform(type.begin(), type.end(), type.begin(), [](unsigned char c) { return std::tolower(c); });+ if (info && type == "game" && info->name != "app_" + std::to_string(app)) name = info->name;+ if (!name.empty() && info && !info->icon.empty())+ icons_[app] = "https://media.steampowered.com/steamcommunity/public/images/apps/" + std::to_string(app) ++ "/" + info->icon + ".jpg";+ }+ looked_up_[app] = name;+ }+ }+ for (const auto app : candidates) {+ const auto found = looked_up_.find(app);+ if (found == looked_up_.end() || found->second.empty()) continue;+ GameSummary game{app, found->second, {}, {}, {}};+ if (const auto icon = icons_.find(app); icon != icons_.end()) game.artwork_source = icon->second;+ if (const auto added = acquisitions.acquired_at.find(app); added != acquisitions.acquired_at.end())+ game.added_at_unix_seconds = added->second;+ result->games.push_back(std::move(game));+ }+}+} // namespace playden::steamdiff --git a/src/steam/backend/entitled_library.h b/src/steam/backend/entitled_library.hindex afa2ef3..be1efdc 100644--- a/src/steam/backend/entitled_library.h+++ b/src/steam/backend/entitled_library.h@@ -3,11 +3,17 @@#include "steam/backend/cm_client.h"#include "steam/library_backend.h"+#include <mutex>+#include <unordered_map>+namespace playden::steam {// The owned library from GetOwnedGames, enriched with CM acquisition dates. As in the macOS// reference, both run in parallel and a CM failure is never fatal: games then simply lack a date.// A CM logon rejection never reports revoked credentials.+// GetOwnedGames leaves out free-to-play games added to the library but never played. Licensed+// packages none of whose apps are listed are looked up in PICS, and their games are added. Each+// app is looked up once per run, so after the first load a refresh only asks about new licenses.class EntitledLibraryBackend final : public LibraryBackend {public:EntitledLibraryBackend(LibraryBackend& owned, AcquisitionSource& acquisitions)@@ -19,9 +25,16 @@ class EntitledLibraryBackend final : public LibraryBackend {CmError last_acquisition_error() const { return last_error_.load(); }private:+ void AddLicensedGames(const StoredSession& session, const AcquisitionResult& acquisitions,+ const std::atomic<bool>& cancel, LibraryResult* result);+LibraryBackend& owned_;AcquisitionSource& acquisitions_;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_;+ std::unordered_map<std::uint32_t, std::string> looked_up_;+ std::unordered_map<std::uint32_t, std::string> icons_;};} // namespace playden::steamdiff --git a/src/steam/backend/library_client.cpp b/src/steam/backend/library_client.cppindex 6a66344..0bb461a 100644--- a/src/steam/backend/library_client.cpp+++ b/src/steam/backend/library_client.cpp@@ -123,13 +123,13 @@ LibraryResult LibraryClient::Fetch(const StoredSession& session,HttpRequest request;request.method = HttpMethod::kGet;- // include_free_sub: a free-to-play game added to the library but never played is only- // returned with it; include_played_free_games covers the ones played at least once.+ // A free-to-play game added to the library but never played isn't listed, whatever the+ // options; EntitledLibraryBackend adds those from the account's licenses.request.url ="https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/""?access_token=" + PercentEncode(session.access_token) +"&steamid=" + std::to_string(session.steam_id) +- "&include_appinfo=true&include_played_free_games=true&include_free_sub=true&format=json";+ "&include_appinfo=true&include_played_free_games=true&format=json";request.headers = {{"User-Agent", "Playden/1.0"}};request.timeout_ms = kRequestTimeoutMs;request.max_response_bytes = kBodyLimit;diff --git a/tests/entitled_library_test.cpp b/tests/entitled_library_test.cppindex 4c6a316..db31146 100644--- a/tests/entitled_library_test.cpp+++ b/tests/entitled_library_test.cpp@@ -1,8 +1,12 @@#include "steam/backend/entitled_library.h"+#include <algorithm>#include <atomic>#include <cassert>#include <chrono>+#include <map>+#include <string>+#include <vector>#include <thread>using namespace playden;@@ -20,6 +24,16 @@ struct Acquisitions final : AcquisitionSource {AcquisitionResult result{CmError::kNone, {{10, 1500000000u}, {99, 1400000000u}}};bool block_until_stopped = false;std::atomic<bool> saw_stop{false};+ std::map<std::uint32_t, std::string> app_info;+ std::vector<std::vector<std::uint32_t>> app_info_requests;+ AppInfoBuffers FetchAppInfo(const StoredSession&, const std::vector<std::uint32_t>& ids,+ const std::atomic<bool>&) override {+ app_info_requests.push_back(ids);+ AppInfoBuffers result{CmError::kNone, {}};+ for (const auto id : ids)+ if (const auto found = app_info.find(id); found != app_info.end()) result.buffers[id] = found->second;+ return result;+ }AcquisitionResult FetchAcquisitionDates(const StoredSession&, const std::atomic<bool>& cancel) override {while (block_until_stopped) {if (cancel) {@@ -87,9 +101,51 @@ void CancelReachesARunningCmSession() {assert(!result.games[0].added_at_unix_seconds);}+std::string AppInfoText(std::uint32_t id, const std::string& name, const std::string& type) {+ return "\"appinfo\"\n{\n\t\"appid\"\t\"" + std::to_string(id) + "\"\n\t\"common\"\n\t{\n\t\t\"name\"\t\"" + name ++ "\"\n\t\t\"type\"\t\"" + type + "\"\n\t\t\"icon\"\t\"abc123\"\n\t}\n}\n";+}++// A free-to-play game added with "Add to library" and never played: GetOwnedGames leaves it out,+// its free license names it. Packages with a listed game, DLC and tools add nothing.+void LicensedFreeGamesAreAdded() {+ Owned owned;+ Acquisitions acquisitions;+ acquisitions.result.acquired_at[2767030] = 1700000000u;+ acquisitions.result.package_apps = {{0, {480}}, // Steam's basic free package+ {100, {10, 11}}, // a bought game and its DLC+ {200, {2767030}}, // the free game+ {300, {30}}, // DLC bought on its own+ {400, {40}}}; // an app Steam doesn't describe+ acquisitions.app_info = {{2767030, AppInfoText(2767030, "Synthetic Rivals", "Game")},+ {30, AppInfoText(30, "Synthetic DLC", "DLC")},+ {480, AppInfoText(480, "Spacewar", "Game")}};+ EntitledLibraryBackend backend(owned, acquisitions);+ std::atomic<bool> cancel{false};+ auto result = backend.Fetch(Session(), cancel);+ assert(result.error == LibraryError::kNone && result.games.size() == 3);+ const auto& added = result.games.back();+ assert(added.id == 2767030 && added.title == "Synthetic Rivals" && added.added_at_unix_seconds == 1700000000u);+ assert(added.artwork_source == "https://media.steampowered.com/steamcommunity/public/images/apps/2767030/abc123.jpg");+ assert(acquisitions.app_info_requests.size() == 1);+ assert((acquisitions.app_info_requests[0] == std::vector<std::uint32_t>{30, 40, 2767030}));++ // A refresh asks only about apps it hasn't seen this run.+ acquisitions.result.package_apps[500] = {50};+ acquisitions.app_info[50] = AppInfoText(50, "Synthetic New", "game");+ result = backend.Fetch(Session(), cancel);+ assert(result.games.size() == 4 && std::any_of(result.games.begin(), result.games.end(),+ [](const auto& game) { return game.title == "Synthetic New"; }));+ assert(acquisitions.app_info_requests.size() == 2 &&+ (acquisitions.app_info_requests[1] == std::vector<std::uint32_t>{50}));+ result = backend.Fetch(Session(), cancel);+ assert(result.games.size() == 4 && acquisitions.app_info_requests.size() == 2);+}+} // namespaceint main() {+ LicensedFreeGamesAreAdded();DatesMergeIntoOwnedGames();CmFailureIsNeverFatal();OwnedFailureStopsTheCmSession();diff --git a/tests/library_client_test.cpp b/tests/library_client_test.cppindex f6e755e..0dc1a97 100644--- a/tests/library_client_test.cpp+++ b/tests/library_client_test.cpp@@ -103,7 +103,7 @@ void RequestAndMapping() {assert(request.url =="https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/""?access_token=synthetic-token&steamid=76561198000000001&include_appinfo=true&"- "include_played_free_games=true&include_free_sub=true&format=json");+ "include_played_free_games=true&format=json");const std::vector<std::pair<std::string, std::string>> expected_headers = {{"User-Agent", "Playden/1.0"}};assert(request.headers == expected_headers);@@ -112,8 +112,7 @@ void RequestAndMapping() {assert(request.max_response_bytes == 16 * 1024 * 1024);}-// A free-to-play game added to the library and never played, as include_free_sub returns it:-// no playtime, no last played time, and fields Playden doesn't read.+// A free-to-play game once played: no playtime, no last played time, and fields Playden doesn't read.void FreeGameNeverPlayed() {Fixture fixture;const auto result = Fetch(&fixture,