Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Optimize launch speed: fast prefix reuse, bridge staging check, and icon caching
Sharad Mayank Sinha024b84a40fad
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 6ef0a35..f0be837 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -291,23 +291,48 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenstage_step="prefix arch check"refuse_foreign_prefixecho "sync: WINEMSYNC=$WINEMSYNC from $msync_from" >> "$log" 2>&1 || true+ setup_marker="$WINEPREFIX/.notproton_setup_v1"+ retina_marker="$WINEPREFIX/.notproton_retina"+ current_retina="${NOTPROTON_RETINA:-0}"+"$WINESERVER" -k >> "$log" 2>&1 || true- stage_step="profile layout"- lay_out_proton_profile- "$WINELOADER" wineboot --init >> "$log" 2>&1 || true- "$WINELOADER" reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug' /v Auto /t REG_SZ /d 0 /f >> "$log" 2>&1 || true- "$WINELOADER" reg add 'HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug' /v Auto /t REG_SZ /d 0 /f >> "$log" 2>&1 || true- "$WINELOADER" reg add 'HKCU\Software\Wine\WineDbg' /v ShowCrashDialog /t REG_DWORD /d 0 /f >> "$log" 2>&1 || true-- echo "video: RetinaMode=${NOTPROTON_RETINA:-0}" >> "$log" 2>&1 || true- if [ "$NOTPROTON_RETINA" = "1" ]; then- "$WINELOADER" reg add 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /t REG_SZ /d y /f >> "$log" 2>&1 || true+ if [ ! -f "$setup_marker" ]; then+ echo "=== first-time prefix initialization ===" >> "$log" 2>&1 || true+ stage_step="profile layout"+ lay_out_proton_profile+ init_ok=1+ "$WINELOADER" wineboot --init >> "$log" 2>&1 || init_ok=0+ "$WINELOADER" reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug' /v Auto /t REG_SZ /d 0 /f >> "$log" 2>&1 || init_ok=0+ "$WINELOADER" reg add 'HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug' /v Auto /t REG_SZ /d 0 /f >> "$log" 2>&1 || init_ok=0+ "$WINELOADER" reg add 'HKCU\Software\Wine\WineDbg' /v ShowCrashDialog /t REG_DWORD /d 0 /f >> "$log" 2>&1 || init_ok=0++ echo "video: RetinaMode=${NOTPROTON_RETINA:-0}" >> "$log" 2>&1 || true+ if [ "$NOTPROTON_RETINA" = "1" ]; then+ "$WINELOADER" reg add 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /t REG_SZ /d y /f >> "$log" 2>&1 || init_ok=0+ else+ "$WINELOADER" reg delete 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /f >> "$log" 2>&1 || true+ fi+ printf '%s' "$current_retina" > "$retina_marker" 2>/dev/null || true++ "$WINELOADER" reg add 'HKLM\Software\Classes\steam' /v 'URL Protocol' /t REG_SZ /d '' /f >> "$log" 2>&1 || init_ok=0+ "$WINELOADER" reg add 'HKLM\Software\Classes\steam\shell\open\command' /ve /t REG_SZ /d '"C:\Program Files (x86)\Steam\steam.exe" "%1"' /f >> "$log" 2>&1 || init_ok=0+ if [ "$init_ok" = 1 ]; then+ : > "$setup_marker" 2>/dev/null || true+ else+ echo "=== prefix initialization failed, will retry on next launch ===" >> "$log" 2>&1 || true+ fielse- "$WINELOADER" reg delete 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /f >> "$log" 2>&1 || true+ echo "=== fast prefix reuse (skipped wineboot and static reg add) ===" >> "$log" 2>&1 || true+ if [ ! -f "$retina_marker" ] || [ "$(cat "$retina_marker" 2>/dev/null)" != "$current_retina" ]; then+ echo "video: RetinaMode updating to ${NOTPROTON_RETINA:-0}" >> "$log" 2>&1 || true+ if [ "$NOTPROTON_RETINA" = "1" ]; then+ "$WINELOADER" reg add 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /t REG_SZ /d y /f >> "$log" 2>&1 || true+ else+ "$WINELOADER" reg delete 'HKCU\Software\Wine\Mac Driver' /v RetinaMode /f >> "$log" 2>&1 || true+ fi+ printf '%s' "$current_retina" > "$retina_marker" 2>/dev/null || true+ fifi-- "$WINELOADER" reg add 'HKLM\Software\Classes\steam' /v 'URL Protocol' /t REG_SZ /d '' /f >> "$log" 2>&1 || true- "$WINELOADER" reg add 'HKLM\Software\Classes\steam\shell\open\command' /ve /t REG_SZ /d '"C:\Program Files (x86)\Steam\steam.exe" "%1"' /f >> "$log" 2>&1 || truefibridge_src="$HOME/Library/Application Support/notproton/bridge"@@ -392,8 +417,11 @@ if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; thenecho "=== bridge missing $f ===" >> "$log" 2>&1 || truecontinuefi- cp -f "$src" "$prefix_steam/$f" || \- echo "=== failed to stage $f ===" >> "$log" 2>&1+ dst="$prefix_steam/$f"+ if [ ! -f "$dst" ] || ! cmp -s "$src" "$dst"; then+ cp -f "$src" "$dst" || \+ echo "=== failed to stage $f ===" >> "$log" 2>&1+ fidonefor f in "$prefix_steam"/*.dll "$prefix_steam"/*.so "$prefix_steam"/*.exe; do[ -f "$f" ] || continue@@ -468,13 +496,12 @@ game_name_xml=$(printf '%s' "$game_name" | sed -e 's/&/\&/g' -e 's/</\</gloader_root="$HOME/Library/Application Support/notproton/launchers/$app_id"mkdir -p "$loader_root"loader_app="$loader_root/$bundle_name.app"-rm -rf "$loader_root"/*.apploader_contents="$loader_app/Contents"loader_macos="$loader_contents/MacOS"loader_res="$loader_contents/Resources"-mkdir -p "$loader_macos" "$loader_res"icon_arg=""+icon_cache="$loader_root/game.icns"resolve_icon() {set +eiconmaker="$HOME/Library/Application Support/notproton/iconmaker"@@ -483,23 +510,26 @@ resolve_icon() {if [ -n "$meta_clienticon" ]; thenico="$loader_root/clienticon-$meta_clienticon.ico"absent="$loader_root/clienticon-$meta_clienticon.absent"- find "$loader_root" -maxdepth 1 -name 'clienticon-*' ! -name "clienticon-$meta_clienticon.*" -delete 2>/dev/null || true+ find "$loader_root" -maxdepth 1 -name 'clienticon-*' ! -name "clienticon-$meta_clienticon.*" -delete 2>/dev/null || truefind "$absent" -mtime +14 -delete 2>/dev/null || trueif [ ! -s "$ico" ] && [ ! -f "$absent" ]; thenurl="https://shared.fastly.steamstatic.com/community_assets/images/apps/$app_id/$meta_clienticon.ico"- code=$(curl -fsL --connect-timeout 5 --max-time 20 -w '%{http_code}' -o "$ico.new" "$url" 2>>"$log")+ code=$(curl -sL --connect-timeout 3 --max-time 8 -w '%{http_code}' -o "$ico.new" "$url" 2>>"$log" || echo "none")magic=$(od -An -tx1 -N4 "$ico.new" 2>/dev/null | tr -d ' \n')if [ "$magic" = "00000100" ]; thenmv -f "$ico.new" "$ico"echo "fetched client icon $meta_clienticon" >> "$log" 2>&1 || trueelserm -f "$ico.new"- if [ "$code" = "404" ]; then- : > "$absent"- echo "no client icon published for $meta_clienticon" >> "$log" 2>&1 || true- else- echo "client icon fetch for $meta_clienticon failed (http ${code:-none}), will retry" >> "$log" 2>&1 || true- fi+ case "$code" in+ *404*)+ : > "$absent"+ echo "no client icon published for $meta_clienticon" >> "$log" 2>&1 || true+ ;;+ *)+ echo "client icon fetch for $meta_clienticon skipped or timed out, will retry" >> "$log" 2>&1 || true+ ;;+ esacfifi[ -s "$ico" ] && art="$ico"@@ -508,7 +538,7 @@ resolve_icon() {art="$art_dir/$meta_icon.jpg"fiif [ -z "$art" ]; then- art=$(find "$art_dir" -maxdepth 1 -type f -name '*.jpg' 2>/dev/null | grep -E '/[0-9a-f]{40}\.jpg$' | head -1)+ art=$(find "$art_dir" -maxdepth 1 -type f -name '*.jpg' 2>/dev/null | grep -E '/[0-9a-f]{40}\.jpg$' | head -1)fi# Capsule art (horrible) fallback if no icon at all exists...if [ -z "$art" ]; then@@ -528,12 +558,11 @@ resolve_icon() {if [ -n "$art" ]; thenicon_source="$art $(stat -f %m "$art" 2>/dev/null || echo 0)"fi- icon_cache="$loader_root/game.icns"- if [ -n "$art" ] && [ -s "$icon_cache" ] && [ "$(cat "$loader_root/notproton-icon.source" 2>/dev/null)" = "$icon_source" ] && cp -f "$icon_cache" "$loader_res/game.icns"; then+ if [ -n "$art" ] && [ -s "$icon_cache" ] && [ "$(cat "$loader_root/notproton-icon.source" 2>/dev/null)" = "$icon_source" ]; thenicon_arg=" <key>CFBundleIconFile</key><string>game</string>"echo "icon reused from $art" >> "$log" 2>&1 || trueelif [ -n "$art" ] && [ -x "$iconmaker" ]; then- if "$iconmaker" "$art" "$icon_cache" >> "$log" 2>&1 && cp -f "$icon_cache" "$loader_res/game.icns"; then+ if "$iconmaker" "$art" "$icon_cache" >> "$log" 2>&1; thenicon_arg=" <key>CFBundleIconFile</key><string>game</string>"printf '%s\n' "$icon_source" > "$loader_root/notproton-icon.source"echo "icon built from $art" >> "$log" 2>&1 || true@@ -555,6 +584,33 @@ if [ "${NOTPROTON_HIDE_LAUNCHER_TILE:-0}" = "1" ]; thenuielement_arg=" <key>LSUIElement</key><true/>"echo "launcher tile hidden by NOTPROTON_HIDE_LAUNCHER_TILE" >> "$log" 2>&1 || truefi++# Bump when the Info.plist or launcher templates below change+bundle_template_ver=1+bundle_needs_build=0+if [ ! -d "$loader_app" ] || [ ! -x "$loader_macos/launcher" ] || [ ! -f "$loader_contents/Info.plist" ] || [ ! -e "$loader_macos/wine" ]; then+ bundle_needs_build=1+elif [ ! -f "$loader_root/.notproton-bundle-ver" ] || [ "$(cat "$loader_root/.notproton-bundle-ver" 2>/dev/null)" != "$bundle_template_ver" ]; then+ bundle_needs_build=1+elif ! cmp -s "$WINELOADER" "$loader_macos/wine" 2>/dev/null; then+ bundle_needs_build=1+else+ plist_has_icon=$(grep -q '<key>CFBundleIconFile</key>' "$loader_contents/Info.plist" 2>/dev/null && echo 1 || echo 0)+ want_icon=$([ -n "$icon_arg" ] && echo 1 || echo 0)+ plist_has_ui=$(grep -q '<key>LSUIElement</key>' "$loader_contents/Info.plist" 2>/dev/null && echo 1 || echo 0)+ want_ui=$([ "${NOTPROTON_HIDE_LAUNCHER_TILE:-0}" = "1" ] && echo 1 || echo 0)+ if [ "$plist_has_icon" != "$want_icon" ] || [ "$plist_has_ui" != "$want_ui" ]; then+ bundle_needs_build=1+ fi+fi++needs_lsregister="$bundle_needs_build"+if [ "$bundle_needs_build" = 1 ]; then+ rm -rf "$loader_root"/*.app+ mkdir -p "$loader_macos" "$loader_res"+ printf '%s\n' "$bundle_template_ver" > "$loader_root/.notproton-bundle-ver" 2>/dev/null || true+ [ -s "$icon_cache" ] && cp -f "$icon_cache" "$loader_res/game.icns" 2>/dev/null || true+# Bump bundle_template_ver above when modifying this templatecat > "$loader_contents/Info.plist" <<PLIST<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">@@ -592,6 +648,7 @@ elseecho "loader staging failed, game mode unavailable" >> "$log" 2>&1 || truefi+# Bump bundle_template_ver above when modifying this templatecat > "$loader_macos/launcher" <<LAUNCHER#!/bin/shexport WINELOADER="$WINELOADER"@@ -611,6 +668,22 @@ fiexit \$?LAUNCHERchmod +x "$loader_macos/launcher"+else+ WINELOADER="$loader_macos/wine"+ echo "reusing existing staged bundle (skipped rebuild and lsregister)" >> "$log" 2>&1 || true+ for f in "$wine_unix"/*; do+ [ -e "$f" ] || continue+ base=${f##*/}+ case "$base" in+ wine|wine.app) continue ;;+ esac+ ln -sfn "$f" "$loader_macos/$base" 2>/dev/null || true+ done+ if [ -s "$icon_cache" ] && ! cmp -s "$icon_cache" "$loader_res/game.icns" 2>/dev/null; then+ cp -f "$icon_cache" "$loader_res/game.icns" 2>/dev/null || true+ needs_lsregister=1+ fi+fiwine_helpers='winedevice\.exe|services\.exe|plugplay\.exe|svchost\.exe'wine_helpers="$wine_helpers|rpcss\.exe|explorer\.exe|steam\.exe"@@ -704,9 +777,11 @@ set -- \--env STEAM_COMPAT_APP_ID="$STEAM_COMPAT_APP_ID" \--env STEAM_DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" \--env NOTPROTON_GAME_CWD="$game_cwd" "$@"-lsregister="/System/Library/Frameworks/CoreServices.framework/Versions/A"-lsregister="$lsregister/Frameworks/LaunchServices.framework/Support/lsregister"-[ -x "$lsregister" ] && "$lsregister" -f "$loader_app" >> "$log" 2>&1 || true+if [ "$needs_lsregister" = 1 ]; then+ lsregister="/System/Library/Frameworks/CoreServices.framework/Versions/A"+ lsregister="$lsregister/Frameworks/LaunchServices.framework/Support/lsregister"+ [ -x "$lsregister" ] && "$lsregister" -f "$loader_app" >> "$log" 2>&1 || true+fiopen -n -W -a "$loader_app" "$@" >> "$log" 2>&1 &open_pid=$!status=0diff --git a/dylib/tests/anchorcheck.c b/dylib/tests/anchorcheck.cindex e7a44c7..d989b9c 100644--- a/dylib/tests/anchorcheck.c+++ b/dylib/tests/anchorcheck.c@@ -330,7 +330,7 @@ static int report_db(const dbcheck_t *db, int is_live) {else if (!r->anchor) { verdict = (r->has_pattern && r->aob)? "ANCHOR FAILED (aob resolves)": "ANCHOR FAILED";- if (is_live) bad++; }+ bad++; }else if (!is_live) { verdict = (r->has_pattern && r->aob && r->aob != r->anchor)? "stale pattern hit elsewhere": "resolved"; }