Skip to content

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

C++

Keep 120 Hz output off until a stale title is updated

Leonardo Lobato8d2637893670
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 9ca5859..bb208a0 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -1283,6 +1283,7 @@ void Controller::TickRuntime() {
snapshot.status == RuntimeHostStatus::kReady;
game.settings_revision = record->settings_revision;
game.launch_entry_id = record->launch_entry_id;
+ game.runtime_current = record->runtime_current;
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 adc6122..b8c0363 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -932,7 +932,7 @@ std::string RuntimeHost::ApplyPreparationSteps(Composition& c, const rt::Runtime
if (candidate.id == files.saved->preset_id) preset = &candidate;
rt::SettingsError error;
static const std::map<std::string, std::string> none;
- const auto kit = c.kit ? rt::KitCapabilitiesFromManifest(c.kit->capabilities, true) : rt::KitCapabilities{};
+ const auto kit = TitleKit(c, record);
if (!rt::BuildEffectiveSettings(*files.recipe, preset, files.saved ? files.saved->overrides : none, kit, &files.settings,
&error))
return {}; // publication reports invalid settings
@@ -1196,11 +1196,22 @@ void RuntimeHost::ClearWork() {
Publish([](RuntimeSnapshot& s) { s.work_progress.reset(); });
}
+// Whether the install is bound to exactly the installed kit's runtime artifacts.
+static bool ArtifactsBound(const auto& kit_artifacts, const rt::RuntimeInstall& record) {
+ return record.artifacts.size() == kit_artifacts.size() &&
+ std::all_of(kit_artifacts.begin(), kit_artifacts.end(), [&](const auto& artifact) {
+ return std::any_of(record.artifacts.begin(), record.artifacts.end(), [&](const auto& bound) {
+ return bound.artifact_id == artifact.artifact_id && bound.identity == artifact.identity &&
+ bound.sha256 == artifact.sha256;
+ });
+ });
+}
+
void RuntimeHost::PublishInstalls(const Composition& composition, const std::string& only) {
- std::map<std::string, bool> checked;
+ std::map<std::string, std::pair<bool, bool>> checked; // title_current, runtime_current
if (!only.empty()) {
std::lock_guard<std::mutex> lock(mutex_);
- for (const auto& view : snapshot_.installs) checked[view.install_id] = view.title_current;
+ for (const auto& view : snapshot_.installs) checked[view.install_id] = {view.title_current, view.runtime_current};
}
std::vector<RuntimeInstallView> installs;
for (const auto& record : composition.repository.Snapshot()) {
@@ -1218,11 +1229,14 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::str
view.failure = record.last_failure->message;
view.failure_code = record.last_failure->code;
}
- if (const auto kept = checked.find(record.install_id); !only.empty() && record.install_id != only && kept != checked.end())
- view.title_current = kept->second;
- else if (record.state == rt::PreparationState::kReady && composition.kit)
- view.title_current = composition.installer->TitleCurrent(record) &&
- composition.installer->TitleMetadataCurrent(record) && TitleNameCurrent(record);
+ if (const auto kept = checked.find(record.install_id); !only.empty() && record.install_id != only && kept != checked.end()) {
+ view.title_current = kept->second.first;
+ view.runtime_current = kept->second.second;
+ } else if (record.state == rt::PreparationState::kReady && composition.kit) {
+ const bool files_current = composition.installer->TitleCurrent(record);
+ view.title_current = files_current && composition.installer->TitleMetadataCurrent(record) && TitleNameCurrent(record);
+ view.runtime_current = files_current && ArtifactsBound(composition.kit->view.artifacts, record);
+ }
if (const auto found = composition.admission.find(record.install_id); found != composition.admission.end())
view.admission = found->second;
view.settings_revision = record.settings_revision;
@@ -1248,6 +1262,17 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::str
PublishPrepared(&composition);
}
+bool RuntimeHost::TitleRuntimeCurrent(const Composition& c, const rt::RuntimeInstall& record) const {
+ return c.kit && c.installer->TitleCurrent(record) && ArtifactsBound(c.kit->view.artifacts, record);
+}
+
+rt::KitCapabilities RuntimeHost::TitleKit(const Composition& c, const rt::RuntimeInstall& record) const {
+ if (!c.kit) return {};
+ const auto kit = rt::KitCapabilitiesFromManifest(c.kit->capabilities, true);
+ // The title's markers are read only when the kit has something an older runtime would refuse.
+ return kit.display_120hz ? rt::KitForTitleRuntime(kit, TitleRuntimeCurrent(c, record)) : kit;
+}
+
// The complete OWNER protocol for the publish-profile step: persist the exact
// requested plan, arm OWNER, then capture, publish, register and commit Ready.
// Recovery journals resume their saved request or frozen operation; nothing is
@@ -1280,7 +1305,7 @@ rt::PackageActionResult RuntimeHost::DrivePublication(Composition& c, const rt::
: rt::GameSettingsRecord{};
for (const auto& preset : c.presets)
if (preset.id == input.record.preset_id) input.preset = &preset;
- input.kit = rt::KitCapabilitiesFromManifest(c.kit->capabilities, true);
+ input.kit = TitleKit(c, record);
input.target = {record.default_profile_id, record.install_path};
input.runtime_dir = config_.runtime_dir;
rt::SettingsLaunchPlan plan;
@@ -1576,7 +1601,7 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeI
const rt::SettingsPreset* preset = nullptr;
for (const auto& candidate : c.presets)
if (candidate.id == saved.preset_id) preset = &candidate;
- const auto kit = rt::KitCapabilitiesFromManifest(c.kit->capabilities, true);
+ const auto kit = TitleKit(c, record);
// Another program or folder chosen in Game settings: the PS5 title and the bottle stay, and
// the install record names the new program when this publication commits (Reconcile), so a
// crash in between resumes with it. Callers run this only while the game is stopped.
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index cce05e1..2e01388 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -168,6 +168,9 @@ struct RuntimeInstallView {
bool awaiting_registration = false;
// False when a Ready title was made from an earlier kit; Prepare updates it.
bool title_current = true;
+ // Whether the title runs the installed kit's runtime (its files and artifacts are the kit's). Unlike title_current,
+ // a new game name or icon does not count. Settings only the newer runtime takes (120 Hz output) wait for Update.
+ bool runtime_current = true;
// Publication admission result for Ready titles ("ok" or the refusal); a
// refusal means the next start would be refused, and Prepare repairs it.
std::string admission = "ok";
@@ -553,6 +556,13 @@ class RuntimeHost {
std::string InstallScriptsStep(const GameFiles& files); // and redistributables
// The Steam app ID the game's emulator uses.
SteamworksAppView SteamworksAppFor(const GameFiles& files) const;
+ // Whether the install's title runs the installed kit's runtime: its owner markers name this kit
+ // (PackageInstaller::TitleCurrent) and its bound artifacts are the kit's. A title made from an earlier kit runs
+ // that kit's runtime until Update.
+ bool TitleRuntimeCurrent(const Composition& composition, const runtime::RuntimeInstall& record) const;
+ // The installed kit's capabilities as this install's title can use them (runtime::KitForTitleRuntime): profile
+ // keys only a newer runtime takes are left out until Update. Use it wherever a profile is built for the title.
+ runtime::KitCapabilities TitleKit(const Composition& composition, const runtime::RuntimeInstall& record) const;
// Empty while the kit on disk is the one admitted at startup; otherwise what to tell the player.
std::string KitReplaced(const Composition& composition) const;
// Makes an owned, world-writable folder from root down to working 0755 (dxvk.conf goes there).
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index cc01a51..c76b034 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -3628,7 +3628,8 @@ void Simulation::rebuild_view() {
overrides.erase(modal.setting_id);
rt::EffectiveSettings base;
rt::SettingsError ignored;
- if (rt::BuildEffectiveSettings(RecipeFor(settings_game), preset_for(settings_game), overrides, kit_, &base, &ignored))
+ if (rt::BuildEffectiveSettings(RecipeFor(settings_game), preset_for(settings_game), overrides, kit_for(settings_game),
+ &base, &ignored))
inherited = base.values.at(modal.setting_id);
}
if (modal.id == "game-settings" || modal.id == "game-maintenance") {
@@ -8101,6 +8102,11 @@ const rt::GameRecipe& Simulation::RecipeFor(GameId id) const {
return recipe;
}
+rt::KitCapabilities Simulation::kit_for(GameId id) const {
+ const auto runtime = state_.runtime_games.find(id);
+ return rt::KitForTitleRuntime(kit_, runtime == state_.runtime_games.end() || runtime->second.runtime_current);
+}
+
const rt::SettingsPreset* Simulation::preset_for(GameId id) const {
const auto record = state_.game_settings.find(id);
const std::string wanted = record == state_.game_settings.end() || record->second.preset_id.empty()
@@ -8115,7 +8121,7 @@ bool Simulation::EffectiveSettingsFor(GameId id, rt::EffectiveSettings* settings
static const std::map<std::string, std::string> none;
rt::SettingsError error;
return rt::BuildEffectiveSettings(RecipeFor(id), preset_for(id), record == state_.game_settings.end() ? none : record->second.overrides,
- kit_, settings, &error);
+ kit_for(id), settings, &error);
}
std::vector<std::string> Simulation::game_settings_actions() const {
@@ -8255,7 +8261,7 @@ void Simulation::build_preset_comparison(GameId id, const std::string& preset_id
rt::EffectiveSettings current, after;
rt::SettingsError error;
if (!chosen || !EffectiveSettingsFor(id, &current) ||
- !rt::BuildEffectiveSettings(RecipeFor(id), chosen, kept_start_choices(id), kit_, &after, &error))
+ !rt::BuildEffectiveSettings(RecipeFor(id), chosen, kept_start_choices(id), kit_for(id), &after, &error))
return;
ViewData::Comparison comparison;
comparison.title = chosen->name;
@@ -8514,7 +8520,7 @@ void Simulation::set_game_setting(const std::string& id, const std::string& valu
rt::EffectiveSettings base;
rt::SettingsError error;
// Choosing the inherited value removes the override, so the row is no longer "changed".
- const bool inherited = rt::BuildEffectiveSettings(RecipeFor(game), preset_for(game), overrides, kit_, &base, &error)
+ const bool inherited = rt::BuildEffectiveSettings(RecipeFor(game), preset_for(game), overrides, kit_for(game), &base, &error)
&& base.values.at(id).value == value;
if (inherited) record.overrides.erase(id);
else record.overrides[id] = value;
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 347c9cd..8e50d69 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -159,6 +159,9 @@ struct LiveRuntimeGame {
// Prepared and waiting for the PS5 to register its title, which it does once Playden
// quits: the game is ready to play from Home, and Play quits there.
bool awaiting_registration = false;
+ // The title runs the installed kit's runtime (false while a Ready title waits for Update): settings only the
+ // newer runtime takes, such as 120 Hz output, are offered only then.
+ bool runtime_current = true;
// Has a prepared title (Ready, perhaps with an update or repair to make): its Game
// settings and maintenance apply to it.
bool prepared = false;
@@ -1125,6 +1128,9 @@ private:
// Rows the preset chooser compares: Current → This preset for the focused preset.
void build_preset_comparison(GameId id, const std::string& preset_id);
[[nodiscard]] const playden::runtime::SettingsPreset* preset_for(GameId id) const;
+ // The kit's capabilities as the game's PS5 title can use them: a title still on an earlier kit's runtime (Update
+ // pending) gets no 120 Hz output until it is updated (runtime::KitForTitleRuntime).
+ [[nodiscard]] playden::runtime::KitCapabilities kit_for(GameId id) const;
void start_logs();
void finish_logs();
void queue_service_action(ServiceAction action, Store store = Store::kSteam);
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index d0032da..9b5a12f 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -221,6 +221,53 @@ bool has_notice(const Simulation& model, const std::string& id) {
return std::any_of(notices.begin(), notices.end(), [&id](const auto& notice) { return notice.id == id; });
}
+// 120 Hz output needs the game's title on a runtime that takes it: a title waiting for Update says so, and Frame
+// limit choices that need 120 Hz output are disabled with their reason.
+void live_120hz_waits_for_the_title_update(const std::filesystem::path& base) {
+ std::filesystem::create_directories(base);
+ auto model = make_live(base);
+ model.SetGameSettingsFile(base / "display-settings.json");
+ model.SetSettingsData({{"playden-default", "Playden default", "Most games", "", {}}}, {});
+ model.SetKitCapabilities(playden::runtime::KitCapabilitiesFromManifest({"dxvk", "display-120hz"}, true));
+ model.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ playden::GameSummary game;
+ game.id = SteamId(220);
+ game.title = "Half-Life 2";
+ check(model.UpdateLibrary({{game}, false, {}, false, true, 100}), "display game library delivered");
+ model.UpdateInstalls({}, {{SteamId(220), 1024, "internal", true}});
+ playden::homebrew::LiveRuntimeGame runtime;
+ runtime.game_id = SteamId(220);
+ runtime.status = "Update available";
+ runtime.prepared = runtime.has_title = true;
+ runtime.runtime_current = false;
+ runtime.launch_entry_id = "game";
+ runtime.activity = playden::homebrew::TitleActivity::Stopped;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ check(model.action("details:220"), "open the display game's details");
+ activate(model, "details-more");
+ activate(model, "game-settings");
+ activate(model, "section-more");
+ const auto* refresh = find_row(model, "setting-refresh");
+ check(refresh && !refresh->enabled && refresh->subtitle == "Update this game to use it.",
+ "120 Hz output waits for the title's Update");
+ activate(model, "setting-frame_limit");
+ const auto* limit_120 = find_row(model, "choice-1");
+ check(limit_120 && limit_120->title == "120" && !limit_120->enabled && limit_120->subtitle == "Update this game to use it.",
+ "Frame limit 120 waits for the title's Update");
+ check(find_row(model, "choice-2") && find_row(model, "choice-2")->enabled, "Frame limit 60 stays available");
+ check(model.action("circle"), "close the Frame limit picker");
+
+ runtime.status = "Ready";
+ runtime.ready = true;
+ runtime.runtime_current = true;
+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});
+ refresh = find_row(model, "setting-refresh");
+ check(refresh && refresh->enabled, "an updated title offers 120 Hz output");
+ activate(model, "setting-frame_limit");
+ const auto* at_60 = find_row(model, "choice-1");
+ check(at_60 && !at_60->enabled && at_60->subtitle == "Only with 120 Hz output.", "Frame limit 120 needs 120 Hz output");
+}
+
// A prepared game's settings and maintenance: rows that need the game closed wait for the
// console's answer, a closed sheet asks for the settings to be applied, and maintenance
// requests go to the runtime after a confirmation.
@@ -879,6 +926,7 @@ int main() {
settings_survive_account_restore_and_cache_action_is_honest(base);
live_settings_follow_the_prepared_title(base);
+ live_120hz_waits_for_the_title_update(base / "display");
live_program_change_applies_like_other_settings(base);
live_imported_game_steam_app_id(base);
live_imported_program_seeds_once(base);
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index de53213..2f14f83 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -1895,6 +1895,80 @@ void KitWithoutUnownedRootsKeepsTightening() {
host.Shutdown();
}
+// A kit with 120 Hz output over a title still running an earlier kit's runtime: until Update, the title's profile
+// has no frame_rate (its runtime would refuse the whole profile) and Frame limit stays DXVK's. After Update the
+// display paces it.
+void StaleTitleWaitsForUpdateBefore120Hz() {
+ Fixture fixture;
+ auto config = fixture.Config();
+ config.host_namespace_prefix = fixture.root;
+ 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");
+ };
+ unsigned uuids = 0;
+ config.uuid = [&uuids]() -> std::optional<std::string> {
+ ++uuids; return std::string("00000000-0000-4000-8000-00000000000") + std::to_string(uuids);
+ };
+ config.unix_time = [] { return std::int64_t{1760000000}; };
+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ const auto profile = fixture.root / "data/playden/games/steam-220/library/profiles/playden-steam-220.profile";
+ GameSettingsRecord saved;
+ config.settings_record = [&saved](const playden::GameId&) -> std::optional<GameSettingsRecord> { return saved; };
+ Write(game / "hl2.exe", "existing-game", 0644);
+ CHECK(chmod(game.c_str(), 0755) == 0);
+ {
+ auto kit = SyntheticKit(fixture.root / "kit");
+ kit.capabilities = {"dxvk", "offline_bottle", "per_game_title", "wow64_i386"};
+ auto first = config;
+ first.admit_kit = [kit](std::string*) { return std::optional<RuntimeKit>(kit); };
+ RuntimeHost host(first);
+ CHECK(host.Start());
+ host.Prepare(Hl2());
+ const auto ready = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && !s.installs.empty() && s.installs[0].state == PreparationState::kReady;
+ }, 60);
+ CHECK(ready.installs[0].title_current && ready.installs[0].runtime_current);
+ host.Shutdown();
+ }
+ auto respun = SyntheticKit(fixture.root / "kit-respun", "native-2", "kit-1", 'c');
+ respun.capabilities = {"display-120hz", "dxvk", "offline_bottle", "per_game_title", "wow64_i386"};
+ config.admit_kit = [respun](std::string*) { return std::optional<RuntimeKit>(respun); };
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ const auto started = WaitFor(host, Started);
+ CHECK(!started.installs[0].title_current && !started.installs[0].runtime_current);
+ const auto apply = [&host] {
+ const auto before = host.Snapshot().maintenance_handled;
+ host.Maintain(220, RuntimeMaintenance::kApplySettings);
+ return WaitFor(host, [before](const RuntimeSnapshot& s) { return s.maintenance_handled > before; }, 60);
+ };
+ saved.revision = 1;
+ saved.overrides = {{"refresh", "120"}, {"frame_limit", "60"}};
+ auto result = apply();
+ if (!result.maintenance.at(220).ok) std::fprintf(stderr, "stale apply: %s\n", result.maintenance.at(220).message.c_str());
+ CHECK(result.maintenance.at(220).ok && result.installs[0].settings_revision == 1);
+ CHECK(Read(profile).find("frame_rate") == std::string::npos && Read(profile).find("refresh") == std::string::npos);
+ CHECK(Read(game / "dxvk.conf").find("dxgi.maxFrameRate = 60") != std::string::npos);
+
+ host.Prepare(Hl2());
+ result = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && !s.installs.empty() && (s.installs[0].title_current || s.refusals.count(220));
+ }, 60);
+ CHECK(!result.refusals.count(220) && result.installs[0].runtime_current);
+ saved.revision = 2;
+ result = apply();
+ if (!result.maintenance.at(220).ok) std::fprintf(stderr, "updated apply: %s\n", result.maintenance.at(220).message.c_str());
+ CHECK(result.maintenance.at(220).ok && result.installs[0].settings_revision == 2);
+ CHECK(Read(profile).find("\nrefresh = 120\nframe_rate = 60\n") != std::string::npos);
+ CHECK(!fs::exists(game / "dxvk.conf") || Read(game / "dxvk.conf").find("maxFrameRate") == std::string::npos);
+ host.Shutdown();
+}
+
// A kit respin while a settings update waits for recovery (#5): the title is still this
// install's, so Update first finishes the saved update, and the title only reports that
// it needs Update (not current) until a second Update refreshes it.
@@ -4667,6 +4741,7 @@ int main(int argc, char** argv) {
for (int route = 0; route <= 5; ++route) OwnedPublicationOpenedUpRecovers(route);
SettingsSavedDuringPrepareReachReadyTitle();
KitRespinKeepsWaitingSettingsUpdate();
+ StaleTitleWaitsForUpdateBefore120Hz();
RemovesTitleKeepingSaves();
PreparesGameInstalledAgainElsewhere();
SharedProfileKitOpensSaves();