@team-antioch/sc2-adjutant-host-windows 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/capture-tour.js +31 -20
- package/dist/game-windows.js +13 -1
- package/dist/game.js +41 -22
- package/dist/helpers/editor.cs +30 -6
- package/dist/index.js +7 -2
- package/docs/windows-host.md +13 -6
- package/package.json +1 -1
- package/sc2-adjutant-plugin.json +1 -1
package/README.md
CHANGED
|
@@ -8,8 +8,11 @@ The Windows **Host Adapter** for [sc2-adjutant](https://github.com/TeamAntioch/s
|
|
|
8
8
|
|---|---|
|
|
9
9
|
| `editor.open`, `editor.checkClosed` | Opens a Map Package in the Galaxy Editor, and tells whether the Editor has it open. |
|
|
10
10
|
| `editor.testDocument`, `editor.save` | Runs File > Test Document, and saves a throwaway copy of a map, through the Editor's menu. |
|
|
11
|
+
| `game.banksDir` | The folder the game keeps its banks in; test_mission snapshots it around a test game. |
|
|
11
12
|
| `editor.captureTour`, `editor.closeCaptureCopies` | Plays a capture map and screenshots each camera stop, then closes it unsaved. |
|
|
12
13
|
| `game.launch` | Starts the game on a Map Package without the Editor. |
|
|
14
|
+
| `game.logsFolder` | `<Documents>\StarCraft II\GameLogs`, Documents as the shell has it. |
|
|
15
|
+
| `game.running`, `game.list`, `game.quit` | Tells whether a game runs, lists the running games with their start times, and quits one recorded game gracefully (close the window, then Yes), ending it only after a timeout. |
|
|
13
16
|
| `screen.capture` | Captures the game's window, even when other windows cover it. |
|
|
14
17
|
| `tts.speak` | Speaks placeholder voice lines with Windows' built-in voices. |
|
|
15
18
|
| `model.render`, `model.rendererKey`, `model.export`, `model.exportGltf` | Renders game and mod models to turntable thumbnails, and exports them as `.m3` or glTF, with the WhiteoutFlakes model viewer on D3D11. It falls back to WARP, Windows' software rasterizer, when the GPU can't run the viewer. |
|
package/dist/capture-tour.js
CHANGED
|
@@ -17,11 +17,11 @@ import { spawn } from "node:child_process";
|
|
|
17
17
|
import { existsSync } from "node:fs";
|
|
18
18
|
import { appendFile, mkdir, readFile, rm } from "node:fs/promises";
|
|
19
19
|
import path from "node:path";
|
|
20
|
-
import { CAPTURE_MAPS_FOLDER } from "@team-antioch/sc2-adjutant/plugin-sdk";
|
|
20
|
+
import { CAPTURE_MAPS_FOLDER, ownedGame, quitOwnedGame, refuseForeignGame } from "@team-antioch/sc2-adjutant/plugin-sdk";
|
|
21
21
|
import { bankFile, captureCopies, watchTour } from "./capture-tour-windows.js";
|
|
22
22
|
import { documentsOf } from "./editor-windows.js";
|
|
23
23
|
import { activate, choose, closeDocument, editorExe, editorHelper, launch, promptText, readEditor } from "./editor.js";
|
|
24
|
-
import { firstAnswer, gamePids,
|
|
24
|
+
import { firstAnswer, gamePids, tolerantCheck, topWindows, wasMinimized, windowsSystem } from "./game.js";
|
|
25
25
|
import { gameWindows } from "./game-windows.js";
|
|
26
26
|
import { deadline, helper, runHelper, sleep } from "./helpers.js";
|
|
27
27
|
/** How long the Editor may take to open and load the capture map, in seconds: a cold Editor took a minute. */
|
|
@@ -44,6 +44,14 @@ function documentsFolder(editor) {
|
|
|
44
44
|
}
|
|
45
45
|
return folder;
|
|
46
46
|
}
|
|
47
|
+
/** The folder the game saves its banks in (`game.banksDir`): `<Documents>\StarCraft II\Banks`. */
|
|
48
|
+
export async function banksDir(_request, context) {
|
|
49
|
+
return path.join(await documentsFolder(await editorHelper(context)), "StarCraft II", "Banks");
|
|
50
|
+
}
|
|
51
|
+
/** game.logsFolder: `<Documents>\StarCraft II\GameLogs`, Documents as the shell has it (it may be redirected). */
|
|
52
|
+
export async function gameLogsFolder(_request, context) {
|
|
53
|
+
return path.join(await documentsFolder(await editorHelper(context)), "StarCraft II", "GameLogs");
|
|
54
|
+
}
|
|
47
55
|
const isOpen = async (editor, mapPath) => documentsOf(await readEditor(editor), mapPath).length > 0;
|
|
48
56
|
/**
|
|
49
57
|
* Opens the map, makes it the active document and runs File > Test Document, then waits for a new
|
|
@@ -113,7 +121,9 @@ async function bankNow(bank) {
|
|
|
113
121
|
*/
|
|
114
122
|
export const WATCH_FAILED_CHECKS = 10;
|
|
115
123
|
/** The watch's world: the game's processes, the bank on disk, and the capture helper on the game's window. */
|
|
116
|
-
export function gameWorld(request, editor, capture, bank, leftover, log
|
|
124
|
+
export function gameWorld(request, editor, capture, bank, leftover, log,
|
|
125
|
+
/** Whether the game this capture started runs; without it, whether any game does (attaching). */
|
|
126
|
+
gameUp) {
|
|
117
127
|
let warned = "";
|
|
118
128
|
/** A capture problem, logged once until another comes up. */
|
|
119
129
|
const warn = (line) => {
|
|
@@ -134,7 +144,7 @@ export function gameWorld(request, editor, capture, bank, leftover, log) {
|
|
|
134
144
|
// Checks that keep failing end the tour, rather than watch a game that may be gone.
|
|
135
145
|
gameRunning: async () => {
|
|
136
146
|
try {
|
|
137
|
-
running = (await gamePids(editor.exe)).length > 0;
|
|
147
|
+
running = gameUp ? await gameUp() : (await gamePids(editor.exe)).length > 0;
|
|
138
148
|
failedChecks = 0;
|
|
139
149
|
}
|
|
140
150
|
catch (error) {
|
|
@@ -214,6 +224,9 @@ export async function captureTour(request, context) {
|
|
|
214
224
|
// Set once this run may have opened the map or started the game; whatever ends the run then
|
|
215
225
|
// quits the game and closes the map.
|
|
216
226
|
let touchedEditor = false;
|
|
227
|
+
// The game this capture starts, once it appears: the only one it watches or quits. Attaching, the author's game is watched and left alone.
|
|
228
|
+
const system = windowsSystem(editor.exe);
|
|
229
|
+
const own = ownedGame(system, request.onGameStarted);
|
|
217
230
|
// Attached to a game already running, the bank may still hold an earlier run's last stop (-1);
|
|
218
231
|
// that content is ignored until the game saves the bank again.
|
|
219
232
|
let leftover;
|
|
@@ -227,7 +240,8 @@ export async function captureTour(request, context) {
|
|
|
227
240
|
}
|
|
228
241
|
else {
|
|
229
242
|
await rm(bank, { force: true });
|
|
230
|
-
|
|
243
|
+
// Nothing is quit here: a game already running isn't this capture's.
|
|
244
|
+
await refuseForeignGame(system);
|
|
231
245
|
// A copy left open by an earlier run would be tested as it was: opening only brings it forward.
|
|
232
246
|
if (await isOpen(editor, mapPath)) {
|
|
233
247
|
log("closing a stale copy");
|
|
@@ -241,12 +255,16 @@ export async function captureTour(request, context) {
|
|
|
241
255
|
await startTest(mapPath, context, editor, log);
|
|
242
256
|
}
|
|
243
257
|
log("game started; it can sit behind other windows now (don't minimize it)");
|
|
244
|
-
return await watchTour({ ...request, ...(leftover !== undefined ? { leftover } : {}) }, gameWorld(request, editor, capture, bank, leftover, log));
|
|
258
|
+
return await watchTour({ ...request, ...(leftover !== undefined ? { leftover } : {}) }, gameWorld(request, editor, capture, bank, leftover, log, request.attach ? undefined : () => own.running()));
|
|
245
259
|
}
|
|
246
260
|
finally {
|
|
247
261
|
try {
|
|
248
262
|
if (touchedEditor) {
|
|
249
|
-
|
|
263
|
+
// A game that appeared since the last look is this capture's too.
|
|
264
|
+
await own.running().catch(() => false);
|
|
265
|
+
const game = own.game();
|
|
266
|
+
if (game)
|
|
267
|
+
await quitOwnedGame(game, system, log).catch((error) => log(`couldn't quit the game: ${error.message}`));
|
|
250
268
|
await closeMap(mapPath, editor, log, earlier);
|
|
251
269
|
}
|
|
252
270
|
}
|
|
@@ -257,27 +275,20 @@ export async function captureTour(request, context) {
|
|
|
257
275
|
}
|
|
258
276
|
/**
|
|
259
277
|
* Closes, without saving, every capture copy the Editor has open (any document under
|
|
260
|
-
* <cacheDir>/capture/maps/), quitting the
|
|
261
|
-
*
|
|
278
|
+
* <cacheDir>/capture/maps/), after quitting the games it is given: the capture's own, which the
|
|
279
|
+
* broker recorded. Another game is left running. The Editor Broker runs this as it starts and after a failed tour.
|
|
262
280
|
*/
|
|
263
281
|
export async function closeCaptureCopies(request, context) {
|
|
264
282
|
const log = request.log ?? (() => undefined);
|
|
265
283
|
const maps = path.join(context.requirePath("cacheDir"), CAPTURE_MAPS_FOLDER);
|
|
266
284
|
const editor = await editorHelper(context);
|
|
285
|
+
// Only the games the broker recorded as a capture's; one it didn't is the author's to quit.
|
|
286
|
+
const system = windowsSystem(editor.exe);
|
|
287
|
+
for (const game of request.games ?? [])
|
|
288
|
+
await quitOwnedGame(game, system, log).catch((error) => log(`couldn't quit game ${game.pid}: ${error.message}`));
|
|
267
289
|
const copies = captureCopies(await readEditor(editor), maps, existsSync);
|
|
268
290
|
if (copies.length === 0)
|
|
269
291
|
return;
|
|
270
|
-
// A check that won't answer is no reason to leave the copies open: the game is quit regardless.
|
|
271
|
-
const running = await firstAnswer(tolerantCheck(() => gamePids(editor.exe))).catch((error) => {
|
|
272
|
-
log(`couldn't tell whether a game is running: ${error.message}`);
|
|
273
|
-
return undefined;
|
|
274
|
-
});
|
|
275
|
-
if (running === undefined || running.length > 0) {
|
|
276
|
-
if (running)
|
|
277
|
-
log("quitting the game a capture copy left running");
|
|
278
|
-
// The copies are closed even when the game won't go, so the next tour doesn't find one stale.
|
|
279
|
-
await quitGame(editor.exe).catch((error) => log(error.message));
|
|
280
|
-
}
|
|
281
292
|
for (const copy of copies) {
|
|
282
293
|
log(`closing ${path.basename(copy)}`);
|
|
283
294
|
await closeMap(copy, editor, log);
|
package/dist/game-windows.js
CHANGED
|
@@ -9,9 +9,21 @@
|
|
|
9
9
|
// "StarCraft II".
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { editorState, GAME_PROCESSES, isEditorProcess } from "./editor-windows.js";
|
|
12
|
+
/**
|
|
13
|
+
* The flags the Editor's Test Document starts the game with besides the map and window mode
|
|
14
|
+
* (docs/reference/game-testing.md §1): preload on, cheats off, and the reload check.
|
|
15
|
+
*/
|
|
16
|
+
export const EDITOR_TEST_FLAGS = ["-preload", "1", "-NoUserCheats", "-reloadcheck"];
|
|
12
17
|
/** How game.launch starts the game on a map: the install's SC2Switcher, windowed. */
|
|
13
18
|
export function switcherLaunch(sc2Path, mapPath) {
|
|
14
|
-
return { exe: path.join(sc2Path, "Support", "SC2Switcher.exe"), args: ["-run", mapPath, "-displaymode", "0"] };
|
|
19
|
+
return { exe: path.join(sc2Path, "Support", "SC2Switcher.exe"), args: ["-run", mapPath, "-displaymode", "0", ...EDITOR_TEST_FLAGS] };
|
|
20
|
+
}
|
|
21
|
+
/** The running games from `editor games` output: a process id and its UTC start time a line, tab-separated. */
|
|
22
|
+
export function parseGames(stdout) {
|
|
23
|
+
return stdout.split(/\r?\n/).flatMap((line) => {
|
|
24
|
+
const [pid, startedAt] = line.split("\t");
|
|
25
|
+
return pid && startedAt && /^\d+$/.test(pid) ? [{ pid: Number(pid), startedAt: startedAt.trim() }] : [];
|
|
26
|
+
});
|
|
15
27
|
}
|
|
16
28
|
const isGameProcess = (name) => GAME_PROCESSES.some((game) => game.toLowerCase() === name.toLowerCase());
|
|
17
29
|
/** The game's visible top-level windows, 32- or 64-bit. */
|
package/dist/game.js
CHANGED
|
@@ -6,9 +6,10 @@ import { spawn } from "node:child_process";
|
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
7
|
import { mkdir, rename, rm } from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
|
+
import { quitOwnedGame } from "@team-antioch/sc2-adjutant/plugin-sdk";
|
|
9
10
|
import { GAME_PROCESSES, parseMenu, parseWindows } from "./editor-windows.js";
|
|
10
|
-
import { captureFormat, captureTarget, editorMenuWindows, gameWindows, switcherLaunch } from "./game-windows.js";
|
|
11
|
-
import {
|
|
11
|
+
import { captureFormat, captureTarget, editorMenuWindows, gameWindows, parseGames, switcherLaunch } from "./game-windows.js";
|
|
12
|
+
import { helper, runHelper, sleep } from "./helpers.js";
|
|
12
13
|
/** How long the game's window may take to appear once the switcher runs, in seconds. */
|
|
13
14
|
const GAME_WINDOW_SECONDS = 30;
|
|
14
15
|
/** The capture helper's exit status for a minimized window (helpers/capture.cs). */
|
|
@@ -58,29 +59,47 @@ export async function firstAnswer(check) {
|
|
|
58
59
|
return answer;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
/** Every running game, 32- or 64-bit, with its start time. Rejects when the helper fails: that is no answer, not "no game". */
|
|
63
|
+
export async function gameProcesses(editor) {
|
|
64
|
+
return parseGames(await runHelper(editor, ["games", ...GAME_PROCESSES]));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The game as core's game ownership drives it on Windows: the quit request closes the game's
|
|
68
|
+
* window, which asks it to confirm exit; Yes is pressed in that window; the process is ended
|
|
69
|
+
* (TerminateProcess) only after the timeout.
|
|
70
|
+
*/
|
|
71
|
+
export function windowsSystem(editor) {
|
|
72
|
+
const windowOf = async (pid) => {
|
|
73
|
+
const window = gameWindows(await topWindows(editor)).find((each) => each.pid === pid);
|
|
74
|
+
if (!window)
|
|
75
|
+
throw new Error(`game ${pid} has no window to close`);
|
|
76
|
+
return window.hwnd;
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
list: () => gameProcesses(editor),
|
|
80
|
+
requestQuit: async (pid) => void (await runHelper(editor, ["close", await windowOf(pid)])),
|
|
81
|
+
confirmQuit: async (pid) => void (await runHelper(editor, ["key", await windowOf(pid), "y"])),
|
|
82
|
+
kill: async (pid) => {
|
|
83
|
+
process.kill(pid);
|
|
84
|
+
},
|
|
85
|
+
sleep,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** game.list: every running game with its start time, for the Editor Broker's ownership records. */
|
|
89
|
+
export async function listGames(_request, context) {
|
|
90
|
+
return gameProcesses(await helper(context, "editor"));
|
|
91
|
+
}
|
|
92
|
+
/** game.running: whether any game runs, from the same list (the broker's bank checks ask it). */
|
|
93
|
+
export async function gameRunning(_request, context) {
|
|
94
|
+
return (await listGames({}, context)).length > 0;
|
|
95
|
+
}
|
|
96
|
+
/** game.quit: this game and no other, gracefully, ended only after a timeout (core's quitOwnedGame). */
|
|
97
|
+
export async function quitGame(request, context) {
|
|
98
|
+
return quitOwnedGame(request.game, windowsSystem(await helper(context, "editor")), request.log ?? (() => undefined));
|
|
80
99
|
}
|
|
81
100
|
/**
|
|
82
101
|
* Starts the game on a Map Package with no Editor: `Support\SC2Switcher.exe -run "<map>"
|
|
83
|
-
* -displaymode 0`, windowed. Resolves once the game's window is up; the map is still loading then.
|
|
102
|
+
* -displaymode 0 -preload 1 -NoUserCheats -reloadcheck`, windowed, with the flags the Editor adds. Resolves once the game's window is up; the map is still loading then.
|
|
84
103
|
* Refuses while a game runs, even one with no window yet.
|
|
85
104
|
*/
|
|
86
105
|
export async function launchGame(request, context) {
|
package/dist/helpers/editor.cs
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
// editor windows one line per top-level window: hwnd, owner hwnd, pid, process, class, visible (1/0), has a menu (1/0), title (tab-separated)
|
|
5
5
|
// editor menu <hwnd> one line per item of the window's menus, one level down: menu, command id, checked (1/0), label, shortcut
|
|
6
6
|
// editor pids <name>... the ids of the running processes with those names (no ".exe"), one per line
|
|
7
|
+
// editor games <name>... the running processes with those names: id and start time (UTC, round-trip format), tab-separated, one per line
|
|
8
|
+
// editor close <hwnd> posts WM_CLOSE to the window, as its close button does (a game then asks to confirm)
|
|
9
|
+
// editor key <hwnd> <key> brings the window forward and presses one key in it: space or y
|
|
7
10
|
// editor post <hwnd> <id> posts WM_COMMAND <id> to the window, as choosing that menu item does
|
|
8
11
|
// editor buttons <hwnd> one line per child button: hwnd, enabled (1/0), text (tab-separated); then "text" lines for its static text
|
|
9
12
|
// editor click <hwnd> clicks the button (BN_CLICKED to its dialog), without bringing anything forward
|
|
@@ -68,11 +71,13 @@ static class Editor {
|
|
|
68
71
|
const uint INPUT_KEYBOARD = 1;
|
|
69
72
|
const uint KEYEVENTF_KEYUP = 0x0002;
|
|
70
73
|
const ushort VK_SPACE = 0x20;
|
|
74
|
+
const ushort VK_Y = 0x59;
|
|
71
75
|
const uint ES_CONTINUOUS = 0x80000000;
|
|
72
76
|
const uint ES_SYSTEM_REQUIRED = 0x00000001;
|
|
73
77
|
const uint ES_DISPLAY_REQUIRED = 0x00000002;
|
|
74
78
|
const uint GW_OWNER = 4;
|
|
75
79
|
const uint WM_COMMAND = 0x0111;
|
|
80
|
+
const uint WM_CLOSE = 0x0010;
|
|
76
81
|
const uint WM_GETTEXT = 0x000D;
|
|
77
82
|
const uint BM_CLICK = 0x00F5;
|
|
78
83
|
const uint SMTO_ABORTIFHUNG = 0x0002;
|
|
@@ -133,6 +138,19 @@ static class Editor {
|
|
|
133
138
|
return 0;
|
|
134
139
|
}
|
|
135
140
|
|
|
141
|
+
static int Games(string[] names) {
|
|
142
|
+
foreach (var name in names) foreach (var process in Process.GetProcessesByName(name)) {
|
|
143
|
+
try { Console.WriteLine(process.Id + "\t" + process.StartTime.ToUniversalTime().ToString("o")); }
|
|
144
|
+
catch (Exception) { /* exited, or not readable: not a game to name */ }
|
|
145
|
+
}
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static int Close(IntPtr hwnd) {
|
|
150
|
+
if (!IsWindow(hwnd)) { Console.Error.WriteLine("no window " + hwnd); return 2; }
|
|
151
|
+
return PostMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) ? 0 : 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
136
154
|
static int Menu(IntPtr hwnd) {
|
|
137
155
|
if (!IsWindow(hwnd)) { Console.Error.WriteLine("no window " + hwnd); return 2; }
|
|
138
156
|
var menu = GetMenu(hwnd);
|
|
@@ -216,7 +234,9 @@ static class Editor {
|
|
|
216
234
|
* a background process take the foreground only while its input is attached to the foreground
|
|
217
235
|
* window's thread.
|
|
218
236
|
*/
|
|
219
|
-
static int Space(IntPtr hwnd) {
|
|
237
|
+
static int Space(IntPtr hwnd) { return Key(hwnd, VK_SPACE, "Space"); }
|
|
238
|
+
|
|
239
|
+
static int Key(IntPtr hwnd, ushort vk, string name) {
|
|
220
240
|
if (!IsWindow(hwnd)) { Console.Error.WriteLine("no window " + hwnd); return 2; }
|
|
221
241
|
if (IsIconic(hwnd)) ShowWindowAsync(hwnd, SW_SHOWNOACTIVATE);
|
|
222
242
|
var foreground = GetForegroundWindow();
|
|
@@ -228,13 +248,13 @@ static class Editor {
|
|
|
228
248
|
SetForegroundWindow(hwnd);
|
|
229
249
|
if (attached) AttachThreadInput(mine, theirs, false);
|
|
230
250
|
System.Threading.Thread.Sleep(300);
|
|
231
|
-
if (GetForegroundWindow() != hwnd) { Console.Error.WriteLine("couldn't bring the window forward to press
|
|
251
|
+
if (GetForegroundWindow() != hwnd) { Console.Error.WriteLine("couldn't bring the window forward to press " + name); return 1; }
|
|
232
252
|
var size = Marshal.SizeOf(typeof(Input));
|
|
233
253
|
// With its scan code too, for a game that reads keys by scan code.
|
|
234
|
-
var scan = (ushort)MapVirtualKey(
|
|
254
|
+
var scan = (ushort)MapVirtualKey(vk, 0);
|
|
235
255
|
var inputs = new[] {
|
|
236
|
-
new Input { Type = INPUT_KEYBOARD, Union = new InputUnion { Key = new KeyboardInput { Vk =
|
|
237
|
-
new Input { Type = INPUT_KEYBOARD, Union = new InputUnion { Key = new KeyboardInput { Vk =
|
|
256
|
+
new Input { Type = INPUT_KEYBOARD, Union = new InputUnion { Key = new KeyboardInput { Vk = vk, Scan = scan } } },
|
|
257
|
+
new Input { Type = INPUT_KEYBOARD, Union = new InputUnion { Key = new KeyboardInput { Vk = vk, Scan = scan, Flags = KEYEVENTF_KEYUP } } },
|
|
238
258
|
};
|
|
239
259
|
return SendInput((uint)inputs.Length, inputs, size) == inputs.Length ? 0 : 1;
|
|
240
260
|
}
|
|
@@ -253,6 +273,10 @@ static class Editor {
|
|
|
253
273
|
try {
|
|
254
274
|
if (command == "windows" && args.Length == 1) return Windows();
|
|
255
275
|
if (command == "pids" && args.Length >= 2) { var names = new string[args.Length - 1]; Array.Copy(args, 1, names, 0, names.Length); return Pids(names); }
|
|
276
|
+
if (command == "games" && args.Length >= 2) { var gameNames = new string[args.Length - 1]; Array.Copy(args, 1, gameNames, 0, gameNames.Length); return Games(gameNames); }
|
|
277
|
+
if (command == "close" && args.Length == 2) return Close(Handle(args[1]));
|
|
278
|
+
if (command == "key" && args.Length == 3 && args[2] == "space") return Space(Handle(args[1]));
|
|
279
|
+
if (command == "key" && args.Length == 3 && args[2] == "y") return Key(Handle(args[1]), VK_Y, "Y");
|
|
256
280
|
if (command == "menu" && args.Length == 2) return Menu(Handle(args[1]));
|
|
257
281
|
if (command == "post" && args.Length == 3) return Post(Handle(args[1]), int.Parse(args[2]));
|
|
258
282
|
if (command == "buttons" && args.Length == 2) return Buttons(Handle(args[1]));
|
|
@@ -265,7 +289,7 @@ static class Editor {
|
|
|
265
289
|
Console.Error.WriteLine(error.Message);
|
|
266
290
|
return 2;
|
|
267
291
|
}
|
|
268
|
-
Console.Error.WriteLine("usage: editor windows | pids <name>... | menu <hwnd> | post <hwnd> <id> | buttons <hwnd> | click <hwnd> | documents | restore <hwnd> | space <hwnd> | awake <pid>");
|
|
292
|
+
Console.Error.WriteLine("usage: editor windows | pids <name>... | games <name>... | close <hwnd> | key <hwnd> space|y | menu <hwnd> | post <hwnd> <id> | buttons <hwnd> | click <hwnd> | documents | restore <hwnd> | space <hwnd> | awake <pid>");
|
|
269
293
|
return 2;
|
|
270
294
|
}
|
|
271
295
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
// (`editorPath`, `sc2Path`, `cacheDir`, `modelViewerPath`); nothing about the machine is built in. Its
|
|
10
10
|
// native helpers (helpers/*.cs) are compiled on first use into <cacheDir>/host-windows/bin
|
|
11
11
|
// (helpers.ts). docs/windows-host.md has the Editor and game facts it relies on.
|
|
12
|
-
import { captureTour, closeCaptureCopies } from "./capture-tour.js";
|
|
12
|
+
import { banksDir, captureTour, closeCaptureCopies, gameLogsFolder } from "./capture-tour.js";
|
|
13
13
|
import { checkClosed, openInEditor, saveInEditor, testDocument } from "./editor.js";
|
|
14
|
-
import { captureScreen, launchGame } from "./game.js";
|
|
14
|
+
import { captureScreen, gameRunning, launchGame, listGames, quitGame } from "./game.js";
|
|
15
15
|
import { speak } from "./speech.js";
|
|
16
16
|
import { exportModel, exportModelGltf, rendererKey, renderModel } from "./whiteoutflakes.js";
|
|
17
17
|
const plugin = {
|
|
@@ -22,8 +22,13 @@ const plugin = {
|
|
|
22
22
|
"editor.save": saveInEditor,
|
|
23
23
|
"editor.captureTour": captureTour,
|
|
24
24
|
"editor.closeCaptureCopies": closeCaptureCopies,
|
|
25
|
+
"game.banksDir": banksDir,
|
|
25
26
|
"screen.capture": captureScreen,
|
|
26
27
|
"game.launch": launchGame,
|
|
28
|
+
"game.running": gameRunning,
|
|
29
|
+
"game.list": listGames,
|
|
30
|
+
"game.quit": quitGame,
|
|
31
|
+
"game.logsFolder": gameLogsFolder,
|
|
27
32
|
"tts.speak": speak,
|
|
28
33
|
"model.render": renderModel,
|
|
29
34
|
"model.rendererKey": rendererKey,
|
package/docs/windows-host.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
How the mapper drives the StarCraft II Editor and game on Windows: the facts behind the Windows Host Adapter, `bundled:host-windows` (`packages/plugin-host-windows/`). How to install it and which capabilities it has are in the package's [README](../README.md), what each capability takes and returns is in [the plugin API](../../../docs/plugin-api.md#host-adapter-kinds), and the machine config is in [core's README](../../core/README.md#the-machine-config). This doc is what the adapter's code relies on, and what an author or assistant needs when doing the same by hand. The plan and the spikes behind it are spec #727. Everything here was seen on SC2 build 98310, in a Parallels Windows 11 ARM64 VM, between 2026-11-14 and 2026-11-18.
|
|
4
4
|
|
|
5
|
-
The adapter has `editor.open`, `editor.checkClosed`, `editor.testDocument`, `editor.save`, `editor.captureTour`, `editor.closeCaptureCopies`, `game.launch`, `screen.capture`, `tts.speak`, `model.render`, `model.rendererKey`, `model.export` and `model.exportGltf`. The [macOS host](../../plugin-host-macos/docs/macos-host.md) has the facts the two platforms share: the Editor Broker, banks, the Custom Script the Editor keeps.
|
|
5
|
+
The adapter has `editor.open`, `editor.checkClosed`, `editor.testDocument`, `editor.save`, `editor.captureTour`, `editor.closeCaptureCopies`, `game.banksDir`, `game.launch`, `screen.capture`, `tts.speak`, `model.render`, `model.rendererKey`, `model.export` and `model.exportGltf`. The [macOS host](../../plugin-host-macos/docs/macos-host.md) has the facts the two platforms share: the Editor Broker, banks, the Custom Script the Editor keeps.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -55,7 +55,7 @@ The Editor's windows are top-level `#32770` dialogs. One main window, with the n
|
|
|
55
55
|
|
|
56
56
|
`editor.testDocument` refuses a map the Editor already has open (it would test the copy it loaded), opens the map, makes it the active document, posts Test Document and waits for a new `SC2.exe`. Test Document copies the map to `<install>\Maps\Test\EditorTest.SC2Map` and starts `Support\SC2Switcher.exe`, which starts `Versions\Base<build>\SC2.exe -run "Test\EditorTest.SC2Map" -displaymode 2 ...`. Here the game was running 13 s after the call, with the Editor already open.
|
|
57
57
|
|
|
58
|
-
**Use windowed mode in a VM.** The Editor's default Test Document window mode is fullscreen (`-displaymode 2`), and in the VM the game then loses its D3D device (`D3DERR_DEVICELOST`) and shows nothing. Choose windowed in the Editor's Test Document preferences (File > Preferences > Test Document; the setting `TestDocWindowed`), which passes `-displaymode 0` ([game-testing.md](../../../docs/reference/game-testing.md#the-editors-command-line) has every Test Document setting). To quit
|
|
58
|
+
**Use windowed mode in a VM.** The Editor's default Test Document window mode is fullscreen (`-displaymode 2`), and in the VM the game then loses its D3D device (`D3DERR_DEVICELOST`) and shows nothing. Choose windowed in the Editor's Test Document preferences (File > Preferences > Test Document; the setting `TestDocWindowed`), which passes `-displaymode 0` ([game-testing.md](../../../docs/reference/game-testing.md#the-editors-command-line) has every Test Document setting). To quit a game you started by hand, close its window and press Yes in its Confirm Exit dialog, or stop `SC2.exe` (`Stop-Process -Name SC2`) if it hangs.
|
|
59
59
|
|
|
60
60
|
**Quit the game before testing again.** With a game still running, Test Document may load the map in it instead of starting another (the `-reloadcheck` command), so no new `SC2.exe` appears and the adapter can't tell that it worked: it says so.
|
|
61
61
|
|
|
@@ -63,7 +63,7 @@ The game can also start with no Editor: `game.launch`, below.
|
|
|
63
63
|
|
|
64
64
|
## Starting the game
|
|
65
65
|
|
|
66
|
-
`game.launch` runs `<sc2Path>\Support\SC2Switcher.exe -run "<absolute map path>" -displaymode 0
|
|
66
|
+
`game.launch` runs `<sc2Path>\Support\SC2Switcher.exe -run "<absolute map path>" -displaymode 0 -preload 1 -NoUserCheats -reloadcheck` (the last three are what the Editor's Test Document adds, [game-testing.md](../../../docs/reference/game-testing.md#the-editors-command-line)), with `Support\` as its working folder, and waits up to 30 s for the game's window. The switcher gets past the launcher handshake that stops a bare launch of the game ([game-testing.md](../../../docs/reference/game-testing.md#the-launcher-handshake-and-exit-code-47)), with no Battle.net and no Editor. It starts `Versions\Base<build>\SC2.exe` and exits. Here the window was up after 12 s, showing the map's loading screen, and the map had loaded within about 35 s of the call. `game.launch` resolves once the window is up, while the map still loads.
|
|
67
67
|
|
|
68
68
|
- **Windowed.** `-displaymode 0` is a window. Fullscreen (2, the Editor's default) loses its D3D device in the VM.
|
|
69
69
|
- **The game's window** is a visible top-level window of `SC2.exe` (or `SC2_x64.exe`), class `StarCraft II`, titled `StarCraft II`. An `SC2Switcher.exe` that hasn't exited can have a window titled `StarCraft II` too, so the adapter goes by the process, not the title.
|
|
@@ -81,24 +81,31 @@ The game can also start with no Editor: `game.launch`, below.
|
|
|
81
81
|
|
|
82
82
|
## Capture tours
|
|
83
83
|
|
|
84
|
+
`game.banksDir` is `<Documents>\StarCraft II\Banks`, with Documents as the shell has it (the same lookup the capture tour uses for its bank). The Editor Broker copies that folder into `<cacheDir>\banks\` before a Test Document and records what the test game changed once it quits. `game.running` answers from the same process list as `game.list`, so the broker knows when the test game has quit ([game-testing.md](../../../docs/reference/game-testing.md#what-a-test-game-does-to-the-banks-folder-issue-54)).
|
|
85
|
+
|
|
84
86
|
`editor.captureTour` runs a camera tour as the macOS adapter does, for `capture_shots`, `capture-exemplars`, `capture-sets` and `capture-edit`, which all go through core's Editor Broker (on Windows it listens on a named pipe named for the `cacheDir`; the [macOS host](../../plugin-host-macos/docs/macos-host.md#the-editor-broker-one-editor-job-at-a-time) has how the broker queues and merges jobs). It only takes a map in `<cacheDir>\capture\maps\`, since it closes it without saving.
|
|
85
87
|
|
|
86
|
-
1. It deletes the tour's bank,
|
|
88
|
+
1. It deletes the tour's bank, refuses with "A game is running that this tool didn't start. Quit it, or capture with `attach`." when any game runs (it never stops one it didn't start), and closes a copy of the map the Editor still has open from an earlier run. Then the broker writes the map (`writeMap`).
|
|
87
89
|
2. It opens the map in the Editor (up to 5 minutes, for a cold Editor), makes it the active document and posts File > Test Document, then waits up to 60 s for a new game. A prompt the Editor brings up instead, such as script errors, fails the tour with its text.
|
|
88
90
|
3. Every half second it reads the bank, `<Documents>\StarCraft II\Banks\<bank>.SC2Bank` (Documents as the shell has it: here `C:\Mac\Home\Documents`). The map counts its int key `stop` up from 1. Each new stop is captured as `<stop>.jpg`, zero-padded, and with `recordKeys` the stop and those keys' fixed values are appended to `stops.txt`. A capture that fails is tried again on the next read, while the bank still shows that stop.
|
|
89
91
|
4. It ends `done` at stop -1, `game exited` when the game quits first, and `never started` when no stop comes within `startSeconds`; after `pressSpaceAfterSeconds` with no stop it presses Space every 10 s, for a loading screen that waits for it. Pressing brings the game forward (attaching to the foreground window's input, as Windows requires) and takes focus from whoever is typing.
|
|
90
|
-
5. Whatever ends it, it
|
|
92
|
+
5. Whatever ends it, it quits the game it started (see **Quitting a game** below) and closes the map with File > Close, answering No to "Save changes to '<path>'?". While the Editor shows another prompt (script errors, say), it leaves the map open and says so, since a Close posted under a prompt could stack a save prompt behind it: answer it there and close the map without saving.
|
|
91
93
|
|
|
92
94
|
- **Frames.** The capture helper's `frame` command captures the game's window with Windows.Graphics.Capture (as `screen.capture` does), keeps only its client area, the window's frame and title bar cut off by the client rectangle's place in the window's extended frame bounds, scales it so neither side is over `width` (never enlarging it) and writes a JPEG at `quality`. One capture, crop and encode takes about 0.7 to 1 s, so a frame shows the game up to a second after its stop was announced, and stops less than about 1.5 s apart can be missed (the bank holds only the latest). The game's window is found once and again only after a capture fails. The game's picture isn't 16:9 here: the Editor's windowed Test Document gave a 1280×800 client area (16:10), and `game.launch` one of 1.42:1. Core's area tours frame their views for 16:9, so here a frame shows a little more above and below.
|
|
93
95
|
- **Covered, not minimized.** The game can sit behind other windows. A minimized one gives no frames, so a capture that finds it minimized restores it (`ShowWindowAsync(SW_SHOWNOACTIVATE)`, leaving it behind whatever covers it) and captures again. While the map loaded in front, the game undid a minimize by itself.
|
|
94
96
|
- **Awake.** For the tour's lifetime the editor helper's `awake` command holds `SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)`, as `caffeinate -d` does on the Mac. It exits with the process that started it.
|
|
95
97
|
- **Failed checks.** A game check or bank read whose helper fails for a moment changes nothing: the game is taken as still running and the bank as last read. Ten game checks failing in a row (about 5 s) end the tour with that error, rather than watch a game that may be gone. Stopping the game and `editor.closeCaptureCopies` stop it even when the check won't answer.
|
|
98
|
+
- **Quitting a game.** The Editor Broker records each game a job starts by pid and start time (`game.list`: the editor helper's `games` command prints each `SC2`/`SC2_x64` process's id and UTC start time; a pid is reused, so the start time must match too). `game.quit` quits one recorded game and no other: it posts `WM_CLOSE` to the game's window (`editor close <hwnd>`), which asks the game to confirm, then presses Y for Yes in that window (`editor key <hwnd> y`), so the game writes its logs. If the process is still there after 20 s and still has the recorded start time, it ends it (`TerminateProcess`). The log says which it was. The Yes key, and that the quit leaves complete logs, are checked on a real run (#57). A Test Document's game is the author's: the broker holds its queue until it quits and never quits it.
|
|
96
99
|
- **`attach`.** With `attach`, the author has started the game (with `game.launch`, say): the tour only watches it, leaves the Editor alone and doesn't stop the game at the end. The bank as an earlier run left it (usually ending at -1) is ignored until the game saves it again.
|
|
97
100
|
|
|
98
|
-
`editor.closeCaptureCopies` closes, without saving, every document the Editor has open in this `cacheDir`'s `capture\maps\`,
|
|
101
|
+
`editor.closeCaptureCopies` closes, without saving, every document the Editor has open in this `cacheDir`'s `capture\maps\`, after quitting the games the broker hands it (the ones it recorded as a capture's; any other game is left running). A document counts when the path the Editor shows can stand for `<cacheDir>\capture\maps\<its name>` and either shows that path whole or the copy is on disk: the Window menu's elided `C:/.../capture/maps/X.SC2Map` could be another cache's copy. The broker runs it as it starts and after a failed tour.
|
|
99
102
|
|
|
100
103
|
Timings here: from a closed Editor, the game was running 47 s after the call and the first stop came 38 s after that; with the Editor open, Test Document ran after 14 to 17 s. Stopping the game and closing the map took 6 to 9 s.
|
|
101
104
|
|
|
105
|
+
## Input (unverified, for future input work)
|
|
106
|
+
|
|
107
|
+
Once the game has focus it takes keys sent with `SendInput`, but it ignores `SetCursorPos`, so a pointer can't be moved by setting its position. Resizing the game's window from outside desyncs the mouse: clicks land where the window used to be. Neither is covered by a test here; recorded so work that clicks in the game starts from it.
|
|
108
|
+
|
|
102
109
|
## Placeholder voices
|
|
103
110
|
|
|
104
111
|
`tts.speak` speaks a line with Windows' built-in voices through System.Speech (`SpeechSynthesizer`), straight to a 22050 Hz, 16-bit, mono PCM WAV (`SetOutputToWaveFile` with a `SpeechAudioFormatInfo`), the format SC2 plays, so no conversion follows. The text goes to the helper in a UTF-8 file, never on its command line, so a long line or one with quotes arrives whole. A line of 14 words made 6.4 s of audio in about 1.2 s, and the first call also compiles the helper. The voices leave about 0.1 s of silence before the speech and 0.75 to 0.8 s after it; core trims each spoken placeholder to its speech before it moves the file into place (`packages/core/src/host/placeholder-voices.ts`), whatever the Host Adapter, and encodes it to Ogg with ffmpeg for a Mission whose voice format is `.ogg`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@team-antioch/sc2-adjutant-host-windows",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The Windows Host Adapter Plugin for sc2-adjutant: opens the Galaxy Editor, runs Test Document and saves a copy of a map there, captures camera tours, starts the game and captures its window, speaks placeholder voice lines and renders game models.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/sc2-adjutant-plugin.json
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
"pluginApi": 2,
|
|
5
5
|
"roles": ["host-adapter"],
|
|
6
6
|
"entry": "./dist/index.js",
|
|
7
|
-
"contributions": { "capabilities": ["editor.open", "editor.checkClosed", "editor.testDocument", "editor.save", "editor.captureTour", "editor.closeCaptureCopies", "screen.capture", "game.launch", "tts.speak", "model.render", "model.rendererKey", "model.export", "model.exportGltf"] }
|
|
7
|
+
"contributions": { "capabilities": ["editor.open", "editor.checkClosed", "editor.testDocument", "editor.save", "editor.captureTour", "editor.closeCaptureCopies", "game.banksDir", "screen.capture", "game.launch", "game.running", "game.list", "game.quit", "game.logsFolder", "tts.speak", "model.render", "model.rendererKey", "model.export", "model.exportGltf"] }
|
|
8
8
|
}
|