Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

11.3 KB
Raw Blame
#!/bin/zsh
# Game smoke: every verified title that is installed in the Gaming environment must still
# launch, show its window, and keep drawing. The "never regress" gate for games, the way
# render-smoke.sh is for renderers and upgrade-smoke.sh is for the app.
#
# For each entry in GAMES (appid, renderer, window regex, name, optional extra args): restart
# Steam under the row's renderer (a game inherits the running client's renderer), launch, wait
# for a window, then take three captures ten seconds apart and require that they differ (a
# frozen or blank window fails) and that no Wine crash dialog appeared. Records
# private/game-smoke/latest.json {passed, epoch, date, results[]}, which Scripts/release.sh
# reads (warn-only, 14-day window). Captures land in private/game-smoke/.
#
# Titles that are not installed are skipped (reported as "not installed"), so the gate only
# ever measures what this machine has; the release note says what was covered.
#
# Usage: Scripts/game-smoke.sh            (the whole table)
#        Scripts/game-smoke.sh 730 4465480 (only these appids)
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
HB="$ROOT/.build/debug/highball"; [ -x "$HB" ] || swift build --package-path "$ROOT" >/dev/null
H="$HOME/Library/Application Support/Highball"
ST="$H/bottles/Gaming/drive_c/Program Files (x86)/Steam/steamapps"
OUT="$ROOT/private/game-smoke"; mkdir -p "$OUT"
WINLIST="$ROOT/Scripts/winlist"   # CGWindowList helper built by Scripts/build-winlist.sh
[ -x "$WINLIST" ] || { echo "missing $WINLIST (run Scripts/build-winlist.sh)"; exit 2; }

