Skip to content

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

C++

Run a program from the game folder once

Leonardo Lobato408402cba952
diff --git a/README.md b/README.md
index 8b097d4..a8a7054 100644
--- a/README.md
+++ b/README.md
@@ -351,6 +351,9 @@ build/homebrew-host/playden-homebrew --simulation --scenario signed-out
happening, use Settings › Account › **Sign in again**: it keeps your library, favorites and settings.
- Godot games (Slay the Spire 2) need `--rendering-driver opengl3` in Game settings › Extra arguments. Playden picks
Godot's Vulkan renderer, which did not work on this kit.
+- Some games start only after their own settings program has run once. On the game's page, use Options ›
+ **Run a program once…**, pick that program, change the settings, close it, then press Play. Its own Play button
+ can't start the game on the PS5. Until Playden opens again, the game's Home tile starts that program too.
- The 120 Hz choice of the "Refresh rate" game setting needs a newer runtime kit; it is not available with this kit.
- When you close a game from the PS5 menu, it can stay suspended. Pressing Play again resumes it instead of starting
it again.
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 656c01c..7ec2f63 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -947,6 +947,13 @@ void Controller::TickRuntime() {
}
}
auto plays = model_.TakeRuntimePlayRequests();
+ {
+ auto programs = model_.TakeRuntimeSetupPrograms();
+ for (const auto id : plays) {
+ if (const auto found = programs.find(id); found != programs.end()) setup_programs_[id] = found->second;
+ else setup_programs_.erase(id);
+ }
+ }
// A game whose update is putting its files in place doesn't start (the details page says so).
if (installs_) std::erase_if(plays, [this](GameId id) { return installs_->Locked(id); });
std::erase_if(plays, [this](GameId id) { return HoldForDropFolder(id, DropFolderNext::kPlay); });
@@ -1219,11 +1226,14 @@ void Controller::TickRuntime() {
});
model_.NotifyPlayStopped(id, moving ? "The game is moving to another drive. Play once the move finishes."
: "The game's update is putting its files in place. Play once it finishes.");
+ setup_programs_.erase(id);
continue;
}
play_queued_.insert(id);
++plays_requested_;
- runtime_->Play(*app);
+ const auto program = setup_programs_.find(id);
+ runtime_->Play(*app, program == setup_programs_.end() ? std::string() : program->second);
+ if (program != setup_programs_.end()) setup_programs_.erase(program);
}
plays_ready_ = std::move(later);
{
diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hpp
index bd98088..cb801f8 100644
--- a/src/homebrew/controller.hpp
+++ b/src/homebrew/controller.hpp
@@ -232,6 +232,9 @@ class Controller {
// may start without syncing after a failed check, and what Play shows meanwhile.
std::map<GameId, bool> sync_before_play_;
std::vector<GameId> plays_ready_;
+ // Plays that run a program from the game folder once (Simulation::TakeRuntimeSetupPrograms), until handed to the
+ // runtime; a plain Play of the game drops its entry.
+ std::map<GameId, std::string> setup_programs_;
std::set<GameId> play_without_sync_;
// Games are prepared without a button press: once their download finishes (games
// downloading now, then games waiting to be prepared), and when Play finds one not
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 3fd8e6a..29aca49 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -587,11 +587,11 @@ void RuntimeHost::HoldPreparations(bool hold) {
wake_.notify_all();
}
-void RuntimeHost::Play(std::uint32_t app_id) {
+void RuntimeHost::Play(std::uint32_t app_id, std::string setup_program) {
{
std::lock_guard<std::mutex> lock(mutex_);
if (stopping_) return;
- play_requests_.push_back(app_id);
+ play_requests_.push_back({app_id, std::move(setup_program)});
}
wake_.notify_all();
}
@@ -1755,7 +1755,8 @@ std::string RuntimeHost::UnlinkDxvkConfig(const rt::RuntimeInstall& record) {
std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstall& record, bool* published,
bool steam_account_known, bool* prepare_again,
- std::string* upgrade_deferred, std::string* code, bool force) {
+ std::string* upgrade_deferred, std::string* code, bool force,
+ const std::string& setup_program) {
if (published) *published = false;
if (code) code->clear();
if (prepare_again) *prepare_again = false;
@@ -1770,8 +1771,8 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
// (another runtime) reports its refusal instead.
const auto saved_revision = config_.settings_record
? config_.settings_record(GameOf(record)).value_or(rt::GameSettingsRecord{}).revision : 0;
- const bool upgrade_only = !force && record.moved_from.empty() && saved_revision <= record.settings_revision &&
- NeedsUnownedPublication(c, record);
+ const bool upgrade_only = !force && setup_program.empty() && record.setup_program.empty() && record.moved_from.empty() &&
+ saved_revision <= record.settings_revision && NeedsUnownedPublication(c, record);
// A game folder that isn't there (a stale record, an unplugged drive) can't be published, and
// arming the request first would leave a journal on the record: nothing is armed for it.
if (upgrade_only || !record.moved_from.empty()) {
@@ -1783,7 +1784,8 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
return {};
}
}
- auto refused = PublishSavedSettings(c, record, published, steam_account_known, prepare_again, code, force);
+ auto refused = PublishSavedSettings(c, record, published, steam_account_known, prepare_again, code, force, false,
+ setup_program);
if (refused.empty() || !upgrade_only) return refused;
Log("settings update app=" + std::to_string(record.runtime_number) + " unowned upgrade deferred, owned publication kept: " +
refused);
@@ -1798,7 +1800,7 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeInstall& record, bool* published,
bool steam_account_known, bool* prepare_again, std::string* code,
- bool force, bool defaults_published) {
+ bool force, bool defaults_published, const std::string& setup_program) {
if (code) code->clear();
// Refusals only a new preparation gets past (the title's recipe or settings can't be published again).
const auto again = [prepare_again](std::string message) {
@@ -1815,6 +1817,25 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
" title=" + std::to_string(record.settings_revision));
return {};
}
+ // Run a program once: the saved settings with that program and the Mouse controller preset (its rows as the preset
+ // sets them, so a recipe's or the player's controller choices don't hide the pointer) in their place. The title
+ // keeps that profile until the next publication without one puts the saved settings back (RuntimeInstall::
+ // setup_program), whatever their revision.
+ const bool restoring = setup_program.empty() && !record.setup_program.empty();
+ if (!setup_program.empty()) {
+ auto& overrides = saved.overrides;
+ std::erase_if(overrides, [](const auto& entry) {
+ static const std::set<std::string> program = {"program", "architecture", "program_folder", "program_arguments",
+ "start_check"};
+ return program.count(entry.first) || entry.first.rfind("button.", 0) == 0;
+ });
+ overrides["launch_option"] = rt::kProgramEntryId;
+ overrides["program"] = setup_program;
+ overrides["controller_preset"] = "mouse";
+ for (const auto& [id, value] : rt::ControllerPresetInputs().at("mouse")) overrides[id] = value;
+ for (const char* id : {"launch_option", "program", "controller_preset", "controller", "pointer_stick", "pointer_speed"})
+ overrides[std::string(rt::kUnlockPrefix) + id] = "on";
+ }
// A game whose folder moved (RuntimeInstall::moved_from) is published again at its revision, so
// its descriptor, profile and dxvk.conf name the new folder.
const bool moved = !record.moved_from.empty();
@@ -1822,7 +1843,8 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
const bool unowned_upgrade = !moved && NeedsUnownedPublication(c, record);
if (unowned_upgrade) Log("settings update app=" + std::to_string(record.runtime_number) + " publishes the game folder unowned");
// "Steam features" only swaps the game's own files, so it follows the saved value at once.
- if (!force && saved.revision <= record.settings_revision && !moved && !unowned_upgrade)
+ if (!force && setup_program.empty() && !restoring && saved.revision <= record.settings_revision && !moved &&
+ !unowned_upgrade)
return ApplyPreparationSteps(c, record, steam_account_known);
if (!c.kit) return "No verified runtime kit is installed.";
if (saved.revision < record.settings_revision)
@@ -1928,7 +1950,8 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
return again("The settings no longer match this game's PS5 title; prepare it again.");
// A forced publication runs only when the new runtime changes what the settings write (120 Hz output), so a
// respin that changes nothing there keeps its publication, registration and bottle as they are.
- if (force) {
+ // So is a program's run, or the return from one, that publishes what the title already has.
+ if (force || !setup_program.empty() || restoring) {
// POSIX reads, as elsewhere here: the PS5 libc++ has no locale support for file streams.
const auto read = [](const std::filesystem::path& path) {
std::string bytes;
@@ -1944,8 +1967,13 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
const auto config = HostPath(record.install_path) / WorkingFolder(next.launch_working_directory, next.launch_path,
next.launch_in_install_root) /
"dxvk.conf";
- if (read(profile) == plan.profile_bytes && read(config) == plan.dxvk_config) return {};
+ if (read(profile) == plan.profile_bytes && read(config) == plan.dxvk_config)
+ return restoring ? MarkSetupProgram(c, record.install_id, {}) : std::string{};
}
+ // Recorded before the program's profile is published, so a publication cut off part way still gets the saved
+ // settings back.
+ if (!setup_program.empty())
+ if (const auto marked = MarkSetupProgram(c, record.install_id, setup_program); !marked.empty()) return marked;
const auto transaction = config_.uuid();
if (!transaction) return "No secure random source for the settings update.";
rt::SettingsPublicationRequest request;
@@ -1985,9 +2013,22 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
if (published) *published = true;
if (const auto current = c.records.Find(record.install_id)) OpenGameFolders(c, *current);
if (moved) FinishGamesMove(c);
+ if (restoring) return MarkSetupProgram(c, record.install_id, {});
return {};
}
+std::string RuntimeHost::MarkSetupProgram(Composition& c, const std::string& install_id, const std::string& program) {
+ auto record = c.records.Find(install_id);
+ if (!record) return "The game's install record is missing.";
+ if (record->setup_program == program) return {};
+ Log("setup program app=" + std::to_string(record->runtime_number) + " " +
+ (program.empty() ? "done: " + record->setup_program : "runs once: " + program));
+ record->setup_program = program;
+ const auto written = c.repository.Update(*record);
+ PublishInstalls(c, install_id);
+ return written.ok() ? std::string{} : "The program's run could not be recorded: " + written.message();
+}
+
bool RuntimeHost::MoveGames(Composition& c, std::string* error) {
auto move = config_.moved_games_root ? config_.moved_games_root() : std::nullopt;
auto journal = rt::LoadLayoutJournal(config_.state_root);
@@ -2336,7 +2377,7 @@ void RuntimeHost::PublishLaunch(Composition& c, const rt::LaunchSnapshot& launch
});
}
-void RuntimeHost::RunPlay(Composition& c, std::uint32_t app_id) {
+void RuntimeHost::RunPlay(Composition& c, std::uint32_t app_id, const std::string& setup_program) {
// The player waits on this Play: Microsoft's MFC may be downloaded for it, with a progress line.
RedistWorkScope redist(redist_work_, true, app_id);
std::optional<rt::RuntimeInstall> record;
@@ -2371,7 +2412,19 @@ void RuntimeHost::RunPlay(Composition& c, std::uint32_t app_id) {
c.coordinator->Activity(record->title_id) == rt::NativeActivity::kStopped;
}
std::string settings;
- if (!record->moved_from.empty()) {
+ if (!setup_program.empty()) {
+ // Another program for one run: its profile is published now, so nothing of the game may be running.
+ if (!idle) {
+ auto busy = MaintenanceRefusal(c, *record);
+ settings = busy.empty() ? std::string("Close the game first.") : std::move(busy);
+ } else if (!record->moved_from.empty()) {
+ settings = "This game needs an update for Playden 0.6 first: press Play once.";
+ } else {
+ settings = RepublishSettings(c, *record, nullptr, true, nullptr, nullptr, nullptr, false, setup_program);
+ }
+ Log("play setup program app=" + std::to_string(app_id) + " program=" + setup_program + " " +
+ (settings.empty() ? "published" : settings));
+ } else if (!record->moved_from.empty()) {
// Its folder moved in 0.6: the title starts only once its publication names the new one.
if (!idle) {
auto busy = MaintenanceRefusal(c, *record);
@@ -4454,8 +4507,10 @@ bool RuntimeHost::RunServices() {
if (c.kit)
for (const auto& record : c.repository.Snapshot()) {
// Only newer settings: the Steam account is not known yet, so Steam files wait for Play.
+ // So are they after a program's run (RuntimeInstall::setup_program), whatever their revision.
const auto saved = config_.settings_record ? config_.settings_record(GameOf(record)) : std::nullopt;
- if (!saved || saved->revision <= record.settings_revision || !record.moved_from.empty() ||
+ const bool newer = saved && saved->revision > record.settings_revision;
+ if ((!newer && record.setup_program.empty()) || !record.moved_from.empty() ||
!MaintenanceRefusal(c, record).empty()) continue;
bool published = false;
const auto refused = RepublishSettings(c, record, &published, false);
@@ -4490,7 +4545,7 @@ bool RuntimeHost::RunServices() {
startup_hold.reset();
bool reload = false;
for (;;) {
- std::vector<std::uint32_t> plays;
+ std::vector<PlayRequest> plays;
std::vector<RemovalRequest> removals;
std::vector<std::uint32_t> kept_deletes;
std::vector<std::pair<std::uint32_t, RuntimeMaintenance>> maintenance;
@@ -4601,9 +4656,10 @@ bool RuntimeHost::RunServices() {
Log("leftover requests cleanup kept=" + std::to_string(kept) + " remaining=" + std::to_string(left));
Publish([&](RuntimeSnapshot& s) { s.leftover_requests = left; });
}
- for (const auto app : plays) {
+ for (const auto& play : plays) {
+ const auto app = play.app;
if (composition) {
- RunPlay(*composition, app);
+ RunPlay(*composition, app, play.setup_program);
poll = true;
} else {
Publish([&](RuntimeSnapshot& s) {
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index eac5e3c..e010deb 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -464,8 +464,10 @@ class RuntimeHost {
// The names each game's PS5 title should carry. A Ready title whose installed
// name differs reports an update, and Prepare applies the new name.
void SetTitleNames(std::map<std::uint32_t, std::string> names);
- // Queues Play of a Ready game.
- void Play(std::uint32_t runtime_number);
+ // Queues Play of a Ready game. With setup_program (a program in the game folder, relative to it), the title starts
+ // that program once instead, with the Mouse controller preset, and the game's saved settings come back with the
+ // next publication: the next Play, or the next start of Playden (RuntimeInstall::setup_program).
+ void Play(std::uint32_t runtime_number, std::string setup_program = {});
// A game's files changed outside the runtime (an update finished): the installs are checked again, so
// RuntimeInstallView::files_changed follows.
void RecheckInstalls();
@@ -548,16 +550,22 @@ class RuntimeHost {
// With force, the settings are published again even when the title already has their revision:
// after Update moved the title to another runtime, which may take different profile keys (120 Hz
// output). Nothing is published when they write the same profile and dxvk.conf as before.
+ // With setup_program, the saved settings are published with that program and the Mouse controller preset in
+ // their place, for one run (Play). A title that publishes such a run gets its saved settings back from the next
+ // call without it, whatever their revision.
std::string RepublishSettings(Composition& composition, const runtime::RuntimeInstall& record,
bool* published = nullptr, bool steam_account_known = true,
bool* prepare_again = nullptr, std::string* upgrade_deferred = nullptr,
- std::string* code = nullptr, bool force = false);
+ std::string* code = nullptr, bool force = false, const std::string& setup_program = {});
// RepublishSettings without the upgrade's fallback.
// `defaults_published`: with force, a game with no saved settings whose title has revision 0 was
// published from Playden's defaults, so they are published again.
std::string PublishSavedSettings(Composition& composition, const runtime::RuntimeInstall& record,
bool* published, bool steam_account_known, bool* prepare_again,
- std::string* code = nullptr, bool force = false, bool defaults_published = false);
+ std::string* code = nullptr, bool force = false, bool defaults_published = false,
+ const std::string& setup_program = {});
+ // Records the program the title's profile starts once (RuntimeInstall::setup_program); empty: none.
+ std::string MarkSetupProgram(Composition& composition, const std::string& install_id, const std::string& program);
// Whether an update left its marker in the Ready game's folder (installs::kFilesChangedName).
bool FilesChanged(const runtime::RuntimeInstall& record) const;
// The Ready-path part of Prepare for a game whose files changed: its generated recipe is made again
@@ -647,7 +655,7 @@ class RuntimeHost {
void HealBottle(Composition& composition, const std::string& data_root, const std::string& title_id);
runtime::LaunchEvidence Evidence(Composition& composition, const runtime::RuntimeInstall& record,
const std::string& session_id);
- void RunPlay(Composition& composition, std::uint32_t runtime_number);
+ void RunPlay(Composition& composition, std::uint32_t runtime_number, const std::string& setup_program = {});
// Removes a game's PS5 title; empty when it has none left, otherwise why not.
// moving: the title goes because its game was installed again elsewhere (journal "remove-move"),
// so Prepare, not Uninstall, finishes a removal that stopped part way.
@@ -736,7 +744,11 @@ class RuntimeHost {
mutable std::shared_ptr<const RuntimeSnapshot> shared_; // Shared()'s copy of snapshot_ at shared_revision_
mutable std::uint64_t shared_revision_ = 0;
std::vector<RuntimePrepareRequest> prepare_requests_;
- std::vector<std::uint32_t> play_requests_;
+ struct PlayRequest {
+ std::uint32_t app = 0;
+ std::string setup_program; // Play(…, setup_program)
+ };
+ std::vector<PlayRequest> play_requests_;
struct RemovalRequest {
std::uint32_t app = 0;
bool delete_saves = false;
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index f54d5b6..3562606 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -521,7 +521,7 @@ std::string action_label(const std::string& key) {
{"install-confirm", "Install"}, {"install-version", "Version"}, {"install-language", "Language"}, {"install-dlc", "Includes"}, {"update-confirm", "Download and install"}, {"storage-picker", "Change storage"},
{"value-edit", "Edit…"}, {"value-reset", "Reset to recipe"}, {"override-add", "Add an override…"},
{"unlock-setting", "Change anyway"}, {"export-recipe", "Export as recipe"}, {"program-scan", "Looking for programs…"},
- {"preset-picker", "Preset"}, {"game-settings", "Game settings"}, {"game-maintenance", "Maintenance"}, {"game-move", "Move to…"}, {"runtime-check-again", "Check again"}, {"reset-settings", "Reset all to preset"}, {"clear-shader-cache", "Clear shader cache"},
+ {"preset-picker", "Preset"}, {"game-settings", "Game settings"}, {"game-maintenance", "Maintenance"}, {"run-once", "Run a program once…"}, {"run-once-start", "Run once"}, {"game-move", "Move to…"}, {"runtime-check-again", "Check again"}, {"reset-settings", "Reset all to preset"}, {"clear-shader-cache", "Clear shader cache"},
{"section-compatibility", "Compatibility"}, {"section-advanced", "Advanced"}, {"heading-game", "Game"},
{"heading-display", "Display"}, {"heading-controls", "Controls"}, {"heading-sound", "Sound"},
{"heading-graphics", "Graphics"}, {"heading-windows", "Windows"},
@@ -2310,6 +2310,12 @@ std::vector<GameId> Simulation::TakeRuntimePlayRequests() {
return requests;
}
+std::map<GameId, std::string> Simulation::TakeRuntimeSetupPrograms() {
+ auto programs = std::move(pending_runtime_setup_programs_);
+ pending_runtime_setup_programs_.clear();
+ return programs;
+}
+
bool Simulation::TakeRuntimeCleanupRequest() {
const bool requested = pending_runtime_cleanup_;
pending_runtime_cleanup_ = false;
@@ -5338,6 +5344,9 @@ void Simulation::rebuild_view() {
&base, &ignored))
inherited = base.values.at(modal.setting_id);
}
+ if (modal.id == "setup-programs")
+ view_.subtitle = "Pick a program from the game folder, such as its settings launcher. It runs one time with the "
+ "Mouse preset; Play and Game settings stay as they are.";
if (modal.id == "game-settings" || modal.id == "game-maintenance") {
if (const auto* game = find_game(state_, settings_game)) view_.subtitle = game->title;
} else if (!modal.setting_id.empty()) {
@@ -6092,6 +6101,30 @@ void Simulation::rebuild_view() {
record->second.revision > runtime_game->second.settings_revision)
item.subtitle = "Changes apply on next launch";
}
+ } else if (action_key == "run-once") {
+ item.subtitle = "Starts a program from the game folder, such as its settings launcher, one time. Play doesn't change.";
+ std::string refusal;
+ if (live() && !game_closed(state_.navigation.selected_game_id, &refusal)) {
+ item.enabled = false;
+ item.subtitle = refusal;
+ }
+ } else if (modal.id == "setup-programs" && action_key.rfind("setup-program-", 0) == 0) {
+ item.kind = RowKind::Choice;
+ const auto setup = game_setups_.find(state_.navigation.selected_game_id);
+ const auto index = static_cast<std::size_t>(std::stoul(action_key.substr(14)));
+ if (setup != game_setups_.end() && index < setup->second.programs.size()) {
+ const auto& program = setup->second.programs[index];
+ item.title = program.path;
+ const auto detected = rt::DetectedLabel(program.detected);
+ item.subtitle = program.architecture.empty() ? "Not a Windows program the PS5 can start."
+ : !program.refusal.empty() ? program.refusal
+ : (program.architecture == "pe64" ? "64-bit" : "32-bit") + (detected.empty() ? std::string() : " · " + detected);
+ item.enabled = !program.architecture.empty() && program.refusal.empty();
+ rt::EffectiveSettings values;
+ if (EffectiveSettingsFor(state_.navigation.selected_game_id, &values) && values.launch &&
+ BottlePath(values.launch->executable) == BottlePath(program.path))
+ item.value = "The game's program";
+ }
} else if (action_key == "game-maintenance") {
if (live())
if (const auto runtime_game = state_.runtime_games.find(state_.navigation.selected_game_id);
@@ -8788,6 +8821,7 @@ void Simulation::activate() {
if (auto previous = state_.runtime_games.find(id); previous != state_.runtime_games.end())
previous->second.play_detail.clear();
pending_runtime_play_requests_.push_back(id);
+ pending_runtime_setup_programs_.erase(id);
}
} else if (action_name == "details-update") {
const auto id = state_.navigation.detail_id.value_or(state_.navigation.selected_game_id);
@@ -9360,6 +9394,38 @@ void Simulation::activate() {
}
// From Game actions it opens on top of that sheet, so Circle returns there.
open_modal({"game-maintenance", "Maintenance", state_.navigation.focus_key, maintenance_actions(), 0, false});
+ } else if (action_name == "run-once") {
+ // Whether the game runs, for the rows; the confirmation checks it again.
+ pending_activity_requests_.push_back(state_.navigation.selected_game_id);
+ open_setup_programs();
+ } else if (action_name.rfind("setup-program-", 0) == 0) {
+ const auto setup = game_setups_.find(state_.navigation.selected_game_id);
+ const auto index = static_cast<std::size_t>(std::stoul(action_name.substr(14)));
+ if (setup == game_setups_.end() || index >= setup->second.programs.size()) return;
+ setup_program_choice_ = setup->second.programs[index].path;
+ const auto slash = setup_program_choice_.find_last_of('/');
+ const auto name = slash == std::string::npos ? setup_program_choice_ : setup_program_choice_.substr(slash + 1);
+ ModalEntry confirm{"confirmation", "Run " + name + " once?", state_.navigation.focus_key, {"cancel", "run-once-start"}, 1, false};
+ confirm.body = "Playden starts " + setup_program_choice_ + " instead of the game, one time. It runs until you close it.\n\n"
+ "Controls use the Mouse preset for this run: the left stick moves the pointer, Cross clicks, Circle "
+ "right-clicks and Options presses Enter.\n\n"
+ "If the program has its own Play button, it may not start the game on the PS5. Change your settings in "
+ "it, close it, then press Play in Playden. Play and Game settings stay as they are.";
+ open_modal(std::move(confirm));
+ } else if (live() && action_name == "run-once-start") {
+ const auto id = state_.navigation.selected_game_id;
+ std::string refusal;
+ if (setup_program_choice_.empty() || !game_closed(id, &refusal)) {
+ if (!refusal.empty()) push_notice({"run-once-" + ToKey(id), "The program can't run now", "", false, kLiveNoticeSeconds, false, refusal});
+ return;
+ }
+ // Back to the game's page, where Play shows the start as it does the game's.
+ while (!state_.navigation.modals.empty()) close_modal();
+ if (auto previous = state_.runtime_games.find(id); previous != state_.runtime_games.end())
+ previous->second.play_detail.clear();
+ pending_runtime_play_requests_.push_back(id);
+ pending_runtime_setup_programs_[id] = setup_program_choice_;
+ state_.navigation.focus_key = "details-play";
} else if (action_name == "game-move") {
const auto game = state_.navigation.selected_game_id;
if (move_blocker(game, {}).empty() && move_volumes().size() >= 2) open_move_picker(game);
@@ -10492,6 +10558,10 @@ void Simulation::SetGameSetups(std::map<GameId, LiveGameSetup> setups) {
close_modal();
open_setting("launch_option");
}
+ if (!state_.navigation.modals.empty() && state_.navigation.modals.back().id == "setup-programs") {
+ close_modal();
+ open_setup_programs();
+ }
rebuild_view();
}
@@ -10647,9 +10717,30 @@ std::vector<std::string> Simulation::details_context_actions() const {
const auto maintenance = std::find(actions.begin(), actions.end(), "game-maintenance");
actions.insert(maintenance == actions.end() ? actions.begin() : maintenance + 1, "manage-saves");
}
+ // A program from the game folder (its settings launcher) for one run, after Maintenance.
+ if (live() && game_prepared(selected)) {
+ const auto maintenance = std::find(actions.begin(), actions.end(), "game-maintenance");
+ actions.insert(maintenance == actions.end() ? actions.begin() : maintenance + 1, "run-once");
+ }
return actions;
}
+void Simulation::open_setup_programs() {
+ const auto id = state_.navigation.selected_game_id;
+ const auto setup = game_setups_.find(id);
+ std::vector<std::string> actions;
+ if (setup != game_setups_.end())
+ for (std::size_t index = 0; index < setup->second.programs.size(); ++index)
+ actions.push_back("setup-program-" + std::to_string(index));
+ // Every opening scans again, as the Program picker does; the last list shows meanwhile.
+ if (live()) {
+ if (requested_program_scans_.insert(id).second) pending_program_scans_.push_back(id);
+ if (setup == game_setups_.end() || !setup->second.scanned) actions.push_back("program-scan");
+ }
+ actions.push_back("cancel");
+ open_modal({"setup-programs", "Run a program once", state_.navigation.focus_key, std::move(actions), 0, false});
+}
+
std::vector<std::string> Simulation::maintenance_actions() const {
std::vector<std::string> actions{"maintenance-reset", "maintenance-update", "maintenance-repair", "maintenance-shader",
"maintenance-backup", "maintenance-recreate", "cancel"};
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index a88ce76..6de9ea7 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -932,6 +932,9 @@ public:
// Queues Prepare without a button press: after a download, or before Play.
void RequestRuntimePrepare(GameId id);
[[nodiscard]] std::vector<GameId> TakeRuntimePlayRequests();
+ // The Play requests above that run a program from the game folder once instead of the game (Run a program
+ // once…): the program, relative to the game folder. A plain Play request of the same game replaces its entry.
+ [[nodiscard]] std::map<GameId, std::string> TakeRuntimeSetupPrograms();
[[nodiscard]] bool TakeRuntimeCleanupRequest();
// Live mode: kept game data, deletions the player confirmed, and why an uninstall stopped.
void UpdateKeptBottles(std::vector<LiveKeptBottle> kept);
@@ -1181,6 +1184,8 @@ private:
std::vector<LiveCompletedPreparation> prepared_dismissed_;
std::optional<GameId> prepare_next_asked_;
std::vector<GameId> pending_runtime_play_requests_;
+ std::map<GameId, std::string> pending_runtime_setup_programs_;
+ std::string setup_program_choice_; // Run a program once: the program the confirmation names
bool pending_runtime_cleanup_ = false;
bool library_catalog_received_ = false;
std::set<Store> catalog_sources_; // stores whose library arrived at least once
@@ -1405,6 +1410,8 @@ private:
// A game whose setup waits for its program (LiveGameSetup::steam_choices): the sheet that asks,
// installers and tools last, and the choice, which sets the game up again.
void open_steam_programs(GameId id);
+ // Run a program once…: the game folder's programs, then a confirmation.
+ void open_setup_programs();
void choose_steam_launch(GameId id, const std::string& program);
std::vector<LaunchProgram> steam_programs_shown_;
std::set<GameId> steam_programs_asked_; // games whose waiting setup asked once already
diff --git a/src/runtime/game_install.cpp b/src/runtime/game_install.cpp
index 979ee86..68d8939 100644
--- a/src/runtime/game_install.cpp
+++ b/src/runtime/game_install.cpp
@@ -205,6 +205,7 @@ bool ValidRecord(const RuntimeInstall& record) {
!IsSimpleId(record.journal->step))) return false;
if (!record.moved_from.empty() &&
(!IsAbsoluteNormalizedPath(record.moved_from) || record.moved_from == record.install_path)) return false;
+ if (!record.setup_program.empty() && !IsRelativeLaunchPath(record.setup_program)) return false;
return true;
}
@@ -295,6 +296,10 @@ std::optional<RuntimeInstall> ParseRecord(const JsonValue& value, RepositoryErro
if (!moved->is_string() || moved->text().empty()) return std::nullopt;
record.moved_from = moved->text();
}
+ if (const auto* setup = value.Find("setup_program")) {
+ if (!setup->is_string() || setup->text().empty()) return std::nullopt;
+ record.setup_program = setup->text();
+ }
if (!ValidRecord(record)) return std::nullopt;
return record;
}
@@ -335,6 +340,7 @@ void WriteRecord(TextOutput& output, const RuntimeInstall& record) {
StringField(output, "step", record.journal->step, false); output << '}'; }
else output << "null";
if (!record.moved_from.empty()) { output << ','; StringField(output, "moved_from", record.moved_from, false); }
+ if (!record.setup_program.empty()) { output << ','; StringField(output, "setup_program", record.setup_program, false); }
output << '}';
}
diff --git a/src/runtime/game_install.h b/src/runtime/game_install.h
index 8f45240..d891e2e 100644
--- a/src/runtime/game_install.h
+++ b/src/runtime/game_install.h
@@ -89,6 +89,10 @@ struct RuntimeInstall {
// republication against install_path; a committed publication clears it. Stored only
// when set, so older readers (which ignore unknown keys) are unaffected.
std::string moved_from;
+ // A program from the game folder that the title's published profile starts once in place of the game, with the
+ // Mouse controller preset (Run a program once), relative to the install root. The next publication puts the
+ // saved settings back and clears it, whatever their revision. Stored only when set.
+ std::string setup_program;
};
// The title range reserved for Playden games; excludes the launcher itself.
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index c953c68..1f1f76c 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -662,6 +662,83 @@ void live_program_change_applies_like_other_settings(const std::filesystem::path
"program: the reset applies the same way");
}
+// Run a program once… (Game actions): a program from the game folder, its settings launcher, starts once through
+// Play's own request, which carries the program; Game settings and the next Play stay the game's.
+void live_runs_setup_program_once(const std::filesystem::path& base) {
+ using playden::homebrew::GameId;
+ using playden::homebrew::TitleActivity;
+ std::filesystem::create_directories(base);
+ auto model = make_live(base);
+ model.SetGameSettingsFile(base / "setup-program-settings.json");
+ model.SetSettingsData({{"playden-default", "Playden default", "Most games", "", {}}}, {});
+ model.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ playden::GameSummary game;
+ game.id = SteamId(35140);
+ game.title = "Batman: Arkham Asylum GOTY Edition";
+ check(model.UpdateLibrary({{game}, false, {}, false, true, 100}), "setup program: library delivered");
+ model.UpdateInstalls({}, {{SteamId(35140), 1024, "internal", true}});
+ playden::runtime::GameRecipe recipe;
+ recipe.id = playden::runtime::GeneratedRecipeId(35140);
+ recipe.version = 2;
+ recipe.app_id = 35140;
+ recipe.name = game.title;
+ recipe.launch_entries = {{"launch-1", "Play", "Binaries/ShippingPC-BmGame.exe", "", ""}};
+ model.SetGeneratedRecipes({recipe});
+ std::map<GameId, playden::homebrew::LiveGameSetup> setups;
+ setups[SteamId(35140)].scanned = true;
+ setups[SteamId(35140)].programs = {{"Binaries/BmLauncher.exe", "pe32", "", false, ""},
+ {"Binaries/ShippingPC-BmGame.exe", "pe32", "", false, ""},
+ {"Binaries/UE3ShaderCompileWorker.exe", "pe32", "Uses a missing DLL.", false, ""}};
+ model.SetGameSetups(setups);
+ playden::homebrew::LiveRuntimeGame runtime;
+ runtime.game_id = SteamId(35140);
+ runtime.status = "Ready";
+ runtime.ready = runtime.prepared = runtime.has_title = runtime.can_play = true;
+ runtime.launch_entry_id = "launch-1";
+ runtime.activity = TitleActivity::Running;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ check(model.action("details:35140"), "setup program: open details");
+
+ // Not while the game runs.
+ activate(model, "details-more");
+ check(find_row(model, "run-once") && !find_row(model, "run-once")->enabled, "setup program: waits while the game runs");
+ model.action("circle");
+ runtime.activity = TitleActivity::Stopped;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+
+ // The folder's programs: the game's own is named, one the console can't start is not offered.
+ activate(model, "details-more");
+ check(find_row(model, "run-once")->enabled && find_row(model, "run-once")->title == "Run a program once…",
+ "setup program: Game actions offers it");
+ activate(model, "run-once");
+ check(model.state().navigation.modals.back().id == "setup-programs", "setup program: the picker opens");
+ check(find_row(model, "setup-program-0")->enabled && find_row(model, "setup-program-1")->value == "The game's program" &&
+ !find_row(model, "setup-program-2")->enabled,
+ "setup program: the picker names the game's program and refuses what can't start");
+ (void)model.TakeProgramScanRequests();
+ activate(model, "setup-program-0");
+ check(model.state().navigation.modals.back().title == "Run BmLauncher.exe once?" &&
+ model.state().navigation.modals.back().body.find("Mouse preset") != std::string::npos,
+ "setup program: the confirmation names the program and the Mouse preset");
+ check(model.TakeRuntimePlayRequests().empty(), "setup program: nothing starts before the confirmation");
+ activate(model, "run-once-start");
+ check(model.state().navigation.modals.empty() &&
+ model.TakeRuntimePlayRequests() == std::vector<playden::GameId>{SteamId(35140)},
+ "setup program: Run once asks for Play");
+ check(model.TakeRuntimeSetupPrograms() == std::map<GameId, std::string>{{SteamId(35140), "Binaries/BmLauncher.exe"}},
+ "setup program: the Play request carries the program");
+ check(!model.state().game_settings.count(SteamId(35140)), "setup program: Game settings stay as they were");
+
+ // A plain Play after a run that never reached the runtime starts the game.
+ activate(model, "details-more");
+ activate(model, "run-once");
+ activate(model, "setup-program-0");
+ activate(model, "run-once-start");
+ activate(model, "details-play");
+ check(model.TakeRuntimePlayRequests().size() == 2 && model.TakeRuntimeSetupPrograms().empty(),
+ "setup program: Play replaces the program's run");
+}
+
void live_download_telemetry() {
using namespace playden::homebrew;
Simulation model({}, {}, ModelMode::Live);
@@ -2022,6 +2099,7 @@ int main() {
live_refresh_rate_keeps_off_over_a_preset_cap(base / "capped");
live_update_runtime_from_maintenance(base / "update-runtime");
live_program_change_applies_like_other_settings(base);
+ live_runs_setup_program_once(base);
live_imported_game_steam_app_id(base);
live_imported_program_seeds_once(base);
live_setup_asks_for_a_steam_program(base);
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index 2d75d01..0c86c15 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -1681,6 +1681,121 @@ void UpdatedFilesSetUpTheLaunchAgain() {
host.Shutdown();
}
+// Run a program once: Play with a program from the game folder publishes it, with the Mouse preset, for one start. The
+// game's own settings come back with the next publication: the next start of Playden, or the next Play.
+void RunsSetupProgramOnce() {
+ Fixture fixture;
+ auto config = fixture.Config();
+ config.host_namespace_prefix = fixture.root;
+ config.session_data_root = fixture.root / "data";
+ config.package_paths.console_data_root = "/data";
+ config.package_paths.host_data_root = fixture.root / "data";
+ config.package_operations.hash_file = HashArtifactFile;
+ config.package_operations.hash_bytes = HashArtifactBytes;
+ config.package_operations.free_space_unverifiable = true;
+ config.package_operations.validate_bottle = [](const fs::path& bottle) {
+ return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
+ };
+ const auto kit = SyntheticKit(fixture.root / "kit");
+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
+ unsigned uuids = 0;
+ config.uuid = [&uuids]() -> std::optional<std::string> {
+ char id[37];
+ std::snprintf(id, sizeof(id), "00000000-0000-4000-8000-%012u", ++uuids);
+ return std::string(id);
+ };
+ config.unix_time = [] { return std::int64_t{1760000000}; };
+ std::vector<std::vector<std::string>> launches;
+ config.launch_title = [&launches](const std::string&, const std::vector<std::string>& arguments) {
+ launches.push_back(arguments);
+ return TitleResult{true, 0, "launch"};
+ };
+ GameSettingsRecord saved;
+ saved.overrides = {{"controller_preset", "gamepad"}, {"button.cross", "key:space"}};
+ config.settings_record = [&](const playden::GameId&) -> std::optional<GameSettingsRecord> { return saved; };
+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/4300";
+ std::string pe(0x80 + 26, '\0');
+ pe[0] = 'M'; pe[1] = 'Z'; pe[0x3c] = 0x40; pe[0x40] = 'P'; pe[0x41] = 'E';
+ pe[0x44] = 0x4c; pe[0x45] = 0x01; pe[0x40 + 24] = 0x0b; pe[0x40 + 25] = 0x01;
+ Write(game / "Binaries/Game.exe", pe, 0644);
+ Write(game / "Binaries/Launcher.exe", pe, 0644);
+ RuntimePrepareRequest request{4300, "/data/homebrew/FAKE77031/games/4300", "internal", "Setup Game"};
+ request.launches = {{"", "", "Binaries\\Game.exe", "", ""}};
+ const auto profile = fixture.root / "data/playden/games/steam-4300/library/profiles/playden-steam-4300.profile";
+ const auto installs = config.state_root / "installs.json";
+ const auto sessions = fixture.root / "data/playden/games/steam-4300/logs/sessions";
+ // The program quits: its session record says so, as the title shell writes it.
+ const auto exited = [&](const std::string& argument) {
+ const auto id = argument.substr(argument.find('=') + 1);
+ fs::create_directories(sessions);
+ CHECK(chmod(sessions.parent_path().c_str(), 0700) == 0 && chmod(sessions.c_str(), 0700) == 0);
+ Write(sessions / (id + ".json"),
+ R"({"schema_version":1,"session_id":")" + id + R"(","install_id":"steam-4300","title_id":"FAKE78001",)"
+ R"("origin":"playden","settings_revision":0,"runtime_bundle_id":"wine-wow64","phase":"exited"})" "\n", 0600);
+ };
+ const auto ended = [](const RuntimeSnapshot& s) { return s.launch && s.launch->state == LaunchState::kExited; };
+ const auto handed_off = [&](RuntimeHost& host) {
+ CHECK(WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready; }, 30).handoff_ready);
+ CHECK(host.Handoff());
+ };
+ const auto game_published = [&] {
+ const auto text = Read(profile);
+ return text.find("\\Binaries\\Game.exe\n") != std::string::npos && text.find("preset = gamepad") != std::string::npos &&
+ Read(installs).find("setup_program") == std::string::npos;
+ };
+ {
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(request);
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && (s.refusals.count(4300) || (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));
+ }, 60);
+ if (done.refusals.count(4300)) std::fprintf(stderr, "Prepare refused: %s\n", done.refusals.at(4300).c_str());
+ CHECK(!done.refusals.count(4300) && game_published());
+ fixture.activity->store(static_cast<int>(NativeActivity::kStopped));
+ // The launcher starts with the Mouse preset; the player's buttons and the game's program don't come along.
+ host.Play(4300, "Binaries/Launcher.exe");
+ handed_off(host);
+ const auto text = Read(profile);
+ CHECK(text.find("\\Binaries\\Launcher.exe\n") != std::string::npos && text.find("preset = mouse") != std::string::npos);
+ CHECK(text.find("space") == std::string::npos);
+ CHECK(Read(installs).find("\"setup_program\":\"Binaries/Launcher.exe\"") != std::string::npos);
+ CHECK(host.Snapshot().installs[0].launch_path == "Binaries/Launcher.exe");
+ CHECK(launches.size() == 1);
+ exited(launches[0][0]);
+ WaitFor(host, ended, 30);
+ // Starting the game ends Playden; it starts again once the program quit.
+ host.Shutdown();
+ }
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ const auto restored = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.installs.empty() && s.installs[0].launch_path == "Binaries/Game.exe";
+ }, 60);
+ CHECK(restored.installs[0].launch_path == "Binaries/Game.exe" && game_published());
+
+ // The program's run again, and this time the next Play puts the game back before it starts.
+ host.Play(4300, "Binaries/Launcher.exe");
+ handed_off(host);
+ CHECK(Read(profile).find("\\Binaries\\Launcher.exe\n") != std::string::npos && launches.size() == 2);
+ exited(launches[1][0]);
+ WaitFor(host, ended, 30);
+ host.Play(4300);
+ handed_off(host);
+ CHECK(game_published() && host.Snapshot().installs[0].launch_path == "Binaries/Game.exe");
+ exited(launches[2][0]);
+ WaitFor(host, ended, 30);
+
+ // A program that isn't there is refused, and the game's settings stay.
+ const auto handled = host.Snapshot().plays_handled;
+ host.Play(4300, "Binaries/Missing.exe");
+ const auto refused = WaitFor(host, [handled](const RuntimeSnapshot& s) { return s.plays_handled > handled; }, 30);
+ CHECK(refused.play_refusals.count(4300) && refused.play_refusals.at(4300).find("missing") != std::string::npos);
+ CHECK(game_published() && launches.size() == 3);
+ host.Shutdown();
+}
+
// Settings saved while the game is being prepared, after its profile was written, reach the title
// as soon as it is ready instead of waiting for the next Playden start.
void SettingsSavedDuringPrepareReachReadyTitle() {
@@ -5913,6 +6028,7 @@ int main(int argc, char** argv) {
ShippedRecipeWritesGameIni(false);
ShippedRecipeWritesGameIni(true);
GeneratedRecipeGetsShippedIni();
+ RunsSetupProgramOnce();
ShippedRecipeRequirementsFollowTheKit(false);
ShippedRecipeRequirementsFollowTheKit(true);
MigrationRewritesInstallPathsAndRepublishes();
diff --git a/tests/runtime_game_install_test.cpp b/tests/runtime_game_install_test.cpp
index b1a80ad..b3eea00 100644
--- a/tests/runtime_game_install_test.cpp
+++ b/tests/runtime_game_install_test.cpp
@@ -528,6 +528,19 @@ void MovedRecordsRewriteTogetherAndKeepTheirMark() {
CHECK(restarted.Update(cleared).ok());
RuntimeInstallRepository again(storage, "installs.json", Free);
CHECK(again.Load().ok() && again.Find("install-a")->moved_from.empty() && !again.Find("install-b")->moved_from.empty());
+
+ // A program's run (Run a program once) is kept the same way, only while set, and only as a path in the game folder.
+ auto setup = *again.Find("install-a"); setup.setup_program = "Binaries/BmLauncher.exe";
+ auto outside = setup; outside.setup_program = "../BmLauncher.exe";
+ CHECK(!again.Update(outside).ok());
+ CHECK(again.Update(setup).ok());
+ RuntimeInstallRepository reloaded(storage, "installs.json", Free);
+ CHECK(reloaded.Load().ok() && reloaded.Find("install-a")->setup_program == "Binaries/BmLauncher.exe" &&
+ reloaded.Find("install-b")->setup_program.empty());
+ setup.setup_program.clear();
+ CHECK(reloaded.Update(setup).ok());
+ const auto unset = storage.ReadDurable("installs.json", 1 << 20);
+ CHECK(unset.ok() && std::string(unset.value().begin(), unset.value().end()).find("setup_program") == std::string::npos);
}
std::string ReadText(const std::string& path) {