Skip to content

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

C++

Let an install leave out chosen DLC

Leonardo Lobatobec6290a38a0
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 09040c1..8aef89c 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -846,12 +846,14 @@ std::string RuntimeHost::SteamworksStep(const GameFiles& files, bool steam_accou
return std::find(ids.begin(), ids.end(), id) != ids.end();
};
std::vector<std::uint32_t> added;
+ // DLC turned off at install stays out: the game would look for files that aren't there.
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 (dlc != steam_app.app_id && !listed(identity.owned_dlc, dlc) && !listed(added, dlc) && !listed(identity.excluded_dlc, 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);
+ rt::WriteSteamworksFacts(root.string(), identity.depots, identity.owned_dlc, identity.language, identity.excluded_dlc);
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"));
}
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index 6c68ee5..f880d32 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -117,7 +117,8 @@ struct RuntimeHostConfig {
std::function<std::optional<std::string>(const GameId& game, const std::filesystem::path& program)> 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.
+ // the 64 that Steam's listofdlc names, or bought after the download, reach the emulator; DLC the download
+ // recorded as turned off doesn't. 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
diff --git a/src/installs/install_record.cpp b/src/installs/install_record.cpp
index 83f2095..339fd6d 100644
--- a/src/installs/install_record.cpp
+++ b/src/installs/install_record.cpp
@@ -64,6 +64,9 @@ std::optional<InstalledRecord> ParseInstallRecord(std::string_view text) {
record.depots.push_back(depot);
}
}
+ if (const auto* excluded = root->Find("excluded_dlc"); excluded && excluded->is_array())
+ for (const auto& entry : excluded->array())
+ if (const auto dlc = AsUint32(&entry); dlc && *dlc != 0) record.excluded_dlc.push_back(*dlc);
return record;
}
diff --git a/src/installs/install_record.h b/src/installs/install_record.h
index df81152..9013904 100644
--- a/src/installs/install_record.h
+++ b/src/installs/install_record.h
@@ -31,9 +31,12 @@ struct InstalledRecord {
std::string branch = "public";
std::string language = "english";
std::vector<RecordedDepot> depots;
+ // DLC the player turned off when installing: its updates leave them out too, and they don't count as new DLC.
+ std::vector<std::uint32_t> excluded_dlc;
bool operator==(const InstalledRecord& other) const {
return version == other.version && app_id == other.app_id && install_bytes == other.install_bytes &&
- branch == other.branch && language == other.language && depots == other.depots;
+ branch == other.branch && language == other.language && depots == other.depots &&
+ excluded_dlc == other.excluded_dlc;
}
};
diff --git a/src/installs/install_service.cpp b/src/installs/install_service.cpp
index d3b4167..622d520 100644
--- a/src/installs/install_service.cpp
+++ b/src/installs/install_service.cpp
@@ -204,9 +204,16 @@ bool ValidOptionValue(std::string_view value) {
return true;
}
+// Past this a job's excluded DLC would not fit a registry line (Scan), and the game would be lost with its line.
+constexpr std::size_t kMaxRegisteredDlc = 1000;
+
InstallOptions Registrable(InstallOptions options) {
if (!ValidOptionValue(options.language)) options.language.clear();
if (!ValidOptionValue(options.branch)) options.branch.clear();
+ std::sort(options.excluded_dlc.begin(), options.excluded_dlc.end());
+ options.excluded_dlc.erase(std::unique(options.excluded_dlc.begin(), options.excluded_dlc.end()), options.excluded_dlc.end());
+ options.excluded_dlc.erase(std::remove(options.excluded_dlc.begin(), options.excluded_dlc.end(), 0u), options.excluded_dlc.end());
+ if (options.excluded_dlc.size() > kMaxRegisteredDlc) options.excluded_dlc.resize(kMaxRegisteredDlc);
return options;
}
@@ -222,15 +229,16 @@ struct RegistryEntry {
// <from> to <to>; once <volume> is <to>, only the old folder is left to delete.
std::string move_to;
std::string move_from;
- InstallOptions options; // a job's "lang=<code>" and "branch=<name>" fields
+ InstallOptions options; // a job's "lang=<code>", "branch=<name>" and "nodlc=<app>,<app>" fields
+ std::optional<std::uint64_t> estimated_bytes; // a job's "est=<bytes>": what it reserves on its drive
std::int64_t finished_at = 0; // "finished=<unix seconds>": a moved game's install time, older than its record
};
// One line per game: "<key>" (legacy, primary volume) or "<key>\t<volume id>\t<install bytes>",
// followed by "\tpaused" for a job that should wait for Resume after a restart, or "\tremoving" for
// an uninstall whose folder is not deleted yet, or "\tupdate" for an installed game with an update job
-// (then "\tpaused" is the update's), or "\tmove=<volume>\tfrom=<volume>" for one with a move job, then a job's install options as "\tlang=<code>" and
-// "\tbranch=<name>" (none: the defaults), and "\tfinished=<unix seconds>" for a moved game's install time. Fields
+// (then "\tpaused" is the update's), or "\tmove=<volume>\tfrom=<volume>" for one with a move job, then a job's install options as "\tlang=<code>",
+// "\tbranch=<name>" and "\tnodlc=<app>,<app>" (none: the defaults), its estimate as "\test=<bytes>", and "\tfinished=<unix seconds>" for a moved game's install time. Fields
// after the install bytes may come in any order, and
// unknown ones are skipped. The key is ToKey: a Steam game's app ID, "local-<uuid>" for an imported game.
std::optional<RegistryEntry> ParseRegistryLine(std::string_view line) {
@@ -257,7 +265,7 @@ std::optional<RegistryEntry> ParseRegistryLine(std::string_view line) {
const auto field = fields.substr(0, tab);
fields = tab == std::string_view::npos ? std::string_view{} : fields.substr(tab + 1);
constexpr std::string_view kLanguage = "lang=", kBranch = "branch=", kMove = "move=", kFrom = "from=",
- kFinished = "finished=";
+ kFinished = "finished=", kNoDlc = "nodlc=", kEstimate = "est=";
if (field == "paused") entry.paused = true;
else if (field.substr(0, kMove.size()) == kMove && ValidVolumeId(field.substr(kMove.size())))
entry.move_to = std::string(field.substr(kMove.size()));
@@ -267,6 +275,22 @@ std::optional<RegistryEntry> ParseRegistryLine(std::string_view line) {
else if (field == "update") entry.update = true;
else if (field.substr(0, kLanguage.size()) == kLanguage) entry.options.language = std::string(field.substr(kLanguage.size()));
else if (field.substr(0, kBranch.size()) == kBranch) entry.options.branch = std::string(field.substr(kBranch.size()));
+ else if (field.substr(0, kEstimate.size()) == kEstimate) {
+ const auto text = field.substr(kEstimate.size());
+ std::uint64_t bytes = 0;
+ const auto parsed = std::from_chars(text.data(), text.data() + text.size(), bytes);
+ if (parsed.ec == std::errc{} && parsed.ptr == text.data() + text.size()) entry.estimated_bytes = bytes;
+ }
+ else if (field.substr(0, kNoDlc.size()) == kNoDlc) {
+ for (auto list = field.substr(kNoDlc.size()); !list.empty();) {
+ const auto comma = list.find(',');
+ const auto text = list.substr(0, comma);
+ list = comma == std::string_view::npos ? std::string_view{} : list.substr(comma + 1);
+ std::uint32_t dlc = 0;
+ const auto parsed = std::from_chars(text.data(), text.data() + text.size(), dlc);
+ if (parsed.ec == std::errc{} && parsed.ptr == text.data() + text.size()) entry.options.excluded_dlc.push_back(dlc);
+ }
+ }
else if (field.substr(0, kFinished.size()) == kFinished) {
const auto value = field.substr(kFinished.size());
std::int64_t time = 0;
@@ -360,11 +384,13 @@ void InstallService::Scan() {
const auto& primary = volumes_.front().games_root;
std::vector<RegistryEntry> entries;
if (FILE* registry = std::fopen((primary + "/" + kRegistry).c_str(), "r")) {
- char line[512];
- while (std::fgets(line, sizeof(line), registry) && entries.size() < kMaxJobs * 4) {
+ // A job's excluded DLC makes for long lines: kMaxRegisteredDlc entries fit. Not on the stack: it is small on the console.
+ std::vector<char> buffer(16 * 1024);
+ char* const line = buffer.data();
+ while (std::fgets(line, static_cast<int>(buffer.size()), registry) && entries.size() < kMaxJobs * 4) {
const auto length = std::strcspn(line, "\r\n");
// A line longer than the buffer isn't one Playden wrote: it and its remainder are skipped.
- if (line[length] == '\0' && length == sizeof(line) - 1) {
+ if (line[length] == '\0' && length == buffer.size() - 1) {
int rest = 0;
while ((rest = std::fgetc(registry)) != EOF && rest != '\n') {}
continue;
@@ -460,6 +486,7 @@ void InstallService::Scan() {
job.view.id = entry.id;
job.view.kind = InstallJobKind::kUpdate;
job.view.volume_id = entry.volume_id;
+ job.estimated_bytes = job.view.estimated_bytes = entry.estimated_bytes;
// The registry keeps what the player chose; what it doesn't say, the update on disk was for.
job.options = entry.options;
if (update) {
@@ -491,6 +518,7 @@ void InstallService::Scan() {
job.view.failure = kInterrupted;
}
job.view.volume_id = entry.volume_id;
+ job.estimated_bytes = job.view.estimated_bytes = entry.estimated_bytes;
job.options = entry.options;
jobs_.push_back(job);
} else if (entry.install_bytes > 0) {
@@ -535,6 +563,9 @@ bool InstallService::SaveRegistry(bool sync) {
std::string fields = waits ? "\tpaused" : "";
if (!job.options.language.empty()) fields += "\tlang=" + job.options.language;
if (!job.options.branch.empty()) fields += "\tbranch=" + job.options.branch;
+ for (std::size_t index = 0; index < job.options.excluded_dlc.size(); ++index)
+ fields += (index ? "," : "\tnodlc=") + std::to_string(job.options.excluded_dlc[index]);
+ if (job.view.kind != InstallJobKind::kMove && job.estimated_bytes) fields += "\test=" + std::to_string(*job.estimated_bytes);
return fields;
};
// An update job rides on its game's line, which stays an installed game's line for older versions.
@@ -781,7 +812,7 @@ std::string InstallService::Move(GameId id, const std::string& volume_id) {
job.view.volume_id = volume_id;
job.view.from_volume_id = game->volume_id;
job.view.total_bytes = game->install_bytes;
- job.estimated_bytes = game->install_bytes;
+ job.estimated_bytes = job.view.estimated_bytes = game->install_bytes;
jobs_.push_back(job);
Publish();
wake_.notify_all();
@@ -791,7 +822,7 @@ std::string InstallService::Move(GameId id, const std::string& volume_id) {
// Sets the job's volume and estimate; a volume that is absent or short of space fails the job.
bool InstallService::Admit(Job& job, const std::string& target, std::optional<std::uint64_t> estimated_bytes) {
job.view.volume_id = target;
- job.estimated_bytes = estimated_bytes;
+ job.estimated_bytes = job.view.estimated_bytes = estimated_bytes;
const auto* volume = FindVolume(target);
const auto space = volume && volume->available ? FreeBytes(volume->games_root) : std::nullopt;
if (!volume || !volume->available) {
diff --git a/src/installs/install_service.h b/src/installs/install_service.h
index c2a0540..f912e78 100644
--- a/src/installs/install_service.h
+++ b/src/installs/install_service.h
@@ -53,7 +53,10 @@ std::vector<InstallRequest> ParseInstallRequests(const std::string& text);
struct InstallOptions {
std::string language; // a Steam content language code ("german")
std::string branch; // a Steam branch name
- bool operator==(const InstallOptions& other) const { return language == other.language && branch == other.branch; }
+ std::vector<std::uint32_t> excluded_dlc; // DLC the player turned off, sorted: not claimed, downloaded or reported
+ bool operator==(const InstallOptions& other) const {
+ return language == other.language && branch == other.branch && excluded_dlc == other.excluded_dlc;
+ }
bool operator!=(const InstallOptions& other) const { return !(*this == other); }
};
@@ -96,6 +99,7 @@ struct InstallJobView {
std::uint64_t done_bytes = 0;
std::uint64_t total_bytes = 0;
std::uint64_t held_bytes = 0; // installed bytes already on disk (see PendingInstallBytes)
+ std::optional<std::uint64_t> estimated_bytes; // what the job was asked with, which its drive reserves
std::string failure; // short, user-facing
std::string volume_id;
std::optional<std::uint64_t> bytes_per_second;
diff --git a/src/runtime/steamworks.cpp b/src/runtime/steamworks.cpp
index ec727af..5f8feb3 100644
--- a/src/runtime/steamworks.cpp
+++ b/src/runtime/steamworks.cpp
@@ -402,25 +402,27 @@ SteamworksResult RestoreSteamworks(const std::string& install_root, const std::v
}
std::string SerializeSteamworksFacts(const std::vector<std::uint32_t>& depots, const std::vector<std::uint32_t>& owned_dlc,
- const std::string& language) {
+ const std::string& language, const std::vector<std::uint32_t>& excluded_dlc) {
std::string text = "depots=" + Join(Sorted(depots), ",") + "\ndlc=" + Join(Sorted(owned_dlc), ",") + "\n";
// The language the depots were installed for. Older files have no line and read as English,
// which is what they were installed in.
if (!language.empty() && language != std::string(steam::kDefaultContentLanguage))
text += "language=" + language + "\n";
+ if (!excluded_dlc.empty()) text += "nodlc=" + Join(Sorted(excluded_dlc), ",") + "\n";
return text;
}
bool WriteSteamworksFacts(const std::string& install_root, const std::vector<std::uint32_t>& depots,
- const std::vector<std::uint32_t>& owned_dlc, const std::string& language) {
+ const std::vector<std::uint32_t>& owned_dlc, const std::string& language,
+ const std::vector<std::uint32_t>& excluded_dlc) {
return WriteAtomic(fs::path(install_root) / kSteamworksFactsFile,
- SerializeSteamworksFacts(depots, owned_dlc, language));
+ SerializeSteamworksFacts(depots, owned_dlc, language, excluded_dlc));
}
bool ReadSteamworksFacts(const std::string& install_root, SteamworksIdentity* identity) {
const auto text = ReadFile(fs::path(install_root) / kSteamworksFactsFile, 64 * 1024);
if (!text) return false;
- std::vector<std::uint32_t> depots, dlc;
+ std::vector<std::uint32_t> depots, dlc, excluded;
std::string language;
std::size_t start = 0;
while (start < text->size()) {
@@ -437,7 +439,10 @@ bool ReadSteamworksFacts(const std::string& install_root, SteamworksIdentity* id
if (steam::IsContentLanguage(value)) language = value;
continue;
}
- auto* target = line.compare(0, equals, "depots") == 0 ? &depots : line.compare(0, equals, "dlc") == 0 ? &dlc : nullptr;
+ auto* target = line.compare(0, equals, "depots") == 0 ? &depots
+ : line.compare(0, equals, "dlc") == 0 ? &dlc
+ : line.compare(0, equals, "nodlc") == 0 ? &excluded
+ : nullptr;
if (!target) continue;
std::size_t at = equals + 1;
while (at < line.size()) {
@@ -455,6 +460,7 @@ bool ReadSteamworksFacts(const std::string& install_root, SteamworksIdentity* id
}
identity->depots = std::move(depots);
identity->owned_dlc = std::move(dlc);
+ identity->excluded_dlc = std::move(excluded);
if (!language.empty()) identity->language = language;
return true;
}
diff --git a/src/runtime/steamworks.h b/src/runtime/steamworks.h
index b83a371..7f92faf 100644
--- a/src/runtime/steamworks.h
+++ b/src/runtime/steamworks.h
@@ -30,7 +30,7 @@ inline constexpr const char* kSteamworksSavePath = "C:\\Program Files (x86)\\Ste
// What the download recorded beside the game (SteamworksFactsFile): installed depots and the
// DLC this account owns.
-inline constexpr const char* kSteamworksFactsFile = ".playden-steam"; // "depots=1,2\ndlc=3\n"
+inline constexpr const char* kSteamworksFactsFile = ".playden-steam"; // "depots=1,2\ndlc=3\nnodlc=4\n"
struct SteamworksIdentity {
std::uint32_t app_id = 0;
@@ -38,6 +38,7 @@ struct SteamworksIdentity {
std::uint64_t steam_id = 0;
std::string language = "english";
std::vector<std::uint32_t> owned_dlc;
+ std::vector<std::uint32_t> excluded_dlc; // turned off at install: never added to owned_dlc
std::vector<std::uint32_t> depots; // empty: no depots.txt
// A steam_appid.txt beside a DLL that has none (Steam games). Off for a game whose app ID came from its
// own steam_appid.txt or Game settings: the emulator reads steam_settings/steam_appid.txt, and a file
@@ -84,11 +85,13 @@ std::vector<std::string> SteamInterfaces(std::string_view dll_bytes);
// The facts file the download writes, and its reader (missing or unreadable: false). `language`
// is the content language the depots were installed for; English, and files written before
-// Playden could choose one, leave the line out.
+// Playden could choose one, leave the line out. `excluded_dlc`: DLC the player turned off at install, which each
+// prepare leaves out when it adds the account's owned DLC.
std::string SerializeSteamworksFacts(const std::vector<std::uint32_t>& depots, const std::vector<std::uint32_t>& owned_dlc,
- const std::string& language = {});
+ const std::string& language = {}, const std::vector<std::uint32_t>& excluded_dlc = {});
bool WriteSteamworksFacts(const std::string& install_root, const std::vector<std::uint32_t>& depots,
- const std::vector<std::uint32_t>& owned_dlc, const std::string& language = {});
+ const std::vector<std::uint32_t>& owned_dlc, const std::string& language = {},
+ const std::vector<std::uint32_t>& excluded_dlc = {});
bool ReadSteamworksFacts(const std::string& install_root, SteamworksIdentity* identity);
} // namespace playden::runtime
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cpp
index db61672..014b6d0 100644
--- a/src/steam/backend/app_info.cpp
+++ b/src/steam/backend/app_info.cpp
@@ -368,6 +368,9 @@ 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);
+ if (const VdfNode* extended = root->Find("extended")) app.free_app = ChildU32(extended, "isfreeapp").value_or(0) != 0;
+ if (!app.free_app && common != nullptr)
+ if (const VdfNode* extended = common->Find("extended")) app.free_app = ChildU32(extended, "isfreeapp").value_or(0) != 0;
// 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.
{
@@ -541,6 +544,7 @@ bool SelectDepots(const AppInfo& app, const std::vector<AppInfo>& dlc_apps, cons
if (depot.shared_install) { reject(depot, "shared"); continue; }
if (owned_depots && owned_depots->count(depot.id) == 0 && from_app.count(depot.id) == 0) { reject(depot, "licence"); continue; }
if (depot.owner_app != app.app_id && owned_apps.count(depot.owner_app) == 0) { reject(depot, "dlc"); continue; }
+ if (depot.owner_app != app.app_id && selection.excluded_dlc.count(depot.owner_app)) { reject(depot, "dlc-off"); continue; }
eligible = true;
if (!depot.manifest_gid || *depot.manifest_gid == 0) { reject(depot, "branch"); continue; }
passed.push_back(&depot);
@@ -599,6 +603,68 @@ bool SelectDepots(const AppInfo& app, const std::vector<AppInfo>& dlc_apps, cons
return true;
}
+namespace {
+// A DLC's name for a list under its game: "Game: Extras" and "Game - Extras" read as "Extras".
+std::string DlcDisplayName(const std::string& game, const std::string& name, std::uint32_t dlc) {
+ // Steam without a name: ParseAppInfo's placeholder.
+ if (name.empty() || name == "app_" + std::to_string(dlc)) return {};
+ if (game.empty() || name.size() <= game.size() || LowerString(name.substr(0, game.size())) != LowerString(game)) return name;
+ const auto rest = name.find_first_not_of(" :-\xE2\x80\x93\x94", game.size());
+ // The game's name must end there: "Portal 2" isn't in front of "Portal 25".
+ if (rest == std::string::npos || rest == game.size()) return name;
+ return name.substr(rest);
+}
+} // namespace
+
+std::vector<DlcOffer> OfferedDlc(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, const std::set<std::uint32_t>& refused) {
+ // Free DLC an install would claim counts as granted: its depots are what the player decides on.
+ std::set<std::uint32_t> free, apps = owned_apps;
+ auto depots = owned_depots;
+ for (const AppInfo& dlc : dlc_apps) {
+ if (!dlc.free_app || owned_apps.count(dlc.app_id) || refused.count(dlc.app_id) ||
+ std::find(app.dlc_app_ids.begin(), app.dlc_app_ids.end(), dlc.app_id) == app.dlc_app_ids.end())
+ continue;
+ free.insert(dlc.app_id);
+ apps.insert(dlc.app_id);
+ if (!depots) continue;
+ for (const DepotInfo& depot : dlc.depots) depots->insert(depot.id);
+ for (const DepotInfo& depot : app.depots)
+ if (depot.dlc_app_id == dlc.app_id) depots->insert(depot.id);
+ }
+ DepotSelection all = selection;
+ all.excluded_dlc.clear();
+ SelectionResult selected;
+ if (!SelectDepots(app, dlc_apps, apps, depots, all, &selected)) return {};
+
+ std::map<std::uint32_t, std::vector<DepotInfo>> owners;
+ for (const DepotInfo& depot : selected.depots)
+ if (depot.owner_app != 0 && depot.owner_app != app.app_id) owners[depot.owner_app].push_back(depot);
+ std::vector<DlcOffer> offers;
+ for (const auto& [owner, owned] : owners) {
+ DlcOffer offer;
+ offer.app_id = owner;
+ offer.free = free.count(owner) > 0;
+ DepotBytes(owned, &offer.install_bytes, &offer.download_bytes);
+ if (offer.install_bytes == 0) continue;
+ for (const AppInfo& dlc : dlc_apps)
+ if (dlc.app_id == owner) offer.name = DlcDisplayName(app.name, dlc.name, owner);
+ offers.push_back(std::move(offer));
+ }
+ SortDlcOffers(&offers);
+ return offers;
+}
+
+void SortDlcOffers(std::vector<DlcOffer>* offers) {
+ std::sort(offers->begin(), offers->end(), [](const DlcOffer& left, const DlcOffer& right) {
+ if (left.name.empty() != right.name.empty()) return right.name.empty();
+ const auto a = LowerString(left.name), b = LowerString(right.name);
+ return a != b ? a < b : left.app_id < right.app_id;
+ });
+}
+
void DepotBytes(const std::vector<DepotInfo>& depots, std::uint64_t* install, std::uint64_t* download) {
std::uint64_t total = 0;
std::uint64_t compressed = 0;
diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.h
index 8152384..28137ef 100644
--- a/src/steam/backend/app_info.h
+++ b/src/steam/backend/app_info.h
@@ -103,6 +103,7 @@ 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;
+ 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;
std::string icon; // common/icon: the hash of the library icon, as GetOwnedGames img_icon_url
@@ -116,14 +117,15 @@ std::optional<AppInfo> ParseAppInfo(std::uint32_t app_id, std::string_view buffe
bool OsListMatchesWindows(std::string_view os_list);
// What an install asks for: the content language as Steam names it ("german"; empty: English)
-// and the branch whose manifests are installed.
+// and the branch whose manifests are installed. `excluded_dlc`: DLC the player turned off, whose depots stay out.
struct DepotSelection {
std::string language;
std::string branch = "public";
+ std::set<std::uint32_t> excluded_dlc;
};
struct SelectionResult {
- // A depot left out, and why: os, shared, licence, dlc, branch, language, arch or duplicate.
+ // A depot left out, and why: os, shared, licence, dlc, dlc-off, branch, language, arch or duplicate.
struct Rejected {
std::uint32_t id = 0;
std::uint32_t source_app = 0;
@@ -139,7 +141,7 @@ struct SelectionResult {
// Windows depot selection over the game's depots and those its DLC apps list (`dlc_apps`, the
// appinfo of DLC from the game's listofdlc). Each depot passes, in order: os, shared install,
// licence (an owned depot or depotfromapp; every depot when the licenses are unknown), DLC
-// ownership, and a manifest on the branch. A depot listed twice is kept once, from a listing
+// ownership, the player's excluded DLC, and a manifest on the branch. A depot listed twice is kept once, from a listing
// with a manifest on the branch; two different manifests for one depot fail the selection.
//
// Then per owner (the game, or one DLC): the content language, then a usable 64-bit Windows
@@ -184,6 +186,26 @@ std::vector<BranchOffer> OfferedBranches(const AppInfo& app, const std::vector<A
const std::optional<std::set<std::uint32_t>>& owned_depots,
const std::string& language);
+// A DLC with files an install can leave out, for the install sheet's DLC list.
+struct DlcOffer {
+ std::uint32_t app_id = 0;
+ std::string name; // without the game's name in front; empty when Steam doesn't describe the DLC
+ std::uint64_t install_bytes = 0;
+ std::uint64_t download_bytes = 0;
+ bool free = false; // not owned yet: an install claims it, unless it is turned off
+};
+
+// The DLC an install of the game could hold, as SelectDepots selects them: owned DLC and free DLC this account can
+// still claim (`refused`: free DLC Steam said no to). DLC with no files (most of them only unlock something) isn't
+// listed. Sorted by name, DLC without a name last.
+std::vector<DlcOffer> OfferedDlc(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, const std::set<std::uint32_t>& refused = {});
+
+// `offers` in the list's order: by name, DLC without a name last.
+void SortDlcOffers(std::vector<DlcOffer>* offers);
+
// What `depots` install and download, in bytes. Some appinfo reports a download larger than the
// install (FINAL FANTASY XIII, issue #5); compressed chunks never are, so the download is capped.
void DepotBytes(const std::vector<DepotInfo>& depots, std::uint64_t* install, std::uint64_t* download);
diff --git a/src/steam/backend/cm_app_details.cpp b/src/steam/backend/cm_app_details.cpp
index e20b2af..7f6f84a 100644
--- a/src/steam/backend/cm_app_details.cpp
+++ b/src/steam/backend/cm_app_details.cpp
@@ -59,6 +59,7 @@ std::vector<DepotInfo> DepotsToUpdate(std::uint32_t id, const std::string& buffe
DepotSelection selection;
if (!record.language.empty()) selection.language = record.language;
if (!record.branch.empty()) selection.branch = record.branch;
+ selection.excluded_dlc.insert(record.excluded_dlc.begin(), record.excluded_dlc.end());
std::set<std::uint32_t> apps{id};
apps.insert(licensed->apps.begin(), licensed->apps.end());
SelectionResult selected;
@@ -87,6 +88,7 @@ AppDetails DetailsFromAppInfo(std::uint32_t id, const std::string& buffer,
if (installed) {
if (!installed->language.empty()) selection.language = installed->language;
if (!installed->branch.empty()) selection.branch = installed->branch;
+ selection.excluded_dlc.insert(installed->excluded_dlc.begin(), installed->excluded_dlc.end());
}
SelectionResult selected;
// As an install selects them; without licenses, or when they grant none of it, every eligible depot.
diff --git a/src/steam/backend/depot_installer.cpp b/src/steam/backend/depot_installer.cpp
index f641fe3..330aa1b 100644
--- a/src/steam/backend/depot_installer.cpp
+++ b/src/steam/backend/depot_installer.cpp
@@ -1020,8 +1020,14 @@ InstallOutcome DepotInstaller::Run(const StoredSession& session, const InstallTa
std::string text = "{\"version\":2,\"app_id\":" + std::to_string(target.app_id) + identity +
",\"install_bytes\":" + std::to_string(progress.install_total) +
",\"files\":" + std::to_string(progress.files_total) + ",\"branch\":\"" +
- RecordText(target.branch, "public") + "\",\"language\":\"" + RecordText(target.language, "english") +
- "\",\"depots\":[";
+ RecordText(target.branch, "public") + "\",\"language\":\"" + RecordText(target.language, "english") + "\"";
+ if (!target.excluded_dlc.empty()) {
+ text += ",\"excluded_dlc\":[";
+ for (std::size_t index = 0; index < target.excluded_dlc.size(); ++index)
+ text += (index ? "," : "") + std::to_string(target.excluded_dlc[index]);
+ text += "]";
+ }
+ text += ",\"depots\":[";
for (std::size_t index = 0; index < access.grants.size(); ++index) {
// Grants skip refused depots, so the selection is looked up by id.
const auto& grant = access.grants[index];
diff --git a/src/steam/backend/depot_installer.h b/src/steam/backend/depot_installer.h
index da00095..e2386fd 100644
--- a/src/steam/backend/depot_installer.h
+++ b/src/steam/backend/depot_installer.h
@@ -45,6 +45,8 @@ struct InstallTarget {
// language they resolved to. Empty: "public" and "english".
std::string branch;
std::string language;
+ // Written to the install record: DLC the player turned off, which `depots` leave out.
+ std::vector<std::uint32_t> excluded_dlc;
// An update of the finished install at install_root: only files whose content changed are downloaded,
// into <root>/.playden-update/staging/ with their own journal, while the game stays as it was. Once
// everything is there they replace the game's files, files the new version dropped are deleted, and
diff --git a/src/steam/backend/steam_install_runner.cpp b/src/steam/backend/steam_install_runner.cpp
index 8b5c60f..d3f4e84 100644
--- a/src/steam/backend/steam_install_runner.cpp
+++ b/src/steam/backend/steam_install_runner.cpp
@@ -361,8 +361,14 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
result.retry_later = dlc_error == CmError::kNetwork || dlc_error == CmError::kTimeout;
return result;
}
+ // What the player turned off: this install's choice, and for an update what its install left out.
+ std::set<std::uint32_t> excluded(options.excluded_dlc.begin(), options.excluded_dlc.end());
+ if (update)
+ if (const auto record = installs::ReadInstallRecord(root + "/" + DepotInstaller::kInstallRecord))
+ excluded.insert(record->excluded_dlc.begin(), record->excluded_dlc.end());
InstallTarget target;
target.app_id = id;
+ target.excluded_dlc.assign(excluded.begin(), excluded.end());
target.install_root = root;
// Like the reference, only depots this account's licenses grant are installed. Accounts with
// thousands of licenses take a minute here (issue #47), so the player sees this step.
@@ -379,7 +385,10 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
if (!grant) {
log("dlc", "claim", "skipped=no-licenses");
} else {
- claimed = FreeDlcCandidates(*app, dlc_apps, grant->apps, refused_before);
+ // Free DLC that is turned off isn't claimed: a claim stays on the account.
+ auto not_asked = refused_before;
+ not_asked.insert(excluded.begin(), excluded.end());
+ claimed = FreeDlcCandidates(*app, dlc_apps, grant->apps, not_asked);
}
}
if (!claimed.empty()) {
@@ -441,6 +450,7 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
DepotSelection selection;
selection.language = language;
if (!options.branch.empty()) selection.branch = options.branch;
+ selection.excluded_dlc = excluded;
SelectionResult selected;
const bool any = SelectDepots(*app, dlc_apps, owned_apps, entitlements.owned_depots, selection, &selected);
// Every depot left out and why, as depot:reason.
@@ -510,15 +520,17 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
std::vector<std::uint32_t> depots, dlc;
for (const auto& depot : target.depots)
if (std::find(skipped.begin(), skipped.end(), depot.id) == skipped.end()) depots.push_back(depot.id);
- // Owned DLC, claimed ones included, and any DLC whose content is installed.
+ // Owned DLC, claimed ones included, and any DLC whose content is installed. DLC that is turned off isn't there
+ // for the game: it would look for files the install left out.
for (const auto app_id : app->dlc_app_ids)
- if (app_id != id && entitlements.owned_apps.count(app_id) && std::find(dlc.begin(), dlc.end(), app_id) == dlc.end())
+ if (app_id != id && entitlements.owned_apps.count(app_id) && !excluded.count(app_id) &&
+ std::find(dlc.begin(), dlc.end(), app_id) == dlc.end())
dlc.push_back(app_id);
for (const auto& depot : target.depots)
if (depot.owner_app != 0 && depot.owner_app != id &&
std::find(dlc.begin(), dlc.end(), depot.owner_app) == dlc.end())
dlc.push_back(depot.owner_app);
- const bool written = runtime::WriteSteamworksFacts(folder, depots, dlc, effective_language);
+ const bool written = runtime::WriteSteamworksFacts(folder, depots, dlc, effective_language, target.excluded_dlc);
if (!written) log("steamworks_facts", "write-failed", folder.c_str());
else
log("steamworks_facts", "written",
@@ -527,7 +539,7 @@ InstallRunner::Result SteamInstallRunner::Run(const StoredSession& session, std:
.c_str());
return written;
};
- // The facts go in place with the record: a game with a record has them.
+ // The facts go in place with the record: a game with a record has them, with the DLC it left out.
target.update = update;
target.before_apply = write_facts;
if (update) target.may_apply = may_apply;
diff --git a/tests/app_details_test.cpp b/tests/app_details_test.cpp
index 4f7e88d..6431c1c 100644
--- a/tests/app_details_test.cpp
+++ b/tests/app_details_test.cpp
@@ -736,6 +736,12 @@ void InstalledGamesCompareWithTheirRecord() {
record.depots.pop_back();
details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
assert(details.update.new_dlc && !details.update.newer);
+ // DLC turned off at install stays out of the install: nothing new, and an update doesn't bring it.
+ record.excluded_dlc = {8100};
+ details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
+ assert(!details.update.available());
+ for (const auto& depot : DepotsToUpdate(8000, buffer, grant, record, {})) assert(depot.id != 8011);
+ record.excluded_dlc.clear();
// A version 1 record names the game as every depot's owner: a held DLC depot is not new DLC.
record = bought;
record.version = 1;
diff --git a/tests/depot_installer_test.cpp b/tests/depot_installer_test.cpp
index ccad6b0..33b9185 100644
--- a/tests/depot_installer_test.cpp
+++ b/tests/depot_installer_test.cpp
@@ -1611,6 +1611,7 @@ void UpdateReplacesChangedFiles(const std::filesystem::path& root) {
auto target = UpdateTarget(root);
target.depots[0].manifest_gid = 21;
target.language = "german";
+ target.excluded_dlc = {900, 901};
std::vector<std::string> folders;
target.before_apply = [&](const std::string& folder, const std::vector<std::uint32_t>& skipped) {
folders.push_back(folder);
@@ -1650,6 +1651,7 @@ void UpdateReplacesChangedFiles(const std::filesystem::path& root) {
CHECK(outcome.progress.install_total == 27 + 13 + 5 && outcome.progress.files_total == 3);
const auto record = playden::installs::ReadInstallRecord((root / DepotInstaller::kInstallRecord).string());
CHECK(record && record->language == "german" && record->install_bytes == 45);
+ CHECK((record->excluded_dlc == std::vector<std::uint32_t>{900, 901}));
CHECK((record->depots == std::vector<playden::installs::RecordedDepot>{{441, 21, 440, 440}, {442, 12, 440, 440}}));
const auto tree = Read(root / DepotInstaller::kFileTree);
CHECK(tree.find("\t5\tnew/added.txt\n") != std::string::npos && tree.find("empty.txt") == std::string::npos);
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index d133a64..65153f2 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -1459,13 +1459,15 @@ void PreparesGameWithoutShippedRecipe() {
// The game's own Steam library (a 64-bit PE that asks for one interface).
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);
+ // 4270 was turned off at install: the game isn't told about it.
+ Write(game / ".playden-steam", "depots=4243\ndlc=4250\nnodlc=4270\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};
+ return std::vector<std::uint32_t>{4260, 4250, 4242, 4270};
};
+
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;
@@ -1509,7 +1511,7 @@ void PreparesGameWithoutShippedRecipe() {
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 / ".playden-steam") == "depots=4243\ndlc=4250,4260\nnodlc=4270\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/install_service_test.cpp b/tests/install_service_test.cpp
index 0598d44..8095262 100644
--- a/tests/install_service_test.cpp
+++ b/tests/install_service_test.cpp
@@ -828,6 +828,14 @@ void InstallOptionsReachTheRunner(const std::filesystem::path& root) {
service.Pause(SteamId(902));
// Values the registry can't hold are dropped: the defaults apply.
service.Install(SteamId(903), std::nullopt, {}, {"bad value", "a\tb"});
+ // DLC turned off, kept sorted; hundreds of them still fit a registry line.
+ service.Install(SteamId(906), std::nullopt, {}, {{}, {}, {30, 10, 20, 10, 0}});
+ // What the job was asked with, which its drive reserves, also comes back.
+ service.Install(SteamId(909), 4096);
+ service.Pause(SteamId(909));
+ std::vector<std::uint32_t> many;
+ for (std::uint32_t dlc = 0; dlc < 900; ++dlc) many.push_back(4000000000u + dlc);
+ service.Install(SteamId(907), std::nullopt, {}, {{}, {}, many});
}
{
std::ifstream registry(root / ".playden-games");
@@ -840,23 +848,31 @@ void InstallOptionsReachTheRunner(const std::filesystem::path& root) {
CHECK(line_of("901") == "901\tinternal\t0");
CHECK(line_of("902") == "902\tinternal\t0\tpaused\tlang=french");
CHECK(line_of("903") == "903\tinternal\t0");
+ CHECK(line_of("906") == "906\tinternal\t0\tnodlc=10,20,30");
+ CHECK(line_of("909") == "909\tinternal\t0\tpaused\test=4096");
}
// Fields after the bytes come in any order, unknown ones are skipped, and bad values are dropped.
{
std::ofstream registry(root / ".playden-games", std::ios::app);
registry << "904\tinternal\t0\tbranch=public\tfuture=1\tlang=spanish\tpaused\n"
- << "905\tinternal\t0\tlang=\x01x\n";
+ << "905\tinternal\t0\tlang=\x01x\n"
+ << "908\tinternal\t0\tnodlc=7,bad,,9\n";
}
runner.block = false;
InstallService again(runner, root.string());
AwaitAt(__LINE__, again, [](const InstallSnapshot& s) {
- return Installed(s, SteamId(900)) && Installed(s, SteamId(901)) && Installed(s, SteamId(903)) && Installed(s, SteamId(905));
+ return Installed(s, SteamId(900)) && Installed(s, SteamId(901)) && Installed(s, SteamId(903)) && Installed(s, SteamId(905)) &&
+ Installed(s, SteamId(906)) && Installed(s, SteamId(907)) && Installed(s, SteamId(908));
});
+ CHECK(options_at(root / "906") == (InstallOptions{{}, {}, {10, 20, 30}}));
+ CHECK(options_at(root / "907") && options_at(root / "907")->excluded_dlc.size() == 900);
+ CHECK(options_at(root / "908") == (InstallOptions{{}, {}, {7, 9}}));
CHECK(options_at(root / "900") == (InstallOptions{"german", "beta"}));
CHECK(options_at(root / "901") == InstallOptions{});
CHECK(options_at(root / "903") == InstallOptions{});
CHECK(options_at(root / "905") == InstallOptions{});
const auto paused = again.Snapshot();
+ CHECK(JobOf(paused, SteamId(909)) && JobOf(paused, SteamId(909))->estimated_bytes == std::optional<std::uint64_t>(4096));
CHECK(JobOf(paused, SteamId(902)) && JobOf(paused, SteamId(902))->state == InstallJobState::kPaused);
CHECK(JobOf(paused, SteamId(904)) && JobOf(paused, SteamId(904))->state == InstallJobState::kPaused);
again.Resume(SteamId(902));
diff --git a/tests/runtime_steamworks_test.cpp b/tests/runtime_steamworks_test.cpp
index ed19655..0774cce 100644
--- a/tests/runtime_steamworks_test.cpp
+++ b/tests/runtime_steamworks_test.cpp
@@ -154,6 +154,11 @@ int main(int argc, char** argv) {
SteamworksIdentity facts;
CHECK(ReadSteamworksFacts(root.string(), &facts));
CHECK((facts.depots == std::vector<std::uint32_t>{10, 20}) && (facts.owned_dlc == std::vector<std::uint32_t>{3000, 3001}));
+ CHECK(facts.excluded_dlc.empty());
+ Write(root / kSteamworksFactsFile, SerializeSteamworksFacts({10}, {3000}, {}, {4001, 4000}));
+ SteamworksIdentity turned_off;
+ CHECK(ReadSteamworksFacts(root.string(), &turned_off));
+ CHECK((turned_off.excluded_dlc == std::vector<std::uint32_t>{4000, 4001}) && (turned_off.owned_dlc == std::vector<std::uint32_t>{3000}));
// A file from before Playden could choose a language reads as English, which is what it got.
CHECK(facts.language == "english");
diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cpp
index d20d70d..4c0f36e 100644
--- a/tests/steam_app_info_test.cpp
+++ b/tests/steam_app_info_test.cpp
@@ -902,6 +902,82 @@ void TestVersions() {
BetaKeyMatchesBranch("default", "") && BetaKeyMatchesBranch("", "beta") && !BetaKeyMatchesBranch("4.04", "public"));
}
+// The shape of Warhammer 40,000: Space Marine 2: a free pack the game lists, a paid DLC, one only its own appinfo
+// lists, and DLC with no files.
+void TestDlcChoice() {
+ const auto game = ParseAppInfo(5000, R"("appinfo"
+{
+ "common" { "name" "Big Game" "type" "Game" }
+ "extended" { "listofdlc" "5001,5002,5003,5004,5005,5006" }
+ "depots"
+ {
+ "5000" { "manifests" { "public" { "gid" "1" "size" "1000" "download" "800" } } }
+ "5011" { "dlcappid" "5001" "manifests" { "public" { "gid" "2" "size" "3000" "download" "2000" } } }
+ "5012" { "dlcappid" "5002" "manifests" { "public" { "gid" "3" "size" "20" "download" "10" } } }
+ "5015" { "dlcappid" "5005" "manifests" { "public" { "gid" "6" "size" "0" "download" "0" } } }
+ "5016" { "dlcappid" "5006" "manifests" { "public" { "gid" "7" "size" "7" "download" "7" } } }
+ }
+})");
+ CHECK(game.has_value());
+ const auto dlc = [](std::uint32_t id, const std::string& fields) {
+ const auto parsed = ParseAppInfo(id, "\"appinfo\" { " + fields + " }");
+ CHECK(parsed.has_value());
+ return *parsed;
+ };
+ const std::vector<AppInfo> dlc_apps{
+ dlc(5001, R"("common" { "name" "Big Game - Texture Pack" "type" "DLC" } "extended" { "isfreeapp" "1" })"),
+ dlc(5002, R"("common" { "name" "Art Book" "type" "DLC" })"),
+ dlc(5003, R"("common" { "name" "Big Game: Campaign" "type" "DLC" }
+ "depots" { "5013" { "manifests" { "public" { "gid" "4" "size" "50" "download" "40" } } } })"),
+ dlc(5004, R"("common" { "name" "Skin" "type" "DLC" } "extended" { "isfreeapp" "1" })"),
+ dlc(5005, R"("common" { "name" "Unlock" "type" "DLC" })"),
+ };
+ CHECK(dlc_apps[0].free_app && !dlc_apps[1].free_app);
+ const std::set<std::uint32_t> owned{5000, 5002, 5003, 5005, 5006};
+ const std::set<std::uint32_t> depots{5000, 5012, 5013, 5015, 5016};
+
+ // Sorted by name, without the game's in front; the DLC Steam doesn't describe last; no files, no row.
+ auto offers = OfferedDlc(*game, dlc_apps, owned, depots, DepotSelection{});
+ CHECK(offers.size() == 4);
+ CHECK(offers[0].name == "Art Book" && offers[0].install_bytes == 20 && offers[0].download_bytes == 10 && !offers[0].free);
+ CHECK(offers[1].name == "Campaign" && offers[1].app_id == 5003 && offers[1].install_bytes == 50);
+ CHECK(offers[2].name == "Texture Pack" && offers[2].free && offers[2].install_bytes == 3000);
+ CHECK(offers[3].name.empty() && offers[3].app_id == 5006);
+
+ // Free DLC Steam refused this account, or already owned, isn't offered as free.
+ offers = OfferedDlc(*game, dlc_apps, owned, depots, DepotSelection{}, {5001});
+ CHECK(std::none_of(offers.begin(), offers.end(), [](const DlcOffer& offer) { return offer.app_id == 5001; }));
+ auto claimed = owned;
+ claimed.insert(5001);
+ auto claimed_depots = depots;
+ claimed_depots.insert(5011);
+ offers = OfferedDlc(*game, dlc_apps, claimed, claimed_depots, DepotSelection{});
+ CHECK(offers[2].app_id == 5001 && !offers[2].free);
+
+ // The list doesn't depend on what is turned off.
+ DepotSelection without;
+ without.excluded_dlc = {5002, 5003, 5000};
+ CHECK(OfferedDlc(*game, dlc_apps, owned, depots, without).size() == 4);
+
+ // Excluded DLC stays out with its reason, wherever its depot is listed; the game's own content can't be excluded.
+ SelectionResult result;
+ CHECK(SelectDepots(*game, dlc_apps, owned, depots, without, &result));
+ std::set<std::uint32_t> ids;
+ for (const auto& depot : result.depots) ids.insert(depot.id);
+ CHECK((ids == std::set<std::uint32_t>{5000, 5015, 5016}));
+ const auto reason = [&](std::uint32_t id) {
+ for (const auto& rejected : result.rejected)
+ if (rejected.id == id) return rejected.reason;
+ return std::string();
+ };
+ CHECK(reason(5012) == "dlc-off" && reason(5013) == "dlc-off" && reason(5011) == "licence");
+
+ // A name that only starts like the game's stays whole.
+ const auto similar = dlc(5002, R"("common" { "name" "Big Gamers Pack" "type" "DLC" })");
+ offers = OfferedDlc(*game, {similar}, owned, depots, DepotSelection{});
+ CHECK(offers[0].name == "Big Gamers Pack");
+}
+
void TestWindowsArguments() {
using Args = std::vector<std::string>;
CHECK(ParseWindowsArguments("-a \"b c\"") == Args({"-a", "b c"}));
@@ -970,6 +1046,7 @@ int main(int argc, char** argv) {
TestSelectionNeedsTheGamesContent();
TestEligibleLaunches();
TestVersions();
+ TestDlcChoice();
TestWindowsArguments();
TestRelativeGamePath();
TestOsList();