# appid | renderer | window regex | name | extra launch args (map load etc.)
GAMES=(
  "730|dxmt|Counter-Strike 2|cs2|"
  "4465480|dxvk|Counter-Strike: Global|csgo-legacy|-novid +map de_dust2"
  "620|dxvk|PORTAL 2|portal2|"
  "400|dxvk|Portal|portal|"
  "1902490|dxvk|Aperture Desk Job|aperture|"
  "244210|d3dmetal|Assetto|assetto|"
  "230410|dxmt|Warframe|warframe|"
  "3314060|dxvk|Sims|sims|"
  "319510|dxvk|Five Nights|fnaf|"
  # Canary set (2026-09-18): one title per graphics path, all installed here as demos or
  # verified rows, so a renderer or engine change cannot slip through on a path nobody ran.
  # The Last Caretaker demo went black after its first run because its 4K menu video kills a
  # D3DMetal thread through Media Foundation; the the-last-caretaker recipe (mfplat off for the
  # game's exe) fixes it and is applied to canary-r6, so this row guards the recipe. It runs
  # there and not in Gaming: in the long-lived Gaming bottle the demo waits black at idle GPU
  # with no assertion and no deadlock for a reason not found on 2026-09-20, while four runs in
  # fresh clones of Gaming (r5 and r6) show the title. Title is a still, dark picture, so the
  # verdict comes from the GPU fallback below.
  "3916150|d3dmetal|Caretaker|caretaker||canary-r6"
  "1773210|d3dmetal|HumanitZ|humanitz|"
  "3527290|dxvk|PEAK|peak|"
  # DXMT, the default mode, had no canary until 2026-09-19. Umamusume's title screen animates
  # and needs no sign-in (Cygames' EULA accepted once in Steam).
  "3224770|dxmt|Umamusume|umamusume|"
  # A sixth column names a bottle other than Gaming: canary-r6 is a clone of Gaming on the r6
  # engine (D3DMetal from GPTK 4), so an engine revision gets the same guard as the default.
  "1773210|d3dmetal|HumanitZ|humanitz-r6||canary-r6"
  # The Wine 11 engine r11 (2026-09-20) carries two patches nothing else exercises: 0010 (a
  # game's Media Foundation video reaches DXMT as a shared texture) and 0011 (the LastError
  # slot MSVC-built code reads). The Last Flame Prologue is a Unity title whose menu plays such a
  # video under DXMT, so its menu drawing on re-w11 covers both paths; the lasterr probe in the
  # gate covers 0011 more directly. re-w11 is the bottle kept on the newest Wine 11 revision.
  "2517810|dxmt|The Last Flame|lastflame||re-w11"
)
only=("$@")
results=(); passed=true
for row in "${GAMES[@]}"; do
  IFS='|' read -r appid renderer winre name extra bottle <<< "$row"
  bottle=${bottle:-Gaming}
  if [ ${#only[@]} -gt 0 ] && ! printf '%s\n' "${only[@]}" | grep -qxE "$appid|$name"; then continue; fi
  if [ ! -d "$H/bottles/$bottle" ]; then echo "[$name] bottle $bottle absent"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"bottle absent\"}"); continue; fi
  ST="$H/bottles/$bottle/drive_c/Program Files (x86)/Steam/steamapps"
  st=$(grep -E '"StateFlags"' "$ST/appmanifest_$appid.acf" 2>/dev/null | grep -oE '[0-9]+' | tail -1)
  if [ "$st" != "4" ]; then echo "[$name] not installed"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"not installed\"}"); continue; fi
  echo "[$(date +%H:%M:%S)] $name ($appid) under $renderer"
  # Scoped to the row's bottle: a machine-wide Steam kill took down the launcher nightly's own
  # Steam when both ran (2026-09-19).
  $HB bottle kill "$bottle" >/dev/null 2>&1; sleep 3
  ($HB run "$bottle" 'C:\Program Files (x86)\Steam\steam.exe' --renderer $renderer -- -silent > /dev/null 2>&1 &); sleep 35
  # Steam's own log from here on tells a launch Steam held back from one that failed.
  clog="$H/bottles/$bottle/drive_c/Program Files (x86)/Steam/logs/console_log.txt"
  clines=$(wc -l < "$clog" 2>/dev/null | tr -d ' '); clines=${clines:-0}
  ($HB run "$bottle" 'C:\Program Files (x86)\Steam\steam.exe' -- -applaunch $appid $extra > "$OUT/$name.log" 2>&1 &)
  n=0; until "$WINLIST" 2>/dev/null | grep -iE "wine.*($winre)" | grep -q 'on=true' || [ $n -ge 60 ]; do sleep 3; n=$((n+1)); done
  id=$("$WINLIST" 2>/dev/null | grep -iE "wine.*($winre)" | grep on=true | head -1 | awk '{print $1}')
  # The account playing on another computer (the M4, say) makes Steam wait for an answer to
  # end that session before it starts a paid game. Nothing ran then, and the smoke must never
  # answer for the owner, so the row is skipped rather than failed (2026-10-12: The Sims, FNAF
  # and PEAK read as "no window" while the account was in Microsoft Flight Simulator 2024).
  if [ -z "$id" ] && tail -n +$((clines + 1)) "$clog" 2>/dev/null | grep -qE "AppID $appid.*waiting for user response to KickingOtherSession"; then
    echo "  SKIPPED: Steam waits to end this account's session on another computer, nothing ran"
    results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"account busy elsewhere\"}")
  elif [ -z "$id" ]; then echo "  FAIL: no window within $((n*3))s"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"no window\"}"); passed=false
  else
    # Capture three frames ten seconds apart. Prefer the per-window grab, but some games use a
    # layer-hosted (Metal) window that screencapture -l cannot image (it returns nothing/black);
    # fall back to a full-screen shot cropped to the window rect, which works for any window type.
    # Geometry sits in the two fields before "layer=", never at a fixed index: a title with
    # spaces ("Five Nights at Freddy's") shifts the columns and broke the parse on 2026-09-08.
    geo=$("$WINLIST" 2>/dev/null | awk -v id="$id" '$1==id{print $(NF-3), $(NF-2)}')
    gx=${geo%%,*}; rest=${geo#*,}; gy=${rest%% *}; wh=${geo##* }; gw=${wh%%x*}; gh=${wh##*x}
    grab(){ local out="$1"; screencapture -x -l "$id" "$out" 2>/dev/null
      # if the -l grab is missing or ~uniformly black, use full-screen + crop
      if [ ! -s "$out" ] || [ "$(sips -g pixelWidth "$out" 2>/dev/null | awk '/pixelWidth/{print $2}')" = "" ]; then
        screencapture -x "$OUT/.fs.png" 2>/dev/null
        [ -n "$gw" ] && sips --cropOffset $((gy*2)) $((gx*2)) -c $((gh*2)) $((gw*2)) "$OUT/.fs.png" --out "$out" >/dev/null 2>&1
      fi; }
    sleep 40; h=(); for k in 1 2 3; do grab "$OUT/$name-$k.png"; h+=("$(md5 -q "$OUT/$name-$k.png" 2>/dev/null)"); sleep 10; done
    # Only a crash dialog from this row's environment counts. Other sessions run Wine on this Mac
    # too: on 2026-10-06 a dialog from another environment failed The Sims while its three
    # captures showed the game drawing, and the row passed on its own re-run. The dialog's owner
    # (winedbg, started in the crashing program's environment) carries WINEPREFIX; a dialog whose
    # environment cannot be read still counts.
    crash=0
    for cpid in $("$WINLIST" 2>/dev/null | grep -iE 'Program Error|Wine Debugger' | grep on=true | grep -oE 'pid=[0-9]+' | cut -d= -f2); do
      cenv=$(ps -E -p "$cpid" -o command= 2>/dev/null)
      if [[ "$cenv" == *"WINEPREFIX="* && "$cenv" != *"WINEPREFIX=$H/bottles/$bottle "* && "$cenv" != *"WINEPREFIX=$H/bottles/$bottle" ]]; then
        echo "  (a crash dialog from another environment, pid $cpid, not counted)"; continue
      fi
      crash=$((crash + 1))
    done
    if [ "$crash" -gt 0 ]; then echo "  FAIL: crash dialog"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"crash dialog\"}"); passed=false
    elif [ "${h[1]}" = "${h[2]}" ] && [ "${h[2]}" = "${h[3]}" ]; then
      # Identical captures also come from a still picture that is drawn every frame (The Last
      # Caretaker's title, black with one blinking line). The GPU tells those apart: a game whose
      # render thread died sits at 2-5% (its black screen, 2026-09-19), a live one keeps it busy.
      gsum=0; for k in 1 2 3; do g=$(ioreg -r -c AGXAccelerator -d1 2>/dev/null | grep -oE '"Device Utilization %"=[0-9]+' | head -1 | cut -d= -f2); gsum=$((gsum + ${g:-0})); sleep 2; done; gavg=$((gsum/3))
      if [ $gavg -ge 30 ]; then echo "  ok: window after ~$((n*3))s, still picture but drawing (GPU ${gavg}%)"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"ok\",\"windowAfter\":$((n*3)),\"gpu\":$gavg}")
      else echo "  FAIL: window frozen or blank (3 identical captures, GPU ${gavg}%)"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"frozen\",\"gpu\":$gavg}"); passed=false; fi
    else echo "  ok: window after ~$((n*3))s, drawing"; results+=("{\"appid\":$appid,\"name\":\"$name\",\"result\":\"ok\",\"windowAfter\":$((n*3))}"); fi
  fi
  # Games started through Steam show Windows paths in the process list (steamapps\common\...),
  # so both separators must match; with "/" only, The Last Caretaker demo outlived three runs
  # (2026-09-18) and sat fullscreen under everything that followed.
  pkill -9 -f -iE "steamapps[/\\\\]common[/\\\\][^ ]*($winre|$name)" 2>/dev/null; pkill -9 -f winedbg 2>/dev/null; sleep 2
  # kill the game by its window-owning wine process if still up (generic)
  for p in $(ps -axo pid,command | grep -E 'steamapps[/\\\\]common' | grep -vE 'grep|steam\.exe|steamwebhelper|gameoverlayui' | awk '{print $1}'); do kill -9 $p 2>/dev/null; done
done
for b in Gaming canary-r6 re-w11; do $HB bottle kill "$b" >/dev/null 2>&1; done
# Nothing installed is not a pass: say so and exit 3 so Scripts/gate.sh records "skipped".
if ! printf '%s\n' "${results[@]}" | grep -qvE '"(not installed|bottle absent|account busy elsewhere)"'; then
  echo "GAME SMOKE SKIPPED: nothing in the table ran (not installed, or the account busy on another computer)"
  python3 -c "import json,time;json.dump({'passed':False,'skipped':True,'epoch':int(time.time()),'date':time.strftime('%Y-%m-%d'),'results':[]},open('$OUT/latest.json','w'),indent=2)"
  exit 3
fi
python3 - "$OUT/latest.json" "$passed" "$(IFS=,; echo "${results[*]}")" <<'PY'
import json,sys,time
out, passed, res = sys.argv[1], sys.argv[2]=="true", sys.argv[3]
json.dump({"passed": passed, "epoch": int(time.time()), "date": time.strftime("%Y-%m-%d"),
           "engine": "shipped", "results": json.loads("["+res+"]")}, open(out,"w"), indent=2)
print("GAME SMOKE", "PASSED" if passed else "FAILED", "->", out)
PY
$passed