Play your Steam library's Windows games on a jailbroken PS5.
C++
Start Steam entries without a folder in the install root
Leonardo Lobato8d8e36b610b8
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex 6da4804..53a39c3 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -742,6 +742,7 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::strview.launch_entry_id = record.launch_entry_id;view.launch_path = record.launch_path;view.launch_working_directory = record.launch_working_directory;+ view.launch_in_install_root = record.launch_in_install_root;std::error_code error;for (std::filesystem::directory_iterator it(SaveBackupRoot(record.install_id), error), end; !error && it != end;it.increment(error)) {@@ -821,8 +822,9 @@ rt::PackageActionResult RuntimeHost::DrivePublication(Composition& c, const rt::// With no working folder set, the profile runs the program from its own folder// (prospero_profile.cpp), so that is where dxvk.conf goes.-static std::string WorkingFolder(const std::string& working, std::string program) {+static std::string WorkingFolder(const std::string& working, std::string program, bool in_install_root) {if (!working.empty() && working != ".") return working;+ if (in_install_root) return {};std::replace(program.begin(), program.end(), '\\', '/');const auto slash = program.rfind('/');return slash == std::string::npos ? std::string() : program.substr(0, slash);@@ -886,7 +888,8 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstif (rt::BuildEffectiveSettings(*recipe, preset, saved.overrides, kit, &desired, &ignored) && desired.launch) {const auto& launch = *desired.launch;if (launch.id != record.launch_entry_id || !same(launch.executable, record.launch_path) ||- !same(launch.working_directory, record.launch_working_directory)) {+ !same(launch.working_directory, record.launch_working_directory) ||+ launch.in_install_root != record.launch_in_install_root) {const auto root = HostPath(record.install_path).string();const auto architecture = rt::GameProgramArchitecture(root, launch.executable);if (architecture.empty())@@ -896,7 +899,7 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstreturn refusal;// Checked here, before a publication starts: one that fails part way leaves the title// waiting for recovery.- const auto folder = WorkingFolder(launch.working_directory, launch.executable);+ const auto folder = WorkingFolder(launch.working_directory, launch.executable, launch.in_install_root);struct stat folder_info{};if (!folder.empty() && (lstat((HostPath(record.install_path) / folder).c_str(), &folder_info) != 0 ||!S_ISDIR(folder_info.st_mode)))@@ -904,12 +907,14 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstconst auto records_ownership = platform::RecordsOwnership(HostPath(record.install_path));if (records_ownership && *records_ownership)if (const auto refused = TightenWorkingFolder(HostPath(record.install_path),- WorkingFolder(launch.working_directory, launch.executable));+ WorkingFolder(launch.working_directory, launch.executable,+ launch.in_install_root));!refused.empty())return refused;next.launch_entry_id = launch.id;next.launch_path = launch.executable;next.launch_working_directory = launch.working_directory == "." ? std::string() : launch.working_directory;+ next.launch_in_install_root = launch.in_install_root && next.launch_working_directory.empty();// The recipe stays the one the game was prepared with: its graphics and engine arguments// came from the first program's files, and only a preparation sees Steam's launch options.Log("program switch app=" + std::to_string(record.app_id) + " from=" + record.launch_entry_id + ":" +@@ -934,7 +939,8 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst} else {overrides.erase("program");}- overrides["program_folder"] = next.launch_working_directory;+ // "." is the install root, empty the program's own folder (BuildEffectiveSettings).+ overrides["program_folder"] = next.launch_in_install_root ? std::string(".") : next.launch_working_directory;input.preset = preset;input.kit = kit;input.target = {next.default_profile_id, next.install_path};@@ -1422,7 +1428,8 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&}}if (existing) {- if (const auto refused = tighten_working(WorkingFolder(existing->launch_working_directory, existing->launch_path));+ if (const auto refused = tighten_working(WorkingFolder(existing->launch_working_directory, existing->launch_path,+ existing->launch_in_install_root));!refused.empty())return refused;}@@ -1615,7 +1622,8 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&if (!refusal.empty()) return refusal;}}- if (const auto refused = tighten_working(WorkingFolder(launch.working_directory, launch.executable)); !refused.empty())+ if (const auto refused = tighten_working(WorkingFolder(launch.working_directory, launch.executable, launch.in_install_root));+ !refused.empty())return refused;rt::ReserveRequest reserve;reserve.install_id = InstallId(request.app_id);@@ -1628,6 +1636,7 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&reserve.launch_entry_id = launch.id;reserve.launch_path = launch.executable;reserve.launch_working_directory = launch.working_directory;+ reserve.launch_in_install_root = launch.in_install_root;reserve.install_path = request.install_path;reserve.volume_id = request.volume_id;// Titles removed during this run go last: a kit with fixed titles still gets one back.@@ -1912,7 +1921,8 @@ std::string RuntimeHost::RunMaintenance(Composition& c, std::uint32_t app, Runtireturn published ? "Settings applied." : "Settings are up to date.";}case RuntimeMaintenance::kClearShaderCache: {- rt::LaunchEntry launch{record->launch_entry_id, {}, record->launch_path, record->launch_working_directory, {}};+ rt::LaunchEntry launch{record->launch_entry_id, {}, record->launch_path, record->launch_working_directory, {},+ record->launch_in_install_root};std::string reason;if (!rt::ClearShaderCache(launch, HostPath(record->install_path).string(), &reason))return "The shader cache could not be cleared: " + reason + ".";diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hppindex c36fed8..f69ce86 100644--- a/src/homebrew/runtime_host.hpp+++ b/src/homebrew/runtime_host.hpp@@ -146,7 +146,8 @@ struct RuntimeInstallView {std::uint64_t settings_revision = 0;std::string launch_entry_id;std::string launch_path; // its program, relative to the install root- std::string launch_working_directory; // its folder; empty: the program's own+ std::string launch_working_directory; // its folder; empty: the program's own, or the install root:+ bool launch_in_install_root = false; // a Steam entry that names no folder starts there// Save backups kept for the game, and when the newest was made (Unix time).std::size_t save_backups = 0;std::int64_t latest_save_backup = 0;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex a3beb2e..093eab5 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -2976,7 +2976,8 @@ void Simulation::rebuild_view() {else if (!settings_values.launch) item.subtitle = "Pick the game's program from its folder.";}else if (id.rfind("button.", 0) == 0) item.value = binding_label(value.value);- else if (id == "program_folder") item.value = value.value.empty() ? "Program's folder" : value.value;+ else if (id == "program_folder")+ item.value = value.value.empty() ? "Program's folder" : value.value == "." ? "Game folder" : value.value;else if (definition->kind == rt::SettingKind::kText) item.value = value.value.empty() ? "Empty" : value.value;else item.value = choice_label(*definition, value.value);item.badge = value.unlocked ? "Changed anyway" : value.locked ? "Required by this game"diff --git a/src/runtime/game_install.cpp b/src/runtime/game_install.cppindex 9ff9b23..c68c402 100644--- a/src/runtime/game_install.cpp+++ b/src/runtime/game_install.cpp@@ -87,6 +87,7 @@ bool NormalizeLaunchPaths(RuntimeInstall& record) {if (!executable || !working) return false;record.launch_path = *executable;record.launch_working_directory = *working == "." ? "" : *working;+ record.launch_in_install_root = record.launch_in_install_root && record.launch_working_directory.empty();return true;}@@ -175,6 +176,7 @@ bool ValidRecord(const RuntimeInstall& record) {!IsRelativeLaunchPath(record.launch_path) ||!IsBoundedText(record.launch_arguments, kMaxLaunchArgumentsBytes, true) ||(!record.launch_working_directory.empty() && !IsRelativeLaunchPath(record.launch_working_directory)) ||+ (record.launch_in_install_root && !record.launch_working_directory.empty()) ||!IsAbsoluteNormalizedPath(record.install_path) || !IsSimpleId(record.volume_id) ||record.artifacts.size() > kMaxArtifacts) return false;for (const auto& artifact : record.artifacts)@@ -215,6 +217,9 @@ std::optional<RuntimeInstall> ParseRecord(const JsonValue& value, RepositoryErroconst auto* artifacts = Required(value, "artifacts", JsonValue::Type::kArray);const auto* failure = value.Find("last_failure");const auto* journal = value.Find("journal");+ // Added later: records without it start the program in its own folder, as before.+ const auto* in_install_root = value.Find("launch_in_install_root");+ if (in_install_root && !in_install_root->is_bool()) return std::nullopt;if (!install_id || !title_id || !app_id || !data_root || !profile || !bundle || !recipe ||!recipe_version || !revision || !exit_policy || !launch_entry_id || !launch ||!launch_arguments || !launch_working_directory || !install_path || !volume ||@@ -234,6 +239,7 @@ std::optional<RuntimeInstall> ParseRecord(const JsonValue& value, RepositoryErrorecord.launch_entry_id = launch_entry_id->text(); record.launch_path = launch->text();record.launch_arguments = launch_arguments->text();record.launch_working_directory = launch_working_directory->text();+ record.launch_in_install_root = in_install_root && in_install_root->boolean();record.install_path = install_path->text();record.volume_id = volume->text(); record.state = *parsed_state;for (const auto& entry : artifacts->array()) {@@ -273,6 +279,7 @@ void WriteRecord(TextOutput& output, const RuntimeInstall& record) {StringField(output, "launch_path", record.launch_path);StringField(output, "launch_arguments", record.launch_arguments);StringField(output, "launch_working_directory", record.launch_working_directory);+ if (record.launch_in_install_root) output << "\"launch_in_install_root\":true,";StringField(output, "install_path", record.install_path); StringField(output, "volume_id", record.volume_id);StringField(output, "state", StateName(record.state)); output << "\"artifacts\":[";for (std::size_t i = 0; i < record.artifacts.size(); ++i) {@@ -443,6 +450,7 @@ RepositoryResult<RuntimeInstall> RuntimeInstallRepository::Reserve(const Reservecandidate.launch_entry_id = request.launch_entry_id; candidate.launch_path = request.launch_path;candidate.launch_arguments = request.launch_arguments;candidate.launch_working_directory = request.launch_working_directory;+ candidate.launch_in_install_root = request.launch_in_install_root;candidate.install_path = request.install_path;candidate.volume_id = request.volume_id;if (!NormalizeLaunchPaths(candidate))diff --git a/src/runtime/game_install.h b/src/runtime/game_install.hindex ae3fa1c..7415a12 100644--- a/src/runtime/game_install.h+++ b/src/runtime/game_install.h@@ -67,6 +67,8 @@ struct RuntimeInstall {std::string launch_path;std::string launch_arguments;std::string launch_working_directory;+ // With no working directory: the program starts in the install root, not its own folder.+ bool launch_in_install_root = false;std::string install_path;std::string volume_id;PreparationState state = PreparationState::kDownloaded;@@ -94,6 +96,7 @@ struct ReserveRequest {std::string launch_path;std::string launch_arguments;std::string launch_working_directory;+ bool launch_in_install_root = false;std::string install_path;std::string volume_id;std::vector<std::string> kit_title_variants;diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cppindex ded753e..729a203 100644--- a/src/runtime/game_settings.cpp+++ b/src/runtime/game_settings.cpp@@ -237,7 +237,7 @@ std::vector<SettingDefinition> BuildCatalogue() {}{auto folder = Text("program_folder", "Program folder",- "Folder the program starts in, inside the game folder. Empty: the program's own folder.",+ "Folder the program starts in, inside the game folder; . is the game folder itself. Empty: the program's own folder.","[application] working_directory", T::kAdvanced);list.push_back(std::move(folder));}@@ -630,11 +630,13 @@ bool BuildEffectiveSettings(const GameRecipe& recipe, const SettingsPreset* presauto& own_arguments = out.values["program_arguments"];if (launch) {if (folder.source == ValueSource::kUser) {+ // "." is the game folder itself; empty is the program's own folder.const auto relative = steam::RelativeGamePath(folder.value, true);launch->working_directory = !relative || *relative == "." ? std::string() : *relative;+ launch->in_install_root = relative && *relative == "." && !folder.value.empty();} else {- folder.value = launch->working_directory;- folder.source = launch->working_directory.empty() ? ValueSource::kPlayden : ValueSource::kRecipe;+ folder.value = launch->working_directory.empty() && launch->in_install_root ? "." : launch->working_directory;+ folder.source = folder.value.empty() ? ValueSource::kPlayden : ValueSource::kRecipe;}if (own_arguments.source == ValueSource::kUser) {launch->arguments = own_arguments.value;@@ -786,15 +788,9 @@ bool RenderProsperoProfile(const GameRecipe& recipe, const EffectiveSettings& seif (!root) return fail("install folder cannot be mapped for Wine");const auto executable = steam::RelativeGamePath(settings.launch->executable);if (!executable) return fail("launch executable is not a game path");- std::string working;- if (settings.launch->working_directory.empty()) {- const auto slash = executable->rfind('/');- working = slash == std::string::npos ? std::string() : executable->substr(0, slash);- } else {- const auto relative = steam::RelativeGamePath(settings.launch->working_directory, true);- if (!relative) return fail("launch working folder is not a game path");- working = *relative;- }+ const auto folder = LaunchWorkingFolder(*settings.launch);+ if (!folder) return fail("launch working folder is not a game path");+ const auto& working = *folder;const auto value = [&](const char* id) -> const std::string& { return settings.values.at(id).value; };const auto on = [&](const char* id) { return value(id) == "on" ? "true" : "false"; };@@ -1110,6 +1106,11 @@ bool ParseGameRecipe(std::string_view text, GameRecipe* recipe, std::string* rea!StringField(item, "working_directory", &entry.working_directory, false) ||!StringField(item, "arguments", &entry.arguments, false))return fail("launch entry needs id, label and executable");+ if (const auto* root_folder = item.get("in_install_root")) {+ const auto value = root_folder->boolean();+ if (!value) return fail("launch entry in_install_root must be true or false");+ entry.in_install_root = *value && entry.working_directory.empty();+ }if (HasControl(entry.arguments)) return fail("launch entry arguments contain a control character");out.launch_entries.push_back(std::move(entry));}@@ -1246,7 +1247,7 @@ std::string SerializeGameRecipe(const GameRecipe& recipe) {if (index) text += ",";text += "{\"id\":" + quoted(entry.id) + ",\"label\":" + quoted(entry.label) + ",\"executable\":" +quoted(entry.executable) + ",\"working_directory\":" + quoted(entry.working_directory) +- ",\"arguments\":" + quoted(entry.arguments) + "}";+ ",\"arguments\":" + quoted(entry.arguments) + (entry.in_install_root ? ",\"in_install_root\":true" : "") + "}";}text += "],\"arguments\":" + quoted(recipe.arguments) + ",\"resolution_arguments\":" +quoted(recipe.resolution_arguments) + ",\"dll_overrides\":" + quoted(recipe.dll_overrides) +@@ -1434,6 +1435,19 @@ std::optional<std::string> GameInsteadOf(const std::string& install_root, const} // namespace+std::optional<std::string> LaunchWorkingFolder(const LaunchEntry& launch) {+ const auto executable = steam::RelativeGamePath(launch.executable);+ if (!executable) return std::nullopt;+ if (launch.working_directory.empty()) {+ if (launch.in_install_root) return std::string();+ const auto slash = executable->rfind('/');+ return slash == std::string::npos ? std::string() : executable->substr(0, slash);+ }+ const auto relative = steam::RelativeGamePath(launch.working_directory, true);+ if (!relative) return std::nullopt;+ return *relative == "." ? std::string() : *relative;+}+bool GenerateGameRecipe(std::uint32_t app_id, const std::string& name, const std::vector<LaunchEntry>& launches,const std::string& install_root, GameRecipe* recipe, std::string* reason,const KitCapabilities& kit, const RecipeChoices& choices, bool* refusal_soft,@@ -1469,13 +1483,20 @@ bool GenerateGameRecipe(std::uint32_t app_id, const std::string& name, const std}}int steam_entries = 0;- for (const auto& [launch, chosen] : candidates) {+ // Steam's own entries are the last ones; the player's program and the game found instead of a+ // launcher come before them.+ const auto first_steam = candidates.size() - launches.size();+ for (std::size_t index = 0; index < candidates.size(); ++index) {+ const auto& [launch, chosen] = candidates[index];const auto relative = steam::RelativeGamePath(launch.executable);if (!relative || relative->size() < 4 || LowerAscii(relative->substr(relative->size() - 4)) != ".exe") continue;if (HasControl(launch.arguments) || launch.arguments.size() > kProsperoMaxArgumentBytes / 2 ||!SplitProsperoArguments(launch.arguments, nullptr))continue;std::string working;+ // Steam starts an entry that names no folder in the install root (Slay the Spire runs+ // jre/bin/javaw.exe -jar desktop-1.0.jar); other programs start in their own folder.+ bool in_install_root = index >= first_steam;if (!launch.working_directory.empty()) {const auto directory = steam::RelativeGamePath(launch.working_directory, true);if (!directory) continue;@@ -1506,6 +1527,7 @@ bool GenerateGameRecipe(std::uint32_t app_id, const std::string& name, const stdon_disk = probe.unreal_program;const auto folder = on_disk->rfind('/');working = folder == std::string::npos ? std::string() : on_disk->substr(0, folder);+ in_install_root = false;}const auto architecture = ExecutableArchitecture(install_root + "/" + *on_disk);if (architecture.empty()) continue;@@ -1537,6 +1559,8 @@ bool GenerateGameRecipe(std::uint32_t app_id, const std::string& name, const stdif (entry.label.size() > 120) entry.label.resize(120);entry.executable = *on_disk;entry.working_directory = working;+ // Only when it differs from the program's own folder, so recipes of games in the root stay as they were.+ entry.in_install_root = in_install_root && working.empty() && on_disk->find('/') != std::string::npos;entry.arguments = CollapseSpaces(launch.arguments);out.launch_entries.push_back(std::move(entry));}@@ -1671,17 +1695,9 @@ std::optional<ManagedDirectory> OpenSafeParent(const std::string& path,std::optional<ManagedDirectory> OpenLaunchDirectory(const LaunchEntry& launch,const std::string& install_root) {- const auto executable = steam::RelativeGamePath(launch.executable);- if (!executable) return std::nullopt;- std::string working;- if (launch.working_directory.empty()) {- const auto slash = executable->rfind('/');- working = slash == std::string::npos ? std::string() : executable->substr(0, slash);- } else {- const auto relative = steam::RelativeGamePath(launch.working_directory, true);- if (!relative) return std::nullopt;- working = *relative;- }+ const auto folder = LaunchWorkingFolder(launch);+ if (!folder) return std::nullopt;+ const auto& working = *folder;auto directory = ManagedDirectory::Open(install_root, DirectoryPolicy::kApprovedTree);if (!directory) return std::nullopt;for (std::size_t start = 0; start < working.size();) {@@ -2698,7 +2714,8 @@ std::string SerializeCommunityRecipe(const CommunityRecipe& community) {const auto& entry = recipe.launch_entries[index];text += std::string(index ? "," : "") + "\n {\"id\": " + quoted(entry.id) + ", \"label\": " + quoted(entry.label) +", \"executable\": " + quoted(entry.executable) + ", \"working_directory\": " +- quoted(entry.working_directory) + ", \"arguments\": " + quoted(entry.arguments) + "}";+ quoted(entry.working_directory) + ", \"arguments\": " + quoted(entry.arguments) ++ (entry.in_install_root ? ", \"in_install_root\": true" : "") + "}";}text += "\n ],\n \"arguments\": " + quoted(recipe.arguments) + ",\n \"resolution_arguments\": " +quoted(recipe.resolution_arguments) + ",\n \"dll_overrides\": " + quoted(recipe.dll_overrides) +diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.hindex dfd240e..b6ff344 100644--- a/src/runtime/game_settings.h+++ b/src/runtime/game_settings.h@@ -83,10 +83,17 @@ struct LaunchEntry {std::string id;std::string label;std::string executable; // relative to the install root, '/' or '\' separated- std::string working_directory; // relative to the install root; empty = executable's folder+ std::string working_directory; // relative to the install root; empty = executable's folder (see below)std::string arguments; // this entry's own arguments, after the recipe's+ // With an empty working_directory: start in the install root instead, as Steam does for an+ // entry that names no folder.+ bool in_install_root = false;};+// The folder an entry starts in, relative to the install root ("" is the root itself); nothing+// when its paths leave the game folder.+std::optional<std::string> LaunchWorkingFolder(const LaunchEntry& launch);+// One value Playden owns in the bottle's user.reg (HKEY_CURRENT_USER). An empty data// removes the value, so the game inherits Wine's default again.struct RegistryValue {diff --git a/src/runtime/settings_publication_journal.cpp b/src/runtime/settings_publication_journal.cppindex 4d7a761..e634fe5 100644--- a/src/runtime/settings_publication_journal.cpp+++ b/src/runtime/settings_publication_journal.cpp@@ -63,7 +63,12 @@ template<class C, class T> void Presence(C& c, std::optional<T>& value) {if (!c.ok || present > 1) { c.ok = false; return; }if constexpr (C::reading) { if (present) value.emplace(); else value.reset(); }}-template<class C> void IdentityPayload(C& c, RuntimeInstall& r, SettingsLaunchPlan& p) {+// Version 3 of an operation (2 of a request) adds where a program without a working folder starts; it is+// written only when that is the install root, so the bytes of every other publication are unchanged.+bool StartsInInstallRoot(const RuntimeInstall& r, const SettingsLaunchPlan& p) {+ return r.launch_in_install_root || p.launch_entry.in_install_root;+}+template<class C> void IdentityPayload(C& c, RuntimeInstall& r, SettingsLaunchPlan& p, bool with_root) {c.U32(r.schema_version); c.Text(r.install_id, 64); c.Text(r.title_id, 9); c.U32(r.app_id);c.Text(r.data_root, 511); c.Text(r.default_profile_id, 64); c.Text(r.runtime_bundle_id, 64);c.Text(r.recipe_id, 64); c.Text(r.recipe_version, 64); c.U64(r.settings_revision); c.Text(r.exit_policy, 15);@@ -86,11 +91,17 @@ template<class C> void IdentityPayload(C& c, RuntimeInstall& r, SettingsLaunchPlfor (auto& value : p.registry) { c.Text(value.key, 1024); c.Text(value.name, 64); c.Text(value.data, 128); }c.Text(p.launch_entry.id, 128); c.Text(p.launch_entry.label, 1024);c.Text(p.launch_entry.executable, 1024); c.Text(p.launch_entry.working_directory, 1024);+ if (with_root) {+ unsigned flags = (r.launch_in_install_root ? 1u : 0u) | (p.launch_entry.in_install_root ? 2u : 0u); c.U32(flags);+ if (flags == 0 || flags > 3) c.ok = false;+ if constexpr (C::reading) { r.launch_in_install_root = flags & 1u; p.launch_entry.in_install_root = flags & 2u; }+ }}template<class C> void Payload(C& c, SettingsPublicationOperation& o) {- std::string magic = "PWOP2"; c.Text(magic, 5); if (magic != "PWOP2") c.ok = false;+ std::string magic = StartsInInstallRoot(o.install, o.plan) ? "PWOP3" : "PWOP2"; c.Text(magic, 5);+ if (magic != "PWOP2" && magic != "PWOP3") c.ok = false;c.U32(o.schema); c.Text(o.transaction_id, 36); c.Text(o.kit_id, 64); c.U64(o.previous_revision);- IdentityPayload(c, o.install, o.plan);+ IdentityPayload(c, o.install, o.plan, magic == "PWOP3");c.Text(o.descriptor_bytes, 8192); c.Text(o.catalog_bytes, 8192); c.Text(o.metadata_bytes, 32768);c.Text(o.previous_receipt_bytes, 8192); c.Text(o.previous_metadata_bytes, 32768);std::uint64_t registry_time = static_cast<std::uint64_t>(o.registry_unix_time); c.U64(registry_time);@@ -154,7 +165,8 @@ bool BaseValid(const SettingsPublicationOperation& o, std::string* reason) {p.profile_id != r.default_profile_id || p.settings_revision != r.settings_revision ||o.previous_revision > p.settings_revision || p.launch_entry_id != r.launch_entry_id ||p.launch_entry.id != r.launch_entry_id || NormalRelative(p.launch_entry.executable) != NormalRelative(r.launch_path) ||- NormalRelative(p.launch_entry.working_directory) != NormalRelative(r.launch_working_directory))+ NormalRelative(p.launch_entry.working_directory) != NormalRelative(r.launch_working_directory) ||+ p.launch_entry.in_install_root != r.launch_in_install_root)return Reject(reason, "Frozen OWNER record and launch plan disagree.");if (!PayloadBytes(o)) return Reject(reason, "Frozen operation exceeds field or total bounds.");const bool has_previous = !o.previous_receipt_bytes.empty();@@ -197,6 +209,7 @@ bool BaseValid(const SettingsPublicationOperation& o, std::string* reason) {std::string expected_exe = r.install_path + "/" + NormalRelative(r.launch_path);std::string expected_working = r.install_path;if (!r.launch_working_directory.empty()) expected_working += "/" + NormalRelative(r.launch_working_directory);+ else if (r.launch_in_install_root) {}else if (expected_exe.find_last_of('/') != std::string::npos) expected_working = expected_exe.substr(0, expected_exe.find_last_of('/'));if (!CanonicalPath(executable) || !CanonicalPath(working) || executable != expected_exe || working != expected_working ||o.catalog_bytes != p.profile_id + ".profile\n")@@ -292,9 +305,10 @@ bool FrozenValid(const SettingsPublicationOperation& o, std::string* reason) {}namespace {template<class C> void RequestPayload(C& c, SettingsPublicationRequest& r) {- std::string magic = "PWRQ1"; c.Text(magic, 5); if (magic != "PWRQ1") c.ok = false;+ std::string magic = StartsInInstallRoot(r.install, r.plan) ? "PWRQ2" : "PWRQ1"; c.Text(magic, 5);+ if (magic != "PWRQ1" && magic != "PWRQ2") c.ok = false;c.U32(r.schema); c.Text(r.transaction_id, 36); c.Text(r.kit_id, 64);- IdentityPayload(c, r.install, r.plan);+ IdentityPayload(c, r.install, r.plan, magic == "PWRQ2");auto time = static_cast<std::uint64_t>(r.registry_unix_time); c.U64(time);if (time > static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max())) c.ok = false;if constexpr (C::reading) { if (c.ok) r.registry_unix_time = static_cast<std::int64_t>(time); }@@ -307,7 +321,8 @@ bool RequestValid(const SettingsPublicationRequest& q, std::string* reason) {p.recipe_version != r.recipe_version || p.profile_id != r.default_profile_id ||p.settings_revision != r.settings_revision || p.launch_entry_id != r.launch_entry_id ||p.launch_entry.id != r.launch_entry_id || NormalRelative(p.launch_entry.executable) != NormalRelative(r.launch_path) ||- NormalRelative(p.launch_entry.working_directory) != NormalRelative(r.launch_working_directory))+ NormalRelative(p.launch_entry.working_directory) != NormalRelative(r.launch_working_directory) ||+ p.launch_entry.in_install_root != r.launch_in_install_root)return Reject(reason, "Requested OWNER identity and settings plan disagree.");PwGameProfile profile{};if (pw_game_profile_parse(reinterpret_cast<const uint8_t*>(p.profile_bytes.data()), p.profile_bytes.size(), &profile) != PW_OK ||diff --git a/src/runtime/settings_publication_owner.cpp b/src/runtime/settings_publication_owner.cppindex 1d3dc60..85ad136 100644--- a/src/runtime/settings_publication_owner.cpp+++ b/src/runtime/settings_publication_owner.cpp@@ -11,6 +11,7 @@ void CommitLaunch(RuntimeInstall* record, const RuntimeInstall& published) {record->launch_entry_id = published.launch_entry_id;record->launch_path = published.launch_path;record->launch_working_directory = published.launch_working_directory;+ record->launch_in_install_root = published.launch_in_install_root;record->launch_arguments = published.launch_arguments;}PackageActionResult Failure(const char* code, const char* message) {diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cppindex ff76040..84d64ed 100644--- a/tests/game_settings_test.cpp+++ b/tests/game_settings_test.cpp@@ -1181,10 +1181,34 @@ int main(int argc, char** argv) {CHECK(generated.launch_entries[0].working_directory == "Bin");CHECK(generated.launch_entries[0].arguments == "-windowed -nosplash");CHECK(generated.launch_entries[1].executable == "Bin/Tool.exe" && generated.launch_entries[1].label == "Tool.exe");+ // A Steam entry that names no folder starts in the install root, as on Steam; one that names a folder starts there.+ CHECK(generated.launch_entries[1].working_directory.empty() && generated.launch_entries[1].in_install_root);+ CHECK(!generated.launch_entries[0].in_install_root);+ CHECK(LaunchWorkingFolder(generated.launch_entries[1]) == std::string());// The recipe round-trips through its JSON form.GameRecipe reread;CHECK(ParseGameRecipe(SerializeGameRecipe(generated), &reread, &reason));- CHECK(SerializeGameRecipe(reread) == SerializeGameRecipe(generated));+ CHECK(SerializeGameRecipe(reread) == SerializeGameRecipe(generated) && reread.launch_entries[1].in_install_root);+ {+ // The Program folder row shows it as the game folder; "." chooses it, empty the program's own folder.+ EffectiveSettings root_settings;+ SettingsError root_error;+ CHECK(BuildEffectiveSettings(generated, nullptr, {{"launch_option", "launch-2"}}, KitCapabilities{},+ &root_settings, &root_error));+ CHECK(root_settings.values.at("program_folder").value == "." && root_settings.launch->in_install_root);+ CHECK(BuildEffectiveSettings(generated, nullptr, {{"launch_option", "launch-2"}, {"program_folder", ""}},+ KitCapabilities{}, &root_settings, &root_error));+ CHECK(!root_settings.launch->in_install_root && LaunchWorkingFolder(*root_settings.launch) == std::string("Bin"));+ CHECK(BuildEffectiveSettings(generated, nullptr, {{"program_folder", "."}}, KitCapabilities{},+ &root_settings, &root_error));+ CHECK(root_settings.launch->working_directory.empty() && root_settings.launch->in_install_root);+ // A player's program starts in its own folder.+ GameRecipe chosen;+ RecipeChoices choices;+ choices.program = "Bin/Tool.exe";+ CHECK(GenerateGameRecipe(4246, "Chosen", {}, game_root.string(), &chosen, &reason, KitCapabilities{}, choices));+ CHECK(!chosen.launch_entries.front().in_install_root);+ }// The launch entry's own arguments reach the profile, before the player's.EffectiveSettings generated_settings;SettingsError generated_error;diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cppindex c01377c..8a52860 100644--- a/tests/homebrew_runtime_host_test.cpp+++ b/tests/homebrew_runtime_host_test.cpp@@ -1690,6 +1690,71 @@ void PreparesGameOnUnownedDrive() {// Selaco (issue 52): Steam lists only .bat files, so Playden refuses it, but the program the// player picks in Game settings prepares and starts; later settings updates keep that program.+void SteamEntryWithoutFolderStartsInInstallRoot() {+ 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");+ };+ const auto kit = SyntheticKit(fixture.root / "kit");+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };+ unsigned uuids = 0;+ config.uuid = [&uuids]() -> std::optional<std::string> {+ ++uuids; return std::string("00000000-0000-4000-8000-00000000000") + std::to_string(uuids);+ };+ config.unix_time = [] { return std::int64_t{1760000000}; };+ config.session_data_root = fixture.root / "data";+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/646570";+ 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;+ // Slay the Spire: Steam starts jre/bin/javaw.exe -jar desktop-1.0.jar in the install root.+ Write(game / "jre/bin/javaw.exe", pe, 0644);+ Write(game / "desktop-1.0.jar", "jar", 0644);+ CHECK(chmod(game.c_str(), 0755) == 0 && chmod((game / "jre").c_str(), 0755) == 0 && chmod((game / "jre/bin").c_str(), 0755) == 0);+ GameSettingsRecord saved;+ config.settings_record = [&](std::uint32_t) -> std::optional<GameSettingsRecord> { return saved; };+ RuntimePrepareRequest request{646570, "/data/homebrew/FAKE77031/games/646570", "internal", "Slay the Spire"};+ request.launches = {{"", "Play", "jre\\bin\\javaw.exe", "", "-jar desktop-1.0.jar"}};+ const auto profile = fixture.root / "data/playden/games/steam-646570/library/profiles/playden-steam-646570.profile";+ RuntimeHost host(config);+ CHECK(host.Start());+ CHECK(WaitFor(host, Started).kit_available);+ host.Prepare(request);+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) {+ return !s.preparing_app && !s.installs.empty() && s.installs[0].state == PreparationState::kReady;+ }, 60);+ if (done.refusals.count(646570)) std::fprintf(stderr, "refused: %s\n", done.refusals.at(646570).c_str());+ CHECK(!done.installs.empty() && done.installs[0].launch_in_install_root && done.installs[0].launch_working_directory.empty());+ CHECK(Read(profile).find("working_directory = Z:\\data\\homebrew\\FAKE77031\\games\\646570\n") != std::string::npos);+ // The program's own folder, chosen in Game settings, reaches the title and the record; "." goes back to the game folder.+ fixture.activity->store(static_cast<int>(NativeActivity::kStopped));+ const auto apply = [&](std::uint64_t revision) {+ saved.revision = revision;+ const auto before = host.Snapshot().maintenance_handled;+ host.Maintain(646570, RuntimeMaintenance::kApplySettings);+ return WaitFor(host, [before](const RuntimeSnapshot& s) { return s.maintenance_handled > before; }, 60);+ };+ saved.overrides = {{"program_folder", "jre/bin"}};+ auto applied = apply(1);+ if (!applied.maintenance.at(646570).ok) std::fprintf(stderr, "apply: %s\n", applied.maintenance.at(646570).message.c_str());+ CHECK(applied.maintenance.at(646570).ok && !applied.installs[0].launch_in_install_root &&+ applied.installs[0].launch_working_directory == "jre/bin");+ CHECK(Read(profile).find("working_directory = Z:\\data\\homebrew\\FAKE77031\\games\\646570\\jre\\bin\n") != std::string::npos);+ saved.overrides = {{"program_folder", "."}};+ applied = apply(2);+ CHECK(applied.maintenance.at(646570).ok && applied.installs[0].launch_in_install_root &&+ applied.installs[0].launch_working_directory.empty());+ CHECK(Read(profile).find("working_directory = Z:\\data\\homebrew\\FAKE77031\\games\\646570\n") != std::string::npos);+ host.Shutdown();+}+void PreparesProgramChosenInSettings() {Fixture fixture;auto config = fixture.Config();@@ -1999,6 +2064,7 @@ int main(int argc, char** argv) {PreparationEndsAwaitingRegistration();PreparesGameWithoutShippedRecipe();PreparesProgramChosenInSettings();+ SteamEntryWithoutFolderStartsInInstallRoot();PreparesUdkGameWithEulaAccepted();ResumesInterruptedCaptureFromSavedRequest();ResumesInterruptedCaptureFromSavedRequest(true);diff --git a/tests/runtime_game_install_test.cpp b/tests/runtime_game_install_test.cppindex 00c4c74..9e28137 100644--- a/tests/runtime_game_install_test.cpp+++ b/tests/runtime_game_install_test.cpp@@ -390,9 +390,21 @@ void LaunchPathsUseTheSharedSteamPathContract() {request.launch_working_directory = path;CHECK(repository.Reserve(request).error() == RepositoryError::kInvalidRecord);}+ // Starting in the install root is kept across a restart; it only holds without a working folder.+ request.install_id = "install-root";+ request.launch_working_directory = ".";+ request.launch_in_install_root = true;+ CHECK(repository.Reserve(request).ok());+ request.install_id = "install-root-folder";+ request.launch_working_directory = "bin";+ auto with_folder = repository.Reserve(request);+ CHECK(with_folder.ok() && !with_folder.value().launch_in_install_root);RuntimeInstallRepository restarted(storage, "runtime-installs.json", Free);CHECK(restarted.Load().ok());CHECK(restarted.Find("install-hl2")->launch_path == "bin/Game.exe");+ CHECK(!restarted.Find("install-hl2")->launch_in_install_root);+ CHECK(restarted.Find("install-root")->launch_in_install_root &&+ restarted.Find("install-root")->launch_working_directory.empty());}void JournalSyncFailureRequiresReloadBeforeFurtherEffects() {diff --git a/tests/runtime_settings_publication_journal_test.cpp b/tests/runtime_settings_publication_journal_test.cppindex 180d3fa..bbb3fd2 100644--- a/tests/runtime_settings_publication_journal_test.cpp+++ b/tests/runtime_settings_publication_journal_test.cpp@@ -50,6 +50,20 @@ int main() {}auto request_extra = *request_bytes; request_extra.push_back(0);CHECK(!DecodeSettingsPublicationRequest(request_extra, &reason));+ {+ // A program that starts in the install root is a version 2 request; others keep the version 1 bytes.+ auto rooted = request;+ rooted.install.launch_working_directory.clear(); rooted.plan.launch_entry.working_directory.clear();+ rooted.install.launch_in_install_root = rooted.plan.launch_entry.in_install_root = true;+ auto rooted_bytes = EncodeSettingsPublicationRequest(rooted, &reason); CHECK(rooted_bytes);+ CHECK(std::string(rooted_bytes->begin() + 4, rooted_bytes->begin() + 9) == "PWRQ2");+ CHECK(std::string(request_bytes->begin() + 4, request_bytes->begin() + 9) == "PWRQ1");+ auto rooted_back = DecodeSettingsPublicationRequest(*rooted_bytes, &reason); CHECK(rooted_back);+ CHECK(rooted_back->install.launch_in_install_root && rooted_back->plan.launch_entry.in_install_root);+ CHECK(EncodeSettingsPublicationRequest(*rooted_back, &reason) == rooted_bytes);+ rooted.plan.launch_entry.in_install_root = false;+ CHECK(!EncodeSettingsPublicationRequest(rooted, &reason));+ }auto invalid_request = request; ++invalid_request.plan.settings_revision;CHECK(!EncodeSettingsPublicationRequest(invalid_request, &reason));invalid_request = request; invalid_request.transaction_id = "00000000-0000-0000-0000-000000000000";@@ -61,6 +75,19 @@ int main() {auto encoded = EncodeSettingsPublicationOperation(*frozen, &reason); CHECK(encoded);auto decoded = DecodeSettingsPublicationOperation(*encoded, &reason); CHECK(decoded);CHECK(EncodeSettingsPublicationOperation(*decoded, &reason) == encoded);+ {+ // Starting in the install root survives a restart: version 3 decodes and encodes to the same bytes and digest.+ auto rooted = Fixture();+ rooted.install.launch_in_install_root = rooted.plan.launch_entry.in_install_root = true;+ auto rooted_frozen = FreezeSettingsPublicationOperation(rooted, &reason); CHECK(rooted_frozen);+ auto rooted_bytes = EncodeSettingsPublicationOperation(*rooted_frozen, &reason); CHECK(rooted_bytes);+ CHECK(std::string(rooted_bytes->begin() + 4, rooted_bytes->begin() + 9) == "PWOP3");+ CHECK(std::string(encoded->begin() + 4, encoded->begin() + 9) == "PWOP2");+ auto rooted_back = DecodeSettingsPublicationOperation(*rooted_bytes, &reason); CHECK(rooted_back);+ CHECK(rooted_back->install.launch_in_install_root && rooted_back->plan.launch_entry.in_install_root &&+ rooted_back->plan_sha256 == rooted_frozen->plan_sha256);+ CHECK(EncodeSettingsPublicationOperation(*rooted_back, &reason) == rooted_bytes);+ }auto publication = RebuildFrozenProfilePublication(*decoded, &reason); CHECK(publication);CHECK(publication->profile_references_validated && publication->profile_bytes == decoded->plan.profile_bytes);CHECK(publication->input_presets.size() == 1 && publication->input_presets[0].filename == "gamepad.input");