Let Steam install prerequisites and retire blanket registry seeding

This commit is contained in:
xXJsonDeruloXx committed 2026-10-01 18:27:53 -04:00
1 parent c2506e15d6
commit a9cd982ec8
5 files changed
+182 -118

No files matched your search

@@ -0,0 +1,86 @@
#!/usr/bin/python3
"""Undo the old blanket HasRunKey seeder before Steam/Wine starts.
Steam must run native prerequisites and record their real result. Only prefixes carrying
our old seeder stamp are migrated. Proton's intentional .NET/XNA defaults remain intact.
"""
import os
from pathlib import Path
import re
import sys
import tempfile
def restore_prefix(prefix):
prefix = Path(prefix)
stamp = prefix / '.bannerlator-redists'
reg = prefix / 'system.reg'
if not stamp.is_file() or stamp.is_symlink() or not reg.is_file() or reg.is_symlink():
return False
text = reg.read_text(encoding='utf-8')
if not text.startswith('WINE REGISTRY Version 2'):
raise ValueError('not a Wine registry')
out = []
clear = False
for line in text.splitlines(keepends=True):
match = re.match(r'^\[([^\]]+)\]', line)
if match:
key = match[1].replace('\\\\', '\\').lower()
parts = key.split('\\')
try:
common = parts.index('commonredist')
except ValueError:
clear = False
else:
clear = (parts[:common] in (
['software', 'valve', 'steam', 'apps'],
['software', 'wow6432node', 'valve', 'steam', 'apps'])
and len(parts) > common + 1
and parts[common + 1] not in ('.net', 'xna'))
if clear and re.fullmatch(r'"[^"\r\n]+"=dword:00000001\s*', line):
continue
out.append(line)
updated = ''.join(out)
if updated != text:
stat = reg.stat()
descriptor, temporary = tempfile.mkstemp(dir=prefix, prefix='.redists-')
try:
with os.fdopen(descriptor, 'w', encoding='utf-8') as f:
f.write(updated)
os.chmod(temporary, stat.st_mode & 0o777)
# Preserve template dates: this migration already covers existing prefixes and
# should not force every game through a Proton prefix upgrade.
os.utime(temporary, ns=(stat.st_atime_ns, stat.st_mtime_ns))
os.replace(temporary, reg)
finally:
if os.path.exists(temporary):
os.unlink(temporary)
stamp.unlink()
return updated != text
def restore(steam_root, libraries=('/mnt/droiddeck-sd',)):
roots = [Path(steam_root), *(Path(p) for p in libraries)]
prefixes = []
for root in roots:
prefixes.extend(root.glob('steamapps/compatdata/*/pfx'))
prefixes.extend(root.glob('steamapps/common/Proton*/files/share/default_pfx*'))
prefixes.extend(Path(steam_root).glob('compatibilitytools.d/*/files/share/default_pfx*'))
seen = set()
changed = 0
for prefix in prefixes:
actual = prefix.resolve()
if actual in seen:
continue
seen.add(actual)
try:
if restore_prefix(actual):
changed += 1
print('bannerlator-restore-redists: restored Steam prerequisite checks in %s' % prefix)
except (OSError, UnicodeError, ValueError) as error:
print('bannerlator-restore-redists: %s: %s' % (prefix, error), file=sys.stderr)
return changed
if __name__ == '__main__':
restore(sys.argv[1])
@@ -1,94 +0,0 @@
#!/bin/bash
# Marks Steam's shared redistributables as already run in every Proton prefix, and in the
# template Proton makes new prefixes from.
#
# A game whose depot lists _CommonRedist makes the client run the real installer inside the
# prefix on first launch. Those are x86 bundles, so they run under FEX, and the 2019 one leaves
# a task behind every time: its main thread exits while a helper stays blocked reading a pipe it
# also holds the write end of, so the process never reaps and the client keeps waiting on it.
#
# The client skips a "Run Process" block whose HasRunKey is already set, which is the same escape
# WineUtils.seedVcRedistRegistryIfDllsPresent() takes for the app's own containers. The names and
# versions come out of the install scripts rather than a list kept here, because Valve revises
# them; a prefix already carrying the same set is left alone.
set -u
steam_root=${1:?steam root}
redist="$steam_root/steamapps/common/Steamworks Shared/_CommonRedist"
# Every process an install script would run, as the registry key and value the client writes once
# it has run it. Names sit one level inside "Run Process", the key they share a level further in.
pairs=$(find "$redist" -name installscript.vdf -print0 2>/dev/null | sort -z | xargs -0 -r awk '
FNR == 1 { depth = 0; name = ""; key = "" }
/^[[:space:]]*\{/ { depth++; next }
/^[[:space:]]*\}/ {
if (depth == 3 && name != "" && key != "")
printf "%s\t%s\n", key, name
depth--
next
}
{
n = split($0, part, "\"")
if (n >= 5 && tolower(part[2]) == "hasrunkey") { key = part[4]; next }
if (n >= 3 && depth == 2) { name = part[2]; key = "" }
}
')
# The client downloads the scripts with the first game that wants them, which is too late for that
# game; until then the set they held when this was written stands in. (WinNative's list.)
[ -n "$pairs" ] || pairs=$(sed 's/^\([^ ]*\) /HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\\1\t/' <<'KNOWN'
DirectX\\Jun2010 dxsetup
.NET\\4.8 4.8
vcredist\\2008 x86 SP1
vcredist\\2008 x64 SP1
vcredist\\2010 x86
vcredist\\2010 x64
vcredist\\2013 x86 12.0.30501
vcredist\\2013 x64 12.0.30501
vcredist\\2015 x86 Update 3 14.0.24215.0
vcredist\\2015 x64 Update 3 14.0.24215.0
vcredist\\2017 x86 14.10.25008.0
vcredist\\2017 x64 14.10.25008.0
vcredist\\2019 x86 14.28.29334.0
vcredist\\2019 x64 14.28.29334.0
vcredist\\2022 x86 14.51.36247.0
vcredist\\2022 x64 14.51.36247.0
KNOWN
)
# The stamp is the set of names, taken before the block below dates its keys: stamped from the
# dated block it never matched, and every prefix had the whole block appended again on every beat.
stamp=$(printf '%s' "$pairs" | cksum)
block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$(date +%s)" '
{
path = $1
sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path)
if (path == $1)
next
printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, $2
# The client writes these from 32-bit steam.exe, so its own copy lands under Wow6432Node;
# both spellings are seeded because the reader picks by its own word size.
sub(/^Software\\\\/, "Software\\\\\\\\Wow6432Node\\\\\\\\", path)
printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, $2
}
')
[ -n "$block" ] || exit 0
# Proton builds a new prefix from its template, and the client runs the install scripts in that
# prefix moments later, so the template carries the markers too. Its date is kept: Proton reads a
# changed one as a new template and upgrades every prefix made from the old.
for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
"$steam_root"/compatibilitytools.d/*/files/share/default_pfx*/system.reg \
"$steam_root"/steamapps/compatdata/*/pfx/system.reg \
/mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg; do
[ -f "$reg" ] || continue
seeded=$(dirname "$reg")/.bannerlator-redists
[ "$(cat "$seeded" 2>/dev/null)" = "$stamp" ] && continue
dated=$(mktemp) || continue
touch -r "$reg" "$dated"
if printf '%s\n' "$block" >>"$reg"; then
printf '%s\n' "$stamp" >"$seeded"
echo "== seeded redist markers into $reg"
fi
touch -r "$dated" "$reg"
rm -f "$dated"
done
@@ -323,9 +323,9 @@ case $mode in
step "adding the app's own games to the client's library"
bannerlator-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
fi
# Steam runs a game's shared redistributables inside its prefix on first launch; marking
# them as already run keeps those x86 installers from starting under emulation at all.
bannerlator-seed-redists "$steam_root" || true
# Undo earlier blanket success markers while Wine is stopped. Steam now installs its
# prerequisites normally; the Proton wrapper handles the old VC MSI bundles quietly.
bannerlator-restore-redists "$steam_root" || true
# The compatibility tool runs Valve's arm64 Proton, which the client fetches like any depot.
# Asked for on the command line the first time, so a Windows title has it before it is needed.
if [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
@@ -397,18 +397,6 @@ case $mode in
# titles are installed: a title installed this session gets the client's own per-app Proton
# choice, which it cannot start. Refresh the per-app entries every so often; the registrar is
# idempotent, so a repeat costs nothing.
# The seeder has the same problem and a worse consequence. It marks the shared redistributables
# as already run in each prefix that exists, and a game's prefix is not created until the
# client launches it - so a title played for the first time this session was never covered, and
# its install scripts run for real. That is exactly the hang the seeder exists to prevent: Need
# for Speed Payback sat on "Running install script" with vcredist_x86.exe blocked in pipe_read,
# holding both ends of a pipe nobody would write to, while the client waited for it to exit.
# Seeding again on the same beat covers a prefix the moment it appears.
# The seeder runs on a shorter beat than the registrar because it is racing something. The
# client creates a prefix when it launches a title and runs that title's install scripts
# moments later, so the seeder has only that gap to mark the redistributables as already run.
# It stamps each prefix it has covered and skips it thereafter, so the extra passes cost
# almost nothing.
# The drawer's "Stretch games to fill the screen" works live: the app writes its choice to
# ~/.droiddeck-fill, and each change goes to gamescope as GAMESCOPE_FORCE_WINDOWS_FULLSCREEN on
# the root window, which it watches. What gamescope was started with is where this begins.
@@ -478,13 +466,8 @@ case $mode in
esac
done
) &
# The library beat. Both helpers are whole programs under proot (the compat one a python
# start and a parse of the client's config), and nearly every beat has nothing new for them.
# The seeder marks Proton's prefix template as well as the prefixes, so a new prefix is born
# marked and every 15 s is soon enough for the rest. The compat pass runs when a directory it
# reads from has changed since its last run - a new manifest, a new depot or tool, the client
# rewriting config.vdf - which [ -nt ] answers without starting anything, and once a minute
# regardless.
# Refresh compatibility registrations when a library or client config changes, and once
# a minute regardless. Prerequisite checks belong to Steam and are not changed on this beat.
(
beat=0
compat_stamp=$HOME/.bl-compat-beat
@@ -502,7 +485,6 @@ case $mode in
nap 5
beat=$((beat + 1))
[ "$((beat % 3))" -eq 0 ] || continue
bannerlator-seed-redists "$steam_root" >/dev/null 2>&1 || true
if compat_due; then
: > "$compat_stamp"
bannerlator-steam-compat "$steam_root" >/dev/null 2>&1 || true