Play your Steam library's Windows games on a jailbroken PS5.
C++
Finish settings republish on the next Update
Leonardo Lobato80ad80409beb
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex c33a2a6..8847200 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -1579,11 +1579,16 @@ std::string RuntimeHost::PublishSavedSettings(Composition& c, const rt::RuntimeIif (prepare_again) *prepare_again = true;return message;};- auto saved = config_.settings_record- ? config_.settings_record(GameOf(record)).value_or(rt::GameSettingsRecord{})- : rt::GameSettingsRecord{};- // A forced publication keeps the title's revision: the settings are the same, the runtime is not.- if (force) saved.revision = std::max(saved.revision, record.settings_revision);+ const auto stored = config_.settings_record ? config_.settings_record(GameOf(record)) : std::nullopt;+ auto saved = stored.value_or(rt::GameSettingsRecord{});+ // A forced publication republishes the title's own revision for another runtime, so it needs the saved settings of+ // that revision or a newer one: Playden defaults standing in for a missing or unreadable record are not they.+ if (force && (!stored || saved.revision < record.settings_revision)) {+ Log("forced republish skipped app=" + std::to_string(record.runtime_number) + " saved=" ++ (stored ? std::to_string(saved.revision) : std::string("none")) ++ " title=" + std::to_string(record.settings_revision));+ return {};+ }// 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();@@ -2606,10 +2611,7 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&const auto written = WriteTitleMetadata(c, *existing, request.title_name);if (written.state != rt::PackageActionState::kComplete) return written.message;}- // A title that moves to the kit's runtime gets its settings published again below: the profile- // was built for the runtime it had, and the new one may take more keys (120 Hz output) or fewer.- const bool runtime_refresh = !c.installer->TitleCurrent(*existing);- if (runtime_refresh || !metadata_current) {+ if (!c.installer->TitleCurrent(*existing) || !metadata_current) {// Same kit id and recipe; title files changed (a new wrapper build) or// the runtime was rebuilt (same artifacts, new bytes). The registration// and publication stay as they are. A rebuilt runtime is copied into the@@ -2691,14 +2693,18 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&PublishInstalls(c);if (admission != "ok") return "The PS5 title still fails its start check: " + admission;OpenGameFolders(c, *existing);- if (runtime_refresh) {- const auto refreshed_record = c.records.Find(existing->install_id);- if (!refreshed_record) return "The game's install record is missing.";+ // The profile was built for the runtime the title had then; the kit's may take more keys (120 Hz output) or+ // fewer. Every Update that gets here publishes the saved settings again when they now write something else+ // (nothing otherwise), so an Update that failed after its title refresh is finished by the next one.+ {+ const auto current = c.records.Find(existing->install_id);+ if (!current) return "The game's install record is missing.";bool republished = false;- const auto refused = RepublishSettings(c, *refreshed_record, &republished, true, nullptr, nullptr, nullptr, true);- Log("runtime refresh republish app=" + std::to_string(request.runtime_number) + " published=" +- std::to_string(republished) + (refused.empty() ? std::string() : " refused=" + refused));+ const auto refused = RepublishSettings(c, *current, &republished, true, nullptr, nullptr, nullptr, true);+ Log("update republish app=" + std::to_string(request.runtime_number) + " published=" + std::to_string(republished) ++ (refused.empty() ? std::string() : " refused=" + refused));if (!refused.empty()) return refused;+ changed = changed || republished;}return changed ? std::string{} : "This game is already prepared.";}diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cppindex 64dd4db..271e0f4 100644--- a/tests/homebrew_runtime_host_test.cpp+++ b/tests/homebrew_runtime_host_test.cpp@@ -814,7 +814,13 @@ void RefreshesInstalledTitleToRespunKit() {config.package_operations.validate_bottle = [](const fs::path& bottle) {return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");};- config.uuid = []() -> std::optional<std::string> { return std::string("00000000-0000-4000-8000-000000000001"); };+ // Every publication transaction takes a UUID: counting them shows that an Update which changes nothing the+ // settings write starts none.+ auto transactions = std::make_shared<int>(0);+ config.uuid = [transactions]() -> std::optional<std::string> {+ ++*transactions;+ return std::string("00000000-0000-4000-8000-000000000001");+ };config.unix_time = [] { return std::int64_t{1760000000}; };const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";Write(game / "hl2.exe", "existing-game", 0644);@@ -834,6 +840,7 @@ void RefreshesInstalledTitleToRespunKit() {const auto bottle_reg = fixture.root / "data/playden/games/steam-220/library/prefixes/game/user.reg";const auto registry_before = Read(bottle_reg);const auto installs_before = Read(fixture.root / "data/runtime-state/installs.json");+ const int transactions_before = *transactions;CHECK(fixture.registry_mutations == 2);{ // A different kit id is not a respin; it needs republication.const auto other = SyntheticKit(fixture.root / "kit-other", "native", "kit-2", 'b');@@ -859,6 +866,7 @@ void RefreshesInstalledTitleToRespunKit() {}, 60);if (done.refusals.count(220)) std::fprintf(stderr, "Refresh refused: %s\n", done.refusals.at(220).c_str());CHECK(!done.refusals.count(220) && done.installs[0].state == PreparationState::kReady);+ CHECK(*transactions == transactions_before && !done.installs[0].recovery_pending);CHECK(Read(fixture.root / "data/homebrew/FAKE78001/eboot.bin") == "native-2");CHECK(Read(bottle_reg) == registry_before);CHECK(Read(fixture.root / "data/runtime-state/installs.json") == installs_before);@@ -880,6 +888,7 @@ void RefreshesInstalledTitleToRespunKit() {}, 60);if (up.refusals.count(220)) std::fprintf(stderr, "Upgrade refused: %s\n", up.refusals.at(220).c_str());CHECK(!up.refusals.count(220) && up.installs[0].state == PreparationState::kReady);+ CHECK(*transactions == transactions_before);CHECK(Read(fixture.root / "data/homebrew/FAKE78001/win/wine/lib/core.prx") == "runtime-neutral");const auto upgraded_installs = Read(fixture.root / "data/runtime-state/installs.json");CHECK(upgraded_installs != installs_before &&@@ -2004,6 +2013,104 @@ void StaleTitleWaitsForUpdateBefore120Hz() {host.Shutdown();}+// Prepares HL2 on a kit without 120 Hz output and publishes saved 120 Hz settings there (revision 1), then returns+// the kit with 120 Hz output that the title is not updated to yet.+RuntimeKit PrepareStaleFor120Hz(Fixture& fixture, RuntimeHostConfig config, GameSettingsRecord* saved) {+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";+ 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"};+ config.admit_kit = [kit](std::string*) { return std::optional<RuntimeKit>(kit); };+ RuntimeHost host(config);+ CHECK(host.Start());+ host.Prepare(Hl2());+ WaitFor(host, [](const RuntimeSnapshot& s) {+ return !s.preparing_app && !s.installs.empty() && s.installs[0].state == PreparationState::kReady;+ }, 60);+ saved->revision = 1;+ saved->overrides = {{"refresh", "120"}, {"frame_limit", "60"}};+ const auto before = host.Snapshot().maintenance_handled;+ host.Maintain(220, RuntimeMaintenance::kApplySettings);+ const auto applied = WaitFor(host, [before](const RuntimeSnapshot& s) { return s.maintenance_handled > before; }, 60);+ CHECK(applied.maintenance.at(220).ok && applied.installs[0].settings_revision == 1);+ host.Shutdown();+ auto display = SyntheticKit(fixture.root / "kit-display", "native-2", "kit-1", 'c');+ display.capabilities = {"display-120hz", "dxvk", "offline_bottle", "per_game_title", "wow64_i386"};+ return display;+}++RuntimeSnapshot UpdateHl2(RuntimeHost& host) {+ const auto before = host.Snapshot().prepares_handled;+ host.Prepare(Hl2());+ return WaitFor(host, [before](const RuntimeSnapshot& s) { return s.prepares_handled > before && !s.preparing_app; }, 60);+}++// An Update that fails after the title was refreshed (here its start check) is finished by the next Update, even+// though the title is current by then, after a Playden restart in between.+void UpdateFinishesAFailedRepublish() {+ Fixture fixture;+ unsigned uuids = 0;+ GameSettingsRecord saved;+ auto config = DisplayConfig(fixture, &uuids, &saved);+ const auto display = PrepareStaleFor120Hz(fixture, config, &saved);+ 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";+ config.admit_kit = [display](std::string*) { return std::optional<RuntimeKit>(display); };+ // A dxvk.conf Playden did not write: the title fails its start check after the refresh.+ const auto published_config = Read(game / "dxvk.conf");+ Write(game / "dxvk.conf", "dxgi.maxFrameRate = 50\n", 0644);+ {+ RuntimeHost host(config);+ CHECK(host.Start());+ const auto failed = UpdateHl2(host);+ CHECK(failed.refusals.count(220) && failed.installs[0].runtime_current);+ CHECK(Read(profile).find("frame_rate") == std::string::npos);+ host.Shutdown();+ }+ Write(game / "dxvk.conf", published_config, 0644);+ const auto transactions = uuids;+ RuntimeHost host(config);+ CHECK(host.Start());+ const auto started = WaitFor(host, Started);+ CHECK(started.installs[0].title_current);+ const auto done = UpdateHl2(host);+ if (done.refusals.count(220)) std::fprintf(stderr, "Second Update refused: %s\n", done.refusals.at(220).c_str());+ CHECK(!done.refusals.count(220) && !done.installs[0].recovery_pending && done.installs[0].settings_revision == 1);+ CHECK(Read(profile).find("\nrefresh = 120\nframe_rate = 60\n") != std::string::npos);+ // One publication in all: either the saved request resumed, or a new one when the first left none behind.+ CHECK(uuids - transactions <= 1);+ // Another Update has nothing left to publish.+ const auto again_transactions = uuids;+ const auto again = UpdateHl2(host);+ CHECK(again.refusals.count(220) && again.refusals.at(220) == "This game is already prepared.");+ CHECK(uuids == again_transactions && !again.installs[0].recovery_pending);+ host.Shutdown();+}++// Without the game's saved settings (missing or unreadable), Update publishes nothing: Playden defaults would replace+// what the title has.+void UpdateWithoutSavedSettingsKeepsThePublication() {+ Fixture fixture;+ unsigned uuids = 0;+ GameSettingsRecord saved;+ auto config = DisplayConfig(fixture, &uuids, &saved);+ const auto display = PrepareStaleFor120Hz(fixture, config, &saved);+ 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";+ const auto published = Read(profile);+ const auto config_before = Read(game / "dxvk.conf");+ config.admit_kit = [display](std::string*) { return std::optional<RuntimeKit>(display); };+ config.settings_record = [](const playden::GameId&) -> std::optional<GameSettingsRecord> { return std::nullopt; };+ const auto transactions = uuids;+ RuntimeHost host(config);+ CHECK(host.Start());+ const auto done = UpdateHl2(host);+ CHECK(!done.refusals.count(220) && done.installs[0].runtime_current && done.installs[0].settings_revision == 1);+ CHECK(uuids == transactions && Read(profile) == published && Read(game / "dxvk.conf") == config_before);+ host.Shutdown();+}+// A game prepared on a kit with 120 Hz output publishes its 120 Hz settings with the first profile.void FreshPrepareOn120HzKitPublishesIt() {Fixture fixture;@@ -4803,6 +4910,8 @@ int main(int argc, char** argv) {KitRespinKeepsWaitingSettingsUpdate();StaleTitleWaitsForUpdateBefore120Hz();FreshPrepareOn120HzKitPublishesIt();+ UpdateFinishesAFailedRepublish();+ UpdateWithoutSavedSettingsKeepsThePublication();RemovesTitleKeepingSaves();PreparesGameInstalledAgainElsewhere();SharedProfileKitOpensSaves();