Skip to content

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

C++

Apply language values from Steam install scripts

Leonardo Lobato8c833ecd4587
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 9f4bb97..eabf244 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -974,7 +974,11 @@ std::string RuntimeHost::InstallScriptsStep(const GameFiles& files) {
const auto& record = files.record;
const auto install_dir = rt::ProsperoWindowsPath(record.install_path);
if (!install_dir) return {};
- const auto script = rt::ApplyInstallScripts(files.root.string(), *install_dir, files.prefix, config_.unix_time());
+ // The game's language comes from its download; a game with no facts (imported) gets the English values.
+ rt::SteamworksIdentity identity;
+ rt::ReadSteamworksFacts(files.root.string(), &identity);
+ const auto script = rt::ApplyInstallScripts(files.root.string(), *install_dir, identity.language, files.prefix,
+ config_.unix_time());
if (!script.found.empty()) {
std::string names;
for (const auto& name : script.found) names += (names.empty() ? "" : ",") + name;
diff --git a/src/runtime/install_script.cpp b/src/runtime/install_script.cpp
index 1fcef5a..9ec787e 100644
--- a/src/runtime/install_script.cpp
+++ b/src/runtime/install_script.cpp
@@ -110,8 +110,8 @@ bool ReadScript(const std::filesystem::path& path, std::string* text) {
} // namespace
-bool ParseInstallScript(std::string_view text, const std::string& install_dir, InstallScriptValues* values,
- std::string* reason) {
+bool ParseInstallScript(std::string_view text, const std::string& install_dir, const std::string& language,
+ InstallScriptValues* values, std::string* reason) {
const auto fail = [&](const char* why) {
if (reason) *reason = why;
return false;
@@ -141,23 +141,35 @@ bool ParseInstallScript(std::string_view text, const std::string& install_dir, I
for (const auto& [type, entries] : key.children) {
const auto kind = Lower(type);
if (!entries.is_dict || (kind != "string" && kind != "dword")) continue;
- for (const auto& [name, data] : entries.children) {
- if (data.is_dict || name.empty() || !Ascii(name)) continue;
+ const auto add = [&](const std::string& name, const std::string& data) {
+ if (name.empty() || !Ascii(name)) return;
std::string value;
- if (!Substitute(data.value, install_dir, &value) || !Ascii(value)) continue;
+ if (!Substitute(data, install_dir, &value) || !Ascii(value)) return;
if (kind == "dword") {
char* end = nullptr;
errno = 0;
const auto number = std::strtoull(value.c_str(), &end, 0);
- if (value.empty() || errno || *end || number > 0xffffffffull) continue;
+ if (value.empty() || errno || *end || number > 0xffffffffull) return;
char text_value[16];
std::snprintf(text_value, sizeof(text_value), "dword:%08llx", number);
value = text_value;
} else {
value = RegistryString(value);
}
- for (const auto& name_key : keys) target.push_back({name_key, name, value});
+ const bool unnamed = Lower(name) == "(default)";
+ for (const auto& name_key : keys) target.push_back({name_key, unnamed ? std::string() : name, value, unnamed});
+ };
+ // A subkey holds the values for one language ("dword" { "english" { "Language" "1" } }).
+ const steam::VdfNode* localized = nullptr;
+ for (const auto* wanted : {language.c_str(), "english"}) {
+ for (const auto& [name, data] : entries.children)
+ if (!localized && data.is_dict && Lower(name) == Lower(wanted)) localized = &data;
}
+ for (const auto& [name, data] : entries.children)
+ if (!data.is_dict) add(name, data.value);
+ if (localized)
+ for (const auto& [name, data] : localized->children)
+ if (!data.is_dict) add(name, data.value);
}
}
return true;
@@ -200,7 +212,8 @@ bool ReadInstallScript(const std::string& path, std::string* text) {
}
InstallScriptResult ApplyInstallScripts(const std::string& game_root, const std::string& install_dir,
- const std::string& prefix_dir, std::int64_t unix_time) {
+ const std::string& language, const std::string& prefix_dir,
+ std::int64_t unix_time) {
InstallScriptResult result;
std::vector<std::filesystem::path> scripts;
std::error_code error;
@@ -219,7 +232,7 @@ InstallScriptResult ApplyInstallScripts(const std::string& game_root, const std:
result.found.push_back(name);
std::string text, reason;
InstallScriptValues parsed;
- if (!ReadScript(path, &text) || !ParseInstallScript(text, install_dir, &parsed, &reason)) {
+ if (!ReadScript(path, &text) || !ParseInstallScript(text, install_dir, language, &parsed, &reason)) {
result.skipped.push_back(name);
continue;
}
diff --git a/src/runtime/install_script.h b/src/runtime/install_script.h
index 07eb646..ac900df 100644
--- a/src/runtime/install_script.h
+++ b/src/runtime/install_script.h
@@ -19,13 +19,15 @@ namespace playden::runtime {
// game folder's Windows path). HKLM\Software keys go to both registry views, as Steam, a
// 32-bit program, writes them where 32-bit and 64-bit games find them. Only "string" and
// "dword" values are taken; a value with another %TOKEN% or non-ASCII text, and keys under
-// other roots, are skipped. Text may be UTF-8 or UTF-16 with a byte order mark.
+// other roots, are skipped. Text may be UTF-8 or UTF-16 with a byte order mark. A language subkey
+// of "string" or "dword" gives its values only for that language: language (Steam's name, like
+// "russian"; empty for none) is used, then "english". A value named (Default) is the key's unnamed one.
struct InstallScriptValues {
std::vector<RegistryValue> machine; // system.reg (HKEY_LOCAL_MACHINE)
std::vector<RegistryValue> user; // user.reg (HKEY_CURRENT_USER)
};
-bool ParseInstallScript(std::string_view text, const std::string& install_dir, InstallScriptValues* values,
- std::string* reason);
+bool ParseInstallScript(std::string_view text, const std::string& install_dir, const std::string& language,
+ InstallScriptValues* values, std::string* reason);
// Applies the Registry sections of the install scripts at the top of game_root (file names
// starting with "installscript" and ending ".vdf", any case) to the stopped bottle at
@@ -39,7 +41,8 @@ struct InstallScriptResult {
std::string message; // on failure
};
InstallScriptResult ApplyInstallScripts(const std::string& game_root, const std::string& install_dir,
- const std::string& prefix_dir, std::int64_t unix_time);
+ const std::string& language, const std::string& prefix_dir,
+ std::int64_t unix_time);
// A redistributable an install script runs on the game's first start ("Run Process" entry).
struct RedistEntry {
diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cpp
index 7ef2b92..5f6dfcf 100644
--- a/tests/game_settings_test.cpp
+++ b/tests/game_settings_test.cpp
@@ -1287,7 +1287,7 @@ int main(int argc, char** argv) {
" }\n }\n }\n \"Run Process\"\n {\n \"DirectX\"\n {\n"
" \"process 1\" \"%INSTALLDIR%\\\\Redists\\\\directx\\\\DXSETUP.exe\"\n }\n }\n}\n";
InstallScriptValues values;
- CHECK(ParseInstallScript(fnv, "Z:\\data\\games\\22380", &values, &reason));
+ CHECK(ParseInstallScript(fnv, "Z:\\data\\games\\22380", "", &values, &reason));
CHECK(values.user.empty() && values.machine.size() == 2);
CHECK(values.machine[0].key == "SOFTWARE\\Bethesda Softworks\\FalloutNV" && values.machine[0].name == "Installed Path" &&
values.machine[0].data == "\"Z:\\\\data\\\\games\\\\22380\\\\\"");
@@ -1301,13 +1301,13 @@ int main(int argc, char** argv) {
std::string utf16 = "\xff\xfe";
for (const char value : mixed) utf16 += std::string{value, '\0'};
values = {};
- CHECK(ParseInstallScript(utf16, "Z:\\g", &values, &reason));
+ CHECK(ParseInstallScript(utf16, "Z:\\g", "", &values, &reason));
CHECK(values.machine.empty() && values.user.size() == 2);
CHECK(values.user[0].key == "Software\\Studio\\Game" && values.user[0].name == "Installed" &&
values.user[0].data == "dword:00000001");
CHECK(values.user[1].name == "Ok" && values.user[1].data == "\"yes\"");
values = {};
- CHECK(!ParseInstallScript("\"InstallScript\" {", "Z:\\g", &values, &reason));
+ CHECK(!ParseInstallScript("\"InstallScript\" {", "Z:\\g", "", &values, &reason));
const auto script_root = std::filesystem::canonical(std::filesystem::temp_directory_path()) /
("playden-install-script-" + std::to_string(::getpid()));
@@ -1321,10 +1321,10 @@ int main(int argc, char** argv) {
std::ofstream(bottle / "system.reg") << system_reg;
::chmod((bottle / "system.reg").c_str(), 0600);
// No script: nothing found, nothing written.
- auto applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", bottle.string(), 1791500000);
+ auto applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", "", bottle.string(), 1791500000);
CHECK(applied.ok && applied.found.empty() && !std::filesystem::exists(bottle / "system.reg.playden-backup"));
std::ofstream(game / "InstallScript.vdf") << fnv;
- applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", bottle.string(), 1791500000);
+ applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", "", bottle.string(), 1791500000);
CHECK(applied.ok && applied.found == std::vector<std::string>{"InstallScript.vdf"} && applied.values == 2);
const auto written = ReadText(bottle / "system.reg");
CHECK(written.find("\n[SOFTWARE\\\\Bethesda Softworks\\\\FalloutNV] 1791500000\n"
@@ -1332,7 +1332,7 @@ int main(int argc, char** argv) {
CHECK(written.find("\n[Software\\\\Wow6432Node\\\\Bethesda Softworks\\\\FalloutNV] 1791500000\n") != std::string::npos);
CHECK(ReadText(bottle / "system.reg.playden-backup") == system_reg);
// Again: already there, so the hive is left as it is.
- applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", bottle.string(), 1791600000);
+ applied = ApplyInstallScripts(game.string(), "Z:\\data\\games\\22380", "", bottle.string(), 1791600000);
CHECK(applied.ok && ReadText(bottle / "system.reg") == written);
std::filesystem::remove_all(script_root);
}
diff --git a/tests/runtime_redist_test.cpp b/tests/runtime_redist_test.cpp
index b8efd95..aed6d94 100644
--- a/tests/runtime_redist_test.cpp
+++ b/tests/runtime_redist_test.cpp
@@ -330,8 +330,29 @@ void TestScripts() {
InstallScriptValues values;
CHECK(ParseInstallScript("\"InstallScript\" { \"Registry\" { \"HKEY_LOCAL_MACHINE\\\\Software\\\\Studio\" { \"string\" { "
"\"Path\" \"%INSTALLDIR%\" } } } } \"kvsignatures\" { \"InstallScript\" \"00\" }",
- "Z:\\games\\1", &values, &reason));
+ "Z:\\games\\1", "", &values, &reason));
CHECK(values.machine.size() == 2);
+ // Values under a language subkey apply for that language, then for English; (Default) is the unnamed value.
+ const std::string localized =
+ "\"InstallScript\" { \"Registry\" { \"HKEY_CURRENT_USER\\\\Software\\\\Studio\" { "
+ "\"string\" { \"(Default)\" \"main\" \"Plain\" \"p\" \"english\" { \"Name\" \"en\" } \"Russian\" { \"Name\" \"ru\" } } "
+ "\"dword\" { \"english\" { \"Language\" \"1\" } \"french\" { \"Language\" \"2\" } } } } }";
+ const auto parsed_for = [&](const std::string& language) {
+ InstallScriptValues parsed;
+ CHECK(ParseInstallScript(localized, "Z:\\games\\1", language, &parsed, &reason));
+ return parsed.user;
+ };
+ auto english = parsed_for("");
+ CHECK(english.size() == 4);
+ CHECK(FindValue(english, "Software\\Studio", "Name")->data == "\"en\"");
+ CHECK(FindValue(english, "Software\\Studio", "Language")->data == "dword:00000001");
+ CHECK(FindValue(english, "Software\\Studio", "Plain")->data == "\"p\"");
+ const auto unnamed = std::find_if(english.begin(), english.end(), [](const RegistryValue& value) { return value.default_value; });
+ CHECK(unnamed != english.end() && unnamed->name.empty() && unnamed->data == "\"main\"");
+ auto russian = parsed_for("russian");
+ CHECK(FindValue(russian, "Software\\Studio", "Name")->data == "\"ru\"");
+ CHECK(FindValue(russian, "Software\\Studio", "Language")->data == "dword:00000001"); // no Russian value: English
+ CHECK(FindValue(parsed_for("french"), "Software\\Studio", "Language")->data == "dword:00000002");
RedistEntry rooted{"X", "msiexec", "/i Z:\\data\\games\\696180\\\\tmp\\x.msi", ""};
CHECK(ClassifyRedist(rooted, "Z:\\data\\games\\696180", &package) == RedistAction::kNotRun);
RedistEntry dotted{"X", "msiexec", "/i Z:\\data\\games\\696180\\.\\x.msi", ""};