Play your Steam library's Windows games on a jailbroken PS5.
C++
Start NW.js games on kits with driver threads
Leonardo Lobato979b128af506
diff --git a/COMPATIBILITY.md b/COMPATIBILITY.mdindex 636685c..44eadbe 100644--- a/COMPATIBILITY.md+++ b/COMPATIBILITY.md@@ -30,6 +30,7 @@ uses: Direct3D 8–11 goes through DXVK to Vulkan, and Direct3D 12 through vkd3d| [A Story About My Uncle](https://store.steampowered.com/app/278360) | ✅ Works | 0.12 | UE3 · D3D9 · DXVK · 32-bit | USB: set Program to Steam Launch entry (Binaries/Win32/ASAMU-Win32-Shipping.exe); automatic UnrealLightmass.exe selection is wrong. Intro and opening house render cleanly; controller movement, camera look and zoom verified. Grappling, platforming and later areas untested. || [Absolute Drift](https://store.steampowered.com/app/320140) | ✅ Works | 0.14 | — | Default settings, DualSense. ([#388](https://github.com/leolobato/playden-ps5/issues/388), firmware 13.60) || [Agefield High: Rock the School](https://store.steampowered.com/app/3562580) | ✅ Works | 0.17 | — | Default settings. ([#386](https://github.com/leolobato/playden-ps5/pull/386)) |+| [Alabaster Dawn Demo](https://store.steampowered.com/app/3900710) | ✅ Works | 0.19 | NW.js · 32-bit | Default settings. || [Alan Wake](https://store.steampowered.com/app/108710) | ✅ Works | 0.13 | — | Game settings › Graphics = DXVK ([#250](https://github.com/leolobato/playden-ps5/issues/250)). ([#277](https://github.com/leolobato/playden-ps5/issues/277), firmware 13.42) || [Alan Wake's American Nightmare](https://store.steampowered.com/app/202750) | ✅ Works | 0.13 | — | Default settings, DualSense. ([#268](https://github.com/leolobato/playden-ps5/issues/268), firmware 13.42) || [American Truck Simulator](https://store.steampowered.com/app/270880) | ✅ Works | 0.10 | — | Disable news, World of Trucks and image spotlight. DualSense or USB mouse and keyboard; startup takes over a minute. ([#27](https://github.com/leolobato/playden-ps5/issues/27), firmware 9.40) |@@ -146,6 +147,7 @@ uses: Direct3D 8–11 goes through DXVK to Vulkan, and Direct3D 12 through vkd3d| [LEGO Marvel Super Heroes](https://store.steampowered.com/app/249130) | ✅ Works | 0.16 | — | Default settings, DualSense, default (Xbox controller). ([#405](https://github.com/leolobato/playden-ps5/pull/405), firmware 13.60) || [Lethal Company](https://store.steampowered.com/app/1966720) | ✅ Works | 0.13 | — | Default settings, DualSense. Play with LAN: Online shows an error. ([#141](https://github.com/leolobato/playden-ps5/issues/141), firmware 13.60) || [Little Nightmares Enhanced Edition](https://store.steampowered.com/app/2149010) | ✅ Works | 0.15 | — | Default settings, DualSense. ([#298](https://github.com/leolobato/playden-ps5/issues/298), firmware 11.60) |+| [Look Outside](https://store.steampowered.com/app/3373660) | ✅ Works | 0.19 | RPG Maker (NW.js) · 64-bit | Default settings. || [Loop Hero](https://store.steampowered.com/app/1282730) | ✅ Works | 0.10 | GameMaker · D3D11 · 64-bit | The controller drives the menus. || [Lords of the Fallen](https://store.steampowered.com/app/1501750) | ✅ Works | 0.13 | — | Default settings, DualSense. ([#322](https://github.com/leolobato/playden-ps5/issues/322), firmware 13.60) || Lost Planet: Extreme Condition Colonies Edition | ✅ Works | 0.13 | — | Imported copy. Default settings, DualSense. ([#185](https://github.com/leolobato/playden-ps5/issues/185), firmware 10.01) |@@ -320,6 +322,7 @@ uses: Direct3D 8–11 goes through DXVK to Vulkan, and Direct3D 12 through vkd3d| Mecha Chameleon | ❌ Broken | 0.16 | — | Needs an online login ([#115](https://github.com/leolobato/playden-ps5/issues/115)). ([#409](https://github.com/leolobato/playden-ps5/issues/409), firmware 13.60) || [Monaco](https://store.steampowered.com/app/113020) | ❌ Broken | 0.12 | Custom · D3D9 · DXVK · 32-bit | Creates the D3D9 device, then exits during startup before the menu. Log reports missing winegstreamer.prx when wmadmod loads, followed by an unhandled page fault. Retested with project.ini AUDIO_MUTE_ALL 1; still exits. Original configuration restored. || [MoonLess](https://store.steampowered.com/app/2322060) | ❌ Broken | 0.13 | GameMaker · D3D11 · 64-bit | Crashes right after it opens its window. |+| [OMORI](https://store.steampowered.com/app/1150690) | ❌ Broken | 0.19 | RPG Maker (NW.js) · 32-bit | Stops at the start. || [Order of the Sinking Star](https://store.steampowered.com/app/499170) | ❌ Broken | 0.12 | — · D3D12 · vkd3d-proton · 64-bit | vkd3d-proton starts, then the game says it needs a GPU with Direct3D feature level 12_0 and quits. Also after Recreate bottle. ([#95](https://github.com/leolobato/playden-ps5/issues/95), firmware 13.60) || [Overwatch](https://store.steampowered.com/app/2357570) | ❌ Broken | 0.13 | — · D3D12 · 64-bit | Crashes at start. ([#183](https://github.com/leolobato/playden-ps5/pull/183), firmware 13.00) || [Project Zomboid](https://store.steampowered.com/app/108600) | ❌ Broken | 0.16 | Java (LWJGL) · OpenGL · 64-bit | Stops about 20 seconds after start: it runs out of open files ([#194](https://github.com/leolobato/playden-ps5/issues/194)). |@@ -344,12 +347,10 @@ uses: Direct3D 8–11 goes through DXVK to Vulkan, and Direct3D 12 through vkd3d| [Wizard101](https://store.steampowered.com/app/799960) | ❌ Broken | 0.12 | — | Stops with "Unable to launch game. Your Steam client may be out-of-date", also with Steam features = Game's own files. ([#101](https://github.com/leolobato/playden-ps5/issues/101), firmware 13.60) || [Wrap House Simulator](https://store.steampowered.com/app/3533100) | ❌ Broken | 0.10 | — | Reaches the menu, but play lags at every setting, even the Low preset at 1600×900. USB mouse and keyboard. ([#19](https://github.com/leolobato/playden-ps5/issues/19), firmware 9.40) || [Cookie Clicker](https://store.steampowered.com/app/1454400) | ⛔ Refused | 0.13 | Electron | Runs on Electron (a built-in web browser), which Playden can't start on the PS5 yet. ([#195](https://github.com/leolobato/playden-ps5/issues/195), firmware 13.00) |-| [CrossCode](https://store.steampowered.com/app/368340) | ⛔ Refused | 0.12 | NW.js | Runs on NW.js (a built-in web browser), which Playden can't start on the PS5 yet. ([#102](https://github.com/leolobato/playden-ps5/issues/102), firmware 13.60) |+| [CrossCode](https://store.steampowered.com/app/368340) | ⛔ Refused | 0.12 | NW.js | Refused on kit 0.12. NW.js games start from kit 0.19; not tested since. ([#102](https://github.com/leolobato/playden-ps5/issues/102), firmware 13.60) || [Crysis 3](https://store.steampowered.com/app/1282690) | ⛔ Refused | 0.17 | — | Needs the EA app. ([#415](https://github.com/leolobato/playden-ps5/issues/415), firmware 12.20) || [FACEMINER](https://store.steampowered.com/app/2276980) | ⛔ Refused | 0.17 | — | Electron game. ([#424](https://github.com/leolobato/playden-ps5/issues/424), firmware 12.20) |-| [Look Outside](https://store.steampowered.com/app/3373660) | ⛔ Refused | 0.10 | RPG Maker (NW.js) · 64-bit | Runs on NW.js (a built-in web browser), which Playden can't start on the PS5 yet. || [Need for Speed Most Wanted](https://store.steampowered.com/app/1262560) | ⛔ Refused | 0.10 | Chameleon · D3D11 · 32-bit | Needs the EA app. |-| [OMORI](https://store.steampowered.com/app/1150690) | ⛔ Refused | 0.11 | RPG Maker (NW.js) · 64-bit | Runs on NW.js (a built-in web browser), which Playden can't start on the PS5 yet. || [The Sims 4](https://store.steampowered.com/app/1222670) | ⛔ Refused | 0.16 | — | Needs the EA app. ([#397](https://github.com/leolobato/playden-ps5/issues/397), firmware 13.60) |## Kitsdiff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex 3c39647..9f4bb97 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -2592,7 +2592,9 @@ void RuntimeHost::RunPlay(Composition& c, std::uint32_t app_id, const std::strinLog("play moved app=" + std::to_string(app_id) + " " + (settings.empty() ? "republished" : settings));}} else if (idle) {- settings = RepublishSettings(c, *record);+ RefreshGeneratedRecipeDefaults(c, *record);+ const auto current = c.records.Find(record->install_id);+ settings = current ? RepublishSettings(c, *current) : std::string("The game's install record is missing.");}// Saves the game wrote and FTP edits made since, once nothing of the bottle is held and// only when Play goes ahead: a refused Play changes no modes.@@ -2952,6 +2954,49 @@ const rt::GameRecipe* RuntimeHost::RecipeForPrepare(Composition& c, const Runtimreturn &c.recipes.back();}+void RuntimeHost::RefreshGeneratedRecipeDefaults(Composition& c, const rt::RuntimeInstall& record) {+ const auto kit = c.kit ? rt::KitCapabilitiesFromManifest(c.kit->capabilities, true) : rt::KitCapabilities{};+ const auto app = std::to_string(record.runtime_number);+ for (auto& candidate : c.recipes) {+ if (candidate.id != record.recipe_id || !RecipeFits(candidate, record)) continue;+ auto refreshed = candidate;+ if (!rt::RefreshRecipeDefaults(HostPath(record.install_path).string(), kit, &refreshed)) return;+ // Settings older than the title's can't be published over it, and a forced publication skips them without a word:+ // the recipe would be marked as refreshed with the old profile still in place.+ const auto stored = config_.settings_record ? config_.settings_record(GameOf(record)) : std::nullopt;+ if (stored ? stored->revision < record.settings_revision : record.settings_revision != 0) {+ Log("generated recipe refresh app=" + app + " waits: saved settings older than the title's");+ return;+ }+ if (c.kit)+ if (const auto lacks = KitLacksForRecipe(refreshed, c.kit->view); !lacks.empty()) {+ Log("generated recipe refresh app=" + app + " refused=" + lacks);+ return;+ }+ const auto before = candidate;+ candidate = std::move(refreshed);+ // Forced because the player's settings didn't change, only what Playden sets up for the game, and a game with no+ // saved settings is published from the defaults. It publishes nothing when the profile comes out the same+ // (arguments the player typed). The recipe is saved only once this worked. A request whose publication never began+ // is dropped, so the game starts as it did and the next Play tries again; one that began waits for recovery, like+ // any settings update.+ const auto refused = PublishSavedSettings(c, record, nullptr, true, nullptr, nullptr, true, true);+ if (!refused.empty()) {+ Log("generated recipe refresh app=" + app + " refused=" + refused);+ for (auto& again : c.recipes)+ if (again.id == before.id) again = before;+ DropUpgradeRequest(c, record.install_id, refused);+ return;+ }+ const auto saved = rt::SerializeGameRecipe(candidate);+ const auto written = c.storage.WriteAtomicPrivate(GeneratedRecipeFile(candidate.id), Bytes(saved.begin(), saved.end()));+ Log("generated recipe refreshed app=" + app + " defaults revision " + std::to_string(before.defaults_revision) + " to " ++ std::to_string(candidate.defaults_revision) + (written.ok() ? std::string() : " not saved: " + written.message()));+ PublishRecipes(c);+ return;+ }+}+void RuntimeHost::LoadGeneratedRecipes(Composition& c) {for (const auto& record : c.repository.Snapshot()) {if (!rt::IsGeneratedRecipeId(record.recipe_id)) continue;@@ -3225,6 +3270,7 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&// 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.{+ if (const auto before = c.records.Find(existing->install_id)) RefreshGeneratedRecipeDefaults(c, *before);const auto current = c.records.Find(existing->install_id);if (!current) return "The game's install record is missing.";bool republished = false;diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hppindex c322f0f..eda116b 100644--- a/src/homebrew/runtime_host.hpp+++ b/src/homebrew/runtime_host.hpp@@ -551,6 +551,9 @@ class RuntimeHost {const runtime::GameRecipe* RecipeForPrepare(Composition& composition, const RuntimePrepareRequest& request,std::string* reason);void LoadGeneratedRecipes(Composition& composition);+ // A generated recipe set up with older defaults for its engine takes the current ones and its title is published+ // again. Nothing of the game may be running. A refusal leaves the game as it was, for the next try.+ void RefreshGeneratedRecipeDefaults(Composition& composition, const runtime::RuntimeInstall& record);void PublishRecipes(const Composition& composition);runtime::PackageActionResult DrivePublication(Composition& composition, const runtime::RuntimeInstall& record);// Moves *next (an install record) to the program and folder the saved settings choose, after checkingdiff --git a/src/runtime/game_probe.cpp b/src/runtime/game_probe.cppindex 7696fdf..4bf55b9 100644--- a/src/runtime/game_probe.cpp+++ b/src/runtime/game_probe.cpp@@ -4,6 +4,7 @@#include <algorithm>#include <array>+#include <cctype>#include <cerrno>#include <cstdint>#include <cstdio>@@ -90,6 +91,8 @@ struct PeFacts {// A writable section shared between processes that doesn't fill whole console pages.bool unaligned_shared = false;bool pe64 = false; // PE32+ (x64), otherwise PE32 (x86)+ std::uint64_t resource_offset = 0; // file offset of the resource directory, 0 when there is none+ std::uint32_t resource_size = 0;std::vector<std::string> imports; // lower casestd::vector<std::string> delay_imports; // lower case; read only when asked};@@ -147,6 +150,11 @@ PeFacts ReadPe(const std::string& path, bool delay_imports = false) {for (const auto& section : list)if (entry >= section.address && entry - section.address < section.size) facts.entry_section = section.name;facts.valid = true;+ if (const auto resource_rva = directory(2))+ if (const auto at = file_offset(resource_rva)) {+ facts.resource_offset = *at;+ facts.resource_size = directories + 2 * 8 + 8 <= optional.size() ? U32(optional.data() + directories + 2 * 8 + 4) : 0;+ }auto descriptor = import_rva ? file_offset(import_rva) : std::nullopt;for (unsigned count = 0; descriptor && count < 512; ++count, *descriptor += 20) {@@ -178,6 +186,53 @@ PeFacts ReadPe(const std::string& path, bool delay_imports = false) {return facts;}+// A library's version from its version resource: the "FileVersion" string, else the fixed file version.+// Empty when it carries neither (or only 0.0.0.0). Only letters, digits, '.' and '-' are kept.+std::string ResourceVersion(const std::string& path) {+ const auto pe = ReadPe(path);+ if (!pe.valid || pe.resource_size == 0) return {};+ std::vector<unsigned char> data(std::min(pe.resource_size, kVersionScanBytes));+ data.resize(Program(path).ReadSome(pe.resource_offset, data.data(), data.size()));+ const auto clean = [](std::string text) {+ std::string out;+ for (char value : text) {+ if (!std::isalnum(static_cast<unsigned char>(value)) && value != '.' && value != '-') break;+ if (out.size() == 32) break;+ out += value;+ }+ return out;+ };+ // A String entry: wLength, wValueLength (characters, with the terminating null), wType, the key, padding to+ // 4 bytes from the entry's start, then the value.+ static const std::string key = [] {+ std::string wide;+ for (char value : std::string_view("FileVersion")) wide += value, wide += '\0';+ return wide + std::string(2, '\0');+ }();+ for (auto at = std::search(data.begin(), data.end(), key.begin(), key.end()); at != data.end();+ at = std::search(at + 2, data.end(), key.begin(), key.end())) {+ const auto start = static_cast<std::size_t>(at - data.begin());+ if (start < 6) continue;+ const std::size_t characters = U16(data.data() + start - 4);+ std::size_t value = start + key.size();+ value += (4 - (value - (start - 6)) % 4) % 4;+ if (characters < 2 || value + characters * 2 > data.size()) continue;+ std::string text;+ for (std::size_t i = 0; i + 1 < characters; ++i)+ text += data[value + i * 2 + 1] == 0 ? static_cast<char>(data[value + i * 2]) : '?';+ if (auto version = clean(text); !version.empty()) return version;+ }+ // VS_FIXEDFILEINFO: the signature, the structure version, then the file version as two 32-bit halves.+ static const unsigned char signature[] = {0xbd, 0x04, 0xef, 0xfe};+ const auto fixed = std::search(data.begin(), data.end(), std::begin(signature), std::end(signature));+ if (fixed == data.end() || data.end() - fixed < 16) return {};+ const auto major = U32(&*fixed + 8), minor = U32(&*fixed + 12);+ if (major == 0 && minor == 0) return {};+ auto version = std::to_string(major >> 16) + '.' + std::to_string(major & 0xffff) + '.' + std::to_string(minor >> 16);+ if (minor & 0xffff) version += '.' + std::to_string(minor & 0xffff);+ return version;+}+// Graphics library names a program loads at run time (Unity, GameMaker and others call// LoadLibrary instead of importing). ASCII and UTF-16, any case.const std::array<std::pair<const char*, const char*>, 9>& Libraries() {@@ -529,6 +584,7 @@ GameProbe ProbeGame(const std::string& install_root, const std::string& executabprobe.steam_stub_detail = stub.detail;}probe.shared_section = program.unaligned_shared;+ probe.x64 = program.pe64;AddImports(program, &probe.apis);for (const auto& [name, directory] : here)if (!directory && EndsWith(Lower(name), ".dll")) AddImports(ReadPe((root / folder / name).string()), &probe.apis);@@ -571,8 +627,11 @@ GameProbe ProbeGame(const std::string& install_root, const std::string& executabprobe.engine = "java";} else if (Find(here, "love.dll", false)) {probe.engine = "love"; // LÖVE draws with OpenGL through SDL, which it loads at run time- } else if (Find(here, "nw.dll", false)) {+ } else if (const auto nw = Find(here, "nw.dll", false)) {probe.engine = "nwjs"; // NW.js (RPG Maker MV and MZ): Chromium with Node+ probe.engine_version = ResourceVersion((root / folder / *nw).string());+ } else if (Find(here, "nw.pak", false)) {+ probe.engine = "nwjs"; // node-webkit before NW.js 0.13 (CrossCode's demo): Chromium built into the program} else if (std::any_of(here.begin(), here.end(), [&](const auto& entry) {if (!entry.second) return false;const auto inside = Entries(root / folder / entry.first);@@ -594,6 +653,12 @@ namespace {bool LegacyDirect3D9(const GameProbe& probe) { return probe.legacy_unity && probe.unity_major < 5; }} // namespace+int DefaultsRevision(std::string_view engine) {+ engine = engine.substr(0, engine.find_first_of(", "));+ if (engine == "nwjs") return 2; // 1: low-end device mode and a larger V8 heap. 2: low-end device mode gone+ return 0;+}+GameDefaults DefaultsFor(const GameProbe& probe, const RuntimeAbilities& runtime) {GameDefaults out;const auto has = [&](const char* api) { return probe.apis.count(api) != 0; };@@ -610,8 +675,19 @@ GameDefaults DefaultsFor(const GameProbe& probe, const RuntimeAbilities& runtimeif (probe.steam_stub && !probe.steam_stub_supported) {out.refusal = "This game's program has Steam DRM in a form Playden can't unpack yet.";} else if (probe.engine == "nwjs") {- // Chromium starts helper processes, and in one process it reserves 64 GB of address space.- out.refusal = "This game runs on NW.js (a built-in web browser), which Playden can't start on the PS5 yet.";+ // Chromium starts helper processes, which a PS5 title can't, so everything runs in the game's+ // process. There Chromium reserves 64 GB of address space, which the kit's high area may now hold.+ // ANGLE draws WebGL with Direct3D 11. 64-bit NW.js plays (Look Outside, NW.js 0.94), and so does a recent 32-bit+ // one (Alabaster Dawn's demo, NW.js 0.86). Older 32-bit builds still stop early (OMORI, from 2017; CrossCode's demo,+ // node-webkit 0.8), but they start like the others. V8 runs out of heap at about 124 MiB without the larger limit in a+ // 32-bit game. A game loading hundreds of files at once needs the kit's direct-memory sections (Wine 0976);+ // --enable-low-end-device-mode in Extra arguments also avoids those failed loads, if a game has to turn them off.+ out.graphics = "dxvk";+ out.arguments = "--single-process --in-process-gpu --no-sandbox --disable-gpu-sandbox --disable-breakpad "+ "--js-flags=--max-old-space-size=1024";+ // On an older runtime the game hangs before its first frame in the default Xbox controller mode.+ if (!runtime.driver_threads)+ out.refusal = "This game runs on NW.js (a built-in web browser), which this runtime kit can't start yet.";} else if (probe.engine == "unity") {// Unity also names d3d12 and Vulkan; D3D11 is the path DXVK covers. Unity 4 and earlier (Hexcells,// Thomas Was Alone) draw with Direct3D 9, where D3D11 was a player option. Unity 5 builds may leave@@ -674,6 +750,7 @@ GameDefaults DefaultsFor(const GameProbe& probe, const RuntimeAbilities& runtimeif (probe.il2cpp) facts += facts.empty() ? "il2cpp" : "-il2cpp";if (LegacyDirect3D9(probe)) facts += "-legacy";else if (probe.legacy_unity) facts += "-legacy5";+ if (!probe.engine_version.empty()) facts += "," + probe.engine + "-" + probe.engine_version;for (const auto& api : probe.apis) facts += (facts.empty() ? "" : ",") + api;// An Unreal 5 game names both renderers; this says which one it starts on.if (probe.unreal5) facts += out.d3d12.empty() ? ",dx11" : ",dx12";@@ -702,6 +779,8 @@ std::string DetectedLabel(const std::string& summary) {{"gamemaker", "GameMaker"}, {"godot", "Godot"}, {"love", "L\xC3\x96VE"}, {"nwjs", "NW.js"}, {"sil", "SIL"},{"idtech3", "id Tech 3"}, {"hashlink", "HashLink"}, {"xna", "XNA"}, {"java", "Java"}})if (facts.count(id)) engine = name;+ for (const auto& fact : facts)+ if (engine == "NW.js" && fact.rfind("nwjs-", 0) == 0) engine += " " + fact.substr(5);std::string api;if (graphics == "opengl") api = "OpenGL";else if (graphics == "dxvk" && engine == "Unreal Engine 5")diff --git a/src/runtime/game_probe.h b/src/runtime/game_probe.hindex 9564eda..3d1a5c5 100644--- a/src/runtime/game_probe.h+++ b/src/runtime/game_probe.h@@ -1,8 +1,10 @@#pragma once#include <cstddef>+#include <cstdint>#include <set>#include <string>+#include <string_view>namespace playden::runtime {@@ -12,6 +14,10 @@ namespace playden::runtime {struct GameProbe {std::string engine; // "unity", "unreal", "source", "gamemaker", "godot", "love", "nwjs", "sil", "idtech3",// "hashlink", "xna", or empty+ // NW.js: nw.dll's version ("0.94.0"), empty when its version resource carries none (2017 builds such as OMORI's)+ // and for node-webkit before NW.js 0.13 (no nw.dll). Logs and the settings sheet show it.+ std::string engine_version;+ bool x64 = false; // the program is PE32+ (x64)bool il2cpp = false; // Unity with GameAssembly.dllbool legacy_unity = false; // Unity before 2017.2: the player is built into the programint unity_major = 0; // for legacy_unity, the Unity version from the data folder (4, 5); 0 when unknown@@ -35,6 +41,8 @@ struct GameProbe {};inline constexpr unsigned long long kProbeScanBytes = 256ull * 1024ull * 1024ull;+// At most this much of a library's resources is read for its version.+inline constexpr std::uint32_t kVersionScanBytes = 8u * 1024u * 1024u;// executable is relative to install_root with '/' separators, as spelled on disk.GameProbe ProbeGame(const std::string& install_root, const std::string& executable);@@ -86,7 +94,8 @@ struct GameDefaults {std::string refusal; // non-empty: the console cannot run this program; a sentence for the player// The refusal comes from a broad detection (.NET, a shared section) that a run could get// past, so the player may "Try anyway"; graphics and arguments are still filled in.- // SteamStub forms Playden can't unpack, NW.js and Direct3D 12 only (on a kit without vkd3d-proton) are never soft.+ // SteamStub forms Playden can't unpack, Direct3D 12 only (on a kit without vkd3d-proton) and NW.js (on a kit+ // without driver threads) are never soft.bool refusal_soft = false;std::string summary; // e.g. "unity,d3d11 graphics=dxvk", for logs and the settings sheet};@@ -95,8 +104,13 @@ struct RuntimeAbilities {bool shared_sections = false; // maps a shared section the console's pages can't hold as a private copybool wine_mono = false; // carries Wine Mono, so .NET programs startbool vkd3d_proton = false; // carries vkd3d-proton, so Direct3D 12 programs draw+ bool driver_threads = false; // hosted driver threads skip the game's thread attach, so NW.js gets past its start};GameDefaults DefaultsFor(const GameProbe& probe, const RuntimeAbilities& runtime = {});+// Which DefaultsFor an engine's games were set up with. Raise an engine's number when what DefaultsFor gives its games+// changes: their saved recipes then take the new defaults on the next Play or kit update, without a Recreate bottle.+// An engine not listed is 0. `engine` may be a GameDefaults::summary, whose first word is the engine.+int DefaultsRevision(std::string_view engine);// The player's words for a GameDefaults::summary: "Unity · Direct3D 11", "OpenGL"; empty// when nothing was recognised.diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cppindex 4a53cc9..bb07221 100644--- a/src/runtime/game_settings.cpp+++ b/src/runtime/game_settings.cpp@@ -1569,6 +1569,12 @@ bool ParseGameRecipe(std::string_view text, GameRecipe* recipe, std::string* rea!StringField(*root, "graphics", &out.graphics, false) ||!StringField(*root, "detected", &out.detected, false))return fail("recipe has a field of the wrong type");+ if (const auto* revision = root->get("defaults_revision")) {+ std::uint64_t parsed_revision = 0;+ if (!ExactUnsigned(revision, static_cast<std::uint64_t>(std::numeric_limits<int>::max()), &parsed_revision, false))+ return fail("recipe has a field of the wrong type");+ out.defaults_revision = static_cast<int>(parsed_revision);+ }const auto* entries = root->get("launch_entries");if (!entries || !entries->array() || entries->array()->empty()) return fail("recipe needs launch_entries");for (const auto& item : *entries->array()) {@@ -1787,7 +1793,10 @@ std::string SerializeGameRecipe(const GameRecipe& recipe) {quoted(recipe.resolution_arguments) + ",\"dll_overrides\":" + quoted(recipe.dll_overrides) +",\"architecture\":" + quoted(recipe.architecture) + ",\"runtime\":" + quoted(recipe.runtime) +",\"prefix\":" + quoted(recipe.prefix) + ",\"graphics\":" + quoted(recipe.graphics) +- (recipe.detected.empty() ? std::string() : ",\"detected\":" + quoted(recipe.detected)) + ",\"defaults\":{";+ (recipe.detected.empty() ? std::string() : ",\"detected\":" + quoted(recipe.detected)) ++ (recipe.defaults_revision == 0 ? std::string()+ : ",\"defaults_revision\":" + std::to_string(recipe.defaults_revision)) ++ ",\"defaults\":{";bool first = true;for (const auto& [id, value] : recipe.defaults) {if (!first) text += ",";@@ -2073,6 +2082,7 @@ bool GenerateGameRecipe(const GameId& game, std::uint32_t runtime_number, constabilities.shared_sections = kit.shared_sections;abilities.wine_mono = kit.wine_mono;abilities.vkd3d_proton = kit.vkd3d_proton;+ abilities.driver_threads = kit.driver_threads;const auto defaults = DefaultsFor(probe, abilities);if (!defaults.refusal.empty() && !(defaults.refusal_soft && choices.try_anyway)) {if (first_refusal.empty()) first_refusal = defaults.refusal, first_refusal_soft = defaults.refusal_soft;@@ -2098,6 +2108,7 @@ bool GenerateGameRecipe(const GameId& game, std::uint32_t runtime_number, constout.arguments = defaults.arguments;out.resolution_arguments = defaults.resolution_arguments;out.detected = defaults.summary;+ out.defaults_revision = DefaultsRevision(defaults.summary);// Most Steam games stop when the Steam client is missing; the emulator answers instead.out.defaults["steam_features"] = "emulate";if (!defaults.environment.empty()) out.defaults["environment"] = defaults.environment;@@ -2141,6 +2152,35 @@ bool GenerateGameRecipe(const GameId& game, std::uint32_t runtime_number, constreturn true;}+bool RefreshRecipeDefaults(const std::string& install_root, const KitCapabilities& kit, GameRecipe* recipe) {+ if (!IsGeneratedRecipeId(recipe->id) || recipe->launch_entries.empty() ||+ recipe->defaults_revision >= DefaultsRevision(recipe->detected))+ return false;+ const auto relative = steam::RelativeGamePath(recipe->launch_entries.front().executable);+ const auto on_disk = relative ? ResolveGameFile(install_root, *relative) : std::nullopt;+ if (!on_disk) return false;+ RuntimeAbilities abilities;+ abilities.shared_sections = kit.shared_sections;+ abilities.wine_mono = kit.wine_mono;+ abilities.vkd3d_proton = kit.vkd3d_proton;+ abilities.driver_threads = kit.driver_threads;+ const auto defaults = DefaultsFor(ProbeGame(install_root, *on_disk), abilities);+ auto refreshed = *recipe;+ refreshed.graphics = defaults.graphics;+ refreshed.arguments = defaults.arguments;+ refreshed.resolution_arguments = defaults.resolution_arguments;+ refreshed.detected = defaults.summary;+ refreshed.defaults_revision = DefaultsRevision(defaults.summary);+ if (defaults.environment.empty()) refreshed.defaults.erase("environment");+ else refreshed.defaults["environment"] = defaults.environment;+ if (defaults.d3d12.empty()) refreshed.defaults.erase("d3d12");+ else refreshed.defaults["d3d12"] = defaults.d3d12;+ // The files no longer show this engine (an update changed it): that's for the files-changed path, not this one.+ if (refreshed.defaults_revision < DefaultsRevision(recipe->detected)) return false;+ *recipe = std::move(refreshed);+ return true;+}+std::string GameProgramArchitecture(const std::string& install_root, const std::string& relative) {const auto path = steam::RelativeGamePath(relative);if (!path) return {};@@ -2157,6 +2197,7 @@ std::string GameProgramRefusal(const std::string& install_root, const std::strinabilities.shared_sections = kit.shared_sections;abilities.wine_mono = kit.wine_mono;abilities.vkd3d_proton = kit.vkd3d_proton;+ abilities.driver_threads = kit.driver_threads;const auto defaults = DefaultsFor(ProbeGame(install_root, *on_disk), abilities);return defaults.refusal_soft && try_anyway ? std::string() : defaults.refusal;}@@ -2199,6 +2240,7 @@ std::vector<GameProgram> ListGamePrograms(const std::string& install_root, constabilities.shared_sections = kit.shared_sections;abilities.wine_mono = kit.wine_mono;abilities.vkd3d_proton = kit.vkd3d_proton;+ abilities.driver_threads = kit.driver_threads;for (const auto& relative : found) {GameProgram program;program.path = relative;@@ -3267,6 +3309,7 @@ KitCapabilities KitCapabilitiesFromManifest(const std::vector<std::string>& capakit.opengl_zink = has(kKitOpenGLZink);kit.wine_mono = has(kKitWineMono);kit.vkd3d_proton = has(kKitVkd3dProton);+ kit.driver_threads = has(kKitDriverThreads);kit.display_120hz = has(kKitDisplay120Hz);kit.profile_version_2 = has(kKitProfileVersion2);kit.input_rumble = has(kKitInputRumble);diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.hindex eef5318..510f377 100644--- a/src/runtime/game_settings.h+++ b/src/runtime/game_settings.h@@ -61,6 +61,7 @@ struct KitCapabilities {bool opengl_zink = false; // OpenGL games draw through Mesa's Zink, not the PS5 OpenGL SDKbool wine_mono = false; // .NET programs start on the kit's Wine Monobool vkd3d_proton = false; // the kit's runtime carries vkd3d-proton's Direct3D 12 DLLs+ bool driver_threads = false; // threads started in a hosted driver skip the game's thread attach (NW.js)// [display] refresh on every graphics path and [display] frame_rate (paced by the display). Counts only for a title// that runs this kit's runtime: an older runtime refuses a profile with frame_rate (KitForTitleRuntime).bool display_120hz = false;@@ -181,6 +182,7 @@ struct GameRecipe {std::map<std::string, std::string> defaults; // setting id -> valuestd::set<std::string> locked; // setting ids the player cannot changestd::string detected; // generated recipes: what the game's files showed (GameDefaults::summary)+ int defaults_revision = 0; // generated recipes: the DefaultsRevision of the defaults above// Values the bottle's user.reg gets when the game's files are prepared, as a Steam install// script's would be (docs/community-recipes.md): strings under HKEY_CURRENT_USER.std::vector<RegistryValue> registry;@@ -348,6 +350,11 @@ std::string SerializeGameRecipe(const GameRecipe& recipe);std::string GeneratedRecipeId(std::uint32_t app_id);// "steam-<app id>-auto" or "local-<uuid>-auto".bool IsGeneratedRecipeId(std::string_view id);+// A generated recipe set up with older defaults for its engine (DefaultsRevision) takes the current ones from its+// program's files: arguments, graphics and what those imply. Its id, version and programs stay, and what the player+// changed is kept apart from the recipe, so it still wins. False when nothing changed, also when the program can't be+// read now (a drive not plugged in): the next Play tries again.+bool RefreshRecipeDefaults(const std::string& install_root, const KitCapabilities& kit, GameRecipe* recipe);// A community recipe (community-<app id>, docs/community-recipes.md). Like a generated one, it// is not a shipped recipe, so it does not force the game's own Steam library.bool IsCommunityRecipeId(std::string_view id);@@ -362,8 +369,8 @@ RecipeChoices RecipeChoicesFrom(const GameSettingsRecord& record);// Builds that recipe from Steam's launch options (default first). Entries whose executable is// not a game-relative .exe are skipped. The architecture comes from the first usable entry's// PE header under install_root; entries built for the other architecture are skipped, and so-// are programs the console cannot run (SteamStub, NW.js, Direct3D 12 only, and .NET or a-// shared section unless the player chose "Try anyway"). An Unreal root program from Steam is+// are programs the console cannot run (SteamStub, Direct3D 12 only, NW.js on an older kit, and+// .NET or a shared section unless the player chose "Try anyway"). An Unreal root program from Steam is// replaced by its *-Shipping.exe. The player's program comes first and Steam's entries stay// as suggestions. On failure, reason is a short sentence for the player and refusal_soft// says whether "Try anyway" or another program could get past it.@@ -566,6 +573,9 @@ inline constexpr const char* kKitWineMono = "wine-mono";// Runtime ability: the kit's runtime carries vkd3d-proton's d3d12.dll and d3d12core.dll at// lib/vkd3d-proton/<arch>-windows, for games that draw with Direct3D 12 (with DXVK's dxgi).inline constexpr const char* kKitVkd3dProton = "vkd3d-proton";+// Runtime ability: threads that start in ntoskrnl.exe or a driver skip DLL_THREAD_ATTACH and TLS callbacks, as Windows'+// system threads do, so a game's TLS callback can't stop its start in Xbox controller mode (NW.js).+inline constexpr const char* kKitDriverThreads = "wine-driver-threads";// The runtime honors [display] refresh = 60|120 on every graphics path (Wine reports the rate it asked for) and// [display] frame_rate = 0|120|60|40|30, which the display paces. Runtimes without it refuse a profile with frame_rate.inline constexpr const char* kKitDisplay120Hz = "display-120hz";diff --git a/src/runtime/kit_trust.cpp b/src/runtime/kit_trust.cppindex ca6b7dc..2857bc7 100644--- a/src/runtime/kit_trust.cpp+++ b/src/runtime/kit_trust.cpp@@ -16,7 +16,7 @@ KitAdmissionConfig DevelopmentKitAdmission() {kKitInputWheel, kKitEnvironment, kKitWineMono, kKitVkd3dProton,kKitDisplay120Hz, kKitProfileVersion2, kKitInputRumble,kKitDisplayFramegen, kKitDisplayFpsCounter, kKitLauncherMode,- kKitInputPlaystation};+ kKitInputPlaystation, kKitDriverThreads};std::sort(config.known_capabilities.begin(), config.known_capabilities.end());return config;}diff --git a/tests/game_probe_test.cpp b/tests/game_probe_test.cppindex e6543ed..8555a12 100644--- a/tests/game_probe_test.cpp+++ b/tests/game_probe_test.cpp@@ -33,6 +33,7 @@ struct PeSpec {std::size_t data_at = 0x1400; // file offset of the section holding the import tablebool shared_data = false; // the data section is writable and shared, on 4 KB pagesstd::vector<std::string> delay_imports; // delay-loaded DLLs (descriptors at RVA 0x2a00)+ std::string resource; // the resource directory's bytes, at RVA 0x2c00 (at most 0x400)};void Put32(std::string* bytes, std::size_t at, std::uint32_t value) {@@ -84,6 +85,11 @@ void WritePe(const fs::path& path, const PeSpec& spec) {bytes.replace(spec.data_at + (name_rva - 0x2000), spec.delay_imports[i].size(), spec.delay_imports[i]);name_rva += static_cast<std::uint32_t>(spec.delay_imports[i].size() + 1);}+ if (!spec.resource.empty()) {+ Put32(&bytes, directories + 2 * 8, 0x2c00);+ Put32(&bytes, directories + 2 * 8 + 4, static_cast<std::uint32_t>(spec.resource.size()));+ bytes.replace(spec.data_at + 0xc00, spec.resource.size(), spec.resource);+ }std::ofstream(path, std::ios::binary) << bytes;}@@ -98,6 +104,26 @@ void Write(const fs::path& path, const std::string& bytes) {std::ofstream(path, std::ios::binary | std::ios::trunc) << bytes;}+// A version resource's FileVersion String entry (key, padding, value), and its VS_FIXEDFILEINFO.+std::string FileVersionString(const std::string& value) {+ std::string entry(6, '\0');+ entry += Wide("FileVersion") + std::string(2, '\0');+ entry.resize((entry.size() + 3) / 4 * 4, '\0');+ entry += Wide(value) + std::string(2, '\0');+ Put16(&entry, 0, static_cast<std::uint16_t>(entry.size()));+ Put16(&entry, 2, static_cast<std::uint16_t>(value.size() + 1));+ Put16(&entry, 4, 1);+ return std::string(10, 'x') + entry; // anywhere in the resources+}+std::string FixedFileInfo(std::uint32_t major, std::uint32_t minor) {+ std::string info(52, '\0');+ Put32(&info, 0, 0xfeef04bd);+ Put32(&info, 4, 0x10000);+ Put32(&info, 8, major);+ Put32(&info, 12, minor);+ return std::string(4, 'x') + info;+}+void Touch(const fs::path& path) {fs::create_directories(path.parent_path());std::ofstream(path) << "x";@@ -379,12 +405,115 @@ int main() {CHECK(defaults.graphics == "opengl" && defaults.summary.rfind("sil,", 0) == 0);CHECK(DetectedLabel(defaults.summary) == "SIL \xC2\xB7 OpenGL");}- { // NW.js (Look Outside, RPG Maker MZ) is refused: Chromium can't start on the console.+ { // 64-bit NW.js (Look Outside, RPG Maker MZ) runs Chromium in one process on DXVK.const auto root = fresh();WritePe(root / "Game.exe", {true, {"nw.dll", "KERNEL32.dll"}});WritePe(root / "nw.dll", {true, {"dxgi.dll", "KERNEL32.dll"}});- const auto defaults = DefaultsFor(ProbeGame(root.string(), "Game.exe"));- CHECK(defaults.refusal.find("NW.js") != std::string::npos && defaults.summary.rfind("nwjs,", 0) == 0);+ RuntimeAbilities abilities;+ abilities.driver_threads = true;+ const auto defaults = DefaultsFor(ProbeGame(root.string(), "Game.exe"), abilities);+ CHECK(defaults.refusal.empty());+ CHECK(defaults.summary.rfind("nwjs,", 0) == 0 && defaults.graphics == "dxvk");+ CHECK(defaults.arguments.find("--single-process") != std::string::npos);+ CHECK(defaults.arguments.find("--enable-low-end-device-mode") == std::string::npos);+ CHECK(defaults.arguments.find("--js-flags=--max-old-space-size=1024") != std::string::npos);+ // On a kit without it the game would hang in Xbox controller mode, so it stays refused.+ const auto older_kit = DefaultsFor(ProbeGame(root.string(), "Game.exe"));+ CHECK(older_kit.refusal.find("this runtime kit can't start") != std::string::npos && !older_kit.refusal_soft);+ CHECK(KitCapabilitiesFromManifest({"dxvk", kKitDriverThreads}, false).driver_threads);+ CHECK(!KitCapabilitiesFromManifest({"dxvk"}, false).driver_threads);+ }+ { // 32-bit NW.js starts like 64-bit, on a kit with driver threads and with no "Try anyway". Older builds still stop.+ const auto root = fresh();+ WritePe(root / "OMORI.exe", {false, {"nw.dll", "KERNEL32.dll"}});+ WritePe(root / "nw.dll", {false, {"d3d11.dll", "dxgi.dll", "KERNEL32.dll"}});+ RuntimeAbilities abilities;+ abilities.driver_threads = true;+ const auto defaults = DefaultsFor(ProbeGame(root.string(), "OMORI.exe"), abilities);+ CHECK(defaults.refusal.empty() && !defaults.refusal_soft);+ CHECK(defaults.graphics == "dxvk" && defaults.arguments.find("--single-process") != std::string::npos);+ const auto older_kit = DefaultsFor(ProbeGame(root.string(), "OMORI.exe"));+ CHECK(older_kit.refusal.find("this runtime kit can't start") != std::string::npos && !older_kit.refusal_soft);+ }+ { // A saved recipe set up with older defaults for its engine takes the current ones, and keeps what it is.+ const auto root = fresh();+ WritePe(root / "Game.exe", {true, {"nw.dll", "KERNEL32.dll"}});+ WritePe(root / "nw.dll", {true, {"dxgi.dll", "KERNEL32.dll"}});+ KitCapabilities kit;+ kit.driver_threads = true;+ GameRecipe recipe;+ std::string reason;+ CHECK(GenerateGameRecipe(3373660, "Look Outside", {{"", "", "Game.exe", "", ""}}, root.string(), &recipe, &reason, kit));+ // Changed these arguments? Raise DefaultsRevision("nwjs") too, so games already set up take them.+ CHECK(DefaultsRevision("nwjs") == 2);+ CHECK(recipe.arguments == "--single-process --in-process-gpu --no-sandbox --disable-gpu-sandbox --disable-breakpad "+ "--js-flags=--max-old-space-size=1024");+ CHECK(recipe.defaults_revision == 2 && !RefreshRecipeDefaults(root.string(), kit, &recipe));+ GameRecipe saved;+ CHECK(ParseGameRecipe(SerializeGameRecipe(recipe), &saved, &reason) && saved.defaults_revision == 2);++ // As a recipe from before the revisions reads: no number, the old arguments.+ auto old = recipe;+ old.defaults_revision = 0;+ old.arguments = "--single-process";+ CHECK(ParseGameRecipe(SerializeGameRecipe(old), &saved, &reason) && saved.defaults_revision == 0);+ CHECK(SerializeGameRecipe(old).find("defaults_revision") == std::string::npos);+ auto missing = old;+ CHECK(!RefreshRecipeDefaults((root / "not-plugged-in").string(), kit, &missing) && missing.arguments == old.arguments);+ CHECK(RefreshRecipeDefaults(root.string(), kit, &old));+ CHECK(old.arguments == recipe.arguments && old.defaults_revision == 2);+ CHECK(old.id == recipe.id && old.version == recipe.version && old.launch_entries.size() == recipe.launch_entries.size());+ CHECK(!RefreshRecipeDefaults(root.string(), kit, &old));++ // A recipe Playden didn't generate, and an engine whose defaults never changed, stay as they are.+ auto shipped = recipe;+ shipped.id = "steam-3373660-shipped-v1";+ shipped.defaults_revision = 0;+ shipped.arguments = "--mine";+ CHECK(!RefreshRecipeDefaults(root.string(), kit, &shipped) && shipped.arguments == "--mine");+ auto unity = recipe;+ unity.detected = "unity,d3d11 graphics=dxvk";+ unity.defaults_revision = 0;+ unity.arguments = "-force-d3d11";+ CHECK(!RefreshRecipeDefaults(root.string(), kit, &unity) && unity.arguments == "-force-d3d11");+ CHECK(DefaultsRevision("unity,d3d11 graphics=dxvk") == 0 && DefaultsRevision("nwjs,nwjs-0.86,d3d11") == 2);+ }+ { // node-webkit before NW.js 0.13 (CrossCode's demo): Chromium in the program, nw.pak beside it, no nw.dll.+ const auto root = fresh();+ WritePe(root / "crosscode-beta.exe", {false, {"KERNEL32.dll"}});+ Touch(root / "nw.pak");+ Touch(root / "libGLESv2.dll");+ const auto probe = ProbeGame(root.string(), "crosscode-beta.exe");+ CHECK(probe.engine == "nwjs" && probe.engine_version.empty() && !probe.x64);+ RuntimeAbilities abilities;+ abilities.driver_threads = true;+ CHECK(DefaultsFor(probe, abilities).refusal.empty());+ }+ { // NW.js's version comes from nw.dll's FileVersion string (Look Outside: 0.94.0) and shows on the settings sheet.+ const auto root = fresh();+ WritePe(root / "Game.exe", {true, {"nw.dll", "KERNEL32.dll"}});+ PeSpec nw{true, {"dxgi.dll", "KERNEL32.dll"}};+ nw.resource = FixedFileInfo(0, 0) + FileVersionString("0.94.0");+ WritePe(root / "nw.dll", nw);+ const auto probe = ProbeGame(root.string(), "Game.exe");+ CHECK(probe.engine == "nwjs" && probe.engine_version == "0.94.0");+ const auto defaults = DefaultsFor(probe);+ CHECK(defaults.summary == "nwjs,nwjs-0.94.0,dxgi graphics=dxvk");+ CHECK(DetectedLabel(defaults.summary) == "NW.js 0.94.0 \xC2\xB7 Direct3D 11");+ }+ { // Without a FileVersion string, the fixed file version; a build with neither (OMORI's) has no version.+ const auto root = fresh();+ WritePe(root / "Game.exe", {false, {"nw.dll", "KERNEL32.dll"}});+ PeSpec nw{false, {"dxgi.dll", "KERNEL32.dll"}};+ nw.resource = FixedFileInfo(29, 4u << 16);+ WritePe(root / "nw.dll", nw);+ CHECK(ProbeGame(root.string(), "Game.exe").engine_version == "0.29.4");+ nw.resource = FixedFileInfo(0, 0) + FileVersionString("");+ WritePe(root / "nw.dll", nw);+ const auto probe = ProbeGame(root.string(), "Game.exe");+ CHECK(probe.engine == "nwjs" && probe.engine_version.empty());+ CHECK(DefaultsFor(probe).summary == "nwjs,dxgi graphics=dxvk");+ CHECK(DetectedLabel(DefaultsFor(probe).summary) == "NW.js \xC2\xB7 Direct3D 11");}{ // An Unreal root program is replaced by its Shipping program, which starts in its own folder.const auto root = fresh();diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cppindex 19cc3ac..7ef2b92 100644--- a/tests/game_settings_test.cpp+++ b/tests/game_settings_test.cpp@@ -641,6 +641,16 @@ int main(int argc, char** argv) {CHECK(BuildEffectiveSettings(gdi, nullptr, {{"performance_overlay", "on"}}, KitCapabilities{}, &settings, &error));CHECK(!settings.values.at("performance_overlay").available && Value(settings, "performance_overlay") == "off");+ // The switch that keeps a game off the kit's direct-memory sections reaches the title as [debug] env.+ {+ KitCapabilities debug_kit;+ debug_kit.environment = true;+ debug_kit.opengl_zink = true;+ CHECK(BuildEffectiveSettings(hl2, nullptr, {{"environment", "PW_SECTIONS_FLEXIBLE=1"}}, debug_kit, &settings, &error));+ CHECK(RenderProsperoProfile(hl2, settings, target, &profile, &reason));+ CHECK(profile.text.find("env = PW_SECTIONS_FLEXIBLE=1\n") != std::string::npos);+ }+// Environment variables need a runtime that reads [environment]; released ones refuse it.const std::map<std::string, std::string> environment = {{"environment", "WINE_CPU_TOPOLOGY=4:0,1,2,3; DXVK_FRAME_RATE = 45"}};CHECK(BuildEffectiveSettings(hl2, nullptr, environment, KitCapabilities{}, &settings, &error));diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cppindex 5ca4588..9154816 100644--- a/tests/homebrew_runtime_host_test.cpp+++ b/tests/homebrew_runtime_host_test.cpp@@ -1577,6 +1577,119 @@ void PreparesGameWithoutShippedRecipe() {legacy.Shutdown();}+// A game set up before Playden's defaults for its engine changed takes the new ones on the next Play: its saved+// recipe is refreshed and its title published again, with no Recreate bottle, and a player's extra arguments stay.+// A game with no saved settings takes them too (1). Settings older than the title's can't be published, so the recipe+// keeps its old number (2). A publication refused before it began leaves nothing on the record: that Play starts the+// game as before, and the next one takes the new defaults (3).+void OlderEngineDefaultsArePublishedOnPlay(int scenario) {+ 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");+ };+ auto kit = SyntheticKit(fixture.root / "kit");+ kit.capabilities.push_back("wine-driver-threads");+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };+ unsigned uuids = 0;+ config.uuid = [&uuids]() -> std::optional<std::string> {+ ++uuids; return std::string("00000000-0000-4000-8000-0000000000") + (uuids < 10 ? "0" : "") + std::to_string(uuids);+ };+ config.unix_time = [] { return std::int64_t{1760000000}; };+ config.session_data_root = fixture.root / "data";+ config.launch_title = [](const std::string&, const std::vector<std::string>&) { return TitleResult{true, 0, "launch"}; };+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/4244";+ std::string pe(0x80 + 26, '\0');+ pe[0] = 'M'; pe[1] = 'Z'; pe[0x3c] = 0x40; pe[0x40] = 'P'; pe[0x41] = 'E';+ pe[0x44] = 0x64; pe[0x45] = static_cast<char>(0x86); pe[0x40 + 24] = 0x0b; pe[0x40 + 25] = 0x02;+ Write(game / "Game.exe", pe, 0644);+ Write(game / "nw.dll", pe, 0644);+ CHECK(chmod(game.c_str(), 0755) == 0);+ GameSettingsRecord saved;+ // Published first with the old arguments, as a build from before these flags left it.+ const std::string old_arguments = "--single-process --in-process-gpu --no-sandbox --disable-gpu-sandbox --disable-breakpad";+ saved.overrides["arguments"] = old_arguments;+ if (scenario == 2) saved.revision = 5;+ bool no_record = false;+ config.settings_record = [&](const playden::GameId&) -> std::optional<GameSettingsRecord> {+ if (no_record) return std::nullopt;+ return saved;+ };+ RuntimePrepareRequest request{4244, "/data/homebrew/FAKE77031/games/4244", "internal", "NW Game"};+ request.launches = {{"", "", "Game.exe", "", ""}};+ const auto profile = fixture.root / "data/playden/games/steam-4244/library/profiles/playden-steam-4244.profile";+ const auto recipe_file = fixture.root / "data/runtime-state/recipe-steam-4244-auto.json";+ const std::string new_flag = "--js-flags=--max-old-space-size=1024";+ {+ RuntimeHost host(config);+ CHECK(host.Start());+ CHECK(WaitFor(host, Started).kit_available);+ host.Prepare(request);+ const auto ready = WaitFor(host, [](const RuntimeSnapshot& s) {+ return !s.preparing_app && (s.refusals.count(4244) || (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));+ }, 60);+ if (ready.refusals.count(4244)) std::fprintf(stderr, "Prepare refused: %s\n", ready.refusals.at(4244).c_str());+ CHECK(ready.installs.size() == 1 && ready.installs[0].state == PreparationState::kReady);+ CHECK(Read(profile).find(new_flag) == std::string::npos && Read(profile).find(old_arguments) != std::string::npos);+ host.Shutdown();+ }++ // The saved recipe as that build wrote it: the old arguments, no number. The arguments were never the player's.+ saved.overrides.erase("arguments");+ auto recipe_text = Read(recipe_file);+ const auto cut = [&](const std::string& what) {+ const auto at = recipe_text.find(what);+ CHECK(at != std::string::npos);+ recipe_text.erase(at, what.size());+ };+ cut(" --js-flags=--max-old-space-size=1024");+ cut(",\"defaults_revision\":2");+ CHECK(chmod(recipe_file.c_str(), 0600) == 0);+ Write(recipe_file, recipe_text, 0600);++ no_record = scenario == 1;+ if (scenario == 2) saved.revision = 1;+ const auto operation = fixture.root / "data/playden/games/steam-4244/.playden-control/settings-operation.v1";+ if (scenario == 3) {+ fs::remove(operation);+ fs::create_symlink("settings-operation.gone.v1", operation);+ }++ const auto play = [&](RuntimeHost& host) {+ CHECK(host.Start());+ const auto started = WaitFor(host, [](const RuntimeSnapshot& s) { return Started(s) && !s.generated_recipes.empty(); });+ CHECK(started.generated_recipes[0].defaults_revision == 0);+ host.Play(4244);+ const auto played = WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready || s.play_refusals.count(4244) != 0; }, 30);+ if (played.play_refusals.count(4244)) std::fprintf(stderr, "Play refused: %s\n", played.play_refusals.at(4244).c_str());+ CHECK(played.handoff_ready);+ return played;+ };+ if (scenario == 2 || scenario == 3) {+ RuntimeHost host(config);+ const auto played = play(host);+ CHECK(played.generated_recipes[0].defaults_revision == 0);+ CHECK(Read(recipe_file).find(new_flag) == std::string::npos);+ CHECK(Read(profile).find(new_flag) == std::string::npos);+ CHECK(Read(fixture.root / "data/runtime-state/installs.json").find("\"journal\":{") == std::string::npos);+ host.Shutdown();+ if (scenario == 2) return;+ fs::remove(operation);+ }+ RuntimeHost host(config);+ const auto played = play(host);+ CHECK(played.generated_recipes[0].defaults_revision == 2);+ CHECK(Read(recipe_file).find(new_flag) != std::string::npos);+ CHECK(Read(profile).find(new_flag) != std::string::npos);+ host.Shutdown();+}+// An update changed a Ready game's files (its marker in the game's folder): Play refuses until Prepare has// made the launch again from the new files and Steam's options, as a fresh preparation would, and published// it; then the marker goes. A program that is gone with no other to start keeps the marker and says why.@@ -6292,6 +6405,7 @@ int main(int argc, char** argv) {AnyTitleKitMakesTheGameItsOwnTitle();PreparationEndsAwaitingRegistration();PreparesGameWithoutShippedRecipe();+ for (int scenario = 0; scenario <= 3; ++scenario) OlderEngineDefaultsArePublishedOnPlay(scenario);UpdatedFilesSetUpTheLaunchAgain();PreparesProgramChosenInSettings();PreparesSteamProgramChosenAfterDownload();