@gameslate/sdk 0.3.4 → 0.3.6
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 +9 -0
- package/lib/catalogue.d.ts +61 -0
- package/lib/catalogue.js +20 -0
- package/lib/condition.d.ts +1 -0
- package/lib/condition.js +9 -1
- package/lib/host/live-sandbox.js +10 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/logic.d.ts +8 -2
- package/lib/logic.js +7 -5
- package/lib/pack.d.ts +47 -0
- package/lib/plugin/contract.d.ts +7 -1
- package/lib/plugin/sandbox-guest.js +4 -0
- package/lib/plugins-api.d.ts +10 -0
- package/lib/plugins-api.js +2 -0
- package/lib/sandbox-protocol.d.ts +63 -0
- package/lib/signature.d.ts +46 -0
- package/lib/signature.js +80 -0
- package/lib/status.d.ts +14 -1
- package/lib/status.js +30 -0
- package/lib/types.d.ts +23 -20
- package/lib/types.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,15 @@ gameslate-plugin build ./my-plugin --out ./dist/my-plugin --tested-with 2.3.0
|
|
|
38
38
|
gameslate-plugin validate ./dist/my-plugin
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
For closed-source games, `memory.scan({ pattern: '48 8B 05 ?? ?? ?? ??', offset: 3, kind: 'rip32' })`
|
|
42
|
+
finds an address by a byte pattern in the game's own code (once per session, exactly one match),
|
|
43
|
+
so the plugin survives patches. It is optional: check `memory.scan` exists (cores before 0.3.6,
|
|
44
|
+
and emulators, don't have it).
|
|
45
|
+
|
|
46
|
+
Catalogue counters can declare a `role` (`health`, `magic`, `armor`, `keys`) and `format:
|
|
47
|
+
'percent'` so the core's AI and chips find them; declare your `variants` (`{ id, label,
|
|
48
|
+
shuffled? }`) for every `variant` your decoder emits.
|
|
49
|
+
|
|
41
50
|
`live.js` and `assets.js` run in the core's sandbox, built for a neutral platform: no Node APIs,
|
|
42
51
|
no file system, no network. Read the game through `GameMemory`, the player's files through
|
|
43
52
|
`InputFile`, and bytes with `Bytes`. Return data (states, drawings, pixels, meshes); the core
|
package/lib/catalogue.d.ts
CHANGED
|
@@ -34,20 +34,44 @@ export declare const CounterSchema: z.ZodObject<{
|
|
|
34
34
|
max: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
35
35
|
/** values → display text (e.g. wallet tier 0/1/2 → 99/200/500) */
|
|
36
36
|
display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
37
|
+
/** what core features know it as: the AI's health and magic, the "no small key" chip */
|
|
38
|
+
role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
|
|
39
|
+
/** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
|
|
40
|
+
format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
|
|
37
41
|
}, "strict", z.ZodTypeAny, {
|
|
38
42
|
label: string;
|
|
39
43
|
id: string;
|
|
40
44
|
icon?: string | undefined;
|
|
41
45
|
max?: string | number | undefined;
|
|
42
46
|
display?: Record<string, string> | undefined;
|
|
47
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
48
|
+
format?: "number" | "percent" | undefined;
|
|
43
49
|
}, {
|
|
44
50
|
label: string;
|
|
45
51
|
id: string;
|
|
46
52
|
icon?: string | undefined;
|
|
47
53
|
max?: string | number | undefined;
|
|
48
54
|
display?: Record<string, string> | undefined;
|
|
55
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
56
|
+
format?: "number" | "percent" | undefined;
|
|
49
57
|
}>;
|
|
50
58
|
export type CatalogueCounter = z.infer<typeof CounterSchema>;
|
|
59
|
+
export type CounterRole = NonNullable<CatalogueCounter['role']>;
|
|
60
|
+
/** A variant of the game the decoder can report (`state.variant`). */
|
|
61
|
+
export declare const VariantSchema: z.ZodObject<{
|
|
62
|
+
id: z.ZodString;
|
|
63
|
+
label: z.ZodString;
|
|
64
|
+
/** item locations are randomised: curated hints and item-based objective checks don't hold */
|
|
65
|
+
shuffled: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
}, "strict", z.ZodTypeAny, {
|
|
67
|
+
label: string;
|
|
68
|
+
id: string;
|
|
69
|
+
shuffled?: boolean | undefined;
|
|
70
|
+
}, {
|
|
71
|
+
label: string;
|
|
72
|
+
id: string;
|
|
73
|
+
shuffled?: boolean | undefined;
|
|
74
|
+
}>;
|
|
51
75
|
export declare const LayoutSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
52
76
|
kind: z.ZodLiteral<"slotGrid">;
|
|
53
77
|
id: z.ZodString;
|
|
@@ -580,18 +604,26 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
580
604
|
max: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
581
605
|
/** values → display text (e.g. wallet tier 0/1/2 → 99/200/500) */
|
|
582
606
|
display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
607
|
+
/** what core features know it as: the AI's health and magic, the "no small key" chip */
|
|
608
|
+
role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
|
|
609
|
+
/** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
|
|
610
|
+
format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
|
|
583
611
|
}, "strict", z.ZodTypeAny, {
|
|
584
612
|
label: string;
|
|
585
613
|
id: string;
|
|
586
614
|
icon?: string | undefined;
|
|
587
615
|
max?: string | number | undefined;
|
|
588
616
|
display?: Record<string, string> | undefined;
|
|
617
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
618
|
+
format?: "number" | "percent" | undefined;
|
|
589
619
|
}, {
|
|
590
620
|
label: string;
|
|
591
621
|
id: string;
|
|
592
622
|
icon?: string | undefined;
|
|
593
623
|
max?: string | number | undefined;
|
|
594
624
|
display?: Record<string, string> | undefined;
|
|
625
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
626
|
+
format?: "number" | "percent" | undefined;
|
|
595
627
|
}>, "many">;
|
|
596
628
|
/** flag sets the pack's decoder streams (bit conditions may only reference these) */
|
|
597
629
|
flagSets: z.ZodArray<z.ZodString, "many">;
|
|
@@ -995,6 +1027,21 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
995
1027
|
shownByDefault: boolean;
|
|
996
1028
|
icon?: string | undefined;
|
|
997
1029
|
}>, "many">>;
|
|
1030
|
+
/** the variants `state.variant` may name (vanilla, master quest, randomizer, …) */
|
|
1031
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1032
|
+
id: z.ZodString;
|
|
1033
|
+
label: z.ZodString;
|
|
1034
|
+
/** item locations are randomised: curated hints and item-based objective checks don't hold */
|
|
1035
|
+
shuffled: z.ZodOptional<z.ZodBoolean>;
|
|
1036
|
+
}, "strict", z.ZodTypeAny, {
|
|
1037
|
+
label: string;
|
|
1038
|
+
id: string;
|
|
1039
|
+
shuffled?: boolean | undefined;
|
|
1040
|
+
}, {
|
|
1041
|
+
label: string;
|
|
1042
|
+
id: string;
|
|
1043
|
+
shuffled?: boolean | undefined;
|
|
1044
|
+
}>, "many">>;
|
|
998
1045
|
}, "strict", z.ZodTypeAny, {
|
|
999
1046
|
counters: {
|
|
1000
1047
|
label: string;
|
|
@@ -1002,6 +1049,8 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
1002
1049
|
icon?: string | undefined;
|
|
1003
1050
|
max?: string | number | undefined;
|
|
1004
1051
|
display?: Record<string, string> | undefined;
|
|
1052
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1053
|
+
format?: "number" | "percent" | undefined;
|
|
1005
1054
|
}[];
|
|
1006
1055
|
flagSets: string[];
|
|
1007
1056
|
items: {
|
|
@@ -1107,6 +1156,11 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
1107
1156
|
shownByDefault: boolean;
|
|
1108
1157
|
icon?: string | undefined;
|
|
1109
1158
|
}[] | undefined;
|
|
1159
|
+
variants?: {
|
|
1160
|
+
label: string;
|
|
1161
|
+
id: string;
|
|
1162
|
+
shuffled?: boolean | undefined;
|
|
1163
|
+
}[] | undefined;
|
|
1110
1164
|
}, {
|
|
1111
1165
|
counters: {
|
|
1112
1166
|
label: string;
|
|
@@ -1114,6 +1168,8 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
1114
1168
|
icon?: string | undefined;
|
|
1115
1169
|
max?: string | number | undefined;
|
|
1116
1170
|
display?: Record<string, string> | undefined;
|
|
1171
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1172
|
+
format?: "number" | "percent" | undefined;
|
|
1117
1173
|
}[];
|
|
1118
1174
|
flagSets: string[];
|
|
1119
1175
|
items: {
|
|
@@ -1219,6 +1275,11 @@ export declare const CatalogueSchema: z.ZodObject<{
|
|
|
1219
1275
|
shownByDefault: boolean;
|
|
1220
1276
|
icon?: string | undefined;
|
|
1221
1277
|
}[] | undefined;
|
|
1278
|
+
variants?: {
|
|
1279
|
+
label: string;
|
|
1280
|
+
id: string;
|
|
1281
|
+
shuffled?: boolean | undefined;
|
|
1282
|
+
}[] | undefined;
|
|
1222
1283
|
}>;
|
|
1223
1284
|
export type Catalogue = z.infer<typeof CatalogueSchema>;
|
|
1224
1285
|
/**
|
package/lib/catalogue.js
CHANGED
|
@@ -28,6 +28,19 @@ export const CounterSchema = z
|
|
|
28
28
|
max: z.union([z.number(), Id]).optional(),
|
|
29
29
|
/** values → display text (e.g. wallet tier 0/1/2 → 99/200/500) */
|
|
30
30
|
display: z.record(z.string(), z.string()).optional(),
|
|
31
|
+
/** what core features know it as: the AI's health and magic, the "no small key" chip */
|
|
32
|
+
role: z.enum(['health', 'magic', 'armor', 'keys']).optional(),
|
|
33
|
+
/** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
|
|
34
|
+
format: z.enum(['number', 'percent']).optional(),
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
/** A variant of the game the decoder can report (`state.variant`). */
|
|
38
|
+
export const VariantSchema = z
|
|
39
|
+
.object({
|
|
40
|
+
id: Id,
|
|
41
|
+
label: z.string().min(1),
|
|
42
|
+
/** item locations are randomised: curated hints and item-based objective checks don't hold */
|
|
43
|
+
shuffled: z.boolean().optional(),
|
|
31
44
|
})
|
|
32
45
|
.strict();
|
|
33
46
|
export const LayoutSchema = z.discriminatedUnion('kind', [
|
|
@@ -184,6 +197,8 @@ export const CatalogueSchema = z
|
|
|
184
197
|
pinRules: z.array(PinRuleSchema),
|
|
185
198
|
/** pin categories the map's options let the player filter; pins name theirs */
|
|
186
199
|
pinCategories: z.array(PinCategorySchema).optional(),
|
|
200
|
+
/** the variants `state.variant` may name (vanilla, master quest, randomizer, …) */
|
|
201
|
+
variants: z.array(VariantSchema).optional(),
|
|
187
202
|
})
|
|
188
203
|
.strict();
|
|
189
204
|
function duplicates(ids) {
|
|
@@ -239,6 +254,9 @@ function checkConditionReferences(where, cond, known) {
|
|
|
239
254
|
...refs.flagSets
|
|
240
255
|
.filter(id => !known.flagSets.has(id))
|
|
241
256
|
.map(id => `${where}: undeclared flag set "${id}"`),
|
|
257
|
+
...refs.variants
|
|
258
|
+
.filter(id => known.variants && !known.variants.has(id))
|
|
259
|
+
.map(id => `${where}: undeclared variant "${id}"`),
|
|
242
260
|
];
|
|
243
261
|
}
|
|
244
262
|
function checkDuplicateIds(cat) {
|
|
@@ -250,6 +268,7 @@ function checkDuplicateIds(cat) {
|
|
|
250
268
|
['reference section', cat.reference.map(r => r.id)],
|
|
251
269
|
['chip', cat.chips.map(c => c.id)],
|
|
252
270
|
['pin rule', cat.pinRules.map(r => r.id)],
|
|
271
|
+
['variant', (cat.variants ?? []).map(v => v.id)],
|
|
253
272
|
];
|
|
254
273
|
return groups.flatMap(([what, ids]) => duplicates(ids).map(d => `duplicate ${what} id "${d}"`));
|
|
255
274
|
}
|
|
@@ -296,6 +315,7 @@ export function checkCatalogue(input) {
|
|
|
296
315
|
counters: new Set(cat.counters.map(c => c.id)),
|
|
297
316
|
missions: new Set(cat.missions.map(m => m.id)),
|
|
298
317
|
flagSets: new Set(cat.flagSets),
|
|
318
|
+
variants: cat.variants ? new Set(cat.variants.map(v => v.id)) : null,
|
|
299
319
|
};
|
|
300
320
|
return [
|
|
301
321
|
...checkDuplicateIds(cat),
|
package/lib/condition.d.ts
CHANGED
package/lib/condition.js
CHANGED
|
@@ -103,7 +103,13 @@ export function evaluate(cond, state, ctx = {}) {
|
|
|
103
103
|
throw new Error(`Unhandled condition shape: ${JSON.stringify(cond)}`);
|
|
104
104
|
}
|
|
105
105
|
export function collectReferences(cond) {
|
|
106
|
-
const out = {
|
|
106
|
+
const out = {
|
|
107
|
+
items: [],
|
|
108
|
+
missions: [],
|
|
109
|
+
counters: [],
|
|
110
|
+
flagSets: [],
|
|
111
|
+
variants: [],
|
|
112
|
+
};
|
|
107
113
|
const walk = (c) => {
|
|
108
114
|
if ('has' in c)
|
|
109
115
|
out.items.push(c.has);
|
|
@@ -113,6 +119,8 @@ export function collectReferences(cond) {
|
|
|
113
119
|
out.counters.push(c.counter);
|
|
114
120
|
else if ('bit' in c)
|
|
115
121
|
out.flagSets.push(c.bit.set);
|
|
122
|
+
else if ('variant' in c)
|
|
123
|
+
out.variants.push(c.variant);
|
|
116
124
|
else if ('all' in c)
|
|
117
125
|
c.all.forEach(walk);
|
|
118
126
|
else if ('any' in c)
|
package/lib/host/live-sandbox.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GameStateSchema, PackViewsSchema, SandboxDescriptionSchema, } from '../index.js';
|
|
1
|
+
import { SignatureSchema, GameStateSchema, PackViewsSchema, SandboxDescriptionSchema, } from '../index.js';
|
|
2
2
|
import { errorText, QuickJsGuest } from './quickjs-guest.js';
|
|
3
3
|
export { loadQuickJs } from './quickjs-guest.js';
|
|
4
4
|
/*
|
|
@@ -193,6 +193,15 @@ export class PluginSandbox {
|
|
|
193
193
|
refreshMappings: handle => {
|
|
194
194
|
this.memory(handle).refreshMappings();
|
|
195
195
|
},
|
|
196
|
+
/* the guest's signature is untrusted: parsed here, before the core scans anything */
|
|
197
|
+
scan: (handle, signature) => {
|
|
198
|
+
const memory = this.memory(handle);
|
|
199
|
+
if (!memory.scan)
|
|
200
|
+
throw new Error('signature scans are not available for this game');
|
|
201
|
+
const sig = SignatureSchema.parse(JSON.parse(vm().getString(signature)));
|
|
202
|
+
const at = memory.scan(sig);
|
|
203
|
+
return at === null ? vm().null : vm().newString(at.toString());
|
|
204
|
+
},
|
|
196
205
|
};
|
|
197
206
|
}
|
|
198
207
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/logic.d.ts
CHANGED
|
@@ -15,7 +15,11 @@ export interface FilteredHint {
|
|
|
15
15
|
* Evaluates hint conditions strictly on the client BEFORE constructing any LLM prompt,
|
|
16
16
|
* stripping higher tiers and excluding any hints whose prerequisites are not yet met.
|
|
17
17
|
*/
|
|
18
|
-
export declare function filterHintGraph(graph: HintGraph, state: GameState, maxTier: 1 | 2 | 3,
|
|
18
|
+
export declare function filterHintGraph(graph: HintGraph, state: GameState, maxTier: 1 | 2 | 3, opts: {
|
|
19
|
+
/** item locations randomised or not known yet (`variantShuffling` isn't `plain`): curated hints don't hold (C7) */
|
|
20
|
+
shuffled: boolean;
|
|
21
|
+
difficultyRanks?: Record<string, number> | undefined;
|
|
22
|
+
}): FilteredHint[];
|
|
19
23
|
export interface LayerSelectionState {
|
|
20
24
|
layerId: string;
|
|
21
25
|
switchedAtMs: number;
|
|
@@ -65,4 +69,6 @@ export declare function getActiveObjectivesForDifficulty(manifest: GameManifest,
|
|
|
65
69
|
* Evaluates effective completion status for a stage goal, honoring direct `state.objectives[obj.id]`
|
|
66
70
|
* as well as live inventory/flag completion rules (`completedByItems` / `completedByFlags`) in non-randomizer runs.
|
|
67
71
|
*/
|
|
68
|
-
export declare function getObjectiveStatus(obj: ObjectiveMeta, state: GameState | null | undefined
|
|
72
|
+
export declare function getObjectiveStatus(obj: ObjectiveMeta, state: GameState | null | undefined,
|
|
73
|
+
/** item locations randomised (`variantShuffling` is `shuffled`): holding an item proves nothing */
|
|
74
|
+
shuffled: boolean): ObjectiveStatus;
|
package/lib/logic.js
CHANGED
|
@@ -52,10 +52,10 @@ function availableTiersFor(node, maxTier) {
|
|
|
52
52
|
* Evaluates hint conditions strictly on the client BEFORE constructing any LLM prompt,
|
|
53
53
|
* stripping higher tiers and excluding any hints whose prerequisites are not yet met.
|
|
54
54
|
*/
|
|
55
|
-
export function filterHintGraph(graph, state, maxTier,
|
|
56
|
-
|
|
57
|
-
if (state.variant === 'randomizer')
|
|
55
|
+
export function filterHintGraph(graph, state, maxTier, opts) {
|
|
56
|
+
if (opts.shuffled)
|
|
58
57
|
return [];
|
|
58
|
+
const difficultyRanks = opts.difficultyRanks ?? DIFFICULTY_RANK;
|
|
59
59
|
const ctx = {
|
|
60
60
|
state,
|
|
61
61
|
inventory: new Set(state.inventory),
|
|
@@ -171,14 +171,16 @@ export function getActiveObjectivesForDifficulty(manifest, locationId, difficult
|
|
|
171
171
|
* Evaluates effective completion status for a stage goal, honoring direct `state.objectives[obj.id]`
|
|
172
172
|
* as well as live inventory/flag completion rules (`completedByItems` / `completedByFlags`) in non-randomizer runs.
|
|
173
173
|
*/
|
|
174
|
-
export function getObjectiveStatus(obj, state
|
|
174
|
+
export function getObjectiveStatus(obj, state,
|
|
175
|
+
/** item locations randomised (`variantShuffling` is `shuffled`): holding an item proves nothing */
|
|
176
|
+
shuffled) {
|
|
175
177
|
if (!state)
|
|
176
178
|
return 'incomplete';
|
|
177
179
|
const direct = state.objectives[obj.id];
|
|
178
180
|
if (direct === 'complete' || direct === 'failed') {
|
|
179
181
|
return direct;
|
|
180
182
|
}
|
|
181
|
-
if (
|
|
183
|
+
if (!shuffled) {
|
|
182
184
|
if (obj.completedByItems &&
|
|
183
185
|
obj.completedByItems.length > 0 &&
|
|
184
186
|
obj.completedByItems.every(id => state.inventory.includes(id))) {
|
package/lib/pack.d.ts
CHANGED
|
@@ -37,18 +37,24 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
37
37
|
icon: z.ZodOptional<z.ZodString>;
|
|
38
38
|
max: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
39
39
|
display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
40
|
+
role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
|
|
41
|
+
format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
|
|
40
42
|
}, "strict", z.ZodTypeAny, {
|
|
41
43
|
label: string;
|
|
42
44
|
id: string;
|
|
43
45
|
icon?: string | undefined;
|
|
44
46
|
max?: string | number | undefined;
|
|
45
47
|
display?: Record<string, string> | undefined;
|
|
48
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
49
|
+
format?: "number" | "percent" | undefined;
|
|
46
50
|
}, {
|
|
47
51
|
label: string;
|
|
48
52
|
id: string;
|
|
49
53
|
icon?: string | undefined;
|
|
50
54
|
max?: string | number | undefined;
|
|
51
55
|
display?: Record<string, string> | undefined;
|
|
56
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
57
|
+
format?: "number" | "percent" | undefined;
|
|
52
58
|
}>, "many">;
|
|
53
59
|
flagSets: z.ZodArray<z.ZodString, "many">;
|
|
54
60
|
inventoryLayouts: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
@@ -434,6 +440,19 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
434
440
|
shownByDefault: boolean;
|
|
435
441
|
icon?: string | undefined;
|
|
436
442
|
}>, "many">>;
|
|
443
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
444
|
+
id: z.ZodString;
|
|
445
|
+
label: z.ZodString;
|
|
446
|
+
shuffled: z.ZodOptional<z.ZodBoolean>;
|
|
447
|
+
}, "strict", z.ZodTypeAny, {
|
|
448
|
+
label: string;
|
|
449
|
+
id: string;
|
|
450
|
+
shuffled?: boolean | undefined;
|
|
451
|
+
}, {
|
|
452
|
+
label: string;
|
|
453
|
+
id: string;
|
|
454
|
+
shuffled?: boolean | undefined;
|
|
455
|
+
}>, "many">>;
|
|
437
456
|
}, "strict", z.ZodTypeAny, {
|
|
438
457
|
counters: {
|
|
439
458
|
label: string;
|
|
@@ -441,6 +460,8 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
441
460
|
icon?: string | undefined;
|
|
442
461
|
max?: string | number | undefined;
|
|
443
462
|
display?: Record<string, string> | undefined;
|
|
463
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
464
|
+
format?: "number" | "percent" | undefined;
|
|
444
465
|
}[];
|
|
445
466
|
flagSets: string[];
|
|
446
467
|
items: {
|
|
@@ -546,6 +567,11 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
546
567
|
shownByDefault: boolean;
|
|
547
568
|
icon?: string | undefined;
|
|
548
569
|
}[] | undefined;
|
|
570
|
+
variants?: {
|
|
571
|
+
label: string;
|
|
572
|
+
id: string;
|
|
573
|
+
shuffled?: boolean | undefined;
|
|
574
|
+
}[] | undefined;
|
|
549
575
|
}, {
|
|
550
576
|
counters: {
|
|
551
577
|
label: string;
|
|
@@ -553,6 +579,8 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
553
579
|
icon?: string | undefined;
|
|
554
580
|
max?: string | number | undefined;
|
|
555
581
|
display?: Record<string, string> | undefined;
|
|
582
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
583
|
+
format?: "number" | "percent" | undefined;
|
|
556
584
|
}[];
|
|
557
585
|
flagSets: string[];
|
|
558
586
|
items: {
|
|
@@ -658,6 +686,11 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
658
686
|
shownByDefault: boolean;
|
|
659
687
|
icon?: string | undefined;
|
|
660
688
|
}[] | undefined;
|
|
689
|
+
variants?: {
|
|
690
|
+
label: string;
|
|
691
|
+
id: string;
|
|
692
|
+
shuffled?: boolean | undefined;
|
|
693
|
+
}[] | undefined;
|
|
661
694
|
}>;
|
|
662
695
|
/** Scale of the game's world coordinates, for distances shown to the player and the AI. */
|
|
663
696
|
world: z.ZodObject<{
|
|
@@ -685,6 +718,8 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
685
718
|
icon?: string | undefined;
|
|
686
719
|
max?: string | number | undefined;
|
|
687
720
|
display?: Record<string, string> | undefined;
|
|
721
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
722
|
+
format?: "number" | "percent" | undefined;
|
|
688
723
|
}[];
|
|
689
724
|
flagSets: string[];
|
|
690
725
|
items: {
|
|
@@ -790,6 +825,11 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
790
825
|
shownByDefault: boolean;
|
|
791
826
|
icon?: string | undefined;
|
|
792
827
|
}[] | undefined;
|
|
828
|
+
variants?: {
|
|
829
|
+
label: string;
|
|
830
|
+
id: string;
|
|
831
|
+
shuffled?: boolean | undefined;
|
|
832
|
+
}[] | undefined;
|
|
793
833
|
};
|
|
794
834
|
}, {
|
|
795
835
|
id: string;
|
|
@@ -805,6 +845,8 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
805
845
|
icon?: string | undefined;
|
|
806
846
|
max?: string | number | undefined;
|
|
807
847
|
display?: Record<string, string> | undefined;
|
|
848
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
849
|
+
format?: "number" | "percent" | undefined;
|
|
808
850
|
}[];
|
|
809
851
|
flagSets: string[];
|
|
810
852
|
items: {
|
|
@@ -910,6 +952,11 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
910
952
|
shownByDefault: boolean;
|
|
911
953
|
icon?: string | undefined;
|
|
912
954
|
}[] | undefined;
|
|
955
|
+
variants?: {
|
|
956
|
+
label: string;
|
|
957
|
+
id: string;
|
|
958
|
+
shuffled?: boolean | undefined;
|
|
959
|
+
}[] | undefined;
|
|
913
960
|
};
|
|
914
961
|
}>;
|
|
915
962
|
export type PackData = z.infer<typeof PackDataSchema>;
|
package/lib/plugin/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AssetList, AssetOutput, Bytes, GameCapability, GamePack, GameState, InputFile, InputPick } from '../index.js';
|
|
1
|
+
import type { AssetList, AssetOutput, Bytes, GameCapability, GamePack, GameState, InputFile, InputPick, Signature } from '../index.js';
|
|
2
2
|
/**
|
|
3
3
|
* What a plugin may do with the matched game's memory: read it, and nothing else. The core opens
|
|
4
4
|
* and closes the process; a plugin never sees a pid, a path or a file handle.
|
|
@@ -15,6 +15,12 @@ export interface GameMemory {
|
|
|
15
15
|
resolveSymbol(name: string): bigint | null;
|
|
16
16
|
/** Re-read the process's memory map (after a level load moves heap regions). */
|
|
17
17
|
refreshMappings(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Where a byte pattern in the game's own executable points (issue #14): null when it isn't
|
|
20
|
+
* there; throws when it matches more than once. Run once per session and cached by the core.
|
|
21
|
+
* Absent on cores before sdk 0.3.6 and for memory without an executable image (emulators).
|
|
22
|
+
*/
|
|
23
|
+
scan?(signature: Signature): bigint | null;
|
|
18
24
|
}
|
|
19
25
|
/** A memory-read state source for one game. Packs export theirs from games/<id>/source.ts. */
|
|
20
26
|
export interface GamePlugin {
|
|
@@ -14,6 +14,10 @@ function memoryFor(host, handle, info) {
|
|
|
14
14
|
return at === null ? null : BigInt(at);
|
|
15
15
|
},
|
|
16
16
|
refreshMappings: () => host.refreshMappings(handle),
|
|
17
|
+
scan: signature => {
|
|
18
|
+
const at = host.scan(handle, JSON.stringify(signature));
|
|
19
|
+
return at === null ? null : BigInt(at);
|
|
20
|
+
},
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
function describe(plugin) {
|
package/lib/plugins-api.d.ts
CHANGED
|
@@ -131,6 +131,8 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
131
131
|
total: z.ZodNumber;
|
|
132
132
|
done: z.ZodNumber;
|
|
133
133
|
built: z.ZodNumber;
|
|
134
|
+
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
135
|
+
upToDate: z.ZodNumber;
|
|
134
136
|
failed: z.ZodNumber;
|
|
135
137
|
current: z.ZodOptional<z.ZodString>;
|
|
136
138
|
notes: z.ZodArray<z.ZodString, "many">;
|
|
@@ -155,6 +157,7 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
155
157
|
folder: string;
|
|
156
158
|
total: number;
|
|
157
159
|
built: number;
|
|
160
|
+
upToDate: number;
|
|
158
161
|
failures: {
|
|
159
162
|
label: string;
|
|
160
163
|
error: string;
|
|
@@ -171,6 +174,7 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
171
174
|
folder: string;
|
|
172
175
|
total: number;
|
|
173
176
|
built: number;
|
|
177
|
+
upToDate: number;
|
|
174
178
|
failures: {
|
|
175
179
|
label: string;
|
|
176
180
|
error: string;
|
|
@@ -310,6 +314,8 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
310
314
|
total: z.ZodNumber;
|
|
311
315
|
done: z.ZodNumber;
|
|
312
316
|
built: z.ZodNumber;
|
|
317
|
+
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
318
|
+
upToDate: z.ZodNumber;
|
|
313
319
|
failed: z.ZodNumber;
|
|
314
320
|
current: z.ZodOptional<z.ZodString>;
|
|
315
321
|
notes: z.ZodArray<z.ZodString, "many">;
|
|
@@ -334,6 +340,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
334
340
|
folder: string;
|
|
335
341
|
total: number;
|
|
336
342
|
built: number;
|
|
343
|
+
upToDate: number;
|
|
337
344
|
failures: {
|
|
338
345
|
label: string;
|
|
339
346
|
error: string;
|
|
@@ -350,6 +357,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
350
357
|
folder: string;
|
|
351
358
|
total: number;
|
|
352
359
|
built: number;
|
|
360
|
+
upToDate: number;
|
|
353
361
|
failures: {
|
|
354
362
|
label: string;
|
|
355
363
|
error: string;
|
|
@@ -392,6 +400,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
392
400
|
folder: string;
|
|
393
401
|
total: number;
|
|
394
402
|
built: number;
|
|
403
|
+
upToDate: number;
|
|
395
404
|
failures: {
|
|
396
405
|
label: string;
|
|
397
406
|
error: string;
|
|
@@ -434,6 +443,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
434
443
|
folder: string;
|
|
435
444
|
total: number;
|
|
436
445
|
built: number;
|
|
446
|
+
upToDate: number;
|
|
437
447
|
failures: {
|
|
438
448
|
label: string;
|
|
439
449
|
error: string;
|
package/lib/plugins-api.js
CHANGED
|
@@ -26,6 +26,8 @@ export const JobStatusSchema = z.object({
|
|
|
26
26
|
total: z.number().int(),
|
|
27
27
|
done: z.number().int(),
|
|
28
28
|
built: z.number().int(),
|
|
29
|
+
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
30
|
+
upToDate: z.number().int(),
|
|
29
31
|
failed: z.number().int(),
|
|
30
32
|
current: z.string().optional(),
|
|
31
33
|
notes: z.array(z.string()),
|
|
@@ -85,18 +85,24 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
85
85
|
icon: z.ZodOptional<z.ZodString>;
|
|
86
86
|
max: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
87
87
|
display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
88
|
+
role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
|
|
89
|
+
format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
|
|
88
90
|
}, "strict", z.ZodTypeAny, {
|
|
89
91
|
label: string;
|
|
90
92
|
id: string;
|
|
91
93
|
icon?: string | undefined;
|
|
92
94
|
max?: string | number | undefined;
|
|
93
95
|
display?: Record<string, string> | undefined;
|
|
96
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
97
|
+
format?: "number" | "percent" | undefined;
|
|
94
98
|
}, {
|
|
95
99
|
label: string;
|
|
96
100
|
id: string;
|
|
97
101
|
icon?: string | undefined;
|
|
98
102
|
max?: string | number | undefined;
|
|
99
103
|
display?: Record<string, string> | undefined;
|
|
104
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
105
|
+
format?: "number" | "percent" | undefined;
|
|
100
106
|
}>, "many">;
|
|
101
107
|
flagSets: z.ZodArray<z.ZodString, "many">;
|
|
102
108
|
inventoryLayouts: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
@@ -482,6 +488,19 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
482
488
|
shownByDefault: boolean;
|
|
483
489
|
icon?: string | undefined;
|
|
484
490
|
}>, "many">>;
|
|
491
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
492
|
+
id: z.ZodString;
|
|
493
|
+
label: z.ZodString;
|
|
494
|
+
shuffled: z.ZodOptional<z.ZodBoolean>;
|
|
495
|
+
}, "strict", z.ZodTypeAny, {
|
|
496
|
+
label: string;
|
|
497
|
+
id: string;
|
|
498
|
+
shuffled?: boolean | undefined;
|
|
499
|
+
}, {
|
|
500
|
+
label: string;
|
|
501
|
+
id: string;
|
|
502
|
+
shuffled?: boolean | undefined;
|
|
503
|
+
}>, "many">>;
|
|
485
504
|
}, "strict", z.ZodTypeAny, {
|
|
486
505
|
counters: {
|
|
487
506
|
label: string;
|
|
@@ -489,6 +508,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
489
508
|
icon?: string | undefined;
|
|
490
509
|
max?: string | number | undefined;
|
|
491
510
|
display?: Record<string, string> | undefined;
|
|
511
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
512
|
+
format?: "number" | "percent" | undefined;
|
|
492
513
|
}[];
|
|
493
514
|
flagSets: string[];
|
|
494
515
|
items: {
|
|
@@ -594,6 +615,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
594
615
|
shownByDefault: boolean;
|
|
595
616
|
icon?: string | undefined;
|
|
596
617
|
}[] | undefined;
|
|
618
|
+
variants?: {
|
|
619
|
+
label: string;
|
|
620
|
+
id: string;
|
|
621
|
+
shuffled?: boolean | undefined;
|
|
622
|
+
}[] | undefined;
|
|
597
623
|
}, {
|
|
598
624
|
counters: {
|
|
599
625
|
label: string;
|
|
@@ -601,6 +627,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
601
627
|
icon?: string | undefined;
|
|
602
628
|
max?: string | number | undefined;
|
|
603
629
|
display?: Record<string, string> | undefined;
|
|
630
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
631
|
+
format?: "number" | "percent" | undefined;
|
|
604
632
|
}[];
|
|
605
633
|
flagSets: string[];
|
|
606
634
|
items: {
|
|
@@ -706,6 +734,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
706
734
|
shownByDefault: boolean;
|
|
707
735
|
icon?: string | undefined;
|
|
708
736
|
}[] | undefined;
|
|
737
|
+
variants?: {
|
|
738
|
+
label: string;
|
|
739
|
+
id: string;
|
|
740
|
+
shuffled?: boolean | undefined;
|
|
741
|
+
}[] | undefined;
|
|
709
742
|
}>;
|
|
710
743
|
world: z.ZodObject<{
|
|
711
744
|
unitsPerMeter: z.ZodNumber;
|
|
@@ -731,6 +764,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
731
764
|
icon?: string | undefined;
|
|
732
765
|
max?: string | number | undefined;
|
|
733
766
|
display?: Record<string, string> | undefined;
|
|
767
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
768
|
+
format?: "number" | "percent" | undefined;
|
|
734
769
|
}[];
|
|
735
770
|
flagSets: string[];
|
|
736
771
|
items: {
|
|
@@ -836,6 +871,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
836
871
|
shownByDefault: boolean;
|
|
837
872
|
icon?: string | undefined;
|
|
838
873
|
}[] | undefined;
|
|
874
|
+
variants?: {
|
|
875
|
+
label: string;
|
|
876
|
+
id: string;
|
|
877
|
+
shuffled?: boolean | undefined;
|
|
878
|
+
}[] | undefined;
|
|
839
879
|
};
|
|
840
880
|
}, {
|
|
841
881
|
id: string;
|
|
@@ -851,6 +891,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
851
891
|
icon?: string | undefined;
|
|
852
892
|
max?: string | number | undefined;
|
|
853
893
|
display?: Record<string, string> | undefined;
|
|
894
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
895
|
+
format?: "number" | "percent" | undefined;
|
|
854
896
|
}[];
|
|
855
897
|
flagSets: string[];
|
|
856
898
|
items: {
|
|
@@ -956,6 +998,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
956
998
|
shownByDefault: boolean;
|
|
957
999
|
icon?: string | undefined;
|
|
958
1000
|
}[] | undefined;
|
|
1001
|
+
variants?: {
|
|
1002
|
+
label: string;
|
|
1003
|
+
id: string;
|
|
1004
|
+
shuffled?: boolean | undefined;
|
|
1005
|
+
}[] | undefined;
|
|
959
1006
|
};
|
|
960
1007
|
}>, "many">;
|
|
961
1008
|
sources: z.ZodArray<z.ZodObject<{
|
|
@@ -1024,6 +1071,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1024
1071
|
icon?: string | undefined;
|
|
1025
1072
|
max?: string | number | undefined;
|
|
1026
1073
|
display?: Record<string, string> | undefined;
|
|
1074
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1075
|
+
format?: "number" | "percent" | undefined;
|
|
1027
1076
|
}[];
|
|
1028
1077
|
flagSets: string[];
|
|
1029
1078
|
items: {
|
|
@@ -1129,6 +1178,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1129
1178
|
shownByDefault: boolean;
|
|
1130
1179
|
icon?: string | undefined;
|
|
1131
1180
|
}[] | undefined;
|
|
1181
|
+
variants?: {
|
|
1182
|
+
label: string;
|
|
1183
|
+
id: string;
|
|
1184
|
+
shuffled?: boolean | undefined;
|
|
1185
|
+
}[] | undefined;
|
|
1132
1186
|
};
|
|
1133
1187
|
}[];
|
|
1134
1188
|
sources: {
|
|
@@ -1161,6 +1215,8 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1161
1215
|
icon?: string | undefined;
|
|
1162
1216
|
max?: string | number | undefined;
|
|
1163
1217
|
display?: Record<string, string> | undefined;
|
|
1218
|
+
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1219
|
+
format?: "number" | "percent" | undefined;
|
|
1164
1220
|
}[];
|
|
1165
1221
|
flagSets: string[];
|
|
1166
1222
|
items: {
|
|
@@ -1266,6 +1322,11 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1266
1322
|
shownByDefault: boolean;
|
|
1267
1323
|
icon?: string | undefined;
|
|
1268
1324
|
}[] | undefined;
|
|
1325
|
+
variants?: {
|
|
1326
|
+
label: string;
|
|
1327
|
+
id: string;
|
|
1328
|
+
shuffled?: boolean | undefined;
|
|
1329
|
+
}[] | undefined;
|
|
1269
1330
|
};
|
|
1270
1331
|
}[];
|
|
1271
1332
|
sources: {
|
|
@@ -1317,6 +1378,8 @@ export interface SandboxHostApi {
|
|
|
1317
1378
|
isValidRange(handle: number, address: string, byteLength: number): boolean;
|
|
1318
1379
|
resolveSymbol(handle: number, name: string): string | null;
|
|
1319
1380
|
refreshMappings(handle: number): void;
|
|
1381
|
+
/** a signature scan (JSON of a Signature); the address as a decimal string, or null */
|
|
1382
|
+
scan(handle: number, signature: string): string | null;
|
|
1320
1383
|
}
|
|
1321
1384
|
/** A player's file as the asset guest sees it: a handle for `inputRead`, its name and size. */
|
|
1322
1385
|
export declare const SandboxInputFileSchema: z.ZodObject<{
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const SignatureSchema: z.ZodEffects<z.ZodObject<{
|
|
3
|
+
pattern: z.ZodEffects<z.ZodString, string, string>;
|
|
4
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
kind: z.ZodEnum<["match", "rip32", "abs32", "abs64"]>;
|
|
6
|
+
instructionEnd: z.ZodDefault<z.ZodNumber>;
|
|
7
|
+
}, "strict", z.ZodTypeAny, {
|
|
8
|
+
kind: "match" | "rip32" | "abs32" | "abs64";
|
|
9
|
+
pattern: string;
|
|
10
|
+
offset: number;
|
|
11
|
+
instructionEnd: number;
|
|
12
|
+
}, {
|
|
13
|
+
kind: "match" | "rip32" | "abs32" | "abs64";
|
|
14
|
+
pattern: string;
|
|
15
|
+
offset?: number | undefined;
|
|
16
|
+
instructionEnd?: number | undefined;
|
|
17
|
+
}>, {
|
|
18
|
+
kind: "match" | "rip32" | "abs32" | "abs64";
|
|
19
|
+
pattern: string;
|
|
20
|
+
offset: number;
|
|
21
|
+
instructionEnd: number;
|
|
22
|
+
}, {
|
|
23
|
+
kind: "match" | "rip32" | "abs32" | "abs64";
|
|
24
|
+
pattern: string;
|
|
25
|
+
offset?: number | undefined;
|
|
26
|
+
instructionEnd?: number | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export type Signature = z.input<typeof SignatureSchema>;
|
|
29
|
+
export type ParsedSignature = z.output<typeof SignatureSchema>;
|
|
30
|
+
/** A pattern as bytes and which of them must match. */
|
|
31
|
+
export declare function parsePattern(pattern: string): {
|
|
32
|
+
bytes: Uint8Array;
|
|
33
|
+
fixed: boolean[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Every offset in `haystack` where the pattern matches (at most `limit`). The first byte is
|
|
37
|
+
* fixed (the schema insists), so the native indexOf finds candidates.
|
|
38
|
+
*/
|
|
39
|
+
export declare function findPattern(haystack: Uint8Array, pattern: string, limit?: number): number[];
|
|
40
|
+
/** How many bytes past the field `resolveSignature` needs to read. */
|
|
41
|
+
export declare function fieldBytes(sig: ParsedSignature): number;
|
|
42
|
+
/**
|
|
43
|
+
* The address a match points to. `fieldAddress` is match + offset; `field` holds the bytes there
|
|
44
|
+
* (little-endian, `fieldBytes(sig)` of them).
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveSignature(sig: ParsedSignature, fieldAddress: bigint, field: Uint8Array): bigint;
|
package/lib/signature.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/*
|
|
3
|
+
* Signature scans (issue #14): finding where a closed-source game keeps something by a byte
|
|
4
|
+
* pattern in its code, so a plugin survives patches and store versions instead of hard-coding an
|
|
5
|
+
* address. The core runs the scan over the game's executable image; this module is the pure part
|
|
6
|
+
* (patterns, matching, and turning a match into an address) shared by the core and tests.
|
|
7
|
+
*
|
|
8
|
+
* pattern "48 8B 05 ?? ?? ?? ??" hex bytes, `??` for any byte
|
|
9
|
+
* offset bytes from the match's start to the field of interest
|
|
10
|
+
* kind what the field is:
|
|
11
|
+
* match the field's own address
|
|
12
|
+
* rip32 a 32-bit displacement relative to the end of the instruction (x86-64 RIP
|
|
13
|
+
* addressing); `instructionEnd` counts any bytes after the displacement (an
|
|
14
|
+
* immediate) that still belong to the instruction
|
|
15
|
+
* abs32 / abs64 an absolute pointer stored there
|
|
16
|
+
*/
|
|
17
|
+
const PATTERN_RE = /^(?:[0-9A-Fa-f]{2}|\?\?)(?: (?:[0-9A-Fa-f]{2}|\?\?))*$/;
|
|
18
|
+
/* Long enough to be unique in a game's code, short enough to read in one go. */
|
|
19
|
+
const MAX_PATTERN_BYTES = 64;
|
|
20
|
+
export const SignatureSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
pattern: z
|
|
23
|
+
.string()
|
|
24
|
+
.regex(PATTERN_RE, 'hex bytes separated by spaces, ?? for any byte')
|
|
25
|
+
.refine(p => !p.startsWith('??'), 'must start with a fixed byte'),
|
|
26
|
+
offset: z.number().int().min(-4096).max(4096).default(0),
|
|
27
|
+
kind: z.enum(['match', 'rip32', 'abs32', 'abs64']),
|
|
28
|
+
instructionEnd: z.number().int().min(0).max(16).default(0),
|
|
29
|
+
})
|
|
30
|
+
.strict()
|
|
31
|
+
.refine(s => s.pattern.split(' ').length <= MAX_PATTERN_BYTES, 'pattern is too long');
|
|
32
|
+
/** A pattern as bytes and which of them must match. */
|
|
33
|
+
export function parsePattern(pattern) {
|
|
34
|
+
const tokens = pattern.split(' ');
|
|
35
|
+
return {
|
|
36
|
+
bytes: Uint8Array.from(tokens, t => (t === '??' ? 0 : parseInt(t, 16))),
|
|
37
|
+
fixed: tokens.map(t => t !== '??'),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every offset in `haystack` where the pattern matches (at most `limit`). The first byte is
|
|
42
|
+
* fixed (the schema insists), so the native indexOf finds candidates.
|
|
43
|
+
*/
|
|
44
|
+
export function findPattern(haystack, pattern, limit = 2) {
|
|
45
|
+
const { bytes, fixed } = parsePattern(pattern);
|
|
46
|
+
const first = bytes[0] ?? 0;
|
|
47
|
+
const hits = [];
|
|
48
|
+
for (let i = haystack.indexOf(first); i >= 0 && i + bytes.length <= haystack.length; i = haystack.indexOf(first, i + 1)) {
|
|
49
|
+
let k = 1;
|
|
50
|
+
while (k < bytes.length && (!fixed[k] || haystack[i + k] === bytes[k]))
|
|
51
|
+
k++;
|
|
52
|
+
if (k === bytes.length) {
|
|
53
|
+
hits.push(i);
|
|
54
|
+
if (hits.length >= limit)
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return hits;
|
|
59
|
+
}
|
|
60
|
+
/** How many bytes past the field `resolveSignature` needs to read. */
|
|
61
|
+
export function fieldBytes(sig) {
|
|
62
|
+
return sig.kind === 'abs64' ? 8 : sig.kind === 'match' ? 0 : 4;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The address a match points to. `fieldAddress` is match + offset; `field` holds the bytes there
|
|
66
|
+
* (little-endian, `fieldBytes(sig)` of them).
|
|
67
|
+
*/
|
|
68
|
+
export function resolveSignature(sig, fieldAddress, field) {
|
|
69
|
+
const view = new DataView(field.buffer, field.byteOffset, field.byteLength);
|
|
70
|
+
switch (sig.kind) {
|
|
71
|
+
case 'match':
|
|
72
|
+
return fieldAddress;
|
|
73
|
+
case 'rip32':
|
|
74
|
+
return fieldAddress + 4n + BigInt(sig.instructionEnd) + BigInt(view.getInt32(0, true));
|
|
75
|
+
case 'abs32':
|
|
76
|
+
return BigInt(view.getUint32(0, true));
|
|
77
|
+
case 'abs64':
|
|
78
|
+
return view.getBigUint64(0, true);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/lib/status.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Catalogue, CatalogueCounter, CatalogueMission, CollectibleEntry, ReferenceEntry } from './catalogue.js';
|
|
1
|
+
import type { Catalogue, CatalogueCounter, CounterRole, CatalogueMission, CollectibleEntry, ReferenceEntry } from './catalogue.js';
|
|
2
2
|
import type { EvaluationContext } from './condition.js';
|
|
3
3
|
import type { GameState } from './types.js';
|
|
4
4
|
/** Context whose `{ mission }` conditions resolve against this catalogue (cycles → unknown). */
|
|
@@ -22,3 +22,16 @@ export interface CounterView {
|
|
|
22
22
|
}
|
|
23
23
|
/** Counter value + display text; null when the counter isn't streamed (unknown, not zero). */
|
|
24
24
|
export declare function getCounterView(counter: CatalogueCounter, state: GameState): CounterView | null;
|
|
25
|
+
/** The pack's counter with this role and its value now, or undefined (no such counter, or unread). */
|
|
26
|
+
export declare function counterByRole(catalogue: Catalogue | undefined, state: GameState, role: CounterRole): (CounterView & {
|
|
27
|
+
counter: CatalogueCounter;
|
|
28
|
+
fraction: number | null;
|
|
29
|
+
}) | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Whether item locations are randomised, so curated hints and item-based objective checks don't
|
|
32
|
+
* hold. A declared variant says so itself. With no catalogue yet (the pack is loading) or a
|
|
33
|
+
* variant it doesn't declare, it's `unknown`: withhold hints (no vanilla spoiler slips through),
|
|
34
|
+
* but don't call an item-completed objective incomplete or tell the AI items are shuffled.
|
|
35
|
+
*/
|
|
36
|
+
export declare function variantShuffling(state: GameState, catalogue: Catalogue | undefined): VariantShuffling;
|
|
37
|
+
export type VariantShuffling = 'shuffled' | 'plain' | 'unknown';
|
package/lib/status.js
CHANGED
|
@@ -69,7 +69,37 @@ export function getCounterView(counter, state) {
|
|
|
69
69
|
: counter.max
|
|
70
70
|
? (readCounter(state, counter.max) ?? null)
|
|
71
71
|
: null;
|
|
72
|
+
if (counter.format === 'percent') {
|
|
73
|
+
/* no max declared: the value is already a 0..1 share. A declared max that's unread or
|
|
74
|
+
* not positive leaves the share unknown, so the counter isn't shown. */
|
|
75
|
+
const of = counter.max === undefined ? 1 : max;
|
|
76
|
+
if (of === null || of <= 0)
|
|
77
|
+
return null;
|
|
78
|
+
return { value, text: `${Math.round((value / of) * 100)}%`, max: of };
|
|
79
|
+
}
|
|
72
80
|
const mapped = counter.display?.[String(value)];
|
|
73
81
|
const text = mapped ?? (max !== null ? `${value}/${max}` : String(value));
|
|
74
82
|
return { value, text, max };
|
|
75
83
|
}
|
|
84
|
+
/** The pack's counter with this role and its value now, or undefined (no such counter, or unread). */
|
|
85
|
+
export function counterByRole(catalogue, state, role) {
|
|
86
|
+
const counter = catalogue?.counters.find(c => c.role === role);
|
|
87
|
+
const view = counter && getCounterView(counter, state);
|
|
88
|
+
if (!counter || !view)
|
|
89
|
+
return undefined;
|
|
90
|
+
return { ...view, counter, fraction: view.max ? view.value / view.max : null };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Whether item locations are randomised, so curated hints and item-based objective checks don't
|
|
94
|
+
* hold. A declared variant says so itself. With no catalogue yet (the pack is loading) or a
|
|
95
|
+
* variant it doesn't declare, it's `unknown`: withhold hints (no vanilla spoiler slips through),
|
|
96
|
+
* but don't call an item-completed objective incomplete or tell the AI items are shuffled.
|
|
97
|
+
*/
|
|
98
|
+
export function variantShuffling(state, catalogue) {
|
|
99
|
+
if (state.variant === undefined)
|
|
100
|
+
return 'plain';
|
|
101
|
+
const declared = catalogue?.variants?.find(v => v.id === state.variant);
|
|
102
|
+
if (!declared)
|
|
103
|
+
return 'unknown';
|
|
104
|
+
return declared.shuffled === true ? 'shuffled' : 'plain';
|
|
105
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -119,7 +119,8 @@ export declare const GameStateSchema: z.ZodObject<{
|
|
|
119
119
|
}>;
|
|
120
120
|
locationId: z.ZodString;
|
|
121
121
|
difficulty: z.ZodOptional<z.ZodString>;
|
|
122
|
-
|
|
122
|
+
/** one of the pack's declared variants (catalogue `variants`) */
|
|
123
|
+
variant: z.ZodOptional<z.ZodString>;
|
|
123
124
|
position: z.ZodNullable<z.ZodObject<{
|
|
124
125
|
x: z.ZodNumber;
|
|
125
126
|
y: z.ZodNumber;
|
|
@@ -229,7 +230,7 @@ export declare const GameStateSchema: z.ZodObject<{
|
|
|
229
230
|
flags: Record<string, boolean>;
|
|
230
231
|
stats?: Record<string, number> | undefined;
|
|
231
232
|
difficulty?: string | undefined;
|
|
232
|
-
variant?:
|
|
233
|
+
variant?: string | undefined;
|
|
233
234
|
enemies?: {
|
|
234
235
|
label: string;
|
|
235
236
|
id: string;
|
|
@@ -275,7 +276,7 @@ export declare const GameStateSchema: z.ZodObject<{
|
|
|
275
276
|
flags: Record<string, boolean>;
|
|
276
277
|
stats?: Record<string, number> | undefined;
|
|
277
278
|
difficulty?: string | undefined;
|
|
278
|
-
variant?:
|
|
279
|
+
variant?: string | undefined;
|
|
279
280
|
enemies?: {
|
|
280
281
|
label: string;
|
|
281
282
|
id: string;
|
|
@@ -1048,7 +1049,8 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1048
1049
|
}>;
|
|
1049
1050
|
locationId: z.ZodString;
|
|
1050
1051
|
difficulty: z.ZodOptional<z.ZodString>;
|
|
1051
|
-
|
|
1052
|
+
/** one of the pack's declared variants (catalogue `variants`) */
|
|
1053
|
+
variant: z.ZodOptional<z.ZodString>;
|
|
1052
1054
|
position: z.ZodNullable<z.ZodObject<{
|
|
1053
1055
|
x: z.ZodNumber;
|
|
1054
1056
|
y: z.ZodNumber;
|
|
@@ -1158,7 +1160,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1158
1160
|
flags: Record<string, boolean>;
|
|
1159
1161
|
stats?: Record<string, number> | undefined;
|
|
1160
1162
|
difficulty?: string | undefined;
|
|
1161
|
-
variant?:
|
|
1163
|
+
variant?: string | undefined;
|
|
1162
1164
|
enemies?: {
|
|
1163
1165
|
label: string;
|
|
1164
1166
|
id: string;
|
|
@@ -1204,7 +1206,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1204
1206
|
flags: Record<string, boolean>;
|
|
1205
1207
|
stats?: Record<string, number> | undefined;
|
|
1206
1208
|
difficulty?: string | undefined;
|
|
1207
|
-
variant?:
|
|
1209
|
+
variant?: string | undefined;
|
|
1208
1210
|
enemies?: {
|
|
1209
1211
|
label: string;
|
|
1210
1212
|
id: string;
|
|
@@ -1253,7 +1255,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1253
1255
|
flags: Record<string, boolean>;
|
|
1254
1256
|
stats?: Record<string, number> | undefined;
|
|
1255
1257
|
difficulty?: string | undefined;
|
|
1256
|
-
variant?:
|
|
1258
|
+
variant?: string | undefined;
|
|
1257
1259
|
enemies?: {
|
|
1258
1260
|
label: string;
|
|
1259
1261
|
id: string;
|
|
@@ -1302,7 +1304,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1302
1304
|
flags: Record<string, boolean>;
|
|
1303
1305
|
stats?: Record<string, number> | undefined;
|
|
1304
1306
|
difficulty?: string | undefined;
|
|
1305
|
-
variant?:
|
|
1307
|
+
variant?: string | undefined;
|
|
1306
1308
|
enemies?: {
|
|
1307
1309
|
label: string;
|
|
1308
1310
|
id: string;
|
|
@@ -1423,7 +1425,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1423
1425
|
flags: Record<string, boolean>;
|
|
1424
1426
|
stats?: Record<string, number> | undefined;
|
|
1425
1427
|
difficulty?: string | undefined;
|
|
1426
|
-
variant?:
|
|
1428
|
+
variant?: string | undefined;
|
|
1427
1429
|
enemies?: {
|
|
1428
1430
|
label: string;
|
|
1429
1431
|
id: string;
|
|
@@ -1544,7 +1546,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1544
1546
|
flags: Record<string, boolean>;
|
|
1545
1547
|
stats?: Record<string, number> | undefined;
|
|
1546
1548
|
difficulty?: string | undefined;
|
|
1547
|
-
variant?:
|
|
1549
|
+
variant?: string | undefined;
|
|
1548
1550
|
enemies?: {
|
|
1549
1551
|
label: string;
|
|
1550
1552
|
id: string;
|
|
@@ -1597,7 +1599,8 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1597
1599
|
}>;
|
|
1598
1600
|
locationId: z.ZodString;
|
|
1599
1601
|
difficulty: z.ZodOptional<z.ZodString>;
|
|
1600
|
-
|
|
1602
|
+
/** one of the pack's declared variants (catalogue `variants`) */
|
|
1603
|
+
variant: z.ZodOptional<z.ZodString>;
|
|
1601
1604
|
position: z.ZodNullable<z.ZodObject<{
|
|
1602
1605
|
x: z.ZodNumber;
|
|
1603
1606
|
y: z.ZodNumber;
|
|
@@ -1707,7 +1710,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1707
1710
|
flags: Record<string, boolean>;
|
|
1708
1711
|
stats?: Record<string, number> | undefined;
|
|
1709
1712
|
difficulty?: string | undefined;
|
|
1710
|
-
variant?:
|
|
1713
|
+
variant?: string | undefined;
|
|
1711
1714
|
enemies?: {
|
|
1712
1715
|
label: string;
|
|
1713
1716
|
id: string;
|
|
@@ -1753,7 +1756,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1753
1756
|
flags: Record<string, boolean>;
|
|
1754
1757
|
stats?: Record<string, number> | undefined;
|
|
1755
1758
|
difficulty?: string | undefined;
|
|
1756
|
-
variant?:
|
|
1759
|
+
variant?: string | undefined;
|
|
1757
1760
|
enemies?: {
|
|
1758
1761
|
label: string;
|
|
1759
1762
|
id: string;
|
|
@@ -1807,7 +1810,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1807
1810
|
flags: Record<string, boolean>;
|
|
1808
1811
|
stats?: Record<string, number> | undefined;
|
|
1809
1812
|
difficulty?: string | undefined;
|
|
1810
|
-
variant?:
|
|
1813
|
+
variant?: string | undefined;
|
|
1811
1814
|
enemies?: {
|
|
1812
1815
|
label: string;
|
|
1813
1816
|
id: string;
|
|
@@ -1862,7 +1865,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
1862
1865
|
flags: Record<string, boolean>;
|
|
1863
1866
|
stats?: Record<string, number> | undefined;
|
|
1864
1867
|
difficulty?: string | undefined;
|
|
1865
|
-
variant?:
|
|
1868
|
+
variant?: string | undefined;
|
|
1866
1869
|
enemies?: {
|
|
1867
1870
|
label: string;
|
|
1868
1871
|
id: string;
|
|
@@ -2102,7 +2105,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
2102
2105
|
}>>;
|
|
2103
2106
|
locationId: z.ZodOptional<z.ZodString>;
|
|
2104
2107
|
difficulty: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
2105
|
-
variant: z.ZodOptional<z.ZodOptional<z.
|
|
2108
|
+
variant: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
2106
2109
|
position: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
2107
2110
|
x: z.ZodNumber;
|
|
2108
2111
|
y: z.ZodNumber;
|
|
@@ -2201,7 +2204,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
2201
2204
|
} | undefined;
|
|
2202
2205
|
locationId?: string | undefined;
|
|
2203
2206
|
difficulty?: string | undefined;
|
|
2204
|
-
variant?:
|
|
2207
|
+
variant?: string | undefined;
|
|
2205
2208
|
position?: {
|
|
2206
2209
|
x: number;
|
|
2207
2210
|
y: number;
|
|
@@ -2247,7 +2250,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
2247
2250
|
} | undefined;
|
|
2248
2251
|
locationId?: string | undefined;
|
|
2249
2252
|
difficulty?: string | undefined;
|
|
2250
|
-
variant?:
|
|
2253
|
+
variant?: string | undefined;
|
|
2251
2254
|
position?: {
|
|
2252
2255
|
x: number;
|
|
2253
2256
|
y: number;
|
|
@@ -2301,7 +2304,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
2301
2304
|
} | undefined;
|
|
2302
2305
|
locationId?: string | undefined;
|
|
2303
2306
|
difficulty?: string | undefined;
|
|
2304
|
-
variant?:
|
|
2307
|
+
variant?: string | undefined;
|
|
2305
2308
|
position?: {
|
|
2306
2309
|
x: number;
|
|
2307
2310
|
y: number;
|
|
@@ -2355,7 +2358,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
2355
2358
|
} | undefined;
|
|
2356
2359
|
locationId?: string | undefined;
|
|
2357
2360
|
difficulty?: string | undefined;
|
|
2358
|
-
variant?:
|
|
2361
|
+
variant?: string | undefined;
|
|
2359
2362
|
position?: {
|
|
2360
2363
|
x: number;
|
|
2361
2364
|
y: number;
|
package/lib/types.js
CHANGED
|
@@ -48,7 +48,8 @@ export const GameStateSchema = z.object({
|
|
|
48
48
|
provenance: ProvenanceSchema,
|
|
49
49
|
locationId: z.string(),
|
|
50
50
|
difficulty: z.string().optional(),
|
|
51
|
-
|
|
51
|
+
/** one of the pack's declared variants (catalogue `variants`) */
|
|
52
|
+
variant: z.string().min(1).optional(),
|
|
52
53
|
position: Position3DSchema.nullable(),
|
|
53
54
|
enemies: z.array(EnemyActorSchema).optional(),
|
|
54
55
|
npcs: z.array(NpcActorSchema).optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gameslate/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Build plugins for GameSlate, the second-screen companion for PC games: the plugin contract, game-state and catalogue schemas, and the plugin builder.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|