mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
feat: launch Easy Anti-Cheat games offline when they support it (#1039)
This commit is contained in:
1 parent
8ca389149b
commit
2a8618ab5c
6 files changed
+93
No files matched your search
@@ -126,6 +126,35 @@ def skip_red_launcher(command):
|
||||
return command
|
||||
|
||||
|
||||
def offline_without_anticheat(command, env):
|
||||
"""Start the configured game executable when the player opts into launching without EAC."""
|
||||
if (env.get("DROIDDECK_ANTICHEAT_OFFLINE") != "1" or len(command) <= 2
|
||||
or command[1] != "waitforexitandrun"
|
||||
or not re.fullmatch(r"start_protected_game(?:_?x64|_?64)?\.exe",
|
||||
os.path.basename(command[2]), re.IGNORECASE)):
|
||||
return command
|
||||
folder = os.path.dirname(command[2])
|
||||
try:
|
||||
with open(os.path.join(folder, "EasyAntiCheat", "settings.json"), encoding="utf-8-sig") as source:
|
||||
executable = json.load(source).get("executable")
|
||||
except (OSError, ValueError, AttributeError):
|
||||
return command
|
||||
if not isinstance(executable, str) or not executable:
|
||||
return command
|
||||
relative = os.path.normpath(executable.replace("\\", "/"))
|
||||
game = os.path.join(folder, relative)
|
||||
if os.path.isabs(relative) or relative.startswith("..") or not os.path.isfile(game):
|
||||
return command
|
||||
# Resolve symlinks before accepting an executable inside the game directory.
|
||||
root = os.path.realpath(folder)
|
||||
if os.path.commonpath((root, os.path.realpath(game))) != root:
|
||||
return command
|
||||
if os.path.normcase(os.path.abspath(game)) == os.path.normcase(os.path.abspath(command[2])):
|
||||
return command
|
||||
print("droiddeck-game-env: started without Easy Anti-Cheat (offline only)", file=sys.stderr)
|
||||
return command[:2] + [game] + command[3:]
|
||||
|
||||
|
||||
def engine_fixes(exe, args):
|
||||
"""Environment and extra arguments a game needs because of what it is built with."""
|
||||
game = Game(exe, args)
|
||||
@@ -326,6 +355,8 @@ def main():
|
||||
env = apply_config(env, {"version": 1}, app_id, fixes)
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
|
||||
if app_id and len(command) > 1 and command[1] == "waitforexitandrun":
|
||||
command = offline_without_anticheat(command, env)
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env = force_ssbs(command, env)
|
||||
|
||||
@@ -201,6 +201,64 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
(other / "Other.exe").touch()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(other / "Other.exe"), []), ({}, [], []))
|
||||
|
||||
def test_easy_anti_cheat_games_start_offline_only_when_opted_in(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
game = Path(tmp) / "ELDEN RING/Game"
|
||||
(game / "EasyAntiCheat").mkdir(parents=True)
|
||||
for name in ("start_protected_game.exe", "eldenring.exe"):
|
||||
(game / name).touch()
|
||||
(game / "EasyAntiCheat/settings.json").write_text('\ufeff{ "executable" : "eldenring.exe" }', encoding="utf-8")
|
||||
command = ["proton", "waitforexitandrun", str(game / "start_protected_game.exe"), "-arg"]
|
||||
offline = MODULE["offline_without_anticheat"]
|
||||
self.assertEqual(offline(command, {}), command)
|
||||
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "0"}), command)
|
||||
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}),
|
||||
["proton", "waitforexitandrun", str(game / "eldenring.exe"), "-arg"])
|
||||
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "../../escape.exe" }')
|
||||
(Path(tmp) / "escape.exe").touch()
|
||||
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
||||
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "missing.exe" }')
|
||||
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
||||
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "link/escape.exe" }')
|
||||
outside = Path(tmp) / "outside"
|
||||
outside.mkdir()
|
||||
(outside / "escape.exe").touch()
|
||||
(game / "link").symlink_to(outside, target_is_directory=True)
|
||||
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
||||
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "eldenring.exe" }')
|
||||
plain = ["proton", "waitforexitandrun", str(game / "eldenring.exe")]
|
||||
self.assertEqual(offline(plain, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), plain)
|
||||
self.assertEqual(offline(["proton", "run", command[2]],
|
||||
{"DROIDDECK_ANTICHEAT_OFFLINE": "1"}),
|
||||
["proton", "run", command[2]])
|
||||
|
||||
def test_easy_anti_cheat_forwarding_through_entrypoint(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
game = home / "ELDEN RING/Game"
|
||||
(game / "EasyAntiCheat").mkdir(parents=True)
|
||||
bootstrapper = game / "start_protected_game.exe"
|
||||
target = game / "eldenring.exe"
|
||||
bootstrapper.touch()
|
||||
target.touch()
|
||||
(game / "EasyAntiCheat/settings.json").write_text(json.dumps({"executable": "eldenring.exe"}))
|
||||
proton = home / "fake-proton"
|
||||
proton.write_text("#!" + sys.executable + "\nimport json, sys\nprint(json.dumps(sys.argv[1:]))\n")
|
||||
proton.chmod(0o755)
|
||||
config = home / ".config/droiddeck/game-environment.json"
|
||||
config.parent.mkdir(parents=True)
|
||||
env = dict(os.environ, HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/42")
|
||||
env.pop("DROIDDECK_ANTICHEAT_OFFLINE", None)
|
||||
for setting, expected in (("1", target), ("0", bootstrapper), (None, bootstrapper)):
|
||||
with self.subTest(setting=setting):
|
||||
values = {} if setting is None else {"DROIDDECK_ANTICHEAT_OFFLINE": setting}
|
||||
config.write_text(json.dumps({"version": 1, "games": {"42": values}}))
|
||||
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"),
|
||||
str(proton), "waitforexitandrun", str(bootstrapper), "-arg"],
|
||||
env=env, text=True, capture_output=True, check=True)
|
||||
self.assertEqual(json.loads(result.stdout.strip()),
|
||||
["waitforexitandrun", str(expected), "-arg"])
|
||||
|
||||
def test_deep_rock_gdk_avoids_the_raytracing_pipeline_crash(self):
|
||||
game = "/game/FSD/Binaries/WinGDK/FSD-WinGDK-Shipping.exe"
|
||||
env, extra, notes = MODULE["engine_fixes"](game, [])
|
||||
|
||||
Reference in new issue
Block a user