Play your Steam library's Windows games on a jailbroken PS5.
C++
Offer launch options for installed DLC
Leonardo Lobatod67d0abd321f
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex 207d4e2..e5baab4 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -2092,12 +2092,12 @@ void Controller::TickInstalls() {continue;}// A version other than public starts as that branch does: the launch options Steam's details gave before the- // install were the public branch's. They are asked for again for the installed record, and the preparation- // waits for them (RequestPrepare).+ // install were the public branch's. A DLC in the install can add options of its own (DUSK HD). They are asked for+ // again for the installed record, and the preparation waits for them (RequestPrepare).const auto installed = std::find_if(snapshot.installed.begin(), snapshot.installed.end(),[id](const steam::InstalledGame& game) { return game.id == id; });- if (installed != snapshot.installed.end() && installed->record && !installed->record->branch.empty() &&- installed->record->branch != "public") {+ if (installed != snapshot.installed.end() && installed->record &&+ ((!installed->record->branch.empty() && installed->record->branch != "public") || installs::HoldsDlc(*installed->record))) {launch_options_.erase(id);launch_options_reason_.erase(id);launches_any_branch_.erase(id);diff --git a/src/installs/install_record.h b/src/installs/install_record.hindex 9013904..2e587a5 100644--- a/src/installs/install_record.h+++ b/src/installs/install_record.h@@ -40,6 +40,13 @@ struct InstalledRecord {}};+// Whether a depot of the install is a DLC's. Steam may then offer launch options that it didn't before the install.+inline bool HoldsDlc(const InstalledRecord& record) {+ for (const auto& depot : record.depots)+ if (depot.owner != 0 && depot.owner != record.app_id) return true;+ return false;+}+inline constexpr const char* kInstallRecordName = ".playden-install.json";// Left in the game's root by an update that changed its files (written before the update's record): the// game's launch, set up from the old files, is made again from the new ones before it starts, and thediff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cppindex 1751bde..edd8a43 100644--- a/src/steam/backend/app_info.cpp+++ b/src/steam/backend/app_info.cpp@@ -827,9 +827,13 @@ bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_a};auto eligible = eligible_for(false);// Steam still starts a game whose only options name other branches (GUILTY GEAR -STRIVE- lists- // one for "debug"): every branch's options are then candidates.- const bool fallback = eligible.empty();- if (fallback) eligible = eligible_for(true);+ // one for "debug"): every branch's options are then candidates. An option that needs a DLC doesn't count: it can't+ // take the place of the game's own, whichever branch that names.+ const auto own = [](const AppLaunch& launch) { return !launch.required_dlc || *launch.required_dlc == 0; };+ const auto any_branch_options = eligible_for(true);+ const bool fallback = std::none_of(eligible.begin(), eligible.end(), own) &&+ (eligible.empty() || std::any_of(any_branch_options.begin(), any_branch_options.end(), own));+ if (fallback) eligible = any_branch_options;if (any_branch != nullptr) *any_branch = fallback && !eligible.empty();// A dedicated server listed without the "server" type is not the game either, unless it is all// Steam lists.@@ -845,6 +849,10 @@ bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_areturn Fail(reason, "The game has no valid Windows launch configuration.");}std::stable_sort(eligible.begin(), eligible.end(), [](const AppLaunch& a, const AppLaunch& b) {+ // What needs a DLC is a choice, never what Play starts by itself, whatever Steam's order says.+ const bool a_dlc = a.required_dlc && *a.required_dlc != 0;+ const bool b_dlc = b.required_dlc && *b.required_dlc != 0;+ if (a_dlc != b_dlc) return b_dlc;const bool a_default = LowerString(a.type) == "default";const bool b_default = LowerString(b.type) == "default";if (a_default != b_default) return a_default;diff --git a/src/steam/backend/cm_app_details.cpp b/src/steam/backend/cm_app_details.cppindex ccc085d..83df2cb 100644--- a/src/steam/backend/cm_app_details.cpp+++ b/src/steam/backend/cm_app_details.cpp@@ -179,7 +179,12 @@ AppDetails DetailsFromAppInfo(std::uint32_t id, const std::string& buffer,std::vector<AppLaunch> launches;// An installed game starts as its branch does.const std::string branch = installed && !installed->branch.empty() ? installed->branch : std::string("public");- details.windows_installable = EligibleLaunches(*app, owned, branch, &launches, &reason, &details.launches_any_branch);+ // A launch entry that needs a DLC (DUSK HD is a program of its own) is offered once the install holds that DLC.+ std::set<std::uint32_t> startable = owned;+ if (installed)+ for (const auto& depot : installed->depots)+ if (depot.owner != 0) startable.insert(depot.owner);+ details.windows_installable = EligibleLaunches(*app, startable, branch, &launches, &reason, &details.launches_any_branch);if (!details.windows_installable) details.reason = "No Windows launch configuration.";for (const auto& launch : launches)details.launches.push_back({launch.executable, launch.arguments, launch.working_directory,diff --git a/tests/app_details_test.cpp b/tests/app_details_test.cppindex 664f892..bc977c2 100644--- a/tests/app_details_test.cpp+++ b/tests/app_details_test.cpp@@ -751,6 +751,43 @@ void IncludedDlcIsCounted() {assert(DepotsToMeasure(6100, pack_game, both, "public", "english", {*pack}, {6101}).empty());}+// A launch entry that needs a DLC is offered once the install holds that DLC, after the game's own.+void LaunchesFollowInstalledDlc() {+ const std::string buffer = R"("appinfo"+{+ "extended" { "listofdlc" "9101" }+ "config" { "launch" {+ "0" { "executable" "HD/game.exe" "description" "Game HD" "config" { "oslist" "windows" "ownsdlc" "9101" } }+ "1" { "executable" "game.exe" "description" "Game" "config" { "oslist" "windows" } }+ } }+ "depots"+ {+ "9000" { "manifests" { "public" { "gid" "1" "size" "100" "download" "50" } } }+ "9111" { "dlcappid" "9101" "manifests" { "public" { "gid" "2" "size" "10" "download" "5" } } }+ "branches" { "public" { "buildid" "1" } }+ }+})";+ const LicensedDepots::Grant grant{{9000, 9101}, {9000, 9111}};+ // Not installed: only what any install can start, whatever is owned.+ auto details = DetailsFromAppInfo(9000, buffer, grant);+ assert(details.launches.size() == 1 && details.launches[0].executable == "game.exe");+ // Owned but turned off, so not in the install: still not offered.+ installs::InstalledRecord record;+ record.version = 2;+ record.app_id = 9000;+ record.depots = {{9000, 1, 9000, 9000}};+ record.excluded_dlc = {9101};+ details = DetailsFromAppInfo(9000, buffer, grant, "english", record);+ assert(details.launches.size() == 1 && details.launches[0].executable == "game.exe");+ assert(!installs::HoldsDlc(record));+ // In the install: offered, and the game itself stays first, what Play starts.+ record.excluded_dlc.clear();+ record.depots.push_back({9111, 2, 9101, 9000});+ assert(installs::HoldsDlc(record));+ details = DetailsFromAppInfo(9000, buffer, grant, "english", record);+ assert(details.launches.size() == 2 && details.launches[0].executable == "game.exe" && details.launches[1].executable == "HD/game.exe");+}+// The versions an install can choose, with each one's own size; the licenses filter them as they do the sizes.void VersionsAreOffered() {const std::string buffer = R"("appinfo"@@ -886,6 +923,7 @@ int main() {ImpossibleDownloadSizeFallsBackToInstallSize();SizesFollowTheContentLanguage();IncludedDlcIsCounted();+ LaunchesFollowInstalledDlc();VersionsAreOffered();InstalledGamesCompareWithTheirRecord();}diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cppindex 3b91bd7..99e7ed7 100644--- a/tests/steam_app_info_test.cpp+++ b/tests/steam_app_info_test.cpp@@ -761,8 +761,9 @@ void TestEligibleLaunches() {std::string reason;CHECK(EligibleLaunches(*app, {kApp}, "public", &launches, &reason));CHECK((LaunchIds(launches) == Strings{"0", "10"}));+ // With the DLC its entry joins, after the others: Play's default doesn't change.CHECK(EligibleLaunches(*app, {kApp, 999}, "public", &launches, &reason));- CHECK((LaunchIds(launches) == Strings{"0", "3", "10"}));+ CHECK((LaunchIds(launches) == Strings{"0", "10", "3"}));AppInfo none = *app;none.launches.resize(2); // "0" is not first any more; keep only "3" and "10"-less set@@ -772,7 +773,12 @@ void TestEligibleLaunches() {AppInfo reordered = *app;reordered.launches[0].type = "";- reordered.launches[3].type = "Default"; // launch "3" sorts first despite its id+ reordered.launches[3].type = "Default";+ // An entry that needs a DLC stays a choice, even marked as the default...+ CHECK(EligibleLaunches(reordered, {kApp, 999}, "", &launches, &reason));+ CHECK((LaunchIds(launches) == Strings{"0", "10", "3"}));+ // ...and without that, "3" sorts first despite its id.+ reordered.launches[3].required_dlc.reset();CHECK(EligibleLaunches(reordered, {kApp, 999}, "", &launches, &reason));CHECK((LaunchIds(launches) == Strings{"3", "0", "10"}));@@ -819,7 +825,19 @@ void TestEligibleLaunches() {CHECK(EligibleLaunches(branches, {kApp}, "", &launches, &reason, &any_branch));CHECK((LaunchIds(launches) == Strings{"0", "2", "10"}) && any_branch);CHECK(EligibleLaunches(branches, {kApp, 999}, "", &launches, &reason, &any_branch));- CHECK((LaunchIds(launches) == Strings{"0", "2", "3", "10"}) && any_branch);+ CHECK((LaunchIds(launches) == Strings{"0", "2", "10", "3"}) && any_branch);+ // The DLC's option on this branch doesn't hide the game's on another: the game's still come first.+ for (auto& launch : branches.launches)+ if (launch.required_dlc) launch.beta_key.reset();+ CHECK(EligibleLaunches(branches, {kApp, 999}, "", &launches, &reason, &any_branch));+ CHECK((LaunchIds(launches) == Strings{"0", "2", "10", "3"}) && any_branch);+ // Only a DLC's option exists: that is no other-branch fallback.+ AppInfo only_dlc = branches;+ only_dlc.launches.erase(std::remove_if(only_dlc.launches.begin(), only_dlc.launches.end(),+ [](const AppLaunch& launch) { return !launch.required_dlc; }),+ only_dlc.launches.end());+ CHECK(EligibleLaunches(only_dlc, {kApp, 999}, "", &launches, &reason, &any_branch));+ CHECK((LaunchIds(launches) == Strings{"3"}) && !any_branch);}// Versions: each branch installs its own manifests, with no fallback to the public ones.