// Looking at Setup and driving it without a screen (nothing here runs for a player): // --snapshot every page and state drawn to a PNG with sample values, then exit // TRIFORCE_UI_SCRIPT= a list of steps (wait for a page, click a button, type a path, take a picture or a run of // pictures to look at motion) run against the // real flows in an off-screen window; it carries on in the Setup that an install or a self-update // starts (the place in the list is kept beside the file). Pictures and script.log go to // TRIFORCE_UI_SHOTS. Used with TRIFORCE_TEST_ROOT (Setup.cs), which keeps the install in one folder. // TRIFORCE_SOUND_LOG= such a run makes no sound; with this, each sound a player's Setup would have played is a line // in that file (Sound.cs NotedPlayer) using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; namespace TriforceSetup; sealed partial class Shell { /// The window's picture as it is now RenderTargetBitmap Picture(double scale) { var rtb = new RenderTargetBitmap((int)(Root.ActualWidth * scale), (int)(Root.ActualHeight * scale), 96 * scale, 96 * scale, PixelFormats.Pbgra32); var v = new DrawingVisual(); using (var dc = v.RenderOpen()) dc.DrawRectangle(Window.Background, null, new Rect(0, 0, Root.ActualWidth, Root.ActualHeight)); rtb.Render(v); rtb.Render(Root); rtb.Freeze(); return rtb; } static void SavePicture(BitmapSource picture, string dir, string name) { var enc = new PngBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(picture)); using var f = File.Create(System.IO.Path.Combine(dir, name + ".png")); enc.Save(f); } async Task Shot(string dir, string name, int settle = 150) { await Window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle); await Task.Delay(settle); SavePicture(Picture(1.5), dir, name); } /// --snapshot : every page and every state that looks different, with sample values (nothing of this PC in them) async void Snapshots(string dir) { try { Directory.CreateDirectory(dir); Part("WindowEdge").Visibility = Visibility.Visible; const string game = @"C:\Users\you\Games\Triforce"; lang = Strings.All[0]; LanguageBox.SelectedItem = lang; InstallPath.Text = @"C:\Users\you\AppData\Local\Programs\Triforce"; InstallSpace.Text = @"Setup and its tools take about 2 GB. C:\ has 212 GB free."; Show(InstallPage); await Shot(dir, "01-install"); Show(FetchPage); stage.All(false); FetchUnknown(true); FetchState("Gathering the stones", "Asking for the newest Triforce.", "Checking for updates"); FetchCancel.Content = "Cancel"; await Shot(dir, "02-gather-checking"); FetchState("Gathering the stones", "Downloading the Triforce tools (264 MB), once. Updates come the same way.", "Downloading the tools"); stage.Set(Art.Emerald, true); stage.Set(Art.Sapphire, true); stage.Charge(Art.Ruby, 0.62 * 0.7); FetchProgress(0.62, "164 / 264 MB"); await Shot(dir, "03-gather-download"); stage.All(false); FetchUnknown(false); FetchTitle.Text = "The Triforce site could not be reached"; FetchNote.Text = "Check your internet connection, then try again."; FetchNote.Foreground = Brush("Bad"); FetchStep.Text = ""; FetchRetry.Visibility = FetchSkip.Visibility = Visibility.Visible; FetchCancel.Content = "Close"; await Shot(dir, "04-gather-failed"); FetchRetry.Visibility = FetchSkip.Visibility = Visibility.Collapsed; // welcome back: ready, an update, nothing built yet, no answer from GitHub HomeFill(true, "Triforce v1.1.0", game, "v1.1.0", "v1.1.0", false, null); SavesLineFill(true, "6 save slots", "Last played 8 Nov 2026, 02:46"); Show(HomePage); await Shot(dir, "05-home-ready"); // (the gleam held at seven places on its way across, in gleam\: the same page, so each differs from 05-home-ready // only by the band, which must lie on the crest's own pixels and nowhere else) Directory.CreateDirectory(System.IO.Path.Combine(dir, "gleam")); foreach (var at in new[] { 5, 20, 35, 50, 65, 80, 95 }) { stage.GleamAt(at / 100.0); await Shot(System.IO.Path.Combine(dir, "gleam"), "home-gleam-" + at.ToString("00")); } stage.GleamAt(-1); // (and the ring of marks an eighth of a turn on: the fine ring inside it must not change at all) stage.TurnMarks(45); await Shot(System.IO.Path.Combine(dir, "gleam"), "arc-marks-turned-45"); stage.TurnMarks(0); HomeFill(true, "Triforce v1.0.0", game, "v1.0.0", "v1.1.0", true, null); await Shot(dir, "06-home-update"); HomeFill(false, null, null, null, "v1.1.0", false, null); SavesLineFill(null, "None yet", "They can come in from an emulator once your game is built."); await Shot(dir, "07-home-no-game"); HomeFill(true, "Triforce v1.1.0", game, "v1.1.0", "v1.1.0", false, new System.Net.Http.HttpRequestException("offline")); SavesLineFill(false, "No saves yet", "Bring them in, or start a new game."); await Shot(dir, "08-home-offline"); // the forge: nothing chosen yet, a checked file with a game to update, folders with the wrong version OutPath.Text = game; Show(SetupPage); checkDelay.Stop(); Say(T(S.DropHint), "TextDim", null); SpaceText.Text = T(S.Needs) + " " + string.Format(T(S.Free), @"C:\", 212); await Shot(dir, "09-forge"); UpdateBanner.Visibility = Visibility.Visible; UpdateText.Text = "Your game in " + game + " is Triforce v1.0.0. Version v1.1.0 is ready: updating keeps your saves and settings."; NupPath.Text = @"D:\Games\OcarinaOfTime.nup"; checkDelay.Stop(); Say(T(S.VersionOk), "Good", "Good"); BuildButton.IsEnabled = true; SpaceText.Text = T(S.Needs) + " " + string.Format(T(S.Free), @"C:\", 212); await Shot(dir, "10-forge-checked"); UpdateBanner.Visibility = Visibility.Collapsed; UseFolders.IsChecked = true; RomfsPath.Text = @"D:\Games\OcarinaOfTime\romfs"; ExefsPath.Text = @"D:\Games\OcarinaOfTime\exefs"; checkDelay.Stop(); Say(T(S.VersionBad), "Bad", "Bad"); BuildButton.IsEnabled = false; SpaceText.Text = T(S.Needs) + " " + string.Format(T(S.Free), @"C:\", 212); await Shot(dir, "11-forge-folders"); foreach (var code in new[] { "de", "ja" }) { lang = Strings.All.First(l => l.Code == code); LanguageBox.SelectedItem = lang; checkDelay.Stop(); Say(T(S.VersionBad), "Bad", "Bad"); SpaceText.Text = T(S.Needs) + " " + string.Format(T(S.Free), @"C:\", 212); await Shot(dir, "12-forge-" + code); } lang = Strings.All[0]; LanguageBox.SelectedItem = lang; checkDelay.Stop(); UseNup.IsChecked = true; checkDelay.Stop(); // building: a step running, its details, done, stopped, and the question when closing Show(BuildPage); stage.All(false); BuildTitle.Text = T(S.Building); BuildNote.Text = T(S.Patience) + " " + T(S.Elapsed) + ": 14 min"; rows["read"].Done(); rows["lift"].Done(); rows["compile"].Begin(); rows["compile"].Progress(0.41); SetButtons(cancel: true); await Shot(dir, "13-build"); Log.Text = string.Join("\n", new[] { "@@stage read", "reading D:\\Games\\OcarinaOfTime.nup", "program 0400486024DEC000, update v131072, build e0f3ccfa", "romfs: 18,412 files, 11.6 GB", "@@stage lift", "lifting 14,134 functions in 96 pieces", "lift done in 222 s", "@@stage compile", "[ 312/ 760] clang -O2 -c sa/gen/code_038.c -o sa/build/code_038.o", "[ 313/ 760] clang -O2 -c sa/gen/code_039.c -o sa/build/code_039.o", "[ 314/ 760] clang -O2 -c sa/gen/code_040.c -o sa/build/code_040.o", "[ 315/ 760] clang -O2 -c sa/gen/code_041.c -o sa/build/code_041.o", }); ShowLog.IsChecked = true; await Shot(dir, "14-build-details"); ShowLog.IsChecked = false; Ask(T(S.CloseQuestion), T(S.StopClose), T(S.KeepBuilding), () => { }); await Shot(dir, "15-build-ask-close"); HideAsk(); foreach (var r in rows.Values) r.Done(); stage.All(true); BuildEyebrow.Label = "IV · Play"; BuildTitle.Text = T(S.Ready); BuildNote.Text = game + " · " + T(S.BuiltIn) + " 38 min"; SetButtons(done: true); await Shot(dir, "16-build-done"); foreach (var r in rows.Values) r.Reset(); stage.All(false); BuildEyebrow.Label = "III · Forge"; rows["read"].Done(); rows["lift"].Done(); rows["compile"].Begin(); rows["compile"].Stopped(); BuildTitle.Text = T(S.Stopped); BuildNote.Text = "The compiler stopped at sa/gen/code_041.c (exit code 1). See the details."; BuildNote.Foreground = Brush("Bad"); SetButtons(back: true, report: true); await Shot(dir, "17-build-stopped"); BuildNote.Foreground = Brush("Text"); // convert saves: what was found, and nothing found Show(SavesPage); found = new List { new() { Name = "Eden", Folder = @"C:\Users\you\AppData\Roaming\eden\nand\user\save\0000000000000000\1401D3E59D96EFFB99D2488BA99C6EBE\" + Saves.TitleId, Slots = 6, Last = new DateTime(2026, 11, 9, 6, 19, 0) }, new() { Name = "Ryujinx", Folder = @"C:\Users\you\AppData\Roaming\Ryujinx\bis\user\save\0000000000000003\0", Slots = 3, Last = new DateTime(2026, 10, 30, 21, 20, 0) }, new() { Name = @"yuzu (D:\Emulators\yuzu)", Folder = @"D:\Emulators\yuzu\user\nand\user\save\0000000000000000\8A1C0F6E27B94D13A5E07C2B9F3D6E41\" + Saves.TitleId, Slots = 1, Last = new DateTime(2026, 6, 2, 18, 5, 0) }, }; SavesListLabel.Label = "Take the saves from"; ShowSaveList(); SavesInfo.Text = "Triforce's saves become Eden's (6 slots, last played 9 Nov 2026). Triforce's current saves (6 slots, last played 8 Nov 2026) are backed up first."; SavesInfo.Foreground = Brush("Text"); SavesTarget.Text = @"Into " + game + @"\user\save\" + Saves.TriforceUid; SavesGo.IsEnabled = true; await Shot(dir, "18-saves"); found = new List(); ShowSaveList(); SavesOut.IsChecked = true; await Window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle); SaveList.ItemsSource = null; SavesListLabel.Label = "Put Triforce's saves into"; SavesInfo.Text = "No emulator saves of this game were found. Use Choose a folder to point at the emulator's save folder for this game (0400486024DEC000)."; SavesInfo.Foreground = Brush("Text"); SavesTarget.Text = ""; SavesGo.IsEnabled = false; await Shot(dir, "19-saves-none"); // mods: a list with mods that share files, one off, one whose code waits for a build; and none yet Mod Sample(string folder, int files, int patches, int cheats, params string[] shared) { var (off, number, name) = Mods.Parse(folder); var m = new Mod { Path = game + @"\mods\" + folder, Rel = folder, Top = folder, Folder = folder, Name = name, Number = number, On = !off, Patches = patches, Cheats = cheats }; m.Files.AddRange(shared); for (var i = shared.Length; i < files; i++) m.Files.Add(folder.ToLowerInvariant() + "/" + i); return m; } var sample = new List { Sample("01-Clearer water", 38, 0, 0), Sample("02-Greener fields", 1204, 0, 0, "pack/actor/grass.pack.zs", "pack/actor/tree.pack.zs"), Sample("03-Tall grass", 212, 0, 0, "pack/actor/grass.pack.zs", "pack/actor/tree.pack.zs"), Sample("-04-Night sky", 16, 0, 0), Sample("05-Sixty frames", 0, 2, 1), }; Show(ModsPage); ModsFill(sample, sample[2].Path, null); ModsInfo.Text = ModWords(sample[2]); ModsBuild.Visibility = Visibility.Visible; await Shot(dir, "20-mods"); ModsFill(sample, sample[4].Path, "Sixty frames was added: 2 code patch files, 1 cheat file. Its code patches and cheats take effect once the game is built again."); ModsBuild.Visibility = Visibility.Visible; await Shot(dir, "21-mods-added"); ModsFill(new List(), null, @"No mods yet. Add a mod takes a .zip, .7z or .rar file; or put a mod's folder (the one that holds romfs) into " + game + @"\mods yourself."); await Shot(dir, "22-mods-none"); ModsFill(sample, sample[0].Path, "The archive holds a path that leaves its own folder (..): \"../../Windows/evil.dll\". Nothing was unpacked.", true); await Shot(dir, "23-mods-refused"); // Add to Steam: the question, and Steam running HomeFill(true, "Triforce v1.1.0", game, "v1.1.0", "v1.1.0", false, null); Show(HomePage); Ask("Add Triforce to Link's Steam library? Steam then starts the game itself, without Setup.", "Add to Steam", T(S.Back), () => { }); await Shot(dir, "24-steam-ask"); HideAsk(); Tell(Steam.CloseFirst); await Shot(dir, "25-steam-close-first"); HideAsk(); // (and the shortcut's pictures as they would be written into Steam's grid folder, in steam\: drawn, never fetched) Directory.CreateDirectory(System.IO.Path.Combine(dir, "steam")); foreach (var picture in SteamArt.Make()) File.WriteAllBytes(System.IO.Path.Combine(dir, "steam", picture.Key + ".png"), picture.Value); } catch (Exception e) { File.WriteAllText(System.IO.Path.Combine(dir, "error.txt"), e.ToString()); } Window.Close(); } // ---- TRIFORCE_UI_SCRIPT ---- string? scriptFile, scriptShots; /// A script to follow (testing)? Then the window stays off the screen and the steps start once it is up bool Scripted() { scriptFile = Environment.GetEnvironmentVariable("TRIFORCE_UI_SCRIPT"); if (string.IsNullOrEmpty(scriptFile) || !File.Exists(scriptFile)) return false; scriptShots = Environment.GetEnvironmentVariable("TRIFORCE_UI_SHOTS") is { Length: > 0 } s ? s : System.IO.Path.GetDirectoryName(scriptFile)!; Directory.CreateDirectory(scriptShots); Window.WindowStartupLocation = WindowStartupLocation.Manual; Window.Left = -20000; Window.ShowActivated = false; Window.ShowInTaskbar = false; return true; } void ScriptLog(string line) { try { File.AppendAllText(System.IO.Path.Combine(scriptShots!, "script.log"), DateTime.Now.ToString("HH:mm:ss.fff") + " " + line + Environment.NewLine); } catch (Exception) { } } async void RunScript() { var steps = File.ReadAllLines(scriptFile!); var place = scriptFile + ".pos"; var at = File.Exists(place) && int.TryParse(File.ReadAllText(place).Trim(), out var p) ? p : 0; ScriptLog("-- Setup " + Program.Version + " (" + Install.Self + ") from step " + at + "; window " + Window.ActualWidth + " x " + Window.ActualHeight + ", inside " + Part("Host").ActualWidth + " x " + Part("Host").ActualHeight + ", picture " + Root.ActualWidth + " x " + Root.ActualHeight + ", Windows' answer about the edge colour 0x" + edgeAnswer.ToString("X8") + " (" + edgeNote + ")"); try { for (; at < steps.Length; at++) { var line = steps[at].Trim(); var cut = line.Split(new[] { ' ' }, 3); var waits = cut[0] == "wait" || cut[0] == "enabled" || cut[0] == "gone"; if (!waits) File.WriteAllText(place, (at + 1).ToString()); if (line.Length == 0 || line.StartsWith("#")) continue; string a = cut.Length > 1 ? cut[1] : "", b = cut.Length > 2 ? cut[2] : ""; switch (cut[0]) { case "wait": // wait [seconds] await Until(() => Part(a).Visibility == Visibility.Visible, b, line); break; case "enabled": // enabled [seconds] await Until(() => Part(a) is { IsEnabled: true, IsVisible: true }, b, line); break; case "gone": // gone [seconds] await Until(() => Part(a).Visibility != Visibility.Visible, b, line); break; case "click": var c = Part(a); if (!c.IsVisible || !c.IsEnabled) throw new InvalidOperationException(a + " cannot be clicked (visible " + c.IsVisible + ", enabled " + c.IsEnabled + ")"); if (c is ToggleButton t && c is not RadioButton) t.IsChecked = t.IsChecked != true; else if (c is RadioButton r) r.IsChecked = true; if (c is ButtonBase) c.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); break; case "text": Part(a).Text = b; break; case "pick": FolderPicker.Answers.Enqueue(a + (b.Length > 0 ? " " + b : "")); break; case "select": SaveList.SelectedIndex = int.Parse(a); break; case "mod": ModList.SelectedIndex = int.Parse(a); break; // mod : the mod picked on the Mods page (pick : the archive Add a mod takes) case "sleep": await Task.Delay(int.Parse(a)); break; case "shot": await Shot(scriptShots!, a, 700); break; case "frames": // frames : what is on screen now and at each step after (to look at motion) case "crest": // crest : the same, but only the crest and its surroundings, at full size var f = b.Split(' '); var run = new List<(double at, BitmapSource picture)>(); var watch = System.Diagnostics.Stopwatch.StartNew(); for (var n = 0; n < int.Parse(f[0]); n++) { if (n > 0) await Task.Delay(int.Parse(f[1])); BitmapSource now = cut[0] == "frames" ? Picture(0.75) : new CroppedBitmap(Picture(1.5), new Int32Rect(960, 144, 615, 576)); now.Freeze(); run.Add((watch.Elapsed.TotalMilliseconds, now)); } // (saved afterwards: writing a picture takes longer than the motion lasts) for (var n = 0; n < run.Count; n++) SavePicture(run[n].picture, scriptShots!, a + "-" + n.ToString("00") + "-" + (int)run[n].at + "ms"); break; case "sheen": // sheen
: the light that crosses a gold button under the mouse, held at x (no mouse here) var gold = Part