Play your Steam library's Windows games on a jailbroken PS5.
C++
Offer launcher mode after a launcher fails to start
Leonardo Lobato21a60952b4e2
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex 93f6172..9cba866 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -1406,6 +1406,11 @@ void Controller::TickRuntime() {case LaunchState::kIdle: break;}}+ // What this game's last run asked for and couldn't start, once its name is known.+ if (const auto hint = snapshot.launcher_hints.find(NumberIn(snapshot, id));+ hint != snapshot.launcher_hints.end() && !launcher_hints_told_.count(hint->first) &&+ model_.NotifyLauncherHint(id, hint->second))+ launcher_hints_told_.insert(hint->first);// What the latest Play went ahead without (Microsoft's MFC), unless something newer is said.if (const auto notice = snapshot.play_notices.find(NumberIn(snapshot, id));notice != snapshot.play_notices.end() && game.play_detail.empty())diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex cb801f8..33667d5 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -223,6 +223,7 @@ class Controller {// Save lifecycle around Play: games whose session just ended sync once their// folder is known; games syncing now cannot start.std::set<GameId> sync_after_session_;+ std::set<std::uint32_t> launcher_hints_told_; // each once per Playden startstd::set<GameId> cloud_busy_;// Play requested but not yet visible in the runtime's launch state.std::set<GameId> play_queued_;diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex 81fb012..2830379 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -4510,6 +4510,19 @@ bool RuntimeHost::RunServices() {Log("admission check title=" + record.title_id + " result=" + c.admission[record.install_id]);}PublishInstalls(c);+ // A title's last run ended before this start (a game's start closes Playden).+ {+ std::map<std::uint32_t, std::string> hints;+ for (const auto& record : c.repository.Snapshot()) {+ if (record.state != rt::PreparationState::kReady || record.install_path.empty()) continue;+ const auto program = rt::TakeRefusedGameProgram((HostPath(record.data_root) / "library/prefixes/game").string(),+ record.install_path, HostPath(record.install_path).string());+ if (program.empty()) continue;+ Log("launcher hint app=" + std::to_string(record.runtime_number) + " program=" + program);+ hints[record.runtime_number] = program;+ }+ if (!hints.empty()) Publish([&](RuntimeSnapshot& s) { s.launcher_hints = std::move(hints); });+ }if (config_.title_log)for (const auto& record : c.repository.Snapshot()) {const auto root = config_.host_namespace_prefix.empty()diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hppindex 95b4457..3aeca46 100644--- a/src/homebrew/runtime_host.hpp+++ b/src/homebrew/runtime_host.hpp@@ -363,6 +363,8 @@ struct RuntimeSnapshot {// What the latest Play from Playden went ahead without, per runtime number (Microsoft's MFC that could not be// downloaded): Play still starts the game, and the player sees why it may stop.std::map<std::uint32_t, std::string> play_notices;+ // Games whose last run couldn't start a program in their folder: a launcher, without launcher mode. Told once.+ std::map<std::uint32_t, std::string> launcher_hints;// The Steam app ID each game from another store was last prepared with, by runtime number. Steam// games are not listed: theirs is their own.std::map<std::uint32_t, SteamworksAppView> steamworks_apps;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex d0987e1..4f43ed4 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -514,7 +514,7 @@ 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"},{"collection", "Collections"}, {"note", "Compatibility and note"}, {"verify", "Verify files"},- {"uninstall", "Uninstall…"}, {"import-remove", "Remove from library…"}, {"uninstall-delete-saves", "Delete saves too"}, {"run-once-dont-show", "Don't show again"}, {"launcher-help-dont-show", "Don't show again"}, {"launcher-help-on", "Turn on"}, {"logs", "Open logs"}, {"logs-back", "Back"},+ {"uninstall", "Uninstall…"}, {"import-remove", "Remove from library…"}, {"uninstall-delete-saves", "Delete saves too"}, {"run-once-dont-show", "Don't show again"}, {"launcher-help-dont-show", "Don't show again"}, {"launcher-help-on", "Turn on"}, {"launcher-hint-later", "Not now"}, {"launcher-hint-on", "Turn on and play"}, {"logs", "Open logs"}, {"logs-back", "Back"},{"logs-pick", "Logs"}, {"log-install", "Install log"}, {"log-auth", "Sign-in log"},{"log-launch", "Launch log"}, {"log-cloud", "Cloud saves log"}, {"logs-refresh", "Refresh"},{"cloud-sync", "Cloud saves"}, {"cloud-choose", "Cloud saves"}, {"cloud-use-cloud", "Use Cloud saves"},@@ -2762,6 +2762,32 @@ void Simulation::show_ready_prompt() {open_modal(std::move(prompt));}+bool Simulation::NotifyLauncherHint(GameId id, const std::string& program) {+ const auto* game = find_game(state_, id);+ // Until the game and the kit's abilities are known. A kit without launcher mode has nothing to offer.+ if (!game || !launcher_mode_kit()) return false;+ if (!live()) return true;+ const auto record = state_.game_settings.find(id);+ if (record != state_.game_settings.end()) {+ const auto on = record->second.overrides.find("start_through_launcher");+ if (on != record->second.overrides.end() && on->second == "on") return true;+ }+ // A recipe that requires it off has a reason, and the offer couldn't change it.+ rt::EffectiveSettings values;+ if (EffectiveSettingsFor(id, &values)) {+ const auto row = values.values.find("start_through_launcher");+ if (row != values.values.end() && row->second.locked && !row->second.unlocked) return true;+ }+ const auto slash = program.find_last_of('/');+ const auto name = slash == std::string::npos ? program : program.substr(slash + 1);+ alert_prompts_.push_back({"This game uses a launcher",+ game->title + " tried to start " + name + " and couldn't.\n\nTurn on Start through a launcher for this game?",+ id, true});+ show_alert_prompt();+ rebuild_view();+ return true;+}+void Simulation::show_alert(std::string title, std::string body, GameId settings_game) {const bool queued = std::any_of(alert_prompts_.begin(), alert_prompts_.end(), [&](const AlertPrompt& alert) {return alert.title == title && alert.body == body;@@ -2784,7 +2810,8 @@ void Simulation::show_alert_prompt() {alert_settings_game_ = alert.settings_game;std::vector<std::string> actions = {"alert-ok"};if (alert.settings_game.valid()) actions = {"alert-ok", "alert-settings"};- ModalEntry prompt{"confirmation", std::move(alert.title), state_.navigation.focus_key, std::move(actions), 0, false};+ if (alert.launcher_hint) actions = {"launcher-hint-later", "launcher-hint-on"};+ ModalEntry prompt{"confirmation", std::move(alert.title), state_.navigation.focus_key, std::move(actions), alert.launcher_hint ? 1 : 0, false};prompt.body = alert.body.empty() ? std::string(" ") : std::move(alert.body);open_modal(std::move(prompt));}@@ -9121,8 +9148,26 @@ void Simulation::activate() {wait.body = "Playden quits to the PS5 Home screen once this game's saves are in step with Steam Cloud.";open_modal(std::move(wait));}- } else if (action_name == "ready-later" || action_name == "alert-ok") {+ } else if (action_name == "ready-later" || action_name == "alert-ok" || action_name == "launcher-hint-later") {+ close_modal();+ } else if (action_name == "launcher-hint-on") {+ const auto game = alert_settings_game_;close_modal();+ if (game.valid() && find_game(state_, game)) {+ state_.navigation.selected_game_id = game;+ const auto had = state_.game_settings.find(game);+ const std::optional<rt::GameSettingsRecord> before = had == state_.game_settings.end() ? std::nullopt : std::make_optional(had->second);+ set_game_setting("start_through_launcher", "on");+ // Play reads the settings from disk: without them it would fail the same way.+ if (save_profile()) {+ pending_runtime_play_requests_.push_back(game);+ } else {+ // As it was, so the sheet doesn't say On and a later save doesn't turn it on unasked.+ if (before) state_.game_settings[game] = *before;+ else state_.game_settings.erase(game);+ show_alert("The setting could not be saved", "Start through a launcher is not on yet. Try again from Game settings.");+ }+ }} else if (action_name == "alert-settings") {const auto game = alert_settings_game_;close_modal();diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 335d175..e10f514 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -973,6 +973,9 @@ public:void NotifyUninstallFinished(GameId id);// Play prepared the game first and that ended without a playable title.void NotifyPlayStopped(GameId id, const std::string& reason);+ // The game's last run tried to start this program and couldn't: offers launcher mode.+ // False until the game is known, so the caller tells it again.+ bool NotifyLauncherHint(GameId id, const std::string& program);// A preparation the player started left the game waiting for the PS5: ask, when// nothing else is open, whether to quit to the PS5 Home screen to play it.void NotifyReadyToPlay(GameId id);@@ -1244,7 +1247,7 @@ private:std::map<GameId, StoreFacts> store_facts_; // live: from the Steam store, applied over library refreshesstd::vector<GameId> ready_prompts_; // games to announce as ready to play, oldest first// settings_game: a game whose refusal Game settings can get past; the dialog offers it.- struct AlertPrompt { std::string title; std::string body; GameId settings_game; };+ struct AlertPrompt { std::string title; std::string body; GameId settings_game; bool launcher_hint = false; };GameId alert_settings_game_; // the game the open failure dialog's "Game settings" opens// Games refused at Prepare whose program or "Try anyway" the player changed since: their page// no longer shows the old refusal.diff --git a/src/runtime/game_probe.cpp b/src/runtime/game_probe.cppindex a3f2ebb..f826c56 100644--- a/src/runtime/game_probe.cpp+++ b/src/runtime/game_probe.cpp@@ -6,6 +6,7 @@#include <array>#include <cerrno>#include <cstdint>+#include <cstdio>#include <cstring>#include <filesystem>#include <optional>@@ -433,6 +434,73 @@ bool ProgramDrawsWithOpenGLOnly(const std::string& install_root, const std::strireturn apis == std::set<std::string>{"opengl"};}+namespace {++// Whether a program itself looks like a game: what it imports or names, not the libraries beside it (a crash reporter+// sits next to the game's DLLs). A game may load its graphics at run time, so the names inside it count too.+bool ProgramLooksLikeGame(const fs::path& path, const PeFacts& facts) {+ std::set<std::string> apis;+ AddImports(facts, &apis);+ for (const auto& name : facts.delay_imports) {+ for (const auto& [library, api] : Libraries())+ if (name == library) apis.insert(api);+ if (name == "ddraw.dll") apis.insert("ddraw");+ }+ std::string engine;+ ScanNames(path.string(), &apis, &engine);+ if (!apis.empty() || !engine.empty()) return true;+ const auto has = [](const std::vector<std::string>& list, const char* name) {+ return std::find(list.begin(), list.end(), name) != list.end();+ };+ if (has(facts.imports, "unityplayer.dll") || has(facts.delay_imports, "unityplayer.dll")) return true;+ const auto stem = LowerStem(Lower(path.filename().string()));+ return stem == "java" || stem == "javaw" || EndsWith(stem, "-shipping");+}++} // namespace++std::string TakeRefusedGameProgram(const std::string& prefix_dir, const std::string& console_root,+ const std::string& host_root) {+ const auto note = fs::path(prefix_dir) / ".pw-exec-refused";+ std::error_code error;+ if (!fs::is_regular_file(fs::symlink_status(note, error))) return {};+ std::FILE* file = std::fopen(note.c_str(), "rb");+ if (!file) return {}; // stays, for a start that can read it+ char buffer[2048];+ std::string text(buffer, std::fread(buffer, 1, sizeof(buffer), file));+ const bool read_failed = std::ferror(file) != 0;+ std::fclose(file);+ if (read_failed) return {};+ // The program named, in the game's folder; empty for anything else.+ const auto named = [&]() -> std::string {+ static constexpr std::string_view kHeader = "pw-exec-refused 1\nimage=";+ if (text.rfind(kHeader, 0) != 0 || text.back() != '\n') return {};+ auto image = text.substr(kHeader.size(), text.size() - kHeader.size() - 1);+ if (image.find('\n') != std::string::npos || image.size() < 3 || Lower(image.substr(0, 3)) != "z:\\") return {};+ std::replace(image.begin(), image.end(), '\\', '/');+ image.erase(0, 2); // Z:+ auto root = console_root;+ while (!root.empty() && root.back() == '/') root.pop_back();+ if (root.empty() || image.size() <= root.size() + 1 || image[root.size()] != '/' ||+ Lower(image.substr(0, root.size())) != Lower(root))+ return {};+ auto relative = image.substr(root.size() + 1);+ if (relative.empty() || relative.front() == '/' || relative.find("..") != std::string::npos) return {};+ if (!fs::is_regular_file(fs::symlink_status(fs::path(host_root) / relative, error))) return {};+ return relative;+ }();+ std::string program;+ if (!named.empty()) {+ const auto path = fs::path(host_root) / named;+ const auto facts = ReadPe(path.string(), true);+ if (!facts.valid) return {}; // stays: the drive may answer at a later start+ if (ProgramLooksLikeGame(path, facts)) program = named;+ }+ // One that can't be removed would say the same at every start, without another failed run.+ if (!fs::remove(note, error) || error) return {};+ return program;+}+GameProbe ProbeGame(const std::string& install_root, const std::string& executable) {GameProbe probe;const fs::path root(install_root);diff --git a/src/runtime/game_probe.h b/src/runtime/game_probe.hindex 54f6819..d1bebcc 100644--- a/src/runtime/game_probe.h+++ b/src/runtime/game_probe.h@@ -43,6 +43,13 @@ GameProbe ProbeGame(const std::string& install_root, const std::string& executab// Unlike GameProbe::apis, the libraries beside it don't count, so a launcher next to the game's DLLs is not one.bool ProgramDrawsWithOpenGLOnly(const std::string& install_root, const std::string& executable);+// The program a game's last run couldn't start, from the note the title's Wine leaves in the bottle: what a launcher+// without launcher mode asked for. Relative to host_root, as spelled in the note, when it's a program in the game's+// folder (console_root on the console, host_root as seen here) that draws or has an engine, so a crash reporter or an+// updater isn't taken for the game. The note names one run: this removes it.+std::string TakeRefusedGameProgram(const std::string& prefix_dir, const std::string& console_root,+ const std::string& host_root);+// The program that starts an Unreal game when executable (relative to install_root, '/' separators) is its root// launcher, which only starts that one as a child process, which the console cannot do; relative to install_root,// as spelled on disk. Empty for any other program. GameProbe::unreal_program, without reading the programs.diff --git a/tests/game_probe_test.cpp b/tests/game_probe_test.cppindex a916584..bc36d7d 100644--- a/tests/game_probe_test.cpp+++ b/tests/game_probe_test.cpp@@ -787,6 +787,58 @@ int main() {CHECK(!ProgramDrawsWithOpenGLOnly(root.string(), "Missing.exe"));}+ { // A run's note: a program in the game's folder that draws, once; a helper or a path elsewhere is nothing.+ const auto root = fresh();+ const auto prefix = root / "prefix";+ fs::create_directories(prefix);+ WritePe(root / "game/bin/Game.exe", {false, {"KERNEL32.dll", "d3d11.dll"}});+ WritePe(root / "game/Reporter.exe", {false, {"KERNEL32.dll"}});+ const auto note = [&](const std::string& image) {+ std::ofstream(prefix / ".pw-exec-refused", std::ios::binary) << "pw-exec-refused 1\nimage=" << image << "\n";+ };+ const auto take = [&] { return TakeRefusedGameProgram(prefix.string(), "/data/games/1", (root / "game").string()); };+ CHECK(take().empty());+ note("Z:\\data\\games\\1\\bin\\Game.exe");+ CHECK(take() == "bin/Game.exe");+ // A helper beside the game's libraries is still a helper; a program that names its engine is the game.+ WritePe(root / "game/d3d.dll", {false, {"d3d11.dll"}});+ note("Z:\\data\\games\\1\\Reporter.exe");+ CHECK(take().empty());+ WritePe(root / "game/UnityGame.exe", {false, {"UnityPlayer.dll"}});+ note("Z:\\data\\games\\1\\UnityGame.exe");+ CHECK(take() == "UnityGame.exe");+ note("Z:\\data\\games\\1\\\\bin\\Game.exe");+ CHECK(take().empty());+ // Graphics named inside the program count; a folder's name doesn't make a helper the game.+ WritePe(root / "game/Risk.exe", {true, {"KERNEL32.dll"}, false, false, "D3D11.DLL"});+ note("Z:\\data\\games\\1\\Risk.exe");+ CHECK(take() == "Risk.exe");+ WritePe(root / "game/Game-Shipping/Reporter.exe", {false, {"KERNEL32.dll"}});+ note("Z:\\data\\games\\1\\Game-Shipping\\Reporter.exe");+ CHECK(take().empty());+ WritePe(root / "game/Game-Win64-Shipping.exe", {false, {"KERNEL32.dll"}});+ note("Z:\\data\\games\\1\\Game-Win64-Shipping.exe");+ CHECK(take() == "Game-Win64-Shipping.exe");+ // A program that can't be read keeps the note for a later start.+ { std::ofstream(root / "game/Broken.exe", std::ios::binary) << "x"; }+ note("Z:\\data\\games\\1\\Broken.exe");+ CHECK(take().empty() && fs::exists(prefix / ".pw-exec-refused"));+ fs::remove(prefix / ".pw-exec-refused");+ CHECK(!fs::exists(prefix / ".pw-exec-refused") && take().empty());+ note("Z:\\data\\games\\1\\Reporter.exe");+ CHECK(take().empty());+ note("Z:\\data\\games\\12\\bin\\Game.exe");+ CHECK(take().empty());+ note("Z:\\data\\games\\1\\..\\1\\bin\\Game.exe");+ CHECK(take().empty());+ note("C:\\data\\games\\1\\bin\\Game.exe");+ CHECK(take().empty());+ note("Z:\\data\\games\\1\\bin\\Missing.exe");+ CHECK(take().empty());+ std::ofstream(prefix / ".pw-exec-refused", std::ios::binary) << "something else\n";+ CHECK(take().empty() && !fs::exists(prefix / ".pw-exec-refused"));+ }+// The player's words for what was found.CHECK(DetectedLabel("unity-il2cpp,d3d11,d3d12 graphics=dxvk") == "Unity \xC2\xB7 Direct3D 11");CHECK(DetectedLabel("d3d9 graphics=dxvk") == "Direct3D 9");diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cppindex 9673e40..91d9c1f 100644--- a/tests/homebrew_live_model_test.cpp+++ b/tests/homebrew_live_model_test.cpp@@ -771,6 +771,26 @@ void live_runs_setup_program_once(const std::filesystem::path& base) {check(model.state().navigation.modals.empty() && model.TakeRuntimePlayRequests() == std::vector<playden::GameId>{SteamId(35140)} &&model.TakeRuntimeSetupPrograms() == std::map<GameId, std::string>{{SteamId(35140), "Binaries/BmLauncher.exe"}},"launcher mode: with it set, picking a program starts it");++ // A kit without launcher mode offers nothing, and the caller may tell it again later.+ model.SetKitCapabilities(playden::runtime::KitCapabilitiesFromManifest({}, true));+ check(!model.NotifyLauncherHint(SteamId(35140), "Binaries/BatmanAC.exe") && model.state().navigation.modals.empty(),+ "launcher hint: not without the kit's launcher mode");+ model.SetKitCapabilities(playden::runtime::KitCapabilitiesFromManifest({"launcher-mode"}, true));+ // A run that couldn't start a program offers launcher mode once, and Turn on and play does both.+ model.NotifyLauncherHint(SteamId(35140), "Binaries/BatmanAC.exe");+ check(model.state().navigation.modals.back().title == "This game uses a launcher" &&+ model.state().navigation.modals.back().body.find("BatmanAC.exe") != std::string::npos,+ "launcher hint: the dialog names the program");+ activate(model, "launcher-hint-later");+ check(model.state().navigation.modals.empty() && model.TakeRuntimePlayRequests().empty(), "launcher hint: Not now does nothing");+ model.NotifyLauncherHint(SteamId(35140), "Binaries/BatmanAC.exe");+ activate(model, "launcher-hint-on");+ check(model.TakeRuntimePlayRequests() == std::vector<playden::GameId>{SteamId(35140)} &&+ model.state().game_settings.at(SteamId(35140)).overrides.at("start_through_launcher") == "on",+ "launcher hint: it turns the setting on and plays");+ model.NotifyLauncherHint(SteamId(35140), "Binaries/BatmanAC.exe");+ check(model.state().navigation.modals.empty(), "launcher hint: not offered with the setting on");}void live_download_telemetry() {