mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
Target Android SDK 37 for Play Store review
Integrate current main while preserving the original SDK migration history. Update the Android toolchain, runtime permissions, foreground service lifecycle, storage access, native execution and platform API compatibility. Complete translations and regression coverage. Validation: 3,260 JVM tests, 1,620 Python tests (eight skips), 171 Rust tests, six native regression programs and release lint with zero errors. Signed APK upgrade installed on the requested device. Signed app bundle validated with bundletool. Review candidate: physical before/after feature checks, performance parity and native 16 KiB audio compatibility remain pending. Play Console acceptance has not been verified.
This commit is contained in:
commit
b14587baeb
1553 files changed
+124616
-8790
No files matched your search
@@ -45,7 +45,7 @@ lib=$out/x86_64/libwebkitinput.so
|
||||
gcc -m64 -shared -fPIC -O2 -Wall -Wextra -nostdlib -fno-stack-protector -fno-builtin -fvisibility=hidden \
|
||||
-o "$lib" tools/linuxfs/fex/webkitinput.c
|
||||
strip --strip-unneeded "$lib"
|
||||
if objdump -p "$lib" | grep -q NEEDED || [ "$(nm -D --undefined-only "$lib" | awk '{print $1 $2}' | LC_ALL=C sort | tr '\n' ' ')" != "wdlsym wg_object_get_data wg_object_set wg_object_set_data wg_type_check_instance_is_a wgtk_container_forall wgtk_container_get_type wgtk_key_snooper_install wgtk_widget_get_toplevel wwebkit_user_script_new wwebkit_user_script_unref wwebkit_web_view_get_type wwebkit_web_view_get_uri wwebkit_web_view_run_javascript " ]; then
|
||||
if objdump -p "$lib" | grep -q NEEDED || [ "$(nm -D --undefined-only "$lib" | awk '{print $1 $2}' | LC_ALL=C sort | tr '\n' ' ')" != "wdlsym wg_getenv wg_object_get_data wg_object_set wg_object_set_data wg_type_check_instance_is_a wgtk_container_forall wgtk_container_get_type wgtk_key_snooper_install wgtk_widget_get_toplevel wwebkit_user_script_new wwebkit_user_script_unref wwebkit_web_view_get_type wwebkit_web_view_get_uri wwebkit_web_view_run_javascript " ]; then
|
||||
echo "$lib must need nothing but weak GLib, GTK and WebKit calls" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -11,7 +11,11 @@ export MOZ_DISABLE_CONTENT_SANDBOX=1 MOZ_DISABLE_GMP_SANDBOX=1 MOZ_DISABLE_RDD_S
|
||||
export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
|
||||
export MOZ_SHM_NO_SEALS=1
|
||||
export KWIN_COMPOSE=Q QT_QUICK_BACKEND=software LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe
|
||||
export KWIN_USE_OVERLAYS=0
|
||||
[ -e /etc/mpv/mpv.conf ] || { mkdir -p /etc/mpv && echo gpu-sw=yes >/etc/mpv/mpv.conf; } 2>/dev/null
|
||||
for conf in client client-rt; do
|
||||
mkdir -p "/etc/pipewire/$conf.conf.d" && printf 'context.properties = {\n module.rt = false\n}\n' >"/etc/pipewire/$conf.conf.d/droiddeck-rt.conf"
|
||||
done 2>/dev/null
|
||||
export DROIDDECK_NESTED_SCALE=1
|
||||
export DROIDDECK_GLTHREAD=${mesa_glthread:-}
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 mesa_glthread
|
||||
@@ -32,7 +36,7 @@ cat > /usr/share/applications/droiddeck-steam-x64.desktop <<'ENTRY'
|
||||
Type=Application
|
||||
Name=Steam x86-64 (FEX, experimental)
|
||||
Comment=Valve's x86-64 Linux client under FEX, in its own home with its own login
|
||||
Exec=qterminal -e /usr/local/bin/droiddeck-steam-x64
|
||||
Exec=konsole -e /usr/local/bin/droiddeck-steam-x64
|
||||
Icon=steam
|
||||
Categories=System;
|
||||
ENTRY
|
||||
@@ -40,6 +44,20 @@ python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 | sed 's/^/[pads] /'
|
||||
( while sleep 30; do python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 | sed 's/^/[pads] /'; done ) &
|
||||
python3 /usr/local/bin/droiddeck-desktop-gpu 2>&1 | sed 's/^/[gpu] /'
|
||||
/usr/local/bin/droiddeck-desktop-window-rules 2>&1 | sed 's/^/[rules] /'
|
||||
( python3 /usr/local/bin/droiddeck-library-perms 2>&1 | sed 's/^/[perms] /' ) &
|
||||
mkdir -p /usr/local/share/applications
|
||||
cat > /usr/local/share/applications/droiddeck-ime.desktop <<'ENTRY'
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Android keyboard
|
||||
Exec=/usr/local/bin/droiddeck-ime
|
||||
NoDisplay=true
|
||||
X-KDE-Wayland-VirtualKeyboard=true
|
||||
ENTRY
|
||||
input_method=$(kreadconfig6 --file kwinrc --group Wayland --key InputMethod 2>/dev/null)
|
||||
case $input_method in
|
||||
''|*/droiddeck-ime.desktop) kwriteconfig6 --file kwinrc --group Wayland --key InputMethod /usr/local/share/applications/droiddeck-ime.desktop ;;
|
||||
esac
|
||||
python3 /usr/local/bin/droiddeck-open --install 2>&1 | sed 's/^/[open] /'
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
[ -e /etc/xdg/kiorc ] || printf '[Executable scripts]\nbehaviourOnLaunch=execute\n' >/etc/xdg/kiorc 2>/dev/null
|
||||
@@ -52,6 +70,19 @@ if [ ! -e "$HOME/.config/droiddeck-desktop-icons" ]; then
|
||||
touch "$HOME/.config/droiddeck-desktop-icons"
|
||||
fi
|
||||
[ -f "$desktop_dir/Return.desktop" ] && cp -f /usr/share/applications/droiddeck-return-gaming.desktop "$desktop_dir/Return.desktop" 2>/dev/null
|
||||
if command -v flatpak >/dev/null 2>&1 && [ ! -d /var/lib/pacman ]; then
|
||||
FLATPAK_BWRAP=/usr/local/bin/droiddeck-bwrap flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >/dev/null 2>&1 &
|
||||
fi
|
||||
skel_done=$HOME/.local/share/droiddeck/skel-copied
|
||||
if [ -d /etc/skel ] && [ ! -e "$skel_done" ]; then
|
||||
cp -rn /etc/skel/. "$HOME/" 2>/dev/null
|
||||
mkdir -p "${skel_done%/*}" && : > "$skel_done"
|
||||
fi
|
||||
if [ -x /usr/lib/snapd/snap-confine ] && [ ! -d /var/lib/pacman ]; then
|
||||
/usr/local/bin/droiddeck-snapd >/dev/null 2>&1 &
|
||||
export XDG_DATA_DIRS=/var/lib/snapd/desktop:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
|
||||
export PATH=$PATH:/snap/bin
|
||||
fi
|
||||
update-mime-database /usr/share/mime >/dev/null 2>&1 &
|
||||
[ -f /usr/share/icons/hicolor/icon-theme.cache ] || gtk-update-icon-cache -q -t /usr/share/icons/hicolor 2>/dev/null &
|
||||
[ -f /usr/share/glib-2.0/schemas/gschemas.compiled ] || glib-compile-schemas /usr/share/glib-2.0/schemas 2>/dev/null
|
||||
@@ -79,12 +110,16 @@ if [ "$(cat /usr/share/droiddeck/kwin-compositor 2>/dev/null)" = opengl ]; then
|
||||
if [ -z "${KWIN_RENDER_NODES:-}" ] && [ -c /dev/dri/renderD0 ]; then
|
||||
export KWIN_RENDER_NODES=/dev/dri/renderD0
|
||||
fi
|
||||
mkdir -p /run/droiddeck/kwin
|
||||
printf '#!/bin/sh\nGALLIUM_THREAD=0 exec /usr/bin/kwin_wayland "$@"\n' > /run/droiddeck/kwin/kwin_wayland
|
||||
chmod 755 /run/droiddeck/kwin/kwin_wayland
|
||||
export PATH=/run/droiddeck/kwin:$PATH
|
||||
fi
|
||||
echo "== droiddeck-desktop: Plasma on $WAYLAND_DISPLAY"
|
||||
dbus-run-session -- startplasma-wayland
|
||||
rc=$?
|
||||
echo "== droiddeck-desktop: Plasma ended ($rc)"
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
if [ "$rc" -eq 0 ] && [ -z "${BL_BOTTOM_DESKTOP:-}" ]; then
|
||||
/usr/local/bin/droiddeck-steam-launch bigpicture
|
||||
sleep 30
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
SYSTEM_DIR = "/usr/share/applications"
|
||||
@@ -9,6 +10,8 @@ FLATPAK_DIR = os.path.join(HOME, ".local/share/flatpak/exports/share/application
|
||||
USER_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
MARK = "X-DroidDeck-GPU=1"
|
||||
SKIP = re.compile(r"^(steam|droiddeck-game-|droiddeck-steam|steamdeck-)", re.I)
|
||||
CHROMIUM_ENV = "env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 ELECTRON_DISABLE_SANDBOX=1 "
|
||||
CHROMIUM_FLAGS = " --no-sandbox --ozone-platform=x11"
|
||||
|
||||
|
||||
def enabled():
|
||||
@@ -16,7 +19,6 @@ def enabled():
|
||||
|
||||
|
||||
def main_group(text):
|
||||
"""The [Desktop Entry] group's lines, and everything after it."""
|
||||
lines = text.splitlines()
|
||||
start = next((i for i, l in enumerate(lines) if l.strip() == "[Desktop Entry]"), None)
|
||||
if start is None:
|
||||
@@ -25,15 +27,40 @@ def main_group(text):
|
||||
return lines[:start + 1], lines[start + 1:end], lines[end:]
|
||||
|
||||
|
||||
def split_program(exec_line):
|
||||
if exec_line.startswith('"'):
|
||||
end = exec_line.find('"', 1)
|
||||
if end < 0:
|
||||
return None, None
|
||||
return exec_line[:end + 1], exec_line[end + 1:]
|
||||
program, _, rest = exec_line.partition(" ")
|
||||
return program, (" " + rest) if rest else ""
|
||||
|
||||
|
||||
def chromium(exec_line):
|
||||
program, _ = split_program(exec_line)
|
||||
if not program:
|
||||
return False
|
||||
program = program.strip('"')
|
||||
path = program if os.path.isabs(program) else shutil.which(program)
|
||||
if not path:
|
||||
return False
|
||||
here = os.path.dirname(os.path.realpath(path))
|
||||
return any(os.path.exists(os.path.join(d, "chrome-sandbox")) for d in (here, os.path.dirname(here)))
|
||||
|
||||
|
||||
def chromium_exec(exec_line):
|
||||
program, rest = split_program(exec_line)
|
||||
return CHROMIUM_ENV + program + CHROMIUM_FLAGS + rest
|
||||
|
||||
|
||||
def gpu_exec(exec_line):
|
||||
"""The Exec that runs a program on the GPU; a Flatpak app goes through its launcher, which
|
||||
keeps it on gamescope's X server instead of the desktop's Wayland socket."""
|
||||
if exec_line.startswith("/usr/bin/flatpak run ") or exec_line.startswith("flatpak run "):
|
||||
exec_line = "/usr/local/bin/droiddeck-flatpak-run " + exec_line.split(" run ", 1)[1]
|
||||
return "droiddeck-gpu " + exec_line
|
||||
|
||||
|
||||
def wrap(text):
|
||||
def wrap(text, gpu_on=True):
|
||||
head, group, rest = main_group(text)
|
||||
if group is None:
|
||||
return None
|
||||
@@ -42,14 +69,30 @@ def wrap(text):
|
||||
if "=" in l and not l.lstrip().startswith("#"):
|
||||
k, v = l.split("=", 1)
|
||||
keys.setdefault(k.strip(), v)
|
||||
cats = set(filter(None, keys.get("Categories", "").split(";")))
|
||||
if not cats & {"Game", "Emulator"}:
|
||||
return None
|
||||
if keys.get("Type", "Application") != "Application" or keys.get("NoDisplay", "").lower() == "true":
|
||||
return None
|
||||
exec_line = keys.get("Exec", "").strip()
|
||||
if not exec_line or exec_line.startswith("droiddeck-gpu "):
|
||||
return None
|
||||
cats = set(filter(None, keys.get("Categories", "").split(";")))
|
||||
gpu = gpu_on and bool(cats & {"Game", "Emulator"})
|
||||
browser = chromium(exec_line)
|
||||
if not gpu and not browser:
|
||||
return None
|
||||
if browser:
|
||||
exec_line = chromium_exec(exec_line)
|
||||
if not gpu:
|
||||
def fix(lines):
|
||||
return ["Exec=" + chromium_exec(l[5:].strip()) if l.startswith("Exec=") and chromium(l[5:].strip()) else l
|
||||
for l in lines]
|
||||
out_group = fix(group)
|
||||
while out_group and not out_group[-1].strip():
|
||||
out_group.pop()
|
||||
out_group.append(MARK)
|
||||
out_rest = fix(rest)
|
||||
if out_rest and out_rest[0].strip():
|
||||
out_rest.insert(0, "")
|
||||
return "\n".join(head + out_group + out_rest) + "\n"
|
||||
out_group = []
|
||||
actions = keys.get("Actions", "")
|
||||
for l in group:
|
||||
@@ -68,7 +111,8 @@ def wrap(text):
|
||||
wrapped_rest = []
|
||||
for l in rest:
|
||||
if l.startswith("Exec=") and not l[5:].startswith("droiddeck-gpu "):
|
||||
l = "Exec=" + gpu_exec(l[5:])
|
||||
action = l[5:].strip()
|
||||
l = "Exec=" + gpu_exec(chromium_exec(action) if chromium(action) else action)
|
||||
wrapped_rest.append(l)
|
||||
if wrapped_rest and wrapped_rest[0].strip():
|
||||
wrapped_rest.insert(0, "")
|
||||
@@ -87,7 +131,7 @@ def main():
|
||||
on = enabled()
|
||||
os.makedirs(USER_DIR, exist_ok=True)
|
||||
written = set()
|
||||
sources = [d for d in (SYSTEM_DIR, LOCAL_DIR, FLATPAK_DIR) if os.path.isdir(d)] if on else []
|
||||
sources = [d for d in (SYSTEM_DIR, LOCAL_DIR, FLATPAK_DIR) if os.path.isdir(d)]
|
||||
for source in sources:
|
||||
for name in sorted(os.listdir(source)):
|
||||
if not name.endswith(".desktop") or SKIP.match(name):
|
||||
@@ -97,7 +141,7 @@ def main():
|
||||
continue
|
||||
try:
|
||||
with open(os.path.join(source, name), encoding="utf-8", errors="replace") as f:
|
||||
text = wrap(f.read())
|
||||
text = wrap(f.read(), on)
|
||||
except OSError:
|
||||
continue
|
||||
if text is None:
|
||||
|
||||
@@ -6,21 +6,42 @@ if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
fi
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
window=0
|
||||
if [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then
|
||||
window=1
|
||||
parent=$WAYLAND_DISPLAY
|
||||
args=(--backend sdl --expose-wayland -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
else
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
fi
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
fi
|
||||
[ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled)
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
if [ "$window" = 1 ]; then
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} in a window on $parent)"
|
||||
else
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
fi
|
||||
export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11
|
||||
unset LIBGL_ALWAYS_SOFTWARE QT_QUICK_BACKEND KWIN_COMPOSE
|
||||
wsi=",${MESA_VK_WSI_DEBUG:-},"
|
||||
while [[ $wsi == *,sw,* ]]; do wsi=${wsi//,sw,/,}; done
|
||||
wsi=${wsi#,}; wsi=${wsi%,}
|
||||
if [ -n "$wsi" ]; then export MESA_VK_WSI_DEBUG=$wsi; else unset MESA_VK_WSI_DEBUG; fi
|
||||
export BL_DESKTOP_GPU_CHILD=1
|
||||
export MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink LIBGL_KOPPER_DRI2=true
|
||||
[ -n "${DROIDDECK_GLTHREAD:-}" ] && export mesa_glthread=$DROIDDECK_GLTHREAD
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
if [ "$window" = 1 ]; then
|
||||
export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-}
|
||||
SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
else
|
||||
gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
fi
|
||||
rc=$?
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc"
|
||||
exit $rc
|
||||
@@ -19,7 +19,6 @@ typedef struct {
|
||||
typedef VkResult (*Enumerate)(const char *, unsigned int *, VkExtensionProperties *);
|
||||
typedef Function (*ProcAddr)(void *, const char *);
|
||||
|
||||
/* The driver cannot enumerate devices for an instance with VK_KHR_display, and gamescope's WSI layer aborts on that. */
|
||||
static const char *const hidden_extensions[] = {
|
||||
"VK_KHR_display",
|
||||
"VK_KHR_get_display_properties2",
|
||||
|
||||
@@ -22,6 +22,7 @@ extern void webkit_web_view_run_javascript(void *view, const char *script, void
|
||||
extern WebKitUserScript *webkit_user_script_new(const char *source, int frames, int time,
|
||||
const char *const *allow, const char *const *block) __attribute__((weak));
|
||||
extern void webkit_user_script_unref(WebKitUserScript *script) __attribute__((weak));
|
||||
extern const char *g_getenv(const char *name) __attribute__((weak));
|
||||
|
||||
static const char NAV_SCRIPT[] =
|
||||
"(()=>{let open=-1e9,arrowAt=-1e9,ringed=null,ringOutline='',ringOffset='',settleTimer=0,settling=false,redirecting=false;"
|
||||
@@ -196,3 +197,45 @@ __attribute__((visibility("default"))) void webkit_user_content_manager_add_scri
|
||||
}
|
||||
next(manager, script);
|
||||
}
|
||||
|
||||
static int starts(const char *text, const char *prefix)
|
||||
{
|
||||
while (*prefix)
|
||||
if (*text++ != *prefix++)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fab_uri(const char *uri)
|
||||
{
|
||||
if (!uri)
|
||||
return 0;
|
||||
if (starts(uri, "https://"))
|
||||
uri += 8;
|
||||
else if (starts(uri, "http://"))
|
||||
uri += 7;
|
||||
else
|
||||
return 0;
|
||||
if (starts(uri, "www."))
|
||||
uri += 4;
|
||||
if (!starts(uri, "fab.com"))
|
||||
return 0;
|
||||
uri += 7;
|
||||
return !*uri || *uri == '/' || *uri == '?' || *uri == '#' || *uri == ':';
|
||||
}
|
||||
|
||||
static int hidden_launcher(void)
|
||||
{
|
||||
const char *hidden = g_getenv ? g_getenv("DROIDDECK_EPIC_HIDDEN") : 0;
|
||||
return hidden && hidden[0] == '1' && !hidden[1];
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) void webkit_web_view_load_uri(void *view, const char *uri)
|
||||
{
|
||||
static void (*next)(void *, const char *);
|
||||
if (!next && dlsym)
|
||||
next = (void (*)(void *, const char *))dlsym((void *)-1l, "webkit_web_view_load_uri");
|
||||
if (!next)
|
||||
return;
|
||||
next(view, hidden_launcher() && fab_uri(uri) ? "about:blank" : uri);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
LD_LIBRARY_PATH=/usr/local/lib/droiddeck-inno
|
||||
export LD_LIBRARY_PATH
|
||||
exec /usr/local/lib/droiddeck-inno/innoextract "$@"
|
||||
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
BIN
Binary file not shown.
+23
@@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
Copyright (C) 2011-2020 Daniel Scharrer <daniel@constexpr.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author(s) be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
@@ -1,22 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""The guest side of the agent bridge (docs/agent-control.md).
|
||||
|
||||
Started by droiddeck-session inside the session, so whatever it runs has the session's own
|
||||
environment: DISPLAY, the games' Xwayland, XDG_RUNTIME_DIR, and the preloads every guest process
|
||||
gets - which is what lets it reach the Steam client's DevTools port, open to guest processes only.
|
||||
|
||||
The app talks to it through files under $BL_LAUNCH_DIR/agent (the session root, the same path on
|
||||
both sides):
|
||||
|
||||
req/<id>.json a request the app wrote (tmp + rename)
|
||||
resp/<id>.json the answer, written the same way
|
||||
hello.json this daemon is up: pid, version, what it can do
|
||||
focus.json gamescope's focus and every server's top-level windows, rewritten on change
|
||||
cdp-port the client's DevTools port, written by droiddeck-session
|
||||
|
||||
Requests: ping, exec, focus, cdp, quit. Each answer is {"ok": true, ...} or
|
||||
{"ok": false, "error": {"code", "message"}}.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import json
|
||||
@@ -72,7 +54,6 @@ class AgentError(Exception):
|
||||
|
||||
|
||||
class X:
|
||||
"""One connection to an Xwayland server. The rootfs has xprop but no python X library."""
|
||||
|
||||
def __init__(self, display):
|
||||
num = display.lstrip(":").split(".")[0]
|
||||
@@ -116,7 +97,6 @@ class X:
|
||||
return buf
|
||||
|
||||
def request(self, data):
|
||||
"""Send one request and return its reply, or None for an X error (a window that went)."""
|
||||
self.s.sendall(data)
|
||||
while True:
|
||||
head = self._read(32)
|
||||
@@ -186,7 +166,6 @@ class X:
|
||||
|
||||
|
||||
def windows(x):
|
||||
"""Top-level windows that are mapped or carry an app id: what gamescope picks focus from."""
|
||||
out = []
|
||||
for win in x.children(x.root):
|
||||
attrs = x.attributes(win)
|
||||
@@ -230,9 +209,6 @@ def displays():
|
||||
|
||||
|
||||
def focus_snapshot():
|
||||
"""gamescope's focus as Steam sees it (root properties on the client's server) and every
|
||||
server's windows. GAMESCOPE_FOCUSABLE_WINDOWS is the list the client orders the base layer
|
||||
from: a game missing there stays behind the client however healthy its window looks."""
|
||||
shown = displays()
|
||||
if not shown:
|
||||
raise AgentError("NO_DISPLAY", "This session has no X display")
|
||||
@@ -259,30 +235,96 @@ def focus_snapshot():
|
||||
STEAM_APP_CLASS = re.compile(r"steam_app_(\d+)$")
|
||||
|
||||
|
||||
def tag_game_windows(snap):
|
||||
if os.environ.get("BL_STEAM_CLIENT_ARCH") != "x86_64":
|
||||
return False
|
||||
def process_env(pid, proc=Path("/proc")):
|
||||
try:
|
||||
return dict(entry.split(b"=", 1) for entry in (proc / str(pid) / "environ").read_bytes().split(b"\0") if b"=" in entry)
|
||||
except OSError:
|
||||
return {}
|
||||
|
||||
|
||||
def steam_app_id(env):
|
||||
try:
|
||||
app = int(env.get(b"SteamAppId", b"0"))
|
||||
except ValueError:
|
||||
return None
|
||||
return app if 0 < app < 2**32 else None
|
||||
|
||||
|
||||
def under_reaper(pid, proc=Path("/proc")):
|
||||
for _ in range(64):
|
||||
try:
|
||||
if (proc / str(pid) / "comm").read_text().strip() == "reaper":
|
||||
return True
|
||||
stat = (proc / str(pid) / "stat").read_text()
|
||||
pid = int(stat[stat.rindex(")") + 2:].split()[1])
|
||||
except (OSError, ValueError, IndexError):
|
||||
return False
|
||||
if pid <= 1:
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def sandboxed_apps(proc=Path("/proc")):
|
||||
apps = {}
|
||||
try:
|
||||
pids = [entry for entry in os.listdir(proc) if entry.isdigit()]
|
||||
except OSError:
|
||||
return apps
|
||||
for pid in pids:
|
||||
env = process_env(pid, proc)
|
||||
flatpak, app = env.get(b"FLATPAK_ID"), steam_app_id(env)
|
||||
if flatpak and app:
|
||||
name = flatpak.decode(errors="replace").lower()
|
||||
for key in {name, name.rsplit(".", 1)[-1]}:
|
||||
apps[key] = app if apps.get(key, app) == app else None
|
||||
return apps
|
||||
|
||||
|
||||
def window_steam_app(win, flatpaks, proc=Path("/proc")):
|
||||
match = STEAM_APP_CLASS.match(win.get("class") or "")
|
||||
if match:
|
||||
return match.group(1) if os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64" else None
|
||||
pid = win.get("pid")
|
||||
if pid:
|
||||
if under_reaper(pid, proc):
|
||||
return None
|
||||
app = steam_app_id(process_env(pid, proc))
|
||||
if app:
|
||||
return str(app)
|
||||
app = flatpaks().get((win.get("class") or "").lower())
|
||||
return str(app) if app else None
|
||||
|
||||
|
||||
def tag_game_windows(snap, proc=Path("/proc")):
|
||||
tagged = False
|
||||
found = []
|
||||
|
||||
def flatpaks():
|
||||
if not found:
|
||||
found.append(sandboxed_apps(proc))
|
||||
return found[0]
|
||||
|
||||
for display, wins in snap.get("displays", {}).items():
|
||||
if display == os.environ.get("DISPLAY"):
|
||||
continue
|
||||
for win in wins:
|
||||
match = STEAM_APP_CLASS.match(win.get("class") or "")
|
||||
if not match or win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect"):
|
||||
if win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect") or win.get("inputOnly"):
|
||||
continue
|
||||
app = window_steam_app(win, flatpaks, proc)
|
||||
if not app:
|
||||
continue
|
||||
try:
|
||||
done = subprocess.run(["xprop", "-display", display, "-id", str(win["window"]), "-f", "STEAM_GAME", "32c",
|
||||
"-set", "STEAM_GAME", match.group(1)],
|
||||
"-set", "STEAM_GAME", app],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5).returncode == 0
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
done = False
|
||||
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, match.group(1), "ok" if done else "failed"))
|
||||
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, app, "ok" if done else "failed"))
|
||||
tagged = tagged or done
|
||||
return tagged
|
||||
|
||||
|
||||
def vr_scene_app(path=Path('/run/droiddeck/droiddeck-steamvr/scene-focus.json'), proc=Path('/proc')):
|
||||
"""Only a live SteamVR scene with its dashboard hidden may claim game focus."""
|
||||
try:
|
||||
state = json.loads(path.read_text())
|
||||
server, scene = int(state['serverPid']), int(state['scenePid'])
|
||||
@@ -318,8 +360,6 @@ class VrSceneFocus:
|
||||
|
||||
|
||||
class FocusWatcher(threading.Thread):
|
||||
"""Rewrites focus.json when gamescope's focus properties change, and every few seconds when
|
||||
the windows do (a window can change without any root property moving)."""
|
||||
|
||||
def __init__(self, path):
|
||||
super().__init__(daemon=True, name="focus")
|
||||
@@ -383,7 +423,6 @@ class FocusWatcher(threading.Thread):
|
||||
|
||||
|
||||
class WebSocket:
|
||||
"""A minimal RFC 6455 client: text frames out, text frames in. Enough for CDP."""
|
||||
|
||||
def __init__(self, url, timeout):
|
||||
target = urllib.parse.urlsplit(url)
|
||||
@@ -538,9 +577,56 @@ KEYBOARD_CHECK_SECONDS = 30
|
||||
KEYBOARD_JS = r"""
|
||||
(() => {
|
||||
const self = window.__droiddeckKeyboard || (window.__droiddeckKeyboard = { watched: new WeakSet(), last: null });
|
||||
self.wrapped = self.wrapped || new WeakSet();
|
||||
self.route = self.route === true;
|
||||
self.wrap = vkm => {
|
||||
if (!vkm || self.wrapped.has(vkm) || typeof vkm.ShowVirtualKeyboard !== "function") return;
|
||||
self.wrapped.add(vkm);
|
||||
const show = vkm.ShowVirtualKeyboard;
|
||||
vkm.ShowVirtualKeyboard = function (ref, props, modal) {
|
||||
if (self.route && !modal && typeof this.SetActiveVirtualKeyboardTarget === "function" &&
|
||||
!this.BUseVRKeyboard?.() && !this.m_Instance?.IsDesktopOverlayWindow?.()) {
|
||||
this.SetActiveVirtualKeyboardTarget(ref, props);
|
||||
self.follow(this);
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__("request");
|
||||
return;
|
||||
}
|
||||
return show.call(this, ref, props, modal);
|
||||
};
|
||||
};
|
||||
self.editing = vkm => {
|
||||
let el = null;
|
||||
try { el = vkm?.m_ownerWindow?.document?.activeElement || null; } catch (e) {}
|
||||
if (!el) return null;
|
||||
return el.tagName === "TEXTAREA" || el.isContentEditable === true ||
|
||||
(el.tagName === "INPUT" && !/^(button|checkbox|radio|range|submit|reset|file|image|color)$/i.test(el.type || ""));
|
||||
};
|
||||
self.follow = vkm => {
|
||||
self.active = vkm;
|
||||
self.missed = 0;
|
||||
self.seen = false;
|
||||
self.follower = self.follower || setInterval(() => {
|
||||
if (!self.active) return;
|
||||
const ref = self.active.m_currentVirtualKeyboardRef;
|
||||
const editing = self.editing(self.active);
|
||||
const valid = !!ref && (editing !== null ? editing :
|
||||
(typeof ref.BIsElementValidForInput !== "function" || ref.BIsElementValidForInput()));
|
||||
if (valid) self.seen = true;
|
||||
if (self.route && ref && (valid || !self.seen)) {
|
||||
self.missed = 0;
|
||||
return;
|
||||
}
|
||||
if (++self.missed < 2) return;
|
||||
self.active = null;
|
||||
clearInterval(self.follower);
|
||||
self.follower = null;
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__("dismiss");
|
||||
}, 150);
|
||||
};
|
||||
self.check = () => {
|
||||
let showing = false;
|
||||
for (const win of Array.from(globalThis.SteamUIStore?.WindowStore?.SteamUIWindows || [])) {
|
||||
self.wrap(win?.VirtualKeyboardManager);
|
||||
const value = win?.VirtualKeyboardManager?.IsShowingVirtualKeyboard;
|
||||
if (!value) continue;
|
||||
if (!self.watched.has(value) && typeof value.Subscribe === "function") {
|
||||
@@ -559,6 +645,29 @@ KEYBOARD_JS = r"""
|
||||
return self.check();
|
||||
})()
|
||||
""".replace("__BINDING__", KEYBOARD_BINDING)
|
||||
KEYBOARD_ROUTE_SECONDS = 0.5
|
||||
KEYBOARD_ROUTE_JS = r"""
|
||||
(route => {
|
||||
const self = window.__droiddeckKeyboard;
|
||||
if (!self) return false;
|
||||
self.route = route;
|
||||
if (!route) return true;
|
||||
for (const win of Array.from(globalThis.SteamUIStore?.WindowStore?.SteamUIWindows || [])) {
|
||||
const vkm = win?.VirtualKeyboardManager;
|
||||
if (vkm?.m_bIsInlineVirtualKeyboardOpen?.m_currentValue === true && vkm?.m_bIsVirtualKeyboardModal?.m_currentValue !== true &&
|
||||
typeof vkm.SetVirtualKeyboardHidden === "function") {
|
||||
const ref = vkm.m_currentVirtualKeyboardRef, props = vkm.m_ActiveElementProps;
|
||||
vkm.SetVirtualKeyboardHidden();
|
||||
if (ref && typeof vkm.SetActiveVirtualKeyboardTarget === "function") {
|
||||
vkm.SetActiveVirtualKeyboardTarget(ref, props);
|
||||
if (typeof self.follow === "function") self.follow(vkm);
|
||||
}
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__("request");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
})(__ROUTE__)
|
||||
""".replace("__BINDING__", KEYBOARD_BINDING)
|
||||
|
||||
|
||||
class KeyboardWatcher(threading.Thread):
|
||||
@@ -566,8 +675,14 @@ class KeyboardWatcher(threading.Thread):
|
||||
super().__init__(daemon=True, name="keyboard")
|
||||
self.agent_dir = agent_dir
|
||||
self.path = agent_dir / "keyboard.json"
|
||||
self.request_path = agent_dir / "keyboard-request.json"
|
||||
self.dismiss_path = agent_dir / "keyboard-dismiss.json"
|
||||
self.dismissals = 0
|
||||
self.route_path = agent_dir / "keyboard-route"
|
||||
self.showing = None
|
||||
self.seq = 0
|
||||
self.requests = 0
|
||||
self.route = None
|
||||
self.next_id = 0
|
||||
self.attached = False
|
||||
|
||||
@@ -578,6 +693,30 @@ class KeyboardWatcher(threading.Thread):
|
||||
self.seq += 1
|
||||
write_json(self.path, {"steamKeyboard": showing, "seq": self.seq})
|
||||
|
||||
def request(self):
|
||||
self.requests += 1
|
||||
write_json(self.request_path, {"seq": self.requests})
|
||||
|
||||
def dismiss(self):
|
||||
self.dismissals += 1
|
||||
write_json(self.dismiss_path, {"seq": self.dismissals})
|
||||
|
||||
def wanted_route(self):
|
||||
try:
|
||||
return self.route_path.read_text().strip() == "bottom"
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
def apply_route(self, ws, force=False):
|
||||
route = self.wanted_route()
|
||||
if route == self.route and not force:
|
||||
return
|
||||
result = self.call(ws, "Runtime.evaluate", {
|
||||
"expression": KEYBOARD_ROUTE_JS.replace("__ROUTE__", "true" if route else "false"), "returnByValue": True})
|
||||
if result.get("exceptionDetails"):
|
||||
raise AgentError("JS_EXCEPTION", json.dumps(result["exceptionDetails"])[:500])
|
||||
self.route = route
|
||||
|
||||
def run(self):
|
||||
failures, last = 0, None
|
||||
while True:
|
||||
@@ -604,10 +743,18 @@ class KeyboardWatcher(threading.Thread):
|
||||
try:
|
||||
self.call(ws, "Runtime.addBinding", {"name": KEYBOARD_BINDING})
|
||||
self.report(self.install(ws))
|
||||
self.apply_route(ws, force=True)
|
||||
self.attached = True
|
||||
installed = time.monotonic()
|
||||
while True:
|
||||
if not ws.buffer and not select.select([ws.s], [], [], KEYBOARD_CHECK_SECONDS)[0]:
|
||||
self.report(self.install(ws))
|
||||
wait = min(KEYBOARD_ROUTE_SECONDS, KEYBOARD_CHECK_SECONDS)
|
||||
if not ws.buffer and not select.select([ws.s], [], [], wait)[0]:
|
||||
if time.monotonic() - installed >= KEYBOARD_CHECK_SECONDS:
|
||||
self.report(self.install(ws))
|
||||
self.apply_route(ws, force=True)
|
||||
installed = time.monotonic()
|
||||
else:
|
||||
self.apply_route(ws)
|
||||
continue
|
||||
self.event(json.loads(ws.recv()))
|
||||
finally:
|
||||
@@ -635,7 +782,12 @@ class KeyboardWatcher(threading.Thread):
|
||||
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")
|
||||
if params.get("payload") == "request":
|
||||
self.request()
|
||||
elif params.get("payload") == "dismiss":
|
||||
self.dismiss()
|
||||
else:
|
||||
self.report(params.get("payload") == "true")
|
||||
|
||||
|
||||
def steam_idle_inhibit(agent_dir, inhibit):
|
||||
@@ -707,11 +859,6 @@ def steam_selection(agent_dir, timeout=5):
|
||||
|
||||
|
||||
def steam_shortcut_app_id(game_id):
|
||||
"""Return the 32-bit app id in Steam's shortcut CGameID form, or None for other ids.
|
||||
|
||||
DroidDeck's shortcut IDs are `(appid << 32) | 0x02000000`. The URL still needs that full
|
||||
CGameID for RunGame; the app-details API separately needs the unsigned 32-bit app id.
|
||||
"""
|
||||
if not isinstance(game_id, str) or not game_id.isascii() or not game_id.isdigit():
|
||||
return None
|
||||
try:
|
||||
@@ -727,7 +874,6 @@ def steam_shortcut_app_id(game_id):
|
||||
|
||||
|
||||
def wait_for_steam_shortcut_overview(agent_dir, game_id, timeout=45):
|
||||
"""Wait until Steam can map a shortcut CGameID to its 32-bit app overview."""
|
||||
app_id = steam_shortcut_app_id(game_id)
|
||||
if app_id is None:
|
||||
return {"supported": False, "ready": False}
|
||||
@@ -782,8 +928,6 @@ def steam_shortcut_state(agent_dir, game_id, timeout=6):
|
||||
|
||||
|
||||
def game_pids(app_id):
|
||||
"""Our processes started for this Steam app (Steam sets SteamAppId / SteamGameId in their
|
||||
environment, and Proton's wine processes inherit it)."""
|
||||
wanted = [("SteamAppId=%s" % app_id).encode(), ("SteamGameId=%s" % app_id).encode()]
|
||||
me = os.getpid()
|
||||
pids = []
|
||||
@@ -842,8 +986,6 @@ VR_ACTIONS = ("status", "install", "start", "stop")
|
||||
|
||||
|
||||
def steamvr(req):
|
||||
"""Cardboard mode's SteamVR: a fixed helper with four actions, unlike exec (no command line from
|
||||
the request). install downloads 571 MB, so it runs detached and status reports it."""
|
||||
action = req.get("action", "status")
|
||||
if action not in VR_ACTIONS:
|
||||
raise AgentError("INVALID_REQUEST", "vr action must be one of " + ", ".join(VR_ACTIONS))
|
||||
@@ -1064,11 +1206,10 @@ def main(argv):
|
||||
if len(argv) != 2 or not argv[1].isascii() or not argv[1].isdecimal():
|
||||
print("usage: droiddeck-agent --steam-supports-vr <appid>", file=sys.stderr)
|
||||
return 2
|
||||
# Optional-VR games (Thumper, VRChat) carry vr_supported without vr_only.
|
||||
expression = ("(o => o ? (o.vr_supported === true || o.vr_only === true) : null)"
|
||||
"(window.appStore?.GetAppOverviewByGameID?.(%s))" % json.dumps(argv[1]))
|
||||
value = None
|
||||
deadline = time.monotonic() + 12 # Steam's UI is busiest while a game starts.
|
||||
deadline = time.monotonic() + 12
|
||||
while value is None and time.monotonic() < deadline:
|
||||
try:
|
||||
value = cdp_eval(Path(base) / "agent", expression, await_promise=False, timeout=8).get("value")
|
||||
|
||||
+1339
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
# KDE Plasma on a dual-screen handheld's bottom screen, next to the session on the top one.
|
||||
set -u
|
||||
export HOME=${HOME:-/root}
|
||||
if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
mkdir -p "$BL_DEBUG_DIR" 2>/dev/null || true
|
||||
exec >>"$BL_DEBUG_DIR/bottom-desktop.log" 2>&1
|
||||
fi
|
||||
echo "== droiddeck-bottom-desktop $(date -u '+%Y-%m-%d %H:%M:%S UTC') ${BL_WIDTH:-?}x${BL_HEIGHT:-?} beside a ${BL_TOP_SESSION:-?} session"
|
||||
[ -x /usr/local/bin/droiddeck-desktop ] || { echo "== the desktop package is not installed"; exit 66; }
|
||||
|
||||
# Launch requests would reach the top session's watcher and could replace it.
|
||||
unset BL_LAUNCH_DIR BL_LOG
|
||||
export BL_BOTTOM_DESKTOP=1
|
||||
|
||||
for _ in $(seq 1 100); do
|
||||
wayland-info >/dev/null 2>&1 && break
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
if command -v dbus-daemon >/dev/null 2>&1 && command -v droiddeck-netmanager >/dev/null 2>&1 \
|
||||
&& ! pgrep -f 'dbus-daemon --config-file=/usr/local/share/droiddeck/system-bus.conf' >/dev/null 2>&1; then
|
||||
mkdir -p /run/dbus /usr/local/share/droiddeck
|
||||
cat > /usr/local/share/droiddeck/system-bus.conf <<'BUSCONF'
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<type>system</type>
|
||||
<listen>unix:path=/run/dbus/system_bus_socket</listen>
|
||||
<auth>EXTERNAL</auth>
|
||||
<servicedir>/usr/share/droiddeck/system-services</servicedir>
|
||||
<policy context="default">
|
||||
<allow user="*"/>
|
||||
<allow own="*"/>
|
||||
<allow send_destination="*"/>
|
||||
<allow receive_sender="*"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
BUSCONF
|
||||
rm -f /run/dbus/system_bus_socket
|
||||
dbus-daemon --config-file=/usr/local/share/droiddeck/system-bus.conf --nofork --nopidfile &
|
||||
for _ in $(seq 1 50); do
|
||||
[ -S /run/dbus/system_bus_socket ] && break
|
||||
sleep 0.1
|
||||
done
|
||||
[ -S /run/dbus/system_bus_socket ] && droiddeck-login1 --with-netmanager &
|
||||
fi
|
||||
|
||||
# The game on the top screen keeps the CPU first.
|
||||
renice -n 5 $$ >/dev/null 2>&1 || true
|
||||
exec /usr/local/bin/droiddeck-desktop
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
import base64
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
SOCKET_FILE = "/etc/droiddeck/bwrap-socket"
|
||||
@@ -22,6 +24,11 @@ def socket_name():
|
||||
|
||||
|
||||
SOCKET = socket_name()
|
||||
FEX_DIR = "/run/droiddeck-fex"
|
||||
OWN_FEX = "/usr/local"
|
||||
X86_MACHINES = (3, 62)
|
||||
ARM_LIBS = "/usr/lib/aarch64-linux-gnu"
|
||||
ARM_LOADER = "/usr/lib/ld-linux-aarch64.so.1"
|
||||
VERSION = "bubblewrap 0.11.0 (droiddeck)"
|
||||
|
||||
NO_ARG = {
|
||||
@@ -61,7 +68,6 @@ def fd_path(fd):
|
||||
|
||||
|
||||
def expand(argv):
|
||||
"""argv with every --args FD replaced by the NUL-separated arguments read from FD."""
|
||||
out = []
|
||||
i = 0
|
||||
while i < len(argv):
|
||||
@@ -87,8 +93,10 @@ class Spec:
|
||||
self.info_fds = []
|
||||
self.json_fds = []
|
||||
self.keep_fds = []
|
||||
self.lock_files = []
|
||||
self.command = []
|
||||
self.argv0 = None
|
||||
self.env_tool = None
|
||||
|
||||
|
||||
def parse(argv):
|
||||
@@ -159,6 +167,8 @@ def parse(argv):
|
||||
read_fd(int(args[0]))
|
||||
elif a == "--sync-fd":
|
||||
s.keep_fds.append(int(args[0]))
|
||||
elif a == "--lock-file":
|
||||
s.lock_files.append(args[0])
|
||||
elif a == "--info-fd":
|
||||
s.info_fds.append(int(args[0]))
|
||||
elif a == "--json-status-fd":
|
||||
@@ -177,7 +187,6 @@ def real(path):
|
||||
|
||||
|
||||
def remaps_nothing(s):
|
||||
"""True when every path in the sandbox is what it is out here already."""
|
||||
for op in s.ops:
|
||||
t = op["t"]
|
||||
if t == "bind":
|
||||
@@ -203,6 +212,159 @@ def remaps_nothing(s):
|
||||
return True
|
||||
|
||||
|
||||
def host_path(s, path):
|
||||
for op in reversed(s.ops):
|
||||
if op["t"] != "bind":
|
||||
continue
|
||||
dest = op["dest"].rstrip("/")
|
||||
if path == dest or path.startswith(dest + "/"):
|
||||
return op["src"].rstrip("/") + path[len(dest):]
|
||||
return path
|
||||
|
||||
|
||||
def sandbox_link(s, path):
|
||||
for op in reversed(s.ops):
|
||||
if op.get("dest", "").rstrip("/") != path:
|
||||
continue
|
||||
if op["t"] == "symlink":
|
||||
return op["target"]
|
||||
if op["t"] == "bind":
|
||||
return None
|
||||
break
|
||||
here = sandbox_source(s, path)
|
||||
return os.readlink(here) if os.path.islink(here) else None
|
||||
|
||||
|
||||
def sandbox_source(s, path):
|
||||
for op in reversed(s.ops):
|
||||
if op["t"] != "bind":
|
||||
continue
|
||||
dest = op["dest"].rstrip("/")
|
||||
if path == dest or path.startswith(dest + "/"):
|
||||
return real(op["src"]).rstrip("/") + path[len(dest):]
|
||||
return path
|
||||
|
||||
|
||||
def sandbox_file(s, path):
|
||||
parts = [p for p in path.split("/") if p]
|
||||
done = "/"
|
||||
hops = 0
|
||||
i = 0
|
||||
while i < len(parts):
|
||||
step = os.path.join(done, parts[i])
|
||||
link = sandbox_link(s, step)
|
||||
if link is None:
|
||||
done = step
|
||||
i += 1
|
||||
continue
|
||||
hops += 1
|
||||
if hops > 40:
|
||||
return None
|
||||
base = "/" if link.startswith("/") else done
|
||||
parts = [p for p in os.path.normpath(os.path.join(base, link)).split("/") if p] + parts[i + 1:]
|
||||
done = "/"
|
||||
i = 0
|
||||
here = sandbox_source(s, done)
|
||||
return here if os.path.isfile(here) else None
|
||||
|
||||
|
||||
def program_path(s, program):
|
||||
if "/" in program:
|
||||
return os.path.normpath(os.path.join(s.cwd or "/", program))
|
||||
for folder in s.env.get("PATH", "/usr/bin:/bin").split(":"):
|
||||
if not folder:
|
||||
continue
|
||||
candidate = os.path.normpath(os.path.join(s.cwd or "/", folder, program))
|
||||
if sandbox_file(s, candidate):
|
||||
return candidate
|
||||
return None
|
||||
|
||||
|
||||
def machine(s, path, depth=0):
|
||||
here = sandbox_file(s, path)
|
||||
if here is None:
|
||||
return None
|
||||
try:
|
||||
with open(here, "rb") as f:
|
||||
head = f.read(256)
|
||||
except OSError:
|
||||
return None
|
||||
if head[:4] == b"\x7fELF" and len(head) >= 20:
|
||||
return struct.unpack("<H" if head[5] == 1 else ">H", head[18:20])[0]
|
||||
if head[:2] == b"#!" and depth < 4:
|
||||
words = head[2:].split(b"\n")[0].split()
|
||||
if words:
|
||||
return machine(s, words[0].decode("utf-8", "replace"), depth + 1)
|
||||
return None
|
||||
|
||||
|
||||
def own_fex():
|
||||
return all(os.access(os.path.join(OWN_FEX, "bin", name), os.X_OK) for name in ("FEX", "FEXServer")) \
|
||||
and os.path.isfile(os.path.join(OWN_FEX, "lib", "libxxhash.so.0"))
|
||||
|
||||
|
||||
def fex_ready():
|
||||
if own_fex():
|
||||
return True
|
||||
try:
|
||||
subprocess.call([os.path.join(OWN_FEX, "bin", "droiddeck-fex-update")], stdout=sys.stderr)
|
||||
except OSError:
|
||||
return False
|
||||
return own_fex()
|
||||
|
||||
|
||||
def start_fex_server():
|
||||
try:
|
||||
subprocess.Popen([os.path.join(OWN_FEX, "bin", "FEXServer"), "-p", "30"], stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
except OSError as e:
|
||||
sys.stderr.write("bwrap: could not start FEXServer: %s\n" % e)
|
||||
|
||||
|
||||
def through_fex(s):
|
||||
program = program_path(s, s.command[0])
|
||||
if program is None or machine(s, program) not in X86_MACHINES:
|
||||
return False
|
||||
if not fex_ready():
|
||||
sys.stderr.write("bwrap: %s is an x86 program and FEX is not installed\n" % program)
|
||||
return False
|
||||
for src, dest in ((os.path.join(OWN_FEX, "bin", "FEX"), FEX_DIR + "/bin/FEX"),
|
||||
(os.path.join(OWN_FEX, "bin", "FEXServer"), FEX_DIR + "/bin/FEXServer"),
|
||||
(os.path.join(OWN_FEX, "lib", "libxxhash.so.0"), FEX_DIR + "/lib/libxxhash.so.0"),
|
||||
("/usr/bin/env", FEX_DIR + "/bin/env"),
|
||||
(ARM_LIBS, ARM_LIBS),
|
||||
(real(ARM_LOADER), ARM_LOADER)):
|
||||
s.ops.append({"t": "bind", "src": src, "dest": dest, "try": False, "ro": True})
|
||||
data = s.env.get("XDG_CACHE_HOME") or "/tmp"
|
||||
s.env["FEX_APP_CONFIG_LOCATION"] = FEX_DIR + "/config/"
|
||||
s.env["FEX_APP_DATA_LOCATION"] = data + "/droiddeck-fex/"
|
||||
s.env["FEX_APP_CACHE_LOCATION"] = data + "/droiddeck-fex/cache/"
|
||||
for name in ("FEX_ROOTFS", "FEX_THUNKHOSTLIBS", "FEX_THUNKGUESTLIBS", "FEX_THUNKCONFIG", "FEX_PORTABLE",
|
||||
"GLIBC_TUNABLES", "MESA_LOADER_DRIVER_OVERRIDE", "GALLIUM_DRIVER", "VK_ICD_FILENAMES",
|
||||
"VK_DRIVER_FILES"):
|
||||
s.env.pop(name, None)
|
||||
s.command = [FEX_DIR + "/bin/FEX", program] + s.command[1:]
|
||||
s.argv0 = None
|
||||
s.env_tool = FEX_DIR + "/bin/env"
|
||||
start_fex_server()
|
||||
return True
|
||||
|
||||
|
||||
def hold_locks(s):
|
||||
for path in s.lock_files:
|
||||
try:
|
||||
fd = os.open(host_path(s, path), os.O_RDONLY)
|
||||
except OSError as e:
|
||||
sys.stderr.write("bwrap: Can't open lock file %s: %s\n" % (path, e.strerror))
|
||||
sys.exit(1)
|
||||
try:
|
||||
fcntl.lockf(fd, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
except OSError as e:
|
||||
sys.stderr.write("bwrap: Can't lock file %s: %s\n" % (path, e.strerror))
|
||||
sys.exit(1)
|
||||
os.set_inheritable(fd, True)
|
||||
|
||||
|
||||
def report_pid(s, pid):
|
||||
for fd in s.info_fds:
|
||||
try:
|
||||
@@ -261,6 +423,8 @@ def run_by_app(s):
|
||||
if s.argv0:
|
||||
argv[0] = s.argv0
|
||||
request = {"argv": argv, "env": s.env, "cwd": s.cwd or "/", "ops": ops}
|
||||
if s.env_tool:
|
||||
request["envTool"] = s.env_tool
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock.connect(SOCKET)
|
||||
@@ -282,7 +446,7 @@ def run_by_app(s):
|
||||
if payload is None:
|
||||
break
|
||||
if kind == b"P":
|
||||
report_pid(s, int(payload))
|
||||
report_pid(s, os.getpid())
|
||||
elif kind == b"O":
|
||||
out.write(payload)
|
||||
out.flush()
|
||||
@@ -301,10 +465,12 @@ def run_by_app(s):
|
||||
|
||||
def main():
|
||||
s = parse(expand(sys.argv[1:]))
|
||||
hold_locks(s)
|
||||
if remaps_nothing(s):
|
||||
run_here(s)
|
||||
else:
|
||||
run_by_app(s)
|
||||
return
|
||||
through_fex(s)
|
||||
run_by_app(s)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Expose available Steam libraries in Dolphin, retaining the old PCManFM bookmark."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -13,6 +12,7 @@ import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
LIBRARY = Path("/mnt/droiddeck-sd")
|
||||
ADDED = Path("/mnt/droiddeck-lib")
|
||||
URI = "file:///mnt/droiddeck-sd"
|
||||
KDE_OWNER = "http://www.kde.org"
|
||||
MARK = "DroidDeckSteamLibrary"
|
||||
@@ -43,7 +43,7 @@ def steam_libraries(home, data):
|
||||
if not isinstance(path, str):
|
||||
continue
|
||||
path = Path(re.sub(r'\\(["\\])', r'\1', path))
|
||||
managed = path == LIBRARY or path.is_relative_to(home / "Games")
|
||||
managed = path == LIBRARY or path.is_relative_to(home / "Games") or path.is_relative_to(ADDED)
|
||||
if selected is not None and managed and path not in selected:
|
||||
continue
|
||||
if path == LIBRARY and selected is None and not os.environ.get("BL_LIBRARY_LABEL"):
|
||||
|
||||
@@ -8,7 +8,7 @@ X64 = os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64"
|
||||
CLIENT_HOME = (os.environ.get("BL_X64_HOME") or os.path.join(HOME, ".droiddeck-x64")) if X64 else HOME
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(CLIENT_HOME, ".local/share/Steam")
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd/x86-64" if X64 else "/mnt/droiddeck-sd", "SD Games"))
|
||||
NOT_GAMES = {228980, 1070560, 1391110, 1493710, 1628350, 3127680, 4183110, 4185400, 4427310, 4628740}
|
||||
NOT_GAMES = {228980, 1070560, 1161040, 1391110, 1493710, 1628350, 1826330, 3127680, 4183110, 4185400, 4427310, 4628740}
|
||||
APPS_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
PREFIX = "droiddeck-game-"
|
||||
NAME = re.compile(r'^\s*"name"\s*"([^"]*)"', re.M)
|
||||
@@ -54,7 +54,6 @@ def icon_for(appid):
|
||||
|
||||
|
||||
def client_entries():
|
||||
"""App ids the client already wrote a menu entry for."""
|
||||
found = set()
|
||||
if not os.path.isdir(APPS_DIR):
|
||||
return found
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
free_name() {
|
||||
local dir=$1 name=$2 base ext n=2
|
||||
[ -e "$dir/$name" ] || { echo "$name"; return; }
|
||||
base=${name%.*} ext=
|
||||
[ "$base" != "$name" ] && [ -n "$base" ] && ext=.${name##*.} || base=$name
|
||||
while [ -e "$dir/$base ($n)$ext" ]; do n=$((n + 1)); done
|
||||
echo "$base ($n)$ext"
|
||||
}
|
||||
share() {
|
||||
local android=$HOME/Storage/$1 link=$HOME/$2 f
|
||||
[ -d "$android" ] && [ -w "$android" ] || return 0
|
||||
[ "$(readlink "$link" 2>/dev/null)" = "$android" ] && return 0
|
||||
if [ -L "$link" ]; then
|
||||
rm -f "$link"
|
||||
elif [ -d "$link" ]; then
|
||||
shopt -s dotglob nullglob
|
||||
for f in "$link"/*; do
|
||||
mv -n -- "$f" "$android/$(free_name "$android" "${f##*/}")" || return 1
|
||||
done
|
||||
shopt -u dotglob nullglob
|
||||
rmdir "$link" 2>/dev/null || mv "$link" "$link.old.$$" || return 1
|
||||
elif [ -e "$link" ]; then
|
||||
mv "$link" "$link.old.$$" || return 1
|
||||
fi
|
||||
ln -s "$android" "$link"
|
||||
}
|
||||
status=0
|
||||
share Download Downloads || status=1
|
||||
share Documents Documents || status=1
|
||||
exit $status
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
export FLATPAK_BWRAP=/usr/local/bin/droiddeck-bwrap
|
||||
cores="libretro-core-info libretro-beetle-pce-fast libretro-beetle-psx libretro-beetle-vb libretro-beetle-wswan
|
||||
libretro-bsnes-mercury-performance libretro-desmume libretro-gambatte libretro-genesisplusgx libretro-mgba
|
||||
libretro-nestopia libretro-sameboy libretro-snes9x"
|
||||
case "${1:-}" in
|
||||
install)
|
||||
echo "== STEP RetroArch"
|
||||
droiddeck-root /usr/bin/apt-get update -q || { echo "== FAIL apt-get update"; exit 1; }
|
||||
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; }
|
||||
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; }
|
||||
;;
|
||||
*)
|
||||
echo "usage: droiddeck-emulators install" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
@@ -100,6 +100,10 @@ CLIENT_ENV = {
|
||||
"JSC_useDFGJIT": "0",
|
||||
"JSC_useFTLJIT": "0",
|
||||
}
|
||||
HIDDEN_ENV = {
|
||||
"DROIDDECK_EPIC_HIDDEN": "1",
|
||||
"EGL_DISABLE_STORE_PREWARM": "1",
|
||||
}
|
||||
KEPT_ENV = ("HOME", "USER", "LOGNAME", "LANG", "LANGUAGE", "LC_ALL", "LC_MESSAGES", "TZ", "XDG_RUNTIME_DIR", "BL_LAUNCH_DIR")
|
||||
LAUNCH_VERBS = ("waitforexitandrun", "run", "runinprefix")
|
||||
EPIC_ARGS = ("-auth_", "-epic")
|
||||
@@ -725,7 +729,7 @@ def fex_environment(fex, files, env):
|
||||
return result
|
||||
|
||||
|
||||
def client_environment(base, fex, files, display, bus, broker, a11y=None):
|
||||
def client_environment(base, fex, files, display, bus, broker, a11y=None, hidden=False):
|
||||
env = {name: base[name] for name in KEPT_ENV if base.get(name)}
|
||||
env.setdefault("HOME", HOME)
|
||||
env.setdefault("LANG", "C.UTF-8")
|
||||
@@ -734,6 +738,8 @@ def client_environment(base, fex, files, display, bus, broker, a11y=None):
|
||||
env["DBUS_SESSION_BUS_ADDRESS"] = bus
|
||||
env[BROKER_ENV] = broker
|
||||
env.update(CLIENT_ENV)
|
||||
if hidden:
|
||||
env.update(HIDDEN_ENV)
|
||||
if a11y:
|
||||
for name in A11Y_OFF:
|
||||
env.pop(name, None)
|
||||
@@ -1248,7 +1254,7 @@ class Session:
|
||||
path = broker_path()
|
||||
self.broker = Broker(path, self.mode, base)
|
||||
write_json(instance_file(), {"pid": os.getpid(), "mode": self.mode, "bus": bus, "broker": path})
|
||||
env = client_environment(base, fex, files, display, bus, path, self.a11y)
|
||||
env = client_environment(base, fex, files, display, bus, path, self.a11y, hidden=self.mode == "hidden")
|
||||
self.command = [fex["bin"], os.path.join(app_dir, "AppRun")]
|
||||
self.env = env
|
||||
say("starting the Epic Games Launcher %s (%s, display %s)" % (current.get("app"), self.mode, display))
|
||||
|
||||
@@ -11,6 +11,7 @@ import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
HOME = os.environ.get("HOME") or "/root"
|
||||
STEAM_ROOT = os.path.join(HOME, ".local", "share", "Steam")
|
||||
@@ -27,6 +28,8 @@ PRELOADS = "/usr/local/lib/droiddeck-fex"
|
||||
URUNTIME = "/usr/local/lib/droiddeck/uruntime"
|
||||
HOST_PRELOAD = "/etc/ld.so.preload"
|
||||
FEX_APPID = "3127680"
|
||||
OWN_FEX = "/usr/local"
|
||||
OWN_FEX_TAG = os.path.join(OWN_FEX, "share", "fex-emu", ".droiddeck-tag")
|
||||
SNIPER_APPID = "1628350"
|
||||
SLR4_APPID = "4183110"
|
||||
INSTALL_DIRS = {FEX_APPID: "FEX-Emu", SNIPER_APPID: "SteamLinuxRuntime_sniper", SLR4_APPID: "SteamLinuxRuntime_4"}
|
||||
@@ -152,8 +155,52 @@ def first_dir(prefix, candidates):
|
||||
return None
|
||||
|
||||
|
||||
def own_fex_loads():
|
||||
for name in ("FEX", "FEXServer"):
|
||||
binary = os.path.join(OWN_FEX, "bin", name)
|
||||
if not os.access(binary, os.X_OK):
|
||||
return False
|
||||
try:
|
||||
listed = subprocess.run(["/usr/lib/ld-linux-aarch64.so.1", "--list", binary],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=20)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return False
|
||||
if listed.returncode != 0 or b"not found" in listed.stdout:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def update_own_fex():
|
||||
wanted = os.environ.get("BL_FEX_TAG")
|
||||
if not wanted:
|
||||
return
|
||||
if (read_text(OWN_FEX_TAG) or "").strip() == wanted and own_fex_loads():
|
||||
return
|
||||
failed = os.path.join(STATE, "update-failed")
|
||||
try:
|
||||
if (read_text(failed) or "").strip() == wanted and time.time() - os.path.getmtime(failed) < 3600:
|
||||
return
|
||||
except OSError:
|
||||
pass
|
||||
say("installing DroidDeck's FEX build %s" % wanted)
|
||||
try:
|
||||
code = subprocess.call([os.path.join(BIN_DIR, "droiddeck-fex-update")], stdout=sys.stderr)
|
||||
except OSError:
|
||||
code = 1
|
||||
if code == 0:
|
||||
with contextlib.suppress(OSError):
|
||||
os.remove(failed)
|
||||
return
|
||||
with contextlib.suppress(OSError):
|
||||
with open(failed, "w", encoding="utf-8") as handle:
|
||||
handle.write(wanted + "\n")
|
||||
say("DroidDeck's FEX build %s did not install; using the FEX already here" % wanted)
|
||||
|
||||
|
||||
def fex_install():
|
||||
prefixes = []
|
||||
if os.path.isfile(OWN_FEX_TAG) and own_fex_loads():
|
||||
prefixes.append((OWN_FEX, False))
|
||||
tool = app_dir(FEX_APPID)
|
||||
if tool:
|
||||
prefixes += [(os.path.join(tool, sub), True) for sub in ("usr", "", "files/usr", "files")]
|
||||
@@ -282,7 +329,6 @@ def mirror(source, provider, name, target):
|
||||
|
||||
|
||||
def build_rootfs(base, provider):
|
||||
"""The runtime with glibc and libstdc++ taken from a newer one, which FEX's GL and Vulkan thunks are built against."""
|
||||
base_files, provider_files = os.path.join(base, "files"), os.path.join(provider, "files")
|
||||
rootfs = os.path.join(STATE, "rootfs")
|
||||
stamp = "%d\n%s\n%s%s\n%s" % (ROOTFS_LAYOUT, os.path.realpath(base), read_text(os.path.join(base_files, MARKER)) or "",
|
||||
@@ -384,8 +430,6 @@ def link_steam_sdk():
|
||||
|
||||
|
||||
def link_guest_sdk(root):
|
||||
# Proton's lsteamclient only looks in $HOME/.steam/sdk64; on ARM Steam that is the arm64 client, so
|
||||
# the x86 runtime gets its own link, which FEX resolves before the host path.
|
||||
for sdk, candidates in (("sdk64", ("linux64", "ubuntu12_64")), ("sdk32", ("linux32", "ubuntu12_32"))):
|
||||
want = "x86_64" if sdk == "sdk64" else "i386"
|
||||
directory = next((os.path.join(STEAM_ROOT, candidate) for candidate in candidates
|
||||
@@ -445,6 +489,7 @@ def describe(fex, platform, graphics=None):
|
||||
|
||||
def prepare(app=SNIPER_APPID):
|
||||
with locked():
|
||||
update_own_fex()
|
||||
fex = fex_install()
|
||||
platform = runtime_platform(app)
|
||||
status = describe(fex, platform)
|
||||
@@ -564,17 +609,13 @@ def guest_environment(fex, env):
|
||||
result["FEX_APP_CONFIG_LOCATION"] = CONFIG_DIR + "/"
|
||||
result["FEX_APP_DATA_LOCATION"] = data + "/"
|
||||
result["FEX_APP_CACHE_LOCATION"] = CACHE_DIR + "/"
|
||||
# Valve's FEX-Emu binds its server socket under $STEAM_COMPAT_DATA_PATH/fex-emu whatever FEX_APP_DATA_LOCATION or
|
||||
# FEX_SERVERSOCKETPATH say, and sun_path is 108 bytes: compatdata under the app's data folder is too long.
|
||||
if result.get("STEAM_COMPAT_DATA_PATH"):
|
||||
short = data if data != DATA_DIR else "/tmp/fex"
|
||||
os.makedirs(short, exist_ok=True)
|
||||
result["STEAM_COMPAT_DATA_PATH"] = short
|
||||
result.setdefault("FEX_SILENTLOG", "0")
|
||||
result.setdefault("FEX_OUTPUTLOG", "stderr")
|
||||
# The session's tunables are for the host libc; an x86 ld.so copying them under FEX fails in sbrk.
|
||||
result.pop("GLIBC_TUNABLES", None)
|
||||
# Mono's incremental Boehm collector corrupts its heap under FEX, so Unity games crash at their first collections.
|
||||
result.setdefault("GC_DISABLE_INCREMENTAL", "1")
|
||||
if fex["portable"]:
|
||||
result["FEX_PORTABLE"] = "1"
|
||||
@@ -589,7 +630,8 @@ def guest_environment(fex, env):
|
||||
result["FEX_THUNKHOSTLIBS"] = fex["host_thunks"]
|
||||
result["FEX_THUNKGUESTLIBS"] = fex["guest_thunks"]
|
||||
result["FEX_THUNKCONFIG"] = os.path.join(CONFIG_DIR, "ThunksConfig.json")
|
||||
preload = [part for part in split_paths(result.get("LD_PRELOAD")) if os.path.exists(part) and not is_arm(part)]
|
||||
preload = [part for part in split_paths(result.get("LD_PRELOAD"))
|
||||
if "/" not in part or (os.path.exists(part) and not is_arm(part))]
|
||||
library_path = [part for part in (result.get("LD_LIBRARY_PATH") or "").split(":")
|
||||
if part and "arm64" not in part and "aarch64" not in part]
|
||||
for name, parts in (("LD_PRELOAD", preload), ("LD_LIBRARY_PATH", library_path)):
|
||||
@@ -664,22 +706,32 @@ def launch(command, env, mode, decide=None):
|
||||
folder = decide if decide and os.path.isdir(decide) else os.path.dirname(program)
|
||||
if thunks == "on" and x86_64 and os.path.isfile(os.path.join(PRELOADS, "x86_64", VULKAN_PIN)) \
|
||||
and vulkan_thunk_loads(fex, folder):
|
||||
# Any LD_AUDIT module makes Mono's garbage collector crash under FEX, so the Vulkan thunk is pinned by search path.
|
||||
guest["LD_LIBRARY_PATH"] = ":".join(["/usr/" + VULKAN_PIN_DIR] + split_paths(guest.get("LD_LIBRARY_PATH")))
|
||||
thunks = "on, its own Vulkan loader too"
|
||||
say("running %s with %s (runtime %s, thunks %s)" % (program, fex["bin"], guest.get("FEX_ROOTFS", "none"), thunks))
|
||||
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
|
||||
|
||||
|
||||
def game_environment(env):
|
||||
def game_environment(env, command):
|
||||
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
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
return game_env["apply_config"](env, json.load(source), str(app))
|
||||
fixes = {}
|
||||
game = game_env["Game"](resolve(command[0], env), command[1:])
|
||||
for check in game_env["FIXES"]:
|
||||
found = check(game)
|
||||
if found and found[0]:
|
||||
fixes.update(found[0])
|
||||
say(found[2])
|
||||
try:
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
except FileNotFoundError:
|
||||
config = {"version": 1}
|
||||
return game_env["apply_config"](env, config, str(app), fixes)
|
||||
except FileNotFoundError:
|
||||
return env
|
||||
except Exception as error:
|
||||
@@ -718,6 +770,7 @@ def extracted():
|
||||
|
||||
def want_fex():
|
||||
with locked():
|
||||
update_own_fex()
|
||||
status = describe(fex_install(), runtime_platform(), graphics_platform())
|
||||
if not status["ready"]:
|
||||
request_install()
|
||||
@@ -810,7 +863,7 @@ def main(argv):
|
||||
return 0
|
||||
if not command:
|
||||
return 2
|
||||
return launch(command, game_environment(dict(os.environ)), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
if action == "run":
|
||||
try:
|
||||
mode, decide, command = parse_run(args)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
FEX_TAG=fex-2610-r5
|
||||
FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4
|
||||
FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst
|
||||
|
||||
fex_loads() {
|
||||
local b out
|
||||
for b in FEX FEXServer unsquashfs; do
|
||||
out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue
|
||||
echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2
|
||||
return 1
|
||||
done
|
||||
}
|
||||
|
||||
fex_install() {
|
||||
local tag=$1 sha=$2 urls=$3 dst=/ tmp u f
|
||||
tmp=$(mktemp -d)
|
||||
for u in $urls; do
|
||||
curl -fsSL --retry 2 --connect-timeout 20 --speed-limit 1024 --speed-time 60 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
rm -f "$tmp/fex.tzst"
|
||||
done
|
||||
if [ ! -s "$tmp/fex.tzst" ]; then
|
||||
echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
(cd "$tmp/root" && find . ! -type d) > "$tmp/files"
|
||||
mkdir "$tmp/old"
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then
|
||||
cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; }
|
||||
fi
|
||||
done < "$tmp/files"
|
||||
if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" &&
|
||||
mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then
|
||||
rm -rf "$tmp"
|
||||
return 0
|
||||
fi
|
||||
echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
[ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f"
|
||||
done < "$tmp/files"
|
||||
tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
}
|
||||
|
||||
fex_ready() {
|
||||
local have ok=
|
||||
have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true)
|
||||
[ -x /usr/local/bin/FEX ] && fex_loads / && ok=1
|
||||
if [ -n "${BL_FEX_TAG:-}" ]; then
|
||||
if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi
|
||||
step "downloading FEX ($BL_FEX_TAG)"
|
||||
if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi
|
||||
fi
|
||||
if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi
|
||||
step "downloading FEX ($FEX_TAG)"
|
||||
if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
||||
set -eu
|
||||
step() { echo "== STEP $*" >&2; }
|
||||
fex_ready || exit 1
|
||||
echo "$FEX_NOW ($FEX_FROM)"
|
||||
fi
|
||||
@@ -1,7 +1,15 @@
|
||||
#!/usr/bin/python3
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.parse
|
||||
|
||||
os.environ.setdefault("FLATPAK_BWRAP", "/usr/local/bin/droiddeck-bwrap")
|
||||
|
||||
@@ -11,13 +19,25 @@ gi.require_version("Flatpak", "1.0")
|
||||
from gi.repository import Flatpak, Gio, GLib
|
||||
|
||||
REMOTE = "flathub"
|
||||
SYSTEM_BUS = "/run/dbus/system_bus_socket"
|
||||
BUS_COMMANDS = ("install", "install-bundle", "uninstall", "update", "prune")
|
||||
BUS_CONFIG = """<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<type>system</type>
|
||||
<listen>unix:path=%s</listen>
|
||||
<auth>EXTERNAL</auth>
|
||||
<policy context="default">
|
||||
<allow user="*"/>
|
||||
<allow own="*"/>
|
||||
<allow send_destination="*"/>
|
||||
<allow receive_sender="*"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
"""
|
||||
|
||||
|
||||
def prepare_rootfs():
|
||||
"""Some runtimes (KDE 6.10) ship etc/resolv.conf as a link to /run/host/monitor/resolv.conf.
|
||||
Deploying one, Flatpak removes that link only if GIO reports it existing, and GIO follows it:
|
||||
dangling here, it was left in place and making Flatpak's own link failed ("File exists").
|
||||
With the target present in the rootfs the link resolves and the deploy goes through."""
|
||||
target = "/run/host/monitor/resolv.conf"
|
||||
try:
|
||||
if not os.path.exists(target):
|
||||
@@ -33,6 +53,116 @@ def prepare_rootfs():
|
||||
emit(e="warning", message="could not prepare %s: %s" % (target, err))
|
||||
|
||||
|
||||
def bus_reachable(path):
|
||||
if isinstance(path, tuple):
|
||||
try:
|
||||
socket.create_connection(path, timeout=1).close()
|
||||
return True
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock.connect(path)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
|
||||
def system_bus_paths():
|
||||
address = os.environ.get("DBUS_SYSTEM_BUS_ADDRESS", "")
|
||||
if not address:
|
||||
return [SYSTEM_BUS]
|
||||
paths = []
|
||||
for entry in filter(None, address.split(";")):
|
||||
found = None
|
||||
kind, _, params = entry.partition(":")
|
||||
values = dict(part.partition("=")[::2] for part in params.split(","))
|
||||
if kind == "unix":
|
||||
if values.get("path"):
|
||||
found = urllib.parse.unquote_to_bytes(values["path"])
|
||||
elif values.get("abstract"):
|
||||
found = b"\0" + urllib.parse.unquote_to_bytes(values["abstract"])
|
||||
elif kind == "tcp":
|
||||
port = urllib.parse.unquote(values.get("port", ""))
|
||||
digits = port.lstrip("0")
|
||||
if not re.fullmatch(r"[0-9]+", port, re.ASCII) or not 0 < len(digits) <= 5 or int(digits) > 65535:
|
||||
continue
|
||||
found = (urllib.parse.unquote(values.get("host", "localhost")), int(digits))
|
||||
if found is None:
|
||||
return None
|
||||
paths.append(found)
|
||||
return paths
|
||||
|
||||
|
||||
def system_bus_reachable():
|
||||
paths = system_bus_paths()
|
||||
return paths is None or any(bus_reachable(path) for path in paths)
|
||||
|
||||
|
||||
def stop_system_bus(bus):
|
||||
if not bus:
|
||||
return
|
||||
proc, work, conf, path = bus
|
||||
if proc.poll() is None:
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
remove_bus_files(work, conf, path)
|
||||
|
||||
|
||||
def remove_bus_files(work, conf, path):
|
||||
for name in (path, conf):
|
||||
try:
|
||||
os.unlink(name)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
os.rmdir(work)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def private_system_bus():
|
||||
if system_bus_reachable():
|
||||
return None
|
||||
daemon = shutil.which("dbus-daemon")
|
||||
if not daemon:
|
||||
emit(e="warning", message="no system bus and no dbus-daemon to start one")
|
||||
return None
|
||||
try:
|
||||
work = tempfile.mkdtemp(prefix="droiddeck-flatpak-bus-")
|
||||
except OSError as err:
|
||||
emit(e="warning", message="could not start a private system bus: %s" % err)
|
||||
return None
|
||||
conf = os.path.join(work, "bus.conf")
|
||||
path = os.path.join(work, "bus")
|
||||
try:
|
||||
with open(conf, "w") as f:
|
||||
f.write(BUS_CONFIG % path)
|
||||
proc = subprocess.Popen([daemon, "--config-file=" + conf, "--nofork", "--nopidfile"],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
except OSError as err:
|
||||
remove_bus_files(work, conf, path)
|
||||
emit(e="warning", message="could not start a private system bus: %s" % err)
|
||||
return None
|
||||
bus = (proc, work, conf, path)
|
||||
for _ in range(50):
|
||||
if bus_reachable(path) or proc.poll() is not None:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
if not bus_reachable(path):
|
||||
stop_system_bus(bus)
|
||||
emit(e="warning", message="the private system bus did not start")
|
||||
return None
|
||||
os.environ["DBUS_SYSTEM_BUS_ADDRESS"] = "unix:path=" + path
|
||||
return bus
|
||||
|
||||
|
||||
def emit(**kw):
|
||||
sys.stdout.write(json.dumps(kw) + "\n")
|
||||
sys.stdout.flush()
|
||||
@@ -43,7 +173,6 @@ def installation():
|
||||
|
||||
|
||||
def app_ref(inst, app_id):
|
||||
"""The installed ref of an app, or None."""
|
||||
for ref in inst.list_installed_refs_by_kind(Flatpak.RefKind.APP, None):
|
||||
if ref.get_name() == app_id:
|
||||
return ref
|
||||
@@ -109,21 +238,31 @@ def run(t, state, report_done=True):
|
||||
return 0
|
||||
|
||||
|
||||
def arches():
|
||||
native = Flatpak.get_default_arch()
|
||||
return [native, "x86_64"] if native == "aarch64" else [native]
|
||||
|
||||
|
||||
def install(app_id):
|
||||
inst = installation()
|
||||
arch = Flatpak.get_default_arch()
|
||||
if app_ref(inst, app_id) is not None:
|
||||
emit(e="done", note="already installed")
|
||||
return 0
|
||||
branch, last = None, None
|
||||
for candidate in ("stable", "master"):
|
||||
try:
|
||||
branch = inst.fetch_remote_ref_sync(REMOTE, Flatpak.RefKind.APP, app_id, arch, candidate, None).get_branch()
|
||||
arch, branch, last = None, None, None
|
||||
for candidate_arch in arches():
|
||||
for candidate in ("stable", "master"):
|
||||
try:
|
||||
branch = inst.fetch_remote_ref_sync(REMOTE, Flatpak.RefKind.APP, app_id, candidate_arch, candidate,
|
||||
None).get_branch()
|
||||
arch = candidate_arch
|
||||
break
|
||||
except GLib.Error as err:
|
||||
last = err
|
||||
if branch is not None:
|
||||
break
|
||||
except GLib.Error as err:
|
||||
last = err
|
||||
if branch is None:
|
||||
emit(e="error", message="%s is not on Flathub for %s (%s)" % (app_id, arch, last.message if last else "no branch"))
|
||||
emit(e="error", message="%s is not on Flathub for %s (%s)" % (app_id, " or ".join(arches()),
|
||||
last.message if last else "no branch"))
|
||||
return 1
|
||||
t, state = transaction(inst)
|
||||
t.add_install(REMOTE, "app/%s/%s/%s" % (app_id, arch, branch), None)
|
||||
@@ -137,14 +276,18 @@ def install(app_id):
|
||||
|
||||
|
||||
def install_bundle(path):
|
||||
"""A single-file bundle (flatpak build-bundle), for apps Flathub does not carry."""
|
||||
inst = installation()
|
||||
bundle = Gio.File.new_for_path(path)
|
||||
try:
|
||||
app_id = Flatpak.BundleRef.new(bundle).get_name()
|
||||
ref = Flatpak.BundleRef.new(bundle)
|
||||
app_id = ref.get_name()
|
||||
except GLib.Error as err:
|
||||
emit(e="error", message="%s is not a Flatpak bundle (%s)" % (os.path.basename(path), err.message))
|
||||
return 1
|
||||
if ref.get_arch() not in arches():
|
||||
emit(e="error", code="arch", id=app_id, arch=ref.get_arch(),
|
||||
message="%s is built for %s, not %s" % (app_id, ref.get_arch(), " or ".join(arches())))
|
||||
return 1
|
||||
if app_ref(inst, app_id) is not None:
|
||||
emit(e="done", id=app_id, note="already installed")
|
||||
return 0
|
||||
@@ -242,6 +385,16 @@ def main():
|
||||
cmd, args = sys.argv[1], sys.argv[2:]
|
||||
if cmd in ("install", "install-bundle", "update"):
|
||||
prepare_rootfs()
|
||||
bus = private_system_bus() if cmd in BUS_COMMANDS else None
|
||||
if bus:
|
||||
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(128 + signum))
|
||||
try:
|
||||
return command(cmd, args)
|
||||
finally:
|
||||
stop_system_bus(bus)
|
||||
|
||||
|
||||
def command(cmd, args):
|
||||
if cmd == "install" and args:
|
||||
return install(args[0])
|
||||
if cmd == "install-bundle" and args:
|
||||
|
||||
@@ -3,7 +3,9 @@ set -u
|
||||
export LANG=C.UTF-8
|
||||
step() { echo "== STEP $*"; }
|
||||
fail() { echo "== FAIL $*"; exit 1; }
|
||||
[ "$(id -u)" = 0 ] || fail "needs root: install Flatpak from the launcher's Store, which runs this as root"
|
||||
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
PACKAGES="flatpak ostree appstream libxmlb libmalcontent libfyaml accountsservice composefs xdg-dbus-proxy"
|
||||
while read -r pkg probe; do
|
||||
[ -n "$pkg" ] || continue
|
||||
@@ -24,6 +26,7 @@ NEEDS
|
||||
WORK=/var/cache/droiddeck-flatpak
|
||||
CONF=$WORK/pacman.conf
|
||||
mkdir -p "$WORK/pkg" "$WORK/db" || fail "cannot create $WORK"
|
||||
exec 9>"$WORK/setup.lock" && flock -n 9 || fail "another Flatpak setup is still running"
|
||||
|
||||
OVERSEAS="https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org"
|
||||
MAINLAND=""
|
||||
@@ -48,10 +51,14 @@ if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubrin
|
||||
fi
|
||||
|
||||
step "Reading the package lists"
|
||||
pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy >/dev/null 2>&1 \
|
||||
|| pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1 | tail -3 \
|
||||
|| fail "could not reach the Arch Linux ARM mirrors"
|
||||
[ -f "$WORK/db/sync/extra.db" ] || fail "could not reach the Arch Linux ARM mirrors"
|
||||
rm -f "$WORK/db/db.lck"
|
||||
sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) \
|
||||
|| sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1)
|
||||
if [ ! -f "$WORK/db/sync/extra.db" ]; then
|
||||
printf '%s\n' "$sync_log" | tail -3
|
||||
reason=$(printf '%s\n' "$sync_log" | grep -m1 -i '^error' | cut -c1-160)
|
||||
fail "could not reach the Arch Linux ARM mirrors${reason:+ ($reason)}"
|
||||
fi
|
||||
|
||||
step "Downloading Flatpak"
|
||||
out=$(pacman --config "$CONF" --dbpath "$WORK/db" --cachedir "$WORK/pkg" --noconfirm -Sw -dd $PACKAGES 2>&1)
|
||||
@@ -71,7 +78,13 @@ done
|
||||
mv -f "$WORK/installed.new" "$WORK/installed"
|
||||
find "$WORK/pkg" -type f -mtime +1 -delete 2>/dev/null
|
||||
|
||||
missing=$(for f in /usr/bin/flatpak /usr/lib/libflatpak.so.0 /usr/lib/libostree-1.so.1 /usr/bin/xdg-dbus-proxy; do
|
||||
else
|
||||
command -v flatpak >/dev/null 2>&1 || fail "Flatpak is missing from the runtime"
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
fi
|
||||
missing=$(for f in /usr/bin/flatpak /usr/lib/libflatpak.so.0 /usr/lib/libostree-1.so.1 /usr/lib/aarch64-linux-gnu/libflatpak.so.0 /usr/lib/aarch64-linux-gnu/libostree-1.so.1 /usr/bin/xdg-dbus-proxy; do
|
||||
[ -e "$f" ] || continue
|
||||
ldd "$f" 2>&1 | grep -E 'not found|version .* not found'
|
||||
done | sort -u)
|
||||
[ -z "$missing" ] || { echo "$missing"; fail "Flatpak is missing libraries"; }
|
||||
@@ -91,7 +104,7 @@ Description=Central repository of Flatpak applications
|
||||
Icon=https://dl.flathub.org/repo/logo.svg
|
||||
GPGKey=mQINBFlD2sABEADsiUZUOYBg1UdDaWkEdJYkTSZD68214m8Q1fbrP5AptaUfCl8KYKFMNoAJRBXn9FbE6q6VBzghHXj/rSnA8WPnkbaEWR7xltOqzB1yHpCQ1l8xSfH5N02DMUBSRtD/rOYsBKbaJcOgW0K21sX+BecMY/AI2yADvCJEjhVKrjR9yfRX+NQEhDcbXUFRGt9ZT+TI5yT4xcwbvvTu7aFUR/dH7+wjrQ7lzoGlZGFFrQXSs2WI0WaYHWDeCwymtohXryF8lcWQkhH8UhfNJVBJFgCY8Q6UHkZG0FxMu8xnIDBMjBmSZKwKQn0nwzwM2afskZEnmNPYDI8nuNsSZBZSAw+ThhkdCZHZZRwzmjzyRuLLVFpOj3XryXwZcSefNMPDkZAuWWzPYjxS80cm2hG1WfqrG0Gl8+iX69cbQchb7gbEb0RtqNskTo9DDmO0bNKNnMbzmIJ3/rTbSahKSwtewklqSP/01o0WKZiy+n/RAkUKOFBprjJtWOZkc8SPXV/rnoS2dWsJWQZhuPPtv3tefdDiEyp7ePrfgfKxuHpZES0IZRiFI4J/nAUP5bix+srcIxOVqAam68CbAlPvWTivRUMRVbKjJiGXIOJ78wAMjqPg3QIC0GQ0EPAWwAOzzpdgbnG7TCQetaVV8rSYCuirlPYN+bJIwBtkOC9SWLoPMVZTwQARAQABtC5GbGF0aHViIFJlcG8gU2lnbmluZyBLZXkgPGZsYXRodWJAZmxhdGh1Yi5vcmc+iQJUBBMBCAA+FiEEblwF2XnHba+TwIE1QYTdTZB6fK4FAllD2sACGwMFCRLMAwAFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQQYTdTZB6fK5RJQ/+Ptd4sWxaiAW91FFk7+wmYOkEe1NY2UDNJjEEz34PNP/1RoxveHDt43kYJQ23OWaPJuZAbu+fWtjRYcMBzOsMCaFcRSHFiDIC9aTp4ux/mo+IEeyarYt/oyKb5t5lta6xaAqg7rwt65jW5/aQjnS4h7eFZ+dAKta7Y/fljNrOznUp81/SMcx4QA5G2Pw0hs4Xrxg59oONOTFGBgA6FF8WQghrpR7SnEe0FSEOVsAjwQ13Cfkfa7b70omXSWp7GWfUzgBKyoWxKTqzMN3RQHjjhPJcsQnrqH5enUu4Pcb2LcMFpzimHnUgb9ft72DP5wxfzHGAWOUiUXHbAekfq5iFks8cha/RST6wkxG3Rf44Zn09aOxh1btMcGL+5xb1G0BuCQnA0fP/kDYIPwh9z22EqwRQOspIcvGeLVkFeIfubxpcMdOfQqQnZtHMCabV5Q/Rk9K1ZGc8M2hlg8gHbXMFch2xJ0Wu72eXbA/UY5MskEeBgawTQnQOK/vNm7t0AJMpWK26Qg6178UmRghmeZDj9uNRc3EI1nSbgvmGlpDmCxaAGqaGL1zW4KPW5yN25/qeqXcgCvUjZLI9PNq3Kvizp1lUrbx7heRiSoazCucvHQ1VHUzcPVLUKKTkoTP8okThnRRRsBcZ1+jI4yMWIDLOCT7IW3FePr+3xyuy5eEo9a25Ag0EWUPa7AEQALT/CmSyZ8LWlRYQZKYw417p7Z2hxqd6TjwkwM3IQ1irumkWcTZBZIbBgrSOg6CcXD2oWydCQHWi9qaxhuhEl2bJL5LskmBcMxVdQeD0LLHd8QUnbnnIby8ocvWN1alPfvJFjCUTrmD22U1ycOzRw2lIe4kiQONbOZtdWrVImQQSndjFlisitbmlWHvHm2lOOYy8+GJB7YffVV193hmnBSJffCy4bvkuLxsI+n1DhOzc7MPV3z6HGk4HiEcF0yyt9tCYhpsxHFdBoq2h771HfAcS0s98EVAqYMFnf9em+4cnYpdI6mhIfS1FQiKl6DBAYA8tT3ggla00DurPo0JwX/zN+PaO5h/6O9aCZwV7G6rbkgMuqMergXaf8oP38gr0z+MqWnkfM63Bodq68GP4l4hd02BoFBbDf38TMuGQB14+twJMdfbAxo2MbgluvQgfwHfZ2ca6gyEY+9s/YD1gugLjV+S6CB51WkFNe1z4tAPgJZNxUcKCbeaHNbthl8Hks/pY9RCEseX/EdfzF18epbSjJMPh4DPQXbUoFwmyuYcoBOPmvZHNl9hK7B/1RP8w1ZrXk8qdupC0SNbafX7270B7lMMVImzZetGsM9ypXJ6llhp3FwW09iseNyGJGPsr/dvTMGDXqOPfU/9SAS1LSTY4K9PbRtdrBE318YX8mIk5ABEBAAGJBHIEGAEIACYWIQRuXAXZecdtr5PAgTVBhN1NkHp8rgUCWUPa7AIbAgUJEswDAAJACRBBhN1NkHp8rsF0IAQZAQgAHRYhBFSmzd2JGfsgQgDYrFYnAunj7X7oBQJZQ9rsAAoJEFYnAunj7X7oR6AP/0KYmiAFeqx14Z43/6s2gt3VhxlSd8bmcVV7oJFbMhdHBIeWBp2BvsUf00I0Zl14ZkwCKfLwbbORC2eIxvzJ+QWjGfPhDmS4XUSmhlXxWnYEveSek5Tde+fmu6lqKM8CHg5BNx4GWIX/vdLi1wWJZyhrUwwICAxkuhKxuP2Z1An48930eslTD2GGcjByc27+9cIZjHKa07I/aLffo04V+oMT9/tgzoquzgpVV4jwekADo2MJjhkkPveSNI420bgT+Q7Fi1l0X1aFUniBvQMsaBa27PngWm6xE2ZYvh7nWCdd5g0c0eLIHxWwzV1lZ4Ryx4ITO/VL25ItECcjhTRdYa64sA62MYSaB0x3eR+SihpgP3wSNPFu3MJo6FKTFdi4CBAEmpWHFW7FcRmd+cQXeFrHLN3iNVWryy0HK/CUEJmiZEmpNiXecl4vPIIuyF0zgSCztQtKoMr+injpmQGC/rF/ELBVZTUSLNB350S0Ztvw0FKWDAJSxFmoxt3xycqvvt47rxTrhi78nkk6jATKGyvP55sO+K7Q7Wh0DXA69hvPrYW2eu8jGCdVGxi6HX7L1qcfEd0378S71dZ3g9o6KKl1OsDWWQ6MJ6FGBZedl/ibRfs8p5+sbCX3lQSjEFy3rx6n0rUrXx8U2qb+RCLzJlmC5MNBOTDJwHPcX6gKsUcXZrEQALmRHoo3SrewO41RCr+5nUlqiqV3AohBMhnQbGzyHf2+drutIaoh7Rj80XRh2bkkuPLwlNPf+bTXwNVGse4bej7B3oV6Ae1N7lTNVF4Qh+1OowtGjmfJPWo0z1s6HFJVxoIof9z58Msvgao0zrKGqaMWaNQ6LUeC9g9Aj/9Uqjbo8X54aLiYs8Z1WNc06jKP+gv8AWLtv6CR+l2kLez1YMDucjm7v6iuCMVAmZdmxhg5I/X2+OM3vBsqPDdQpr2TPDLX3rCrSBiS0gOQ6DwN5N5QeTkxmY/7QO8bgLo/Wzu1iilH4vMKW6LBKCaRx5UEJxKpL4wkgITsYKneIt3NTHo5EOuaYk+y2+Dvt6EQFiuMsdbfUjs3seIHsghX/cbPJa4YUqZAL8C4OtVHaijwGo0ymt9MWvS9yNKMyT0JhN2/BdeOVWrHk7wXXJn/ZjpXilicXKPx4udCF76meE+6N2u/T+RYZ7fP1QMEtNZNmYDOfA6sViuPDfQSHLNbauJBo/n1sRYAsL5mcG22UDchJrlKvmK3EOADCQg+myrm8006LltubNB4wWNzHDJ0Ls2JGzQZCd/xGyVmUiidCBUrD537WdknOYE4FD7P0cHaM9brKJ/M8LkEH0zUlo73bY4XagbnCqve6PvQb5G2Z55qhWphd6f4B6DGed86zJEa/RhS
|
||||
REPO
|
||||
if ! flatpak remote-list --user --columns=name 2>/dev/null | grep -qx flathub; then
|
||||
if ! flatpak remote-list --columns=name 2>/dev/null | grep -qx flathub; then
|
||||
out=$(flatpak remote-add --user --if-not-exists flathub "$WORK/flathub.flatpakrepo" 2>&1)
|
||||
rc=$?
|
||||
echo "$out"
|
||||
|
||||
@@ -4,8 +4,10 @@ import json
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
|
||||
@@ -33,12 +35,10 @@ DOTNET_FEX = {
|
||||
"FEX_MEMCPYSETTSOENABLED": "1",
|
||||
"FEX_HALFBARRIERTSOENABLED": "1",
|
||||
"FEX_X87REDUCEDPRECISION": "0",
|
||||
"FEX_MULTIBLOCK": "0",
|
||||
}
|
||||
|
||||
|
||||
def game_files(exe):
|
||||
"""Lower-cased names of the files next to the game's executable and one directory below."""
|
||||
names = set()
|
||||
folder = os.path.dirname(exe)
|
||||
try:
|
||||
@@ -57,7 +57,6 @@ def game_files(exe):
|
||||
|
||||
|
||||
class Game:
|
||||
"""What a fix gets to look at: the executable, its launch arguments and the files beside it."""
|
||||
|
||||
def __init__(self, exe, args):
|
||||
self.exe = exe
|
||||
@@ -84,7 +83,13 @@ def is_godot(game):
|
||||
@fix
|
||||
def dotnet_memory_ordering(game):
|
||||
if "coreclr.dll" in game.files:
|
||||
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO and without multiblock"
|
||||
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO"
|
||||
|
||||
|
||||
@fix
|
||||
def unity_memory_ordering(game):
|
||||
if {"unityplayer.so", "gameassembly.so", "unityplayer.dll"} & game.files:
|
||||
return {"FEX_TSOENABLED": "1"}, [], "Unity: FEX with TSO"
|
||||
|
||||
|
||||
@fix
|
||||
@@ -96,10 +101,16 @@ def godot_vulkan(game):
|
||||
@fix
|
||||
def godot_sentry(game):
|
||||
sentry = sorted(n[:-4] for n in game.files if n.startswith("libsentry.windows.") and n.endswith(".dll"))
|
||||
if is_godot(game) and sentry:
|
||||
if is_godot(game) and sentry and ("coreclr.dll" in game.files or "godotsharp.dll" in game.files):
|
||||
return {"WINEDLLOVERRIDES": ";".join(n + "=d" for n in sentry)}, [], "Godot: Sentry crash handler off"
|
||||
|
||||
|
||||
@fix
|
||||
def d3dgear_hook(game):
|
||||
if "d3dgear64.dll" in game.files:
|
||||
return {"WINEDLLOVERRIDES": "d3dgear64=d"}, [], "D3DGear capture hook off (it stops the game drawing)"
|
||||
|
||||
|
||||
@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")):
|
||||
@@ -108,17 +119,56 @@ def deep_rock_gdk_raytracing(game):
|
||||
|
||||
@fix
|
||||
def arkham_city_x87(game):
|
||||
"""Batman: Arkham City (BatmanAC.exe, also started through BmLauncher.exe beside it) leans on x87
|
||||
and stops with Unreal's "Fatal error!" right after start when FEX reduces its precision."""
|
||||
if "batmanac.exe" in game.files:
|
||||
return {"FEX_X87REDUCEDPRECISION": "0"}, [], "Batman: Arkham City: FEX with full x87 precision"
|
||||
|
||||
|
||||
|
||||
@fix
|
||||
def teardown_vsync(game):
|
||||
if game.stem == "teardown":
|
||||
return {"vblank_mode": "2"}, [], "Teardown: OpenGL keeps the game's own vsync"
|
||||
|
||||
|
||||
@fix
|
||||
def protonfixes_off(game):
|
||||
if game.stem in ("blackops3", "darksoulsremastered"):
|
||||
return {"PROTONFIXES_DISABLE": "1"}, [], "umu-protonfixes off (its ALSA audio and VC++ installer steps fail here)"
|
||||
|
||||
|
||||
@fix
|
||||
def little_nightmares_threads(game):
|
||||
if game.stem == "littlenightmares":
|
||||
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):
|
||||
"""Cyberpunk 2077's prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the
|
||||
game half a minute later and then stays up beside it, well over a core busy for as long as the
|
||||
game runs. The game is started itself instead; the prelauncher's own --launcher-skip started it
|
||||
twice."""
|
||||
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")
|
||||
if os.path.isfile(game):
|
||||
@@ -127,8 +177,62 @@ def skip_red_launcher(command):
|
||||
return command
|
||||
|
||||
|
||||
UBISOFT_LAUNCHER = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
|
||||
UBISOFT_SETTINGS = "drive_c/users/steamuser/AppData/Local/Ubisoft Game Launcher/settings.yaml"
|
||||
|
||||
|
||||
def overlay_off(text):
|
||||
lines = text.splitlines()
|
||||
try:
|
||||
start = next(i for i, line in enumerate(lines) if re.fullmatch(r"overlay:\s*(#.*)?", line))
|
||||
except StopIteration:
|
||||
if lines and not lines[-1].strip():
|
||||
lines.pop()
|
||||
return "\n".join(lines + ["overlay:", " enabled: false", " warning_enabled: false"]) + "\n"
|
||||
end = start + 1
|
||||
for index in range(start + 1, len(lines)):
|
||||
if lines[index].strip() and not lines[index].startswith(" "):
|
||||
break
|
||||
if lines[index].strip():
|
||||
end = index + 1
|
||||
block = lines[start + 1:end]
|
||||
for key in ("enabled", "warning_enabled"):
|
||||
entry = " %s: false" % key
|
||||
found = [i for i, line in enumerate(block) if line.split(":", 1)[0] == " " + key]
|
||||
if found:
|
||||
block[found[0]] = entry
|
||||
else:
|
||||
block.append(entry)
|
||||
return "\n".join(lines[:start + 1] + block + lines[end:]) + "\n"
|
||||
|
||||
|
||||
def ubisoft_overlay_off(env):
|
||||
prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx"
|
||||
if not (prefix / UBISOFT_LAUNCHER).is_dir():
|
||||
return
|
||||
settings = prefix / UBISOFT_SETTINGS
|
||||
try:
|
||||
text = settings.read_text(encoding="utf-8") if settings.exists() else ""
|
||||
updated = overlay_off(text)
|
||||
if updated == text:
|
||||
return
|
||||
settings.parent.mkdir(parents=True, exist_ok=True)
|
||||
handle, staged = tempfile.mkstemp(prefix=".settings-", dir=settings.parent)
|
||||
try:
|
||||
with os.fdopen(handle, "w", encoding="utf-8") as target:
|
||||
target.write(updated)
|
||||
if settings.exists():
|
||||
os.chmod(staged, settings.stat().st_mode & 0o7777)
|
||||
os.replace(staged, settings)
|
||||
except BaseException:
|
||||
os.unlink(staged)
|
||||
raise
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay turned off", file=sys.stderr)
|
||||
except (OSError, UnicodeDecodeError) as error:
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
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",
|
||||
@@ -146,7 +250,6 @@ def offline_without_anticheat(command, env):
|
||||
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
|
||||
@@ -157,20 +260,21 @@ def offline_without_anticheat(command, env):
|
||||
|
||||
|
||||
def engine_fixes(exe, args):
|
||||
"""Environment and extra arguments a game needs because of what it is built with."""
|
||||
game = Game(exe, args)
|
||||
env, extra, notes = {}, [], []
|
||||
for check in FIXES:
|
||||
found = check(game)
|
||||
if found:
|
||||
env.update(found[0])
|
||||
for name, value in found[0].items():
|
||||
if name == "WINEDLLOVERRIDES" and env.get(name):
|
||||
value = env[name] + ";" + value
|
||||
env[name] = value
|
||||
extra += found[1]
|
||||
notes.append(found[2])
|
||||
return env, extra, notes
|
||||
|
||||
|
||||
def win_components(compat, app_id):
|
||||
"""The game's Windows components put into its prefix; returns their WINEDLLOVERRIDES entries."""
|
||||
if not compat:
|
||||
return ""
|
||||
try:
|
||||
@@ -196,6 +300,141 @@ def game_gpu(env):
|
||||
return result
|
||||
|
||||
|
||||
def vram_cap(env):
|
||||
value = env.get("BL_VRAM_MB", "")
|
||||
if not re.fullmatch(r"[1-9][0-9]{0,6}", value):
|
||||
return env
|
||||
result = env.copy()
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
return result
|
||||
|
||||
|
||||
def parse_cores(text):
|
||||
cores = set()
|
||||
for part in text.replace(" ", "").split(","):
|
||||
match = re.fullmatch(r"(\d{1,3})(?:-(\d{1,3}))?", part)
|
||||
if not match:
|
||||
return None
|
||||
first, last = int(match.group(1)), int(match.group(2) or match.group(1))
|
||||
if last < first:
|
||||
return None
|
||||
cores.update(range(first, last + 1))
|
||||
return cores or None
|
||||
|
||||
|
||||
def online_cores():
|
||||
try:
|
||||
with open("/sys/devices/system/cpu/online") as f:
|
||||
cores = parse_cores(f.read().strip())
|
||||
except OSError:
|
||||
cores = None
|
||||
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
|
||||
|
||||
|
||||
def game_cores(env):
|
||||
text = env.get("DROIDDECK_GAME_CORES", "").strip()
|
||||
if not text:
|
||||
return
|
||||
cores = parse_cores(text)
|
||||
chosen = cores & online_cores() if cores else None
|
||||
if not chosen:
|
||||
print("droiddeck-game-env: ignoring game cores %r" % text, file=sys.stderr)
|
||||
return
|
||||
try:
|
||||
os.sched_setaffinity(0, chosen)
|
||||
print("droiddeck-game-env: game cores %s" % ",".join(map(str, sorted(chosen))), file=sys.stderr)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
|
||||
|
||||
|
||||
def core_speeds(cores, root="/sys/devices/system/cpu"):
|
||||
for name in ("cpu_capacity", "cpufreq/cpuinfo_max_freq"):
|
||||
speeds = {}
|
||||
for core in cores:
|
||||
try:
|
||||
with open("%s/cpu%d/%s" % (root, core, name)) as f:
|
||||
speeds[core] = int(f.read().strip())
|
||||
except (OSError, ValueError):
|
||||
break
|
||||
else:
|
||||
return speeds
|
||||
return None
|
||||
|
||||
|
||||
def fastest_first(cores):
|
||||
cores = sorted(cores)
|
||||
speeds = core_speeds(cores)
|
||||
return sorted(cores, key=lambda core: -speeds[core]) if speeds else cores
|
||||
|
||||
|
||||
def proton_cpu_limit(command, env):
|
||||
app_id = env.get("SteamGameId", "")
|
||||
if not command or not app_id.isdigit():
|
||||
return None
|
||||
try:
|
||||
if os.path.getsize(command[0]) > 4 * 1024 * 1024:
|
||||
return None
|
||||
with open(command[0], encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
except OSError:
|
||||
return None
|
||||
table = re.search(r"^default_cpu_limit = \{(.*?)^\}", text, re.M | re.S)
|
||||
match = table and re.search(r'^\s*"%s"\s*:\s*"?(\w+)' % app_id, table.group(1), re.M)
|
||||
if not match:
|
||||
return None
|
||||
value = match.group(1)
|
||||
return int(value) if value.isdigit() else value
|
||||
|
||||
|
||||
def cpu_topology(env, command=()):
|
||||
if "PROTON_CPU_TOPOLOGY" in env:
|
||||
return
|
||||
if "WINE_CPU_TOPOLOGY" in env:
|
||||
if env["WINE_CPU_TOPOLOGY"]:
|
||||
env["PROTON_CPU_TOPOLOGY"] = env["WINE_CPU_TOPOLOGY"]
|
||||
return
|
||||
picked = bool(env.get("DROIDDECK_GAME_CORES", "").strip() or env.get("BL_GAME_CPUS", "").strip())
|
||||
fastest = env.get("DROIDDECK_FASTEST_CORES", "").strip() != "0" and game_id(env) is not None
|
||||
if not (picked or fastest):
|
||||
return
|
||||
try:
|
||||
cores = sorted(os.sched_getaffinity(0))
|
||||
except OSError:
|
||||
return
|
||||
online = online_cores()
|
||||
if not cores or cores[-1] >= len(online):
|
||||
return
|
||||
picked = picked and not set(cores) >= online
|
||||
if fastest:
|
||||
limit = None if picked else proton_cpu_limit(command, env)
|
||||
if isinstance(limit, str):
|
||||
return
|
||||
cores = fastest_first(cores)[:limit or None]
|
||||
elif set(cores) >= online:
|
||||
return
|
||||
if cores == sorted(online):
|
||||
return
|
||||
env["WINE_CPU_TOPOLOGY"] = env["PROTON_CPU_TOPOLOGY"] = "%d:%s" % (len(cores), ",".join(map(str, cores)))
|
||||
print("droiddeck-game-env: Windows sees %d cores (%s)" % (len(cores), env["WINE_CPU_TOPOLOGY"]), file=sys.stderr)
|
||||
|
||||
|
||||
def gl_vsync(env):
|
||||
if "vblank_mode" in env or game_id(env) is None:
|
||||
return False
|
||||
env["vblank_mode"] = "0"
|
||||
return True
|
||||
|
||||
|
||||
def game_images(env):
|
||||
if game_id(env) is None:
|
||||
return False
|
||||
env.setdefault("GAMESCOPE_WSI_MIN_IMAGE_COUNT", "8")
|
||||
env.setdefault("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT", "1")
|
||||
return True
|
||||
|
||||
|
||||
def apply_config(env, config, app_id, fixes=None):
|
||||
if config.get("version") != 1:
|
||||
raise ValueError("unsupported environment configuration")
|
||||
@@ -228,6 +467,55 @@ def apply_config(env, config, app_id, fixes=None):
|
||||
return result
|
||||
|
||||
|
||||
GAME_DEBUG_CHANNELS = (
|
||||
"timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree",
|
||||
)
|
||||
WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)")
|
||||
|
||||
|
||||
def game_debug_channels(*values):
|
||||
selectors = {}
|
||||
for value in values:
|
||||
if not isinstance(value, str) or "\0" in value or len(value) > 8192:
|
||||
continue
|
||||
for part in value.split(","):
|
||||
part = part.strip()
|
||||
match = WINE_DEBUG_SELECTOR.fullmatch(part)
|
||||
if match is None:
|
||||
continue
|
||||
key = (match[1] or "", match[3])
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = part
|
||||
for channel in GAME_DEBUG_CHANNELS:
|
||||
key = ("", channel)
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = "+" + channel
|
||||
formatted = ",".join(selectors.values())
|
||||
if len(formatted) > 8192:
|
||||
formatted = ",".join("+" + channel for channel in GAME_DEBUG_CHANNELS)
|
||||
return formatted
|
||||
|
||||
|
||||
def apply_game_debug_logs(env, config, debug_dir):
|
||||
if not isinstance(config, dict) or config.get("version") != 1 or config.get("gameDebugLogs") is not True:
|
||||
return env
|
||||
if (not isinstance(debug_dir, str) or "\0" in debug_dir or len(debug_dir) > 8192
|
||||
or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)):
|
||||
print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": debug_dir,
|
||||
"PROTON_CRASH_REPORT_DIR": debug_dir,
|
||||
"DXVK_LOG_PATH": debug_dir,
|
||||
"DXVK_LOG_LEVEL": "debug",
|
||||
"VKD3D_DEBUG": "info",
|
||||
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
def sync_config(config, app_id):
|
||||
games = config.get("games", {})
|
||||
return {
|
||||
@@ -280,10 +568,6 @@ SSBS_LIB = "/usr/local/lib/libssbs.so"
|
||||
|
||||
|
||||
def force_ssbs(command, env):
|
||||
"""DROIDDECK_FORCE_SSBS=1 (a game's or the shared environment): preload libssbs.so into this
|
||||
Proton's Wine, which then keeps PSTATE.SSBS set across signal returns - speculative store
|
||||
bypass stays allowed, as force_ssbs.diff does inside a rebuilt ntdll. ARM64 Protons only: the
|
||||
library is aarch64 and only arm64 Wine has the signal path it fixes."""
|
||||
if env.get("DROIDDECK_FORCE_SSBS", "").lower() not in ("1", "on", "true", "yes"):
|
||||
return env
|
||||
proton = os.path.dirname(command[0]) if command else ""
|
||||
@@ -304,10 +588,6 @@ EVALUATOR_SCRIPT = re.compile(r"(?:^|[\\/])evaluatorscript_[0-9]+\.vdf$", re.IGN
|
||||
|
||||
|
||||
def mark_install_scripts(command, env):
|
||||
"""The client is about to run a game's install scripts (iscriptevaluator.exe): mark every process
|
||||
in them but a Vulkan runtime installer as already run first, so no redistributable installer
|
||||
starts - on first launch the shared ones may still be downloading, and on ARM64 Proton the VC++
|
||||
ones stop with an error."""
|
||||
if not any(arg.lower().replace("\\", "/").endswith("iscriptevaluator.exe") for arg in command):
|
||||
return []
|
||||
root = env.get("BL_X64_STEAM_ROOT") or env.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or str(Path.home() / ".local/share/Steam")
|
||||
@@ -414,7 +694,198 @@ def record_install_scripts(digest, env):
|
||||
print("droiddeck-game-env: install scripts not recorded (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
def start(launch, launch_env, digest):
|
||||
def directaudio_settings(env):
|
||||
if "directaudio" not in env.get("WINE_AUDIO_DRIVER", "").split(","):
|
||||
return env
|
||||
for name, value in list(env.items()):
|
||||
if name.startswith("AUDIO_DIRECT_"):
|
||||
env["BANNER_" + name] = value
|
||||
return env
|
||||
|
||||
|
||||
DIRT_GAMES = {"dirt3_game": "dirt3", "showdown": "dirtshowdown", "showdown_avx": "dirtshowdown"}
|
||||
DIRT_WS2 = "/usr/local/lib/droiddeck-dirt/ws2_32.dll"
|
||||
DIRT_MARKER = b"droiddeck-dirt-ws2_32"
|
||||
DIRT_FIXED = "showdown_avx.exe".encode("utf-16-le")
|
||||
DIRT_SAVED = ".droiddeck-original"
|
||||
|
||||
|
||||
def dirt_telemetry_on(prefix, game):
|
||||
try:
|
||||
folders = [f for f in (Path(prefix) / "pfx/drive_c/users/steamuser/Documents/My Games").iterdir()
|
||||
if f.name.lower().replace(" ", "") == game]
|
||||
except OSError:
|
||||
return False
|
||||
for folder in folders:
|
||||
try:
|
||||
text = (folder / "hardwaresettings/hardware_settings_config.xml").read_text(encoding="latin-1")
|
||||
except OSError:
|
||||
continue
|
||||
for tag in ("udp", "motion"):
|
||||
element = re.search(r"<%s\s[^>]*>" % tag, text)
|
||||
if element:
|
||||
attrs = dict(re.findall(r'\s(\w+)="([^"]*)"', element.group(0)))
|
||||
return attrs.get("enabled") == "true" and attrs.get("ip", "").lower() not in ("", "dbox")
|
||||
return False
|
||||
|
||||
|
||||
def proton_ws2(proton):
|
||||
return Path(proton).parent / "files/lib/wine/i386-windows/ws2_32.dll"
|
||||
|
||||
|
||||
def proton_has_dirt_fix(proton):
|
||||
try:
|
||||
return DIRT_FIXED in proton_ws2(proton).read_bytes()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
WINE_DLL_DIRS = ("/lib/wine/i386-windows", "/lib/wine/x86_64-windows", "/lib/wine/aarch64-windows", "/lib/wine",
|
||||
"/lib/wine/fakedlls", "/lib64/wine", "/lib64/wine/fakedlls", "/lib64/wine/x86_64-windows")
|
||||
|
||||
|
||||
def is_wine_dll_link(path):
|
||||
try:
|
||||
return os.path.islink(path) and os.path.dirname(os.readlink(path)).endswith(WINE_DLL_DIRS)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def prefix_ws2(prefix):
|
||||
return Path(prefix) / "pfx/drive_c/windows/syswow64/ws2_32.dll"
|
||||
|
||||
|
||||
def is_dirt_stand_in(path):
|
||||
try:
|
||||
return not path.is_symlink() and DIRT_MARKER in path.read_bytes()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def dirt_ws2_wanted(command, env):
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
if len(command) < 3 or not prefix or not os.path.isfile(DIRT_WS2):
|
||||
return None
|
||||
game = DIRT_GAMES.get(os.path.splitext(os.path.basename(command[2]))[0].lower())
|
||||
if not game or not dirt_telemetry_on(prefix, game) or proton_has_dirt_fix(command[0]):
|
||||
return None
|
||||
return prefix if os.path.lexists(prefix_ws2(prefix)) else None
|
||||
|
||||
|
||||
def swap_dirt_ws2(prefix):
|
||||
target = prefix_ws2(prefix)
|
||||
saved = target.with_name(target.name + DIRT_SAVED)
|
||||
data = Path(DIRT_WS2).read_bytes()
|
||||
if not is_dirt_stand_in(target):
|
||||
if os.path.lexists(saved):
|
||||
os.unlink(saved)
|
||||
os.replace(target, saved)
|
||||
staged = target.with_name(target.name + ".droiddeck-tmp")
|
||||
staged.write_bytes(data)
|
||||
os.replace(staged, target)
|
||||
|
||||
|
||||
def restore_dirt_ws2(prefix, proton):
|
||||
target = prefix_ws2(prefix)
|
||||
saved = target.with_name(target.name + DIRT_SAVED)
|
||||
own = proton_ws2(proton)
|
||||
had_saved = os.path.lexists(saved)
|
||||
if had_saved:
|
||||
if os.path.lexists(target) and not is_dirt_stand_in(target):
|
||||
os.unlink(saved)
|
||||
return False
|
||||
if not own.is_file() or not is_wine_dll_link(saved) or os.path.realpath(saved) == os.path.realpath(own):
|
||||
os.replace(saved, target)
|
||||
return True
|
||||
os.unlink(saved)
|
||||
if own.is_file() and (is_dirt_stand_in(target) or (had_saved and not os.path.lexists(target))):
|
||||
link = target.with_name(target.name + ".droiddeck-tmp")
|
||||
if os.path.lexists(link):
|
||||
os.unlink(link)
|
||||
os.symlink(own, link)
|
||||
os.replace(link, target)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
EGO_RESTRICTIONS = "system/hardware_settings_restrictions.xml"
|
||||
EGO_CORE_RULE = re.compile(r'[ \t]*<restrict_if name="cores" op="(int_[a-z]+)" value="(\d+)">.*?</restrict_if>[ \t]*\r?\n', re.S)
|
||||
EGO_OPS = {"int_eq": int.__eq__, "int_ne": int.__ne__, "int_ge": int.__ge__, "int_gt": int.__gt__,
|
||||
"int_le": int.__le__, "int_lt": int.__lt__}
|
||||
|
||||
|
||||
def windows_core_count(env):
|
||||
count = (env.get("WINE_CPU_TOPOLOGY") or "").split(":", 1)[0]
|
||||
return int(count) if count.isascii() and count.isdigit() and int(count) > 0 else None
|
||||
|
||||
|
||||
def ego_core_plan(command, env):
|
||||
count = windows_core_count(env)
|
||||
if not count or len(command) < 3:
|
||||
return None
|
||||
folder = Path(command[2]).parent
|
||||
path = folder / EGO_RESTRICTIONS
|
||||
try:
|
||||
raw = path.read_bytes()
|
||||
except OSError:
|
||||
return None
|
||||
text = raw.decode("latin-1")
|
||||
start, end = text.find("<cpu>"), text.find("</cpu>")
|
||||
if start < 0 or end < start:
|
||||
return None
|
||||
rules = list(EGO_CORE_RULE.finditer(text, start, end))
|
||||
if not rules or any(EGO_OPS.get(rule.group(1), lambda a, b: True)(count, int(rule.group(2))) for rule in rules):
|
||||
return None
|
||||
smaller = [rule for rule in rules if rule.group(1) == "int_eq" and int(rule.group(2)) < count]
|
||||
if not smaller:
|
||||
return None
|
||||
source = max(smaller, key=lambda rule: int(rule.group(2)))
|
||||
worker_map = re.search(r'workerMapFile="([^"]+)"', source.group(0))
|
||||
if worker_map and not (folder / worker_map.group(1)).is_file():
|
||||
return None
|
||||
plan = source.group(0).replace('value="%s"' % source.group(2), 'value="%d"' % count, 1)
|
||||
saved = path.with_name(path.name + DIRT_SAVED)
|
||||
if not os.path.lexists(saved):
|
||||
saved.write_bytes(raw)
|
||||
handle, staged = tempfile.mkstemp(prefix=path.name + ".", suffix=".droiddeck-tmp", dir=str(path.parent))
|
||||
try:
|
||||
with os.fdopen(handle, "wb") as out:
|
||||
out.write((text[:source.end()] + plan + text[source.end():]).encode("latin-1"))
|
||||
os.replace(staged, path)
|
||||
except BaseException:
|
||||
if os.path.lexists(staged):
|
||||
os.unlink(staged)
|
||||
raise
|
||||
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 forward(signum, frame):
|
||||
try:
|
||||
process.send_signal(signum)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
previous = {signum: signal.signal(signum, forward) for signum in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP)}
|
||||
try:
|
||||
code = process.wait()
|
||||
finally:
|
||||
for signum, handler in previous.items():
|
||||
signal.signal(signum, handler)
|
||||
return 128 - code if code < 0 else code
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None):
|
||||
if after:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
try:
|
||||
return wait_forwarding_signals(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 digest:
|
||||
code = subprocess.run(launch, env=launch_env, check=False).returncode
|
||||
if code == 0:
|
||||
@@ -429,6 +900,7 @@ def main():
|
||||
return 2
|
||||
env = game_gpu(os.environ.copy())
|
||||
mic_enabled = env.get("BL_MIC_ENABLED")
|
||||
debug_dir = env.get("BL_DEBUG_DIR", "")
|
||||
scripts = mark_install_scripts(command, env)
|
||||
if scripts and install_scripts_done(scripts, env):
|
||||
print("droiddeck-game-env: install scripts already run in this prefix; evaluator skipped", file=sys.stderr)
|
||||
@@ -438,12 +910,19 @@ def main():
|
||||
except OSError:
|
||||
digest = None
|
||||
app_id = game_id(env)
|
||||
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 = {}
|
||||
if waiting:
|
||||
command = skip_red_launcher(command)
|
||||
ubisoft_overlay_off(env)
|
||||
fixes, extra, notes = engine_fixes(command[2], command[3:]) if len(command) > 2 else ({}, [], [])
|
||||
if not gl_default:
|
||||
fixes.pop("vblank_mode", None)
|
||||
for note in notes:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
command += extra
|
||||
@@ -451,11 +930,18 @@ def main():
|
||||
if components:
|
||||
own = fixes.get("WINEDLLOVERRIDES")
|
||||
fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components
|
||||
dirt_prefix = dirt_ws2_wanted(command, env)
|
||||
if dirt_prefix:
|
||||
own = fixes.get("WINEDLLOVERRIDES")
|
||||
fixes["WINEDLLOVERRIDES"] = own + ";ws2_32=n,b" if own else "ws2_32=n,b"
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
config = {}
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
if waiting:
|
||||
if "vblank_mode" in config.get("shared", {}):
|
||||
fixes.pop("vblank_mode", None)
|
||||
env = apply_config(env, config, app_id, fixes)
|
||||
else:
|
||||
env = apply_config(env, sync_config(config, app_id), app_id)
|
||||
@@ -464,11 +950,29 @@ 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 waiting:
|
||||
before_debug = env
|
||||
env = apply_game_debug_logs(env, config, debug_dir)
|
||||
if env is not before_debug:
|
||||
print("droiddeck-game-env: game debug logs enabled for this launch", file=sys.stderr)
|
||||
if gl_default and env.get("vblank_mode") == "0":
|
||||
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)
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env["AUDIO_DIRECT_MIC"] = "0"
|
||||
env = directaudio_settings(env)
|
||||
env = vram_cap(env)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
cpu_topology(env, command)
|
||||
if app_id and len(command) > 2 and command[1] == "waitforexitandrun":
|
||||
try:
|
||||
note = ego_core_plan(command, env)
|
||||
except OSError as error:
|
||||
note = "no thread plan added for this core count (%s)" % error
|
||||
if note:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
try:
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
except Exception as error:
|
||||
@@ -481,16 +985,45 @@ def main():
|
||||
return 1
|
||||
if xbox_result is not None:
|
||||
return xbox_result
|
||||
after = None
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
if app_id and prefix and len(command) > 1 and command[1] == "waitforexitandrun":
|
||||
try:
|
||||
if dirt_prefix:
|
||||
after = lambda: restore_dirt_ws2(dirt_prefix, command[0])
|
||||
swap_dirt_ws2(dirt_prefix)
|
||||
print("droiddeck-game-env: DiRT telemetry fix: ws2_32 stand-in in the prefix until the game exits",
|
||||
file=sys.stderr)
|
||||
elif restore_dirt_ws2(prefix, command[0]):
|
||||
print("droiddeck-game-env: DiRT telemetry fix: put the prefix's own ws2_32 back", file=sys.stderr)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: DiRT telemetry fix not applied (%s)" % error, file=sys.stderr)
|
||||
if after:
|
||||
after = None
|
||||
try:
|
||||
restore_dirt_ws2(dirt_prefix, command[0])
|
||||
except OSError as undo:
|
||||
print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); Wine uses its own copy "
|
||||
"and the next launch puts the file back" % undo, file=sys.stderr)
|
||||
sync = load_sync()
|
||||
launch, launch_env = select_sync(command, env, sync)
|
||||
if launch[0] != command[0]:
|
||||
try:
|
||||
return start(launch, launch_env, digest)
|
||||
return start(launch, launch_env, digest, after)
|
||||
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)
|
||||
return start(launch, launch_env, digest)
|
||||
try:
|
||||
return start(launch, launch_env, digest, after)
|
||||
except OSError:
|
||||
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)
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
#!/usr/bin/python3
|
||||
import fcntl
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
BIN = Path(__file__).resolve().parent
|
||||
IDLE = {"wineserver", "services.exe", "winedevice.exe", "explorer.exe", "rpcss.exe", "plugplay.exe",
|
||||
"conhost.exe", "lsass.exe", "svchost.exe", "steam.exe", "wineboot.exe", "winemenubuilder.exe"}
|
||||
|
||||
|
||||
def control(folder):
|
||||
folder = Path(folder).resolve(strict=True)
|
||||
root = folder / ".droiddeck-gog"
|
||||
if root.is_symlink():
|
||||
raise ValueError("GOG control directory is a symbolic link")
|
||||
root.mkdir(exist_ok=True)
|
||||
return root
|
||||
|
||||
|
||||
def read(path):
|
||||
if path.is_symlink():
|
||||
raise ValueError("GOG metadata is a symbolic link")
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def write(path, value):
|
||||
if path.is_symlink():
|
||||
raise ValueError("GOG metadata is a symbolic link")
|
||||
descriptor, name = tempfile.mkstemp(prefix=path.name + ".", suffix=".new", dir=path.parent)
|
||||
temporary = Path(name)
|
||||
try:
|
||||
with os.fdopen(descriptor, "w") as stream:
|
||||
json.dump(value, stream)
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
os.replace(temporary, path)
|
||||
directory = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY)
|
||||
try:
|
||||
try:
|
||||
os.fsync(directory)
|
||||
except OSError as error:
|
||||
if error.errno not in (errno.EINVAL, errno.ENOTSUP):
|
||||
raise
|
||||
finally:
|
||||
os.close(directory)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def lock_file(root):
|
||||
return os.fdopen(os.open(root / "lease", os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW, 0o600), "r+")
|
||||
|
||||
|
||||
def generation(pid):
|
||||
try:
|
||||
return Path("/proc/%s/stat" % pid).read_text().rsplit(")", 1)[1].split()[19]
|
||||
except (OSError, IndexError):
|
||||
return None
|
||||
|
||||
|
||||
def lease(folder, owner):
|
||||
root = control(folder)
|
||||
with lock_file(root) as stream:
|
||||
fcntl.lockf(stream, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
sidecar = read(Path(folder) / ".droiddeck-store.json")
|
||||
if sidecar.get("state", "installed") != "installed":
|
||||
raise ValueError("Resume or recover the GOG update before playing")
|
||||
journal = root / "operation.json"
|
||||
if journal.exists() and read(journal).get("phase") != "download":
|
||||
raise ValueError("GOG maintenance is incomplete")
|
||||
start = generation(owner)
|
||||
if start is None:
|
||||
raise ValueError("Game launcher has exited")
|
||||
print("ready", flush=True)
|
||||
sys.stdout.close()
|
||||
while generation(owner) == start:
|
||||
time.sleep(0.25)
|
||||
return 0
|
||||
|
||||
|
||||
def desktop_environment(base, proc=Path("/proc")):
|
||||
env = dict(base)
|
||||
if env.get("DROIDDECK_GOG_DESKTOP") != "1":
|
||||
return env
|
||||
deadline = time.monotonic() + 45
|
||||
while True:
|
||||
for entry in proc.iterdir():
|
||||
if not entry.name.isdigit():
|
||||
continue
|
||||
try:
|
||||
command = (entry / "cmdline").read_bytes().split(b"\0")[0]
|
||||
if command != b"/usr/bin/plasmashell":
|
||||
continue
|
||||
values = dict(os.fsdecode(item).split("=", 1) for item in (entry / "environ").read_bytes().split(b"\0") if b"=" in item)
|
||||
if values.get("BL_DESKTOP") != "1" or values.get("XDG_RUNTIME_DIR") != env.get("XDG_RUNTIME_DIR"):
|
||||
continue
|
||||
if not values.get("DISPLAY") or values.get("WAYLAND_DISPLAY") == env.get("WAYLAND_DISPLAY"):
|
||||
continue
|
||||
for key in ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "BL_DESKTOP"):
|
||||
if key in values:
|
||||
env[key] = values[key]
|
||||
return env
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
if time.monotonic() >= deadline:
|
||||
raise ValueError("The desktop display is not ready; resume the Linux session and verify recovery before retrying")
|
||||
time.sleep(0.25)
|
||||
|
||||
|
||||
def target_for(folder, appid, game):
|
||||
run = runpy.run_path(str(BIN / "droiddeck-proton-run"))["main"].__globals__
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or run["STEAM_ROOT"]
|
||||
target = run["shortcut_target"](str(int(appid) & 0xffffffff), str(game), str(folder), root)
|
||||
target.install = str(folder)
|
||||
return run, root, target
|
||||
|
||||
|
||||
def runner(folder, appid, game, graphical=False):
|
||||
run, root, target = target_for(folder, appid, game)
|
||||
available = run["tools"](root)
|
||||
name, _ = run["choose_tool"](target.appid, run["mapping"](root), available)
|
||||
if name is None:
|
||||
raise ValueError("No Proton tool is installed for this game")
|
||||
tool, command = available[name]
|
||||
base = desktop_environment(os.environ) if graphical else dict(os.environ)
|
||||
env = run["environment"](base, target, tool, root, window=base.get("BL_DESKTOP") == "1")
|
||||
env["DROIDDECK_GOG_MAINTENANCE"] = "1"
|
||||
env["FEX_X87REDUCEDPRECISION"] = "0"
|
||||
env.pop("BL_STORE_EXIT", None)
|
||||
return str(Path(tool) / command), env, target.compatdata
|
||||
|
||||
|
||||
def active(prefix, proc=Path("/proc")):
|
||||
result = []
|
||||
prefix = os.path.realpath(os.path.join(prefix, "pfx"))
|
||||
for entry in proc.iterdir():
|
||||
if not entry.name.isdigit():
|
||||
continue
|
||||
try:
|
||||
env = dict(part.split(b"=", 1) for part in (entry / "environ").read_bytes().split(b"\0") if b"=" in part)
|
||||
if os.path.realpath(os.fsdecode(env.get(b"WINEPREFIX", b""))) != prefix:
|
||||
continue
|
||||
args = (entry / "cmdline").read_bytes().split(b"\0")
|
||||
name = os.fsdecode(args[0]).replace("\\", "/").rsplit("/", 1)[-1].lower()
|
||||
if name not in IDLE:
|
||||
result.append(int(entry.name))
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
return result
|
||||
|
||||
|
||||
def idle(folder, appid, game):
|
||||
_, _, target = target_for(folder, appid, game)
|
||||
if active(target.compatdata):
|
||||
raise ValueError("Close the GOG game before maintenance")
|
||||
return 0
|
||||
|
||||
|
||||
def validate_installer(folder, installer):
|
||||
root = control(folder)
|
||||
path = Path(installer)
|
||||
if path.is_symlink() or not path.resolve(strict=True).is_relative_to(root / "downloads") or path.suffix.lower() != ".exe":
|
||||
raise ValueError("The patch executable is outside GOG download storage")
|
||||
with path.open("rb") as stream:
|
||||
if stream.read(2) != b"MZ":
|
||||
raise ValueError("The GOG patch is not a Windows executable")
|
||||
return path
|
||||
|
||||
|
||||
def installer_arguments(path):
|
||||
with path.open("rb") as stream:
|
||||
data = stream.read(4 * 1024 * 1024)
|
||||
return ["/NOGUI"] if b"Inno Setup Setup Data" in data else []
|
||||
|
||||
|
||||
def start(folder, appid, installer, game):
|
||||
root = control(folder)
|
||||
validate_installer(folder, installer)
|
||||
with lock_file(root) as stream:
|
||||
fcntl.lockf(stream, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
journal = read(root / "operation.json")
|
||||
if journal.get("phase") != "patch-ready":
|
||||
raise ValueError("The patch must be selected again before it can run")
|
||||
idle(folder, appid, game)
|
||||
journal["phase"] = "patch-starting"
|
||||
write(root / "operation.json", journal)
|
||||
write(root / "patch-status.json", {"state": "starting", "startedAt": time.time()})
|
||||
with (root / "patch.log").open("ab") as log:
|
||||
subprocess.Popen([sys.executable, str(Path(__file__).resolve()), "run", folder, appid, installer, game],
|
||||
stdin=subprocess.DEVNULL, stdout=log, stderr=log, start_new_session=True, close_fds=True)
|
||||
return 0
|
||||
|
||||
|
||||
def status(folder):
|
||||
root = control(folder)
|
||||
path = root / "patch-status.json"
|
||||
result = read(path)
|
||||
ended = result.get("state") == "running" and generation(result.get("pid")) != result.get("generation")
|
||||
abandoned = result.get("state") == "starting" and time.time() - result.get("startedAt", 0) > 60
|
||||
if ended or abandoned:
|
||||
result = {"state": "uncertain", "reason": "The patch helper ended without a confirmed result; verify recovery before retrying"}
|
||||
write(path, result)
|
||||
journal = read(root / "operation.json")
|
||||
journal["phase"] = "patch-uncertain"
|
||||
write(root / "operation.json", journal)
|
||||
print(json.dumps(result), flush=True)
|
||||
return 0
|
||||
|
||||
|
||||
def run_patch(folder, appid, installer, game):
|
||||
root = control(folder)
|
||||
try:
|
||||
with lock_file(root) as stream:
|
||||
fcntl.lockf(stream, fcntl.LOCK_EX)
|
||||
path = validate_installer(folder, installer)
|
||||
command, env, prefix = runner(folder, appid, game, True)
|
||||
if active(prefix):
|
||||
raise ValueError("Close the GOG game before applying the patch")
|
||||
journal = read(root / "operation.json")
|
||||
if journal.get("phase") != "patch-starting":
|
||||
raise ValueError("The patch is already running or needs recovery")
|
||||
journal["phase"] = "patch-applying"
|
||||
write(root / "operation.json", journal)
|
||||
sidecar_path = Path(folder) / ".droiddeck-store.json"
|
||||
sidecar = read(sidecar_path)
|
||||
sidecar["state"] = "updating"
|
||||
write(sidecar_path, sidecar)
|
||||
installed_path = root / "installed.json"
|
||||
if installed_path.is_file():
|
||||
installed = read(installed_path)
|
||||
installed.update(verified=False, manifest={}, files=[])
|
||||
write(installed_path, installed)
|
||||
write(root / "patch-status.json", {"state": "running", "pid": os.getpid(), "generation": generation(os.getpid())})
|
||||
os.makedirs(prefix, exist_ok=True)
|
||||
setup = runpy.run_path(str(BIN / "droiddeck-store-launch"))["main"].__globals__
|
||||
previous = dict(os.environ)
|
||||
try:
|
||||
os.environ.update(env)
|
||||
pfx = Path(prefix) / "pfx"
|
||||
if not (pfx / "system.reg").is_file() or not (pfx / "drive_c/windows/system32/reg.exe").is_file():
|
||||
subprocess.run([command, "run", "wineboot.exe", "-u"], env=env, timeout=90, check=True)
|
||||
if not (pfx / "drive_c/windows/system32/reg.exe").is_file():
|
||||
raise ValueError("Proton did not initialize the game's registry tool")
|
||||
result = setup["apply_gog_registry"](Path(folder), prefix, command, installation=journal.get("before"))
|
||||
if not result.startswith(("ready", "written=")):
|
||||
raise ValueError("GOG registry preparation failed; the patch was not applied")
|
||||
prepare_setup(folder, command, env)
|
||||
finally:
|
||||
os.environ.clear(); os.environ.update(previous)
|
||||
proc = subprocess.Popen([command, "run", str(path), *installer_arguments(path)], cwd=str(path.parent), env=env)
|
||||
code = proc.wait()
|
||||
quiet_at = time.monotonic()
|
||||
while True:
|
||||
if active(prefix):
|
||||
quiet_at = time.monotonic()
|
||||
elif time.monotonic() - quiet_at >= 2:
|
||||
break
|
||||
time.sleep(0.25)
|
||||
journal["phase"] = "patch-uncertain"
|
||||
write(root / "operation.json", journal)
|
||||
if code:
|
||||
raise ValueError("GOG patch installer exited with code %d; inspect patch.log" % code)
|
||||
write(root / "patch-status.json", {"state": "done", "exitCode": code})
|
||||
return 0
|
||||
except Exception as error:
|
||||
write(root / "patch-status.json", {"state": "failed", "reason": str(error)})
|
||||
return 1
|
||||
|
||||
|
||||
def prepare_setup(folder, command, env):
|
||||
root = control(folder)
|
||||
record_path = root / "installed.json"
|
||||
if not record_path.is_file():
|
||||
return
|
||||
journal = read(root / "operation.json")
|
||||
record = journal.get("before") or read(record_path)
|
||||
manifest = record.get("manifest", {})
|
||||
if not record.get("build"):
|
||||
return
|
||||
info_path = Path(folder) / ("goggame-%s.info" % record["id"])
|
||||
language = read(info_path).get("language", "") if info_path.is_file() else ""
|
||||
legacy = manifest.get("product", {})
|
||||
products = manifest.get("products", []) if not legacy else [
|
||||
{"productId": str(item["gameID"]), "temp_executable": item["executable"].lstrip("/\\")}
|
||||
for item in legacy.get("support_commands", [])
|
||||
if "Neutral" in item.get("languages", []) or record.get("language") in item.get("languages", []) or language in item.get("languages", [])]
|
||||
for product in products:
|
||||
if str(product.get("productId")) not in record.get("products", []):
|
||||
continue
|
||||
program = None
|
||||
if manifest.get("scriptInterpreter"):
|
||||
if not (Path(folder) / ("goggame-%s.script" % product["productId"])).is_file():
|
||||
continue
|
||||
program = Path(folder) / "support/__redist/ISI/scriptinterpreter.exe"
|
||||
elif product.get("temp_executable"):
|
||||
relative = product["temp_executable"].replace("\\", "/")
|
||||
for candidate in (Path(folder) / "support" / str(product["productId"]) / relative, Path(folder) / relative):
|
||||
if candidate.is_file():
|
||||
program = candidate
|
||||
break
|
||||
if program is None:
|
||||
continue
|
||||
if not program.resolve(strict=True).is_relative_to(Path(folder).resolve()):
|
||||
raise ValueError("GOG setup executable leaves the installation")
|
||||
windows = "Z:" + str(Path(folder).resolve()).replace("/", "\\")
|
||||
args = ["/VERYSILENT", "/DIR=" + windows, "/ProductId=" + str(product["productId"]),
|
||||
"/galaxyclient", "/buildId=" + str(legacy.get("timestamp", record["build"])), "/versionName=" + record.get("version", ""),
|
||||
"/lang-code=" + record.get("language", "en-US"), "/supportDir=" + windows + "\\support", "/nodesktopshortcut"]
|
||||
if language:
|
||||
args += ["/Language=" + language, "/LANG=" + language.lower()]
|
||||
result = subprocess.run([command, "run", str(program), *args], env=env, cwd=folder, timeout=120)
|
||||
if result.returncode:
|
||||
raise ValueError("GOG installation setup failed; the patch was not applied")
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) == 3 and argv[0] == "lease":
|
||||
return lease(argv[1], int(argv[2]))
|
||||
if len(argv) == 4 and argv[0] == "idle":
|
||||
return idle(*argv[1:])
|
||||
if len(argv) == 2 and argv[0] == "status":
|
||||
return status(argv[1])
|
||||
if len(argv) == 5 and argv[0] == "start":
|
||||
return start(*argv[1:])
|
||||
if len(argv) == 5 and argv[0] == "run":
|
||||
return run_patch(*argv[1:])
|
||||
raise ValueError("Invalid GOG maintenance command")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
except Exception as error:
|
||||
print("GOG maintenance: " + str(error), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Let GTK draw close buttons inside gamescope, which supplies no window decorations."""
|
||||
import ctypes as c
|
||||
import os
|
||||
import signal
|
||||
@@ -45,6 +44,13 @@ def advertise_compositing():
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit('usage: droiddeck-gpu-window <program> [args...]')
|
||||
if 'BL_GPU_CHILD_WSI' in os.environ:
|
||||
wsi = os.environ.pop('BL_GPU_CHILD_WSI')
|
||||
if wsi:
|
||||
os.environ['MESA_VK_WSI_DEBUG'] = wsi
|
||||
else:
|
||||
os.environ.pop('MESA_VK_WSI_DEBUG', None)
|
||||
os.environ['SDL_VIDEODRIVER'] = 'x11'
|
||||
os.environ.setdefault('GTK_CSD', '1')
|
||||
try:
|
||||
connection = advertise_compositing()
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import select
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
DISPLAY_ID = 1
|
||||
REGISTRY_ID = 2
|
||||
METHOD_ID = 3
|
||||
SETTLE = 0.15
|
||||
|
||||
|
||||
def wl_string(value):
|
||||
data = value.encode() + b"\0"
|
||||
return struct.pack("<I", len(data)) + data + b"\0" * (-len(data) % 4)
|
||||
|
||||
|
||||
def read_string(payload, offset):
|
||||
(length,) = struct.unpack_from("<I", payload, offset)
|
||||
start = offset + 4
|
||||
text = payload[start:start + length - 1].decode(errors="replace")
|
||||
return text, start + length + (-length % 4)
|
||||
|
||||
|
||||
class Connection:
|
||||
def __init__(self, sock):
|
||||
self.sock = sock
|
||||
self.buffer = b""
|
||||
|
||||
def send(self, obj, opcode, payload=b""):
|
||||
self.sock.sendall(struct.pack("<II", obj, ((8 + len(payload)) << 16) | opcode) + payload)
|
||||
|
||||
def messages(self, timeout):
|
||||
ready, _, _ = select.select([self.sock], [], [], timeout)
|
||||
if not ready:
|
||||
return []
|
||||
data, _, _, _ = self.sock.recvmsg(65536, socket.CMSG_SPACE(16 * 4))
|
||||
if not data:
|
||||
raise EOFError
|
||||
self.buffer += data
|
||||
out = []
|
||||
while len(self.buffer) >= 8:
|
||||
obj, word = struct.unpack_from("<II", self.buffer)
|
||||
size = word >> 16
|
||||
if size < 8 or len(self.buffer) < size:
|
||||
break
|
||||
out.append((obj, word & 0xFFFF, self.buffer[8:size]))
|
||||
self.buffer = self.buffer[size:]
|
||||
return out
|
||||
|
||||
|
||||
class Report:
|
||||
def __init__(self, directory):
|
||||
self.directory = directory
|
||||
self.seq = 0
|
||||
self.sent = None
|
||||
|
||||
def write(self, field, hint=0, purpose=0):
|
||||
state = (field, purpose)
|
||||
if state == self.sent or not self.directory:
|
||||
return
|
||||
self.sent = state
|
||||
self.seq += 1
|
||||
os.makedirs(self.directory, exist_ok=True)
|
||||
target = os.path.join(self.directory, "ime.json")
|
||||
temp = target + ".tmp"
|
||||
fd = os.open(temp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
with os.fdopen(fd, "w") as handle:
|
||||
json.dump({"textField": field, "hint": hint, "purpose": purpose, "seq": self.seq}, handle)
|
||||
os.replace(temp, target)
|
||||
print(f"droiddeck-ime: text field {'focused' if field else 'left'}", file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
def connect():
|
||||
fd = os.environ.pop("WAYLAND_SOCKET", "")
|
||||
if fd.isdigit():
|
||||
return socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, fileno=int(fd))
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(os.path.join(os.environ["XDG_RUNTIME_DIR"], os.environ.get("WAYLAND_DISPLAY", "wayland-0")))
|
||||
return sock
|
||||
|
||||
|
||||
def main():
|
||||
launch = os.environ.get("BL_LAUNCH_DIR", "")
|
||||
report = Report(os.environ.get("BL_IME_DIR") or (os.path.join(launch, "agent") if launch else ""))
|
||||
conn = Connection(connect())
|
||||
conn.send(DISPLAY_ID, 1, struct.pack("<I", REGISTRY_ID))
|
||||
contexts = {}
|
||||
current = None
|
||||
pending = None
|
||||
while True:
|
||||
timeout = None if pending is None else max(0.0, pending - time.monotonic())
|
||||
try:
|
||||
batch = conn.messages(timeout)
|
||||
except (EOFError, ConnectionError):
|
||||
report.write(False)
|
||||
return 0
|
||||
for obj, opcode, payload in batch:
|
||||
if obj == DISPLAY_ID and opcode == 0:
|
||||
_, code = struct.unpack_from("<II", payload)
|
||||
message, _ = read_string(payload, 8)
|
||||
print(f"droiddeck-ime: protocol error {code}: {message}", file=sys.stderr, flush=True)
|
||||
report.write(False)
|
||||
return 1
|
||||
if obj == REGISTRY_ID and opcode == 0:
|
||||
(name,) = struct.unpack_from("<I", payload)
|
||||
interface, offset = read_string(payload, 4)
|
||||
(version,) = struct.unpack_from("<I", payload, offset)
|
||||
if interface == "zwp_input_method_v1":
|
||||
conn.send(REGISTRY_ID, 0, struct.pack("<I", name) + wl_string(interface)
|
||||
+ struct.pack("<II", min(version, 1), METHOD_ID))
|
||||
elif obj == METHOD_ID and opcode == 0:
|
||||
(context,) = struct.unpack_from("<I", payload)
|
||||
contexts[context] = [0, 0]
|
||||
current = context
|
||||
pending = None
|
||||
report.write(True)
|
||||
elif obj == METHOD_ID and opcode == 1:
|
||||
(context,) = struct.unpack_from("<I", payload)
|
||||
contexts.pop(context, None)
|
||||
conn.send(context, 0)
|
||||
if context == current:
|
||||
current = None
|
||||
pending = time.monotonic() + SETTLE
|
||||
elif obj in contexts and opcode == 2:
|
||||
hint, purpose = struct.unpack_from("<II", payload)
|
||||
contexts[obj] = [hint, purpose]
|
||||
if obj == current:
|
||||
report.write(True, hint, purpose)
|
||||
if pending is not None and time.monotonic() >= pending:
|
||||
pending = None
|
||||
if current is None:
|
||||
report.write(False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,20 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Holds a game launcher's hidden web interface on one slow core while something else has focus.
|
||||
|
||||
Rockstar's launcher keeps drawing its Chromium interface (SocialClubHelper.exe: a renderer, and a
|
||||
GPU process compositing through DXVK) for as long as it runs, hidden behind the game too, and at a
|
||||
higher priority than the game's (Wine passes Chromium's on: the GPU process ran at nice -10). With
|
||||
Red Dead Redemption 2 in front on the RedMagic that was 1.3 to 2.5 cores under FEX, on a phone
|
||||
already held back by its temperature, for a page nobody sees. Held, riding at the throttle limit
|
||||
went from 46.5 to 48.7 fps, 1% lows from 27.5 to 32.6. So while the focused window belongs to
|
||||
anything but the launcher, every helper thread runs on one core of the slowest cluster at nice 19;
|
||||
when the launcher's own window has focus again (signing in, the game closed) each thread gets its
|
||||
own mask and priority back. Stopping the helpers instead would not hold: proot, the tracer of every
|
||||
guest process, resumes a stopped tracee.
|
||||
|
||||
Focus comes from droiddeck-agent's focus.json (the path is the argument), which the agent rewrites
|
||||
whenever gamescope's focus changes. droiddeck-session starts this for Steam sessions;
|
||||
BL_LAUNCHER_CORES=0 leaves the launchers alone."""
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
@@ -35,7 +19,6 @@ def log(message):
|
||||
|
||||
|
||||
def image(proc, pid):
|
||||
"""A process's program as Wine names it (argv[0]), lower case with backslashes, or None."""
|
||||
try:
|
||||
with open(proc / str(pid) / "cmdline", "rb") as stream:
|
||||
first = stream.read(4096).split(b"\0", 1)[0]
|
||||
@@ -56,7 +39,6 @@ def tasks(proc, pid):
|
||||
|
||||
|
||||
class Cores:
|
||||
"""The kernel calls, apart so a test can stand in for them."""
|
||||
|
||||
def own(self):
|
||||
return os.sched_getaffinity(0)
|
||||
@@ -81,8 +63,6 @@ class Holder:
|
||||
self.core = None
|
||||
|
||||
def slow_core(self):
|
||||
"""The last core of the slowest cluster the session has - not of the game's cores, which
|
||||
the launcher inherits when BL_GAME_CPUS is set: the core the game misses least."""
|
||||
def top(cpu):
|
||||
try:
|
||||
return int((self.cpufreq / f"cpu{cpu}/cpufreq/cpuinfo_max_freq").read_text())
|
||||
@@ -98,8 +78,6 @@ class Holder:
|
||||
yield int(name)
|
||||
|
||||
def hold(self):
|
||||
"""Every helper thread onto the slow core at NICE: new ones, and held ones the program has
|
||||
moved since (Chromium sets its threads' priorities, and Wine passes that on)."""
|
||||
if self.core is None:
|
||||
self.core = self.slow_core()
|
||||
hold = ({self.core}, NICE)
|
||||
@@ -125,8 +103,6 @@ class Holder:
|
||||
return None
|
||||
|
||||
def release(self):
|
||||
"""Every held thread back to its own mask and priority; one started during the hold gets
|
||||
what its process had."""
|
||||
for pid, before in self.held.items():
|
||||
default = before.get(pid) or self.first()
|
||||
for tid in tasks(self.proc, pid):
|
||||
@@ -141,7 +117,6 @@ class Holder:
|
||||
|
||||
|
||||
def focused(snapshot):
|
||||
"""(app id, pid) of the window gamescope has focused, from droiddeck-agent's snapshot."""
|
||||
window = snapshot.get("focusedWindow")
|
||||
for entry in snapshot.get("focusableWindows") or []:
|
||||
if entry.get("window") == window:
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import sys
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
STEAM = os.path.join(HOME, ".local/share/Steam")
|
||||
STORES = os.environ.get("DROIDDECK_STORES_ROOT", "/mnt/droiddeck-stores")
|
||||
TOOLS = re.compile(r"^(Proton |Proton$|SteamLinuxRuntime|Steamworks Shared$)")
|
||||
|
||||
|
||||
def libraries():
|
||||
paths = [STEAM]
|
||||
try:
|
||||
with open(os.path.join(STEAM, "steamapps/libraryfolders.vdf"), encoding="utf-8", errors="replace") as f:
|
||||
paths += [p.replace("\\\\", "\\") for p in re.findall(r'"path"\s+"([^"]+)"', f.read())]
|
||||
except OSError:
|
||||
pass
|
||||
seen = []
|
||||
for path in paths:
|
||||
real = os.path.realpath(path)
|
||||
if real not in seen:
|
||||
seen.append(real)
|
||||
return seen
|
||||
|
||||
|
||||
def roots():
|
||||
found = []
|
||||
for library in libraries():
|
||||
for name in ("common", "compatdata"):
|
||||
found.append((os.path.join(library, "steamapps", name), name == "common"))
|
||||
found.append((os.path.join(HOME, "Games"), False))
|
||||
try:
|
||||
found += [(entry.path, False) for entry in os.scandir(STORES) if entry.is_dir(follow_symlinks=False)]
|
||||
except OSError:
|
||||
pass
|
||||
return [(path, skip_tools) for path, skip_tools in found if os.path.isdir(path)]
|
||||
|
||||
|
||||
def fix(path, st, wanted):
|
||||
if st.st_uid != os.geteuid() or st.st_mode & wanted == wanted:
|
||||
return 0
|
||||
try:
|
||||
os.chmod(path, stat.S_IMODE(st.st_mode) | wanted)
|
||||
return 1
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
|
||||
def walk(top, skip_tools):
|
||||
fixed = 0
|
||||
stack = [(top, True)]
|
||||
while stack:
|
||||
directory, first = stack.pop()
|
||||
try:
|
||||
entries = list(os.scandir(directory))
|
||||
except OSError:
|
||||
continue
|
||||
for entry in entries:
|
||||
if first and skip_tools and TOOLS.match(entry.name):
|
||||
continue
|
||||
try:
|
||||
st = entry.stat(follow_symlinks=False)
|
||||
except OSError:
|
||||
continue
|
||||
if stat.S_ISDIR(st.st_mode):
|
||||
fixed += fix(entry.path, st, stat.S_IRWXU)
|
||||
stack.append((entry.path, False))
|
||||
elif stat.S_ISREG(st.st_mode):
|
||||
fixed += fix(entry.path, st, stat.S_IRUSR | stat.S_IWUSR)
|
||||
return fixed
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
os.nice(19)
|
||||
except OSError:
|
||||
pass
|
||||
total = 0
|
||||
for top, skip_tools in roots():
|
||||
try:
|
||||
fixed = fix(top, os.stat(top), stat.S_IRWXU) + walk(top, skip_tools)
|
||||
except OSError:
|
||||
continue
|
||||
if fixed:
|
||||
print(f"droiddeck-library-perms: {top}: {fixed} made writable")
|
||||
total += fixed
|
||||
print(f"droiddeck-library-perms: {total} files and folders made writable")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,10 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Steam's login1 sleep notifications, backed by DroidDeck's session pause.
|
||||
|
||||
Android owns device power. Suspend here pauses the guest through SessionService;
|
||||
the app's Resume action thaws it and completes PrepareForSleep(false). Steam
|
||||
must see this service before startup or it can stay black after its idle timer.
|
||||
"""
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import os
|
||||
|
||||
@@ -1,32 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Installs a Windows Installer package (.msi) the way Wine's own msiexec would, without running it.
|
||||
|
||||
droiddeck-msi-install <package.msi | installer.exe> <component dir>
|
||||
droiddeck-msi-install --unpack <archive | installer.exe | cabinet> <dir>
|
||||
|
||||
A .msi is a database: which files go to which folder, which registry values to write, which .NET
|
||||
and side-by-side assemblies to register. This reads those tables (msiinfo), unpacks the package's
|
||||
cabinets (cabextract, which knows every compression a cabinet can use) and lays the result out
|
||||
for droiddeck-wincomponents, which puts it into a game's prefix at launch:
|
||||
|
||||
<component dir>/drive_c/... the files, at the paths they get on 64-bit Windows
|
||||
<component dir>/registry.json the registry values, in the view (32/64-bit) Windows uses
|
||||
|
||||
An installer .exe is opened the same way when it is a wrapper around packages: a WiX bundle
|
||||
(Visual C++ 2012 and later, the .NET Core and 5+ runtimes: the packages sit in a cabinet the
|
||||
bundle's own header locates, named in its manifest), a self-extracting cabinet (Visual C++ 2005
|
||||
to 2010) or a self-extracting 7-Zip archive (.NET Framework 4.0 to 4.8). The packages inside are
|
||||
laid out one after the other into the same component dir; the 32- and 64-bit ones both, an ARM64
|
||||
one never. An .exe that is its own setup program (NSIS, InnoSetup) holds no package: an error says so.
|
||||
|
||||
What a package does by running its own code (custom actions such as DXSETUP, self-registering
|
||||
DLLs) cannot be done this way; each is named in the notes, so nothing is left out silently.
|
||||
|
||||
--unpack opens an archive or installer for the caller to take files out of (cabextract for a
|
||||
cabinet or self-extracting cabinet, 7-Zip for the rest) and prints the files it found.
|
||||
|
||||
Prints "progress <text>" lines while it works and ends with "result <json>": the counts and notes.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -47,7 +19,6 @@ SKIP_PLATFORMS = ("arm64", "arm")
|
||||
|
||||
|
||||
def tool_env():
|
||||
"""The environment the tools run in: their own libraries (libmsi, libgsf, libgcab) beside them."""
|
||||
env = dict(os.environ)
|
||||
env["LD_LIBRARY_PATH"] = ":".join(p for p in (str(TOOLS), env.get("LD_LIBRARY_PATH", "")) if p)
|
||||
return env
|
||||
@@ -95,7 +66,6 @@ class MsiError(Exception):
|
||||
|
||||
|
||||
def progress(text, fraction=None):
|
||||
"""A progress line: "progress <text>", or "progress NN% <text>" when how far along is known."""
|
||||
if fraction is None:
|
||||
print("progress " + text, flush=True)
|
||||
else:
|
||||
@@ -103,7 +73,6 @@ def progress(text, fraction=None):
|
||||
|
||||
|
||||
class Span:
|
||||
"""The slice of the whole job one package's progress maps into (a wrapper runs several)."""
|
||||
def __init__(self, lo=0.0, hi=1.0):
|
||||
self.lo, self.hi = lo, hi
|
||||
|
||||
@@ -137,7 +106,6 @@ class Package:
|
||||
self.summary[name.strip().lower()] = value.strip()
|
||||
|
||||
def table(self, name):
|
||||
"""The table's rows as dicts by column name; an absent table has none."""
|
||||
if name in self._tables:
|
||||
return self._tables[name]
|
||||
rows = []
|
||||
@@ -158,7 +126,6 @@ class Package:
|
||||
|
||||
|
||||
def long_name(value):
|
||||
"""A Directory/File name column: "short|long", the long one when there are two."""
|
||||
return value.split("|")[-1]
|
||||
|
||||
|
||||
@@ -176,7 +143,6 @@ KEYWORDS = {"not", "and", "or", "xor", "eqv", "imp"}
|
||||
|
||||
|
||||
class Conditions:
|
||||
"""Windows Installer's condition language, enough of it for what packages ask at install time."""
|
||||
|
||||
def __init__(self, props, feature_state=None, component_state=None):
|
||||
self.props = props
|
||||
@@ -318,7 +284,6 @@ class Conditions:
|
||||
|
||||
|
||||
def win_to_rel(path):
|
||||
"""C:\\windows\\x\\ -> drive_c/windows/x; None for a path off drive C or a folder left out."""
|
||||
if not path:
|
||||
return None
|
||||
match = re.match(r"^[Cc]:\\?(.*)$", path)
|
||||
@@ -341,7 +306,6 @@ def clean_version(version):
|
||||
|
||||
|
||||
def clr_version(path):
|
||||
"""The .NET runtime an assembly was built for ("v4.0.30319"), from its metadata header."""
|
||||
try:
|
||||
data = Path(path).read_bytes()
|
||||
except OSError:
|
||||
@@ -389,7 +353,6 @@ class Installer:
|
||||
return 3 if name in self.included_components else -1
|
||||
|
||||
def directory(self, key):
|
||||
"""The folder a Directory key resolves to, as drive_c/..., or None when it is left out."""
|
||||
if key in self._resolving:
|
||||
return None
|
||||
value = self.props.get(key)
|
||||
@@ -414,7 +377,6 @@ class Installer:
|
||||
return parent + "/" + default
|
||||
|
||||
def format(self, text):
|
||||
"""Formatted text: [Property], [Folder], [#file], [$component], [%env], [\\x], [~]."""
|
||||
if not text:
|
||||
return text
|
||||
|
||||
@@ -449,7 +411,6 @@ class Installer:
|
||||
|
||||
|
||||
def run_set_actions(self):
|
||||
"""The property/folder-setting custom actions, in sequence order; the rest go to the notes."""
|
||||
actions = {row["Action"]: row for row in self.pkg.table("CustomAction")}
|
||||
sequence = {}
|
||||
for table in ("InstallUISequence", "InstallExecuteSequence"):
|
||||
@@ -506,7 +467,6 @@ class Installer:
|
||||
self.included_components.add(name)
|
||||
|
||||
def assemblies(self):
|
||||
"""Component -> where its files go when it is a global assembly (the GAC or winsxs)."""
|
||||
names = {}
|
||||
for row in self.pkg.table("MsiAssemblyName"):
|
||||
names.setdefault(row["Component_"], {})[row["Name"].lower()] = row["Value"]
|
||||
@@ -535,7 +495,6 @@ class Installer:
|
||||
|
||||
@staticmethod
|
||||
def sxs_names(ident):
|
||||
"""Wine's winsxs names for a side-by-side assembly: its folder and, for a policy, the policy folder."""
|
||||
arch = ident.get("processorarchitecture", "x86").lower() or "x86"
|
||||
name = ident.get("name", "").lower()
|
||||
token = ident.get("publickeytoken", "").lower()
|
||||
@@ -548,7 +507,6 @@ class Installer:
|
||||
return "assembly", "%s_%s_%s_%s_none_deadbeef" % (arch, name, token, version), version
|
||||
|
||||
def unpack(self, work):
|
||||
"""Every cabinet in the package, unpacked; returns File key -> unpacked file."""
|
||||
found = {}
|
||||
media = [row for row in self.pkg.table("Media") if row.get("Cabinet", "")]
|
||||
for index, row in enumerate(media):
|
||||
@@ -656,7 +614,6 @@ class Installer:
|
||||
self.registry.append({"hive": hive, "key": key, "name": name, "type": kind, "data": data})
|
||||
|
||||
def registry_data(self, raw):
|
||||
"""A Registry table Value: (type, data) as droiddeck-wincomponents writes them."""
|
||||
if raw is None or raw == "":
|
||||
return "sz", ""
|
||||
if raw.startswith("#x") or raw.startswith("#X"):
|
||||
@@ -773,7 +730,6 @@ class Installer:
|
||||
|
||||
|
||||
def sibling(path, name):
|
||||
"""A file next to [path] called [name], whatever its case; None when there is none."""
|
||||
folder = path.parent
|
||||
candidate = folder / name
|
||||
if candidate.is_file():
|
||||
@@ -786,7 +742,6 @@ def sibling(path, name):
|
||||
|
||||
|
||||
def kind_of(path):
|
||||
"""What a file is by its first bytes: msi, exe, cab or other."""
|
||||
with open(path, "rb") as source:
|
||||
head = source.read(8)
|
||||
if head.startswith(MSI_MAGIC):
|
||||
@@ -806,9 +761,6 @@ def run_tool(args, timeout=1800):
|
||||
|
||||
|
||||
def burn_containers(data):
|
||||
"""A WiX bundle's containers as (offset, size) pairs: the .wixburn section of the stub names
|
||||
their sizes; each is a cabinet laid out after the stub, found by its header since signing can
|
||||
move them. None when the file is no bundle."""
|
||||
try:
|
||||
pe = struct.unpack_from("<I", data, 0x3C)[0]
|
||||
if data[pe:pe + 4] != b"PE\0\0":
|
||||
@@ -845,8 +797,6 @@ def burn_containers(data):
|
||||
|
||||
|
||||
def unpack_burn(path, dest, containers):
|
||||
"""Unpacks a bundle's containers into [dest] and gives the payloads the names its manifest
|
||||
lists (a9 -> packages/vcRuntimeMinimum_amd64/vc_runtimeMinimum_x64.msi)."""
|
||||
data = path.read_bytes()
|
||||
names = {}
|
||||
for index, (start, size) in enumerate(containers):
|
||||
@@ -877,8 +827,6 @@ def unpack_burn(path, dest, containers):
|
||||
|
||||
|
||||
def unpack_installer(path, dest):
|
||||
"""Opens an installer or archive into [dest]: a bundle by its header, a cabinet (or
|
||||
self-extracting one) with cabextract, anything else with 7-Zip."""
|
||||
kind = kind_of(path)
|
||||
if kind == "exe":
|
||||
containers = burn_containers(path.read_bytes())
|
||||
@@ -900,7 +848,6 @@ def unpack_installer(path, dest):
|
||||
|
||||
|
||||
def packages_in(root):
|
||||
"""The Windows Installer packages an unpacked installer holds, shallowest first, by name."""
|
||||
found = []
|
||||
for entry in sorted(root.rglob("*")):
|
||||
if entry.is_file() and kind_of(entry) == "msi":
|
||||
@@ -910,11 +857,6 @@ def packages_in(root):
|
||||
|
||||
|
||||
def choose_packages(found, root):
|
||||
"""Which packages make up the install: the ones at the top of the installer (a bundle keeps
|
||||
each in its own folder, so there every level counts), for the x86 and x64 platforms. The .NET
|
||||
Framework 4.5+ installers carry a complete product (netfx_Full_*) beside the 4.0 parts they
|
||||
patch (netfx_Core_*, netfx_Extended_*) and per-Windows-version copies in NetFx* folders: the
|
||||
complete product wins, the copies are left out."""
|
||||
if not found:
|
||||
return []
|
||||
depth = min(len(entry.relative_to(root).parts) for entry in found)
|
||||
@@ -933,7 +875,6 @@ def choose_packages(found, root):
|
||||
|
||||
|
||||
def install_wrapper(path, out):
|
||||
"""Lays out every package inside an installer wrapper; the result is the sum of them."""
|
||||
total = {"product": "", "version": "", "counts": {"files": 0, "assemblies": 0, "registry": 0}, "notes": [], "packages": []}
|
||||
with tempfile.TemporaryDirectory(dir=str(out.parent), prefix=".unpack-") as work:
|
||||
dest = Path(work) / "x"
|
||||
@@ -968,9 +909,6 @@ NESTED_SUFFIXES = (".7z", ".zip", ".cab", ".exe", ".msi", ".rar", ".xz", ".gz",
|
||||
|
||||
|
||||
def open_nested(dest, depth=0):
|
||||
"""Archives inside an unpacked installer (QuickTime's cabinets, an NSIS pack's payloads) are
|
||||
opened in place, one "<name>.nested" folder per archive, two levels deep: the same layout the
|
||||
component recordings (winlator-contents tools/snapshot/record.py) map their file sources to."""
|
||||
if depth > 1:
|
||||
return 0
|
||||
opened = 0
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Runs a program from the desktop: a Windows program through the Proton Steam has chosen, a Linux
|
||||
program (x86 ones under FEX), an AppImage, or a script (under FEX beside x86 programs, as a game's
|
||||
start script is). Shared storage is noexec: FEX runs x86 programs there where they lie (libblsession's
|
||||
noexec.c), while a native one is copied - alone into the cache, or with its folder by the app once (as
|
||||
Add an app does) when that holds native programs or libraries. A Steam library's games are Steam's.
|
||||
|
||||
droiddeck-open [--window | --terminal] FILE [ARGS...] the file manager's Run entries
|
||||
droiddeck-open --exec FILE [ARGS...] an exec the kernel refused (libblsession)
|
||||
droiddeck-open --install the Run entries and default handlers
|
||||
|
||||
The desktop composites in software, so a program started from it goes full screen on the GPU
|
||||
(droiddeck-gpu), as the menu's games do: --window keeps it in a desktop window instead, --terminal
|
||||
runs it in Konsole. A plain script stays on the desktop, and an exec whose output is read (a terminal,
|
||||
a pipe, a file) stays where it was started.
|
||||
"""
|
||||
import fcntl
|
||||
import hashlib
|
||||
import os
|
||||
@@ -120,7 +105,6 @@ def for_x86(script):
|
||||
|
||||
|
||||
def runnable(path):
|
||||
"""The program itself, or a copy in the cache of a native one on noexec storage."""
|
||||
if not noexec(path) or machine(head(path)) in EMULATED:
|
||||
return path
|
||||
st = os.stat(path)
|
||||
@@ -141,7 +125,6 @@ def runnable(path):
|
||||
|
||||
|
||||
def appimage(path):
|
||||
"""The image unpacked once into the cache, laid out as droiddeck-appimage-run expects."""
|
||||
st = os.stat(path)
|
||||
real = os.path.realpath(path)
|
||||
key = hashlib.sha1(("%s\0%d\0%d" % (real, st.st_size, st.st_mtime_ns)).encode("utf-8")).hexdigest()[:16]
|
||||
@@ -150,7 +133,6 @@ def appimage(path):
|
||||
|
||||
|
||||
def once(key, make):
|
||||
"""[make]() for [key] one start at a time: a second start waits for the first, then finds it done."""
|
||||
locks = os.path.join(CACHE, "locks")
|
||||
os.makedirs(locks, exist_ok=True)
|
||||
with open(os.path.join(locks, key), "w") as lock:
|
||||
@@ -203,8 +185,6 @@ def import_of(key, what):
|
||||
|
||||
|
||||
def imported(what, real, key, name):
|
||||
"""[real] added by the app instead, as Add an app adds it (to the menu too): an AppImage whose hard
|
||||
links (sharun's) only the app's own proot can make, or a folder of native programs off noexec storage."""
|
||||
launch = os.environ.get("BL_LAUNCH_DIR")
|
||||
if not launch or not os.path.isdir(launch):
|
||||
raise RuntimeError("%s cannot run from here; add it in DroidDeck with Add an app." % name)
|
||||
@@ -235,9 +215,6 @@ def imported(what, real, key, name):
|
||||
|
||||
|
||||
def game_folder(path):
|
||||
"""The folder of [path] when it runs only from a copy: on noexec storage, holding native programs or
|
||||
libraries (besides [path]) that it starts or loads. Not the storage itself, one of Android's folders
|
||||
or a Steam library."""
|
||||
real = os.path.realpath(path)
|
||||
folder = os.path.dirname(real)
|
||||
if in_steam_library(real) or not noexec(folder):
|
||||
@@ -263,12 +240,10 @@ def game_folder(path):
|
||||
|
||||
|
||||
def in_steam_library(path):
|
||||
"""Whether [path] is in a Steam library: its games are Steam's to start, never copied in."""
|
||||
return "steamapps" in os.path.realpath(path).lower().split(os.sep)
|
||||
|
||||
|
||||
def storage_root(folder):
|
||||
"""The top of the storage [folder] is on: the last folder above it on the same file system."""
|
||||
top = folder
|
||||
try:
|
||||
dev = os.stat(folder).st_dev
|
||||
@@ -280,7 +255,6 @@ def storage_root(folder):
|
||||
|
||||
|
||||
def copied_in(path):
|
||||
"""The app's copy of [path]'s folder, added (once) for it."""
|
||||
real = os.path.realpath(path)
|
||||
key = hashlib.sha1(("folder\0%s" % real).encode("utf-8")).hexdigest()[:16]
|
||||
name = os.path.basename(os.path.dirname(real))
|
||||
@@ -288,7 +262,6 @@ def copied_in(path):
|
||||
|
||||
|
||||
def steam_title(path):
|
||||
"""The Steam game [path] is the program of: Steam starts it, with the client most games need."""
|
||||
try:
|
||||
run = runpy.run_path(PROTON_RUN)
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or run["STEAM_ROOT"]
|
||||
@@ -299,7 +272,6 @@ def steam_title(path):
|
||||
|
||||
|
||||
def command(path, args, what, window=False, appid=None):
|
||||
"""(command, working directory) that runs [path] in place."""
|
||||
folder = os.path.dirname(path)
|
||||
if what == "steam":
|
||||
return [STEAM_LAUNCH, "desktop", appid], folder
|
||||
@@ -321,7 +293,6 @@ def on_desktop(env):
|
||||
|
||||
|
||||
def unattended(env):
|
||||
"""Nobody reads the output: it goes to /dev/null or the desktop's log, as from Dolphin or the menu."""
|
||||
try:
|
||||
out = os.fstat(1)
|
||||
except OSError:
|
||||
@@ -337,7 +308,6 @@ def unattended(env):
|
||||
|
||||
|
||||
def placed(cmd, what, mode, env):
|
||||
"""[cmd] where it shows: full screen on the GPU from the desktop, else where it was started."""
|
||||
if mode == "terminal" and what not in ("windows", "steam") and shutil.which("konsole"):
|
||||
return ["konsole", "--hold", "-e"] + cmd
|
||||
if mode == "window" or what in ("script", "steam") or not on_desktop(env):
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""A game's web links to Android: Wine's winebrowser starts this (named as the browser in the
|
||||
prefix's HKCU\\Software\\Wine\\WineBrowser, and as xdg-open first on a game's PATH), and an
|
||||
http(s) address goes to the app, which opens it in Android's browser - so an EOS sign-in step or a
|
||||
store page can be finished on the phone. Anything else goes on to the system's own xdg-open.
|
||||
|
||||
The session channel is $BL_LAUNCH_DIR/stores; Wine may not pass that variable on to what it
|
||||
starts, so droiddeck-proton also leaves it in LAUNCH_DIR_FILE."""
|
||||
|
||||
import json
|
||||
import os
|
||||
@@ -25,7 +18,6 @@ def hand_over(url, launch_dir):
|
||||
|
||||
|
||||
def where(url):
|
||||
"""scheme://host only, for the log: no path, no query."""
|
||||
from urllib.parse import urlsplit
|
||||
try:
|
||||
u = urlsplit(url)
|
||||
|
||||
@@ -89,7 +89,6 @@ def rpcs3_shader_mode():
|
||||
|
||||
|
||||
def ini_section(lines, name):
|
||||
"""(start, end) line indices of [name]'s body, or None."""
|
||||
start = None
|
||||
for i, l in enumerate(lines):
|
||||
t = l.strip()
|
||||
@@ -102,9 +101,6 @@ def ini_section(lines, name):
|
||||
|
||||
|
||||
def patch_ini_section(path, section, body, what, needle="SDL-", require=None, done="Player 1 on the controller"):
|
||||
"""Add body's lines to [section] of an ini the emulator wrote itself, unless the section
|
||||
already binds a controller (needle). Missing file: nothing - the emulator writes its own
|
||||
defaults on first run and this runs again."""
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
@@ -178,7 +174,6 @@ def ini_get(path, section, key):
|
||||
|
||||
|
||||
def ini_set(path, section, key, value):
|
||||
"""Sets one key (the first of that name) in [section], adding either as needed."""
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
lines = f.read().splitlines()
|
||||
span = ini_section(lines, section)
|
||||
@@ -440,9 +435,6 @@ def armsx2():
|
||||
|
||||
|
||||
def armsx2_bios(ini):
|
||||
"""PCSX2 boots the one BIOS file named in [Filenames] BIOS (inside [Folders] Bios); its first-time
|
||||
setup is what names it. With that skipped, the first dump in the folder is named here - a US one
|
||||
first - while none is named or the named one is gone. A choice made in ARMSX2 is kept."""
|
||||
folder = ini_get(ini, "Folders", "Bios") or ps2_bios_folder()
|
||||
if not os.path.isabs(folder):
|
||||
folder = os.path.join(os.path.dirname(os.path.dirname(ini)), folder)
|
||||
@@ -518,12 +510,6 @@ DOLPHIN_DATA = "/usr/share/dolphin-emu"
|
||||
|
||||
|
||||
def dolphin_data():
|
||||
"""The Dolphin build in the catalog finds its own data - the GameCube fonts, the per-game fixes
|
||||
(GameSettings: GUT.ini puts Ultimate Spider-Man on the MMU), its icons and shaders - only at the
|
||||
fixed /usr/share/dolphin-emu it was built for; there is no setting or variable to move it. Here it
|
||||
runs from a copy unpacked under /tmp (no FUSE), so it found none of it: a GameCube game stopped
|
||||
on "Windows-1252 fonts are not loaded", another on an invalid write the missing game fix would
|
||||
have prevented. So the folder is unpacked from the AppImage to that path, once per AppImage."""
|
||||
import shutil, subprocess, tempfile
|
||||
try:
|
||||
st = os.stat(DOLPHIN_APPIMAGE)
|
||||
@@ -716,7 +702,6 @@ def melonds_geometry():
|
||||
|
||||
|
||||
def toml_get(lines, table, key):
|
||||
"""The raw value of key in [table], or None."""
|
||||
inside = False
|
||||
for l in lines:
|
||||
t = l.strip()
|
||||
@@ -728,7 +713,6 @@ def toml_get(lines, table, key):
|
||||
|
||||
|
||||
def toml_set(lines, table, key, value):
|
||||
"""key = value in [table]; the table is added at the end when missing."""
|
||||
start = None
|
||||
for i, l in enumerate(lines):
|
||||
t = l.strip()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Audio stays on the session's PulseAudio, so WirePlumber runs its upstream video-only profile.
|
||||
set -u
|
||||
|
||||
bundle=/usr/local/lib/droiddeck-pipewire.tzst
|
||||
|
||||
@@ -31,7 +31,6 @@ def fetch_json(url):
|
||||
|
||||
|
||||
def pick_asset(source):
|
||||
"""(release tag, asset url, sha512 url or None) for the newest full release with an ARM64 build."""
|
||||
repo, pattern = SOURCES[source]
|
||||
for release in fetch_json(RELEASES % repo + "?per_page=15"):
|
||||
if release.get("draft") or release.get("prerelease"):
|
||||
@@ -58,8 +57,6 @@ def release_asset(source, tag):
|
||||
|
||||
|
||||
def download(url, path):
|
||||
"""Resumable, because this is hundreds of megabytes over a phone's connection. curl is used
|
||||
rather than urllib so a retry continues rather than starting again."""
|
||||
log("downloading %s" % os.path.basename(path))
|
||||
rc = subprocess.call([
|
||||
"curl", "-fL", "--retry", "5", "--retry-delay", "3", "--retry-connrefused",
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Runs a Windows program with the Proton the Steam client has chosen for it.
|
||||
|
||||
droiddeck-proton-run [--window] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run --app ID [--dir FOLDER] [--options TEXT] [PROGRAM [ARGS...]]
|
||||
|
||||
The program belongs to an installed Steam game when it sits in one's folder, to a prefix when it
|
||||
sits in one's drive_c, or to a non-Steam shortcut that names it; any other program gets a prefix of
|
||||
its own, under the id the client gives a new shortcut. That title's CompatToolMapping entry in
|
||||
config.vdf picks the tool, else the client's default for all other titles ("0"). The tool is
|
||||
started as the client starts it - its toolmanifest's command line, the waitforexitandrun verb and
|
||||
the STEAM_COMPAT_* environment - so its wrapper applies the game's settings, components and audio.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D.
|
||||
--app starts one game without the Steam client (its Start without Steam): a Steam game's default
|
||||
Windows launch option from appinfo.vdf when no program is given, else the program in that
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -30,7 +14,10 @@ BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
STATE = os.path.join(HOME, ".local", "share", "droiddeck-compat", "state.json")
|
||||
EXTRA_LIBRARIES = ("/mnt/droiddeck", "/mnt/droiddeck-sd")
|
||||
SYSTEM_TOOLS = ("/usr/share/steam/compatibilitytools.d", "/usr/local/share/steam/compatibilitytools.d")
|
||||
DESKTOP_GL = {"LIBGL_ALWAYS_SOFTWARE": "1", "GALLIUM_DRIVER": "llvmpipe"}
|
||||
NOT_DESKTOP_GL = ("MESA_LOADER_DRIVER_OVERRIDE", "LIBGL_KOPPER_DRI2")
|
||||
VERB = "waitforexitandrun"
|
||||
VERBS = (VERB, "run")
|
||||
SHORTCUT_BIT = 0x80000000
|
||||
STEAM_APP_LIMIT = 2 ** 31
|
||||
|
||||
@@ -83,7 +70,6 @@ def mapping(root):
|
||||
|
||||
|
||||
def tools(root):
|
||||
"""Windows compatibility tools this runtime can start, by the name config.vdf uses."""
|
||||
found = {}
|
||||
for base in [os.path.join(root, "compatibilitytools.d")] + list(SYSTEM_TOOLS):
|
||||
try:
|
||||
@@ -113,7 +99,6 @@ def state_default():
|
||||
|
||||
|
||||
def choose_tool(appid, current, available):
|
||||
"""(tool name, why) from the client's mapping, else the session's own default."""
|
||||
for key, why in ((appid, "Steam's choice for this title"), ("0", "Steam's default")):
|
||||
name = current.get(key)
|
||||
if name in available:
|
||||
@@ -136,7 +121,6 @@ class Target:
|
||||
|
||||
|
||||
def ancestors(path):
|
||||
"""(folder, the entry below it on the way to path) from the program's folder up to /."""
|
||||
child, folder = path, os.path.dirname(path)
|
||||
while True:
|
||||
yield folder, os.path.basename(child)
|
||||
@@ -185,9 +169,9 @@ def steam_game(program, libs):
|
||||
def prefix_of(program):
|
||||
for folder, below in ancestors(program):
|
||||
parent = os.path.dirname(folder)
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and os.path.basename(folder).isdigit():
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and re.fullmatch(r"-?[0-9]+", os.path.basename(folder)):
|
||||
library = os.path.dirname(os.path.dirname(parent))
|
||||
return Target(os.path.basename(folder), folder, os.path.dirname(program), library, "prefix")
|
||||
return Target(str(int(os.path.basename(folder)) % 2 ** 32), folder, os.path.dirname(program), library, "prefix")
|
||||
return None
|
||||
|
||||
|
||||
@@ -203,7 +187,6 @@ def same_file(a, b):
|
||||
|
||||
|
||||
def shortcut_entries(root):
|
||||
"""(appid, exe, start dir) of the client's non-Steam shortcuts and the app's added games."""
|
||||
entries = []
|
||||
try:
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
@@ -230,16 +213,71 @@ def shortcut_entries(root):
|
||||
return entries
|
||||
|
||||
|
||||
def prefix_folder(root, appid):
|
||||
folder = os.path.join(root, "steamapps", "compatdata")
|
||||
try:
|
||||
names = sorted(os.listdir(folder))
|
||||
except OSError:
|
||||
names = []
|
||||
candidates = []
|
||||
for name in names:
|
||||
if not re.fullmatch(r"-?[0-9]+", name):
|
||||
continue
|
||||
try:
|
||||
matches = int(name) % 2 ** 32 == appid % 2 ** 32
|
||||
except ValueError:
|
||||
continue
|
||||
match = os.path.join(folder, name)
|
||||
if matches and os.path.isdir(match):
|
||||
candidates.append((os.path.isdir(os.path.join(match, "pfx")),
|
||||
name == str(appid % 2 ** 32), name, match))
|
||||
if candidates:
|
||||
return min(candidates, key=lambda item: (not item[0], not item[1], item[2]))[3]
|
||||
return os.path.join(folder, str(appid % 2 ** 32))
|
||||
|
||||
|
||||
def vdf_string(token):
|
||||
return re.sub(r'\\(.)', r'\1', token[1:-1]) if token.startswith('"') else ""
|
||||
|
||||
|
||||
def steam_options(app, root):
|
||||
try:
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
account = tool["account_dir"](root)
|
||||
if not account:
|
||||
return ""
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f:
|
||||
shortcuts = tool["parse"](f.read()).get("shortcuts", {})
|
||||
for value in shortcuts.values():
|
||||
if isinstance(value, dict) and (value.get("appid", value.get("AppId")) or 0) & 0xFFFFFFFF == int(app):
|
||||
options = value.get("LaunchOptions", value.get("launchoptions", ""))
|
||||
return options if isinstance(options, str) else ""
|
||||
return ""
|
||||
tokens = compat()["tokenize"](read_text(os.path.join(account, "config", "localconfig.vdf")) or "")
|
||||
start = compat()["find_block"](tokens, ["UserLocalConfigStore", "Software", "Valve", "Steam", "apps", app])
|
||||
if start is None:
|
||||
return ""
|
||||
end, depth = compat()["block_end"](tokens, start), 0
|
||||
for i in range(start + 1, end):
|
||||
if tokens[i] in ("{", "}"):
|
||||
depth += 1 if tokens[i] == "{" else -1
|
||||
elif depth == 0 and tokens[i].lower() == '"launchoptions"' and i + 1 < end:
|
||||
return vdf_string(tokens[i + 1])
|
||||
except (OSError, ValueError, IndexError, KeyError, TypeError, AttributeError, struct.error):
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def shortcut(program, root):
|
||||
for appid, exe, start in shortcut_entries(root):
|
||||
if same_file(program, exe):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "shortcut", start if os.path.isdir(start) else None)
|
||||
return None
|
||||
|
||||
|
||||
def own_id(program):
|
||||
"""The id the client gives a new shortcut: the CRC of its quoted target and its name."""
|
||||
name = os.path.splitext(os.path.basename(program))[0]
|
||||
return zlib.crc32(('"%s"%s' % (program, name)).encode("utf-8")) | SHORTCUT_BIT
|
||||
|
||||
@@ -250,10 +288,19 @@ def locate(program, root):
|
||||
if found:
|
||||
return found
|
||||
appid = own_id(program)
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "own")
|
||||
|
||||
|
||||
def fixed(program, root, appid):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
os.path.dirname(program), root, "fixed")
|
||||
|
||||
|
||||
def prefix_id(value):
|
||||
return value if value.isdigit() and not value.startswith("0") and int(value) <= 0xFFFFFFFF else None
|
||||
|
||||
|
||||
def split_words(text):
|
||||
try:
|
||||
return shlex.split(text or "")
|
||||
@@ -262,8 +309,6 @@ def split_words(text):
|
||||
|
||||
|
||||
def split_options(text):
|
||||
"""A shortcut's launch options: NAME=value words before %command% go to the environment, the words
|
||||
after it - or all of them, without %command% - are the program's arguments."""
|
||||
words = split_words(text)
|
||||
if "%command%" not in words:
|
||||
return {}, words
|
||||
@@ -277,7 +322,6 @@ def split_options(text):
|
||||
|
||||
|
||||
def find_file(base, relative):
|
||||
"""base/relative, matching each part without regard to case as Windows does."""
|
||||
path = base
|
||||
for part in [p for p in relative.replace("\\", "/").split("/") if p and p != "."]:
|
||||
exact = os.path.join(path, part)
|
||||
@@ -304,7 +348,6 @@ def steam_install(appid, root):
|
||||
|
||||
|
||||
def steam_launch(appid, root):
|
||||
"""(target, program, arguments) for a Steam game's default Windows launch option, or None."""
|
||||
library, install = steam_install(appid, root)
|
||||
if not install or not os.path.isdir(install):
|
||||
return None
|
||||
@@ -325,19 +368,19 @@ def steam_launch(appid, root):
|
||||
|
||||
|
||||
def shortcut_target(appid, program, start, root):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)), os.path.dirname(program), root,
|
||||
appid = int(appid) % 2 ** 32
|
||||
return Target(str(appid), prefix_folder(root, appid), os.path.dirname(program), root,
|
||||
"shortcut", start if start and os.path.isdir(start) else None)
|
||||
|
||||
|
||||
def steam_launches(target, program, root):
|
||||
"""Whether a launch option of the Steam game starts [program]: then Steam should start it."""
|
||||
if target.kind != "steam":
|
||||
return False
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(target.appid, {})
|
||||
return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ())
|
||||
|
||||
|
||||
def environment(env, target, tool_folder, root, window=False):
|
||||
def environment(env, target, tool_folder, root, window=False, game_id=None):
|
||||
env = dict(env)
|
||||
steamapps = [os.path.join(lib, "steamapps") for lib in libraries(root)]
|
||||
env.update({
|
||||
@@ -355,28 +398,52 @@ def environment(env, target, tool_folder, root, window=False):
|
||||
else:
|
||||
game = str(number << 32 | 0x02000000)
|
||||
env.update(SteamAppId="0", STEAM_COMPAT_APP_ID="0", SteamGameId=game, SteamOverlayGameId=game)
|
||||
if game_id:
|
||||
env.update(SteamGameId=game_id, SteamOverlayGameId=game_id)
|
||||
if window:
|
||||
env.setdefault("PROTON_USE_WINED3D", "1")
|
||||
env.update(DESKTOP_GL)
|
||||
for name in NOT_DESKTOP_GL:
|
||||
env.pop(name, None)
|
||||
return env
|
||||
|
||||
|
||||
def windows_path(path):
|
||||
def windows_path(path, compatdata=None):
|
||||
if compatdata:
|
||||
drive = os.path.join(compatdata, "pfx", "drive_c")
|
||||
inside = os.path.relpath(path, drive)
|
||||
if inside != "." and not inside.startswith(".."):
|
||||
return "C:\\" + inside.replace("/", "\\")
|
||||
return "Z:" + path.replace("/", "\\")
|
||||
|
||||
|
||||
def arguments(program, args):
|
||||
def arguments(program, args, desktop=None, compatdata=None):
|
||||
if program.lower().endswith(".msi"):
|
||||
return ["msiexec", "/i", windows_path(program)] + args
|
||||
if desktop:
|
||||
return ["explorer.exe", "/desktop=droiddeck,%s" % desktop, windows_path(program, compatdata)] + args
|
||||
return [program] + args
|
||||
|
||||
|
||||
def main(argv):
|
||||
window = False
|
||||
app, start, options = None, None, ""
|
||||
prefix = None
|
||||
verb = VERB
|
||||
game_id = None
|
||||
desktop = None
|
||||
app, start, options = None, None, None
|
||||
while argv and argv[0].startswith("--"):
|
||||
option = argv.pop(0)
|
||||
if option == "--window":
|
||||
window = True
|
||||
elif option == "--prefix" and argv and prefix_id(argv[0]):
|
||||
prefix = argv.pop(0)
|
||||
elif option == "--verb" and argv and argv[0] in VERBS:
|
||||
verb = argv.pop(0)
|
||||
elif option == "--game-id" and argv and argv[0].isdigit() and argv[0] != "0":
|
||||
game_id = argv.pop(0)
|
||||
elif option == "--desktop" and argv and re.fullmatch(r"[1-9][0-9]{2,4}x[1-9][0-9]{2,4}", argv[0]):
|
||||
desktop = argv.pop(0)
|
||||
elif option in ("--app", "--dir", "--options") and argv:
|
||||
value = argv.pop(0)
|
||||
if option == "--app":
|
||||
@@ -394,9 +461,11 @@ def main(argv):
|
||||
say("%s is not an app id" % app)
|
||||
return 2
|
||||
if not argv and app is None:
|
||||
say("usage: droiddeck-proton-run [--window] PROGRAM [ARGS...]")
|
||||
say("usage: droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
if options is None:
|
||||
options = steam_options(app, root) if app is not None else ""
|
||||
extra, args = split_options(options)
|
||||
if not argv:
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
@@ -416,6 +485,8 @@ def main(argv):
|
||||
args = args + argv[1:]
|
||||
if app is not None and int(app) >= STEAM_APP_LIMIT:
|
||||
target = shortcut_target(app, program, start, root)
|
||||
elif prefix:
|
||||
target = fixed(program, root, prefix)
|
||||
else:
|
||||
target = locate(program, root)
|
||||
available = tools(root)
|
||||
@@ -425,7 +496,7 @@ def main(argv):
|
||||
return 69
|
||||
folder, command = available[name]
|
||||
os.makedirs(target.compatdata, exist_ok=True)
|
||||
env = environment(os.environ, target, folder, root, window)
|
||||
env = environment(os.environ, target, folder, root, window, game_id)
|
||||
env.update(extra)
|
||||
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
|
||||
", without the Steam client" if app is not None else ""))
|
||||
@@ -434,7 +505,7 @@ def main(argv):
|
||||
except OSError:
|
||||
os.chdir(os.path.dirname(program))
|
||||
entry = os.path.join(folder, command)
|
||||
os.execve(entry, [entry, VERB] + arguments(program, args), env)
|
||||
os.execve(entry, [entry, verb] + arguments(program, args, desktop, target.compatdata), env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/python3
|
||||
import array
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
|
||||
SOCKET_FILE = "/etc/droiddeck/root-socket"
|
||||
|
||||
|
||||
def socket_name():
|
||||
name = os.environ.get("DROIDDECK_ROOT_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.root")
|
||||
|
||||
|
||||
def frame(sock, kind, payload):
|
||||
sock.sendall(kind.encode() + struct.pack(">i", len(payload)) + payload)
|
||||
|
||||
|
||||
def read_exact(sock, n):
|
||||
data = b""
|
||||
while len(data) < n:
|
||||
chunk = sock.recv(n - len(data))
|
||||
if not chunk:
|
||||
return None
|
||||
data += chunk
|
||||
return data
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 2 or argv[1] in ("-h", "--help"):
|
||||
print("usage: droiddeck-root [--check] command [arg ...]", file=sys.stderr)
|
||||
return 2
|
||||
try:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(socket_name())
|
||||
except OSError as e:
|
||||
print(f"droiddeck-root: DroidDeck's root service is not reachable: {e}", file=sys.stderr)
|
||||
return 126
|
||||
if argv[1] == "--check":
|
||||
return 0
|
||||
env = dict(os.environ)
|
||||
for name in ("LD_PRELOAD", "PROOT_FASTPATH", "DROIDDECK_ROOT_SOCKET"):
|
||||
env.pop(name, None)
|
||||
for name in [k for k in env if k.startswith("PROOT_")]:
|
||||
env.pop(name, None)
|
||||
try:
|
||||
cwd = os.getcwd()
|
||||
except OSError:
|
||||
cwd = "/root"
|
||||
body = json.dumps({"argv": argv[1:], "env": env, "cwd": cwd}).encode()
|
||||
fds = array.array("i", [0, 1, 2])
|
||||
sock.sendmsg([b"R" + struct.pack(">i", len(body))], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, fds)])
|
||||
sock.sendall(body)
|
||||
|
||||
def forward(signum, _frame):
|
||||
try:
|
||||
frame(sock, "S", str(signum).encode())
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGQUIT, signal.SIGUSR1, signal.SIGUSR2):
|
||||
signal.signal(signum, forward)
|
||||
signal.signal(signal.SIGTSTP, signal.SIG_IGN)
|
||||
status = 1
|
||||
while True:
|
||||
try:
|
||||
head = read_exact(sock, 5)
|
||||
except InterruptedError:
|
||||
continue
|
||||
except OSError:
|
||||
break
|
||||
if head is None:
|
||||
break
|
||||
kind = chr(head[0])
|
||||
payload = read_exact(sock, struct.unpack(">i", head[1:])[0]) or b""
|
||||
if kind == "E":
|
||||
print("droiddeck-root: " + payload.decode(errors="replace"), file=sys.stderr)
|
||||
elif kind == "X":
|
||||
status = int(payload.decode() or "1")
|
||||
break
|
||||
return status
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
@@ -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/) vulkan[depth] = 1
|
||||
if (program ~ /vulkan|uplay|ubisoft/) vulkan[depth] = 1
|
||||
next
|
||||
}
|
||||
if (n == 3) pending = part[2]
|
||||
@@ -144,8 +144,6 @@ unseed() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# The ledger lines whose values the registry still holds, in both views where we wrote both. A Proton
|
||||
# update replaces its default_pfx system.reg but not our ledger beside it, and new prefixes copy both.
|
||||
present() { awk -F'\t' -v hive="$hive" '
|
||||
NR == FNR {
|
||||
path = $1
|
||||
@@ -192,10 +190,14 @@ present() { awk -F'\t' -v hive="$hive" '
|
||||
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 \
|
||||
/mnt/droiddeck-lib/*/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
/mnt/droiddeck-lib/*/x86-64/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
/root/Games/*/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
"$steam_root"/compatibilitytools.d/*/files/share/default_pfx*/system.reg \
|
||||
"$steam_root"/steamapps/compatdata/*/pfx/system.reg \
|
||||
/mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg \
|
||||
/mnt/droiddeck-lib/*/steamapps/compatdata/*/pfx/system.reg \
|
||||
/mnt/droiddeck-lib/*/x86-64/steamapps/compatdata/*/pfx/system.reg \
|
||||
/root/Games/*/steamapps/compatdata/*/pfx/system.reg; do
|
||||
[ -f "$reg" ] && regs+=("$reg")
|
||||
done
|
||||
@@ -243,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 markers out of $reg"
|
||||
echo "== took Vulkan runtime and Ubisoft Connect markers out of $reg"
|
||||
fi
|
||||
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
|
||||
declare -A held=()
|
||||
|
||||
@@ -14,22 +14,59 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
if [ "$(stat -c %s "$BL_LOG" 2>/dev/null || echo 0)" -gt 8388608 ]; then
|
||||
mv -f "$BL_LOG" "$BL_LOG.1"
|
||||
fi
|
||||
exec > >({ dd of="$BL_LOG" oflag=append conv=notrunc iflag=count_bytes count="${BL_LOG_CAP:-268435456}" bs=65536 status=none; cat >/dev/null; }) 2>&1
|
||||
dd=$(command -v gnudd || echo dd)
|
||||
exec > >({ "$dd" of="$BL_LOG" oflag=append conv=notrunc iflag=count_bytes count="${BL_LOG_CAP:-268435456}" bs=65536 status=none; cat >/dev/null; }) 2>&1
|
||||
echo "== droiddeck-session $(date) mode=$mode $*"
|
||||
echo "== uid=$(id -u) size=${BL_WIDTH:-?}x${BL_HEIGHT:-?} fps=${BL_FPS:-0} icd=${VK_ICD_FILENAMES:-none}"
|
||||
echo "== uid=$(id -u) size=${BL_WIDTH:-?}x${BL_HEIGHT:-?} icd=${VK_ICD_FILENAMES:-none}"
|
||||
echo "== gamescope: $(gamescope --version 2>&1 | head -1) at $(command -v gamescope)"
|
||||
echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)"
|
||||
fi
|
||||
|
||||
sync_timezone() {
|
||||
local zone=${TZ:-}
|
||||
case "$zone" in ''|/*|*..*) return 0 ;; esac
|
||||
[ -f "/usr/share/zoneinfo/$zone" ] || return 0
|
||||
if [ "$(readlink /etc/localtime 2>/dev/null)" != "/usr/share/zoneinfo/$zone" ]; then
|
||||
ln -sfn "/usr/share/zoneinfo/$zone" /etc/localtime.droiddeck && mv -Tf /etc/localtime.droiddeck /etc/localtime || return 0
|
||||
fi
|
||||
[ "$(cat /etc/timezone 2>/dev/null)" = "$zone" ] || printf '%s\n' "$zone" > /etc/timezone
|
||||
} 2>/dev/null
|
||||
sync_timezone
|
||||
|
||||
write_system_bus_config() {
|
||||
mkdir -p /run/dbus /usr/local/share/droiddeck
|
||||
cat > /usr/local/share/droiddeck/system-bus.conf <<'BUSCONF'
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<type>system</type>
|
||||
<listen>unix:path=/run/dbus/system_bus_socket</listen>
|
||||
<auth>EXTERNAL</auth>
|
||||
<servicedir>/usr/share/droiddeck/system-services</servicedir>
|
||||
<policy context="default">
|
||||
<allow user="*"/>
|
||||
<allow own="*"/>
|
||||
<allow send_destination="*"/>
|
||||
<allow receive_sender="*"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
BUSCONF
|
||||
rm -f /run/dbus/system_bus_socket
|
||||
}
|
||||
|
||||
prepare_locale() {
|
||||
local dir=/usr/lib/locale stamp=/usr/lib/locale/.droiddeck-archive want have= pkg
|
||||
pkg=(/var/lib/pacman/local/glibc-[0-9]*)
|
||||
want=${pkg[0]##*/}
|
||||
if [ -d /var/lib/pacman/local ]; then
|
||||
pkg=(/var/lib/pacman/local/glibc-[0-9]*)
|
||||
want=${pkg[0]##*/}
|
||||
else
|
||||
want=libc6-$(dpkg-query -W -f='${Version}' libc6 2>/dev/null)
|
||||
fi
|
||||
[ -f "$stamp" ] && read -r have < "$stamp"
|
||||
[ "$have" = "$want" ] && [ -f "$dir/locale-archive" ] && [ ! "$dir/locale-archive" -nt "$stamp" ] && return 0
|
||||
[ -d "$dir/C.utf8" ] && command -v localedef >/dev/null 2>&1 || return 0
|
||||
DROIDDECK_LINK_RENAME=1 localedef --add-to-archive --replace "$dir/C.utf8" >/dev/null 2>&1 || return 0
|
||||
rm -f /usr/lib/gconv/gconv-modules.cache
|
||||
rm -f /usr/lib/gconv/gconv-modules.cache /usr/lib/aarch64-linux-gnu/gconv/gconv-modules.cache
|
||||
command -v iconvconfig >/dev/null 2>&1 && iconvconfig >/dev/null 2>&1
|
||||
printf '%s\n' "$want" > "$stamp"
|
||||
echo "== locale archive built for $want"
|
||||
@@ -62,10 +99,37 @@ clear_stale_tmp() {
|
||||
[ -z "${BL_INSIDE:-}" ] && clear_stale_tmp
|
||||
if [ -z "${BL_INSIDE:-}" ]; then
|
||||
if [ "${BL_ZRAM:-0}" = 1 ]; then printf 0 > /tmp/.bl-zram; else rm -f /tmp/.bl-zram; fi
|
||||
rm -f /tmp/.bl-clock
|
||||
head -c 8 /dev/zero > /tmp/.bl-clock
|
||||
fi
|
||||
|
||||
steam_devtools() {
|
||||
_bl_cdp=()
|
||||
if [ -f "$steam_root/.cef-enable-remote-debugging" ]; then
|
||||
if timeout 5 python3 -c 'import socket, sys
|
||||
s = socket.socket()
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(("127.0.0.1", int(sys.argv[1])))' "$1" 2>/dev/null; then
|
||||
BL_CDP_PORT=$1
|
||||
return 0
|
||||
fi
|
||||
echo "== steam: port $1 is held by another app; Decky cannot load this session and Steam's devtools use another port"
|
||||
fi
|
||||
BL_CDP_PORT=$((20000 + RANDOM % 30000))
|
||||
_bl_cdp=(-cef-enable-debugging -devtools-port "$BL_CDP_PORT")
|
||||
}
|
||||
|
||||
steam_update_stuck() {
|
||||
[ "$1" -lt 60 ] || steam_updates=0
|
||||
local stamp
|
||||
stamp=$(stat -c '%n %Y %s' "${steam_root:-}"/package/*.installed 2>/dev/null)
|
||||
if [ "$1" -ge 60 ]; then
|
||||
steam_updates=0
|
||||
steam_installs=0
|
||||
elif [ "$stamp" != "${steam_update_stamp-$stamp}" ] && [ "${steam_installs:-0}" -lt 5 ]; then
|
||||
steam_updates=0
|
||||
steam_installs=$((${steam_installs:-0} + 1))
|
||||
fi
|
||||
steam_update_stamp=$stamp
|
||||
steam_updates=$((steam_updates + 1))
|
||||
[ "$steam_updates" -ge 3 ]
|
||||
}
|
||||
@@ -74,7 +138,6 @@ run_gamescope() (
|
||||
local status_file child_status compositor_status
|
||||
status_file=$(mktemp "${XDG_RUNTIME_DIR:-/tmp}/droiddeck-steam-exit.XXXXXX") || exit 73
|
||||
trap 'rm -f "$status_file"' EXIT
|
||||
# Gamescope can return success when its primary child crashed.
|
||||
BL_STEAM_EXIT_FILE="$status_file" gamescope "$@"
|
||||
compositor_status=$?
|
||||
if read -r child_status < "$status_file" && [[ $child_status =~ ^[0-9]{1,3}$ ]] \
|
||||
@@ -86,12 +149,6 @@ run_gamescope() (
|
||||
|
||||
collect_steam_logs() {
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] || return 0
|
||||
local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
[ "${steam_x64:-0}" = 1 ] && steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
|
||||
mkdir -p "$BL_DEBUG_DIR/steam" 2>/dev/null || return 0
|
||||
[ -d "$steam_root/logs" ] && find "$steam_root/logs" -maxdepth 1 -type f -size -8192k \
|
||||
-exec cp {} "$BL_DEBUG_DIR/steam/" \; 2>/dev/null
|
||||
[ "${steam_x64:-0}" = 0 ] && [ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/steam/" 2>/dev/null
|
||||
local sync_store=$HOME/.local/share/droiddeck-esync sync_file
|
||||
if [ -d "$sync_store" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-esync" 2>/dev/null; then
|
||||
for sync_file in launches.log tools.tsv wanted.tsv prefixes.json; do
|
||||
@@ -102,7 +159,6 @@ collect_steam_logs() {
|
||||
if [ -d "$fex_state" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-fex" 2>/dev/null; then
|
||||
cp "$fex_state/status.json" "$fex_state/config/Config.json" "$BL_DEBUG_DIR/droiddeck-fex/" 2>/dev/null
|
||||
fi
|
||||
echo "== steam logs copied to $BL_DEBUG_DIR/steam"
|
||||
}
|
||||
trap 'collect_steam_logs 2>/dev/null || true' TERM INT HUP
|
||||
if [ -n "${BL_VK_DRIVER:-}" ]; then
|
||||
@@ -142,6 +198,7 @@ rm -f "${XDG_RUNTIME_DIR:-/run/droiddeck}/droiddeck-remote-play"
|
||||
/usr/local/bin/droiddeck-steamvr unregister >/dev/null 2>&1 || true
|
||||
if [ "$mode" = lxqt ] || [ "$mode" = desktop ]; then
|
||||
/usr/local/bin/droiddeck-desktop-bookmarks || true
|
||||
/usr/local/bin/droiddeck-downloads || true
|
||||
fi
|
||||
export FLATPAK_BWRAP=/usr/local/bin/droiddeck-bwrap
|
||||
export XDG_DATA_DIRS=$XDG_DATA_HOME/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
|
||||
@@ -209,6 +266,20 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
step "starting the desktop"
|
||||
start_agent --no-focus
|
||||
[ -x /usr/local/bin/droiddeck-desktop ] || { echo "== the desktop package is not installed"; exit 66; }
|
||||
if command -v dbus-daemon >/dev/null 2>&1 && command -v droiddeck-netmanager >/dev/null 2>&1; then
|
||||
write_system_bus_config
|
||||
dbus-daemon --config-file=/usr/local/share/droiddeck/system-bus.conf --nofork --nopidfile &
|
||||
for _ in $(seq 1 50); do
|
||||
[ -S /run/dbus/system_bus_socket ] && break
|
||||
nap 0.1
|
||||
done
|
||||
if [ -S /run/dbus/system_bus_socket ]; then
|
||||
droiddeck-login1 --with-netmanager &
|
||||
echo "== desktop: system bus up, network and power services running"
|
||||
else
|
||||
echo "== desktop: the system bus did not come up"
|
||||
fi
|
||||
fi
|
||||
cores=$(program_cores)
|
||||
if [ -n "$cores" ]; then
|
||||
echo "== desktop cores: $cores (the desktop and every program started from it)"
|
||||
@@ -219,24 +290,32 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
nested=$width
|
||||
nested_h=$height
|
||||
if [ "${BL_FOLLOW_OUTPUT:-0}" = 1 ]; then
|
||||
echo "== gamescope: the output follows the screen (${width}x${height} to start)"
|
||||
elif [ "$mode" = steam ] && [ "${BL_GAMESCOPE_STRETCH_16X9:-0}" = 1 ]; then
|
||||
wide=$(( (height * 16 + 4) / 9 / 2 * 2 ))
|
||||
tall=$(( (width * 9 + 8) / 16 / 2 * 2 ))
|
||||
if [ "$wide" -gt "$width" ]; then
|
||||
nested=$wide
|
||||
echo "== gamescope: games at ${nested}x${height} stretched to the ${width}x${height} output"
|
||||
elif [ "$tall" -gt "$height" ]; then
|
||||
nested_h=$tall
|
||||
fi
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
if [ "$mode" = steam ]; then
|
||||
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 "$height")
|
||||
[ "$nested" != "$width" ] && args+=(-S stretch) && export BL_STRETCHED=1
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args=(--backend wayland --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
|
||||
fi
|
||||
if [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
export GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1
|
||||
fi
|
||||
[ "$mode" = steam ] && [ "${BL_STEAM_UI:-}" != desktop ] && args+=(-e)
|
||||
if [ "$mode" = steam ] && [ "${BL_XWAYLAND_COUNT:-2}" -gt 1 ]; then
|
||||
@@ -254,7 +333,11 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
args+=(--mangoapp)
|
||||
echo "== gamescope: mangoapp on ($(command -v mangoapp), config $MANGOHUD_CONFIGFILE)"
|
||||
fi
|
||||
mkdir -p /run/droiddeck-hud && export DROIDDECK_HUD_FRAMES=/run/droiddeck-hud/frames
|
||||
export BL_INSIDE=1
|
||||
rm -f "${XDG_RUNTIME_DIR:-/tmp}"/gamescope-limiter-*
|
||||
export GAMESCOPE_LIMITER_FILE="${XDG_RUNTIME_DIR:-/tmp}/droiddeck-gamescope-limiter"
|
||||
rm -f "$GAMESCOPE_LIMITER_FILE"
|
||||
if [ "$mode" = steam ]; then
|
||||
if /usr/local/bin/droiddeck-pipewire start; then
|
||||
eval "$(/usr/local/bin/droiddeck-pipewire env)"
|
||||
@@ -381,7 +464,6 @@ case $mode in
|
||||
steam_cef_gpu=1
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
step "checking the Steam client's arm64 parts (first run downloads them, ~1-2 min)"
|
||||
# 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 || steam_setup_failed $?
|
||||
@@ -402,8 +484,14 @@ case $mode in
|
||||
steam_root=$XDG_DATA_HOME/Steam
|
||||
if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then
|
||||
droiddeck-steam-x64 --sync-login || true
|
||||
droiddeck-steam-x64 --share || true
|
||||
fi
|
||||
steam_client=("$steam_root/steamrtarm64/steam")
|
||||
_bl_srt_shim=$HOME/.droiddeck-steamrt-shim
|
||||
if droiddeck-steamrt-shim "$steam_root/steamrtarm64" "$_bl_srt_shim"; then
|
||||
echo "== steam: Valve containerized the arm64 Steam client (it carries a Steam Runtime container); starting it through $_bl_srt_shim"
|
||||
steam_client=(env STEAM_RUNTIME_STEAMRT="$_bl_srt_shim" PATH="$_bl_srt_shim/bin:$PATH" "${steam_client[@]}")
|
||||
fi
|
||||
fi
|
||||
_bl_proton_root=$steam_root
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
@@ -446,49 +534,190 @@ case $mode in
|
||||
fi
|
||||
if [ "${BL_ZRAM:-0}" = 1 ]; then
|
||||
step "zRAM compression: on"
|
||||
[ "${BL_ZRAM_CLIENT:-1}" = 1 ] || step "zRAM: Steam, the hidden Epic Games Launcher and Battle.net are not compressed while games run (turned off in Performance)"
|
||||
_bl_ram_cap=0
|
||||
case ${BL_RAM_CAP_MB:-} in
|
||||
''|0) ;;
|
||||
*[!0-9]*|0*|???????*) step "RAM cap: ignored invalid value '$BL_RAM_CAP_MB'" ;;
|
||||
*) _bl_ram_cap=$((BL_RAM_CAP_MB * 1024)); step "RAM cap: ${BL_RAM_CAP_MB} MB" ;;
|
||||
esac
|
||||
(
|
||||
bl_zram_scan() {
|
||||
_bl_game=0 _bl_pids=()
|
||||
_bl_game=0 _bl_pids=() _bl_others=() _bl_apps=
|
||||
local _d _c _args _name _a _id _fex _lower _bnet=() _bnet_game=0
|
||||
for _d in /proc/[0-9]*; do
|
||||
# Under FEX the program is FEX's first argument.
|
||||
{ IFS= read -r -d '' _c && case ${_c##*/} in FEX|FEXInterpreter) IFS= read -r -d '' _c ;; esac; } \
|
||||
2>/dev/null < "$_d/cmdline" || continue
|
||||
case ${_c##*/} in
|
||||
reaper) _bl_game=1 ;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d#/proc/}") ;;
|
||||
[ "${_d##*/}" != "$BASHPID" ] || continue
|
||||
_args=()
|
||||
while IFS= read -r -d '' _c; do _args+=("$_c"); done 2>/dev/null < "$_d/cmdline" || true
|
||||
[ "${#_args[@]}" -gt 0 ] || continue
|
||||
_name=${_args[0]} _fex=0
|
||||
if [ "${#_args[@]}" -gt 1 ]; then
|
||||
case ${_name##*/} in FEX|FEXInterpreter) _name=${_args[1]} _fex=1 ;; esac
|
||||
fi
|
||||
case ${_name##*/} in
|
||||
reaper)
|
||||
for _a in "${_args[@]}"; do
|
||||
case $_a in
|
||||
AppId=769) ;;
|
||||
AppId=[0-9]*)
|
||||
_id=${_a#AppId=}
|
||||
case $_id in *[!0-9]*) ;; *) _bl_game=1; _bl_apps="$_bl_apps $_id" ;; esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d##*/}") ;;
|
||||
*)
|
||||
_lower=${_name,,}
|
||||
if [ "$_fex" = 1 ] && grep -qz '^DROIDDECK_EPIC_HIDDEN=1$' "$_d/environ" 2>/dev/null; then
|
||||
_bl_pids+=("${_d##*/}")
|
||||
elif [[ $_lower == [a-z]:[\\/]'program files (x86)'[\\/]battle.net[\\/]* ||
|
||||
$_lower == [a-z]:[\\/]programdata[\\/]battle.net[\\/]* ]]; then
|
||||
_bnet+=("${_d##*/}")
|
||||
else
|
||||
_bl_others+=("${_d##*/}")
|
||||
if [[ $_lower == [a-z]:[\\/]* ]]; then
|
||||
case ${_lower##*[\\/]} in
|
||||
agent.exe|conhost.exe|explorer.exe|lsass.exe|plugplay.exe|rpcss.exe|services.exe|start.exe|\
|
||||
steam.exe|svchost.exe|tabtip.exe|winedevice.exe|rundll32.exe|wineboot.exe|winemenubuilder.exe) ;;
|
||||
*)
|
||||
for _a in "${_args[@]:1}"; do
|
||||
[ "${_a,,}" = -uid ] && _bnet_game=1
|
||||
done
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ "$_bnet_game" = 1 ]; then
|
||||
_bl_pids+=("${_bnet[@]}")
|
||||
else
|
||||
_bl_others+=("${_bnet[@]}")
|
||||
fi
|
||||
}
|
||||
bl_zram_usage() {
|
||||
local _p _k _v _u _rss=0 _swap=0
|
||||
for _p in "${_bl_pids[@]}"; do
|
||||
for _p in "$@"; do
|
||||
while read -r _k _v _u; do
|
||||
case $_k in VmRSS:) _rss=$((_rss + _v)) ;; VmSwap:) _swap=$((_swap + _v)) ;; esac
|
||||
done 2>/dev/null < "/proc/$_p/status"
|
||||
done
|
||||
echo "${#_bl_pids[@]} processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
_bl_rss=$_rss
|
||||
echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
}
|
||||
bl_session_others() {
|
||||
local _p
|
||||
_bl_session=()
|
||||
for _p in "${_bl_others[@]}"; do
|
||||
grep -q -m1 '/libblsession\.so$' "/proc/$_p/maps" 2>/dev/null && _bl_session+=("$_p")
|
||||
done
|
||||
}
|
||||
bl_zram_pick() {
|
||||
if [ "$1" = session ]; then
|
||||
bl_session_others
|
||||
_pids=("${_bl_session[@]}")
|
||||
else
|
||||
_pids=("${_bl_pids[@]}")
|
||||
fi
|
||||
}
|
||||
bl_zram_wait() {
|
||||
local _p _left _start=$SECONDS
|
||||
while [ $((SECONDS - _start)) -lt 12 ]; do
|
||||
_left=0
|
||||
for _p in "$@"; do
|
||||
[ -s "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
[ -d "/proc/$_p" ] || continue
|
||||
[ $((SECONDS - _start)) -ge 2 ] && [ ! -e "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
_left=1
|
||||
done
|
||||
[ "$_left" = 1 ] || break
|
||||
nap 0.2
|
||||
done
|
||||
for _p in "$@"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
}
|
||||
bl_zram_send() {
|
||||
step "zRAM: $2 ($(bl_zram_usage))"
|
||||
printf '%s' "$1" > /tmp/.bl-zram
|
||||
[ "${#_bl_pids[@]}" = 0 ] || kill -URG "${_bl_pids[@]}" 2>/dev/null
|
||||
nap 5
|
||||
local _mode=$1 _what=$2 _which=$3 _pids _p
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: $_what ($(bl_zram_usage "${_pids[@]}"))"
|
||||
for _p in "${_pids[@]}"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
printf '%s' "$_mode" > /tmp/.bl-zram
|
||||
[ "${#_pids[@]}" = 0 ] || kill -URG "${_pids[@]}" 2>/dev/null
|
||||
if [ "$_mode" = 1 ]; then bl_zram_wait "${_pids[@]}"; else nap 5; fi
|
||||
bl_zram_scan
|
||||
step "zRAM: done ($(bl_zram_usage))"
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: done ($(bl_zram_usage "${_pids[@]}"))"
|
||||
}
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
bl_game_focused() {
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] || [ -z "${BL_LAUNCH_DIR:-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
local id
|
||||
id=$(sed -n 's/.*"focusedApp"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' \
|
||||
"$BL_LAUNCH_DIR/agent/focus.json" 2>/dev/null | head -1)
|
||||
[ -n "$id" ] || return 1
|
||||
case " ${_bl_apps-} " in
|
||||
*" $id "*) return 0 ;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
bl_over_cap() {
|
||||
[ "$_bl_ram_cap" -gt 0 ] || return 1
|
||||
_bl_measured=$SECONDS
|
||||
bl_session_others
|
||||
bl_zram_usage "${_bl_pids[@]}" "${_bl_session[@]}" > /dev/null
|
||||
[ "$_bl_rss" -gt "$_bl_ram_cap" ]
|
||||
}
|
||||
bl_cap_due() {
|
||||
[ "$_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
|
||||
while kill -0 $$ 2>/dev/null; do
|
||||
bl_zram_scan
|
||||
if [ "$_bl_game" = 1 ]; then
|
||||
[ "$_bl_since" -ge 0 ] || _bl_since=$SECONDS
|
||||
if [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
if bl_cap_due; then
|
||||
if bl_over_cap; then
|
||||
if [ "$_bl_capped" -lt 0 ] || [ $((SECONDS - _bl_capped)) -ge "$_bl_backoff" ]; then
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
if [ "$_bl_rss" -ge $((512 * 1024)) ]; then
|
||||
bl_zram_send 1 "over the ${BL_RAM_CAP_MB} MB RAM cap, compressing the client" client
|
||||
[ "$_bl_game" = 1 ] && _bl_packed=$SECONDS
|
||||
else
|
||||
step "RAM cap: over, client already small ($((_bl_rss / 1024)) MB resident), skipping it"
|
||||
fi
|
||||
bl_over_cap && bl_zram_send 1 "still over the RAM cap, compressing the rest of the session" session
|
||||
if bl_over_cap; then
|
||||
_bl_backoff=$((_bl_backoff * 2 > 600 ? 600 : _bl_backoff * 2))
|
||||
step "RAM cap: still over after paging out, next try in ${_bl_backoff} s"
|
||||
else
|
||||
_bl_backoff=30
|
||||
fi
|
||||
_bl_capped=$SECONDS
|
||||
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
|
||||
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_zram_send 1 "compressing the client"
|
||||
bl_zram_send 1 "compressing the client" client
|
||||
_bl_packed=$SECONDS
|
||||
fi
|
||||
elif [ "$_bl_since" -ge 0 ]; then
|
||||
[ "$_bl_packed" -lt 0 ] || bl_zram_send 0 "game closed, reading the client back"
|
||||
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
|
||||
fi
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
else
|
||||
_bl_since=-1
|
||||
fi
|
||||
nap 5
|
||||
done
|
||||
@@ -527,6 +756,11 @@ case $mode in
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
fi
|
||||
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
|
||||
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
|
||||
"${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam" &&
|
||||
echo "$BL_SHADER_PRECACHE" > "$HOME/.bl-shader-precache-applied" || true
|
||||
fi
|
||||
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
|
||||
step "asking the client to fetch the ARM64 Proton"
|
||||
set -- "$@" steam://install/4427310
|
||||
@@ -631,14 +865,11 @@ case $mode in
|
||||
until [ "$(_bl_focused)" = 769 ] || [ "$SECONDS" -ge "$_bl_end" ]; do
|
||||
sleep 1
|
||||
done
|
||||
# Shortcut CGameIDs are 64-bit; Steam app ids fit in 32 bits and keep the old short delay.
|
||||
[ "${#game}" -gt 10 ] && shortcut=1
|
||||
[ -n "$shortcut" ] || sleep 4
|
||||
echo "== steam: interface up; launching the requested game $game"
|
||||
_bl_hand_off
|
||||
[ -n "$shortcut" ] || return 0
|
||||
# Steam can drop a shortcut launch it gets before the shortcut's overview exists (large libraries).
|
||||
# A launch can be running before it creates its first window.
|
||||
while [ "$(_bl_focused)" = 769 ] && [ "$waited" -lt 20 ]; do
|
||||
sleep 1
|
||||
waited=$((waited + 1))
|
||||
@@ -699,23 +930,7 @@ case $mode in
|
||||
set -- "$@" "$_bl_url"
|
||||
fi
|
||||
if command -v dbus-daemon >/dev/null 2>&1 && command -v droiddeck-netmanager >/dev/null 2>&1; then
|
||||
mkdir -p /run/dbus /usr/local/share/droiddeck
|
||||
cat > /usr/local/share/droiddeck/system-bus.conf <<'BUSCONF'
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<type>system</type>
|
||||
<listen>unix:path=/run/dbus/system_bus_socket</listen>
|
||||
<auth>EXTERNAL</auth>
|
||||
<policy context="default">
|
||||
<allow user="*"/>
|
||||
<allow own="*"/>
|
||||
<allow send_destination="*"/>
|
||||
<allow receive_sender="*"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
BUSCONF
|
||||
rm -f /run/dbus/system_bus_socket
|
||||
write_system_bus_config
|
||||
dbus-daemon --config-file=/usr/local/share/droiddeck/system-bus.conf --nofork --nopidfile &
|
||||
system_bus=$!
|
||||
for _ in $(seq 1 50); do
|
||||
@@ -746,11 +961,12 @@ BUSCONF
|
||||
exit 69
|
||||
fi
|
||||
|
||||
# The UI bridge launches SteamVR, which needs the guest agent's library environment.
|
||||
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME)
|
||||
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME -u STEAM_STEAMRT_RECURSION_GUARD)
|
||||
[ "${LD_LIBRARY_PATH+x}" ] && _bl_compat_env+=("LD_LIBRARY_PATH=$LD_LIBRARY_PATH")
|
||||
[ "${STEAM_RUNTIME+x}" ] && _bl_compat_env+=("STEAM_RUNTIME=$STEAM_RUNTIME")
|
||||
[ "${STEAM_STEAMRT_RECURSION_GUARD+x}" ] && _bl_compat_env+=("STEAM_STEAMRT_RECURSION_GUARD=$STEAM_STEAMRT_RECURSION_GUARD")
|
||||
export STEAM_RUNTIME=1
|
||||
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
|
||||
decky_loader=$HOME/homebrew/services/PluginLoader
|
||||
@@ -786,21 +1002,20 @@ BUSCONF
|
||||
echo "== Decky: installed loader architecture is unsupported by this guest; not starting"
|
||||
fi
|
||||
fi
|
||||
_bl_cdp=()
|
||||
if [ -f "$steam_root/.cef-enable-remote-debugging" ]; then
|
||||
export BL_CDP_PORT=8080
|
||||
else
|
||||
export BL_CDP_PORT=$((20000 + RANDOM % 30000))
|
||||
_bl_cdp=(-cef-enable-debugging -devtools-port "$BL_CDP_PORT")
|
||||
fi
|
||||
if [ -f "$HOME/.droiddeck-decky-enabled" ] && [ "${decky_arch:-}" = x86_64 ]; then
|
||||
steam_devtools 8080
|
||||
export BL_CDP_PORT
|
||||
if [ -f "$HOME/.droiddeck-decky-enabled" ] && [ "${decky_arch:-}" = x86_64 ] && [ ${#_bl_cdp[@]} = 0 ]; then
|
||||
echo "== steam: devtools port $BL_CDP_PORT left open for the x86_64 Decky loader"
|
||||
else
|
||||
export BL_CDP_GUARD=$BL_CDP_PORT
|
||||
echo "== steam: devtools port $BL_CDP_PORT, guest processes only"
|
||||
fi
|
||||
[ -n "${BL_LAUNCH_DIR:-}" ] && mkdir -p "$BL_LAUNCH_DIR/agent" && echo "$BL_CDP_PORT" > "$BL_LAUNCH_DIR/agent/cdp-port"
|
||||
[ "$steam_x64" = 1 ] || "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 &
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
{ droiddeck-steam-compat --files-only "$steam_root" 2>&1 & }
|
||||
else
|
||||
{ "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 & }
|
||||
fi
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan)
|
||||
@@ -830,6 +1045,9 @@ BUSCONF
|
||||
unset _stale _f
|
||||
fi
|
||||
steam_channel=steamdeck_publicbeta
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
steam_channel=$(droiddeck-steam-install --channel 2>/dev/null || echo steamdeck_publicbeta)
|
||||
fi
|
||||
_bl_lang=()
|
||||
[ -n "${BL_STEAM_LANGUAGE:-}" ] && _bl_lang=(-language "$BL_STEAM_LANGUAGE")
|
||||
steam_beta=$steam_root/package/beta
|
||||
@@ -845,6 +1063,8 @@ BUSCONF
|
||||
fi
|
||||
echo "== steam args: ${_bl_ui[*]} ${_bl_cdp[*]} ${_bl_lang[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-ozone-platform=x11 ${_bl_cef[*]} $*$([ "$steam_x64" = 1 ] && echo ' (x86-64 client under FEX)')"
|
||||
steam_updates=0
|
||||
steam_installs=0
|
||||
steam_update_stamp=$(stat -c '%n %Y %s' "$steam_root"/package/*.installed 2>/dev/null)
|
||||
rm -f "$HOME/.bl-stop-requested" "$STEAMOS_STEAM_SHUTDOWN_SENTINEL" "$STEAMOS_STEAM_REBOOT_SENTINEL"
|
||||
steam_other_game_running() {
|
||||
local line value n open
|
||||
@@ -998,13 +1218,12 @@ BUSCONF
|
||||
: > "$compat_restarted"
|
||||
compat_restarts=0
|
||||
compat_settled() {
|
||||
local app m flags r card=/mnt/droiddeck-sd
|
||||
# The arm64 card library may hold that client's copy of the same title.
|
||||
[ "$steam_x64" = 1 ] && card=/mnt/droiddeck-sd/x86-64
|
||||
local app m flags r card=/mnt/droiddeck-sd added=(/mnt/droiddeck-lib/*)
|
||||
[ "$steam_x64" = 1 ] && { card=/mnt/droiddeck-sd/x86-64; added=(/mnt/droiddeck-lib/*/x86-64); }
|
||||
while read -r app; do
|
||||
[ -n "$app" ] || continue
|
||||
m=
|
||||
for r in "$steam_root" "$card"; do
|
||||
for r in "$steam_root" "$card" "${added[@]}"; do
|
||||
[ -f "$r/steamapps/appmanifest_$app.acf" ] && { m=$r/steamapps/appmanifest_$app.acf; break; }
|
||||
done
|
||||
[ -n "$m" ] || return 1
|
||||
@@ -1073,7 +1292,7 @@ BUSCONF
|
||||
done
|
||||
fi
|
||||
if [ "$beat" -le 720 ] && [ "$((beat % 3))" -eq 0 ] && { [ -z "$library_job" ] || ! kill -0 "$library_job" 2>/dev/null; }; then
|
||||
libraries=("$steam_root/steamapps" /mnt/droiddeck/steamapps /mnt/droiddeck-sd/steamapps /root/Games/*/steamapps)
|
||||
libraries=("$steam_root/steamapps" /mnt/droiddeck/steamapps /mnt/droiddeck-sd/steamapps /mnt/droiddeck-lib/*/steamapps /mnt/droiddeck-lib/*/x86-64/steamapps /root/Games/*/steamapps)
|
||||
seed=; compat=
|
||||
seed_due && seed=1
|
||||
compat_due && compat=1
|
||||
@@ -1116,7 +1335,6 @@ BUSCONF
|
||||
lossless_left=0
|
||||
elif ! pgrep -x wineserver >/dev/null 2>&1; then
|
||||
(
|
||||
# The probe reaches the x86-64 client through the arm64 client's steamclient.so, as the import watcher does.
|
||||
if [ "$steam_x64" = 1 ]; then export BL_STEAMCLIENT=$XDG_DATA_HOME/Steam/steamrtarm64/steamclient.so; fi
|
||||
answer=$(droiddeck-steam-games probe "$steam_root" 993090 2>/dev/null) || exit 0
|
||||
case $answer in
|
||||
@@ -1176,7 +1394,6 @@ BUSCONF
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
fi
|
||||
# The x86-64 client rewrote config.vdf from memory on exit, over the live passes' mapping.
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
[ -z "${_bl_x64_tool:-}" ] ||
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool steam-compatibility "$steam_root" --x64 >/dev/null 2>&1 || true
|
||||
@@ -1222,6 +1439,12 @@ BUSCONF
|
||||
set --
|
||||
continue
|
||||
fi
|
||||
if [ "$steam_x64" = 1 ] && [ "$rc" -eq 132 ] && [ -z "${_bl_x64_sigill:-}" ]; then
|
||||
_bl_x64_sigill=1
|
||||
echo "== steam: the x86-64 client stopped on an illegal instruction after it updated itself; starting it again once"
|
||||
set --
|
||||
continue
|
||||
fi
|
||||
[ "$rc" -eq 42 ] || break
|
||||
if steam_update_stuck "$steam_ran"; then
|
||||
echo "== steam: asked to restart for an update $steam_updates times and it is not installing; the session stops here rather than loop"
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
[ "${1:-}" = run ] || exec /usr/bin/snap "$@"
|
||||
shift
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--) shift; break ;;
|
||||
-*) shift ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
target=${1:?usage: snap run <snap>[.<app>] [args...]}
|
||||
shift
|
||||
name=${target%%.*}
|
||||
app=${target#*.}
|
||||
exec /usr/local/bin/droiddeck-snap-run "$name" "$app" "$@"
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--classic) shift ;;
|
||||
--base) shift 2 ;;
|
||||
--*) shift ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
tag=${1:?security tag}
|
||||
shift
|
||||
[ "${1##*/}" = snap-exec ] && shift
|
||||
app=${1:-}
|
||||
shift
|
||||
name=${tag#snap.}
|
||||
name=${name%%.*}
|
||||
app=${app#*.}
|
||||
[ -n "$app" ] || app=$name
|
||||
exec /usr/local/bin/droiddeck-snap-run "$name" "$app" "$@"
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
SNAP_DIR = "/snap"
|
||||
HOST_DIRS = ("/etc", "/home", "/root", "/tmp", "/run", "/var/snap", "/var/lib/snapd", "/var/tmp", "/var/log",
|
||||
"/media", "/mnt", "/snap", "/usr/src", "/lib/modules")
|
||||
|
||||
|
||||
def load(name):
|
||||
with open(f"{SNAP_DIR}/{name}/current/meta/snap.yaml") as f:
|
||||
return yaml.safe_load(f) or {}
|
||||
|
||||
|
||||
def expand(value, env):
|
||||
return re.sub(r"\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?", lambda m: env.get(m.group(1), ""), str(value))
|
||||
|
||||
|
||||
def provider_path(path, provider, revision):
|
||||
snap = f"{SNAP_DIR}/{provider}/{revision}"
|
||||
for var, value in (("$SNAP_DATA", f"/var/snap/{provider}/{revision}"),
|
||||
("$SNAP_COMMON", f"/var/snap/{provider}/common"), ("$SNAP", snap)):
|
||||
if path == var or path.startswith(var + "/"):
|
||||
return os.path.normpath(value + path[len(var):])
|
||||
return os.path.normpath(f"{snap}/{path}")
|
||||
|
||||
|
||||
def content_binds(name, meta, env):
|
||||
out = []
|
||||
for plug_name, plug in (meta.get("plugs") or {}).items():
|
||||
if not isinstance(plug, dict) or plug.get("interface") != "content" or not plug.get("target"):
|
||||
continue
|
||||
provider = (plug.get("default-provider") or "").split(":")[0]
|
||||
if not provider or not os.path.isdir(f"{SNAP_DIR}/{provider}/current"):
|
||||
continue
|
||||
try:
|
||||
slots = load(provider).get("slots") or {}
|
||||
except OSError:
|
||||
continue
|
||||
revision = os.path.basename(os.path.realpath(f"{SNAP_DIR}/{provider}/current"))
|
||||
target = expand(plug["target"], env)
|
||||
for slot_name, slot in slots.items():
|
||||
if not isinstance(slot, dict) or slot.get("interface") != "content":
|
||||
continue
|
||||
if slot.get("content", slot_name) != plug.get("content", plug_name):
|
||||
continue
|
||||
nested = "source" in slot
|
||||
reads = (slot.get("source") or {}).get("read") if nested else slot.get("read")
|
||||
for path in reads or []:
|
||||
source = provider_path(str(path), provider, revision)
|
||||
out.append((plug_name, source, os.path.join(target, os.path.basename(source)) if nested else target))
|
||||
if not nested:
|
||||
break
|
||||
break
|
||||
return out
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 3:
|
||||
print("usage: droiddeck-snap-run SNAP APP [ARG...]", file=sys.stderr)
|
||||
return 2
|
||||
name, app, args = argv[1], argv[2], argv[3:]
|
||||
meta = load(name)
|
||||
spec = (meta.get("apps") or {}).get(app)
|
||||
if spec is None:
|
||||
print(f"error: snap \"{name}\" has no app \"{app}\"", file=sys.stderr)
|
||||
return 1
|
||||
revision = os.path.basename(os.path.realpath(f"{SNAP_DIR}/{name}/current"))
|
||||
home = os.environ.get("HOME", "/root")
|
||||
snap = f"{SNAP_DIR}/{name}/{revision}"
|
||||
env = dict(os.environ)
|
||||
for k in ("LD_PRELOAD", "LD_LIBRARY_PATH"):
|
||||
env.pop(k, None)
|
||||
env.update({
|
||||
"SNAP": snap, "SNAP_NAME": name, "SNAP_INSTANCE_NAME": name, "SNAP_INSTANCE_KEY": "",
|
||||
"SNAP_REVISION": revision, "SNAP_VERSION": str(meta.get("version", "")), "SNAP_ARCH": "arm64",
|
||||
"SNAP_LIBRARY_PATH": "/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void",
|
||||
"SNAP_DATA": f"/var/snap/{name}/{revision}", "SNAP_COMMON": f"/var/snap/{name}/common",
|
||||
"SNAP_USER_DATA": f"{home}/snap/{name}/{revision}", "SNAP_USER_COMMON": f"{home}/snap/{name}/common",
|
||||
"SNAP_REAL_HOME": home, "SNAP_UID": str(os.getuid()), "SNAP_EUID": str(os.geteuid()),
|
||||
"SNAP_COOKIE": "", "SNAP_CONTEXT": "", "SNAP_REEXEC": "0",
|
||||
})
|
||||
for d in (env["SNAP_USER_DATA"], env["SNAP_USER_COMMON"], env["SNAP_DATA"], env["SNAP_COMMON"]):
|
||||
os.makedirs(d, exist_ok=True)
|
||||
current = f"{home}/snap/{name}/current"
|
||||
if os.path.realpath(current) != env["SNAP_USER_DATA"]:
|
||||
try:
|
||||
os.unlink(current)
|
||||
except OSError:
|
||||
pass
|
||||
os.symlink(revision, current)
|
||||
confinement = meta.get("confinement", "strict")
|
||||
if confinement != "classic":
|
||||
env["HOME"] = env["SNAP_USER_DATA"]
|
||||
env["PATH"] = ":".join([f"{snap}/usr/sbin", f"{snap}/usr/bin", f"{snap}/sbin", f"{snap}/bin",
|
||||
"/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/usr/games"])
|
||||
env["LD_LIBRARY_PATH"] = env["SNAP_LIBRARY_PATH"]
|
||||
for scope in (meta.get("environment") or {}, spec.get("environment") or {}):
|
||||
for k, v in scope.items():
|
||||
env[k] = expand(v, env)
|
||||
command = shlex.split(expand(spec.get("command", ""), env))
|
||||
if command and not command[0].startswith("/"):
|
||||
command[0] = f"{snap}/{command[0]}"
|
||||
chain = [c if c.startswith("/") else f"{snap}/{c}" for c in (meta.get("command-chain") or []) + (spec.get("command-chain") or [])]
|
||||
program = chain + command + args
|
||||
if confinement == "classic":
|
||||
os.execvpe(program[0], program, env)
|
||||
base = meta.get("base") or "core"
|
||||
root = f"{SNAP_DIR}/{base}/current"
|
||||
if not os.path.isdir(root):
|
||||
print(f"error: the base snap \"{base}\" is not installed; run: snap install {base}", file=sys.stderr)
|
||||
return 1
|
||||
bwrap = ["/usr/local/bin/droiddeck-bwrap", "--bind", root, "/", "--dev-bind", "/dev", "/dev", "--proc", "/proc",
|
||||
"--bind", "/sys", "/sys"]
|
||||
for d in HOST_DIRS:
|
||||
if os.path.isdir(d):
|
||||
bwrap += ["--bind", d, d]
|
||||
bwrap += ["--bind", "/", "/var/lib/snapd/hostfs"]
|
||||
bwrap += ["--bind", "/dev/null", "/etc/ld.so.preload"]
|
||||
binds = content_binds(name, meta, env)
|
||||
for _, source, target in binds:
|
||||
if os.path.isdir(source):
|
||||
bwrap += ["--bind", source, target]
|
||||
content = {k for k, v in (meta.get("plugs") or {}).items() if isinstance(v, dict) and v.get("interface") == "content"}
|
||||
plugs = (set(meta.get("plugs") or {}) | set(spec.get("plugs") or [])) - content | {plug for plug, _, _ in binds}
|
||||
env["DROIDDECK_SNAP_PLUGS"] = " ".join(sorted(plugs))
|
||||
bwrap += ["--bind", "/usr/local/bin/droiddeck-snapctl", "/usr/lib/snapd/snapctl"]
|
||||
bwrap += ["--chdir", os.getcwd() if os.path.isdir(os.getcwd()) else env["HOME"], "--clearenv"]
|
||||
for k, v in env.items():
|
||||
bwrap += ["--setenv", k, v]
|
||||
os.execv(bwrap[0], bwrap + ["--"] + program)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
case $1 in
|
||||
is-connected)
|
||||
shift
|
||||
while [ $# -gt 1 ]; do shift; done
|
||||
case " $DROIDDECK_SNAP_PLUGS " in
|
||||
*" ${1:-} "*) exit 0 ;;
|
||||
esac
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
+542
@@ -0,0 +1,542 @@
|
||||
#!/usr/bin/python3
|
||||
import datetime
|
||||
import hashlib
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import socketserver
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
STORE = "https://api.snapcraft.io/v2"
|
||||
ARCH = "arm64"
|
||||
SNAP_DIR = "/snap"
|
||||
BIN_DIR = "/snap/bin"
|
||||
LIB = "/var/lib/snapd"
|
||||
STATE = LIB + "/droiddeck-state.json"
|
||||
DESKTOP_DIR = LIB + "/desktop/applications"
|
||||
SOCKETS = ("/run/snapd.socket", "/run/snapd-snap.socket")
|
||||
FIND_FIELDS = ("title,summary,description,version,revision,confinement,base,publisher,license,contact,website,"
|
||||
"media,categories,store-url,download,type,channel,common-ids,links")
|
||||
INFO_FIELDS = ("title,summary,description,version,revision,confinement,base,publisher,license,contact,website,"
|
||||
"media,categories,snap-id,store-url,download,type,channel-map,common-ids,links,created-at")
|
||||
HEADERS = {"Snap-Device-Series": "16", "Snap-Device-Architecture": ARCH, "User-Agent": "snapd/2.70 droiddeck"}
|
||||
|
||||
lock = threading.RLock()
|
||||
install_lock = threading.Lock()
|
||||
changes = {}
|
||||
change_seq = [0]
|
||||
|
||||
|
||||
def now():
|
||||
return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
||||
|
||||
|
||||
def load_state():
|
||||
try:
|
||||
with open(STATE) as f:
|
||||
return json.load(f)
|
||||
except (OSError, ValueError):
|
||||
return {"snaps": {}}
|
||||
|
||||
|
||||
def save_state(state):
|
||||
tmp = STATE + ".tmp"
|
||||
with open(tmp, "w") as f:
|
||||
json.dump(state, f, indent=1)
|
||||
os.replace(tmp, STATE)
|
||||
|
||||
|
||||
def store_get(path, params=None):
|
||||
url = STORE + path + ("?" + urllib.parse.urlencode(params) if params else "")
|
||||
req = urllib.request.Request(url, headers=HEADERS)
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
return json.load(r)
|
||||
|
||||
|
||||
def publisher(p):
|
||||
p = p or {}
|
||||
return {"id": p.get("id", ""), "username": p.get("username", ""), "display-name": p.get("display-name", ""),
|
||||
"validation": p.get("validation", "unproven")}
|
||||
|
||||
|
||||
def media_of(snap):
|
||||
out = []
|
||||
for m in snap.get("media") or []:
|
||||
if m.get("type") in ("icon", "screenshot", "banner") and m.get("url"):
|
||||
item = {"type": m["type"], "url": m["url"]}
|
||||
if m.get("width"):
|
||||
item["width"] = m["width"]
|
||||
item["height"] = m.get("height", 0)
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
|
||||
def icon_of(media):
|
||||
return next((m["url"] for m in media if m["type"] == "icon"), "")
|
||||
|
||||
|
||||
def from_store(name, snap, revision=None, channel=None):
|
||||
media = media_of(snap)
|
||||
rev = revision or snap.get("revision") or {}
|
||||
out = {
|
||||
"id": snap.get("snap-id", ""), "name": name, "title": snap.get("title") or name,
|
||||
"summary": snap.get("summary", ""), "description": snap.get("description", ""),
|
||||
"type": rev.get("type") or snap.get("type") or "app", "version": rev.get("version", ""),
|
||||
"revision": str(rev.get("revision", "")), "channel": channel or "stable",
|
||||
"confinement": rev.get("confinement") or "strict", "base": rev.get("base") or "",
|
||||
"publisher": publisher(snap.get("publisher")), "developer": (snap.get("publisher") or {}).get("username", ""),
|
||||
"license": snap.get("license", ""), "contact": snap.get("contact", ""), "website": snap.get("website", ""),
|
||||
"media": media, "icon": icon_of(media), "store-url": snap.get("store-url", ""),
|
||||
"download-size": (rev.get("download") or {}).get("size", 0), "status": "available",
|
||||
"categories": [{"name": c.get("name", ""), "featured": bool(c.get("featured"))} for c in snap.get("categories") or []],
|
||||
"common-ids": rev.get("common-ids") or snap.get("common-ids") or [],
|
||||
"private": False, "devmode": False, "jailmode": False, "trymode": False, "apps": [],
|
||||
}
|
||||
return out
|
||||
|
||||
|
||||
def installed_snap(name, entry):
|
||||
snap = dict(entry["info"])
|
||||
snap["status"] = "active"
|
||||
snap["install-date"] = entry.get("installed", now())
|
||||
snap["installed-size"] = entry.get("size", 0)
|
||||
snap["revision"] = str(entry["revision"])
|
||||
snap["version"] = entry.get("version", snap.get("version", ""))
|
||||
snap["tracking-channel"] = entry.get("channel", "latest/stable")
|
||||
snap["channel"] = entry.get("channel", "latest/stable")
|
||||
snap["mounted-from"] = f"{LIB}/snaps/{name}_{entry['revision']}.snap"
|
||||
snap["apps"] = [{"name": a, "snap": name, "desktop-file": f"{DESKTOP_DIR}/{name}_{a}.desktop"} for a in entry.get("apps", [])]
|
||||
return snap
|
||||
|
||||
|
||||
def find(query, section=None, name_exact=False):
|
||||
if name_exact:
|
||||
try:
|
||||
info = store_get(f"/snaps/info/{query}", {"architecture": ARCH, "fields": INFO_FIELDS})
|
||||
except Exception:
|
||||
return []
|
||||
rev = next((c for c in info.get("channel-map", []) if c["channel"]["architecture"] == ARCH
|
||||
and c["channel"]["risk"] == "stable"), None)
|
||||
if not rev:
|
||||
return []
|
||||
return [from_store(info["name"], dict(info["snap"], **{"snap-id": info.get("snap-id", "")}), rev, "stable")]
|
||||
params = {"architecture": ARCH, "fields": FIND_FIELDS}
|
||||
if query:
|
||||
params["q"] = query
|
||||
if section:
|
||||
params["category"] = section
|
||||
if not query and not section:
|
||||
params["featured"] = "true"
|
||||
result = store_get("/snaps/find", params)
|
||||
out = []
|
||||
state = load_state()
|
||||
for r in result.get("results", []):
|
||||
snap = from_store(r["name"], dict(r.get("snap", {}), **{"snap-id": r.get("snap-id", "")}), r.get("revision"))
|
||||
if r["name"] in state["snaps"]:
|
||||
snap["status"] = "active"
|
||||
snap["installed-size"] = state["snaps"][r["name"]].get("size", 0)
|
||||
out.append(snap)
|
||||
return out
|
||||
|
||||
|
||||
def new_change(kind, summary, snaps):
|
||||
with lock:
|
||||
change_seq[0] += 1
|
||||
cid = str(change_seq[0])
|
||||
changes[cid] = {"id": cid, "kind": kind, "summary": summary, "status": "Doing", "ready": False,
|
||||
"spawn-time": now(), "tasks": [{"id": cid + "-1", "kind": kind, "summary": summary, "status": "Doing",
|
||||
"progress": {"label": "", "done": 0, "total": 1},
|
||||
"spawn-time": now()}],
|
||||
"data": {"snap-names": snaps}}
|
||||
return cid
|
||||
|
||||
|
||||
def progress(cid, label, done, total):
|
||||
with lock:
|
||||
task = changes[cid]["tasks"][0]
|
||||
task["progress"] = {"label": label, "done": done, "total": max(total, 1)}
|
||||
task["summary"] = changes[cid]["summary"]
|
||||
|
||||
|
||||
def finish(cid, err=None):
|
||||
with lock:
|
||||
c = changes[cid]
|
||||
c["status"] = "Error" if err else "Done"
|
||||
c["ready"] = True
|
||||
c["ready-time"] = now()
|
||||
c["tasks"][0]["status"] = c["status"]
|
||||
if err:
|
||||
c["err"] = err
|
||||
|
||||
|
||||
def root_run(argv):
|
||||
if os.getuid() == 0:
|
||||
return subprocess.run(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
return subprocess.run(["/usr/local/bin/droiddeck-root"] + argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
text=True)
|
||||
|
||||
|
||||
def snap_yaml(path):
|
||||
try:
|
||||
import yaml
|
||||
with open(path) as f:
|
||||
return yaml.safe_load(f) or {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def download(cid, name, url, sha3, size, target):
|
||||
tmp = target + ".partial"
|
||||
h = hashlib.sha3_384()
|
||||
req = urllib.request.Request(url, headers=HEADERS)
|
||||
with urllib.request.urlopen(req, timeout=120) as r, open(tmp, "wb") as out:
|
||||
done = 0
|
||||
while True:
|
||||
chunk = r.read(1 << 20)
|
||||
if not chunk:
|
||||
break
|
||||
out.write(chunk)
|
||||
h.update(chunk)
|
||||
done += len(chunk)
|
||||
progress(cid, f"Download snap \"{name}\"", done, size)
|
||||
if sha3 and h.hexdigest() != sha3:
|
||||
os.unlink(tmp)
|
||||
raise RuntimeError(f"{name}: downloaded snap does not match the store's sha3-384")
|
||||
os.replace(tmp, target)
|
||||
|
||||
|
||||
def write_desktop(name, rev, meta):
|
||||
os.makedirs(DESKTOP_DIR, exist_ok=True)
|
||||
gui = f"{SNAP_DIR}/{name}/{rev}/meta/gui"
|
||||
apps = (meta.get("apps") or {})
|
||||
for app, spec in apps.items():
|
||||
source = os.path.join(gui, f"{app}.desktop")
|
||||
if (spec or {}).get("daemon") or not os.path.isfile(source):
|
||||
continue
|
||||
command = name if app == name else f"{name}.{app}"
|
||||
out = []
|
||||
with open(source, encoding="utf-8", errors="replace") as f:
|
||||
for line in f:
|
||||
if line.startswith("Exec="):
|
||||
args = line[5:].strip().split(" ", 1)
|
||||
rest = (" " + args[1]) if len(args) > 1 else ""
|
||||
line = f"Exec={BIN_DIR}/{command}{rest}\n"
|
||||
elif line.startswith("Icon="):
|
||||
line = "Icon=" + line[5:].replace("${SNAP}", f"{SNAP_DIR}/{name}/current")
|
||||
out.append(line)
|
||||
out.append(f"X-SnapInstanceName={name}\n")
|
||||
target = f"{DESKTOP_DIR}/{name}_{app}.desktop"
|
||||
with open(target + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.writelines(out)
|
||||
os.replace(target + ".tmp", target)
|
||||
subprocess.run(["update-desktop-database", DESKTOP_DIR], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
||||
def link_bins(name, meta):
|
||||
os.makedirs(BIN_DIR, exist_ok=True)
|
||||
apps = []
|
||||
for app, spec in (meta.get("apps") or {}).items():
|
||||
if (spec or {}).get("daemon"):
|
||||
continue
|
||||
command = name if app == name else f"{name}.{app}"
|
||||
path = os.path.join(BIN_DIR, command)
|
||||
with open(path + ".tmp", "w") as f:
|
||||
f.write(f"#!/bin/sh\nexec /usr/local/bin/droiddeck-snap-run {name} {app} \"$@\"\n")
|
||||
os.chmod(path + ".tmp", 0o755)
|
||||
os.replace(path + ".tmp", path)
|
||||
apps.append(app)
|
||||
return apps
|
||||
|
||||
|
||||
def remove_tree(top):
|
||||
if os.path.isdir(top) and not os.path.islink(top):
|
||||
os.chmod(top, 0o700)
|
||||
for root, dirs, _ in os.walk(top):
|
||||
for d in dirs:
|
||||
path = os.path.join(root, d)
|
||||
if not os.path.islink(path):
|
||||
os.chmod(path, 0o700)
|
||||
shutil.rmtree(top, ignore_errors=True)
|
||||
|
||||
|
||||
def install_one(cid, name, channel, state, parents=()):
|
||||
if name in state["snaps"] or name in parents:
|
||||
return
|
||||
info = store_get(f"/snaps/info/{name}", {"architecture": ARCH, "fields": INFO_FIELDS})
|
||||
risk = channel.split("/")[-1] if channel else "stable"
|
||||
track = channel.split("/")[0] if channel and "/" in channel else "latest"
|
||||
rev = next((c for c in info.get("channel-map", []) if c["channel"]["architecture"] == ARCH
|
||||
and c["channel"]["risk"] == risk and c["channel"]["track"] == track), None)
|
||||
if not rev:
|
||||
raise RuntimeError(f"snap \"{name}\" has no {track}/{risk} release for {ARCH}")
|
||||
number = rev["revision"]
|
||||
os.makedirs(f"{LIB}/snaps", exist_ok=True)
|
||||
blob = f"{LIB}/snaps/{name}_{number}.snap"
|
||||
d = rev.get("download") or {}
|
||||
with lock:
|
||||
changes[cid]["summary"] = f"Install \"{name}\" snap"
|
||||
download(cid, name, d["url"], d.get("sha3-384"), d.get("size", 0), blob)
|
||||
progress(cid, f"Unpack snap \"{name}\"", 0, 1)
|
||||
target = f"{SNAP_DIR}/{name}/{number}"
|
||||
remove_tree(target)
|
||||
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||
r = root_run(["unsquashfs", "-q", "-n", "-no-xattrs", "-f", "-excludes", "-d", target, blob, "dev"])
|
||||
if r.returncode != 0:
|
||||
raise RuntimeError(f"cannot unpack {name}: {r.stdout.strip()[-400:]}")
|
||||
os.makedirs(f"{target}/dev", exist_ok=True)
|
||||
current = f"{SNAP_DIR}/{name}/current"
|
||||
if os.path.islink(current):
|
||||
os.unlink(current)
|
||||
os.symlink(str(number), current)
|
||||
for sub in (f"/var/snap/{name}/{number}", f"/var/snap/{name}/common"):
|
||||
os.makedirs(sub, exist_ok=True)
|
||||
cur = f"/var/snap/{name}/current"
|
||||
if os.path.islink(cur):
|
||||
os.unlink(cur)
|
||||
os.symlink(str(number), cur)
|
||||
meta = snap_yaml(f"{target}/meta/snap.yaml")
|
||||
entry = {"revision": number, "version": rev.get("version", ""), "channel": f"{track}/{risk}",
|
||||
"installed": now(), "size": d.get("size", 0), "info": from_store(name, dict(info["snap"], **{"snap-id": info.get("snap-id", "")}), rev, f"{track}/{risk}"),
|
||||
"base": meta.get("base") or ("core" if (meta.get("type") or "app") == "app" else ""), "apps": []}
|
||||
base = meta.get("base")
|
||||
if (meta.get("type") or "app") == "app":
|
||||
install_one(cid, base or "core", "latest/stable", state, parents + (name,))
|
||||
for plug in (meta.get("plugs") or {}).values():
|
||||
if isinstance(plug, dict) and plug.get("interface") == "content" and plug.get("default-provider"):
|
||||
provider = plug["default-provider"].split(":")[0]
|
||||
install_one(cid, provider, "latest/stable", state, parents + (name,))
|
||||
entry["apps"] = link_bins(name, meta)
|
||||
write_desktop(name, number, meta)
|
||||
state["snaps"][name] = entry
|
||||
save_state(state)
|
||||
|
||||
|
||||
def remove_one(name, state):
|
||||
entry = state["snaps"].pop(name, None)
|
||||
if not entry:
|
||||
raise RuntimeError(f"snap \"{name}\" is not installed")
|
||||
for app in entry.get("apps", []):
|
||||
command = name if app == name else f"{name}.{app}"
|
||||
try:
|
||||
os.unlink(os.path.join(BIN_DIR, command))
|
||||
except OSError:
|
||||
pass
|
||||
if os.path.isdir(DESKTOP_DIR):
|
||||
for f in os.listdir(DESKTOP_DIR):
|
||||
if f.startswith(name + "_") and f.endswith(".desktop"):
|
||||
os.unlink(os.path.join(DESKTOP_DIR, f))
|
||||
subprocess.run(["update-desktop-database", DESKTOP_DIR], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
remove_tree(f"{SNAP_DIR}/{name}")
|
||||
for f in os.listdir(f"{LIB}/snaps"):
|
||||
if f.startswith(name + "_"):
|
||||
os.unlink(os.path.join(f"{LIB}/snaps", f))
|
||||
save_state(state)
|
||||
|
||||
|
||||
def run_change(cid, action, names, channel):
|
||||
with install_lock:
|
||||
apply_change(cid, action, names, channel)
|
||||
|
||||
|
||||
def apply_change(cid, action, names, channel):
|
||||
try:
|
||||
state = load_state()
|
||||
for name in names:
|
||||
if action == "install":
|
||||
install_one(cid, name, channel or "latest/stable", state)
|
||||
elif action == "remove":
|
||||
remove_one(name, state)
|
||||
elif action == "refresh":
|
||||
old = state["snaps"].get(name)
|
||||
if old:
|
||||
remove_one(name, state)
|
||||
install_one(cid, name, old.get("channel", "latest/stable"), state)
|
||||
else:
|
||||
raise RuntimeError(f"unsupported action {action}")
|
||||
finish(cid)
|
||||
except Exception as e:
|
||||
finish(cid, str(e))
|
||||
|
||||
|
||||
SECTIONS = ["featured", "art-and-design", "books-and-reference", "development", "devices-and-iot", "education",
|
||||
"entertainment", "finance", "games", "health-and-fitness", "music-and-audio", "news-and-weather",
|
||||
"personalisation", "photo-and-video", "productivity", "science", "security", "server-and-cloud",
|
||||
"social", "utilities"]
|
||||
|
||||
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
protocol_version = "HTTP/1.1"
|
||||
|
||||
def log_message(self, fmt, *args):
|
||||
pass
|
||||
|
||||
def address_string(self):
|
||||
return "snapd"
|
||||
|
||||
def reply(self, body, code=200, kind="sync"):
|
||||
payload = {"type": kind, "status-code": code, "status": http.client.responses.get(code, "")}
|
||||
payload.update(body)
|
||||
data = json.dumps(payload).encode()
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
def ok(self, result):
|
||||
self.reply({"result": result})
|
||||
|
||||
def error(self, code, message, kind=""):
|
||||
self.reply({"result": {"message": message, "kind": kind}}, code, "error")
|
||||
|
||||
def body(self):
|
||||
n = int(self.headers.get("Content-Length") or 0)
|
||||
raw = self.rfile.read(n) if n else b"{}"
|
||||
try:
|
||||
return json.loads(raw or b"{}")
|
||||
except ValueError:
|
||||
return {}
|
||||
|
||||
def do_GET(self):
|
||||
url = urllib.parse.urlsplit(self.path)
|
||||
q = urllib.parse.parse_qs(url.query)
|
||||
path = url.path
|
||||
try:
|
||||
if path == "/v2/system-info":
|
||||
return self.ok({"series": "16", "version": "2.70+droiddeck", "build-id": "droiddeck", "os-release": {"id": "ubuntu", "version-id": "26.04"},
|
||||
"on-classic": True, "managed": False, "kernel-version": os.uname().release,
|
||||
"locations": {"snap-mount-dir": SNAP_DIR, "snap-bin-dir": BIN_DIR},
|
||||
"refresh": {"timer": "00:00~24:00/4"}, "confinement": "partial",
|
||||
"sandbox-features": {}, "architecture": ARCH})
|
||||
if path == "/v2/snaps":
|
||||
state = load_state()
|
||||
wanted = (q.get("snaps", [""])[0] or "").split(",")
|
||||
snaps = [installed_snap(n, e) for n, e in state["snaps"].items() if not wanted[0] or n in wanted]
|
||||
return self.ok(snaps)
|
||||
m = re.fullmatch(r"/v2/snaps/([^/]+)", path)
|
||||
if m:
|
||||
state = load_state()
|
||||
if m.group(1) in state["snaps"]:
|
||||
return self.ok(installed_snap(m.group(1), state["snaps"][m.group(1)]))
|
||||
return self.error(404, f"snap not installed", "snap-not-found")
|
||||
if path == "/v2/find":
|
||||
name = q.get("name", [None])[0]
|
||||
query = name or q.get("q", [""])[0]
|
||||
section = q.get("section", [None])[0] or q.get("category", [None])[0]
|
||||
if section == "featured":
|
||||
section = None
|
||||
select = q.get("select", [""])[0]
|
||||
if select == "refresh":
|
||||
return self.ok([])
|
||||
if select == "private":
|
||||
return self.ok([])
|
||||
return self.ok(find(query, section, bool(name)))
|
||||
if path in ("/v2/sections",):
|
||||
return self.ok(SECTIONS)
|
||||
if path == "/v2/categories":
|
||||
return self.ok([{"name": s} for s in SECTIONS if s != "featured"])
|
||||
m = re.fullmatch(r"/v2/changes/([^/]+)", path)
|
||||
if m:
|
||||
with lock:
|
||||
c = changes.get(m.group(1))
|
||||
c = json.loads(json.dumps(c)) if c else None
|
||||
return self.ok(c) if c else self.error(404, "cannot find change", "")
|
||||
if path == "/v2/changes":
|
||||
with lock:
|
||||
return self.ok([json.loads(json.dumps(c)) for c in changes.values()])
|
||||
m = re.fullmatch(r"/v2/icons/([^/]+)/icon", path)
|
||||
if m:
|
||||
return self.icon(m.group(1))
|
||||
if path == "/v2/apps":
|
||||
state = load_state()
|
||||
apps = [{"snap": n, "name": a, "desktop-file": f"{DESKTOP_DIR}/{n}_{a}.desktop"}
|
||||
for n, e in state["snaps"].items() for a in e.get("apps", [])]
|
||||
return self.ok(apps)
|
||||
if path in ("/v2/connections", "/v2/interfaces"):
|
||||
return self.ok({"established": [], "plugs": [], "slots": []})
|
||||
if path in ("/v2/aliases", "/v2/users", "/v2/notices", "/v2/assertions/model"):
|
||||
return self.ok({} if path == "/v2/aliases" else [])
|
||||
return self.error(404, f"not found: {path}")
|
||||
except Exception as e:
|
||||
return self.error(500, str(e))
|
||||
|
||||
def icon(self, name):
|
||||
state = load_state()
|
||||
entry = state["snaps"].get(name)
|
||||
if not entry:
|
||||
return self.error(404, "not installed", "snap-not-found")
|
||||
for candidate in ("meta/gui/icon.png", "meta/gui/icon.svg"):
|
||||
path = f"{SNAP_DIR}/{name}/current/{candidate}"
|
||||
if os.path.isfile(path):
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "image/svg+xml" if path.endswith("svg") else "image/png")
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
return
|
||||
return self.error(404, "no icon", "")
|
||||
|
||||
def do_POST(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
body = self.body()
|
||||
m = re.fullmatch(r"/v2/snaps/([^/]+)", path)
|
||||
if m or path == "/v2/snaps":
|
||||
names = [m.group(1)] if m else body.get("snaps") or []
|
||||
action = body.get("action", "")
|
||||
channel = body.get("channel") or ""
|
||||
if channel and "/" not in channel:
|
||||
channel = "latest/" + channel
|
||||
if action not in ("install", "remove", "refresh"):
|
||||
return self.error(400, f"unsupported action \"{action}\"")
|
||||
cid = new_change(f"{action}-snap", f"{action.capitalize()} {', '.join(names)}", names)
|
||||
threading.Thread(target=run_change, args=(cid, action, names, channel), daemon=True).start()
|
||||
return self.reply({"change": cid}, 202, "async")
|
||||
m = re.fullmatch(r"/v2/changes/([^/]+)", path)
|
||||
if m:
|
||||
return self.error(400, "changes cannot be aborted")
|
||||
if path in ("/v2/login", "/v2/logout", "/v2/snapctl"):
|
||||
return self.error(400, "not supported by DroidDeck's snap service")
|
||||
return self.error(404, f"not found: {path}")
|
||||
|
||||
def do_PUT(self):
|
||||
return self.do_POST()
|
||||
|
||||
|
||||
class Server(socketserver.ThreadingMixIn, socketserver.UnixStreamServer):
|
||||
daemon_threads = True
|
||||
|
||||
def get_request(self):
|
||||
conn, _ = self.socket.accept()
|
||||
return conn, ("snapd", 0)
|
||||
|
||||
|
||||
def serve(path):
|
||||
try:
|
||||
os.unlink(path)
|
||||
except OSError:
|
||||
pass
|
||||
server = Server(path, Handler)
|
||||
os.chmod(path, 0o666)
|
||||
server.serve_forever()
|
||||
|
||||
|
||||
def main():
|
||||
for d in (LIB, SNAP_DIR, BIN_DIR, DESKTOP_DIR, LIB + "/snaps"):
|
||||
os.makedirs(d, exist_ok=True)
|
||||
threads = [threading.Thread(target=serve, args=(p,), daemon=True) for p in SOCKETS]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -2,6 +2,7 @@
|
||||
import base64
|
||||
import ctypes
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import runpy
|
||||
import select
|
||||
@@ -15,6 +16,56 @@ import time
|
||||
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||
COMPAT = runpy.run_path(os.path.join(HERE, "steam-compatibility"))
|
||||
BINDING = "droiddeckCompatChanged"
|
||||
BRIGHTNESS_BINDING = "droiddeckBrightnessChanged"
|
||||
CONTROLS_DIR = "/etc/droiddeck-device-controls"
|
||||
BRIGHTNESS_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckBrightness) return "present";
|
||||
const display = SteamClient.System?.Display;
|
||||
if (!display?.RegisterForBrightnessChanges || !display?.SetBrightness) return "unavailable";
|
||||
const self = { expected: null, updating: true, revision: 0, localAt: -Infinity };
|
||||
// A held stick steps Steam faster than Android's readback returns; those stale readbacks would snap the slider back.
|
||||
const HOLD_MS = 750;
|
||||
// Returns "held" while a readback is being ignored, so the caller retries it after the hold.
|
||||
self.set = value => {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) return true;
|
||||
if (performance.now() - self.localAt < HOLD_MS) return "held";
|
||||
if (!self.updating && self.expected !== null && Math.abs(value - self.expected) < 0.0001) return true;
|
||||
self.expected = value;
|
||||
self.updating = true;
|
||||
const revision = ++self.revision;
|
||||
setTimeout(() => { if (self.revision === revision) self.updating = false; }, 500);
|
||||
display.SetBrightness(value);
|
||||
return true;
|
||||
};
|
||||
self.subscription = display.RegisterForBrightnessChanges(state => {
|
||||
const value = state?.flBrightness;
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1 || self.expected === null) return;
|
||||
if (Math.abs(value - self.expected) < 0.0001) { self.updating = false; return; }
|
||||
if (self.updating) { self.updating = false; return; }
|
||||
self.expected = value;
|
||||
self.localAt = performance.now();
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__(String(value));
|
||||
});
|
||||
window.__droiddeckBrightness = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", BRIGHTNESS_BINDING)
|
||||
|
||||
|
||||
def brightness_request(payload, directory=CONTROLS_DIR):
|
||||
try:
|
||||
value = float(payload)
|
||||
if not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
path = os.path.join(directory, "brightness.request")
|
||||
with open(path + ".tmp", "w") as target:
|
||||
target.write(str(value) + "\n")
|
||||
os.replace(path + ".tmp", path)
|
||||
except (ValueError, TypeError, OSError):
|
||||
return
|
||||
|
||||
|
||||
INSTALL_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckCompat) return "present";
|
||||
@@ -182,10 +233,6 @@ SWITCH_JS = r"""
|
||||
})()
|
||||
""".replace("__BINDING__", SWITCH_BINDING)
|
||||
SESSION_SELECT = "/usr/bin/steamos-session-select"
|
||||
# Steam opens its Steam Controller welcome tour at every start while the client setting
|
||||
# controller_show_ibex_tour (CMsgClientSettings field 140014) is on, and only a finished tour turns it
|
||||
# off; closing it leaves it on. The app's pad is an emulated controller, so the tour never applies.
|
||||
# A pending firmware update still opens Steam's updater, which checks the update priority instead.
|
||||
TOUR_JS = r"""
|
||||
(() => {
|
||||
let key = 140014 * 8;
|
||||
@@ -196,6 +243,112 @@ TOUR_JS = r"""
|
||||
return "off";
|
||||
})()
|
||||
"""
|
||||
FRAME_LIMIT_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckFrameLimit) return "present";
|
||||
const settings = window.settingsStore;
|
||||
let service = null;
|
||||
try {
|
||||
// Steam's webpack does not expose its module cache; the gamescope service client is found by
|
||||
// the calls its module makes and loaded by id.
|
||||
let require;
|
||||
window.webpackChunksteamui.push([[Symbol("droiddeck-frame-limit")], {}, r => { require = r; }]);
|
||||
for (const id of Object.keys(require.m || {})) {
|
||||
const source = String(require.m[id]);
|
||||
if (!source.includes("SetBlurParams") || !source.includes("RegisterForNotifyStateChanged")) continue;
|
||||
let exports;
|
||||
try { exports = require(id); } catch (e) { continue; }
|
||||
if (!exports || typeof exports !== "object") continue;
|
||||
service = Object.values(exports).find(value => value && typeof value.GetState === "function" &&
|
||||
typeof value.RegisterForNotifyStateChanged === "function" && typeof value.SetBlurParams === "function");
|
||||
if (service) break;
|
||||
}
|
||||
} catch (e) {
|
||||
service = null;
|
||||
}
|
||||
if (!service || !settings?.clientSettings || typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable";
|
||||
const self = { timer: null };
|
||||
const write = value => {
|
||||
const bytes = [];
|
||||
for (let n of [21002 * 8, value]) {
|
||||
while (n > 127) { bytes.push((n & 127) | 128); n = Math.floor(n / 128); }
|
||||
bytes.push(n);
|
||||
}
|
||||
return SteamClient.Settings.SetSetting(btoa(String.fromCharCode(...bytes)));
|
||||
};
|
||||
self.check = async () => {
|
||||
let rates;
|
||||
try {
|
||||
const reply = await service.GetState({});
|
||||
if (!reply.BSuccess()) return;
|
||||
rates = reply.Body().toObject().state?.active_display_info?.supported_frame_rates;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(rates) || rates.length === 0) return;
|
||||
const current = settings.clientSettings;
|
||||
if (!current.gamescope_enable_app_target_framerate || rates.includes(current.gamescope_app_target_framerate)) return;
|
||||
try {
|
||||
await write(Math.max(...rates));
|
||||
} catch (e) {
|
||||
}
|
||||
};
|
||||
self.schedule = () => {
|
||||
clearTimeout(self.timer);
|
||||
self.timer = setTimeout(self.check, 1500);
|
||||
};
|
||||
self.subscription = service.RegisterForNotifyStateChanged(self.schedule);
|
||||
self.interval = setInterval(self.schedule, 5000);
|
||||
self.schedule();
|
||||
window.__droiddeckFrameLimit = self;
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
FILE_BINDING = "droiddeckOpenFileDialog"
|
||||
FILE_JS = r"""
|
||||
(() => {
|
||||
const cancelled = () => ({ result: 2, message: "" });
|
||||
if (window.__droiddeckFiles) {
|
||||
window.__droiddeckFiles.cancelAll();
|
||||
return "present";
|
||||
}
|
||||
const self = { next: 0, pending: new Map() };
|
||||
const open = function (options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof window.__BINDING__ !== "function") { reject(cancelled()); return; }
|
||||
const id = ++self.next;
|
||||
self.pending.set(id, { resolve, reject });
|
||||
try { window.__BINDING__(JSON.stringify({ id, options: options || {} })); }
|
||||
catch (e) { self.pending.delete(id); reject(cancelled()); }
|
||||
});
|
||||
};
|
||||
self.done = (id, path) => {
|
||||
const item = self.pending.get(id);
|
||||
if (!item) return false;
|
||||
self.pending.delete(id);
|
||||
if (typeof path === "string" && path) item.resolve(path); else item.reject(cancelled());
|
||||
return true;
|
||||
};
|
||||
self.cancelAll = () => {
|
||||
const items = Array.from(self.pending.values());
|
||||
self.pending.clear();
|
||||
for (const item of items) item.reject(cancelled());
|
||||
};
|
||||
const patch = (w) => {
|
||||
const system = w?.SteamClient?.System;
|
||||
if (system && system.OpenFileDialog !== open) system.OpenFileDialog = open;
|
||||
};
|
||||
patch(window);
|
||||
if (SteamClient.System.OpenFileDialog !== open) throw new Error("Steam OpenFileDialog could not be redirected");
|
||||
const popups = window.g_PopupManager;
|
||||
if (popups) {
|
||||
for (const popup of popups.GetPopups?.() || []) patch(popup.window);
|
||||
popups.AddPopupCreatedCallback?.((popup) => patch(popup.window));
|
||||
}
|
||||
window.__droiddeckFiles = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", FILE_BINDING)
|
||||
VR_BINDING = "droiddeckLaunchSteamVr"
|
||||
VR_HELPER = "/usr/local/bin/droiddeck-steamvr"
|
||||
VR_JS = r"""
|
||||
@@ -262,7 +415,6 @@ VR_JS = r"""
|
||||
|
||||
|
||||
def launch_steamvr():
|
||||
"""Keep downloads/startup off the Steam UI bridge's event loop."""
|
||||
say("SteamVR library launch: using the DroidDeck ARM64 helper")
|
||||
state = os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/tmp"), "droiddeck-steamvr")
|
||||
try:
|
||||
@@ -274,6 +426,62 @@ def launch_steamvr():
|
||||
say("SteamVR library launch failed: %s" % e)
|
||||
|
||||
|
||||
def choose_file(options):
|
||||
import gi
|
||||
gi.require_version("Gdk", "3.0")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, Gtk
|
||||
directory = bool(options.get("bChooseDirectory"))
|
||||
save = bool(options.get("bSaveMode")) and not directory
|
||||
action = (Gtk.FileChooserAction.SELECT_FOLDER if directory else
|
||||
Gtk.FileChooserAction.SAVE if save else Gtk.FileChooserAction.OPEN)
|
||||
dialog = Gtk.FileChooserDialog(title=str(options.get("strTitle") or ""), action=action)
|
||||
dialog.add_buttons("gtk-cancel", Gtk.ResponseType.CANCEL,
|
||||
"gtk-save" if save else "gtk-open", Gtk.ResponseType.ACCEPT)
|
||||
dialog.set_default_response(Gtk.ResponseType.ACCEPT)
|
||||
dialog.set_local_only(True)
|
||||
dialog.set_do_overwrite_confirmation(True)
|
||||
for folder in ("/root/Storage", "/mnt/droiddeck-sd"):
|
||||
if os.path.isdir(folder):
|
||||
try:
|
||||
dialog.add_shortcut_folder(folder)
|
||||
except Exception:
|
||||
pass
|
||||
if not directory:
|
||||
for entry in options.get("rgFilters") or []:
|
||||
patterns = [str(p) for p in entry.get("rFilePatterns") or [] if p]
|
||||
if not patterns:
|
||||
continue
|
||||
chosen = Gtk.FileFilter()
|
||||
chosen.set_name(str(entry.get("strFileTypeName") or ", ".join(patterns)))
|
||||
for pattern in patterns:
|
||||
pattern = "*" if pattern == "*.*" else pattern
|
||||
chosen.add_pattern(pattern)
|
||||
if pattern.lower() != pattern.upper():
|
||||
chosen.add_pattern(pattern.upper())
|
||||
dialog.add_filter(chosen)
|
||||
if entry.get("bUseAsDefault"):
|
||||
dialog.set_filter(chosen)
|
||||
initial = str(options.get("strInitialFile") or "").strip('"')
|
||||
if initial:
|
||||
if os.path.isdir(initial):
|
||||
dialog.set_current_folder(initial)
|
||||
elif save:
|
||||
if os.path.isdir(os.path.dirname(initial)):
|
||||
dialog.set_current_folder(os.path.dirname(initial))
|
||||
dialog.set_current_name(os.path.basename(initial))
|
||||
elif os.path.exists(initial):
|
||||
dialog.set_filename(initial)
|
||||
elif os.path.isdir(os.path.dirname(initial)):
|
||||
dialog.set_current_folder(os.path.dirname(initial))
|
||||
screen = Gdk.Screen.get_default()
|
||||
if screen is not None:
|
||||
dialog.set_default_size(screen.get_width(), screen.get_height())
|
||||
chosen_path = dialog.get_filename() if dialog.run() == Gtk.ResponseType.ACCEPT else None
|
||||
dialog.destroy()
|
||||
return chosen_path
|
||||
|
||||
|
||||
class Closed(Exception):
|
||||
pass
|
||||
|
||||
@@ -519,10 +727,11 @@ class Watcher:
|
||||
|
||||
|
||||
class Helper:
|
||||
def __init__(self, steam_root, port, steamos=False):
|
||||
def __init__(self, steam_root, port, steamos=False, files_only=False):
|
||||
self.steam_root = steam_root
|
||||
self.port = port
|
||||
self.steamos = steamos
|
||||
self.files_only = files_only
|
||||
self.page = None
|
||||
self.known = set()
|
||||
self.installed = None
|
||||
@@ -530,6 +739,106 @@ class Helper:
|
||||
self.tools_asked = {}
|
||||
self.tools_checked = None
|
||||
self.vr_launch = None
|
||||
self.chooser = None
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
|
||||
def sync_controls(self):
|
||||
try:
|
||||
with open(os.path.join(CONTROLS_DIR, "state.json")) as source:
|
||||
state = json.load(source)
|
||||
value = state.get("brightness")
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
if not self.controls_installed:
|
||||
self.page.call("Runtime.addBinding", {"name": BRIGHTNESS_BINDING})
|
||||
self.controls_installed = self.page.evaluate(BRIGHTNESS_JS) in ("installed", "present")
|
||||
if not self.controls_installed:
|
||||
return
|
||||
if state != self.controls_state:
|
||||
applied = self.page.evaluate("window.__droiddeckBrightness ? window.__droiddeckBrightness.set(%s) : false" % json.dumps(value))
|
||||
if applied is True:
|
||||
self.controls_state = state
|
||||
elif applied != "held":
|
||||
self.controls_installed = False
|
||||
self.controls_state = None
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def sync_frame_limit(self):
|
||||
if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry:
|
||||
return
|
||||
try:
|
||||
state = self.page.evaluate(FRAME_LIMIT_JS)
|
||||
except RuntimeError as e:
|
||||
state = "failed (%s)" % e
|
||||
if state != self.frame_limit_state:
|
||||
say("frame limit sync: %s" % state)
|
||||
self.frame_limit_state = state
|
||||
self.frame_limit_retry = time.monotonic() + 10
|
||||
|
||||
def open_chooser(self, payload):
|
||||
try:
|
||||
request = json.loads(payload)
|
||||
ident = int(request["id"])
|
||||
options = request.get("options", {})
|
||||
if not isinstance(options, dict):
|
||||
raise ValueError("options are not an object")
|
||||
except (ValueError, KeyError, TypeError) as e:
|
||||
say("ignored a file dialog request (%s)" % e)
|
||||
return
|
||||
if self.chooser is not None:
|
||||
self.finish_chooser(ident, None)
|
||||
return
|
||||
command = [sys.executable, os.path.realpath(__file__), "--choose-file"]
|
||||
data = os.environ.get("XDG_DATA_HOME") or os.path.join(os.path.expanduser("~"), ".local", "share")
|
||||
for root in (self.steam_root, os.path.join(data, "Steam")):
|
||||
reaper = os.path.join(root, "steamrtarm64", "reaper")
|
||||
if os.access(reaper, os.X_OK):
|
||||
command = [reaper, "SteamLaunch", "AppId=769", "--"] + command
|
||||
break
|
||||
try:
|
||||
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
proc.stdin.write(json.dumps(options).encode("utf-8"))
|
||||
proc.stdin.close()
|
||||
except OSError as e:
|
||||
say("could not open a file dialog (%s)" % e)
|
||||
self.finish_chooser(ident, None)
|
||||
return
|
||||
say("file dialog open: %s" % (options.get("strTitle") or "untitled"))
|
||||
self.chooser = (ident, proc)
|
||||
|
||||
def chooser_done(self):
|
||||
ident, proc = self.chooser
|
||||
self.chooser = None
|
||||
out = proc.stdout.read().decode("utf-8", "replace")
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
if proc.returncode == 2:
|
||||
say("file dialog needs GTK 3 and PyGObject, which come with the desktop")
|
||||
try:
|
||||
path = json.loads(out) if proc.returncode == 0 else None
|
||||
except ValueError:
|
||||
path = None
|
||||
self.finish_chooser(ident, path if isinstance(path, str) and path else None)
|
||||
|
||||
def finish_chooser(self, ident, path):
|
||||
say("file dialog %s" % ("chose " + path if path else "cancelled"))
|
||||
self.page.evaluate("window.__droiddeckFiles?.done(%d, %s)" % (ident, json.dumps(path)))
|
||||
|
||||
def close_chooser(self):
|
||||
if self.chooser is not None:
|
||||
_, proc = self.chooser
|
||||
self.chooser = None
|
||||
try:
|
||||
os.killpg(proc.pid, signal.SIGTERM)
|
||||
except OSError:
|
||||
pass
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
|
||||
def attach(self):
|
||||
path = shared_context(self.port)
|
||||
@@ -539,13 +848,22 @@ class Helper:
|
||||
try:
|
||||
if page.evaluate("typeof SteamClient === 'object' && typeof SteamClient.WebUITransport === 'object'") is not True:
|
||||
raise LookupError("SteamClient is not ready")
|
||||
if self.files_only:
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.sync_controls()
|
||||
return True
|
||||
page.call("Runtime.addBinding", {"name": BINDING})
|
||||
page.call("Runtime.addBinding", {"name": VR_BINDING})
|
||||
page.evaluate(VR_JS)
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
try:
|
||||
page.evaluate(TOUR_JS)
|
||||
except RuntimeError:
|
||||
# The optional tour setting must not block the compat bridge.
|
||||
pass
|
||||
if not self.steamos:
|
||||
page.call("Runtime.addBinding", {"name": SWITCH_BINDING})
|
||||
@@ -555,6 +873,11 @@ class Helper:
|
||||
page.ws.close()
|
||||
raise
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
self.sync_controls()
|
||||
return True
|
||||
|
||||
def reconcile(self):
|
||||
@@ -577,15 +900,13 @@ class Helper:
|
||||
prior_auto = state.get("auto", {})
|
||||
if not isinstance(prior_auto, dict):
|
||||
prior_auto = {}
|
||||
# "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"])
|
||||
asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
|
||||
apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
|
||||
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
|
||||
refused = set(apps) - set(current)
|
||||
refused_native = native_choices & refused
|
||||
@@ -597,7 +918,6 @@ class Helper:
|
||||
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"](
|
||||
@@ -611,7 +931,6 @@ class Helper:
|
||||
else:
|
||||
for app in set(native) | native_choices:
|
||||
if app in raw_mapping:
|
||||
# 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 or app in picked and (
|
||||
@@ -619,6 +938,9 @@ class Helper:
|
||||
current[app] = ""
|
||||
elif not current.get(app):
|
||||
current.pop(app, None)
|
||||
requests = COMPAT["settled_game_requests"](state, current, catalog)
|
||||
overrides = COMPAT["requested_games"](requests or {}, catalog, [t["name"] for t in live])
|
||||
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
|
||||
changes, auto = COMPAT["plan_mapping"](
|
||||
current, installed, [t["name"] for t in live], default,
|
||||
COMPAT["followers"](state, current), native, picks, overrides,
|
||||
@@ -630,7 +952,8 @@ class Helper:
|
||||
state.update(
|
||||
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
|
||||
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)
|
||||
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True,
|
||||
games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
|
||||
state.pop("native", None)
|
||||
if waiting:
|
||||
state["pending"] = wanted
|
||||
@@ -640,7 +963,6 @@ class Helper:
|
||||
COMPAT["write_json"](state_file, state)
|
||||
|
||||
def ensure_tools(self):
|
||||
"""Proton, FEX and the runtimes FEX needs are fetched as soon as the client is up, never left pending."""
|
||||
now = time.monotonic()
|
||||
if self.tools_checked is not None and now - self.tools_checked < TOOL_CHECK_SECONDS:
|
||||
return
|
||||
@@ -666,7 +988,6 @@ class Helper:
|
||||
return isinstance(request.get("seq"), int) and request["seq"] > int(state.get("applied", 0) or 0)
|
||||
|
||||
def drain(self):
|
||||
"""The page's events; a switch to the desktop is acted on as it comes."""
|
||||
events = self.page.drain()
|
||||
if any(called(e, SWITCH_BINDING) for e in events):
|
||||
switch_to_desktop()
|
||||
@@ -678,17 +999,43 @@ class Helper:
|
||||
if vr_games and (self.vr_launch is None or self.vr_launch.poll() is not None):
|
||||
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
|
||||
self.vr_launch = launch_steamvr()
|
||||
for e in events:
|
||||
if called(e, BRIGHTNESS_BINDING):
|
||||
brightness_request(e.get("params", {}).get("payload"))
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
return events
|
||||
|
||||
def serve_files(self):
|
||||
say("attached to the client on port %d for its file dialogs" % self.port)
|
||||
while True:
|
||||
self.sync_controls()
|
||||
sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else [])
|
||||
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:
|
||||
self.chooser_done()
|
||||
if self.page.ws in ready or self.page.events:
|
||||
self.drain()
|
||||
|
||||
def serve(self, watcher):
|
||||
if self.files_only:
|
||||
return self.serve_files()
|
||||
with open(COMPAT["state_path"]("live.pid"), "w") as f:
|
||||
f.write("%d\n" % os.getpid())
|
||||
say("attached to the client on port %d" % self.port)
|
||||
self.reconcile()
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
self.sync_controls()
|
||||
self.sync_frame_limit()
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
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:
|
||||
self.chooser_done()
|
||||
due = False
|
||||
if self.page.ws in ready:
|
||||
due = any(called(e, BINDING) for e in self.drain())
|
||||
@@ -716,13 +1063,45 @@ def detach():
|
||||
COMPAT["write_json"](state_file, state)
|
||||
|
||||
|
||||
def chooser_main():
|
||||
try:
|
||||
options = json.load(sys.stdin)
|
||||
except ValueError:
|
||||
return 1
|
||||
try:
|
||||
path = choose_file(options if isinstance(options, dict) else {})
|
||||
except (ImportError, ValueError):
|
||||
return 2
|
||||
if not path:
|
||||
return 1
|
||||
print(json.dumps(path))
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
steam_root = sys.argv[1]
|
||||
files_only = sys.argv[1:2] == ["--files-only"]
|
||||
steam_root = sys.argv[2 if files_only else 1]
|
||||
try:
|
||||
port = int(os.environ.get("BL_CDP_PORT", ""))
|
||||
except ValueError:
|
||||
say("no devtools port for this session; the client's mapping is kept through config.vdf")
|
||||
return 0
|
||||
if files_only:
|
||||
helper = Helper(steam_root, port, files_only=True)
|
||||
failures = 0
|
||||
while True:
|
||||
try:
|
||||
helper.attach()
|
||||
failures = 0
|
||||
helper.serve(None)
|
||||
except Exception as e:
|
||||
helper.close_chooser()
|
||||
if helper.page is not None:
|
||||
say("lost the client (%s); reattaching" % e)
|
||||
helper.page.ws.close()
|
||||
helper.page = None
|
||||
failures += 1
|
||||
time.sleep(min(2 * max(failures, 1), 10))
|
||||
os.makedirs(COMPAT["COMPAT_DIR"], exist_ok=True)
|
||||
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json")] +
|
||||
[os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
|
||||
@@ -737,6 +1116,7 @@ def main():
|
||||
last = None
|
||||
helper.serve(watcher)
|
||||
except Exception as e:
|
||||
helper.close_chooser()
|
||||
if helper.page is not None:
|
||||
say("lost the client (%s); reattaching" % e)
|
||||
helper.page.ws.close()
|
||||
@@ -750,8 +1130,11 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.argv[1:2] == ["--choose-file"]:
|
||||
sys.exit(chooser_main())
|
||||
signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
|
||||
try:
|
||||
sys.exit(main())
|
||||
finally:
|
||||
detach()
|
||||
if sys.argv[1:2] != ["--files-only"]:
|
||||
detach()
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Honor a desktop launch even when Steam remembers Big Picture from its last session."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Resolve added games against the signed-in Steam client's licenses."""
|
||||
import ctypes as C
|
||||
import json
|
||||
import os
|
||||
@@ -14,11 +13,13 @@ import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
STATE = ".droiddeck-games.json"
|
||||
TRIED = ".droiddeck-import-tried.json"
|
||||
WINNATIVE = ".winnative-steam/steamapps"
|
||||
LIBRARY = "/mnt/droiddeck-sd"
|
||||
LEGACY_LIBRARY = "/mnt/bannerlator-sd"
|
||||
PARKED = ".droiddeck-parked"
|
||||
BASE_ID = 76561197960265728
|
||||
SPACEWAR = 480
|
||||
|
||||
|
||||
def read_json(path, default):
|
||||
@@ -64,8 +65,6 @@ def source_stamp(game):
|
||||
|
||||
|
||||
def store_game(game):
|
||||
"""Games a store client installed belong to that store: the Steam copy of the same title is
|
||||
another license with its own files, and an import would let Steam update over the store's."""
|
||||
return bool(game.get("store"))
|
||||
|
||||
|
||||
@@ -85,14 +84,14 @@ def identify(game):
|
||||
folder = Path(game["folder"])
|
||||
steamapps = folder.parent.parent
|
||||
for library in ([steamapps] if folder.parent.name == "common" and steamapps.name == "steamapps" else []) + [folder.parent / WINNATIVE]:
|
||||
matches = manifest_ids(library, folder.name)
|
||||
matches = [appid for appid in manifest_ids(library, folder.name) if appid != SPACEWAR]
|
||||
if matches:
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
ids = set()
|
||||
for parent in {folder, Path(game["exe"]).parent}:
|
||||
try:
|
||||
appid = int((parent / "steam_appid.txt").read_text().strip())
|
||||
if 0 < appid < 0x80000000:
|
||||
if 0 < appid < 0x80000000 and appid != SPACEWAR:
|
||||
ids.add(appid)
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
@@ -106,7 +105,7 @@ def identify(game):
|
||||
ids = {int(item["id"]) for item in items
|
||||
if key(item.get("name", "")) == key(game["name"]) and key(game["name"])}
|
||||
if ids:
|
||||
return next(iter(ids)) if len(ids) == 1 else None
|
||||
return next(iter(ids)) if len(ids) == 1 and SPACEWAR not in ids else None
|
||||
return None
|
||||
except (OSError, ValueError, KeyError):
|
||||
return None
|
||||
@@ -148,7 +147,6 @@ def probe(steam_root, ids):
|
||||
|
||||
|
||||
def game_running():
|
||||
"""Whether a Proton game is up: a wineserver is there for as long as any prefix is in use."""
|
||||
try:
|
||||
pids = [p for p in os.listdir("/proc") if p.isdigit()]
|
||||
except OSError:
|
||||
@@ -171,18 +169,49 @@ def downloads_idle(steam_root):
|
||||
|
||||
|
||||
def request_restart(steam_root):
|
||||
"""The client reads manifests and shortcuts only at start, so an import needs one restart;
|
||||
the session's loop runs the importer between the exit and the next start."""
|
||||
Path(os.environ.get("HOME", "/root"), ".bl-restart-once").touch()
|
||||
command = shlex.split(os.environ.get("BL_STEAM_SHUTDOWN", "")) or [str(Path(steam_root) / "steamrtarm64/steam"), "-shutdown"]
|
||||
subprocess.run(command,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=30)
|
||||
|
||||
|
||||
def ask_restart(names, timeout=600, clock=None, sleep=None):
|
||||
clock, sleep = clock or time.monotonic, sleep or time.sleep
|
||||
folder = Path(os.environ.get("HOME", "/root"), ".cache/droiddeck")
|
||||
ask, answer = folder / "steam-import.json", folder / "steam-import.answer"
|
||||
token = str(time.time_ns())
|
||||
answer.unlink(missing_ok=True)
|
||||
save_json(ask, {"token": token, "games": names})
|
||||
try:
|
||||
deadline = clock() + timeout
|
||||
while clock() < deadline:
|
||||
reply = read_json(answer, None)
|
||||
if isinstance(reply, dict) and reply.get("token") == token:
|
||||
return reply.get("choice") == "now"
|
||||
sleep(1)
|
||||
return False
|
||||
finally:
|
||||
ask.unlink(missing_ok=True)
|
||||
answer.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def unimported(steam_root, snapshot, candidates):
|
||||
routes = read_json(Path(steam_root) / "userdata" / snapshot["account"] / "config/.droiddeck-routes.json", {})
|
||||
config = Path(steam_root) / "userdata" / snapshot["account"] / "config"
|
||||
routes = read_json(config / ".droiddeck-routes.json", {})
|
||||
routed = set(routes.values()) if isinstance(routes, dict) else set()
|
||||
return sorted({appid for appid in candidates.values() if snapshot["owned"].get(str(appid)) is True} - routed)
|
||||
tried = read_json(config / TRIED, [])
|
||||
tried = {appid for appid in tried if isinstance(appid, int)} if isinstance(tried, list) else set()
|
||||
owned = {appid for appid in candidates.values() if snapshot["owned"].get(str(appid)) is True}
|
||||
if tried - routed != tried:
|
||||
save_json(config / TRIED, sorted(tried - routed))
|
||||
return sorted(owned - routed - tried)
|
||||
|
||||
|
||||
def remember_tried(steam_root, account, appids):
|
||||
config = Path(steam_root) / "userdata" / account / "config"
|
||||
tried = read_json(config / TRIED, [])
|
||||
tried = {appid for appid in tried if isinstance(appid, int)} if isinstance(tried, list) else set()
|
||||
save_json(config / TRIED, sorted(tried | set(appids)))
|
||||
|
||||
|
||||
def watch(steam_root, listing):
|
||||
@@ -193,7 +222,7 @@ def watch(steam_root, listing):
|
||||
next_lookup = 0
|
||||
last_status = None
|
||||
probed, next_probe, failures = None, 0, 0
|
||||
pending, requested = [], []
|
||||
pending, requested, account = [], [], None
|
||||
while True:
|
||||
now = time.monotonic()
|
||||
for game in games:
|
||||
@@ -233,6 +262,7 @@ def watch(steam_root, listing):
|
||||
snapshot["sources"] = sources
|
||||
save_json(Path(steam_root) / "userdata" / snapshot["account"] / "config" / STATE, snapshot)
|
||||
pending = unimported(steam_root, snapshot, candidates)
|
||||
account = snapshot["account"]
|
||||
status = "matched %d/%d games; %d owned" % (len(candidates), len(games), sum(snapshot["owned"].values()))
|
||||
except (OSError, ValueError, KeyError, StopIteration, subprocess.TimeoutExpired) as error:
|
||||
status = "ownership check unavailable: " + str(error)
|
||||
@@ -242,9 +272,14 @@ def watch(steam_root, listing):
|
||||
status = last_status
|
||||
if pending and pending != requested and not game_running() and downloads_idle(steam_root):
|
||||
requested = pending
|
||||
print("droiddeck-steam-games: restarting the client once to import %s" % pending, flush=True)
|
||||
names = sorted({game["name"] for game in games if candidates.get(game["folder"]) in pending})
|
||||
try:
|
||||
request_restart(steam_root)
|
||||
remember_tried(steam_root, account, pending)
|
||||
if ask_restart(names) and not game_running() and downloads_idle(steam_root):
|
||||
print("droiddeck-steam-games: restarting the client once to import %s" % pending, flush=True)
|
||||
request_restart(steam_root)
|
||||
else:
|
||||
print("droiddeck-steam-games: %s will be imported the next time the client starts" % pending, flush=True)
|
||||
except (OSError, subprocess.TimeoutExpired) as error:
|
||||
print("droiddeck-steam-games: restart unavailable: %s" % error, flush=True)
|
||||
if status != last_status:
|
||||
@@ -254,8 +289,6 @@ def watch(steam_root, listing):
|
||||
|
||||
|
||||
def installed_build(folder, appid, installdir):
|
||||
"""The build another Steam client recorded for these files, so Steam updates from it
|
||||
instead of verifying every file."""
|
||||
try:
|
||||
text = (folder.parent / WINNATIVE / f"appmanifest_{appid}.acf").read_text()
|
||||
install = re.search(r'("installdir"\s*")([^"\\]*)(")', text, re.I)
|
||||
@@ -382,20 +415,18 @@ def seed_install(steam_root, game, appid):
|
||||
return True
|
||||
|
||||
|
||||
def release(steam_root, game):
|
||||
"""Undoes an import made before store games were skipped. Only our symlink and manifest go;
|
||||
the store's folder stays where it is."""
|
||||
def release(steam_root, game, stale, reason):
|
||||
steamapps = Path(steam_root) / "steamapps"
|
||||
sources = {game.get("folder", ""), legacy_path(game.get("folder", ""))}
|
||||
for target in sorted((steamapps / "common").glob("DroidDeck-*")):
|
||||
appid = target.name.removeprefix("DroidDeck-")
|
||||
if not (appid.isdigit() and target.is_symlink() and os.readlink(target) in sources):
|
||||
if not (appid.isdigit() and target.is_symlink() and os.readlink(target) in sources and stale(int(appid))):
|
||||
continue
|
||||
for manifest in (steamapps / f"appmanifest_{appid}.acf", steamapps / PARKED / f"appmanifest_{appid}.acf"):
|
||||
if manifest.is_file() and ours(manifest, appid):
|
||||
manifest.unlink()
|
||||
target.unlink()
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} came from {game['store']}; it is a shortcut again, not Steam app {appid}")
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} {reason}; it is no longer Steam app {appid}")
|
||||
|
||||
|
||||
def route(steam_root, acct, games):
|
||||
@@ -416,7 +447,7 @@ def route(steam_root, acct, games):
|
||||
for game in games:
|
||||
if store_game(game):
|
||||
try:
|
||||
release(steam_root, game)
|
||||
release(steam_root, game, lambda old: True, f"came from {game['store']}")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: store import not undone ({error})")
|
||||
shortcuts.append(game)
|
||||
@@ -428,17 +459,23 @@ def route(steam_root, acct, games):
|
||||
appid = candidates.get(folder, candidates.get(legacy_path(folder)))
|
||||
stamp = source_stamp(game)
|
||||
recorded = sources.get(folder, sources.get(legacy_path(folder)))
|
||||
confirmed = (isinstance(appid, int) and 0 < appid < 0x80000000
|
||||
and owned.get(str(appid)) is True and stamp is not None
|
||||
and recorded in (stamp, [stamp[0], legacy_path(stamp[1])] + stamp[2:]))
|
||||
current = stamp is not None and recorded in (stamp, [stamp[0], legacy_path(stamp[1])] + stamp[2:])
|
||||
named = isinstance(appid, int) and 0 < appid < 0x80000000 and appid != SPACEWAR
|
||||
try:
|
||||
release(steam_root, game, lambda old: old == SPACEWAR or (current and named and old != appid),
|
||||
"names another Steam app now")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: earlier import not undone ({error})")
|
||||
confirmed = named and current and owned.get(str(appid)) is True
|
||||
if confirmed:
|
||||
try:
|
||||
if seed_install(steam_root, game, appid):
|
||||
routes[str(game["appid"])] = appid
|
||||
continue
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} stays a shortcut this session: it could not be linked as Steam app {appid}")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: import unavailable ({error})")
|
||||
elif isinstance(appid, int) and 0 < appid < 0x80000000 and seeded(steamapps, game, appid):
|
||||
elif named and seeded(steamapps, game, appid):
|
||||
routes[str(game["appid"])] = appid
|
||||
continue
|
||||
shortcuts.append(game)
|
||||
|
||||
@@ -1,25 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
cdn_list="https://client-update.steamstatic.com https://client-update.akamai.steamstatic.com https://client-update.fastly.steamstatic.com"
|
||||
steam_channel=steamdeck_publicbeta
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
beta_channel=steamdeck_publicbeta
|
||||
stable_channel=steamdeck_stable
|
||||
steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
channel_state=$steam_root/package/droiddeck-channel
|
||||
pinned=1
|
||||
wanted=${BL_STEAM_CHANNEL:-$(cat "$HOME/.config/droiddeck/steam-channel" 2>/dev/null || true)}
|
||||
case $wanted in
|
||||
stable|"$stable_channel") steam_channel=$stable_channel ;;
|
||||
beta|"$beta_channel") steam_channel=$beta_channel ;;
|
||||
*)
|
||||
pinned=
|
||||
steam_channel=$beta_channel
|
||||
[ "$(cat "$channel_state" 2>/dev/null)" = "$stable_channel" ] && steam_channel=$stable_channel
|
||||
;;
|
||||
esac
|
||||
if [ "${1:-}" = --channel ]; then
|
||||
echo "$steam_channel"
|
||||
exit 0
|
||||
fi
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
stamp=$steam_root/package/droiddeck-installed
|
||||
legacy_stamp=$steam_root/package/bannerlator-installed
|
||||
unconfirmed=$steam_root/package/droiddeck-unconfirmed
|
||||
repair_request=$HOME/.bl-steam-repair
|
||||
parts=$steam_root/package/droiddeck-download
|
||||
if [ -f "$legacy_stamp" ] && [ ! -f "$stamp" ]; then
|
||||
mv -f "$legacy_stamp" "$stamp" || true
|
||||
fi
|
||||
repair=""
|
||||
fallback=""
|
||||
starts=0
|
||||
[ -f "$unconfirmed" ] && starts=$(grep -cx start "$unconfirmed" || true)
|
||||
if [ -e "$repair_request" ]; then
|
||||
repair="requested"
|
||||
elif [ -f "$unconfirmed" ] && ! grep -qx repaired "$unconfirmed" \
|
||||
&& [ "$(grep -cx start "$unconfirmed")" -ge 2 ]; then
|
||||
repair="the client was started $(grep -cx start "$unconfirmed") times without showing anything"
|
||||
elif [ "$starts" -ge 2 ] && ! grep -qx repaired "$unconfirmed"; then
|
||||
repair="the client was started $starts times without showing anything"
|
||||
elif [ "$starts" -ge 2 ] && [ -z "$pinned" ] && [ "$steam_channel" = "$beta_channel" ] && [ "${1:-}" != --sync ]; then
|
||||
repair="the repaired $beta_channel client was started $starts more times without showing anything"
|
||||
fallback=1
|
||||
fi
|
||||
if [ -n "$fallback" ]; then
|
||||
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $repair"
|
||||
steam_channel=$stable_channel
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
fi
|
||||
if [ -n "$repair" ]; then
|
||||
echo "== STEP $(date -u +%H:%M:%S) repairing the Steam client ($repair)"
|
||||
if [ ! -f "$parts/.repair" ]; then
|
||||
rm -rf "$parts"
|
||||
mkdir -p "$parts" && : > "$parts/.repair"
|
||||
fi
|
||||
rm -f "$stamp" "$legacy_stamp" "$steam_root/.crash" "$steam_root/steam.pid" \
|
||||
"$steam_root"/package/steam_client_*.manifest "$steam_root"/package/steam_client_*.installed
|
||||
for part in "$steam_root"/package/*.zip.*; do
|
||||
@@ -42,20 +74,99 @@ fi
|
||||
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
|
||||
"$candidate/$manifest" -o "$work/manifest"; then
|
||||
cdn=$candidate
|
||||
break
|
||||
|
||||
nap() {
|
||||
[ -n "${nap_fd:-}" ] || exec {nap_fd}<> <(:)
|
||||
read -r -t "$1" -u "$nap_fd" _ 2>/dev/null || :
|
||||
}
|
||||
size_of() {
|
||||
local n=0
|
||||
[ -f "$1" ] && n=$(wc -c < "$1")
|
||||
echo $((n))
|
||||
}
|
||||
limits=(--connect-timeout 30 --speed-limit 4096 --speed-time 60)
|
||||
read -r -a delays <<< "${BL_STEAM_RETRY_DELAYS:-5 10 20 30 30}"
|
||||
|
||||
step() { echo "== STEP $(date -u +%H:%M:%S) $*"; }
|
||||
progress() {
|
||||
local mb=$(( (done_bytes + $(size_of "$1")) / 1000000 ))
|
||||
[ -z "${3:-}" ] && [ "$mb" = "${shown_mb:-}" ] && [ "$2" = "${shown_part:-}" ] && return 0
|
||||
shown_mb=$mb shown_part=$2
|
||||
step "downloading Steam: $2 ($i/$total), $mb of $((total_bytes / 1000000)) MB${3:+ - $3}"
|
||||
}
|
||||
|
||||
fetch() {
|
||||
local url=$1 dest=$2 size=$3 sum=$4 part=$5 failures=0 bad=0 finished=0 before rc fd wait
|
||||
while :; do
|
||||
if [ -f "$dest" ] && { [ "$finished" = 1 ] || { [ "$size" -gt 0 ] && [ "$(size_of "$dest")" -ge "$size" ]; }; }; then
|
||||
echo "$sum $dest" | sha256sum -c --quiet 2>/dev/null && return 0
|
||||
rm -f "$dest"
|
||||
finished=0 bad=$((bad + 1))
|
||||
[ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; }
|
||||
fi
|
||||
before=$(size_of "$dest")
|
||||
exec {fd}< <(code=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && echo "0 $code" || echo "$? $code")
|
||||
until read -r -t 5 -u "$fd" rc http; do
|
||||
if [ $? -le 128 ]; then rc=1; break; fi
|
||||
progress "$dest" "$part"
|
||||
done
|
||||
exec {fd}<&-
|
||||
if [ "$rc" = 0 ]; then finished=1; continue; fi
|
||||
case "$rc:${http:-}" in
|
||||
22:416 | 33:*) rm -f "$dest" ;;
|
||||
22:4??)
|
||||
echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi
|
||||
if [ "$failures" -gt "${#delays[@]}" ]; then
|
||||
echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2
|
||||
return 1
|
||||
fi
|
||||
wait=${delays[$((failures > 0 ? failures - 1 : 0))]}
|
||||
progress "$dest" "$part" "interrupted (curl exit $rc), trying again in ${wait} s"
|
||||
nap "$wait"
|
||||
done
|
||||
}
|
||||
|
||||
fetch_manifest() {
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
|
||||
"$candidate/$manifest" -o "$work/manifest"; then
|
||||
cdn=$candidate
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
|
||||
cdn_order=("$cdn")
|
||||
for candidate in $cdn_list; do
|
||||
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
|
||||
done
|
||||
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
|
||||
awk -F'"' '
|
||||
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
|
||||
$2 == "file" { file[block] = $4 }
|
||||
$2 == "sha2" { sha[block] = $4 }
|
||||
$2 == "size" { size[block] = $4 }
|
||||
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b], size[b] + 0 }
|
||||
' "$work/manifest" | sort > "$work/parts"
|
||||
[ -s "$work/parts" ] && return 0
|
||||
echo "droiddeck-steam-install: no client components in $manifest; its blocks are:" \
|
||||
"$(awk -F'"' '/^\t"/ && NF >= 3 && $4 == "" { printf "%s ", $2 }' "$work/manifest")" >&2
|
||||
return 1
|
||||
}
|
||||
if ! fetch_manifest; then
|
||||
if [ -n "$sync" ] || [ -n "$pinned" ] || [ "$steam_channel" = "$stable_channel" ]; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
|
||||
cdn_order=("$cdn")
|
||||
for candidate in $cdn_list; do
|
||||
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
|
||||
done
|
||||
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
|
||||
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $manifest has no arm64 client"
|
||||
steam_channel=$stable_channel
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
fallback=1
|
||||
fetch_manifest || exit 1
|
||||
fi
|
||||
if [ -n "$sync" ]; then
|
||||
installed=$(awk -F'"' '$2 == "version" { print $4; exit }' "$steam_root/package/$manifest.manifest" 2>/dev/null || true)
|
||||
if [ -x "$steam_root/steamrtarm64/steam" ] && [ "$installed" = "$version" ]; then
|
||||
@@ -64,31 +175,36 @@ if [ -n "$sync" ]; then
|
||||
fi
|
||||
echo "== STEP $(date -u +%H:%M:%S) updating the arm64 Steam client to $version (was ${installed:-none}) for the x86-64 client"
|
||||
fi
|
||||
awk -F'"' '
|
||||
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
|
||||
$2 == "file" { file[block] = $4 }
|
||||
$2 == "sha2" { sha[block] = $4 }
|
||||
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b] }
|
||||
' "$work/manifest" | sort > "$work/parts"
|
||||
[ -s "$work/parts" ] || { echo "droiddeck-steam-install: no client components in $manifest" >&2; exit 1; }
|
||||
total=$(grep -c . "$work/parts" 2>/dev/null || echo 0)
|
||||
total_bytes=$(awk '{ n += $4 } END { print n + 0 }' "$work/parts")
|
||||
|
||||
mkdir -p "$steam_root/package"
|
||||
while read -r block file sum; do
|
||||
mkdir -p "$parts"
|
||||
for left in "$parts"/*; do
|
||||
[ -e "$left" ] || continue
|
||||
name=${left##*/}
|
||||
name=${name%.unpacked}
|
||||
grep -qF " $name " "$work/parts" || rm -rf "$left"
|
||||
done
|
||||
done_bytes=0
|
||||
while read -r block file sum size; do
|
||||
i=$((${i:-0} + 1))
|
||||
echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)"
|
||||
if [ -f "$parts/$file.unpacked" ]; then
|
||||
done_bytes=$((done_bytes + size))
|
||||
continue
|
||||
fi
|
||||
progress "$parts/$file" "$block"
|
||||
fetched=""
|
||||
for host in "${cdn_order[@]}"; do
|
||||
if curl -fsSL --connect-timeout 10 --speed-limit 1024 --speed-time 60 --max-time 1800 \
|
||||
"$host/$file" -o "$work/$file" && echo "$sum $work/$file" | sha256sum -c --quiet; then
|
||||
if fetch "$host/$file" "$parts/$file" "$size" "$sum" "$block"; then
|
||||
fetched=$host
|
||||
break
|
||||
fi
|
||||
rm -f "$work/$file"
|
||||
done
|
||||
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
|
||||
unzip -qo "$work/$file" -d "$steam_root"
|
||||
rm -f "$work/$file"
|
||||
unzip -qo "$parts/$file" -d "$steam_root"
|
||||
: > "$parts/$file.unpacked"
|
||||
rm -f "$parts/$file"
|
||||
done_bytes=$((done_bytes + size))
|
||||
done < "$work/parts"
|
||||
find "$steam_root" -depth -name '*\\*' | while read -r odd; do
|
||||
fixed=${odd//\\//}
|
||||
@@ -111,12 +227,16 @@ mkdir -p "$HOME/.steam"
|
||||
ln -sfn "$steam_root" "$HOME/.steam/root"
|
||||
ln -sfn "$steam_root" "$HOME/.steam/steam"
|
||||
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/bin64"
|
||||
# sdk64 is where x86_64 Steamworks looks for steamclient.so; arm64 builds look in sdkarm64.
|
||||
ln -sfn "$steam_root/linux64" "$HOME/.steam/sdk64"
|
||||
ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64"
|
||||
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64"
|
||||
ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32"
|
||||
echo "$version" > "$stamp"
|
||||
rm -rf "$parts"
|
||||
if [ -n "$fallback" ]; then
|
||||
echo "$stable_channel" > "$channel_state"
|
||||
echo "== STEP $(date -u +%H:%M:%S) the Steam client now follows $stable_channel (beta in ~/.config/droiddeck/steam-channel returns to $beta_channel)"
|
||||
fi
|
||||
if [ -n "$repair" ]; then
|
||||
echo repaired > "$unconfirmed"
|
||||
rm -f "$repair_request"
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Sets the Steam client's interface language to the app's, before the client starts.
|
||||
|
||||
droiddeck-steam-language <home> <language>
|
||||
|
||||
<language> is one of the client's language names (english, spanish, latam, japanese, koreana,
|
||||
schinese, tchinese, ...). The client reads it from <home>/.steam/registry.vdf, under
|
||||
HKCU/Software/Valve/Steam and again under .../Steamsteamglobal: that second key is copied over the
|
||||
first at every start, so setting only the first is undone by the old value. Its update window
|
||||
reads the first key alone, and nothing reads LANG. exportedsettings.json is what the client writes
|
||||
beside them when its own setting changes. The session also passes -language, which the interface
|
||||
honours over the file; the file is still what the update window shows itself in.
|
||||
|
||||
Run only while the client is stopped: it keeps the registry in memory and writes it back on exit.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -63,7 +49,6 @@ def serialize(tokens):
|
||||
|
||||
|
||||
def block_end(tokens, start):
|
||||
"""Index of the '}' closing the block whose '{' is at start."""
|
||||
depth = 0
|
||||
for i in range(start, len(tokens)):
|
||||
if tokens[i] == "{":
|
||||
@@ -76,8 +61,6 @@ def block_end(tokens, start):
|
||||
|
||||
|
||||
def child(tokens, start, end, name):
|
||||
"""Index of the '{' of the block called name directly inside tokens[start:end], or None.
|
||||
Keys are matched without case, as the client does."""
|
||||
i = start
|
||||
while i < end:
|
||||
if tokens[i] in ("{", "}"):
|
||||
@@ -93,7 +76,6 @@ def child(tokens, start, end, name):
|
||||
|
||||
|
||||
def ensure_block(tokens, path):
|
||||
"""The '{' of the block at path, creating it and any missing parent at the end of its parent."""
|
||||
start, end = 0, len(tokens)
|
||||
for depth, name in enumerate(path):
|
||||
found = child(tokens, start, end, name)
|
||||
|
||||
@@ -12,6 +12,10 @@ case $target in
|
||||
esac
|
||||
|
||||
if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
case ",${MESA_VK_WSI_DEBUG:-}," in
|
||||
*,sw,*) ;;
|
||||
*) export MESA_VK_WSI_DEBUG=${MESA_VK_WSI_DEBUG:+$MESA_VK_WSI_DEBUG,}sw ;;
|
||||
esac
|
||||
if [ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ]; then
|
||||
client_home=${BL_X64_HOME:-${HOME:-/root}/.droiddeck-x64}
|
||||
client=(/usr/local/bin/droiddeck-steam-x64 --exec)
|
||||
@@ -21,6 +25,14 @@ if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
client_home=$HOME
|
||||
client=("$steam_root/steamrtarm64/steam")
|
||||
fi
|
||||
if [ "${BL_BOTTOM_DESKTOP:-}" = 1 ]; then
|
||||
pid=$(cat "$client_home/.steam/steam.pid" 2>/dev/null || true)
|
||||
if [ -p "$client_home/.steam/steam.pipe" ] && [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
|
||||
# The top screen's client takes the request, so games open there.
|
||||
exec "${client[@]}" -nobigpicture -no-cef-sandbox \
|
||||
-cef-ozone-platform=x11 -cef-disable-gpu "${url:-steam://open/library}"
|
||||
fi
|
||||
fi
|
||||
mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}/droiddeck"
|
||||
exec 9>"${XDG_CACHE_HOME:-$HOME/.cache}/droiddeck/steam-desktop.lock"
|
||||
if ! flock -n 9; then
|
||||
@@ -35,6 +47,7 @@ if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
echo "droiddeck-steam-launch: the desktop client did not become ready" >&2
|
||||
exit 69
|
||||
fi
|
||||
[ "$url" = steam://exit ] && exit 0
|
||||
export BL_INSIDE=1 BL_STEAM_UI=desktop
|
||||
exec /usr/local/bin/droiddeck-session steam "${url:-steam://open/library}"
|
||||
fi
|
||||
|
||||
@@ -9,9 +9,6 @@ MAIN_LABEL = "Internal Storage"
|
||||
|
||||
|
||||
def register(steam_root, library, label):
|
||||
"""Adds one library folder to the client's list; the client then offers it as an install
|
||||
location as well as reading the games already in it. Registered even when empty: a new user
|
||||
should be able to install straight into it."""
|
||||
steamapps = os.path.join(library, "steamapps")
|
||||
if not os.path.isdir(steamapps):
|
||||
return 0
|
||||
@@ -58,8 +55,6 @@ RENAMED = (("/mnt/bannerlator-sd", "/mnt/droiddeck-sd"),)
|
||||
|
||||
|
||||
def rename(steam_root, old, new):
|
||||
"""Moves a library registered under an earlier mount point to the current one, keeping its
|
||||
entry (content id, app sizes) rather than registering it anew."""
|
||||
path = os.path.join(steam_root, "steamapps", "libraryfolders.vdf")
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
@@ -77,8 +72,6 @@ def rename(steam_root, old, new):
|
||||
|
||||
|
||||
def forget(steam_root, library):
|
||||
"""Removes a library folder earlier builds registered and this one no longer binds, so the
|
||||
client does not keep offering a location that is not there."""
|
||||
path = os.path.join(steam_root, "steamapps", "libraryfolders.vdf")
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
@@ -107,10 +100,6 @@ def forget(steam_root, library):
|
||||
|
||||
|
||||
def relabel(steam_root, target, label):
|
||||
"""Names a library for what it is. The client writes its own entry with an empty label and
|
||||
falls back to showing the mount point - "Local Drive (/)" - so the install dialog gives no
|
||||
clue which of the two places is the phone and which is the card. A library registered on an
|
||||
earlier run keeps whatever label it was given then, so both are named here every time."""
|
||||
path = os.path.join(steam_root, "steamapps", "libraryfolders.vdf")
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
@@ -153,6 +142,7 @@ def relabel(steam_root, target, label):
|
||||
|
||||
|
||||
GAMES_DIR = "/root/Games/"
|
||||
ADDED_DIR = "/mnt/droiddeck-lib/"
|
||||
|
||||
|
||||
def wanted():
|
||||
@@ -193,7 +183,7 @@ def main():
|
||||
if managed:
|
||||
keep = {library for library, _ in libraries}
|
||||
for library in registered(steam_root):
|
||||
if library not in keep and (library == LIBRARIES[0][0] or library.startswith(GAMES_DIR)):
|
||||
if library not in keep and (library == LIBRARIES[0][0] or library.startswith((GAMES_DIR, ADDED_DIR))):
|
||||
forget(steam_root, library)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/python3
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
|
||||
VDF = runpy.run_path(str(Path(__file__).with_name("droiddeck-steam-ui-scale")))
|
||||
PATH = ("Software", "Valve", "Steam", "ShaderCacheManager", "DisableShaderCache")
|
||||
|
||||
|
||||
def set_text(text, enabled):
|
||||
value = "0" if enabled else "1"
|
||||
updated, changed = VDF["seed_value"](text, PATH, value)
|
||||
if changed:
|
||||
return updated, True
|
||||
block = VDF["parse"](text).get("InstallConfigStore")
|
||||
for section in PATH[:-1]:
|
||||
block = block.get(section)
|
||||
current = block.get(PATH[-1])
|
||||
if isinstance(current, VDF["Block"]):
|
||||
raise ValueError("invalid DisableShaderCache setting")
|
||||
if current == value:
|
||||
return text, False
|
||||
at = block.offset(PATH[-1])
|
||||
end = VDF["TOKEN"].match(text, at).end()
|
||||
return text[:at] + f'"{value}"' + text[end:], True
|
||||
|
||||
|
||||
def apply(steam_root, enabled):
|
||||
config = Path(steam_root) / "config/config.vdf"
|
||||
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
|
||||
updated, changed = set_text(text, enabled)
|
||||
if changed:
|
||||
VDF["atomic_write"](config, updated)
|
||||
return changed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3 or sys.argv[1] not in ("0", "1"):
|
||||
print("usage: droiddeck-steam-shaders <0|1> <steam root>...", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
enabled = sys.argv[1] == "1"
|
||||
status = 0
|
||||
for root in sys.argv[2:]:
|
||||
if not Path(root).is_dir():
|
||||
continue
|
||||
try:
|
||||
if apply(root, enabled):
|
||||
print(f"== steam: shader pre-caching {'on' if enabled else 'off'} in {root}")
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
print(f"== steam: left shader pre-caching unchanged in {root}: {error}", file=sys.stderr)
|
||||
status = 1
|
||||
sys.exit(status)
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
#!/usr/bin/python3
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
NOT_GAMES = frozenset((
|
||||
"228980", "1070560", "1391110", "1628350", "1493710", "3127680",
|
||||
"4183110", "4185400", "4427310", "4628740",
|
||||
))
|
||||
TOOL_DIR = re.compile(r"(steam ?linux ?runtime.*|proton.*|steamworks shared|fex|steamvr)", re.I)
|
||||
AUTOMATIC = ("", "droiddeck-direct", "droiddeck-fex", "droiddeck-proton-arm64", "droiddeck-proton-11-arm64")
|
||||
LINUX_TOOLS = ("droiddeck-direct", "droiddeck-fex")
|
||||
STATE = ".droiddeck-shared.json"
|
||||
LABELS = {"arm64": "ARM64 client games", "x86-64": "x86-64 client games"}
|
||||
|
||||
|
||||
def say(message):
|
||||
print("droiddeck-steam-share: " + message)
|
||||
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="surrogateescape") as f:
|
||||
return f.read()
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def write(path, text):
|
||||
staged = path + ".droiddeck-new"
|
||||
with open(staged, "w", encoding="utf-8", errors="surrogateescape") as f:
|
||||
f.write(text)
|
||||
os.replace(staged, path)
|
||||
|
||||
|
||||
def field(text, key):
|
||||
m = re.search(r'"%s"\s+"([^"]*)"' % re.escape(key), text or "", re.I)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
def number(text, key):
|
||||
value = field(text, key)
|
||||
return int(value) if value and value.isdigit() else 0
|
||||
|
||||
|
||||
def same(a, b):
|
||||
return os.path.realpath(a) == os.path.realpath(b)
|
||||
|
||||
|
||||
def libraries(root, skip):
|
||||
found = [root] + [p.replace("\\\\", "\\") for p in
|
||||
re.findall(r'"path"\s+"((?:[^"\\]|\\.)*)"', read(os.path.join(root, "steamapps", "libraryfolders.vdf")) or "")]
|
||||
return [p for p in dict.fromkeys(found) if not any(same(p, s) for s in skip)]
|
||||
|
||||
|
||||
def installs(libs):
|
||||
games = {}
|
||||
for library in libs:
|
||||
steamapps = os.path.join(library, "steamapps")
|
||||
try:
|
||||
names = sorted(os.listdir(steamapps))
|
||||
except OSError:
|
||||
continue
|
||||
for name in names:
|
||||
m = re.fullmatch(r"appmanifest_(\d+)\.acf", name)
|
||||
if not m or m.group(1) in NOT_GAMES or m.group(1) in games:
|
||||
continue
|
||||
text = read(os.path.join(steamapps, name))
|
||||
folder = field(text, "installdir")
|
||||
if (not folder or folder in (".", "..") or "/" in folder or TOOL_DIR.fullmatch(folder)
|
||||
or not number(text, "StateFlags") & 4
|
||||
or not os.path.isdir(os.path.join(steamapps, "common", folder))):
|
||||
continue
|
||||
games[m.group(1)] = (steamapps, text, folder)
|
||||
return games
|
||||
|
||||
|
||||
def link(path, target):
|
||||
if os.path.islink(path):
|
||||
if os.readlink(path) == target:
|
||||
return True
|
||||
os.unlink(path)
|
||||
elif os.path.lexists(path):
|
||||
return False
|
||||
os.symlink(target, path)
|
||||
return True
|
||||
|
||||
|
||||
def unlink(path):
|
||||
if os.path.islink(path):
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def emptied(src, folder):
|
||||
path = os.path.join(src, "common", folder)
|
||||
return not os.path.isdir(path) or not os.listdir(path)
|
||||
|
||||
|
||||
def sync(view, source, own):
|
||||
steamapps = os.path.join(view, "steamapps")
|
||||
for sub in ("common", "compatdata"):
|
||||
os.makedirs(os.path.join(steamapps, sub), exist_ok=True)
|
||||
state = {}
|
||||
try:
|
||||
state = json.loads(read(os.path.join(view, STATE)) or "{}")
|
||||
except ValueError:
|
||||
pass
|
||||
managed = {app: tuple(v) for app, v in state.get("shared", {}).items() if isinstance(v, list) and len(v) == 2}
|
||||
hidden = state.get("hidden", {})
|
||||
shared, back = {}, []
|
||||
for app, (src, folder) in managed.items():
|
||||
if app in source and app not in own:
|
||||
continue
|
||||
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
|
||||
if app not in own and not os.path.isfile(manifest) and emptied(src, folder) and os.path.isfile(os.path.join(src, "appmanifest_%s.acf" % app)):
|
||||
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
|
||||
unlink(os.path.join(steamapps, "common", folder))
|
||||
unlink(os.path.join(steamapps, "compatdata", app))
|
||||
if os.path.isfile(manifest):
|
||||
os.unlink(manifest)
|
||||
for app, (src, text, folder) in sorted(source.items(), key=lambda item: int(item[0])):
|
||||
if app in own:
|
||||
continue
|
||||
stamp = number(text, "LastUpdated")
|
||||
if hidden.get(app) == stamp:
|
||||
continue
|
||||
hidden.pop(app, None)
|
||||
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
|
||||
mine = read(manifest)
|
||||
if app in managed and mine is None:
|
||||
unlink(os.path.join(steamapps, "common", folder))
|
||||
unlink(os.path.join(steamapps, "compatdata", app))
|
||||
if emptied(src, folder):
|
||||
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
|
||||
else:
|
||||
hidden[app] = stamp
|
||||
continue
|
||||
if not link(os.path.join(steamapps, "common", folder), os.path.join(src, "common", folder)):
|
||||
continue
|
||||
if os.path.isdir(os.path.join(src, "compatdata", app)):
|
||||
link(os.path.join(steamapps, "compatdata", app), os.path.join(src, "compatdata", app))
|
||||
if mine is not None and number(mine, "LastUpdated") > stamp:
|
||||
write(os.path.join(src, "appmanifest_%s.acf" % app), mine)
|
||||
back.append(app)
|
||||
elif mine != text:
|
||||
write(manifest, text)
|
||||
shared[app] = [src, folder]
|
||||
state = {"shared": shared, "hidden": hidden}
|
||||
write(os.path.join(view, STATE), json.dumps(state, indent=1, sort_keys=True) + "\n")
|
||||
return shared, back
|
||||
|
||||
|
||||
def tools(root):
|
||||
names = set()
|
||||
folder = os.path.join(root, "compatibilitytools.d")
|
||||
try:
|
||||
entries = os.listdir(folder)
|
||||
except OSError:
|
||||
return names
|
||||
for entry in entries:
|
||||
text = read(os.path.join(folder, entry, "compatibilitytool.vdf")) or ""
|
||||
m = re.search(r'"compat_tools"\s*\{\s*"([^"]+)"', text)
|
||||
if m:
|
||||
names.add(m.group(1))
|
||||
return names
|
||||
|
||||
|
||||
def mapping_block(text):
|
||||
m = re.search(r'"CompatToolMapping"\s*\{', text)
|
||||
if not m:
|
||||
return None
|
||||
depth, k = 1, m.end()
|
||||
while depth and k < len(text):
|
||||
depth += {"{": 1, "}": -1}.get(text[k], 0)
|
||||
k += 1
|
||||
return m.end(), k - 1
|
||||
|
||||
|
||||
def entries(text):
|
||||
span = mapping_block(text)
|
||||
found = {}
|
||||
if not span:
|
||||
return found
|
||||
inner = text[span[0]:span[1]]
|
||||
for m in re.finditer(r'"(\d+)"\s*\{([^{}]*)\}', inner):
|
||||
name = re.search(r'"name"\s*"([^"]*)"', m.group(2))
|
||||
found.setdefault(m.group(1), name.group(1) if name else "")
|
||||
return found
|
||||
|
||||
|
||||
def set_tools(config, wanted):
|
||||
text = read(config)
|
||||
if text is None or not wanted:
|
||||
return []
|
||||
span = mapping_block(text)
|
||||
if not span:
|
||||
return []
|
||||
inner = text[span[0]:span[1]]
|
||||
changed = []
|
||||
for app, tool in sorted(wanted.items(), key=lambda item: int(item[0])):
|
||||
m = re.search(r'"%s"\s*\{([^{}]*)\}' % app, inner)
|
||||
if m:
|
||||
name = re.search(r'"name"\s*"([^"]*)"', m.group(1))
|
||||
name = name.group(1) if name else ""
|
||||
if name == tool or not (canonical(name) in map(canonical, AUTOMATIC) or name.startswith("proton_")):
|
||||
continue
|
||||
if name and (name in LINUX_TOOLS) == (tool in LINUX_TOOLS):
|
||||
continue
|
||||
inner = inner[:m.start()] + inner[m.end():]
|
||||
inner = ('\n\t\t\t\t\t"%s"\n\t\t\t\t\t{\n\t\t\t\t\t\t"name"\t\t"%s"\n\t\t\t\t\t\t"config"\t\t""\n'
|
||||
'\t\t\t\t\t\t"priority"\t\t"250"\n\t\t\t\t\t}' % (app, tool)) + inner
|
||||
changed.append(app)
|
||||
if changed:
|
||||
write(config, text[:span[0]] + inner + text[span[1]:])
|
||||
return changed
|
||||
|
||||
|
||||
def canonical(name):
|
||||
return re.sub(r"arm64|aarch64", "a64", name)
|
||||
|
||||
|
||||
def translate(name, here, available):
|
||||
if name == "droiddeck-fex" and here == "x86-64":
|
||||
return "droiddeck-direct"
|
||||
if name == "droiddeck-direct" and here == "arm64":
|
||||
return "droiddeck-fex"
|
||||
return {canonical(a): a for a in available}.get(canonical(name))
|
||||
|
||||
|
||||
def library_helper():
|
||||
sibling = os.path.join(os.path.dirname(os.path.realpath(__file__)), "droiddeck-steam-library")
|
||||
return runpy.run_path(sibling if os.path.isfile(sibling) else "/usr/local/bin/droiddeck-steam-library")
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 5 or argv[0] not in LABELS:
|
||||
say("usage: droiddeck-steam-share arm64|x86-64 ARM_STEAM X64_STEAM X64_CARD SHARED_DIR")
|
||||
return 2
|
||||
here, arm, x64, x64_card, shared_dir = argv
|
||||
views = {name: os.path.join(shared_dir, name) for name in LABELS}
|
||||
roots = {"arm64": arm, "x86-64": x64}
|
||||
other = "x86-64" if here == "arm64" else "arm64"
|
||||
skip = list(views.values()) + [x64, x64_card]
|
||||
arm_libs = libraries(arm, skip)
|
||||
x64_libs = [x64] + [p for p in libraries(x64, list(views.values()) + [arm]) if not same(p, x64)]
|
||||
games = {"arm64": installs(arm_libs), "x86-64": installs(x64_libs)}
|
||||
view = views[other]
|
||||
shared, back = sync(view, games[other], games[here])
|
||||
helper = library_helper()
|
||||
if not any(re.fullmatch(r"appmanifest_\d+\.acf", n) for n in os.listdir(os.path.join(view, "steamapps"))):
|
||||
helper["forget"](roots[here], view)
|
||||
return 0
|
||||
helper["register"](roots[here], view, LABELS[other])
|
||||
helper["relabel"](roots[here], view, LABELS[other])
|
||||
picks = entries(read(os.path.join(roots[other], "config", "config.vdf")) or "")
|
||||
available = tools(roots[here]) | {"droiddeck-direct" if here == "x86-64" else "droiddeck-fex"}
|
||||
wanted = {}
|
||||
for app in shared:
|
||||
tool = translate(picks.get(app) or picks.get("0", ""), here, available)
|
||||
if tool:
|
||||
wanted[app] = tool
|
||||
changed = set_tools(os.path.join(roots[here], "config", "config.vdf"), wanted)
|
||||
say("%d game(s) from the %s client%s%s" % (
|
||||
len(shared), other,
|
||||
"; tools set for %s" % " ".join(changed) if changed else "",
|
||||
"; manifests sent back for %s" % " ".join(back) if back else ""))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -6,6 +6,7 @@ if [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
steam://*) url=$arg ;;
|
||||
-shutdown) url=steam://exit ;;
|
||||
-gamepadui|-bigpicture) ui=bigpicture ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -16,15 +16,18 @@ TAG = "droiddeck-app"
|
||||
|
||||
|
||||
def account_dir(steam_root):
|
||||
"""The most recent account's userdata folder, else the only one that is not 0."""
|
||||
users = os.path.join(steam_root, "config", "loginusers.vdf")
|
||||
recent = None
|
||||
recent, best = None, None
|
||||
try:
|
||||
with open(users, encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
for block in re.finditer(r'"(\d{5,})"\s*\{([^}]*)\}', text):
|
||||
if re.search(r'"MostRecent"\s*"1"', block.group(2)):
|
||||
recent = int(block.group(1))
|
||||
stamp = re.search(r'"timestamp"\s*"(\d+)"', block.group(2))
|
||||
rank = (bool(re.search(r'"MostRecent"\s*"1"', block.group(2))),
|
||||
bool(re.search(r'"AutoLogin"\s*"1"', block.group(2))),
|
||||
int(stamp.group(1)) if stamp else 0)
|
||||
if any(rank) and (best is None or rank >= best):
|
||||
recent, best = int(block.group(1)), rank
|
||||
except OSError:
|
||||
pass
|
||||
userdata = os.path.join(steam_root, "userdata")
|
||||
@@ -239,9 +242,6 @@ ART_SLOTS = (("p", "p"), ("header", ""), ("hero", "_hero"), ("logo", "_logo"))
|
||||
|
||||
|
||||
def install_art(acct, games):
|
||||
"""Copies each game's art into the client's grid folder under the names it looks for. A file
|
||||
the client already has that this script did not write (art the user set in the client) is
|
||||
left alone; ours are replaced when the source changed and removed when the game lost its art."""
|
||||
grid = os.path.join(acct, "config", "grid")
|
||||
os.makedirs(grid, exist_ok=True)
|
||||
manifest_path = os.path.join(grid, ART_MANIFEST)
|
||||
@@ -350,7 +350,6 @@ def main():
|
||||
if x64_tool:
|
||||
protect = {compat.first_key(os.path.join(tools, e, "compatibilitytool.vdf"), ["compatibilitytools", "compat_tools"]) or e: e
|
||||
for e in (os.listdir(tools) if os.path.isdir(tools) else [])}
|
||||
# Its own state: the arm64 client's state.json lists which of that client's titles follow its default.
|
||||
own = {"default": x64_tool,
|
||||
"directory": os.path.join(os.path.dirname(os.path.abspath(steam_root)), "droiddeck-compat"),
|
||||
"linux_tool": "droiddeck-direct"}
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Initialize Steam's own display settings once; subsequent choices belong to Steam.
|
||||
|
||||
The UI scale, and native resolution: the client treats our gamescope as an external display and,
|
||||
unless "Enable Native Resolution on External Displays" is on, draws itself at 1920x1080 on any
|
||||
larger output - a 2340x1080 session came up as 16:9 with bars. The session's size is already the
|
||||
user's Resolution choice, so the client should use all of it.
|
||||
|
||||
And the screensaver over a running game. The client's defaults (steamui.so's settings descriptor)
|
||||
show screensavers while a game runs, after 300 s on AC power with no button pressed - and a stick or
|
||||
trigger held is no press. Red Dead Redemption 2's cutscenes run longer than that: the slideshow
|
||||
covered the game, and the button that woke it reached the game as well (B asked to quit to the
|
||||
desktop). Customization > Screensaver > "Show screensavers when playing a game" still turns it on."""
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -26,9 +14,10 @@ TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
|
||||
|
||||
|
||||
class Block:
|
||||
def __init__(self, pairs, end):
|
||||
def __init__(self, pairs, end, offsets=()):
|
||||
self.pairs = pairs
|
||||
self.end = end
|
||||
self.offsets = offsets
|
||||
|
||||
def get(self, name):
|
||||
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
|
||||
@@ -36,6 +25,9 @@ class Block:
|
||||
raise ValueError("duplicate UI setting")
|
||||
return matches[0] if matches else None
|
||||
|
||||
def offset(self, name):
|
||||
return next(at for (key, _), at in zip(self.pairs, self.offsets) if key.lower() == name.lower())
|
||||
|
||||
|
||||
def parse(text):
|
||||
tokens = []
|
||||
@@ -51,17 +43,17 @@ def parse(text):
|
||||
raise ValueError("invalid config.vdf")
|
||||
|
||||
def block(index, nested=False):
|
||||
pairs = []
|
||||
pairs, offsets = [], []
|
||||
while index < len(tokens):
|
||||
token, offset = tokens[index]
|
||||
if token == '}':
|
||||
if not nested:
|
||||
raise ValueError("unexpected closing brace")
|
||||
return Block(pairs, offset), index + 1
|
||||
return Block(pairs, offset, offsets), index + 1
|
||||
if not token.startswith('"') or index + 1 == len(tokens):
|
||||
raise ValueError("missing config value")
|
||||
key = token[1:-1]
|
||||
value = tokens[index + 1][0]
|
||||
value, at = tokens[index + 1]
|
||||
index += 2
|
||||
if value == '{':
|
||||
value, index = block(index, True)
|
||||
@@ -70,9 +62,10 @@ def parse(text):
|
||||
else:
|
||||
raise ValueError("invalid config value")
|
||||
pairs.append((key, value))
|
||||
offsets.append(at)
|
||||
if nested:
|
||||
raise ValueError("unclosed config block")
|
||||
return Block(pairs, len(text)), index
|
||||
return Block(pairs, len(text), offsets), index
|
||||
|
||||
return block(0)[0]
|
||||
|
||||
@@ -111,8 +104,6 @@ def seed_text(text, scale):
|
||||
|
||||
|
||||
def seed_value(text, path, value):
|
||||
"""InstallConfigStore/<path> = value, unless the client already has a value there (the
|
||||
user's), adding only the blocks that are missing."""
|
||||
root = parse(text).get('InstallConfigStore')
|
||||
if not isinstance(root, Block):
|
||||
raise ValueError("missing InstallConfigStore")
|
||||
@@ -165,9 +156,6 @@ def initialize(steam_root, width, height):
|
||||
|
||||
|
||||
def seed_once(steam_root, marker_name, seed, message):
|
||||
"""Applies seed to config.vdf the first time only: the marker keeps a later choice - including
|
||||
a return to the client's own default, which the client may store by dropping the key - the
|
||||
user's."""
|
||||
config = Path(steam_root) / 'config/config.vdf'
|
||||
marker = config.with_name(marker_name)
|
||||
if marker.exists():
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
FEX_TAG=fex-2610-r5
|
||||
FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4
|
||||
FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst
|
||||
ROOTFS_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/fex-rootfs-ubuntu-24.04-2026-08-11/Ubuntu_24_04.sqsh
|
||||
ROOTFS_SHA256=2854b06d3ff1b8f6e526135bfb6dd5b7b30ab3ab73e79ae933a3d9fed959a178
|
||||
CDN=https://client-update.fastly.steamstatic.com
|
||||
# Must match the -clientbeta droiddeck-session starts this client with (steam_channel).
|
||||
X64_CHANNEL=steamdeck_publicbeta
|
||||
MANIFEST=steam_client_${X64_CHANNEL}_steamrt64
|
||||
|
||||
@@ -18,6 +14,7 @@ ARM_STEAM=${XDG_DATA_HOME:-$REAL_HOME/.local/share}/Steam
|
||||
LOG=$X64_HOME/steam-x64.log
|
||||
mkdir -p "$X64_HOME"
|
||||
step() { echo "== STEP $(date -u +%H:%M:%S) $*" | tee -a "$LOG"; }
|
||||
. "${BASH_SOURCE[0]%/*}/droiddeck-fex-update"
|
||||
|
||||
x64_default_dir() {
|
||||
local d
|
||||
@@ -80,14 +77,17 @@ x64_sync_client() {
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
# The client rewrites config.vdf from memory as it exits: the mapping is written only while no x86 client runs.
|
||||
x64_map_direct() {
|
||||
local mode=write
|
||||
[ "${1:-}" = --live ] && mode=live
|
||||
[ -f "$STEAM_X64/config/config.vdf" ] || return 0
|
||||
if [ "$mode" = write ] && pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then return 0; fi
|
||||
local libraries="$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps:$X64_HOME/shared/arm64/steamapps" library
|
||||
for library in /mnt/droiddeck-lib/*/x86-64/steamapps; do
|
||||
[ -d "$library" ] && libraries="$libraries:$library"
|
||||
done
|
||||
python3 - "$mode" "$STEAM_X64/config/config.vdf" "$STEAM_X64/appcache/appinfo.vdf" "$X64_HOME/direct-auto.json" \
|
||||
"$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps" "$(x64_default_tool)" \
|
||||
"$X64_HOME/direct-sniper" "$libraries" "$(x64_default_tool)" \
|
||||
"$REAL_HOME/.bl-compat-pending" ${BL_X64_DIRECT_APPS:-550} \
|
||||
<<'PY' || { [ "$mode" = live ] || step "could not map titles to DroidDeck direct"; }
|
||||
# Steam does not swap an installed build when the tool changes: a title installed for Windows stays on Proton.
|
||||
@@ -319,77 +319,6 @@ print("droiddeck-steam-x64: %d Linux title(s) on DroidDeck direct (%d on the new
|
||||
PY
|
||||
}
|
||||
|
||||
# Whether every program in the FEX tree at $1 finds its libraries (r4 did not without libxxhash).
|
||||
fex_loads() {
|
||||
local b out
|
||||
for b in FEX FEXServer unsquashfs; do
|
||||
out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue
|
||||
echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2
|
||||
return 1
|
||||
done
|
||||
}
|
||||
|
||||
# Installs one FEX build only once its archive matches the sha256 and it loads. The files it replaces are kept
|
||||
# until the installed copy loads too, and put back otherwise; the tag is written last.
|
||||
fex_install() {
|
||||
local tag=$1 sha=$2 urls=$3 dst=/ tmp u f
|
||||
tmp=$(mktemp -d)
|
||||
for u in $urls; do
|
||||
curl -fsSL --retry 2 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
rm -f "$tmp/fex.tzst"
|
||||
done
|
||||
if [ ! -s "$tmp/fex.tzst" ]; then
|
||||
echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
(cd "$tmp/root" && find . ! -type d) > "$tmp/files"
|
||||
mkdir "$tmp/old"
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then
|
||||
cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; }
|
||||
fi
|
||||
done < "$tmp/files"
|
||||
if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" &&
|
||||
mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then
|
||||
rm -rf "$tmp"
|
||||
return 0
|
||||
fi
|
||||
echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
[ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f"
|
||||
done < "$tmp/files"
|
||||
tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
}
|
||||
|
||||
# The build DroidDeck-Components' fex.json names (the app passes it as BL_FEX_*) comes first, then a working
|
||||
# installed one, then FEX_TAG above. Sets FEX_NOW and FEX_FROM.
|
||||
x64_fex() {
|
||||
local have ok=
|
||||
have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true)
|
||||
[ -x /usr/local/bin/FEX ] && fex_loads / && ok=1
|
||||
if [ -n "${BL_FEX_TAG:-}" ]; then
|
||||
if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi
|
||||
step "downloading FEX ($BL_FEX_TAG)"
|
||||
if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi
|
||||
fi
|
||||
if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi
|
||||
step "downloading FEX ($FEX_TAG)"
|
||||
if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# A resumable download that reports every tenth of its size as a step.
|
||||
x64_fetch() {
|
||||
local url=$1 out=$2 label=$3 total pid rc=0 last=-1 pct
|
||||
total=$(curl -fsSIL "$url" 2>/dev/null | tr -d '\r' | awk 'tolower($1) == "content-length:" { v = $2 } END { print v + 0 }')
|
||||
@@ -406,13 +335,11 @@ x64_fetch() {
|
||||
}
|
||||
|
||||
x64_prepare() {
|
||||
x64_fex || { step "FEX could not be installed; see $LOG"; exit 1; }
|
||||
fex_ready || { step "FEX could not be installed; see $LOG"; exit 1; }
|
||||
step "FEX ready ($FEX_NOW, $FEX_FROM)"
|
||||
# The client's opt-in to its SteamRT3 build; without it, it re-executes through steam.sh, whose checks fail under proot.
|
||||
mkdir -p "$STEAM_X64" && : > "$STEAM_X64/.steam-enable-steamrt64-client"
|
||||
|
||||
if [ ! -f "$ROOTFS/.droiddeck-complete" ]; then
|
||||
# Resumes a part-done download; a finished one answers 416, which is not a failure here.
|
||||
x64_fetch "$ROOTFS_URL" "$X64_HOME/rootfs.sqsh" "downloading FEX's Ubuntu 24.04 x86 rootfs" || {
|
||||
rc=$?
|
||||
[ "$rc" = 22 ] && [ -s "$X64_HOME/rootfs.sqsh" ] || { step "rootfs download failed (curl $rc)"; exit 1; }
|
||||
@@ -428,13 +355,9 @@ if [ ! -f "$ROOTFS/.droiddeck-complete" ]; then
|
||||
touch "$ROOTFS/.droiddeck-complete"
|
||||
fi
|
||||
echo "== x86-64 rootfs: $(sed -n 's|.*/download/\([^/]*\)/.*|\1|p' <<<"$ROOTFS_URL") (sha256 ${ROOTFS_SHA256:0:12})" >&2
|
||||
# FEX falls back to the guest's own /etc/ld.so.preload (arm64 libraries) when the rootfs has none. The x86
|
||||
# session shim provides System V IPC, which Android kernels lack and the client's tier0 needs to start.
|
||||
: > "$ROOTFS/etc/ld.so.preload"
|
||||
for lib in libblsession libfakeinput; do
|
||||
have=0
|
||||
# 32-bit libfakeinput crashes SDL2 games (a NULL udev attribute reaches strdup), so only the x86_64 copy
|
||||
# is preloaded, by full path: with $LIB, FEX falls through to the session's own i386 copy.
|
||||
arches="x86_64 i386"; [ "$lib" = libfakeinput ] && arches=x86_64
|
||||
rm -f "$ROOTFS/usr/local/lib/i386-linux-gnu/libfakeinput.so"
|
||||
for arch in $arches; do
|
||||
@@ -511,7 +434,6 @@ if [ -f "$scout/steam-runtime.tar.xz" ] &&
|
||||
fi
|
||||
[ -L "$STEAM_X64/steamapps" ] && rm -f "$STEAM_X64/steamapps"
|
||||
mkdir -p "$STEAM_X64/steamapps"
|
||||
# FEX looks in the rootfs first: an empty dev/dri there hides the session's KGSL node, which x86 programs spin on.
|
||||
mkdir -p "$ROOTFS/dev/dri"
|
||||
mkdir -p "$X64_HOME/.steam"
|
||||
ln -sfn "$STEAM_X64" "$X64_HOME/.steam/root"
|
||||
@@ -520,40 +442,7 @@ ln -sfn "$STEAM_X64/ubuntu12_32" "$X64_HOME/.steam/bin32"
|
||||
ln -sfn "$STEAM_X64/ubuntu12_64" "$X64_HOME/.steam/bin64"
|
||||
ln -sfn "$STEAM_X64/linux32" "$X64_HOME/.steam/sdk32"
|
||||
ln -sfn "$STEAM_X64/linux64" "$X64_HOME/.steam/sdk64"
|
||||
# The client's bwrap probe (steam-runtime-check-requirements) needs user namespaces, which no Android app has.
|
||||
srt_real=$STEAM_X64/steamrt64/pv-runtime/steam-runtime-steamrt
|
||||
srt_shim=$X64_HOME/steamrt-shim
|
||||
if [ -d "$srt_real" ]; then
|
||||
rm -rf "$srt_shim"
|
||||
mkdir -p "$srt_shim/bin"
|
||||
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
|
||||
[ -e "$e" ] || continue
|
||||
[ "$(basename "$e")" = bin ] || ln -s "$e" "$srt_shim/$(basename "$e")"
|
||||
done
|
||||
for e in "$srt_real"/bin/*; do ln -s "$e" "$srt_shim/bin/$(basename "$e")"; done
|
||||
rm -f "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
printf '#!/bin/sh
|
||||
exit 0
|
||||
' > "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
chmod 755 "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
rm -f "$srt_shim/bin/steam-runtime-launch-client"
|
||||
cat > "$srt_shim/bin/steam-runtime-launch-client" <<'LAUNCH'
|
||||
#!/bin/sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--) shift; break ;;
|
||||
--directory=*) cd "${1#--directory=}" || exit 127 ;;
|
||||
--env=*) export "${1#--env=}" ;;
|
||||
--unset-env=*) unset "${1#--unset-env=}" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[ $# -gt 0 ] || exit 0
|
||||
exec "$@"
|
||||
LAUNCH
|
||||
chmod 755 "$srt_shim/bin/steam-runtime-launch-client"
|
||||
fi
|
||||
# Valve's platform libraries ship without soname links (pressure-vessel makes them); ldconfig adds them here.
|
||||
droiddeck-steamrt-shim "$STEAM_X64/steamrt64" "$X64_HOME/steamrt-shim" || rm -rf "$X64_HOME/steamrt-shim"
|
||||
srt_libs=$X64_HOME/steamrt-libs
|
||||
rm -rf "$srt_libs"
|
||||
mkdir -p "$srt_libs"
|
||||
@@ -563,13 +452,11 @@ for d in "$STEAM_X64"/steamrt64/pv-runtime/steam-runtime-steamrt/steamrt3c_platf
|
||||
for f in "$d"/*.so*; do [ -e "$srt_libs/$(basename "$f")" ] || ln -s "$f" "$srt_libs/"; done
|
||||
done
|
||||
FEX_ROOTFS=$ROOTFS /usr/local/bin/FEX "$ROOTFS/usr/sbin/ldconfig.real" -n "$srt_libs" >>"$LOG" 2>&1 || step "ldconfig on $srt_libs failed"
|
||||
# The rootfs's HarfBuzz needs a newer FreeType than some games bundle (Counter-Strike 2): use Valve's runtime one.
|
||||
sniper_compat=$X64_HOME/sniper-compat
|
||||
rm -rf "$sniper_compat"
|
||||
mkdir -p "$sniper_compat"
|
||||
hb=$(ls "$srt_libs"/libharfbuzz.so.0.* 2>/dev/null | head -n 1)
|
||||
if [ -n "$hb" ]; then ln -s "$hb" "$sniper_compat/libharfbuzz.so.0"; else step "warning: no HarfBuzz in Valve's runtime for the newer-runtime titles"; fi
|
||||
# LD_LIBRARY_PATH beats the system folders whatever its order: Valve's older glibc must not shadow the rootfs's.
|
||||
for f in "$srt_libs"/*; do
|
||||
n=$(basename "$f")
|
||||
if [ -e "$ROOTFS/usr/lib/x86_64-linux-gnu/$n" ] || [ -e "$ROOTFS/lib/x86_64-linux-gnu/$n" ]; then rm -f "$f"; fi
|
||||
@@ -641,8 +528,8 @@ RUN
|
||||
printf '"InstallConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"CompatToolMapping"\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n' \
|
||||
> "$STEAM_X64/config/config.vdf"
|
||||
fi
|
||||
x64_share x86-64
|
||||
x64_map_direct
|
||||
# Each wrapper execs droiddeck-x64-arm-proton through an arm64 binary, which FEX hands straight to the CPU.
|
||||
arm_tools=$ARM_STEAM/compatibilitytools.d
|
||||
mkdir -p "$X64_HOME/arm64"
|
||||
cp -f /usr/bin/env "$X64_HOME/arm64/env"
|
||||
@@ -654,7 +541,6 @@ RUN
|
||||
for src in "$arm_tools"/*/; do
|
||||
src=${src%/}; name=${src##*/}
|
||||
[ -f "$src/compatibilitytool.vdf" ] && [ -f "$src/toolmanifest.vdf" ] || continue
|
||||
# A droiddeck-fex wrapper made the arm64 client install Valve's FEX when this client probed its tools after logon.
|
||||
case $name in droiddeck-direct|droiddeck-fex) continue ;; esac
|
||||
dst=$STEAM_X64/compatibilitytools.d/$name
|
||||
mkdir -p "$dst"
|
||||
@@ -687,12 +573,11 @@ VDF
|
||||
chmod 755 "$dst/run"
|
||||
done
|
||||
x64_sync_login
|
||||
# Each client keeps its own libraries; written only while no x86 client runs, as it rewrites these on exit.
|
||||
if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
|
||||
listing_ok=0
|
||||
if python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
|
||||
if BL_X64_SHARED=$X64_HOME/shared/arm64 python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
|
||||
import json, os, re, sys
|
||||
keep = {os.path.realpath(sys.argv[1])}
|
||||
keep = {os.path.realpath(sys.argv[1]), os.path.realpath(os.environ["BL_X64_SHARED"])}
|
||||
# Without the session's list nothing is known about the card: leave the folders as they are.
|
||||
if not sys.argv[2]:
|
||||
sys.exit(3)
|
||||
@@ -736,7 +621,6 @@ PY
|
||||
step "could not add the card to the x86-64 client's library folders"
|
||||
fi
|
||||
fi
|
||||
# default-tool is the default this script set: titles still on it move along; a user's choice is kept.
|
||||
default=$(x64_default_dir)
|
||||
if [ -f "$default/compatibilitytool.vdf" ] && [ -f "$STEAM_X64/config/config.vdf" ] &&
|
||||
! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
|
||||
@@ -811,7 +695,6 @@ s = s[:steam.end()] + movie.group(0) + s[steam.end():]
|
||||
open(path, "w", encoding="utf-8", errors="surrogateescape").write(s)
|
||||
PY
|
||||
fi
|
||||
# FEX takes its rootfs from FEXServer, and one started without FEX_ROOTFS serves none: stop it while no x86 client runs.
|
||||
if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
|
||||
FEX_ROOTFS=$ROOTFS /usr/local/bin/FEXServer -k >/dev/null 2>&1 || true
|
||||
fi
|
||||
@@ -826,7 +709,6 @@ x64_webhelper_gpu() {
|
||||
}
|
||||
|
||||
x64_env() {
|
||||
# droiddeck-x64-arm-proton restores this arm64 environment before Proton runs.
|
||||
export -p | grep -v -E '^declare -x (PWD|OLDPWD|SHLVL|_)=' > "$X64_HOME/arm-session.env.new" || true
|
||||
mv -f "$X64_HOME/arm-session.env.new" "$X64_HOME/arm-session.env"
|
||||
unset LD_LIBRARY_PATH LD_PRELOAD STEAM_RUNTIME STEAM_RUNTIME_PREFER_HOST_LIBRARIES
|
||||
@@ -848,7 +730,6 @@ if x64_gpu && [ "${BL_X64_CLIENT_SOFTWARE:-0}" != 1 ]; then
|
||||
else
|
||||
unset FEX_THUNKCONFIG $gpu_vars
|
||||
export LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe
|
||||
# Over DRI3 the X server hands out the GPU node, and Mesa's software path loops on KMS dumb buffers on it.
|
||||
export LIBGL_DRI3_DISABLE=1
|
||||
fi
|
||||
[ "${BL_X64_FP_OFF:-0}" = 1 ] && export PROOT_FP_OFF=1
|
||||
@@ -861,12 +742,9 @@ export FEX_ROOTFS=$ROOTFS
|
||||
export STEAM_EXTRA_COMPAT_TOOLS_PATHS=
|
||||
export STEAM_RUNTIME=1
|
||||
[ -d "$X64_HOME/steamrt-shim" ] && export STEAM_RUNTIME_STEAMRT=$X64_HOME/steamrt-shim
|
||||
# The client starts commands via steam-runtime-launch-client; Valve's needs a session-bus service, the shim's runs them.
|
||||
[ -d "$X64_HOME/steamrt-shim/bin" ] && export PATH=$X64_HOME/steamrt-shim/bin:$PATH
|
||||
export LD_LIBRARY_PATH=$STEAM_X64/steamrt64:$STEAM_X64/steamrt64/panorama:$X64_HOME/steamrt-libs
|
||||
# After an update the client re-executes itself through pressure-vessel-wrap (bwrap) unless this guard is set.
|
||||
export STEAM_STEAMRT_RECURSION_GUARD=1
|
||||
# proot is a tracer: tier0 takes it for a debugger and breaks into it with int3 on its first failed assertion.
|
||||
export BL_WEBHELPER_HIDE_TRACER=1
|
||||
}
|
||||
|
||||
@@ -876,7 +754,6 @@ x64_manifest_version() {
|
||||
awk -F'"' '$2 == "version" { print $4; exit }' "$STEAM_X64/package/steam_client_${chan}_$1.manifest" 2>/dev/null || echo "?"
|
||||
}
|
||||
|
||||
# What x86 GL and Vulkan look like through FEX's thunks, for a session whose menus failed on the GPU.
|
||||
x64_gpu_probe() {
|
||||
local fex=${BL_FEX:-/usr/local/bin/FEX}
|
||||
echo "== x86-64 GPU probe (x86 glxinfo and vulkaninfo through FEX):"
|
||||
@@ -888,8 +765,6 @@ x64_gpu_probe() {
|
||||
) | sed 's/^/ /'
|
||||
}
|
||||
|
||||
# Steam's menus come from the web helper; when its GPU process keeps exiting, Chromium gives up on the GPU and
|
||||
# the menus never appear. Says so once in the session log, with the probe above.
|
||||
x64_gpu_watch() {
|
||||
local log=$STEAM_X64/logs/console-linux.txt from n codes
|
||||
from=$(( $(wc -l 2>/dev/null < "$log" || echo 0) + 1 ))
|
||||
@@ -901,13 +776,22 @@ x64_gpu_watch() {
|
||||
x64_gpu_probe
|
||||
}
|
||||
|
||||
x64_arm_webhelper_cpu_supported() {
|
||||
local status=0
|
||||
awk -F: '
|
||||
$1 ~ /^[[:space:]]*Features[[:space:]]*$/ {
|
||||
if ($2 !~ /(^|[[:space:]])atomics([[:space:]]|$)/) unsupported = 1
|
||||
}
|
||||
END { exit unsupported ? 1 : 0 }
|
||||
' /proc/cpuinfo 2>/dev/null || status=$?
|
||||
[ "$status" != 1 ]
|
||||
}
|
||||
|
||||
x64_exec() {
|
||||
x64_env
|
||||
cd "$STEAM_X64"
|
||||
# The client checksums its files at start and reinstalls over edited ones, so the session shim (preload/net.c)
|
||||
# swaps the web helper at exec. The arm64 helper only comes up against a client of the same build.
|
||||
if [ "${BL_X64_X86_WEBHELPER:-0}" != 1 ] && [ -x /usr/local/bin/droiddeck-x64-arm-webhelper ] &&
|
||||
[ -x "$ARM_STEAM/steamrtarm64/steamwebhelper" ]; then
|
||||
[ -x "$ARM_STEAM/steamrtarm64/steamwebhelper" ] && x64_arm_webhelper_cpu_supported; then
|
||||
local chan x86_build arm_build
|
||||
chan=$(cat "$STEAM_X64/package/beta" 2>/dev/null || echo "$X64_CHANNEL")
|
||||
x86_build=$(awk -F'"' '$2 == "version" { print $4; exit }' "$STEAM_X64/package/steam_client_${chan}_steamrt64.manifest" 2>/dev/null || true)
|
||||
@@ -919,7 +803,6 @@ x64_exec() {
|
||||
fi
|
||||
fi
|
||||
if [ -z "${BL_X64_ARM_WEBHELPER:-}" ] && x64_webhelper_gpu; then
|
||||
# Not --in-process-gpu (the preload's default): a GPU crash there takes the whole helper down.
|
||||
export BL_WEBHELPER_ARGS="--ignore-gpu-blocklist --use-gl=angle --use-angle=gl --ozone-platform=x11"
|
||||
[ -x /usr/local/bin/droiddeck-x64-webhelper ] && export BL_X64_ARM_WEBHELPER=/usr/local/bin/droiddeck-x64-webhelper
|
||||
elif [ -z "${BL_X64_ARM_WEBHELPER:-}" ]; then
|
||||
@@ -942,7 +825,14 @@ x64_exec() {
|
||||
exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@"
|
||||
}
|
||||
|
||||
# Steam renews its token every few days and refuses old copies: copy the newest every start, never while a client runs.
|
||||
x64_share() {
|
||||
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
[ -d "$STEAM_X64/steamapps" ] && [ -d "$ARM_STEAM/steamapps" ] || return 0
|
||||
droiddeck-steam-share "$1" "$ARM_STEAM" "$STEAM_X64" /mnt/droiddeck-sd/x86-64 "$X64_HOME/shared" ||
|
||||
step "could not share the games between the clients"
|
||||
}
|
||||
|
||||
x64_sync_login() {
|
||||
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
@@ -1058,6 +948,7 @@ PY
|
||||
|
||||
case "${1:-}" in
|
||||
--sync-login) x64_sync_login; exit 0 ;;
|
||||
--share) x64_share arm64; exit 0 ;;
|
||||
--prepare) x64_prepare; exit 0 ;;
|
||||
--exec) shift; x64_exec "$@" ;;
|
||||
--gpu) x64_gpu; exit $? ;;
|
||||
@@ -1077,7 +968,6 @@ if [ -n "${BL_FEXSERVER_LOG:-}" ]; then
|
||||
FEX_ROOTFS=$ROOTFS "$(dirname "${BL_FEX:-/usr/local/bin/FEX}")/FEXServer" -f -p 600 >"$BL_FEXSERVER_LOG" 2>&1 &
|
||||
sleep 1
|
||||
fi
|
||||
# The client's connection status comes from NetworkManager on the system bus; a desktop has no system bus.
|
||||
x64_bus= x64_nm= x64_pin=
|
||||
x64_cleanup() {
|
||||
[ -n "$x64_pin" ] && kill "$x64_pin" 2>/dev/null
|
||||
@@ -1116,7 +1006,6 @@ BUSCONF
|
||||
step "network: the system bus did not come up; the client will show no connection"
|
||||
fi
|
||||
fi
|
||||
# Left by a killed client: .crash opens the update UI on its spinner; stale Singleton* locks can blank the UI.
|
||||
if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
|
||||
for f in "$STEAM_X64/.crash" "$STEAM_X64/steam.pid" "$STEAM_X64/config/htmlcache/SingletonLock" \
|
||||
"$STEAM_X64/config/htmlcache/SingletonCookie" "$STEAM_X64/config/htmlcache/SingletonSocket"; do
|
||||
@@ -1134,7 +1023,6 @@ if [ -n "${BL_CLIENT_CPUS:-}" ] && command -v taskset >/dev/null 2>&1; then
|
||||
x64_pin=$!
|
||||
fi
|
||||
for attempt in 1 2 3 4 5; do
|
||||
# The branch on disk must match -clientbeta before every start, or the client loops on rc=42.
|
||||
echo "$X64_CHANNEL" > "$STEAM_X64/package/beta"
|
||||
step "starting the x86-64 SteamRT3 client under FEX (attempt $attempt): $*"
|
||||
rc=0
|
||||
@@ -1142,4 +1030,4 @@ for attempt in 1 2 3 4 5; do
|
||||
( x64_exec -clientbeta "$X64_CHANNEL" -no-cef-sandbox "${cef[@]}" "$@" ) >>"$LOG" 2>&1 || rc=$?
|
||||
step "client exited rc=$rc"
|
||||
[ "$rc" = 42 ] || break
|
||||
done
|
||||
done
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
client=$1
|
||||
shim=$2
|
||||
srt_real=$client/pv-runtime/steam-runtime-steamrt
|
||||
if [ ! -d "$srt_real" ]; then
|
||||
probe=$(find "$client" -maxdepth 4 -name steam-runtime-check-requirements -path '*/bin/*' -print -quit 2>/dev/null || true)
|
||||
srt_real=${probe:+${probe%/bin/*}}
|
||||
fi
|
||||
if [ -z "$srt_real" ] || [ ! -d "$srt_real" ]; then
|
||||
rm -rf "$shim"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "$shim"
|
||||
trap 'rm -rf "$shim"' ERR
|
||||
mkdir -p "$shim/bin"
|
||||
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
|
||||
[ -e "$e" ] || continue
|
||||
[ "$(basename "$e")" = bin ] || ln -s "$e" "$shim/$(basename "$e")"
|
||||
done
|
||||
for e in "$srt_real"/bin/*; do
|
||||
[ -e "$e" ] || continue
|
||||
ln -s "$e" "$shim/bin/$(basename "$e")"
|
||||
done
|
||||
rm -f "$shim/bin/steam-runtime-check-requirements"
|
||||
printf '#!/bin/sh
|
||||
exit 0
|
||||
' > "$shim/bin/steam-runtime-check-requirements"
|
||||
chmod 755 "$shim/bin/steam-runtime-check-requirements"
|
||||
rm -f "$shim/bin/steam-runtime-launch-client"
|
||||
cat > "$shim/bin/steam-runtime-launch-client" <<'LAUNCH'
|
||||
#!/bin/sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--) shift; break ;;
|
||||
--directory=*) cd "${1#--directory=}" || exit 127 ;;
|
||||
--env=*) export "${1#--env=}" ;;
|
||||
--unset-env=*) unset "${1#--unset-env=}" ;;
|
||||
--directory|--env|--unset-env)
|
||||
[ $# -ge 2 ] || exit 127
|
||||
case $1 in
|
||||
--directory) cd "$2" || exit 127 ;;
|
||||
--env) export "$2" ;;
|
||||
--unset-env) unset "$2" ;;
|
||||
esac
|
||||
shift ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[ $# -gt 0 ] || exit 0
|
||||
exec "$@"
|
||||
LAUNCH
|
||||
chmod 755 "$shim/bin/steam-runtime-launch-client"
|
||||
@@ -26,7 +26,6 @@ quest_settings() {
|
||||
configure_graphics() {
|
||||
case "$(cat /sys/class/kgsl/kgsl-3d0/gpu_model 2>/dev/null)" in
|
||||
Adreno840*)
|
||||
# The session's forced sysmem mode loses the Vulkan device in SteamVR.
|
||||
export TU_DEBUG="$(
|
||||
IFS=', '
|
||||
set -f
|
||||
@@ -41,8 +40,6 @@ configure_graphics() {
|
||||
esac
|
||||
}
|
||||
|
||||
# Any OpenXR probe (Steam runs one through Proton at every client start) starts vrserver
|
||||
# while a runtime is registered, so SteamVR is registered only during a DroidDeck VR session.
|
||||
unregister() {
|
||||
if grep -qF "\"$steamvr\"" "$HOME/.config/openvr/openvrpaths.vrpath" 2>/dev/null; then
|
||||
rm -f "$HOME/.config/openvr/openvrpaths.vrpath"
|
||||
@@ -78,7 +75,6 @@ stop() {
|
||||
|
||||
case "${1:-status}" in
|
||||
launch)
|
||||
# Library/URL entry point: use the same installer and start path as the app.
|
||||
exec 8>"$state/launch.lock"
|
||||
flock -n 8 || exit 0
|
||||
if ! installed; then
|
||||
@@ -221,7 +217,6 @@ JSON
|
||||
quest_settings apply || exit 1
|
||||
startup_handed_off=0
|
||||
trap '[ "$startup_handed_off" = 1 ] || quest_settings restore' EXIT
|
||||
# The pinned Frame package's CVP constructor exits on Quest's unsupported SoC.
|
||||
cvp=$steamvr/drivers/cv/bin/linuxarm64/libArcturusPerception.so
|
||||
if [ -f "$cvp" ]; then
|
||||
disabled=$cvp.droiddeck-disabled
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Exit 0 when this game run should open as a SteamVR panel: SteamVR is running and Steam
|
||||
# lists no VR support for the app, optional or required. Under SteamVR, Steam stacks a flat game's window behind
|
||||
# its own, so without the panel the game plays unseen.
|
||||
[ "${1:-}" = waitforexitandrun ] || exit 1
|
||||
[ -z "${DROIDDECK_STEAMVR_PANEL:-}" ] || exit 1
|
||||
# Non-Steam shortcuts run with SteamAppId=0 and their CGameID in SteamGameId.
|
||||
app=${SteamAppId:-}
|
||||
[ "$app" = 0 ] && app=${SteamGameId:-}
|
||||
case $app in '' | 0 | *[!0-9]*) exit 1 ;; esac
|
||||
|
||||
@@ -6,13 +6,11 @@ pgrep -x vrserver >/dev/null 2>&1 || {
|
||||
echo 'Start SteamVR before launching a game with droiddeck-steamvr-game.' >&2
|
||||
exit 1
|
||||
}
|
||||
# droiddeck-steamvr-flat skips a run that a launch option already wrapped.
|
||||
export DROIDDECK_STEAMVR_PANEL=1
|
||||
vrdir=${DROIDDECK_VR_DIR:-/usr/local/lib/droiddeck-vr}
|
||||
export VK_LAYER_PATH="$vrdir/layer${VK_LAYER_PATH:+:$VK_LAYER_PATH}"
|
||||
export VK_INSTANCE_LAYERS="VK_LAYER_DROIDDECK_vr${VK_INSTANCE_LAYERS:+:$VK_INSTANCE_LAYERS}"
|
||||
export VK_LOADER_LAYERS_DISABLE="${VK_LOADER_LAYERS_DISABLE:-~implicit~}"
|
||||
# Quest's guest GPU images use Vulkan sharing rather than DMA-BUF modifiers.
|
||||
if [ -S "/run/droiddeck/droiddeck-xr-frames" ]; then
|
||||
export gamescope_vr_use_modifiers=${gamescope_vr_use_modifiers:-false}
|
||||
fi
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Preserve SteamVR preferences across Quest's required compositor overrides."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
@@ -1,32 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
r"""Before Proton starts a store game, asks the app for what that store needs at launch.
|
||||
|
||||
Run by droiddeck-proton / droiddeck-proton-wrap (steam-compatibility) for every real game launch,
|
||||
whoever started it: the Games tab, a pinned shortcut, or the Steam client's own Play button. It
|
||||
looks for the store launcher DroidDeck wrote (.droiddeck-launch.bat) among the arguments; beside it
|
||||
.droiddeck-store.json says which store and game it is.
|
||||
|
||||
For an Epic game, once the Epic Games Launcher is installed (droiddeck-epic), the game is started
|
||||
through it: the hidden launcher signs the game in and hands its arguments back in
|
||||
.droiddeck-epic-args. Without the launcher, or when it cannot, the game needs a fresh exchange code
|
||||
to sign in, which only the app can mint. The request goes through files under $BL_LAUNCH_DIR/stores (the session root, the same path on both
|
||||
sides):
|
||||
|
||||
req/<id>.json {"op": "epic-code", "store": "epic", "id": "<app name>"} (tmp + rename)
|
||||
resp/<id>.json {"ok": true, "code": true|false, "reason": "..."}
|
||||
|
||||
The app writes .droiddeck-epic-code into the game's folder itself - the code never passes through
|
||||
here - and the launcher .bat reads and deletes it. No answer within TIMEOUT seconds: the game starts
|
||||
with its offline identity. A code file older than STALE_SECONDS is removed first, so a code left by
|
||||
an earlier launch is never used.
|
||||
|
||||
The game's prefix gets Wine's browser set to droiddeck-open-url, which hands web addresses to
|
||||
Android: an EOS sign-in step that falls back to a browser (a consent Epic asks for once per product)
|
||||
is finished there. An EOS overlay pointer (HKCU\Software\Epic Games\EOS "OverlayPath") an earlier
|
||||
build wrote is removed - with it the game exited while loading.
|
||||
|
||||
droiddeck-store-launch <the arguments Steam gave the compat tool>
|
||||
"""
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
@@ -38,6 +10,7 @@ import time
|
||||
import subprocess
|
||||
import tempfile
|
||||
import hashlib
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
LAUNCHER = ".droiddeck-launch.bat"
|
||||
@@ -74,12 +47,6 @@ def sidecar_at(folder):
|
||||
|
||||
|
||||
def find_store_game(argv):
|
||||
"""
|
||||
The (folder, sidecar) of a store game among [argv], or None when this is not one. Steam passes
|
||||
the shortcut's target: the launcher .bat when the game has one (Epic, Amazon, a GOG game with
|
||||
arguments), else the game's exe itself (most GOG games), which may sit in a subfolder - so the
|
||||
folders above it are looked through too, up to MAX_DEPTH, for the sidecar.
|
||||
"""
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'").replace("\\", "/")
|
||||
low = arg.lower()
|
||||
@@ -97,7 +64,6 @@ def find_store_game(argv):
|
||||
|
||||
|
||||
def drop_stale(folder, now=None):
|
||||
"""Removes a code file older than STALE_SECONDS; True when one was removed."""
|
||||
code = folder / EPIC_CODE
|
||||
try:
|
||||
if (now if now is not None else time.time()) - code.stat().st_mtime > STALE_SECONDS:
|
||||
@@ -133,7 +99,6 @@ def through_client(folder, sidecar, timeout=CLIENT_TIMEOUT):
|
||||
|
||||
|
||||
def ask(channel, request, timeout=TIMEOUT):
|
||||
"""Writes [request] under channel/req and waits for channel/resp; the answer, or None on timeout."""
|
||||
req_dir, resp_dir = channel / "req", channel / "resp"
|
||||
req_dir.mkdir(parents=True, exist_ok=True)
|
||||
resp_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -158,7 +123,6 @@ def ask(channel, request, timeout=TIMEOUT):
|
||||
|
||||
|
||||
def windows_path(unix):
|
||||
"""A guest path as Wine names it through Z: (the whole filesystem)."""
|
||||
return "Z:" + unix.replace("/", "\\")
|
||||
|
||||
|
||||
@@ -167,12 +131,6 @@ def reg_escape(value):
|
||||
|
||||
|
||||
def set_value(reg, key, name, value, now=None):
|
||||
"""
|
||||
Appends `key` with `"name"="value"` to a prefix's user.reg unless the last word on it already
|
||||
says so. Appended rather than edited in place, as DirectAudio's key is: Wine reads later sections
|
||||
over earlier ones, and nothing of the file is rewritten under a wineserver that might hold it.
|
||||
False when there is no user.reg yet (Proton creates the prefix after this; the next launch has it).
|
||||
"""
|
||||
if not reg.is_file():
|
||||
return False
|
||||
line = '"%s"="%s"' % (name, reg_escape(value))
|
||||
@@ -190,7 +148,6 @@ def set_value(reg, key, name, value, now=None):
|
||||
|
||||
|
||||
def remove_value(reg, key, name):
|
||||
"""Drops every `"name"=` line under `key` in user.reg; True when one was there."""
|
||||
if not reg.is_file():
|
||||
return False
|
||||
rows, inside, dropped = [], False, False
|
||||
@@ -209,13 +166,11 @@ def remove_value(reg, key, name):
|
||||
|
||||
|
||||
def options(sidecar):
|
||||
"""An Epic game's launch choices from its sidecar, as the Games tab's Epic card sets them."""
|
||||
e = sidecar.get("epic") if isinstance(sidecar.get("epic"), dict) else {}
|
||||
return {"eos": e.get("eos", True) is not False, "offline": e.get("offline", False) is True}
|
||||
|
||||
|
||||
def server_socket(pfx):
|
||||
"""The wineserver socket for prefix [pfx], as Wine names it (server-<dev>-<inode> under /tmp/.wine-<uid>)."""
|
||||
try:
|
||||
st = os.stat(pfx)
|
||||
except OSError:
|
||||
@@ -225,11 +180,6 @@ def server_socket(pfx):
|
||||
|
||||
|
||||
def wait_for_server(pfx, timeout=SERVER_WAIT):
|
||||
"""
|
||||
Waits for a wineserver still holding this prefix (an earlier verb's, or the last launch's) to
|
||||
exit: it rewrites user.reg from its own memory when it does, which drops a line appended
|
||||
meanwhile. True when none is left.
|
||||
"""
|
||||
sock = server_socket(pfx)
|
||||
if sock is None:
|
||||
return True
|
||||
@@ -240,7 +190,6 @@ def wait_for_server(pfx, timeout=SERVER_WAIT):
|
||||
|
||||
|
||||
def has_value(reg, key, name, value=None):
|
||||
"""Whether the last word on `key` in user.reg sets "name" (to [value], when given)."""
|
||||
if not reg.is_file():
|
||||
return False
|
||||
inside, last = False, None
|
||||
@@ -255,7 +204,6 @@ def has_value(reg, key, name, value=None):
|
||||
|
||||
|
||||
def provision_prefix(compat_data, wait=SERVER_WAIT):
|
||||
"""Wine's browser set to the hand-off, and an earlier build's EOS overlay pointer removed."""
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
@@ -291,15 +239,34 @@ def create_prefix(compat_data, proton, timeout=120):
|
||||
CLOUD_TIMEOUT = 15.0
|
||||
CLOUD_STORES = ("gog", "epic")
|
||||
STORE_GAME = 10
|
||||
RAN = 11
|
||||
RAN_FAILED = 12
|
||||
BATTLENET = "/usr/local/bin/droiddeck-battlenet"
|
||||
BATTLENET_EXE = re.compile(r"(?i)/compatdata/2596113170/pfx/drive_c/Program Files \(x86\)/Battle\.net/Battle\.net\.exe$")
|
||||
BATTLENET_LAUNCH = re.compile(r'(?i)^--exec=\s*"?launch\s+([A-Za-z0-9_]{1,16})"?$')
|
||||
|
||||
|
||||
def battlenet(argv, env=os.environ):
|
||||
if env.get("BL_BATTLENET"):
|
||||
return None
|
||||
exe, code = False, None
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'")
|
||||
if BATTLENET_EXE.search(arg.replace("\\", "/")):
|
||||
exe = True
|
||||
found = BATTLENET_LAUNCH.match(arg)
|
||||
if found:
|
||||
code = found.group(1)
|
||||
if not exe:
|
||||
return None
|
||||
return [BATTLENET, "launch", code] if code else [BATTLENET, "open"]
|
||||
|
||||
|
||||
def cloud_on(sidecar):
|
||||
"""Cloud saves for this game (the game card's switch; on unless turned off)."""
|
||||
return str(sidecar.get("store")) in CLOUD_STORES and sidecar.get("cloud", True) is not False
|
||||
|
||||
|
||||
def exited(argv, code=0):
|
||||
"""After the game: ask the app to upload what changed, without waiting for it."""
|
||||
found = find_store_game(argv)
|
||||
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
|
||||
if found is not None and str(found[1].get("store")) == "epic" and os.environ.get(EPIC_HANDLED) != "1" \
|
||||
@@ -320,7 +287,6 @@ COMET_DIR = Path("/usr/local/lib/droiddeck-comet")
|
||||
|
||||
|
||||
def provision_galaxy(compat_data, proton, timeout=90):
|
||||
"""Proton creates the prefix and registers Galaxy before the first game runs."""
|
||||
if not compat_data or not proton or not Path(proton).is_file():
|
||||
return "no-proton"
|
||||
data = Path(compat_data)
|
||||
@@ -471,8 +437,27 @@ def gog_registry(folder):
|
||||
return entries, skipped
|
||||
|
||||
|
||||
def apply_gog_registry(folder, compat_data, proton, timeout=90):
|
||||
def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=None):
|
||||
entries, skipped = gog_registry(folder)
|
||||
if installation:
|
||||
product = str(installation["id"])
|
||||
if not product.isdigit():
|
||||
raise ValueError("Invalid GOG product identifier")
|
||||
values = {"PATH": windows_path(str(folder))}
|
||||
identity = Path(folder) / ("goggame-%s.id" % product)
|
||||
if identity.is_file():
|
||||
actual = json.loads(identity.read_text(encoding="utf-8-sig")).get("buildId")
|
||||
if actual and installation.get("build") and str(actual) != str(installation["build"]):
|
||||
raise ValueError("GOG build metadata changed before patch setup")
|
||||
if installation.get("build"):
|
||||
values["BUILDID"] = installation["build"]
|
||||
if installation.get("version"):
|
||||
values["VER"] = installation["version"]
|
||||
for key, value in values.items():
|
||||
entry = gog_entry({"root": "HKLM", "subkey": "Software\\GOG.com\\Games\\" + product,
|
||||
"valueName": key, "valueData": value, "valueType": "string"}, {})
|
||||
if entry:
|
||||
entries.append(entry)
|
||||
note = " skipped=%d" % skipped if skipped else ""
|
||||
if not entries:
|
||||
return "none" + note
|
||||
@@ -489,7 +474,8 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90):
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-gog-") as tmp:
|
||||
source = Path(tmp) / "registry.reg"
|
||||
source.write_bytes(b"\xff\xfe" + text.encode("utf-16-le"))
|
||||
run = subprocess.run([proton, "run", "reg.exe", "import", windows_path(str(source)), "/reg:32"],
|
||||
executable = pfx / "drive_c/windows/system32/reg.exe"
|
||||
run = subprocess.run([proton, "run", str(executable) if executable.is_file() else "reg.exe", "import", windows_path(str(source)), "/reg:32"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
if run.returncode or not (pfx / "system.reg").is_file():
|
||||
return "import-failed" + note
|
||||
@@ -502,6 +488,8 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90):
|
||||
|
||||
|
||||
def main(argv):
|
||||
if os.environ.get("DROIDDECK_GOG_MAINTENANCE") == "1":
|
||||
return 0
|
||||
if argv and argv[0] == "--exited":
|
||||
rest, code = argv[1:], 0
|
||||
if rest[:1] == ["--code"] and len(rest) > 1:
|
||||
@@ -511,11 +499,27 @@ def main(argv):
|
||||
pass
|
||||
rest = rest[2:]
|
||||
return exited(rest, code)
|
||||
command = battlenet(argv)
|
||||
if command is not None:
|
||||
log("battlenet " + " ".join(command[1:]))
|
||||
return RAN if subprocess.call(command) == 0 else RAN_FAILED
|
||||
found = find_store_game(argv)
|
||||
if found is None:
|
||||
return 0
|
||||
folder, sidecar = found
|
||||
store, game = str(sidecar.get("store")), str(sidecar.get("id"))
|
||||
if store == "gog":
|
||||
helper = Path(__file__).resolve().with_name("droiddeck-gog-maintenance")
|
||||
if helper.is_file():
|
||||
child = subprocess.Popen([sys.executable, str(helper), "lease", str(folder), str(os.getppid())],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
|
||||
start_new_session=True)
|
||||
ready = child.stdout.readline().decode().strip()
|
||||
child.stdout.close()
|
||||
threading.Thread(target=child.wait, daemon=True).start()
|
||||
if ready != "ready":
|
||||
log("gog: close or recover the maintenance operation before playing")
|
||||
return RAN_FAILED
|
||||
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", "")
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
REAL = "/usr/bin/systemd-run"
|
||||
VALUED = {"-u", "--unit", "-p", "--property", "--description", "--slice", "-E", "--setenv",
|
||||
"--working-directory", "--uid", "--gid", "--nice", "-H", "--host", "-M", "--machine",
|
||||
"--on-active", "--on-boot", "--on-startup", "--on-unit-active", "--on-unit-inactive",
|
||||
"--on-calendar", "--path-property", "--socket-property", "--timer-property", "--service-type",
|
||||
"--shell", "--slice-inherit"}
|
||||
|
||||
|
||||
def main(argv):
|
||||
args = argv[1:]
|
||||
if "--user" not in args:
|
||||
os.execv(REAL, [REAL] + args)
|
||||
env = dict(os.environ)
|
||||
cwd = None
|
||||
foreground = False
|
||||
i = 0
|
||||
while i < len(args):
|
||||
a = args[i]
|
||||
if a == "--":
|
||||
i += 1
|
||||
break
|
||||
if not a.startswith("-"):
|
||||
break
|
||||
name, _, inline = a.partition("=")
|
||||
value = inline if inline else (args[i + 1] if name in VALUED and i + 1 < len(args) else "")
|
||||
if name in ("-E", "--setenv") and "=" in value:
|
||||
k, _, v = value.partition("=")
|
||||
env[k] = v
|
||||
elif name == "--working-directory":
|
||||
cwd = value
|
||||
elif name in ("--scope", "--wait", "-W", "--pipe", "-P", "-t", "--pty"):
|
||||
foreground = True
|
||||
i += 1 if inline or name not in VALUED else 2
|
||||
command = args[i:]
|
||||
if not command:
|
||||
os.execv(REAL, [REAL] + args)
|
||||
if cwd:
|
||||
os.chdir(cwd)
|
||||
if foreground:
|
||||
os.execvpe(command[0], command, env)
|
||||
if os.fork() == 0:
|
||||
os.setsid()
|
||||
null = os.open(os.devnull, os.O_RDWR)
|
||||
os.dup2(null, 0)
|
||||
try:
|
||||
os.execvpe(command[0], command, env)
|
||||
except OSError:
|
||||
os._exit(127)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
key=$1
|
||||
shift
|
||||
line=$(grep -m1 "^$key=" /etc/droiddeck/strings 2>/dev/null)
|
||||
text=${line#*=}
|
||||
[ -n "$line" ] || text=$key
|
||||
printf "$text\n" "$@"
|
||||
@@ -1,27 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Windows components (OpenAL, d3dx, XAudio, ...) for a game's Proton prefix.
|
||||
|
||||
The app installs each component under STORE/<id>: its files in system32/ (64-bit) and syswow64/
|
||||
(32-bit) as Windows lays them out, and component.json naming the overrides that make Wine load
|
||||
them instead of its own ("name" for native-then-builtin, or "name=n" with Wine's own letters) and
|
||||
the components it bundles ("requires"). The ids are Bannerlator's catalog names (xaudio2.7,
|
||||
oalinst_dll...). The user picks components per game; the picks are in SELECTION as
|
||||
{"version": 1, "games": {"<appid>": ["oalinst_dll", ...]}}.
|
||||
|
||||
A component installed from a Windows Installer package (droiddeck-msi-install) also has drive_c/,
|
||||
its files at their Windows paths (Program Files, the .NET GAC, winsxs...), and registry.json, the
|
||||
values its package writes.
|
||||
|
||||
droiddeck-game-env calls apply() before every game launch. It copies what is missing or changed
|
||||
into compatdata/<appid>/pfx, writes the components' registry values into the prefix's registry
|
||||
files (system.reg, user.reg) and returns the overrides for WINEDLLOVERRIDES, so Wine never has to
|
||||
be running. A prefix Proton has not made yet gets the registry values on the launch after.
|
||||
|
||||
Proton leaves the files alone afterwards: its builtin refresh (update_builtin_libs) replaces only
|
||||
files that are its own builtins, and a new prefix is built around files already there (copy_pfx
|
||||
skips them). The one case that removes them is a launch on an older Proton than the prefix's,
|
||||
which deletes every file Proton once placed - and the next launch's apply() puts ours back.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -62,7 +39,6 @@ def wanted(app_id, selection=SELECTION):
|
||||
|
||||
|
||||
def component(store, cid):
|
||||
"""The component's overrides, its files as (relative path, source) and the ids it bundles, or None if not installed."""
|
||||
root = Path(store) / cid
|
||||
try:
|
||||
with open(root / "component.json", encoding="utf-8") as source:
|
||||
@@ -87,7 +63,6 @@ def component(store, cid):
|
||||
|
||||
|
||||
def registry_values(root):
|
||||
"""The component's registry values (registry.json), the ones that are well formed."""
|
||||
try:
|
||||
with open(Path(root) / "registry.json", encoding="utf-8") as source:
|
||||
values = json.load(source).get("values", [])
|
||||
@@ -101,16 +76,17 @@ def registry_values(root):
|
||||
return good
|
||||
|
||||
|
||||
def expand(store, ids):
|
||||
"""The picks with everything they bundle, each once, a bundle's parts before it."""
|
||||
def expand(store, ids, saved=None):
|
||||
out, seen = [], set()
|
||||
saved = saved if isinstance(saved, dict) else {}
|
||||
|
||||
def visit(cid, depth):
|
||||
if cid in seen or depth > 8:
|
||||
return
|
||||
seen.add(cid)
|
||||
found = component(store, cid)
|
||||
for dep in (found[2] if found else []):
|
||||
parts = found[2] if found else [d for d in saved.get(cid, []) if valid_id(d)]
|
||||
for dep in parts:
|
||||
visit(dep, depth + 1)
|
||||
out.append(cid)
|
||||
|
||||
@@ -120,7 +96,6 @@ def expand(store, ids):
|
||||
|
||||
|
||||
def spelled(path):
|
||||
"""path with each folder that exists spelled as the prefix spells it (Windows names ignore case)."""
|
||||
parts = path.parts
|
||||
current = Path(parts[0])
|
||||
for part in parts[1:]:
|
||||
@@ -139,7 +114,6 @@ def spelled(path):
|
||||
|
||||
|
||||
def existing(path):
|
||||
"""The file at path as the prefix spells it: Windows names ignore case, the filesystem may not."""
|
||||
folder = spelled(path.parent)
|
||||
path = folder / path.name
|
||||
try:
|
||||
@@ -163,7 +137,6 @@ def same(src, dst):
|
||||
|
||||
|
||||
def builtin(path):
|
||||
"""Proton's own: a symlink into its files, or a Wine DLL that says so in its DOS stub."""
|
||||
if path.is_symlink():
|
||||
return True
|
||||
try:
|
||||
@@ -175,7 +148,6 @@ def builtin(path):
|
||||
|
||||
|
||||
def place(src, target, backup=None):
|
||||
"""Copies src over target unless it is already there; a file of someone else's goes to backup first."""
|
||||
target = spelled(target.parent) / target.name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
found = existing(target)
|
||||
@@ -193,7 +165,6 @@ def place(src, target, backup=None):
|
||||
|
||||
|
||||
def reg_escape(text, extra=""):
|
||||
"""A string as Wine's registry files write it."""
|
||||
out = []
|
||||
for ch in text:
|
||||
if ch == "\\" or ch == '"' or ch in extra:
|
||||
@@ -238,7 +209,6 @@ def reg_key_line(key):
|
||||
|
||||
|
||||
def reg_value_line(name, kind, data):
|
||||
"""name=data as one registry file line; None for a kind that has no line of its own."""
|
||||
head = "@" if name == "" else '"%s"' % reg_escape(name)
|
||||
if kind == "sz":
|
||||
return '%s="%s"' % (head, reg_escape(str(data)))
|
||||
@@ -256,13 +226,11 @@ def reg_value_line(name, kind, data):
|
||||
|
||||
|
||||
def reg_string(line):
|
||||
"""The text of a string value line (plain or str(2)), or None for any other kind."""
|
||||
match = re.match(r'^(?:@|"(?:[^"\\]|\\.)*")=(?:str\(2\):)?"((?:[^"\\]|\\.)*)"\s*$', line)
|
||||
return reg_unescape(match.group(1)) if match else None
|
||||
|
||||
|
||||
class RegistryFile:
|
||||
"""One of a prefix's registry files, as Wine keeps them: [key] sections of name=value lines."""
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = Path(path)
|
||||
@@ -289,7 +257,6 @@ class RegistryFile:
|
||||
self.links[current.lower()] = target
|
||||
|
||||
def link_target(self, number, root):
|
||||
"""Where the link key whose "#link" line is at number leads, relative to this file's root."""
|
||||
for at in range(number + 1, min(number + 8, len(self.lines))):
|
||||
line = self.lines[at]
|
||||
if line.startswith("["):
|
||||
@@ -310,7 +277,6 @@ class RegistryFile:
|
||||
return None
|
||||
|
||||
def resolve(self, key):
|
||||
"""The key Wine really keeps key in: a path through a link key leads to the link's target."""
|
||||
key = key.strip("\\")
|
||||
for _ in range(8):
|
||||
lower = key.lower()
|
||||
@@ -336,7 +302,6 @@ class RegistryFile:
|
||||
return None if end is None else reg_unescape(line[1:end])
|
||||
|
||||
def section(self, key):
|
||||
"""(start, end) line numbers of the key's values, or None."""
|
||||
start = self.index.get(self.resolve(key).lower())
|
||||
if start is None:
|
||||
return None
|
||||
@@ -353,7 +318,6 @@ class RegistryFile:
|
||||
return reg_unescape(match.group(1)).lower() if match else None
|
||||
|
||||
def find(self, key, name):
|
||||
"""(first, last + 1) of the value's lines, or None."""
|
||||
span = self.section(key)
|
||||
if span is None:
|
||||
return None
|
||||
@@ -387,7 +351,6 @@ class RegistryFile:
|
||||
self.changed = True
|
||||
|
||||
def put(self, key, name, raw):
|
||||
"""Sets the value's line(s) to raw, or removes the value when raw is None; True if that changed it."""
|
||||
found = self.find(key, name)
|
||||
if raw is None:
|
||||
if found is None:
|
||||
@@ -430,8 +393,6 @@ class RegistryFile:
|
||||
|
||||
|
||||
def list_line(name, current, item, separator, add, at_end=True):
|
||||
"""current (a string value line) with item added to or taken out of its list, None if it had
|
||||
nothing else; a value that is not a string is left as it is."""
|
||||
text = reg_string(current) if current is not None else ""
|
||||
if text is None:
|
||||
return current
|
||||
@@ -444,10 +405,7 @@ def list_line(name, current, item, separator, add, at_end=True):
|
||||
return reg_value_line(name, "expand_sz" if expand else "sz", separator.join(items))
|
||||
|
||||
|
||||
def apply_registry(pfx, values, state):
|
||||
"""Writes the picked components' registry values into the prefix and takes out the ones of
|
||||
components turned off: a value goes back to what it was before, an entry added to a list such
|
||||
as PATH just leaves the list. Returns (values written, notes)."""
|
||||
def apply_registry(pfx, values, state, held=()):
|
||||
files = {}
|
||||
for hive, name in HIVES.items():
|
||||
if (pfx / name).is_file():
|
||||
@@ -478,6 +436,9 @@ def apply_registry(pfx, values, state):
|
||||
for ident, record in old.items():
|
||||
if ident in keep or not isinstance(record, dict) or not isinstance(record.get("key"), str):
|
||||
continue
|
||||
if record.get("cid") in held:
|
||||
keep[ident] = record
|
||||
continue
|
||||
reg = files.get(record.get("hive"))
|
||||
if reg is None:
|
||||
keep[ident] = record
|
||||
@@ -513,7 +474,6 @@ def save_state(compat, state):
|
||||
|
||||
|
||||
def pending_for(app_id, pending=PENDING):
|
||||
"""The component ids the app is still getting ready for app_id; empty when none (or no file)."""
|
||||
try:
|
||||
with open(pending, encoding="utf-8") as source:
|
||||
ids = json.load(source).get("games", {}).get(str(app_id), [])
|
||||
@@ -523,9 +483,6 @@ def pending_for(app_id, pending=PENDING):
|
||||
|
||||
|
||||
def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT, sleep=time.sleep, clock=time.monotonic):
|
||||
"""Waits (at most timeout seconds) for the components still being got ready for app_id to be in
|
||||
the store or dropped from the pending list. No wait at all when nothing is pending. Returns a
|
||||
note for the log, or None."""
|
||||
def missing():
|
||||
return [cid for cid in pending_for(app_id, pending) if component(store, cid) is None]
|
||||
left = missing()
|
||||
@@ -543,7 +500,6 @@ def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT,
|
||||
|
||||
|
||||
def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING, wait=wait_for_pending):
|
||||
"""Brings the prefix in line with the game's picks. Returns (overrides, notes)."""
|
||||
compat = Path(compat_path)
|
||||
pfx = compat / "pfx"
|
||||
waited = wait(app_id, pending, store) if wait else None
|
||||
@@ -555,14 +511,44 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
copied = 0
|
||||
installed = []
|
||||
values = []
|
||||
for cid in expand(store, ids):
|
||||
held = set()
|
||||
saved_overrides = state.get("overrides") if isinstance(state.get("overrides"), dict) else {}
|
||||
saved_requires = state.get("requires") if isinstance(state.get("requires"), dict) else {}
|
||||
recorded = [c for c in state.get("components", []) if isinstance(c, str) and valid_id(c)]
|
||||
owners = set(state["files"].values())
|
||||
registry_owners = {r.get("cid") for r in (state.get("registry") or {}).values() if isinstance(r, dict)}
|
||||
inferred = set()
|
||||
guessed = set(state.get("guessed") or []) if "requires" in state else set(ids)
|
||||
loose = [c for c in recorded if c not in ids and (c in owners or c in registry_owners)]
|
||||
for cid in ids:
|
||||
if cid in guessed and component(store, cid) is None and cid in recorded:
|
||||
saved_requires = dict(saved_requires, **{cid: loose})
|
||||
inferred.add(cid)
|
||||
kept_overrides, kept_requires = {}, {}
|
||||
for cid in expand(store, ids, saved_requires):
|
||||
found = component(store, cid)
|
||||
if found is None:
|
||||
notes.append("%s is not installed; skipped" % cid)
|
||||
if cid in saved_requires or cid in recorded or cid in owners or cid in registry_owners:
|
||||
held.add(cid)
|
||||
if cid in saved_overrides:
|
||||
names = [n for n in saved_overrides.get(cid, []) if isinstance(n, str)]
|
||||
else:
|
||||
names = sorted({Path(rel).stem.lower() for rel, owner in state["files"].items()
|
||||
if owner == cid and rel.lower().endswith(".dll")})
|
||||
overrides += names
|
||||
kept_overrides[cid] = names
|
||||
if isinstance(saved_requires.get(cid), list) and cid not in inferred:
|
||||
kept_requires[cid] = saved_requires[cid]
|
||||
notes.append("%s is not in the store; kept the files it placed until it is installed again" % cid)
|
||||
else:
|
||||
notes.append("%s is not installed; skipped" % cid)
|
||||
continue
|
||||
installed.append(cid)
|
||||
names, files, _, registry = found
|
||||
names, files, requires, registry = found
|
||||
overrides += names
|
||||
kept_overrides[cid] = list(names)
|
||||
if requires:
|
||||
kept_requires[cid] = list(requires)
|
||||
values += [(cid, value) for value in registry]
|
||||
for rel, src in files:
|
||||
if place(src, pfx / rel, None if rel in state["files"] else compat / BACKUP / rel):
|
||||
@@ -572,6 +558,9 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
for rel, cid in state["files"].items():
|
||||
if rel in keep:
|
||||
continue
|
||||
if cid in held:
|
||||
keep[rel] = cid
|
||||
continue
|
||||
path = existing(pfx / rel)
|
||||
saved = compat / BACKUP / rel
|
||||
if saved.is_file():
|
||||
@@ -587,10 +576,13 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
compat.mkdir(parents=True, exist_ok=True)
|
||||
new_state = {"files": keep, "components": installed, "registry": state.get("registry", {})}
|
||||
new_state = {"files": keep, "components": installed + sorted(held), "overrides": kept_overrides,
|
||||
"requires": kept_requires, "registry": state.get("registry", {})}
|
||||
if inferred:
|
||||
new_state["guessed"] = sorted(inferred)
|
||||
written = 0
|
||||
if values or new_state["registry"]:
|
||||
written, registry_notes = apply_registry(pfx, values, new_state)
|
||||
written, registry_notes = apply_registry(pfx, values, new_state, held)
|
||||
notes += registry_notes
|
||||
save_state(compat, new_state)
|
||||
if copied or removed or restored or written:
|
||||
@@ -601,7 +593,6 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
|
||||
|
||||
def overrides_value(names):
|
||||
"""WINEDLLOVERRIDES entries: native-then-builtin unless the component says otherwise; the last word on a DLL wins."""
|
||||
modes = {}
|
||||
for entry in names:
|
||||
name, _, mode = entry.partition("=")
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#!/bin/bash
|
||||
# Runs natively: droiddeck-steam-x64's x86 wrappers start it through an arm64 binary, which FEX hands to the CPU.
|
||||
tool=$1; shift
|
||||
x64_home=$HOME
|
||||
|
||||
# The game overlay tags the game's windows with the Steam app ID; without it gamescope never shows them.
|
||||
overlay=0
|
||||
case ${LD_PRELOAD:-} in *gameoverlayrenderer.so*) overlay=1 ;; esac
|
||||
|
||||
@@ -20,7 +18,6 @@ else
|
||||
export HOME=/root
|
||||
fi
|
||||
[ -z "$game_display" ] || export DISPLAY=$game_display
|
||||
# Proton takes its Steam client parts from the client's install folder; the x86-64 client's are x86.
|
||||
export BL_X64_STEAM_ROOT=${STEAM_COMPAT_CLIENT_INSTALL_PATH:-}
|
||||
export STEAM_COMPAT_CLIENT_INSTALL_PATH=$HOME/.local/share/Steam
|
||||
arm_overlay=$STEAM_COMPAT_CLIENT_INSTALL_PATH/steamrtarm64/gameoverlayrenderer.so
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
# The arm64 client's web helper for the x86-64 client, run natively: FEX hands this arm64 program to the CPU.
|
||||
x64_home=$HOME
|
||||
arm=/root/.local/share/Steam/steamrtarm64
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Steam's compositor draws each browser window from its X pixmap: frames must reach X, not gamescope's WSI layer.
|
||||
# gamescope sets vk_xwayland_wait_ready=false for its children; kopper swapchains flashed black even with the wait.
|
||||
unset BL_X64_ARM_WEBHELPER
|
||||
# The shim already added the GPU flags (preload/webhelper.c) to these arguments.
|
||||
export BL_WEBHELPER_ARGS=stock DISABLE_GAMESCOPE_WSI=1 vk_xwayland_wait_ready=true LIBGL_KOPPER_DISABLE=true
|
||||
if [ -x ./steamwebhelper ]; then
|
||||
exec ./steamwebhelper "$@"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
"""Licensed Xbox launches through Xodus and the game's selected ARM64 Proton."""
|
||||
import hmac
|
||||
import json
|
||||
import os
|
||||
@@ -15,7 +14,19 @@ import threading
|
||||
|
||||
BIN = Path(__file__).resolve().parent
|
||||
RUNTIME = Path('/usr/local/lib/droiddeck-xbox')
|
||||
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'libnghttp2.dll')
|
||||
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'wintypes.dll', 'libnghttp2.dll')
|
||||
CLASSES = {
|
||||
'twinapi.appcore.dll': ('Windows.ApplicationModel.DataTransfer.DataTransferManager',
|
||||
'Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation',
|
||||
'Windows.System.Profile.AnalyticsInfo', 'Windows.System.UserProfile.AdvertisingManager',
|
||||
'Windows.UI.ViewManagement.ApplicationView'),
|
||||
'windows.web.dll': ('Windows.Data.Json.JsonArray', 'Windows.Data.Json.JsonObject', 'Windows.Data.Json.JsonValue'),
|
||||
'wintypes.dll': ('Windows.Foundation.PropertyValue', 'Windows.Foundation.Collections.PropertySet',
|
||||
'Windows.Foundation.Metadata.ApiInformation', 'Windows.Storage.Streams.Buffer',
|
||||
'Windows.Storage.Streams.DataWriter'),
|
||||
}
|
||||
CLASS_KEY = 'Software\\Microsoft\\WindowsRuntime\\ActivatableClassId\\'
|
||||
VIEW_DRIVES = 'xwvutsrqponmlkjihgfe'
|
||||
|
||||
|
||||
def bridge(upstream):
|
||||
@@ -102,6 +113,53 @@ def bridge(upstream):
|
||||
return server.getsockname()[1], key.decode('ascii'), close
|
||||
|
||||
|
||||
def register_classes(proton, prefix, env):
|
||||
try:
|
||||
registry = (prefix / 'system.reg').read_text(encoding='utf-8', errors='replace')
|
||||
except OSError:
|
||||
return
|
||||
missing = [(name, dll) for dll, names in CLASSES.items() for name in names
|
||||
if '[%s]' % (CLASS_KEY + name).replace('\\', '\\\\') not in registry]
|
||||
if not missing:
|
||||
return
|
||||
text = 'Windows Registry Editor Version 5.00\r\n\r\n' + ''.join(
|
||||
'[HKEY_LOCAL_MACHINE\\%s%s]\r\n"DllPath"="C:\\\\windows\\\\system32\\\\%s"\r\n\r\n' % (CLASS_KEY, name, dll)
|
||||
for name, dll in missing)
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-xbox-') as temporary:
|
||||
source = Path(temporary) / 'classes.reg'
|
||||
source.write_bytes(b'\xff\xfe' + text.encode('utf-16-le'))
|
||||
try:
|
||||
failed = subprocess.run([proton, 'run', 'reg.exe', 'import', 'Z:' + str(source).replace('/', '\\')],
|
||||
stdout=sys.stderr, env=env, timeout=90).returncode != 0
|
||||
except subprocess.TimeoutExpired:
|
||||
failed = True
|
||||
if failed:
|
||||
print('droiddeck-xbox: Windows Runtime class registration failed; launching without it', file=sys.stderr)
|
||||
|
||||
|
||||
def view_drive(prefix, exe):
|
||||
path = Path(exe)
|
||||
view = next((parent for parent in path.parents if parent.name.startswith('droiddeck-xbox-')), None)
|
||||
if not path.is_absolute() or view is None:
|
||||
return exe, None
|
||||
devices = prefix / 'dosdevices'
|
||||
for letter in VIEW_DRIVES:
|
||||
link = devices / (letter + ':')
|
||||
staged = devices / ('.%s-%s' % (letter, secrets.token_hex(4)))
|
||||
try:
|
||||
if os.path.lexists(link) and (os.path.exists(link) or not os.readlink(link).startswith(str(view.parent.parent) + '/')):
|
||||
continue
|
||||
devices.mkdir(parents=True, exist_ok=True)
|
||||
staged.symlink_to(view.parent)
|
||||
os.replace(staged, link)
|
||||
except OSError:
|
||||
if os.path.lexists(staged):
|
||||
staged.unlink()
|
||||
continue
|
||||
return letter.upper() + ':\\' + str(path.relative_to(view.parent)).replace('/', '\\'), link
|
||||
return exe, None
|
||||
|
||||
|
||||
def wine(argv, source_env=None):
|
||||
source_env = os.environ if source_env is None else source_env
|
||||
with open(source_env['DROIDDECK_XBOX_COMMAND_FILE'], encoding='utf-8') as file:
|
||||
@@ -109,7 +167,8 @@ def wine(argv, source_env=None):
|
||||
if len(command) < 3 or command[1] != 'waitforexitandrun' or len(argv) != 1:
|
||||
raise ValueError('Invalid Xbox Proton invocation')
|
||||
env = dict(source_env)
|
||||
env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
|
||||
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
|
||||
env.pop(name, None)
|
||||
env.pop('DROIDDECK_XBOX_COMMAND_FILE', None)
|
||||
prefix = Path(source_env['STEAM_COMPAT_DATA_PATH']) / 'pfx'
|
||||
prefix.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -124,9 +183,18 @@ def wine(argv, source_env=None):
|
||||
if target.is_symlink():
|
||||
target.unlink()
|
||||
shutil.copyfile(RUNTIME / 'windows' / name, target)
|
||||
register_classes(command[0], prefix, env)
|
||||
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
|
||||
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
|
||||
return subprocess.call([*command[:2], argv[0], *command[3:]], env=env)
|
||||
exe, drive = view_drive(prefix, argv[0])
|
||||
try:
|
||||
return subprocess.call([*command[:2], exe, *command[3:]], env=env)
|
||||
finally:
|
||||
if drive is not None:
|
||||
try:
|
||||
drive.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def renew_lease(ask, channel, product, lease, stopped):
|
||||
@@ -171,7 +239,8 @@ def launch(command, env):
|
||||
owned_env = dict(env, DROIDDECK_XBOX_ACTIVE='1', DROIDDECK_XBOX_COMMAND_FILE=str(context),
|
||||
XODUS_SOCKET=reply['socket'], XODUS_BRIDGE_PORT=str(port), XODUS_BRIDGE_KEY=key,
|
||||
XODUS_LOG='off', RUST_LOG='off', XODUS_SAVE_SYNC='auto' if sidecar.get('cloud', True) else 'off')
|
||||
owned_env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
|
||||
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
|
||||
owned_env.pop(name, None)
|
||||
if reply.get('playfab'):
|
||||
owned_env['XODUS_XSTS_PLAYFAB'] = reply['playfab']
|
||||
content = folder / '.xbox-content'
|
||||
|
||||
@@ -69,7 +69,10 @@ bl_store_launch() {
|
||||
fi
|
||||
[ -x /usr/local/bin/droiddeck-store-launch ] || return 0
|
||||
/usr/local/bin/droiddeck-store-launch "$@"
|
||||
[ $? -eq 10 ] && BL_STORE_EXIT=1
|
||||
rc=$?
|
||||
[ $rc -eq 10 ] && BL_STORE_EXIT=1
|
||||
[ $rc -eq 11 ] && exit 0
|
||||
[ $rc -eq 12 ] && exit 1
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -87,6 +90,34 @@ bl_run() {
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DESKTOP_GPU_SETUP = """
|
||||
bl_desktop_gpu() {
|
||||
local name saved gpu=/usr/local/bin/droiddeck-gpu
|
||||
local names=(LD_PRELOAD LD_LIBRARY_PATH ENABLE_VK_LAYER_VALVE_steam_overlay_1 ENABLE_VK_LAYER_VALVE_steam_fossilize_1)
|
||||
if [ -n "${BL_DESKTOP_GPU_CHILD:-}" ]; then
|
||||
for name in "${names[@]}"; do
|
||||
saved=BL_GPU_SAVED_$name
|
||||
[ -n "${!saved+x}" ] || continue
|
||||
export "$name=${!saved}"
|
||||
unset "$saved"
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
[ "${BL_DESKTOP:-}" = 1 ] && [ "${verb:-}" = waitforexitandrun ] && [ -x "$gpu" ] || return 0
|
||||
local choice=${BL_DESKTOP_GPU:-on}
|
||||
case "${choice,,}" in off | 0 | no | false) return 0 ;; esac
|
||||
case " $* " in *iscriptevaluator*) return 0 ;; esac
|
||||
local clear=()
|
||||
for name in "${names[@]}"; do
|
||||
[ -n "${!name+x}" ] || continue
|
||||
export "BL_GPU_SAVED_$name=${!name}"
|
||||
clear+=(-u "$name")
|
||||
done
|
||||
echo "droiddeck-gpu: the desktop starts this game on the GPU" >&2
|
||||
exec env "${clear[@]}" "$gpu" "$0" "$verb" "$@"
|
||||
}
|
||||
bl_desktop_gpu "$@"
|
||||
"""
|
||||
BL_COMPONENTS_SETUP = """
|
||||
bl_components() {
|
||||
base=$1
|
||||
@@ -217,8 +248,6 @@ bl_idtech3() {
|
||||
}
|
||||
"""
|
||||
|
||||
# Source games report VAC-secure or insecure only in their console, written to console.log only with -condebug.
|
||||
# The app keeps the switch and the records in /root: the x86-64 client runs games with its own HOME.
|
||||
BL_VACDIAG_SETUP = """
|
||||
bl_vacdiag() {
|
||||
[ -f /root/.droiddeck-vac-diagnostics ] || return 0
|
||||
@@ -245,6 +274,14 @@ bl_vacdiag() {
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DRIVER_QUERY_SKIP = """
|
||||
case "$verb:${1##*/}:${STEAM_COMPAT_DATA_PATH%/}" in
|
||||
run:d3ddriverquery64.exe:*/compatdata/0 | run:d3ddriverquery.exe:*/compatdata/0)
|
||||
echo "droiddeck-proton: Steam's D3D driver query is not run (it fails here and would start Wine in compatdata/0)" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
"""
|
||||
|
||||
BL_DIRECTAUDIO_SETUP = """
|
||||
bl_is_steam_installscript_target() {
|
||||
local target=${1:-}
|
||||
@@ -292,6 +329,11 @@ bl_directaudio() {
|
||||
fi
|
||||
WINEDLLPATH="$da/lib/wine${WINEDLLPATH:+:$WINEDLLPATH}"
|
||||
export WINEDLLPATH
|
||||
for name in $(compgen -e); do
|
||||
case $name in
|
||||
AUDIO_DIRECT_*) export "BANNER_$name=${!name}" ;;
|
||||
esac
|
||||
done
|
||||
WINE_AUDIO_DRIVER="directaudio,pulse"
|
||||
export WINE_AUDIO_DRIVER
|
||||
pfx="${STEAM_COMPAT_DATA_PATH:-}/pfx"
|
||||
@@ -377,7 +419,7 @@ LAUNCHER_TEMPLATE = LAUNCHER_SH
|
||||
|
||||
def launcher_sh(sources=SOURCES):
|
||||
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DRIVER_QUERY_SKIP + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
@@ -424,6 +466,15 @@ bl_store_launch "$@"
|
||||
BL_STORE_ARGS=("$@")
|
||||
bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$BL_STORE_PROTON" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
|
||||
"""
|
||||
|
||||
|
||||
def extra_wrapper_sh(entry_point):
|
||||
return (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DRIVER_QUERY_SKIP + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP
|
||||
+ BL_IDTECH3_SETUP + BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
EXTRA_COMPAT_TOOL_VDF = """"compatibilitytools"
|
||||
{
|
||||
"compat_tools"
|
||||
@@ -466,7 +517,7 @@ verb=$1; shift
|
||||
case $verb in
|
||||
getcompatpath | getnativepath) printf '%s\\n' "$1"; exit 0 ;;
|
||||
esac
|
||||
""" + BL_GAME_CPUS_SETUP + """
|
||||
""" + BL_DESKTOP_GPU_SETUP + BL_GAME_CPUS_SETUP + """
|
||||
bl_game_cpus
|
||||
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
|
||||
exec /usr/local/bin/droiddeck-steamvr-game ${BL_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
|
||||
@@ -494,7 +545,6 @@ def tokenize(text):
|
||||
|
||||
|
||||
def find_block(tokens, path):
|
||||
"""Index of the '{' opening the block at path, or None."""
|
||||
depth, want, i = 0, 0, 0
|
||||
while i < len(tokens):
|
||||
t = tokens[i]
|
||||
@@ -545,10 +595,6 @@ def serialize(tokens):
|
||||
|
||||
|
||||
def write_changed(path, text, mode=None):
|
||||
"""Writes `text` to `path` only when it differs, through a rename so a reader never sees half a
|
||||
file. The session runs this script every 15 s for as long as the client does; rewriting files
|
||||
that have not changed cost a python start's worth of writes each time, and config.vdf is the
|
||||
client's own, which it may be writing at that moment. Returns whether anything was written."""
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
same = f.read() == text
|
||||
@@ -576,8 +622,6 @@ def display_name(base):
|
||||
|
||||
|
||||
def first_key(path, section):
|
||||
"""The single key naming a block inside `section`, or None. Used to keep a third-party tool's
|
||||
own internal name, so a mapping the user already made against it keeps working."""
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
tokens = tokenize(f.read())
|
||||
@@ -595,7 +639,6 @@ def first_key(path, section):
|
||||
|
||||
|
||||
def manifest_entry_point(path):
|
||||
"""The script a toolmanifest's commandline runs, relative to the tool directory."""
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
tokens = tokenize(f.read())
|
||||
@@ -610,9 +653,6 @@ def manifest_entry_point(path):
|
||||
|
||||
|
||||
def adopt_extras(tools):
|
||||
"""Makes every other Proton in compatibilitytools.d launchable here, and returns the tool names
|
||||
to leave alone in CompatToolMapping - the whole point of installing one is to pick it per game,
|
||||
so register_default must not repoint it back at ours."""
|
||||
adopted = {}
|
||||
try:
|
||||
entries = sorted(os.listdir(tools))
|
||||
@@ -647,11 +687,7 @@ def adopt_extras(tools):
|
||||
name = first_key(compat_vdf, ["compatibilitytools", "compat_tools"]) or entry
|
||||
wrapper = os.path.join(tool_dir, EXTRA_WRAPPER)
|
||||
try:
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
write_changed(wrapper, body, 0o755)
|
||||
write_changed(wrapper, extra_wrapper_sh(entry_point), 0o755)
|
||||
write_changed(manifest, EXTRA_MANIFEST_VDF)
|
||||
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, display_name(entry)))
|
||||
legacy_wrapper = os.path.join(tool_dir, LEGACY_EXTRA_WRAPPER)
|
||||
@@ -690,7 +726,6 @@ def libraries(steam_root):
|
||||
|
||||
|
||||
def installed_apps(steam_root):
|
||||
"""App ids of the titles the client has installed, tools and runtimes excluded."""
|
||||
apps = set()
|
||||
for library in libraries(steam_root):
|
||||
steamapps = os.path.join(library, "steamapps")
|
||||
@@ -710,7 +745,6 @@ STEAM_PLAY_MANIFESTS = 891390
|
||||
|
||||
|
||||
def launch_programs(config):
|
||||
"""The Windows and Linux programs an app's launch options start, relative to its folder (lowercase, "/")."""
|
||||
launch = config.get("launch") if isinstance(config, dict) else None
|
||||
found = []
|
||||
for option in launch.values() if isinstance(launch, dict) else ():
|
||||
@@ -725,7 +759,6 @@ def launch_programs(config):
|
||||
|
||||
|
||||
def launch_options(config):
|
||||
"""An app's launch options as Steam lists them: executable, arguments, working folder, type and oslist."""
|
||||
launch = config.get("launch") if isinstance(config, dict) else None
|
||||
found = []
|
||||
for key, option in launch.items() if isinstance(launch, dict) else ():
|
||||
@@ -903,7 +936,6 @@ def manifest_flags(tokens):
|
||||
|
||||
|
||||
def tool_downloads(steam_root):
|
||||
"""(app, "install" or "update") for each tool the client has yet to install or bring up to date."""
|
||||
wanted = []
|
||||
for app in REQUIRED_TOOLS:
|
||||
tokens = app_manifest(steam_root, app)
|
||||
@@ -1113,14 +1145,92 @@ def requested_tool(request, catalog):
|
||||
|
||||
|
||||
def game_requests(directory=None):
|
||||
value = read_json(state_path("games.json", directory))
|
||||
if value.get("version") != 1 or not isinstance(value.get("games"), dict):
|
||||
return {}
|
||||
return value["games"]
|
||||
return read_game_requests(directory)[0]
|
||||
|
||||
|
||||
def read_game_requests(directory=None):
|
||||
try:
|
||||
with open(state_path("games.json", directory), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
value = json.loads(text)
|
||||
except (OSError, ValueError):
|
||||
return {}, None
|
||||
if not isinstance(value, dict) or value.get("version") != 1 or not isinstance(value.get("games"), dict):
|
||||
return {}, text
|
||||
return value["games"], text
|
||||
|
||||
|
||||
def write_game_requests(requests, original, directory=None):
|
||||
path = state_path("games.json", directory)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
if f.read() != original:
|
||||
return False
|
||||
except OSError:
|
||||
if original is not None:
|
||||
return False
|
||||
return write_json(path, {"version": 1, "games": requests})
|
||||
|
||||
|
||||
def valid_game_request(app, request):
|
||||
return (isinstance(app, str) and re.fullmatch(r"[1-9][0-9]*", app) is not None and int(app) <= 0xFFFFFFFF and
|
||||
(request is None or isinstance(request, dict) and isinstance(request.get("dir"), str) and
|
||||
request["dir"] != "" and isinstance(request.get("valve"), bool)))
|
||||
|
||||
|
||||
def settle_game_requests(requests, state, current, catalog, missing_is_cleared=False):
|
||||
recorded = state.get("games_applied")
|
||||
if isinstance(recorded, dict):
|
||||
applied = dict(recorded)
|
||||
else:
|
||||
applied = dict(requests) if "tools" in state else {}
|
||||
by_name = {t["name"]: t for t in catalog}
|
||||
out = dict(requests)
|
||||
for app, request in requests.items():
|
||||
if not valid_game_request(app, request) or app not in applied or applied[app] != request:
|
||||
continue
|
||||
if request is None:
|
||||
del out[app]
|
||||
continue
|
||||
wanted = requested_tool(request, catalog)
|
||||
if wanted is None:
|
||||
continue
|
||||
if app in current:
|
||||
picked = current[app]
|
||||
elif missing_is_cleared:
|
||||
picked = ""
|
||||
else:
|
||||
continue
|
||||
if picked == wanted:
|
||||
continue
|
||||
tool = by_name.get(picked)
|
||||
if tool and tool["dir"]:
|
||||
out[app] = {"valve": tool["valve"], "dir": tool["dir"]}
|
||||
else:
|
||||
del out[app]
|
||||
return out, out != requests
|
||||
|
||||
|
||||
def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
|
||||
for _ in range(2):
|
||||
requests, text = read_game_requests(directory)
|
||||
settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
|
||||
if not moved or write_game_requests(settled, text, directory):
|
||||
return settled
|
||||
return None
|
||||
|
||||
|
||||
def applied_game_requests(requests, overrides, state):
|
||||
recorded = state.get("games_applied")
|
||||
before = recorded if isinstance(recorded, dict) else {}
|
||||
if requests is None:
|
||||
return dict(before)
|
||||
return {app: request if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL else before[app]
|
||||
for app, request in requests.items()
|
||||
if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL or app in before}
|
||||
|
||||
|
||||
def requested_games(requests, catalog, runnable=None):
|
||||
"""App id -> requested tool, None for inherit, or DEFERRED_GAME_TOOL while unavailable."""
|
||||
runnable = None if runnable is None else set(runnable)
|
||||
resolved = {}
|
||||
for app, request in requests.items():
|
||||
@@ -1140,6 +1250,32 @@ def requested_games(requests, catalog, runnable=None):
|
||||
return resolved
|
||||
|
||||
|
||||
OWN_PROTON = "DroidDeck-Proton"
|
||||
ARCH_WORDS = re.compile(r"(?i)aarch64|arm64|x86_64|x86-64|amd64")
|
||||
|
||||
|
||||
def own_builds(tools):
|
||||
return [t for t in tools if isinstance(t, dict) and not t.get("valve") and
|
||||
isinstance(t.get("dir"), str) and t["dir"].startswith(OWN_PROTON) and t.get("name")]
|
||||
|
||||
|
||||
def build_key(name):
|
||||
return [int(n) for n in re.findall(r"\d+", ARCH_WORDS.sub(" ", name))]
|
||||
|
||||
|
||||
def own_proton_moves(state, catalog):
|
||||
names = {t["name"] for t in catalog}
|
||||
before = state.get("tools") if isinstance(state.get("tools"), list) else ()
|
||||
seen = state.get("own_builds") if isinstance(state.get("own_builds"), list) else []
|
||||
known = {n for n in seen if isinstance(n, str)} | {t["name"] for t in own_builds(before)} | {t["name"] for t in own_builds(catalog)}
|
||||
state["own_builds"] = sorted(known)
|
||||
builds = own_builds(catalog)
|
||||
if not builds:
|
||||
return None, set()
|
||||
newest = max(builds, key=lambda t: (build_key(t["dir"]), t["dir"]))["name"]
|
||||
return newest, known - names
|
||||
|
||||
|
||||
def now_ms():
|
||||
import time
|
||||
return int(time.time() * 1000)
|
||||
@@ -1198,7 +1334,6 @@ def read_mapping(tokens, mapping):
|
||||
|
||||
|
||||
def read_config_mapping(config_path):
|
||||
"""Read per-app choices without creating or rewriting the client's mapping block."""
|
||||
try:
|
||||
with open(config_path, encoding="utf-8", errors="replace") as f:
|
||||
tokens = tokenize(f.read())
|
||||
@@ -1284,9 +1419,6 @@ def live_helper_running(directory=None):
|
||||
|
||||
def register_default(config_path, apps=(), protect=(), default=None, catalog=None, directory=None, settle=False, picks=(),
|
||||
linux_tool=FEX_TOOL):
|
||||
"""Writes the mapping: the "0" default and every title that follows it (see plan_mapping).
|
||||
With settle, the default itself is decided first (see choose_default): before the client
|
||||
starts, config.vdf holds what the client last kept, menu changes included."""
|
||||
with locked(directory):
|
||||
state = read_json(state_path("state.json", directory))
|
||||
with open(config_path, encoding="utf-8", errors="replace") as f:
|
||||
@@ -1300,13 +1432,29 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
catalog = tool_catalog(os.path.dirname(os.path.dirname(os.path.abspath(config_path))),
|
||||
dict(protect) if isinstance(protect, dict) else {name: name for name in protect})
|
||||
names = [t["name"] for t in catalog]
|
||||
newest, gone = own_proton_moves(state, catalog)
|
||||
previous, applied, chosen = state.get("default"), state.get("applied"), state.get("seq")
|
||||
if default is None:
|
||||
if settle:
|
||||
default, state = choose_default(current.get("0", ""), state, read_json(state_path("request.json", directory)), catalog)
|
||||
else:
|
||||
default = state.get("default") if state.get("default") in names else TOOL
|
||||
if settle and newest and default == TOOL and state.get("applied") == applied and state.get("seq") == chosen and (
|
||||
previous in gone or not state.get("own_proton")):
|
||||
default = newest
|
||||
state.update(default=newest, seq=now_ms(), source="update")
|
||||
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
|
||||
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)))
|
||||
overrides = requested_games(game_requests(directory), catalog)
|
||||
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
|
||||
overrides = requested_games(requests or {}, catalog)
|
||||
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
|
||||
native_choices = state.get("native_choices", ())
|
||||
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
|
||||
@@ -1325,6 +1473,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
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["games_applied"] = applied_game_requests(requests, overrides, state)
|
||||
state.pop("native", None)
|
||||
state["tools"] = catalog
|
||||
state.setdefault("default", default)
|
||||
@@ -1333,7 +1482,6 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
|
||||
|
||||
def depot_build(depot):
|
||||
"""The build number a depot's version file starts with; 0 when there is none."""
|
||||
try:
|
||||
with open(os.path.join(depot, "version"), encoding="utf-8", errors="replace") as f:
|
||||
first = f.read().split(None, 1)
|
||||
@@ -1343,7 +1491,6 @@ def depot_build(depot):
|
||||
|
||||
|
||||
def find_source(steam_root, sources=SOURCES):
|
||||
"""The first of `sources` the client has downloaded, newest across the libraries holding it."""
|
||||
for name in sources:
|
||||
found = [os.path.join(root, "steamapps", "common", name) for root in libraries(steam_root)
|
||||
if os.path.isdir(os.path.join(root, "steamapps", "common", name, "files", "bin-arm64"))]
|
||||
@@ -1353,7 +1500,6 @@ def find_source(steam_root, sources=SOURCES):
|
||||
|
||||
|
||||
def build_tool(tool_dir, depot, sources=SOURCES, name=TOOL):
|
||||
"""Our own manifests and the launcher, named after `depot`. The depot is run at launch time."""
|
||||
if os.path.islink(tool_dir):
|
||||
os.unlink(tool_dir)
|
||||
elif os.path.isdir(tool_dir) and set(os.listdir(tool_dir)) - set(OWN_FILES):
|
||||
@@ -1382,7 +1528,6 @@ def remove_tool(tool_dir):
|
||||
|
||||
|
||||
def local_tools(steam_root):
|
||||
"""The names of the compatibility tools installed in steam_root/compatibilitytools.d."""
|
||||
names = set()
|
||||
tools = os.path.join(steam_root, "compatibilitytools.d")
|
||||
try:
|
||||
@@ -1401,11 +1546,6 @@ def local_tools(steam_root):
|
||||
|
||||
|
||||
def x64_repoint(steam_root, tool, live=False):
|
||||
"""The x86-64 client (droiddeck-steam-x64): its tools are arm64 wrappers that script makes and
|
||||
its Linux titles run as Linux builds (FEX), so only the entries the client aimed at a Proton it
|
||||
cannot start are repointed, to `tool`. Tools in its own compatibilitytools.d are kept: the
|
||||
wrappers include proton-cachyos-*-a64, which starts with "proton" like Valve's own.
|
||||
Returns the app ids repointed."""
|
||||
config = os.path.join(steam_root, "config", "config.vdf")
|
||||
if not tool or not os.path.isfile(config):
|
||||
return []
|
||||
@@ -1422,7 +1562,6 @@ def x64_repoint(steam_root, tool, live=False):
|
||||
set_mapping(tokens, mapping, "0", tool)
|
||||
for app, name in current.items():
|
||||
named = name.lower()
|
||||
# A tool named arm64 is never this client's (its wrappers are -a64), so this legacy name is always repointed.
|
||||
legacy = named == "droiddeck-proton-arm64"
|
||||
if (named.startswith("proton") or legacy) and named != tool.lower() \
|
||||
and (legacy or named not in keep):
|
||||
@@ -1433,7 +1572,6 @@ def x64_repoint(steam_root, tool, live=False):
|
||||
if text != serialize(tokenize(original)):
|
||||
write_changed(config, text)
|
||||
print("steam-compatibility: x86-64 client's Proton entries point at %s" % tool)
|
||||
# Steam reads a mapping changed while it runs only at its next start; the session restarts it (.bl-compat-pending).
|
||||
if moved and live:
|
||||
with open(os.path.join(os.path.expanduser("~"), ".bl-compat-pending"), "a") as f:
|
||||
f.write("".join("%s\n" % a for a in moved))
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/futex.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__aarch64__) || defined(BL_CLOCK_ANY_ARCH)
|
||||
|
||||
#ifndef CP_CTL
|
||||
#define CP_CTL "/tmp/.bl-clock"
|
||||
#endif
|
||||
#ifndef FUTEX_LOCK_PI2
|
||||
#define FUTEX_LOCK_PI2 13
|
||||
#endif
|
||||
#define CP_FDS 65536
|
||||
|
||||
static const int64_t *cp_shift;
|
||||
static int cp_state;
|
||||
static size_t cp_cond_byte;
|
||||
static unsigned char cp_cond_mask;
|
||||
static unsigned char cp_fds[CP_FDS / 8];
|
||||
|
||||
static int (*cp_gettime)(clockid_t, struct timespec *);
|
||||
static int (*cp_nanosleep)(clockid_t, int, const struct timespec *, struct timespec *);
|
||||
static int (*cp_cond_timedwait)(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
|
||||
static int (*cp_cond_clockwait)(pthread_cond_t *, pthread_mutex_t *, clockid_t, const struct timespec *);
|
||||
static int (*cp_sem_clockwait)(sem_t *, clockid_t, const struct timespec *);
|
||||
static int (*cp_mutex_clocklock)(pthread_mutex_t *, clockid_t, const struct timespec *);
|
||||
static int (*cp_rdlock)(pthread_rwlock_t *, clockid_t, const struct timespec *);
|
||||
static int (*cp_wrlock)(pthread_rwlock_t *, clockid_t, const struct timespec *);
|
||||
static int (*cp_join)(pthread_t, void **, clockid_t, const struct timespec *);
|
||||
static int (*cp_tfd_create)(int, int);
|
||||
static int (*cp_tfd_settime)(int, int, const struct itimerspec *, struct itimerspec *);
|
||||
|
||||
static void *cp_real(const char *name) {
|
||||
return dlsym(RTLD_NEXT, name);
|
||||
}
|
||||
|
||||
#define CP_REAL(var, name) (var ? var : (var = cp_real(name)))
|
||||
|
||||
static int cp_find_cond_bit(void) {
|
||||
pthread_condattr_t attr;
|
||||
pthread_cond_t mono, real;
|
||||
const unsigned char *a = (const unsigned char *)&mono, *b = (const unsigned char *)ℜ
|
||||
int found = 0;
|
||||
memset(&mono, 0, sizeof(mono));
|
||||
memset(&real, 0, sizeof(real));
|
||||
if (pthread_condattr_init(&attr) != 0) return 0;
|
||||
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 && pthread_cond_init(&mono, &attr) == 0) {
|
||||
if (pthread_cond_init(&real, NULL) == 0) {
|
||||
for (size_t i = 0; i < sizeof(pthread_cond_t); i++) {
|
||||
unsigned char diff = a[i] ^ b[i];
|
||||
if (!diff) continue;
|
||||
if (found || (diff & (diff - 1))) {
|
||||
found = -1;
|
||||
break;
|
||||
}
|
||||
cp_cond_byte = i;
|
||||
cp_cond_mask = diff;
|
||||
found = 1;
|
||||
}
|
||||
pthread_cond_destroy(&real);
|
||||
}
|
||||
pthread_cond_destroy(&mono);
|
||||
}
|
||||
pthread_condattr_destroy(&attr);
|
||||
return found == 1;
|
||||
}
|
||||
|
||||
static void cp_init(void) {
|
||||
struct stat st;
|
||||
void *map;
|
||||
int fd;
|
||||
if (strcmp(program_invocation_short_name, "plasmashell") != 0) return;
|
||||
if (!cp_find_cond_bit()) return;
|
||||
fd = open(CP_CTL, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return;
|
||||
if (fstat(fd, &st) != 0 || st.st_size < (off_t)sizeof(int64_t)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
map = mmap(NULL, sizeof(int64_t), PROT_READ, MAP_SHARED, fd, 0);
|
||||
close(fd);
|
||||
if (map != MAP_FAILED) __atomic_store_n(&cp_shift, (const int64_t *)map, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
static int64_t cp_offset(void) {
|
||||
const int64_t *shift;
|
||||
int state = __atomic_load_n(&cp_state, __ATOMIC_ACQUIRE);
|
||||
if (state == 0) {
|
||||
int expected = 0;
|
||||
if (__atomic_compare_exchange_n(&cp_state, &expected, 1, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) {
|
||||
cp_init();
|
||||
__atomic_store_n(&cp_state, 2, __ATOMIC_RELEASE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (state != 2) return 0;
|
||||
shift = __atomic_load_n(&cp_shift, __ATOMIC_ACQUIRE);
|
||||
if (!shift) return 0;
|
||||
int64_t value = __atomic_load_n(shift, __ATOMIC_RELAXED);
|
||||
return value > 0 ? value : 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor)) static void cp_start(void) {
|
||||
cp_offset();
|
||||
}
|
||||
|
||||
static int cp_mono(clockid_t clock) {
|
||||
return clock == CLOCK_MONOTONIC || clock == CLOCK_MONOTONIC_RAW || clock == CLOCK_MONOTONIC_COARSE;
|
||||
}
|
||||
|
||||
static void cp_move(struct timespec *ts, int64_t ns) {
|
||||
int64_t total = (int64_t)ts->tv_nsec + ns % 1000000000LL;
|
||||
ts->tv_sec += (time_t)(ns / 1000000000LL);
|
||||
while (total < 0) {
|
||||
total += 1000000000LL;
|
||||
ts->tv_sec--;
|
||||
}
|
||||
while (total >= 1000000000LL) {
|
||||
total -= 1000000000LL;
|
||||
ts->tv_sec++;
|
||||
}
|
||||
ts->tv_nsec = (long)total;
|
||||
}
|
||||
|
||||
static const struct timespec *cp_later(const struct timespec *ts, struct timespec *out, int64_t shift) {
|
||||
if (!ts || !shift) return ts;
|
||||
*out = *ts;
|
||||
cp_move(out, shift);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void cp_mark(int fd, int mono) {
|
||||
if (fd < 0 || fd >= CP_FDS) return;
|
||||
if (mono) __atomic_or_fetch(&cp_fds[fd / 8], (unsigned char)(1u << (fd % 8)), __ATOMIC_RELAXED);
|
||||
else __atomic_and_fetch(&cp_fds[fd / 8], (unsigned char)~(1u << (fd % 8)), __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static int cp_marked(int fd) {
|
||||
return fd >= 0 && fd < CP_FDS && (__atomic_load_n(&cp_fds[fd / 8], __ATOMIC_RELAXED) & (1u << (fd % 8)));
|
||||
}
|
||||
|
||||
static int cp_cond_mono(const pthread_cond_t *cond) {
|
||||
return (((const volatile unsigned char *)cond)[cp_cond_byte] & cp_cond_mask) != 0;
|
||||
}
|
||||
|
||||
int clock_gettime(clockid_t clock, struct timespec *ts) {
|
||||
if (!CP_REAL(cp_gettime, "clock_gettime")) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
int rc = cp_gettime(clock, ts);
|
||||
if (rc == 0 && cp_mono(clock)) {
|
||||
int64_t shift = cp_offset();
|
||||
if (shift) cp_move(ts, -shift);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int clock_nanosleep(clockid_t clock, int flags, const struct timespec *req, struct timespec *rem) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_nanosleep, "clock_nanosleep")) return ENOSYS;
|
||||
if ((flags & TIMER_ABSTIME) && cp_mono(clock)) req = cp_later(req, &moved, cp_offset());
|
||||
return cp_nanosleep(clock, flags, req, rem);
|
||||
}
|
||||
|
||||
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_cond_timedwait, "pthread_cond_timedwait")) return ENOSYS;
|
||||
int64_t shift = cp_offset();
|
||||
if (shift && cp_cond_mono(cond)) abstime = cp_later(abstime, &moved, shift);
|
||||
return cp_cond_timedwait(cond, mutex, abstime);
|
||||
}
|
||||
|
||||
int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_cond_clockwait, "pthread_cond_clockwait")) return ENOSYS;
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_cond_clockwait(cond, mutex, clock, abstime);
|
||||
}
|
||||
|
||||
int sem_clockwait(sem_t *sem, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_sem_clockwait, "sem_clockwait")) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_sem_clockwait(sem, clock, abstime);
|
||||
}
|
||||
|
||||
int pthread_mutex_clocklock(pthread_mutex_t *mutex, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_mutex_clocklock, "pthread_mutex_clocklock")) return ENOSYS;
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_mutex_clocklock(mutex, clock, abstime);
|
||||
}
|
||||
|
||||
int pthread_rwlock_clockrdlock(pthread_rwlock_t *lock, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_rdlock, "pthread_rwlock_clockrdlock")) return ENOSYS;
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_rdlock(lock, clock, abstime);
|
||||
}
|
||||
|
||||
int pthread_rwlock_clockwrlock(pthread_rwlock_t *lock, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_wrlock, "pthread_rwlock_clockwrlock")) return ENOSYS;
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_wrlock(lock, clock, abstime);
|
||||
}
|
||||
|
||||
int pthread_clockjoin_np(pthread_t thread, void **result, clockid_t clock, const struct timespec *abstime) {
|
||||
struct timespec moved;
|
||||
if (!CP_REAL(cp_join, "pthread_clockjoin_np")) return ENOSYS;
|
||||
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
|
||||
return cp_join(thread, result, clock, abstime);
|
||||
}
|
||||
|
||||
int timerfd_create(int clock, int flags) {
|
||||
if (!CP_REAL(cp_tfd_create, "timerfd_create")) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
int fd = cp_tfd_create(clock, flags);
|
||||
cp_mark(fd, cp_mono(clock));
|
||||
return fd;
|
||||
}
|
||||
|
||||
static const struct itimerspec *cp_timer(int fd, int flags, const struct itimerspec *value, struct itimerspec *out) {
|
||||
int64_t shift;
|
||||
if (!value || !(flags & TFD_TIMER_ABSTIME) || !cp_marked(fd)) return value;
|
||||
if ((value->it_value.tv_sec == 0 && value->it_value.tv_nsec == 0) || !(shift = cp_offset())) return value;
|
||||
*out = *value;
|
||||
cp_move(&out->it_value, shift);
|
||||
return out;
|
||||
}
|
||||
|
||||
int timerfd_settime(int fd, int flags, const struct itimerspec *value, struct itimerspec *old) {
|
||||
struct itimerspec moved;
|
||||
if (!CP_REAL(cp_tfd_settime, "timerfd_settime")) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
return cp_tfd_settime(fd, flags, cp_timer(fd, flags, value, &moved), old);
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) {
|
||||
struct timespec moved;
|
||||
struct itimerspec timer;
|
||||
int64_t shift;
|
||||
if (number == SYS_clock_gettime) {
|
||||
*ret = real(number, args[0], args[1]);
|
||||
if (*ret == 0 && args[1] && cp_mono((clockid_t)args[0]) && (shift = cp_offset()))
|
||||
cp_move((struct timespec *)args[1], -shift);
|
||||
return 1;
|
||||
}
|
||||
if (number == SYS_timerfd_create) {
|
||||
*ret = real(number, args[0], args[1]);
|
||||
cp_mark((int)*ret, cp_mono((clockid_t)args[0]));
|
||||
return 1;
|
||||
}
|
||||
if (number == SYS_timerfd_settime) {
|
||||
const struct itimerspec *value = cp_timer((int)args[0], (int)args[1], (const struct itimerspec *)args[2], &timer);
|
||||
if (value == (const struct itimerspec *)args[2]) return 0;
|
||||
*ret = real(number, args[0], args[1], (long)value, args[3]);
|
||||
return 1;
|
||||
}
|
||||
if (number == SYS_clock_nanosleep) {
|
||||
if (!((int)args[1] & TIMER_ABSTIME) || !cp_mono((clockid_t)args[0]) || !args[2] || !(shift = cp_offset())) return 0;
|
||||
*ret = real(number, args[0], args[1], (long)cp_later((const struct timespec *)args[2], &moved, shift), args[3]);
|
||||
return 1;
|
||||
}
|
||||
if (number == SYS_futex) {
|
||||
int op = (int)args[1];
|
||||
int cmd = op & FUTEX_CMD_MASK;
|
||||
if (op & FUTEX_CLOCK_REALTIME) return 0;
|
||||
if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI && cmd != FUTEX_LOCK_PI2) return 0;
|
||||
if (!args[3] || !(shift = cp_offset())) return 0;
|
||||
*ret = real(number, args[0], args[1], args[2], (long)cp_later((const struct timespec *)args[3], &moved, shift), args[4], args[5]);
|
||||
return 1;
|
||||
}
|
||||
#ifdef SYS_futex_waitv
|
||||
if (number == SYS_futex_waitv) {
|
||||
if (!args[3] || (clockid_t)args[4] != CLOCK_MONOTONIC || !(shift = cp_offset())) return 0;
|
||||
*ret = real(number, args[0], args[1], args[2], (long)cp_later((const struct timespec *)args[3], &moved, shift), args[4]);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) {
|
||||
(void)number;
|
||||
(void)args;
|
||||
(void)real;
|
||||
(void)ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -178,10 +178,6 @@ static int caller_is_winebus(void *caller) {
|
||||
return strstr(info.dli_fname, "winebus.so") != NULL;
|
||||
}
|
||||
|
||||
/* Wine's HID haptics give every XInput rumble a 1000 ms cutoff and xinput only writes on a change,
|
||||
* but XInput motors hold their speed until the next XInputSetState; evdev's length 0 holds until
|
||||
* stopped. Only this library, preloaded first, sees winebus as the caller. The length is put back
|
||||
* because winebus compares its copy with the next state to decide whether to upload again. */
|
||||
__attribute__((visibility("hidden"))) int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd,
|
||||
unsigned long request, void *arg, void *caller,
|
||||
int *rc) {
|
||||
|
||||
@@ -407,6 +407,7 @@ int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long
|
||||
int bl_ntsync_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_venc_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_vdec_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg,
|
||||
@@ -423,6 +424,7 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
int rc;
|
||||
if (bl_ntsync_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_venc_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_vdec_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_drm_gem_close(fd, request, arg, &rc)) return rc;
|
||||
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
|
||||
if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
|
||||
|
||||
@@ -43,7 +43,7 @@ __attribute__((constructor)) static void noexec_init(void) {
|
||||
real_mprotect = (int (*)(void *, size_t, int))dlsym(RTLD_NEXT, "mprotect");
|
||||
}
|
||||
|
||||
static int private_file_mapping(uintptr_t start, uintptr_t end) {
|
||||
static int private_file_mapping(uintptr_t start, uintptr_t end, int *original_prot) {
|
||||
int fd = (int)syscall(SYS_openat, AT_FDCWD, "/proc/self/maps", O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return 0;
|
||||
char buf[4096], line[1024];
|
||||
@@ -67,6 +67,9 @@ static int private_file_mapping(uintptr_t start, uintptr_t end) {
|
||||
char *path = strchr(perms, '/');
|
||||
struct statvfs vfs;
|
||||
found = path && !(statvfs(path, &vfs) == 0 && (vfs.f_flag & ST_NOEXEC));
|
||||
if (found) *original_prot = (perms[0] == 'r' ? PROT_READ : 0) |
|
||||
(perms[1] == 'w' ? PROT_WRITE : 0) |
|
||||
(perms[2] == 'x' ? PROT_EXEC : 0);
|
||||
}
|
||||
}
|
||||
syscall(SYS_close, fd);
|
||||
@@ -119,12 +122,11 @@ static int write_all(int fd, const unsigned char *p, size_t len) {
|
||||
static int rebake_shared(void *addr, size_t len, int prot) {
|
||||
const char *directory = rx_directory();
|
||||
size_t directory_len = strlen(directory);
|
||||
if (!directory_len || directory_len + 40 >= PATH_MAX) return -1;
|
||||
if (!directory_len || directory_len + 52 >= PATH_MAX) return -1;
|
||||
char path[PATH_MAX], staged[PATH_MAX];
|
||||
char *end = path + directory_len;
|
||||
memcpy(path, directory, directory_len);
|
||||
if (end[-1] != '/') *end++ = '/';
|
||||
*end++ = '/';
|
||||
end = put_hex(end, fnv1a(addr, len));
|
||||
*end++ = '-';
|
||||
end = put_hex(end, len);
|
||||
@@ -155,16 +157,20 @@ static int rebake_shared(void *addr, size_t len, int prot) {
|
||||
return mapped == (long)addr ? 0 : -1;
|
||||
}
|
||||
|
||||
static int rebake(void *addr, size_t len, int prot) {
|
||||
static int rebake(void *addr, size_t len, int prot, int original_prot) {
|
||||
size_t page = getauxval(AT_PAGESZ);
|
||||
if (page) len = (len + page - 1) & ~(page - 1);
|
||||
if (real_mprotect(addr, len, PROT_READ)) return -1;
|
||||
if (!rebake_shared(addr, len, prot)) return 0;
|
||||
void *copy = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (copy == MAP_FAILED) return -1;
|
||||
if (copy == MAP_FAILED) {
|
||||
real_mprotect(addr, len, original_prot);
|
||||
return -1;
|
||||
}
|
||||
memcpy(copy, addr, len);
|
||||
if (mmap(addr, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) {
|
||||
munmap(copy, len);
|
||||
real_mprotect(addr, len, original_prot);
|
||||
return -1;
|
||||
}
|
||||
memcpy(addr, copy, len);
|
||||
@@ -179,8 +185,12 @@ int mprotect(void *addr, size_t len, int prot) {
|
||||
if (result && errno == EACCES && (prot & PROT_EXEC)) {
|
||||
if (in_fex()) {
|
||||
result = real_mprotect(addr, len, prot & ~PROT_EXEC);
|
||||
} else if (len && private_file_mapping((uintptr_t)addr, (uintptr_t)addr + len)) {
|
||||
result = rebake(addr, len, prot);
|
||||
} else {
|
||||
int original_prot;
|
||||
if (len && (uintptr_t)addr <= UINTPTR_MAX - len &&
|
||||
private_file_mapping((uintptr_t)addr, (uintptr_t)addr + len, &original_prot)) {
|
||||
result = rebake(addr, len, prot, original_prot);
|
||||
}
|
||||
}
|
||||
if (result) errno = EACCES;
|
||||
}
|
||||
|
||||
+289
-75
@@ -17,6 +17,7 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <time.h>
|
||||
#include <ucontext.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct ns_sem_args {
|
||||
@@ -68,12 +69,13 @@ struct ns_wait_args {
|
||||
#define NS_PROCS 256u
|
||||
#define NS_FDS 65536
|
||||
#define NS_DEVS 8
|
||||
#define NS_VERSION 1u
|
||||
#define NS_VERSION 2u
|
||||
#define NS_HEAD_MAGIC 0x31434e5953544e44ull
|
||||
#define NS_DEV_MAGIC 0x4e54445600000000ull
|
||||
#define NS_OBJ_MAGIC 0x27ull
|
||||
#define NS_WAITERS 0x80000000u
|
||||
#define NS_SWEEP_NS 2000000000ull
|
||||
#define NS_SPIN_NS 4000ull
|
||||
#define NS_DEAD 0xffffffffu
|
||||
|
||||
#ifndef CLOSE_RANGE_CLOEXEC
|
||||
@@ -144,6 +146,7 @@ struct ns_q {
|
||||
uint32_t waiting;
|
||||
uint32_t inuse;
|
||||
uint32_t next_free;
|
||||
uint32_t sleeping;
|
||||
struct ns_ent ent[NS_ENTS];
|
||||
};
|
||||
|
||||
@@ -168,6 +171,7 @@ struct ns_tls {
|
||||
struct ns_dev *d;
|
||||
uint32_t q;
|
||||
int waiting;
|
||||
int sleep;
|
||||
};
|
||||
|
||||
static struct ns_dev ns_devs[NS_DEVS];
|
||||
@@ -255,19 +259,148 @@ static void ns_unlock(uint32_t *w) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ns_block(sigset_t *old) {
|
||||
sigset_t s;
|
||||
sigfillset(&s);
|
||||
sigdelset(&s, SIGSEGV);
|
||||
sigdelset(&s, SIGBUS);
|
||||
sigdelset(&s, SIGILL);
|
||||
sigdelset(&s, SIGFPE);
|
||||
sigdelset(&s, SIGTRAP);
|
||||
pthread_sigmask(SIG_BLOCK, &s, old);
|
||||
#define NS_DEFER 4
|
||||
#define NS_LEVELS 8
|
||||
|
||||
struct ns_cs {
|
||||
int depth;
|
||||
int count;
|
||||
int level;
|
||||
unsigned held_levels;
|
||||
int sigs[NS_DEFER];
|
||||
siginfo_t info[NS_DEFER];
|
||||
sigset_t held[NS_LEVELS];
|
||||
};
|
||||
|
||||
static __thread struct ns_cs ns_cs;
|
||||
static uintptr_t ns_handlers[_NSIG];
|
||||
static uint8_t ns_siginfo[_NSIG];
|
||||
|
||||
int bl_from_ntdll(const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
static int ns_deferrable(int sig) {
|
||||
return sig > 0 && sig < _NSIG && sig != SIGKILL && sig != SIGSTOP && sig != SIGSEGV && sig != SIGBUS && sig != SIGILL
|
||||
&& sig != SIGFPE && sig != SIGTRAP && sig != SIGSYS;
|
||||
}
|
||||
|
||||
static void ns_restore(const sigset_t *old) {
|
||||
pthread_sigmask(SIG_SETMASK, old, NULL);
|
||||
static int ns_defer(int sig, const siginfo_t *si) {
|
||||
struct ns_cs *cs = &ns_cs;
|
||||
if (sig < SIGRTMIN)
|
||||
for (int i = 0; i < NS_DEFER; i++)
|
||||
if (__atomic_load_n(&cs->sigs[i], __ATOMIC_RELAXED) == sig) return 1;
|
||||
int i = __atomic_fetch_add(&cs->count, 1, __ATOMIC_RELAXED);
|
||||
if (i >= NS_DEFER) {
|
||||
__atomic_fetch_sub(&cs->count, 1, __ATOMIC_RELAXED);
|
||||
return 0;
|
||||
}
|
||||
if (si) memcpy(&cs->info[i], si, sizeof(*si));
|
||||
else memset(&cs->info[i], 0, sizeof(*si));
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
__atomic_store_n(&cs->sigs[i], sig, __ATOMIC_RELAXED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ns_park(int sig, const siginfo_t *si, ucontext_t *uc) {
|
||||
int level = ns_cs.level;
|
||||
if (level < 0 || level >= NS_LEVELS) return 0;
|
||||
sigset_t one;
|
||||
sigemptyset(&one);
|
||||
sigaddset(&one, sig);
|
||||
int saved = errno;
|
||||
pthread_sigmask(SIG_BLOCK, &one, NULL);
|
||||
pid_t pid = getpid(), tid = (pid_t)ns_self();
|
||||
int ok = (si && syscall(SYS_rt_tgsigqueueinfo, pid, tid, sig, si) == 0) || syscall(SYS_tgkill, pid, tid, sig) == 0;
|
||||
if (!ok) pthread_sigmask(SIG_UNBLOCK, &one, NULL);
|
||||
errno = saved;
|
||||
if (!ok) return 0;
|
||||
sigaddset(&uc->uc_sigmask, sig);
|
||||
unsigned long *words = (unsigned long *)&ns_cs.held[level];
|
||||
unsigned bits = 8 * sizeof(unsigned long);
|
||||
__atomic_fetch_or(&words[(unsigned)(sig - 1) / bits], 1ul << ((unsigned)(sig - 1) % bits), __ATOMIC_RELAXED);
|
||||
__atomic_fetch_or(&ns_cs.held_levels, 1u << level, __ATOMIC_RELAXED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void ns_trampoline(int sig, siginfo_t *si, void *uc) {
|
||||
if (__atomic_load_n(&ns_cs.depth, __ATOMIC_RELAXED) > 0 && (ns_defer(sig, si) || (uc && ns_park(sig, si, uc)))) return;
|
||||
uintptr_t h = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
|
||||
if (!h) return;
|
||||
ns_cs.level++;
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (__atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED)) ((void (*)(int, siginfo_t *, void *))h)(sig, si, uc);
|
||||
else ((void (*)(int))h)(sig);
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
ns_cs.level--;
|
||||
}
|
||||
|
||||
static void ns_flush(void) {
|
||||
struct ns_cs *cs = &ns_cs;
|
||||
sigset_t all, mask;
|
||||
sigfillset(&all);
|
||||
int saved = errno;
|
||||
pthread_sigmask(SIG_BLOCK, &all, &mask);
|
||||
int n = cs->count < NS_DEFER ? cs->count : NS_DEFER;
|
||||
pid_t pid = getpid(), tid = (pid_t)ns_self();
|
||||
for (int i = 0; i < n; i++)
|
||||
if (cs->sigs[i] > 0 && syscall(SYS_rt_tgsigqueueinfo, pid, tid, cs->sigs[i], &cs->info[i]) != 0) syscall(SYS_tgkill, pid, tid, cs->sigs[i]);
|
||||
memset(cs->sigs, 0, sizeof(cs->sigs));
|
||||
cs->count = 0;
|
||||
int level = cs->level;
|
||||
if (level >= 0 && level < NS_LEVELS && (cs->held_levels & (1u << level))) {
|
||||
for (int sig = 1; sig < _NSIG; sig++)
|
||||
if (sigismember(&cs->held[level], sig) == 1) sigdelset(&mask, sig);
|
||||
sigemptyset(&cs->held[level]);
|
||||
cs->held_levels &= ~(1u << level);
|
||||
}
|
||||
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static void ns_block(void) {
|
||||
ns_cs.depth++;
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
static void ns_restore(void) {
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (--ns_cs.depth == 0) {
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (ns_cs.count || (ns_cs.held_levels && ns_cs.level >= 0 && ns_cs.level < NS_LEVELS && (ns_cs.held_levels & (1u << ns_cs.level))))
|
||||
ns_flush();
|
||||
}
|
||||
}
|
||||
|
||||
int sigaction(int sig, const struct sigaction *act, struct sigaction *old) {
|
||||
static int (*real)(int, const struct sigaction *, struct sigaction *);
|
||||
if (!real) real = (int (*)(int, const struct sigaction *, struct sigaction *))dlsym(RTLD_NEXT, "sigaction");
|
||||
if (!real) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if (!ns_deferrable(sig) || !ns_on()) return real(sig, act, old);
|
||||
uintptr_t prev = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
|
||||
uint8_t prev_info = __atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED);
|
||||
struct sigaction mine;
|
||||
const struct sigaction *use = act;
|
||||
if (act && act->sa_handler != SIG_DFL && act->sa_handler != SIG_IGN && !(act->sa_flags & SA_RESETHAND) &&
|
||||
bl_from_ntdll(__builtin_return_address(0))) {
|
||||
mine = *act;
|
||||
mine.sa_sigaction = ns_trampoline;
|
||||
mine.sa_flags |= SA_SIGINFO;
|
||||
__atomic_store_n(&ns_siginfo[sig], (act->sa_flags & SA_SIGINFO) ? 1 : 0, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&ns_handlers[sig], (uintptr_t)act->sa_sigaction, __ATOMIC_RELEASE);
|
||||
use = &mine;
|
||||
}
|
||||
int r = real(sig, use, old);
|
||||
if (r != 0 && use == &mine) {
|
||||
__atomic_store_n(&ns_siginfo[sig], prev_info, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&ns_handlers[sig], prev, __ATOMIC_RELEASE);
|
||||
}
|
||||
if (r == 0 && old && old->sa_sigaction == ns_trampoline) {
|
||||
old->sa_sigaction = (void (*)(int, siginfo_t *, void *))prev;
|
||||
if (!prev_info) old->sa_flags &= ~SA_SIGINFO;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline struct ns_obj *ns_obj(struct ns_head *h, uint32_t s) {
|
||||
@@ -378,10 +511,11 @@ static int ns_claim(struct ns_q *q, int32_t index) {
|
||||
if (dead) return 0;
|
||||
}
|
||||
int32_t want = -1;
|
||||
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
|
||||
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static void ns_wake(struct ns_q *q) {
|
||||
if (!__atomic_load_n(&q->sleeping, __ATOMIC_SEQ_CST)) return;
|
||||
int saved = errno;
|
||||
ns_futex(&q->signaled, FUTEX_WAKE, 1, NULL, 0);
|
||||
errno = saved;
|
||||
@@ -618,14 +752,13 @@ static void ns_dev_put_locked(struct ns_dev *d) {
|
||||
|
||||
static void ns_dev_put(struct ns_dev *d) {
|
||||
if (__atomic_sub_fetch(&d->refs, 1, __ATOMIC_ACQ_REL)) return;
|
||||
sigset_t old;
|
||||
int saved = errno;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
uint32_t zero = 0;
|
||||
if (d->h && __atomic_compare_exchange_n(&d->refs, &zero, NS_DEAD, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) ns_release(d);
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
@@ -682,20 +815,18 @@ static void ns_forget_locked(int fd) {
|
||||
}
|
||||
|
||||
static void ns_forget(int fd) {
|
||||
sigset_t old;
|
||||
int saved = errno;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
ns_forget_locked(fd);
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, uint32_t s) {
|
||||
uint64_t e = 0;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
if (!d->h || d->tag != tag || !ns_table() || ns_attach(d) < 0 || s >= NS_SLOTS) goto out;
|
||||
if ((e = __atomic_load_n(&ns_fdt[fd], __ATOMIC_ACQUIRE))) goto out;
|
||||
@@ -710,7 +841,7 @@ static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, u
|
||||
ns_unlock(&o->lock);
|
||||
out:
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -719,8 +850,7 @@ static uint64_t ns_note_device(int fd) {
|
||||
uint64_t e = 0;
|
||||
if (syscall(SYS_fstat, fd, &st) != 0 || !S_ISREG(st.st_mode)) return 0;
|
||||
if (((uint64_t)st.st_size & ~0xffffull) != NS_DEV_MAGIC) return 0;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
struct ns_dev *d = ns_table() ? ns_map(fd, (uint32_t)st.st_size & 0xffff, (uint64_t)st.st_ino) : NULL;
|
||||
if (d) {
|
||||
@@ -732,7 +862,7 @@ static uint64_t ns_note_device(int fd) {
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -773,15 +903,14 @@ static int ns_ready(struct ns_dev *d) {
|
||||
|
||||
static void ns_thread_gone(void *p) {
|
||||
struct ns_tls *t = p;
|
||||
if (!t || !t->d || !t->q) return;
|
||||
sigset_t old;
|
||||
if (!t || !t->d) return;
|
||||
struct ns_dev *d = t->d;
|
||||
ns_block(&old);
|
||||
ns_free_q(d->h, t->q - 1);
|
||||
ns_block();
|
||||
if (t->q) ns_free_q(d->h, t->q - 1);
|
||||
t->q = 0;
|
||||
t->waiting = 0;
|
||||
t->d = NULL;
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
ns_dev_put(d);
|
||||
}
|
||||
|
||||
@@ -789,24 +918,28 @@ static void ns_key_init(void) {
|
||||
pthread_key_create(&ns_key, ns_thread_gone);
|
||||
}
|
||||
|
||||
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
if (ns_tq.d && ns_tq.q && ns_tq.waiting) {
|
||||
ns_drop_q(ns_tq.d->h, ns_tq.q - 1);
|
||||
ns_tq.waiting = 0;
|
||||
}
|
||||
if (ns_tq.d == d && ns_tq.q) {
|
||||
*qi = ns_tq.q - 1;
|
||||
return ns_q(h, *qi);
|
||||
}
|
||||
if (ns_tq.d && ns_tq.q) {
|
||||
struct ns_dev *old = ns_tq.d;
|
||||
ns_free_q(old->h, ns_tq.q - 1);
|
||||
static int ns_hold(struct ns_dev *d) {
|
||||
if (ns_tq.d == d) return 1;
|
||||
if (!ns_dev_get(d)) return 0;
|
||||
if (ns_tq.sleep) return 2;
|
||||
struct ns_dev *old = ns_tq.d;
|
||||
if (old) {
|
||||
ns_block();
|
||||
if (ns_tq.q) ns_free_q(old->h, ns_tq.q - 1);
|
||||
ns_tq.q = 0;
|
||||
ns_tq.waiting = 0;
|
||||
ns_tq.d = NULL;
|
||||
ns_restore();
|
||||
ns_dev_put(old);
|
||||
}
|
||||
pthread_once(&ns_once, ns_key_init);
|
||||
ns_tq.d = d;
|
||||
pthread_setspecific(ns_key, &ns_tq);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct ns_q *ns_new_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
uint32_t i;
|
||||
if (!ns_pop(h, &h->q_free, 0, &i) && !ns_grow(&h->q_hwm, NS_QS, &i)) {
|
||||
ns_sweep_dead(h);
|
||||
@@ -815,22 +948,35 @@ static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_q *q = ns_q(h, i);
|
||||
q->proc = (uint32_t)d->proc;
|
||||
q->waiting = 0;
|
||||
q->sleeping = 0;
|
||||
q->inuse = 1;
|
||||
__atomic_add_fetch(&d->refs, 1, __ATOMIC_ACQ_REL);
|
||||
ns_tq.d = d;
|
||||
ns_tq.q = i + 1;
|
||||
ns_tq.waiting = 0;
|
||||
pthread_setspecific(ns_key, &ns_tq);
|
||||
*qi = i;
|
||||
return q;
|
||||
}
|
||||
|
||||
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
if (ns_tq.d != d) return NULL;
|
||||
if (ns_tq.q && ns_tq.waiting) {
|
||||
ns_drop_q(h, ns_tq.q - 1);
|
||||
ns_tq.waiting = 0;
|
||||
}
|
||||
if (ns_tq.q) {
|
||||
*qi = ns_tq.q - 1;
|
||||
return ns_q(h, *qi);
|
||||
}
|
||||
struct ns_q *q = ns_new_q(d, qi);
|
||||
if (!q) return NULL;
|
||||
ns_tq.q = *qi + 1;
|
||||
ns_tq.waiting = 0;
|
||||
return q;
|
||||
}
|
||||
|
||||
static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
|
||||
struct ns_head *h = d->h;
|
||||
sigset_t old;
|
||||
int fd = -1, err = 0;
|
||||
uint32_t s = 0;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
if (!ns_table() || ns_attach(d) < 0) {
|
||||
err = ENOMEM;
|
||||
@@ -879,7 +1025,7 @@ static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
|
||||
ns_unlock(&o->lock);
|
||||
out:
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
if (fd < 0) errno = err;
|
||||
return fd;
|
||||
}
|
||||
@@ -890,6 +1036,20 @@ static int ns_expired(const struct ns_wait_args *args) {
|
||||
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec >= args->timeout;
|
||||
}
|
||||
|
||||
static uint64_t ns_now(void) {
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec;
|
||||
}
|
||||
|
||||
static void ns_spin(struct ns_q *q) {
|
||||
uint64_t end = ns_now() + NS_SPIN_NS;
|
||||
for (unsigned i = 1; __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1; i++) {
|
||||
ns_relax();
|
||||
if (!(i & 63) && ns_now() >= end) return;
|
||||
}
|
||||
}
|
||||
|
||||
static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
|
||||
struct timespec ts, *tsp = NULL;
|
||||
int op = FUTEX_WAIT_BITSET | ((args->flags & NS_WAIT_REALTIME) ? FUTEX_CLOCK_REALTIME : 0);
|
||||
@@ -898,14 +1058,45 @@ static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
|
||||
ts.tv_nsec = (long)(args->timeout % 1000000000ull);
|
||||
tsp = &ts;
|
||||
}
|
||||
while (__atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
|
||||
if (tsp && ns_expired(args)) return ETIMEDOUT;
|
||||
if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1) {
|
||||
if (errno == ETIMEDOUT) return ETIMEDOUT;
|
||||
if (errno == EINTR) return EINTR;
|
||||
}
|
||||
ns_spin(q);
|
||||
int ret = 0;
|
||||
__atomic_store_n(&q->sleeping, 1, __ATOMIC_SEQ_CST);
|
||||
while (!ret && __atomic_load_n(&q->signaled, __ATOMIC_SEQ_CST) == -1) {
|
||||
if (tsp && ns_expired(args)) ret = ETIMEDOUT;
|
||||
else if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1 && (errno == ETIMEDOUT || errno == EINTR))
|
||||
ret = errno;
|
||||
}
|
||||
return 0;
|
||||
__atomic_store_n(&q->sleeping, 0, __ATOMIC_RELAXED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ns_try_any(struct ns_head *h, const uint32_t *slots, const uint32_t *gens, uint32_t total, uint32_t owner, int *dead) {
|
||||
for (uint32_t i = 0; i < total; i++) {
|
||||
struct ns_obj *o = ns_obj(h, slots[i]);
|
||||
ns_lock(&o->lock);
|
||||
int busy = o->type == NS_FREE || o->gen != gens[i] || o->any_head || o->all_hint;
|
||||
if (!busy && ns_signaled(o, owner)) {
|
||||
switch (o->type) {
|
||||
case NS_SEM:
|
||||
o->a--;
|
||||
break;
|
||||
case NS_MUTEX:
|
||||
*dead = (int)o->ownerdead;
|
||||
o->ownerdead = 0;
|
||||
o->a++;
|
||||
o->b = owner;
|
||||
break;
|
||||
case NS_EVENT:
|
||||
if (!o->a) o->b = 0;
|
||||
break;
|
||||
}
|
||||
ns_unlock(&o->lock);
|
||||
return (int)i;
|
||||
}
|
||||
ns_unlock(&o->lock);
|
||||
if (busy) return -1;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
@@ -927,12 +1118,24 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
for (uint32_t j = 0; j < i; j++)
|
||||
if (slots[j] == slots[i]) return EINVAL;
|
||||
}
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
int nested = ns_tq.sleep > 0;
|
||||
ns_block();
|
||||
if (!all && (nested || !ns_tq.waiting)) {
|
||||
int dead = 0, got = ns_try_any(h, slots, gens, total, args.owner, &dead);
|
||||
if (got >= 0) {
|
||||
ns_restore();
|
||||
ua->index = (uint32_t)got;
|
||||
return dead ? EOWNERDEAD : 0;
|
||||
}
|
||||
if (got == -2 && args.timeout != UINT64_MAX && ns_expired(&args)) {
|
||||
ns_restore();
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
uint32_t qi;
|
||||
struct ns_q *q = ns_ready(d) ? ns_thread_q(d, &qi) : NULL;
|
||||
struct ns_q *q = !ns_ready(d) ? NULL : nested ? ns_new_q(d, &qi) : ns_thread_q(d, &qi);
|
||||
if (!q) {
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return ENOMEM;
|
||||
}
|
||||
ns_maybe_sweep(h);
|
||||
@@ -952,7 +1155,7 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
}
|
||||
q->total = total;
|
||||
q->waiting = 1;
|
||||
ns_tq.waiting = 1;
|
||||
if (!nested) ns_tq.waiting = 1;
|
||||
int bad = 0;
|
||||
if (!all) {
|
||||
for (uint32_t i = 0; i < total && !bad; i++) {
|
||||
@@ -1004,16 +1207,18 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
}
|
||||
int ret = 0;
|
||||
if (!bad && __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
|
||||
sigset_t held;
|
||||
ns_restore(&old);
|
||||
ns_tq.sleep++;
|
||||
ns_restore();
|
||||
ret = ns_sleep(q, &args);
|
||||
ns_block(&held);
|
||||
ns_block();
|
||||
ns_tq.sleep--;
|
||||
}
|
||||
ns_drop_q(h, qi);
|
||||
ns_tq.waiting = 0;
|
||||
if (!nested) ns_tq.waiting = 0;
|
||||
int32_t got = __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE);
|
||||
int dead = (int)q->ownerdead;
|
||||
ns_restore(&old);
|
||||
if (nested) ns_free_q(h, qi);
|
||||
ns_restore();
|
||||
if (bad) return EINVAL;
|
||||
if (got != -1) {
|
||||
ua->index = (uint32_t)got;
|
||||
@@ -1061,12 +1266,11 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
|
||||
return ENOTTY;
|
||||
}
|
||||
if (type != (uint32_t)want) return EINVAL;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
int all = ns_lock_obj(h, o);
|
||||
if (o->type != (uint32_t)want || o->gen != gen) {
|
||||
ns_unlock_obj(h, o, all);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return EINVAL;
|
||||
}
|
||||
switch (req) {
|
||||
@@ -1133,7 +1337,7 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
|
||||
}
|
||||
}
|
||||
ns_unlock_obj(h, o, all);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
if (ret) return ret;
|
||||
if (req == NS_SEM_RELEASE || req == NS_EVENT_SET || req == NS_EVENT_RESET || req == NS_EVENT_PULSE)
|
||||
memcpy(arg, &prev, sizeof(prev));
|
||||
@@ -1176,9 +1380,10 @@ int bl_ntsync_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
uint64_t e = ns_lookup(fd);
|
||||
if (!e) return 0;
|
||||
struct ns_dev *d = &ns_devs[(e >> 56) & 7];
|
||||
if (!ns_dev_get(d)) return 0;
|
||||
int held = ns_hold(d);
|
||||
if (!held) return 0;
|
||||
int out = 0, err = (e & NS_E_DEVICE) ? ns_dev_ioctl(d, req, arg, &out) : ns_obj_ioctl(d, e, req, arg);
|
||||
ns_dev_put(d);
|
||||
if (held == 2) ns_dev_put(d);
|
||||
if (err) {
|
||||
errno = err;
|
||||
*rc = -1;
|
||||
@@ -1254,13 +1459,22 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags) {
|
||||
|
||||
void bl_fsync_fds_closed(unsigned int first, unsigned int last) __attribute__((visibility("hidden")));
|
||||
void bl_venc_closed(int fd) __attribute__((visibility("hidden")));
|
||||
void bl_vdec_closed(int fd) __attribute__((visibility("hidden")));
|
||||
|
||||
int close(int fd) {
|
||||
if (fd >= 0) bl_fsync_fds_closed((unsigned int)fd, (unsigned int)fd);
|
||||
bl_venc_closed(fd);
|
||||
bl_vdec_closed(fd);
|
||||
uint64_t *t = __atomic_load_n(&ns_fdt, __ATOMIC_ACQUIRE);
|
||||
if (t && fd >= 0 && fd < NS_FDS && __atomic_load_n(&t[fd], __ATOMIC_ACQUIRE)) ns_forget(fd);
|
||||
return ns_close_fd(fd);
|
||||
int saved = errno;
|
||||
int mode = fd >= 0 ? fcntl(fd, F_GETFL) : -1;
|
||||
int r = ns_close_fd(fd);
|
||||
if (r < 0 && errno == EIO && mode >= 0 && (mode & O_ACCMODE) == O_RDONLY) {
|
||||
errno = saved;
|
||||
return 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int dup2(int oldfd, int newfd) {
|
||||
|
||||
@@ -15,6 +15,7 @@ int bl_status_without_tracer(const char *path, int flags, const void *caller) __
|
||||
int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_venc_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_vdec_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
int (*real)(int, const char *, int, mode_t)) __attribute__((visibility("hidden")));
|
||||
|
||||
@@ -55,6 +56,7 @@ int open(const char *path, int flags, ...) {
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_vdec_open(path, flags)) != -2) return fd;
|
||||
if (real_open == NULL) real_open = dlsym(RTLD_NEXT, "open");
|
||||
if (real_open == NULL) {
|
||||
errno = ENOSYS;
|
||||
@@ -81,6 +83,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_vdec_open(path, flags)) != -2) return fd;
|
||||
if (real_openat == NULL) real_openat = dlsym(RTLD_NEXT, "openat");
|
||||
if (real_openat == NULL) {
|
||||
errno = ENOSYS;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define FUSE_MAGIC 0x65735546
|
||||
#define SDCARDFS_MAGIC 0x5dca2df5
|
||||
|
||||
static int is_wineserver(void) {
|
||||
static int cached = -1;
|
||||
char exe[PATH_MAX];
|
||||
const char *base;
|
||||
ssize_t n;
|
||||
|
||||
if (cached >= 0) return cached;
|
||||
n = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
|
||||
if (n <= 0) {
|
||||
cached = 0;
|
||||
return cached;
|
||||
}
|
||||
exe[n] = '\0';
|
||||
base = strrchr(exe, '/');
|
||||
cached = strcmp(base ? base + 1 : exe, "wineserver") == 0;
|
||||
return cached;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
void bl_storage_owner(int fd, struct stat *st) {
|
||||
struct statfs fs;
|
||||
int saved = errno;
|
||||
uid_t uid;
|
||||
|
||||
if (st != NULL && is_wineserver()) {
|
||||
uid = getuid();
|
||||
if (st->st_uid != uid && fstatfs(fd, &fs) == 0 && (fs.f_type == FUSE_MAGIC || fs.f_type == SDCARDFS_MAGIC)) st->st_uid = uid;
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
@@ -139,17 +139,31 @@ static int (*next_faccessat(void))(int, const char *, int, int) {
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_runnable(const char *path, int mode);
|
||||
__attribute__((visibility("hidden"))) int bl_writable_access(int dirfd, const char *path, int mode, int flags);
|
||||
|
||||
static int writable_as_owner(int (*real)(int, const char *, int, int), int dirfd, const char *path, int mode, int flags) {
|
||||
if (!bl_writable_access(dirfd, path, mode, flags)) return -1;
|
||||
if ((mode & ~W_OK) == 0 || real(dirfd, path, mode & ~W_OK, flags) == 0) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int check_cwd(const char *path, int mode, int flags) {
|
||||
int (*real)(int, const char *, int, int) = next_faccessat();
|
||||
int result;
|
||||
int err;
|
||||
|
||||
if (real == NULL) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
result = real(AT_FDCWD, path, mode, flags);
|
||||
return result != 0 && errno == EACCES && bl_binfmt_runnable(path, mode) ? 0 : result;
|
||||
if (result == 0) return 0;
|
||||
err = errno;
|
||||
if (err == EACCES && bl_binfmt_runnable(path, mode)) return 0;
|
||||
errno = err;
|
||||
if (writable_as_owner(real, AT_FDCWD, path, mode, flags) == 0) return 0;
|
||||
errno = err;
|
||||
return result;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode) {
|
||||
@@ -166,6 +180,7 @@ int eaccess(const char *path, int mode) {
|
||||
|
||||
int faccessat(int dirfd, const char *path, int mode, int flags) {
|
||||
int (*real)(int, const char *, int, int);
|
||||
int err;
|
||||
|
||||
if (dirfd == AT_FDCWD) {
|
||||
return cached_access(path, mode, flags, check_cwd);
|
||||
@@ -175,5 +190,9 @@ int faccessat(int dirfd, const char *path, int mode, int flags) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
return real(dirfd, path, mode, flags);
|
||||
if (real(dirfd, path, mode, flags) == 0) return 0;
|
||||
err = errno;
|
||||
if (writable_as_owner(real, dirfd, path, mode, flags) == 0) return 0;
|
||||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -23,6 +24,34 @@ static int is_steam_client(void) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
static int wine_name(const char *path) {
|
||||
const char *base;
|
||||
size_t n;
|
||||
|
||||
if (path == NULL) return 0;
|
||||
base = strrchr(path, '/');
|
||||
base = base ? base + 1 : path;
|
||||
n = strlen(path);
|
||||
return strncmp(base, "wine", 4) == 0 || strstr(path, "/lib/wine/") != NULL
|
||||
|| (n > 4 && strcasecmp(path + n - 4, ".exe") == 0);
|
||||
}
|
||||
|
||||
static int is_wine(void) {
|
||||
static int cached = -1;
|
||||
char exe[PATH_MAX];
|
||||
ssize_t n;
|
||||
|
||||
if (cached >= 0) return cached;
|
||||
n = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
|
||||
if (n > 0) exe[n] = '\0';
|
||||
cached = (n > 0 && wine_name(exe)) || wine_name(program_invocation_name);
|
||||
return cached;
|
||||
}
|
||||
|
||||
static int acts_as_root(void) {
|
||||
return is_steam_client() || !is_wine();
|
||||
}
|
||||
|
||||
static int grant_owner_write(int dirfd, const char *path) {
|
||||
struct stat st;
|
||||
|
||||
@@ -37,7 +66,7 @@ int bl_writable_retry(int dirfd, const char *path, int flags) {
|
||||
char parent[PATH_MAX];
|
||||
const char *slash;
|
||||
|
||||
if (saved != EACCES || path == NULL || (flags & O_ACCMODE) == O_RDONLY || !is_steam_client()) return 0;
|
||||
if (saved != EACCES || path == NULL || (flags & O_ACCMODE) == O_RDONLY || !acts_as_root()) return 0;
|
||||
if (faccessat(dirfd, path, F_OK, 0) == 0) {
|
||||
granted = grant_owner_write(dirfd, path);
|
||||
} else if (flags & O_CREAT) {
|
||||
@@ -53,3 +82,15 @@ int bl_writable_retry(int dirfd, const char *path, int flags) {
|
||||
errno = saved;
|
||||
return granted;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_writable_access(int dirfd, const char *path, int mode, int flags) {
|
||||
int saved = errno;
|
||||
struct stat st;
|
||||
int owned;
|
||||
|
||||
if (saved != EACCES || path == NULL || !(mode & W_OK) || !acts_as_root()) return 0;
|
||||
owned = fstatat(dirfd, path, &st, flags & AT_SYMLINK_NOFOLLOW) == 0 && st.st_uid == geteuid();
|
||||
errno = saved;
|
||||
return owned;
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
/* In Deck mode (-steamos3) the x86-64 client's SteamOS audio manager passes libpulse the NULL operation of a
|
||||
* failed request, and libpulse aborts on it ("Assertion 'o' failed ... pa_operation_get_state()"). */
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
@@ -9,7 +7,6 @@ typedef struct pa_operation pa_operation;
|
||||
|
||||
#define PA_OPERATION_CANCELLED 2
|
||||
|
||||
/* A libpulse loaded with RTLD_LOCAL (Wine's winepulse.so) is not in RTLD_NEXT's scope. */
|
||||
static void *libpulse(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (!fn) {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#define BL_RESOLVE_BENEATH 0x08
|
||||
#define BL_RESOLVE_IN_ROOT 0x10
|
||||
// The kernel's MAXSYMLINKS.
|
||||
#define BL_MAX_SYMLINKS 40
|
||||
#define BL_PROC_ROOT_INO 1
|
||||
|
||||
@@ -49,6 +48,7 @@ static int openat2_missing;
|
||||
static int (*next_fstatat)(int, const char *, bl_stat *, int);
|
||||
static int (*next_openat)(int, const char *, int, ...);
|
||||
static ssize_t (*next_readlinkat)(int, const char *, char *, size_t);
|
||||
static int (*next_statx)(int, const char *, int, unsigned int, struct statx *);
|
||||
|
||||
static int find_fastpath(struct dl_phdr_info *info, size_t size, void *name) {
|
||||
(void)size;
|
||||
@@ -68,6 +68,7 @@ __attribute__((constructor)) static void find_fastpath_calls(void) {
|
||||
next_fstatat = (int (*)(int, const char *, bl_stat *, int))dlsym(fastpath, BL_FSTATAT_NAME);
|
||||
next_openat = (int (*)(int, const char *, int, ...))dlsym(fastpath, "openat");
|
||||
next_readlinkat = (ssize_t (*)(int, const char *, char *, size_t))dlsym(fastpath, "readlinkat");
|
||||
next_statx = (int (*)(int, const char *, int, unsigned int, struct statx *))dlsym(fastpath, "statx");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,13 +93,19 @@ static long path_readlink(int dirfd, const char *path, char *buf, size_t size) {
|
||||
return next_readlinkat(dirfd, path, buf, size);
|
||||
}
|
||||
|
||||
static long path_statx(int dirfd, const char *path, int flags, unsigned int mask, struct statx *out) {
|
||||
if (!next_statx) {
|
||||
return real_syscall(SYS_statx, (long)dirfd, (long)path, (long)flags, (long)mask, (long)out);
|
||||
}
|
||||
return next_statx(dirfd, path, flags, mask, out);
|
||||
}
|
||||
|
||||
void *dlopen(const char *filename, int flags) {
|
||||
if (!real_dlopen) {
|
||||
real_dlopen = (void *(*)(const char *, int))dlsym(RTLD_NEXT, "dlopen");
|
||||
}
|
||||
const char *basename = filename ? strrchr(filename, '/') : NULL;
|
||||
basename = basename ? basename + 1 : filename;
|
||||
// Steam's deep binding bypasses the robust-list shim under PRoot.
|
||||
if (basename && strcmp(basename, "vrclient.so") == 0) {
|
||||
flags &= ~RTLD_DEEPBIND;
|
||||
}
|
||||
@@ -139,7 +146,6 @@ static struct robust_list_head *thread_robust_head(void) {
|
||||
return head;
|
||||
}
|
||||
|
||||
// Magic links are procfs links below a process's directory; procfs's root holds only plain ones (self, thread-self, mounts).
|
||||
static int is_magic_link(int dirfd, char *link, size_t parent_len) {
|
||||
int fd = (int)path_open(dirfd, link, O_PATH | O_NOFOLLOW | O_CLOEXEC, 0L);
|
||||
if (fd < 0) {
|
||||
@@ -159,7 +165,6 @@ static int is_magic_link(int dirfd, char *link, size_t parent_len) {
|
||||
return result != 0 || parent.st_ino != BL_PROC_ROOT_INO;
|
||||
}
|
||||
|
||||
// RESOLVE_IN_ROOT walked one component at a time: absolute symlinks restart at dirfd and ".." stops there.
|
||||
static long openat_in_root(int dirfd, const char *path, int flags, long mode) {
|
||||
char resolved[PATH_MAX];
|
||||
char pending[PATH_MAX];
|
||||
@@ -168,7 +173,6 @@ static long openat_in_root(int dirfd, const char *path, int flags, long mode) {
|
||||
int have_root = 0;
|
||||
int root_on_procfs = 0;
|
||||
dev_t root_dev = 0;
|
||||
// O_NOFOLLOW and O_CREAT | O_EXCL leave a final symlink alone, unless a trailing slash follows it.
|
||||
int nofollow = (flags & O_NOFOLLOW) || (flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
|
||||
const char *rest = path;
|
||||
for (;;) {
|
||||
@@ -232,7 +236,6 @@ static long openat_in_root(int dirfd, const char *path, int flags, long mode) {
|
||||
have_root = 1;
|
||||
}
|
||||
if ((st.st_dev != root_dev || root_on_procfs) && is_magic_link(dirfd, resolved, resolved_len)) {
|
||||
// RESOLVE_IN_ROOT refuses magic links.
|
||||
errno = EXDEV;
|
||||
return -1;
|
||||
}
|
||||
@@ -329,7 +332,28 @@ static int execveat_is_execve(const long *args) {
|
||||
return path[0] == '/' || (int)args[0] == AT_FDCWD;
|
||||
}
|
||||
|
||||
static long openat2_call(const long *args) {
|
||||
if (!real_syscall) {
|
||||
real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall");
|
||||
}
|
||||
if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) {
|
||||
long fd = real_syscall(SYS_openat2, args[0], args[1], args[2], args[3]);
|
||||
if (fd != -1 || errno != ENOSYS) {
|
||||
return fd;
|
||||
}
|
||||
__atomic_store_n(&openat2_missing, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
return openat2_via_openat(args);
|
||||
}
|
||||
|
||||
int bl_openat2(int dirfd, const char *path, void *how, size_t size) __asm__("openat2");
|
||||
int bl_openat2(int dirfd, const char *path, void *how, size_t size) {
|
||||
long args[6] = {dirfd, (long)path, (long)how, (long)size, 0, 0};
|
||||
return (int)openat2_call(args);
|
||||
}
|
||||
|
||||
int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) __attribute__((visibility("hidden")));
|
||||
int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) __attribute__((visibility("hidden")));
|
||||
|
||||
long syscall(long number, ...) {
|
||||
va_list ap;
|
||||
@@ -356,22 +380,27 @@ long syscall(long number, ...) {
|
||||
if (!real_syscall) {
|
||||
real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall");
|
||||
}
|
||||
if (bl_clock_syscall(number, args, real_syscall, &handled)) {
|
||||
return handled;
|
||||
}
|
||||
if (bl_writewatch_syscall(number, args, real_syscall, &handled)) {
|
||||
return handled;
|
||||
}
|
||||
if (number == SYS_openat2) {
|
||||
if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) {
|
||||
long fd = real_syscall(number, args[0], args[1], args[2], args[3]);
|
||||
if (fd != -1 || errno != ENOSYS) {
|
||||
return fd;
|
||||
}
|
||||
__atomic_store_n(&openat2_missing, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
return openat2_via_openat(args);
|
||||
return openat2_call(args);
|
||||
}
|
||||
if (number == SYS_openat) {
|
||||
return path_open((int)args[0], (const char *)args[1], (int)args[2], args[3]);
|
||||
}
|
||||
if (number == BL_SYS_FSTATAT) {
|
||||
return path_stat((int)args[0], (const char *)args[1], (bl_stat *)args[2], (int)args[3]);
|
||||
}
|
||||
if (number == SYS_readlinkat) {
|
||||
return path_readlink((int)args[0], (const char *)args[1], (char *)args[2], (size_t)args[3]);
|
||||
}
|
||||
if (number == SYS_statx) {
|
||||
return path_statx((int)args[0], (const char *)args[1], (int)args[2], (unsigned int)args[3], (struct statx *)args[4]);
|
||||
}
|
||||
if (number == SYS_execveat && execveat_is_execve(args)) {
|
||||
return real_syscall(SYS_execve, args[1], args[2], args[3]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* Steam's Linux Remote Play host has no touch injection: client touches arrive as an XTest mouse (absolute
|
||||
* motion plus button 1). While a stream holds the encoder, those become touches into gamescope's own touch
|
||||
* input, as a finger on the device screen would. */
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
@@ -51,9 +48,16 @@ static void rt_send(void *dpy, uint32_t action) {
|
||||
}
|
||||
}
|
||||
|
||||
static void *rt_xtst(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (fn) return fn;
|
||||
void *lib = dlopen("libXtst.so.6", RTLD_LAZY | RTLD_NOLOAD);
|
||||
return lib ? dlsym(lib, name) : NULL;
|
||||
}
|
||||
|
||||
int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long delay) {
|
||||
static int (*real)(void *, int, int, int, unsigned long);
|
||||
if (!real) real = (int (*)(void *, int, int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeMotionEvent");
|
||||
if (!real) real = (int (*)(void *, int, int, int, unsigned long))rt_xtst("XTestFakeMotionEvent");
|
||||
if (rt_enabled()) {
|
||||
pthread_mutex_lock(&rt_lock);
|
||||
rt_x = x;
|
||||
@@ -69,7 +73,7 @@ int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long dela
|
||||
|
||||
int XTestFakeButtonEvent(void *dpy, unsigned int button, int press, unsigned long delay) {
|
||||
static int (*real)(void *, unsigned int, int, unsigned long);
|
||||
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeButtonEvent");
|
||||
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))rt_xtst("XTestFakeButtonEvent");
|
||||
if (button == 1) {
|
||||
pthread_mutex_lock(&rt_lock);
|
||||
int handled = 0;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static int (*next_fstat)(int, struct stat *);
|
||||
void bl_storage_owner(int fd, struct stat *st) __attribute__((visibility("hidden")));
|
||||
static int (*next_fallocate)(int, int, off_t, off_t);
|
||||
static int (*next_posix_fallocate)(int, off_t, off_t);
|
||||
static ssize_t (*next_pwrite)(int, const void *, size_t, off_t);
|
||||
@@ -285,12 +286,17 @@ int fstat(int fd, struct stat *out) {
|
||||
if (next_fstat == NULL) { errno = ENOSYS; return -1; }
|
||||
initialize();
|
||||
errno = entry_errno;
|
||||
if (!enabled) return next_fstat(fd, out);
|
||||
if (!enabled) {
|
||||
int result = next_fstat(fd, out);
|
||||
if (result == 0) bl_storage_owner(fd, out);
|
||||
return result;
|
||||
}
|
||||
uint64_t start = now_ns();
|
||||
errno = entry_errno;
|
||||
int result = next_fstat(fd, out);
|
||||
int call_errno = errno;
|
||||
uint64_t elapsed = now_ns() - start;
|
||||
if (result == 0) bl_storage_owner(fd, out);
|
||||
if (result == 0 && on_selected_device(fd, out)) {
|
||||
add(&stats.fstat_calls, 1);
|
||||
add(&stats.fstat_elapsed_ns, elapsed);
|
||||
|
||||
@@ -195,8 +195,8 @@ static unsigned murmur_hash2(const char *key, size_t len) {
|
||||
len -= 4;
|
||||
}
|
||||
switch (len) {
|
||||
case 3: h ^= data[2] << 16; /* fallthrough */
|
||||
case 2: h ^= data[1] << 8; /* fallthrough */
|
||||
case 3: h ^= data[2] << 16; __attribute__((fallthrough));
|
||||
case 2: h ^= data[1] << 8; __attribute__((fallthrough));
|
||||
case 1: h ^= data[0]; h *= m;
|
||||
}
|
||||
h ^= h >> 13;
|
||||
|
||||
@@ -0,0 +1,978 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__aarch64__) || defined(BL_VDEC_ANY_ARCH)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../../app/src/main/cpp/venc/venc_proto.h"
|
||||
|
||||
#define VDEC_DEVICE "/dev/video-dec0"
|
||||
#define VDEC_INSTANCES 4
|
||||
#define VDEC_BUFFERS 16
|
||||
#define VDEC_BITSTREAM_SIZE (4u << 20)
|
||||
#define VDEC_PADDING 64
|
||||
#define VDEC_DUMB 64
|
||||
|
||||
struct vd_dma_heap_alloc {
|
||||
uint64_t len;
|
||||
uint32_t fd;
|
||||
uint32_t fd_flags;
|
||||
uint64_t heap_flags;
|
||||
};
|
||||
#define VD_DMA_HEAP_IOCTL_ALLOC _IOWR('H', 0x0, struct vd_dma_heap_alloc)
|
||||
|
||||
struct vd_dma_buf_sync {
|
||||
uint64_t flags;
|
||||
};
|
||||
#define VD_DMA_BUF_SYNC_WRITE 2u
|
||||
#define VD_DMA_BUF_SYNC_START 0u
|
||||
#define VD_DMA_BUF_SYNC_END 4u
|
||||
#define VD_DMA_BUF_IOCTL_SYNC _IOW('b', 0, struct vd_dma_buf_sync)
|
||||
|
||||
struct vd_create_dumb {
|
||||
uint32_t height, width, bpp, flags, handle, pitch;
|
||||
uint64_t size;
|
||||
};
|
||||
struct vd_destroy_dumb {
|
||||
uint32_t handle;
|
||||
};
|
||||
struct vd_prime_handle {
|
||||
uint32_t handle, flags;
|
||||
int32_t fd;
|
||||
};
|
||||
#define VD_IOCTL_MODE_CREATE_DUMB _IOWR('d', 0xB2, struct vd_create_dumb)
|
||||
#define VD_IOCTL_MODE_DESTROY_DUMB _IOWR('d', 0xB4, struct vd_destroy_dumb)
|
||||
#define VD_IOCTL_PRIME_HANDLE_TO_FD _IOWR('d', 0x2d, struct vd_prime_handle)
|
||||
|
||||
struct vd_mode_info {
|
||||
uint32_t clock;
|
||||
uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
|
||||
uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
|
||||
uint32_t vrefresh, flags, type;
|
||||
char name[32];
|
||||
};
|
||||
struct vd_res {
|
||||
int count_fbs;
|
||||
uint32_t *fbs;
|
||||
int count_crtcs;
|
||||
uint32_t *crtcs;
|
||||
int count_connectors;
|
||||
uint32_t *connectors;
|
||||
int count_encoders;
|
||||
uint32_t *encoders;
|
||||
uint32_t min_width, max_width, min_height, max_height;
|
||||
};
|
||||
struct vd_connector {
|
||||
uint32_t connector_id, encoder_id, connector_type, connector_type_id;
|
||||
int connection;
|
||||
uint32_t mm_width, mm_height;
|
||||
int subpixel;
|
||||
int count_modes;
|
||||
struct vd_mode_info *modes;
|
||||
int count_props;
|
||||
uint32_t *props;
|
||||
uint64_t *prop_values;
|
||||
int count_encoders;
|
||||
uint32_t *encoders;
|
||||
};
|
||||
struct vd_encoder {
|
||||
uint32_t encoder_id, encoder_type, crtc_id, possible_crtcs, possible_clones;
|
||||
};
|
||||
struct vd_crtc {
|
||||
uint32_t crtc_id, buffer_id, x, y, width, height;
|
||||
int mode_valid;
|
||||
struct vd_mode_info mode;
|
||||
int gamma_size;
|
||||
};
|
||||
struct vd_device {
|
||||
char **nodes;
|
||||
int available_nodes;
|
||||
int bustype;
|
||||
void *businfo;
|
||||
void *deviceinfo;
|
||||
};
|
||||
|
||||
struct vd_capture {
|
||||
int fd;
|
||||
ino_t ino;
|
||||
uint8_t *map;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct vd_done {
|
||||
uint32_t index;
|
||||
struct timeval timestamp;
|
||||
};
|
||||
|
||||
struct vdec {
|
||||
int used, fd;
|
||||
uint32_t fourcc, width, height;
|
||||
uint32_t cap_width, cap_height, bpl, cap_size;
|
||||
uint8_t *bitstream;
|
||||
uint32_t out_count;
|
||||
uint32_t out_done[VDEC_BUFFERS], n_out_done;
|
||||
struct vd_capture cap[VDEC_BUFFERS];
|
||||
uint32_t cap_count;
|
||||
uint32_t cap_queue[VDEC_BUFFERS], n_cap_queue;
|
||||
struct vd_done cap_done[VDEC_BUFFERS];
|
||||
uint32_t n_cap_done;
|
||||
int out_on, cap_on;
|
||||
int sock, hw, hw_failed;
|
||||
int64_t pts;
|
||||
void *ctx, *packet, *frame;
|
||||
uint8_t *packet_data;
|
||||
size_t packet_capacity;
|
||||
int last;
|
||||
uint32_t frames, slow;
|
||||
double decode_ms;
|
||||
};
|
||||
|
||||
static struct {
|
||||
void *(*find_decoder_by_name)(const char *);
|
||||
void *(*alloc_context3)(const void *);
|
||||
int (*open2)(void *, const void *, void **);
|
||||
void (*free_context)(void **);
|
||||
int (*send_packet)(void *, const void *);
|
||||
int (*receive_frame)(void *, void *);
|
||||
void (*flush_buffers)(void *);
|
||||
void *(*packet_alloc)(void);
|
||||
void (*packet_free)(void **);
|
||||
void *(*frame_alloc)(void);
|
||||
void (*frame_free)(void **);
|
||||
void (*frame_unref)(void *);
|
||||
int (*dict_set)(void **, const char *, const char *, int);
|
||||
void (*dict_free)(void **);
|
||||
const char *(*pix_fmt_name)(int);
|
||||
} av;
|
||||
|
||||
static pthread_mutex_t vd_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct vdec vd_all[VDEC_INSTANCES];
|
||||
static int vd_open_count;
|
||||
static int vd_state;
|
||||
static int vd_ffmpeg;
|
||||
static int vd_heap = -1;
|
||||
static int vd_dumb_fd[VDEC_DUMB];
|
||||
static char vd_drm_handle;
|
||||
|
||||
static void vd_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
static void vd_log(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char line[256];
|
||||
va_start(ap, fmt);
|
||||
int n = vsnprintf(line, sizeof line - 1, fmt, ap);
|
||||
va_end(ap);
|
||||
if (n < 0) return;
|
||||
if (n > (int)sizeof line - 2) n = sizeof line - 2;
|
||||
line[n++] = '\n';
|
||||
if (write(2, "droiddeck-vdec: ", 16) < 0 || write(2, line, n) < 0) return;
|
||||
}
|
||||
|
||||
static int vd_load_ffmpeg(void) {
|
||||
void *codec = dlopen("libavcodec.so.62", RTLD_LAZY | RTLD_LOCAL);
|
||||
void *util = codec ? dlopen("libavutil.so.60", RTLD_LAZY | RTLD_LOCAL) : NULL;
|
||||
if (codec == NULL || util == NULL) {
|
||||
vd_log("FFmpeg 8 is not available (%s), Remote Play decoding stays off", dlerror());
|
||||
return 0;
|
||||
}
|
||||
#define VD_SYM(lib, field, name) \
|
||||
if ((*(void **)&av.field = dlsym(lib, name)) == NULL) { \
|
||||
vd_log("FFmpeg has no %s, Remote Play decoding stays off", name); \
|
||||
return 0; \
|
||||
}
|
||||
VD_SYM(codec, find_decoder_by_name, "avcodec_find_decoder_by_name")
|
||||
VD_SYM(codec, alloc_context3, "avcodec_alloc_context3")
|
||||
VD_SYM(codec, open2, "avcodec_open2")
|
||||
VD_SYM(codec, free_context, "avcodec_free_context")
|
||||
VD_SYM(codec, send_packet, "avcodec_send_packet")
|
||||
VD_SYM(codec, receive_frame, "avcodec_receive_frame")
|
||||
VD_SYM(codec, flush_buffers, "avcodec_flush_buffers")
|
||||
VD_SYM(codec, packet_alloc, "av_packet_alloc")
|
||||
VD_SYM(codec, packet_free, "av_packet_free")
|
||||
VD_SYM(util, frame_alloc, "av_frame_alloc")
|
||||
VD_SYM(util, frame_free, "av_frame_free")
|
||||
VD_SYM(util, frame_unref, "av_frame_unref")
|
||||
VD_SYM(util, dict_set, "av_dict_set")
|
||||
VD_SYM(util, dict_free, "av_dict_free")
|
||||
VD_SYM(util, pix_fmt_name, "av_get_pix_fmt_name")
|
||||
#undef VD_SYM
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int vd_have_ffmpeg(void) {
|
||||
if (vd_ffmpeg == 0) vd_ffmpeg = vd_load_ffmpeg() ? 1 : -1;
|
||||
return vd_ffmpeg > 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_venc_connect(void);
|
||||
|
||||
static int vd_enabled(void) {
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
if (vd_state == 0) {
|
||||
const char *flag = getenv("BL_REMOTE_PLAY_DECODE"), *socket = getenv("BL_VENC_SOCKET");
|
||||
vd_state = -1;
|
||||
if (strcmp(program_invocation_short_name, "streaming_client") == 0 && (flag == NULL || strcmp(flag, "0") != 0)) {
|
||||
vd_heap = open("/dev/dma_heap/system", O_RDONLY | O_CLOEXEC);
|
||||
if (vd_heap < 0) vd_log("no /dev/dma_heap/system (%s), Remote Play decoding stays off", strerror(errno));
|
||||
else if ((socket && *socket) || vd_have_ffmpeg()) vd_state = 1;
|
||||
for (int i = 0; i < VDEC_DUMB; i++) vd_dumb_fd[i] = -1;
|
||||
}
|
||||
}
|
||||
int on = vd_state > 0;
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
return on;
|
||||
}
|
||||
|
||||
static struct vdec *vd_find(int fd) {
|
||||
if (fd < 0 || __atomic_load_n(&vd_open_count, __ATOMIC_ACQUIRE) == 0) return NULL;
|
||||
for (int i = 0; i < VDEC_INSTANCES; i++) if (vd_all[i].used && vd_all[i].fd == fd) return &vd_all[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_open(const char *path, int flags) {
|
||||
(void)flags;
|
||||
if (path == NULL || strcmp(path, VDEC_DEVICE) != 0 || !vd_enabled()) return -2;
|
||||
int fd = memfd_create("droiddeck-vdec", 0);
|
||||
if (fd < 0) return -1;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
struct vdec *v = NULL;
|
||||
for (int i = 0; i < VDEC_INSTANCES && v == NULL; i++) if (!vd_all[i].used) v = &vd_all[i];
|
||||
if (v == NULL) {
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
close(fd);
|
||||
errno = EBUSY;
|
||||
return -1;
|
||||
}
|
||||
memset(v, 0, sizeof *v);
|
||||
v->used = 1;
|
||||
v->fd = fd;
|
||||
v->fourcc = V4L2_PIX_FMT_H264;
|
||||
v->last = -1;
|
||||
v->sock = -1;
|
||||
for (int i = 0; i < VDEC_BUFFERS; i++) v->cap[i].fd = -1;
|
||||
__atomic_add_fetch(&vd_open_count, 1, __ATOMIC_RELEASE);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void vd_close_decoder(struct vdec *v) {
|
||||
if (v->frames) {
|
||||
vd_log("%u frames, %.1f ms each on average, %u over 25 ms", v->frames, v->decode_ms / v->frames, v->slow);
|
||||
}
|
||||
if (v->sock >= 0) close(v->sock);
|
||||
v->sock = -1;
|
||||
v->hw = 0;
|
||||
if (v->ctx) av.free_context(&v->ctx);
|
||||
if (v->packet) av.packet_free(&v->packet);
|
||||
if (v->frame) av.frame_free(&v->frame);
|
||||
free(v->packet_data);
|
||||
v->packet_data = NULL;
|
||||
v->packet_capacity = 0;
|
||||
v->frames = v->slow = 0;
|
||||
v->decode_ms = 0;
|
||||
v->last = -1;
|
||||
}
|
||||
|
||||
static int vd_send(int sock, const void *msg, size_t len, int fd) {
|
||||
struct iovec iov = { .iov_base = (void *)msg, .iov_len = len };
|
||||
char control[CMSG_SPACE(sizeof(int))];
|
||||
struct msghdr m = { .msg_iov = &iov, .msg_iovlen = 1 };
|
||||
if (fd >= 0) {
|
||||
memset(control, 0, sizeof control);
|
||||
m.msg_control = control;
|
||||
m.msg_controllen = sizeof control;
|
||||
struct cmsghdr *c = CMSG_FIRSTHDR(&m);
|
||||
c->cmsg_level = SOL_SOCKET;
|
||||
c->cmsg_type = SCM_RIGHTS;
|
||||
c->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
memcpy(CMSG_DATA(c), &fd, sizeof fd);
|
||||
}
|
||||
return sendmsg(sock, &m, MSG_NOSIGNAL) == (ssize_t)len ? 0 : -1;
|
||||
}
|
||||
|
||||
static void vd_send_capture(struct vdec *v, uint32_t index) {
|
||||
struct vdec_capture c = { .type = VDEC_CAPTURE, .index = index, .size = (uint32_t)v->cap[index].len };
|
||||
if (v->sock >= 0 && v->cap[index].map && vd_send(v->sock, &c, sizeof c, v->cap[index].fd) != 0)
|
||||
vd_log("could not hand capture buffer %u to the app: %s", index, strerror(errno));
|
||||
}
|
||||
|
||||
static int vd_open_hardware(struct vdec *v) {
|
||||
if (v->hw_failed) return -1;
|
||||
int sock = bl_venc_connect();
|
||||
if (sock < 0) return -1;
|
||||
struct vdec_config c = {
|
||||
.type = VDEC_CONFIG, .codec = v->fourcc == V4L2_PIX_FMT_HEVC ? VENC_HEVC : VENC_H264,
|
||||
.width = v->width ? v->width : v->cap_width, .height = v->height ? v->height : v->cap_height,
|
||||
.stride = v->bpl, .rows = v->cap_height, .bitstreams = v->out_count, .bitstream_size = VDEC_BITSTREAM_SIZE,
|
||||
};
|
||||
struct vdec_result r;
|
||||
if (vd_send(sock, &c, sizeof c, v->fd) != 0 || recv(sock, &r, sizeof r, 0) != (ssize_t)sizeof r ||
|
||||
r.type != VDEC_RESULT || r.status != 0) {
|
||||
vd_log("the app has no %s decoder for %ux%u", c.codec == VENC_HEVC ? "HEVC" : "H.264", c.width, c.height);
|
||||
close(sock);
|
||||
v->hw_failed = 1;
|
||||
return -1;
|
||||
}
|
||||
v->sock = sock;
|
||||
v->hw = 1;
|
||||
for (uint32_t i = 0; i < v->cap_count; i++) vd_send_capture(v, i);
|
||||
vd_log("decoding %s %ux%u with the app's MediaCodec into %ux%u NV12 dma-bufs",
|
||||
c.codec == VENC_HEVC ? "HEVC" : "H.264", c.width, c.height, v->cap_width, v->cap_height);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_open_decoder(struct vdec *v) {
|
||||
if (vd_open_hardware(v) == 0) return 0;
|
||||
if (!vd_have_ffmpeg()) return -1;
|
||||
const char *name = v->fourcc == V4L2_PIX_FMT_HEVC ? "hevc" : "h264";
|
||||
const void *codec = av.find_decoder_by_name(name);
|
||||
if (codec == NULL) {
|
||||
vd_log("FFmpeg has no %s decoder", name);
|
||||
return -1;
|
||||
}
|
||||
v->ctx = av.alloc_context3(codec);
|
||||
v->packet = av.packet_alloc();
|
||||
v->frame = av.frame_alloc();
|
||||
void *options = NULL;
|
||||
long cores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
char threads[8];
|
||||
snprintf(threads, sizeof threads, "%ld", cores > 4 ? 4L : cores < 1 ? 1L : cores);
|
||||
av.dict_set(&options, "threads", threads, 0);
|
||||
av.dict_set(&options, "thread_type", "slice", 0);
|
||||
av.dict_set(&options, "flags", "+low_delay", 0);
|
||||
av.dict_set(&options, "flags2", "+fast", 0);
|
||||
int r = v->ctx && v->packet && v->frame ? av.open2(v->ctx, codec, &options) : -1;
|
||||
av.dict_free(&options);
|
||||
if (r < 0) {
|
||||
vd_log("could not open the %s decoder (%d)", name, r);
|
||||
vd_close_decoder(v);
|
||||
return -1;
|
||||
}
|
||||
vd_log("decoding %s %ux%u in software into %ux%u NV12 dma-bufs", v->fourcc == V4L2_PIX_FMT_HEVC ? "HEVC" : "H.264",
|
||||
v->width, v->height, v->cap_width, v->cap_height);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vd_unmap_capture(struct vdec *v) {
|
||||
for (uint32_t i = 0; i < VDEC_BUFFERS; i++) {
|
||||
if (v->cap[i].map) munmap(v->cap[i].map, v->cap[i].len);
|
||||
v->cap[i] = (struct vd_capture){ .fd = -1 };
|
||||
}
|
||||
v->cap_count = v->n_cap_queue = v->n_cap_done = 0;
|
||||
v->last = -1;
|
||||
}
|
||||
|
||||
static void vd_sync(int fd, uint64_t flags) {
|
||||
struct vd_dma_buf_sync s = { .flags = flags | VD_DMA_BUF_SYNC_WRITE };
|
||||
ioctl(fd, VD_DMA_BUF_IOCTL_SYNC, &s);
|
||||
}
|
||||
|
||||
static void vd_blank(struct vdec *v, struct vd_capture *c) {
|
||||
size_t luma = (size_t)v->bpl * v->cap_height;
|
||||
if (luma + luma / 2 > c->len) return;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
memset(c->map, 16, luma);
|
||||
memset(c->map + luma, 128, luma / 2);
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
}
|
||||
|
||||
static int vd_map_capture(struct vdec *v, uint32_t index, int fd) {
|
||||
struct stat st;
|
||||
if (fd < 0 || fstat(fd, &st) != 0) return -EINVAL;
|
||||
struct vd_capture *c = &v->cap[index];
|
||||
if (c->map && c->ino == st.st_ino) {
|
||||
c->fd = fd;
|
||||
return 0;
|
||||
}
|
||||
if (c->map) {
|
||||
munmap(c->map, c->len);
|
||||
*c = (struct vd_capture){ .fd = -1 };
|
||||
if (v->last == (int)index) v->last = -1;
|
||||
}
|
||||
off_t len = lseek(fd, 0, SEEK_END);
|
||||
if (len < (off_t)v->cap_size) return -EINVAL;
|
||||
void *p = mmap(NULL, (size_t)len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
vd_log("could not map capture buffer %u: %s", index, strerror(errno));
|
||||
*c = (struct vd_capture){ .fd = -1 };
|
||||
return -EINVAL;
|
||||
}
|
||||
*c = (struct vd_capture){ .fd = fd, .ino = st.st_ino, .map = p, .len = (size_t)len };
|
||||
vd_blank(v, c);
|
||||
if (v->hw) vd_send_capture(v, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_write_frame(struct vdec *v, struct vd_capture *c) {
|
||||
uint8_t **data = (uint8_t **)v->frame;
|
||||
int *linesize = (int *)((uint8_t *)v->frame + 64);
|
||||
int width = *(int *)((uint8_t *)v->frame + 104), height = *(int *)((uint8_t *)v->frame + 108);
|
||||
const char *format = av.pix_fmt_name(*(int *)((uint8_t *)v->frame + 116));
|
||||
if (format == NULL || width <= 0 || height <= 0) return -1;
|
||||
int nv12 = strcmp(format, "nv12") == 0;
|
||||
if (!nv12 && strcmp(format, "yuv420p") != 0 && strcmp(format, "yuvj420p") != 0) {
|
||||
static int warned;
|
||||
if (!warned++) vd_log("cannot show %s frames", format);
|
||||
return -1;
|
||||
}
|
||||
uint32_t w = (uint32_t)width < v->bpl ? (uint32_t)width : v->bpl;
|
||||
uint32_t h = (uint32_t)height < v->cap_height ? (uint32_t)height : v->cap_height;
|
||||
uint8_t *y = c->map, *uv = c->map + (size_t)v->bpl * v->cap_height;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
for (uint32_t row = 0; row < h; row++) memcpy(y + (size_t)row * v->bpl, data[0] + (size_t)row * linesize[0], w);
|
||||
for (uint32_t row = 0; row < (h + 1) / 2; row++) {
|
||||
uint8_t *dst = uv + (size_t)row * v->bpl;
|
||||
if (nv12) {
|
||||
memcpy(dst, data[1] + (size_t)row * linesize[1], w & ~1u);
|
||||
continue;
|
||||
}
|
||||
const uint8_t *u = data[1] + (size_t)row * linesize[1], *vv = data[2] + (size_t)row * linesize[2];
|
||||
for (uint32_t x = 0; x < w / 2; x++) {
|
||||
dst[2 * x] = u[x];
|
||||
dst[2 * x + 1] = vv[x];
|
||||
}
|
||||
}
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vd_copy_last(struct vdec *v, struct vd_capture *c) {
|
||||
if (v->last < 0 || v->cap[v->last].map == NULL || &v->cap[v->last] == c) return;
|
||||
size_t size = v->cap_size < c->len ? v->cap_size : c->len;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
memcpy(c->map, v->cap[v->last].map, size);
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
}
|
||||
|
||||
static double vd_now_ms(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ts.tv_sec * 1000.0 + ts.tv_nsec / 1e6;
|
||||
}
|
||||
|
||||
static void vd_deliver(struct vdec *v, int written, double start, struct timeval timestamp) {
|
||||
uint32_t target = v->cap_queue[0];
|
||||
if (!written) {
|
||||
if (v->last < 0) return;
|
||||
vd_copy_last(v, &v->cap[target]);
|
||||
}
|
||||
double ms = vd_now_ms() - start;
|
||||
v->frames++;
|
||||
v->decode_ms += ms;
|
||||
if (ms > 25.0) v->slow++;
|
||||
memmove(v->cap_queue, v->cap_queue + 1, --v->n_cap_queue * sizeof v->cap_queue[0]);
|
||||
v->cap_done[v->n_cap_done++] = (struct vd_done){ .index = target, .timestamp = timestamp };
|
||||
v->last = (int)target;
|
||||
}
|
||||
|
||||
static void vd_decode_hardware(struct vdec *v, uint32_t index, uint32_t bytes, struct timeval timestamp) {
|
||||
double start = vd_now_ms();
|
||||
v->pts += 16667;
|
||||
struct vdec_packet p = { .type = VDEC_PACKET, .input = index, .bytes = bytes, .capture = v->cap_queue[0], .pts_us = v->pts };
|
||||
struct vdec_result r;
|
||||
if (vd_send(v->sock, &p, sizeof p, -1) != 0 || recv(v->sock, &r, sizeof r, 0) != (ssize_t)sizeof r ||
|
||||
r.type != VDEC_RESULT) {
|
||||
vd_log("lost the app's decoder (%s), switching to software", strerror(errno));
|
||||
vd_close_decoder(v);
|
||||
v->hw_failed = 1;
|
||||
return;
|
||||
}
|
||||
vd_deliver(v, r.status == 0 && r.frame, start, timestamp);
|
||||
}
|
||||
|
||||
static void vd_decode(struct vdec *v, uint32_t index, uint32_t bytes, struct timeval timestamp) {
|
||||
if (!v->cap_on || v->n_cap_queue == 0) return;
|
||||
if (v->ctx == NULL && !v->hw && vd_open_decoder(v) != 0) return;
|
||||
if (v->hw) {
|
||||
vd_decode_hardware(v, index, bytes, timestamp);
|
||||
return;
|
||||
}
|
||||
if (v->packet_capacity < bytes + VDEC_PADDING) {
|
||||
free(v->packet_data);
|
||||
v->packet_capacity = bytes + VDEC_PADDING + (64u << 10);
|
||||
v->packet_data = malloc(v->packet_capacity);
|
||||
if (v->packet_data == NULL) {
|
||||
v->packet_capacity = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
memcpy(v->packet_data, v->bitstream + (size_t)index * VDEC_BITSTREAM_SIZE, bytes);
|
||||
memset(v->packet_data + bytes, 0, VDEC_PADDING);
|
||||
*(uint8_t **)((uint8_t *)v->packet + 24) = v->packet_data;
|
||||
*(int *)((uint8_t *)v->packet + 32) = (int)bytes;
|
||||
double start = vd_now_ms();
|
||||
uint32_t target = v->cap_queue[0];
|
||||
struct vd_capture *c = &v->cap[target];
|
||||
int written = 0;
|
||||
if (av.send_packet(v->ctx, v->packet) >= 0) {
|
||||
while (av.receive_frame(v->ctx, v->frame) >= 0) {
|
||||
if (vd_write_frame(v, c) == 0) written = 1;
|
||||
av.frame_unref(v->frame);
|
||||
}
|
||||
}
|
||||
*(uint8_t **)((uint8_t *)v->packet + 24) = NULL;
|
||||
*(int *)((uint8_t *)v->packet + 32) = 0;
|
||||
vd_deliver(v, written, start, timestamp);
|
||||
}
|
||||
|
||||
static int is_output(uint32_t type) { return type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || type == V4L2_BUF_TYPE_VIDEO_OUTPUT; }
|
||||
static int is_capture(uint32_t type) { return type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || type == V4L2_BUF_TYPE_VIDEO_CAPTURE; }
|
||||
|
||||
static void vd_fill_format(struct vdec *v, struct v4l2_format *f) {
|
||||
struct v4l2_pix_format_mplane *p = &f->fmt.pix_mp;
|
||||
memset(p, 0, sizeof *p);
|
||||
p->field = V4L2_FIELD_NONE;
|
||||
p->num_planes = 1;
|
||||
p->colorspace = V4L2_COLORSPACE_REC709;
|
||||
if (is_output(f->type)) {
|
||||
p->width = v->width;
|
||||
p->height = v->height;
|
||||
p->pixelformat = v->fourcc;
|
||||
p->plane_fmt[0].sizeimage = VDEC_BITSTREAM_SIZE;
|
||||
} else {
|
||||
p->width = v->cap_width;
|
||||
p->height = v->cap_height;
|
||||
p->pixelformat = V4L2_PIX_FMT_NV12;
|
||||
p->plane_fmt[0].bytesperline = v->bpl;
|
||||
p->plane_fmt[0].sizeimage = v->cap_size;
|
||||
}
|
||||
}
|
||||
|
||||
static int vd_set_format(struct vdec *v, struct v4l2_format *f, int apply) {
|
||||
struct v4l2_pix_format_mplane *p = &f->fmt.pix_mp;
|
||||
if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) return -EINVAL;
|
||||
struct vdec t = *v;
|
||||
if (is_output(f->type)) {
|
||||
if (p->pixelformat != V4L2_PIX_FMT_H264 && p->pixelformat != V4L2_PIX_FMT_HEVC) return -EINVAL;
|
||||
t.fourcc = p->pixelformat;
|
||||
t.width = p->width;
|
||||
t.height = p->height;
|
||||
} else {
|
||||
uint32_t w = p->width > t.width ? p->width : t.width, h = p->height > t.height ? p->height : t.height;
|
||||
if (w < 16 || h < 16 || w > 8192 || h > 8192) return -EINVAL;
|
||||
t.cap_width = (w + 15) & ~15u;
|
||||
t.cap_height = (h + 15) & ~15u;
|
||||
t.bpl = t.cap_width;
|
||||
t.cap_size = t.bpl * t.cap_height * 3 / 2;
|
||||
}
|
||||
if (apply) {
|
||||
if (t.fourcc != v->fourcc || (t.hw && (t.bpl != v->bpl || t.cap_height != v->cap_height))) vd_close_decoder(&t);
|
||||
*v = t;
|
||||
}
|
||||
vd_fill_format(&t, f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_reqbufs(struct vdec *v, struct v4l2_requestbuffers *r) {
|
||||
uint32_t n = r->count > VDEC_BUFFERS ? VDEC_BUFFERS : r->count;
|
||||
if (r->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && r->memory == V4L2_MEMORY_MMAP) {
|
||||
if (v->bitstream) munmap(v->bitstream, (size_t)v->out_count * VDEC_BITSTREAM_SIZE);
|
||||
v->bitstream = NULL;
|
||||
v->out_count = v->n_out_done = 0;
|
||||
if (n && ftruncate(v->fd, (off_t)n * VDEC_BITSTREAM_SIZE) != 0) return -ENOMEM;
|
||||
if (n) {
|
||||
void *p = mmap(NULL, (size_t)n * VDEC_BITSTREAM_SIZE, PROT_READ, MAP_SHARED, v->fd, 0);
|
||||
if (p == MAP_FAILED) return -ENOMEM;
|
||||
v->bitstream = p;
|
||||
}
|
||||
v->out_count = n;
|
||||
} else if (r->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && r->memory == V4L2_MEMORY_DMABUF) {
|
||||
if (v->hw) vd_close_decoder(v);
|
||||
vd_unmap_capture(v);
|
||||
v->cap_count = n;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
r->count = n;
|
||||
r->capabilities = r->memory == V4L2_MEMORY_MMAP ? V4L2_BUF_CAP_SUPPORTS_MMAP : V4L2_BUF_CAP_SUPPORTS_DMABUF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_querybuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || b->index >= v->out_count || b->m.planes == NULL || b->length < 1)
|
||||
return -EINVAL;
|
||||
b->memory = V4L2_MEMORY_MMAP;
|
||||
b->flags = V4L2_BUF_FLAG_MAPPED;
|
||||
b->length = 1;
|
||||
b->m.planes[0].length = VDEC_BITSTREAM_SIZE;
|
||||
b->m.planes[0].m.mem_offset = b->index * VDEC_BITSTREAM_SIZE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_qbuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->m.planes == NULL || b->length < 1) return -EINVAL;
|
||||
if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
||||
if (b->index >= v->out_count || v->n_out_done >= VDEC_BUFFERS) return -EINVAL;
|
||||
uint32_t bytes = b->m.planes[0].bytesused;
|
||||
if (bytes > VDEC_BITSTREAM_SIZE) bytes = VDEC_BITSTREAM_SIZE;
|
||||
if (v->out_on && bytes) vd_decode(v, b->index, bytes, b->timestamp);
|
||||
v->out_done[v->n_out_done++] = b->index;
|
||||
} else if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
|
||||
if (b->index >= v->cap_count || v->cap_size == 0) return -EINVAL;
|
||||
int r = vd_map_capture(v, b->index, b->m.planes[0].m.fd);
|
||||
if (r < 0) return r;
|
||||
for (uint32_t i = 0; i < v->n_cap_queue; i++) if (v->cap_queue[i] == b->index) return 0;
|
||||
if (v->n_cap_queue >= VDEC_BUFFERS) return -EINVAL;
|
||||
v->cap_queue[v->n_cap_queue++] = b->index;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
b->flags |= V4L2_BUF_FLAG_QUEUED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_dqbuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->m.planes == NULL || b->length < 1) return -EINVAL;
|
||||
if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
||||
if (v->n_out_done == 0) return -EAGAIN;
|
||||
b->index = v->out_done[0];
|
||||
memmove(v->out_done, v->out_done + 1, --v->n_out_done * sizeof v->out_done[0]);
|
||||
b->memory = V4L2_MEMORY_MMAP;
|
||||
b->flags = V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_MAPPED;
|
||||
b->length = 1;
|
||||
b->m.planes[0].bytesused = 0;
|
||||
b->m.planes[0].length = VDEC_BITSTREAM_SIZE;
|
||||
b->m.planes[0].m.mem_offset = b->index * VDEC_BITSTREAM_SIZE;
|
||||
return 0;
|
||||
}
|
||||
if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) return -EINVAL;
|
||||
if (v->n_cap_done == 0) return -EAGAIN;
|
||||
struct vd_done d = v->cap_done[0];
|
||||
memmove(v->cap_done, v->cap_done + 1, --v->n_cap_done * sizeof d);
|
||||
b->index = d.index;
|
||||
b->memory = V4L2_MEMORY_DMABUF;
|
||||
b->flags = V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_TIMESTAMP_COPY;
|
||||
b->field = V4L2_FIELD_NONE;
|
||||
b->timestamp = d.timestamp;
|
||||
b->length = 1;
|
||||
b->m.planes[0].bytesused = v->cap_size;
|
||||
b->m.planes[0].length = v->cap_size;
|
||||
b->m.planes[0].m.fd = v->cap[d.index].fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_ioctl(struct vdec *v, unsigned long req, void *arg) {
|
||||
switch (req) {
|
||||
case VIDIOC_QUERYCAP: {
|
||||
struct v4l2_capability *c = arg;
|
||||
memset(c, 0, sizeof *c);
|
||||
strcpy((char *)c->driver, "droiddeck_vdec");
|
||||
strcpy((char *)c->card, "DroidDeck video decoder");
|
||||
strcpy((char *)c->bus_info, "platform:droiddeck-vdec");
|
||||
c->version = 0x00060000;
|
||||
c->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
|
||||
c->capabilities = c->device_caps | V4L2_CAP_DEVICE_CAPS;
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_ENUM_FMT: {
|
||||
struct v4l2_fmtdesc *d = arg;
|
||||
static const uint32_t coded[] = { V4L2_PIX_FMT_H264, V4L2_PIX_FMT_HEVC };
|
||||
if (is_capture(d->type) && d->index == 0) {
|
||||
d->pixelformat = V4L2_PIX_FMT_NV12;
|
||||
strcpy((char *)d->description, "Y/CbCr 4:2:0");
|
||||
d->flags = 0;
|
||||
} else if (is_output(d->type) && d->index < 2) {
|
||||
d->pixelformat = coded[d->index];
|
||||
strcpy((char *)d->description, d->index ? "HEVC" : "H.264");
|
||||
d->flags = V4L2_FMT_FLAG_COMPRESSED;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_G_FMT: {
|
||||
struct v4l2_format *f = arg;
|
||||
if (!is_output(f->type) && !is_capture(f->type)) return -EINVAL;
|
||||
vd_fill_format(v, f);
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_S_FMT: return vd_set_format(v, arg, 1);
|
||||
case VIDIOC_TRY_FMT: return vd_set_format(v, arg, 0);
|
||||
case VIDIOC_REQBUFS: return vd_reqbufs(v, arg);
|
||||
case VIDIOC_QUERYBUF: return vd_querybuf(v, arg);
|
||||
case VIDIOC_QBUF: return vd_qbuf(v, arg);
|
||||
case VIDIOC_DQBUF: return vd_dqbuf(v, arg);
|
||||
case VIDIOC_STREAMON:
|
||||
case VIDIOC_STREAMOFF: {
|
||||
uint32_t type = *(uint32_t *)arg;
|
||||
int on = req == VIDIOC_STREAMON;
|
||||
if (is_output(type)) {
|
||||
v->out_on = on;
|
||||
if (!on) {
|
||||
v->n_out_done = 0;
|
||||
if (v->ctx) av.flush_buffers(v->ctx);
|
||||
}
|
||||
} else if (is_capture(type)) {
|
||||
v->cap_on = on;
|
||||
if (!on) v->n_cap_queue = v->n_cap_done = 0;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (v->out_on && v->cap_on && v->ctx == NULL && !v->hw && v->out_count && v->cap_size) vd_open_decoder(v);
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_SUBSCRIBE_EVENT:
|
||||
case VIDIOC_UNSUBSCRIBE_EVENT:
|
||||
case VIDIOC_DECODER_CMD:
|
||||
case VIDIOC_TRY_DECODER_CMD:
|
||||
return 0;
|
||||
case VIDIOC_DQEVENT:
|
||||
return -ENOENT;
|
||||
default:
|
||||
vd_log("unhandled ioctl 0x%lx", req);
|
||||
return -ENOTTY;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
struct vdec *v = vd_find(fd);
|
||||
if (v == NULL) return 0;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
int r = arg ? vd_ioctl(v, req, arg) : -EFAULT;
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
if (r < 0) {
|
||||
errno = -r;
|
||||
*rc = -1;
|
||||
} else {
|
||||
*rc = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) void bl_vdec_closed(int fd) {
|
||||
struct vdec *v = vd_find(fd);
|
||||
if (v == NULL) return;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
vd_close_decoder(v);
|
||||
vd_unmap_capture(v);
|
||||
if (v->bitstream) munmap(v->bitstream, (size_t)v->out_count * VDEC_BITSTREAM_SIZE);
|
||||
v->bitstream = NULL;
|
||||
v->used = 0;
|
||||
__atomic_sub_fetch(&vd_open_count, 1, __ATOMIC_RELEASE);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret) {
|
||||
if (n != 1 || vd_find(fds[0].fd) == NULL) return 0;
|
||||
struct vdec *v = vd_find(fds[0].fd);
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
short ready = (v->n_cap_done ? POLLIN | POLLRDNORM : 0) | (v->n_out_done ? POLLOUT | POLLWRNORM : 0);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
fds[0].revents = ready & fds[0].events;
|
||||
if (fds[0].revents == 0 && timeout_ms != 0) real(NULL, 0, timeout_ms < 0 || timeout_ms > 1000 ? 1000 : timeout_ms);
|
||||
*ret = fds[0].revents ? 1 : 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int drm_get_devices2(uint32_t flags, struct vd_device **devices, int max) {
|
||||
(void)flags;
|
||||
static char *nodes[3] = { "/dev/null", NULL, NULL };
|
||||
static struct vd_device device = { .nodes = nodes, .available_nodes = 1 };
|
||||
if (devices == NULL || max < 1) return 1;
|
||||
devices[0] = &device;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void drm_free_devices(struct vd_device **devices, int count) { (void)devices; (void)count; }
|
||||
|
||||
static struct vd_mode_info drm_mode = {
|
||||
.clock = 148500, .hdisplay = 1920, .hsync_start = 2008, .hsync_end = 2052, .htotal = 2200,
|
||||
.vdisplay = 1080, .vsync_start = 1084, .vsync_end = 1089, .vtotal = 1125, .vrefresh = 60, .name = "1920x1080",
|
||||
};
|
||||
static uint32_t drm_crtc_ids[1] = { 1 }, drm_connector_ids[1] = { 2 }, drm_encoder_ids[1] = { 3 };
|
||||
|
||||
static struct vd_res *drm_get_resources(int fd) {
|
||||
(void)fd;
|
||||
static struct vd_res res = {
|
||||
.count_crtcs = 1, .crtcs = drm_crtc_ids, .count_connectors = 1, .connectors = drm_connector_ids,
|
||||
.count_encoders = 1, .encoders = drm_encoder_ids, .max_width = 8192, .max_height = 8192,
|
||||
};
|
||||
return &res;
|
||||
}
|
||||
|
||||
static struct vd_connector *drm_get_connector(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_connector connector = {
|
||||
.connector_id = 2, .encoder_id = 3, .connector_type = 14, .connection = 1, .count_modes = 1,
|
||||
.modes = &drm_mode, .count_encoders = 1, .encoders = drm_encoder_ids,
|
||||
};
|
||||
return id == 2 ? &connector : NULL;
|
||||
}
|
||||
|
||||
static struct vd_encoder *drm_get_encoder(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_encoder encoder = { .encoder_id = 3, .encoder_type = 8, .crtc_id = 1, .possible_crtcs = 1 };
|
||||
return id == 3 ? &encoder : NULL;
|
||||
}
|
||||
|
||||
static struct vd_crtc *drm_get_crtc(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_crtc crtc;
|
||||
if (id != 1) return NULL;
|
||||
crtc = (struct vd_crtc){ .crtc_id = 1, .width = 1920, .height = 1080, .mode_valid = 1, .mode = drm_mode };
|
||||
return &crtc;
|
||||
}
|
||||
|
||||
static void drm_free(void *p) { (void)p; }
|
||||
static void *drm_null(void) { return NULL; }
|
||||
static int drm_fail(void) { return -EINVAL; }
|
||||
|
||||
static int drm_dumb_slot(uint32_t handle) { return handle >= 1 && handle <= VDEC_DUMB ? (int)handle - 1 : -1; }
|
||||
|
||||
static int drm_ioctl(int fd, unsigned long request, void *arg) {
|
||||
(void)fd;
|
||||
int r = -EINVAL;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
if (request == VD_IOCTL_MODE_CREATE_DUMB && arg) {
|
||||
struct vd_create_dumb *c = arg;
|
||||
uint64_t pitch = ((uint64_t)c->width * c->bpp + 7) / 8;
|
||||
uint64_t size = (pitch * c->height + 4095) & ~4095ull;
|
||||
int slot = -1;
|
||||
for (int i = 0; i < VDEC_DUMB && slot < 0; i++) if (vd_dumb_fd[i] < 0) slot = i;
|
||||
struct vd_dma_heap_alloc a = { .len = size, .fd_flags = O_RDWR | O_CLOEXEC };
|
||||
if (slot < 0 || size == 0 || size > (512ull << 20)) {
|
||||
r = -ENOMEM;
|
||||
} else if (ioctl(vd_heap, VD_DMA_HEAP_IOCTL_ALLOC, &a) != 0) {
|
||||
r = -errno;
|
||||
vd_log("dma-heap allocation of %llu bytes failed: %s", (unsigned long long)size, strerror(errno));
|
||||
} else {
|
||||
vd_dumb_fd[slot] = (int)a.fd;
|
||||
c->handle = (uint32_t)slot + 1;
|
||||
c->pitch = (uint32_t)pitch;
|
||||
c->size = size;
|
||||
r = 0;
|
||||
}
|
||||
} else if (request == VD_IOCTL_PRIME_HANDLE_TO_FD && arg) {
|
||||
struct vd_prime_handle *h = arg;
|
||||
int slot = drm_dumb_slot(h->handle);
|
||||
int dup_fd = slot >= 0 && vd_dumb_fd[slot] >= 0 ? fcntl(vd_dumb_fd[slot], F_DUPFD_CLOEXEC, 0) : -1;
|
||||
if (dup_fd >= 0) {
|
||||
h->fd = dup_fd;
|
||||
r = 0;
|
||||
} else {
|
||||
r = slot >= 0 ? -errno : -ENOENT;
|
||||
}
|
||||
} else if (request == VD_IOCTL_MODE_DESTROY_DUMB && arg) {
|
||||
int slot = drm_dumb_slot(((struct vd_destroy_dumb *)arg)->handle);
|
||||
if (slot >= 0 && vd_dumb_fd[slot] >= 0) {
|
||||
close(vd_dumb_fd[slot]);
|
||||
vd_dumb_fd[slot] = -1;
|
||||
r = 0;
|
||||
} else {
|
||||
r = -ENOENT;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
if (r < 0) {
|
||||
errno = -r;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
void *fn;
|
||||
} drm_table[] = {
|
||||
{ "drmGetDevices2", (void *)drm_get_devices2 },
|
||||
{ "drmFreeDevices", (void *)drm_free_devices },
|
||||
{ "drmSetMaster", (void *)drm_fail },
|
||||
{ "drmSetClientCap", (void *)drm_fail },
|
||||
{ "drmModeGetResources", (void *)drm_get_resources },
|
||||
{ "drmModeFreeResources", (void *)drm_free },
|
||||
{ "drmModeGetConnector", (void *)drm_get_connector },
|
||||
{ "drmModeFreeConnector", (void *)drm_free },
|
||||
{ "drmModeGetEncoder", (void *)drm_get_encoder },
|
||||
{ "drmModeFreeEncoder", (void *)drm_free },
|
||||
{ "drmModeGetCrtc", (void *)drm_get_crtc },
|
||||
{ "drmModeSetCrtc", (void *)drm_fail },
|
||||
{ "drmModeFreeCrtc", (void *)drm_free },
|
||||
{ "drmModeGetPlaneResources", (void *)drm_null },
|
||||
{ "drmModeFreePlaneResources", (void *)drm_free },
|
||||
{ "drmModeGetPlane", (void *)drm_null },
|
||||
{ "drmModeFreePlane", (void *)drm_free },
|
||||
{ "drmModeObjectGetProperties", (void *)drm_null },
|
||||
{ "drmModeFreeObjectProperties", (void *)drm_free },
|
||||
{ "drmModeGetProperty", (void *)drm_null },
|
||||
{ "drmModeFreeProperty", (void *)drm_free },
|
||||
{ "drmModeAddFB2", (void *)drm_fail },
|
||||
{ "drmModeAddFB2WithModifiers", (void *)drm_fail },
|
||||
{ "drmModeRmFB", (void *)drm_fail },
|
||||
{ "drmModeAtomicAlloc", (void *)drm_null },
|
||||
{ "drmModeAtomicFree", (void *)drm_free },
|
||||
{ "drmModeAtomicAddProperty", (void *)drm_fail },
|
||||
{ "drmModeAtomicCommit", (void *)drm_fail },
|
||||
{ "drmIoctl", (void *)drm_ioctl },
|
||||
};
|
||||
|
||||
void *SDL_LoadObject(const char *name) {
|
||||
static void *(*real)(const char *);
|
||||
if (name && strcmp(name, "libdrm.so.2") == 0 && vd_enabled()) return &vd_drm_handle;
|
||||
if (!real) real = (void *(*)(const char *))dlsym(RTLD_NEXT, "SDL_LoadObject");
|
||||
return real ? real(name) : NULL;
|
||||
}
|
||||
|
||||
void *SDL_LoadFunction(void *handle, const char *name) {
|
||||
static void *(*real)(void *, const char *);
|
||||
if (handle == &vd_drm_handle) {
|
||||
for (size_t i = 0; name && i < sizeof drm_table / sizeof drm_table[0]; i++)
|
||||
if (strcmp(drm_table[i].name, name) == 0) return drm_table[i].fn;
|
||||
return NULL;
|
||||
}
|
||||
if (!real) real = (void *(*)(void *, const char *))dlsym(RTLD_NEXT, "SDL_LoadFunction");
|
||||
return real ? real(handle, name) : NULL;
|
||||
}
|
||||
|
||||
void SDL_UnloadObject(void *handle) {
|
||||
static void (*real)(void *);
|
||||
if (handle == &vd_drm_handle) return;
|
||||
if (!real) real = (void (*)(void *))dlsym(RTLD_NEXT, "SDL_UnloadObject");
|
||||
if (real) real(handle);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_open(const char *path, int flags) {
|
||||
(void)path;
|
||||
(void)flags;
|
||||
return -2;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
(void)fd;
|
||||
(void)req;
|
||||
(void)arg;
|
||||
(void)rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) void bl_vdec_closed(int fd) { (void)fd; }
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret) {
|
||||
(void)fds;
|
||||
(void)n;
|
||||
(void)timeout_ms;
|
||||
(void)real;
|
||||
(void)ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,3 @@
|
||||
/* /dev/video-enc0 for Steam's Remote Play V4L2 encoder stage, backed by the app's MediaCodec encoder. */
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -587,7 +586,6 @@ __attribute__((visibility("hidden"))) void bl_venc_closed(int fd) {
|
||||
vn_free_queue(&v->raw);
|
||||
vn_free_queue(&v->coded);
|
||||
v->used = 0;
|
||||
/* A forked child closing its inherited copy must not end the stream for the parent. */
|
||||
if (__atomic_sub_fetch(&vn_open_count, 1, __ATOMIC_RELEASE) == 0 && v->owner == getpid()) vn_marker(0);
|
||||
pthread_mutex_unlock(&vn_lock);
|
||||
}
|
||||
@@ -625,9 +623,14 @@ static int vn_poll(struct pollfd *fds, nfds_t n, int timeout_ms, int (*real)(str
|
||||
return r + ready;
|
||||
}
|
||||
|
||||
__attribute__((weak, visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret);
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t n, int timeout_ms) {
|
||||
static int (*real)(struct pollfd *, nfds_t, int);
|
||||
if (!real) real = (int (*)(struct pollfd *, nfds_t, int))dlsym(RTLD_NEXT, "poll");
|
||||
int ret;
|
||||
if (bl_vdec_poll && bl_vdec_poll(fds, n, timeout_ms, real, &ret)) return ret;
|
||||
if (__atomic_load_n(&vn_open_count, __ATOMIC_ACQUIRE) == 0) return real(fds, n, timeout_ms);
|
||||
return vn_poll(fds, n, timeout_ms, real);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef WEBHELPER_DEFAULT
|
||||
#define WEBHELPER_DEFAULT "--no-zygote --in-process-gpu -AudioServiceOutOfProcess"
|
||||
@@ -25,8 +26,30 @@ static char *join_features(const char *have, const char *add) {
|
||||
return strcat(out, add);
|
||||
}
|
||||
|
||||
static char *const *chromium_argv(const char *path, char *const argv[]) {
|
||||
const char *slash = path ? strrchr(path, '/') : NULL;
|
||||
if (!slash || !argv || !argv[0]) return argv;
|
||||
int argc = 0;
|
||||
for (; argv[argc]; argc++)
|
||||
if (argc && (!strncmp(argv[argc], "--type=", 7) || !strcmp(argv[argc], "--no-sandbox"))) return argv;
|
||||
size_t dir = (size_t)(slash - path) + 1;
|
||||
char *sandbox = malloc(dir + sizeof "chrome-sandbox");
|
||||
if (!sandbox) return argv;
|
||||
memcpy(sandbox, path, dir);
|
||||
strcpy(sandbox + dir, "chrome-sandbox");
|
||||
int chromium = access(sandbox, F_OK) == 0;
|
||||
free(sandbox);
|
||||
if (!chromium) return argv;
|
||||
char **out = calloc((size_t)argc + 2, sizeof *out);
|
||||
if (!out) return argv;
|
||||
out[0] = argv[0];
|
||||
out[1] = (char *)"--no-sandbox";
|
||||
for (int i = 1; i < argc; i++) out[i + 1] = argv[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]) {
|
||||
if (!is_webhelper_browser(path, argv)) return argv;
|
||||
if (!is_webhelper_browser(path, argv)) return chromium_argv(path, argv);
|
||||
const char *spec = getenv("BL_WEBHELPER_ARGS");
|
||||
if (!spec || !*spec) spec = WEBHELPER_DEFAULT;
|
||||
if (!strcmp(spec, "stock")) return argv;
|
||||
|
||||
@@ -126,8 +126,6 @@ static void zr_walk(int compress) {
|
||||
zr_sys(SYS_close, maps);
|
||||
}
|
||||
|
||||
// Before it stops a session for suspend, the app waits for <ZR_CTL>.ack.<pid> to appear (the handler
|
||||
// runs here, not one a program installed over it) and then to hold a byte (the page-out finished).
|
||||
static void zr_ack(int done) {
|
||||
static const char suffix[] = ".ack.";
|
||||
char path[sizeof(ZR_CTL) + sizeof(suffix) + 20];
|
||||
|
||||
Reference in new issue
Block a user