Skip to content

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

C++

Unlock owned DLC that the game's DLC list leaves out

Leonardo Lobato5d3e9e185c73
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index e8f907e..eeaac79 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -570,6 +570,15 @@ int main() {
std::fclose(file);
if (!bytes.empty()) generic_icon = std::move(bytes);
}
+ // Owned DLC: the game's looked-up DLC that the last license read of this account grants.
+ config.owned_dlc = [&library_backend, &licensed_depots](std::uint64_t steam_id, std::uint32_t app_id) {
+ std::vector<std::uint32_t> owned;
+ const auto grant = licensed_depots.Get(steam_id);
+ if (!grant) return owned;
+ for (const auto dlc : library_backend.DlcOf(app_id))
+ if (grant->apps.count(dlc)) owned.push_back(dlc);
+ return owned;
+ };
config.title_icon = [trust = paths.trust_store, art_cache_dir, generic_icon](const playden::GameId& game) -> std::optional<std::string> {
// A store with no cover for the game (an imported one) gets the generic icon.
const auto source = playden::homebrew::CoverUrl(game);
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 2e14402..6082ea0 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -826,8 +826,26 @@ std::string RuntimeHost::SteamworksStep(const GameFiles& files, bool steam_accou
identity.account_name = steam_account_name_;
identity.steam_id = steam_id_;
}
- if (!rt::ReadSteamworksFacts(root.string(), &identity))
+ const bool facts = rt::ReadSteamworksFacts(root.string(), &identity);
+ if (!facts)
Log("steamworks app=" + std::to_string(record.runtime_number) + " no download facts: no DLC or depots listed");
+ // DLC the account owns that the download didn't record. They stay in the facts, so a start before the
+ // next license read still has them.
+ if (config_.owned_dlc) {
+ const auto listed = [](const std::vector<std::uint32_t>& ids, std::uint32_t id) {
+ return std::find(ids.begin(), ids.end(), id) != ids.end();
+ };
+ std::vector<std::uint32_t> added;
+ for (const auto dlc : config_.owned_dlc(identity.steam_id, steam_app.app_id))
+ if (dlc != steam_app.app_id && !listed(identity.owned_dlc, dlc) && !listed(added, dlc)) added.push_back(dlc);
+ if (!added.empty()) {
+ identity.owned_dlc.insert(identity.owned_dlc.end(), added.begin(), added.end());
+ const bool kept = !facts || other_store ||
+ rt::WriteSteamworksFacts(root.string(), identity.depots, identity.owned_dlc, identity.language);
+ Log("steamworks app=" + std::to_string(record.runtime_number) + " owned dlc added=" + std::to_string(added.size()) +
+ " total=" + std::to_string(identity.owned_dlc.size()) + (kept ? "" : " facts=write-failed"));
+ }
+ }
const auto emulator = config_.steamworks_dir.empty() ? config_.runtime_dir + "/steamworks" : config_.steamworks_dir;
// A game from another store keeps its folder as it shipped: no steam_appid.txt of Playden's would hide
// the game's lack of one, so a later app ID in Game settings still reaches the emulator.
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index 3d98f3f..bc2c77e 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -114,6 +114,10 @@ struct RuntimeHostConfig {
// nothing (the kit's icon stays). Runs on the worker; may use the network.
// Named by the game, so a runtime number never reaches a store's artwork.
std::function<std::optional<std::string>(const GameId& game)> title_icon;
+ // The DLC of a Steam game this account owns, from the Library's license read and app lookups
+ // (EntitledLibraryBackend::DlcOf). Each prepare adds them to what the download recorded, so DLC past
+ // the 64 that Steam's listofdlc names, or bought after the download, reach the emulator. Empty: none.
+ std::function<std::vector<std::uint32_t>(std::uint64_t steam_id, std::uint32_t app_id)> owned_dlc;
// One ranged HTTPS GET for what Playden downloads for a game's bottle: Microsoft's Visual C++ redistributable,
// for a game whose files import MFC (runtime/redist_install.h). Runs on the worker, only for work the player
// started (Play, Prepare, maintenance), never at start-up; it should give up soon after cancel turns true
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cpp
index f286a24..31fd347 100644
--- a/src/steam/backend/app_info.cpp
+++ b/src/steam/backend/app_info.cpp
@@ -368,6 +368,16 @@ std::optional<AppInfo> ParseAppInfo(std::uint32_t app_id, std::string_view buffe
if (const VdfNode* extended = common->Find("extended")) dlc_list = extended->String("listofdlc");
}
if (dlc_list) app.dlc_app_ids = ParseDlcList(*dlc_list);
+ // listofdlc stops at 64 entries (Monster Hunter: World's leaves out Iceborne): a DLC names its game itself,
+ // in dlcforappid (whatever its type says, as GameNative reads it), else in common/parent when it is a DLC.
+ {
+ std::optional<std::uint32_t> game;
+ if (const VdfNode* extended = root->Find("extended")) game = ChildU32(extended, "dlcforappid");
+ if ((!game || !*game) && common != nullptr)
+ if (const VdfNode* extended = common->Find("extended")) game = ChildU32(extended, "dlcforappid");
+ if ((!game || !*game) && LowerString(app.type) == "dlc") game = ChildU32(common, "parent");
+ if (game && *game != 0 && *game != app_id) app.dlc_for_app_id = *game;
+ }
app.cloud = ParseCloudSaves(root->Find("ufs"));
if (config != nullptr) {
diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.h
index 3f90bdd..8fd7793 100644
--- a/src/steam/backend/app_info.h
+++ b/src/steam/backend/app_info.h
@@ -100,7 +100,9 @@ struct AppInfo {
std::string install_dir;
std::vector<DepotInfo> depots; // Steam listing order (depot mounting order)
std::vector<AppBranch> branches;
- std::vector<std::uint32_t> dlc_app_ids;
+ 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;
std::vector<AppLaunch> launches; // sorted by id
std::string controller_support;
std::string icon; // common/icon: the hash of the library icon, as GetOwnedGames img_icon_url
diff --git a/src/steam/backend/app_names.cpp b/src/steam/backend/app_names.cpp
index 86b714c..6a7656d 100644
--- a/src/steam/backend/app_names.cpp
+++ b/src/steam/backend/app_names.cpp
@@ -8,10 +8,15 @@ namespace playden::steam {
namespace {
constexpr const char* kPath = "app-names.cache";
-const Bytes kMagic = {'P', 'D', 'N', 'A', 'M', 'E', 0, 1};
+// Version 2 added each entry's dlc_for. Version 1 files still load, without their kOther entries.
+const Bytes kMagicV1 = {'P', 'D', 'N', 'A', 'M', 'E', 0, 1};
+const Bytes kMagic = {'P', 'D', 'N', 'A', 'M', 'E', 0, 2};
constexpr std::size_t kMaxName = 1024;
constexpr std::size_t kMaxIcon = 64;
-constexpr std::size_t kMaxBytes = 4 * 1024 * 1024;
+// Games and demos fill at most kMaxNamedBytes; the other apps' entries are fixed-size and fit beside them.
+constexpr std::size_t kMaxNamedBytes = 4 * 1024 * 1024;
+constexpr std::size_t kOtherEntryBytes = 4 + 1 + 8 + 2 + 2 + 4;
+constexpr std::size_t kMaxBytes = kMaxNamedBytes + kMaxOtherApps * kOtherEntryBytes;
std::uint32_t Checksum(const Bytes& bytes, std::size_t size) {
std::uint32_t crc = 0xffffffffu;
@@ -62,13 +67,15 @@ AppNames LoadAppNames(const Storage& storage) {
const auto read = storage.Read(kPath, kMaxBytes);
if (!read.ok()) return {};
const Bytes& bytes = read.value();
- if (bytes.size() < kMagic.size() + 8 || !std::equal(kMagic.begin(), kMagic.end(), bytes.begin())) return {};
+ if (bytes.size() < kMagic.size() + 8) return {};
+ const bool v1 = std::equal(kMagicV1.begin(), kMagicV1.end(), bytes.begin());
+ if (!v1 && !std::equal(kMagic.begin(), kMagic.end(), bytes.begin())) return {};
const std::size_t body = bytes.size() - 4;
Reader crc{bytes, body, bytes.size()};
if (static_cast<std::uint32_t>(crc.Number(4)) != Checksum(bytes, body)) return {};
Reader reader{bytes, kMagic.size(), body};
const auto count = reader.Number(4);
- if (!reader.okay || count > kMaxAppNames) return {};
+ if (!reader.okay || count > kMaxAppNames + kMaxOtherApps) return {};
AppNames names;
names.reserve(static_cast<std::size_t>(count));
for (std::uint64_t i = 0; i < count; ++i) {
@@ -78,9 +85,11 @@ AppNames LoadAppNames(const Storage& storage) {
name.learned_at = reader.Number(8);
name.name = reader.String(kMaxName);
name.icon = reader.String(kMaxIcon);
+ if (!v1) name.dlc_for = static_cast<std::uint32_t>(reader.Number(4));
if (!reader.okay || !id || kind > 2) return {};
name.kind = static_cast<AppName::Kind>(kind);
if (name.kind != AppName::Kind::kOther && name.name.empty()) return {};
+ if (v1 && name.kind == AppName::Kind::kOther) continue;
names[id] = std::move(name);
}
if (reader.offset != body) return {};
@@ -88,25 +97,30 @@ AppNames LoadAppNames(const Storage& storage) {
}
bool SaveAppNames(const Storage& storage, const AppNames& names) {
- std::vector<std::pair<std::uint32_t, const AppName*>> entries;
- entries.reserve(names.size());
+ using Entry = std::pair<std::uint32_t, const AppName*>;
+ std::vector<Entry> named, others;
for (const auto& [id, name] : names) {
if (!id || name.name.size() > kMaxName || name.icon.size() > kMaxIcon) continue;
- if (name.kind != AppName::Kind::kOther && name.name.empty()) continue;
- entries.emplace_back(id, &name);
+ if (name.kind == AppName::Kind::kOther) others.emplace_back(id, &name);
+ else if (!name.name.empty()) named.emplace_back(id, &name);
}
- // The newest stay, as many as Load accepts: kMaxAppNames entries in kMaxBytes.
- std::sort(entries.begin(), entries.end(),
- [](const auto& a, const auto& b) { return a.second->learned_at > b.second->learned_at; });
+ // The newest stay, as many as Load accepts: kMaxAppNames games and demos in kMaxNamedBytes, and
+ // kMaxOtherApps other apps without a name or icon.
+ const auto newest = [](const Entry& a, const Entry& b) { return a.second->learned_at > b.second->learned_at; };
+ std::sort(named.begin(), named.end(), newest);
std::size_t bytes = kMagic.size() + 4 + 4;
std::size_t kept = 0;
- for (; kept < entries.size() && kept < kMaxAppNames; ++kept) {
- const auto& name = *entries[kept].second;
- const std::size_t size = 4 + 1 + 8 + 2 + name.name.size() + 2 + name.icon.size();
- if (bytes + size > kMaxBytes) break;
+ for (; kept < named.size() && kept < kMaxAppNames; ++kept) {
+ const auto& name = *named[kept].second;
+ const std::size_t size = 4 + 1 + 8 + 2 + name.name.size() + 2 + name.icon.size() + 4;
+ if (bytes + size > kMaxNamedBytes) break;
bytes += size;
}
- entries.resize(kept);
+ named.resize(kept);
+ std::sort(others.begin(), others.end(), newest);
+ if (others.size() > kMaxOtherApps) others.resize(kMaxOtherApps);
+ std::vector<Entry> entries = std::move(named);
+ entries.insert(entries.end(), others.begin(), others.end());
std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) { return a.first < b.first; });
Bytes out = kMagic;
Number(out, entries.size(), 4);
@@ -114,10 +128,13 @@ bool SaveAppNames(const Storage& storage, const AppNames& names) {
Number(out, id, 4);
Number(out, static_cast<std::uint8_t>(name->kind), 1);
Number(out, name->learned_at, 8);
- Number(out, name->name.size(), 2);
- out.insert(out.end(), name->name.begin(), name->name.end());
- Number(out, name->icon.size(), 2);
- out.insert(out.end(), name->icon.begin(), name->icon.end());
+ // Another app keeps no name or icon, so it takes kOtherEntryBytes.
+ const bool other = name->kind == AppName::Kind::kOther;
+ Number(out, other ? 0 : name->name.size(), 2);
+ if (!other) out.insert(out.end(), name->name.begin(), name->name.end());
+ Number(out, other ? 0 : name->icon.size(), 2);
+ if (!other) out.insert(out.end(), name->icon.begin(), name->icon.end());
+ Number(out, name->dlc_for, 4);
}
Number(out, Checksum(out, out.size()), 4);
return storage.WriteAtomic(kPath, out).ok();
diff --git a/src/steam/backend/app_names.h b/src/steam/backend/app_names.h
index 51d9e39..d69a6d0 100644
--- a/src/steam/backend/app_names.h
+++ b/src/steam/backend/app_names.h
@@ -10,21 +10,29 @@
namespace playden::steam {
// What the Library needs about a Steam app it only knows from a license: whether it is a game or a demo
-// and its name. Anything else (DLC, tools, configs) is kept as kOther, so it is never looked up again.
+// and its name. Anything else (DLC, tools, configs) is kept as kOther, so it is never looked up again; a DLC
+// keeps the game it belongs to, which is how a game's DLC past listofdlc's 64 entries is found.
struct AppName {
enum class Kind : std::uint8_t { kOther = 0, kGame = 1, kDemo = 2 };
Kind kind = Kind::kOther;
std::string name; // empty for kOther
std::string icon; // the PICS icon hash, when known
std::uint64_t learned_at = 0; // unix seconds
+ std::uint32_t dlc_for = 0; // a DLC's game (AppInfo::dlc_for_app_id), else 0
};
using AppNames = std::unordered_map<std::uint32_t, AppName>;
+// Games and demos, with their names and icons.
inline constexpr std::size_t kMaxAppNames = 20'000;
+// Other apps (DLC, tools, configs), a few bytes each and kept apart, so the DLC every license brings can't
+// push games out or be pushed out and looked up again on every load.
+inline constexpr std::size_t kMaxOtherApps = 100'000;
// "app-names.cache" in user storage. Names are public data, shared by every account on the console.
-// Load returns nothing for a missing, damaged or foreign file; Save keeps the newest kMaxAppNames.
+// Load returns nothing for a missing, damaged or foreign file; Save keeps the newest kMaxAppNames games and
+// demos and the newest kMaxOtherApps other apps. A file
+// from before DLC kept their game loads without its kOther entries, so those are looked up again.
AppNames LoadAppNames(const Storage& storage);
bool SaveAppNames(const Storage& storage, const AppNames& names);
diff --git a/src/steam/backend/entitled_library.cpp b/src/steam/backend/entitled_library.cpp
index 93bb373..9fd821c 100644
--- a/src/steam/backend/entitled_library.cpp
+++ b/src/steam/backend/entitled_library.cpp
@@ -234,6 +234,7 @@ std::optional<AppName> NameFromAppInfo(std::uint32_t app, const std::string& tex
} else {
*reason = type != "game" && type != "demo" ? "type=" + (type.empty() ? std::string("none") : type.substr(0, 32))
: "no_name";
+ name.dlc_for = info->dlc_for_app_id;
}
name.learned_at = UnixNow();
return name;
@@ -318,6 +319,7 @@ void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,
family_log_(line);
};
std::vector<std::uint32_t> unknown;
+ std::vector<std::uint32_t> dlc_lookups;
{
std::lock_guard<std::mutex> lock(names_mutex_);
LoadNamesLocked();
@@ -390,6 +392,14 @@ void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,
if (const auto found = family->find(app); found != family->end())
late_context_.family_acquired[app] = found->second.rt_time_acquired;
late_games_.clear();
+ // The other licensed apps no lookup has named, a bought game's DLC among them, are looked up too: not for
+ // the Library, but for the game each DLC names (DlcOf).
+ std::set<std::uint32_t> queued(unknown.begin(), unknown.end());
+ for (const auto& [package, apps] : acquisitions.package_apps) {
+ if (package == 0) continue;
+ for (const auto app : apps)
+ if (!listed.count(app) && !names_.count(app) && queued.insert(app).second) dlc_lookups.push_back(app);
+ }
}
if (family_log_) {
if (truncated) family_log_("family library truncated=" + std::to_string(truncated));
@@ -402,15 +412,27 @@ void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,
" in_owned_list=" + std::to_string(in_owned_list) + " named_family=" + std::to_string(named_family) +
" named_saved=" + std::to_string(named_saved) +
" family_list=" + (!family ? "n" : family_fresh ? "y" : "stale") +
- " lookups=" + std::to_string(unknown.size()));
+ " lookups=" + std::to_string(unknown.size()) + " dlc_lookups=" + std::to_string(dlc_lookups.size()));
}
- if (unknown.empty() || cancel.load()) {
+ if ((unknown.empty() && dlc_lookups.empty()) || cancel.load()) {
SaveNames();
return;
}
+ // The Library's own lookups first: they name games, which it waits for.
+ unknown.insert(unknown.end(), dlc_lookups.begin(), dlc_lookups.end());
StartLookups(session, std::move(unknown));
}
+std::vector<std::uint32_t> EntitledLibraryBackend::DlcOf(std::uint32_t app) {
+ std::lock_guard<std::mutex> lock(names_mutex_);
+ LoadNamesLocked();
+ std::vector<std::uint32_t> out;
+ for (const auto& [id, name] : names_)
+ if (name.kind == AppName::Kind::kOther && name.dlc_for == app) out.push_back(id);
+ std::sort(out.begin(), out.end());
+ return out;
+}
+
void EntitledLibraryBackend::StopLookups() {
std::lock_guard<std::mutex> guard(lookup_start_mutex_);
lookup_stop_.store(true);
diff --git a/src/steam/backend/entitled_library.h b/src/steam/backend/entitled_library.h
index 298996a..9d79085 100644
--- a/src/steam/backend/entitled_library.h
+++ b/src/steam/backend/entitled_library.h
@@ -18,6 +18,7 @@
#include <thread>
#include <unordered_map>
#include <unordered_set>
+#include <vector>
namespace playden::steam {
@@ -48,6 +49,9 @@ class EntitledLibraryBackend final : public LibraryBackend {
void SetFamilyWait(std::chrono::milliseconds wait) { family_wait_ = wait; }
// Receives each successful license read, for size estimates.
void SetLicensedDepots(LicensedDepots* licensed) { licensed_ = licensed; }
+ // The licensed DLC apps already looked up that name `app` as their game, sorted, whoever's licenses they
+ // came from (names are public data). Steam's listofdlc stops at 64 entries; this finds the rest.
+ std::vector<std::uint32_t> DlcOf(std::uint32_t app);
// Asks Steam's family service over HTTPS (with this CA bundle; the background lookup's HTTP uses it too)
// and writes "family" lines: which family-shared apps the Library got or left out, and what the service
diff --git a/tests/entitled_library_test.cpp b/tests/entitled_library_test.cpp
index bb9ef4f..816dd82 100644
--- a/tests/entitled_library_test.cpp
+++ b/tests/entitled_library_test.cpp
@@ -75,6 +75,12 @@ std::string AppInfoText(std::uint32_t id, const std::string& name, const std::st
"\"\n\t\t\"type\"\t\"" + type + "\"\n\t\t\"icon\"\t\"abc123\"\n\t}\n}\n";
}
+// A DLC's app info, naming its game the way Steam does.
+std::string DlcInfoText(std::uint32_t id, std::uint32_t game) {
+ return "\"appinfo\"\n{\n\t\"appid\"\t\"" + std::to_string(id) + "\"\n\t\"common\"\n\t{\n\t\t\"type\"\t\"DLC\"\n\t}\n" +
+ "\t\"extended\"\n\t{\n\t\t\"dlcforappid\"\t\"" + std::to_string(game) + "\"\n\t}\n}\n";
+}
+
// A load, the background lookup it started, then a load that lists what the lookup named.
LibraryResult Settled(EntitledLibraryBackend& backend, const StoredSession& session = Session()) {
std::atomic<bool> cancel{false};
@@ -227,6 +233,7 @@ void LicensedFreeGamesAreAdded() {
{400, {40}}}; // an app Steam doesn't know
acquisitions.app_info = {{2767030, AppInfoText(2767030, "Synthetic Rivals", "Game")},
{30, AppInfoText(30, "Synthetic DLC", "DLC")},
+ {11, DlcInfoText(11, 10)},
{480, AppInfoText(480, "Spacewar", "Game")}};
acquisitions.unanswered = {{40, "unknown"}};
EntitledLibraryBackend backend(owned, acquisitions);
@@ -241,7 +248,9 @@ void LicensedFreeGamesAreAdded() {
const auto& added = late.back();
assert(added.id == SteamId(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.Requests() == std::vector<std::vector<std::uint32_t>>{{30, 40, 2767030}}));
+ // The listed game's DLC is looked up after the Library's apps, for the game it names, not for the Library.
+ assert((acquisitions.Requests() == std::vector<std::vector<std::uint32_t>>{{30, 40, 2767030, 11}}));
+ assert((backend.DlcOf(10) == std::vector<std::uint32_t>{11}) && backend.DlcOf(20).empty() && !Find(result, 11));
result = backend.Fetch(Session(), cancel);
assert(result.games.size() == 3 && Find(result, 2767030));
@@ -339,21 +348,56 @@ void AppNamesFileRoundTrips() {
AppNames names;
names[10] = AppName{AppName::Kind::kGame, "Synthetic Game", "abc", 100};
names[11] = AppName{AppName::Kind::kDemo, "Synthetic Demo", "", 101};
- names[12] = AppName{AppName::Kind::kOther, "", "", 102};
+ names[12] = AppName{AppName::Kind::kOther, "", "", 102, 10};
assert(SaveAppNames(storage, names));
auto loaded = LoadAppNames(storage);
assert(loaded.size() == 3 && loaded.at(10).name == "Synthetic Game" && loaded.at(10).icon == "abc" &&
loaded.at(11).kind == AppName::Kind::kDemo && loaded.at(12).kind == AppName::Kind::kOther &&
- loaded.at(12).learned_at == 102);
+ loaded.at(12).learned_at == 102 && loaded.at(12).dlc_for == 10 && loaded.at(10).dlc_for == 0);
+ // A file from before DLC kept their game: its games load, its other apps are looked up again.
+ Bytes v1 = {'P', 'D', 'N', 'A', 'M', 'E', 0, 1, 2, 0, 0, 0};
+ const auto entry = [&v1](std::uint32_t id, std::uint8_t kind, const std::string& name) {
+ for (int i = 0; i < 4; ++i) v1.push_back(static_cast<std::uint8_t>(id >> (8 * i)));
+ v1.push_back(kind);
+ for (int i = 0; i < 8; ++i) v1.push_back(i == 0 ? 7 : 0);
+ v1.push_back(static_cast<std::uint8_t>(name.size()));
+ v1.push_back(0);
+ v1.insert(v1.end(), name.begin(), name.end());
+ v1.push_back(0);
+ v1.push_back(0);
+ };
+ entry(10, 1, "Old Game");
+ entry(12, 0, "");
+ std::uint32_t crc = 0xffffffffu;
+ for (const auto byte : v1) {
+ crc ^= byte;
+ for (int bit = 0; bit < 8; ++bit) crc = (crc >> 1) ^ (0xedb88320u & (0u - (crc & 1u)));
+ }
+ crc = ~crc;
+ for (int i = 0; i < 4; ++i) v1.push_back(static_cast<std::uint8_t>(crc >> (8 * i)));
+ assert(storage.WriteAtomic("app-names.cache", v1).ok());
+ loaded = LoadAppNames(storage);
+ assert(loaded.size() == 1 && loaded.at(10).name == "Old Game" && loaded.at(10).learned_at == 7);
+ assert(SaveAppNames(storage, names));
auto bytes = storage.Read("app-names.cache").value();
bytes[bytes.size() / 2] ^= 1;
assert(storage.WriteAtomic("app-names.cache", bytes).ok());
assert(LoadAppNames(storage).empty());
AppNames many;
- for (std::uint32_t id = 1; id <= kMaxAppNames + 5; ++id) many[id] = AppName{AppName::Kind::kOther, "", "", id};
+ for (std::uint32_t id = 1; id <= kMaxAppNames + 5; ++id) many[id] = AppName{AppName::Kind::kGame, "G", "", id};
assert(SaveAppNames(storage, many));
loaded = LoadAppNames(storage);
assert(loaded.size() == kMaxAppNames && !loaded.count(5) && loaded.count(6) && loaded.count(kMaxAppNames + 5));
+ // Other apps have a cap of their own: a library's DLC neither pushes games out nor is pushed out by them.
+ constexpr std::uint32_t kOthers = kMaxOtherApps + 5;
+ for (std::uint32_t id = 1; id <= kOthers; ++id)
+ many[1'000'000 + id] = AppName{AppName::Kind::kOther, "", "", 1'000'000 + id, 7};
+ assert(SaveAppNames(storage, many));
+ loaded = LoadAppNames(storage);
+ std::size_t games = 0;
+ for (const auto& [id, name] : loaded) games += name.kind == AppName::Kind::kGame;
+ assert(games == kMaxAppNames && loaded.size() == kMaxAppNames + kMaxOtherApps);
+ assert(!loaded.count(1'000'005) && loaded.count(1'000'006) && loaded.at(1'000'000 + kOthers).dlc_for == 7);
// Long names: what is saved still fits what Load reads, newest first.
AppNames long_names;
for (std::uint32_t id = 1; id <= 5000; ++id)
@@ -419,8 +463,9 @@ void FamilySharedAppsAreMarked() {
assert(Find(result, 95) && !Find(result, 95)->family_shared);
assert(!Find(result, 10)->family_shared && !Find(result, 20)->family_shared && !Find(result, 11));
}
- // The package with an owned game is passed over; the borrowed bundle only skips the owned game.
- assert((acquisitions.Requests() == std::vector<std::vector<std::uint32_t>>{{80, 90, 95}}));
+ // The package with an owned game is passed over; the borrowed bundle only skips the owned game. Its DLC
+ // is looked up last, only for the game it names.
+ assert((acquisitions.Requests() == std::vector<std::vector<std::uint32_t>>{{80, 90, 95, 11}}));
// Each shared app is logged once per run; the summary once per load.
assert(lines.Count("family library added app=80 demo=0 source=saved") == 1);
assert(lines.Count("family library added app=90 demo=0 source=saved") == 1);
@@ -547,7 +592,8 @@ void StaleFamilyListDoesNotHideNewGames() {
}
// Steam's family service names the family's games: the load lists them at once, without a lookup. Shared
-// apps it leaves out are not games and are not looked up; a game it lists without a name is.
+// apps it leaves out are not games and are looked up only for the game a DLC names; a game it lists without
+// a name is looked up for the Library.
void FamilyServiceNamesSharedGames() {
Owned owned;
Acquisitions acquisitions;
@@ -576,9 +622,9 @@ void FamilyServiceNamesSharedGames() {
assert(lines.Count("family library left_out app=81 reason=not_in_family_list") == 1);
assert(lines.Count("family library left_out app=83 reason=app_type=4") == 1);
assert(lines.Count("named_family=2 named_saved=0 family_list=y lookups=1") == 1);
- // Only the game listed without a name is looked up.
+ // The game listed without a name is looked up first; the apps the service didn't name follow, for DlcOf.
assert(backend.WaitForLookups(5s));
- assert((acquisitions.Requests() == std::vector<std::vector<std::uint32_t>>{{84}}));
+ assert((acquisitions.Requests() == std::vector<std::vector<std::uint32_t>>{{84, 81, 83}}));
assert(backend.TakeLateGames(123).size() == 1);
}
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index e7d7a54..bfc2080 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -1460,6 +1460,12 @@ void PreparesGameWithoutShippedRecipe() {
const std::string own_api = pe + std::string("\0SteamUser021\0", 14);
Write(game / "Bin/steam_api64.dll", own_api, 0644);
Write(game / ".playden-steam", "depots=4243\ndlc=4250\n", 0644);
+ // The Library knows one more owned DLC than the download recorded (past listofdlc's 64 entries).
+ std::vector<std::pair<std::uint64_t, std::uint32_t>> dlc_asked;
+ config.owned_dlc = [&dlc_asked](std::uint64_t steam_id, std::uint32_t app_id) {
+ dlc_asked.emplace_back(steam_id, app_id);
+ return std::vector<std::uint32_t>{4260, 4250, 4242};
+ };
std::map<std::string, std::string> saved_settings;
config.settings_record = [&saved_settings](const playden::GameId&) -> std::optional<GameSettingsRecord> {
if (saved_settings.empty()) return std::nullopt;
@@ -1500,7 +1506,10 @@ void PreparesGameWithoutShippedRecipe() {
const auto emulator = Read(fs::path(g_runtime_dir) / "steamworks/steam_api64.dll");
CHECK(Read(game / "Bin/steam_api64.dll") == emulator && Read(game / "Bin/steam_api64.dll.orig") == own_api);
CHECK(Read(game / "Bin/steam_settings/configs.user.ini").find("account_name=player\n") != std::string::npos);
- CHECK(Read(game / "Bin/steam_settings/configs.app.ini").find("4250=dlc4250\n") != std::string::npos);
+ CHECK(Read(game / "Bin/steam_settings/configs.app.ini") == "[app::dlcs]\nunlock_all=0\n4250=dlc4250\n4260=dlc4260\n");
+ CHECK(!dlc_asked.empty() && dlc_asked.back() == std::make_pair(std::uint64_t{76561198000000001ull}, std::uint32_t{4242}));
+ // The added DLC stay with the download's facts, for a start before the next license read.
+ CHECK(Read(game / ".playden-steam") == "depots=4243\ndlc=4250,4260\n");
CHECK(Read(game / "Bin/steam_settings/steam_interfaces.txt") == "SteamUser021\n");
// The bottle's owner marker names the generated recipe, so the game's sessions are read.
const auto marker = Read(fixture.root / "data/playden/games/steam-4242/library/prefixes/game/.playden-template-owner");
diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cpp
index 5d9c4bf..93d2b87 100644
--- a/tests/steam_app_info_test.cpp
+++ b/tests/steam_app_info_test.cpp
@@ -282,6 +282,27 @@ void TestParseDefaultsAndFailures() {
CHECK(nested && nested->dlc_app_ids == U32s{5});
}
+// A DLC names its game (Iceborne, past Monster Hunter: World's 64-entry listofdlc): extended/dlcforappid,
+// common/extended's, whatever the type says; else a DLC's common/parent.
+void TestDlcForApp() {
+ const auto extended = ParseAppInfo(1118010,
+ "\"appinfo\" { \"common\" { \"type\" \"DLC\" \"parent\" \"9\" } \"extended\" { \"dlcforappid\" \"582010\" } }");
+ CHECK(extended && extended->dlc_for_app_id == 582010);
+ const auto nested = ParseAppInfo(
+ 8, "\"appinfo\" { \"common\" { \"type\" \"dlc\" \"extended\" { \"dlcforappid\" \"7\" } } }");
+ CHECK(nested && nested->dlc_for_app_id == 7);
+ const auto parent = ParseAppInfo(
+ 8, "\"appinfo\" { \"common\" { \"type\" \"DLC\" \"parent\" \"7\" } \"extended\" { \"dlcforappid\" \"0\" } }");
+ CHECK(parent && parent->dlc_for_app_id == 7);
+ const auto game = ParseAppInfo(8, "\"appinfo\" { \"common\" { \"type\" \"Game\" \"parent\" \"7\" } }");
+ CHECK(game && game->dlc_for_app_id == 0);
+ const auto own = ParseAppInfo(8, "\"appinfo\" { \"common\" { \"type\" \"DLC\" \"parent\" \"8\" } }");
+ CHECK(own && own->dlc_for_app_id == 0);
+ // A hidden DLC whose app info carries no common section still names its game.
+ const auto hidden = ParseAppInfo(8, "\"appinfo\" { \"extended\" { \"dlcforappid\" \"7\" } }");
+ CHECK(hidden && hidden->dlc_for_app_id == 7);
+}
+
void TestSelect() {
const auto app = ParseAppInfo(kApp, Buffer());
CHECK(app);
@@ -922,6 +943,7 @@ int main(int argc, char** argv) {
g_fixtures = argv[1];
TestParse();
TestParseDefaultsAndFailures();
+ TestDlcForApp();
TestSelect();
TestDepotLanguage();
TestMissingBaseDepots();