mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: game debug logs also reach games started by a store client (#2343)
fix: propagate store launcher debug environment
This commit is contained in:
1 parent
a9524ea991
commit
448d296a2b
7 files changed
+138
-54
No files matched your search
@@ -5,6 +5,7 @@ import json
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
@@ -16,6 +17,7 @@ import urllib.request
|
||||
HOME = os.environ.get("HOME") or "/root"
|
||||
BIN = "/usr/local/bin"
|
||||
PROTON_RUN = os.path.join(BIN, "droiddeck-proton-run")
|
||||
GAME_DEBUG = runpy.run_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), "droiddeck-game-debug"))
|
||||
APP_ID = "2596113170"
|
||||
INSTALLER_URL = "https://downloader.battle.net/download/getInstallerForGame?os=win&gameProgram=BATTLENET_APP&version=Live"
|
||||
CLIENT_DIR = ("Program Files (x86)", "Battle.net")
|
||||
@@ -685,6 +687,7 @@ def steam_running(proc="/proc"):
|
||||
|
||||
def proton_env():
|
||||
env = dict(os.environ)
|
||||
env = GAME_DEBUG["apply_game_debug_logs"](env)
|
||||
if not steam_running():
|
||||
env.setdefault("PROTON_SPOOF_STEAMINPUT_VIDPID", "1")
|
||||
return env
|
||||
|
||||
@@ -24,6 +24,7 @@ import urllib.request
|
||||
HOME = os.environ.get("HOME") or "/root"
|
||||
SELF = os.path.abspath(__file__)
|
||||
BIN_DIR = os.path.dirname(SELF)
|
||||
GAME_DEBUG = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-debug"))
|
||||
STATE = os.path.join(HOME, ".local", "share", "droiddeck-epic")
|
||||
CURRENT = os.path.join(STATE, "current.json")
|
||||
APPS = os.path.join(STATE, "app")
|
||||
@@ -1196,6 +1197,7 @@ def run_game(request, session_env, running=None):
|
||||
exe = native_path(request.get("exe") or "")
|
||||
args = request.get("args") or []
|
||||
env = {k: v for k, v in session_env.items() if not k.startswith(("FEX_", "DROIDDECK_EPIC", "EGL_", "WEBKIT_"))}
|
||||
env = GAME_DEBUG["apply_game_debug_logs"](env)
|
||||
preload = env.pop(STEAM_PRELOAD, "")
|
||||
if preload:
|
||||
env["LD_PRELOAD"] = preload
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/python3
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
GAME_DEBUG_CHANNELS = (
|
||||
"timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree",
|
||||
)
|
||||
WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)")
|
||||
|
||||
|
||||
def game_debug_channels(*values):
|
||||
selectors = {}
|
||||
for value in values:
|
||||
if not isinstance(value, str) or "\0" in value or len(value) > 8192:
|
||||
continue
|
||||
for part in value.split(","):
|
||||
part = part.strip()
|
||||
match = WINE_DEBUG_SELECTOR.fullmatch(part)
|
||||
if match is None:
|
||||
continue
|
||||
key = (match[1] or "", match[3])
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = part
|
||||
for channel in GAME_DEBUG_CHANNELS:
|
||||
key = ("", channel)
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = "+" + channel
|
||||
formatted = ",".join(selectors.values())
|
||||
if len(formatted) > 8192:
|
||||
formatted = ",".join("+" + channel for channel in GAME_DEBUG_CHANNELS)
|
||||
return formatted
|
||||
|
||||
|
||||
def load_config():
|
||||
try:
|
||||
path = Path(os.environ.get("HOME") or "/root") / ".config/droiddeck/game-environment.json"
|
||||
with path.open(encoding="utf-8") as source:
|
||||
return json.load(source)
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def session_debug_dir(env):
|
||||
return env.get("BL_DEBUG_DIR", "")
|
||||
|
||||
|
||||
def apply_game_debug_logs(env, config=None, debug_dir=None):
|
||||
if config is None:
|
||||
config = load_config()
|
||||
if not isinstance(config, dict) or config.get("version") != 1 or config.get("gameDebugLogs") is not True:
|
||||
return env
|
||||
if debug_dir is None:
|
||||
debug_dir = session_debug_dir(env)
|
||||
if (not isinstance(debug_dir, str) or "\0" in debug_dir or len(debug_dir) > 8192
|
||||
or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)):
|
||||
print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": debug_dir,
|
||||
"PROTON_CRASH_REPORT_DIR": debug_dir,
|
||||
"DXVK_LOG_PATH": debug_dir,
|
||||
"DXVK_LOG_LEVEL": "debug",
|
||||
"VKD3D_DEBUG": "info",
|
||||
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
|
||||
})
|
||||
return result
|
||||
@@ -17,6 +17,10 @@ D3D9_DEFAULT_MEMORY_MB = 4096
|
||||
SYNC_KEYS = ("BL_SYNC", "BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
|
||||
SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
|
||||
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
|
||||
GAME_DEBUG = runpy.run_path(str(Path(__file__).with_name("droiddeck-game-debug")))
|
||||
game_debug_channels = GAME_DEBUG["game_debug_channels"]
|
||||
apply_game_debug_logs = GAME_DEBUG["apply_game_debug_logs"]
|
||||
session_debug_dir = GAME_DEBUG["session_debug_dir"]
|
||||
|
||||
|
||||
# Prefixes several games share; the game itself is the Steam app being launched.
|
||||
@@ -661,55 +665,6 @@ def bridge_feature_level(env):
|
||||
return "Mali bridge: VKD3D_FEATURE_LEVEL %s capped at 12_0 (no ray tracing or mesh shaders)" % was
|
||||
|
||||
|
||||
GAME_DEBUG_CHANNELS = (
|
||||
"timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree",
|
||||
)
|
||||
WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)")
|
||||
|
||||
|
||||
def game_debug_channels(*values):
|
||||
selectors = {}
|
||||
for value in values:
|
||||
if not isinstance(value, str) or "\0" in value or len(value) > 8192:
|
||||
continue
|
||||
for part in value.split(","):
|
||||
part = part.strip()
|
||||
match = WINE_DEBUG_SELECTOR.fullmatch(part)
|
||||
if match is None:
|
||||
continue
|
||||
key = (match[1] or "", match[3])
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = part
|
||||
for channel in GAME_DEBUG_CHANNELS:
|
||||
key = ("", channel)
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = "+" + channel
|
||||
formatted = ",".join(selectors.values())
|
||||
if len(formatted) > 8192:
|
||||
formatted = ",".join("+" + channel for channel in GAME_DEBUG_CHANNELS)
|
||||
return formatted
|
||||
|
||||
|
||||
def apply_game_debug_logs(env, config, debug_dir):
|
||||
if not isinstance(config, dict) or config.get("version") != 1 or config.get("gameDebugLogs") is not True:
|
||||
return env
|
||||
if (not isinstance(debug_dir, str) or "\0" in debug_dir or len(debug_dir) > 8192
|
||||
or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)):
|
||||
print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": debug_dir,
|
||||
"PROTON_CRASH_REPORT_DIR": debug_dir,
|
||||
"DXVK_LOG_PATH": debug_dir,
|
||||
"DXVK_LOG_LEVEL": "debug",
|
||||
"VKD3D_DEBUG": "info",
|
||||
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
def sync_config(config, app_id):
|
||||
games = config.get("games", {})
|
||||
return {
|
||||
@@ -1333,7 +1288,7 @@ def main():
|
||||
return 2
|
||||
env = game_gpu(os.environ.copy())
|
||||
mic_enabled = env.get("BL_MIC_ENABLED")
|
||||
debug_dir = env.get("BL_DEBUG_DIR", "")
|
||||
debug_dir = session_debug_dir(env)
|
||||
prefix_path = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
app_id = game_id(env)
|
||||
components = ""
|
||||
|
||||
@@ -47,6 +47,47 @@ class LogTest(Temp):
|
||||
self.assertRegex(log.read_text(), r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d \[\d+\] second\n$")
|
||||
|
||||
|
||||
class StoreDebugEnvironmentTest(Temp):
|
||||
def config(self, enabled):
|
||||
config = self.tmp / ".config/droiddeck/game-environment.json"
|
||||
config.parent.mkdir(parents=True, exist_ok=True)
|
||||
config.write_text(json.dumps({"version": 1, "gameDebugLogs": enabled}))
|
||||
|
||||
def env(self, values=None):
|
||||
debug_dir = self.tmp / "session"
|
||||
debug_dir.mkdir(exist_ok=True)
|
||||
base = {"HOME": str(self.tmp), "BL_DEBUG_DIR": str(debug_dir)}
|
||||
base.update(values or {})
|
||||
return base
|
||||
|
||||
def test_store_proton_command_gets_debug_defaults_when_enabled(self):
|
||||
self.config(True)
|
||||
with mock.patch.dict(os.environ, self.env(), clear=True):
|
||||
result = BNET["proton_env"]()
|
||||
self.assertEqual(result["PROTON_LOG"], "1")
|
||||
self.assertEqual(result["DXVK_LOG_LEVEL"], "debug")
|
||||
self.assertEqual(result["PROTON_LOG_DIR"], str(self.tmp / "session"))
|
||||
self.assertIn("+seh", result["WINEDEBUG"])
|
||||
|
||||
def test_store_proton_command_keeps_debug_off_when_disabled(self):
|
||||
self.config(False)
|
||||
with mock.patch.dict(os.environ, self.env(), clear=True):
|
||||
result = BNET["proton_env"]()
|
||||
self.assertNotIn("PROTON_LOG", result)
|
||||
self.assertNotIn("DXVK_LOG_LEVEL", result)
|
||||
|
||||
def test_store_proton_command_keeps_user_debug_values(self):
|
||||
self.config(True)
|
||||
values = {"PROTON_LOG": "0", "DXVK_LOG_LEVEL": "none", "WINEDEBUG": "-all", "PROTON_LOG_DIR": "/custom"}
|
||||
with mock.patch.dict(os.environ, self.env(values), clear=True):
|
||||
result = BNET["proton_env"]()
|
||||
self.assertEqual(result["PROTON_LOG"], "1")
|
||||
self.assertEqual(result["DXVK_LOG_LEVEL"], "debug")
|
||||
self.assertEqual(result["PROTON_LOG_DIR"], str(self.tmp / "session"))
|
||||
self.assertIn("+seh", result["WINEDEBUG"])
|
||||
self.assertIn("-all", result["WINEDEBUG"])
|
||||
|
||||
|
||||
class IdTest(unittest.TestCase):
|
||||
def test_the_prefix_id_is_the_shortcut_id_the_app_names(self):
|
||||
self.assertEqual(int(BNET["APP_ID"]), zlib.crc32(b'"droiddeck-battlenet"Battle.net') | 0x80000000)
|
||||
|
||||
@@ -887,17 +887,28 @@ class BrokerTest(EpicTestCase):
|
||||
folder.mkdir()
|
||||
(folder / ".droiddeck-store.json").write_text(json.dumps({"store": "epic", "id": "Fig", "args": ["-x"]}))
|
||||
(folder / ".droiddeck-launch.bat").write_text('if exist "%~dp0.droiddeck-epic-args" goto client\r\n')
|
||||
debug_dir = self.tmp / "session"
|
||||
debug_dir.mkdir()
|
||||
config = self.home / ".config/droiddeck/game-environment.json"
|
||||
config.parent.mkdir(parents=True)
|
||||
config.write_text(json.dumps({"version": 1, "gameDebugLogs": True}))
|
||||
calls = []
|
||||
|
||||
def popen(command, env=None, cwd=None, start_new_session=False):
|
||||
calls.append((command, env.get("DROIDDECK_EPIC_HANDLED"), start_new_session))
|
||||
calls.append((command, env.get("DROIDDECK_EPIC_HANDLED"), env.get("BL_DEBUG_DIR"),
|
||||
env.get("PROTON_LOG"), env.get("WINEDEBUG"), start_new_session))
|
||||
return mock.Mock(wait=mock.Mock(return_value=7))
|
||||
|
||||
running = []
|
||||
with mock.patch.object(subprocess, "Popen", popen):
|
||||
code = G["run_game"]({"exe": str(folder / "Fig.exe"), "args": ["-epicapp=Fig"]}, {"PATH": "/usr/bin"}, running)
|
||||
with mock.patch.dict(os.environ, {"HOME": str(self.home), "BL_DEBUG_DIR": str(debug_dir),
|
||||
"PROTON_LOG": "0", "WINEDEBUG": "-all"}), \
|
||||
mock.patch.object(subprocess, "Popen", popen):
|
||||
code = G["run_game"]({"exe": str(folder / "Fig.exe"), "args": ["-epicapp=Fig"]},
|
||||
{"PATH": "/usr/bin", "BL_DEBUG_DIR": str(debug_dir)}, running)
|
||||
self.assertEqual(7, code)
|
||||
self.assertEqual(([G["PROTON_RUN"], str(folder / ".droiddeck-launch.bat")], "1", True), calls[0])
|
||||
self.assertEqual(([G["PROTON_RUN"], str(folder / ".droiddeck-launch.bat")], "1", str(debug_dir), "1",
|
||||
mock.ANY, True), calls[0])
|
||||
self.assertIn("+seh", calls[0][4])
|
||||
self.assertEqual([], running)
|
||||
self.assertEqual(b"-epicapp=Fig -x\r\n", (folder / ".droiddeck-epic-args").read_bytes())
|
||||
|
||||
|
||||
Reference in new issue
Block a user