mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Merge remote-tracking branch 'droiddeck/main' into maint/appimage-x64-wayland-runtime
This commit is contained in:
commit
0d6c18b300
562 files changed
+71029
-1963
No files matched your search
@@ -41,6 +41,9 @@ FEX_WAIT = 120
|
||||
START_GRACE = 90
|
||||
POLL = 2
|
||||
STOP_WAIT = 5
|
||||
DRIVES = "defghijklmnopqruvwxy"
|
||||
PRODUCT_DB = ("ProgramData", "Battle.net", "Agent", "product.db")
|
||||
INSTALL_FOLDER = (1, 3, 1)
|
||||
CLOSE_GRACE = 15
|
||||
HANDOFF_WAIT = 120
|
||||
GAME_SETTLE = 20
|
||||
@@ -85,6 +88,8 @@ COUNTRY = re.compile(r"[A-Z]{3}")
|
||||
REGION = re.compile(r"[A-Z]{2}")
|
||||
REPORT = "BNET"
|
||||
ETA_LIMIT = 30 * 86400
|
||||
STALL = 600
|
||||
MOVING = ("download_current", "download_total", "progress", "playable_progress", "state", "phase", "paused", "error")
|
||||
DONE_STATE = 1004
|
||||
REPORTED = ("progress", "playable_progress", "download_rate", "download_remaining", "estimated_time_in_sec", "state",
|
||||
"playable", "paused", "download_complete", "installed", "error")
|
||||
@@ -115,6 +120,12 @@ function field(text, name) {
|
||||
return m ? m[1] : "";
|
||||
}
|
||||
|
||||
function job(text) {
|
||||
if (/"error"\s*:\s*[1-9]/.test(text)) return false;
|
||||
var bare = text.replace(/"extended_status"\s*:\s*\{[^}]*\}/, "");
|
||||
return /"state"\s*:\s*\d+/.test(bare) || /"download_current"\s*:/.test(bare);
|
||||
}
|
||||
|
||||
function install() {
|
||||
// Blizzard's China repository moved to cn.patch.battlenet.com.cn; cn.patch.battle.net only redirects away from it.
|
||||
var patch = zone == "cn" ? "cn.patch.battlenet.com.cn" : zone + ".patch.battle.net";
|
||||
@@ -123,7 +134,7 @@ function install() {
|
||||
save(".form", form);
|
||||
if (form.indexOf('"' + lang + '"') < 0) lang = "enUS";
|
||||
var locale = lang.toLowerCase();
|
||||
call("POST", "/install/" + uid, '{"account_country":"' + country + '","finalized":true,"game_dir":"' + dir + '","geo_ip_country":"' +
|
||||
call("POST", "/install/" + uid, '{"account_country":"' + country + '","finalized":true,"game_dir":"' + dir.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '","geo_ip_country":"' +
|
||||
region + '","language":["' + locale + '"],"selected_asset_locale":"' + locale + '","selected_locale":"' + locale +
|
||||
'","shortcut":"none","tome_torrent":""}');
|
||||
watch("/install/" + uid);
|
||||
@@ -137,7 +148,7 @@ function watch(path) {
|
||||
if (/"error"\s*:\s*[1-9]/.test(s)) break;
|
||||
var state = /"state"\s*:\s*(\d+)/.exec(s.replace(/"extended_status"\s*:\s*\{[^}]*\}/, "")), complete = /"download_complete"\s*:\s*true/.test(s);
|
||||
state = state ? +state[1] : 0;
|
||||
if (state == 1000 || state == 1003 || !complete) started = true;
|
||||
if (state == 1000 || state == 1003 || job(s) && !complete) started = true;
|
||||
if (started && (state == 1004 || complete && /"playable"\s*:\s*true/.test(s))) break;
|
||||
if (!started && state == 1004 && i >= 20) break;
|
||||
if (!started && i >= 180) {
|
||||
@@ -226,8 +237,72 @@ def installed(root):
|
||||
return os.path.isfile(launcher(root))
|
||||
|
||||
|
||||
def install_path(library):
|
||||
return "Z:" + library.rstrip("/")
|
||||
def dosdevices(root):
|
||||
return os.path.join(prefix(root), "pfx", "dosdevices")
|
||||
|
||||
|
||||
def volume_root(path):
|
||||
device = os.stat(path).st_dev
|
||||
while path != "/":
|
||||
parent = os.path.dirname(path)
|
||||
if os.stat(parent).st_dev != device:
|
||||
break
|
||||
path = parent
|
||||
return path
|
||||
|
||||
|
||||
def inside(path, folder):
|
||||
return path == folder or path.startswith(folder.rstrip("/") + "/")
|
||||
|
||||
|
||||
def mapped_drive(root, path, volume):
|
||||
folder = dosdevices(root)
|
||||
try:
|
||||
names = sorted(os.listdir(folder))
|
||||
except OSError:
|
||||
return None
|
||||
for name in names:
|
||||
link = os.path.join(folder, name)
|
||||
if len(name) == 2 and name[0].lower() in DRIVES and name[1] == ":" and os.path.islink(link):
|
||||
target = os.path.realpath(link)
|
||||
if inside(target, volume) and inside(path, target):
|
||||
return name[0].lower(), target
|
||||
return None
|
||||
|
||||
|
||||
def map_drive(root, volume):
|
||||
folder = dosdevices(root)
|
||||
for letter in DRIVES:
|
||||
link = os.path.join(folder, letter + ":")
|
||||
if not os.path.lexists(link):
|
||||
try:
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
os.symlink(volume, link)
|
||||
except OSError as error:
|
||||
say("%s not mapped to a Wine drive: %s" % (volume, error))
|
||||
return None
|
||||
say("Wine drive %s: is %s" % (letter.upper(), volume))
|
||||
return letter, volume
|
||||
say("%s not mapped to a Wine drive: every letter is taken" % volume)
|
||||
return None
|
||||
|
||||
|
||||
def install_path(root, library):
|
||||
library = library.rstrip("/") or "/"
|
||||
try:
|
||||
path = os.path.realpath(library)
|
||||
volume = volume_root(path)
|
||||
except OSError:
|
||||
return "Z:" + library
|
||||
if volume == "/":
|
||||
return "Z:" + library
|
||||
drive = mapped_drive(root, path, volume)
|
||||
if drive is None and not wine_processes(os.path.join(prefix(root), "pfx")):
|
||||
drive = map_drive(root, volume)
|
||||
if drive is None:
|
||||
return "Z:" + library
|
||||
letter, target = drive
|
||||
return letter.upper() + ":\\" + path[len(target):].strip("/").replace("/", "\\")
|
||||
|
||||
|
||||
def write_config(root, library=None):
|
||||
@@ -254,8 +329,8 @@ def write_config(root, library=None):
|
||||
client["HardwareAcceleration"] = "false"
|
||||
changes.append("acceleration")
|
||||
if library and isinstance(client.setdefault("Install", {}), dict) \
|
||||
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(library):
|
||||
client["Install"]["DefaultInstallPath"] = install_path(library)
|
||||
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(root, library).rstrip("\\"):
|
||||
client["Install"]["DefaultInstallPath"] = install_path(root, library)
|
||||
changes.append("library")
|
||||
games = config.setdefault("Games", {})
|
||||
for uid in CLIENT_32_BIT if isinstance(games, dict) else ():
|
||||
@@ -417,13 +492,106 @@ def wallpaper(root):
|
||||
|
||||
|
||||
def windows_path(root, path):
|
||||
found = re.match(r"(?i)^([cz]):[\\/](.*)$", path.strip())
|
||||
found = re.match(r"(?i)^([a-z]):[\\/](.*)$", path.strip())
|
||||
if not found:
|
||||
return None
|
||||
parts = [part for part in re.split(r"[\\/]+", found.group(2)) if part]
|
||||
if not parts or ".." in parts:
|
||||
if ".." in parts:
|
||||
return None
|
||||
return os.path.join(drive_c(root) if found.group(1).lower() == "c" else "/", *parts)
|
||||
letter = found.group(1).lower()
|
||||
link = os.path.join(dosdevices(root), letter + ":")
|
||||
if letter == "c":
|
||||
target = drive_c(root)
|
||||
elif os.path.islink(link):
|
||||
target = os.path.realpath(link)
|
||||
elif letter == "z":
|
||||
target = "/"
|
||||
else:
|
||||
return None
|
||||
return os.path.join(target, *parts)
|
||||
|
||||
|
||||
def varint(data, at):
|
||||
value = shift = 0
|
||||
while at < len(data) and shift < 64:
|
||||
byte = data[at]
|
||||
at += 1
|
||||
value |= (byte & 0x7F) << shift
|
||||
if not byte & 0x80:
|
||||
return value, at
|
||||
shift += 7
|
||||
raise ValueError("varint")
|
||||
|
||||
|
||||
def encode_varint(value):
|
||||
out = bytearray()
|
||||
while value > 0x7F:
|
||||
out.append(value & 0x7F | 0x80)
|
||||
value >>= 7
|
||||
out.append(value)
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def rewrite_field(data, path, change):
|
||||
out, at = bytearray(), 0
|
||||
while at < len(data):
|
||||
start = at
|
||||
tag, at = varint(data, at)
|
||||
kind = tag & 7
|
||||
if kind == 0:
|
||||
at = varint(data, at)[1]
|
||||
elif kind == 1:
|
||||
at += 8
|
||||
elif kind == 5:
|
||||
at += 4
|
||||
elif kind == 2:
|
||||
size, body = varint(data, at)
|
||||
at = body + size
|
||||
else:
|
||||
raise ValueError("wire type")
|
||||
if at > len(data):
|
||||
raise ValueError("length")
|
||||
if kind == 2 and tag >> 3 == path[0]:
|
||||
value = data[body:at]
|
||||
value = change(value) if len(path) == 1 else rewrite_field(value, path[1:], change)
|
||||
out += encode_varint(tag) + encode_varint(len(value)) + value
|
||||
else:
|
||||
out += data[start:at]
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def drive_folder(root, value):
|
||||
try:
|
||||
text = value.decode("utf-8")
|
||||
except UnicodeDecodeError:
|
||||
return value
|
||||
if not re.match(r"(?i)^z:[\\/]", text):
|
||||
return value
|
||||
folder = windows_path(root, text)
|
||||
if not folder or not os.path.isdir(folder):
|
||||
return value
|
||||
moved = install_path(root, folder)
|
||||
return value if moved.startswith("Z:") else moved.replace("\\", "/").encode("utf-8")
|
||||
|
||||
|
||||
def move_installs(root):
|
||||
path = os.path.join(drive_c(root), *PRODUCT_DB)
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
moved = rewrite_field(data, INSTALL_FOLDER, lambda value: drive_folder(root, value))
|
||||
if moved == data or wine_processes(os.path.join(prefix(root), "pfx")):
|
||||
return False
|
||||
with open(path, "rb") as f:
|
||||
if f.read() != data:
|
||||
return False
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
with open(path + ".tmp", "wb") as f:
|
||||
f.write(moved)
|
||||
shutil.copymode(path, path + ".tmp")
|
||||
os.replace(path + ".tmp", path)
|
||||
return True
|
||||
|
||||
|
||||
def wow_folders(root):
|
||||
@@ -533,6 +701,11 @@ def configure(root, library=None):
|
||||
except OSError as error:
|
||||
say("Battle.net's config not written: %s" % error)
|
||||
return
|
||||
try:
|
||||
if move_installs(root):
|
||||
say("Battle.net's installed games on a mapped volume now use its Wine drive")
|
||||
except OSError as error:
|
||||
say("Battle.net's installed games not moved to their Wine drive: %s" % error)
|
||||
try:
|
||||
wallpaper(root)
|
||||
except OSError as error:
|
||||
@@ -1211,7 +1384,7 @@ def summary(status):
|
||||
return out
|
||||
|
||||
|
||||
def agent_job(root, action, uid, product="", folder="", locale="enUS", country="USA", region="US", poll=None, wait=None):
|
||||
def agent_job(root, action, uid, product="", folder="", locale="enUS", country="USA", region="US", poll=None, wait=None, stall=None):
|
||||
pfx = os.path.join(prefix(root), "pfx")
|
||||
if not installed(root) or agent_exe(root) is None:
|
||||
emit("ERROR", "client")
|
||||
@@ -1227,7 +1400,6 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
say("%s not made: %s" % (folder, error))
|
||||
emit("ERROR", "folder")
|
||||
return 2
|
||||
windows = "Z:" + folder
|
||||
told = None
|
||||
while True:
|
||||
processes = wine_processes(pfx)
|
||||
@@ -1244,6 +1416,8 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
with lock:
|
||||
stop_leftovers(pfx)
|
||||
if action == "install":
|
||||
windows = install_path(root, folder)
|
||||
emit("STATE", "starting")
|
||||
base = os.path.join(CACHE, "agent-%s" % uid)
|
||||
for suffix in (".json", ".game", ".form", ".error"):
|
||||
@@ -1266,6 +1440,7 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
os.replace(output, output + ".1")
|
||||
except OSError:
|
||||
pass
|
||||
before = {pid for pid, _ in wine_processes(pfx)}
|
||||
with open(output, "ab") as log:
|
||||
try:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=log, stderr=log, env=env)
|
||||
@@ -1273,6 +1448,9 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
emit("ERROR", "stopped gamescope: %s" % error)
|
||||
return 1
|
||||
seen = None
|
||||
mark = None
|
||||
moved = time.monotonic()
|
||||
stalled = False
|
||||
while True:
|
||||
done = child.poll() is not None
|
||||
status = read_status(base + ".json")
|
||||
@@ -1281,12 +1459,27 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
if brief != seen:
|
||||
emit("PROGRESS", json.dumps(brief, sort_keys=True))
|
||||
seen = brief
|
||||
signature = tuple(brief.get(key) for key in MOVING)
|
||||
if signature != mark:
|
||||
mark = signature
|
||||
moved = time.monotonic()
|
||||
if done:
|
||||
break
|
||||
if action != "uninstall" and time.monotonic() - moved > (STALL if stall is None else stall):
|
||||
say("the %s of %s made no progress for %d s; stopping it" % (action, uid, STALL if stall is None else stall))
|
||||
stalled = True
|
||||
child.kill()
|
||||
child.wait()
|
||||
break
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
leftovers = wine_processes(pfx)
|
||||
if leftovers and idle(leftovers):
|
||||
stop(leftovers)
|
||||
elif stalled:
|
||||
stop([(pid, argv) for pid, argv in leftovers if pid not in before and program(argv) == AGENT])
|
||||
if stalled:
|
||||
emit("ERROR", "stalled")
|
||||
return 6
|
||||
answer = read_status(base + ".game")
|
||||
game = answer or {}
|
||||
status = read_status(base + ".json") or {}
|
||||
|
||||
@@ -4,7 +4,6 @@ import collections
|
||||
import fcntl
|
||||
import filecmp
|
||||
import http.client
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -72,6 +71,14 @@ APP_ID = "com.epicgames.eglv2"
|
||||
DBUS_NAME = APP_ID + ".SingleInstance"
|
||||
DBUS_PATH = "/" + APP_ID.replace(".", "/") + "/SingleInstance"
|
||||
DBUS_METHOD = "org.SingleInstance.DBus.ExecuteCallback"
|
||||
APP_BIN = "usr/bin/EpicGamesLauncher"
|
||||
DEB_ICON = "usr/share/icons/hicolor/256x256@2/apps/EpicGamesLauncher.png"
|
||||
ICON = "epic-games-launcher.png"
|
||||
DESKTOP = "desktop"
|
||||
DESKTOP_KEEP = ("usr/lib/x86_64-linux-gnu/", "usr/share/glib-2.0/schemas/")
|
||||
DESKTOP_LIB = DESKTOP + "/usr/lib/x86_64-linux-gnu"
|
||||
WEBKIT_DIR = "webkit2gtk-4.1"
|
||||
WEBKIT_LIB = "libwebkit2gtk-4.1.so.0"
|
||||
SKIPPED = ("lib/i386-linux-gnu", "lib32", "libx32", "i686-pc-linux-gnu", "share/doc", "include")
|
||||
SETTINGS_SEED = {
|
||||
"minimizeToTray": False,
|
||||
@@ -254,6 +261,35 @@ def inside(root, path):
|
||||
return real == root or real.startswith(root + os.sep)
|
||||
|
||||
|
||||
def unpack_member(archive, member, staging, root, name, link):
|
||||
target = os.path.join(staging, name)
|
||||
if not inside(root, os.path.dirname(target)):
|
||||
return False
|
||||
if member.isdir():
|
||||
os.makedirs(target, exist_ok=True)
|
||||
return False
|
||||
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||
if not inside(root, os.path.dirname(target)):
|
||||
return False
|
||||
if member.issym():
|
||||
remove(target)
|
||||
os.symlink(link(target, member.linkname), target)
|
||||
elif member.islnk():
|
||||
source = safe_name(member.linkname)
|
||||
source = os.path.join(staging, source) if source else None
|
||||
if source and os.path.isfile(source) and inside(root, source):
|
||||
remove(target)
|
||||
shutil.copy2(source, target)
|
||||
elif member.isfile():
|
||||
remove(target)
|
||||
with archive.extractfile(member) as src, open(target, "wb") as out:
|
||||
shutil.copyfileobj(src, out, 1 << 20)
|
||||
os.chmod(target, (member.mode & 0o777) | 0o600)
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def extract_runtime(tarball, dest):
|
||||
staging = dest + ".staging"
|
||||
remove(staging)
|
||||
@@ -271,32 +307,12 @@ def extract_runtime(tarball, dest):
|
||||
continue
|
||||
if top == "files" and rest and skipped(rest):
|
||||
continue
|
||||
target = os.path.join(staging, name)
|
||||
if not inside(root, os.path.dirname(target)):
|
||||
continue
|
||||
if member.isdir():
|
||||
os.makedirs(target, exist_ok=True)
|
||||
continue
|
||||
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||
if not inside(root, os.path.dirname(target)):
|
||||
continue
|
||||
if member.issym():
|
||||
remove(target)
|
||||
os.symlink(rooted_link(files_root, target, member.linkname) if top == "files" else member.linkname, target)
|
||||
elif member.islnk():
|
||||
source = safe_name(member.linkname)
|
||||
source = os.path.join(staging, source) if source else None
|
||||
if source and os.path.isfile(source) and inside(root, source):
|
||||
remove(target)
|
||||
shutil.copy2(source, target)
|
||||
elif member.isfile():
|
||||
remove(target)
|
||||
with archive.extractfile(member) as src, open(target, "wb") as out:
|
||||
shutil.copyfileobj(src, out, 1 << 20)
|
||||
os.chmod(target, (member.mode & 0o777) | 0o600)
|
||||
if top == "files":
|
||||
link = lambda target, linkname: rooted_link(files_root, target, linkname)
|
||||
else:
|
||||
continue
|
||||
count += 1
|
||||
link = lambda target, linkname: linkname
|
||||
if unpack_member(archive, member, staging, root, name, link):
|
||||
count += 1
|
||||
if not os.path.isfile(os.path.join(files_root, "lib", "x86_64-linux-gnu", "libc.so.6")) and \
|
||||
not os.path.islink(os.path.join(files_root, "lib", "x86_64-linux-gnu", "libc.so.6")):
|
||||
remove(staging)
|
||||
@@ -306,63 +322,129 @@ def extract_runtime(tarball, dest):
|
||||
return staging, count
|
||||
|
||||
|
||||
def ar_members(path):
|
||||
@contextlib.contextmanager
|
||||
def deb_data(path, reason):
|
||||
with open(path, "rb") as f:
|
||||
if f.read(8) != b"!<arch>\n":
|
||||
raise Failure("gles-format")
|
||||
raise Failure(reason)
|
||||
while True:
|
||||
header = f.read(60)
|
||||
if len(header) < 60:
|
||||
return
|
||||
raise Failure(reason)
|
||||
name = header[:16].decode("ascii", "replace").strip().rstrip("/")
|
||||
size = int(header[48:58].decode("ascii").strip())
|
||||
data = f.read(size)
|
||||
if size % 2:
|
||||
f.read(1)
|
||||
yield name, data
|
||||
if name.startswith("data.tar"):
|
||||
with tarfile.open(fileobj=f, mode="r|*") as archive:
|
||||
yield archive
|
||||
return
|
||||
f.seek(size + size % 2, os.SEEK_CUR)
|
||||
|
||||
|
||||
def is_deb(path):
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
return f.read(21) == b"!<arch>\ndebian-binary"
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def install_gles(deb, files_root):
|
||||
libdir = os.path.join(files_root, "lib", "x86_64-linux-gnu")
|
||||
os.makedirs(libdir, exist_ok=True)
|
||||
for name, data in ar_members(deb):
|
||||
if not name.startswith("data.tar"):
|
||||
continue
|
||||
with tarfile.open(fileobj=io.BytesIO(data), mode="r:*") as archive:
|
||||
for member in archive:
|
||||
base = os.path.basename(member.name)
|
||||
if not base.startswith("libGLESv2.so"):
|
||||
continue
|
||||
target = os.path.join(libdir, base)
|
||||
remove(target)
|
||||
if member.issym():
|
||||
os.symlink(os.path.basename(member.linkname), target)
|
||||
elif member.isfile():
|
||||
with archive.extractfile(member) as src, open(target, "wb") as out:
|
||||
shutil.copyfileobj(src, out)
|
||||
os.chmod(target, 0o644)
|
||||
if os.path.exists(os.path.join(libdir, "libGLESv2.so.2")):
|
||||
return
|
||||
raise Failure("gles-missing")
|
||||
with deb_data(deb, "gles-format") as archive:
|
||||
for member in archive:
|
||||
base = os.path.basename(member.name)
|
||||
if not base.startswith("libGLESv2.so"):
|
||||
continue
|
||||
target = os.path.join(libdir, base)
|
||||
remove(target)
|
||||
if member.issym():
|
||||
os.symlink(os.path.basename(member.linkname), target)
|
||||
elif member.isfile():
|
||||
with archive.extractfile(member) as src, open(target, "wb") as out:
|
||||
shutil.copyfileobj(src, out)
|
||||
os.chmod(target, 0o644)
|
||||
if not os.path.exists(os.path.join(libdir, "libGLESv2.so.2")):
|
||||
raise Failure("gles-missing")
|
||||
|
||||
|
||||
def extract_app(image, dest):
|
||||
def extract_deb(deb, dest, wanted=None):
|
||||
root = os.path.realpath(dest)
|
||||
|
||||
def link(target, linkname):
|
||||
if not linkname.startswith("/"):
|
||||
return linkname
|
||||
return os.path.relpath(os.path.join(dest, linkname.lstrip("/")), os.path.dirname(target))
|
||||
|
||||
count = 0
|
||||
with deb_data(deb, "app-format") as archive:
|
||||
for member in archive:
|
||||
name = safe_name(member.name)
|
||||
if name is None or (wanted is not None and not wanted(name)):
|
||||
continue
|
||||
if unpack_member(archive, member, dest, root, name, link):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def extract_app(image, dest, desktop=()):
|
||||
staging = dest + ".staging"
|
||||
remove(staging)
|
||||
os.makedirs(staging)
|
||||
status = subprocess.call([os.path.join(BIN_DIR, "droiddeck-fex"), "extract", os.path.abspath(image)],
|
||||
cwd=staging, stdout=subprocess.DEVNULL)
|
||||
root = os.path.realpath(os.path.join(staging, "squashfs-root"))
|
||||
if status != 0 or not app_complete(root):
|
||||
try:
|
||||
if not is_deb(image):
|
||||
raise Failure("app-format")
|
||||
extract_deb(image, staging)
|
||||
layer = os.path.join(staging, DESKTOP)
|
||||
if not inside(os.path.realpath(staging), layer):
|
||||
raise Failure("app-extract")
|
||||
os.makedirs(layer, exist_ok=True)
|
||||
for package in desktop:
|
||||
if not is_deb(package):
|
||||
raise Failure("desktop-format")
|
||||
extract_deb(package, layer, lambda name: any(name.startswith(prefix) for prefix in DESKTOP_KEEP))
|
||||
icon = os.path.join(staging, DEB_ICON)
|
||||
if os.path.isfile(icon):
|
||||
remove(os.path.join(staging, ICON))
|
||||
shutil.copyfile(icon, os.path.join(staging, ICON))
|
||||
if not app_complete(staging):
|
||||
raise Failure("app-extract")
|
||||
except Exception:
|
||||
remove(staging)
|
||||
raise Failure("app-extract")
|
||||
raise
|
||||
remove(dest)
|
||||
os.rename(root, dest)
|
||||
remove(staging)
|
||||
os.rename(staging, dest)
|
||||
|
||||
|
||||
def app_complete(root):
|
||||
return os.path.isfile(os.path.join(root, "AppRun")) and os.path.isfile(os.path.join(root, "usr", "bin", "EpicGamesLauncher"))
|
||||
if not os.path.isfile(os.path.join(root, APP_BIN)):
|
||||
return False
|
||||
return os.path.isfile(os.path.join(root, "AppRun")) or os.path.isfile(os.path.join(root, DESKTOP_LIB, WEBKIT_LIB))
|
||||
|
||||
|
||||
def app_command(app_dir):
|
||||
apprun = os.path.join(app_dir, "AppRun")
|
||||
return apprun if os.path.isfile(apprun) else os.path.join(app_dir, APP_BIN)
|
||||
|
||||
|
||||
def desktop_libs(app_dir):
|
||||
path = os.path.join(app_dir, DESKTOP_LIB)
|
||||
return path if os.path.isdir(path) else None
|
||||
|
||||
|
||||
def link_webkit(files, libs):
|
||||
target = os.path.join(files, "lib", "x86_64-linux-gnu", WEBKIT_DIR)
|
||||
if os.path.isdir(target) and not os.path.islink(target):
|
||||
return
|
||||
source = os.path.join(libs, WEBKIT_DIR) if libs else None
|
||||
if source is None or not os.path.isdir(source):
|
||||
remove(target)
|
||||
return
|
||||
link = os.path.relpath(source, os.path.dirname(target))
|
||||
if os.path.islink(target) and os.readlink(target) == link:
|
||||
return
|
||||
remove(target)
|
||||
os.symlink(link, target)
|
||||
|
||||
|
||||
def ready(path):
|
||||
@@ -396,8 +478,11 @@ def install(options):
|
||||
image = options.get("app")
|
||||
if not image or not os.path.isfile(image):
|
||||
raise Failure("no-app-image")
|
||||
say("unpacking the Epic Games Launcher %s" % app)
|
||||
extract_app(image, app_dir)
|
||||
desktop = options.get("desktop") or []
|
||||
if not all(os.path.isfile(package) for package in desktop):
|
||||
raise Failure("no-desktop-package")
|
||||
say("unpacking the Epic Games Launcher %s (%d desktop packages)" % (app, len(desktop)))
|
||||
extract_app(image, app_dir, desktop)
|
||||
mark_ready(app_dir)
|
||||
if not ready(runtime_dir):
|
||||
tarball, deb = options.get("runtime"), options.get("gles")
|
||||
@@ -729,11 +814,16 @@ def fex_environment(fex, files, env):
|
||||
return result
|
||||
|
||||
|
||||
def client_environment(base, fex, files, display, bus, broker, a11y=None, hidden=False):
|
||||
def client_environment(base, fex, files, display, bus, broker, a11y=None, hidden=False, libs=None):
|
||||
env = {name: base[name] for name in KEPT_ENV if base.get(name)}
|
||||
env.setdefault("HOME", HOME)
|
||||
env.setdefault("LANG", "C.UTF-8")
|
||||
env["PATH"] = SHIMS + ":/usr/bin:/bin"
|
||||
if libs:
|
||||
env["LD_LIBRARY_PATH"] = libs
|
||||
data = os.path.normpath(os.path.join(os.path.dirname(libs), "..", "share"))
|
||||
env["XDG_DATA_DIRS"] = data + ":/usr/local/share:/usr/share"
|
||||
env["GSETTINGS_SCHEMA_DIR"] = os.path.join(data, "glib-2.0", "schemas")
|
||||
env["DISPLAY"] = display
|
||||
env["DBUS_SESSION_BUS_ADDRESS"] = bus
|
||||
env[BROKER_ENV] = broker
|
||||
@@ -1238,6 +1328,8 @@ class Session:
|
||||
seed_settings()
|
||||
install_shims()
|
||||
install_preload(files)
|
||||
libs = desktop_libs(app_dir)
|
||||
link_webkit(files, libs)
|
||||
fex_module()["install_fonts"](files)
|
||||
clear_playing()
|
||||
sync_installations()
|
||||
@@ -1254,8 +1346,8 @@ class Session:
|
||||
path = broker_path()
|
||||
self.broker = Broker(path, self.mode, base)
|
||||
write_json(instance_file(), {"pid": os.getpid(), "mode": self.mode, "bus": bus, "broker": path})
|
||||
env = client_environment(base, fex, files, display, bus, path, self.a11y, hidden=self.mode == "hidden")
|
||||
self.command = [fex["bin"], os.path.join(app_dir, "AppRun")]
|
||||
env = client_environment(base, fex, files, display, bus, path, self.a11y, hidden=self.mode == "hidden", libs=libs)
|
||||
self.command = [fex["bin"], app_command(app_dir)]
|
||||
self.env = env
|
||||
say("starting the Epic Games Launcher %s (%s, display %s)" % (current.get("app"), self.mode, display))
|
||||
self.start_client()
|
||||
@@ -1471,12 +1563,14 @@ def forward(bus, url):
|
||||
return False
|
||||
|
||||
|
||||
def parse_options(args, flags=()):
|
||||
def parse_options(args, flags=(), lists=()):
|
||||
options, rest = {}, []
|
||||
while args:
|
||||
arg = args.pop(0)
|
||||
if arg.startswith("--") and arg[2:] in flags:
|
||||
options[arg[2:]] = True
|
||||
elif arg.startswith("--") and arg[2:] in lists and args:
|
||||
options.setdefault(arg[2:], []).append(args.pop(0))
|
||||
elif arg.startswith("--") and args:
|
||||
options[arg[2:]] = args.pop(0)
|
||||
else:
|
||||
@@ -1830,7 +1924,7 @@ def main(argv):
|
||||
if action == "xdg-open":
|
||||
return shim_open(args)
|
||||
if action == "install":
|
||||
options, _ = parse_options(args)
|
||||
options, _ = parse_options(args, lists=("desktop",))
|
||||
try:
|
||||
return install(options)
|
||||
except (ValueError, tarfile.TarError, OSError) as error:
|
||||
|
||||
@@ -10,24 +10,46 @@ import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
|
||||
GAME_PREFIX = "DROIDDECK_GAME_"
|
||||
GAME_SPLIT_KEYS = ("TU_DEBUG", "MESA_NO_ERROR")
|
||||
CHROMIUM_FILES = {"chrome-sandbox", "chrome_100_percent.pak", "v8_context_snapshot.bin"}
|
||||
D3D9_DEFAULT_MEMORY_MB = 4096
|
||||
SYNC_KEYS = ("BL_SYNC", "BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
|
||||
SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
|
||||
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
|
||||
|
||||
|
||||
# Prefixes several games share; the game itself is the Steam app being launched.
|
||||
SHARED_PREFIXES = {"2929927072"}
|
||||
|
||||
|
||||
def app_number(value):
|
||||
if not re.fullmatch(r"-?[0-9]+", value or ""):
|
||||
return None
|
||||
number = int(value)
|
||||
if not -(2**31) <= number < 2**32 or number == 0:
|
||||
return None
|
||||
return str(number % 2**32)
|
||||
|
||||
|
||||
def game_id(env):
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
if not prefix:
|
||||
return None
|
||||
value = prefix.rsplit("/", 1)[-1]
|
||||
if not re.fullmatch(r"-?[0-9]+", value):
|
||||
found = app_number(prefix.rsplit("/", 1)[-1])
|
||||
if found in SHARED_PREFIXES:
|
||||
return app_number(env.get("SteamAppId", "")) or shortcut_number(env.get("SteamGameId", "")) or found
|
||||
return found
|
||||
|
||||
|
||||
def shortcut_number(value):
|
||||
"""The shortcut appid inside Steam's 64-bit shortcut game id `(appid << 32) | 0x02000000`."""
|
||||
if not re.fullmatch(r"[0-9]{1,20}", value or ""):
|
||||
return None
|
||||
number = int(value)
|
||||
if not -(2**31) <= number < 2**32 or number == 0:
|
||||
if number >= 2**64 or number & 0xFFFFFFFF != 0x02000000:
|
||||
return None
|
||||
return str(number % 2**32)
|
||||
return app_number(str(number >> 32))
|
||||
|
||||
|
||||
DOTNET_FEX = {
|
||||
@@ -124,6 +146,12 @@ def deep_rock_gdk_raytracing(game):
|
||||
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 ff7_rebirth_feature_level(game):
|
||||
if game.stem in ("ff7rebirth", "ff7rebirth_"):
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_2"}, [], "Final Fantasy VII Rebirth: D3D12 feature level 12_2 (the device-reported level fails its DX12 check)"
|
||||
|
||||
|
||||
@fix
|
||||
def arkham_city_x87(game):
|
||||
if "batmanac.exe" in game.files:
|
||||
@@ -358,16 +386,19 @@ def chromium_app(folder):
|
||||
|
||||
|
||||
def game_gpu(env, keep=False):
|
||||
if GAME_TU_DEBUG not in env:
|
||||
if not any(GAME_PREFIX + key in env for key in GAME_SPLIT_KEYS):
|
||||
return env
|
||||
result = env.copy()
|
||||
value = result.pop(GAME_TU_DEBUG)
|
||||
if keep:
|
||||
return result
|
||||
if value:
|
||||
result["TU_DEBUG"] = value
|
||||
else:
|
||||
result.pop("TU_DEBUG", None)
|
||||
for key in GAME_SPLIT_KEYS:
|
||||
if GAME_PREFIX + key not in result:
|
||||
continue
|
||||
value = result.pop(GAME_PREFIX + key)
|
||||
if keep:
|
||||
continue
|
||||
if value:
|
||||
result[key] = value
|
||||
else:
|
||||
result.pop(key, None)
|
||||
return result
|
||||
|
||||
|
||||
@@ -376,7 +407,9 @@ def vram_cap(env):
|
||||
if not re.fullmatch(r"[1-9][0-9]{0,6}", value):
|
||||
return env
|
||||
result = env.copy()
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
cap = "dxgi.maxDeviceMemory = {0}; dxgi.maxSharedMemory = {0}".format(int(value))
|
||||
if int(value) < D3D9_DEFAULT_MEMORY_MB:
|
||||
cap += "; d3d9.maxAvailableMemory = {0}".format(int(value))
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
result["DROIDDECK_VRAM_CAP"] = "1"
|
||||
@@ -1250,6 +1283,10 @@ def main():
|
||||
if scripts and install_scripts_done(scripts, env):
|
||||
print("droiddeck-game-env: install scripts already run in this prefix; evaluator skipped", file=sys.stderr)
|
||||
return 0
|
||||
if scripts and not env.get("DBUS_SESSION_BUS_ADDRESS"):
|
||||
# libdbus would autolaunch a session bus under the evaluator's reaper, which then waits for it
|
||||
# forever: Steam keeps seeing the app as running and cannot move or update it
|
||||
env["DBUS_SESSION_BUS_ADDRESS"] = "disabled:"
|
||||
try:
|
||||
digest = scripts_digest(scripts) if scripts else None
|
||||
except OSError:
|
||||
|
||||
@@ -17,6 +17,7 @@ PROTON_RUN = os.path.join(BIN, "droiddeck-proton-run")
|
||||
APPIMAGE_RUN = os.path.join(BIN, "droiddeck-appimage-run")
|
||||
SCRIPT_RUN = os.path.join(BIN, "droiddeck-script-run")
|
||||
STEAM_LAUNCH = os.path.join(BIN, "droiddeck-steam-launch")
|
||||
STORE_LAUNCH = os.path.join(BIN, "droiddeck-store-launch")
|
||||
PROGRAMS = os.path.join(BIN, "droiddeck-desktop-programs")
|
||||
CACHE = os.path.join(HOME, ".cache", "droiddeck")
|
||||
IMPORTS = {"appimage": ("/opt/appimages/user", "app"), "folder": ("/opt/droiddeck-apps", "entry")}
|
||||
@@ -272,12 +273,32 @@ def steam_title(path):
|
||||
return None
|
||||
|
||||
|
||||
def exe_prefix(path):
|
||||
try:
|
||||
run = runpy.run_path(PROTON_RUN)
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or run["STEAM_ROOT"]
|
||||
target = run["locate"](path, root)
|
||||
return ["--prefix", target.appid, "--compatdata", target.compatdata]
|
||||
except (OSError, ValueError, KeyError, IndexError):
|
||||
return None
|
||||
|
||||
|
||||
def store_launcher(path):
|
||||
try:
|
||||
return runpy.run_path(STORE_LAUNCH)["store_launcher"](path)
|
||||
except (OSError, ValueError, KeyError):
|
||||
return None
|
||||
|
||||
|
||||
def command(path, args, what, window=False, appid=None):
|
||||
folder = os.path.dirname(path)
|
||||
if what == "steam":
|
||||
return [STEAM_LAUNCH, "desktop", appid], folder
|
||||
if what == "windows":
|
||||
return [PROTON_RUN] + (["--window"] if window else []) + [path] + args, folder
|
||||
launcher = None if args else store_launcher(path)
|
||||
prefix = exe_prefix(path) if launcher else None
|
||||
keep = prefix or []
|
||||
return [PROTON_RUN] + (["--window"] if window else []) + keep + [launcher or path] + args, folder
|
||||
if what == "x86 script":
|
||||
return [FEX, "run", "--mode", "on", "--for", folder, "--"] + interpreter(path) + [path] + args, folder
|
||||
if what == "script":
|
||||
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import signal
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
MAGIC = 0x46484444
|
||||
HEADER = 128
|
||||
POLL = 0.5
|
||||
SETTLE = 3.0
|
||||
WINDOW = 1.0
|
||||
LATE = 1.5
|
||||
PACED_LATE_SHARE = 0.02
|
||||
RELEASE_LATE_SHARE = 0.05
|
||||
SLOWER = 1.04
|
||||
MAX_INTERVAL = 1e9 / 30
|
||||
SPREAD = 0.08
|
||||
BACKOFF = 30.0
|
||||
BACKOFF_MAX = 600.0
|
||||
|
||||
|
||||
def log(message):
|
||||
print("droiddeck-pace-cores: " + message, flush=True)
|
||||
|
||||
|
||||
def parse_cores(text):
|
||||
cores = set()
|
||||
for part in text.strip().split(","):
|
||||
if not part:
|
||||
continue
|
||||
first, _, last = part.partition("-")
|
||||
cores.update(range(int(first), int(last or first) + 1))
|
||||
return cores
|
||||
|
||||
|
||||
def efficient_cores(cpu=Path("/sys/devices/system/cpu"), own=None):
|
||||
try:
|
||||
online = parse_cores((cpu / "online").read_text())
|
||||
except (OSError, ValueError):
|
||||
online = set(range(os.cpu_count() or 0))
|
||||
online &= own if own is not None else os.sched_getaffinity(0)
|
||||
for name in ("cpu_capacity", "cpufreq/cpuinfo_max_freq"):
|
||||
try:
|
||||
speed = {core: int((cpu / f"cpu{core}/{name}").read_text()) for core in online}
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
top = max(speed.values(), default=0)
|
||||
return {core for core, value in speed.items() if value < top}
|
||||
return set()
|
||||
|
||||
|
||||
class Frames:
|
||||
"""gamescope's per-frame feed for the HUD: frame intervals of the focused app, its pid and whether Steam is in front."""
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = Path(path)
|
||||
self.count = None
|
||||
|
||||
def read(self):
|
||||
try:
|
||||
data = self.path.read_bytes()
|
||||
except OSError:
|
||||
return None
|
||||
if len(data) < HEADER or struct.unpack_from("<I", data, 0)[0] != MAGIC:
|
||||
return None
|
||||
capacity, pid = struct.unpack_from("<II", data, 8)
|
||||
count, = struct.unpack_from("<Q", data, 16)
|
||||
steam, = struct.unpack_from("<I", data, 40)
|
||||
last = self.count if self.count is not None else count
|
||||
self.count = count
|
||||
first = max(last, count - capacity)
|
||||
intervals = [struct.unpack_from("<Q", data, HEADER + (i % capacity) * 16)[0] for i in range(first, count)]
|
||||
return pid, bool(steam), intervals
|
||||
|
||||
|
||||
def median(values):
|
||||
ordered = sorted(values)
|
||||
return ordered[len(ordered) // 2]
|
||||
|
||||
|
||||
def late_share(intervals, period):
|
||||
return sum(1 for value in intervals if value > LATE * period) / len(intervals)
|
||||
|
||||
|
||||
def paced_interval(intervals):
|
||||
"""The interval of a game a cap holds at 30 fps or more; a starved or uncapped game spreads."""
|
||||
if len(intervals) < 2:
|
||||
return None
|
||||
ordered = sorted(intervals)
|
||||
held = ordered[len(ordered) // 2]
|
||||
if held > 1.04 * MAX_INTERVAL:
|
||||
return None
|
||||
if ordered[len(ordered) // 10] < (1 - SPREAD) * held or ordered[len(ordered) * 9 // 10] > (1 + SPREAD) * held:
|
||||
return None
|
||||
if late_share(intervals, held) > PACED_LATE_SHARE:
|
||||
return None
|
||||
return held
|
||||
|
||||
|
||||
class Cores:
|
||||
|
||||
def get(self, tid):
|
||||
return os.sched_getaffinity(tid)
|
||||
|
||||
def set(self, tid, cpus):
|
||||
os.sched_setaffinity(tid, cpus)
|
||||
|
||||
|
||||
class Parker:
|
||||
"""Keeps one process's threads off the fastest cores and puts back what each had."""
|
||||
|
||||
def __init__(self, efficient, proc=Path("/proc"), cores=None):
|
||||
self.efficient = efficient
|
||||
self.proc = proc
|
||||
self.cores = cores or Cores()
|
||||
self.pid = None
|
||||
self.before = {}
|
||||
self.present = None
|
||||
self.own = set()
|
||||
|
||||
def tasks(self, pid):
|
||||
try:
|
||||
return [int(tid) for tid in os.listdir(self.proc / str(pid) / "task") if tid.isdigit()]
|
||||
except OSError:
|
||||
return []
|
||||
|
||||
def park(self, pid):
|
||||
self.pid = pid
|
||||
tids = self.tasks(pid)
|
||||
if self.present is None:
|
||||
self.present = set(tids)
|
||||
masks = {}
|
||||
for tid in tids:
|
||||
if tid not in self.before:
|
||||
try:
|
||||
masks[tid] = self.cores.get(tid)
|
||||
except OSError:
|
||||
continue
|
||||
# A mask the game gave one of its own threads may be passed on by it, not by a parked thread.
|
||||
self.own.update(frozenset(now) for tid, now in masks.items() if tid in self.present)
|
||||
inherited = {}
|
||||
for before, parked in self.before.values():
|
||||
inherited[frozenset(parked)] = inherited.get(frozenset(parked), set()) | before
|
||||
for tid, now in masks.items():
|
||||
try:
|
||||
wanted = now & self.efficient
|
||||
if wanted and wanted != now:
|
||||
self.cores.set(tid, wanted)
|
||||
self.before[tid] = (now, wanted)
|
||||
elif tid not in self.present and frozenset(now) in inherited and frozenset(now) not in self.own:
|
||||
self.before[tid] = (inherited[frozenset(now)], now)
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
def release(self):
|
||||
for tid, (before, parked) in self.before.items():
|
||||
try:
|
||||
if self.cores.get(tid) == parked:
|
||||
self.cores.set(tid, before)
|
||||
except OSError:
|
||||
continue
|
||||
self.pid = None
|
||||
self.present = None
|
||||
self.own.clear()
|
||||
self.before.clear()
|
||||
|
||||
|
||||
class Governor:
|
||||
def __init__(self, frames, parker, clock=time.monotonic):
|
||||
self.frames = frames
|
||||
self.parker = parker
|
||||
self.clock = clock
|
||||
self.pid = None
|
||||
self.window = []
|
||||
self.since = None
|
||||
self.held = None
|
||||
self.blocked = {}
|
||||
|
||||
def tick(self):
|
||||
read = self.frames.read()
|
||||
if read is None:
|
||||
return
|
||||
pid, steam, intervals = read
|
||||
now = self.clock()
|
||||
if steam or not pid or pid != self.pid:
|
||||
if self.parker.pid is not None:
|
||||
self.release(now, "focus left the game", backoff=False)
|
||||
self.pid = None if steam else pid
|
||||
self.window, self.since = [], now
|
||||
return
|
||||
self.window.extend((now, value) for value in intervals)
|
||||
if self.parker.pid is None and not intervals:
|
||||
self.window, self.since = [], now
|
||||
return
|
||||
if self.parker.pid is None:
|
||||
self.consider(now)
|
||||
else:
|
||||
self.watch(now)
|
||||
|
||||
def consider(self, now):
|
||||
self.window = [entry for entry in self.window if entry[0] >= now - SETTLE]
|
||||
if now - self.since < SETTLE or now < self.blocked.get(self.pid, (0, 0))[0]:
|
||||
return
|
||||
intervals = [value for _, value in self.window]
|
||||
if sum(intervals) < 0.9 * SETTLE * 1e9:
|
||||
return
|
||||
held = paced_interval(intervals)
|
||||
if held is None:
|
||||
return
|
||||
self.held = held
|
||||
self.parker.park(self.pid)
|
||||
if self.parker.before:
|
||||
self.window = []
|
||||
self.since = now
|
||||
log(f"pid {self.pid} holds {1e9 / held:.0f} fps, {len(self.parker.before)} thread(s) off the fastest cores")
|
||||
else:
|
||||
self.parker.release()
|
||||
|
||||
def watch(self, now):
|
||||
self.parker.park(self.pid)
|
||||
self.window = [entry for entry in self.window if entry[0] >= now - WINDOW]
|
||||
intervals = [value for _, value in self.window]
|
||||
if now - self.since < WINDOW:
|
||||
return
|
||||
if len(intervals) < 0.5 * WINDOW * 1e9 / self.held:
|
||||
self.release(now, "frames stalled")
|
||||
return
|
||||
if late_share(intervals, self.held) > RELEASE_LATE_SHARE or median(intervals) > SLOWER * self.held:
|
||||
self.release(now, "frames fell behind")
|
||||
|
||||
def release(self, now, why, backoff=True):
|
||||
pid = self.parker.pid
|
||||
self.parker.release()
|
||||
if backoff:
|
||||
_, wait = self.blocked.get(pid, (0, BACKOFF / 2))
|
||||
wait = min(wait * 2, BACKOFF_MAX)
|
||||
self.blocked[pid] = (now + wait, wait)
|
||||
log(f"pid {pid} back on every core: {why}; not again for {wait:.0f} s")
|
||||
else:
|
||||
log(f"pid {pid} back on every core: {why}")
|
||||
self.window, self.since = [], now
|
||||
|
||||
def stop(self, *_):
|
||||
self.parker.release()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 1:
|
||||
print("usage: droiddeck-pace-cores <gamescope HUD frames file>", file=sys.stderr)
|
||||
return 2
|
||||
efficient = efficient_cores()
|
||||
if not efficient:
|
||||
return 0
|
||||
governor = Governor(Frames(argv[0]), Parker(efficient))
|
||||
for sig in (signal.SIGTERM, signal.SIGHUP, signal.SIGINT):
|
||||
signal.signal(sig, governor.stop)
|
||||
while True:
|
||||
governor.tick()
|
||||
time.sleep(POLL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -315,8 +315,8 @@ def locate(program, root):
|
||||
os.path.dirname(program), root, "own")
|
||||
|
||||
|
||||
def fixed(program, root, appid):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
def fixed(program, root, appid, compatdata=None):
|
||||
return Target(appid, compatdata or os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
os.path.dirname(program), root, "fixed")
|
||||
|
||||
|
||||
@@ -451,6 +451,7 @@ def arguments(program, args, desktop=None, compatdata=None):
|
||||
def main(argv):
|
||||
window = False
|
||||
prefix = None
|
||||
compatdata = None
|
||||
verb = VERB
|
||||
game_id = None
|
||||
desktop = None
|
||||
@@ -461,6 +462,8 @@ def main(argv):
|
||||
window = True
|
||||
elif option == "--prefix" and argv and prefix_id(argv[0]):
|
||||
prefix = argv.pop(0)
|
||||
elif option == "--compatdata" and argv and os.path.isabs(argv[0]):
|
||||
compatdata = argv.pop(0)
|
||||
elif option == "--verb" and argv and argv[0] in VERBS:
|
||||
verb = argv.pop(0)
|
||||
elif option == "--game-id" and argv and argv[0].isdigit() and argv[0] != "0":
|
||||
@@ -484,7 +487,7 @@ def main(argv):
|
||||
say("%s is not an app id" % app)
|
||||
return 2
|
||||
if not argv and app is None:
|
||||
say("usage: droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]")
|
||||
say("usage: droiddeck-proton-run [--window] [--prefix ID [--compatdata DIR]] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
if options is None:
|
||||
@@ -509,7 +512,7 @@ def main(argv):
|
||||
if app is not None and int(app) >= STEAM_APP_LIMIT:
|
||||
target = shortcut_target(app, program, start, root)
|
||||
elif prefix:
|
||||
target = fixed(program, root, prefix)
|
||||
target = fixed(program, root, prefix, compatdata)
|
||||
else:
|
||||
target = locate(program, root)
|
||||
available = tools(root)
|
||||
|
||||
@@ -56,18 +56,75 @@ libraries="$steam_root"
|
||||
for library in $LIBRARIES; do libraries="$libraries
|
||||
$library"; done
|
||||
libraries=$(printf '%s\n%s\n' "$libraries" "$(sed -n 's/^[[:space:]]*"path"[[:space:]]*"\(.*\)"[[:space:]]*$/\1/p' "$steam_root/steamapps/libraryfolders.vdf" 2>/dev/null)" | awk 'NF && !seen[$0]++')
|
||||
sig=$(while IFS= read -r library; do ls -l --time-style=+%s "$library"/steamapps/appmanifest_*.acf 2>/dev/null; done <<<"$libraries" | cksum)
|
||||
if [ "$(head -n 1 "$cache" 2>/dev/null)" != "$sig" ]; then
|
||||
{
|
||||
printf '%s\n' "$sig"
|
||||
while IFS= read -r library; do
|
||||
[ -d "$library/steamapps/common" ] || continue
|
||||
find "$library/steamapps/common" -mindepth 2 -maxdepth 5 -iname 'installscript*.vdf' \
|
||||
-not -path '*/Steamworks Shared/*' 2>/dev/null
|
||||
done <<<"$libraries" | sort -u
|
||||
} >"$cache.tmp" && mv -f "$cache.tmp" "$cache"
|
||||
games=$(while IFS= read -r library; do
|
||||
library="$library" awk '
|
||||
function flush() { if (dir != "") printf "%s|%s|%s|%s\t%s/steamapps/common/%s\n", file, build, updated, size, ENVIRON["library"], dir }
|
||||
FNR == 1 { flush(); file = FILENAME; dir = build = updated = size = "" }
|
||||
{
|
||||
n = split($0, part, "\"")
|
||||
for (i = 2; i + 2 <= n; i += 2) {
|
||||
name = tolower(part[i])
|
||||
if (name == "installdir" && dir == "") dir = part[i + 2]
|
||||
else if (name == "buildid" && build == "") build = part[i + 2]
|
||||
else if (name == "lastupdated" && updated == "") updated = part[i + 2]
|
||||
else if (name == "sizeondisk" && size == "") size = part[i + 2]
|
||||
else continue
|
||||
i += 2
|
||||
}
|
||||
}
|
||||
END { flush() }
|
||||
' "$library"/steamapps/appmanifest_*.acf 2>/dev/null
|
||||
done <<<"$libraries")
|
||||
legacy=
|
||||
[ -s "$cache" ] && ! grep -q $'\t' "$cache" && legacy=$(tail -n +2 "$cache"; echo .)
|
||||
declare -A scanned=() current=()
|
||||
read_scanned() {
|
||||
scanned=()
|
||||
while IFS=$'\t' read -r key _; do
|
||||
[ -n "$key" ] && scanned[$key]=1
|
||||
done < <(grep $'\t' "$cache" 2>/dev/null)
|
||||
}
|
||||
read_scanned
|
||||
later=
|
||||
fresh=()
|
||||
while IFS=$'\t' read -r key dir; do
|
||||
[ -n "$key" ] || continue
|
||||
current[$key]=1
|
||||
[ -z "${scanned[$key]:-}" ] || continue
|
||||
if [ -z "$legacy" ] && [ -n "${DROIDDECK_SEED_SCRIPTS:-}${DROIDDECK_SEED_LATER:-}" ]; then
|
||||
[ -z "${DROIDDECK_SEED_LATER:-}" ] || later=1
|
||||
continue
|
||||
fi
|
||||
[ -d "$dir" ] || continue
|
||||
scanned[$key]=1
|
||||
if [ -n "$legacy" ] && [ "$cache" -nt "${key%%|*}" ]; then
|
||||
found=$(printf '%s\n' "${legacy%.}" | dir="$dir" awk 'index($0, ENVIRON["dir"] "/") == 1')
|
||||
else
|
||||
found=$(find "$dir" -mindepth 1 -maxdepth 4 -iname 'installscript*.vdf' \
|
||||
-not -path '*/Steamworks Shared/*' 2>/dev/null) || continue
|
||||
found=$(printf '%s\n' "$found" | sort -u)
|
||||
fi
|
||||
fresh+=("$key" "$found")
|
||||
done <<<"$games"
|
||||
exec 9>"$cache.lock" && command -v flock >/dev/null 2>&1 && flock 9
|
||||
if [ ${#fresh[@]} -gt 0 ]; then
|
||||
read_scanned
|
||||
for ((i = 0; i < ${#fresh[@]}; i += 2)); do
|
||||
[ -z "${scanned[${fresh[i]}]:-}" ] || continue
|
||||
printf '%s\n' "${fresh[i + 1]}" | key="${fresh[i]}" awk '{ print ENVIRON["key"] "\t" $0 }' >>"$cache"
|
||||
done
|
||||
fi
|
||||
game_scripts() { { tail -n +2 "$cache" 2>/dev/null; printf '%s\n' "${DROIDDECK_SEED_SCRIPTS:-}"; } | sed '/^$/d' | tr '\n' '\0'; }
|
||||
if [ -n "$later" ]; then
|
||||
(DROIDDECK_SEED_LATER= DROIDDECK_SEED_SCRIPTS= DROIDDECK_SEED_DEFERRED=1 setsid "$0" "$steam_root" >/dev/null 2>&1 9>&- &)
|
||||
fi
|
||||
if [ -e "$cache" ]; then
|
||||
keys=$(printf '%s\n' "${!current[@]}") awk -F'\t' '
|
||||
BEGIN { n = split(ENVIRON["keys"], key, "\n"); for (i = 1; i <= n; i++) want[key[i]] = 1 }
|
||||
NF > 1 && ($1 in want)
|
||||
' "$cache" >"$cache.tmp" && { cmp -s "$cache.tmp" "$cache" && rm -f "$cache.tmp" || mv -f "$cache.tmp" "$cache"; }
|
||||
fi
|
||||
[ -z "${DROIDDECK_SEED_DEFERRED:-}" ] || ! pgrep -x wineserver >/dev/null 2>&1 || exit 0
|
||||
game_scripts() { { cut -s -f2- "$cache" 2>/dev/null; printf '%s\n' "${DROIDDECK_SEED_SCRIPTS:-}"; } | sed '/^$/d' | tr '\n' '\0'; }
|
||||
game_pairs=$(game_scripts | read_scripts)
|
||||
[ -n "$(printf '%s' "$game_pairs" | tr -d '[:space:]')" ] && pairs=$(printf '%s\n%s\n' "$pairs" "$game_pairs" | sort -u | sed '/^$/d')
|
||||
declare -A vulkan=()
|
||||
|
||||
@@ -132,8 +132,7 @@ clear_stale_tmp() {
|
||||
[ -z "${BL_INSIDE:-}" ] && clear_stale_tmp
|
||||
if [ -z "${BL_INSIDE:-}" ]; then
|
||||
if [ "${BL_ZRAM:-0}" = 1 ]; then printf 0 > /tmp/.bl-zram; else rm -f /tmp/.bl-zram; fi
|
||||
rm -f /tmp/.bl-clock
|
||||
head -c 8 /dev/zero > /tmp/.bl-clock
|
||||
dd if=/dev/zero of=/tmp/.bl-clock bs=8 count=1 conv=notrunc status=none
|
||||
fi
|
||||
|
||||
steam_devtools() {
|
||||
@@ -512,6 +511,12 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
if [ "$mode" = run ] && [ "${BL_GAME_WIDTH:-0}" -gt 0 ] && [ "${BL_GAME_HEIGHT:-0}" -gt 0 ]; then
|
||||
nested=$BL_GAME_WIDTH
|
||||
nested_h=$BL_GAME_HEIGHT
|
||||
game_size=1
|
||||
echo "== gamescope: the game runs at ${nested}x${nested_h}, scaled to the ${width}x${height} output with its proportions kept"
|
||||
fi
|
||||
backend=${BL_GAMESCOPE_BACKEND:-wayland}
|
||||
case "$backend" in
|
||||
wayland) ;;
|
||||
@@ -529,7 +534,7 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== gamescope: composites every frame (Mali bridge: the Steam UI flickers on separate planes)"
|
||||
fi
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
if [ "${game_size:-0}" != 1 ] && { [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; }; then
|
||||
args+=(-S stretch)
|
||||
export BL_STRETCHED=1
|
||||
fi
|
||||
@@ -812,19 +817,30 @@ case $mode in
|
||||
fi
|
||||
}
|
||||
bl_zram_usage() {
|
||||
local _p _k _v _u _rss=0 _swap=0
|
||||
local _p _k _v _u _resident _anonymous _rss=0 _anon=0 _swap=0
|
||||
for _p in "$@"; do
|
||||
_resident=0 _anonymous=-1
|
||||
while read -r _k _v _u; do
|
||||
case $_k in VmRSS:) _rss=$((_rss + _v)) ;; VmSwap:) _swap=$((_swap + _v)) ;; esac
|
||||
case $_v in ''|*[!0-9]*) continue ;; esac
|
||||
case $_k in
|
||||
VmRSS:) _resident=$_v ;;
|
||||
RssAnon:) _anonymous=$_v ;;
|
||||
VmSwap:) _swap=$((_swap + _v)) ;;
|
||||
esac
|
||||
done 2>/dev/null < "/proc/$_p/status"
|
||||
[ "$_anonymous" -ge 0 ] || _anonymous=$_resident
|
||||
_rss=$((_rss + _resident)) _anon=$((_anon + _anonymous))
|
||||
done
|
||||
_bl_rss=$_rss
|
||||
_bl_rss=$_rss _bl_anon=$_anon
|
||||
_bl_swap=$_swap
|
||||
echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
}
|
||||
bl_memory_read() {
|
||||
local _k _v _u _kind _fields _avg
|
||||
_bl_mem_total=0 _bl_available=-1 _bl_swap_total=0 _bl_swap_free=-1 _bl_psi=0
|
||||
local _k _v _u _kind _fields _avg _whole _frac _gpu_bytes _growth _saved_growth _saved_fall
|
||||
_saved_growth=${_bl_preserved_growth:-0} _saved_fall=${_bl_preserved_fall:-0}
|
||||
_bl_preserved_growth=0 _bl_preserved_fall=0
|
||||
_bl_mem_total=0 _bl_available=-1 _bl_swap_total=0 _bl_swap_free=-1
|
||||
_bl_psi_some=0 _bl_psi_full=0 _bl_gpu=0 _bl_unevictable=0 _bl_shmem=0
|
||||
while read -r _k _v _u; do
|
||||
case $_v in ''|*[!0-9]*) continue ;; esac
|
||||
case $_k in
|
||||
@@ -832,15 +848,50 @@ case $mode in
|
||||
MemAvailable:) _bl_available=$_v ;;
|
||||
SwapTotal:) _bl_swap_total=$_v ;;
|
||||
SwapFree:) _bl_swap_free=$_v ;;
|
||||
Unevictable:) _bl_unevictable=$_v ;;
|
||||
Shmem:) _bl_shmem=$_v ;;
|
||||
esac
|
||||
done 2>/dev/null < /proc/meminfo
|
||||
if [ -r /proc/pressure/memory ]; then
|
||||
while read -r _kind _fields; do
|
||||
[ "$_kind" = some ] || continue
|
||||
_avg=${_fields#avg10=} _avg=${_avg%% *} _avg=${_avg%%.*}
|
||||
case $_avg in ''|*[!0-9]*) ;; *) _bl_psi=$((10#$_avg)) ;; esac
|
||||
[ "$_kind" = some ] || [ "$_kind" = full ] || continue
|
||||
_avg=${_fields#avg10=} _avg=${_avg%% *}
|
||||
_whole=${_avg%%.*} _frac=${_avg#*.}
|
||||
[ "$_frac" = "$_avg" ] && _frac=00
|
||||
_frac=${_frac}00
|
||||
_frac=${_frac:0:2}
|
||||
case $_whole$_frac in ''|*[!0-9]*) continue ;; esac
|
||||
if [ "$_kind" = some ]; then
|
||||
_bl_psi_some=$((10#$_whole * 100 + 10#$_frac))
|
||||
else
|
||||
_bl_psi_full=$((10#$_whole * 100 + 10#$_frac))
|
||||
fi
|
||||
done 2>/dev/null < /proc/pressure/memory
|
||||
fi
|
||||
if [ -r /sys/class/kgsl/kgsl/page_alloc ]; then
|
||||
read -r _gpu_bytes _u < /sys/class/kgsl/kgsl/page_alloc
|
||||
case $_gpu_bytes in ''|*[!0-9]*) _gpu_bytes=0 ;; esac
|
||||
_bl_gpu=$((_gpu_bytes / 1024))
|
||||
fi
|
||||
_bl_psi=$_bl_psi_some
|
||||
[ "$_bl_psi_full" -gt "$_bl_psi" ] && _bl_psi=$_bl_psi_full
|
||||
if [ "${_bl_sample_at:-}" = "" ]; then
|
||||
_bl_growth=0 _bl_fall=0
|
||||
_bl_sample_at=$SECONDS _bl_sample_available=$_bl_available _bl_sample_gpu=$_bl_gpu
|
||||
_bl_sample_unevictable=$_bl_unevictable _bl_sample_shmem=$_bl_shmem
|
||||
elif [ "$SECONDS" -gt "$_bl_sample_at" ]; then
|
||||
_bl_growth=0 _bl_fall=0
|
||||
_growth=$((_bl_gpu - _bl_sample_gpu)); [ "$_growth" -gt 0 ] && _bl_growth=$((_bl_growth + _growth))
|
||||
_growth=$((_bl_unevictable - _bl_sample_unevictable)); [ "$_growth" -gt 0 ] && _bl_growth=$((_bl_growth + _growth))
|
||||
_growth=$((_bl_shmem - _bl_sample_shmem)); [ "$_growth" -gt 0 ] && _bl_growth=$((_bl_growth + _growth))
|
||||
_bl_fall=$((_bl_sample_available - _bl_available))
|
||||
[ "$_saved_growth" -gt "$_bl_growth" ] && _bl_growth=$_saved_growth
|
||||
[ "$_saved_fall" -gt "$_bl_fall" ] && _bl_fall=$_saved_fall
|
||||
_bl_sample_at=$SECONDS _bl_sample_available=$_bl_available _bl_sample_gpu=$_bl_gpu
|
||||
_bl_sample_unevictable=$_bl_unevictable _bl_sample_shmem=$_bl_shmem
|
||||
fi
|
||||
_bl_real_available=$_bl_available
|
||||
[ "$_bl_real_available" -ge 0 ] && _bl_real_available=$((_bl_real_available - _bl_growth))
|
||||
_bl_headroom=$((_bl_mem_total / 5))
|
||||
[ "$_bl_headroom" -ge $((512 * 1024)) ] || _bl_headroom=$((512 * 1024))
|
||||
[ "$_bl_headroom" -le $((1536 * 1024)) ] || _bl_headroom=$((1536 * 1024))
|
||||
@@ -852,25 +903,29 @@ case $mode in
|
||||
}
|
||||
bl_memory_tight() {
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_available" -ge 0 ] &&
|
||||
{ [ "$_bl_available" -lt "$_bl_headroom" ] ||
|
||||
{ [ "$_bl_psi" -ge 1 ] && [ "$_bl_available" -lt $((_bl_mem_total / 3)) ]; }; }
|
||||
{ [ "$_bl_real_available" -lt "$_bl_headroom" ] ||
|
||||
{ [ "$_bl_psi" -ge 100 ] && [ "$_bl_real_available" -lt $((_bl_mem_total / 3)) ]; } ||
|
||||
{ [ "$_bl_fall" -ge $((256 * 1024)) ] && [ "$_bl_real_available" -lt $((_bl_headroom * 2)) ]; }; }
|
||||
}
|
||||
bl_client_can_pageout() {
|
||||
bl_memory_read
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_swap_total" -gt 0 ] &&
|
||||
[ $((_bl_swap_free - _bl_rss)) -ge "$_bl_swap_reserve" ]
|
||||
[ "$_bl_mem_total" -gt 0 ] && bl_zram_has_room
|
||||
}
|
||||
bl_zram_has_room() {
|
||||
[ "$_bl_swap_total" -gt 0 ] &&
|
||||
[ $((_bl_swap_free - _bl_anon - ${_bl_client_reserve:-0})) -ge "$_bl_swap_reserve" ]
|
||||
}
|
||||
bl_client_can_readback() {
|
||||
bl_memory_read
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
[ "$_bl_mem_total" -gt 0 ] && ! bl_memory_tight &&
|
||||
[ "$_bl_available" -ge $((_bl_swap * 2)) ] &&
|
||||
[ $((_bl_available - _bl_swap)) -ge "$_bl_headroom" ]
|
||||
[ "$_bl_mem_total" -gt 0 ] && ! bl_memory_tight && ! bl_memory_critical &&
|
||||
[ "$_bl_real_available" -ge $((_bl_swap * 2)) ] &&
|
||||
[ $((_bl_real_available - _bl_swap)) -ge "$_bl_headroom" ]
|
||||
}
|
||||
bl_client_pressure() {
|
||||
[ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ "$_bl_game" = 1 ] &&
|
||||
[ "${#_bl_pids[@]}" -gt 0 ] && bl_memory_tight || return 0
|
||||
[ "${#_bl_pids[@]}" -gt 0 ] && { bl_memory_tight || bl_memory_critical; } || return 0
|
||||
[ "$_bl_pressure_at" -lt 0 ] ||
|
||||
[ $((SECONDS - _bl_pressure_at)) -ge "$_bl_pressure_backoff" ] || return 0
|
||||
[ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 30 ] || return 0
|
||||
@@ -880,12 +935,29 @@ case $mode in
|
||||
return 0
|
||||
fi
|
||||
[ "$_bl_rss" -ge $((128 * 1024)) ] || return 0
|
||||
local _before=$_bl_rss
|
||||
bl_zram_send 1 "memory pressure, compressing the client (available $((_bl_available / 1024)) MB, swap free $((_bl_swap_free / 1024)) MB)" client
|
||||
_bl_pressure_before=$_bl_rss
|
||||
if [ "${1:-}" = defer ]; then
|
||||
_bl_client_reserve=$_bl_anon
|
||||
_bl_client_pending=1
|
||||
fi
|
||||
bl_zram_send 1 "memory pressure, compressing the client (available $((_bl_available / 1024)) MB, swap free $((_bl_swap_free / 1024)) MB)" client "${1:-}"
|
||||
_bl_packed=$SECONDS
|
||||
if [ "${1:-}" = defer ]; then
|
||||
_bl_client_targets=("${_bl_zram_targets[@]}")
|
||||
else
|
||||
bl_client_pressure_result
|
||||
fi
|
||||
}
|
||||
bl_client_pressure_finish() {
|
||||
[ "${_bl_client_pending:-0}" = 1 ] || return 0
|
||||
bl_zram_finish 1 "${_bl_client_targets[@]}"
|
||||
bl_client_pressure_result "${_bl_client_targets[@]}"
|
||||
_bl_client_pending=0 _bl_client_reserve=0 _bl_client_targets=()
|
||||
}
|
||||
bl_client_pressure_result() {
|
||||
[ "${_bl_pageout_complete:-0}" = 1 ] || return 0
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
if [ $((_before - _bl_rss)) -lt $((16 * 1024)) ]; then
|
||||
if [ "$#" -gt 0 ]; then bl_zram_usage "$@" > /dev/null; else bl_zram_usage "${_bl_pids[@]}" > /dev/null; fi
|
||||
if [ $((_bl_pressure_before - _bl_rss)) -lt $((16 * 1024)) ]; then
|
||||
_bl_pressure_backoff=$((_bl_pressure_backoff * 2 > 300 ? 300 : _bl_pressure_backoff * 2))
|
||||
else
|
||||
_bl_pressure_backoff=30
|
||||
@@ -893,15 +965,13 @@ case $mode in
|
||||
}
|
||||
bl_memory_critical() {
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_available" -ge 0 ] &&
|
||||
{ [ "$_bl_available" -lt "$_bl_tier_headroom" ] ||
|
||||
{ [ "$_bl_psi" -ge 1 ] && [ "$_bl_available" -lt $((_bl_tier_headroom * 3 / 2)) ]; }; }
|
||||
}
|
||||
bl_low_ram() {
|
||||
[ "$_bl_mem_total" -gt 0 ] && [ "$_bl_mem_total" -le $((13 * 1024 * 1024)) ]
|
||||
{ [ "$_bl_real_available" -lt "$_bl_tier_headroom" ] ||
|
||||
{ [ "$_bl_psi" -ge 100 ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 3 / 2)) ]; } ||
|
||||
{ [ "$_bl_fall" -ge $((256 * 1024)) ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 2)) ]; }; }
|
||||
}
|
||||
bl_session_pressure() {
|
||||
bl_memory_read
|
||||
[ "$_bl_game" = 1 ] && bl_low_ram && bl_memory_critical || return 0
|
||||
[ "$_bl_game" = 1 ] && bl_memory_critical || return 0
|
||||
local _wait=$_bl_tier_backoff _before _pids _targets
|
||||
[ "$_bl_available" -ge $((_bl_headroom / 2)) ] || [ "$_bl_tier_pushed" -lt 0 ] || _wait=30
|
||||
[ "$_bl_tier_at" -lt 0 ] || [ $((SECONDS - _bl_tier_at)) -ge "$_wait" ] || return 0
|
||||
@@ -917,21 +987,18 @@ case $mode in
|
||||
fi
|
||||
fi
|
||||
_bl_tier_at=$SECONDS _bl_tier_pushed=0
|
||||
bl_zram_pick game
|
||||
bl_zram_pick session
|
||||
bl_zram_usage "${_pids[@]}" > /dev/null
|
||||
[ "$_bl_rss" -ge $((256 * 1024)) ] || return 0
|
||||
if [ "$_bl_swap_total" -le 0 ] || [ $((_bl_swap_free - _bl_rss)) -lt "$_bl_swap_reserve" ]; then
|
||||
if ! bl_zram_has_room; then
|
||||
step "zRAM: low-memory page-out skipped, swap headroom too small ($((_bl_swap_free / 1024)) MB free)"
|
||||
return 0
|
||||
fi
|
||||
_targets=("${_pids[@]}") _before=$_bl_swap
|
||||
bl_zram_send 1 "low memory (available $((_bl_available / 1024)) MB), compressing idle game memory" game
|
||||
bl_zram_send 1 "low memory (available $((_bl_real_available / 1024)) MB), compressing idle game memory" session
|
||||
bl_zram_usage "${_targets[@]}" > /dev/null
|
||||
_bl_tier_pushed=$((_bl_swap - _before))
|
||||
bl_tier_note "${_targets[@]}"
|
||||
if [ "${_bl_pageout_complete:-0}" = 1 ] && [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ "${#_bl_pids[@]}" -gt 0 ]; then
|
||||
_bl_pressure_at=$SECONDS _bl_packed=$SECONDS
|
||||
fi
|
||||
}
|
||||
bl_proc_start() {
|
||||
local _s=
|
||||
@@ -962,7 +1029,7 @@ case $mode in
|
||||
}
|
||||
bl_watch_nap() {
|
||||
local _i
|
||||
if [ "$_bl_game" = 1 ] && bl_low_ram && [ "$_bl_available" -ge 0 ] && [ "$_bl_available" -lt $((_bl_tier_headroom * 2)) ]; then
|
||||
if [ "$_bl_game" = 1 ] && [ "$_bl_available" -ge 0 ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 2)) ]; then
|
||||
for _i in 1 2 3 4 5; do
|
||||
nap 1
|
||||
bl_memory_read
|
||||
@@ -1018,10 +1085,16 @@ case $mode in
|
||||
for _p in "${_pids[@]}"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
printf '%s' "$_mode" > /tmp/.bl-zram
|
||||
[ "${#_pids[@]}" = 0 ] || kill -URG "${_pids[@]}" 2>/dev/null
|
||||
if [ "$_mode" = 1 ]; then bl_zram_wait "${_pids[@]}"; else nap 5; fi
|
||||
_bl_zram_targets=("${_pids[@]}")
|
||||
[ "${4:-}" != defer ] || return 0
|
||||
bl_zram_finish "$_mode" "${_pids[@]}"
|
||||
}
|
||||
bl_zram_finish() {
|
||||
local _mode=$1
|
||||
shift
|
||||
if [ "$_mode" = 1 ]; then bl_zram_wait "$@"; else nap 5; fi
|
||||
bl_zram_scan
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: done ($(bl_zram_usage "${_pids[@]}"))"
|
||||
step "zRAM: done ($(bl_zram_usage "$@"))"
|
||||
}
|
||||
bl_game_focused() {
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] || [ -z "${BL_LAUNCH_DIR:-}" ]; then
|
||||
@@ -1048,6 +1121,8 @@ case $mode in
|
||||
}
|
||||
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
|
||||
_bl_pressure_at=-1 _bl_pressure_backoff=30 _bl_tier_at=-1 _bl_tier_backoff=30 _bl_tier_pushed=0 _bl_tier_back=0 _bl_tier_targets=() _bl_tier_swaps=() _bl_tier_starts=()
|
||||
_bl_client_pending=0 _bl_client_reserve=0 _bl_client_targets=()
|
||||
_bl_sample_at= _bl_sample_available=0 _bl_sample_gpu=0 _bl_sample_unevictable=0 _bl_sample_shmem=0
|
||||
while kill -0 $$ 2>/dev/null; do
|
||||
bl_zram_scan
|
||||
bl_memory_read
|
||||
@@ -1074,8 +1149,11 @@ case $mode in
|
||||
_bl_backoff=30
|
||||
fi
|
||||
fi
|
||||
_bl_preserved_growth=$_bl_growth _bl_preserved_fall=$_bl_fall
|
||||
bl_client_pressure defer
|
||||
_bl_preserved_growth=$_bl_growth _bl_preserved_fall=$_bl_fall
|
||||
bl_session_pressure
|
||||
bl_client_pressure
|
||||
bl_client_pressure_finish
|
||||
if [ "$_bl_game" = 1 ] && bl_game_focused; then
|
||||
if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then
|
||||
_bl_since=$SECONDS _bl_since_apps=$_bl_apps
|
||||
@@ -1105,6 +1183,10 @@ case $mode in
|
||||
&& [ "${BL_STEAM_UI:-}" != desktop ] && [ -x /usr/local/bin/droiddeck-launcher-cores ]; then
|
||||
/usr/local/bin/droiddeck-launcher-cores "$BL_LAUNCH_DIR/agent/focus.json" 2>&1 &
|
||||
fi
|
||||
if [ "${BL_PACE_CORES:-1}" != 0 ] && [ -n "${DROIDDECK_HUD_FRAMES:-}" ] && [ -z "${BL_DESKTOP:-}" ] \
|
||||
&& [ -x /usr/local/bin/droiddeck-pace-cores ]; then
|
||||
/usr/local/bin/droiddeck-pace-cores "$DROIDDECK_HUD_FRAMES" 2>&1 &
|
||||
fi
|
||||
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
step "registering the app's game library with Steam"
|
||||
@@ -1118,7 +1200,7 @@ case $mode in
|
||||
step "adding the app's own games to the client's library"
|
||||
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
DROIDDECK_SEED_LATER=1 droiddeck-seed-redists "$steam_root" || true
|
||||
else
|
||||
_bl_x64_tool=$(droiddeck-steam-x64 --default-tool)
|
||||
if [ -n "$_bl_x64_tool" ]; then
|
||||
@@ -1132,7 +1214,7 @@ case $mode in
|
||||
if [ -z "${BL_DESKTOP:-}" ] && [ "${BL_STEAM_UI:-}" != desktop ]; then
|
||||
droiddeck-steam-ui-scale "$steam_root" "${BL_WIDTH:-1280}" "${BL_HEIGHT:-720}" || true
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
DROIDDECK_SEED_LATER=1 droiddeck-seed-redists "$steam_root" || true
|
||||
fi
|
||||
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
|
||||
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
|
||||
@@ -1396,6 +1478,8 @@ case $mode in
|
||||
decky_stop() { [ -z "$decky_child" ] || kill "$decky_child" 2>/dev/null; [ -z "$decky_child" ] || wait "$decky_child" 2>/dev/null; exit 0; }
|
||||
trap decky_stop TERM INT HUP
|
||||
decky_exits=0
|
||||
# The guest has no "deck" user, which Decky otherwise requires at startup.
|
||||
export UNPRIVILEGED_USER=root
|
||||
while :; do
|
||||
if [ "$decky_arch" = x86_64 ]; then /usr/local/bin/droiddeck-fex run --mode on -- "$decky_loader" >>"$HOME/homebrew/services/PluginLoader.log" 2>&1 &
|
||||
else "$decky_loader" >>"$HOME/homebrew/services/PluginLoader.log" 2>&1 &
|
||||
@@ -1458,6 +1542,9 @@ case $mode in
|
||||
_bl_cef=(-cef-disable-gpu -cef-disable-gpu-compositing)
|
||||
echo "== steam: browser UI in software (Mali bridge)"
|
||||
elif [ "${_bl_cef[0]}" = -cef-force-gpu ]; then
|
||||
# With Steam's own web helper layout the Deck UI's footer and overlays flicker on the bridge
|
||||
# (Mali-G78 MP14). ANGLE on Vulkan without Chromium's Vulkan compositing draws them steadily.
|
||||
: "${BL_VKBRIDGE_CEF_ANGLE=vulkan}" "${BL_VKBRIDGE_CEF_VULKAN=0}"
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle="${BL_VKBRIDGE_CEF_ANGLE:-vulkan}")
|
||||
fi
|
||||
[ "${BL_VKBRIDGE_CEF_LOG:-0}" = 1 ] && _bl_cef+=(-cef-enable-logging=stderr -cef-v=1)
|
||||
|
||||
@@ -71,7 +71,11 @@ def store_game(game):
|
||||
|
||||
def manifest_ids(steamapps, name):
|
||||
matches = []
|
||||
for manifest in Path(steamapps).glob("appmanifest_*.acf"):
|
||||
try:
|
||||
manifests = list(Path(steamapps).glob("appmanifest_*.acf"))
|
||||
except OSError:
|
||||
return matches
|
||||
for manifest in manifests:
|
||||
try:
|
||||
install = re.search(r'"installdir"\s*"([^"\\]*)"', manifest.read_text(), re.I)
|
||||
if install and install[1] == name:
|
||||
@@ -81,13 +85,21 @@ def manifest_ids(steamapps, name):
|
||||
return matches
|
||||
|
||||
|
||||
def identify(game):
|
||||
def manifest_identity(game):
|
||||
folder = Path(game["folder"])
|
||||
steamapps = folder.parent.parent
|
||||
for library in ([steamapps] if folder.parent.name == "common" and steamapps.name == "steamapps" else []) + [folder.parent / WINNATIVE]:
|
||||
matches = [appid for appid in manifest_ids(library, folder.name) if appid != SPACEWAR]
|
||||
if matches:
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
return (matches[0], library) if len(matches) == 1 else None
|
||||
return False
|
||||
|
||||
|
||||
def identify(game):
|
||||
folder = Path(game["folder"])
|
||||
found = manifest_identity(game)
|
||||
if found is not False:
|
||||
return found[0] if found is not None else None
|
||||
ids = set()
|
||||
for parent in {folder, Path(game["exe"]).parent}:
|
||||
try:
|
||||
@@ -508,6 +520,57 @@ def release(steam_root, game, stale, reason):
|
||||
print(f"droiddeck-steam-games: {game.get('name', appid)} {reason}; it is no longer Steam app {appid}")
|
||||
|
||||
|
||||
PREFIX_LINKS = ".droiddeck-prefix-links.json"
|
||||
|
||||
|
||||
def steam_prefix(steam_root, game):
|
||||
identity = manifest_identity(game)
|
||||
if not identity or not identity[0]:
|
||||
return None, None
|
||||
appid, steamapps = identity
|
||||
installed = steamapps == Path(game["folder"]).parent.parent
|
||||
for library in [steamapps.parent] if installed else dict.fromkeys([steamapps.parent] + libraries(steam_root)):
|
||||
prefix = library / "steamapps/compatdata" / str(appid)
|
||||
if (prefix / "pfx/drive_c").is_dir():
|
||||
return appid, str(prefix)
|
||||
return appid, None
|
||||
|
||||
|
||||
def share_prefix(steam_root, game):
|
||||
shortcut = Path(steam_root) / "steamapps/compatdata" / str(game["appid"] & 0xFFFFFFFF)
|
||||
record = Path(steam_root) / "steamapps" / PREFIX_LINKS
|
||||
links = read_json(record, {})
|
||||
if not isinstance(links, dict):
|
||||
links = {}
|
||||
before = dict(links)
|
||||
key = str(shortcut)
|
||||
name = game.get("name", "game")
|
||||
appid, target = steam_prefix(steam_root, game)
|
||||
try:
|
||||
current = os.readlink(shortcut) if os.path.islink(shortcut) else None
|
||||
if current is not None and links.get(key) == current and current != target:
|
||||
if target is not None or (not os.path.exists(shortcut) and Path(current).parent.parent.is_dir()):
|
||||
shortcut.unlink()
|
||||
current = None
|
||||
if current is None:
|
||||
links.pop(key, None)
|
||||
if current is None and os.path.lexists(shortcut):
|
||||
if target is not None:
|
||||
print(f"droiddeck-steam-games: {name} keeps its own prefix; Steam app {appid} saves are in {target}")
|
||||
elif current is None and target is not None:
|
||||
shortcut.parent.mkdir(parents=True, exist_ok=True)
|
||||
shortcut.symlink_to(target)
|
||||
links[key] = target
|
||||
print(f"droiddeck-steam-games: {name} shares the saves prefix of Steam app {appid}")
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: {name} keeps its own prefix ({error})")
|
||||
if links != before:
|
||||
try:
|
||||
save_json(record, links)
|
||||
except OSError as error:
|
||||
print(f"droiddeck-steam-games: prefix links not recorded ({error})")
|
||||
|
||||
|
||||
def route(steam_root, acct, games):
|
||||
snapshot = read_json(Path(acct) / "config" / STATE, {})
|
||||
if not isinstance(snapshot, dict):
|
||||
@@ -557,6 +620,7 @@ def route(steam_root, acct, games):
|
||||
elif named and seeded(steamapps, game, appid):
|
||||
routes[str(game["appid"])] = appid
|
||||
continue
|
||||
share_prefix(steam_root, game)
|
||||
shortcuts.append(game)
|
||||
try:
|
||||
park(steamapps)
|
||||
|
||||
@@ -449,7 +449,11 @@ mkdir -p "$srt_libs"
|
||||
for d in "$STEAM_X64"/steamrt64/pv-runtime/steam-runtime-steamrt/steamrt3c_platform_*/files/lib/x86_64-linux-gnu \
|
||||
"$STEAM_X64"/steamrt64/pv-runtime/steam-runtime-steamrt/steamrt3c_platform_*/files/usr/lib/x86_64-linux-gnu; do
|
||||
[ -d "$d" ] || continue
|
||||
for f in "$d"/*.so*; do [ -e "$srt_libs/$(basename "$f")" ] || ln -s "$f" "$srt_libs/"; done
|
||||
for f in "$d"/*.so*; do
|
||||
[ -e "$f" ] || [ -L "$f" ] || continue
|
||||
s="$srt_libs/$(basename "$f")"
|
||||
{ [ -e "$s" ] || [ -L "$s" ]; } || ln -s "$f" "$srt_libs/"
|
||||
done
|
||||
done
|
||||
FEX_ROOTFS=$ROOTFS /usr/local/bin/FEX "$ROOTFS/usr/sbin/ldconfig.real" -n "$srt_libs" >>"$LOG" 2>&1 || step "ldconfig on $srt_libs failed"
|
||||
sniper_compat=$X64_HOME/sniper-compat
|
||||
@@ -458,6 +462,7 @@ mkdir -p "$sniper_compat"
|
||||
hb=$(ls "$srt_libs"/libharfbuzz.so.0.* 2>/dev/null | head -n 1)
|
||||
if [ -n "$hb" ]; then ln -s "$hb" "$sniper_compat/libharfbuzz.so.0"; else step "warning: no HarfBuzz in Valve's runtime for the newer-runtime titles"; fi
|
||||
for f in "$srt_libs"/*; do
|
||||
[ -e "$f" ] || [ -L "$f" ] || continue
|
||||
n=$(basename "$f")
|
||||
if [ -e "$ROOTFS/usr/lib/x86_64-linux-gnu/$n" ] || [ -e "$ROOTFS/lib/x86_64-linux-gnu/$n" ]; then rm -f "$f"; fi
|
||||
done
|
||||
|
||||
@@ -5,6 +5,7 @@ import binascii
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
@@ -47,14 +48,14 @@ def sidecar_at(folder):
|
||||
return sidecar
|
||||
|
||||
|
||||
def find_store_game(argv):
|
||||
def find_store_game(argv, depth=MAX_DEPTH):
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'").replace("\\", "/")
|
||||
low = arg.lower()
|
||||
if not (low.endswith(LAUNCHER) or low.endswith(".exe") or low.endswith(".bat")) or "/" not in arg:
|
||||
continue
|
||||
folder = Path(arg).parent
|
||||
for _ in range(MAX_DEPTH):
|
||||
for _ in range(depth):
|
||||
sidecar = sidecar_at(folder)
|
||||
if sidecar is not None:
|
||||
return folder, sidecar
|
||||
@@ -64,6 +65,21 @@ def find_store_game(argv):
|
||||
return None
|
||||
|
||||
|
||||
def store_launcher(path):
|
||||
real = os.path.realpath(path)
|
||||
for start in dict.fromkeys([os.path.abspath(path), real]):
|
||||
found = find_store_game([start], depth=len(Path(start).parts))
|
||||
if found is None:
|
||||
continue
|
||||
folder, sidecar = found
|
||||
launcher, exe = str(sidecar.get("launcher") or ""), str(sidecar.get("exe") or "")
|
||||
if not launcher or not exe or (folder / launcher).is_symlink() or not (folder / launcher).is_file():
|
||||
continue
|
||||
if os.path.realpath(folder / exe).lower() == real.lower():
|
||||
return str(folder / launcher)
|
||||
return None
|
||||
|
||||
|
||||
def drop_stale(folder, now=None):
|
||||
code = folder / EPIC_CODE
|
||||
try:
|
||||
@@ -270,12 +286,22 @@ def cloud_on(sidecar):
|
||||
def exited(argv, code=0):
|
||||
found = find_store_game(argv)
|
||||
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
|
||||
if found is not None and launch_dir and str(found[1].get("store")) == "rockstar":
|
||||
ask(Path(launch_dir) / "stores", {"op": "rockstar-exited", "store": "rockstar", "id": str(found[1].get("id"))}, timeout=1.0)
|
||||
compat_data = os.environ.get("STEAM_COMPAT_DATA_PATH")
|
||||
if compat_data:
|
||||
(Path(compat_data) / "pfx" / ROCKSTAR_FOLDER / "launch.json").unlink(missing_ok=True)
|
||||
return 0
|
||||
if found is not None and str(found[1].get("store")) == "epic" and os.environ.get(EPIC_HANDLED) != "1" \
|
||||
and os.access(EPIC_CLIENT, os.X_OK):
|
||||
try:
|
||||
subprocess.run([EPIC_CLIENT, "exited", "--code", str(code)], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, timeout=10)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
pass
|
||||
if found is not None and launch_dir and str(found[1].get("store")) == "ea":
|
||||
ask(Path(launch_dir) / "stores", {"op": "ea-exited", "store": "ea", "id": str(found[1].get("id"))}, timeout=1.0)
|
||||
log("ea %s exited" % found[1].get("id"))
|
||||
return 0
|
||||
if found is None or not launch_dir or not cloud_on(found[1]):
|
||||
return 0
|
||||
store, game = str(found[1].get("store")), str(found[1].get("id"))
|
||||
@@ -284,6 +310,443 @@ def exited(argv, code=0):
|
||||
return 0
|
||||
|
||||
|
||||
UBISOFT_DIR = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
|
||||
UBISOFT_WINDOWS_DIR = "C:\\Program Files (x86)\\Ubisoft\\Ubisoft Game Launcher\\"
|
||||
UBISOFT_INSTALLER_URL = "https://static3.cdn.ubi.com/orbit/launcher_installer/UbisoftConnectInstaller.exe"
|
||||
ROCKSTAR_SERVICE = Path("/usr/local/lib/droiddeck-rockstar")
|
||||
ROCKSTAR_FOLDER = "drive_c/Program Files/Rockstar Games/Launcher"
|
||||
ROCKSTAR_TITLES = {"gta3": "Grand Theft Auto III", "gtavc": "Grand Theft Auto: Vice City", "gtasa": "GTA: San Andreas",
|
||||
"gta4": "Grand Theft Auto IV", "lanoire": "LANoireMTL"}
|
||||
|
||||
|
||||
def rockstar_sdk(folder, sidecar):
|
||||
if str(sidecar.get("id")) in ("gta4", "lanoire"):
|
||||
return True
|
||||
root = folder.resolve()
|
||||
exe = (folder / str(sidecar.get("exe") or "").replace("\\", "/")).resolve()
|
||||
if not exe.is_relative_to(root):
|
||||
return False
|
||||
for directory in {root, exe.parent}:
|
||||
if directory.is_dir() and any(p.is_file() and not p.is_symlink() and p.name.lower() in ("socialclub.dll", "socialclub64.dll")
|
||||
for p in directory.iterdir()):
|
||||
return True
|
||||
if str(sidecar.get("id")) in ROCKSTAR_TITLES:
|
||||
return False
|
||||
level = [root]
|
||||
for _ in range(4):
|
||||
children = []
|
||||
for directory in level:
|
||||
for path in directory.iterdir():
|
||||
if path.is_symlink():
|
||||
continue
|
||||
if path.name.lower() == "title.rgl" and path.is_file() and path.resolve().is_relative_to(root) and 112 <= path.stat().st_size <= 1048576:
|
||||
with path.open("rb") as source:
|
||||
if source.read(4) == b"RGLM":
|
||||
return True
|
||||
if len(children) < 256 and path.is_dir() and path.resolve().is_relative_to(root):
|
||||
children.append(path)
|
||||
level = children
|
||||
return False
|
||||
|
||||
|
||||
def rockstar_registry(folder, title, compat_data, proton, sdk_arch=None):
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
launcher = r"C:\Program Files\Rockstar Games\Launcher"
|
||||
values = [(r"Rockstar Games\Launcher", launcher)]
|
||||
if title:
|
||||
values.append(("Rockstar Games\\" + title, windows_path(str(folder))))
|
||||
entries = [("Software\\" + view + key, value) for view in ("", "Wow6432Node\\") for key, value in values]
|
||||
if sdk_arch:
|
||||
entries.append((r"Software\Rockstar Games\Rockstar Games Social Club", r"C:\Program Files\Rockstar Games\Social Club"))
|
||||
program = "Program Files (x86)" if sdk_arch == "x86" else "Program Files"
|
||||
entries.append((r"Software\Wow6432Node\Rockstar Games\Rockstar Games Social Club", "C:\\" + program + r"\Rockstar Games\Social Club"))
|
||||
reg = pfx / "system.reg"
|
||||
if all(has_value(reg, "[" + key.replace("\\", "\\\\") + "]", "InstallFolder", value) for key, value in entries):
|
||||
return True
|
||||
if wait_for_server(pfx, 2):
|
||||
return all(set_value(reg, "[" + key.replace("\\", "\\\\") + "]", "InstallFolder", value) for key, value in entries)
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-rockstar-") as temp:
|
||||
path = Path(temp) / "install.reg"
|
||||
text = "Windows Registry Editor Version 5.00\r\n\r\n"
|
||||
text += "\r\n".join('[HKEY_LOCAL_MACHINE\\%s]\r\n"InstallFolder"="%s"\r\n' % (key, reg_escape(value)) for key, value in entries)
|
||||
path.write_text(text, encoding="utf-16")
|
||||
result = subprocess.run([proton, "run", "reg.exe", "import", windows_path(str(path))],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=45)
|
||||
return result.returncode == 0
|
||||
|
||||
|
||||
def rockstar_runtime(folder, exe, compat_data, arch):
|
||||
if arch == "x86":
|
||||
rockstar_runtime(folder, exe, compat_data, "x64")
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
target = pfx / "drive_c" / ("Program Files (x86)" if arch == "x86" else "Program Files") / "Rockstar Games/Social Club"
|
||||
if not target.resolve().is_relative_to(pfx.resolve()):
|
||||
raise ValueError("invalid Social Club destination")
|
||||
required = ("socialclub.dll", "socialclub.pak") + (("SocialClubHelper.exe",) if arch == "x64" else ())
|
||||
marker = target / ".droiddeck-installing"
|
||||
if all((target / name).is_file() for name in required) and not marker.exists():
|
||||
return "present"
|
||||
root = folder.resolve()
|
||||
installers = [base / sub / "Social-Club-Setup.exe" for base in (root, exe.parent)
|
||||
for sub in ("Redistributables", "Installers")]
|
||||
installer = next((p for p in installers if p.is_file() and p.resolve().is_relative_to(root) and p.stat().st_size <= 256 * 1024 * 1024), None)
|
||||
if installer is None:
|
||||
return "game-runtime"
|
||||
tool = shutil.which("7z")
|
||||
if not tool:
|
||||
return "no-unpacker"
|
||||
listing = subprocess.run([tool, "l", "-t7z", "-slt", "-ba", str(installer)], capture_output=True,
|
||||
stdin=subprocess.DEVNULL, timeout=30)
|
||||
if listing.returncode:
|
||||
return "installer-unreadable"
|
||||
entries, size = [], 0
|
||||
for block in listing.stdout.decode("utf-8", "replace").split("\n\n"):
|
||||
fields = dict(line.split(" = ", 1) for line in block.splitlines() if " = " in line)
|
||||
name = fields.get("Path", "").replace("\\", "/")
|
||||
if not name.startswith(arch + "/"):
|
||||
continue
|
||||
if ".." in name.split("/") or ":" in name or fields.get("Symbolic Link") or fields.get("Hard Link"):
|
||||
raise ValueError("invalid Social Club archive path")
|
||||
entry_size = int(fields.get("Size", "0"))
|
||||
if entry_size < 0:
|
||||
raise ValueError("invalid Social Club member size")
|
||||
size += entry_size
|
||||
entries.append(name)
|
||||
if not entries or len(entries) > 2048 or size > 768 * 1024 * 1024:
|
||||
raise ValueError("invalid Social Club archive size")
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-socialclub-") as temporary:
|
||||
result = subprocess.run([tool, "x", "-t7z", "-y", "-o" + temporary, str(installer), arch + "/*"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, timeout=180)
|
||||
source = Path(temporary) / arch
|
||||
if result.returncode or not all((source / name).is_file() for name in required):
|
||||
return "installer-incomplete"
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
if marker.is_symlink():
|
||||
raise ValueError("invalid Social Club install marker")
|
||||
marker.touch()
|
||||
for path in source.rglob("*"):
|
||||
if path.is_symlink() or not path.resolve().is_relative_to(source.resolve()):
|
||||
raise ValueError("invalid Social Club archive member")
|
||||
if not path.is_file():
|
||||
continue
|
||||
output = target / path.relative_to(source)
|
||||
if not output.resolve().is_relative_to(pfx.resolve()):
|
||||
raise ValueError("invalid Social Club output path")
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.NamedTemporaryFile(dir=output.parent, delete=False) as stage:
|
||||
stage_path = Path(stage.name)
|
||||
try:
|
||||
with path.open("rb") as stream:
|
||||
shutil.copyfileobj(stream, stage)
|
||||
except BaseException:
|
||||
stage_path.unlink(missing_ok=True)
|
||||
raise
|
||||
os.replace(stage_path, output)
|
||||
marker.unlink()
|
||||
return "installed"
|
||||
|
||||
|
||||
def prepare_rockstar(folder, sidecar, compat_data, launch_dir, proton="", ask_app=None):
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
target = Path(compat_data) / "pfx" / ROCKSTAR_FOLDER
|
||||
if not target.resolve().is_relative_to((Path(compat_data) / "pfx").resolve()):
|
||||
return "invalid-service-path"
|
||||
config = target / "launch.json"
|
||||
config.unlink(missing_ok=True)
|
||||
legacy = str(sidecar.get("id")) in ROCKSTAR_TITLES
|
||||
sdk = rockstar_sdk(folder, sidecar)
|
||||
title = ROCKSTAR_TITLES.get(str(sidecar.get("id")))
|
||||
if not launch_dir:
|
||||
return "no-channel"
|
||||
root = folder.resolve()
|
||||
exe = (folder / str(sidecar.get("exe") or "").replace("\\", "/")).resolve()
|
||||
if not exe.is_relative_to(root):
|
||||
return "invalid-game-path"
|
||||
workdir = (folder / str(sidecar["workdir"])).resolve() if sidecar.get("workdir") is not None else exe.parent
|
||||
if not workdir.is_relative_to(root) or not exe.is_file() or legacy and not any((p / "MTLX.dll").is_file() for p in (root, exe.parent)):
|
||||
return "invalid-game-path"
|
||||
args = sidecar.get("args") or []
|
||||
if not isinstance(args, list) or any(not isinstance(arg, str) or "\0" in arg for arg in args):
|
||||
return "invalid-game-arguments"
|
||||
with exe.open("rb") as source:
|
||||
if source.read(2) != b"MZ":
|
||||
return "invalid-game-exe"
|
||||
source.seek(0x3c)
|
||||
raw = source.read(4)
|
||||
if len(raw) != 4:
|
||||
return "invalid-game-exe"
|
||||
source.seek(int.from_bytes(raw, "little"))
|
||||
signature = source.read(6)
|
||||
if len(signature) != 6 or signature[:4] != b"PE\0\0" or signature[4:] not in (b"\x4c\x01", b"\x64\x86"):
|
||||
return "invalid-game-exe"
|
||||
service = ROCKSTAR_SERVICE / ("Launcher32.exe" if signature[4:] == b"\x4c\x01" else "Launcher64.exe")
|
||||
if not service.is_file():
|
||||
return "no-service"
|
||||
made = "present" if (Path(compat_data) / "pfx/user.reg").is_file() else create_prefix(compat_data, proton)
|
||||
if made not in ("created", "present"):
|
||||
return "prefix-" + made
|
||||
arch = "x86" if signature[4:] == b"\x4c\x01" else "x64"
|
||||
if sdk:
|
||||
log("rockstar runtime: " + rockstar_runtime(folder, exe, compat_data, arch))
|
||||
if not rockstar_registry(folder, title, compat_data, proton, sdk_arch=arch if sdk else None):
|
||||
return "registry-unavailable"
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.NamedTemporaryFile(prefix="Launcher-", suffix=".exe", dir=target, delete=False) as temporary:
|
||||
temporary_path = Path(temporary.name)
|
||||
try:
|
||||
with service.open("rb") as source:
|
||||
shutil.copyfileobj(source, temporary)
|
||||
except BaseException:
|
||||
temporary_path.unlink(missing_ok=True)
|
||||
raise
|
||||
os.replace(temporary_path, target / "Launcher.exe")
|
||||
answer = (ask_app or ask)(Path(launch_dir) / "stores", {"op": "rockstar-launch", "store": "rockstar", "id": str(sidecar.get("id"))}, timeout=120.0)
|
||||
if not isinstance(answer, dict) or not answer.get("ok"):
|
||||
return "session-" + (str(answer.get("reason") or "refused") if isinstance(answer, dict) else "timeout")
|
||||
if legacy and (not isinstance(answer.get("material"), str) or not re.fullmatch(r"[0-9A-Fa-f]{640}", answer["material"])):
|
||||
return "invalid-material"
|
||||
expires = answer.get("expiresAt")
|
||||
if not isinstance(expires, int) or not time.time() * 1000 < expires <= time.time() * 1000 + 120_000:
|
||||
return "invalid-expiry"
|
||||
launch = {"folder": windows_path(str(root)), "exe": windows_path(str(exe)), "workdir": windows_path(str(workdir)),
|
||||
"args": args, "expiresAt": expires}
|
||||
if legacy:
|
||||
launch.update(pipe=answer.get("pipe"), material=answer["material"])
|
||||
if sdk:
|
||||
session = answer.get("session")
|
||||
if not isinstance(session, dict) or not isinstance(session.get("accountId"), str) \
|
||||
or not re.fullmatch(r"[1-9][0-9]{0,19}", session["accountId"]) or int(session["accountId"]) > 2**64 - 1 \
|
||||
or any(not isinstance(session.get(key), str) or not session[key] or "\0" in session[key]
|
||||
or len(session[key].encode("utf-8")) > limit for key, limit in (("identity", 512), ("ticket", 49152))):
|
||||
return "invalid-sdk-session"
|
||||
launch["session"] = {key: session[key] for key in ("accountId", "identity", "ticket")}
|
||||
if "titleId" in session:
|
||||
if not isinstance(session["titleId"], str) or not re.fullmatch(r"[a-z][a-z0-9_]{0,63}", session["titleId"]):
|
||||
return "invalid-sdk-title"
|
||||
launch["session"]["titleId"] = session["titleId"]
|
||||
if len(json.dumps(launch).encode("utf-8")) > 65536:
|
||||
return "handoff-too-large"
|
||||
with tempfile.NamedTemporaryFile(mode="w", prefix="launch-", suffix=".json", dir=target, delete=False) as temporary:
|
||||
temporary_path = Path(temporary.name)
|
||||
try:
|
||||
json.dump(launch, temporary)
|
||||
except BaseException:
|
||||
temporary_path.unlink(missing_ok=True)
|
||||
raise
|
||||
os.replace(temporary_path, config)
|
||||
return "ready"
|
||||
|
||||
|
||||
UBISOFT_CACHE = Path("/root/.cache/droiddeck/ubisoft")
|
||||
UBISOFT_LAUNCH = ".droiddeck-ubisoft.json"
|
||||
UBISOFT_SERVICE = Path("/usr/local/lib/droiddeck-ubisoft/droiddeck-upc.exe")
|
||||
UBISOFT_ASK_WAIT = 45.0
|
||||
UBISOFT_EXTRACT_WAIT = 300
|
||||
# Ubisoft's own game-side runtime from the Connect installer, unmodified: the API and aux DLLs the
|
||||
# game's loader opens from InstallDir, the starter it re-executes into and its imports, and the overlay
|
||||
# DLLs uplay_r1.dll loads even with the overlay off (its startup fails without them).
|
||||
UBISOFT_RUNTIME = ("uplay_r1.dll", "uplay_r164.dll", "uplay_aux_r1.dll", "uplay_aux_r164.dll",
|
||||
"uplay_r2.dll", "uplay_r264.dll", "ubiorbitapi_r2.dll", "ubiorbitapi_r264.dll",
|
||||
"UbisoftGameLauncher.exe", "UbisoftGameLauncher64.exe", "discord-rpc.x86.dll",
|
||||
"discord-rpc.x64.dll", "steam_api.dll", "steam_api64.dll", "overlay.dll", "overlay64.dll")
|
||||
UBISOFT_VIEWS = ("[Software\\\\Ubisoft\\\\Launcher%s]", "[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher%s]")
|
||||
MIN_INSTALLER = 1 << 20
|
||||
|
||||
|
||||
def ubisoft_runtime_dir(compat_data):
|
||||
return Path(compat_data) / "pfx" / UBISOFT_DIR
|
||||
|
||||
|
||||
def ubisoft_runtime_ready(compat_data):
|
||||
folder = ubisoft_runtime_dir(compat_data)
|
||||
return all((folder / name).is_file() for name in UBISOFT_RUNTIME)
|
||||
|
||||
|
||||
def fetch_installer(url=UBISOFT_INSTALLER_URL, folder=UBISOFT_CACHE):
|
||||
target = folder / "UbisoftConnectInstaller.exe"
|
||||
if target.is_file() and target.stat().st_size >= MIN_INSTALLER:
|
||||
return target
|
||||
import urllib.request
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
part = target.with_name(target.name + ".part")
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||
with urllib.request.urlopen(request, timeout=60) as reply, open(part, "wb") as out:
|
||||
shutil.copyfileobj(reply, out)
|
||||
if part.stat().st_size < MIN_INSTALLER:
|
||||
part.unlink()
|
||||
raise OSError("installer too small")
|
||||
os.replace(part, target)
|
||||
return target
|
||||
|
||||
|
||||
def install_runtime(compat_data, wait=UBISOFT_EXTRACT_WAIT):
|
||||
if ubisoft_runtime_ready(compat_data):
|
||||
return "present"
|
||||
if not (Path(compat_data) / "pfx").is_dir():
|
||||
return "no-prefix"
|
||||
try:
|
||||
installer = fetch_installer()
|
||||
except OSError as error:
|
||||
return "download-failed-" + type(error).__name__
|
||||
target = ubisoft_runtime_dir(compat_data)
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ubisoft-", dir=str(UBISOFT_CACHE)) as tmp:
|
||||
try:
|
||||
subprocess.run(["7z", "e", "-y", "-o" + tmp, str(installer)] + list(UBISOFT_RUNTIME), stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=wait)
|
||||
except subprocess.TimeoutExpired:
|
||||
return "extract-timeout"
|
||||
except OSError:
|
||||
return "no-7z"
|
||||
missing = [name for name in UBISOFT_RUNTIME if not (Path(tmp) / name).is_file()]
|
||||
if missing:
|
||||
return "extract-missing-" + ",".join(missing)
|
||||
for name in UBISOFT_RUNTIME:
|
||||
shutil.copyfile(Path(tmp) / name, target / name)
|
||||
if not ubisoft_runtime_ready(compat_data):
|
||||
return "copy-failed"
|
||||
try:
|
||||
installer.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
return "installed"
|
||||
|
||||
|
||||
def ubisoft_product(sidecar):
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
try:
|
||||
return int(str(extra.get("productId") or ""))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def ubisoft_install_dir(folder):
|
||||
return windows_path(str(folder)).replace("\\", "/").rstrip("/") + "/"
|
||||
|
||||
|
||||
def register_ubisoft(folder, product, compat_data):
|
||||
reg = Path(compat_data) / "pfx" / "system.reg"
|
||||
if not reg.is_file():
|
||||
return "no-registry"
|
||||
if not wait_for_server(reg.parent):
|
||||
return "server-running"
|
||||
for view in UBISOFT_VIEWS:
|
||||
set_value(reg, view % "", "InstallDir", UBISOFT_WINDOWS_DIR)
|
||||
set_value(reg, view % ("\\\\Installs\\\\%d" % product), "InstallDir", ubisoft_install_dir(folder))
|
||||
return "registered %d" % product
|
||||
|
||||
|
||||
UBISOFT_HIVES = {"HKEY_LOCAL_MACHINE": "system.reg", "HKEY_CURRENT_USER": "user.reg"}
|
||||
|
||||
|
||||
def manifest_value(values, folder, language):
|
||||
"""The value Connect writes for a manifest registry entry: the install folder, the entry for the
|
||||
language being played, or the only entry there is."""
|
||||
entries = [v for v in values if isinstance(v, dict)]
|
||||
if not entries:
|
||||
return None
|
||||
names = [str(v.get("name") or "") for v in entries]
|
||||
if "$INSTALL_DIR" in names:
|
||||
return windows_path(str(folder)).rstrip("\\") + "\\"
|
||||
for v in entries:
|
||||
if str(v.get("value") or "").lower() == language.lower():
|
||||
return str(v.get("value"))
|
||||
prefix = language.split("-")[0].lower()
|
||||
for v in entries:
|
||||
if str(v.get("value") or "").lower().split("-")[0] == prefix:
|
||||
return str(v.get("value"))
|
||||
return str(entries[0].get("value") or entries[0].get("name") or "")
|
||||
|
||||
|
||||
def apply_manifest_registry(compat_data, registry, folder, language):
|
||||
written = 0
|
||||
for item in registry or []:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
path = str(item.get("key") or "").replace("/", "\\")
|
||||
hive, _, rest = path.partition("\\")
|
||||
target = UBISOFT_HIVES.get(hive.upper())
|
||||
if not target or "\\" not in rest:
|
||||
continue
|
||||
subkey, _, name = rest.rpartition("\\")
|
||||
value = manifest_value(item.get("values"), folder, language)
|
||||
if value is None or not name:
|
||||
continue
|
||||
reg = Path(compat_data) / "pfx" / target
|
||||
parts = subkey.split("\\")
|
||||
views = [parts]
|
||||
if target == "system.reg" and len(parts) > 1 and parts[0].lower() == "software" and parts[1].lower() != "wow6432node":
|
||||
views.append(parts[:1] + ["Wow6432Node"] + parts[1:])
|
||||
for view in views:
|
||||
key = "[" + "\\\\".join(view) + "]"
|
||||
if set_value(reg, key, name, value):
|
||||
written += 1
|
||||
return written
|
||||
|
||||
|
||||
def ubisoft_launch(folder, sidecar, product, compat_data, answer):
|
||||
"""The launch file droiddeck-upc.exe reads: the game, the account and this launch's ticket."""
|
||||
account = answer.get("account") if isinstance(answer.get("account"), dict) else {}
|
||||
user = str(account.get("userId") or "user")
|
||||
saves = Path(compat_data) / "pfx" / "drive_c/users/steamuser/Saved Games/Ubisoft" / user / str(product)
|
||||
saves.mkdir(parents=True, exist_ok=True)
|
||||
exe = str(sidecar.get("exe") or "").replace("\\", "/")
|
||||
workdir = folder / str(sidecar.get("workdir")) if sidecar.get("workdir") else folder
|
||||
UBISOFT_CACHE.mkdir(parents=True, exist_ok=True)
|
||||
return {
|
||||
"productId": product,
|
||||
"exe": windows_path(str(folder / exe)),
|
||||
"args": " ".join(str(a) for a in sidecar.get("args") or []),
|
||||
"workdir": windows_path(str(workdir)),
|
||||
"account": account,
|
||||
"ticket": str(answer.get("ticket") or ""),
|
||||
"owned": [int(i) for i in answer.get("owned") or [] if str(i).isdigit()],
|
||||
"products": [p for p in answer.get("products") or [] if isinstance(p, dict) and isinstance(p.get("id"), int)],
|
||||
"appId": str(answer.get("appId") or ""),
|
||||
"chunks": [c for c in answer.get("chunks") or [] if isinstance(c, dict) and isinstance(c.get("id"), int)],
|
||||
"saves": "C:/users/steamuser/Saved Games/Ubisoft/%s/%d/" % (user, product),
|
||||
"language": str(answer.get("language") or "en-US"),
|
||||
"bridge": windows_path(str(UBISOFT_CACHE / ("bridge-%d" % product))),
|
||||
"log": windows_path(str(UBISOFT_CACHE / ("upc-%d.log" % product))),
|
||||
}
|
||||
|
||||
|
||||
def prepare_ubisoft(folder, sidecar, compat_data, launch_dir, proton="", ask_app=None):
|
||||
launch = folder / UBISOFT_LAUNCH
|
||||
try:
|
||||
launch.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
product = ubisoft_product(sidecar)
|
||||
if product is None:
|
||||
return "no-product"
|
||||
if not UBISOFT_SERVICE.is_file():
|
||||
return "no-service"
|
||||
made = create_prefix(compat_data, proton) if not (Path(compat_data) / "pfx/user.reg").is_file() else "present"
|
||||
if made not in ("present", "created"):
|
||||
return "prefix " + made
|
||||
runtime = install_runtime(compat_data)
|
||||
if not ubisoft_runtime_ready(compat_data):
|
||||
return "runtime " + runtime
|
||||
registry = register_ubisoft(folder, product, compat_data)
|
||||
if not launch_dir:
|
||||
return "runtime %s, %s, no-channel" % (runtime, registry)
|
||||
answer = (ask_app or ask)(Path(launch_dir) / "stores", {"op": "ubisoft-launch", "store": "ubisoft", "id": str(sidecar.get("id"))},
|
||||
timeout=UBISOFT_ASK_WAIT)
|
||||
if not isinstance(answer, dict) or not answer.get("ok") or not answer.get("ticket"):
|
||||
reason = "timeout" if answer is None else str(answer.get("reason") or "refused")
|
||||
return "runtime %s, %s, session %s" % (runtime, registry, reason)
|
||||
written = 0
|
||||
if answer.get("registry") and wait_for_server(Path(compat_data) / "pfx"):
|
||||
written = apply_manifest_registry(compat_data, answer.get("registry"), folder, str(answer.get("language") or "en-US"))
|
||||
tmp = launch.with_name(launch.name + ".tmp")
|
||||
tmp.write_text(json.dumps(ubisoft_launch(folder, sidecar, product, compat_data, answer)))
|
||||
os.replace(tmp, launch)
|
||||
return "runtime %s, %s, %d manifest value(s), session ready" % (runtime, registry, written)
|
||||
|
||||
COMET_DIR = Path("/usr/local/lib/droiddeck-comet")
|
||||
|
||||
|
||||
@@ -613,6 +1076,344 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=Non
|
||||
return "import-failed" + note
|
||||
|
||||
|
||||
EA_HARDWARE = ".droiddeck-ea-hw.json"
|
||||
EA_CLIENT = "C:\\Program Files (x86)\\Origin\\Origin.exe"
|
||||
EA_WMI = (
|
||||
("boardManufacturer", "Win32_BaseBoard", "Manufacturer"),
|
||||
("boardSerial", "Win32_BaseBoard", "SerialNumber"),
|
||||
("biosManufacturer", "Win32_BIOS", "Manufacturer"),
|
||||
("biosSerial", "Win32_BIOS", "SerialNumber"),
|
||||
("osInstallDate", "Win32_OperatingSystem", "InstallDate"),
|
||||
("osSerial", "Win32_OperatingSystem", "SerialNumber"),
|
||||
("gpuPnpId", "Win32_VideoController", "PNPDeviceID"),
|
||||
("cpuManufacturer", "Win32_Processor", "Manufacturer"),
|
||||
("processorId", "Win32_Processor", "ProcessorId"),
|
||||
("brand", "Win32_Processor", "Name"),
|
||||
)
|
||||
EA_ROOTS = {"HKLM": "HKEY_LOCAL_MACHINE", "HKCU": "HKEY_CURRENT_USER"}
|
||||
|
||||
|
||||
def decode_output(data):
|
||||
if data[:2] in (b"\xff\xfe", b"\xfe\xff") or (len(data) > 1 and data[1:2] == b"\x00"):
|
||||
return data.decode("utf-16", "replace")
|
||||
return data.decode("utf-8", "replace")
|
||||
|
||||
|
||||
def wmi_value(text):
|
||||
rows = [row.strip() for row in text.replace("\r", "\n").split("\n") if row.strip()]
|
||||
return rows[1] if len(rows) > 1 else ""
|
||||
|
||||
|
||||
CPUID_LEAVES = (0, 1, 0x80000002, 0x80000003, 0x80000004)
|
||||
|
||||
|
||||
def cpuid_exe():
|
||||
"""A 32-bit console program that writes the raw CPUID leaves an x86 game sees under the emulator."""
|
||||
import struct
|
||||
base, rva = 0x400000, 0x1000
|
||||
buf, written = base + rva + 0x180, base + rva + 0x1D0
|
||||
iat = base + rva + 0x138
|
||||
code = b"\x53\x57\xbf" + struct.pack("<I", buf)
|
||||
for leaf in CPUID_LEAVES:
|
||||
code += b"\xb8" + struct.pack("<I", leaf) + b"\x31\xc9\x0f\xa2\x89\x07\x89\x5f\x04\x89\x4f\x08\x89\x57\x0c\x83\xc7\x10"
|
||||
code += b"\x6a\xf5\xff\x15" + struct.pack("<I", iat)
|
||||
code += b"\x6a\x00\x68" + struct.pack("<I", written) + b"\x6a\x50\x68" + struct.pack("<I", buf) + b"\x50\xff\x15" + struct.pack("<I", iat + 4)
|
||||
code += b"\x6a\x00\xff\x15" + struct.pack("<I", iat + 8)
|
||||
section = bytearray(0x200)
|
||||
section[:len(code)] = code
|
||||
names = [(0x148, b"GetStdHandle"), (0x158, b"WriteFile"), (0x164, b"ExitProcess")]
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
|
||||
for i, (at, name) in enumerate(names):
|
||||
struct.pack_into("<I", section, 0x128 + 4 * i, rva + at)
|
||||
struct.pack_into("<I", section, 0x138 + 4 * i, rva + at)
|
||||
section[at + 2:at + 2 + len(name)] = name
|
||||
section[0x172:0x172 + 12] = b"KERNEL32.dll"
|
||||
header = bytearray(0x200)
|
||||
header[0:2] = b"MZ"
|
||||
struct.pack_into("<I", header, 0x3C, 0x40)
|
||||
header[0x40:0x44] = b"PE\0\0"
|
||||
struct.pack_into("<HHIIIHH", header, 0x44, 0x14C, 1, 0, 0, 0, 0xE0, 0x0103)
|
||||
opt = struct.pack("<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII", 0x10B, 0, 0, 0x200, 0, 0, rva, rva, rva, base, 0x1000, 0x200,
|
||||
4, 0, 0, 0, 4, 0, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
|
||||
dirs = bytearray(128)
|
||||
struct.pack_into("<II", dirs, 8, rva + 0x100, 40)
|
||||
struct.pack_into("<II", dirs, 96, rva + 0x138, 16)
|
||||
header[0x58:0x58 + 0xE0] = opt + bytes(dirs)
|
||||
header[0x138:0x138 + 40] = struct.pack("<8sIIIIIIHHI", b".text", 0x1000, rva, 0x200, 0x200, 0, 0, 0, 0, 0xE0000060)
|
||||
return bytes(header) + bytes(section)
|
||||
|
||||
|
||||
EA_STUB_DIR = "Program Files (x86)/Origin"
|
||||
EA_STUB = "C:\\Program Files (x86)\\Origin\\Origin.exe"
|
||||
|
||||
|
||||
def origin_stub_exe():
|
||||
"""A 32-bit program that only sleeps: the process older EA SDKs look for while a game runs."""
|
||||
import struct
|
||||
base, rva = 0x400000, 0x1000
|
||||
iat = base + rva + 0x138
|
||||
code = b"\x6a\xff\xff\x15" + struct.pack("<I", iat) + b"\xeb\xf6"
|
||||
section = bytearray(0x200)
|
||||
section[:len(code)] = code
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
|
||||
struct.pack_into("<I", section, 0x128, rva + 0x148)
|
||||
struct.pack_into("<I", section, 0x138, rva + 0x148)
|
||||
section[0x14A:0x14A + 5] = b"Sleep"
|
||||
section[0x172:0x172 + 12] = b"KERNEL32.dll"
|
||||
header = bytearray(cpuid_exe()[:0x200])
|
||||
struct.pack_into("<H", header, 0x58 + 68, 2)
|
||||
return bytes(header) + bytes(section)
|
||||
|
||||
|
||||
def install_origin_stub(compat_data):
|
||||
if not compat_data:
|
||||
return "no-prefix"
|
||||
target = Path(compat_data) / "pfx/drive_c" / EA_STUB_DIR / "Origin.exe"
|
||||
data = origin_stub_exe()
|
||||
try:
|
||||
if target.is_file() and target.read_bytes() == data:
|
||||
return "ready"
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
return "written"
|
||||
except OSError:
|
||||
return "failed"
|
||||
|
||||
|
||||
def cpuid_values(raw):
|
||||
import struct
|
||||
if len(raw) < 80:
|
||||
return {}
|
||||
regs = [struct.unpack_from("<IIII", raw, 16 * i) for i in range(5)]
|
||||
vendor = struct.pack("<III", regs[0][1], regs[0][3], regs[0][2]).split(b"\0")[0].decode("latin-1")
|
||||
brand = b"".join(struct.pack("<IIII", *r) for r in regs[2:]).split(b"\0")[0].decode("latin-1")
|
||||
return {"cpuVendor": vendor, "cpuEax": "%08X" % regs[1][0], "cpuEdx": "%08X" % regs[1][3],
|
||||
"cpuEcx": "%08x" % regs[1][2], "cpuBrand": brand}
|
||||
|
||||
|
||||
EA_PROBE_FIELDS = ("boardManufacturer", "biosManufacturer", "osInstallDate", "osSerial", "volumeSerial", "hostname",
|
||||
"cpuVendor", "cpuEax", "cpuEdx", "cpuEcx")
|
||||
|
||||
|
||||
def probe_complete(values):
|
||||
return all(str(values.get(key) or "").strip() for key in EA_PROBE_FIELDS)
|
||||
|
||||
|
||||
def ea_hardware(compat_data, proton, timeout=240):
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
cache = pfx / EA_HARDWARE
|
||||
try:
|
||||
cached = json.loads(cache.read_text())
|
||||
if isinstance(cached, dict) and probe_complete(cached):
|
||||
return cached, "cached"
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
if not proton or not Path(proton).is_file():
|
||||
return {}, "no-proton"
|
||||
values = {}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
|
||||
folder = Path(tmp)
|
||||
lines = ["@echo off"]
|
||||
for key, cls, prop in EA_WMI:
|
||||
lines.append('wmic path %s get %s > "%s"' % (cls, prop, windows_path(str(folder / (key + ".txt")))))
|
||||
lines.append('vol C: > "%s"' % windows_path(str(folder / "volume.txt")))
|
||||
lines.append('hostname > "%s"' % windows_path(str(folder / "hostname.txt")))
|
||||
(folder / "cpuid.exe").write_bytes(cpuid_exe())
|
||||
lines.append('"%s" > "%s"' % (windows_path(str(folder / "cpuid.exe")), windows_path(str(folder / "cpuid.bin"))))
|
||||
bat = folder / "probe.bat"
|
||||
bat.write_bytes(("\r\n".join(lines) + "\r\n").encode())
|
||||
try:
|
||||
subprocess.run([proton, "run", "cmd.exe", "/d", "/c", windows_path(str(bat))], stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
return {}, "timeout"
|
||||
except OSError:
|
||||
return {}, "failed"
|
||||
for key, _, _ in EA_WMI:
|
||||
try:
|
||||
values[key] = wmi_value(decode_output((folder / (key + ".txt")).read_bytes()))
|
||||
except OSError:
|
||||
values[key] = ""
|
||||
try:
|
||||
found = re.search(r"([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})", decode_output((folder / "volume.txt").read_bytes()))
|
||||
values["volumeSerial"] = (found.group(1) + found.group(2)).lower() if found else ""
|
||||
except OSError:
|
||||
values["volumeSerial"] = ""
|
||||
try:
|
||||
values["hostname"] = decode_output((folder / "hostname.txt").read_bytes()).strip().splitlines()[0].strip()
|
||||
except (OSError, IndexError):
|
||||
values["hostname"] = ""
|
||||
try:
|
||||
values.update(cpuid_values((folder / "cpuid.bin").read_bytes()))
|
||||
except OSError:
|
||||
pass
|
||||
if probe_complete(values):
|
||||
try:
|
||||
cache.write_text(json.dumps(values))
|
||||
except OSError:
|
||||
pass
|
||||
return values, "probed"
|
||||
return values, "incomplete"
|
||||
|
||||
|
||||
def ea_registry_entries(folder, sidecar):
|
||||
install = windows_path(str(folder)).rstrip("\\") + "\\"
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
title = str(extra.get("displayName") or sidecar.get("title") or folder.name).strip()
|
||||
locale = str(extra.get("locale") or "en_US")
|
||||
entries = [
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Desktop", "InstallSuccessful", "true"),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "InstallSuccessful", "true"),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "ClientPath", EA_CLIENT),
|
||||
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin", "ClientPath", EA_CLIENT),
|
||||
]
|
||||
for content in [c.strip() for c in str(extra.get("contentIds") or extra.get("contentId") or "").split(",")]:
|
||||
if re.fullmatch(r"[A-Za-z0-9._-]{1,64}", content):
|
||||
key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin Games\\" + content
|
||||
entries += [(key, "DisplayName", title), (key, "Install Dir", install), (key, "Locale", locale)]
|
||||
try:
|
||||
keys = json.loads(extra.get("registry") or "[]")
|
||||
except ValueError:
|
||||
keys = []
|
||||
for pair in keys if isinstance(keys, list) else []:
|
||||
if not isinstance(pair, list) or len(pair) != 2:
|
||||
continue
|
||||
key, name = str(pair[0]), str(pair[1])
|
||||
root, _, rest = key.partition("\\")
|
||||
key = EA_ROOTS.get(root.upper(), root) + ("\\" + rest if rest else "")
|
||||
if key.upper().startswith(("HKEY_LOCAL_MACHINE\\", "HKEY_CURRENT_USER\\")) and name and "\n" not in key + name:
|
||||
entries.append((key, name, install))
|
||||
if title:
|
||||
entries.append((key, "DisplayName", title))
|
||||
entries.append((key, "Locale", locale))
|
||||
return entries
|
||||
|
||||
|
||||
def ea_registry(folder, sidecar, compat_data, proton, timeout=90):
|
||||
if not compat_data or not proton or not Path(proton).is_file():
|
||||
return "no-proton"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
text = "Windows Registry Editor Version 5.00\r\n\r\n" + "".join(
|
||||
'[%s]\r\n"%s"="%s"\r\n\r\n' % (key, reg_escape(name), reg_escape(value)) for key, name, value in ea_registry_entries(folder, sidecar))
|
||||
stamp = hashlib.sha256(text.encode("utf-8")).hexdigest()
|
||||
marker = pfx / (".droiddeck-ea-registry-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp and (pfx / "system.reg").is_file():
|
||||
return "ready"
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
|
||||
source = Path(tmp) / "registry.reg"
|
||||
source.write_bytes(b"\xff\xfe" + text.encode("utf-16-le"))
|
||||
executable = pfx / "drive_c/windows/system32/reg.exe"
|
||||
for view in ("/reg:32", "/reg:64"):
|
||||
run = subprocess.run([proton, "run", str(executable) if executable.is_file() else "reg.exe", "import", windows_path(str(source)), view],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
if run.returncode:
|
||||
return "import-failed"
|
||||
marker.write_text(stamp)
|
||||
return "written"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "timeout"
|
||||
except OSError:
|
||||
return "import-failed"
|
||||
|
||||
|
||||
def find_case(folder, relative):
|
||||
current = Path(folder)
|
||||
for part in [p for p in relative.replace("\\", "/").split("/") if p and p != "."]:
|
||||
exact = current / part
|
||||
if exact.exists():
|
||||
current = exact
|
||||
continue
|
||||
try:
|
||||
current = next(c for c in current.iterdir() if c.name.lower() == part.lower())
|
||||
except (OSError, StopIteration):
|
||||
return None
|
||||
return current if current != Path(folder) else None
|
||||
|
||||
|
||||
def touchup_args(raw, locale, install):
|
||||
raw = raw.replace("{locale}", locale)
|
||||
raw = raw.replace('"{installLocation}"', '"%s"' % install).replace("{installLocation}", install)
|
||||
try:
|
||||
return shlex.split(raw.replace("\\", "\\\\"))
|
||||
except ValueError:
|
||||
return raw.split()
|
||||
|
||||
|
||||
def ea_touchup(folder, sidecar, compat_data, proton, timeout=900):
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
relative = str(extra.get("touchup") or "")
|
||||
if not relative:
|
||||
return "none"
|
||||
exe = find_case(folder, relative)
|
||||
if exe is None or not exe.is_file():
|
||||
return "missing"
|
||||
if not compat_data or not proton or not Path(proton).is_file():
|
||||
return "no-proton"
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
stamp = str(sidecar.get("installVersion") or "") + " " + str(sidecar.get("installedAt") or "")
|
||||
marker = pfx / (".droiddeck-ea-touchup-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
|
||||
try:
|
||||
if marker.is_file() and marker.read_text() == stamp:
|
||||
return "done"
|
||||
except OSError:
|
||||
pass
|
||||
args = touchup_args(str(extra.get("touchupArgs") or ""), str(extra.get("locale") or "en_US"), windows_path(str(folder)).rstrip("\\"))
|
||||
try:
|
||||
run = subprocess.run([proton, "run", str(exe)] + args, cwd=str(exe.parent), stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
result = "ok" if run.returncode == 0 else "exit-%d" % run.returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
result = "timeout"
|
||||
except OSError:
|
||||
return "failed"
|
||||
try:
|
||||
marker.write_text(stamp)
|
||||
except OSError:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def write_licenses(compat_data, licenses):
|
||||
if not compat_data:
|
||||
return 0
|
||||
root = Path(compat_data) / "pfx/drive_c"
|
||||
written = 0
|
||||
for item in licenses or []:
|
||||
relative = str(item.get("path") or "") if isinstance(item, dict) else ""
|
||||
if not relative or relative.startswith("/") or ".." in relative.split("/"):
|
||||
continue
|
||||
target = root / relative
|
||||
try:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(base64.b64decode(item.get("data") or ""))
|
||||
written += 1
|
||||
except (OSError, binascii.Error):
|
||||
pass
|
||||
return written
|
||||
|
||||
|
||||
def prepare_ea(folder, sidecar, compat_data, launch_dir):
|
||||
game = str(sidecar.get("id"))
|
||||
proton = os.environ.get("BL_STORE_PROTON", "")
|
||||
made = create_prefix(compat_data, proton)
|
||||
ready = made in ("present", "created") or (compat_data and (Path(compat_data) / "pfx/user.reg").is_file())
|
||||
stub = install_origin_stub(compat_data) if ready else "no-prefix"
|
||||
hardware, probe = ea_hardware(compat_data, proton) if ready else ({}, "no-prefix")
|
||||
answer = None
|
||||
if launch_dir:
|
||||
answer = ask(Path(launch_dir) / "stores", {"op": "ea-prepare", "store": "ea", "id": game, "hardware": hardware}, timeout=40.0)
|
||||
sidecar = sidecar_at(Path(folder)) or sidecar
|
||||
log("ea %s prefix=%s stub=%s hardware=%s registry=%s touchup=%s" % (
|
||||
game, made, stub, probe, ea_registry(folder, sidecar, compat_data, proton), ea_touchup(folder, sidecar, compat_data, proton)))
|
||||
if answer is None:
|
||||
log("ea %s session=no reason=%s" % (game, "timeout" if launch_dir else "no-channel"))
|
||||
return
|
||||
written = write_licenses(compat_data, answer.get("licenses"))
|
||||
log("ea %s session=%s reason=%s lsx=%s licence=%s files=%d" % (
|
||||
game, "yes" if answer.get("ok") else "no", answer.get("reason", ""), answer.get("lsx"), answer.get("license", ""), written))
|
||||
|
||||
|
||||
def gog_support_actions(folder):
|
||||
found = []
|
||||
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
|
||||
@@ -771,6 +1572,28 @@ def main(argv):
|
||||
prepare_gog(sidecar, compat_data, launch_dir)
|
||||
log("gog registry: " + apply_gog_registry(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
|
||||
log("gog support data: " + gog_support_data(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
|
||||
if store == "rockstar":
|
||||
if game not in ROCKSTAR_TITLES and not rockstar_sdk(folder, sidecar):
|
||||
if compat_data:
|
||||
(Path(compat_data) / "pfx" / ROCKSTAR_FOLDER / "launch.json").unlink(missing_ok=True)
|
||||
return STORE_GAME
|
||||
try:
|
||||
state = prepare_rockstar(folder, sidecar, compat_data, launch_dir, os.environ.get("BL_STORE_PROTON", ""))
|
||||
except (OSError, ValueError, subprocess.TimeoutExpired):
|
||||
state = "preparation-failed"
|
||||
log("rockstar %s: %s" % (game, state))
|
||||
if state != "ready" and launch_dir:
|
||||
ask(Path(launch_dir) / "stores", {"op": "rockstar-exited", "store": "rockstar", "id": game}, timeout=1.0)
|
||||
return STORE_GAME if state == "ready" else RAN_FAILED
|
||||
if store == "ubisoft":
|
||||
try:
|
||||
log("ubisoft %s: %s" % (game, prepare_ubisoft(folder, sidecar, compat_data, launch_dir, os.environ.get("BL_STORE_PROTON", ""))))
|
||||
except OSError as e:
|
||||
try:
|
||||
(folder / UBISOFT_LAUNCH).unlink()
|
||||
except OSError:
|
||||
pass
|
||||
log("ubisoft %s: not prepared (%s), starting directly" % (game, e))
|
||||
if store == "epic":
|
||||
handled = os.environ.get(EPIC_HANDLED) == "1" and (folder / EPIC_ARGS).is_file()
|
||||
if not handled:
|
||||
@@ -808,6 +1631,9 @@ def main(argv):
|
||||
got = bool(answer.get("code"))
|
||||
log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", "")))
|
||||
log("epic prefix=%s %s" % (prefix_id or "?", provision_prefix(compat_data)))
|
||||
if store == "ea":
|
||||
prepare_ea(folder, sidecar, compat_data, launch_dir)
|
||||
return STORE_GAME
|
||||
if not cloud_on(sidecar):
|
||||
if store in CLOUD_STORES:
|
||||
log("cloud %s %s down result=skipped reason=off" % (store, game))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -75,8 +76,16 @@ def pe_has_arm64ec_metadata(path):
|
||||
return False
|
||||
|
||||
|
||||
# Only x64 code and members of the same runtime family import these, so an x64 copy loads in an
|
||||
# ARM64EC prefix, and games check for a newer version than Wine's builtins report.
|
||||
VC_RUNTIME = re.compile(r"(msvc[pr]\d.*|vcruntime\d.*|vcomp\d*|vcamp\d.*|vccorlib\d.*|concrt\d.*|mfcm?\d.*)\.dll",
|
||||
re.IGNORECASE)
|
||||
|
||||
|
||||
def machine_compatible(path, machines, machine=None):
|
||||
machine = pe_machine(path) if machine is None else machine
|
||||
if machine == 0x8664 and 0xA641 in machines and VC_RUNTIME.fullmatch(Path(path).name):
|
||||
return True
|
||||
if machine == 0x8664 and pe_has_arm64ec_metadata(path):
|
||||
return 0xA641 in machines
|
||||
return machine in machines
|
||||
|
||||
@@ -152,6 +152,13 @@ bl_components() {
|
||||
else
|
||||
cm_app=""
|
||||
fi
|
||||
if [ "$cm_app" = 2929927072 ] && [[ "${SteamAppId:-}" =~ ^[0-9]{1,10}$ ]] && (( 10#$SteamAppId > 0 && 10#$SteamAppId <= 4294967295 )); then
|
||||
cm_app=$((10#$SteamAppId))
|
||||
elif [ "$cm_app" = 2929927072 ] && [[ "${SteamGameId:-}" =~ ^[1-9][0-9]{9,19}$ ]] &&
|
||||
{ [ ${#SteamGameId} -lt 20 ] || [[ ! "$SteamGameId" > 18446744073709551615 ]]; } &&
|
||||
(( (10#$SteamGameId & 0xFFFFFFFF) == 0x02000000 && ((10#$SteamGameId >> 32) & 0xFFFFFFFF) != 0 )); then
|
||||
cm_app=$(( (10#$SteamGameId >> 32) & 0xFFFFFFFF ))
|
||||
fi
|
||||
if [ -z "$cm_app" ]; then
|
||||
echo "droiddeck-proton: components: invalid game prefix, left as it is" >&2
|
||||
return 0
|
||||
@@ -1533,7 +1540,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
auto = followers(state, current)
|
||||
known = {app for app in state.get("owned", ()) if isinstance(app, str)} if isinstance(state.get("owned"), list) else set()
|
||||
pinned = {app: current[app] for app in set(owned) - known
|
||||
if current.get(app) in {TOOL, previous} | gone and app not in auto}
|
||||
if app in current and current.get(app) in {TOOL, previous} | gone and app not in auto}
|
||||
if pinned and isinstance(auto, dict):
|
||||
state["auto"] = dict(auto, **pinned)
|
||||
state["owned"] = sorted(set(owned), key=app_order)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *,
|
||||
char *const[], char *const[]);
|
||||
__attribute__((visibility("hidden")))
|
||||
char *const *bl_webhelper_argv(const char *path, char *const argv[], char *const envp[]);
|
||||
|
||||
#if defined(__aarch64__) || defined(BINFMT_TEST)
|
||||
|
||||
@@ -141,21 +143,26 @@ __attribute__((visibility("hidden"))) int bl_binfmt_spawn(pid_t *pid, const char
|
||||
}
|
||||
|
||||
int execvpe(const char *file, char *const argv[], char *const envp[]) {
|
||||
char resolved[PATH_MAX];
|
||||
const char *path = lookup(file, resolved, sizeof resolved) ? resolved : file;
|
||||
char *const *adjusted = bl_webhelper_argv(path, argv, envp);
|
||||
static int (*real)(const char *, char *const[], char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execvpe");
|
||||
bl_binfmt_before_search(file, argv, envp);
|
||||
real(file, argv, envp);
|
||||
return bl_binfmt_after_search(file, argv, envp, errno);
|
||||
bl_binfmt_before_search(file, (char *const *)adjusted, envp);
|
||||
real(file, (char *const *)adjusted, envp);
|
||||
return bl_binfmt_after_search(file, (char *const *)adjusted, envp, errno);
|
||||
}
|
||||
|
||||
int posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *fa, const posix_spawnattr_t *attr,
|
||||
char *const argv[], char *const envp[]) {
|
||||
char path[PATH_MAX];
|
||||
int found = lookup(file, path, sizeof path);
|
||||
char *const *adjusted = bl_webhelper_argv(found ? path : file, argv, envp);
|
||||
static spawn_fn real, spawn;
|
||||
if (!real) real = (spawn_fn)dlsym(RTLD_NEXT, "posix_spawnp");
|
||||
if (!spawn) spawn = (spawn_fn)dlsym(RTLD_NEXT, "posix_spawn");
|
||||
char path[PATH_MAX];
|
||||
if (!handing_off() || !lookup(file, path, sizeof path)) return real(pid, file, fa, attr, argv, envp);
|
||||
return bl_binfmt_spawn(pid, path, fa, attr, argv, envp, spawn);
|
||||
if (!handing_off() || !found) return real(pid, file, fa, attr, (char *const *)adjusted, envp);
|
||||
return bl_binfmt_spawn(pid, path, fa, attr, (char *const *)adjusted, envp, spawn);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -81,7 +81,6 @@ static void cp_init(void) {
|
||||
struct stat st;
|
||||
void *map;
|
||||
int fd;
|
||||
if (strcmp(program_invocation_short_name, "plasmashell") != 0) return;
|
||||
if (!cp_find_cond_bit()) return;
|
||||
fd = open(CP_CTL, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DESCRIPTOR "user.wine.sd"
|
||||
#define STORE "/.droiddeck-descriptors"
|
||||
#define ENTRY_MAX (PATH_MAX * 2)
|
||||
|
||||
int bl_is_wineserver(void) __attribute__((visibility("hidden")));
|
||||
|
||||
static int store_seen;
|
||||
|
||||
static int kept(const char *name) {
|
||||
return name != NULL && strcmp(name, DESCRIPTOR) == 0 && bl_is_wineserver();
|
||||
}
|
||||
|
||||
static int store_root(char *out, size_t size) {
|
||||
const char *prefix = getenv("WINEPREFIX");
|
||||
int n;
|
||||
|
||||
if (prefix == NULL || prefix[0] != '/') return -1;
|
||||
n = snprintf(out, size, "%s" STORE, prefix);
|
||||
return n > 0 && (size_t)n < size ? n : -1;
|
||||
}
|
||||
|
||||
static int store_exists(void) {
|
||||
char root[PATH_MAX];
|
||||
|
||||
if (store_seen) return 1;
|
||||
if (store_root(root, sizeof(root)) < 0) return 0;
|
||||
store_seen = access(root, F_OK) == 0;
|
||||
return store_seen;
|
||||
}
|
||||
|
||||
static int entry_for(const char *path, char *out, size_t size, const char *suffix, int create) {
|
||||
int used = store_root(out, size);
|
||||
const char *part = path, *end;
|
||||
|
||||
if (used < 0 || path[0] != '/') return -1;
|
||||
if (create && mkdir(out, 0700) != 0 && errno != EEXIST) return -1;
|
||||
while (*part == '/') part++;
|
||||
if (*part == '\0') return -1;
|
||||
for (;;) {
|
||||
size_t length;
|
||||
const char *tail;
|
||||
|
||||
end = strchr(part, '/');
|
||||
length = end ? (size_t)(end - part) : strlen(part);
|
||||
tail = end ? ".d" : suffix;
|
||||
if (length + strlen(tail) > NAME_MAX || used + length + strlen(tail) + 2 > size) return -1;
|
||||
out[used++] = '/';
|
||||
memcpy(out + used, part, length);
|
||||
used += (int)length;
|
||||
strcpy(out + used, tail);
|
||||
used += (int)strlen(tail);
|
||||
if (!end) break;
|
||||
if (create && mkdir(out, 0700) != 0 && errno != EEXIST) return -1;
|
||||
part = end + 1;
|
||||
}
|
||||
if (create) store_seen = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int path_of(int fd, char *out, size_t size) {
|
||||
char link[40];
|
||||
ssize_t n;
|
||||
|
||||
snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
|
||||
n = readlink(link, out, size - 1);
|
||||
if (n <= 0 || out[0] != '/') return -1;
|
||||
out[n] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int resolved(const char *path, char *out, size_t size) {
|
||||
int fd, result;
|
||||
|
||||
if (path == NULL) return -1;
|
||||
fd = open(path, O_PATH | O_NOFOLLOW | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
result = path_of(fd, out, size);
|
||||
close(fd);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int entry_of(int fd, char *out, size_t size, int create) {
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (path_of(fd, path, sizeof(path)) != 0) return -1;
|
||||
return entry_for(path, out, size, ".sd", create);
|
||||
}
|
||||
|
||||
static ssize_t stored_read(int fd, void *value, size_t size) {
|
||||
char entry[ENTRY_MAX];
|
||||
struct stat st;
|
||||
ssize_t got = 0;
|
||||
int file;
|
||||
|
||||
if (entry_of(fd, entry, sizeof(entry), 0) != 0) return -2;
|
||||
file = open(entry, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
|
||||
if (file < 0) {
|
||||
if (errno != ENOENT) return -2;
|
||||
errno = ENODATA;
|
||||
return -1;
|
||||
}
|
||||
if (fstat(file, &st) != 0) {
|
||||
close(file);
|
||||
return -2;
|
||||
}
|
||||
if (size == 0) {
|
||||
close(file);
|
||||
return (ssize_t)st.st_size;
|
||||
}
|
||||
if ((size_t)st.st_size > size) {
|
||||
close(file);
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
while (got < st.st_size) {
|
||||
ssize_t n = read(file, (char *)value + got, (size_t)(st.st_size - got));
|
||||
if (n <= 0) {
|
||||
close(file);
|
||||
return -2;
|
||||
}
|
||||
got += n;
|
||||
}
|
||||
close(file);
|
||||
return got;
|
||||
}
|
||||
|
||||
static int stored_write(int fd, const void *value, size_t size) {
|
||||
char entry[ENTRY_MAX], fresh[ENTRY_MAX + 8];
|
||||
size_t put = 0;
|
||||
int file;
|
||||
|
||||
if (entry_of(fd, entry, sizeof(entry), 1) != 0) return -1;
|
||||
snprintf(fresh, sizeof(fresh), "%s.new", entry);
|
||||
file = open(fresh, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600);
|
||||
if (file < 0) return -1;
|
||||
while (put < size) {
|
||||
ssize_t n = write(file, (const char *)value + put, size - put);
|
||||
if (n <= 0) {
|
||||
close(file);
|
||||
unlinkat(AT_FDCWD, fresh, 0);
|
||||
return -1;
|
||||
}
|
||||
put += (size_t)n;
|
||||
}
|
||||
if (close(file) != 0 || renameat(AT_FDCWD, fresh, AT_FDCWD, entry) != 0) {
|
||||
unlinkat(AT_FDCWD, fresh, 0);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size) {
|
||||
static ssize_t (*next)(int, const char *, void *, size_t);
|
||||
ssize_t result;
|
||||
|
||||
if (next == NULL) next = dlsym(RTLD_NEXT, "fgetxattr");
|
||||
if (next == NULL) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
result = next(fd, name, value, size);
|
||||
if (result >= 0 || errno != ENOTSUP || !kept(name)) return result;
|
||||
result = stored_read(fd, value, size);
|
||||
if (result == -2) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags) {
|
||||
static int (*next)(int, const char *, const void *, size_t, int);
|
||||
int saved = errno, result;
|
||||
|
||||
if (next == NULL) next = dlsym(RTLD_NEXT, "fsetxattr");
|
||||
if (next == NULL) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
result = next(fd, name, value, size, flags);
|
||||
if (result == 0 || errno != ENOTSUP || !kept(name)) return result;
|
||||
if (stored_write(fd, value, size) != 0) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
errno = saved;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fremovexattr(int fd, const char *name) {
|
||||
static int (*next)(int, const char *);
|
||||
char entry[ENTRY_MAX];
|
||||
int saved = errno, result;
|
||||
|
||||
if (next == NULL) next = dlsym(RTLD_NEXT, "fremovexattr");
|
||||
if (next == NULL) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
result = next(fd, name);
|
||||
if (result == 0 || errno != ENOTSUP || !kept(name)) return result;
|
||||
if (entry_of(fd, entry, sizeof(entry), 0) != 0) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
if (unlinkat(AT_FDCWD, entry, 0) != 0) {
|
||||
errno = errno == ENOENT ? ENODATA : ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
errno = saved;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tracked(const char *path, char *out, size_t size) {
|
||||
int saved = errno, found;
|
||||
|
||||
found = bl_is_wineserver() && store_exists() && resolved(path, out, size) == 0;
|
||||
errno = saved;
|
||||
return found;
|
||||
}
|
||||
|
||||
static void forget(const char *path, int folder) {
|
||||
char entry[ENTRY_MAX];
|
||||
int saved = errno;
|
||||
|
||||
if (entry_for(path, entry, sizeof(entry), ".sd", 0) == 0) unlinkat(AT_FDCWD, entry, 0);
|
||||
if (folder && entry_for(path, entry, sizeof(entry), ".d", 0) == 0) unlinkat(AT_FDCWD, entry, AT_REMOVEDIR);
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static void follow(const char *from, const char *to) {
|
||||
static const char *const kinds[] = {".sd", ".d"};
|
||||
char old[ENTRY_MAX], new[ENTRY_MAX];
|
||||
int saved = errno;
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
if (entry_for(from, old, sizeof(old), kinds[i], 0) != 0) continue;
|
||||
if (access(old, F_OK) != 0) {
|
||||
if (i == 0 && entry_for(to, new, sizeof(new), kinds[i], 0) == 0) unlinkat(AT_FDCWD, new, 0);
|
||||
continue;
|
||||
}
|
||||
if (entry_for(to, new, sizeof(new), kinds[i], 1) != 0 || renameat(AT_FDCWD, old, AT_FDCWD, new) != 0) {
|
||||
if (i == 0) unlinkat(AT_FDCWD, old, 0);
|
||||
}
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_descriptor_unlink(const char *path, int (*real)(const char *)) {
|
||||
char target[PATH_MAX];
|
||||
int known = tracked(path, target, sizeof(target)), result = real(path);
|
||||
|
||||
if (result == 0 && known) forget(target, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_descriptor_rmdir(const char *path, int (*real)(const char *)) {
|
||||
char target[PATH_MAX];
|
||||
int known = tracked(path, target, sizeof(target)), result = real(path);
|
||||
|
||||
if (result == 0 && known) forget(target, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_descriptor_remove(const char *path, int (*real)(const char *)) {
|
||||
return bl_descriptor_rmdir(path, real);
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_descriptor_rename(const char *from, const char *to, int (*real)(const char *, const char *)) {
|
||||
char old[PATH_MAX], new[PATH_MAX];
|
||||
int known = tracked(from, old, sizeof(old)), result = real(from, to);
|
||||
|
||||
if (result == 0 && known && tracked(to, new, sizeof(new))) follow(old, new);
|
||||
return result;
|
||||
}
|
||||
@@ -83,6 +83,19 @@ static int notify = -1;
|
||||
static int forked;
|
||||
static struct { dev_t dev; int fuse; } devs[8];
|
||||
static int ndevs;
|
||||
// Libraries preloaded after this one can call back in while a lock is held (the native userland
|
||||
// hook's inotify_add_watch calls mkdir() by name); such calls go straight to the next library.
|
||||
static __thread int holding;
|
||||
|
||||
static void take(pthread_mutex_t *m) {
|
||||
pthread_mutex_lock(m);
|
||||
holding++;
|
||||
}
|
||||
|
||||
static void give(pthread_mutex_t *m) {
|
||||
holding--;
|
||||
pthread_mutex_unlock(m);
|
||||
}
|
||||
|
||||
static long long now_ns(void) {
|
||||
struct timespec t;
|
||||
@@ -109,32 +122,32 @@ static int enabled(void) {
|
||||
}
|
||||
|
||||
static int eligible(const char *path) {
|
||||
if (path == NULL || path[0] != '/' || !enabled()) return 0;
|
||||
if (holding || path == NULL || path[0] != '/' || !enabled()) return 0;
|
||||
const char *s = strstr(path, "/steamapps");
|
||||
return s && (s[10] == '/' || s[10] == 0);
|
||||
}
|
||||
|
||||
static int on_fuse(dev_t dev, const char *path) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
for (int i = 0; i < ndevs; i++) {
|
||||
if (devs[i].dev == dev) {
|
||||
int fuse = devs[i].fuse;
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return fuse;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
struct statfs fs;
|
||||
int saved = errno;
|
||||
int fuse = statfs(path, &fs) == 0 && (unsigned long)fs.f_type == FUSE_MAGIC;
|
||||
errno = saved;
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
if (ndevs < 8) {
|
||||
devs[ndevs].dev = dev;
|
||||
devs[ndevs].fuse = fuse;
|
||||
ndevs++;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return fuse;
|
||||
}
|
||||
|
||||
@@ -404,7 +417,7 @@ __attribute__((constructor)) static void resolve(void) {
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
static DIR *hit(const struct stat *st, struct handle *h, long long now) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
if (!changing) pump(NULL, 0);
|
||||
int slot = find(st->st_dev, st->st_ino);
|
||||
if (slot >= 0 && same(table[slot], st) && now - table[slot]->filled < DIR_TTL_NS && records(table[slot]) == 0) {
|
||||
@@ -413,7 +426,7 @@ static DIR *hit(const struct stat *st, struct handle *h, long long now) {
|
||||
h->snap->used = now;
|
||||
DIR *d = wrap(h);
|
||||
if (d) {
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return d;
|
||||
}
|
||||
unref(h->snap);
|
||||
@@ -421,7 +434,7 @@ static DIR *hit(const struct stat *st, struct handle *h, long long now) {
|
||||
} else if (slot >= 0) {
|
||||
drop(slot);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -462,11 +475,11 @@ static int above(struct handle *h, const char *path) {
|
||||
}
|
||||
|
||||
static int track(struct handle *h, const char *path) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
h->wd = watch(path, WATCHED);
|
||||
DIR *d = h->wd >= 0 && above(h, path) ? wrap(h) : NULL;
|
||||
if (d == NULL) let_go(h->wd, h->up, h->nup);
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return d != NULL;
|
||||
}
|
||||
|
||||
@@ -486,11 +499,11 @@ static void filling(struct handle *h, DIR *real, const struct stat *st, long lon
|
||||
}
|
||||
|
||||
static void untrack(struct handle *h) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
int i = registered((DIR *)h);
|
||||
if (i >= 0) __atomic_store_n(&handles[i], NULL, __ATOMIC_RELEASE);
|
||||
let_go(h->wd, h->up, h->nup);
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
}
|
||||
|
||||
DIR *opendir(const char *path) {
|
||||
@@ -553,11 +566,11 @@ static void finish(struct handle *h) {
|
||||
h->fill = NULL;
|
||||
int current = stat(h->path, &st) == 0 && same(l, &st);
|
||||
if (current) l->folds = folds(h->path, &st);
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
if (!changing) pump(NULL, 0);
|
||||
if (current && !__atomic_load_n(&h->dirty, __ATOMIC_RELAXED)) install(l);
|
||||
else destroy(l);
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
}
|
||||
|
||||
static struct dirent64 *entry(struct handle *h) {
|
||||
@@ -624,7 +637,8 @@ int readdir_r(DIR *d, struct dirent *out, struct dirent **result) {
|
||||
|
||||
int closedir(DIR *d) {
|
||||
NEXT(closedir);
|
||||
pthread_mutex_lock(&lock);
|
||||
if (holding && registered(d) < 0) return next_closedir(d);
|
||||
take(&lock);
|
||||
int i = registered(d);
|
||||
struct handle *h = i >= 0 ? handles[i] : NULL;
|
||||
if (h) {
|
||||
@@ -632,7 +646,7 @@ int closedir(DIR *d) {
|
||||
if (h->snap) unref(h->snap);
|
||||
let_go(h->wd, h->up, h->nup);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
if (h == NULL) return next_closedir(d);
|
||||
int r = 0;
|
||||
if (h->real) r = next_closedir(h->real);
|
||||
@@ -704,10 +718,10 @@ static int watching(const char *path) {
|
||||
}
|
||||
|
||||
static void begin(void) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
pump(NULL, 0);
|
||||
changing = 1;
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
}
|
||||
|
||||
static void before(struct side *s) {
|
||||
@@ -796,10 +810,10 @@ static int patch(struct side *s, int what, uint32_t event, int ok, int error, co
|
||||
}
|
||||
|
||||
static void end(struct expect *x, int nx) {
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
pump(x, nx);
|
||||
changing = 0;
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
}
|
||||
|
||||
int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
@@ -809,17 +823,17 @@ int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
struct side s;
|
||||
if (!(flags & O_CREAT) || (dirfd != AT_FDCWD && (path == NULL || path[0] != '/')) || !watching(path) || !split(path, &s))
|
||||
return real(dirfd, path, flags, mode);
|
||||
pthread_mutex_lock(&oplock);
|
||||
take(&oplock);
|
||||
begin();
|
||||
before(&s);
|
||||
int fd = real(dirfd, path, flags, mode);
|
||||
int saved = errno;
|
||||
struct expect x;
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
int nx = patch(&s, ADDED, IN_CREATE, fd >= 0, saved, path, &x);
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
end(&x, nx);
|
||||
pthread_mutex_unlock(&oplock);
|
||||
give(&oplock);
|
||||
errno = saved;
|
||||
return fd;
|
||||
}
|
||||
@@ -829,26 +843,34 @@ int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
NEXT(name); \
|
||||
struct side s; \
|
||||
if (!watching(path) || !split(path, &s)) return call; \
|
||||
pthread_mutex_lock(&oplock); \
|
||||
take(&oplock); \
|
||||
begin(); \
|
||||
before(&s); \
|
||||
int r = call; \
|
||||
int saved = errno; \
|
||||
struct expect x; \
|
||||
pthread_mutex_lock(&lock); \
|
||||
take(&lock); \
|
||||
int nx = patch(&s, what, event, r == 0, saved, what == ADDED ? path : NULL, &x); \
|
||||
if (r == 0 && what == REMOVED) forget_below(path); \
|
||||
pthread_mutex_unlock(&lock); \
|
||||
give(&lock); \
|
||||
end(&x, nx); \
|
||||
pthread_mutex_unlock(&oplock); \
|
||||
give(&oplock); \
|
||||
errno = saved; \
|
||||
return r; \
|
||||
}
|
||||
|
||||
ONE_PATH(mkdir, ADDED, IN_CREATE, next_mkdir(path, mode), mode_t mode)
|
||||
ONE_PATH(rmdir, REMOVED, IN_DELETE, next_rmdir(path))
|
||||
ONE_PATH(unlink, REMOVED, IN_DELETE, next_unlink(path))
|
||||
ONE_PATH(remove, REMOVED, IN_DELETE, next_remove(path))
|
||||
int bl_descriptor_unlink(const char *path, int (*real)(const char *)) __attribute__((visibility("hidden")));
|
||||
int bl_descriptor_rmdir(const char *path, int (*real)(const char *)) __attribute__((visibility("hidden")));
|
||||
int bl_descriptor_remove(const char *path, int (*real)(const char *)) __attribute__((visibility("hidden")));
|
||||
int bl_descriptor_rename(const char *from, const char *to, int (*real)(const char *, const char *))
|
||||
__attribute__((visibility("hidden")));
|
||||
|
||||
static int moved(const char *from, const char *to) { return bl_descriptor_rename(from, to, next_rename); }
|
||||
|
||||
ONE_PATH(rmdir, REMOVED, IN_DELETE, bl_descriptor_rmdir(path, next_rmdir))
|
||||
ONE_PATH(unlink, REMOVED, IN_DELETE, bl_descriptor_unlink(path, next_unlink))
|
||||
ONE_PATH(remove, REMOVED, IN_DELETE, bl_descriptor_remove(path, next_remove))
|
||||
|
||||
#define TWO_PATHS(name, gone, event, call) \
|
||||
int name(const char *from, const char *to) { \
|
||||
@@ -856,7 +878,7 @@ ONE_PATH(remove, REMOVED, IN_DELETE, next_remove(path))
|
||||
struct side a, b; \
|
||||
int track_a = gone && watching(from) && split(from, &a), track_b = watching(to) && split(to, &b); \
|
||||
if (!track_a && !track_b) return call(from, to); \
|
||||
pthread_mutex_lock(&oplock); \
|
||||
take(&oplock); \
|
||||
begin(); \
|
||||
if (track_a) before(&a); \
|
||||
if (track_b) before(&b); \
|
||||
@@ -864,16 +886,16 @@ ONE_PATH(remove, REMOVED, IN_DELETE, next_remove(path))
|
||||
int saved = errno; \
|
||||
struct expect x[2]; \
|
||||
int nx = 0; \
|
||||
pthread_mutex_lock(&lock); \
|
||||
take(&lock); \
|
||||
if (track_a) nx += patch(&a, REMOVED, IN_MOVED_FROM, r == 0, saved, NULL, &x[nx]); \
|
||||
if (track_b) { \
|
||||
if (track_a && strcmp(a.dir, b.dir) == 0) b.known = stat(b.dir, &b.before) == 0; \
|
||||
nx += patch(&b, ADDED, event, r == 0, saved, to, &x[nx]); \
|
||||
} \
|
||||
if (r == 0 && gone) { forget_below(from); forget_below(to); } \
|
||||
pthread_mutex_unlock(&lock); \
|
||||
give(&lock); \
|
||||
end(x, nx); \
|
||||
pthread_mutex_unlock(&oplock); \
|
||||
give(&oplock); \
|
||||
errno = saved; \
|
||||
return r; \
|
||||
}
|
||||
@@ -881,7 +903,7 @@ ONE_PATH(remove, REMOVED, IN_DELETE, next_remove(path))
|
||||
int bl_link_lock(const char *oldpath, const char *newpath, int result) __attribute__((visibility("hidden")));
|
||||
static int link_or_lock(const char *from, const char *to) { return bl_link_lock(from, to, next_link(from, to)); }
|
||||
|
||||
TWO_PATHS(rename, 1, IN_MOVED_TO, next_rename)
|
||||
TWO_PATHS(rename, 1, IN_MOVED_TO, moved)
|
||||
TWO_PATHS(link, 0, IN_CREATE, link_or_lock)
|
||||
TWO_PATHS(symlink, 0, IN_CREATE, next_symlink)
|
||||
|
||||
@@ -923,13 +945,13 @@ int bl_dircache_absent(const char *path) {
|
||||
for (const char *c = s.name; *c; c++)
|
||||
if ((unsigned char)*c >= 0x80) return 0;
|
||||
long long now = now_ns();
|
||||
pthread_mutex_lock(&lock);
|
||||
take(&lock);
|
||||
int absent = 0;
|
||||
if (!changing) {
|
||||
pump(NULL, 0);
|
||||
absent = listed_absent(s.dir, s.name, now);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
give(&lock);
|
||||
return absent;
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,8 @@ __attribute__((visibility("hidden"))) void bl_binfmt_before(const char *path, ch
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_retry(const char *path, char *const argv[], char *const envp[], int error);
|
||||
__attribute__((visibility("hidden"))) void bl_binfmt_before_search(const char *file, char *const argv[], char *const envp[]);
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_after_search(const char *file, char *const argv[], char *const envp[], int error);
|
||||
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]);
|
||||
__attribute__((visibility("hidden")))
|
||||
char *const *bl_webhelper_argv(const char *path, char *const argv[], char *const envp[]);
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *fa,
|
||||
const posix_spawnattr_t *attr, char *const argv[], char *const envp[],
|
||||
spawn_fn real);
|
||||
@@ -341,7 +342,7 @@ static char **web_helper_redirect(const char *path, char *const argv[], const ch
|
||||
}
|
||||
|
||||
int execve(const char *path, char *const argv_in[], char *const envp[]) {
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in);
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in, envp);
|
||||
static int (*real)(const char *, char *const[], char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execve");
|
||||
maybe_answer_lsof(path, argv);
|
||||
@@ -372,7 +373,7 @@ static int answer_lsof_via_spawn(const char *path, char *const argv[], pid_t *pi
|
||||
}
|
||||
|
||||
int execvp(const char *file, char *const argv_in[]) {
|
||||
char *const *argv = bl_webhelper_argv(file, argv_in);
|
||||
char *const *argv = bl_webhelper_argv(file, argv_in, environ);
|
||||
static int (*real)(const char *, char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execvp");
|
||||
maybe_answer_lsof(file, argv);
|
||||
@@ -382,7 +383,7 @@ int execvp(const char *file, char *const argv_in[]) {
|
||||
}
|
||||
|
||||
int execv(const char *path, char *const argv_in[]) {
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in);
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in, environ);
|
||||
static int (*real)(const char *, char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execv");
|
||||
maybe_answer_lsof(path, argv);
|
||||
@@ -406,5 +407,6 @@ int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *
|
||||
}
|
||||
static spawn_fn real;
|
||||
if (!real) real = (spawn_fn)dlsym(RTLD_NEXT, "posix_spawn");
|
||||
return bl_binfmt_spawn(pid, path, fa, attr, argv, envp, real);
|
||||
char *const *adjusted = bl_webhelper_argv(path, argv, envp);
|
||||
return bl_binfmt_spawn(pid, path, fa, attr, (char *const *)adjusted, envp, real);
|
||||
}
|
||||
@@ -12,7 +12,8 @@
|
||||
#define FAT_MAGIC 0x4d44
|
||||
#define EXFAT_MAGIC 0x2011bab0
|
||||
|
||||
static int is_wineserver(void) {
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_is_wineserver(void) {
|
||||
static int cached = -1;
|
||||
char exe[PATH_MAX];
|
||||
const char *base;
|
||||
@@ -43,7 +44,7 @@ void bl_storage_owner(int fd, struct stat *st) {
|
||||
int saved = errno;
|
||||
uid_t uid;
|
||||
|
||||
if (st != NULL && is_wineserver()) {
|
||||
if (st != NULL && bl_is_wineserver()) {
|
||||
uid = getuid();
|
||||
if (st->st_uid != uid && has_no_unix_owner(fd)) st->st_uid = uid;
|
||||
}
|
||||
@@ -60,7 +61,7 @@ int fchmod(int fd, mode_t mode) {
|
||||
return -1;
|
||||
}
|
||||
result = next_fchmod(fd, mode);
|
||||
if (result != 0 && errno == EPERM && is_wineserver()) {
|
||||
if (result != 0 && errno == EPERM && bl_is_wineserver()) {
|
||||
if (has_no_unix_owner(fd)) {
|
||||
errno = saved;
|
||||
return 0;
|
||||
|
||||
@@ -81,7 +81,10 @@ __attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *p
|
||||
long pid;
|
||||
if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller) || bl_from_ntdll(caller))
|
||||
return -1;
|
||||
int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC);
|
||||
// through the next open(): the native userland's hook gives the app's ids as root's there
|
||||
static int (*next_open)(const char *, int, ...) = NULL;
|
||||
if (!next_open) next_open = (int (*)(const char *, int, ...))dlsym(RTLD_NEXT, "open");
|
||||
int in = next_open ? next_open(path, O_RDONLY | O_CLOEXEC) : (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC);
|
||||
if (in < 0) goto done;
|
||||
for (;;) {
|
||||
ssize_t n = read(in, text + len, sizeof(text) - 1 - len);
|
||||
|
||||
@@ -12,7 +12,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
__attribute__((constructor)) static void bl_venus_keep_kopper(void) {
|
||||
static const char name[] = "LIBGL_KOPPER_DISABLE=";
|
||||
const char *debug = getenv("VN_DEBUG");
|
||||
if (debug && strstr(debug, "vtest")) unsetenv("LIBGL_KOPPER_DISABLE");
|
||||
if (!debug || !strstr(debug, "vtest") || !environ) return;
|
||||
char **out = environ;
|
||||
for (char **in = environ; *in; in++)
|
||||
if (strncmp(*in, name, sizeof name - 1)) *out++ = *in;
|
||||
*out = NULL;
|
||||
}
|
||||
@@ -26,6 +26,14 @@ static char *join_features(const char *have, const char *add) {
|
||||
return strcat(out, add);
|
||||
}
|
||||
|
||||
static int electron_node_mode(char *const envp[]) {
|
||||
static const char variable[] = "ELECTRON_RUN_AS_NODE=";
|
||||
for (int i = 0; envp && envp[i]; i++)
|
||||
if (!strncmp(envp[i], variable, sizeof variable - 1))
|
||||
return envp[i][sizeof variable - 1] != 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *const *chromium_argv(const char *path, char *const argv[]) {
|
||||
const char *slash = path ? strrchr(path, '/') : NULL;
|
||||
if (!slash || !argv || !argv[0]) return argv;
|
||||
@@ -48,7 +56,9 @@ static char *const *chromium_argv(const char *path, char *const argv[]) {
|
||||
return out;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]) {
|
||||
__attribute__((visibility("hidden")))
|
||||
char *const *bl_webhelper_argv(const char *path, char *const argv[], char *const envp[]) {
|
||||
if (electron_node_mode(envp)) return argv;
|
||||
if (!is_webhelper_browser(path, argv)) return chromium_argv(path, argv);
|
||||
const char *spec = getenv("BL_WEBHELPER_ARGS");
|
||||
if (!spec || !*spec) spec = WEBHELPER_DEFAULT;
|
||||
|
||||
Reference in new issue
Block a user