mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
Merge main into playstore for 0.6.9.2 (version code 20)
Brings the main fixes and features since 8a8bb2053 to the Play line.
Main's new code keeps the Play gates: bundled PRoot, AddonPack and
ComponentDownloads gates, the SDK guards, PackageInfoCompat and the
accessibility consent check, which now also covers system-key capture.
The accessibility disclosure is rewritten in every locale to describe
the hardware-keyboard keys it keeps in a session. The MaliBridge server
task uses the AGP NDK provider. Review notes are in tools/playstore/POLICY.md.
This commit is contained in:
commit
95cb9159de
517 files changed
+46804
-2489
No files matched your search
@@ -52,7 +52,7 @@ CLIENT_WAIT = 300
|
||||
GAME_GRACE = 15
|
||||
LAUNCH_WAIT = 15
|
||||
LAUNCH_ASKS = 3
|
||||
CLIENT_PATH = re.compile(r"[a-z]:\\(program files \(x86\)|programdata)\\battle\.net\\")
|
||||
CLIENT_PATH = re.compile(r"[a-z]:\\(program files \(x86\)\\battle\.net\\([^\\]+$|battle\.net\.\d+\\)|programdata\\battle\.net\\)")
|
||||
IDLE = {"agent.exe", "conhost.exe", "explorer.exe", "lsass.exe", "plugplay.exe", "rpcss.exe", "services.exe",
|
||||
"start.exe", "steam.exe", "svchost.exe", "tabtip.exe", "winedevice.exe", "wineserver"}
|
||||
NOT_GAME = IDLE | {"rundll32.exe", "wineboot.exe", "winemenubuilder.exe"}
|
||||
@@ -113,7 +113,9 @@ function field(text, name) {
|
||||
}
|
||||
|
||||
function install() {
|
||||
var form = call("POST", "/install", '{"uid":"' + uid + '","instructions_patch_url":"http://' + zone + '.patch.battle.net:1119/' +
|
||||
// Blizzard's China repository moved to cn.patch.battlenet.com.cn; cn.patch.battle.net only redirects away from it.
|
||||
var patch = zone == "cn" ? "cn.patch.battlenet.com.cn" : zone + ".patch.battle.net";
|
||||
var form = call("POST", "/install", '{"uid":"' + uid + '","instructions_patch_url":"http://' + patch + ':1119/' +
|
||||
product + '","instructions_product":"NGDP","monitor_pid":12345,"priority":{"insert_at_head":true,"value":900}}');
|
||||
save(".form", form);
|
||||
if (form.indexOf('"' + lang + '"') < 0) lang = "enUS";
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
#!/usr/bin/python3
|
||||
import fcntl
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import stat
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HOME, ".local/share/Steam")
|
||||
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
OPEN = os.path.join(BIN_DIR, "droiddeck-open")
|
||||
APPS_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
PLACED = os.path.join(HOME, ".local/share/droiddeck/desktop-programs-placed")
|
||||
PREFIX = "droiddeck-program-"
|
||||
SHORTCUT_BIT = 0x80000000
|
||||
WINDOWS_DESKTOPS = ("users/Public/Desktop", "users/steamuser/Desktop")
|
||||
NOT_PROGRAMS = re.compile(r"(?i)^unins")
|
||||
ABSENT = (FileNotFoundError, NotADirectoryError, IsADirectoryError)
|
||||
|
||||
_run = None
|
||||
|
||||
|
||||
def present(path, regular=False):
|
||||
try:
|
||||
mode = os.stat(path).st_mode
|
||||
except ABSENT:
|
||||
return False
|
||||
return stat.S_ISREG(mode) if regular else True
|
||||
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
return f.read()
|
||||
except ABSENT:
|
||||
return None
|
||||
|
||||
|
||||
def proton_run():
|
||||
global _run
|
||||
if _run is None:
|
||||
_run = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-proton-run"))
|
||||
return _run
|
||||
|
||||
|
||||
def shortcut_ids(root):
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
# account_dir takes either of these as missing when it cannot be read.
|
||||
read(os.path.join(root, "config", "loginusers.vdf"))
|
||||
listing(os.path.join(root, "userdata"))
|
||||
account = tool["account_dir"](root)
|
||||
if account:
|
||||
try:
|
||||
with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f:
|
||||
tool["parse"](f.read())
|
||||
except ABSENT:
|
||||
pass
|
||||
except (ValueError, IndexError, KeyError, struct.error) as error:
|
||||
raise OSError("Steam's shortcuts.vdf cannot be read: %s" % error) from error
|
||||
return {appid for appid, _, _ in proton_run()["shortcut_entries"](root)}
|
||||
|
||||
|
||||
def runs_here(pfx, exe):
|
||||
target = proton_run()["prefix_of"](exe)
|
||||
return target is not None and os.path.realpath(target.compatdata) == os.path.realpath(os.path.dirname(pfx))
|
||||
|
||||
|
||||
def listing(folder, suffix=""):
|
||||
try:
|
||||
names = os.listdir(folder)
|
||||
except ABSENT:
|
||||
return None
|
||||
return sorted(os.path.join(folder, name) for name in names if name.lower().endswith(suffix))
|
||||
|
||||
|
||||
def prefixes(root):
|
||||
compatdata = os.path.join(root, "steamapps", "compatdata")
|
||||
names = listing(compatdata)
|
||||
if names is None:
|
||||
return []
|
||||
owned = shortcut_ids(root)
|
||||
found = []
|
||||
for name in (os.path.basename(path) for path in names):
|
||||
if not re.fullmatch(r"-?[0-9]+", name):
|
||||
continue
|
||||
appid = int(name) % 2 ** 32
|
||||
pfx = os.path.join(compatdata, name, "pfx")
|
||||
if appid & SHORTCUT_BIT and appid not in owned and listing(os.path.join(pfx, "drive_c", "proton_shortcuts")) is not None:
|
||||
found.append((appid, pfx))
|
||||
return found
|
||||
|
||||
|
||||
def zero_terminated(data, start, wide):
|
||||
if wide:
|
||||
end = start
|
||||
while data[end:end + 2] not in (b"\0\0", b""):
|
||||
end += 2
|
||||
return data[start:end].decode("utf-16-le", "replace")
|
||||
end = data.find(b"\0", start)
|
||||
return data[start:end if end >= 0 else len(data)].decode("cp1252", "replace")
|
||||
|
||||
|
||||
def link_target(path):
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read(1 << 16)
|
||||
size, = struct.unpack_from("<I", data, 0)
|
||||
flags, = struct.unpack_from("<I", data, 0x14)
|
||||
pos, target = size, None
|
||||
if flags & 0x1:
|
||||
pos += 2 + struct.unpack_from("<H", data, pos)[0]
|
||||
if flags & 0x2:
|
||||
info_size, header, info_flags, _, local, _, suffix = struct.unpack_from("<7I", data, pos)
|
||||
if info_flags & 0x1:
|
||||
if header >= 0x24:
|
||||
local_wide, suffix_wide = struct.unpack_from("<2I", data, pos + 0x1C)
|
||||
target = zero_terminated(data, pos + local_wide, True) + zero_terminated(data, pos + suffix_wide, True)
|
||||
else:
|
||||
target = zero_terminated(data, pos + local, False) + zero_terminated(data, pos + suffix, False)
|
||||
pos += info_size
|
||||
args = ""
|
||||
wide = bool(flags & 0x80)
|
||||
for bit in (0x4, 0x8, 0x10, 0x20, 0x40):
|
||||
if flags & bit:
|
||||
count, = struct.unpack_from("<H", data, pos)
|
||||
end = pos + 2 + count * (2 if wide else 1)
|
||||
if bit == 0x20:
|
||||
args = data[pos + 2:end].decode("utf-16-le" if wide else "cp1252", "replace").rstrip("\0")
|
||||
pos = end
|
||||
return target, args
|
||||
except ABSENT + (struct.error, ValueError):
|
||||
return None, ""
|
||||
|
||||
|
||||
def host_path(pfx, windows):
|
||||
found = re.fullmatch(r"([A-Za-z]):\\?(.*)", windows or "")
|
||||
if not found:
|
||||
return None
|
||||
path = os.path.realpath(os.path.join(pfx, "dosdevices", found.group(1).lower() + ":"))
|
||||
for part in (p for p in found.group(2).split("\\") if p):
|
||||
exact = os.path.join(path, part)
|
||||
if not os.path.lexists(exact):
|
||||
try:
|
||||
exact = next((os.path.join(path, name) for name in os.listdir(path) if name.lower() == part.lower()), exact)
|
||||
except ABSENT:
|
||||
return None
|
||||
path = exact
|
||||
return path if present(path) else None
|
||||
|
||||
|
||||
def value(text, key):
|
||||
found = re.search(r"^%s=(.*)$" % re.escape(key), text, re.M)
|
||||
return found.group(1).strip() if found else ""
|
||||
|
||||
|
||||
def windows_link(exec_value):
|
||||
if len(exec_value) >= 2 and exec_value[0] == exec_value[-1] == '"':
|
||||
exec_value = exec_value[1:-1]
|
||||
# A desktop file escapes a backslash once for the key and again inside a quoted Exec argument.
|
||||
return exec_value.replace("\\\\", "\\").replace("\\\\", "\\")
|
||||
|
||||
|
||||
def icon(shortcuts, name):
|
||||
best, size = "system-run", 0
|
||||
for apps in glob.glob(os.path.join(glob.escape(shortcuts), "icons", "*", "apps")):
|
||||
found = re.fullmatch(r"(\d+)x\d+", os.path.basename(os.path.dirname(apps)))
|
||||
path = os.path.join(apps, name + ".png")
|
||||
if name and found and int(found.group(1)) > size and os.path.isfile(path):
|
||||
best, size = path, int(found.group(1))
|
||||
return best
|
||||
|
||||
|
||||
def program(pfx, link):
|
||||
target, args = link_target(link)
|
||||
exe = host_path(pfx, target)
|
||||
if (exe and exe.lower().endswith(".exe") and not NOT_PROGRAMS.match(os.path.basename(exe)) and present(exe, regular=True)
|
||||
and runs_here(pfx, exe)):
|
||||
return exe, args
|
||||
return None, ""
|
||||
|
||||
|
||||
def programs(pfx):
|
||||
shortcuts = os.path.join(pfx, "drive_c", "proton_shortcuts")
|
||||
found = {}
|
||||
for entry in listing(shortcuts, ".desktop") or []:
|
||||
text = read(entry) or ""
|
||||
link = host_path(pfx, windows_link(value(text, "Exec")))
|
||||
if not link or not link.lower().endswith(".lnk"):
|
||||
continue
|
||||
exe, args = program(pfx, link)
|
||||
if exe:
|
||||
found[exe] = dict(name=value(text, "Name") or os.path.splitext(os.path.basename(entry))[0], args=args,
|
||||
icon=icon(shortcuts, value(text, "Icon")), wm_class=value(text, "StartupWMClass"))
|
||||
return found
|
||||
|
||||
|
||||
def on_windows_desktop(pfx):
|
||||
found = set()
|
||||
for folder in WINDOWS_DESKTOPS:
|
||||
for link in listing(os.path.join(pfx, "drive_c", folder), ".lnk") or []:
|
||||
exe, _ = program(pfx, link)
|
||||
if exe:
|
||||
found.add(exe)
|
||||
return found
|
||||
|
||||
|
||||
def windows_args(text):
|
||||
args, current, started, quoted, slashes = [], "", False, False, 0
|
||||
for ch in text:
|
||||
if ch == "\\":
|
||||
slashes += 1
|
||||
started = True
|
||||
elif ch == '"':
|
||||
current += "\\" * (slashes // 2) + ('"' if slashes % 2 else "")
|
||||
if slashes % 2 == 0:
|
||||
quoted = not quoted
|
||||
slashes, started = 0, True
|
||||
else:
|
||||
current += "\\" * slashes
|
||||
slashes = 0
|
||||
if ch in " \t" and not quoted:
|
||||
if started:
|
||||
args.append(current)
|
||||
current, started = "", False
|
||||
else:
|
||||
current += ch
|
||||
started = True
|
||||
if started:
|
||||
args.append(current + "\\" * slashes)
|
||||
return args
|
||||
|
||||
|
||||
def quoted(arg):
|
||||
escaped = re.sub(r'([\\"`$])', r"\\\1", arg).replace("%", "%%")
|
||||
return '"%s"' % escaped.replace("\\", "\\\\")
|
||||
|
||||
|
||||
def entry(exe, found):
|
||||
args = windows_args(found["args"])
|
||||
lines = ["[Desktop Entry]", "Type=Application", "Name=%s" % found["name"].replace("\n", " "),
|
||||
"Comment=Windows program installed from the desktop",
|
||||
"Exec=%s" % " ".join(quoted(arg) for arg in [OPEN, exe] + args),
|
||||
"Icon=%s" % found["icon"], "Terminal=false", "Categories=Game;"]
|
||||
if found["wm_class"]:
|
||||
lines.append("StartupWMClass=%s" % found["wm_class"])
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def desktop_dir():
|
||||
try:
|
||||
path = subprocess.run(["xdg-user-dir", "DESKTOP"], capture_output=True, text=True, timeout=5).stdout.strip()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
path = ""
|
||||
return path if path and path != HOME else os.path.join(HOME, "Desktop")
|
||||
|
||||
|
||||
def sync(directory, wanted, mode=0o644):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
for name in os.listdir(directory):
|
||||
if name.startswith(PREFIX) and name.endswith(".desktop") and name not in wanted:
|
||||
os.unlink(os.path.join(directory, name))
|
||||
for name, body in wanted.items():
|
||||
path = os.path.join(directory, name)
|
||||
if read(path) != body:
|
||||
try:
|
||||
with open(path + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write(body)
|
||||
os.chmod(path + ".tmp", mode)
|
||||
os.replace(path + ".tmp", path)
|
||||
except OSError:
|
||||
if os.path.lexists(path + ".tmp"):
|
||||
os.unlink(path + ".tmp")
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
os.makedirs(os.path.dirname(PLACED), exist_ok=True)
|
||||
with open(PLACED + ".lock", "w") as lock:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
try:
|
||||
refresh()
|
||||
except OSError as error:
|
||||
print("droiddeck-desktop-programs: the menu is left as it was (%s)" % error)
|
||||
|
||||
|
||||
def refresh():
|
||||
menu, desktop_wanted = {}, set()
|
||||
for appid, pfx in prefixes(STEAM_ROOT):
|
||||
on_desktop = on_windows_desktop(pfx)
|
||||
for exe, found in programs(pfx).items():
|
||||
name = "%s%d-%08x.desktop" % (PREFIX, appid, zlib.crc32(exe.encode("utf-8")))
|
||||
menu[name] = entry(exe, found)
|
||||
if exe in on_desktop:
|
||||
desktop_wanted.add(name)
|
||||
placed = set((read(PLACED) or "").split())
|
||||
sync(APPS_DIR, menu)
|
||||
desktop = desktop_dir()
|
||||
shown = {name: menu[name] for name in sorted(desktop_wanted)
|
||||
if name not in placed or present(os.path.join(desktop, name), regular=True)}
|
||||
try:
|
||||
sync(desktop, shown, 0o755)
|
||||
finally:
|
||||
written = {name for name in shown if present(os.path.join(desktop, name), regular=True)}
|
||||
with open(PLACED + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write("".join(name + "\n" for name in sorted((placed | written) & set(menu))))
|
||||
os.replace(PLACED + ".tmp", PLACED)
|
||||
print("droiddeck-desktop-programs: %d program%s in the menu, %d on the desktop" % (
|
||||
len(menu), "" if len(menu) == 1 else "s", len(shown)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,446 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
PREFIX = "DROIDDECK_PROCESS_TRACE "
|
||||
SCHEMA = 1
|
||||
DEFAULT_INTERVAL_MS = 5_000
|
||||
DEFAULT_DURATION_MS = 86_400_000
|
||||
DEFAULT_MAX_RECORDS = 512
|
||||
HEARTBEAT_MS = 300_000
|
||||
MAX_PROCESSES = 256
|
||||
MAX_MAP_BYTES = 8 * 1024 * 1024
|
||||
MAX_MAP_LINES = 65_536
|
||||
MAX_LIBRARIES = 128
|
||||
MAX_CMDLINE_BYTES = 16 * 1024
|
||||
MAX_ENUMERATED_PROCESSES = 4_096
|
||||
MAX_CHILDREN_BYTES = 64 * 1024
|
||||
SAFE_LIBRARY = re.compile(r"[A-Za-z0-9._+-]{1,128}")
|
||||
WINDOWS_GRAPHICS_LIBRARIES = {
|
||||
"d3d8.dll", "d3d9.dll", "d3d10.dll", "d3d10_1.dll", "d3d10core.dll",
|
||||
"d3d11.dll", "d3d12.dll", "dxgi.dll", "vulkan-1.dll",
|
||||
}
|
||||
KNOWN_GRAPHICS_SONAMES = {
|
||||
"libvulkan.so", "libvulkan_freedreno.so", "libvulkan_panfrost.so", "libvulkan_lvp.so",
|
||||
"libvulkan_virtio.so", "libvulkan_dzn.so", "libvulkan_broadcom.so",
|
||||
"libEGL.so", "libEGL_mesa.so", "libGLESv1_CM.so", "libGLESv2.so", "libGLESv3.so",
|
||||
"libGL.so", "libGLX.so", "libGLX_mesa.so", "libgbm.so", "libwayland-client.so",
|
||||
"libX11.so", "libX11-xcb.so", "libdrm.so", "libdrm_amdgpu.so", "libdrm_freedreno.so",
|
||||
"libdrm_intel.so", "libdrm_nouveau.so", "libdrm_radeon.so", "libxcb.so", "libxcb-dri2.so",
|
||||
"libxcb-dri3.so", "libxcb-glx.so", "libxcb-present.so", "libxcb-randr.so", "libxcb-render.so",
|
||||
"libxcb-shm.so", "libxcb-sync.so", "libxcb-xfixes.so", "libhybris-vulkan-icd.so",
|
||||
"libVkLayer_hybris_compat.so", "libVkLayer_DROIDDECK_placed_memory.so",
|
||||
"libVkLayer_KHRONOS_validation.so", "libVkLayer_FROG_gamescope_wsi_aarch64.so",
|
||||
"libVkLayer_MESA_device_select.so", "libVkLayer_MESA_overlay.so", "libvkd3d.so",
|
||||
"libvkd3d-shader.so", "libvkd3d-utils.so",
|
||||
}
|
||||
|
||||
|
||||
def emit(payload, output=sys.stdout):
|
||||
output.write(PREFIX + json.dumps(payload, separators=(",", ":"), sort_keys=True) + "\n")
|
||||
output.flush()
|
||||
|
||||
|
||||
def process_stat(path):
|
||||
text = path.read_text(errors="replace")
|
||||
end = text.rfind(") ")
|
||||
if end < 0:
|
||||
raise ValueError("invalid process stat")
|
||||
fields = text[end + 2:].split()
|
||||
if len(fields) < 20:
|
||||
raise ValueError("short process stat")
|
||||
return int(fields[1]), fields[19]
|
||||
|
||||
|
||||
def bounded_bytes(path, limit):
|
||||
with path.open("rb") as source:
|
||||
return source.read(limit)
|
||||
|
||||
|
||||
def process_role(comm, cmdline):
|
||||
probe = (comm + "\0" + cmdline.decode("utf-8", "replace")).lower()
|
||||
if "steamwebhelper" in probe:
|
||||
return "steam-webhelper"
|
||||
if "gamescope" in probe:
|
||||
return "gamescope"
|
||||
if "xwayland" in probe:
|
||||
return "xwayland"
|
||||
if "mangoapp" in probe:
|
||||
return "mangoapp"
|
||||
if "pressure-vessel" in probe or "steam-runtime" in probe:
|
||||
return "steam-runtime"
|
||||
if "steamrtarm64/steam" in probe or "steamrt64/steam" in probe or comm.lower() == "steam":
|
||||
return "steam-client"
|
||||
if "fexinterpreter" in probe or comm.lower() == "fex":
|
||||
return "fex"
|
||||
if "wineserver" in probe:
|
||||
return "wineserver"
|
||||
if any(name in probe for name in ("wine64", "wine-preloader", "/wine ")):
|
||||
return "wine"
|
||||
if "pipewire" in probe or "pulseaudio" in probe:
|
||||
return "audio-server"
|
||||
if "dbus-daemon" in probe:
|
||||
return "dbus"
|
||||
if "droiddeck-session" in probe:
|
||||
return "session"
|
||||
return "game-or-helper"
|
||||
|
||||
|
||||
def is_graphics_library(name):
|
||||
lower = name.lower()
|
||||
return (
|
||||
lower in WINDOWS_GRAPHICS_LIBRARIES or
|
||||
lower.startswith(("libvulkan", "libvklayer", "vulkan.", "libegl", "libgles", "libglx",
|
||||
"libgl.so", "libgbm", "libdrm", "libwayland", "libxcb", "libx11")) or
|
||||
"vkd3d" in lower or "dxvk" in lower or "zink" in lower or "mangohud" in lower
|
||||
)
|
||||
|
||||
|
||||
def origin_class(path):
|
||||
lower = path.lower()
|
||||
if lower.startswith("/vendor/"):
|
||||
return "android-vendor"
|
||||
if lower.startswith(("/system/", "/apex/")):
|
||||
return "android-system"
|
||||
if "/files/components/" in lower or "/files/system_vulkan/" in lower:
|
||||
return "droiddeck-component"
|
||||
if "/steamapps/common/" in lower:
|
||||
return "steam-tool"
|
||||
if lower.startswith(("/usr/", "/lib/", "/opt/")):
|
||||
return "guest-runtime"
|
||||
if lower.startswith("/tmp/"):
|
||||
return "temporary"
|
||||
return "other"
|
||||
|
||||
|
||||
def library_identity(name, origin):
|
||||
if origin in {"android-vendor", "android-system"}:
|
||||
return name
|
||||
base = name
|
||||
while True:
|
||||
head, separator, tail = base.rpartition(".")
|
||||
if not separator or not tail.isdigit():
|
||||
break
|
||||
base = head
|
||||
if name.lower() in WINDOWS_GRAPHICS_LIBRARIES or base in KNOWN_GRAPHICS_SONAMES:
|
||||
return name
|
||||
return "sha256:" + hashlib.sha256(name.encode()).hexdigest()[:16]
|
||||
|
||||
|
||||
def graphics_libraries(maps_path):
|
||||
libraries = set()
|
||||
total = 0
|
||||
lines = 0
|
||||
with maps_path.open("rb") as source:
|
||||
while lines < MAX_MAP_LINES and total < MAX_MAP_BYTES:
|
||||
raw = source.readline(min(64 * 1024, MAX_MAP_BYTES - total + 1))
|
||||
if not raw:
|
||||
break
|
||||
total += len(raw)
|
||||
lines += 1
|
||||
if total > MAX_MAP_BYTES:
|
||||
return libraries, "capped"
|
||||
parts = raw.decode("utf-8", "replace").rstrip("\n").split(None, 5)
|
||||
if len(parts) < 6 or not parts[5].startswith("/"):
|
||||
continue
|
||||
mapped = parts[5].removesuffix(" (deleted)")
|
||||
name = os.path.basename(mapped)
|
||||
if SAFE_LIBRARY.fullmatch(name) and is_graphics_library(name):
|
||||
origin = origin_class(mapped)
|
||||
libraries.add((library_identity(name, origin), origin))
|
||||
if len(libraries) >= MAX_LIBRARIES:
|
||||
return libraries, "capped"
|
||||
return libraries, "readable"
|
||||
|
||||
|
||||
class Collector:
|
||||
def __init__(self, proc_root, root_pid):
|
||||
self.proc_root = Path(proc_root)
|
||||
self.root_pid = int(root_pid)
|
||||
self.known = {}
|
||||
self.tokens = {}
|
||||
self.next_token = 1
|
||||
self.self_pid = os.getpid()
|
||||
self.root_identity = None
|
||||
self.last_maps_state = None
|
||||
self.last_provider_error = None
|
||||
|
||||
def _scan_fallback(self, result):
|
||||
capped = False
|
||||
try:
|
||||
entries = self.proc_root.iterdir()
|
||||
except OSError:
|
||||
return capped, "proc-unavailable"
|
||||
examined = 0
|
||||
for entry in entries:
|
||||
if not entry.name.isdigit():
|
||||
continue
|
||||
examined += 1
|
||||
if examined > MAX_ENUMERATED_PROCESSES:
|
||||
capped = True
|
||||
break
|
||||
pid = int(entry.name)
|
||||
if pid == self.self_pid or pid in result:
|
||||
continue
|
||||
try:
|
||||
result[pid] = process_stat(entry / "stat")
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
return capped, None
|
||||
|
||||
def _stats(self):
|
||||
result = {}
|
||||
capped = False
|
||||
try:
|
||||
ppid, start = process_stat(self.proc_root / str(self.root_pid) / "stat")
|
||||
if self.root_pid != self.self_pid:
|
||||
result[self.root_pid] = (ppid, start)
|
||||
except (OSError, ValueError):
|
||||
return result, capped, "proc-unavailable", "children", True
|
||||
queue = [self.root_pid]
|
||||
fallback = False
|
||||
while queue and len(result) < MAX_PROCESSES:
|
||||
parent = queue.pop(0)
|
||||
try:
|
||||
raw = bounded_bytes(
|
||||
self.proc_root / str(parent) / "task" / str(parent) / "children", MAX_CHILDREN_BYTES + 1,
|
||||
)
|
||||
except OSError:
|
||||
fallback = True
|
||||
continue
|
||||
if len(raw) > MAX_CHILDREN_BYTES:
|
||||
capped = True
|
||||
fallback = True
|
||||
continue
|
||||
for value in raw.split():
|
||||
if not value.isdigit():
|
||||
continue
|
||||
pid = int(value)
|
||||
if pid == self.self_pid or pid in result:
|
||||
continue
|
||||
if len(result) >= MAX_PROCESSES:
|
||||
capped = True
|
||||
break
|
||||
try:
|
||||
identity = process_stat(self.proc_root / str(pid) / "stat")
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
if identity[0] != parent:
|
||||
continue
|
||||
result[pid] = identity
|
||||
queue.append(pid)
|
||||
if queue:
|
||||
capped = True
|
||||
if fallback:
|
||||
fallback_capped, error = self._scan_fallback(result)
|
||||
capped = capped or fallback_capped
|
||||
return result, capped, error, "children+scan-fallback", True
|
||||
return result, capped, None, "children", capped
|
||||
|
||||
def scan(self):
|
||||
stats, enumeration_capped, provider_error, scope_method, scope_incomplete = self._stats()
|
||||
descendants = set()
|
||||
root = stats.get(self.root_pid)
|
||||
if self.root_identity is None and root is not None:
|
||||
self.root_identity = root
|
||||
if root is not None and self.root_identity != root:
|
||||
provider_error = "root-reused"
|
||||
elif root is not None:
|
||||
descendants.add(self.root_pid)
|
||||
changed = True
|
||||
while changed and len(descendants) < MAX_PROCESSES:
|
||||
changed = False
|
||||
for pid, (ppid, _) in stats.items():
|
||||
if pid not in descendants and ppid in descendants:
|
||||
descendants.add(pid)
|
||||
changed = True
|
||||
if len(descendants) >= MAX_PROCESSES:
|
||||
break
|
||||
if provider_error is None and root is None:
|
||||
provider_error = "root-unavailable"
|
||||
scope_capped = len(descendants) >= MAX_PROCESSES or enumeration_capped
|
||||
current = {}
|
||||
maps_state = {"readable": 0, "unavailable": 0, "capped": 0}
|
||||
for pid in sorted(descendants):
|
||||
process = self.proc_root / str(pid)
|
||||
try:
|
||||
expected = stats[pid]
|
||||
if process_stat(process / "stat") != expected:
|
||||
continue
|
||||
ppid, start = expected
|
||||
comm = (process / "comm").read_text(errors="replace")[:128].strip()
|
||||
cmdline = bounded_bytes(process / "cmdline", MAX_CMDLINE_BYTES)
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
key = (pid, start)
|
||||
try:
|
||||
libraries, state = graphics_libraries(process / "maps")
|
||||
except (OSError, ValueError):
|
||||
libraries, state = set(), "unavailable"
|
||||
maps_state[state] = maps_state.get(state, 0) + 1
|
||||
current[key] = {
|
||||
"ppid": ppid,
|
||||
"role": process_role(comm, cmdline),
|
||||
"libraries": libraries,
|
||||
"identity": expected,
|
||||
"mapState": state,
|
||||
}
|
||||
stable = {}
|
||||
for key, process in current.items():
|
||||
pid = key[0]
|
||||
try:
|
||||
if process_stat(self.proc_root / str(pid) / "stat") != process["identity"]:
|
||||
continue
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
stable[key] = process
|
||||
final = {}
|
||||
valid_pids = {self.root_pid} if any(key[0] == self.root_pid for key in stable) else set()
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for key, process in stable.items():
|
||||
pid = key[0]
|
||||
if key not in final and (pid == self.root_pid or process["ppid"] in valid_pids):
|
||||
final[key] = process
|
||||
valid_pids.add(pid)
|
||||
changed = True
|
||||
current = final
|
||||
try:
|
||||
root_final = process_stat(self.proc_root / str(self.root_pid) / "stat")
|
||||
except (OSError, ValueError):
|
||||
root_final = None
|
||||
if root_final is None:
|
||||
if provider_error is None:
|
||||
provider_error = "root-unavailable"
|
||||
current = {}
|
||||
elif self.root_identity != root_final:
|
||||
provider_error = "root-reused"
|
||||
current = {}
|
||||
maps_state = {"readable": 0, "unavailable": 0, "capped": 0}
|
||||
for process in current.values():
|
||||
state = process["mapState"]
|
||||
maps_state[state] = maps_state.get(state, 0) + 1
|
||||
started = sorted(set(current) - set(self.known))
|
||||
exited = sorted(set(self.known) - set(current))
|
||||
roles_changed = any(
|
||||
key in self.known and current[key]["role"] != self.known[key]["role"] for key in current
|
||||
)
|
||||
for key in started:
|
||||
self.tokens[key] = self.next_token
|
||||
self.next_token += 1
|
||||
state_changed = maps_state != self.last_maps_state or provider_error != self.last_provider_error
|
||||
payload = self._snapshot(
|
||||
current, started, exited, maps_state, scope_capped, provider_error, scope_method, scope_incomplete,
|
||||
)
|
||||
for key in exited:
|
||||
self.tokens.pop(key, None)
|
||||
self.known = current
|
||||
self.last_maps_state = maps_state
|
||||
self.last_provider_error = provider_error
|
||||
return payload, bool(started or exited or roles_changed or payload["librariesChanged"] or state_changed)
|
||||
|
||||
def _snapshot(self, current, started, exited, maps_state, scope_capped, provider_error,
|
||||
scope_method, scope_incomplete):
|
||||
previous_libraries = {item for process in self.known.values() for item in process["libraries"]}
|
||||
libraries = {item for process in current.values() for item in process["libraries"]}
|
||||
role_counts = {}
|
||||
for process in current.values():
|
||||
role = process["role"]
|
||||
role_counts[role] = role_counts.get(role, 0) + 1
|
||||
started_rows = [{"token": self.tokens[key], "role": current[key]["role"]} for key in started[:32]]
|
||||
exited_rows = [{"token": self.tokens.get(key, 0), "role": self.known[key]["role"]} for key in exited[:32]]
|
||||
library_rows = [{"name": name, "origin": origin} for name, origin in sorted(libraries)[:MAX_LIBRARIES]]
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"event": "snapshot",
|
||||
"scope": "root-descendants",
|
||||
"scopeMethod": scope_method,
|
||||
"scopeIncomplete": scope_incomplete,
|
||||
"procView": "guest-visible",
|
||||
"alive": len(current),
|
||||
"roles": role_counts,
|
||||
"started": started_rows,
|
||||
"startedOmitted": max(0, len(started) - len(started_rows)),
|
||||
"exited": exited_rows,
|
||||
"exitedOmitted": max(0, len(exited) - len(exited_rows)),
|
||||
"libraries": library_rows,
|
||||
"librariesOmitted": max(0, len(libraries) - len(library_rows)),
|
||||
"librariesChanged": libraries != previous_libraries,
|
||||
"maps": maps_state,
|
||||
"scopeCapped": scope_capped,
|
||||
"providerStatus": provider_error or "available",
|
||||
}
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--once", action="store_true")
|
||||
parser.add_argument("--watch", action="store_true")
|
||||
parser.add_argument("--root-pid", type=int, default=os.getppid())
|
||||
parser.add_argument("--proc-root", default="/proc")
|
||||
parser.add_argument("--interval-ms", type=int, default=DEFAULT_INTERVAL_MS)
|
||||
parser.add_argument("--duration-ms", type=int, default=DEFAULT_DURATION_MS)
|
||||
parser.add_argument("--max-records", type=int, default=DEFAULT_MAX_RECORDS)
|
||||
args = parser.parse_args(argv)
|
||||
if args.once == args.watch:
|
||||
parser.error("choose exactly one of --once or --watch")
|
||||
if args.root_pid <= 0:
|
||||
parser.error("--root-pid must be positive")
|
||||
args.interval_ms = min(60_000, max(250, args.interval_ms))
|
||||
args.duration_ms = min(DEFAULT_DURATION_MS, max(0, args.duration_ms))
|
||||
args.max_records = min(1_024, max(3, args.max_records))
|
||||
return args
|
||||
|
||||
|
||||
def main(argv=None, environ=None, output=sys.stdout):
|
||||
environ = os.environ if environ is None else environ
|
||||
if environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") != "1":
|
||||
return 0
|
||||
args = parse_args(sys.argv[1:] if argv is None else argv)
|
||||
collector = Collector(args.proc_root, args.root_pid)
|
||||
emit({
|
||||
"schema": SCHEMA,
|
||||
"event": "provider",
|
||||
"mode": "once" if args.once else "watch",
|
||||
"intervalMs": args.interval_ms,
|
||||
"durationMs": 0 if args.once else args.duration_ms,
|
||||
"maxRecords": args.max_records,
|
||||
"scope": "root-descendants",
|
||||
"procView": "guest-visible",
|
||||
}, output)
|
||||
records = 1
|
||||
started = time.monotonic()
|
||||
last_heartbeat = started
|
||||
ended_normally = False
|
||||
while records < args.max_records - 1:
|
||||
payload, changed = collector.scan()
|
||||
now = time.monotonic()
|
||||
if changed or records == 1 or (now - last_heartbeat) * 1000 >= HEARTBEAT_MS:
|
||||
if not changed and records > 1:
|
||||
payload["event"] = "heartbeat"
|
||||
payload.pop("libraries", None)
|
||||
payload["librariesUnchanged"] = True
|
||||
payload["elapsedMs"] = int((now - started) * 1000)
|
||||
emit(payload, output)
|
||||
records += 1
|
||||
last_heartbeat = now
|
||||
if args.once or payload["providerStatus"] in {"root-unavailable", "root-reused"} or \
|
||||
(now - started) * 1000 >= args.duration_ms:
|
||||
ended_normally = True
|
||||
break
|
||||
time.sleep(args.interval_ms / 1000)
|
||||
if not ended_normally:
|
||||
emit({"schema": SCHEMA, "event": "limit", "reason": "max-records"}, output)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -14,7 +14,7 @@ install)
|
||||
droiddeck-root /usr/bin/apt-get install -y -q retroarch retroarch-assets $cores || { echo "== FAIL apt-get install"; exit 1; }
|
||||
echo "== STEP PPSSPP"
|
||||
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo || { echo "== FAIL flathub"; exit 1; }
|
||||
flatpak install --user -y --noninteractive flathub org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; }
|
||||
/usr/bin/python3 /usr/local/bin/droiddeck-flatpak install org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; }
|
||||
printf '#!/bin/sh\nexec /usr/local/bin/droiddeck-flatpak-run org.ppsspp.PPSSPP "$@"\n' > /usr/local/bin/PPSSPPSDL.new &&
|
||||
chmod 755 /usr/local/bin/PPSSPPSDL.new && mv -f /usr/local/bin/PPSSPPSDL.new /usr/local/bin/PPSSPPSDL || { echo "== FAIL PPSSPPSDL"; exit 1; }
|
||||
;;
|
||||
|
||||
@@ -111,6 +111,12 @@ def d3dgear_hook(game):
|
||||
return {"WINEDLLOVERRIDES": "d3dgear64=d"}, [], "D3DGear capture hook off (it stops the game drawing)"
|
||||
|
||||
|
||||
@fix
|
||||
def supergiant_dotnet_reporter(game):
|
||||
if "basecampbugreporter.native.dll" in game.files:
|
||||
return {"WINEDLLOVERRIDES": "mscoree=n,b"}, [], "Supergiant: allow the builtin mscoree"
|
||||
|
||||
|
||||
@fix
|
||||
def deep_rock_gdk_raytracing(game):
|
||||
if game.stem == "fsd-wingdk-shipping" and not any(game.has_arg(arg) for arg in ("-raytracing", "-noraytracing")):
|
||||
@@ -153,32 +159,6 @@ def little_nightmares_threads(game):
|
||||
return {"PROTONFIXES_DISABLE": "1"}, [], "Little Nightmares: umu-protonfixes off (its -onethread puts the game and renderer on one thread)"
|
||||
|
||||
|
||||
@fix
|
||||
def caravan_sandwitch_feature_level(game):
|
||||
if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)"
|
||||
|
||||
|
||||
@fix
|
||||
def robocop_rogue_city_feature_level(game):
|
||||
if "robocop.exe" in game.files or game.stem == "robocop-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "RoboCop: Rogue City: D3D12 feature level 12_1"
|
||||
|
||||
|
||||
@fix
|
||||
def reskate_feature_level(game):
|
||||
if "skate.exe" in game.files and "reskate.dll" in game.files:
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "ReSkate (skate.): D3D12 feature level 12_1"
|
||||
|
||||
|
||||
@fix
|
||||
def cyberpunk_feature_level(game):
|
||||
if game.stem == "cyberpunk2077" or (
|
||||
game.stem == "redprelauncher"
|
||||
and os.path.isfile(os.path.join(os.path.dirname(game.exe), "bin", "x64", "Cyberpunk2077.exe"))
|
||||
):
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Cyberpunk 2077: D3D12 feature level 12_1"
|
||||
|
||||
def skip_red_launcher(command):
|
||||
if len(command) > 2 and os.path.basename(command[2]).lower() == "redprelauncher.exe":
|
||||
game = os.path.join(os.path.dirname(command[2]), "bin", "x64", "Cyberpunk2077.exe")
|
||||
@@ -243,6 +223,20 @@ def ubisoft_overlay_off(env):
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
def ubisoft_composition_off(proton, env):
|
||||
prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx"
|
||||
if not (prefix / UBISOFT_LAUNCHER).is_dir() or not (prefix / "user.reg").is_file():
|
||||
return
|
||||
try:
|
||||
for program in ("upc.exe", "UplayWebCore.exe"):
|
||||
key = r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program
|
||||
subprocess.run([proton, "runinprefix", "reg.exe", "add", key,
|
||||
"/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"], env=env, check=True)
|
||||
print("droiddeck-game-env: Ubisoft Connect uses CEF without DirectComposition", file=sys.stderr)
|
||||
except (OSError, ValueError, subprocess.CalledProcessError) as error:
|
||||
print("droiddeck-game-env: Ubisoft Connect composition configuration failed (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
PZ_JVM_FLAGS = ("-XX:+UseG1GC", "-XX:TieredStopAtLevel=1")
|
||||
|
||||
|
||||
@@ -372,6 +366,8 @@ def vram_cap(env):
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
result["DROIDDECK_VRAM_CAP"] = "1"
|
||||
result["DROIDDECK_VRAM_CAP_MB"] = value
|
||||
return result
|
||||
|
||||
|
||||
@@ -528,9 +524,51 @@ def apply_config(env, config, app_id, fixes=None):
|
||||
if dxvk:
|
||||
own = result.get("DXVK_CONFIG", "").strip().rstrip(";").strip()
|
||||
result["DXVK_CONFIG"] = own + "; " + dxvk if own else dxvk
|
||||
# An open driver pair (PanVK, RADV) on a GPU that is not an Adreno: vkd3d-proton reports the
|
||||
# driver's own feature level and shader model. The app-wide 12_2 / 6_9 over-promised what PanVK
|
||||
# has, and an Unreal DX12 game took paths that crashed. A game's own setting still wins.
|
||||
if env.get("BL_OPEN_DRIVER") == "1":
|
||||
game = config.get("games", {}).get(app_id, {}) or {}
|
||||
for name in ("VKD3D_FEATURE_LEVEL", "VKD3D_SHADER_MODEL"):
|
||||
if name not in game and name in result:
|
||||
result.pop(name)
|
||||
result["DROIDDECK_VKD3D_CAPS"] = "driver"
|
||||
return result
|
||||
|
||||
|
||||
def render_path_defaults(command, env):
|
||||
if len(command) < 3 or command[1] != "waitforexitandrun" or Path(command[2]).name.lower() != "spintires.exe":
|
||||
return None
|
||||
own = env.get("DXVK_CONFIG", "")
|
||||
if re.search(r"(?:^|;)\s*dxvk\.tilerMode\s*=", own) or env.get("DXVK_CONFIG_FILE"):
|
||||
return None
|
||||
if Path("dxvk.conf").is_file() or Path(command[2]).with_name("dxvk.conf").is_file():
|
||||
return None
|
||||
driver = env.get("VK_DRIVER_FILES", env.get("VK_ICD_FILENAMES", ""))
|
||||
if Path(driver).parent.name != "DD-Turnip_v0.4.0":
|
||||
return None
|
||||
try:
|
||||
if Path("/sys/class/kgsl/kgsl-3d0/gpu_model").read_text().strip() != "Adreno722":
|
||||
return None
|
||||
with open(driver, encoding="utf-8") as source:
|
||||
library = json.load(source)["ICD"]["library_path"]
|
||||
if Path(library).name != "libvulkan_freedreno.so":
|
||||
return None
|
||||
except (OSError, ValueError, KeyError, TypeError):
|
||||
return None
|
||||
own = own.strip().rstrip(";").strip()
|
||||
env["DXVK_CONFIG"] = own + "; dxvk.tilerMode = False" if own else "dxvk.tilerMode = False"
|
||||
return "Spintires: DXVK tiler heuristics off on Adreno 722"
|
||||
|
||||
|
||||
def bridge_feature_level(env):
|
||||
if env.get("BL_VKBRIDGE") != "1" or env.get("VKD3D_FEATURE_LEVEL") not in ("12_1", "12_2"):
|
||||
return None
|
||||
was = env["VKD3D_FEATURE_LEVEL"]
|
||||
env["VKD3D_FEATURE_LEVEL"] = "12_0"
|
||||
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",
|
||||
)
|
||||
@@ -923,7 +961,7 @@ def ego_core_plan(command, env):
|
||||
return "%s had no thread plan for %d cores; added a copy of its %s-core plan" % (EGO_RESTRICTIONS, count, source.group(2))
|
||||
|
||||
|
||||
def wait_forwarding_signals(process):
|
||||
def wait_forwarding_signals_raw(process):
|
||||
def forward(signum, frame):
|
||||
try:
|
||||
process.send_signal(signum)
|
||||
@@ -936,20 +974,56 @@ def wait_forwarding_signals(process):
|
||||
finally:
|
||||
for signum, handler in previous.items():
|
||||
signal.signal(signum, handler)
|
||||
return code
|
||||
|
||||
|
||||
def wait_forwarding_signals(process):
|
||||
code = wait_forwarding_signals_raw(process)
|
||||
return 128 - code if code < 0 else code
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None):
|
||||
if after:
|
||||
def diagnostic_game_event(event, app_id, values=None):
|
||||
fields = ["event=" + event, "app_id=" + app_id]
|
||||
fields.extend("%s=%s" % item for item in (values or {}).items())
|
||||
print("DROIDDECK_DIAGNOSTICS " + " ".join(fields), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None):
|
||||
normalized = 128 - raw_code if raw_code < 0 else raw_code
|
||||
values = {
|
||||
"raw_status": raw_code,
|
||||
"normalized_status": normalized,
|
||||
"wrapper_status": normalized if wrapper_status is None else wrapper_status,
|
||||
"signal": -raw_code if raw_code < 0 else 0,
|
||||
}
|
||||
if source is not None:
|
||||
values["source"] = source
|
||||
diagnostic_game_event("game_exit", app_id, values)
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None, diagnostic_app_id=None):
|
||||
if len(launch) > 1 and launch[1] == "waitforexitandrun":
|
||||
ubisoft_composition_off(launch[0], launch_env)
|
||||
launch, launch_env = system_graphics_launch(launch, launch_env)
|
||||
if after or diagnostic_app_id is not None:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
if diagnostic_app_id is not None:
|
||||
diagnostic_game_event("game_start", diagnostic_app_id)
|
||||
try:
|
||||
return wait_forwarding_signals(process)
|
||||
raw_code = wait_forwarding_signals_raw(process)
|
||||
finally:
|
||||
try:
|
||||
after()
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error,
|
||||
file=sys.stderr)
|
||||
if after:
|
||||
try:
|
||||
after()
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error,
|
||||
file=sys.stderr)
|
||||
code = 128 - raw_code if raw_code < 0 else raw_code
|
||||
if digest and after is None and code == 0:
|
||||
record_install_scripts(digest, launch_env)
|
||||
if diagnostic_app_id is not None:
|
||||
diagnostic_game_exit(diagnostic_app_id, raw_code)
|
||||
return code
|
||||
if digest:
|
||||
code = subprocess.run(launch, env=launch_env, check=False).returncode
|
||||
if code == 0:
|
||||
@@ -958,6 +1032,110 @@ def start(launch, launch_env, digest, after=None):
|
||||
return os.execvpe(launch[0], launch, launch_env)
|
||||
|
||||
|
||||
class SystemGraphicsError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def system_graphics_launch(command, env):
|
||||
"""Use the APK's PowerVR compatibility files only for actual Proton game launches."""
|
||||
runtime = env.get("DROIDDECK_POWERVR_RUNTIME")
|
||||
if not runtime or not game_id(env) or len(command) < 3 or command[1] != "waitforexitandrun":
|
||||
return command, env
|
||||
directory = Path(runtime)
|
||||
if not directory.is_absolute():
|
||||
raise SystemGraphicsError("system Vulkan runtime path is not absolute")
|
||||
# run-proton.py picks the same payload by name; Xclipse needs a DXVK within 128 bytes of push data.
|
||||
payload = env.get("DROIDDECK_HYBRIS_DXVK") or "dxvk"
|
||||
if not payload.startswith("dxvk") or "/" in payload:
|
||||
raise SystemGraphicsError("invalid DXVK payload name: %s" % payload)
|
||||
required = (
|
||||
"run-proton.py", "wsi/libVkLayer_window_system_integration.so",
|
||||
"wsi/VkLayer_window_system_integration.json", "lib/libVkLayer_hybris_compat.so",
|
||||
*("%s/%s/%s.dll" % (payload, arch, name) for arch in ("x32", "x64")
|
||||
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")),
|
||||
)
|
||||
try:
|
||||
for name in required:
|
||||
path = directory / name
|
||||
if not path.is_file() or not path.stat().st_size:
|
||||
raise SystemGraphicsError("missing system Vulkan component: %s" % name)
|
||||
wrapper = directory / "run-proton.py"
|
||||
if not os.access(wrapper, os.X_OK):
|
||||
raise SystemGraphicsError("system Vulkan Proton wrapper is not executable")
|
||||
except OSError as error:
|
||||
raise SystemGraphicsError("system Vulkan component is unreadable: %s" % error) from error
|
||||
result = dict(env)
|
||||
layers = "VK_LAYER_window_system_integration:" + env.get("DROIDDECK_HYBRIS_LAYERS", "VK_LAYER_HYBRIS_compat")
|
||||
result.update({
|
||||
"HYBRIS_BC_TEXTURES": "dxvk",
|
||||
"VK_LAYER_PATH": ":".join(filter(None, (str(directory / "wsi"), str(directory / "lib"),
|
||||
env.get("DROIDDECK_HYBRIS_LAYER_PATH")))),
|
||||
"VK_INSTANCE_LAYERS": layers,
|
||||
"ENABLE_GAMESCOPE_WSI": "0",
|
||||
"VK_LOADER_LAYERS_DISABLE": "*gamescope*",
|
||||
"DISABLE_VK_LAYER_VALVE_steam_fossilize_1": "1",
|
||||
})
|
||||
for name in ("DISABLE_WSI_LAYER", "PROTON_USE_WINED3D", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"):
|
||||
result.pop(name, None)
|
||||
return [str(wrapper), *command], result
|
||||
|
||||
|
||||
def game_logs(command, env, app_id, now=None):
|
||||
"""Detailed graphics logs for one game launch, in the session's log folder: Proton's own log,
|
||||
DXVK's and vkd3d-proton's, and the Vulkan driver's startup messages. The app turns this on
|
||||
(BL_GAME_LOGS=1) on a GPU that is not an Adreno, or with Setup's "Detailed graphics logs"."""
|
||||
if env.get("BL_GAME_LOGS") != "1" or not env.get("BL_DEBUG_DIR") or len(command) < 3 \
|
||||
or command[1] != "waitforexitandrun":
|
||||
return env
|
||||
import time
|
||||
stamp = time.strftime("%Y%m%d-%H%M%S", time.localtime(now))
|
||||
name = app_id or re.sub(r"[^A-Za-z0-9._-]+", "_", Path(command[2]).stem)[:40] or "game"
|
||||
parent = Path(env["BL_DEBUG_DIR"]) / "games"
|
||||
try:
|
||||
parent.mkdir(parents=True, exist_ok=True)
|
||||
folder = Path(tempfile.mkdtemp(prefix=stamp + "-", suffix="-" + name, dir=parent))
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: no game log folder (%s)" % error, file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": str(folder),
|
||||
"DXVK_LOG_PATH": str(folder),
|
||||
"DXVK_LOG_LEVEL": env.get("DXVK_LOG_LEVEL", "info"),
|
||||
"VKD3D_LOG_FILE": str(folder / "vkd3d.log"),
|
||||
"VKD3D_DEBUG": env.get("VKD3D_DEBUG", "warn"),
|
||||
"VKD3D_SHADER_DEBUG": env.get("VKD3D_SHADER_DEBUG", "none"),
|
||||
"MESA_LOG_FILE": str(folder / "mesa.log"),
|
||||
"PANVK_DEBUG": env.get("PANVK_DEBUG", "startup"),
|
||||
})
|
||||
try:
|
||||
(folder / "launch.txt").write_text("\n".join([
|
||||
"app: %s" % (app_id or "-"),
|
||||
"exe: %s" % command[2],
|
||||
"proton: %s" % command[0],
|
||||
"started: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now)),
|
||||
] + ["%s=%s" % (key, env[key]) for key in sorted(env)
|
||||
if key.startswith(("VK_", "BL_VK", "BL_DRM", "BL_OPEN", "MESA_", "PANVK", "DXVK_", "VKD3D", "ZINK", "TU_", "DROIDDECK_VKD3D"))]) + "\n")
|
||||
except OSError:
|
||||
pass
|
||||
# Whether the game's sound reaches PulseAudio: the streams 20 s and 60 s in, without waiting.
|
||||
try:
|
||||
subprocess.Popen(["sh", "-c", 'for t in 20 40; do sleep $t; { echo "== $(date +%T)"; '
|
||||
'pactl list sink-inputs 2>&1 | head -80; } >> "$1/audio-streams.txt"; done', "audio", str(folder)],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
start_new_session=True)
|
||||
except OSError:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def exec_proton(command, env):
|
||||
# Synchronization selection has already picked the actual Proton executable.
|
||||
command, env = system_graphics_launch(command, env)
|
||||
os.execvpe(command[0], command, env)
|
||||
|
||||
|
||||
def main():
|
||||
command = sys.argv[1:]
|
||||
if not command:
|
||||
@@ -974,10 +1152,11 @@ def main():
|
||||
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:
|
||||
gl_default = gl_vsync(env)
|
||||
waiting = len(command) > 1 and command[1] == "waitforexitandrun"
|
||||
if waiting:
|
||||
game_images(env)
|
||||
fixes = {}
|
||||
@@ -1024,10 +1203,17 @@ def main():
|
||||
print("droiddeck-game-env: OpenGL does not wait for the screen refresh (vblank_mode=0)", file=sys.stderr)
|
||||
if app_id and len(command) > 1 and command[1] == "waitforexitandrun":
|
||||
command = offline_without_anticheat(command, env)
|
||||
env = game_logs(command, env, app_id)
|
||||
if mic_enabled == "0":
|
||||
env["AUDIO_DIRECT_MIC"] = "0"
|
||||
env = directaudio_settings(env)
|
||||
env = vram_cap(env)
|
||||
note = render_path_defaults(command, env) if app_id else None
|
||||
if note:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
note = bridge_feature_level(env)
|
||||
if note:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
cpu_topology(env, command)
|
||||
@@ -1049,6 +1235,8 @@ def main():
|
||||
print("droiddeck-game-env: Xbox launch could not start (%s)" % error, file=sys.stderr)
|
||||
return 1
|
||||
if xbox_result is not None:
|
||||
if diagnostic_app_id is not None and isinstance(xbox_result, int):
|
||||
diagnostic_game_exit(diagnostic_app_id, xbox_result, "xbox", xbox_result % 256)
|
||||
return xbox_result
|
||||
after = None
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
@@ -1074,13 +1262,13 @@ def main():
|
||||
launch, launch_env = select_sync(command, env, sync)
|
||||
if launch[0] != command[0]:
|
||||
try:
|
||||
return start(launch, launch_env, digest, after)
|
||||
return start(launch, launch_env, digest, after, diagnostic_app_id)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: %s could not start (%s); stock launch" % (launch[0], error), file=sys.stderr)
|
||||
launch, launch_env = command, without_pack(launch_env, env)
|
||||
record_stock(sync, launch, launch_env)
|
||||
try:
|
||||
return start(launch, launch_env, digest, after)
|
||||
return start(launch, launch_env, digest, after, diagnostic_app_id)
|
||||
except OSError:
|
||||
if after:
|
||||
try:
|
||||
@@ -1092,4 +1280,8 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
try:
|
||||
sys.exit(main())
|
||||
except SystemGraphicsError as error:
|
||||
print("droiddeck-game-env: PowerVR graphics runtime unavailable (%s)" % error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -17,6 +17,7 @@ PROTON_RUN = os.path.join(BIN, "droiddeck-proton-run")
|
||||
APPIMAGE_RUN = os.path.join(BIN, "droiddeck-appimage-run")
|
||||
SCRIPT_RUN = os.path.join(BIN, "droiddeck-script-run")
|
||||
STEAM_LAUNCH = os.path.join(BIN, "droiddeck-steam-launch")
|
||||
PROGRAMS = os.path.join(BIN, "droiddeck-desktop-programs")
|
||||
CACHE = os.path.join(HOME, ".cache", "droiddeck")
|
||||
IMPORTS = {"appimage": ("/opt/appimages/user", "app"), "folder": ("/opt/droiddeck-apps", "entry")}
|
||||
SHARED_FOLDERS = ("alarms", "android", "audiobooks", "dcim", "documents", "download", "movies", "music",
|
||||
@@ -395,6 +396,11 @@ def main(argv):
|
||||
if status != 0 and time.monotonic() - started < QUICK_FAILURE:
|
||||
notify("%s did not start" % os.path.basename(path),
|
||||
"It exited with status %d; the session's desktop.log says why." % status)
|
||||
if what == "windows":
|
||||
try:
|
||||
subprocess.call([sys.executable, PROGRAMS])
|
||||
except OSError as error:
|
||||
say("%s: %s" % (PROGRAMS, error))
|
||||
return status
|
||||
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ def steam_launch(appid, root):
|
||||
library, install = steam_install(appid, root)
|
||||
if not install or not os.path.isdir(install):
|
||||
return None
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(str(appid), {})
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={str(appid)}).get(str(appid), {})
|
||||
options = [option for option in entry.get("launch_options", ())
|
||||
if not option["betakey"] and (not option["oslist"] or "windows" in option["oslist"])]
|
||||
options.sort(key=lambda option: (option["type"] not in ("", "default", "none"),
|
||||
@@ -376,7 +376,7 @@ def shortcut_target(appid, program, start, root):
|
||||
def steam_launches(target, program, root):
|
||||
if target.kind != "steam":
|
||||
return False
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(target.appid, {})
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={target.appid}).get(target.appid, {})
|
||||
return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ())
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
|
||||
proc[depth] = 1
|
||||
program = tolower(part[4])
|
||||
sub(/.*[\\\/]/, "", program)
|
||||
if (program ~ /vulkan|uplay|ubisoft/) vulkan[depth] = 1
|
||||
if (program ~ /vulkan|uplay|ubisoft|eaapp/) vulkan[depth] = 1
|
||||
next
|
||||
}
|
||||
if (n == 3) pending = part[2]
|
||||
@@ -245,7 +245,7 @@ for system in "${regs[@]}"; do
|
||||
had=()
|
||||
for line in "${kept[@]}"; do had[$line]=1; done
|
||||
printf '%s\n' "${other[@]}" "${kept[@]}" >"$seeded"
|
||||
echo "== took Vulkan runtime and Ubisoft Connect markers out of $reg"
|
||||
echo "== took Vulkan runtime, Ubisoft Connect and EA app markers out of $reg"
|
||||
fi
|
||||
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
|
||||
declare -A held=()
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
# A GPU that is not an Adreno (BL_RAISE_NOFILE=1): the open-files limit goes up to the hard limit
|
||||
# for the whole session tree (gamescope, Steam, games). A Mali PanVK session ran out after ten
|
||||
# minutes ("Too many open files" importing sync files and dma-bufs) and froze.
|
||||
if [ "${BL_RAISE_NOFILE:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
bl_nofile_was="$(ulimit -Sn)/$(ulimit -Hn)"
|
||||
ulimit -Sn "$(ulimit -Hn)" 2>/dev/null || true
|
||||
echo "== open files: soft/hard $bl_nofile_was -> soft $(ulimit -Sn)"
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] && echo "soft/hard $bl_nofile_was -> soft $(ulimit -Sn) (session tree)" > "$BL_DEBUG_DIR/limits.txt" 2>/dev/null
|
||||
unset bl_nofile_was
|
||||
fi
|
||||
export HOME=${HOME:-/root}
|
||||
mode=${1:-desktop}
|
||||
shift || true
|
||||
@@ -22,6 +32,19 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)"
|
||||
fi
|
||||
|
||||
start_diagnostic_inventory() {
|
||||
[ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ] || return 0
|
||||
[ -z "${BL_INSIDE:-}" ] || return 0
|
||||
if ! command -v droiddeck-diagnostic-inventory >/dev/null 2>&1; then
|
||||
printf '%s\n' 'DROIDDECK_PROCESS_TRACE {"schema":1,"event":"provider","status":"unavailable"}'
|
||||
return 0
|
||||
fi
|
||||
droiddeck-diagnostic-inventory --watch --root-pid "$$" &
|
||||
_bl_diagnostic_inventory=$!
|
||||
trap 'kill "$_bl_diagnostic_inventory" 2>/dev/null || true; wait "$_bl_diagnostic_inventory" 2>/dev/null || true' EXIT
|
||||
}
|
||||
start_diagnostic_inventory
|
||||
|
||||
sync_timezone() {
|
||||
local zone=${TZ:-}
|
||||
case "$zone" in ''|/*|*..*) return 0 ;; esac
|
||||
@@ -141,8 +164,13 @@ run_gamescope() (
|
||||
BL_STEAM_EXIT_FILE="$status_file" gamescope "$@"
|
||||
compositor_status=$?
|
||||
if read -r child_status < "$status_file" && [[ $child_status =~ ^[0-9]{1,3}$ ]] \
|
||||
&& [ "$child_status" -gt 0 ] && [ "$child_status" -le 255 ]; then
|
||||
exit "$child_status"
|
||||
&& [ "$child_status" -le 255 ]; then
|
||||
if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=%s\n' "$compositor_status" "$child_status"
|
||||
fi
|
||||
[ "$child_status" -eq 0 ] || exit "$child_status"
|
||||
elif [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=unavailable\n' "$compositor_status"
|
||||
fi
|
||||
exit "$compositor_status"
|
||||
)
|
||||
@@ -160,7 +188,7 @@ collect_steam_logs() {
|
||||
cp "$fex_state/status.json" "$fex_state/config/Config.json" "$BL_DEBUG_DIR/droiddeck-fex/" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
trap 'collect_steam_logs 2>/dev/null || true' TERM INT HUP
|
||||
trap 'bl_stopping=1; collect_steam_logs 2>/dev/null || true' TERM INT HUP
|
||||
if [ -n "${BL_VK_DRIVER:-}" ]; then
|
||||
bl_icd_lib=$(sed -n 's/.*"library_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$BL_VK_DRIVER" 2>/dev/null | head -1)
|
||||
bl_icd_lib=$(printf '%s' "$bl_icd_lib" | sed 's|\\/|/|g')
|
||||
@@ -177,6 +205,143 @@ if [ -n "${BL_VK_DRIVER:-}" ]; then
|
||||
fi
|
||||
unset bl_icd_lib
|
||||
fi
|
||||
bl_webhelper_layout() {
|
||||
if [ -n "${BL_VKBRIDGE_WEBHELPER_ARGS:-}" ]; then
|
||||
printf '%s\n' "$BL_VKBRIDGE_WEBHELPER_ARGS"
|
||||
elif [ -z "${BL_VKBRIDGE_CEF_ANGLE:-}" ]; then
|
||||
echo stock
|
||||
elif [ "$BL_VKBRIDGE_CEF_ANGLE" = vulkan ] && [ "${BL_VKBRIDGE_CEF_VULKAN:-1}" != 0 ]; then
|
||||
echo "--use-gl=angle --use-angle=vulkan +Vulkan +VulkanFromANGLE +DefaultANGLEVulkan"
|
||||
else
|
||||
echo "--use-gl=angle --use-angle=$BL_VKBRIDGE_CEF_ANGLE"
|
||||
fi
|
||||
}
|
||||
bl_now_ms() {
|
||||
if [ -n "${EPOCHREALTIME:-}" ]; then
|
||||
local t=${EPOCHREALTIME/[.,]/}
|
||||
echo $((10#$t / 1000))
|
||||
else
|
||||
date +%s%3N
|
||||
fi
|
||||
}
|
||||
vkbridge_wait_socket() {
|
||||
local sock=$1 limit=${2:-10000} start now waited
|
||||
[ -n "$sock" ] || return 1
|
||||
if [ -S "$sock" ]; then
|
||||
echo "== vkbridge: server socket ready (waited 0 ms)"
|
||||
return 0
|
||||
fi
|
||||
start=$(bl_now_ms)
|
||||
while :; do
|
||||
now=$(bl_now_ms)
|
||||
waited=$((now - start))
|
||||
if [ -S "$sock" ]; then
|
||||
echo "== vkbridge: server socket ready (waited $waited ms; the server listens after its startup probe)"
|
||||
return 0
|
||||
fi
|
||||
if [ -n "${bl_stopping:-}" ]; then
|
||||
echo "== vkbridge: no server socket after $waited ms; the session is stopping"
|
||||
return 1
|
||||
fi
|
||||
if [ "$waited" -ge "$limit" ]; then
|
||||
echo "== vkbridge: no server socket after $waited ms (gave up at $limit ms)"
|
||||
return 1
|
||||
fi
|
||||
sleep 0.05
|
||||
done
|
||||
}
|
||||
if [ "${BL_VKBRIDGE:-0}" = 1 ]; then
|
||||
bl_vkb_icd=/usr/local/share/vkbridge/droidbridge_icd.json
|
||||
[ -z "${BL_INSIDE:-}" ] && vkbridge_wait_socket "${VKBRIDGE_SOCKET:-}" "${BL_VKBRIDGE_WAIT_MS:-10000}"
|
||||
bl_vkb_missing=
|
||||
[ -r "$bl_vkb_icd" ] || bl_vkb_missing="$bl_vkb_missing icd"
|
||||
[ -r /usr/local/lib/vkbridge/libvulkan_droidbridge.so ] || bl_vkb_missing="$bl_vkb_missing library"
|
||||
[ -S "${VKBRIDGE_SOCKET:-}" ] || bl_vkb_missing="$bl_vkb_missing socket"
|
||||
if [ -z "$bl_vkb_missing" ]; then
|
||||
export VK_DRIVER_FILES=$bl_vkb_icd VK_ICD_FILENAMES=$bl_vkb_icd
|
||||
export VKBRIDGE_SOCKET VKBRIDGE_CLIENT_LOG
|
||||
if [ -r /root/.vkbridge-env ]; then
|
||||
while IFS='=' read -r _k _v; do
|
||||
case "$_k" in VKBRIDGE_*|BL_VKBRIDGE_*) export "$_k=$_v" ;; esac
|
||||
done < /root/.vkbridge-env
|
||||
[ -z "${BL_INSIDE:-}" ] && echo "== vkbridge: development settings from /root/.vkbridge-env: $(cut -d= -f1 /root/.vkbridge-env | tr '\n' ' ')"
|
||||
fi
|
||||
export VKD3D_FEATURE_LEVEL=${VKD3D_FEATURE_LEVEL:-12_0}
|
||||
unset TU_DEBUG
|
||||
if [ -z "${BL_INSIDE:-}" ]; then
|
||||
step "vkbridge self-test"
|
||||
bl_vkb_smoke=$(timeout 60 /usr/local/bin/droiddeck-vkbridge-smoke 2>&1)
|
||||
printf '%s\n' "$bl_vkb_smoke" | sed 's/^/== vkbridge: /'
|
||||
bl_vkb_why=
|
||||
if printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL memory sharing'; then
|
||||
bl_vkb_why=memory
|
||||
elif printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL (image clear|draw)'; then
|
||||
bl_vkb_why=draw
|
||||
fi
|
||||
if [ -n "$bl_vkb_why" ] && [ -r "${BL_VKBRIDGE_FALLBACK_ICD:-}" ]; then
|
||||
export VK_DRIVER_FILES=$BL_VKBRIDGE_FALLBACK_ICD VK_ICD_FILENAMES=$BL_VKBRIDGE_FALLBACK_ICD BL_VKBRIDGE=0
|
||||
export BL_OPEN_DRIVER=1 BL_DRM_STANDIN=/dev/mali0
|
||||
[ "${BL_STEAM_GPU_COMPOSITING:-0}" = 1 ] || export BL_STEAM_SOFT_COMPOSITING=1
|
||||
if [ "$bl_vkb_why" = memory ]; then
|
||||
echo "== vkbridge: memory sharing = none (no method passed the server's self-test); this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)"
|
||||
else
|
||||
echo "== vkbridge: self-test failed images or draws; this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)"
|
||||
fi
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] && printf '%s\n%s\n' "$BL_VKBRIDGE_FALLBACK_ICD" "$bl_vkb_why" > "$BL_DEBUG_DIR/vkbridge-fallback" 2>/dev/null
|
||||
elif [ -n "$bl_vkb_why" ]; then
|
||||
echo "== vkbridge: self-test failed ($bl_vkb_why) and no PanVK pair is installed to fall back on; expect a black screen or a lost device - set a Mali driver pair in Setup"
|
||||
fi
|
||||
unset bl_vkb_why
|
||||
unset bl_vkb_smoke
|
||||
if command -v vulkaninfo >/dev/null 2>&1; then
|
||||
timeout 30 vulkaninfo --summary 2>&1 | sed -n '/^Devices:/,$p' | head -40 | sed 's/^/== vulkaninfo: /'
|
||||
fi
|
||||
fi
|
||||
[ "${BL_VKBRIDGE:-0}" = 1 ] && echo "== vulkan driver: Mali bridge ($bl_vkb_icd, server at $VKBRIDGE_SOCKET)"
|
||||
else
|
||||
echo "== vulkan driver: Mali bridge requested but NOT usable (icd $bl_vkb_icd, socket ${VKBRIDGE_SOCKET:-unset}; missing:$bl_vkb_missing)"
|
||||
[ -n "${BL_INSIDE:-}" ] || exit 69
|
||||
fi
|
||||
unset bl_vkb_icd bl_vkb_missing
|
||||
fi
|
||||
if [ "${BL_VENUS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && command -v vulkaninfo >/dev/null 2>&1; then
|
||||
if bl_vn_info=$(timeout 30 vulkaninfo 2>/dev/null); then
|
||||
case $(printf '%s\n' "$bl_vn_info" | grep -m1 'nullDescriptor') in
|
||||
*true*) echo "== venus: nullDescriptor present (Zink keeps the GPU)" ;;
|
||||
*)
|
||||
export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2
|
||||
echo "== venus: no nullDescriptor on this device even with the Mali compatibility layer; Steam's GL and Xwayland use llvmpipe (software)"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "== venus: vulkaninfo failed or timed out; GL left on Zink"
|
||||
fi
|
||||
unset bl_vn_info
|
||||
fi
|
||||
if [ "${BL_GAME_LOGS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
(
|
||||
{
|
||||
echo "== VK_DRIVER_FILES=${VK_DRIVER_FILES:-} VK_ICD_FILENAMES=${VK_ICD_FILENAMES:-} BL_DRM_STANDIN=${BL_DRM_STANDIN:-}"
|
||||
if command -v vulkaninfo >/dev/null 2>&1; then
|
||||
timeout 10 vulkaninfo --summary
|
||||
echo "== vulkaninfo exit: $?"
|
||||
if timeout 20 vulkaninfo > "$BL_DEBUG_DIR/vulkan-full.txt" 2>&1; then
|
||||
echo "== device extensions (full list in vulkan-full.txt):"
|
||||
sed -n '/^Device Extensions:/,/^$/p' "$BL_DEBUG_DIR/vulkan-full.txt" | grep -o 'VK_[A-Za-z0-9_]*' | sort -u | tr '\n' ' ' | fold -s -w 200
|
||||
echo
|
||||
echo "== key features:"
|
||||
grep -E '^[[:space:]]+(robustBufferAccess2?|robustImageAccess2?|nullDescriptor|logicOp|fillModeNonSolid|shaderClipDistance|shaderCullDistance|dualSrcBlend|geometryShader|scalarBlockLayout|timelineSemaphore|dynamicRendering|synchronization2|maintenance4|maintenance5|maintenance6|shaderDrawParameters|descriptorIndexing|bufferDeviceAddress|vulkanMemoryModel|hostQueryReset|imagelessFramebuffer|samplerYcbcrConversion|shaderInt64|shaderFloat64|shaderInt16|shaderFloat16|storageBuffer16BitAccess|extendedDynamicState[23]?|vertexInputDynamicState|customBorderColors|customBorderColorWithoutFormat|depthClipEnable|multiViewport|textureCompressionBC|indexTypeUint8|rectangularLines|bresenhamLines|transformFeedback|geometryStreams|graphicsPipelineLibrary|pushDescriptor|primitiveTopologyListRestart|dynamicRenderingLocalRead|shaderDemoteToHelperInvocation|subgroupSizeControl|computeFullSubgroups|inlineUniformBlock|pipelineCreationCacheControl) = ' "$BL_DEBUG_DIR/vulkan-full.txt" | sed 's/^[[:space:]]*/ /' | sort -u
|
||||
else
|
||||
echo "== full vulkaninfo failed or timed out (exit $?)"
|
||||
fi
|
||||
else
|
||||
echo "== vulkaninfo is not in this runtime; GPU nodes:"
|
||||
ls -l /dev/kgsl-3d0 /dev/mali0 /dev/dri 2>&1
|
||||
fi
|
||||
} > "$BL_DEBUG_DIR/vulkan-summary.txt" 2>&1
|
||||
) &
|
||||
fi
|
||||
export GAMESCOPE_FORCE_VULKAN_REALTIME=${BL_GAMESCOPE_REALTIME:-0}
|
||||
rm -rf /tmp/.droiddeck-rx
|
||||
|
||||
@@ -189,6 +354,38 @@ nap() {
|
||||
[ -n "${bl_nap_fd:-}" ] || exec {bl_nap_fd}<> <(:)
|
||||
read -r -t "$1" -u "$bl_nap_fd" _ 2>/dev/null || :
|
||||
}
|
||||
# Which program a driver error came from: Mesa's lines ("radv/amdgpu: The CS has been rejected",
|
||||
# "ZINK: vkQueueWaitIdle failed") carry no process name. For the first three minutes of an open
|
||||
# driver pair's session, every process that appears goes into processes.txt with the session log's
|
||||
# line count at that moment, so an error's line number in session.log points at what had just
|
||||
# started. Pure bash over /proc (no execs: see nap).
|
||||
watch_processes() {
|
||||
local out=$BL_DEBUG_DIR/processes.txt log=$BL_DEBUG_DIR/session.log i p pid comm lines
|
||||
local -a argv new
|
||||
local -A seen=()
|
||||
echo "# seconds session.log-lines pid name command line" > "$out" 2>/dev/null || return 0
|
||||
for ((i = 0; i < 360; i++)); do
|
||||
new=()
|
||||
for p in /proc/[0-9]*; do
|
||||
pid=${p#/proc/}
|
||||
[ -n "${seen[$pid]:-}" ] && continue
|
||||
seen[$pid]=1
|
||||
read -r comm < "$p/comm" 2>/dev/null || continue
|
||||
argv=()
|
||||
mapfile -d '' -t argv < "$p/cmdline" 2>/dev/null
|
||||
new+=("$pid"$'\t'"$comm"$'\t'"${argv[*]:0:8}")
|
||||
done
|
||||
if [ ${#new[@]} -gt 0 ]; then
|
||||
lines=0
|
||||
[ -r "$log" ] && { mapfile -t argv < "$log"; lines=${#argv[@]}; argv=(); }
|
||||
for p in "${new[@]}"; do printf '%s\t%s\t%.200s\n' "$SECONDS" "$lines" "$p"; done >> "$out"
|
||||
fi
|
||||
nap 0.5
|
||||
done
|
||||
}
|
||||
if [ "${BL_OPEN_DRIVER:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
watch_processes &
|
||||
fi
|
||||
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
||||
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
|
||||
@@ -222,6 +419,7 @@ program_cores() {
|
||||
[ "${BL_PIN_CORES:-1}" = 0 ] && return 0
|
||||
command -v taskset >/dev/null 2>&1 || return 0
|
||||
if [ -n "${BL_GAME_CPUS:-}" ]; then echo "$BL_GAME_CPUS"; return 0; fi
|
||||
[ "$mode" = run ] && return 0
|
||||
local f n max min= list=
|
||||
for f in /sys/devices/system/cpu/cpu[0-9]*/cpufreq/cpuinfo_max_freq; do
|
||||
max=$(cat "$f" 2>/dev/null) || continue
|
||||
@@ -305,10 +503,23 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
backend=${BL_GAMESCOPE_BACKEND:-wayland}
|
||||
case "$backend" in
|
||||
wayland) ;;
|
||||
sdl) export SDL_VIDEODRIVER=wayland ;;
|
||||
*) echo "== unsupported gamescope backend: $backend"; exit 64 ;;
|
||||
esac
|
||||
if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then
|
||||
export gamescope_cursor_composite=2
|
||||
fi
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
# Through the Mali bridge, Steam's UI flickered while gamescope handed its layers to the phone's
|
||||
# compositor as separate planes, for a reason not yet found; one composited image does not
|
||||
# (Mali-G76 MC4: 145 footer flips in 6 s at rest, 0 composited).
|
||||
if [ "$mode" = steam ] && [ "${BL_VKBRIDGE:-0}" = 1 ] && [ -z "${gamescope_composite_force:-}" ]; then
|
||||
export gamescope_composite_force=1
|
||||
echo "== gamescope: composites every frame (Mali bridge: the Steam UI flickers on separate planes)"
|
||||
fi
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
args+=(-S stretch)
|
||||
export BL_STRETCHED=1
|
||||
@@ -609,8 +820,75 @@ case $mode in
|
||||
done 2>/dev/null < "/proc/$_p/status"
|
||||
done
|
||||
_bl_rss=$_rss
|
||||
_bl_swap=$_swap
|
||||
echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
}
|
||||
bl_memory_read() {
|
||||
local _k _v _u _kind _fields _avg
|
||||
_bl_mem_total=0 _bl_available=-1 _bl_swap_total=0 _bl_swap_free=-1 _bl_psi=0
|
||||
while read -r _k _v _u; do
|
||||
case $_v in ''|*[!0-9]*) continue ;; esac
|
||||
case $_k in
|
||||
MemTotal:) _bl_mem_total=$_v ;;
|
||||
MemAvailable:) _bl_available=$_v ;;
|
||||
SwapTotal:) _bl_swap_total=$_v ;;
|
||||
SwapFree:) _bl_swap_free=$_v ;;
|
||||
esac
|
||||
done 2>/dev/null < /proc/meminfo
|
||||
if [ -r /proc/pressure/memory ]; then
|
||||
while read -r _kind _fields; do
|
||||
[ "$_kind" = some ] || continue
|
||||
_avg=${_fields#avg10=} _avg=${_avg%% *} _avg=${_avg%%.*}
|
||||
case $_avg in ''|*[!0-9]*) ;; *) _bl_psi=$((10#$_avg)) ;; esac
|
||||
done 2>/dev/null < /proc/pressure/memory
|
||||
fi
|
||||
_bl_headroom=$((_bl_mem_total / 5))
|
||||
[ "$_bl_headroom" -ge $((512 * 1024)) ] || _bl_headroom=$((512 * 1024))
|
||||
[ "$_bl_headroom" -le $((1536 * 1024)) ] || _bl_headroom=$((1536 * 1024))
|
||||
_bl_swap_reserve=$((_bl_swap_total / 5))
|
||||
[ "$_bl_swap_reserve" -ge $((256 * 1024)) ] || _bl_swap_reserve=$((256 * 1024))
|
||||
}
|
||||
bl_memory_tight() {
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_available" -ge 0 ] &&
|
||||
{ [ "$_bl_available" -lt "$_bl_headroom" ] ||
|
||||
{ [ "$_bl_psi" -ge 1 ] && [ "$_bl_available" -lt $((_bl_mem_total / 3)) ]; }; }
|
||||
}
|
||||
bl_client_can_pageout() {
|
||||
bl_memory_read
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_swap_total" -gt 0 ] &&
|
||||
[ $((_bl_swap_free - _bl_rss)) -ge "$_bl_swap_reserve" ]
|
||||
}
|
||||
bl_client_can_readback() {
|
||||
bl_memory_read
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
[ "$_bl_mem_total" -gt 0 ] && ! bl_memory_tight &&
|
||||
[ "$_bl_available" -ge $((_bl_swap * 2)) ] &&
|
||||
[ $((_bl_available - _bl_swap)) -ge "$_bl_headroom" ]
|
||||
}
|
||||
bl_client_pressure() {
|
||||
[ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ "$_bl_game" = 1 ] &&
|
||||
[ "${#_bl_pids[@]}" -gt 0 ] && bl_memory_tight || return 0
|
||||
[ "$_bl_pressure_at" -lt 0 ] ||
|
||||
[ $((SECONDS - _bl_pressure_at)) -ge "$_bl_pressure_backoff" ] || return 0
|
||||
[ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 30 ] || return 0
|
||||
_bl_pressure_at=$SECONDS
|
||||
if ! bl_client_can_pageout; then
|
||||
step "zRAM: pressure reclaim skipped, swap headroom too small ($((_bl_swap_free / 1024)) MB free)"
|
||||
return 0
|
||||
fi
|
||||
[ "$_bl_rss" -ge $((128 * 1024)) ] || return 0
|
||||
local _before=$_bl_rss
|
||||
bl_zram_send 1 "memory pressure, compressing the client (available $((_bl_available / 1024)) MB, swap free $((_bl_swap_free / 1024)) MB)" client
|
||||
_bl_packed=$SECONDS
|
||||
[ "${_bl_pageout_complete:-0}" = 1 ] || return 0
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
if [ $((_before - _bl_rss)) -lt $((16 * 1024)) ]; then
|
||||
_bl_pressure_backoff=$((_bl_pressure_backoff * 2 > 300 ? 300 : _bl_pressure_backoff * 2))
|
||||
else
|
||||
_bl_pressure_backoff=30
|
||||
fi
|
||||
}
|
||||
bl_session_others() {
|
||||
local _p
|
||||
_bl_session=()
|
||||
@@ -639,7 +917,11 @@ case $mode in
|
||||
[ "$_left" = 1 ] || break
|
||||
nap 0.2
|
||||
done
|
||||
for _p in "$@"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
_bl_pageout_complete=1
|
||||
for _p in "$@"; do
|
||||
if [ -d "/proc/$_p" ] && [ ! -s "/tmp/.bl-zram.ack.$_p" ]; then _bl_pageout_complete=0; fi
|
||||
rm -f "/tmp/.bl-zram.ack.$_p"
|
||||
done
|
||||
}
|
||||
bl_zram_send() {
|
||||
local _mode=$1 _what=$2 _which=$3 _pids _p
|
||||
@@ -677,8 +959,10 @@ case $mode in
|
||||
[ "$_bl_ram_cap" -gt 0 ] && { [ "$_bl_measured" -lt 0 ] || [ $((SECONDS - _bl_measured)) -ge 30 ]; }
|
||||
}
|
||||
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
|
||||
_bl_pressure_at=-1 _bl_pressure_backoff=30
|
||||
while kill -0 $$ 2>/dev/null; do
|
||||
bl_zram_scan
|
||||
bl_memory_read
|
||||
if bl_cap_due; then
|
||||
if bl_over_cap; then
|
||||
if [ "$_bl_capped" -lt 0 ] || [ $((SECONDS - _bl_capped)) -ge "$_bl_backoff" ]; then
|
||||
@@ -700,29 +984,30 @@ case $mode in
|
||||
fi
|
||||
else
|
||||
_bl_backoff=30
|
||||
if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ]; then
|
||||
bl_zram_send 0 "back under the RAM cap, reading the client back" client
|
||||
_bl_unpack=0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
bl_client_pressure
|
||||
if [ "$_bl_game" = 1 ] && bl_game_focused; then
|
||||
if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then
|
||||
_bl_since=$SECONDS _bl_since_apps=$_bl_apps
|
||||
fi
|
||||
if [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
{ [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; }; then
|
||||
{ [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; } && bl_client_can_pageout; then
|
||||
bl_zram_send 1 "compressing the client" client
|
||||
_bl_packed=$SECONDS
|
||||
fi
|
||||
elif [ "$_bl_game" != 1 ]; then
|
||||
if [ "$_bl_packed" -ge 0 ]; then
|
||||
if bl_over_cap; then _bl_unpack=1; else bl_zram_send 0 "game closed, reading the client back" client; _bl_unpack=0; fi
|
||||
_bl_unpack=1
|
||||
fi
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
else
|
||||
_bl_since=-1
|
||||
fi
|
||||
if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ] && ! bl_over_cap && bl_client_can_readback; then
|
||||
bl_zram_send 0 "memory recovered, reading the client back" client
|
||||
_bl_unpack=0
|
||||
fi
|
||||
nap 5
|
||||
done
|
||||
) &
|
||||
@@ -973,6 +1258,20 @@ case $mode in
|
||||
export STEAM_STEAMRT_RECURSION_GUARD=1
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
||||
bl_steam_path=$PATH
|
||||
bl_steam_angle=vulkan
|
||||
bl_steam_presentation=()
|
||||
if [ "${BL_STEAM_GL_PRESENT:-}" = 1 ]; then
|
||||
bl_steam_path="/usr/local/libexec/droiddeck-steam:$PATH"
|
||||
export DISABLE_GAMESCOPE_WSI=1 LIBGL_KOPPER_DISABLE=true
|
||||
bl_steam_angle=gl
|
||||
bl_steam_presentation=(-cef-disable-gpu-compositing)
|
||||
echo "== steam: system PowerVR uses OpenGL/DRI3 through Zink with software CEF compositing"
|
||||
elif [ "${BL_STEAM_SOFT_COMPOSITING:-}" = 1 ]; then
|
||||
bl_steam_presentation=(-cef-disable-gpu-compositing)
|
||||
echo "== steam: open driver pair - software CEF compositing, GPU raster"
|
||||
fi
|
||||
_bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=$bl_steam_angle")
|
||||
decky_loader=$HOME/homebrew/services/PluginLoader
|
||||
if [ -f "$HOME/.droiddeck-decky-enabled" ] && [ -x "$decky_loader" ]; then
|
||||
decky_arch=$(cat "$HOME/homebrew/services/.droiddeck-decky-arch" 2>/dev/null || echo unknown)
|
||||
@@ -1022,12 +1321,36 @@ case $mode in
|
||||
fi
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan)
|
||||
# bl_steam_angle / bl_steam_presentation (set above) default to the Adreno values (vulkan,
|
||||
# none); only the system-PowerVR path (BL_STEAM_GL_PRESENT=1) changes them.
|
||||
_bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=${bl_steam_angle:-vulkan}")
|
||||
[ "${steam_cef_gpu:-1}" = 1 ] || _bl_cef=(-cef-disable-gpu)
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] && [ "${BL_STEAM_UI:-}" = desktop ]; then
|
||||
_bl_cef=(-cef-disable-gpu)
|
||||
_bl_ui=(-nobigpicture)
|
||||
fi
|
||||
if [ "${BL_VKBRIDGE:-0}" = 1 ]; then
|
||||
# On the GPU the Steam UI held about 400 MB through the bridge (Mali-G76 MC4, 3 GB of RAM); with
|
||||
# a game loading beside it, Android's low-memory killer took the whole session down.
|
||||
if [ -z "${BL_VKBRIDGE_CEF_GPU:-}" ]; then
|
||||
_bl_mem_kb=$(awk '/^MemTotal:/ {print $2}' /proc/meminfo 2>/dev/null)
|
||||
if [ "${_bl_mem_kb:-0}" -gt 0 ] && [ "$_bl_mem_kb" -lt 4194304 ]; then
|
||||
BL_VKBRIDGE_CEF_GPU=0
|
||||
echo "== steam: $((_bl_mem_kb / 1024)) MB of RAM: the browser UI draws in software to leave games the memory"
|
||||
fi
|
||||
fi
|
||||
if [ "${BL_VKBRIDGE_CEF_GPU:-1}" = 0 ]; then
|
||||
_bl_cef=(-cef-disable-gpu -cef-disable-gpu-compositing)
|
||||
echo "== steam: browser UI in software (Mali bridge)"
|
||||
elif [ "${_bl_cef[0]}" = -cef-force-gpu ]; then
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle="${BL_VKBRIDGE_CEF_ANGLE:-vulkan}")
|
||||
fi
|
||||
[ "${BL_VKBRIDGE_CEF_LOG:-0}" = 1 ] && _bl_cef+=(-cef-enable-logging=stderr -cef-v=1)
|
||||
[ -n "${BL_VKBRIDGE_CEF_EXTRA:-}" ] && read -r -a _bl_cef_extra <<<"$BL_VKBRIDGE_CEF_EXTRA" && _bl_cef+=("${_bl_cef_extra[@]}")
|
||||
BL_WEBHELPER_ARGS=$(bl_webhelper_layout)
|
||||
export BL_WEBHELPER_ARGS
|
||||
echo "== steam: web helper process layout: $BL_WEBHELPER_ARGS (Mali bridge)"
|
||||
fi
|
||||
if [ "${BL_STEAM_UI:-}" != desktop ]; then
|
||||
if [ "$steam_x64" = 0 ] || [ "${BL_X64_DECK:-1}" != 0 ]; then
|
||||
_bl_ui+=(-steamdeck -steamos3)
|
||||
@@ -1353,6 +1676,36 @@ case $mode in
|
||||
done
|
||||
) &
|
||||
stop_watcher=$!
|
||||
if [ "${BL_VENUS:-0}" = 1 ] && [ -x /usr/local/bin/droiddeck-glprobe ] && [ "${GALLIUM_DRIVER:-}" = zink ]; then
|
||||
LIBGL_DEBUG=verbose MESA_LOG_LEVEL=debug timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -60 | sed 's/^/== glprobe: /'
|
||||
if [ "${PIPESTATUS[0]}" = 1 ]; then
|
||||
VK_LOADER_DEBUG=error,warn timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -40 | sed 's/^/== glprobe (loader): /'
|
||||
DROIDDECK_MALI_COMPAT_TRACE=1 MESA_DEBUG=1 MESA_LOG_LEVEL=debug LIBGL_DEBUG=verbose ZINK_DEBUG=mem VN_DEBUG=init,result,log_ctx_info \
|
||||
timeout 30 /usr/local/bin/droiddeck-glprobe > "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" 2>&1
|
||||
grep -v drirc "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | head -120 | sed 's/^/== glprobe (trace): /'
|
||||
echo "== glprobe (trace): last pre-device query before Zink gave up: $(grep 'droiddeck-mali-compat: trace:' "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | grep -v 'trace: extensions:' | tail -1)"
|
||||
command -v vulkaninfo >/dev/null 2>&1 && DROIDDECK_MALI_COMPAT_TRACE=1 timeout 20 vulkaninfo --summary 2>&1 | head -40 | sed 's/^/== glprobe (vulkaninfo): /'
|
||||
bl_gl_ok=
|
||||
for bl_variant in "ZINK_DEBUG=" "ZINK_DEBUG= ZINK_DESCRIPTORS=auto" "ZINK_DEBUG= LIBGL_KOPPER_DISABLE=true" "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0"; do
|
||||
if env $bl_variant timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -20 | sed "s/^/== glprobe ($bl_variant): /"; [ "${PIPESTATUS[0]}" = 0 ]; then
|
||||
bl_gl_ok=$bl_variant
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -n "$bl_gl_ok" ] && [ "$bl_gl_ok" != "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0" ]; then
|
||||
for bl_kv in $bl_gl_ok; do
|
||||
case $bl_kv in *=) unset "${bl_kv%=}" ;; *) export "$bl_kv" ;; esac
|
||||
done
|
||||
echo "== venus: GL through Zink starts with: $bl_gl_ok (the Steam client gets that)"
|
||||
else
|
||||
[ -n "$bl_gl_ok" ] && echo "== venus: Zink starts only without the Mali compatibility layer (then without nullDescriptor); not used"
|
||||
export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2
|
||||
echo "== venus: GL through Zink did not start (see glprobe above); the Steam client's GL uses llvmpipe (software)"
|
||||
fi
|
||||
unset bl_gl_ok bl_variant bl_kv
|
||||
fi
|
||||
fi
|
||||
rm -f "$HOME/.bl-restart-game" "$HOME/.bl-restarted-for"
|
||||
while :; do
|
||||
rm -f "$HOME/.bl-restart-once" "$HOME/.bl-restart-lost"
|
||||
@@ -1378,6 +1731,8 @@ case $mode in
|
||||
desktop_ui_pid=$!
|
||||
fi
|
||||
steam_started=$SECONDS
|
||||
PATH="$bl_steam_path" \
|
||||
BL_STEAM_WEBHELPER="$steam_root/steamrtarm64/steamwebhelper" \
|
||||
"${steam_client[@]}" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \
|
||||
-no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@"
|
||||
rc=$?
|
||||
@@ -1387,6 +1742,9 @@ case $mode in
|
||||
wait "$desktop_ui_pid" 2>/dev/null || true
|
||||
fi
|
||||
echo "== steam exited rc=$rc"
|
||||
if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=steam_exit shell_status=%s elapsed_seconds=%s\n' "$rc" "$steam_ran"
|
||||
fi
|
||||
collect_steam_logs
|
||||
if [ -f "$HOME/.config/droiddeck/fex-wanted" ] && [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
/usr/local/bin/droiddeck-fex status >/dev/null 2>&1 || true
|
||||
|
||||
@@ -317,6 +317,74 @@ FRAME_LIMIT_JS = r"""
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
WINDOW_BINDING = "droiddeckWindowAction"
|
||||
WINDOW_TARGET = "createflags=18"
|
||||
WINDOW_MOVES = {"nw": 0, "n": 1, "ne": 2, "e": 3, "se": 4, "s": 5, "sw": 6, "w": 7, "move": 8}
|
||||
WINDOW_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckWindow) return "present";
|
||||
const EDGE = 5, CORNER = 10, THRESHOLD = 3;
|
||||
const CURSORS = { n: "ns-resize", s: "ns-resize", e: "ew-resize", w: "ew-resize",
|
||||
ne: "nesw-resize", sw: "nesw-resize", nw: "nwse-resize", se: "nwse-resize" };
|
||||
const send = action => window.droiddeckWindowAction(action);
|
||||
const filled = () => innerWidth >= screen.availWidth && innerHeight >= screen.availHeight - 60;
|
||||
const side = e => {
|
||||
if (filled()) return "";
|
||||
const right = innerWidth - e.clientX, bottom = innerHeight - e.clientY;
|
||||
const near = (a, b) => a < EDGE || (a < CORNER && b < CORNER);
|
||||
const across = Math.min(e.clientX, right), along = Math.min(e.clientY, bottom);
|
||||
const v = near(e.clientY, across) ? "n" : near(bottom, across) ? "s" : "";
|
||||
const h = near(e.clientX, along) ? "w" : near(right, along) ? "e" : "";
|
||||
return v + h;
|
||||
};
|
||||
const dragging = (x, y) => {
|
||||
for (const node of document.elementsFromPoint(x, y)) {
|
||||
const region = getComputedStyle(node).webkitAppRegion;
|
||||
if (region === "drag") return true;
|
||||
if (region === "no-drag") return false;
|
||||
}
|
||||
return [...document.querySelectorAll("*")].some(node => {
|
||||
if (getComputedStyle(node).webkitAppRegion !== "drag") return false;
|
||||
const box = node.getBoundingClientRect();
|
||||
return x >= box.left && x < box.right && y >= box.top && y < box.bottom;
|
||||
});
|
||||
};
|
||||
const style = document.createElement("style");
|
||||
document.documentElement.append(style);
|
||||
let press = null, shown = "";
|
||||
addEventListener("pointermove", e => {
|
||||
if (press) {
|
||||
if (Math.hypot(e.clientX - press.x, e.clientY - press.y) >= THRESHOLD) {
|
||||
const hit = dragging(press.x, press.y);
|
||||
press = null;
|
||||
if (hit) send("move");
|
||||
}
|
||||
return;
|
||||
}
|
||||
const cursor = e.buttons ? shown : side(e);
|
||||
if (cursor !== shown) {
|
||||
shown = cursor;
|
||||
style.textContent = cursor ? `* { cursor: ${CURSORS[cursor]} !important; }` : "";
|
||||
}
|
||||
}, true);
|
||||
addEventListener("pointerdown", e => {
|
||||
if (e.button !== 0) return;
|
||||
const edge = side(e);
|
||||
if (edge) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
send(edge);
|
||||
} else {
|
||||
press = { x: e.clientX, y: e.clientY };
|
||||
}
|
||||
}, true);
|
||||
addEventListener("pointerup", () => { press = null; }, true);
|
||||
addEventListener("dblclick", e => { if (dragging(e.clientX, e.clientY) && !side(e)) send("maximize"); }, true);
|
||||
SteamClient.Window.ToggleMaximize = () => send("maximize");
|
||||
window.__droiddeckWindow = true;
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
FILE_BINDING = "droiddeckOpenFileDialog"
|
||||
FILE_JS = r"""
|
||||
(() => {
|
||||
@@ -739,6 +807,71 @@ class Watcher:
|
||||
return any(n in wanted or n.startswith("appmanifest_") for n in names)
|
||||
|
||||
|
||||
class XMessage(ctypes.Structure):
|
||||
_fields_ = [("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int),
|
||||
("display", ctypes.c_void_p), ("window", ctypes.c_ulong), ("message_type", ctypes.c_ulong),
|
||||
("format", ctypes.c_int), ("data", ctypes.c_long * 5), ("pad", ctypes.c_long * 20)]
|
||||
|
||||
|
||||
X_ERRORS = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)(lambda display, error: 0)
|
||||
|
||||
|
||||
def window_action(action):
|
||||
if action != "maximize" and action not in WINDOW_MOVES:
|
||||
return False
|
||||
x11 = ctypes.CDLL("libX11.so.6")
|
||||
x11.XOpenDisplay.restype = ctypes.c_void_p
|
||||
x11.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
x11.XDefaultRootWindow.restype = ctypes.c_ulong
|
||||
x11.XDefaultRootWindow.argtypes = [ctypes.c_void_p]
|
||||
x11.XInternAtom.restype = ctypes.c_ulong
|
||||
x11.XInternAtom.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]
|
||||
x11.XGetWindowProperty.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_long, ctypes.c_long,
|
||||
ctypes.c_int, ctypes.c_ulong] + [ctypes.c_void_p] * 5
|
||||
x11.XQueryPointer.argtypes = [ctypes.c_void_p, ctypes.c_ulong] + [ctypes.c_void_p] * 7
|
||||
x11.XSendEvent.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_long, ctypes.c_void_p]
|
||||
x11.XFree.argtypes = [ctypes.c_void_p]
|
||||
x11.XFlush.argtypes = [ctypes.c_void_p]
|
||||
x11.XCloseDisplay.argtypes = [ctypes.c_void_p]
|
||||
x11.XSetErrorHandler(X_ERRORS)
|
||||
display = x11.XOpenDisplay(None)
|
||||
if not display:
|
||||
return False
|
||||
try:
|
||||
root = x11.XDefaultRootWindow(display)
|
||||
atom = lambda name: x11.XInternAtom(display, name, 0)
|
||||
kind, width, count, after = ctypes.c_ulong(), ctypes.c_int(), ctypes.c_ulong(), ctypes.c_ulong()
|
||||
data = ctypes.c_void_p()
|
||||
if x11.XGetWindowProperty(display, root, atom(b"_NET_ACTIVE_WINDOW"), 0, 1, 0, 33, ctypes.byref(kind),
|
||||
ctypes.byref(width), ctypes.byref(count), ctypes.byref(after),
|
||||
ctypes.byref(data)) != 0 or not data.value:
|
||||
return False
|
||||
window = ctypes.cast(data, ctypes.POINTER(ctypes.c_ulong))[0] if count.value else 0
|
||||
x11.XFree(data)
|
||||
if not window:
|
||||
return False
|
||||
if action == "maximize":
|
||||
kind_name = b"_NET_WM_STATE"
|
||||
values = [2, atom(b"_NET_WM_STATE_MAXIMIZED_VERT"), atom(b"_NET_WM_STATE_MAXIMIZED_HORZ"), 1, 0]
|
||||
else:
|
||||
ignored = ctypes.c_ulong()
|
||||
x, y, inner, mask = ctypes.c_int(), ctypes.c_int(), ctypes.c_int(), ctypes.c_uint()
|
||||
if not x11.XQueryPointer(display, root, ctypes.byref(ignored), ctypes.byref(ignored), ctypes.byref(x),
|
||||
ctypes.byref(y), ctypes.byref(inner), ctypes.byref(inner), ctypes.byref(mask)):
|
||||
return False
|
||||
if not mask.value & 0x100:
|
||||
return False
|
||||
kind_name = b"_NET_WM_MOVERESIZE"
|
||||
values = [x.value, y.value, WINDOW_MOVES[action], 1, 1]
|
||||
message = XMessage(type=33, window=window, message_type=atom(kind_name), format=32)
|
||||
message.data[:] = values
|
||||
sent = x11.XSendEvent(display, root, 0, (1 << 19) | (1 << 20), ctypes.byref(message))
|
||||
x11.XFlush(display)
|
||||
return bool(sent)
|
||||
finally:
|
||||
x11.XCloseDisplay(display)
|
||||
|
||||
|
||||
class Helper:
|
||||
def __init__(self, steam_root, port, steamos=False, files_only=False):
|
||||
self.steam_root = steam_root
|
||||
@@ -757,6 +890,8 @@ class Helper:
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
self.windows = {}
|
||||
self.windows_retry = 0
|
||||
|
||||
def sync_controls(self):
|
||||
try:
|
||||
@@ -780,6 +915,41 @@ class Helper:
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def sync_windows(self):
|
||||
if os.environ.get("XDG_CURRENT_DESKTOP") != "KDE":
|
||||
return
|
||||
if time.monotonic() >= self.windows_retry:
|
||||
self.windows_retry = time.monotonic() + 2
|
||||
try:
|
||||
targets = http_get(self.port, "/json/list")
|
||||
except (OSError, ValueError):
|
||||
targets = []
|
||||
seen = set()
|
||||
for target in targets:
|
||||
url = target.get("webSocketDebuggerUrl")
|
||||
if WINDOW_TARGET not in target.get("url", "").split("&")[0] or not url:
|
||||
continue
|
||||
seen.add(target.get("id"))
|
||||
try:
|
||||
page = self.windows.get(target.get("id"))
|
||||
if page is None:
|
||||
page = Page(self.port, "/" + url.split("/", 3)[3])
|
||||
page.call("Runtime.addBinding", {"name": WINDOW_BINDING}, timeout=5)
|
||||
self.windows[target.get("id")] = page
|
||||
page.evaluate(WINDOW_JS, timeout=5)
|
||||
except (Closed, OSError, RuntimeError, ValueError) as e:
|
||||
say("window controls: %s" % e)
|
||||
self.windows.pop(target.get("id"), None)
|
||||
for ident in set(self.windows) - seen:
|
||||
del self.windows[ident]
|
||||
for ident, page in list(self.windows.items()):
|
||||
try:
|
||||
for event in page.drain():
|
||||
if called(event, WINDOW_BINDING):
|
||||
window_action(event.get("params", {}).get("payload"))
|
||||
except (Closed, OSError, ValueError):
|
||||
del self.windows[ident]
|
||||
|
||||
def sync_frame_limit(self):
|
||||
if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry:
|
||||
return
|
||||
@@ -1025,7 +1195,9 @@ class Helper:
|
||||
say("attached to the client on port %d for its file dialogs" % self.port)
|
||||
while True:
|
||||
self.sync_controls()
|
||||
self.sync_windows()
|
||||
sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else [])
|
||||
sources += [page.ws for page in self.windows.values()]
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
@@ -1044,7 +1216,9 @@ class Helper:
|
||||
while True:
|
||||
self.sync_controls()
|
||||
self.sync_frame_limit()
|
||||
self.sync_windows()
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
sources += [page.ws for page in self.windows.values()]
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
|
||||
@@ -11,6 +11,7 @@ import time
|
||||
import unicodedata
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import zlib
|
||||
|
||||
STATE = ".droiddeck-games.json"
|
||||
TRIED = ".droiddeck-import-tried.json"
|
||||
@@ -301,15 +302,76 @@ def installed_build(folder, appid, installdir):
|
||||
if not (folder / ".download_complete").is_file():
|
||||
return None
|
||||
try:
|
||||
ids = json.loads((folder / ".DepotDownloader/depot.config").read_text())["installedManifestIDs"]
|
||||
depots = sorted((int(depot), int(gid)) for depot, gid in ids.items())
|
||||
except (OSError, ValueError, KeyError, TypeError, AttributeError):
|
||||
return None
|
||||
depots = config_depots((folder / ".DepotDownloader/depot.config").read_bytes())
|
||||
except OSError:
|
||||
depots = None
|
||||
if not depots:
|
||||
depots = completed_depots(folder / ".DepotDownloader/completed")
|
||||
if not depots or not all(0 < depot < 0x80000000 and 0 < gid < 0x7FFFFFFFFFFFFFFF for depot, gid in depots):
|
||||
return None
|
||||
return "".join(f' "{depot}"\n {{\n "manifest" "{gid}"\n }}\n' for depot, gid in depots)
|
||||
|
||||
|
||||
def varint(data, i):
|
||||
value = shift = 0
|
||||
while True:
|
||||
byte = data[i]
|
||||
i += 1
|
||||
value |= (byte & 0x7F) << shift
|
||||
shift += 7
|
||||
if byte < 0x80:
|
||||
return value, i
|
||||
|
||||
|
||||
def proto_fields(data):
|
||||
i = 0
|
||||
while i < len(data):
|
||||
key, i = varint(data, i)
|
||||
kind = key & 7
|
||||
if kind == 0:
|
||||
value, i = varint(data, i)
|
||||
elif kind == 2:
|
||||
size, i = varint(data, i)
|
||||
value, i = data[i:i + size], i + size
|
||||
elif kind in (1, 5):
|
||||
value, i = None, i + (8 if kind == 1 else 4)
|
||||
else:
|
||||
raise ValueError
|
||||
yield key >> 3, kind, value
|
||||
|
||||
|
||||
def config_depots(data):
|
||||
try:
|
||||
ids = json.loads(data.decode())["installedManifestIDs"]
|
||||
return sorted((int(depot), int(gid)) for depot, gid in ids.items())
|
||||
except (ValueError, KeyError, TypeError, AttributeError):
|
||||
pass
|
||||
try:
|
||||
depots = {}
|
||||
for number, kind, entry in proto_fields(zlib.decompress(data, -15)):
|
||||
if number == 1 and kind == 2:
|
||||
fields = {n: v for n, k, v in proto_fields(entry) if k == 0}
|
||||
if 1 in fields and 2 in fields:
|
||||
depots[fields[1]] = fields[2]
|
||||
return sorted(depots.items()) or None
|
||||
except (zlib.error, ValueError, IndexError):
|
||||
return None
|
||||
|
||||
|
||||
def completed_depots(completed):
|
||||
newest = {}
|
||||
try:
|
||||
for manifest in completed.iterdir():
|
||||
match = re.fullmatch(r"(\d+)_(\d+)\.manifest", manifest.name)
|
||||
if match and manifest.is_file():
|
||||
depot, gid, mtime = int(match[1]), int(match[2]), manifest.stat().st_mtime
|
||||
if depot not in newest or mtime > newest[depot][0]:
|
||||
newest[depot] = (mtime, gid)
|
||||
except OSError:
|
||||
return []
|
||||
return sorted((depot, gid) for depot, (_, gid) in newest.items())
|
||||
|
||||
|
||||
def update_not_started(text, steamapps, appid, installdir):
|
||||
fields = dict(re.findall(r'^\s*"(\w+)"\s*"([^"]*)"', text, re.M))
|
||||
return (fields.get("installdir") == installdir and fields.get("buildid", "0") == "0"
|
||||
@@ -318,6 +380,13 @@ def update_not_started(text, steamapps, appid, installdir):
|
||||
and not (steamapps / "downloading" / str(appid)).exists())
|
||||
|
||||
|
||||
def update_on_launch(text):
|
||||
if re.search(r'^\s*"AutoUpdateBehavior"', text, re.M):
|
||||
return re.sub(r'^(\s*"AutoUpdateBehavior"\s*")0(")', r"\g<1>1\2", text, count=1, flags=re.M)
|
||||
end = text.rstrip().rfind("}")
|
||||
return text[:end] + '\t"AutoUpdateBehavior"\t\t"1"\n' + text[end:]
|
||||
|
||||
|
||||
def libraries(steam_root):
|
||||
try:
|
||||
text = (Path(steam_root) / "steamapps/libraryfolders.vdf").read_text(errors="replace")
|
||||
@@ -374,9 +443,11 @@ def seed_install(steam_root, game, appid):
|
||||
minimal = ('"AppState"\n{\n' + f' "appid" "{appid}"\n "Universe" "1"\n "name" "{title}"\n'
|
||||
+ f' "StateFlags" "4"\n "installdir" "{name}"\n' + '}\n')
|
||||
legacy = minimal.replace(' "Universe" "1"\n', '')
|
||||
# Steam checks every file of an import with no build before updating it, from scratch each time it is interrupted.
|
||||
bare = minimal[:-2] + ' "AutoUpdateBehavior" "1"\n}\n'
|
||||
build = installed_build(source, appid, name)
|
||||
if build is None:
|
||||
content = minimal
|
||||
content = bare
|
||||
elif build.lstrip().startswith('"AppState"'):
|
||||
content = build
|
||||
else:
|
||||
@@ -390,13 +461,21 @@ def seed_install(steam_root, game, appid):
|
||||
for root in libraries(steam_root):
|
||||
existing = root / "steamapps" / manifest.name
|
||||
if existing.is_file():
|
||||
if (existing == manifest and source.is_dir() and target.is_symlink()
|
||||
and os.readlink(target) == str(source)
|
||||
and existing.read_text() != content
|
||||
and (existing.read_text() in (minimal, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"'))
|
||||
or (build is not None and update_not_started(existing.read_text(), steamapps, appid, name)))):
|
||||
if not (existing == manifest and source.is_dir() and target.is_symlink()
|
||||
and os.readlink(target) == str(source)):
|
||||
return True
|
||||
text = existing.read_text()
|
||||
staging = (steamapps / "downloading" / str(appid)).exists()
|
||||
if build is None and update_not_started(text, steamapps, appid, name):
|
||||
wanted = update_on_launch(text)
|
||||
elif ((text in (minimal, bare, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) and not staging)
|
||||
or (build is not None and update_not_started(text, steamapps, appid, name))):
|
||||
wanted = content
|
||||
else:
|
||||
wanted = text
|
||||
if wanted != text:
|
||||
temp = manifest.with_suffix(".droiddeck")
|
||||
temp.write_text(content)
|
||||
temp.write_text(wanted)
|
||||
os.replace(temp, manifest)
|
||||
return True
|
||||
if not source.is_dir():
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Staged as taskset in a PATH directory used only by the Steam client.
|
||||
# Valve's ARM64 helper uses `taskset 0x7c /path/to/steamwebhelper ...` and exits
|
||||
# before starting the browser when Android denies sched_setaffinity.
|
||||
set -u
|
||||
if [ "$#" -ge 2 ] && [[ "$1" =~ ^(0[xX])?[0-9a-fA-F]+$ ]] &&
|
||||
[ -n "${BL_STEAM_WEBHELPER:-}" ] && [ "$2" -ef "$BL_STEAM_WEBHELPER" ]; then
|
||||
mask=$1
|
||||
shift
|
||||
# Pin this wrapper before exec; never retry a helper that has already run.
|
||||
if ! /usr/bin/taskset -p "$mask" "$$" >/dev/null 2>&1; then
|
||||
echo "droiddeck: Steam helper CPU pinning unavailable; using the allowed CPUs" >&2
|
||||
fi
|
||||
exec -- "$@"
|
||||
fi
|
||||
# Queries, existing-process changes, and other programs retain taskset's behavior.
|
||||
exec /usr/bin/taskset "$@"
|
||||
@@ -730,7 +730,7 @@ if x64_gpu; then
|
||||
echo "export FEX_THUNKCONFIG='$X64_HOME/thunks.json'"
|
||||
echo "unset LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE GALLIUM_DRIVER"
|
||||
for v in $gpu_vars; do
|
||||
eval "val=\${$v-}"; [ -n "$val" ] && printf "export %s='%s'\n" "$v" "$val"
|
||||
eval "val=\${$v-}"; [ -n "$val" ] && printf "export %s='%s'\n" "$v" "${val//\'/\'\\\'\'}"
|
||||
done
|
||||
} > "$X64_HOME/game-gpu.env"
|
||||
fi
|
||||
@@ -829,7 +829,7 @@ x64_exec() {
|
||||
mkdir -p "$STEAM_X64/logs"
|
||||
touch "$STEAM_X64/logs/bootstrap_log.txt"
|
||||
( tail -n0 -F --pid=$$ "$STEAM_X64/logs/bootstrap_log.txt" 2>/dev/null |
|
||||
grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)' | sed -u 's/,//g' >&2 ) &
|
||||
grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)|^[[:space:]]*(\[[^]]+\][[:space:]]*)*(Extracting package|Installing update)\.\.\.[[:space:]]*$' | sed -u 's/,//g' >&2 ) &
|
||||
echo "== x86-64 client: steamrt64 $(x64_manifest_version steamrt64) (the client may update itself)" >&2
|
||||
x64_webhelper_gpu && { x64_gpu_watch >&2 & }
|
||||
exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@"
|
||||
|
||||
@@ -357,6 +357,27 @@ GOG_ROOTS = {"HKEY_LOCAL_MACHINE": "HKEY_LOCAL_MACHINE", "HKLM": "HKEY_LOCAL_MAC
|
||||
"HKEY_CLASSES_ROOT": "HKEY_CLASSES_ROOT", "HKCR": "HKEY_CLASSES_ROOT"}
|
||||
WINE_USER = "C:\\users\\steamuser"
|
||||
|
||||
# GOG completes some installs by running a support installer from the game folder (the
|
||||
# goggame-<id>.script "Execute" action). Under ARM64 FEX that 32-bit self-extractor stops at
|
||||
# "Path not found", so the values it would write are applied here instead. Only products GOG
|
||||
# ships no setRegistry action for are listed; a script's own entries always win.
|
||||
# The Witcher: Enhanced Edition (#694) exits during startup unless the installer's
|
||||
# HKLM\Software\CD Projekt Red\The Witcher keys exist - the same ones The Witcher's own
|
||||
# setup writes (InstallFolder, RegionVersion, IsDjinniInstalled) plus its language.
|
||||
GOG_INSTALL_REGISTRY = {
|
||||
"1207658924": [
|
||||
("HKLM", "Software\\CD Projekt Red\\The Witcher", "InstallFolder", "string", "{app}\\"),
|
||||
("HKLM", "Software\\CD Projekt Red\\The Witcher", "RegionVersion", "string", "US"),
|
||||
("HKLM", "Software\\CD Projekt Red\\The Witcher", "IsDjinniInstalled", "dword", 1),
|
||||
("HKLM", "Software\\CD Projekt Red\\The Witcher", "Language", "string", "{language}"),
|
||||
("HKCU", "Software\\CD Projekt RED\\Witcher\\Settings", "TextLanguage", "string", "{language}"),
|
||||
("HKCU", "Software\\CD Projekt RED\\Witcher\\Settings", "VoiceLanguage", "string", "{language}"),
|
||||
],
|
||||
}
|
||||
# The Witcher's text and voice language IDs, from its installer's registry data.
|
||||
GOG_LANGUAGE_IDS = {"en": 3, "fr": 11, "de": 10, "es": 12, "it": 13, "ru": 14, "cs": 15, "hu": 16,
|
||||
"zh": 21, "pl": 5}
|
||||
|
||||
|
||||
def gog_paths(folder, product):
|
||||
app = windows_path(str(folder))
|
||||
@@ -416,8 +437,94 @@ def gog_entry(arguments, paths):
|
||||
return None
|
||||
|
||||
|
||||
def gog_registry(folder):
|
||||
entries, skipped = [], 0
|
||||
def gog_installed_products(folder):
|
||||
products = {}
|
||||
for info in sorted(Path(folder).glob("goggame-*.info")):
|
||||
product = info.name[len("goggame-"):-len(".info")]
|
||||
if not product.isdigit():
|
||||
continue
|
||||
try:
|
||||
products[product] = json.loads(info.read_text(encoding="utf-8-sig"))
|
||||
except (OSError, ValueError):
|
||||
products[product] = {}
|
||||
return products
|
||||
|
||||
|
||||
def gog_language_id(info):
|
||||
languages = info.get("languages") if isinstance(info, dict) else None
|
||||
if isinstance(languages, str):
|
||||
languages = [languages]
|
||||
code = str(languages[0]).lower()[:2] if isinstance(languages, list) and languages else ""
|
||||
return GOG_LANGUAGE_IDS.get(code, GOG_LANGUAGE_IDS["en"])
|
||||
|
||||
|
||||
GOG_VALUE_HIVES = {"hklm": "local_machine", "hkey_local_machine": "local_machine",
|
||||
"hkcu": "current_user", "hkey_current_user": "current_user",
|
||||
"hkcr": "classes_root", "hkey_classes_root": "classes_root"}
|
||||
|
||||
|
||||
def gog_value_key(root, section, name, view32=True):
|
||||
"""A registry value's identity, keeping the root and the 32-bit view apart.
|
||||
|
||||
The fallback import always targets the 32-bit view (`/reg:32`), which Wine keeps under
|
||||
`Software\\Wow6432Node` for HKLM: a native HKLM value must not pass for the 32-bit one.
|
||||
HKCU\\Software is shared by both views, so its values read the same either way.
|
||||
"""
|
||||
text = section.replace("\\\\", "\\").strip("\\").lower()
|
||||
hive = GOG_VALUE_HIVES.get(root.lower(), root.lower())
|
||||
if text.startswith("software\\wow6432node\\"):
|
||||
text = text[len("software\\wow6432node\\"):]
|
||||
elif hive == "local_machine" and not view32 and text.startswith("software\\"):
|
||||
text = "native\\" + text
|
||||
elif text.startswith("software\\"):
|
||||
text = text[len("software\\"):]
|
||||
return "%s|%s|%s" % (hive, text, name.lower())
|
||||
|
||||
|
||||
def gog_registry_values(pfx):
|
||||
"""Values already in the prefix, so install defaults never overwrite a player's choice."""
|
||||
values = set()
|
||||
for file, root in (("system.reg", "hklm"), ("user.reg", "hkcu")):
|
||||
try:
|
||||
lines = (pfx / file).read_text(encoding="utf-8", errors="ignore").splitlines()
|
||||
except OSError:
|
||||
continue
|
||||
section = ""
|
||||
for line in lines:
|
||||
if line.startswith("["):
|
||||
end = line.find("]")
|
||||
section = line[1:end] if end > 0 else line[1:]
|
||||
continue
|
||||
match = re.match(r'^"([^"]+)"=', line)
|
||||
if match and section:
|
||||
values.add(gog_value_key(root, section, match.group(1), view32=False))
|
||||
return values
|
||||
|
||||
|
||||
def gog_scripted_products(folder):
|
||||
products = set()
|
||||
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
|
||||
try:
|
||||
actions = json.loads(script.read_text(encoding="utf-8-sig")).get("actions")
|
||||
except (OSError, ValueError, AttributeError):
|
||||
continue
|
||||
if isinstance(actions, list) and any(
|
||||
isinstance(action, dict) and isinstance(action.get("install"), dict)
|
||||
and action["install"].get("action") == "setRegistry" for action in actions):
|
||||
products.add(script.name[len("goggame-"):-len(".script")])
|
||||
return products
|
||||
|
||||
|
||||
def gog_expected_values(folder):
|
||||
"""The fallback values a launch must find, so the marker never hides one that was deleted."""
|
||||
scripted = gog_scripted_products(folder)
|
||||
return [gog_value_key(root, subkey, name) for product in gog_installed_products(folder)
|
||||
if product in GOG_INSTALL_REGISTRY and product not in scripted
|
||||
for root, subkey, name, _kind, _value in GOG_INSTALL_REGISTRY[product]]
|
||||
|
||||
|
||||
def gog_registry(folder, existing=()):
|
||||
entries, skipped, scripted = [], 0, set()
|
||||
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
|
||||
product = script.name[len("goggame-"):-len(".script")]
|
||||
try:
|
||||
@@ -434,11 +541,28 @@ def gog_registry(folder):
|
||||
skipped += 1
|
||||
else:
|
||||
entries.append(entry)
|
||||
scripted.add(product)
|
||||
for product, info in gog_installed_products(folder).items():
|
||||
if product in scripted or product not in GOG_INSTALL_REGISTRY:
|
||||
continue
|
||||
paths = dict(gog_paths(folder, product), language=str(gog_language_id(info)))
|
||||
for root, subkey, name, kind, value in GOG_INSTALL_REGISTRY[product]:
|
||||
if gog_value_key(root, subkey, name) in existing:
|
||||
continue
|
||||
entry = gog_entry({"root": root, "subkey": subkey, "valueName": name,
|
||||
"valueType": kind, "valueData": value}, paths)
|
||||
if entry is None:
|
||||
skipped += 1
|
||||
else:
|
||||
entries.append(entry)
|
||||
return entries, skipped
|
||||
|
||||
|
||||
def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=None):
|
||||
entries, skipped = gog_registry(folder)
|
||||
pfx = Path(compat_data) / "pfx" if compat_data else None
|
||||
existing = gog_registry_values(pfx) if pfx else set()
|
||||
entries, skipped = gog_registry(folder, existing)
|
||||
expected = gog_expected_values(folder)
|
||||
if installation:
|
||||
product = str(installation["id"])
|
||||
if not product.isdigit():
|
||||
@@ -465,10 +589,10 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=Non
|
||||
return "no-proton" + note
|
||||
text = "Windows Registry Editor Version 5.00\r\n\r\n" + "".join(entry + "\r\n\r\n" for entry in entries)
|
||||
stamp = hashlib.sha256(text.encode("utf-8")).hexdigest()
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
marker = pfx / GOG_REGISTRY_MARK
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp and (pfx / "system.reg").is_file():
|
||||
if (marker.is_file() and marker.read_text() == stamp and (pfx / "system.reg").is_file()
|
||||
and set(expected) <= existing):
|
||||
return "ready" + note
|
||||
Path(compat_data).mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-gog-") as tmp:
|
||||
|
||||
@@ -476,15 +476,30 @@ def save_state(compat, state):
|
||||
def pending_for(app_id, pending=PENDING):
|
||||
try:
|
||||
with open(pending, encoding="utf-8") as source:
|
||||
ids = json.load(source).get("games", {}).get(str(app_id), [])
|
||||
config = json.load(source)
|
||||
ids = config.get("games", {}).get(str(app_id), [])
|
||||
revisions = config.get("revisions", {})
|
||||
except (OSError, ValueError, AttributeError):
|
||||
return []
|
||||
return [i for i in ids if valid_id(i)] if isinstance(ids, list) else []
|
||||
return {}
|
||||
revisions = revisions if isinstance(revisions, dict) else {}
|
||||
return {i: max(0, revisions[i]) if type(revisions.get(i)) is int else 0
|
||||
for i in ids if valid_id(i)} if isinstance(ids, list) else {}
|
||||
|
||||
|
||||
def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT, sleep=time.sleep, clock=time.monotonic):
|
||||
def missing():
|
||||
return [cid for cid in pending_for(app_id, pending) if component(store, cid) is None]
|
||||
left = []
|
||||
for cid, revision in pending_for(app_id, pending).items():
|
||||
try:
|
||||
with open(Path(store) / cid / "component.json", encoding="utf-8") as source:
|
||||
meta = json.load(source)
|
||||
installed = meta.get("revision", 0)
|
||||
ready = type(installed) is int and installed >= revision
|
||||
except (OSError, ValueError, AttributeError):
|
||||
ready = False
|
||||
if not ready:
|
||||
left.append(cid)
|
||||
return left
|
||||
left = missing()
|
||||
if not left:
|
||||
return None
|
||||
@@ -585,6 +600,8 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
written, registry_notes = apply_registry(pfx, values, new_state, held)
|
||||
notes += registry_notes
|
||||
save_state(compat, new_state)
|
||||
overrides, fallback = reachable_overrides(pfx, overrides)
|
||||
notes += fallback
|
||||
if copied or removed or restored or written:
|
||||
note = "components %s: %d file(s) placed, %d removed" % (",".join(ids) or "none", copied, removed)
|
||||
note += ", %d put back as they were" % restored if restored else ""
|
||||
@@ -592,6 +609,26 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
return overrides, notes
|
||||
|
||||
|
||||
def native_dll(pfx, name):
|
||||
for arch in ARCH_DIRS:
|
||||
path = existing(pfx / "drive_c/windows" / arch / (name + ".dll"))
|
||||
if path is None or builtin(path) or not os.access(path, os.R_OK):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def reachable_overrides(pfx, names):
|
||||
kept, notes = [], []
|
||||
for entry in names:
|
||||
name, sep, mode = entry.partition("=")
|
||||
name = name.strip().lower()
|
||||
if sep and mode.strip().lower() == "n" and not native_dll(pfx, name):
|
||||
entry = name + "=n,b"
|
||||
notes.append("%s=n has no native DLL in the prefix; using n,b" % name)
|
||||
kept.append(entry)
|
||||
return kept, notes
|
||||
|
||||
|
||||
def overrides_value(names):
|
||||
modes = {}
|
||||
for entry in names:
|
||||
|
||||
@@ -26,6 +26,9 @@ SNIPER_APPID = "1628350"
|
||||
SLR4_APPID = "4183110"
|
||||
FEX_DEPENDENCIES = (FEX_APPID, SNIPER_APPID, SLR4_APPID)
|
||||
REQUIRED_TOOLS = (PROTON_ARM64_APPID,) + FEX_DEPENDENCIES
|
||||
# Linux builds that bundle an arm64 binary their launcher starts; Steamworks offers no arm64
|
||||
# launch-option architecture, so appinfo cannot say so (#1774).
|
||||
FEX_DEFAULT_APPS = frozenset({"4385780"})
|
||||
FULLY_INSTALLED = 4
|
||||
UPDATE_REQUIRED = 2
|
||||
REQUEST_HANDOFF_SECONDS = 30
|
||||
@@ -173,6 +176,9 @@ bl_components() {
|
||||
local -A cm_sums=()
|
||||
while IFS=$'\\t' read -r scope t want comp rel sum src; do
|
||||
[ -n "$scope" ] || continue
|
||||
# The selected system PowerVR runtime supplies DXVK at launch. Keep saved selections
|
||||
# for a later manual-driver session without rewriting this Proton's bundled files now.
|
||||
[ "$comp" = dxvk ] && [ -n "${DROIDDECK_POWERVR_RUNTIME:-}" ] && continue
|
||||
cm_rows+=("$comp"$'\\t'"$rel"$'\\t'"$sum"$'\\t'"$src")
|
||||
[ "$src" != "-" ] && [ -f "$base/$rel" ] && cm_files+=("$base/$rel")
|
||||
done <<< "$cm_selected"
|
||||
@@ -779,20 +785,32 @@ def launch_options(config):
|
||||
return found
|
||||
|
||||
|
||||
def appinfo_entries(path):
|
||||
def appinfo_entries(path, wanted=None):
|
||||
"""Read metadata for all apps, or only the requested app-id strings."""
|
||||
import struct
|
||||
if wanted is not None:
|
||||
wanted = set(wanted)
|
||||
if not wanted:
|
||||
return {}
|
||||
try:
|
||||
stamp = os.stat(path).st_mtime_ns
|
||||
except OSError:
|
||||
return {}
|
||||
cached = APPINFO_CACHE.get(path)
|
||||
if cached and cached[0] == stamp:
|
||||
return cached[1]
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
except OSError:
|
||||
return {}
|
||||
covered = cached[2]
|
||||
if covered is None or (wanted is not None and wanted <= covered):
|
||||
return cached[1] if wanted is None else {app: cached[1][app] for app in wanted if app in cached[1]}
|
||||
data = cached[3]
|
||||
needed = None if wanted is None else wanted - covered
|
||||
else:
|
||||
cached = None
|
||||
needed = wanted
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
except OSError:
|
||||
return {}
|
||||
if len(data) < 8:
|
||||
return {}
|
||||
magic = struct.unpack_from("<I", data, 0)[0]
|
||||
@@ -854,6 +872,8 @@ def appinfo_entries(path):
|
||||
break
|
||||
start = offset + 8
|
||||
offset = start + size
|
||||
if needed is not None and str(app) not in needed:
|
||||
continue
|
||||
try:
|
||||
info = section(start + header)[0].get("appinfo", {})
|
||||
except (ValueError, IndexError, struct.error):
|
||||
@@ -878,8 +898,14 @@ def appinfo_entries(path):
|
||||
entry["app_mappings"] = {str(m.get("appid", key)): str(m.get("tool", "")) for key, m in mappings.items()
|
||||
if isinstance(m, dict)} if isinstance(mappings, dict) else {}
|
||||
found[str(app)] = entry
|
||||
APPINFO_CACHE[path] = (stamp, found)
|
||||
return found
|
||||
covered = wanted
|
||||
if cached is not None and wanted is not None:
|
||||
cached[1].update(found)
|
||||
found = cached[1]
|
||||
covered = cached[2] | wanted
|
||||
# None coverage is complete; partial entries keep one immutable file snapshot.
|
||||
APPINFO_CACHE[path] = (stamp, found, covered, data if covered is not None else None)
|
||||
return found if wanted is None else {app: found[app] for app in wanted if app in found}
|
||||
|
||||
|
||||
def appinfo_platforms(path, wanted):
|
||||
@@ -912,7 +938,7 @@ def native_targets(steam_root, apps):
|
||||
if "arm64" in osarch or "aarch64" in osarch:
|
||||
targets[app] = None
|
||||
continue
|
||||
if "windows" in oslist:
|
||||
if "windows" in oslist and app not in FEX_DEFAULT_APPS:
|
||||
targets[app] = NATIVE_CHOICE
|
||||
continue
|
||||
targets[app] = FEX_TOOL
|
||||
@@ -1063,7 +1089,7 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks
|
||||
continue
|
||||
mine = auto.get(app)
|
||||
target = native.get(app, default)
|
||||
if not name and app in native_choices:
|
||||
if not name and (app in native_choices or (app in current and app in FEX_DEFAULT_APPS)):
|
||||
target = NATIVE_CHOICE
|
||||
stale = unrunnable(name, runnable)
|
||||
if name and not stale and (mine is None or name != mine):
|
||||
@@ -1360,6 +1386,20 @@ def read_config_mapping(config_path):
|
||||
return read_mapping(tokens, mapping + steam + 1) if mapping is not None else {}
|
||||
|
||||
|
||||
def mapping_entry(app, tool):
|
||||
return ['"%s"' % app, "{", '"name"', '"%s"' % tool, '"config"', '""',
|
||||
'"priority"', '"75"' if app == "0" else '"250"', "}"]
|
||||
|
||||
|
||||
def set_mapping_tool(tokens, block, tool):
|
||||
end = block_end(tokens, block)
|
||||
for i in range(block + 1, end):
|
||||
if tokens[i] == '"name"':
|
||||
tokens[i + 1] = '"%s"' % tool
|
||||
return
|
||||
tokens[block + 1:block + 1] = ['"name"', '"%s"' % tool]
|
||||
|
||||
|
||||
def set_mapping(tokens, mapping, app, tool):
|
||||
block = find_block(tokens[mapping + 1:], [app])
|
||||
if tool is None:
|
||||
@@ -1368,16 +1408,40 @@ def set_mapping(tokens, mapping, app, tool):
|
||||
del tokens[block - 1:block_end(tokens, block) + 1]
|
||||
return
|
||||
if block is None:
|
||||
tokens[mapping + 1:mapping + 1] = [
|
||||
'"%s"' % app, "{", '"name"', '"%s"' % tool, '"config"', '""', '"priority"', '"75"' if app == "0" else '"250"', "}"]
|
||||
tokens[mapping + 1:mapping + 1] = mapping_entry(app, tool)
|
||||
return
|
||||
block += mapping + 1
|
||||
end = block_end(tokens, block)
|
||||
for i in range(block + 1, end):
|
||||
if tokens[i] == '"name"':
|
||||
tokens[i + 1] = '"%s"' % tool
|
||||
return
|
||||
tokens[block + 1:block + 1] = ['"name"', '"%s"' % tool]
|
||||
set_mapping_tool(tokens, block + mapping + 1, tool)
|
||||
|
||||
|
||||
def set_mappings(tokens, mapping, changes):
|
||||
"""Apply a batch with one traversal of the affected mapping entries."""
|
||||
pending = {('"%s"' % app).lower(): (app, tool) for app, tool in changes.items()}
|
||||
# Non-string or aliased keys retain the single writer's sequential semantics.
|
||||
if len(changes) < 2 or len(pending) != len(changes) or any(not isinstance(app, str) for app in changes):
|
||||
for app, tool in changes.items():
|
||||
set_mapping(tokens, mapping, app, tool)
|
||||
return
|
||||
updated = []
|
||||
i = mapping + 1
|
||||
while pending and i < len(tokens) and tokens[i] != "}":
|
||||
if i + 1 < len(tokens) and tokens[i + 1] == "{":
|
||||
end = block_end(tokens, i + 1)
|
||||
change = pending.pop(tokens[i].lower(), None)
|
||||
if change is None:
|
||||
updated.extend(tokens[i:end + 1])
|
||||
elif change[1] is not None:
|
||||
entry = tokens[i:end + 1]
|
||||
set_mapping_tool(entry, 1, change[1])
|
||||
updated.extend(entry)
|
||||
i = end + 1
|
||||
else:
|
||||
updated.append(tokens[i])
|
||||
i += 1
|
||||
added = []
|
||||
for app, tool in reversed(list(pending.values())):
|
||||
if tool is not None:
|
||||
added.extend(mapping_entry(app, tool))
|
||||
tokens[mapping + 1:i] = added + updated
|
||||
|
||||
|
||||
def steam_running():
|
||||
@@ -1450,10 +1514,9 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
if settle and newest:
|
||||
state["own_proton"] = True
|
||||
if newest:
|
||||
for app, name in list(current.items()):
|
||||
if app != "0" and name in gone:
|
||||
set_mapping(tokens, mapping, app, newest)
|
||||
current[app] = newest
|
||||
replacements = {app: newest for app, name in current.items() if app != "0" and name in gone}
|
||||
set_mappings(tokens, mapping, replacements)
|
||||
current.update(replacements)
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = {app: newest if name in gone else name for app, name in state["auto"].items()}
|
||||
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
|
||||
@@ -1469,8 +1532,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
changes, auto = plan_mapping(
|
||||
current, apps, names, default, followers(state, current), native, picks,
|
||||
overrides, managed, native_choices)
|
||||
for app, tool in changes.items():
|
||||
set_mapping(tokens, mapping, app, tool)
|
||||
set_mappings(tokens, mapping, changes)
|
||||
text = serialize(tokens)
|
||||
if text != serialize(tokenize(original)):
|
||||
write_changed(config_path, text)
|
||||
@@ -1562,16 +1624,16 @@ def x64_repoint(steam_root, tool, live=False):
|
||||
keep = local_tools(steam_root)
|
||||
moved = []
|
||||
current = read_mapping(tokens, mapping)
|
||||
if "0" not in current:
|
||||
set_mapping(tokens, mapping, "0", tool)
|
||||
changes = {} if "0" in current else {"0": tool}
|
||||
for app, name in current.items():
|
||||
named = name.lower()
|
||||
legacy = named == "droiddeck-proton-arm64"
|
||||
if (named.startswith("proton") or legacy) and named != tool.lower() \
|
||||
and (legacy or named not in keep):
|
||||
set_mapping(tokens, mapping, app, tool)
|
||||
changes[app] = tool
|
||||
if app != "0":
|
||||
moved.append(app)
|
||||
set_mappings(tokens, mapping, changes)
|
||||
text = serialize(tokens)
|
||||
if text != serialize(tokenize(original)):
|
||||
write_changed(config, text)
|
||||
|
||||
Reference in new issue
Block a user