Skip to content

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

C++

Keep the program chosen at Install as Steam's option

Leonardo Lobato6e999b62a7a9
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 58655a4..a219051 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -1820,6 +1820,16 @@ void Controller::SubmitPrepare(GameId id, bool announce) {
if (const auto found = launch_options_.find(id); found != launch_options_.end())
for (const auto& option : found->second)
request.launches.push_back({"", option.description, option.executable, option.working_directory, option.arguments});
+ // The program chosen at Install when Steam listed options only for other branches goes first.
+ if (const auto record = model_.state().game_settings.find(id);
+ record != model_.state().game_settings.end() && !record->second.steam_launch.empty())
+ std::stable_partition(request.launches.begin(), request.launches.end(), [&](const auto& launch) {
+ const auto path = steam::RelativeGamePath(launch.executable);
+ const auto& chosen = record->second.steam_launch;
+ return path && std::equal(path->begin(), path->end(), chosen.begin(), chosen.end(), [](char a, char b) {
+ return std::tolower(static_cast<unsigned char>(a)) == std::tolower(static_cast<unsigned char>(b));
+ });
+ });
// Steam's launch options and app details are for Steam games only: another store's game starts the
// program the player picks in Game settings.
const bool steam = id.store == Store::kSteam;
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index c4497d8..c7b1fc7 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -1190,13 +1190,14 @@ bool Simulation::ask_steam_program(GameId id) {
const auto* game = find_game(state_, id);
if (!game || game->launch_programs.empty()) return false;
const auto programs = steam_programs(*game);
- // A program the player already chose in Game settings is kept.
- if (const auto found = state_.game_settings.find(id);
- found != state_.game_settings.end() && found->second.overrides.count("program"))
+ // A program the player already chose (in Game settings, or here for an earlier install) is kept.
+ if (const auto found = state_.game_settings.find(id); found != state_.game_settings.end() &&
+ (found->second.overrides.count("program") ||
+ !found->second.steam_launch.empty()))
return false;
if (const auto clear = playden::stores::local::ClearGameProgram(programs)) {
// Steam's first option is tried first; an installer or tool listed before the game isn't.
- if (programs[*clear].path != game->launch_programs.front().path) SeedGameProgram(id, programs[*clear].path);
+ if (programs[*clear].path != game->launch_programs.front().path) choose_steam_launch(id, programs[*clear].path);
return false;
}
steam_programs_shown_ = programs;
@@ -1209,13 +1210,13 @@ bool Simulation::ask_steam_program(GameId id) {
return true;
}
-bool Simulation::SeedGameProgram(GameId id, const std::string& program, bool chosen) {
+bool Simulation::SeedGameProgram(GameId id, const std::string& program) {
if (!live() || !id.valid() || settings_load_failed_ || game_settings_file_.empty()) return false;
if (!rt::ValidateSettingValue(rt::GameRecipe{}, "program", program, nullptr)) return false;
// Only a record never saved: once the player changed anything (a Program reset included), the
// choice is theirs.
- if (const auto found = state_.game_settings.find(id); !chosen && found != state_.game_settings.end() &&
- (found->second.revision != 0 || !found->second.overrides.empty()))
+ if (const auto found = state_.game_settings.find(id);
+ found != state_.game_settings.end() && (found->second.revision != 0 || !found->second.overrides.empty()))
return false;
auto& record = state_.game_settings[id];
record.overrides["program"] = program;
@@ -2005,6 +2006,14 @@ bool live_install_allowed(InstallReadiness readiness, bool free_space_supported)
} // namespace
+// The Steam option is kept as Steam's (its arguments, folder and the launcher and Unreal rules
+// preparation applies), only first; Game settings › Program still lists the others.
+void Simulation::choose_steam_launch(GameId id, const std::string& program) {
+ if (!live() || !id.valid()) return;
+ state_.game_settings[id].steam_launch = program;
+ save_profile();
+}
+
void Simulation::start_live_install(GameId id) {
// Install at once when the game fits the default drive (or its size is checked later);
// otherwise the sheet says why and offers another drive for this install.
@@ -6443,7 +6452,7 @@ void Simulation::activate() {
const auto index = static_cast<std::size_t>(std::stoul(action_name.substr(14)));
if (index >= steam_programs_shown_.size()) return;
const auto id = steam_programs_game_;
- SeedGameProgram(id, steam_programs_shown_[index].path, true);
+ choose_steam_launch(id, steam_programs_shown_[index].path);
close_modal();
start_live_install(id);
} else if (live() && action_name == "open-downloads") {
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 7fd7997..4cb67e7 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -734,8 +734,7 @@ public:
// Writes the program an imported game starts with into its Game settings when the game has no
// saved settings yet (just added); never over anything the player changed, a reset Program
// included. Saved at once so the next preparation reads it. True when it was written.
- // `chosen`: the player picked it just now (Install's program sheet), so it is written anyway.
- bool SeedGameProgram(GameId id, const std::string& program, bool chosen = false);
+ bool SeedGameProgram(GameId id, const std::string& program);
[[nodiscard]] std::vector<GameId> TakeKeptDeleteRequests();
// Live mode: maintenance the player confirmed (and settings to apply when the sheet
// closes), and games whose title activity the sheet needs to know.
@@ -1087,6 +1086,7 @@ private:
// (the import rules: installers and tools last, one clear program isn't asked for).
[[nodiscard]] static std::vector<LaunchProgram> steam_programs(const Game& game);
bool ask_steam_program(GameId id);
+ void choose_steam_launch(GameId id, const std::string& program);
void start_live_install(GameId id);
std::vector<LaunchProgram> steam_programs_shown_;
GameId steam_programs_game_;
diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cpp
index 753610a..a416d47 100644
--- a/src/runtime/game_settings.cpp
+++ b/src/runtime/game_settings.cpp
@@ -1219,6 +1219,8 @@ bool RecordFromValue(const storage_json::Value& root, GameSettingsRecord* out) {
// A malformed app ID is dropped, not the record: the rest of the player's settings still load.
if (const auto* app = root.Find("steam_app_id"); app && app->is_string())
out->steam_app_id = ParseSteamAppId(app->text()).value_or(0);
+ if (const auto* launch = root.Find("steam_launch"); launch && launch->is_string())
+ out->steam_launch = steam::RelativeGamePath(launch->text()).value_or(std::string());
// Settings this build does not know are dropped so an older record still loads.
for (auto it = out->overrides.begin(); it != out->overrides.end();)
it = FindSetting(it->first) || IsUnlockKey(it->first) ? std::next(it) : out->overrides.erase(it);
@@ -1256,6 +1258,7 @@ std::string SerializeGameSettingsRecord(const GameSettingsRecord& record) {
}
text += "}";
if (record.steam_app_id) text += ",\"steam_app_id\":\"" + std::to_string(record.steam_app_id) + "\"";
+ if (!record.steam_launch.empty()) text += ",\"steam_launch\":\"" + json::escape(record.steam_launch) + "\"";
return text + "}";
}
@@ -1877,7 +1880,7 @@ std::string SerializeSettingsFile(
bool first = true;
for (const auto& [id, record] : records) {
if (!id.valid() || (record.preset_id.empty() && record.overrides.empty() && record.revision == 0 &&
- !record.steam_app_id))
+ !record.steam_app_id && record.steam_launch.empty()))
continue;
if (!first) text += ",";
first = false;
diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.h
index 530e3b2..de7e4de 100644
--- a/src/runtime/game_settings.h
+++ b/src/runtime/game_settings.h
@@ -151,11 +151,14 @@ struct GameSettingsRecord {
// A game from another store that uses Steamworks: its Steam app ID for the emulator, when the game's
// folder has no steam_appid.txt (the game's own file wins). 0: not set. Saved only when set.
std::uint32_t steam_app_id = 0;
+ // A Steam game whose launch options are all for other branches: the program the player chose at
+ // Install. Its option goes first when the game is prepared. Empty: not set. Saved only when set.
+ std::string steam_launch;
};
inline bool operator==(const GameSettingsRecord& left, const GameSettingsRecord& right) {
return left.preset_id == right.preset_id && left.overrides == right.overrides && left.revision == right.revision &&
- left.steam_app_id == right.steam_app_id;
+ left.steam_app_id == right.steam_app_id && left.steam_launch == right.steam_launch;
}
inline bool operator!=(const GameSettingsRecord& left, const GameSettingsRecord& right) { return !(left == right); }
diff --git a/tests/game_settings_io_test.cpp b/tests/game_settings_io_test.cpp
index 3731c57..cf96b2f 100644
--- a/tests/game_settings_io_test.cpp
+++ b/tests/game_settings_io_test.cpp
@@ -148,6 +148,18 @@ int main(int argc, char** argv) {
CHECK(ParseGameSettingsRecord("{\"steam_app_id\":\" 4294967295\\n\"}", &parsed, &reason) &&
parsed.steam_app_id == 4294967295u);
CHECK(!ParseSteamAppId("+5") && !ParseSteamAppId("") && ParseSteamAppId("\t7\r\n") == 7u);
+ // The Steam program chosen at Install is saved only when set, as a game-relative path.
+ GameSettingsRecord only_launch;
+ only_launch.steam_launch = "Win64/RSDragonwilds.exe";
+ const auto launches = root / "launches.json";
+ CHECK(SaveGameSettingsFile(launches.string(), {{SteamId(1374490), only_launch}}, &reason));
+ CHECK(Read(launches).find("\"steam_launch\":\"Win64/RSDragonwilds.exe\"") != std::string::npos);
+ std::map<playden::GameId, GameSettingsRecord> launches_loaded;
+ CHECK(LoadGameSettingsFile(launches.string(), &launches_loaded, &reason) &&
+ launches_loaded.at(SteamId(1374490)) == only_launch);
+ CHECK(ParseGameSettingsRecord("{\"steam_launch\":\"Bin\\\\Game.exe\"}", &parsed, &reason) &&
+ parsed.steam_launch == "Bin/Game.exe");
+ CHECK(ParseGameSettingsRecord("{\"steam_launch\":\"../x.exe\"}", &parsed, &reason) && parsed.steam_launch.empty());
}
const auto public_private_root = root / "public-settings";
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index 9001c19..8400433 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -840,8 +840,12 @@ void live_install_asks_for_a_steam_program(const std::filesystem::path& base) {
auto requests = model.TakeInstallRequests();
check(requests.size() == 1 && requests[0].kind == InstallRequestKind::Install && requests[0].game_id == SteamId(1374490),
"steam program: choosing one installs");
- check(model.state().game_settings.at(SteamId(1374490)).overrides.at("program") == "Aqua-Coyote.exe",
- "steam program: the choice goes into Game settings");
+ check(model.state().game_settings.at(SteamId(1374490)).steam_launch == "Aqua-Coyote.exe" &&
+ model.state().game_settings.at(SteamId(1374490)).overrides.empty(),
+ "steam program: the choice is kept as Steam's option, not as a Program");
+ activate(model, "details-install");
+ check(model.view().surface != "steam-programs" && model.TakeInstallRequests().size() == 1,
+ "steam program: an earlier choice isn't asked for again");
// One program besides installers and tools: no question.
check(model.action("details:1384160") &&
@@ -852,6 +856,12 @@ void live_install_asks_for_a_steam_program(const std::filesystem::path& base) {
check(model.view().surface != "steam-programs" && requests.size() == 1 && requests[0].game_id == SteamId(1384160),
"steam program: one clear program installs at once");
check(!model.state().game_settings.count(SteamId(1384160)), "steam program: Steam's first option needs no setting");
+ // An installer or tool listed before the game: the game's option goes first.
+ check(model.UpdateAppDetails(SteamId(1384160), 100, 200, true, {{"Redist/vcredist.exe", true}, {"GGST.exe", false}}),
+ "steam program: details with a tool first");
+ activate(model, "details-install");
+ check(model.TakeInstallRequests().size() == 1 && model.state().game_settings.at(SteamId(1384160)).steam_launch == "GGST.exe",
+ "steam program: the clear program goes before the tool");
}
} // namespace