Merge branch 'main' into fix/gog-native-installer-extract

This commit is contained in:
Moroni Granja authored and GitHub committed 2026-10-21 07:56:53 -03:00
commit d006538f13
182 files changed
+9467 -698

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ for bad in libstdc++.so.6 libgcc_s.so.1; do
done
syms() { "${READELF:-readelf}" -Ws "$1" | awk '$4 == "FUNC" && $5 == "GLOBAL" {sub(/@.*/, "", $8); print $8}'; }
FAKE=$(syms "$D/libfakeinput.so")
for sym in open openat ioctl read close poll ppoll select stat fstat access scandir; do
for sym in open openat ioctl read readv close poll ppoll select stat fstat access scandir; do
grep -qx "$sym" <<<"$FAKE" || { echo "::error::libfakeinput.so does not export $sym"; exit 1; }
done
if grep -qxE '__gxx_personality_v0|__cxa_throw|_Unwind_Resume' <<<"$FAKE"; then
@@ -23,6 +23,7 @@ import json
import math
import re
import os
import select
import selectors
import signal
import socket
@@ -532,6 +533,111 @@ def cdp_eval(agent_dir, expression, target=None, await_promise=True, timeout=15)
ws.close()
KEYBOARD_BINDING = "droiddeckSteamKeyboard"
KEYBOARD_CHECK_SECONDS = 30
KEYBOARD_JS = r"""
(() => {
const self = window.__droiddeckKeyboard || (window.__droiddeckKeyboard = { watched: new WeakSet(), last: null });
self.check = () => {
let showing = false;
for (const win of Array.from(globalThis.SteamUIStore?.WindowStore?.SteamUIWindows || [])) {
const value = win?.VirtualKeyboardManager?.IsShowingVirtualKeyboard;
if (!value) continue;
if (!self.watched.has(value) && typeof value.Subscribe === "function") {
self.watched.add(value);
value.Subscribe(() => setTimeout(() => self.check()));
}
if (value.m_currentValue === true) showing = true;
}
if (showing !== self.last) {
self.last = showing;
if (typeof window.__BINDING__ === "function") window.__BINDING__(String(showing));
}
return showing;
};
self.timer = self.timer || setInterval(() => self.check(), 500);
return self.check();
})()
""".replace("__BINDING__", KEYBOARD_BINDING)
class KeyboardWatcher(threading.Thread):
def __init__(self, agent_dir):
super().__init__(daemon=True, name="keyboard")
self.agent_dir = agent_dir
self.path = agent_dir / "keyboard.json"
self.showing = None
self.seq = 0
self.next_id = 0
self.attached = False
def report(self, showing):
if showing == self.showing:
return
self.showing = showing
self.seq += 1
write_json(self.path, {"steamKeyboard": showing, "seq": self.seq})
def run(self):
failures, last = 0, None
while True:
try:
self.watch()
except Exception as e:
if self.attached:
log("Steam keyboard: lost the client (%s); reattaching" % e)
failures = 0
elif str(e) != last:
log("Steam keyboard: waiting for the client (%s)" % e)
self.attached = False
last = str(e)
self.report(False)
failures += 1
time.sleep(min(2 * failures, 10))
def watch(self):
targets = [t for t in cdp_targets(self.agent_dir)
if t.get("title") == "SharedJSContext" and t.get("webSocketDebuggerUrl")]
if not targets:
raise AgentError("NO_TARGET", "No SharedJSContext yet")
ws = WebSocket(targets[0]["webSocketDebuggerUrl"], 5)
try:
self.call(ws, "Runtime.addBinding", {"name": KEYBOARD_BINDING})
self.report(self.install(ws))
self.attached = True
while True:
if not ws.buffer and not select.select([ws.s], [], [], KEYBOARD_CHECK_SECONDS)[0]:
self.report(self.install(ws))
continue
self.event(json.loads(ws.recv()))
finally:
ws.close()
def install(self, ws):
result = self.call(ws, "Runtime.evaluate", {"expression": KEYBOARD_JS, "returnByValue": True})
if result.get("exceptionDetails"):
raise AgentError("JS_EXCEPTION", json.dumps(result["exceptionDetails"])[:500])
return result.get("result", {}).get("value") is True
def call(self, ws, method, params):
self.next_id += 1
ws.send(json.dumps({"id": self.next_id, "method": method, "params": params}))
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
message = json.loads(ws.recv())
if message.get("id") == self.next_id:
if "error" in message:
raise AgentError("CDP_ERROR", json.dumps(message["error"]))
return message.get("result", {})
self.event(message)
raise AgentError("TIMEOUT", "No answer to %s from DevTools" % method)
def event(self, message):
params = message.get("params") or {}
if message.get("method") == "Runtime.bindingCalled" and params.get("name") == KEYBOARD_BINDING:
self.report(params.get("payload") == "true")
def steam_idle_inhibit(agent_dir, inhibit):
expression = """(async want => {
const toggle = () => new Promise(done => {
@@ -918,6 +1024,8 @@ def serve(agent_dir, focus=True, poll=0.1):
can_focus = focus and bool(os.environ.get("DISPLAY"))
if can_focus:
FocusWatcher(agent_dir / "focus.json").start()
if focus:
KeyboardWatcher(agent_dir).start()
write_json(agent_dir / "hello.json", {"pid": os.getpid(), "version": VERSION, "started": int(time.time() * 1000),
"displays": displays(), "focus": can_focus})
log("serving %s (focus %s)" % (agent_dir, "on" if can_focus else "off"))
@@ -7,7 +7,21 @@ import socket
import struct
import sys
SOCKET = "\0" + os.environ.get("DROIDDECK_BWRAP_SOCKET", "com.droiddeck.launcher.bwrap")
SOCKET_FILE = "/etc/droiddeck/bwrap-socket"
def socket_name():
name = os.environ.get("DROIDDECK_BWRAP_SOCKET", "")
if not name:
try:
with open(SOCKET_FILE, encoding="utf-8") as f:
name = f.read().strip()
except OSError:
pass
return "\0" + (name or "com.droiddeck.launcher.bwrap")
SOCKET = socket_name()
VERSION = "bubblewrap 0.11.0 (droiddeck)"
NO_ARG = {
@@ -674,6 +674,7 @@ def launch(command, env, mode, decide=None):
def game_environment(env):
try:
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
env = game_env["game_gpu"](env)
app = game_env["game_id"](env) or env.get("SteamAppId") or env.get("SteamGameId")
if not app:
return env
@@ -7,6 +7,7 @@ import subprocess
import sys
from pathlib import Path
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
SYNC_KEYS = ("BL_SYNC", "BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
@@ -125,6 +126,35 @@ def skip_red_launcher(command):
return command
def offline_without_anticheat(command, env):
"""Start the configured game executable when the player opts into launching without EAC."""
if (env.get("DROIDDECK_ANTICHEAT_OFFLINE") != "1" or len(command) <= 2
or command[1] != "waitforexitandrun"
or not re.fullmatch(r"start_protected_game(?:_?x64|_?64)?\.exe",
os.path.basename(command[2]), re.IGNORECASE)):
return command
folder = os.path.dirname(command[2])
try:
with open(os.path.join(folder, "EasyAntiCheat", "settings.json"), encoding="utf-8-sig") as source:
executable = json.load(source).get("executable")
except (OSError, ValueError, AttributeError):
return command
if not isinstance(executable, str) or not executable:
return command
relative = os.path.normpath(executable.replace("\\", "/"))
game = os.path.join(folder, relative)
if os.path.isabs(relative) or relative.startswith("..") or not os.path.isfile(game):
return command
# Resolve symlinks before accepting an executable inside the game directory.
root = os.path.realpath(folder)
if os.path.commonpath((root, os.path.realpath(game))) != root:
return command
if os.path.normcase(os.path.abspath(game)) == os.path.normcase(os.path.abspath(command[2])):
return command
print("droiddeck-game-env: started without Easy Anti-Cheat (offline only)", file=sys.stderr)
return command[:2] + [game] + command[3:]
def engine_fixes(exe, args):
"""Environment and extra arguments a game needs because of what it is built with."""
game = Game(exe, args)
@@ -153,6 +183,18 @@ def win_components(compat, app_id):
return ""
def game_gpu(env):
if GAME_TU_DEBUG not in env:
return env
result = env.copy()
value = result.pop(GAME_TU_DEBUG)
if value:
result["TU_DEBUG"] = value
else:
result.pop("TU_DEBUG", None)
return result
def apply_config(env, config, app_id, fixes=None):
if config.get("version") != 1:
raise ValueError("unsupported environment configuration")
@@ -283,7 +325,7 @@ def main():
command = sys.argv[1:]
if not command:
return 2
env = os.environ.copy()
env = game_gpu(os.environ.copy())
mic_enabled = env.get("BL_MIC_ENABLED")
mark_install_scripts(command, env)
app_id = game_id(env)
@@ -313,6 +355,8 @@ def main():
env = apply_config(env, {"version": 1}, app_id, fixes)
except (OSError, ValueError, TypeError, AttributeError):
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
if app_id and len(command) > 1 and command[1] == "waitforexitandrun":
command = offline_without_anticheat(command, env)
if mic_enabled == "0":
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
env = force_ssbs(command, env)
@@ -188,6 +188,7 @@ present() { awk -F'\t' '
}
' - "$1"; }
regs=()
for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
/mnt/droiddeck-sd/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
/root/Games/*/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
@@ -195,8 +196,21 @@ for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/syste
"$steam_root"/steamapps/compatdata/*/pfx/system.reg \
/mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg \
/root/Games/*/steamapps/compatdata/*/pfx/system.reg; do
[ -f "$reg" ] || continue
[ -f "$reg" ] && regs+=("$reg")
done
declare -A regid=()
if [ ${#regs[@]} -gt 0 ]; then
while IFS=$'\t' read -r id name; do
regid[$name]=$id
done < <(stat -c $'%i %s %.9Y\t%n' -- "${regs[@]}" 2>/dev/null)
fi
for reg in "${regs[@]}"; do
seeded=${reg%/*}/.droiddeck-redists
checked=${reg%/*}/.droiddeck-redists-checked
id=${regid[$reg]:-}
prev=
[ -f "$checked" ] && read -r prev <"$checked"
legacy=${reg%/*}/.bannerlator-redists
if [ -f "$legacy" ] && [ ! -f "$seeded" ]; then
mv -f "$legacy" "$seeded"
@@ -210,12 +224,13 @@ for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/syste
if [ -n "${vulkan[$line]:-}" ]; then stale+=("$line"); else kept+=("$line"); fi
done
if [ ${#stale[@]} -gt 0 ] && unseed "$reg" "${stale[@]}"; then
id=
had=()
for line in "${kept[@]}"; do had[$line]=1; done
printf '%s\n' "${kept[@]}" >"$seeded"
echo "== took Vulkan runtime markers out of $reg"
fi
if [ ${#had[@]} -gt 0 ]; then
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
declare -A held=()
while IFS= read -r line; do [[ $line == *$'\t'* ]] && held[$line]=1; done < <(printf '%s\n' "${!had[@]}" | present "$reg")
if [ ${#held[@]} -lt ${#had[@]} ]; then
@@ -228,7 +243,11 @@ for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/syste
fi
missing=()
for line in "${want[@]}"; do [ -n "${had[$line]:-}" ] || missing+=("$line"); done
[ ${#missing[@]} -eq 0 ] && continue
if [ ${#missing[@]} -eq 0 ]; then
[ -n "$id" ] && [ "$id" != "$prev" ] && printf '%s\n' "$id" >"$checked"
continue
fi
rm -f "$checked"
dated=$(mktemp) || continue
touch -r "$reg" "$dated"
if printf '%s\n' "$(block_for "${missing[@]}")" >>"$reg"; then
@@ -4,6 +4,11 @@ export HOME=${HOME:-/root}
mode=${1:-desktop}
shift || true
step() { echo "== STEP $(date -u +%H:%M:%S) $*"; }
steam_setup_failed() {
echo "== steam: the Steam client could not be set up (status $1)"
[ -z "${BL_STEAM_EXIT_FILE:-}" ] || printf '%s\n' "$1" > "$BL_STEAM_EXIT_FILE"
exit "$1"
}
if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
mkdir -p "$(dirname "$BL_LOG")" 2>/dev/null
if [ "$(stat -c %s "$BL_LOG" 2>/dev/null || echo 0)" -gt 8388608 ]; then
@@ -303,6 +308,9 @@ case $mode in
taskset -cp "$cores" $$ >/dev/null 2>&1 || true
fi
python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 || true
if [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
export WAYLAND_DISPLAY= XDG_SESSION_TYPE=x11
fi
run_program() {
local rc=0 child sig forwarded=0
{ trap - INT QUIT; exec "$@"; } <&0 &
@@ -350,6 +358,12 @@ case $mode in
esac
;;
steam)
if [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
export WAYLAND_DISPLAY= XDG_SESSION_TYPE=x11
fi
export MOZ_DISABLE_CONTENT_SANDBOX=1 MOZ_DISABLE_GMP_SANDBOX=1 MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
export MOZ_SHM_NO_SEALS=1
steam_x64=0
[ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ] && steam_x64=1
steam_cef_gpu=1
@@ -358,10 +372,10 @@ case $mode in
# droiddeck-steam-install removes the repair request: read it first so Repair Steam covers both clients.
_bl_x64_repair=0
[ -e "$HOME/.bl-steam-repair" ] && _bl_x64_repair=1
droiddeck-steam-install || exit $?
droiddeck-steam-install || steam_setup_failed $?
droiddeck-steam-install --sync steamdeck_publicbeta || step "could not update the arm64 client's parts; the x86-64 client keeps its own web helper"
step "checking the x86-64 Steam client (FEX, experimental; the first run downloads ~2 GB)"
BL_X64_REPAIR=$_bl_x64_repair droiddeck-steam-x64 --prepare || exit $?
BL_X64_REPAIR=$_bl_x64_repair droiddeck-steam-x64 --prepare || steam_setup_failed $?
step "x86-64 Steam client ready"
steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
steam_client=(droiddeck-steam-x64 --exec)
@@ -371,7 +385,7 @@ case $mode in
fi
else
step "checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)"
droiddeck-steam-install || exit $?
droiddeck-steam-install || steam_setup_failed $?
step "Steam client ready"
steam_root=$XDG_DATA_HOME/Steam
if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then
@@ -105,7 +105,7 @@ INSTALL_JS = r"""
const body = [];
uint(1, appid, body);
const r = await send("CompatManager.GetCompatTools#1", body);
if (!r.ok) throw new Error("GetCompatTools " + appid + " failed (" + r.eresult + " " + r.error + ")");
if (!r.ok) throw Object.assign(new Error("GetCompatTools " + appid + " failed (" + r.eresult + " " + r.error + ")"), { eresult: r.eresult });
return { selected: text(r.body, 3), fallback: text(r.body, 4), tools: (r.body[1] || []).map((t) => text(parse(t), 1)) };
};
self.set = async (appid, name) => {
@@ -119,7 +119,13 @@ INSTALL_JS = r"""
};
self.many = async (apps) => {
const out = {};
for (const app of apps) out[app] = (await self.get(Number(app))).selected;
for (const app of apps) {
try {
out[app] = (await self.get(Number(app))).selected;
} catch (e) {
if (e.eresult !== 128) throw e;
}
}
return out;
};
window.__droiddeckCompat = self;
@@ -555,11 +561,24 @@ class Helper:
# "native" from earlier builds also lists dual-platform games nobody chose to run natively.
prior_native = state.get("native_choices", ())
native_choices = set(prior_native if isinstance(prior_native, (list, tuple, set)) else ())
picked = COMPAT["picked_apps"](state)
runnable = {t["name"].lower() for t in live}
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
overrides = COMPAT["requested_games"](
COMPAT["game_requests"](), catalog, [t["name"] for t in live])
apps = sorted(set(apps) | set(overrides), key=COMPAT["app_order"])
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
refused = set(apps) - set(current)
refused_native = native_choices & refused
if refused:
apps = [app for app in apps if app not in refused]
installed = [app for app in installed if app not in refused]
picks = [app for app in picks if app not in refused]
prior_auto = {app: tool for app, tool in prior_auto.items() if app not in refused}
if isinstance(state.get("auto"), dict):
state["auto"] = prior_auto
native_choices -= refused
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
current["0"] = top["selected"]
native = COMPAT["native_targets"](self.steam_root, apps)
raw_mapping = COMPAT["read_config_mapping"](
@@ -568,7 +587,7 @@ class Helper:
for app in native_choices:
current[app] = ""
for app in set(native) - native_choices:
if not current.get(app):
if not current.get(app) and app not in picked:
current.pop(app, None)
else:
for app in set(native) | native_choices:
@@ -576,7 +595,8 @@ class Helper:
# The client shows an explicit native choice as the tool it inherits, and writes config.vdf late.
if raw_mapping[app] == "" or current.get(app) not in self.known:
current[app] = raw_mapping[app]
elif app in prior_auto or app in native_choices:
elif app in prior_auto or app in native_choices or app in picked and (
not current.get(app) or COMPAT["unrunnable"](current[app], runnable)):
current[app] = ""
elif not current.get(app):
current.pop(app, None)
@@ -590,8 +610,8 @@ class Helper:
tool if tool is not None else "Steam native default"))
state.update(
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
native_choices=sorted(app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]),
tools=catalog, live=True)
native_choices=sorted(refused_native | {app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]}),
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True)
state.pop("native", None)
if waiting:
state["pending"] = wanted
@@ -271,6 +271,23 @@ def provision_prefix(compat_data, wait=SERVER_WAIT):
return state + (" server-running" if busy else "")
def create_prefix(compat_data, proton, timeout=120):
if not compat_data or not proton or not Path(proton).is_file():
return "no-proton"
reg = Path(compat_data) / "pfx/user.reg"
if reg.is_file():
return "present"
try:
Path(compat_data).mkdir(parents=True, exist_ok=True)
subprocess.run([proton, "run", "cmd.exe", "/d", "/c", "exit"], stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
except subprocess.TimeoutExpired:
return "timeout"
except OSError:
return "failed"
return "created" if reg.is_file() else "failed"
CLOUD_TIMEOUT = 15.0
CLOUD_STORES = ("gog", "epic")
STORE_GAME = 10
@@ -502,6 +519,10 @@ def main(argv):
compat_data = os.environ.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
prefix_id = os.path.basename(compat_data) if compat_data else ""
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
if launch_dir and cloud_on(sidecar):
made = create_prefix(compat_data, os.environ.get("BL_STORE_PROTON", ""))
if made != "present":
log("cloud %s %s prefix=%s" % (store, game, made))
if store == "gog":
prepare_gog(sidecar, compat_data, launch_dir)
log("gog registry: " + apply_gog_registry(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
@@ -1042,6 +1042,16 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks
return changes, kept
def picked_apps(state):
picked = state.get("picked", ())
return {app for app in picked if isinstance(app, str)} if isinstance(picked, list) else set()
def picked_after(current, changes):
return sorted(({app for app, tool in current.items() if tool} - set(changes) |
{app for app, tool in changes.items() if tool}) - {"0"}, key=app_order)
def followers(state, current):
if "auto" in state:
return state["auto"]
@@ -1287,6 +1297,8 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
if linux_tool != FEX_TOOL:
native = {app: linux_tool if tool == FEX_TOOL else tool for app, tool in native.items()}
for app in picked_apps(state) & set(native):
current.setdefault(app, "")
changes, auto = plan_mapping(
current, apps, names, default, followers(state, current), native, picks,
overrides, managed, native_choices)
@@ -1297,6 +1309,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
write_changed(config_path, text)
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
state["picked"] = picked_after(current, changes)
state.pop("native", None)
state["tools"] = catalog
state.setdefault("default", default)