#!/usr/bin/env bash # Boot -> first title -> main menu -> OPTIONS, and capture the UI draw order # there. OPTIONS is the fourth menu item, so: three d-pad steps down, then (A). # # The recipe for the first two hops is measured, not guessed (see # docs/re/canary-scripted-input-traps.md): the title that ENDS THE BOOT accepts a # single (A); the one the attract loop returns to accepts nothing. So never tap # during the boot, and take the first title. set -u export HOME=/sylph-home/re SDL_AUDIODRIVER=dummy DISPLAY=:98 SD="$(cd "$(dirname "$0")" && pwd)" OUT="${1:-/sylph-home/re/optcap}" mkdir -p "$OUT"; rm -f "$OUT"/xenia_re_ui_draws_*.log shot(){ screenshot "$1" >/dev/null 2>&1; } screen(){ shot /tmp/odc.png; python3 "$SD/screen_id.py" /tmp/odc.png | awk '{print $1}'; } alive(){ ps -o pid=,stat= -C xenia_canary 2>/dev/null | awk '$2 !~ /^Z/ {print $1}'; } # No capture flags at launch: F10 arms the capture unconditionally now, and # launching with --log_ui_draws correlated (0 of 7) with the title refusing (A). ( cd "$OUT" && nohup run-canary --mem_watch=false \ --logged_profile_slot_0_xuid=B13EBABEBABEBABE \ >"$OUT/canary.stdout" 2>"$OUT/canary.stderr" & ) sleep 8 until xdotool search --name "Xenia-canary" >/dev/null 2>&1; do [ -n "$(alive)" ] || { echo "EMULATOR GONE"; exit 4; }; sleep 1 done win="$(xdotool search --name "Xenia-canary" | tail -1)" deadline=$(( SECONDS + 420 )) while [ $SECONDS -lt $deadline ]; do s="$(screen)"; echo "t=${SECONDS}s $s" [ "$s" = "title" ] && break sleep 1 done [ "$s" = "title" ] || { echo "NO BOOT TITLE"; exit 1; } echo "-> A on the boot title" python3 "$SD/pad.py" tap A 0.3 for _ in 1 2 3 4 5 6 7 8; do sleep 3; s="$(screen)"; echo " $s"; [ "$s" = "menu" ] && break; done shot "$OUT/menu.png" [ "$s" = "menu" ] || { echo "NO MENU (screen=$s)"; exit 2; } echo "-> three d-pad steps down, then A (OPTIONS is the 4th item)" for i in 1 2 3; do python3 "$SD/pad.py" dpad down 0.08; sleep 1.2; done shot "$OUT/menu-on-options.png" python3 "$SD/pad.py" tap A 0.3 sleep 8 shot "$OUT/options.png" echo "screen after A: $(screen)" xdotool windowactivate --sync "$win"; sleep 1 xdotool key F10; sleep 3 xdotool mousemove 900 400 click 1; sleep 2 shot "$OUT/options-armed.png" ls -l "$OUT"/xenia_re_ui_draws_*.log 2>/dev/null || echo "NO CAPTURE LOG" grep -i "UI-CAP" "$OUT/canary.stdout" | tail -3 echo "OPTIONS CAPTURE DONE (emulator left running)"