Play your Steam library's Windows games on a jailbroken PS5.
C++
Let a recipe carry registry values; add FF XIII
Timothy Slaterd4c7d541e934
diff --git a/docs/community-recipes.md b/docs/community-recipes.mdindex 7f2882b..54bfebf 100644--- a/docs/community-recipes.md+++ b/docs/community-recipes.md@@ -66,6 +66,7 @@ Recipe fields:| `graphics` | `auto`, `gdi`, `dxvk` or `opengl`. || `defaults` | Game settings by setting id (`SettingsCatalogue()`), only values that differ from Playden's default. || `locked` | Setting ids the player must choose "Change anyway" to change. |+| `registry` | Values the bottle gets under `HKEY_CURRENT_USER` when the game's files are prepared, as a Steam install script's would be: `{"Software\\Wine\\AppDefaults\\game.exe\\Direct3D": {"VideoMemorySize": "4096"}}`. Strings only. The Windows version and text scale values belong to Game settings and are refused here. |Community fields:diff --git a/runtime/recipes/recipes.lst b/runtime/recipes/recipes.lstindex 75bdd30..02241b6 100644--- a/runtime/recipes/recipes.lst+++ b/runtime/recipes/recipes.lst@@ -1,2 +1,3 @@# Recipes Playden ships, one file per line (the console title cannot list folders).steam-220-hl2-v1.json+steam-292120-ffxiii-v1.jsondiff --git a/runtime/recipes/steam-292120-ffxiii-v1.json b/runtime/recipes/steam-292120-ffxiii-v1.jsonnew file mode 100644index 0000000..c2ba1af--- /dev/null+++ b/runtime/recipes/steam-292120-ffxiii-v1.json@@ -0,0 +1,24 @@+{+ "recipe_id": "steam-292120-ffxiii-v1",+ "recipe_version": 1,+ "app_id": 292120,+ "name": "Final Fantasy XIII",+ "launch_entries": [+ {"id": "game", "label": "Final Fantasy XIII", "executable": "white_data/prog/win/bin/ffxiiiimg.exe"}+ ],+ "arguments": "",+ "resolution_arguments": "",+ "dll_overrides": "",+ "architecture": "pe32",+ "runtime": "wine-wow64",+ "prefix": "game",+ "graphics": "dxvk",+ "defaults": {+ "steam_features": "emulate",+ "controller": "xinput"+ },+ "registry": {+ "Software\\Wine\\AppDefaults\\ffxiiiimg.exe\\Direct3D": {"VideoMemorySize": "4096"}+ },+ "locked": []+}diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex 035c513..76aae87 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -478,6 +478,15 @@ std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstal}if (!script.ok) return "The game's install script could not be applied: " + script.message + ".";}+ // Registry values the recipe carries (docs/community-recipes.md), written the way an install script's are.+ if (!recipe->registry.empty()) {+ std::string reason;+ const bool ok = rt::ApplyBottleRegistryValues(recipe->registry, (HostPath(record.data_root) / "library/prefixes/game").string(),+ config_.unix_time(), "user.reg", &reason);+ Log("recipe registry app=" + std::to_string(record.app_id) + " values=" + std::to_string(recipe->registry.size()) ++ (ok ? std::string() : " failed=" + reason));+ if (!ok) return "The recipe's registry values could not be applied: " + reason + ".";+ }// Self-contained .NET games reserve more address space than the console grants unless// their garbage collector is given a heap limit (runtime/dotnet_heap.h).const auto dotnet = rt::LimitDotnetHeap(root.string());diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cppindex d2de250..0b739f0 100644--- a/src/runtime/game_settings.cpp+++ b/src/runtime/game_settings.cpp@@ -925,6 +925,51 @@ bool ExactUnsigned(const json::Value* value, std::uint64_t maximum, std::uint64_return true;}+constexpr std::size_t kMaxRecipeRegistryValues = 16;++// A registry value a recipe may carry: a key under HKEY_CURRENT_USER as Wine spells it, a+// printable ASCII name and string, and never one of the two values the title publication+// owns (settings_publication.cpp), which the next publication would put back.+bool RecipeRegistryValueAllowed(const std::string& key, const std::string& name, const std::string& value,+ std::string* why) {+ const auto printable = [](const std::string& text, bool backslashes) {+ for (const unsigned char c : text)+ if (c < 0x20 || c > 0x7e || c == '"' || (c == '\\' && !backslashes)) return false;+ return true;+ };+ const auto lower = [](std::string text) {+ for (auto& c : text) c = c >= 'A' && c <= 'Z' ? static_cast<char>(c - 'A' + 'a') : c;+ return text;+ };+ if (key.empty() || key.size() > 200 || !printable(key, true) || key.front() == '\\' || key.back() == '\\' ||+ key.find("\\\\") != std::string::npos) {+ *why = "key is not a registry path";+ return false;+ }+ const auto folded = lower(key);+ if (folded.rfind("hkey_", 0) == 0 || folded.rfind("hkcu", 0) == 0 || folded.rfind("hklm", 0) == 0) {+ *why = "keys are relative to HKEY_CURRENT_USER";+ return false;+ }+ if (name.empty() || name.size() > 64 || !printable(name, false)) {+ *why = "value name is not printable ASCII";+ return false;+ }+ if (value.size() > 256 || !printable(value, false)) {+ *why = "value is not a printable ASCII string";+ return false;+ }+ static constexpr std::string_view kAppDefaults = "software\\wine\\appdefaults\\";+ const bool version = folded.rfind(kAppDefaults, 0) == 0 &&+ folded.find('\\', kAppDefaults.size()) == std::string::npos && lower(name) == "version";+ const bool log_pixels = folded == "control panel\\desktop" && lower(name) == "logpixels";+ if (version || log_pixels) {+ *why = "Game settings own this value";+ return false;+ }+ return true;+}+} // namespacebool ParseGameRecipe(std::string_view text, GameRecipe* recipe, std::string* reason) {@@ -973,6 +1018,22 @@ bool ParseGameRecipe(std::string_view text, GameRecipe* recipe, std::string* reaout.locked.insert(*item.string());}}+ if (const auto* registry = root->get("registry")) {+ const auto* keys = registry->object();+ if (!keys) return fail("registry must map keys to their values");+ for (const auto& [key, names] : *keys) {+ const auto* list = names.object();+ if (!list) return fail("registry key " + key + " must map value names to strings");+ for (const auto& [name, value] : *list) {+ const auto* string = value.string();+ std::string why;+ if (!string) return fail("registry value " + name + " must be a string");+ if (!RecipeRegistryValueAllowed(key, name, *string, &why)) return fail("registry " + key + " " + name + ": " + why);+ if (out.registry.size() >= kMaxRecipeRegistryValues) return fail("registry has too many values");+ out.registry.push_back({key, name, "\"" + *string + "\""});+ }+ }+ }if (out.dll_overrides.size() && !IsProsperoDllOverrides(out.dll_overrides)) return fail("recipe dll_overrides are invalid");if (out.architecture != "pe32" && out.architecture != "pe64") return fail("architecture must be pe32 or pe64");for (const auto& [id, value] : out.defaults) {@@ -1098,7 +1159,26 @@ std::string SerializeGameRecipe(const GameRecipe& recipe) {first = false;text += quoted(id);}- return text + "]}\n";+ text += "]";+ if (!recipe.registry.empty()) {+ // Grouped by key as the file has it; data holds the quoted string.+ std::map<std::string, std::vector<const RegistryValue*>> keys;+ for (const auto& value : recipe.registry) keys[value.key].push_back(&value);+ text += ",\"registry\":{";+ first = true;+ for (const auto& [key, values] : keys) {+ if (!first) text += ",";+ first = false;+ text += quoted(key) + ":{";+ for (std::size_t index = 0; index < values.size(); ++index) {+ if (index) text += ",";+ text += quoted(values[index]->name) + ":" + quoted(values[index]->data.substr(1, values[index]->data.size() - 2));+ }+ text += "}";+ }+ text += "}";+ }+ return text + "}\n";}namespace {diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.hindex 26ff7f4..e2235ca 100644--- a/src/runtime/game_settings.h+++ b/src/runtime/game_settings.h@@ -86,6 +86,14 @@ struct LaunchEntry {std::string arguments; // this entry's own arguments, after the recipe's};+// 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 {+ std::string key; // e.g. Software\Wine\AppDefaults\hl2.exe (single backslashes)+ std::string name; // e.g. Version+ std::string data; // Wine's text form: "\"win7\"" or "dword:00000078"; empty removes+};+struct GameRecipe {std::string id;int version = 0;@@ -104,6 +112,9 @@ 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)+ // 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;};struct SettingsPreset {@@ -264,14 +275,6 @@ std::string SerializeGameSettingsRecord(const GameSettingsRecord& record);// nothing else. Missing cache is success. Call only while the game is not running.bool ClearShaderCache(const LaunchEntry& launch, const std::string& install_root, std::string* reason);-// 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 {- std::string key; // e.g. Software\Wine\AppDefaults\hl2.exe (single backslashes)- std::string name; // e.g. Version- std::string data; // Wine's text form: "\"win7\"" or "dword:00000078"; empty removes-};-// The registry values the effective settings ask for: Windows version for the launch// executable (AppDefaults) and text scale (Wine's LogPixels). Empty when the kit cannot// edit the bottle.diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cppindex 471d417..6e6be53 100644--- a/tests/game_settings_test.cpp+++ b/tests/game_settings_test.cpp@@ -630,6 +630,45 @@ int main(int argc, char** argv) {CHECK(!ParseGameRecipe(R"({"recipe_id":"x","recipe_version":1.5,"app_id":1,"launch_entries":[{"id":"a","label":"A","executable":"a.exe"}]})", &hl2, &reason));CHECK(!ParseGameRecipe(R"({"recipe_id":"x","recipe_version":1,"app_id":-1,"launch_entries":[{"id":"a","label":"A","executable":"a.exe"}]})", &hl2, &reason));CHECK(!ParseGameRecipe(R"({"recipe_id":"x","recipe_version":1,"app_id":4294967296,"launch_entries":[{"id":"a","label":"A","executable":"a.exe"}]})", &hl2, &reason));+ // A recipe can carry registry values the bottle gets when the game's files are prepared, like a+ // Steam install script: HKEY_CURRENT_USER strings only, never the two values the title publication owns.+ {+ const std::string head = R"({"recipe_id":"x","recipe_version":1,"app_id":1,"launch_entries":[{"id":"a","label":"A","executable":"a.exe"}],"registry":)";+ GameRecipe with_registry;+ CHECK(ParseGameRecipe(head + R"({"Software\\Wine\\AppDefaults\\a.exe\\Direct3D":{"VideoMemorySize":"4096"}}})", &with_registry, &reason));+ CHECK(with_registry.registry.size() == 1 && with_registry.registry[0].key == "Software\\Wine\\AppDefaults\\a.exe\\Direct3D" &&+ with_registry.registry[0].name == "VideoMemorySize" && with_registry.registry[0].data == "\"4096\"");+ GameRecipe reread;+ CHECK(ParseGameRecipe(SerializeGameRecipe(with_registry), &reread, &reason) && reread.registry.size() == 1 &&+ reread.registry[0].key == with_registry.registry[0].key && reread.registry[0].data == "\"4096\"");+ CHECK(SerializeGameRecipe(hl2).find("registry") == std::string::npos); // absent when empty+ GameRecipe refused;+ CHECK(!ParseGameRecipe(head + R"([]})", &refused, &reason)); // not an object+ CHECK(!ParseGameRecipe(head + R"({"Software\\X":{"A":1}}})", &refused, &reason)); // not a string+ CHECK(!ParseGameRecipe(head + R"({"HKEY_CURRENT_USER\\Software\\X":{"A":"1"}}})", &refused, &reason)); // keys are relative to HKCU+ CHECK(!ParseGameRecipe(head + R"({"Software\\X":{"A":"say \"hi\""}}})", &refused, &reason)); // no quotes in a value+ CHECK(!ParseGameRecipe(head + R"({"Software\\Wine\\AppDefaults\\a.exe":{"version":"win7"}}})", &refused, &reason)); // owned by the publication+ CHECK(!ParseGameRecipe(head + R"({"Control Panel\\Desktop":{"LogPixels":"120"}}})", &refused, &reason));+ // Applied to a bottle the way an install script is.+ const auto registry_root = std::filesystem::canonical(std::filesystem::temp_directory_path()) /+ ("playden-recipe-registry-" + std::to_string(::getpid()));+ std::filesystem::remove_all(registry_root);+ std::filesystem::create_directories(registry_root);+ std::filesystem::permissions(registry_root, std::filesystem::perms::owner_all);+ std::ofstream(registry_root / "user.reg") << "WINE REGISTRY Version 2\n;; All keys relative to REGISTRY\\\\User\\\\S-1-5-21-0-0-0-1000\n\n#arch=win64\n";+ ::chmod((registry_root / "user.reg").c_str(), 0600);+ CHECK(ApplyBottleRegistryValues(with_registry.registry, registry_root.string(), 1791500000, "user.reg", &reason));+ CHECK(ReadText(registry_root / "user.reg").find("\n[Software\\\\Wine\\\\AppDefaults\\\\a.exe\\\\Direct3D] 1791500000\n\"VideoMemorySize\"=\"4096\"\n") != std::string::npos);+ std::filesystem::remove_all(registry_root);+ }+ // Final Fantasy XIII asks DxDiag for its video memory, which Wine answers from wined3d, so the shipped+ // recipe sets wined3d's VideoMemorySize for its program.+ {+ GameRecipe ffxiii;+ CHECK(ParseGameRecipe(ReadText(source / "runtime/recipes/steam-292120-ffxiii-v1.json"), &ffxiii, &reason));+ CHECK(ffxiii.app_id == 292120 && ffxiii.registry.size() == 1 && ffxiii.registry[0].name == "VideoMemorySize" &&+ ffxiii.registry[0].key == "Software\\Wine\\AppDefaults\\ffxiiiimg.exe\\Direct3D" && ffxiii.registry[0].data == "\"4096\"");+ }CHECK(!ParseSettingsPresets(R"({"presets":[{"id":"x","name":"X","settings":{"graphics":"gdi"}}]})", &presets, &reason));CHECK(!ParseSettingsPresets(R"({"presets":[{"id":"x","name":"X","settings":{"extra_arguments":"-a"}}]})", &presets, &reason));@@ -656,7 +695,8 @@ int main(int argc, char** argv) {std::vector<SettingsPreset> loaded_presets;std::vector<GameRecipe> loaded_recipes;CHECK(LoadSettingsData((source / "runtime").string(), &loaded_presets, &loaded_recipes, &reason));- CHECK(loaded_presets.size() == 4 && loaded_recipes.size() == 1 && loaded_recipes.front().app_id == 220);+ CHECK(loaded_presets.size() == 4 && loaded_recipes.size() == 2 && loaded_recipes.front().app_id == 220 &&+ loaded_recipes.back().id == "steam-292120-ffxiii-v1");CHECK(!LoadSettingsData((source / "missing").string(), &loaded_presets, &loaded_recipes, &reason));// ApplyGameSettings writes the profile and a Playden dxvk.conf, removes it when nothing is