Skip to content

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

C++

Offer Recreate bottle when settings outgrow it

Leonardo Lobato86d2f37cd2c7
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index a5627de..9da6d14 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -962,6 +962,8 @@ void Controller::TickRuntime() {
snapshot.status == RuntimeHostStatus::kReady;
game.settings_revision = record->settings_revision;
game.launch_entry_id = record->launch_entry_id;
+ game.launch_path = record->launch_path;
+ game.launch_working_directory = record->launch_working_directory;
game.save_backups = record->save_backups;
game.latest_save_backup = record->latest_save_backup;
}
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index ecabb7e..e76f10c 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -626,6 +626,8 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::str
view.admission = found->second;
view.settings_revision = record.settings_revision;
view.launch_entry_id = record.launch_entry_id;
+ view.launch_path = record.launch_path;
+ view.launch_working_directory = record.launch_working_directory;
std::error_code error;
for (std::filesystem::directory_iterator it(SaveBackupRoot(record.install_id), error), end; !error && it != end;
it.increment(error)) {
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index f8fc839..64f05a6 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -141,6 +141,8 @@ struct RuntimeInstallView {
// title was prepared with (a different Launch option needs the bottle made again).
std::uint64_t settings_revision = 0;
std::string launch_entry_id;
+ std::string launch_path; // its program, relative to the install root
+ std::string launch_working_directory; // its folder; empty: the program's own
// Save backups kept for the game, and when the newest was made (Unix time).
std::size_t save_backups = 0;
std::int64_t latest_save_backup = 0;
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 40e16b9..3e33135 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -14,6 +14,7 @@
#include <cstring>
#include <algorithm>
+#include <cctype>
#include <cerrno>
#include <ctime>
#include <fcntl.h>
@@ -401,7 +402,7 @@ std::vector<std::string> split_overrides(const std::string& list) {
std::string action_label(const std::string& key) {
static const std::map<std::string, std::string> labels = {
- {"cancel", "Cancel"}, {"confirm-destructive", "Confirm"}, {"ready-later", "Later"}, {"alert-ok", "OK"}, {"alert-settings", "Game settings"}, {"runtime-cleanup-confirm", "Clean up"}, {"quit-to-home", "Play"}, {"favorite", "Favorite"},
+ {"cancel", "Cancel"}, {"confirm-destructive", "Confirm"}, {"ready-later", "Later"}, {"bottle-recreate", "Recreate bottle"}, {"runtime-play-anyway", "Play anyway"}, {"alert-ok", "OK"}, {"alert-settings", "Game settings"}, {"runtime-cleanup-confirm", "Clean up"}, {"quit-to-home", "Play"}, {"favorite", "Favorite"},
{"collection", "Collections"}, {"note", "Compatibility and note"}, {"verify", "Verify files"},
{"uninstall", "Uninstall"}, {"uninstall-delete-saves", "Delete saves too"}, {"logs", "Open logs"}, {"logs-back", "Back"},
{"logs-pick", "Logs"}, {"log-install", "Install log"}, {"log-auth", "Sign-in log"},
@@ -2418,13 +2419,10 @@ void Simulation::rebuild_view() {
item.enabled = false;
item.subtitle = closed_reason;
}
- // The prepared title keeps its launch entry until the bottle is made again.
- if (id == "launch_option" && live()) {
- const auto runtime_game = state_.runtime_games.find(settings_game);
- if (runtime_game != state_.runtime_games.end() && runtime_game->second.prepared &&
- settings_values.launch && settings_values.launch->id != runtime_game->second.launch_entry_id)
- item.subtitle = "Takes effect after Maintenance > Recreate bottle.";
- }
+ // A changed "Prepares bottle" row waits for the bottle to be made again.
+ if (definition->apply == rt::ApplyMode::kPreparesBottle && value.source == rt::ValueSource::kUser &&
+ bottle_outdated(settings_game))
+ item.subtitle = "Takes effect after Maintenance > Recreate bottle.";
// The technical names show on the focused row only, so more rows fit.
const bool focused_row = modal.focused_action >= 0 &&
static_cast<std::size_t>(modal.focused_action) < modal.action_keys.size() &&
@@ -2916,6 +2914,7 @@ void Simulation::rebuild_view() {
: value.status == "Needs repair" ? "Runtime needs repair" : value.status;
runtime.subtitle = rechosen_after_refusal_.count(game->id) && value.status == "Not prepared"
? "Play prepares it with your choices from Game settings" : value.detail;
+ if (bottle_outdated(game->id)) runtime.subtitle = "Settings apply when the bottle is prepared again";
runtime.enabled = false;
if (value.progress) runtime.progress = std::max(*value.progress, 0.001F);
}
@@ -4121,7 +4120,29 @@ void Simulation::activate() {
push_notice({"runtime-cleanup", "Unused game settings data cleaned up", "", false, kLiveNoticeSeconds, false, ""});
} else if (live() && action_name == "runtime-play") {
const auto id = state_.navigation.detail_id.value_or(state_.navigation.selected_game_id);
+ // Settings changed since the title was made apply only once the bottle is made again.
+ if (id != 0 && bottle_outdated(id)) offer_recreate_bottle(id, true);
+ else if (id != 0) pending_runtime_play_requests_.push_back(id);
+ } else if (live() && action_name == "runtime-play-anyway") {
+ const auto id = recreate_offer_game_;
+ close_modal();
if (id != 0) pending_runtime_play_requests_.push_back(id);
+ } else if (live() && action_name == "bottle-recreate") {
+ const auto id = recreate_offer_game_;
+ std::string refusal;
+ if (id == 0) {
+ close_modal();
+ } else if (!game_closed(id, &refusal)) {
+ // The offer stays open; the console's answer about the game arrives shortly.
+ push_notice({"recreate-" + std::to_string(id), "Recreate bottle has to wait", "", false, kLiveNoticeSeconds,
+ false, refusal});
+ } else {
+ close_modal();
+ request_maintenance(id, MaintenanceKind::RecreateBottle);
+ const auto* game = find_game(state_, id);
+ push_notice({"recreate-" + std::to_string(id), "Recreating the bottle", "", false, kLiveNoticeSeconds, false,
+ game ? game->title : std::string()});
+ }
} else if (live() && action_name == "live-install") {
const auto id = state_.navigation.detail_id.value_or(state_.navigation.selected_game_id);
if (id != 0) pending_install_requests_.push_back({InstallRequestKind::Install, id});
@@ -5533,6 +5554,53 @@ bool Simulation::game_closed(GameId id, std::string* reason) const {
return true;
}
+namespace {
+// A game-relative path as the bottle config compares it: '/' separated, lower case, "." for none.
+std::string BottlePath(std::string path) {
+ std::replace(path.begin(), path.end(), '\\', '/');
+ std::transform(path.begin(), path.end(), path.begin(),
+ [](unsigned char value) { return static_cast<char>(std::tolower(value)); });
+ return path == "." ? std::string() : path;
+}
+} // namespace
+
+std::optional<Simulation::BottleConfig> Simulation::prepared_bottle(GameId id) const {
+ if (!live() || !game_prepared(id)) return std::nullopt;
+ const auto& title = state_.runtime_games.at(id);
+ return BottleConfig{title.launch_entry_id, BottlePath(title.launch_path), BottlePath(title.launch_working_directory)};
+}
+
+std::optional<Simulation::BottleConfig> Simulation::chosen_bottle(GameId id) const {
+ // Without the game's own recipe the sheet's generic one says nothing about the title.
+ if (RecipeFor(id).id.rfind("simulated-", 0) == 0) return std::nullopt;
+ rt::EffectiveSettings values;
+ if (!EffectiveSettingsFor(id, &values) || !values.launch) return std::nullopt;
+ const auto& launch = *values.launch;
+ return BottleConfig{launch.id, BottlePath(launch.executable), BottlePath(launch.working_directory)};
+}
+
+bool Simulation::bottle_outdated(GameId id) const {
+ const auto prepared = prepared_bottle(id);
+ if (!prepared) return false;
+ const auto chosen = chosen_bottle(id);
+ return chosen && *chosen != *prepared;
+}
+
+void Simulation::offer_recreate_bottle(GameId id, bool on_play) {
+ if (!bottle_outdated(id)) return;
+ // Recreate bottle needs the game closed; ask now so the answer is there when it is chosen.
+ pending_activity_requests_.push_back(id);
+ recreate_offer_game_ = id;
+ ModalEntry offer{"confirmation", on_play ? "Recreate the bottle first?" : "Recreate the bottle now?",
+ on_play ? "details-play" : state_.navigation.focus_key,
+ on_play ? std::vector<std::string>{"cancel", "runtime-play-anyway", "bottle-recreate"}
+ : std::vector<std::string>{"ready-later", "bottle-recreate"},
+ on_play ? 2 : 1, false};
+ offer.body = "Some settings apply only when the bottle is prepared again. Recreate bottle keeps saves and settings; "
+ "the game then waits for the PS5 Home screen once more.";
+ open_modal(std::move(offer));
+}
+
void Simulation::request_maintenance(GameId id, MaintenanceKind kind) {
if (!live()) {
// Fixture mode only describes what the real action does.
@@ -5755,12 +5823,17 @@ void Simulation::announce_settings_saved() {
for (const auto& [id, value] : before.overrides) ids.insert(id);
for (const auto& [id, value] : after.overrides) ids.insert(id);
int changes = before.preset_id != after.preset_id ? 1 : 0;
+ bool bottle_setting_changed = false;
for (const auto& id : ids) {
const auto old_value = before.overrides.find(id);
const auto new_value = after.overrides.find(id);
if ((old_value == before.overrides.end()) != (new_value == after.overrides.end()) ||
- (old_value != before.overrides.end() && old_value->second != new_value->second))
+ (old_value != before.overrides.end() && old_value->second != new_value->second)) {
++changes;
+ const auto* definition = rt::FindSetting(id);
+ bottle_setting_changed = bottle_setting_changed ||
+ (definition && definition->apply == rt::ApplyMode::kPreparesBottle);
+ }
}
if (changes == 0) return;
const auto game = state_.navigation.selected_game_id;
@@ -5777,15 +5850,15 @@ void Simulation::announce_settings_saved() {
runtime_game->second.play_status == "Playing")
: !game_closed(game);
when += running ? " the next time Playden starts the game" : " on next launch";
- const auto old_launch = before.overrides.find("launch_option");
- const auto new_launch = after.overrides.find("launch_option");
- const bool launch_changed = (old_launch == before.overrides.end()) != (new_launch == after.overrides.end()) ||
- (old_launch != before.overrides.end() && old_launch->second != new_launch->second);
- if (launch_changed && live() && game_prepared(game)) when += " · Launch option after Recreate bottle";
+ const bool outdated = bottle_outdated(game);
+ if (outdated) when += " · Some after Recreate bottle";
push_notice({"settings-saved", "Settings saved · " + (after.overrides.empty() ? name : "Custom · from " + name), "", false,
kLiveNoticeSeconds, false, when});
// A prepared title gets the new settings now when it is stopped; otherwise Play applies them.
if (live() && game_prepared(game)) pending_maintenance_requests_.push_back({game, MaintenanceKind::ApplySettings});
+ // A "Prepares bottle" setting changed just now: offer to make the bottle again now rather than at Play.
+ // A running game, or one whose player chose Later before, gets the offer when Play is next pressed.
+ if (outdated && bottle_setting_changed && !running) offer_recreate_bottle(game, false);
}
bool Simulation::can_change_game_settings() {
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 789de2a..71fddb8 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -108,6 +108,8 @@ struct LiveRuntimeGame {
// The settings revision its PS5 title publishes and the launch entry it was made for.
std::uint64_t settings_revision = 0;
std::string launch_entry_id;
+ std::string launch_path; // its program, relative to the install root
+ std::string launch_working_directory; // empty: the program's own folder
TitleActivity activity = TitleActivity::Unknown;
// The newest maintenance request and its outcome.
std::optional<MaintenanceKind> maintenance;
@@ -602,6 +604,7 @@ private:
ViewData route_view_;
std::string last_error_;
std::string pending_destructive_action_;
+ GameId recreate_offer_game_ = 0; // the game the open Recreate bottle offer is for
std::string selected_volume_id_;
std::vector<playden::runtime::SettingsPreset> settings_presets_;
std::map<std::uint32_t, playden::runtime::GameRecipe> recipes_;
@@ -734,6 +737,23 @@ private:
// Whether a setting or action that needs the game closed can run: false while the game
// runs or the console has not said; reason says why.
[[nodiscard]] bool game_closed(GameId id, std::string* reason = nullptr) const;
+ // What a prepared bottle is made for: the values of the "Prepares bottle" settings that its PS5
+ // title keeps until the bottle is made again (RuntimeHost::Launch starts the title's own program).
+ struct BottleConfig {
+ std::string launch_entry_id;
+ std::string program; // relative to the install root, lower case, '/' separated
+ std::string working_directory; // the same; empty: the program's own folder
+ bool operator==(const BottleConfig&) const = default;
+ };
+ // The config the game's PS5 title was prepared with, and the one its Game settings make now.
+ // Empty when the game has no prepared title or Playden does not know its recipe yet.
+ [[nodiscard]] std::optional<BottleConfig> prepared_bottle(GameId id) const;
+ [[nodiscard]] std::optional<BottleConfig> chosen_bottle(GameId id) const;
+ // Game settings changed a "Prepares bottle" setting since the title was made: those changes
+ // wait for Recreate bottle.
+ [[nodiscard]] bool bottle_outdated(GameId id) const;
+ // Offers Recreate bottle for such a game; on_play adds "Play anyway".
+ void offer_recreate_bottle(GameId id, bool on_play);
[[nodiscard]] std::vector<std::string> maintenance_actions() const;
// The game page's More menu: Game settings and Maintenance first for a prepared game.
[[nodiscard]] std::vector<std::string> details_context_actions() const;
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index 71db7e5..6574604 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -306,6 +306,106 @@ void live_settings_follow_the_prepared_title(const std::filesystem::path& base)
check(!find_row(model, "maintenance-shader")->enabled, "maintenance waits while the game runs");
}
+
+// A program chosen after the title was made starts only once the bottle is made again: closing
+// Game settings offers Recreate bottle, the game page says so, and Play offers it again.
+void live_program_change_offers_recreate_bottle(const std::filesystem::path& base) {
+ using playden::homebrew::GameId;
+ using playden::homebrew::MaintenanceKind;
+ using playden::homebrew::TitleActivity;
+ using Requests = std::vector<std::pair<GameId, MaintenanceKind>>;
+ std::filesystem::create_directories(base);
+ auto model = make_live(base);
+ model.SetGameSettingsFile(base / "recreate-settings.json");
+ model.SetSettingsData({{"playden-default", "Playden default", "Most games", "", {}}}, {});
+ model.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ playden::GameSummary game;
+ game.id = 22380;
+ game.title = "Fallout: New Vegas";
+ check(model.UpdateLibrary({{game}, false, {}, false, true, 100}), "recreate: library delivered");
+ model.UpdateInstalls({}, {{22380, 1024, "internal", true}});
+ // Prepared from Steam's launch option, the launcher, as on the console.
+ playden::runtime::GameRecipe recipe;
+ recipe.id = playden::runtime::GeneratedRecipeId(22380);
+ recipe.version = 2;
+ recipe.app_id = 22380;
+ recipe.name = game.title;
+ recipe.launch_entries = {{"launch-1", "Fallout: New Vegas", "FalloutNVLauncher.exe", "", ""}};
+ model.SetGeneratedRecipes({recipe});
+ std::map<GameId, playden::homebrew::LiveGameSetup> setups;
+ setups[22380].scanned = true;
+ setups[22380].programs = {{"FalloutNV.exe", "pe32", "", false, ""}, {"Other/Other.exe", "pe32", "", false, ""}};
+ model.SetGameSetups(setups);
+ playden::homebrew::LiveRuntimeGame runtime;
+ runtime.game_id = 22380;
+ runtime.status = "Ready";
+ runtime.ready = runtime.prepared = runtime.has_title = runtime.can_play = true;
+ runtime.launch_entry_id = "launch-1";
+ runtime.launch_path = "FalloutNVLauncher.exe";
+ runtime.activity = TitleActivity::Stopped;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ check(model.action("details:22380"), "recreate: open details");
+ const auto marked = [&] {
+ return find_row(model, "details-runtime")->subtitle == "Settings apply when the bottle is prepared again";
+ };
+ check(!marked(), "recreate: an unchanged bottle is not marked");
+
+ activate(model, "details-more");
+ activate(model, "game-settings");
+ (void)model.TakeActivityRequests();
+ activate(model, "setting-launch_option");
+ activate(model, "program-0");
+ check(find_row(model, "setting-launch_option")->subtitle.rfind("Takes effect after Maintenance > Recreate bottle.", 0) == 0,
+ "recreate: the Program row says the new program waits for Recreate bottle");
+ check(model.action("circle"), "recreate: close the settings sheet");
+ check(!model.state().navigation.modals.empty() &&
+ model.state().navigation.modals.back().title == "Recreate the bottle now?",
+ "recreate: closing the sheet offers Recreate bottle");
+ check(model.TakeMaintenanceRequests() == Requests{{22380, MaintenanceKind::ApplySettings}},
+ "recreate: the other settings are still applied");
+ activate(model, "ready-later");
+ check(model.state().navigation.modals.empty() && model.TakeMaintenanceRequests().empty(),
+ "recreate: Later leaves the bottle as it is");
+ check(marked(), "recreate: the game page marks the pending settings");
+ activate(model, "details-more");
+ activate(model, "game-settings");
+ activate(model, "setting-resolution");
+ activate(model, "choice-0");
+ check(model.action("circle") && model.state().navigation.modals.empty(),
+ "recreate: after Later, other changes do not offer it again");
+ (void)model.TakeMaintenanceRequests();
+
+ activate(model, "details-play");
+ check(model.state().navigation.modals.back().title == "Recreate the bottle first?" &&
+ model.TakeRuntimePlayRequests().empty(),
+ "recreate: Play offers Recreate bottle instead of starting the old program");
+ activate(model, "runtime-play-anyway");
+ check(model.TakeRuntimePlayRequests() == std::vector<GameId>{22380}, "recreate: Play anyway starts the prepared bottle");
+
+ activate(model, "details-play");
+ runtime.activity = TitleActivity::Running;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ activate(model, "bottle-recreate");
+ check(model.TakeMaintenanceRequests().empty() && !model.state().navigation.modals.empty(),
+ "recreate: a running game keeps the offer open");
+ runtime.activity = TitleActivity::Stopped;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ activate(model, "bottle-recreate");
+ check(model.TakeMaintenanceRequests() == Requests{{22380, MaintenanceKind::RecreateBottle}},
+ "recreate: the offer recreates the bottle");
+
+ // Made for the chosen program: nothing pending. Another program from the folder is pending again.
+ runtime.launch_entry_id = "program";
+ runtime.launch_path = "FalloutNV.exe";
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ check(!marked(), "recreate: a title made for the chosen program is not marked");
+ activate(model, "details-play");
+ check(model.TakeRuntimePlayRequests() == std::vector<GameId>{22380}, "recreate: Play starts it at once");
+ runtime.launch_path = "Other/Other.exe";
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ check(marked(), "recreate: one folder program replacing another is marked too");
+}
+
} // namespace
int main() {
@@ -316,6 +416,7 @@ int main() {
settings_survive_account_restore_and_cache_action_is_honest(base);
live_settings_follow_the_prepared_title(base);
+ live_program_change_offers_recreate_bottle(base);
live_starts_clean_and_never_reads_or_writes_fixtures(base);
live_dispatches_bounded_service_effects_and_replaces_challenges(base);
failed_signout_preserves_account_until_external_clear(base);