feat(bionic): DroidDeck-Bionic compatibility tool (Wine on Android's libc, no proot) (#3037)

DroidDeck-Bionic: a Steam compatibility tool that runs the game itself on Android's libc (bionic) instead of glibc inside proot. Steam, the stores and the session stay on DroidDeck's Linux side; only the game process leaves proot.

- Listed in the Proton list only when Run without proot is on, in its own row. Its builds are pre-releases on Droid-Deck/DroidDeck-Proton (DroidDeck-Bionic-12.8-rNN, runtime built by .github/workflows/build-bionic-runtime.yml from tools/bionic-runtime); the app installs and updates them like the other extra tools and never makes one the default unless the user picks it.
- With proot on, a launch sent to a bionic tool goes to the newest DroidDeck-Proton (picks stay as set).
- ProtonExtras / ProtonMenu / ExperimentalProtons / droiddeck-proton-extra: bionic pre-releases checked and listed only without proot; updates carry the default and per-game picks over; deleting a tool never follows links out of it. ProtonDefault: picks left on an older bionic build move to the installed one.
- Components: FEX builds for bionic (bionic-stable on DroidDeck-Components); each tool is offered only the FEX builds that fit it.
- Session logs: the bionic game log and its graphics logs are part of Share logs.

Synced with main twice before the merge (latest sync fbed69ce on main 67b82ad9; Build APK and validation green); a local trial merge on main 3e1fc3e6 had no conflicts and the game-environment, Proton-extra and store-launch tests pass.
This commit is contained in:
The412Banner authored and GitHub committed 2026-11-24 23:39:23 +00:00
1 parent 3e1fc3e60e
commit 9e6f81540f
49 files changed
+3459 -84

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
DroidDeck bionic runtime pack: sources, credits and licences
Built by DroidDeck's CI with tools/bionic-runtime/build.sh (GPL-3.0, like DroidDeck). Exact pins and the
sha256 of every file are in MANIFEST.txt.
Built from source in this pack:
- layer/libVkLayer_FROG_gamescope_wsi_aarch64.so: gamescope's Vulkan WSI layer (Valve Corporation, BSD-2-Clause,
https://github.com/ValveSoftware/gamescope) at the pinned tag with DroidDeck's patches 0117 and 0119
(tools/gamescope/patches), using vkroots by Joshua Ashton (vkroots.h: Apache-2.0 OR MIT,
https://github.com/Joshua-Ashton/vkroots) and the Khronos Vulkan-Headers (Apache-2.0 / MIT).
- preload/libfakeinput.so: DroidDeck's app/src/main/cpp/fakeinput_steam.cpp, taken from WinNative by maxjivi05
(GPL-3.0, https://github.com/WinNative-Emu/WinNative), mmap ring controller input by ribbit384 (WinNative #345).
- preload/libnotag.so, bin/gstag: DroidDeck (GPL-3.0).
- layer/libVkLayer_droiddeck_gpuload.so: DroidDeck's HUD GPU-load Vulkan layer (tools/gpuload, GPL-3.0), built for the
bionic userland.
Taken unchanged from The412Banner's Bannerlator (GPL-3.0, https://github.com/The412Banner/Bannerlator):
- lib/: Android builds of open-source libraries from Bannerlator's base imagefs
(https://github.com/The412Banner/winlator-contents, release base-assets-v1), among them X.Org libX11/libXext/...
and libxcb (MIT/X11), Wayland (MIT), SDL2 (zlib), GStreamer and its plugins, GLib, PulseAudio, GnuTLS, libsndfile,
alsa-lib, libiconv (LGPL-2.1 or later), FreeType (FTL or GPL-2.0), Fontconfig (MIT), libxml2 (MIT), libffi (MIT),
PCRE2 (BSD-3-Clause), zlib (zlib), and FFmpeg 8 libraries (LGPL-2.1 or later) from Bannerlator's ffmpeg8.tzst.
share/X11 and etc/ (fonts, tls) come from the same imagefs.
From The412Banner/Banners-Turnip (https://github.com/The412Banner/Banners-Turnip, release
fastgl-x11egl-mesa-d8cfbe8-r1):
- egl/: Mesa (MIT, https://gitlab.freedesktop.org/mesa/mesa) EGL, GLX and Gallium with Zink at Mesa main d8cfbe82766,
built for the bionic userland with the x11 and wayland platforms (branch fix/fastgl-zink-readback, the
exp/egl-x11-platform recipe that builds Bannerlator's Fast OpenGL set), with libwayland-client (MIT) and libarchive
(BSD-2-Clause); egl/x11egl.json records the build. Newer Mesa brings Zink's kopper front-buffer readback fixes by
Mike Blumenkrantz.
From The412Banner/bionic-vulkan-wrapper (https://github.com/The412Banner/bionic-vulkan-wrapper, release
wayland-adapter-placed-export-r1):
- adapter/libvulkan_wrapper.so: the Wayland adapter Bannerlator ships (branch banner/wayland-wsi-bgra-native) plus
placed-mapping fixes for 32-bit OpenGL / WineD3D (branch banner/wayland-wsi-placed-export), a Mesa tree (MIT) in
the line of Pipetto-crypto's wrapper and leegao's bionic Vulkan wrapper. adapter/adapter.json records the build.
Taken unchanged from DroidDeck-Proton (https://github.com/Droid-Deck/DroidDeck-Proton, release DroidDeck-Proton-11-12.8):
- d7vk/ddraw.dll: D7VK by WinterSnowfall (zlib, https://github.com/WinterSnowfall/d7vk, commit 06656b9e), Direct3D 7
and older on Vulkan, based on DXVK by Philip Rebohle and contributors (zlib, https://github.com/doitsujin/dxvk);
32-bit build from DroidDeck-Proton's CI.
Not in this pack: the bionic DroidDeck-Proton layer (The412Banner/proton-wine releases), GPU drivers, DXVK/VKD3D
and FEX (DroidDeck components).
@@ -0,0 +1,14 @@
{
"file_format_version" : "1.0.0",
"layer" : {
"name": "VK_LAYER_FROG_gamescope_wsi_aarch64",
"type": "GLOBAL",
"api_version": "1.3.221",
"library_path": "./libVkLayer_FROG_gamescope_wsi_aarch64.so",
"implementation_version": "1",
"description": "Gamescope WSI (XWayland Bypass) Layer (aarch64), bionic build",
"functions": { "vkNegotiateLoaderLayerInterfaceVersion": "vkNegotiateLoaderLayerInterfaceVersion" },
"enable_environment": { "ENABLE_GAMESCOPE_WSI": "1" },
"disable_environment": { "DISABLE_GAMESCOPE_WSI": "1" }
}
}
+9
View File
@@ -0,0 +1,9 @@
// glibc's program_invocation_name is __progname in Android's libc (exported, set from argv[0]).
#pragma once
#ifdef __cplusplus
extern "C" char *__progname;
#else
extern char *__progname;
#endif
#define program_invocation_name __progname
#define program_invocation_short_name __progname
+272
View File
@@ -0,0 +1,272 @@
#!/usr/bin/env bash
# Builds DroidDeck's bionic runtime pack: the Android-side (bionic libc) pieces a bionic DroidDeck-Proton layer
# needs inside DroidDeck's gamescope session. The Proton layer itself comes from The412Banner/proton-wine releases;
# GPU drivers, DXVK/VKD3D and FEX stay app options. Binaries target Android 11+ (API 30: the fake-input
# library hooks statx).
#
# usage: NDK=<Android NDK root> tools/bionic-runtime/build.sh <work dir> <out dir>
# host needs: curl git tar zstd python3, wayland-scanner, and the X11/xcb/wayland/glm headers
# (Debian/Ubuntu: libwayland-bin libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libglm-dev)
set -euo pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
ROOT=$(cd "$HERE/../.." && pwd)
WORK=${1:?usage: build.sh <work dir> <out dir>}
OUT=${2:?usage: build.sh <work dir> <out dir>}
: "${NDK:?set NDK to the Android NDK root}"
API=30
# Pinned inputs (bump together with their sha256).
IMAGEFS_URL=https://github.com/The412Banner/winlator-contents/releases/download/base-assets-v1/imagefs.tar.zst
IMAGEFS_SHA256=7838756e6a05c91afff68f4bf12aa2780f815877753f8dd354e203e99b9caf8a # same pin as Bannerlator app/build.gradle
BL_COMMIT=410c969dfe37ed0c687d6a5ee3327ea21a53e0f8 # The412Banner/Bannerlator
BL_ASSETS=https://raw.githubusercontent.com/The412Banner/Bannerlator/$BL_COMMIT/app/src/main/assets
# The Wayland adapter: Bannerlator's (bionic-vulkan-wrapper banner/wayland-wsi-bgra-native f970b6c) plus the placed-
# mapping fixes 32-bit OpenGL / WineD3D need (branch banner/wayland-wsi-placed-export), from that repository's release.
ADAPTER_URL=https://github.com/The412Banner/bionic-vulkan-wrapper/releases/download/wayland-adapter-placed-export-r1
ADAPTER_SHA256=653791c2c2ea904a5122909f01d26689553e91cc4dc7a981478c1303adc96ea5 # libvulkan_wrapper.so
ADAPTER_JSON_SHA256=5448fd64f15fa13ca3c805967c2b4788eb5f86d29a2d2755e15498130cdef9b3
# OpenGL: the Fast OpenGL Mesa set (EGL + GLX + Zink) rebuilt from Mesa main d8cfbe82766 for Zink's kopper readback
# fixes (Banners-Turnip fix/fastgl-zink-readback e07e94d0, run 44232301491); Bannerlator's copy is the 7cda7850 build.
FASTGL_URL=https://github.com/The412Banner/Banners-Turnip/releases/download/fastgl-x11egl-mesa-d8cfbe8-r1
FFMPEG8_SHA256=34ca9076b6b69bc96ee0d53fcb7b9d0d8df869b9f1255dd686bf89cc590b1b08 # ffmpeg8.tzst
GAMESCOPE_TAG=3.16.29
GAMESCOPE_COMMIT=8f212644c46460549035971ab914421180f61a7c
GAMESCOPE_PATCHES="0117-wsi-cache-present-bypass-check.patch 0119-wsi-default-images-under-limiter.patch"
VULKAN_HEADERS_TAG=v1.4.341
# The bionic DroidDeck-Proton layer the pack is made for: linked against (libwayland-client) and checked against, not packed.
# Layer v16 (067c719d) plus the ARM64EC code-map fix for 39-bit hosts (d4c9ffa7, run 44291095238).
LAYER_URL=https://github.com/The412Banner/proton-wine/releases/download/build-bionic-layers-20261118-v16-unwind/DroidDeck-Proton-11.0-12.8-arm64ec.wcp
LAYER_SHA256=3cc74b877bc8707d75aa2cc22e335373b6a6c0b6b1937c7b3c2cd98e55de2e89 # proton-wine d48e30a1 (a188791d + fecf7376 on d4c9ffa7)
LAYER_VERSION=12.8
# Packed into the DroidDeck-Bionic tool next to the layer: FEX with Android-built unix libraries, and default
# DXVK / VKD3D-Proton (DroidDeck components can swap these in files/lib/wine/{dxvk,vkd3d-proton} later).
FEX_URL=https://github.com/The412Banner/Nightlies/releases/download/FEXCore-2611.1/FEXCore-2611.1-unix.wcp
FEX_SHA256=caca997e5e077feb5d9b7cf0f2c680cd93b442278903e3f3e7b1bd9cd544770c
DXVK_URL=https://github.com/The412Banner/Nightlies/releases/download/Dxvk-gplasync-Linux/dxvk-gplasync-2.4.1-1-pre-reg-linux.wcp
DXVK_SHA256=379b5dcde331de45a5f0ac7775d2c657c9c1510616afb9143ab8cdfbfa8e5342
# VKD3D-Proton from DroidDeck-Components' stable release: the linux-nightly files are replaced as nightlies land.
VKD3D_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/linux-stable/DD-vkd3d-proton-arm64ec-3.1.wcp
VKD3D_SHA256=bd458d8adb08631d7d5da93c51ad02ce224178127d3408ca693b2947bf85bdd0
# D7VK's 32-bit ddraw.dll (PROTON_USE_D7VK): the same file DroidDeck-Proton 11-12.8 ships, built there from
# WinterSnowfall/d7vk; only that file is taken out of the release archive.
D7VK_FROM=https://github.com/Droid-Deck/DroidDeck-Proton/releases/download/DroidDeck-Proton-11-12.8/DroidDeck-Proton-11-12.8-aarch64.tar.gz
D7VK_MEMBER="DroidDeck-Proton 11-12.8/files/lib/wine/d7vk/i386-windows/ddraw.dll"
D7VK_SHA256=aaf28d3dee147fd359d14bb08228f9d21335fb5fec334415e396353a967574aa
D7VK_COMMIT=06656b9e94bf275854e3d83d6426517253937738
case "$(uname -s):$(uname -m)" in
Linux:x86_64) NDK_HOST=linux-x86_64 ;;
Linux:aarch64|Linux:arm64) NDK_HOST=linux-aarch64 ;;
Darwin:arm64) NDK_HOST=darwin-arm64 ;;
Darwin:x86_64) NDK_HOST=darwin-x86_64 ;;
*) echo "unsupported host $(uname -s):$(uname -m)" >&2; exit 1 ;;
esac
TC="$NDK/toolchains/llvm/prebuilt/$NDK_HOST/bin"
[[ -d "$TC" ]] || TC="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
CC="$TC/aarch64-linux-android${API}-clang"
CXX="$TC/aarch64-linux-android${API}-clang++"
READELF="$TC/llvm-readelf"
STRIP="$TC/llvm-strip"
[[ -x "$CC" && -x "$CXX" ]] || { echo "no NDK clang under $TC" >&2; exit 1; }
fetch() { # url sha256 dest
curl -fsSL --retry 5 --retry-delay 3 --retry-connrefused -o "$3" "$1"
echo "$2 $3" | sha256sum -c -
}
rm -rf "$WORK"; mkdir -p "$WORK" "$OUT"
PACK="$WORK/droiddeck-bionic-runtime"
mkdir -p "$PACK"/{lib,layer,preload,bin,adapter,share,etc}
echo "== imagefs (Bannerlator base, pinned)"
fetch "$IMAGEFS_URL" "$IMAGEFS_SHA256" "$WORK/imagefs.tar.zst"
mkdir -p "$WORK/imagefs"
tar --zstd -xf "$WORK/imagefs.tar.zst" -C "$WORK/imagefs"
IMG="$WORK/imagefs/usr/lib"
[[ -d "$IMG" ]] || { echo "imagefs has no usr/lib" >&2; exit 1; }
echo "== bionic DroidDeck-Proton layer (pinned; its lib/ is on the library path at run time)"
fetch "$LAYER_URL" "$LAYER_SHA256" "$WORK/layer.wcp"
mkdir -p "$WORK/layer"
tar --zstd -xf "$WORK/layer.wcp" -C "$WORK/layer" lib
LAYERLIB="$WORK/layer/lib"
echo "== Wayland adapter (pinned release)"
fetch "$ADAPTER_URL/libvulkan_wrapper.so" "$ADAPTER_SHA256" "$PACK/adapter/libvulkan_wrapper.so"
fetch "$ADAPTER_URL/adapter.json" "$ADAPTER_JSON_SHA256" "$PACK/adapter/adapter.json"
echo "== Bannerlator assets (pinned): FFmpeg 8"
fetch "$BL_ASSETS/ffmpeg8.tzst" "$FFMPEG8_SHA256" "$WORK/ffmpeg8.tzst"
echo "== D7VK ddraw.dll (DroidDeck-Proton 11-12.8 release, that file only)"
mkdir -p "$PACK/d7vk"
curl -fsSL --retry 5 --retry-delay 3 --retry-connrefused "$D7VK_FROM" | tar -xzO -f - "$D7VK_MEMBER" > "$PACK/d7vk/ddraw.dll"
echo "$D7VK_SHA256 $PACK/d7vk/ddraw.dll" | sha256sum -c -
# OpenGL: bionic Mesa (EGL + GLX + Zink, x11 and wayland platforms) for winex11's EGL backend, the set Bannerlator's
# Fast OpenGL uses, from the newer Mesa build pinned in FASTGL_URL
mkdir -p "$PACK/egl"
for e in libEGL.so.1:7d1febabcb0cb6348128bc44885886fba6a2edc103fcfc91f5f858e460b33fd6 \
libGL.so.1:8de5c26d4de6dcac4dd2605d8742622711adcdb76d9fe5f5848894e439bb3826 \
libGLESv2.so.2:2136442182ed8d724f80b2d69ee89f654694fd84439fdeb14010034c14f57658 \
libgallium-27.0.0-devel.so:392ca9d6d3127b2ac5fc232d25830111c759dc672f437794731fc2778ff0eb34 \
libwayland-client.so:fa49c2f119b84a0cf54669de1706a6bc427bb8a7f147c977328575ccbb920126 \
libarchive.so:eb3b13634bd2c188d71e886f8c690ef32f6b4a2a0e8a7197a7f974b2d341b7ab \
x11egl.json:90c1dcebb746625b81b4cf5335e177a4b7cbe608b359c9be5eaa43d8f0de499b; do
fetch "$FASTGL_URL/${e%%:*}" "${e#*:}" "$PACK/egl/${e%%:*}"
done
cp "$HERE/icd.json" "$PACK/adapter/icd.json"
echo "== libraries from the imagefs"
copy_lib() { # name: copies the file and every link on the way to it, as links (Android's own libraries are skipped)
local name=$1 src=$IMG/$1 target
[[ -e "$src" || -L "$src" ]] || { echo "missing in imagefs: $name" >&2; return 1; }
[[ -L "$src" && "$(readlink "$src")" == /* ]] && return 0
while [[ -L "$src" ]]; do
target=$(readlink "$src")
[[ -e "$PACK/lib/$(basename "$src")" || -L "$PACK/lib/$(basename "$src")" ]] || ln -s "$(basename "$target")" "$PACK/lib/$(basename "$src")"
src="$(dirname "$src")/$target"
done
[[ -e "$PACK/lib/$(basename "$src")" ]] || cp "$src" "$PACK/lib/"
}
grep -v -e '^#' -e '^$' "$HERE/runtime-libs.txt" | while read -r name; do copy_lib "$name"; done
[[ -e "$PACK/lib/libSDL2-2.0.so.0" ]] || ln -s libSDL2-2.0.so "$PACK/lib/libSDL2-2.0.so.0"
mkdir -p "$PACK/lib/gstreamer-1.0"
grep -v -e '^#' -e '^$' "$HERE/gst-plugins.txt" | while read -r p; do cp "$IMG/gstreamer-1.0/libgst$p.so" "$PACK/lib/gstreamer-1.0/"; done
tar --zstd -xf "$WORK/ffmpeg8.tzst" -C "$PACK/lib"
for f in "$PACK"/lib/libav*.so.* "$PACK"/lib/libsw*.so.*; do # soname links for the FFmpeg 8 files
[[ -L "$f" ]] && continue
so=$("$READELF" -d "$f" | sed -n 's/.*(SONAME).*\[\(.*\)\]/\1/p')
[[ -n "$so" && ! -e "$PACK/lib/$so" ]] && ln -s "$(basename "$f")" "$PACK/lib/$so"
done
# GStreamer plugins: add the libraries they need from the imagefs; drop plugins needing something it lacks
python3 "$HERE/check-needed.py" "$READELF" "$PACK" --available "$LAYERLIB" --fill "$IMG" --prune lib/gstreamer-1.0
cp -a "$WORK/imagefs/usr/share/X11" "$PACK/share/"
cp -a "$WORK/imagefs/etc/fonts" "$WORK/imagefs/etc/tls" "$PACK/etc/"
echo "== gamescope $GAMESCOPE_TAG WSI layer (+ DroidDeck patches: $GAMESCOPE_PATCHES)"
GS="$WORK/gamescope"
git clone -q --depth 1 --branch "$GAMESCOPE_TAG" https://github.com/ValveSoftware/gamescope "$GS"
[[ "$(git -C "$GS" rev-parse HEAD)" == "$GAMESCOPE_COMMIT" ]] || { echo "gamescope $GAMESCOPE_TAG is not $GAMESCOPE_COMMIT" >&2; exit 1; }
git -C "$GS" submodule update -q --init --depth 1 subprojects/vkroots || git -C "$GS" submodule update -q --init subprojects/vkroots
for p in $GAMESCOPE_PATCHES; do git -C "$GS" apply "$ROOT/tools/gamescope/patches/$p"; done
git clone -q --depth 1 --branch "$VULKAN_HEADERS_TAG" https://github.com/KhronosGroup/Vulkan-Headers "$WORK/vulkan-headers"
INC="$WORK/inc"; GEN="$WORK/gen"; mkdir -p "$INC" "$GEN"
cp -r "$WORK/vulkan-headers/include/vulkan" "$WORK/vulkan-headers/include/vk_video" "$INC/"
cp -r /usr/include/X11 /usr/include/xcb /usr/include/glm "$INC/"
cp /usr/include/wayland-*.h "$INC/"
for p in gamescope-swapchain gamescope-limiter; do
wayland-scanner client-header "$GS/protocol/$p.xml" "$GEN/$p-client-protocol.h"
wayland-scanner private-code "$GS/protocol/$p.xml" "$GEN/$p-protocol.c"
"$CC" -O2 -fPIC -c -I"$INC" "$GEN/$p-protocol.c" -o "$GEN/$p-protocol.o"
done
LINK=(-L"$PACK/lib" -Wl,-rpath-link,"$PACK/lib" -L"$LAYERLIB" -Wl,-rpath-link,"$LAYERLIB")
"$CXX" -std=c++20 -O2 -fPIC -shared -DWLR_USE_UNSTABLE -D_GNU_SOURCE -include "$HERE/bionic_compat.h" \
-I"$GS/subprojects/vkroots" -I"$GEN" -I"$INC" -I"$GS/layer" -I"$GS/src" \
"$GS/layer/VkLayer_FROG_gamescope_wsi.cpp" "$GEN"/*.o "${LINK[@]}" \
-lwayland-client -lX11-xcb -lX11 -lxcb -lxcb-composite -static-libstdc++ -Wl,--no-undefined \
-o "$PACK/layer/libVkLayer_FROG_gamescope_wsi_aarch64.so"
cp "$HERE/VkLayer_FROG_gamescope_wsi.aarch64.json" "$PACK/layer/"
echo "== DroidDeck GPU-load layer (tools/gpuload), off unless its DroidDeck variables are set"
for l in gpuload; do
"$CC" -std=c11 -shared -fPIC -O2 -Wall -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden \
-pthread -Wl,-z,defs -include "$HERE/bionic_compat.h" -I"$INC" -I"$ROOT/tools/gpuload/src" \
"$ROOT/tools/gpuload/src/vk_layer_droiddeck_$l.c" -o "$PACK/layer/libVkLayer_droiddeck_$l.so"
done
for j in gpu_load:gpuload; do
sed 's#"library_path": *"[^"]*"#"library_path": "./libVkLayer_droiddeck_'"${j#*:}"'.so"#' \
"$ROOT/tools/gpuload/layer/VK_LAYER_DROIDDECK_${j%%:*}.json" > "$PACK/layer/VK_LAYER_DROIDDECK_${j%%:*}.json"
grep -q '"library_path": "./libVkLayer_droiddeck_' "$PACK/layer/VK_LAYER_DROIDDECK_${j%%:*}.json"
done
echo "== DroidDeck fake input (app/src/main/cpp/fakeinput_steam.cpp), heap-tagging off, window tagger"
"$CXX" -shared -fPIC -O2 -Wall -Wno-attributes -pthread -std=c++17 "$ROOT/app/src/main/cpp/fakeinput_steam.cpp" \
-ldl -static-libstdc++ -o "$PACK/preload/libfakeinput.so"
"$CC" -shared -fPIC -O2 -Wall "$HERE/notag.c" -ldl -o "$PACK/preload/libnotag.so"
"$CC" -shared -fPIC -O2 -Wall "$HERE/execshim.c" -ldl -o "$PACK/preload/libexecshim.so"
"$CC" -shared -fPIC -O2 -Wall -Wextra -fvisibility=hidden "$HERE/steamshm.c" -ldl -o "$PACK/preload/libsteamshm.so"
"$CC" -O2 -Wall "$HERE/gstag.c" -o "$PACK/bin/gstag"
"$STRIP" --strip-unneeded "$PACK/layer/"*.so "$PACK/preload/"*.so "$PACK/bin/gstag"
echo "== every library a pack file needs must be in the pack or on Android"
python3 "$HERE/check-needed.py" "$READELF" "$PACK" --available "$LAYERLIB"
echo "== manifest"
REV=$(git -C "$ROOT" rev-parse --short=8 HEAD)
cp "$HERE/NOTICE" "$PACK/NOTICE"
{
echo "droiddeck-bionic-runtime $REV ($(date -u +%Y-%m-%dT%H:%M:%SZ), Android API $API, NDK $(basename "$NDK"))"
echo "imagefs $IMAGEFS_URL sha256 $IMAGEFS_SHA256"
echo "bannerlator $BL_COMMIT (ffmpeg8.tzst)"
echo "fastgl $FASTGL_URL (egl/: Mesa EGL + GLX + Zink, Mesa main d8cfbe82766)"
echo "adapter $ADAPTER_URL (libvulkan_wrapper.so sha256 $ADAPTER_SHA256)"
echo "layer $LAYER_URL sha256 $LAYER_SHA256 (not packed)"
echo "d7vk $D7VK_COMMIT: i386 ddraw.dll from $D7VK_FROM"
echo "gamescope $GAMESCOPE_TAG $GAMESCOPE_COMMIT + $GAMESCOPE_PATCHES; vkroots $(git -C "$GS/subprojects/vkroots" rev-parse HEAD); Vulkan-Headers $VULKAN_HEADERS_TAG"
echo
(cd "$PACK" && find . -type f ! -name MANIFEST.txt | sort | xargs sha256sum)
} > "$PACK/MANIFEST.txt"
tar --zstd -cf "$OUT/droiddeck-bionic-runtime-$REV.tar.zst" -C "$WORK" droiddeck-bionic-runtime
(cd "$OUT" && sha256sum "droiddeck-bionic-runtime-$REV.tar.zst" > "droiddeck-bionic-runtime-$REV.tar.zst.sha256")
du -sh "$PACK" "$OUT"/*.tar.zst
echo "== DroidDeck-Bionic tool: layer + this pack + FEX + DXVK/VKD3D + tool scripts, in Proton's layout"
NAME="DroidDeck-Bionic-$LAYER_VERSION-r${BUILD_NUMBER:-0}"
T="$WORK/tool/$NAME"
mkdir -p "$T/files" "$T/bionic"
tar --zstd -xf "$WORK/layer.wcp" -C "$T/files" bin lib share prefixPack.txz
mkdir -p "$WORK/pfx" && tar -xJf "$T/files/prefixPack.txz" -C "$WORK/pfx" && rm "$T/files/prefixPack.txz"
mv "$WORK/pfx/.wine" "$T/files/default_pfx"
# No drives in the template: its links point into Winlator, and a Z: -> / link here once let DroidDeck's tool delete
# walk the whole device. launch.sh makes C: and Z: in each game's own prefix.
rm -rf "$T/files/default_pfx/dosdevices"
for c in FEX:"$FEX_URL":"$FEX_SHA256" DXVK:"$DXVK_URL":"$DXVK_SHA256" VKD3D:"$VKD3D_URL":"$VKD3D_SHA256"; do
n=${c%%:*}; rest=${c#*:}; sha=${rest##*:}; url=${rest%:*}
fetch "$url" "$sha" "$WORK/$n.wcp"
mkdir -p "$WORK/$n" && tar --zstd -xf "$WORK/$n.wcp" -C "$WORK/$n"
done
cp "$WORK/FEX/aarch64-unix/"*.so "$T/files/lib/wine/aarch64-unix/"
cp "$WORK/FEX/system32/"*.dll "$T/files/lib/wine/aarch64-windows/"
cp -r "$WORK/DXVK/files/lib/wine/dxvk" "$WORK/VKD3D/files/lib/wine/vkd3d-proton" "$T/files/lib/wine/"
cp -a "$PACK" "$T/files/runtime"
# a spare copy of the tool's FEX for launch.sh, which puts it back if DroidDeck's component check swapped in its
# own FEX (glibc unix libraries) for a game with a per-game FEX choice
mkdir -p "$T/files/runtime/fex/aarch64-unix" "$T/files/runtime/fex/aarch64-windows"
cp "$WORK/FEX/aarch64-unix/"*.so "$T/files/runtime/fex/aarch64-unix/"
cp "$WORK/FEX/system32/"*.dll "$T/files/runtime/fex/aarch64-windows/"
install -m 755 "$HERE/tool/proton" "$T/proton"
install -m 755 "$HERE/tool/launch.sh" "$T/bionic/launch.sh"
cp "$HERE/tool/desktop.reg" "$HERE/tool/Xdefaults" "$T/bionic/"
cp "$HERE/tool/toolmanifest.vdf" "$T/"
# The name Steam registers the tool under ends in -Proton: Steam maps Windows save folders (WinAppDataLocal, WinMyDocuments
# ...) into compatdata/<app>/pfx only for tools whose name contains "proton" (a case-insensitive search in
# steamclient.so's compat manager); without it Steam Cloud skipped every such save rule. The folder, the version file and
# the release keep $NAME, which is what DroidDeck matches on.
sed -e "s/@NAME@/$NAME-Proton/" -e "s/@DISPLAY@/DroidDeck-Bionic $LAYER_VERSION r${BUILD_NUMBER:-0}/" "$HERE/tool/compatibilitytool.vdf.in" > "$T/compatibilitytool.vdf"
echo "$(date -u +%s) $NAME" > "$T/version"
{
echo "$NAME: DroidDeck runtime pack $REV + layer + FEX/DXVK/VKD3D"
echo "fex $FEX_URL sha256 $FEX_SHA256"
echo "dxvk $DXVK_URL sha256 $DXVK_SHA256"
echo "vkd3d $VKD3D_URL sha256 $VKD3D_SHA256"
} > "$T/SOURCES.txt"
python3 "$HERE/check-needed.py" "$READELF" "$T/files" --available "$T/files/lib"
echo "== no link may point out of the tool (DroidDeck deletes old tool folders)"
python3 - "$T" <<'PY'
import os, sys
root = os.path.realpath(sys.argv[1])
bad = []
for d, dirs, files in os.walk(root):
for n in dirs + files:
p = os.path.join(d, n)
if os.path.islink(p):
t = os.path.realpath(p)
if t != root and not t.startswith(root + os.sep):
bad.append("%s -> %s" % (os.path.relpath(p, root), os.readlink(p)))
if bad:
sys.exit("links out of the tool:\n" + "\n".join(bad))
print("no links out of the tool")
PY
tar -C "$WORK/tool" -cf - "$NAME" | xz -T0 -6 > "$OUT/$NAME-aarch64.tar.xz"
(cd "$OUT" && sha512sum "$NAME-aarch64.tar.xz" > "$NAME-aarch64.sha512sum")
du -sh "$T" "$OUT/$NAME-aarch64.tar.xz"
+126
View File
@@ -0,0 +1,126 @@
#!/usr/bin/env python3
"""Checks that every library an ELF file in the bionic runtime pack needs is in the pack, in --available
(the Proton layer's lib/, on the library path at run time) or on Android.
usage: check-needed.py <llvm-readelf> <pack dir> [--available DIR]... [--fill IMAGEFS_LIB] [--prune SUBDIR]
--fill copies missing libraries (and the links on the way to them) from IMAGEFS_LIB into <pack>/lib, repeatedly
--prune deletes ELF files under <pack>/SUBDIR that still miss a library (plugins nothing else links to)
Exits 1 when anything is still missing."""
import argparse
import os
import shutil
import subprocess
import sys
# Android's own libraries (/system/lib64, /apex) the pack may rely on.
ANDROID = {
"libc.so", "libm.so", "libdl.so", "liblog.so", "libz.so", "libandroid.so", "libnativewindow.so", "libsync.so",
"libEGL.so", "libGLESv1_CM.so", "libGLESv2.so", "libGLESv3.so", "libvulkan.so", "libaaudio.so", "libOpenSLES.so",
"libmediandk.so", "libjnigraphics.so", "libcamera2ndk.so", "libbinder_ndk.so", "ld-android.so",
}
# Known gaps, loaded only for features the first version does not cover.
OPTIONAL = {
"libGL.so.1", # OpenGL games; a dangling link in the pinned imagefs
"libodbc.so", # odbc32
}
def elf_files(pack):
for root, _, files in os.walk(pack):
for f in files:
path = os.path.join(root, f)
if os.path.islink(path) or not os.path.isfile(path):
continue
with open(path, "rb") as fh:
if fh.read(4) == b"\x7fELF":
yield path
def needed(readelf, path):
run = subprocess.run([readelf, "-d", path], capture_output=True, text=True)
if run.returncode != 0: # a damaged ELF must fail the check, not pass with no dependencies
raise SystemExit("check-needed: %s -d %s failed (%d): %s" % (readelf, path, run.returncode, run.stderr.strip()))
return [l.split("[", 1)[1].split("]", 1)[0] for l in run.stdout.splitlines() if "(NEEDED)" in l]
def names_in(*dirs):
names = set()
for d in dirs:
for root, _, files in os.walk(d):
# a link whose target is missing provides nothing
names.update(f for f in files if os.path.isfile(os.path.join(root, f)))
return names
def missing_map(readelf, pack, available):
have = names_in(pack, *available)
missing = {}
for path in elf_files(pack):
for lib in needed(readelf, path):
if lib not in have and lib not in ANDROID and lib not in OPTIONAL:
missing.setdefault(lib, []).append(path)
return missing
def copy_from(img, name, dest):
"""Copies img/name into dest, keeping relative links; False when absent or one of Android's (absolute link)."""
src = os.path.join(img, name)
if not os.path.lexists(src):
return False
while os.path.islink(src):
target = os.readlink(src)
if target.startswith("/"):
return False
link = os.path.join(dest, os.path.basename(src))
if not os.path.lexists(link):
os.symlink(os.path.basename(target), link)
src = os.path.join(os.path.dirname(src), target)
if not os.path.exists(src):
return False
out = os.path.join(dest, os.path.basename(src))
if not os.path.exists(out):
shutil.copy2(src, out)
return True
def main():
ap = argparse.ArgumentParser()
ap.add_argument("readelf")
ap.add_argument("pack")
ap.add_argument("--available", action="append", default=[])
ap.add_argument("--fill")
ap.add_argument("--prune")
a = ap.parse_args()
if a.fill:
added = []
while True:
missing = missing_map(a.readelf, a.pack, a.available)
new = [lib for lib in sorted(missing) if copy_from(a.fill, lib, os.path.join(a.pack, "lib"))]
if not new:
break
added += new
print(f"added from the imagefs: {len(added)} ({', '.join(added)})" if added else "added from the imagefs: none")
if a.prune:
prune_root = os.path.join(a.pack, a.prune)
while True:
missing = missing_map(a.readelf, a.pack, a.available)
doomed = {p for users in missing.values() for p in users if p.startswith(prune_root + os.sep)}
if not doomed:
break
for p in sorted(doomed):
libs = sorted(l for l, users in missing.items() if p in users)
print(f"pruned {os.path.relpath(p, a.pack)}: missing {', '.join(libs)}")
os.remove(p)
missing = missing_map(a.readelf, a.pack, a.available)
for lib, users in sorted(missing.items()):
print(f"missing {lib}: needed by {', '.join(sorted(os.path.relpath(u, a.pack) for u in users)[:5])}")
if missing:
sys.exit(1)
print("all needed libraries present")
if __name__ == "__main__":
main()
+235
View File
@@ -0,0 +1,235 @@
// execshim: preloaded into the bionic Wine processes. From targetSdk 29 Android refuses execve() of files in the
// app's data directory, but the system linker still starts them: "/system/bin/linker64 <file> [args]". So an
// execve()/posix_spawn() of a dynamic ELF under /data whose interpreter is /system/bin/linker64 becomes a linker64
// start, and a "#!" script there becomes a start of its interpreter. Static ELFs (wine-preloader) and everything
// else pass through unchanged: where Android refuses them, Wine falls back to its loader, as on any failed exec.
// A program started that way sees /proc/self/exe as linker64; wineserver looks for its NLS files next to its own
// executable (server/unicode.c get_nls_dir), so realpath()/readlink() of /proc/self/exe answer with the program
// linker64 runs (the second /proc/self/cmdline entry).
#define _GNU_SOURCE
#include <dlfcn.h>
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#if __has_include(<spawn.h>)
#include <spawn.h>
#else // old Android headers (e.g. Termux's): bionic's own definitions, both opaque pointers
typedef struct __posix_spawnattr *posix_spawnattr_t;
typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t;
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#define LINKER "/system/bin/linker64"
enum kind { PASS, VIA_LINKER, VIA_INTERP };
// What starting `path` needs; for scripts, the interpreter and its optional argument.
static enum kind classify(const char *path, char *resolved, char *interp, char *iarg) {
if (!path || !realpath(path, resolved) || strncmp(resolved, "/data/", 6) != 0) return PASS;
// non-blocking, so a FIFO without a writer cannot hang the start; anything but a regular file goes to libc
int fd = open(resolved, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
if (fd < 0) return PASS;
struct stat st;
if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) {
close(fd);
return PASS;
}
enum kind k = PASS;
unsigned char head[256];
ssize_t n = pread(fd, head, sizeof head, 0);
if (n >= (ssize_t)sizeof(Elf64_Ehdr) && memcmp(head, ELFMAG, SELFMAG) == 0 && head[EI_CLASS] == ELFCLASS64) {
Elf64_Ehdr eh;
memcpy(&eh, head, sizeof eh);
for (int i = 0; i < eh.e_phnum && k == PASS; i++) {
Elf64_Phdr ph;
if (pread(fd, &ph, sizeof ph, (off_t)(eh.e_phoff + (Elf64_Off)i * eh.e_phentsize)) != sizeof ph) break;
if (ph.p_type != PT_INTERP || ph.p_filesz == 0 || ph.p_filesz >= PATH_MAX) continue;
char name[PATH_MAX] = {0};
if (pread(fd, name, ph.p_filesz, (off_t)ph.p_offset) == (ssize_t)ph.p_filesz && strcmp(name, LINKER) == 0)
k = VIA_LINKER;
}
} else if (n > 2 && head[0] == '#' && head[1] == '!') {
char line[256];
size_t len = 0;
for (ssize_t i = 2; i < n && head[i] != '\n' && len < sizeof line - 1; i++) line[len++] = (char)head[i];
line[len] = 0;
char *p = line;
while (*p == ' ' || *p == '\t') p++;
char *end = p;
while (*end && *end != ' ' && *end != '\t') end++;
char *rest = *end ? end + 1 : end;
*end = 0;
while (*rest == ' ' || *rest == '\t') rest++;
size_t rl = strlen(rest);
while (rl && (rest[rl - 1] == ' ' || rest[rl - 1] == '\t' || rest[rl - 1] == '\r')) rest[--rl] = 0;
if (*p) {
strcpy(interp, p);
strcpy(iarg, rest);
k = VIA_INTERP;
}
}
close(fd);
return k;
}
static int argc_of(char *const argv[]) {
int n = 0;
while (argv && argv[n]) n++;
return n;
}
// New argv for the rewritten start; *file is what to start. NULL when nothing changes.
static char **rewrite(const char *path, char *const argv[], const char **file, char *storage) {
char *resolved = storage, *interp = storage + PATH_MAX, *iarg = storage + 2 * PATH_MAX;
enum kind k = classify(path, resolved, interp, iarg);
if (k == PASS) return NULL;
int argc = argc_of(argv);
// up to four leading entries, argc - 1 trailing ones and the terminator (argc may be 0)
char **out = calloc((size_t)(argc > 0 ? argc - 1 : 0) + 5, sizeof *out);
if (!out) return NULL;
int j = 0;
if (k == VIA_LINKER) {
*file = LINKER;
out[j++] = (char *)LINKER;
out[j++] = resolved;
} else {
// the interpreter may itself live in app data
char *iresolved = storage + 3 * PATH_MAX, *x = storage + 4 * PATH_MAX, *y = storage + 5 * PATH_MAX;
if (classify(interp, iresolved, x, y) == VIA_LINKER) {
*file = LINKER;
out[j++] = (char *)LINKER;
out[j++] = iresolved;
} else {
*file = interp;
out[j++] = interp;
}
if (*iarg) out[j++] = iarg;
out[j++] = resolved;
}
for (int i = 1; i < argc; i++) out[j++] = argv[i];
out[j] = NULL;
return out;
}
// libc's functions: bound when the library loads (single-threaded), so execve() in a post-fork child finds them bound.
// A call that comes before that (another library's constructor) binds through an atomic slot: concurrent binders
// store the same pointer, and readers never see a torn one.
typedef ssize_t (*readlink_fn)(const char *, char *, size_t);
typedef char *(*realpath_fn)(const char *, char *);
typedef int (*execve_fn)(const char *, char *const[], char *const[]);
typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *,
char *const[], char *const[]);
static void *slot_readlink, *slot_realpath, *slot_execve, *slot_spawn, *slot_spawnp;
static void *bound(void **slot, const char *name) {
void *p = __atomic_load_n(slot, __ATOMIC_ACQUIRE);
if (!p) {
p = dlsym(RTLD_NEXT, name);
__atomic_store_n(slot, p, __ATOMIC_RELEASE);
}
return p;
}
#define real_readlink ((readlink_fn)bound(&slot_readlink, "readlink"))
#define real_realpath ((realpath_fn)bound(&slot_realpath, "realpath"))
#define real_execve ((execve_fn)bound(&slot_execve, "execve"))
#define real_spawn ((spawn_fn)bound(&slot_spawn, "posix_spawn"))
#define real_spawnp ((spawn_fn)bound(&slot_spawnp, "posix_spawnp"))
__attribute__((constructor)) static void bind_libc(void) {
(void)real_readlink;
(void)real_realpath;
(void)real_execve;
(void)real_spawn;
(void)real_spawnp;
}
// The program linker64 runs, when this process is such a start; 0 otherwise.
static int linker_program(char *out, size_t n) {
if (!real_readlink) return 0;
char link[PATH_MAX];
ssize_t l = real_readlink("/proc/self/exe", link, sizeof link - 1);
if (l <= 0) return 0;
link[l] = 0;
const char *base = strrchr(link, '/'); // /system/bin/linker64 is a link into /apex/com.android.runtime/bin
if (strcmp(base ? base + 1 : link, "linker64") != 0) return 0;
int fd = open("/proc/self/cmdline", O_RDONLY | O_CLOEXEC);
if (fd < 0) return 0;
char buf[2 * PATH_MAX];
ssize_t got = read(fd, buf, sizeof buf - 1);
close(fd);
if (got <= 0) return 0;
buf[got] = 0;
size_t first = strlen(buf);
if ((ssize_t)first + 1 >= got || !buf[first + 1] || strlen(buf + first + 1) >= n) return 0;
strcpy(out, buf + first + 1);
return 1;
}
char *realpath(const char *path, char *resolved) {
if (!real_realpath) {
errno = ENOSYS;
return NULL;
}
char prog[PATH_MAX];
if (path && strcmp(path, "/proc/self/exe") == 0 && linker_program(prog, sizeof prog)) return real_realpath(prog, resolved);
return real_realpath(path, resolved);
}
ssize_t readlink(const char *path, char *buf, size_t size) {
char prog[PATH_MAX], full[PATH_MAX];
if (path && strcmp(path, "/proc/self/exe") == 0 && linker_program(prog, sizeof prog)) {
if (real_realpath && real_realpath(prog, full)) {
size_t l = strlen(full);
if (l > size) l = size;
memcpy(buf, full, l);
return (ssize_t)l;
}
}
if (!real_readlink) {
errno = ENOSYS;
return -1;
}
return real_readlink(path, buf, size);
}
int execve(const char *path, char *const argv[], char *const envp[]) {
execve_fn real = real_execve;
if (!real) {
errno = ENOSYS;
return -1;
}
char storage[6 * PATH_MAX]; // stack only: this may run in posix_spawn's vfork-like child (where it passes)
const char *file = path;
char **args = rewrite(path, argv, &file, storage);
int ret = real(file, args ? args : argv, envp);
int saved = errno;
free(args);
errno = saved;
return ret;
}
int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *actions,
const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) {
spawn_fn real = real_spawn;
if (!real) return ENOSYS;
char storage[6 * PATH_MAX];
const char *file = path;
// file actions can change the child's directory before it starts: a relative path is resolved there by libc, so
// it is left to libc instead of being resolved here against the parent's directory
char **args = (actions && path && path[0] != '/') ? NULL : rewrite(path, argv, &file, storage);
int ret = real(pid, file, actions, attr, args ? args : argv, envp);
free(args);
return ret;
}
int posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *actions,
const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) {
if (file && strchr(file, '/')) return posix_spawn(pid, file, actions, attr, argv, envp);
spawn_fn real = real_spawnp;
if (!real) return ENOSYS;
return real(pid, file, actions, attr, argv, envp);
}
+41
View File
@@ -0,0 +1,41 @@
# GStreamer plugins packed for winegstreamer (game video/audio), from the imagefs's lib/gstreamer-1.0 by name
# (libgst<name>.so): Proton's usual set as far as this imagefs has it (no vpx; videoconvert+videoscale are videoconvertscale).
coreelements
app
audioconvert
audiorate
audioresample
ogg
opus
pbtypes
playback
rawparse
subparse
theora
typefindfunctions
videoconvertscale
videorate
volume
vorbis
apetag
audioparsers
autodetect
avi
deinterlace
id3demux
interleave
isomp4
matroska
mpg123
videocrop
videofilter
wavparse
flac
videoparsersbad
libav
asf
dvdsub
mpegpsdemux
mpegtsdemux
jpeg
png
+330
View File
@@ -0,0 +1,330 @@
// gstag: tags top-level X windows whose WM_CLASS contains <match> (any case) with
// STEAM_GAME=<appid>, so gamescope treats a game started outside Steam's process tree
// as the game (stand-in until a bionic winex11 sets STEAM_GAME itself).
// Usage: gstag <display> <appid> <match> <seconds> [stop when this pid exits]
// gamescope publishes focus (GAMESCOPE_FOCUSED_APP) and reads GAMESCOPECTRL_BASELAYER_APPID on its first X server
// (:0, Steam's); with several (DroidDeck: games on :1) those two are read and written there.
// If gamescope still focuses another app 8 s after the tag, it sets GAMESCOPECTRL_BASELAYER_APPID once to
// <appid>,769 (what Steam writes when it shows a game); Steam can change it again later (e.g. the Steam button).
#define _GNU_SOURCE
#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <time.h>
#include <unistd.h>
static int fd, tconn = -1, cconn = -1;
static uint16_t tseq, cseq; // sequence number of the last request sent on each connection
static uint8_t rbuf[1 << 16];
static uint32_t pending[256]; static int npending;
static uint32_t tagged[256]; static int ntagged;
static int wr(const void *p, size_t n) {
const uint8_t *b = p;
while (n) { ssize_t k = write(fd, b, n); if (k <= 0) return -1; b += k; n -= (size_t)k; }
return 0;
}
static int rd(void *p, size_t n) {
uint8_t *b = p;
while (n) { ssize_t k = read(fd, b, n); if (k <= 0) return -1; b += k; n -= (size_t)k; }
return 0;
}
static size_t pad4(size_t n) { return (n + 3) & ~(size_t)3; }
// Sends one request on the current connection; its sequence number goes to *seq. 0 when sent.
static int request(const void *p, size_t n, uint16_t *seq) {
if (wr(p, n)) return -1;
uint16_t *last = (fd == cconn && cconn != tconn) ? &cseq : &tseq;
++*last;
if (seq) *seq = *last;
return 0;
}
// Reads one whole packet into rbuf; a reply (or generic event) longer than rbuf ends the connection. 0 when read.
static int packet(void) {
if (rd(rbuf, 32)) return -1;
uint8_t type = rbuf[0] & 0x7f;
if (rbuf[0] == 1 || type == 35) {
uint32_t words = *(uint32_t *)(rbuf + 4);
if (words > (sizeof rbuf - 32) / 4) return -1;
if (words && rd(rbuf + 32, words * 4u)) return -1;
}
return 0;
}
static int known(uint32_t *list, int n, uint32_t w) { for (int i = 0; i < n; i++) if (list[i] == w) return 1; return 0; }
static void forget(uint32_t *list, int *n, uint32_t w) {
for (int i = 0; i < *n; i++)
if (list[i] == w) { list[i] = list[--*n]; return; }
}
static void note_event(const uint8_t *e) {
uint8_t type = e[0] & 0x7f;
uint32_t win = *(uint32_t *)(e + 8);
if (type == 17) { // DestroyNotify: a destroyed window is neither a candidate nor a tagged game window
forget(pending, &npending, win);
forget(tagged, &ntagged, win);
return;
}
if (type != 16 && type != 19) return; // CreateNotify, MapNotify
if (win && !known(tagged, ntagged, win) && !known(pending, npending, win) && npending < 256) pending[npending++] = win;
}
// Reads until the answer to request `seq`. Returns 1 reply, 0 error, -1 io. Events are noted; errors of requests
// without a reply (a ChangeProperty on a window that is gone) and other stale packets are skipped.
static int reply(uint16_t seq) {
for (;;) {
if (packet()) return -1;
if (rbuf[0] > 1) { note_event(rbuf); continue; }
if (*(uint16_t *)(rbuf + 2) != seq) continue;
return rbuf[0] == 1;
}
}
static uint32_t intern(const char *name) {
size_t n = strlen(name);
uint8_t req[256] = {0};
req[0] = 16;
*(uint16_t *)(req + 2) = (uint16_t)(2 + pad4(n) / 4);
*(uint16_t *)(req + 4) = (uint16_t)n;
memcpy(req + 8, name, n);
uint16_t seq;
if (request(req, 8 + pad4(n), &seq)) return 0;
return reply(seq) == 1 ? *(uint32_t *)(rbuf + 8) : 0;
}
// WM_CLASS of a window into out (both strings joined by '|'); 0 if none.
static int wm_class(uint32_t win, char *out, size_t cap) {
uint8_t req[24] = {0};
req[0] = 20;
*(uint16_t *)(req + 2) = 6;
*(uint32_t *)(req + 4) = win;
*(uint32_t *)(req + 8) = 67; // WM_CLASS
*(uint32_t *)(req + 12) = 31; // STRING
*(uint32_t *)(req + 20) = 64;
uint16_t seq;
if (request(req, sizeof req, &seq) || reply(seq) != 1) return 0;
uint32_t n = *(uint32_t *)(rbuf + 16);
if (!n || n >= cap) return 0;
for (uint32_t i = 0; i < n; i++) out[i] = rbuf[32 + i] ? (char)rbuf[32 + i] : '|';
out[n] = 0;
return 1;
}
static void set_cards(uint32_t win, uint32_t prop, const uint32_t *values, uint32_t n) {
uint8_t req[24 + 4 * 8] = {0};
if (n > 8) n = 8;
req[0] = 18;
*(uint16_t *)(req + 2) = (uint16_t)(6 + n);
*(uint32_t *)(req + 4) = win;
*(uint32_t *)(req + 8) = prop;
*(uint32_t *)(req + 12) = 6; // CARDINAL
req[16] = 32;
*(uint32_t *)(req + 20) = n;
memcpy(req + 24, values, 4 * n);
request(req, 24 + 4 * n, NULL);
}
// First CARDINAL of a root property into *value (0 when unset). 0 when the property could not be read.
static int first_card(uint32_t root, uint32_t prop, uint32_t *value) {
uint8_t gp[24] = {20, 0, 6, 0};
uint16_t seq;
*(uint32_t *)(gp + 4) = root;
*(uint32_t *)(gp + 8) = prop;
*(uint32_t *)(gp + 20) = 64;
if (request(gp, sizeof gp, &seq) || reply(seq) != 1) return 0;
*value = *(uint32_t *)(rbuf + 16) ? *(uint32_t *)(rbuf + 32) : 0;
return 1;
}
// 1 when the window still exists (GetWindowAttributes answers), 0 when it is gone, -1 on an io failure.
static int alive(uint32_t win) {
uint8_t ga[8] = {3, 0, 2, 0};
uint16_t seq;
*(uint32_t *)(ga + 4) = win;
if (request(ga, sizeof ga, &seq)) return -1;
return reply(seq);
}
static void set_card(uint32_t win, uint32_t prop, uint32_t value) {
uint8_t req[28] = {0};
req[0] = 18;
*(uint16_t *)(req + 2) = 7;
*(uint32_t *)(req + 4) = win;
*(uint32_t *)(req + 8) = prop;
*(uint32_t *)(req + 12) = 6; // CARDINAL
req[16] = 32;
*(uint32_t *)(req + 20) = 1;
*(uint32_t *)(req + 24) = value;
request(req, sizeof req, NULL);
}
// Connects to display :<disp> (abstract socket) and returns the socket, its root window in *root; -1 on failure.
static int x_connect(int disp, uint32_t *root) {
struct sockaddr_un sa = {.sun_family = AF_UNIX};
int n = snprintf(sa.sun_path + 1, sizeof sa.sun_path - 1, "/tmp/.X11-unix/X%d", disp);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (connect(fd, (struct sockaddr *)&sa, (socklen_t)(offsetof(struct sockaddr_un, sun_path) + 1 + n))) {
printf("gstag: connect to :%d failed: %s\n", disp, strerror(errno)); close(fd); return -1;
}
uint8_t setup[12] = {'l', 0, 11, 0};
if (wr(setup, sizeof setup) || rd(rbuf, 8)) { close(fd); return -1; }
uint32_t extra = *(uint16_t *)(rbuf + 6) * 4u;
if (extra > sizeof rbuf - 8 || rd(rbuf + 8, extra) || rbuf[0] != 1) { printf("gstag: :%d refused\n", disp); close(fd); return -1; }
uint8_t *d = rbuf + 8;
uint16_t vlen = *(uint16_t *)(d + 16);
uint8_t nformats = d[21];
*root = *(uint32_t *)(d + 32 + pad4(vlen) + 8u * nformats);
return fd;
}
int main(int argc, char **argv) {
if (argc < 5) { fprintf(stderr, "usage: %s <display> <appid> <match> <seconds> [pid]\n", argv[0]); return 2; }
setvbuf(stdout, NULL, _IONBF, 0);
int disp = atoi(argv[1]);
uint32_t appid = (uint32_t)strtoul(argv[2], NULL, 10);
const char *match = argv[3];
int seconds = atoi(argv[4]);
pid_t watch = argc > 5 ? (pid_t)atoi(argv[5]) : 0;
uint32_t root, croot;
int tfd = x_connect(disp, &root), cfd = tfd;
if (tfd < 0) return 3;
croot = root;
if (disp != 0) {
int c = x_connect(0, &croot);
if (c >= 0) cfd = c;
else croot = root;
}
tconn = tfd;
cconn = cfd;
fd = tfd;
uint32_t a_game = intern("STEAM_GAME");
uint8_t cwa[16] = {2, 0, 4, 0}; // ChangeWindowAttributes(root, CWEventMask=SubstructureNotify)
*(uint32_t *)(cwa + 4) = root;
*(uint32_t *)(cwa + 8) = 0x800;
*(uint32_t *)(cwa + 12) = 0x80000;
request(cwa, sizeof cwa, NULL);
uint8_t qt[8] = {15, 0, 2, 0}; // QueryTree(root): windows that exist already
uint16_t qseq;
*(uint32_t *)(qt + 4) = root;
if (request(qt, sizeof qt, &qseq) == 0 && reply(qseq) == 1) {
uint16_t nk = *(uint16_t *)(rbuf + 16);
uint32_t kids[1024];
if (nk > 1024) nk = 1024;
memcpy(kids, rbuf + 32, nk * 4u);
for (int i = 0; i < nk && npending < 256; i++) pending[npending++] = kids[i];
}
printf("gstag: watching display %d for WM_CLASS ~ \"%s\" -> STEAM_GAME=%u\n", disp, match, appid);
fd = cfd; // atoms belong to the server they are interned on
uint32_t a_apps = intern("GAMESCOPE_FOCUSABLE_APPS");
uint32_t a_focus = intern("GAMESCOPE_FOCUSED_APP");
uint32_t a_ctrl = intern("GAMESCOPECTRL_BASELAYER_APPID");
fd = tfd;
time_t tagged_at = 0; int focus_checked = 0, focus_reads = 0;
time_t end = time(NULL) + seconds, next_status = time(NULL) + 3;
while (time(NULL) < end) {
if (time(NULL) >= next_status) {
next_status = time(NULL) + 5;
printf("status:");
uint32_t props[3] = {a_apps, a_focus, a_ctrl};
const char *names[3] = {"focusable", "focused", "baselayer"};
fd = cfd;
for (int k = 0; k < 3; k++) {
uint8_t gp[24] = {20, 0, 6, 0};
*(uint32_t *)(gp + 4) = croot;
*(uint32_t *)(gp + 8) = props[k];
*(uint32_t *)(gp + 20) = 64;
uint16_t gseq;
if (request(gp, sizeof gp, &gseq) == 0 && reply(gseq) == 1) {
uint32_t cnt = *(uint32_t *)(rbuf + 16);
printf(" %s=[", names[k]);
for (uint32_t i = 0; i < cnt && i < 16; i++) printf("%s%u", i ? "," : "", ((uint32_t *)(rbuf + 32))[i]);
printf("]");
}
}
fd = tfd;
for (int i = 0; i < ntagged; i++) {
uint8_t ga[8] = {3, 0, 2, 0}; // GetWindowAttributes
uint16_t aseq, gseq;
*(uint32_t *)(ga + 4) = tagged[i];
int map = -1, ovr = -1, w = -1, h = -1;
if (request(ga, sizeof ga, &aseq) == 0 && reply(aseq) == 1) { map = rbuf[26]; ovr = rbuf[27]; }
uint8_t gg[8] = {14, 0, 2, 0}; // GetGeometry
*(uint32_t *)(gg + 4) = tagged[i];
if (request(gg, sizeof gg, &gseq) == 0 && reply(gseq) == 1) { w = *(uint16_t *)(rbuf + 16); h = *(uint16_t *)(rbuf + 18); }
printf(" win0x%x=%dx%d map%d ovr%d", tagged[i], w, h, map, ovr);
}
printf("\n");
}
if (tagged_at && !focus_checked && time(NULL) - tagged_at >= 8) {
// the override is only for a game that still has a window: a tagged window that was destroyed is gone
// from `tagged` (DestroyNotify), and one that is left must still answer
int live = 0;
for (int i = 0; i < ntagged && !live; i++) live = alive(tagged[i]) == 1;
uint32_t f = 0;
fd = cfd;
int read_ok = live && first_card(croot, a_focus, &f);
fd = tfd;
if (!live) {
focus_checked = 1;
printf("gstag: no tagged window left 8 s after the tag; focus left as it is\n");
} else if (!read_ok) {
// a failed read says nothing about who has focus: try again on the next pass, a few times
if (++focus_reads >= 3) { focus_checked = 1; printf("gstag: focus could not be read; left as it is\n"); }
} else {
focus_checked = 1;
if (f != appid) {
uint32_t ids[2] = {appid, 769};
fd = cfd;
set_cards(croot, a_ctrl, ids, 2);
fd = tfd;
printf("gstag: focus was %u, not %u, 8 s after the tag; set GAMESCOPECTRL_BASELAYER_APPID=%u,769\n", f, appid, appid);
} else printf("gstag: %u has focus\n", appid);
}
}
if (watch && kill(watch, 0) != 0 && errno == ESRCH) { printf("gstag: pid %d gone, stopping\n", watch); break; }
for (int i = 0; i < npending; ) {
char cls[512];
uint32_t w = pending[i];
if (wm_class(w, cls, sizeof cls) && strcasestr(cls, match)) {
set_card(w, a_game, appid);
if (ntagged < 256) tagged[ntagged++] = w;
if (!tagged_at) tagged_at = time(NULL);
printf("gstag: tagged window 0x%x (%s)\n", w, cls);
pending[i] = pending[--npending];
} else i++;
}
fd_set rs; FD_ZERO(&rs); FD_SET(fd, &rs);
struct timeval tv = {0, 500000};
if (select(fd + 1, &rs, NULL, NULL, &tv) > 0) {
if (packet()) { printf("gstag: connection closed or a packet too long\n"); break; }
if (rbuf[0] > 1) note_event(rbuf); // replies and errors here belong to no request waiting
}
if (npending > 200) {
// drop only windows that are gone; live candidates may still get WM_CLASS
for (int i = 0; i < npending; ) {
int a = alive(pending[i]);
if (a < 0) break;
if (a == 0) pending[i] = pending[--npending];
else i++;
}
if (npending > 200) { // still too many: keep the newest
memmove(pending, pending + (npending - 200), 200 * sizeof *pending);
npending = 200;
}
}
}
printf("gstag: done, %d window(s) tagged\n", ntagged);
return 0;
}
+4
View File
@@ -0,0 +1,4 @@
{
"file_format_version": "1.0.0",
"ICD": { "library_path": "./libvulkan_wrapper.so", "api_version": "1.3.0" }
}
+11
View File
@@ -0,0 +1,11 @@
// Turns off Android's heap pointer tagging (TBI) in the bionic Wine processes it is preloaded into.
// Wine/FEX paths can hand free() a pointer whose top byte was dropped; with tagging on, bionic aborts
// ("Pointer tag for 0x... was truncated"). Going from TBI to none at run time is allowed by bionic.
// mallopt is looked up at run time, so the file builds with any NDK API level.
#include <dlfcn.h>
#define M_BIONIC_SET_HEAP_TAGGING_LEVEL_OPT (-204)
#define M_HEAP_TAGGING_LEVEL_NONE_VAL 0
__attribute__((constructor(101))) static void ddbionic_notag(void) {
int (*mallopt_fn)(int, int) = (int (*)(int, int))dlsym(RTLD_DEFAULT, "mallopt");
if (mallopt_fn) mallopt_fn(M_BIONIC_SET_HEAP_TAGGING_LEVEL_OPT, M_HEAP_TAGGING_LEVEL_NONE_VAL);
}
+78
View File
@@ -0,0 +1,78 @@
# Android (bionic) libraries the bionic DroidDeck-Proton layer needs from Bannerlator's base imagefs (usr/lib), by name.
# Made 2026-11-16 from the NEEDED closure of layer v16 (proton-wine 067c719d) lib/wine/aarch64-unix + bin, plus the
# libraries Wine opens by name (strings of its unix modules), the Wayland adapter and the gamescope WSI layer.
# libGL.so.1 is left out: it is a dangling link in this imagefs (OpenGL games are not covered yet).
libSDL2.so
libX11-xcb.so
libX11-xcb.so.1
libX11.so
libX11.so.6
libXau.so.6
libXcursor.so
libXext.so
libXext.so.6
libXfixes.so
libXfixes.so.3
libXi.so
libXrandr.so
libXrender.so
libXrender.so.1
libadrenotools.so
libandroid-support.so
libandroid-sysv-semaphore.so
libandroid-sysvshm.so
libasound.so
libbrotlicommon.so.1
libbrotlidec.so.1
libbz2.so.1.0
libc++_shared.so
libexpat.so.1
libffi.so
libfile_redirect_hook.so
libfontconfig.so
libfreetype.so
libfreetype.so.6
libgio-2.0.so.0
libglib-2.0.so.0
libgmodule-2.0.so.0
libgmp.so
libgmp.so.10
libgnutls.so
libgobject-2.0.so.0
libgsl_alloc_hook.so
libgstapp-1.0.so
libgstaudio-1.0.so
libgstbase-1.0.so
libgstbase-1.0.so.0
libgstgl-1.0.so
libgstreamer-1.0.so
libgstreamer-1.0.so.0
libgsttag-1.0.so
libgsttag-1.0.so.0
libgstvideo-1.0.so
libgstvideo-1.0.so.0
libhogweed.so.6
libhook_impl.so
libiconv.so
libidn2.so.0
libmain_hook.so
libnettle.so.8
libpcre2-8.so.0
libpng16.so
libpulse.so
libpulsecommon-13.0.so
libsndfile.so
libunistring.so
libvulkan.so.1
libxcb-composite.so
libxcb-composite.so.0
libxcb-dri3.so
libxcb-present.so
libxcb-randr.so
libxcb-shm.so
libxcb-sync.so
libxcb.so
libxcb.so.1
libxml2.so.16
libz.so
libz.so.1
+549
View File
@@ -0,0 +1,549 @@
// Valve's Android libsteamclient keeps its named shared memory ("/u<uid>-Shm_<crc>" streams and the
// "/u<uid>-ValveIPCSharedObj-Steam" object that holds the named locks and events) in a table inside the process, so
// the Steam Input data DroidDeck's Linux Steam publishes in /dev/shm never reaches a game on DroidDeck-Bionic. Once
// that library is loaded, this preload makes it use the files the Linux client uses: DROIDDECK_BIONIC_SHM_DIR
// (DroidDeck's /dev/shm) under Steam's user id. DROIDDECK_BIONIC_STEAMSHM=0 turns it off.
// The library's thread semaphores come from sem_open with a per-object name ("%p"), which Android's libc does not
// implement (it always fails), so this preload also gives sem_open/sem_close a table of in-process semaphores.
#define _GNU_SOURCE
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <link.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <sys/auxv.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <unistd.h>
#define EXPORT __attribute__((visibility("default")))
typedef int (*shm_open_fn)(const char *name, size_t size, bool *created);
typedef void (*shm_unlink_fn)(const char *name);
static shm_open_fn orig_open;
static shm_unlink_fn orig_unlink;
static char shm_dir[PATH_MAX];
static char steam_uid[16];
static int notes;
static void say(const char *fmt, ...)
{
char b[600];
va_list a;
va_start(a, fmt);
int n = vsnprintf(b, sizeof b, fmt, a);
va_end(a);
if (n > 0) write(2, b, n < (int)sizeof b ? (size_t)n : sizeof b - 1);
}
// "/u<digits>-Shm_<hex>" or "/u<digits>-ValveIPCSharedObj-Steam": the part after the uid, else NULL.
static const char *shared_part(const char *name)
{
if (!name || name[0] != '/' || name[1] != 'u') return NULL;
const char *p = name + 2;
while (*p >= '0' && *p <= '9') p++;
if (p == name + 2 || *p != '-') return NULL;
if (!strcmp(p + 1, "ValveIPCSharedObj-Steam")) return p + 1;
const char *h = p + 5;
if (strncmp(p + 1, "Shm_", 4)) return NULL;
while ((*h >= '0' && *h <= '9') || (*h >= 'a' && *h <= 'f')) h++;
return h > p + 5 && h <= p + 13 && !*h ? p + 1 : NULL;
}
// The uid Steam put in its IPC object's name (DroidDeck's Linux side reports 0).
static const char *uid_of_steam(void)
{
if (steam_uid[0]) return steam_uid;
DIR *d = opendir(shm_dir);
struct dirent *e;
while (d && (e = readdir(d))) {
const char *n = e->d_name, *p = n + 1;
if (n[0] != 'u') continue;
while (*p >= '0' && *p <= '9') p++;
if (p > n + 1 && p - n - 1 < (long)sizeof steam_uid && !strcmp(p, "-ValveIPCSharedObj-Steam")) {
memcpy(steam_uid, n + 1, (size_t)(p - n - 1));
steam_uid[p - n - 1] = 0;
break;
}
}
if (d) closedir(d);
if (!steam_uid[0]) return "0";
return steam_uid;
}
static bool real_path(const char *part, char *out, size_t n)
{
int w = snprintf(out, n, "%s/u%s-%s", shm_dir, uid_of_steam(), part);
return w > 0 && (size_t)w < n;
}
static int hook_open(const char *name, size_t size, bool *created)
{
const char *part = shared_part(name);
char path[PATH_MAX];
if (!part || !real_path(part, path, sizeof path)) return orig_open(name, size, created);
for (int i = 0; i < 4; i++) {
int fd = open(path, O_RDWR | O_CLOEXEC);
if (fd >= 0) {
if (notes++ < 64) say("steamshm: %s opened (%zu bytes)\n", path, size);
return fd;
}
if (errno != ENOENT) break;
// made and sized under a private name, then put in place in one step: no other process can open it while it
// is still empty, and an object another process published first is opened instead
char tmp[PATH_MAX];
int w = snprintf(tmp, sizeof tmp, "%s.%d.%d", path, (int)getpid(), i);
if (w <= 0 || (size_t)w >= sizeof tmp) break;
fd = open(tmp, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600);
if (fd < 0) break;
if (ftruncate(fd, (off_t)size) != 0) {
close(fd);
unlink(tmp);
break;
}
int placed = (int)syscall(SYS_renameat2, AT_FDCWD, tmp, AT_FDCWD, path, 1 /* RENAME_NOREPLACE */);
if (placed != 0 && (errno == ENOSYS || errno == EINVAL)) { // no renameat2: a hard link fails on EEXIST too
placed = link(tmp, path);
unlink(tmp);
}
if (placed == 0) {
if (created) *created = true;
if (notes++ < 64) say("steamshm: %s created (%zu bytes)\n", path, size);
return fd;
}
int err = errno;
close(fd);
unlink(tmp);
errno = err;
if (err != EEXIST) break;
}
say("steamshm: %s failed (errno %d)\n", path, errno);
return -1;
}
static void hook_unlink(const char *name)
{
const char *part = shared_part(name);
char path[PATH_MAX];
// Steam's IPC object belongs to Steam: never removed from a game
if (!part || !strncmp(part, "Valve", 5) || !real_path(part, path, sizeof path)) {
orig_unlink(name);
return;
}
if (unlink(path) == 0 && notes++ < 64) say("steamshm: %s removed\n", path);
}
struct object {
uintptr_t base;
uintptr_t lo[8], hi[8];
bool exec[8];
int n;
};
static int find_object(struct dl_phdr_info *info, size_t size, void *data)
{
(void)size;
struct object *o = data;
const char *n = info->dlpi_name;
size_t l = n ? strlen(n) : 0;
if (l < 18 || strcmp(n + l - 18, "/libsteamclient.so")) return 0;
o->base = info->dlpi_addr;
o->n = 0;
for (int i = 0; i < info->dlpi_phnum && o->n < 8; i++) {
const ElfW(Phdr) *p = &info->dlpi_phdr[i];
if (p->p_type != PT_LOAD) continue;
o->lo[o->n] = info->dlpi_addr + p->p_vaddr;
o->hi[o->n] = o->lo[o->n] + p->p_memsz;
o->exec[o->n] = (p->p_flags & PF_X) != 0;
o->n++;
}
return 1;
}
static bool readable(const struct object *o, uintptr_t a, size_t n)
{
for (int i = 0; i < o->n; i++)
if (a >= o->lo[i] && a + n <= o->hi[i]) return true;
return false;
}
static int64_t sext(uint64_t v, int bits)
{
return (int64_t)(v << (64 - bits)) >> (64 - bits);
}
// adrp xd at w[0] and add xd, xd, #imm at w[1]: the address they form, or 0.
static uintptr_t adrp_add(const uint32_t *w, int reg)
{
if ((w[0] & 0x9f000000) != 0x90000000 || (int)(w[0] & 31) != reg) return 0;
if ((w[1] & 0xffc00000) != 0x91000000 || (int)(w[1] & 31) != reg || (int)((w[1] >> 5) & 31) != reg) return 0;
uint64_t imm = ((uint64_t)((w[0] >> 5) & 0x7ffff) << 2) | ((w[0] >> 29) & 3);
uintptr_t page = ((uintptr_t)w & ~(uintptr_t)0xfff) + (uintptr_t)(sext(imm, 21) << 12);
return page + ((w[1] >> 10) & 0xfff);
}
static uintptr_t bl_target(const uint32_t *w)
{
if ((w[0] & 0xfc000000) != 0x94000000) return 0;
return (uintptr_t)w + (uintptr_t)(sext(w[0] & 0x3ffffff, 26) << 2);
}
// The first four instructions get copied into a trampoline: none may depend on the pc.
static bool relocatable(const uint32_t *w)
{
for (int i = 0; i < 4; i++) {
uint32_t x = w[i];
if ((x & 0x1f000000) == 0x10000000 || (x & 0x7c000000) == 0x14000000 || (x & 0xff000010) == 0x54000000 ||
(x & 0x7e000000) == 0x34000000 || (x & 0x7e000000) == 0x36000000 || (x & 0x3b000000) == 0x18000000)
return false;
}
return true;
}
// Back from w to the frame setup: stp x29, x30, [sp, #-N]!, or sub sp, sp, #N then stp x29, x30, [sp, #M].
static uint32_t *function_start(const struct object *o, uint32_t *w)
{
for (int i = 0; i < 256; i++, w--) {
if (!readable(o, (uintptr_t)w - 4, 8)) return NULL;
if ((*w & 0xffc07fff) == 0xa9807bfd) return w;
if ((*w & 0xffc07fff) == 0xa9007bfd) return (w[-1] & 0xff8003ff) == 0xd10003ff ? w - 1 : NULL;
}
return NULL;
}
// open(".", O_TMPFILE | O_RDWR, 0777) in the library's shared-memory open: its only nameless file.
static uint32_t *find_shm_open(const struct object *o)
{
uint32_t *found = NULL;
for (int s = 0; s < o->n; s++) {
if (!o->exec[s]) continue;
for (uint32_t *w = (uint32_t *)o->lo[s]; (uintptr_t)(w + 6) <= o->hi[s]; w++) {
if (w[0] != 0x52880041 || w[3] != 0x72a00801 || w[4] != 0x52803fe2 || !bl_target(w + 5)) continue;
uintptr_t str = adrp_add(w + 1, 0);
if (!str || !readable(o, str, 2) || memcmp((const char *)str, ".", 2)) continue;
if (found) return NULL;
found = w;
}
}
return found ? function_start(o, found) : NULL;
}
static const char *find_string(const struct object *o, const char *s)
{
size_t n = strlen(s) + 1;
for (int i = 0; i < o->n; i++) {
const char *p = memmem((const void *)o->lo[i], o->hi[i] - o->lo[i], s, n);
if (p) return p;
}
return NULL;
}
// CSharedMemory::Open: snprintf of "/u%d-Shm_%x", a call to the unlink with that name, then the open.
static uint32_t *find_shm_unlink(const struct object *o, uintptr_t open_fn)
{
const char *fmt = find_string(o, "/u%d-Shm_%x");
uint32_t *found = NULL;
if (!fmt) return NULL;
for (int s = 0; s < o->n; s++) {
if (!o->exec[s]) continue;
for (uint32_t *w = (uint32_t *)o->lo[s]; (uintptr_t)(w + 64) <= o->hi[s]; w++) {
if ((w[0] & 0x9f000000) != 0x90000000 || adrp_add(w, (int)(w[0] & 31)) != (uintptr_t)fmt) continue;
uint32_t *p = w + 2, *end = w + 12;
while (p < end && !bl_target(p)) p++; // snprintf
if (p == end) continue;
uint32_t *u = p + 1;
end = p + 5;
while (u < end && !bl_target(u)) u++;
if (u == end) continue;
bool opens = false;
for (uint32_t *q = u + 1; q < u + 48; q++)
if (bl_target(q) == open_fn) opens = true;
if (!opens) continue;
uint32_t *fn = (uint32_t *)bl_target(u);
if (found && found != fn) return NULL;
found = fn;
}
}
return found;
}
static void flush(uintptr_t a, size_t n)
{
uint64_t ctr;
__asm__ volatile("mrs %0, ctr_el0" : "=r"(ctr));
uintptr_t d = 4u << ((ctr >> 16) & 15), i = 4u << (ctr & 15), x;
for (x = a & ~(d - 1); x < a + n; x += d) __asm__ volatile("dc cvau, %0" ::"r"(x) : "memory");
__asm__ volatile("dsb ish" ::: "memory");
for (x = a & ~(i - 1); x < a + n; x += i) __asm__ volatile("ic ivau, %0" ::"r"(x) : "memory");
__asm__ volatile("dsb ish\n\tisb" ::: "memory");
}
static void jump_code(uint32_t *out, uintptr_t to)
{
out[0] = 0x58000050; // ldr x16, #8
out[1] = 0xd61f0200; // br x16
memcpy(out + 2, &to, 8);
}
static void *trampoline(uint32_t *fn)
{
size_t page = getauxval(AT_PAGESZ);
uint32_t *t = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (t == MAP_FAILED) return NULL;
memcpy(t, fn, 16);
jump_code(t + 4, (uintptr_t)(fn + 4));
if (mprotect(t, page, PROT_READ | PROT_EXEC)) {
munmap(t, page);
return NULL;
}
flush((uintptr_t)t, 32);
return t;
}
static void drop_trampoline(void *t)
{
if (t) munmap(t, getauxval(AT_PAGESZ));
}
// The library's code pages are file mappings: patched anonymous copies are prepared first and then moved over the
// originals in one step each. Both hooks go in or neither: the pages of both functions (one range when they share a
// page) are copied, patched and made executable before anything is replaced, and a copy of the original pages is
// kept, so a failed second replacement puts the first range back.
struct range {
uintptr_t lo;
size_t len;
uint8_t *patched, *saved;
};
static bool prepare(struct range *r, uintptr_t lo, uintptr_t hi)
{
r->lo = lo;
r->len = hi - lo;
r->patched = mmap(NULL, r->len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
r->saved = mmap(NULL, r->len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (r->patched == MAP_FAILED || r->saved == MAP_FAILED) {
if (r->patched != MAP_FAILED) munmap(r->patched, r->len);
if (r->saved != MAP_FAILED) munmap(r->saved, r->len);
r->patched = r->saved = NULL;
return false;
}
memcpy(r->patched, (void *)lo, r->len);
memcpy(r->saved, (void *)lo, r->len);
return true;
}
static void patch(struct range *r, uint32_t *fn, uintptr_t to)
{
if ((uintptr_t)fn >= r->lo && (uintptr_t)fn + 16 <= r->lo + r->len)
jump_code((uint32_t *)(r->patched + ((uintptr_t)fn - r->lo)), to);
}
static bool seal(struct range *r)
{
return !mprotect(r->patched, r->len, PROT_READ | PROT_EXEC) && !mprotect(r->saved, r->len, PROT_READ | PROT_EXEC);
}
static bool commit(struct range *r)
{
if (mremap(r->patched, r->len, r->len, MREMAP_MAYMOVE | MREMAP_FIXED, (void *)r->lo) == MAP_FAILED) return false;
r->patched = NULL; // now the mapping at lo
flush(r->lo, r->len);
return true;
}
static void restore(struct range *r)
{
if (r->saved && mremap(r->saved, r->len, r->len, MREMAP_MAYMOVE | MREMAP_FIXED, (void *)r->lo) != MAP_FAILED) {
r->saved = NULL;
flush(r->lo, r->len);
}
}
static void release(struct range *r)
{
if (r->patched) munmap(r->patched, r->len);
if (r->saved) munmap(r->saved, r->len);
r->patched = r->saved = NULL;
}
static bool redirect_both(uint32_t *fa, uintptr_t ta, uint32_t *fb, uintptr_t tb)
{
size_t page = getauxval(AT_PAGESZ);
uintptr_t alo = (uintptr_t)fa & ~(page - 1), ahi = ((uintptr_t)fa + 16 + page - 1) & ~(page - 1);
uintptr_t blo = (uintptr_t)fb & ~(page - 1), bhi = ((uintptr_t)fb + 16 + page - 1) & ~(page - 1);
struct range r[2] = {{0}};
int n = 1;
if (alo < bhi && blo < ahi) { // overlapping pages: one range holds both patches
if (!prepare(&r[0], alo < blo ? alo : blo, ahi > bhi ? ahi : bhi)) return false;
} else if (!prepare(&r[0], alo, ahi) || !prepare(&r[1], blo, bhi)) {
release(&r[0]);
release(&r[1]);
return false;
} else n = 2;
for (int i = 0; i < n; i++) {
patch(&r[i], fa, ta);
patch(&r[i], fb, tb);
}
bool ok = true;
for (int i = 0; i < n && ok; i++) ok = seal(&r[i]);
if (ok && !commit(&r[0])) ok = false;
else if (ok && n == 2 && !commit(&r[1])) {
restore(&r[0]);
ok = false;
}
for (int i = 0; i < n; i++) release(&r[i]);
return ok;
}
static void install(void)
{
const char *mode = getenv("DROIDDECK_BIONIC_STEAMSHM");
const char *dir = getenv("DROIDDECK_BIONIC_SHM_DIR");
struct object o = {0};
uint32_t *open_fn, *unlink_fn = NULL;
if (mode && !strcmp(mode, "0")) return;
if (!dir || !*dir || strlen(dir) >= sizeof shm_dir) {
say("steamshm: no DROIDDECK_BIONIC_SHM_DIR; Steam Input data stays in the library\n");
return;
}
strcpy(shm_dir, dir);
if (!dl_iterate_phdr(find_object, &o)) {
say("steamshm: libsteamclient.so not found among the loaded libraries\n");
return;
}
open_fn = find_shm_open(&o);
unlink_fn = open_fn ? find_shm_unlink(&o, (uintptr_t)open_fn) : NULL;
if (!open_fn || !unlink_fn || !relocatable(open_fn) || !relocatable(unlink_fn)) {
say("steamshm: this libsteamclient.so does not match (open %p, unlink %p); left as it is\n",
(void *)open_fn, (void *)unlink_fn);
return;
}
orig_open = (shm_open_fn)trampoline(open_fn);
orig_unlink = (shm_unlink_fn)trampoline(unlink_fn);
if (!orig_open || !orig_unlink ||
!redirect_both(unlink_fn, (uintptr_t)hook_unlink, open_fn, (uintptr_t)hook_open)) {
drop_trampoline((void *)orig_open);
drop_trampoline((void *)orig_unlink);
orig_open = NULL;
orig_unlink = NULL;
say("steamshm: could not redirect the library's shared memory; left as it is\n");
return;
}
say("steamshm: libsteamclient.so +%#lx open / +%#lx unlink use %s (Steam uid %s)\n",
(unsigned long)((uintptr_t)open_fn - o.base), (unsigned long)((uintptr_t)unlink_fn - o.base), shm_dir,
uid_of_steam());
}
struct named_sem {
struct named_sem *next;
sem_t sem;
int refs;
char name[];
};
static struct named_sem *sems;
static pthread_mutex_t sems_lock = PTHREAD_MUTEX_INITIALIZER;
// Named semaphores of this process only: the last sem_close frees one (there is no sem_unlink to wait for).
EXPORT sem_t *sem_open(const char *name, int oflag, ...)
{
unsigned value = 0;
if (oflag & O_CREAT) {
va_list a;
va_start(a, oflag);
(void)va_arg(a, unsigned); // mode
value = va_arg(a, unsigned);
va_end(a);
}
if (!*name) {
errno = EINVAL;
return SEM_FAILED;
}
sem_t *r = SEM_FAILED;
pthread_mutex_lock(&sems_lock);
struct named_sem *s = sems;
while (s && strcmp(s->name, name)) s = s->next;
if (s && (oflag & O_CREAT) && (oflag & O_EXCL)) {
errno = EEXIST;
} else if (s) {
s->refs++;
r = &s->sem;
} else if (!(oflag & O_CREAT)) {
errno = ENOENT;
} else if ((s = calloc(1, sizeof *s + strlen(name) + 1))) {
strcpy(s->name, name);
if (sem_init(&s->sem, 0, value) == 0) {
s->refs = 1;
s->next = sems;
sems = s;
r = &s->sem;
} else {
free(s);
}
} else {
errno = ENOMEM;
}
pthread_mutex_unlock(&sems_lock);
return r;
}
EXPORT int sem_close(sem_t *sem)
{
int r = -1;
pthread_mutex_lock(&sems_lock);
struct named_sem **p = &sems;
while (*p && &(*p)->sem != sem) p = &(*p)->next;
if (*p) {
struct named_sem *s = *p;
r = 0;
if (--s->refs == 0) {
*p = s->next;
sem_destroy(&s->sem);
free(s);
}
} else {
errno = EINVAL;
}
pthread_mutex_unlock(&sems_lock);
return r;
}
static long raw_getuid(void)
{
register long x8 __asm__("x8") = 174; // __NR_getuid
register long x0 __asm__("x0");
__asm__ volatile("svc #0" : "=r"(x0) : "r"(x8) : "memory");
return x0;
}
// libsteamclient asks for the uid just before it names each shared-memory object, so its first call installs the
// redirect before the first open. Calls from anywhere else only return the uid.
EXPORT uid_t getuid(void)
{
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static int done;
if (!__atomic_load_n(&done, __ATOMIC_ACQUIRE)) {
Dl_info i;
size_t l;
if (dladdr(__builtin_return_address(0), &i) && i.dli_fname && (l = strlen(i.dli_fname)) >= 18 &&
!strcmp(i.dli_fname + l - 18, "/libsteamclient.so")) {
pthread_mutex_lock(&lock);
if (!done) {
install();
__atomic_store_n(&done, 1, __ATOMIC_RELEASE);
}
pthread_mutex_unlock(&lock);
}
}
return (uid_t)raw_getuid();
}
+2
View File
@@ -0,0 +1,2 @@
! DroidDeck-Bionic: an empty X resource file. XENVIRONMENT points here so libX11 has a resource database to
! keep; with no file at all it looks for ~/.Xdefaults again on every XGetDefault call (each GDI font selection).
@@ -0,0 +1,13 @@
"compatibilitytools"
{
"compat_tools"
{
"@NAME@"
{
"install_path" "."
"display_name" "@DISPLAY@"
"from_oslist" "windows"
"to_oslist" "linux"
}
}
}
+13
View File
@@ -0,0 +1,13 @@
Windows Registry Editor Version 5.00
; Black instead of Wine's default colour, and no shell/taskbar or tray, if a game is run on a Wine desktop
; (launch.sh itself runs games straight on gamescope).
[HKEY_CURRENT_USER\Control Panel\Colors]
"Background"="0 0 0"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ThemeManager\Control Panel\Colors]
"Background"="0 0 0"
[HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops\Default]
"EnableShell"=dword:00000000
"ShowSystray"=dword:00000000
+443
View File
@@ -0,0 +1,443 @@
#!/system/bin/sh
# DroidDeck-Bionic launcher, Android side. ../proton calls it: launch.sh <verb> <compatdata dir> <exe> [args...]
# Runs <exe> on the bionic Proton layer in ../files with the prefix <compatdata>/pfx, inside DroidDeck's
# gamescope session. Every program from app data starts through /system/bin/linker64 (targetSdk 29+ refuses
# execve of app data files); the runtime pack's execshim does the same for Wine's own starts.
verb=$1; COMPAT=$2; EXE=$3
shift 3
TOOL=$(cd "$(dirname "$0")/.." && pwd)
F=$TOOL/files
PACK=$F/runtime
ROOTFS=${DROIDDECK_BIONIC_ROOT:?started without DROIDDECK_BIONIC_ROOT}
APP=${ROOTFS%/linuxfs}
LINKER=/system/bin/linker64
VERSION=$(awk '{print $2}' "$TOOL/version" 2>/dev/null)
LOGS=${DROIDDECK_BIONIC_LOGS:-}
mkdir -p "$COMPAT"
LOG=$COMPAT/droiddeck-bionic.log
[ "$verb" = runinprefix ] || { [ -f "$LOG" ] && mv -f "$LOG" "$LOG.1"; }
# A game's log is written into DroidDeck's session folder (../proton names it), which Share logs takes only as a
# file with one name; the usual name here points to it, and dangles once that session's folder is removed.
[ -L "$LOG" ] && [ ! -e "$LOG" ] && rm -f "$LOG"
if [ -n "$LOGS" ] && [ ! -e "$LOG" ] && mkdir -p "$LOGS" 2>/dev/null && : >> "$LOGS/droiddeck-bionic.log" 2>/dev/null; then
ln -s "$LOGS/droiddeck-bionic.log" "$LOG" 2>/dev/null
fi
exec >> "$LOG" 2>&1
echo "$(date +%H:%M:%S) $verb $EXE ($VERSION, uid $(id -u), DISPLAY ${DISPLAY:-unset})"
# Keep Steam's game identity, DroidDeck's input/display/driver/sync settings and its game environment (the names
# ../proton lists in DROIDDECK_BIONIC_KEEP); drop the rest of the glibc guest's environment.
KEEP=" ${DROIDDECK_BIONIC_KEEP:-} "
for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
case "$KEEP" in *" $v "*) continue ;; esac
case "$v" in
SteamAppId|SteamGameId|SteamOverlayGameId|SteamClientLaunch|SteamEnv|SteamAppUser|SteamUser|STEAM_COMPAT_*) ;;
ANDROID_*|BOOTCLASSPATH|DEX2OATBOOTCLASSPATH|SYSTEMSERVERCLASSPATH|EXTERNAL_STORAGE|ASEC_MOUNTPOINT) ;;
FAKE_*|SDL_*|DD_WIDTH|DD_HEIGHT|DD_VK_DRIVER|WINEDLLOVERRIDES) ;;
DISPLAY|GAMESCOPE_WAYLAND_DISPLAY|FEX_*) ;;
TU_DEBUG|MESA_NO_ERROR|DXVK_CONFIG|DXVK_HUD|DROIDDECK_FORCE_SSBS) ;;
mesa_glthread|vblank_mode|ZINK_*|GALLIUM_HUD|GALLIUM_THREAD) ;;
DD_SYNC|DD_FSYNC_FIRST|DD_SYNC_FALLBACK|PROTON_NO_ESYNC|PROTON_NO_FSYNC|PROTON_NO_NTSYNC|WINEESYNC) ;;
PROTON_USE_D7VK) ;;
XODUS_*|RUST_LOG) ;;
WINE_OFFSCREEN_CHECK_MS|WINE_CPU_TOPOLOGY|WINE_LARGE_ADDRESS_AWARE|WINESTEAMNOEXEC|TZ) ;;
DXVK_LOG_LEVEL|DXVK_HDR|VKD3D_DEBUG|VKD3D_SHADER_DEBUG) ;;
DXVK_LOG_PATH|VKD3D_LOG_FILE|MESA_LOG_FILE) ;;
DROIDDECK_GPU_LOAD|DROIDDECK_GPU_LOAD_DIR|DROIDDECK_VRAM_CAP|DROIDDECK_VRAM_CAP_MB|DROIDDECK_DISPLAY_DRIVER) ;;
DROIDDECK_GUEST_ROOT) ;;
VKD3D_FEATURE_LEVEL|VKD3D_SHADER_MODEL|vk_x11_strict_image_count) ;;
*) unset "$v" 2>/dev/null ;;
esac
done
export PATH=/system/bin:/system/xbin
# DISPLAY: the X server Steam gives games. DroidDeck's gamescope runs two (Steam's UI on :0, games on
# STEAM_GAME_DISPLAY_0), so Steam's menus do not take X focus from the game.
export HOME=$COMPAT WINEPREFIX=$COMPAT/pfx TMPDIR=$ROOTFS/tmp LANG=en_US.UTF-8 DISPLAY=${DISPLAY:-:0}
# Proton's user name: the same C:\users\steamuser (saves, settings) as DroidDeck-Proton in a shared prefix
export USER=steamuser LOGNAME=steamuser
# Graphics: DroidDeck's chosen Turnip (its Android half) through Bannerlator's Wayland adapter, and gamescope's
# WSI layer handing the swapchain to gamescope (zero copy).
drvlib() { # an Android driver folder's library: meta.json's libraryName, else libvulkan_freedreno.so
l=$(sed -n 's/.*"libraryName"[[:space:]]*:[[:space:]]*"\([^"/]*\)".*/\1/p' "$1/meta.json" 2>/dev/null | head -1)
echo "${l:-libvulkan_freedreno.so}"
}
DRV=$(basename "$(dirname "${DD_VK_DRIVER:-/x/none/icd.json}")")
DRVDIR=$APP/graphics_driver/$DRV
if [ ! -f "$DRVDIR/$(drvlib "$DRVDIR")" ]; then
# The runtime driver has no Android build: the one DroidDeck's display uses, else the first one installed.
DRVDIR=
if [ -n "${DROIDDECK_DISPLAY_DRIVER:-}" ] && [ "${DROIDDECK_DISPLAY_DRIVER#*/}" = "$DROIDDECK_DISPLAY_DRIVER" ] && \
[ -f "$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER/$(drvlib "$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER")" ]; then
DRVDIR=$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER
else
for d in "$APP"/graphics_driver/*/; do [ -f "$d$(drvlib "${d%/}")" ] && { DRVDIR=${d%/}; break; }; done
fi
echo "driver $DRV has no Android build; using ${DRVDIR:+$(basename "$DRVDIR")}${DRVDIR:-none} (display driver ${DROIDDECK_DISPLAY_DRIVER:-unknown})"
fi
echo "driver $DRVDIR"
RTD=$APP/.wayland-rt
export VK_ICD_FILENAMES=$PACK/adapter/icd.json ADRENOTOOLS_DRIVER_PATH=$DRVDIR/ ADRENOTOOLS_HOOKS_PATH=$PACK/lib
export ADRENOTOOLS_DRIVER_NAME=$(drvlib "$DRVDIR")
export VK_ADD_IMPLICIT_LAYER_PATH=$PACK/layer ENABLE_GAMESCOPE_WSI=1 GAMESCOPE_WAYLAND_DISPLAY=${GAMESCOPE_WAYLAND_DISPLAY:-gamescope-0}
export XDG_RUNTIME_DIR=$RTD DROIDDECK_WSI_BYPASS_CHECK_MS=100 GAMESCOPE_WSI_FORCE_BYPASS=1
[ -e "$RTD/droiddeck-gamescope-limiter" ] && export GAMESCOPE_LIMITER_FILE=$RTD/droiddeck-gamescope-limiter
# Wine: DXVK/VKD3D over the builtins, X11 inside gamescope (winewayland would pick DroidDeck's compositor),
# FEX for x86 code, userspace ntsync (no /dev/ntsync on Android), Valve's Android Steam client library.
export WINEDLLOVERRIDES="${WINEDLLOVERRIDES:+$WINEDLLOVERRIDES;}d3d8,d3d9,d3d10core,d3d11,dxgi,d3d12,d3d12core=n,b;winewayland.drv=d"
# Sync as chosen in DroidDeck (Wine sync, per-game PROTON_NO_*): ntsync is userspace ntsync (no /dev/ntsync on
# Android) with esync as its fallback; Android has no futex_waitv, so an fsync choice runs ntsync.
on() { case "$1" in 1|on|true|yes) return 0 ;; esac; return 1; }
NT=1; ES=1
[ "${DD_SYNC:-1}" = 0 ] && NT=0
[ "${DD_FSYNC_FIRST:-0}" = 1 ] && NT=1
[ "${DD_SYNC:-1}" = 0 ] && [ "${DD_SYNC_FALLBACK:-1}" = 0 ] && ES=0
on "${PROTON_NO_NTSYNC:-}" && NT=0
{ on "${PROTON_NO_ESYNC:-}" || [ "${WINEESYNC:-}" = 0 ]; } && ES=0
export WINENTSYNC=$NT WINEESYNC=$ES
# Userspace ntsync keeps its state in one file. Per prefix, not in the shared TMPDIR (DroidDeck-Proton's ntsync
# uses that too), and cleared before Wine starts in this prefix: a process killed while it held the file's lock
# leaves it held, and every later start in that prefix hangs at its first ntsync wait.
export NTSYNC_SHM=$COMPAT/ntsync-shm
# DroidDeck's Force SSBS (its glibc libssbs.so preload) is bionic Wine's own WINE_FORCE_SSBS
on "${DROIDDECK_FORCE_SSBS:-}" && export WINE_FORCE_SSBS=1
export HODLL=libwow64fex.dll WINEDEBUG=err+all,fixme-all
export XENVIRONMENT=$TOOL/bionic/Xdefaults
# The adapter's Wayland swapchain gets its buffers back from gamescope later than DroidDeck-Proton's Turnip does;
# with gamescope's default three images the game waits for one about a fifth of the time at high frame rates.
# droiddeck-game-env's fix for a game that needs its own image count sets vk_x11_strict_image_count instead.
case "${vk_x11_strict_image_count:-}" in
true|1) ;;
*) export GAMESCOPE_WSI_MIN_IMAGE_COUNT=${GAMESCOPE_WSI_MIN_IMAGE_COUNT:-4} GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT=${GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT:-1} ;;
esac
# FEX: DroidDeck-Proton's defaults (its share/fex-emu/Config.json: x87 in 64-bit precision, TSO without the vector
# and memcpy parts); droiddeck-game-env's per-game choices (FEX_* in the environment, e.g. .NET, Unity) win.
export FEX_TSOENABLED=${FEX_TSOENABLED:-1} FEX_VECTORTSOENABLED=${FEX_VECTORTSOENABLED:-0} \
FEX_MEMCPYSETTSOENABLED=${FEX_MEMCPYSETTSOENABLED:-0} FEX_HALFBARRIERTSOENABLED=${FEX_HALFBARRIERTSOENABLED:-1} \
FEX_X87REDUCEDPRECISION=${FEX_X87REDUCEDPRECISION:-1} FEX_MULTIBLOCK=${FEX_MULTIBLOCK:-1} FEX_MAXINST=${FEX_MAXINST:-500} FEX_DISKCACHE=${FEX_DISKCACHE:-1}
echo "fex $(env | grep '^FEX_' | sort | tr '\n' ' ')"
echo "sync ntsync=$WINENTSYNC esync=$WINEESYNC ssbs=${WINE_FORCE_SSBS:-0} tu_debug=${TU_DEBUG:-} kept=$(echo $KEEP)"
export WINESTEAMCLIENTPATH64=$ROOTFS/root/.local/share/Steam/androidarm64/libsteamclient.so
# The layer sends a game's steamclient(64).dll to lsteamclient (and so to DroidDeck's Steam through the library
# above) only with WINE_LSTEAMCLIENT set; without it Valve's Windows steamclient runs alone and SteamAPI_Init fails.
export WINE_LSTEAMCLIENT=${WINE_LSTEAMCLIENT:-1}
# Steam Input data (Valve's Steam Deck layouts with game actions) lives in DroidDeck's /dev/shm; libsteamshm.so
# points the Android library's shared memory there (it keeps its own in-process otherwise) and gives it the
# sem_open Android lacks (without it the game hangs once that data arrives).
export DROIDDECK_BIONIC_SHM_DIR=${APP%/files}/no_backup/guest-runtime/shm
export DXVK_LOG_PATH=${DXVK_LOG_PATH:-$COMPAT} PULSE_SERVER=unix:$APP/pulseaudio/PS0
export ANDROID_SYSVSHM_SERVER=$COMPAT/.no-sysvshm-server # its client faults on an unset name, inside a Wine lock
# The pack's imagefs libraries carry Winlator's prefix for plugins and X11 data. No FONTCONFIG_*: with the
# imagefs fonts.conf (Android's /system/fonts) DiRT Showdown quit right after start.
export GST_PLUGIN_SYSTEM_PATH=$PACK/lib/gstreamer-1.0 GST_REGISTRY=$COMPAT/gst-registry.bin GST_REGISTRY_FORK=no
export XLOCALEDIR=$PACK/share/X11/locale XKB_CONFIG_ROOT=$PACK/share/X11/xkb
export SSL_CERT_FILE=$PACK/etc/tls/cert.pem SSL_CERT_DIR=$PACK/etc/tls/certs OPENSSL_CONF=$PACK/etc/tls/openssl.cnf
export WINE_ADDITIONAL_CERTS_DIR=$PACK/etc/tls/cert.pem
# Controller: the bionic winebus has no udev bus, so Steam's virtual pad is shown to it as an Xbox 360 pad;
# Steam's ignore list names that id because of the built-in pad, which Wine does not see here.
export FAKE_EVDEV_STEAM_PAD_AS_X360=1
export SDL_GAMECONTROLLER_IGNORE_DEVICES="$(echo "${SDL_GAMECONTROLLER_IGNORE_DEVICES:-}" | sed -e 's#0x045e/0x028e,##' -e 's#,0x045e/0x028e$##')"
# OpenGL, and WineD3D on it (DirectDraw, Direct3D 1-8 without DXVK): Mesa's Zink on Vulkan through winex11's EGL
# backend (the runtime's egl/), the way Bannerlator's Fast OpenGL runs it; DroidDeck's GL settings above are kept.
export WINE_USE_EGL=1 WINE_X11FORCEGLX=1 GALLIUM_DRIVER=zink MESA_LOADER_DRIVER_OVERRIDE=zink LIBGL_KOPPER_DRI2=1
export ZINK_DESCRIPTORS=${ZINK_DESCRIPTORS:-lazy} ZINK_DEBUG=${ZINK_DEBUG:-compact} vblank_mode=${vblank_mode:-0}
# Gallium's threaded context off, as in Bannerlator's Fast OpenGL: with it, WineD3D (DirectDraw / Direct3D 1-7)
# crashed in native code within seconds (AIO Direct3D 7, SIGSEGV).
export GALLIUM_THREAD=${GALLIUM_THREAD:-0}
# Mesa's GL thread off unless the game's own DroidDeck environment sets it: with DroidDeck's session-wide
# mesa_glthread=true, WineD3D's persistent buffer writes lost vertex colours on this Mesa build (AIO 64-bit
# Direct3D 7 drew its cube white; DroidDeck-Proton's Mesa does not do this).
case "$KEEP" in *" mesa_glthread "*) ;; *) export mesa_glthread=false ;; esac
# egl/ first: the layer's own lib/ carries a Wayland-only Mesa EGL of the same names, which winex11 cannot use
LIBS=$PACK/egl:$F/lib:$PACK/lib:/system/lib64
PRELOAD=$PACK/preload/libexecshim.so:$PACK/preload/libnotag.so:$PACK/preload/libfakeinput.so:$PACK/preload/libsteamshm.so
wine_() { LD_LIBRARY_PATH=$LIBS LD_PRELOAD=$PRELOAD "$LINKER" "$F/lib/wine/aarch64-unix/wine" "$@"; }
wineserver_() { LD_LIBRARY_PATH=$LIBS LD_PRELOAD=$PRELOAD "$LINKER" "$F/bin/wineserver" "$@"; }
is_builtin() { head -c 128 "$1" 2>/dev/null | grep -q "Wine builtin DLL"; }
# Names wine.inf has Wine's update delete from system32 (section FakeDlls) or syswow64 (FakeDllsWow64), "11,,name,-":
# in Windows they live only under Microsoft.NET or winsxs. Wine deletes through a link, so a link there cost this
# tool its own fusion.dll, ngen.exe, comctl32_v6.dll and the rest, and later prefixes their .NET stubs and comctl32 v6.
inf_drops() {
awk -v s="[$1]" '/^\[/ { h = $0; sub(/[ \t\r]+$/, "", h); on = (h == s); next }
on && /^11,,[^,]+,-[ \t\r]*$/ { split($0, a, ","); print a[3] }' "$F/share/wine/wine.inf" 2>/dev/null
}
dropped() { # name patterns
set -f
for p in $2; do case "$1" in $p) set +f; return 0 ;; esac; done
set +f; return 1
}
link_dir() { # src dst [names]: links every file of src into dst; replaces links and Wine builtin copies, keeps native
# DLLs; names (wine.inf patterns) are not linked and a link left under one is removed
[ -d "$1" ] || return 0
for f in "$1"/*; do
[ -f "$f" ] || continue
t=$2/${f##*/}
if [ -n "${3:-}" ] && dropped "${f##*/}" "$3"; then
[ -L "$t" ] && rm -f "$t"
continue
fi
if [ -L "$t" ]; then
[ "$(readlink "$t")" = "$f" ] && continue
rm -f "$t"
elif [ -e "$t" ]; then
is_builtin "$t" || continue
rm -f "$t"
fi
ln -s "$f" "$t"
done
}
winpath() { echo "Z:$1" | sed 's#/#\\#g'; }
# The prefix carries this tool's builtins when it was last set up by this version; another Proton (or an
# older DroidDeck-Bionic) leaves its own links there, and the compatdata version file tells DroidDeck-Proton
# to relink when it runs this prefix again.
# Drive Z: is the whole device for this tool: winpath, getcompatpath and the Xbox paths name Android paths on Z:.
# Proton copies a prefix's links as relative ones, and DroidDeck-Proton's relative z: reaches only the Linux userland
# here, so a game outside it (SD card, shared storage) was on no drive and Wine crashed on its path at start.
# DroidDeck-Proton follows z: -> / in the guest's view, with proot and without.
drive_z() {
z=$1/dosdevices/z:
[ -d "$1/dosdevices" ] || return 0
[ -L "$z" ] || { [ -e "$z" ] && return 0; }
old=$(readlink "$z" 2>/dev/null)
[ "$old" = / ] && return 0
rm -f "$z" && ln -s / "$z" && echo "$(date +%H:%M:%S) drive z: -> / (was ${old:-missing})"
}
prepare_prefix() {
P=$COMPAT/pfx
drive_z "$P"
if [ -f "$P/.droiddeck-bionic" ] && [ "$(cat "$P/.droiddeck-bionic")" = "$VERSION" ] && \
[ "$(cat "$COMPAT/version" 2>/dev/null)" = "$VERSION" ]; then return 0; fi
if [ ! -f "$P/system.reg" ]; then
echo "$(date +%H:%M:%S) new prefix from the layer's template"
mkdir -p "$P" && cp -a "$F/default_pfx/." "$P/"
fi
W=$P/drive_c/windows
mkdir -p "$W/system32" "$W/syswow64" "$P/dosdevices"
echo "$(date +%H:%M:%S) linking builtins"
link_dir "$F/lib/wine/aarch64-windows" "$W/system32" "$(inf_drops FakeDlls)"
link_dir "$F/lib/wine/i386-windows" "$W/syswow64" "$(inf_drops FakeDllsWow64)"
for c in dxvk vkd3d-proton; do
link_dir "$F/lib/wine/$c/aarch64-windows" "$W/system32"
link_dir "$F/lib/wine/$c/i386-windows" "$W/syswow64"
done
# This layer's Wine always uses the profile C:\users\xuser, Proton's is C:\users\steamuser: one links to the
# other so saves and settings are the same whichever tool runs the game.
U=$P/drive_c/users
if [ -d "$U/steamuser" ] && [ ! -e "$U/xuser" ]; then ln -s steamuser "$U/xuser"
elif [ -d "$U/xuser" ] && [ ! -L "$U/xuser" ] && [ ! -e "$U/steamuser" ]; then ln -s xuser "$U/steamuser"; fi
[ -e "$P/dosdevices/c:" ] || ln -s ../drive_c "$P/dosdevices/c:"
[ -e "$P/dosdevices/z:" ] || ln -s / "$P/dosdevices/z:"
wine_ regedit /S "$(winpath "$TOOL/bionic/desktop.reg")"
wineserver_ -w
echo "$VERSION" > "$P/.droiddeck-bionic"
echo "$VERSION" > "$COMPAT/version"
# Proton (DroidDeck-Proton, GE, ...) reads tracked_files when it takes this prefix over; one this tool made has
# none. The version above is not a Proton prefix version, so Proton updates the prefix and never treats it as
# one from a newer Proton (which would delete its tracked files).
[ -e "$COMPAT/tracked_files" ] || : > "$COMPAT/tracked_files"
echo "$(date +%H:%M:%S) prefix ready"
}
prefix_busy() { # a process of this prefix is running
for p in /proc/[0-9]*; do
[ "${p#/proc/}" = "$$" ] && continue
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
done
return 1
}
programs_left() { # a program of this prefix is still running, apart from Wine's own services and this script's helpers
for p in /proc/[0-9]*; do
q=${p#/proc/}
[ -O "$p" ] || continue
[ "$q" = "$$" ] || [ "$q" = "${GT:-x}" ] && continue
c=; read -r c < "$p/comm" 2>/dev/null
case "$c" in
""|wineserver|services.exe|winedevice.exe|plugplay.exe|explorer.exe|svchost.exe|rpcss.exe|conhost.exe|start.exe|\
winemenubuilder|wineboot.exe|tabtip.exe) continue ;;
esac
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
done
return 1
}
stop_wine() { # wineserver -k, then whatever of this prefix is left (e.g. a game's crash reporter)
wineserver_ -k 2>/dev/null
sleep 1
for p in /proc/[0-9]*; do
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" || continue
[ "${p#/proc/}" = "$$" ] && continue
echo "$(date +%H:%M:%S) left over: ${p#/proc/} $(cat "$p/comm" 2>/dev/null)"
kill -9 "${p#/proc/}" 2>/dev/null
done
}
# A FEX from DroidDeck's components runs here only as an Android build (its unix libraries link Android's libc).
# Missing or glibc unix libraries (an older app put its glibc FEX here): put the tool's own FEX back.
fex_ok=1
for f in aarch64-unix/libwow64fex.so aarch64-unix/libarm64ecfex.so; do
if [ ! -f "$F/lib/wine/$f" ] || grep -q "ld-linux-aarch64" "$F/lib/wine/$f"; then fex_ok=0; fi
done
if [ $fex_ok = 0 ]; then
for f in aarch64-unix/libwow64fex.so aarch64-unix/libarm64ecfex.so aarch64-windows/libwow64fex.dll aarch64-windows/libarm64ecfex.dll; do
[ -f "$PACK/fex/$f" ] || continue
cmp -s "$PACK/fex/$f" "$F/lib/wine/$f" || { cat "$PACK/fex/$f" > "$F/lib/wine/$f" && echo "$(date +%H:%M:%S) restored the tool's FEX $f"; }
done
fi
echo "fex build: $(grep -a -o -m1 'FEX-[0-9][0-9.]*[0-9A-Za-z.+-]*' "$F/lib/wine/aarch64-windows/libarm64ecfex.dll" | head -1)"
if [ "$verb" != runinprefix ] && prefix_busy; then
echo "$(date +%H:%M:%S) Wine left running in this prefix; stopping it"
stop_wine
fi
prefix_busy || rm -f "$NTSYNC_SHM".v*
# Links into a tool that is gone (an older DroidDeck-Bionic, a deleted DroidDeck-Proton) or to a file it no longer has.
# Wine's update cannot write over them, so drivers (network, controller) and other files stay missing. Drop them and
# clear both stamps: prepare_prefix relinks this tool's files and Wine's update puts its own back.
dead=0
for d in system32 syswow64 system32/drivers Fonts; do
for f in "$COMPAT/pfx/drive_c/windows/$d"/*; do
[ -L "$f" ] && [ ! -e "$f" ] && rm -f "$f" && dead=$((dead + 1))
done
done
if [ $dead -gt 0 ]; then
rm -f "$COMPAT/pfx/.update-timestamp" "$COMPAT/pfx/.droiddeck-bionic"
echo "$(date +%H:%M:%S) removed $dead dead link(s) from the prefix; relinking and Wine's update follow"
fi
prepare_prefix
# FEX keeps translated code per program in the prefix (AppData/Local/fex-emu/DiskCache) and reuses it with whatever FEX
# runs the prefix next. Code cached by another FEX build (DroidDeck-Proton's, or a different FEX picked in the
# Components tab) made this FEX crash in Steam's install-script step, and Wine then looped on the crash, so Steam never
# started the game. The cache is cleared when the FEX that runs the prefix is not the one that filled it.
# The stamp holds this FEX's ID and what the caches held when this tool last finished with the prefix, so a cache that
# another FEX wrote to since (DroidDeck-Proton running the same game) is cleared too.
fexid=$(cat "$F/lib/wine/aarch64-windows/libarm64ecfex.dll" "$F/lib/wine/aarch64-windows/libwow64fex.dll" \
"$F/lib/wine/aarch64-unix/libarm64ecfex.so" "$F/lib/wine/aarch64-unix/libwow64fex.so" 2>/dev/null | md5sum | cut -c1-16)
fex_cache_sum() { # names, sizes and times of the files in the prefix's FEX code caches
for u in "$COMPAT/pfx/drive_c/users"/*; do
[ -L "$u" ] && continue
c=$u/AppData/Local/fex-emu/DiskCache
[ -d "$c" ] && find "$c" -type f -exec stat -c '%n %s %Y' {} + 2>/dev/null
done | sort | md5sum | cut -c1-16
}
save_fex_stamp() { echo "$fexid $(fex_cache_sum)" > "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null; }
if [ "$(cat "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null)" != "$fexid $(fex_cache_sum)" ]; then
for u in "$COMPAT/pfx/drive_c/users"/*; do
c=$u/AppData/Local/fex-emu/DiskCache
[ -L "$u" ] || [ ! -d "$c" ] && continue
rm -rf "$c" && echo "$(date +%H:%M:%S) FEX code cache of ${u##*/} cleared (another FEX build wrote to it, or it is unknown)"
done
save_fex_stamp
fi
# Steam's Windows client files in the prefix, the ones Proton copies from Steam's legacycompat folder: a game's
# steam_api loads C:\Program Files (x86)\Steam\steamclient64.dll, and a prefix this tool made has none.
SC=$ROOTFS/root/.local/share/Steam/legacycompat
D="$COMPAT/pfx/drive_c/Program Files (x86)/Steam"
if [ -d "$SC" ]; then
mkdir -p "$D"
for c in steamclient.dll:steamclient.dll steamclient64.dll:steamclient64.dll GameOverlayRenderer64.dll:GameOverlayRenderer64.dll \
SteamService.exe:steam.exe Steam.dll:Steam.dll; do
s=$SC/${c%%:*}; d=$D/${c#*:}
[ -f "$s" ] || continue
[ -f "$d" ] && [ ! "$s" -nt "$d" ] && continue
cp "$s" "$d.new" && mv -f "$d.new" "$d" && touch -r "$s" "$d" && echo "$(date +%H:%M:%S) Steam client file ${c#*:}"
done
fi
# DXVK and VKD3D-Proton: the prefix uses this tool's files, where DroidDeck puts its component choices. Another Proton
# that ran this prefix left its own copies, which link_dir keeps as native DLLs. A name the tool's DXVK does not ship
# (d3d10.dll, d3d10_1.dll) goes back to Wine's own.
for a in aarch64-windows:system32 i386-windows:syswow64; do
arch=${a%%:*}; W=$COMPAT/pfx/drive_c/windows/${a#*:}
[ -d "$W" ] || continue
for n in d3d8 d3d9 d3d10 d3d10_1 d3d10core d3d11 dxgi d3d12 d3d12core; do
s=$F/lib/wine/dxvk/$arch/$n.dll
[ -f "$s" ] || s=$F/lib/wine/vkd3d-proton/$arch/$n.dll
[ -f "$s" ] || s=$F/lib/wine/$arch/$n.dll
[ -f "$s" ] || continue
t=$W/$n.dll
[ -L "$t" ] && [ "$(readlink "$t")" = "$s" ] && continue
rm -f "$t" && ln -s "$s" "$t" && echo "$(date +%H:%M:%S) ${a#*:}/$n.dll -> ${s#$F/lib/wine/}"
done
done
# D7VK (Direct3D 7 and older on Vulkan) for 32-bit games when PROTON_USE_D7VK is set and not 0, as DroidDeck-Proton:
# its ddraw.dll in syswow64 with Wine's own beside it as ddraw_.dll. Switched off, Wine's link goes back. Only the
# links in the prefix are removed, never the files they point to.
S=$COMPAT/pfx/drive_c/windows/syswow64
if [ -n "${PROTON_USE_D7VK:-}" ] && [ "$PROTON_USE_D7VK" != 0 ] && [ -f "$PACK/d7vk/ddraw.dll" ]; then
rm -f "$S/ddraw.dll" "$S/ddraw_.dll"
ln -s "$PACK/d7vk/ddraw.dll" "$S/ddraw.dll" && ln -s "$F/lib/wine/i386-windows/ddraw.dll" "$S/ddraw_.dll"
export WINEDLLOVERRIDES="$WINEDLLOVERRIDES;ddraw=n,b"
echo "$(date +%H:%M:%S) D7VK on (32-bit ddraw)"
elif [ -L "$S/ddraw_.dll" ] || [ -e "$S/ddraw_.dll" ]; then
rm -f "$S/ddraw.dll" "$S/ddraw_.dll"
ln -s "$F/lib/wine/i386-windows/ddraw.dll" "$S/ddraw.dll"
echo "$(date +%H:%M:%S) D7VK off: Wine's ddraw again"
fi
# A Windows path (an Xbox game on its own drive letter) starts in the folder Steam gave.
case "$EXE" in [A-Za-z]:[\\/]*) ;; *) cd "$(dirname "$EXE")" || exit 1 ;; esac
if [ "$verb" = runinprefix ]; then
wine_ "$EXE" "$@"
rc=$?
save_fex_stamp
exit $rc
fi
name=${EXE##*/}; name=${name##*\\}
comm=$(echo "$name" | cut -c1-15)
game_pids() { # processes of this prefix with the game's name (two prefixes can run programs with the same name)
for p in $(grep -lFx "$comm" /proc/[0-9]*/comm 2>/dev/null); do
p=${p%/comm}
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qxF "WINEPREFIX=$COMPAT/pfx" && echo "${p#/proc/}"
done
}
# The game's windows go straight to gamescope's X server, as with DroidDeck-Proton (no Wine desktop): the game
# sees gamescope's real modes and refresh rate, and gamescope manages its windows.
wine_ "$EXE" "$@" &
WP=$!
# Steam's overlay library marks a game's windows with the app ID Steam tracks (STEAM_GAME); that library is
# glibc-only, so this prefix's windows (WM_CLASS = the Windows program name) are tagged from outside, or gamescope
# never shows them.
GT=
if [ "${SteamAppId:-0}" != 0 ]; then
XD=${DISPLAY#*:}; XD=${XD%%.*}
"$LINKER" "$PACK/bin/gstag" "${XD:-0}" "$SteamAppId" .exe 86400 > "$COMPAT/gstag.log" 2>&1 &
GT=$!
fi
trap 'echo "$(date +%H:%M:%S) stopped by Steam"; [ -n "$GT" ] && kill $GT 2>/dev/null; stop_wine; save_fex_stamp; exit 0' TERM INT HUP
n=0
while [ $n -lt 90 ] && [ -z "$(game_pids)" ]; do
# A program that ended before it was seen (Steam's install-script step takes about a second) leaves nothing
# to wait for; a launcher that left a game running is still waited for as before.
if [ $n -ge 2 ] && ! kill -0 $WP 2>/dev/null && ! programs_left; then break; fi
sleep 1; n=$((n + 1))
done
echo "$(date +%H:%M:%S) game process $(game_pids | tr '\n' ' ')after ${n}s"
# The program Steam started counts while it runs: a program that names its main thread (Chromium-based games call
# it CrBrowserMain) changes its process name, which Wine copies, and is then no longer found by name. A launcher
# that started the game and ended leaves the game as another program of this prefix, so the wait goes on while any
# program of the prefix runs, apart from Wine's own services (Proton waits for the prefix's programs the same way).
while [ -n "$(game_pids)" ] || kill -0 $WP 2>/dev/null || programs_left; do sleep 2; done
echo "$(date +%H:%M:%S) game exited"
[ -n "$GT" ] && kill $GT 2>/dev/null
stop_wine
wait $WP
rc=$?
save_fex_stamp
echo "$(date +%H:%M:%S) done (exit $rc)"
exit $rc
+120
View File
@@ -0,0 +1,120 @@
#!/bin/bash
# DroidDeck-Bionic: a Steam compatibility tool that runs Windows games on the bionic (Android libc) Proton layer
# under files/, outside the Linux userland. Steam calls it inside DroidDeck's no-proot guest; it turns guest paths
# into Android paths and hands over to bionic/launch.sh, an Android /system/bin/sh script.
# Verbs: run/waitforexitandrun (start the game), runinprefix (run a program in the prefix), getcompatpath/
# getnativepath (path conversion); the rest are accepted and ignored.
set -u
verb=${1:-}
[ $# -gt 0 ] && shift
if [ -z "${DDNATV_ROOT:-}" ]; then
echo "DroidDeck-Bionic needs Settings > Run without proot" >&2
exit 1
fi
# guest path -> Android path: the longest no-proot bind whose guest side starts the path, else inside the rootfs
real() {
local p="$1" best="" host="" b g h
local -a binds
IFS='|' read -r -a binds <<< "${DDNATV_BINDS:-}"
for b in "${binds[@]}"; do
h="${b%%:*}"; g="${b#*:}"
case "$p" in "$g"|"$g"/*) [ ${#g} -gt ${#best} ] && { best="$g"; host="$h"; } ;; esac
done
if [ -n "$best" ]; then echo "$host${p#"$best"}"; return; fi
case "$p" in /data/*|/storage/*|/sdcard/*|/system/*|/apex/*|/vendor/*) echo "$p" ;; *) echo "$DDNATV_ROOT$p" ;; esac
}
# A guest Z: path (also as NAME=Z:..., e.g. an installer's /DIR=) -> the Z: path of its Android file; anything else unchanged
zpath() {
local p k
case "$1" in
[Zz]:[\\/]*) p=${1:2}; p=$(real "${p//\\//}"); printf 'Z:%s\n' "${p//\//\\}" ;;
*=[Zz]:[\\/]*) k=${1%%=[Zz]:[\\/]*}; printf '%s=%s\n' "$k" "$(zpath "${1#"$k="}")" ;;
*) printf '%s\n' "$1" ;;
esac
}
# Where a game launch's log goes in DroidDeck's session folder (Share logs takes that folder): the game's log folder
# when Detailed graphics logs made one (droiddeck-game-env), else a folder of its own; nothing for other verbs
session_logs() {
[ "$verb" = waitforexitandrun ] && [ -n "${DD_DEBUG_DIR:-}" ] || return 0
if [ -n "${PROTON_LOG_DIR:-}" ]; then
real "$PROTON_LOG_DIR"
else
local id=${SteamAppId:-0}
printf '%s/games/%s-bionic-%s\n' "$(real "${DD_DEBUG_DIR%/}")" "$(date +%Y-%m-%d-%H%M%S)" "${id//[^0-9]/}"
fi
}
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
tool=$(real "$here")
compat=$(real "${STEAM_COMPAT_DATA_PATH:-$HOME/.local/share/Steam/steamapps/compatdata/0}")
case "$verb" in
run|waitforexitandrun|runinprefix)
[ $# -gt 0 ] || exit 0
# Another Windows path (DroidDeck's Xbox launch names the game on a drive letter of its own) or a bare program
# name (DroidDeck's store steps run cmd.exe, which Wine finds in system32) goes to Wine unchanged.
case "$1" in
[Zz]:[\\/]*) exe=$(zpath "$1") ;;
[A-Za-z]:[\\/]*) exe=$1 ;;
/*) exe=$(real "$1") ;;
*/*) exe=$(real "$PWD/$1") ;;
*) exe=$1 ;;
esac
shift
# DroidDeck's store and Xbox helpers name guest files by Z: paths (reg.exe import, cmd.exe /c, msiexec /i, setup
# /DIR=); this Wine's Z: is Android's root.
args=()
for a in "$@"; do args+=("$(zpath "$a")"); done
export DROIDDECK_BIONIC_ROOT="$DDNATV_ROOT"
# The guest's root as this Wine names it; the store launch files DroidDeck writes (StoreLaunch.kt) start their
# helpers from it.
r=$(real /); r=${r%/}; DROIDDECK_GUEST_ROOT="Z:${r//\//\\}"; export DROIDDECK_GUEST_ROOT
# The Xbox runtime's DLC and mount folders come as ;-separated Z: paths of the guest.
zreal() {
local out="" part
local -a parts
IFS=';' read -r -a parts <<< "$1"
for part in "${parts[@]}"; do
out="${out:+$out;}$(zpath "$part")"
done
echo "$out"
}
for v in XODUS_MOUNT_ROOT XODUS_CONTENT_ROOTS; do
[ -n "${!v:-}" ] && { printf -v "$v" '%s' "$(zreal "${!v}")"; export "${v?}"; }
done
# The HUD's GPU-load folder is a guest path; the bionic game writes to it by its Android path.
[ -n "${DROIDDECK_GPU_LOAD_DIR:-}" ] && { DROIDDECK_GPU_LOAD_DIR=$(real "$DROIDDECK_GPU_LOAD_DIR"); export DROIDDECK_GPU_LOAD_DIR; }
# So are the graphics log locations Detailed graphics logs or game debugging set for this launch.
for v in DXVK_LOG_PATH VKD3D_LOG_FILE MESA_LOG_FILE; do
[ -n "${!v:-}" ] && { printf -v "$v" '%s' "$(real "${!v}")"; export "${v?}"; }
done
DROIDDECK_BIONIC_LOGS=$(session_logs); export DROIDDECK_BIONIC_LOGS
# DroidDeck's game environment (shared entries and this game's), already applied by droiddeck-game-env: the
# names launch.sh keeps when it drops the rest of the guest environment.
DROIDDECK_BIONIC_KEEP=$(python3 - "${STEAM_COMPAT_DATA_PATH:-}" 2>/dev/null <<'PY'
import json, os, re, sys
try:
config = json.load(open(os.path.expanduser("~/.config/droiddeck/game-environment.json"), encoding="utf-8"))
except (OSError, ValueError):
sys.exit(0)
scope = os.path.basename(sys.argv[1].rstrip("/"))
names = set((config.get("shared") or {}).keys())
if re.fullmatch(r"[1-9][0-9]{0,9}", scope):
names |= set(((config.get("games") or {}).get(scope) or {}).keys())
print(" ".join(sorted(n for n in names if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", n) and n in os.environ)))
PY
)
export DROIDDECK_BIONIC_KEEP
exec /system/bin/sh "$tool/bionic/launch.sh" "$verb" "$compat" "$exe" ${args[@]+"${args[@]}"} ;;
getcompatpath)
p=$(real "${1:-}")
printf 'Z:%s\n' "${p//\//\\}" ;;
getnativepath)
p=${1:-}; p=${p#[Zz]:}; p=${p//\\//}
echo "$p" ;;
*) exit 0 ;;
esac
@@ -0,0 +1,5 @@
"manifest"
{
"version" "2"
"commandline" "/proton %verb%"
}