mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
chore: merge main into feat/lse-emu
This commit is contained in:
commit
e87eebfaec
194 files changed
+12217
-1137
No files matched your search
@@ -927,6 +927,33 @@ def steam_shortcut_state(agent_dir, game_id, timeout=6):
|
||||
time.sleep(min(0.5, max(0, deadline - time.monotonic())))
|
||||
|
||||
|
||||
def steam_ready(agent_dir):
|
||||
expression = """(() => {
|
||||
const store = globalThis.appStore;
|
||||
return !!store?.m_bIsInitialized && typeof globalThis.SteamClient?.Apps?.ContinueGameAction === 'function';
|
||||
})()"""
|
||||
return cdp_eval(agent_dir, expression, await_promise=False, timeout=3).get("value") is True
|
||||
|
||||
|
||||
def steam_clear_pending_interstitial(agent_dir, app_id):
|
||||
if not isinstance(app_id, str) or not app_id.isascii() or not app_id.isdigit() or int(app_id) <= 0:
|
||||
raise AgentError("INVALID_APP_ID", "appId must be a positive decimal Steam app id")
|
||||
expression = """(async () => {
|
||||
const apps = globalThis.SteamClient?.Apps;
|
||||
if (typeof apps?.GetActiveGameActions !== 'function' || typeof apps.ContinueGameAction !== 'function') return false;
|
||||
const active = await apps.GetActiveGameActions() || [];
|
||||
for (const action of active) {
|
||||
const appid = String(action?.strAppID ?? action?.gameid ?? action?.nAppID ?? '');
|
||||
if (appid === %s && action?.strTaskName === 'ShowInterstitials') {
|
||||
apps.ContinueGameAction(action.nGameActionID, appid, 'ShowInterstitials');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})()""" % json.dumps(app_id)
|
||||
return cdp_eval(agent_dir, expression, timeout=3).get("value") is True
|
||||
|
||||
|
||||
def game_pids(app_id):
|
||||
wanted = [("SteamAppId=%s" % app_id).encode(), ("SteamGameId=%s" % app_id).encode()]
|
||||
me = os.getpid()
|
||||
@@ -1261,6 +1288,19 @@ def main(argv):
|
||||
return 1
|
||||
print(state)
|
||||
return {"ready": 0, "missing": 4, "not-shortcut": 3}.get(state, 1)
|
||||
if argv and argv[0] == "--steam-ready":
|
||||
try:
|
||||
return 0 if steam_ready(Path(base) / "agent") else 1
|
||||
except (AgentError, OSError, ValueError):
|
||||
return 1
|
||||
if argv and argv[0] == "--steam-clear-pending-interstitial":
|
||||
if len(argv) != 2:
|
||||
print("usage: droiddeck-agent --steam-clear-pending-interstitial <appid>", file=sys.stderr)
|
||||
return 2
|
||||
try:
|
||||
return 0 if steam_clear_pending_interstitial(Path(base) / "agent", argv[1]) else 1
|
||||
except (AgentError, OSError, ValueError):
|
||||
return 1
|
||||
serve(Path(base) / "agent", focus="--no-focus" not in argv)
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
export FLATPAK_BWRAP=/usr/local/bin/droiddeck-bwrap
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE GALLIUM_DRIVER LIBGL_KOPPER_DRI2 VK_ICD_FILENAMES VK_DRIVER_FILES
|
||||
case ":${XDG_DATA_DIRS:-}:" in
|
||||
*"/flatpak/exports/share:"*) ;;
|
||||
*) export XDG_DATA_DIRS=$HOME/.local/share/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} ;;
|
||||
|
||||
@@ -17,12 +17,12 @@ SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
|
||||
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
|
||||
|
||||
|
||||
def game_id(env):
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
if not prefix:
|
||||
return None
|
||||
value = prefix.rsplit("/", 1)[-1]
|
||||
if not re.fullmatch(r"-?[0-9]+", value):
|
||||
# Prefixes several games share; the game itself is the Steam app being launched.
|
||||
SHARED_PREFIXES = {"2929927072"}
|
||||
|
||||
|
||||
def app_number(value):
|
||||
if not re.fullmatch(r"-?[0-9]+", value or ""):
|
||||
return None
|
||||
number = int(value)
|
||||
if not -(2**31) <= number < 2**32 or number == 0:
|
||||
@@ -30,6 +30,26 @@ def game_id(env):
|
||||
return str(number % 2**32)
|
||||
|
||||
|
||||
def game_id(env):
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
if not prefix:
|
||||
return None
|
||||
found = app_number(prefix.rsplit("/", 1)[-1])
|
||||
if found in SHARED_PREFIXES:
|
||||
return app_number(env.get("SteamAppId", "")) or shortcut_number(env.get("SteamGameId", "")) or found
|
||||
return found
|
||||
|
||||
|
||||
def shortcut_number(value):
|
||||
"""The shortcut appid inside Steam's 64-bit shortcut game id `(appid << 32) | 0x02000000`."""
|
||||
if not re.fullmatch(r"[0-9]{1,20}", value or ""):
|
||||
return None
|
||||
number = int(value)
|
||||
if number >= 2**64 or number & 0xFFFFFFFF != 0x02000000:
|
||||
return None
|
||||
return app_number(str(number >> 32))
|
||||
|
||||
|
||||
DOTNET_FEX = {
|
||||
"FEX_TSOENABLED": "1",
|
||||
"FEX_VECTORTSOENABLED": "1",
|
||||
@@ -333,12 +353,12 @@ def engine_fixes(exe, args):
|
||||
return env, extra, notes
|
||||
|
||||
|
||||
def win_components(compat, app_id):
|
||||
def win_components(compat, app_id, proton=None, env=None):
|
||||
if not compat:
|
||||
return ""
|
||||
try:
|
||||
module = runpy.run_path(str(Path(__file__).resolve().parent / "droiddeck-wincomponents"))
|
||||
names, notes = module["apply"](compat.rstrip("/"), app_id)
|
||||
names, notes = module["apply"](compat.rstrip("/"), app_id, proton=proton, env=env or os.environ)
|
||||
for note in notes:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
return module["overrides_value"](names)
|
||||
@@ -859,6 +879,60 @@ WINE_DLL_DIRS = ("/lib/wine/i386-windows", "/lib/wine/x86_64-windows", "/lib/win
|
||||
"/lib/wine/fakedlls", "/lib64/wine", "/lib64/wine/fakedlls", "/lib64/wine/x86_64-windows")
|
||||
|
||||
|
||||
FOREIGN_SUFFIX = ".foreign-arch"
|
||||
PE = runpy.run_path(str(Path(__file__).resolve().parent / "droiddeck-wine-pe"))
|
||||
pe_machine = PE["pe_machine"]
|
||||
|
||||
|
||||
def repair_foreign_system_dlls(prefix, proton, env=None):
|
||||
dist = Path(proton).parent / "files/lib/wine"
|
||||
windows = Path(prefix) / "pfx/drive_c/windows"
|
||||
machines_by_folder = PE["proton_pe_machines"](proton, env or {})
|
||||
if machines_by_folder is None:
|
||||
return []
|
||||
repaired = []
|
||||
for folder, (libdir, machines) in machines_by_folder.items():
|
||||
builtins = dist / libdir
|
||||
try:
|
||||
builtin_names = {name.lower(): name for name in os.listdir(builtins)}
|
||||
except OSError:
|
||||
continue
|
||||
try:
|
||||
names = sorted(os.listdir(windows / folder))
|
||||
except OSError:
|
||||
continue
|
||||
for name in names:
|
||||
path = windows / folder / name
|
||||
builtin_name = builtin_names.get(name.lower())
|
||||
source = builtins / builtin_name if builtin_name else builtins / name
|
||||
if path.is_symlink() or not name.lower().endswith(".dll") or not source.is_file() or not path.is_file():
|
||||
continue
|
||||
machine = pe_machine(path)
|
||||
if machine is None or PE["machine_compatible"](path, machines, machine):
|
||||
continue
|
||||
link = windows / folder / (name + ".bl-new")
|
||||
backup = windows / folder / (name + FOREIGN_SUFFIX)
|
||||
serial = 1
|
||||
while os.path.lexists(backup):
|
||||
backup = windows / folder / (name + FOREIGN_SUFFIX + ".%d" % serial)
|
||||
serial += 1
|
||||
try:
|
||||
os.symlink(os.path.relpath(source, path.parent), link)
|
||||
os.replace(path, backup)
|
||||
try:
|
||||
os.replace(link, path)
|
||||
except OSError:
|
||||
if not os.path.lexists(path) and os.path.lexists(backup):
|
||||
os.replace(backup, path)
|
||||
raise
|
||||
except OSError:
|
||||
if link.is_symlink():
|
||||
link.unlink()
|
||||
continue
|
||||
repaired.append("%s/%s (machine 0x%x)" % (folder, name, machine))
|
||||
return repaired
|
||||
|
||||
|
||||
def is_wine_dll_link(path):
|
||||
try:
|
||||
return os.path.islink(path) and os.path.dirname(os.readlink(path)).endswith(WINE_DLL_DIRS)
|
||||
@@ -1156,6 +1230,42 @@ def main():
|
||||
env = game_gpu(os.environ.copy())
|
||||
mic_enabled = env.get("BL_MIC_ENABLED")
|
||||
debug_dir = env.get("BL_DEBUG_DIR", "")
|
||||
prefix_path = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
app_id = game_id(env)
|
||||
components = ""
|
||||
waiting = bool(app_id and len(command) > 1 and command[1] == "waitforexitandrun")
|
||||
config = {}
|
||||
launch_config = None
|
||||
launch_config_valid = True
|
||||
effective_env = env
|
||||
if waiting:
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
launch_config = config
|
||||
except FileNotFoundError:
|
||||
launch_config = {"version": 1}
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
launch_config_valid = False
|
||||
if launch_config_valid:
|
||||
try:
|
||||
effective_env = apply_config(env, launch_config, app_id)
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
launch_config_valid = False
|
||||
if not launch_config_valid:
|
||||
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
|
||||
if waiting:
|
||||
components = win_components(prefix_path, app_id, command[0], effective_env)
|
||||
if prefix_path and command:
|
||||
try:
|
||||
fixed = repair_foreign_system_dlls(prefix_path, command[0], effective_env)
|
||||
except OSError as error:
|
||||
fixed = []
|
||||
print("droiddeck-game-env: prefix system DLL check skipped (%s)" % error, file=sys.stderr)
|
||||
if fixed:
|
||||
print("droiddeck-game-env: replaced foreign-architecture system DLLs with this Proton's own: %s" % ", ".join(fixed),
|
||||
file=sys.stderr)
|
||||
scripts = mark_install_scripts(command, env)
|
||||
if scripts and install_scripts_done(scripts, env):
|
||||
print("droiddeck-game-env: install scripts already run in this prefix; evaluator skipped", file=sys.stderr)
|
||||
@@ -1164,8 +1274,6 @@ def main():
|
||||
digest = scripts_digest(scripts) if scripts else None
|
||||
except OSError:
|
||||
digest = None
|
||||
app_id = game_id(env)
|
||||
waiting = bool(app_id and len(command) > 1 and command[1] == "waitforexitandrun")
|
||||
diagnostic_app_id = app_id if waiting and os.environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") == "1" else None
|
||||
dirt_prefix = None
|
||||
if app_id:
|
||||
@@ -1183,7 +1291,6 @@ def main():
|
||||
for note in notes:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
command += extra
|
||||
components = win_components(env.get("STEAM_COMPAT_DATA_PATH", ""), app_id)
|
||||
if components:
|
||||
own = fixes.get("WINEDLLOVERRIDES")
|
||||
fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components
|
||||
@@ -1191,22 +1298,21 @@ def main():
|
||||
if dirt_prefix:
|
||||
own = fixes.get("WINEDLLOVERRIDES")
|
||||
fixes["WINEDLLOVERRIDES"] = own + ";ws2_32=n,b" if own else "ws2_32=n,b"
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
config = {}
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
if waiting:
|
||||
if waiting:
|
||||
if launch_config_valid:
|
||||
if "vblank_mode" in config.get("shared", {}):
|
||||
fixes.pop("vblank_mode", None)
|
||||
env = apply_config(env, config, app_id, fixes)
|
||||
else:
|
||||
env = apply_config(env, launch_config, app_id, fixes)
|
||||
else:
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
env = apply_config(env, sync_config(config, app_id), app_id)
|
||||
except FileNotFoundError:
|
||||
if waiting:
|
||||
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)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
|
||||
if waiting:
|
||||
before_debug = env
|
||||
env = apply_game_debug_logs(env, config, debug_dir)
|
||||
|
||||
@@ -70,8 +70,19 @@ def mapping(root):
|
||||
|
||||
|
||||
def tools(root):
|
||||
c = compat()
|
||||
wrapper = os.path.join(root, "compatibilitytools.d", c["TOOL"])
|
||||
complete = os.access(os.path.join(wrapper, c["LAUNCHER"]), os.X_OK) and os.path.isfile(os.path.join(wrapper, "toolmanifest.vdf"))
|
||||
if c["TOOL"].lower() not in c["local_tools"](root) or not complete:
|
||||
depot = c["find_source"](root, runnable=True)
|
||||
if depot is not None:
|
||||
try:
|
||||
c["build_tool"](wrapper, depot)
|
||||
except OSError:
|
||||
pass
|
||||
found = {}
|
||||
for base in [os.path.join(root, "compatibilitytools.d")] + list(SYSTEM_TOOLS):
|
||||
bases = [os.path.join(root, "compatibilitytools.d")] + list(SYSTEM_TOOLS)
|
||||
for base in bases:
|
||||
try:
|
||||
entries = sorted(os.listdir(base))
|
||||
except OSError:
|
||||
|
||||
@@ -907,21 +907,21 @@ case $mode in
|
||||
bl_session_pressure() {
|
||||
bl_memory_read
|
||||
[ "$_bl_game" = 1 ] && bl_low_ram && bl_memory_critical || return 0
|
||||
local _wait=$_bl_tier_backoff _urgent=0 _before _pids _targets
|
||||
[ "$_bl_available" -ge $((_bl_headroom / 2)) ] || _urgent=1 _wait=30
|
||||
local _wait=$_bl_tier_backoff _before _pids _targets
|
||||
[ "$_bl_available" -ge $((_bl_headroom / 2)) ] || [ "$_bl_tier_pushed" -lt 0 ] || _wait=30
|
||||
[ "$_bl_tier_at" -lt 0 ] || [ $((SECONDS - _bl_tier_at)) -ge "$_wait" ] || return 0
|
||||
if [ "$_bl_tier_at" -ge 0 ] && [ "$_bl_tier_pushed" -gt 0 ]; then
|
||||
bl_tier_readback
|
||||
if [ "$_bl_tier_back" -le $((_bl_tier_pushed / 2)) ]; then
|
||||
_bl_tier_backoff=30
|
||||
elif [ "$_urgent" = 0 ]; then
|
||||
else
|
||||
_bl_tier_backoff=$((_bl_tier_backoff * 2 > 300 ? 300 : _bl_tier_backoff * 2))
|
||||
_bl_tier_at=$SECONDS _bl_tier_pushed=0
|
||||
_bl_tier_at=$SECONDS _bl_tier_pushed=-1
|
||||
step "zRAM: the game read back most of its last page-out, next try in ${_bl_tier_backoff} s"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
_bl_tier_at=$SECONDS
|
||||
_bl_tier_at=$SECONDS _bl_tier_pushed=0
|
||||
bl_zram_pick game
|
||||
bl_zram_usage "${_pids[@]}" > /dev/null
|
||||
[ "$_bl_rss" -ge $((256 * 1024)) ] || return 0
|
||||
@@ -1249,7 +1249,14 @@ case $mode in
|
||||
sleep 1
|
||||
done
|
||||
[ "${#game}" -gt 10 ] && shortcut=1
|
||||
[ -n "$shortcut" ] || sleep 4
|
||||
_bl_ready_end=$((SECONDS + 30))
|
||||
while [ "$waited" -lt 30 ] && [ "$((_bl_ready_end - SECONDS))" -gt 0 ]; do
|
||||
timeout "$((_bl_ready_end - SECONDS))" /usr/local/bin/droiddeck-agent --steam-ready >/dev/null 2>&1 && break
|
||||
[ "$((_bl_ready_end - SECONDS))" -gt 1 ] || break
|
||||
sleep 1
|
||||
waited=$((waited + 1))
|
||||
done
|
||||
waited=0
|
||||
echo "== steam: interface up; launching the requested game $game"
|
||||
_bl_hand_off
|
||||
[ -n "$shortcut" ] || return 0
|
||||
@@ -1269,7 +1276,9 @@ case $mode in
|
||||
elif _bl_starting; then
|
||||
echo "== steam: the requested game started while waiting; not launching again"
|
||||
elif [ "$(_bl_focused)" = 769 ]; then
|
||||
echo "== steam: launching the requested game again $game (overview status $status)"
|
||||
echo "== steam: clearing the pending launch interstitial for $game (overview status $status)"
|
||||
/usr/local/bin/droiddeck-agent --steam-clear-pending-interstitial "$(((game >> 32) & 0xffffffff))" >/dev/null 2>&1 && return 0
|
||||
echo "== steam: launching the requested game again $game"
|
||||
_bl_hand_off
|
||||
else
|
||||
echo "== steam: the game took focus while waiting; not launching again"
|
||||
|
||||
@@ -760,18 +760,50 @@ class Watcher:
|
||||
def __init__(self, files):
|
||||
self.files = files
|
||||
self.fd = -1
|
||||
self.libc = None
|
||||
wanted = {os.path.dirname(f) for f in files}
|
||||
self.missing = {d for d in wanted if not os.path.isdir(d)}
|
||||
self.watched = set()
|
||||
try:
|
||||
libc = ctypes.CDLL(None, use_errno=True)
|
||||
fd = libc.inotify_init1(os.O_NONBLOCK | os.O_CLOEXEC)
|
||||
dirs = sorted({os.path.dirname(f) for f in files if os.path.isdir(os.path.dirname(f))})
|
||||
dirs = sorted((wanted - self.missing) | {self.existing_parent(d) for d in self.missing} - {""})
|
||||
if fd >= 0 and dirs and all(libc.inotify_add_watch(fd, d.encode(), self.MASK) >= 0 for d in dirs):
|
||||
self.watched = set(dirs)
|
||||
self.fd = fd
|
||||
self.libc = libc
|
||||
elif fd >= 0:
|
||||
os.close(fd)
|
||||
except (OSError, AttributeError):
|
||||
self.fd = -1
|
||||
self.stamp = self.snapshot()
|
||||
|
||||
@staticmethod
|
||||
def existing_parent(path):
|
||||
while path and not os.path.isdir(path):
|
||||
parent = os.path.dirname(path)
|
||||
if parent == path:
|
||||
return ""
|
||||
path = parent
|
||||
return path
|
||||
|
||||
def watch_new_dirs(self):
|
||||
appeared = False
|
||||
progressed = True
|
||||
while progressed:
|
||||
progressed = False
|
||||
for d in sorted(self.missing):
|
||||
parent = d if os.path.isdir(d) else self.existing_parent(d)
|
||||
if not parent or parent in self.watched:
|
||||
continue
|
||||
if self.libc.inotify_add_watch(self.fd, parent.encode(), self.MASK) >= 0:
|
||||
self.watched.add(parent)
|
||||
progressed = True
|
||||
appeared = appeared or parent == d
|
||||
for d in [d for d in self.missing if d in self.watched]:
|
||||
self.missing.discard(d)
|
||||
return appeared
|
||||
|
||||
def snapshot(self):
|
||||
stamp = []
|
||||
for f in self.files:
|
||||
@@ -803,8 +835,9 @@ class Watcher:
|
||||
at += 16 + size
|
||||
except BlockingIOError:
|
||||
pass
|
||||
appeared = self.watch_new_dirs() if self.missing else False
|
||||
wanted = {os.path.basename(f) for f in self.files}
|
||||
return any(n in wanted or n.startswith("appmanifest_") for n in names)
|
||||
return appeared or any(n in wanted or n.startswith("appmanifest_") for n in names)
|
||||
|
||||
|
||||
class XMessage(ctypes.Structure):
|
||||
@@ -1084,6 +1117,7 @@ class Helper:
|
||||
installed = COMPAT["installed_apps"](self.steam_root)
|
||||
self.installed = installed
|
||||
picks = COMPAT["valve_picks"](self.steam_root)
|
||||
tools = COMPAT["tool_platforms"](self.steam_root)
|
||||
prior_auto = state.get("auto", {})
|
||||
if not isinstance(prior_auto, dict):
|
||||
prior_auto = {}
|
||||
@@ -1091,7 +1125,7 @@ class Helper:
|
||||
native_choices = set(prior_native if isinstance(prior_native, (list, tuple, set)) else ())
|
||||
picked = COMPAT["picked_apps"](state)
|
||||
runnable = {t["name"].lower() for t in live}
|
||||
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
|
||||
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices | set(tools), key=COMPAT["app_order"])
|
||||
asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
|
||||
apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
|
||||
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
|
||||
@@ -1105,6 +1139,7 @@ class Helper:
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = prior_auto
|
||||
native_choices -= refused
|
||||
tools = {app: platforms for app, platforms in tools.items() if app not in refused}
|
||||
current["0"] = top["selected"]
|
||||
native = COMPAT["native_targets"](self.steam_root, apps)
|
||||
raw_mapping = COMPAT["read_config_mapping"](
|
||||
@@ -1137,7 +1172,7 @@ class Helper:
|
||||
changes, auto = COMPAT["plan_mapping"](
|
||||
current, installed, listed, default,
|
||||
COMPAT["followers"](state, current), native, picks, overrides,
|
||||
prior_auto.keys(), native_choices)
|
||||
prior_auto.keys(), native_choices, tools)
|
||||
changes = dict(moved, **changes)
|
||||
for app, tool in sorted(changes.items(), key=lambda item: COMPAT["app_order"](item[0])):
|
||||
page.compat("set(%d, %s)" % (int(app), json.dumps(tool if tool is not None else "")))
|
||||
@@ -1301,7 +1336,8 @@ def main():
|
||||
failures += 1
|
||||
time.sleep(min(2 * max(failures, 1), 10))
|
||||
os.makedirs(COMPAT["COMPAT_DIR"], exist_ok=True)
|
||||
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json")] +
|
||||
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json"),
|
||||
os.path.join(steam_root, "appcache", "appinfo.vdf")] +
|
||||
[os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
|
||||
steamos = os.environ.get("BL_STEAMDECK") == "1" and os.environ.get("BL_STEAM_UI") != "desktop"
|
||||
helper = Helper(steam_root, port, steamos)
|
||||
|
||||
@@ -5,6 +5,8 @@ import binascii
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
@@ -275,6 +277,10 @@ def exited(argv, code=0):
|
||||
subprocess.run([EPIC_CLIENT, "exited", "--code", str(code)], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, timeout=10)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
pass
|
||||
if found is not None and launch_dir and str(found[1].get("store")) == "ea":
|
||||
ask(Path(launch_dir) / "stores", {"op": "ea-exited", "store": "ea", "id": str(found[1].get("id"))}, timeout=1.0)
|
||||
log("ea %s exited" % found[1].get("id"))
|
||||
return 0
|
||||
if found is None or not launch_dir or not cloud_on(found[1]):
|
||||
return 0
|
||||
store, game = str(found[1].get("store")), str(found[1].get("id"))
|
||||
@@ -283,6 +289,218 @@ def exited(argv, code=0):
|
||||
return 0
|
||||
|
||||
|
||||
UBISOFT_DIR = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
|
||||
UBISOFT_WINDOWS_DIR = "C:\\Program Files (x86)\\Ubisoft\\Ubisoft Game Launcher\\"
|
||||
UBISOFT_INSTALLER_URL = "https://static3.cdn.ubi.com/orbit/launcher_installer/UbisoftConnectInstaller.exe"
|
||||
UBISOFT_CACHE = Path("/root/.cache/droiddeck/ubisoft")
|
||||
UBISOFT_LAUNCH = ".droiddeck-ubisoft.json"
|
||||
UBISOFT_SERVICE = Path("/usr/local/lib/droiddeck-ubisoft/droiddeck-upc.exe")
|
||||
UBISOFT_ASK_WAIT = 45.0
|
||||
UBISOFT_EXTRACT_WAIT = 300
|
||||
# Ubisoft's own game-side runtime from the Connect installer, unmodified: the API and aux DLLs the
|
||||
# game's loader opens from InstallDir, the starter it re-executes into and its imports, and the overlay
|
||||
# DLLs uplay_r1.dll loads even with the overlay off (its startup fails without them).
|
||||
UBISOFT_RUNTIME = ("uplay_r1.dll", "uplay_r164.dll", "uplay_aux_r1.dll", "uplay_aux_r164.dll",
|
||||
"uplay_r2.dll", "uplay_r264.dll", "ubiorbitapi_r2.dll", "ubiorbitapi_r264.dll",
|
||||
"UbisoftGameLauncher.exe", "UbisoftGameLauncher64.exe", "discord-rpc.x86.dll",
|
||||
"discord-rpc.x64.dll", "steam_api.dll", "steam_api64.dll", "overlay.dll", "overlay64.dll")
|
||||
UBISOFT_VIEWS = ("[Software\\\\Ubisoft\\\\Launcher%s]", "[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher%s]")
|
||||
MIN_INSTALLER = 1 << 20
|
||||
|
||||
|
||||
def ubisoft_runtime_dir(compat_data):
|
||||
return Path(compat_data) / "pfx" / UBISOFT_DIR
|
||||
|
||||
|
||||
def ubisoft_runtime_ready(compat_data):
|
||||
folder = ubisoft_runtime_dir(compat_data)
|
||||
return all((folder / name).is_file() for name in UBISOFT_RUNTIME)
|
||||
|
||||
|
||||
def fetch_installer(url=UBISOFT_INSTALLER_URL, folder=UBISOFT_CACHE):
|
||||
target = folder / "UbisoftConnectInstaller.exe"
|
||||
if target.is_file() and target.stat().st_size >= MIN_INSTALLER:
|
||||
return target
|
||||
import urllib.request
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
part = target.with_name(target.name + ".part")
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||
with urllib.request.urlopen(request, timeout=60) as reply, open(part, "wb") as out:
|
||||
shutil.copyfileobj(reply, out)
|
||||
if part.stat().st_size < MIN_INSTALLER:
|
||||
part.unlink()
|
||||
raise OSError("installer too small")
|
||||
os.replace(part, target)
|
||||
return target
|
||||
|
||||
|
||||
def install_runtime(compat_data, wait=UBISOFT_EXTRACT_WAIT):
|
||||
if ubisoft_runtime_ready(compat_data):
|
||||
return "present"
|
||||
if not (Path(compat_data) / "pfx").is_dir():
|
||||
return "no-prefix"
|
||||
try:
|
||||
installer = fetch_installer()
|
||||
except OSError as error:
|
||||
return "download-failed-" + type(error).__name__
|
||||
target = ubisoft_runtime_dir(compat_data)
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ubisoft-", dir=str(UBISOFT_CACHE)) as tmp:
|
||||
try:
|
||||
subprocess.run(["7z", "e", "-y", "-o" + tmp, str(installer)] + list(UBISOFT_RUNTIME), stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=wait)
|
||||
except subprocess.TimeoutExpired:
|
||||
return "extract-timeout"
|
||||
except OSError:
|
||||
return "no-7z"
|
||||
missing = [name for name in UBISOFT_RUNTIME if not (Path(tmp) / name).is_file()]
|
||||
if missing:
|
||||
return "extract-missing-" + ",".join(missing)
|
||||
for name in UBISOFT_RUNTIME:
|
||||
shutil.copyfile(Path(tmp) / name, target / name)
|
||||
if not ubisoft_runtime_ready(compat_data):
|
||||
return "copy-failed"
|
||||
try:
|
||||
installer.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
return "installed"
|
||||
|
||||
|
||||
def ubisoft_product(sidecar):
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
try:
|
||||
return int(str(extra.get("productId") or ""))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def ubisoft_install_dir(folder):
|
||||
return windows_path(str(folder)).replace("\\", "/").rstrip("/") + "/"
|
||||
|
||||
|
||||
def register_ubisoft(folder, product, compat_data):
|
||||
reg = Path(compat_data) / "pfx" / "system.reg"
|
||||
if not reg.is_file():
|
||||
return "no-registry"
|
||||
if not wait_for_server(reg.parent):
|
||||
return "server-running"
|
||||
for view in UBISOFT_VIEWS:
|
||||
set_value(reg, view % "", "InstallDir", UBISOFT_WINDOWS_DIR)
|
||||
set_value(reg, view % ("\\\\Installs\\\\%d" % product), "InstallDir", ubisoft_install_dir(folder))
|
||||
return "registered %d" % product
|
||||
|
||||
|
||||
UBISOFT_HIVES = {"HKEY_LOCAL_MACHINE": "system.reg", "HKEY_CURRENT_USER": "user.reg"}
|
||||
|
||||
|
||||
def manifest_value(values, folder, language):
|
||||
"""The value Connect writes for a manifest registry entry: the install folder, the entry for the
|
||||
language being played, or the only entry there is."""
|
||||
entries = [v for v in values if isinstance(v, dict)]
|
||||
if not entries:
|
||||
return None
|
||||
names = [str(v.get("name") or "") for v in entries]
|
||||
if "$INSTALL_DIR" in names:
|
||||
return windows_path(str(folder)).rstrip("\\") + "\\"
|
||||
for v in entries:
|
||||
if str(v.get("value") or "").lower() == language.lower():
|
||||
return str(v.get("value"))
|
||||
prefix = language.split("-")[0].lower()
|
||||
for v in entries:
|
||||
if str(v.get("value") or "").lower().split("-")[0] == prefix:
|
||||
return str(v.get("value"))
|
||||
return str(entries[0].get("value") or entries[0].get("name") or "")
|
||||
|
||||
|
||||
def apply_manifest_registry(compat_data, registry, folder, language):
|
||||
written = 0
|
||||
for item in registry or []:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
path = str(item.get("key") or "").replace("/", "\\")
|
||||
hive, _, rest = path.partition("\\")
|
||||
target = UBISOFT_HIVES.get(hive.upper())
|
||||
if not target or "\\" not in rest:
|
||||
continue
|
||||
subkey, _, name = rest.rpartition("\\")
|
||||
value = manifest_value(item.get("values"), folder, language)
|
||||
if value is None or not name:
|
||||
continue
|
||||
reg = Path(compat_data) / "pfx" / target
|
||||
parts = subkey.split("\\")
|
||||
views = [parts]
|
||||
if target == "system.reg" and len(parts) > 1 and parts[0].lower() == "software" and parts[1].lower() != "wow6432node":
|
||||
views.append(parts[:1] + ["Wow6432Node"] + parts[1:])
|
||||
for view in views:
|
||||
key = "[" + "\\\\".join(view) + "]"
|
||||
if set_value(reg, key, name, value):
|
||||
written += 1
|
||||
return written
|
||||
|
||||
|
||||
def ubisoft_launch(folder, sidecar, product, compat_data, answer):
|
||||
"""The launch file droiddeck-upc.exe reads: the game, the account and this launch's ticket."""
|
||||
account = answer.get("account") if isinstance(answer.get("account"), dict) else {}
|
||||
user = str(account.get("userId") or "user")
|
||||
saves = Path(compat_data) / "pfx" / "drive_c/users/steamuser/Saved Games/Ubisoft" / user / str(product)
|
||||
saves.mkdir(parents=True, exist_ok=True)
|
||||
exe = str(sidecar.get("exe") or "").replace("\\", "/")
|
||||
workdir = folder / str(sidecar.get("workdir")) if sidecar.get("workdir") else folder
|
||||
UBISOFT_CACHE.mkdir(parents=True, exist_ok=True)
|
||||
return {
|
||||
"productId": product,
|
||||
"exe": windows_path(str(folder / exe)),
|
||||
"args": " ".join(str(a) for a in sidecar.get("args") or []),
|
||||
"workdir": windows_path(str(workdir)),
|
||||
"account": account,
|
||||
"ticket": str(answer.get("ticket") or ""),
|
||||
"owned": [int(i) for i in answer.get("owned") or [] if str(i).isdigit()],
|
||||
"products": [p for p in answer.get("products") or [] if isinstance(p, dict) and isinstance(p.get("id"), int)],
|
||||
"appId": str(answer.get("appId") or ""),
|
||||
"chunks": [c for c in answer.get("chunks") or [] if isinstance(c, dict) and isinstance(c.get("id"), int)],
|
||||
"saves": "C:/users/steamuser/Saved Games/Ubisoft/%s/%d/" % (user, product),
|
||||
"language": str(answer.get("language") or "en-US"),
|
||||
"bridge": windows_path(str(UBISOFT_CACHE / ("bridge-%d" % product))),
|
||||
"log": windows_path(str(UBISOFT_CACHE / ("upc-%d.log" % product))),
|
||||
}
|
||||
|
||||
|
||||
def prepare_ubisoft(folder, sidecar, compat_data, launch_dir, proton="", ask_app=None):
|
||||
launch = folder / UBISOFT_LAUNCH
|
||||
try:
|
||||
launch.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
product = ubisoft_product(sidecar)
|
||||
if product is None:
|
||||
return "no-product"
|
||||
if not UBISOFT_SERVICE.is_file():
|
||||
return "no-service"
|
||||
made = create_prefix(compat_data, proton) if not (Path(compat_data) / "pfx/user.reg").is_file() else "present"
|
||||
if made not in ("present", "created"):
|
||||
return "prefix " + made
|
||||
runtime = install_runtime(compat_data)
|
||||
if not ubisoft_runtime_ready(compat_data):
|
||||
return "runtime " + runtime
|
||||
registry = register_ubisoft(folder, product, compat_data)
|
||||
if not launch_dir:
|
||||
return "runtime %s, %s, no-channel" % (runtime, registry)
|
||||
answer = (ask_app or ask)(Path(launch_dir) / "stores", {"op": "ubisoft-launch", "store": "ubisoft", "id": str(sidecar.get("id"))},
|
||||
timeout=UBISOFT_ASK_WAIT)
|
||||
if not isinstance(answer, dict) or not answer.get("ok") or not answer.get("ticket"):
|
||||
reason = "timeout" if answer is None else str(answer.get("reason") or "refused")
|
||||
return "runtime %s, %s, session %s" % (runtime, registry, reason)
|
||||
written = 0
|
||||
if answer.get("registry") and wait_for_server(Path(compat_data) / "pfx"):
|
||||
written = apply_manifest_registry(compat_data, answer.get("registry"), folder, str(answer.get("language") or "en-US"))
|
||||
tmp = launch.with_name(launch.name + ".tmp")
|
||||
tmp.write_text(json.dumps(ubisoft_launch(folder, sidecar, product, compat_data, answer)))
|
||||
os.replace(tmp, launch)
|
||||
return "runtime %s, %s, %d manifest value(s), session ready" % (runtime, registry, written)
|
||||
|
||||
COMET_DIR = Path("/usr/local/lib/droiddeck-comet")
|
||||
|
||||
|
||||
@@ -352,6 +570,7 @@ def prepare_gog(sidecar, compat_data, launch_dir):
|
||||
|
||||
GOG_SCRIPTS = "goggame-*.script"
|
||||
GOG_REGISTRY_MARK = ".droiddeck-gog-registry"
|
||||
GOG_SUPPORT_MARK = ".droiddeck-gog-support"
|
||||
GOG_ROOTS = {"HKEY_LOCAL_MACHINE": "HKEY_LOCAL_MACHINE", "HKLM": "HKEY_LOCAL_MACHINE",
|
||||
"HKEY_CURRENT_USER": "HKEY_CURRENT_USER", "HKCU": "HKEY_CURRENT_USER",
|
||||
"HKEY_CLASSES_ROOT": "HKEY_CLASSES_ROOT", "HKCR": "HKEY_CLASSES_ROOT"}
|
||||
@@ -611,6 +830,458 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=Non
|
||||
return "import-failed" + note
|
||||
|
||||
|
||||
EA_HARDWARE = ".droiddeck-ea-hw.json"
|
||||
EA_CLIENT = "C:\\Program Files (x86)\\Origin\\Origin.exe"
|
||||
EA_WMI = (
|
||||
("boardManufacturer", "Win32_BaseBoard", "Manufacturer"),
|
||||
("boardSerial", "Win32_BaseBoard", "SerialNumber"),
|
||||
("biosManufacturer", "Win32_BIOS", "Manufacturer"),
|
||||
("biosSerial", "Win32_BIOS", "SerialNumber"),
|
||||
("osInstallDate", "Win32_OperatingSystem", "InstallDate"),
|
||||
("osSerial", "Win32_OperatingSystem", "SerialNumber"),
|
||||
("gpuPnpId", "Win32_VideoController", "PNPDeviceID"),
|
||||
("cpuManufacturer", "Win32_Processor", "Manufacturer"),
|
||||
("processorId", "Win32_Processor", "ProcessorId"),
|
||||
("brand", "Win32_Processor", "Name"),
|
||||
)
|
||||
EA_ROOTS = {"HKLM": "HKEY_LOCAL_MACHINE", "HKCU": "HKEY_CURRENT_USER"}
|
||||
|
||||
|
||||
def decode_output(data):
|
||||
if data[:2] in (b"\xff\xfe", b"\xfe\xff") or (len(data) > 1 and data[1:2] == b"\x00"):
|
||||
return data.decode("utf-16", "replace")
|
||||
return data.decode("utf-8", "replace")
|
||||
|
||||
|
||||
def wmi_value(text):
|
||||
rows = [row.strip() for row in text.replace("\r", "\n").split("\n") if row.strip()]
|
||||
return rows[1] if len(rows) > 1 else ""
|
||||
|
||||
|
||||
CPUID_LEAVES = (0, 1, 0x80000002, 0x80000003, 0x80000004)
|
||||
|
||||
|
||||
def cpuid_exe():
|
||||
"""A 32-bit console program that writes the raw CPUID leaves an x86 game sees under the emulator."""
|
||||
import struct
|
||||
base, rva = 0x400000, 0x1000
|
||||
buf, written = base + rva + 0x180, base + rva + 0x1D0
|
||||
iat = base + rva + 0x138
|
||||
code = b"\x53\x57\xbf" + struct.pack("<I", buf)
|
||||
for leaf in CPUID_LEAVES:
|
||||
code += b"\xb8" + struct.pack("<I", leaf) + b"\x31\xc9\x0f\xa2\x89\x07\x89\x5f\x04\x89\x4f\x08\x89\x57\x0c\x83\xc7\x10"
|
||||
code += b"\x6a\xf5\xff\x15" + struct.pack("<I", iat)
|
||||
code += b"\x6a\x00\x68" + struct.pack("<I", written) + b"\x6a\x50\x68" + struct.pack("<I", buf) + b"\x50\xff\x15" + struct.pack("<I", iat + 4)
|
||||
code += b"\x6a\x00\xff\x15" + struct.pack("<I", iat + 8)
|
||||
section = bytearray(0x200)
|
||||
section[:len(code)] = code
|
||||
names = [(0x148, b"GetStdHandle"), (0x158, b"WriteFile"), (0x164, b"ExitProcess")]
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
|
||||
for i, (at, name) in enumerate(names):
|
||||
struct.pack_into("<I", section, 0x128 + 4 * i, rva + at)
|
||||
struct.pack_into("<I", section, 0x138 + 4 * i, rva + at)
|
||||
section[at + 2:at + 2 + len(name)] = name
|
||||
section[0x172:0x172 + 12] = b"KERNEL32.dll"
|
||||
header = bytearray(0x200)
|
||||
header[0:2] = b"MZ"
|
||||
struct.pack_into("<I", header, 0x3C, 0x40)
|
||||
header[0x40:0x44] = b"PE\0\0"
|
||||
struct.pack_into("<HHIIIHH", header, 0x44, 0x14C, 1, 0, 0, 0, 0xE0, 0x0103)
|
||||
opt = struct.pack("<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII", 0x10B, 0, 0, 0x200, 0, 0, rva, rva, rva, base, 0x1000, 0x200,
|
||||
4, 0, 0, 0, 4, 0, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
|
||||
dirs = bytearray(128)
|
||||
struct.pack_into("<II", dirs, 8, rva + 0x100, 40)
|
||||
struct.pack_into("<II", dirs, 96, rva + 0x138, 16)
|
||||
header[0x58:0x58 + 0xE0] = opt + bytes(dirs)
|
||||
header[0x138:0x138 + 40] = struct.pack("<8sIIIIIIHHI", b".text", 0x1000, rva, 0x200, 0x200, 0, 0, 0, 0, 0xE0000060)
|
||||
return bytes(header) + bytes(section)
|
||||
|
||||
|
||||
EA_STUB_DIR = "Program Files (x86)/Origin"
|
||||
EA_STUB = "C:\\Program Files (x86)\\Origin\\Origin.exe"
|
||||
|
||||
|
||||
def origin_stub_exe():
|
||||
"""A 32-bit program that only sleeps: the process older EA SDKs look for while a game runs."""
|
||||
import struct
|
||||
base, rva = 0x400000, 0x1000
|
||||
iat = base + rva + 0x138
|
||||
code = b"\x6a\xff\xff\x15" + struct.pack("<I", iat) + b"\xeb\xf6"
|
||||
section = bytearray(0x200)
|
||||
section[:len(code)] = code
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
|
||||
struct.pack_into("<I", section, 0x128, rva + 0x148)
|
||||
struct.pack_into("<I", section, 0x138, rva + 0x148)
|
||||
section[0x14A:0x14A + 5] = b"Sleep"
|
||||
section[0x172:0x172 + 12] = b"KERNEL32.dll"
|
||||
header = bytearray(cpuid_exe()[:0x200])
|
||||
struct.pack_into("<H", header, 0x58 + 68, 2)
|
||||
return bytes(header) + bytes(section)
|
||||
|
||||
|
||||
def install_origin_stub(compat_data):
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
target = Path(compat_data) / "pfx/drive_c" / EA_STUB_DIR / "Origin.exe"
|
||||
data = origin_stub_exe()
|
||||
try:
|
||||
if target.is_file() and target.read_bytes() == data:
|
||||
return "ready"
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
return "written"
|
||||
except OSError:
|
||||
return "failed"
|
||||
|
||||
|
||||
def cpuid_values(raw):
|
||||
import struct
|
||||
if len(raw) < 80:
|
||||
return {}
|
||||
regs = [struct.unpack_from("<IIII", raw, 16 * i) for i in range(5)]
|
||||
vendor = struct.pack("<III", regs[0][1], regs[0][3], regs[0][2]).split(b"\0")[0].decode("latin-1")
|
||||
brand = b"".join(struct.pack("<IIII", *r) for r in regs[2:]).split(b"\0")[0].decode("latin-1")
|
||||
return {"cpuVendor": vendor, "cpuEax": "%08X" % regs[1][0], "cpuEdx": "%08X" % regs[1][3],
|
||||
"cpuEcx": "%08x" % regs[1][2], "cpuBrand": brand}
|
||||
|
||||
|
||||
EA_PROBE_FIELDS = ("boardManufacturer", "biosManufacturer", "osInstallDate", "osSerial", "volumeSerial", "hostname",
|
||||
"cpuVendor", "cpuEax", "cpuEdx", "cpuEcx")
|
||||
|
||||
|
||||
def probe_complete(values):
|
||||
return all(str(values.get(key) or "").strip() for key in EA_PROBE_FIELDS)
|
||||
|
||||
|
||||
def ea_hardware(compat_data, proton, timeout=240):
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
cache = pfx / EA_HARDWARE
|
||||
try:
|
||||
cached = json.loads(cache.read_text())
|
||||
if isinstance(cached, dict) and probe_complete(cached):
|
||||
return cached, "cached"
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
if not proton or not Path(proton).is_file():
|
||||
return {}, "no-proton"
|
||||
values = {}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
|
||||
folder = Path(tmp)
|
||||
lines = ["@echo off"]
|
||||
for key, cls, prop in EA_WMI:
|
||||
lines.append('wmic path %s get %s > "%s"' % (cls, prop, windows_path(str(folder / (key + ".txt")))))
|
||||
lines.append('vol C: > "%s"' % windows_path(str(folder / "volume.txt")))
|
||||
lines.append('hostname > "%s"' % windows_path(str(folder / "hostname.txt")))
|
||||
(folder / "cpuid.exe").write_bytes(cpuid_exe())
|
||||
lines.append('"%s" > "%s"' % (windows_path(str(folder / "cpuid.exe")), windows_path(str(folder / "cpuid.bin"))))
|
||||
bat = folder / "probe.bat"
|
||||
bat.write_bytes(("\r\n".join(lines) + "\r\n").encode())
|
||||
try:
|
||||
subprocess.run([proton, "run", "cmd.exe", "/d", "/c", windows_path(str(bat))], stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
return {}, "timeout"
|
||||
except OSError:
|
||||
return {}, "failed"
|
||||
for key, _, _ in EA_WMI:
|
||||
try:
|
||||
values[key] = wmi_value(decode_output((folder / (key + ".txt")).read_bytes()))
|
||||
except OSError:
|
||||
values[key] = ""
|
||||
try:
|
||||
found = re.search(r"([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})", decode_output((folder / "volume.txt").read_bytes()))
|
||||
values["volumeSerial"] = (found.group(1) + found.group(2)).lower() if found else ""
|
||||
except OSError:
|
||||
values["volumeSerial"] = ""
|
||||
try:
|
||||
values["hostname"] = decode_output((folder / "hostname.txt").read_bytes()).strip().splitlines()[0].strip()
|
||||
except (OSError, IndexError):
|
||||
values["hostname"] = ""
|
||||
try:
|
||||
values.update(cpuid_values((folder / "cpuid.bin").read_bytes()))
|
||||
except OSError:
|
||||
pass
|
||||
if probe_complete(values):
|
||||
try:
|
||||
cache.write_text(json.dumps(values))
|
||||
except OSError:
|
||||
pass
|
||||
return values, "probed"
|
||||
return values, "incomplete"
|
||||
|
||||
|
||||
def ea_registry_entries(folder, sidecar):
|
||||
install = windows_path(str(folder)).rstrip("\\") + "\\"
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
title = str(extra.get("displayName") or sidecar.get("title") or folder.name).strip()
|
||||
locale = str(extra.get("locale") or "en_US")
|
||||
entries = [
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Desktop", "InstallSuccessful", "true"),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "InstallSuccessful", "true"),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "ClientPath", EA_CLIENT),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin", "ClientPath", EA_CLIENT),
|
||||
]
|
||||
for content in [c.strip() for c in str(extra.get("contentIds") or extra.get("contentId") or "").split(",")]:
|
||||
if re.fullmatch(r"[A-Za-z0-9._-]{1,64}", content):
|
||||
key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin Games\\" + content
|
||||
entries += [(key, "DisplayName", title), (key, "Install Dir", install), (key, "Locale", locale)]
|
||||
try:
|
||||
keys = json.loads(extra.get("registry") or "[]")
|
||||
except ValueError:
|
||||
keys = []
|
||||
for pair in keys if isinstance(keys, list) else []:
|
||||
if not isinstance(pair, list) or len(pair) != 2:
|
||||
continue
|
||||
key, name = str(pair[0]), str(pair[1])
|
||||
root, _, rest = key.partition("\\")
|
||||
key = EA_ROOTS.get(root.upper(), root) + ("\\" + rest if rest else "")
|
||||
if key.upper().startswith(("HKEY_LOCAL_MACHINE\\", "HKEY_CURRENT_USER\\")) and name and "\n" not in key + name:
|
||||
entries.append((key, name, install))
|
||||
if title:
|
||||
entries.append((key, "DisplayName", title))
|
||||
entries.append((key, "Locale", locale))
|
||||
return entries
|
||||
|
||||
|
||||
def ea_registry(folder, sidecar, compat_data, proton, timeout=90):
|
||||
if not compat_data or not proton or not Path(proton).is_file():
|
||||
return "no-proton"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
text = "Windows Registry Editor Version 5.00\r\n\r\n" + "".join(
|
||||
'[%s]\r\n"%s"="%s"\r\n\r\n' % (key, reg_escape(name), reg_escape(value)) for key, name, value in ea_registry_entries(folder, sidecar))
|
||||
stamp = hashlib.sha256(text.encode("utf-8")).hexdigest()
|
||||
marker = pfx / (".droiddeck-ea-registry-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp and (pfx / "system.reg").is_file():
|
||||
return "ready"
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
|
||||
source = Path(tmp) / "registry.reg"
|
||||
source.write_bytes(b"\xff\xfe" + text.encode("utf-16-le"))
|
||||
executable = pfx / "drive_c/windows/system32/reg.exe"
|
||||
for view in ("/reg:32", "/reg:64"):
|
||||
run = subprocess.run([proton, "run", str(executable) if executable.is_file() else "reg.exe", "import", windows_path(str(source)), view],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
if run.returncode:
|
||||
return "import-failed"
|
||||
marker.write_text(stamp)
|
||||
return "written"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "timeout"
|
||||
except OSError:
|
||||
return "import-failed"
|
||||
|
||||
|
||||
def find_case(folder, relative):
|
||||
current = Path(folder)
|
||||
for part in [p for p in relative.replace("\\", "/").split("/") if p and p != "."]:
|
||||
exact = current / part
|
||||
if exact.exists():
|
||||
current = exact
|
||||
continue
|
||||
try:
|
||||
current = next(c for c in current.iterdir() if c.name.lower() == part.lower())
|
||||
except (OSError, StopIteration):
|
||||
return None
|
||||
return current if current != Path(folder) else None
|
||||
|
||||
|
||||
def touchup_args(raw, locale, install):
|
||||
raw = raw.replace("{locale}", locale)
|
||||
raw = raw.replace('"{installLocation}"', '"%s"' % install).replace("{installLocation}", install)
|
||||
try:
|
||||
return shlex.split(raw.replace("\\", "\\\\"))
|
||||
except ValueError:
|
||||
return raw.split()
|
||||
|
||||
|
||||
def ea_touchup(folder, sidecar, compat_data, proton, timeout=900):
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
relative = str(extra.get("touchup") or "")
|
||||
if not relative:
|
||||
return "none"
|
||||
exe = find_case(folder, relative)
|
||||
if exe is None or not exe.is_file():
|
||||
return "missing"
|
||||
if not compat_data or not proton or not Path(proton).is_file():
|
||||
return "no-proton"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
stamp = str(sidecar.get("installVersion") or "") + " " + str(sidecar.get("installedAt") or "")
|
||||
marker = pfx / (".droiddeck-ea-touchup-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp:
|
||||
return "done"
|
||||
except OSError:
|
||||
pass
|
||||
args = touchup_args(str(extra.get("touchupArgs") or ""), str(extra.get("locale") or "en_US"), windows_path(str(folder)).rstrip("\\"))
|
||||
try:
|
||||
run = subprocess.run([proton, "run", str(exe)] + args, cwd=str(exe.parent), stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
result = "ok" if run.returncode == 0 else "exit-%d" % run.returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
result = "timeout"
|
||||
except OSError:
|
||||
return "failed"
|
||||
try:
|
||||
marker.write_text(stamp)
|
||||
except OSError:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def write_licenses(compat_data, licenses):
|
||||
if not compat_data:
|
||||
return 0
|
||||
root = Path(compat_data) / "pfx/drive_c"
|
||||
written = 0
|
||||
for item in licenses or []:
|
||||
relative = str(item.get("path") or "") if isinstance(item, dict) else ""
|
||||
if not relative or relative.startswith("/") or ".." in relative.split("/"):
|
||||
continue
|
||||
target = root / relative
|
||||
try:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(base64.b64decode(item.get("data") or ""))
|
||||
written += 1
|
||||
except (OSError, binascii.Error):
|
||||
pass
|
||||
return written
|
||||
|
||||
|
||||
def prepare_ea(folder, sidecar, compat_data, launch_dir):
|
||||
game = str(sidecar.get("id"))
|
||||
proton = os.environ.get("BL_STORE_PROTON", "")
|
||||
made = create_prefix(compat_data, proton)
|
||||
ready = made in ("present", "created") or (compat_data and (Path(compat_data) / "pfx/user.reg").is_file())
|
||||
stub = install_origin_stub(compat_data) if ready else "no-prefix"
|
||||
hardware, probe = ea_hardware(compat_data, proton) if ready else ({}, "no-prefix")
|
||||
answer = None
|
||||
if launch_dir:
|
||||
answer = ask(Path(launch_dir) / "stores", {"op": "ea-prepare", "store": "ea", "id": game, "hardware": hardware}, timeout=40.0)
|
||||
sidecar = sidecar_at(Path(folder)) or sidecar
|
||||
log("ea %s prefix=%s stub=%s hardware=%s registry=%s touchup=%s" % (
|
||||
game, made, stub, probe, ea_registry(folder, sidecar, compat_data, proton), ea_touchup(folder, sidecar, compat_data, proton)))
|
||||
if answer is None:
|
||||
log("ea %s session=no reason=%s" % (game, "timeout" if launch_dir else "no-channel"))
|
||||
return
|
||||
written = write_licenses(compat_data, answer.get("licenses"))
|
||||
log("ea %s session=%s reason=%s lsx=%s licence=%s files=%d" % (
|
||||
game, "yes" if answer.get("ok") else "no", answer.get("reason", ""), answer.get("lsx"), answer.get("license", ""), written))
|
||||
|
||||
|
||||
def gog_support_actions(folder):
|
||||
found = []
|
||||
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
|
||||
product = script.name[len("goggame-"):-len(".script")]
|
||||
try:
|
||||
actions = json.loads(script.read_text(encoding="utf-8-sig")).get("actions")
|
||||
except (OSError, ValueError, AttributeError):
|
||||
continue
|
||||
for action in actions if isinstance(actions, list) else []:
|
||||
install = action.get("install") if isinstance(action, dict) else None
|
||||
if isinstance(install, dict) and install.get("action") == "supportData" \
|
||||
and isinstance(install.get("arguments"), dict):
|
||||
found.append((product, install["arguments"]))
|
||||
return found
|
||||
|
||||
|
||||
def gog_support_bases(folder, product, pfx):
|
||||
user = Path(pfx) / "drive_c" / "users" / "steamuser"
|
||||
support = Path(folder) / "support" / product
|
||||
return {"app": Path(folder), "supportdir": support, "support": support,
|
||||
"userdocs": user / "Documents", "localappdata": user / "AppData" / "Local"}
|
||||
|
||||
|
||||
def gog_inside(path, base):
|
||||
root = os.path.realpath(base)
|
||||
real = os.path.realpath(path)
|
||||
return real == root or real.startswith(root + os.sep)
|
||||
|
||||
|
||||
def gog_support_path(text, bases):
|
||||
match = re.fullmatch(r"\{(\w+)\}(.*)", text) if isinstance(text, str) else None
|
||||
if not match or match.group(1).lower() not in bases:
|
||||
return None
|
||||
parts = [part for part in re.split(r"[\\/]+", match.group(2)) if part]
|
||||
if any(part in (".", "..") for part in parts):
|
||||
return None
|
||||
base = bases[match.group(1).lower()]
|
||||
path = base
|
||||
for part in parts:
|
||||
exact = path / part
|
||||
if not exact.exists() and path.is_dir():
|
||||
exact = next((child for child in path.iterdir() if child.name.lower() == part.lower()), exact)
|
||||
path = exact
|
||||
if path != base and not gog_inside(path.parent, base):
|
||||
return None
|
||||
return path, base
|
||||
|
||||
|
||||
def gog_copy_file(source, target, root):
|
||||
if not gog_inside(target.parent, root):
|
||||
raise OSError("outside " + str(root))
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
if target.is_symlink():
|
||||
target.unlink()
|
||||
shutil.copy2(source, target, follow_symlinks=False)
|
||||
|
||||
|
||||
def gog_support_data(folder, compat_data, proton):
|
||||
actions = gog_support_actions(folder)
|
||||
if not actions:
|
||||
return "none"
|
||||
pfx = Path(compat_data) / "pfx" if compat_data else None
|
||||
if not pfx or not (pfx / "drive_c" / "users" / "steamuser").is_dir():
|
||||
made = create_prefix(compat_data, proton)
|
||||
if made not in ("present", "created") or not (pfx / "drive_c" / "users" / "steamuser").is_dir():
|
||||
return "no-prefix"
|
||||
stamp = hashlib.sha256(json.dumps(actions, sort_keys=True).encode("utf-8")).hexdigest()
|
||||
marker = pfx / GOG_SUPPORT_MARK
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp:
|
||||
return "ready"
|
||||
except OSError:
|
||||
pass
|
||||
copied = skipped = missing = 0
|
||||
for product, arguments in actions:
|
||||
bases = gog_support_bases(folder, product, pfx)
|
||||
found = gog_support_path(arguments.get("target"), bases)
|
||||
origin = gog_support_path(arguments["source"], bases) if "source" in arguments else None
|
||||
if found is None or ("source" in arguments and origin is None):
|
||||
skipped += 1
|
||||
continue
|
||||
target, root = found
|
||||
source = origin[0] if origin else None
|
||||
try:
|
||||
if source is None:
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
elif not source.exists():
|
||||
missing += 1
|
||||
elif source.is_dir() and not source.is_symlink():
|
||||
for top, dirs, files in os.walk(source):
|
||||
for name in sorted(files + [d for d in dirs if (Path(top) / d).is_symlink()]):
|
||||
item = Path(top) / name
|
||||
destination = target / item.relative_to(source)
|
||||
if (destination.exists() or destination.is_symlink()) and not arguments.get("overwrite"):
|
||||
continue
|
||||
gog_copy_file(item, destination, root)
|
||||
copied += 1
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
elif (target.exists() or target.is_symlink()) and not arguments.get("overwrite"):
|
||||
continue
|
||||
else:
|
||||
gog_copy_file(source, target, root)
|
||||
copied += 1
|
||||
except OSError:
|
||||
skipped += 1
|
||||
note = "".join(" %s=%d" % (name, count) for name, count in (("skipped", skipped), ("missing", missing)) if count)
|
||||
if not skipped:
|
||||
try:
|
||||
marker.write_text(stamp)
|
||||
except OSError:
|
||||
pass
|
||||
return "copied=%d%s" % (copied, note)
|
||||
|
||||
|
||||
def main(argv):
|
||||
if os.environ.get("DROIDDECK_GOG_MAINTENANCE") == "1":
|
||||
return 0
|
||||
@@ -654,6 +1325,16 @@ def main(argv):
|
||||
if store == "gog":
|
||||
prepare_gog(sidecar, compat_data, launch_dir)
|
||||
log("gog registry: " + apply_gog_registry(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
|
||||
log("gog support data: " + gog_support_data(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
|
||||
if store == "ubisoft":
|
||||
try:
|
||||
log("ubisoft %s: %s" % (game, prepare_ubisoft(folder, sidecar, compat_data, launch_dir, os.environ.get("BL_STORE_PROTON", ""))))
|
||||
except OSError as e:
|
||||
try:
|
||||
(folder / UBISOFT_LAUNCH).unlink()
|
||||
except OSError:
|
||||
pass
|
||||
log("ubisoft %s: not prepared (%s), starting directly" % (game, e))
|
||||
if store == "epic":
|
||||
handled = os.environ.get(EPIC_HANDLED) == "1" and (folder / EPIC_ARGS).is_file()
|
||||
if not handled:
|
||||
@@ -691,6 +1372,9 @@ def main(argv):
|
||||
got = bool(answer.get("code"))
|
||||
log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", "")))
|
||||
log("epic prefix=%s %s" % (prefix_id or "?", provision_prefix(compat_data)))
|
||||
if store == "ea":
|
||||
prepare_ea(folder, sidecar, compat_data, launch_dir)
|
||||
return STORE_GAME
|
||||
if not cloud_on(sidecar):
|
||||
if store in CLOUD_STORES:
|
||||
log("cloud %s %s down result=skipped reason=off" % (store, game))
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
PE = runpy.run_path(str(Path(__file__).resolve().parent / "droiddeck-wine-pe"))
|
||||
PE_MACHINES = PE["PE_MACHINES"]
|
||||
pe_machine = PE["pe_machine"]
|
||||
machine_compatible = PE["machine_compatible"]
|
||||
|
||||
STORE = Path("/opt/droiddeck/wincomponents")
|
||||
SELECTION = Path.home() / ".config/droiddeck/wincomponents.json"
|
||||
PENDING = Path.home() / ".config/droiddeck/wincomponents-pending.json"
|
||||
@@ -473,6 +479,15 @@ def save_state(compat, state):
|
||||
os.replace(temp, compat / STATE)
|
||||
|
||||
|
||||
def foreign_component(rel, path, machines):
|
||||
parts = Path(rel).parts
|
||||
folder = parts[2] if len(parts) > 2 and parts[:2] == ("drive_c", "windows") else None
|
||||
if not machines or folder not in PE_MACHINES or not rel.lower().endswith(".dll"):
|
||||
return False
|
||||
machine = pe_machine(path)
|
||||
return machine is not None and not machine_compatible(path, machines[folder][1], machine)
|
||||
|
||||
|
||||
def pending_for(app_id, pending=PENDING):
|
||||
try:
|
||||
with open(pending, encoding="utf-8") as source:
|
||||
@@ -514,7 +529,8 @@ def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT,
|
||||
return "wincomp: %s waited %dms for %s" % (app_id, waited, ",".join(asked))
|
||||
|
||||
|
||||
def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING, wait=wait_for_pending):
|
||||
def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING, wait=wait_for_pending,
|
||||
proton=None, env=None):
|
||||
compat = Path(compat_path)
|
||||
pfx = compat / "pfx"
|
||||
waited = wait(app_id, pending, store) if wait else None
|
||||
@@ -527,6 +543,9 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
installed = []
|
||||
values = []
|
||||
held = set()
|
||||
skipped = set()
|
||||
placed_stems = set()
|
||||
machines = PE["proton_pe_machines"](proton, env) if proton else None
|
||||
saved_overrides = state.get("overrides") if isinstance(state.get("overrides"), dict) else {}
|
||||
saved_requires = state.get("requires") if isinstance(state.get("requires"), dict) else {}
|
||||
recorded = [c for c in state.get("components", []) if isinstance(c, str) and valid_id(c)]
|
||||
@@ -566,9 +585,17 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
kept_requires[cid] = list(requires)
|
||||
values += [(cid, value) for value in registry]
|
||||
for rel, src in files:
|
||||
if place(src, pfx / rel, None if rel in state["files"] else compat / BACKUP / rel):
|
||||
foreign = foreign_component(rel, src, machines)
|
||||
if foreign:
|
||||
skipped.add(Path(rel).stem.lower())
|
||||
changed = False
|
||||
else:
|
||||
changed = place(src, pfx / rel, None if rel in state["files"] else compat / BACKUP / rel)
|
||||
placed_stems.add(Path(rel).stem.lower())
|
||||
if changed:
|
||||
copied += 1
|
||||
keep[rel] = cid
|
||||
if not foreign:
|
||||
keep[rel] = cid
|
||||
removed = restored = 0
|
||||
for rel, cid in state["files"].items():
|
||||
if rel in keep:
|
||||
@@ -579,6 +606,10 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
path = existing(pfx / rel)
|
||||
saved = compat / BACKUP / rel
|
||||
if saved.is_file():
|
||||
if foreign_component(rel, saved, machines):
|
||||
if path is not None and not path.is_symlink():
|
||||
path.unlink()
|
||||
continue
|
||||
target = path or (pfx / rel)
|
||||
os.replace(saved, target)
|
||||
restored += 1
|
||||
@@ -590,6 +621,14 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
(compat / "config_info").unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
def override_name(entry):
|
||||
name = entry.partition("=")[0].strip().lower()
|
||||
return name[:-4] if name.endswith(".dll") else name
|
||||
|
||||
dropped = skipped - placed_stems
|
||||
overrides = [entry for entry in overrides if override_name(entry) not in dropped]
|
||||
for cid in kept_overrides:
|
||||
kept_overrides[cid] = [entry for entry in kept_overrides[cid] if override_name(entry) not in dropped]
|
||||
compat.mkdir(parents=True, exist_ok=True)
|
||||
new_state = {"files": keep, "components": installed + sorted(held), "overrides": kept_overrides,
|
||||
"requires": kept_requires, "registry": state.get("registry", {})}
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/python3
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
PE_MACHINES = {
|
||||
"system32": ("aarch64-windows", frozenset((0xAA64, 0xA641))),
|
||||
"syswow64": ("i386-windows", frozenset((0x14C,))),
|
||||
}
|
||||
|
||||
|
||||
def pe_machine(path):
|
||||
try:
|
||||
with open(path, "rb") as image:
|
||||
head = image.read(64)
|
||||
if head[:2] != b"MZ" or len(head) < 64:
|
||||
return None
|
||||
image.seek(int.from_bytes(head[60:64], "little"))
|
||||
header = image.read(6)
|
||||
except OSError:
|
||||
return None
|
||||
if header[:4] != b"PE\0\0" or len(header) < 6:
|
||||
return None
|
||||
return int.from_bytes(header[4:6], "little")
|
||||
|
||||
|
||||
def pe_has_arm64ec_metadata(path):
|
||||
try:
|
||||
with open(path, "rb") as image:
|
||||
image.seek(60)
|
||||
raw = image.read(4)
|
||||
if len(raw) != 4:
|
||||
return False
|
||||
pe_offset = int.from_bytes(raw, "little")
|
||||
image.seek(pe_offset)
|
||||
if image.read(4) != b"PE\0\0":
|
||||
return False
|
||||
coff = image.read(20)
|
||||
if len(coff) != 20:
|
||||
return False
|
||||
section_count = int.from_bytes(coff[2:4], "little")
|
||||
if section_count > 96:
|
||||
return False
|
||||
optional_size = int.from_bytes(coff[16:18], "little")
|
||||
optional_offset = pe_offset + 24
|
||||
image.seek(optional_offset)
|
||||
optional = image.read(optional_size)
|
||||
if len(optional) != optional_size or int.from_bytes(optional[:2], "little") != 0x20B:
|
||||
return False
|
||||
directory_count = int.from_bytes(optional[108:112], "little")
|
||||
directory_offset = 112 + 10 * 8
|
||||
if directory_count <= 10 or directory_offset + 8 > len(optional):
|
||||
return False
|
||||
load_config_rva = int.from_bytes(optional[directory_offset:directory_offset + 4], "little")
|
||||
load_config_size = int.from_bytes(optional[directory_offset + 4:directory_offset + 8], "little")
|
||||
if not load_config_rva or load_config_size < 0xD0:
|
||||
return False
|
||||
section_offset = optional_offset + optional_size
|
||||
for index in range(section_count):
|
||||
image.seek(section_offset + index * 40)
|
||||
section = image.read(40)
|
||||
if len(section) != 40:
|
||||
return False
|
||||
virtual_address = int.from_bytes(section[12:16], "little")
|
||||
raw_size = int.from_bytes(section[16:20], "little")
|
||||
raw_offset = int.from_bytes(section[20:24], "little")
|
||||
relative = load_config_rva - virtual_address
|
||||
if 0 <= relative <= raw_size - 0xD0:
|
||||
image.seek(raw_offset + relative)
|
||||
load_config = image.read(0xD0)
|
||||
if len(load_config) != 0xD0 or int.from_bytes(load_config[:4], "little") < 0xD0:
|
||||
return False
|
||||
return int.from_bytes(load_config[0xC8:0xD0], "little") != 0
|
||||
except (OSError, OverflowError, ValueError):
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def machine_compatible(path, machines, machine=None):
|
||||
machine = pe_machine(path) if machine is None else machine
|
||||
if machine == 0x8664 and pe_has_arm64ec_metadata(path):
|
||||
return 0xA641 in machines
|
||||
return machine in machines
|
||||
|
||||
|
||||
def proton_pe_machines(proton, env=None):
|
||||
dist = Path(proton).parent / "files/lib/wine"
|
||||
if (dist / "aarch64-unix").is_dir() and (env or {}).get("PROTON_USE_ARM64", "1") == "1":
|
||||
return PE_MACHINES
|
||||
if (dist / "x86_64-unix").is_dir():
|
||||
return {
|
||||
"system32": ("x86_64-windows", frozenset((0x8664,))),
|
||||
"syswow64": PE_MACHINES["syswow64"],
|
||||
}
|
||||
return None
|
||||
@@ -152,6 +152,13 @@ bl_components() {
|
||||
else
|
||||
cm_app=""
|
||||
fi
|
||||
if [ "$cm_app" = 2929927072 ] && [[ "${SteamAppId:-}" =~ ^[0-9]{1,10}$ ]] && (( 10#$SteamAppId > 0 && 10#$SteamAppId <= 4294967295 )); then
|
||||
cm_app=$((10#$SteamAppId))
|
||||
elif [ "$cm_app" = 2929927072 ] && [[ "${SteamGameId:-}" =~ ^[1-9][0-9]{9,19}$ ]] &&
|
||||
{ [ ${#SteamGameId} -lt 20 ] || [[ ! "$SteamGameId" > 18446744073709551615 ]]; } &&
|
||||
(( (10#$SteamGameId & 0xFFFFFFFF) == 0x02000000 && ((10#$SteamGameId >> 32) & 0xFFFFFFFF) != 0 )); then
|
||||
cm_app=$(( (10#$SteamGameId >> 32) & 0xFFFFFFFF ))
|
||||
fi
|
||||
if [ -z "$cm_app" ]; then
|
||||
echo "droiddeck-proton: components: invalid game prefix, left as it is" >&2
|
||||
return 0
|
||||
@@ -734,6 +741,7 @@ def libraries(steam_root):
|
||||
|
||||
|
||||
def installed_apps(steam_root):
|
||||
entries = appinfo_entries(os.path.join(steam_root, "appcache", "appinfo.vdf"))
|
||||
apps = set()
|
||||
for library in libraries(steam_root):
|
||||
steamapps = os.path.join(library, "steamapps")
|
||||
@@ -743,7 +751,7 @@ def installed_apps(steam_root):
|
||||
continue
|
||||
for name in names:
|
||||
m = re.fullmatch(r"appmanifest_(\d+)\.acf", name)
|
||||
if m and m.group(1) not in NOT_GAMES:
|
||||
if m and m.group(1) not in NOT_GAMES and entries.get(m.group(1), {}).get("type") != "tool":
|
||||
apps.add(m.group(1))
|
||||
return sorted(apps, key=int)
|
||||
|
||||
@@ -927,6 +935,12 @@ def valve_picks(steam_root):
|
||||
return sorted(picks, key=int)
|
||||
|
||||
|
||||
def tool_platforms(steam_root):
|
||||
entries = appinfo_entries(os.path.join(steam_root, "appcache", "appinfo.vdf"))
|
||||
return {app: entry["oslist"] for app, entry in entries.items()
|
||||
if entry["type"] == "tool" and entry["oslist"] & {"linux", "windows"}}
|
||||
|
||||
|
||||
def native_targets(steam_root, apps):
|
||||
wanted = {str(app) for app in apps if str(app) not in NOT_GAMES}
|
||||
if not wanted:
|
||||
@@ -1064,10 +1078,11 @@ NATIVE_CHOICE = object()
|
||||
|
||||
|
||||
def plan_mapping(current, installed, runnable, default, auto, native=None, picks=(), overrides=None, managed=None,
|
||||
native_choices=()):
|
||||
native_choices=(), tools=None):
|
||||
tools = tools or {}
|
||||
runnable = {n.lower() for n in runnable}
|
||||
installed = set(installed)
|
||||
picks = set(picks)
|
||||
picks = set(picks) | {app for app, platforms in tools.items() if "linux" not in platforms}
|
||||
native = native or {}
|
||||
overrides = overrides or {}
|
||||
managed = set(auto) if managed is None else set(managed)
|
||||
@@ -1075,8 +1090,12 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks
|
||||
changes, kept = {}, {}
|
||||
if current.get("0", "") != default:
|
||||
changes["0"] = default
|
||||
for app in sorted((set(current) | installed | picks | set(auto) | set(overrides) | native_choices) - {"0"}, key=app_order):
|
||||
for app in sorted((set(current) | installed | picks | set(auto) | set(overrides) | native_choices | set(tools)) - {"0"}, key=app_order):
|
||||
name = current.get(app, "")
|
||||
if app in tools and "linux" in tools[app] and "windows" not in tools[app]:
|
||||
if name and (name.lower() in runnable or "proton" in name.lower()):
|
||||
changes[app] = None
|
||||
continue
|
||||
if app in overrides:
|
||||
target = overrides[app]
|
||||
if target is DEFERRED_GAME_TOOL:
|
||||
@@ -1560,7 +1579,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
current.setdefault(app, "")
|
||||
changes, auto = plan_mapping(
|
||||
current, apps, names, default, followers(state, current), native, picks,
|
||||
overrides, managed, native_choices)
|
||||
overrides, managed, native_choices, tool_platforms(steam_root))
|
||||
set_mappings(tokens, mapping, changes)
|
||||
text = serialize(tokens)
|
||||
if text != serialize(tokenize(original)):
|
||||
@@ -1587,10 +1606,11 @@ def depot_build(depot):
|
||||
return int(first[0]) if first and first[0].isdigit() else 0
|
||||
|
||||
|
||||
def find_source(steam_root, sources=SOURCES):
|
||||
def find_source(steam_root, sources=SOURCES, runnable=False):
|
||||
for name in sources:
|
||||
found = [os.path.join(root, "steamapps", "common", name) for root in libraries(steam_root)
|
||||
if os.path.isdir(os.path.join(root, "steamapps", "common", name, "files", "bin-arm64"))]
|
||||
if os.path.isdir(os.path.join(root, "steamapps", "common", name, "files", "bin-arm64"))
|
||||
and (not runnable or os.access(os.path.join(root, "steamapps", "common", name, "proton"), os.X_OK))]
|
||||
if found:
|
||||
return max(found, key=depot_build)
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user