diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index ef73b33156..0ba853a6ef 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -827,18 +827,49 @@ def scripts_digest(scripts): return digest.hexdigest() +def only_guarded_runs(items): + # True when every action in the scripts is a "run process" entry. With all their hasrunkeys set, Steam's + # evaluator would run nothing, so the scripts need no run even when Steam has rewritten the file (its + # SteamID, language, install path or order change between launches). + found = False + for _, entries in items: + if not isinstance(entries, list): + return False + for _, entry in entries: + if not isinstance(entry, list): + return False + for _, block in entry: + if not isinstance(block, list): + continue + for section, actions in block: + if section.lower() != "run process" or not isinstance(actions, list): + return False + for _, action in actions: + if not isinstance(action, list) or not any( + isinstance(v, str) and re.fullmatch(r"process [0-9]+", n.lower()) for n, v in action): + return False + found = True + return found + + def install_scripts_done(scripts, env): prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx" try: - if (prefix / INSTALL_STAMP).read_text().strip() != scripts_digest(scripts): - return False - keys = set() + keys, parsed = set(), [] for path in scripts: - keys |= run_keys(read_vdf(Path(path).read_text(encoding="utf-8", errors="replace"))) + parsed.append(read_vdf(Path(path).read_text(encoding="utf-8", errors="replace"))) + keys |= run_keys(parsed[-1]) values = registry_values(prefix / "system.reg") except (OSError, ValueError): return False - return bool(keys) and all(has_run(key, value, values) for key, value in keys) + if not keys or not all(has_run(key, value, values) for key, value in keys): + return False + try: + if (prefix / INSTALL_STAMP).read_text().strip() == scripts_digest(scripts): + return True + except OSError: + pass + return all(only_guarded_runs(items) for items in parsed) def record_install_scripts(digest, env): diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 8bff7c696f..7108d6dbc3 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1031,12 +1031,35 @@ class GameEnvironmentTest(unittest.TestCase): self.assertFalse(done([str(script)], env)) (prefix / "system.reg").write_text(self.REDIST + self.SETUP) self.assertTrue(done([str(script)], env)) + # Steam rewrote the file: only marked "run process" entries, so its evaluator would run nothing either script.write_text(self.SCRIPT.replace("x64.cmd", "x64-update.cmd")) + self.assertTrue(done([str(script)], env)) + script.write_text(self.SCRIPT.replace('"Setup"', '"Setup 2"')) self.assertFalse(done([str(script)], env)) script.write_text('"InstallScript" { "Registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "%INSTALLDIR%" } } } }') MODULE["record_install_scripts"](MODULE["scripts_digest"]([str(script)]), env) self.assertFalse(done([str(script)], env)) + def test_marked_run_process_scripts_count_as_done_without_a_record(self): + with tempfile.TemporaryDirectory() as tmp: + script = Path(tmp) / "evaluatorscript_291550.vdf" + script.write_text(self.SCRIPT.replace('"0" { "appid" "228980"', + '"0" { "appid" "228980" "mode" "1" "language" "english" ' + '"install_path" "/root/x" "SteamID" "7656"')) + prefix = Path(tmp) / "compat/pfx" + prefix.mkdir(parents=True) + env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)} + done = MODULE["install_scripts_done"] + (prefix / "system.reg").write_text(self.REDIST) + self.assertFalse(done([str(script)], env)) + (prefix / "system.reg").write_text(self.REDIST + self.SETUP) + self.assertTrue(done([str(script)], env)) + (prefix / MODULE["INSTALL_STAMP"]).write_text("an older digest\n") + self.assertTrue(done([str(script)], env)) + script.write_text(self.SCRIPT.replace('"run process" {', + '"registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "x" } } } "run process" {')) + self.assertFalse(done([str(script)], env)) + def test_the_evaluator_is_skipped_once_it_finished_the_same_scripts(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) @@ -1052,8 +1075,12 @@ class GameEnvironmentTest(unittest.TestCase): proton.write_text("#!/bin/sh\necho run >> %s\nexit ${EXIT_CODE:-0}\n" % shlex.quote(str(runs))) proton.chmod(0o755) - def evaluate(exit_code="0"): - script.write_text(self.SCRIPT if exit_code != "changed" else self.SCRIPT.replace("setup.exe", "setup-update.exe")) + # a registry action besides the marked runs: Steam's evaluator has work to do, so it runs once + with_registry = self.SCRIPT.replace( + '"run process" {', '"registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "x" } } } "run process" {') + + def evaluate(exit_code="0", text=None): + script.write_text(text or (with_registry if exit_code != "changed" else with_registry.replace("setup.exe", "setup-update.exe"))) env = dict(os.environ, HOME=tmp, STEAM_COMPAT_CLIENT_INSTALL_PATH=str(root), STEAM_COMPAT_DATA_PATH=str(prefix.parent), EXIT_CODE="0" if exit_code == "changed" else exit_code) result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(proton), "run", @@ -1066,6 +1093,8 @@ class GameEnvironmentTest(unittest.TestCase): self.assertEqual(evaluate(), (0, 2)) self.assertEqual(evaluate(), (0, 2)) self.assertEqual(evaluate("changed"), (0, 3)) + # only marked "run process" entries, all set: skipped even though the file differs from the recorded one + self.assertEqual(evaluate(text=self.SCRIPT.replace("x64.cmd", "x64-update.cmd")), (0, 3)) def test_the_mali_bridge_caps_the_vkd3d_feature_level(self): bridge = {"BL_VKBRIDGE": "1", "VKD3D_FEATURE_LEVEL": "12_2"}