import json import os from pathlib import Path import runpy import subprocess import tempfile import unittest BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" COMPAT = runpy.run_path(str(BIN / "steam-compatibility"), run_name="steam_compatibility") SETUP = COMPAT["DD_ANTICHEAT_SETUP"] class AntiCheatRoutingTest(unittest.TestCase): def setUp(self): temp = tempfile.TemporaryDirectory() self.addCleanup(temp.cleanup) self.root = Path(temp.name) self.steam = self.root / "Steam" self.common = self.steam / "steamapps" / "common" self.tools = self.steam / "compatibilitytools.d" self.game = self.common / "Some Game" self.game.mkdir(parents=True) self.tools.mkdir(parents=True) self.record = self.root / "record.json" self.fex = self.root / "droiddeck-fex" self.fex.write_text("#!/bin/bash\nif [ \"$1\" = update ]; then echo \"$1\" >> \"$DD_RECORD.update\"; " "[ -n \"${DD_UPDATED_PATCHES:-}\" ] && printf '%s\\n' \"$DD_UPDATED_PATCHES\" > \"$DD_PATCHES\"; exit 0; fi\n" "python3 -c 'import json,os,sys; json.dump({\"argv\": sys.argv[2:], " "\"eac\": os.environ.get(\"PROTON_EAC_RUNTIME\"), \"be\": os.environ.get(\"PROTON_BATTLEYE_RUNTIME\")}, " "open(sys.argv[1], \"w\"))' \"$DD_RECORD\" \"$@\"\n") self.fex.chmod(0o755) self.patches = self.root / "fex-patches" self.patches.write_text("openat2-enosys-fallback\nfixed-guest-memory-above-host-address-limit\n") def tool(self, name, x86_64=True): tool = self.tools / name (tool / "files" / "lib" / "wine" / ("x86_64-unix" if x86_64 else "aarch64-unix")).mkdir(parents=True) if not x86_64: (tool / "files" / "bin-arm64").mkdir() (tool / "proton").write_text("#!/bin/sh\n") (tool / "proton").chmod(0o755) return tool def runtime(self, name, library): folder = self.common / name / "v2" / "lib64" folder.mkdir(parents=True) (folder / library).write_text("") return self.common / name def file(self, relative): path = self.game / relative path.parent.mkdir(parents=True, exist_ok=True) path.write_text("{}") def launch(self, verb="waitforexitandrun", extra=None): script = SETUP.replace("/usr/local/bin/droiddeck-fex", str(self.fex)).replace( "/usr/local/share/fex-emu/.droiddeck-patches", str(self.patches)) + ( "dd_game_cpus() { :; }\n" "verb=$1; shift\n" "dd_anticheat \"$@\"\n" "echo stayed\n") env = {"PATH": os.environ["PATH"], "HOME": str(self.root), "DD_RECORD": str(self.record), "DD_PATCHES": str(self.patches), "STEAM_COMPAT_INSTALL_PATH": str(self.game), "STEAM_COMPAT_CLIENT_INSTALL_PATH": str(self.steam)} env.update(extra or {}) result = subprocess.run(["bash", "-c", script, "launcher", verb, str(self.game / "game.exe")], env=env, capture_output=True, text=True, timeout=30) routed = json.loads(self.record.read_text()) if self.record.exists() else None return result, routed def test_eos_easy_anti_cheat_runs_the_newest_x86_64_build_under_fex(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") newest = self.tool("DroidDeck-Proton-11.0-10-x86_64") self.tool("DroidDeck-Proton-11.0-20", x86_64=False) runtime = self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") result, routed = self.launch() self.assertNotIn("stayed", result.stdout) self.assertEqual(routed["argv"], ["proton", str(newest / "proton"), "waitforexitandrun", str(self.game / "game.exe")]) self.assertEqual(routed["eac"], str(runtime)) self.assertIn("running DroidDeck-Proton-11.0-10-x86_64 under FEX", result.stderr) def test_battleye_sets_its_own_runtime(self): self.file("BattlEye/BEClient_x64.so") tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") runtime = self.runtime("Proton BattlEye Runtime", "beclient_x64.so") _, routed = self.launch() self.assertEqual((routed["argv"][1], routed["be"], routed["eac"]), (str(tool / "proton"), str(runtime), None)) def test_a_runtime_already_set_with_files_is_kept(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") own = self.root / "own-eac" (own / "v2").mkdir(parents=True) (own / "v2" / "easyanticheat_x64.so").write_text("") _, routed = self.launch(extra={"PROTON_EAC_RUNTIME": str(own)}) self.assertEqual(routed["eac"], str(own)) def test_games_without_anti_cheat_files_stay_on_arm64(self): self.file("Data/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") result, routed = self.launch() self.assertIsNone(routed) self.assertIn("stayed", result.stdout) self.assertEqual(result.stderr, "") def test_without_an_x86_64_build_the_launch_stays_on_arm64(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-20", x86_64=False) self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") result, routed = self.launch() self.assertIsNone(routed) self.assertIn("stayed", result.stdout) self.assertIn("no x86-64 DroidDeck-Proton is installed", result.stderr) def test_without_the_runtime_files_the_launch_stays_on_arm64(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") (self.common / "Proton EasyAntiCheat Runtime").mkdir(parents=True) result, routed = self.launch() self.assertIsNone(routed) self.assertIn("its Proton runtime is not installed", result.stderr) def test_the_user_can_turn_routing_off(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") result, routed = self.launch(extra={"DROIDDECK_ANTICHEAT": "off"}) self.assertIsNone(routed) self.assertIn("stayed", result.stdout) def test_a_tool_the_user_chose_is_kept(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") for chosen in ("GE-Proton11-15-aarch64", "DroidDeck-Bionic-14.1-r85", "proton_experimental"): result, routed = self.launch(extra={"DD_AC_TOOL": chosen}) self.assertIsNone(routed) self.assertIn("stayed", result.stdout) self.assertIn("%s was chosen for this game, so it runs as chosen" % chosen, result.stderr) def test_droiddeck_proton_builds_still_route(self): self.file("EasyAntiCheat/Settings.json") newest = self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") for own in ("DroidDeck-Proton 11-14.1", "DroidDeck-Proton-11-14.2"): self.record.unlink(missing_ok=True) result, routed = self.launch(extra={"DD_AC_TOOL": own}) self.assertEqual(routed["argv"][1], str(newest / "proton")) def test_a_fex_build_without_high_guest_memory_stays_on_arm64(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") for patches in ("openat2-enosys-fallback\n", None): if patches is None: self.patches.unlink() else: self.patches.write_text(patches) result, routed = self.launch() self.assertIsNone(routed) self.assertIn("stayed", result.stdout) self.assertIn("the installed FEX build cannot run anti-cheat", result.stderr) def test_an_older_fex_build_is_updated_before_routing(self): self.file("EasyAntiCheat/Settings.json") tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") self.patches.unlink() result, routed = self.launch(extra={"DD_UPDATED_PATCHES": "fixed-guest-memory-above-host-address-limit"}) self.assertEqual(routed["argv"][1], str(tool / "proton")) self.assertNotIn("cannot run anti-cheat", result.stderr) self.assertTrue((self.root / "record.json.update").exists()) def test_games_without_anti_cheat_files_do_not_update_fex(self): self.file("Data/Settings.json") self.launch() self.assertFalse((self.root / "record.json.update").exists()) def test_choices_are_kept_the_same_with_an_older_fex_build(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") self.patches.unlink() result, routed = self.launch(extra={"DD_AC_TOOL": "GE-Proton11-15-aarch64"}) self.assertIsNone(routed) self.assertIn("GE-Proton11-15-aarch64 was chosen for this game, so it runs as chosen", result.stderr) result, routed = self.launch(extra={"DROIDDECK_ANTICHEAT": "off"}) self.assertIsNone(routed) self.assertEqual(result.stderr, "") def test_the_fex_build_lists_its_patches(self): build = (BIN.parents[4] / "fex" / "build-in-arch.sh").read_text() self.assertIn("> out/usr/local/share/fex-emu/.droiddeck-patches", build) names = {p.stem.split("-", 1)[1] for p in (BIN.parents[4] / "fex" / "patches").glob("*.patch")} self.assertIn("fixed-guest-memory-above-host-address-limit", names) def test_adopted_tools_pass_their_own_folder_name(self): wrapper = COMPAT["extra_wrapper_sh"]("proton") self.assertIn('DD_AC_TOOL=$(basename "$(cd "$here" && pwd -P)") dd_anticheat "$@"', wrapper) self.assertNotIn("DD_AC_TOOL=", COMPAT["LAUNCHER_SH"]) def test_other_verbs_are_left_alone(self): self.file("EasyAntiCheat/Settings.json") self.tool("DroidDeck-Proton-11.0-1-x86_64") self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") result, routed = self.launch(verb="getcompatpath") self.assertIsNone(routed) self.assertIn("stayed", result.stdout) def test_launchers_check_before_arm64_setup_and_x86_64_tools_run_under_fex(self): launcher = COMPAT["LAUNCHER_SH"] self.assertLess(launcher.index('dd_anticheat "$@"'), launcher.index('dd_components "$depot"')) wrapper = COMPAT["extra_wrapper_sh"]("proton") self.assertLess(wrapper.index("dd_x86_64_proton() {"), wrapper.index("dd_fallback=")) self.assertLess(wrapper.index('droiddeck-fex proton "$here/proton"'), wrapper.index('dd_components "$here"')) self.assertIn('! dd_x86_64_proton "$d"', wrapper) if __name__ == "__main__": unittest.main()