mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
Add experimental Xbox and PC Game Pass store support (#1156)
This commit is contained in:
1 parent
af57286c98
commit
f5bba17f53
56 files changed
+3720
-47
No files matched your search
@@ -98,6 +98,12 @@ def godot_sentry(game):
|
||||
return {"WINEDLLOVERRIDES": ";".join(n + "=d" for n in sentry)}, [], "Godot: Sentry crash handler off"
|
||||
|
||||
|
||||
@fix
|
||||
def deep_rock_gdk_raytracing(game):
|
||||
if game.stem == "fsd-wingdk-shipping" and not any(game.has_arg(arg) for arg in ("-raytracing", "-noraytracing")):
|
||||
return {}, ["-noraytracing", "-ini:Engine:[/Script/Engine.RendererSettings]:r.RayTracing=False"], "Deep Rock Galactic GDK: ray tracing off (D3D12 pipeline creation fails on Thor)"
|
||||
|
||||
|
||||
@fix
|
||||
def arkham_city_x87(game):
|
||||
"""Batman: Arkham City (BatmanAC.exe, also started through BmLauncher.exe beside it) leans on x87
|
||||
@@ -310,6 +316,14 @@ def main():
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env = force_ssbs(command, env)
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
try:
|
||||
xbox_result = xbox["launch"](command, env)
|
||||
except (OSError, ValueError, KeyError, RuntimeError) as error:
|
||||
print("droiddeck-game-env: Xbox launch could not start (%s)" % error, file=sys.stderr)
|
||||
return 1
|
||||
if xbox_result is not None:
|
||||
return xbox_result
|
||||
sync = load_sync()
|
||||
launch, launch_env = select_sync(command, env, sync)
|
||||
if launch[0] != command[0]:
|
||||
|
||||
@@ -596,6 +596,7 @@ case $mode in
|
||||
steam_hold_launch() {
|
||||
local game=$1 shortcut= waited=0 status=0
|
||||
_bl_focused() { xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p'; }
|
||||
_bl_starting() { pgrep -f "reaper SteamLaunch AppId=$(((game >> 32) & 0xffffffff))( |$)" >/dev/null 2>&1; }
|
||||
_bl_hand_off() {
|
||||
printf '%s\n' "$game" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
|
||||
}
|
||||
@@ -610,16 +611,22 @@ case $mode in
|
||||
_bl_hand_off
|
||||
[ -n "$shortcut" ] || return 0
|
||||
# Steam can drop a shortcut launch it gets before the shortcut's overview exists (large libraries).
|
||||
# Hand it over again only if the game never took focus, so a launch that worked is not started twice.
|
||||
# A launch can be running before it creates its first window.
|
||||
while [ "$(_bl_focused)" = 769 ] && [ "$waited" -lt 20 ]; do
|
||||
sleep 1
|
||||
waited=$((waited + 1))
|
||||
done
|
||||
[ "$(_bl_focused)" = 769 ] || return 0
|
||||
if _bl_starting; then
|
||||
echo "== steam: the requested game is already starting; not launching again"
|
||||
return 0
|
||||
fi
|
||||
echo "== steam: the game is not in front after about 20 s; waiting for the shortcut overview"
|
||||
/usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$game" 45 || status=$?
|
||||
if [ "$status" -eq 3 ]; then
|
||||
echo "== steam: not a shortcut CGameID; not launching again"
|
||||
elif _bl_starting; then
|
||||
echo "== steam: the requested game started while waiting; not launching again"
|
||||
elif [ "$(_bl_focused)" = 769 ]; then
|
||||
echo "== steam: launching the requested game again $game (overview status $status)"
|
||||
_bl_hand_off
|
||||
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/python3
|
||||
"""Licensed Xbox launches through Xodus and the game's selected ARM64 Proton."""
|
||||
import hmac
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import secrets
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
BIN = Path(__file__).resolve().parent
|
||||
RUNTIME = Path('/usr/local/lib/droiddeck-xbox')
|
||||
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'libnghttp2.dll')
|
||||
|
||||
|
||||
def bridge(upstream):
|
||||
key = secrets.token_hex(32).encode('ascii')
|
||||
server = socket.socket()
|
||||
server.bind(('127.0.0.1', 0))
|
||||
server.listen(16)
|
||||
clients = set()
|
||||
lock = threading.Lock()
|
||||
stopped = threading.Event()
|
||||
|
||||
def forward(source, target):
|
||||
try:
|
||||
while not stopped.is_set():
|
||||
data = source.recv(65536)
|
||||
if not data:
|
||||
break
|
||||
target.sendall(data)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
target.shutdown(socket.SHUT_WR)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def connect(client):
|
||||
remote = None
|
||||
try:
|
||||
client.settimeout(10)
|
||||
supplied = b''
|
||||
while len(supplied) < len(key):
|
||||
part = client.recv(len(key) - len(supplied))
|
||||
if not part:
|
||||
return
|
||||
supplied += part
|
||||
if not hmac.compare_digest(supplied, key):
|
||||
return
|
||||
remote = socket.socket(socket.AF_UNIX)
|
||||
remote.connect(upstream)
|
||||
client.settimeout(None)
|
||||
with lock:
|
||||
clients.add(remote)
|
||||
writer = threading.Thread(target=forward, args=(client, remote), daemon=True)
|
||||
writer.start()
|
||||
forward(remote, client)
|
||||
writer.join(2)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
for sock in (client, remote):
|
||||
if sock is not None:
|
||||
with lock:
|
||||
clients.discard(sock)
|
||||
sock.close()
|
||||
|
||||
def accept():
|
||||
while not stopped.is_set():
|
||||
try:
|
||||
client, _ = server.accept()
|
||||
except OSError:
|
||||
break
|
||||
with lock:
|
||||
if len(clients) >= 64:
|
||||
client.close()
|
||||
continue
|
||||
clients.add(client)
|
||||
threading.Thread(target=connect, args=(client,), daemon=True).start()
|
||||
|
||||
threading.Thread(target=accept, daemon=True).start()
|
||||
|
||||
def close():
|
||||
stopped.set()
|
||||
server.close()
|
||||
with lock:
|
||||
for client in clients:
|
||||
try:
|
||||
client.shutdown(socket.SHUT_RDWR)
|
||||
except OSError:
|
||||
pass
|
||||
client.close()
|
||||
clients.clear()
|
||||
|
||||
return server.getsockname()[1], key.decode('ascii'), close
|
||||
|
||||
|
||||
def wine(argv):
|
||||
with open(os.environ['DROIDDECK_XBOX_COMMAND_FILE'], encoding='utf-8') as file:
|
||||
command = json.load(file)
|
||||
if len(command) < 3 or command[1] != 'waitforexitandrun' or len(argv) != 1:
|
||||
raise ValueError('Invalid Xbox Proton invocation')
|
||||
env = dict(os.environ)
|
||||
env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
|
||||
env.pop('DROIDDECK_XBOX_COMMAND_FILE', None)
|
||||
prefix = Path(os.environ['STEAM_COMPAT_DATA_PATH']) / 'pfx'
|
||||
prefix.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not (prefix / 'system.reg').is_file():
|
||||
result = subprocess.run([command[0], 'run', 'cmd', '/c', 'exit', '0'], stdout=sys.stderr, env=env)
|
||||
if result.returncode:
|
||||
return result.returncode
|
||||
system = prefix / 'drive_c/windows/system32'
|
||||
system.mkdir(parents=True, exist_ok=True)
|
||||
for name in DLLS:
|
||||
target = system / name
|
||||
if target.is_symlink():
|
||||
target.unlink()
|
||||
shutil.copyfile(RUNTIME / 'windows' / name, target)
|
||||
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
|
||||
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
|
||||
return subprocess.call([*command[:2], argv[0], *command[3:]], env=env)
|
||||
|
||||
|
||||
def launch(command, env):
|
||||
if len(command) < 3 or command[1] != 'waitforexitandrun' or env.get('DROIDDECK_XBOX_ACTIVE') == '1':
|
||||
return None
|
||||
store = runpy.run_path(str(BIN / 'droiddeck-store-launch'))
|
||||
found = store['find_store_game'](command[2:])
|
||||
if found is None or found[1].get('store') != 'xbox':
|
||||
return None
|
||||
folder, sidecar = found
|
||||
for name in DLLS:
|
||||
if not (RUNTIME / 'windows' / name).is_file():
|
||||
raise RuntimeError('Xbox Windows runtime is missing; update the Linux runtime')
|
||||
launch_dir = env.get('BL_LAUNCH_DIR')
|
||||
if not launch_dir:
|
||||
raise RuntimeError('No Xbox account channel; start the game from DroidDeck')
|
||||
reply = store['ask'](Path(launch_dir) / 'stores', {'op': 'xbox-prepare', 'id': sidecar['id']}, timeout=95)
|
||||
if not reply or not reply.get('ok'):
|
||||
raise RuntimeError('Xbox account service is unavailable; sign in again and retry')
|
||||
port, key, close = bridge(reply['socket'])
|
||||
try:
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-xbox-') as temporary:
|
||||
context = Path(temporary) / 'command.json'
|
||||
context.write_text(json.dumps(command), encoding='utf-8')
|
||||
context.chmod(0o600)
|
||||
owned_env = dict(env, DROIDDECK_XBOX_ACTIVE='1', DROIDDECK_XBOX_COMMAND_FILE=str(context),
|
||||
DROIDDECK_XBOX_CREDENTIAL_SOCKET=reply['credentials'],
|
||||
XODUS_SOCKET=reply['socket'], XODUS_BRIDGE_PORT=str(port), XODUS_BRIDGE_KEY=key,
|
||||
XODUS_LOG='off', RUST_LOG='off', XODUS_SAVE_SYNC='auto' if sidecar.get('cloud', True) else 'off')
|
||||
content = folder / '.xbox-content'
|
||||
roots = []
|
||||
if content.is_dir():
|
||||
for entry in content.iterdir():
|
||||
try:
|
||||
marker = json.loads((entry / '.droiddeck-content.json').read_text())
|
||||
if marker.get('parent') == sidecar['id'] and marker.get('productId') == entry.name and not entry.is_symlink():
|
||||
roots.append('Z:' + str(entry).replace('/', '\\'))
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
if roots:
|
||||
owned_env['XODUS_CONTENT_ROOTS'] = ';'.join(roots)
|
||||
market = sidecar.get('extra', {}).get('market', 'US')
|
||||
return subprocess.call([str(RUNTIME / 'xodus-cli'), 'run', str(folder), str(BIN / 'droiddeck-xbox'),
|
||||
'--exe', sidecar['exe'], '--materialize-chain', '--market', market], env=owned_env)
|
||||
finally:
|
||||
close()
|
||||
store['ask'](Path(launch_dir) / 'stores', {'op': 'xbox-released', 'id': sidecar['id']})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
sys.exit(wine(sys.argv[1:]))
|
||||
except (OSError, ValueError, KeyError, RuntimeError):
|
||||
print('droiddeck-xbox: Xbox launch failed; check your account, runtime and package.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user