Files
DroidDeck/tools/tests/test_anticheat_routing.py
T
maxjivi05 b11bac2539 Run games with anti-cheat files on an x86-64 DroidDeck-Proton under FEX
The Proton launchers look for Easy Anti-Cheat or BattlEye bridge files in
the game folder and, when an x86-64 DroidDeck-Proton and the matching Proton
runtime are installed, hand the launch to that Proton under FEX with the
game's own prefix. Picking the x86-64 tool directly also runs it under FEX.
DROIDDECK_ANTICHEAT=off keeps a game on ARM64.
2026-12-03 13:01:38 -05:00

148 lines
6.8 KiB
Python

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\npython3 -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)
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)) + (
"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),
"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_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()