@matchomag/cs2-replay 0.0.0-stage → 0.3.0

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.
Files changed (74) hide show
  1. package/FORMAT.md +350 -0
  2. package/README.md +453 -2
  3. package/bin/demo-replay-darwin-amd64 +0 -0
  4. package/bin/demo-replay-darwin-arm64 +0 -0
  5. package/bin/demo-replay-linux-amd64 +0 -0
  6. package/bin/demo-replay-linux-arm64 +0 -0
  7. package/bin/demo-replay-windows-amd64.exe +0 -0
  8. package/bin/demo-replay.js +22 -0
  9. package/dist/2d/index.js +1 -0
  10. package/dist/3d/index.js +11 -0
  11. package/dist/chunks/actors-EZRYEB4I.js +177 -0
  12. package/dist/chunks/chunk-5BFKVD63.js +1 -0
  13. package/dist/chunks/chunk-D5ST2XVO.js +106 -0
  14. package/dist/chunks/chunk-DQPOBPMK.js +1 -0
  15. package/dist/chunks/chunk-FBSLUYGT.js +1 -0
  16. package/dist/chunks/chunk-Q37CWKZX.js +12 -0
  17. package/dist/chunks/chunk-VSIECNZM.js +1 -0
  18. package/dist/chunks/chunk-YJG3LSSB.js +1 -0
  19. package/dist/chunks/chunk-YO73RW3Y.js +1 -0
  20. package/dist/chunks/look-2WBUGHMJ.js +669 -0
  21. package/dist/index.js +1 -0
  22. package/dist/maps/index.js +1 -0
  23. package/dist/parse/index.js +1 -0
  24. package/dist/parse/wasm/replay.wasm +0 -0
  25. package/dist/parse/worker.js +1 -0
  26. package/dist/types/2d/index.d.ts +17 -0
  27. package/dist/types/2d/radar.d.ts +35 -0
  28. package/dist/types/3d/actors.d.ts +90 -0
  29. package/dist/types/3d/characters/anim.d.ts +93 -0
  30. package/dist/types/3d/characters/ao.d.ts +3 -0
  31. package/dist/types/3d/characters/body.d.ts +37 -0
  32. package/dist/types/3d/characters/builder.d.ts +82 -0
  33. package/dist/types/3d/characters/index.d.ts +74 -0
  34. package/dist/types/3d/characters/rig.d.ts +73 -0
  35. package/dist/types/3d/characters/textures.d.ts +4 -0
  36. package/dist/types/3d/characters/viewmodel.d.ts +51 -0
  37. package/dist/types/3d/characters/weapons.d.ts +25 -0
  38. package/dist/types/3d/follow.d.ts +43 -0
  39. package/dist/types/3d/fx/batch.d.ts +87 -0
  40. package/dist/types/3d/fx/context.d.ts +34 -0
  41. package/dist/types/3d/fx/explosion.d.ts +14 -0
  42. package/dist/types/3d/fx/fire.d.ts +11 -0
  43. package/dist/types/3d/fx/index.d.ts +84 -0
  44. package/dist/types/3d/fx/lights.d.ts +25 -0
  45. package/dist/types/3d/fx/meshes.d.ts +18 -0
  46. package/dist/types/3d/fx/misc.d.ts +15 -0
  47. package/dist/types/3d/fx/random.d.ts +21 -0
  48. package/dist/types/3d/fx/smoke.d.ts +10 -0
  49. package/dist/types/3d/fx/textures.d.ts +29 -0
  50. package/dist/types/3d/fx/types.d.ts +117 -0
  51. package/dist/types/3d/greybox.d.ts +22 -0
  52. package/dist/types/3d/index.d.ts +127 -0
  53. package/dist/types/3d/look.d.ts +49 -0
  54. package/dist/types/3d/markers.d.ts +23 -0
  55. package/dist/types/3d/smoke/volume.d.ts +95 -0
  56. package/dist/types/3d/smoke/voxels.d.ts +87 -0
  57. package/dist/types/3d/world/index.d.ts +179 -0
  58. package/dist/types/3d/world/look.d.ts +16 -0
  59. package/dist/types/3d/world/material.d.ts +128 -0
  60. package/dist/types/3d/world/post.d.ts +75 -0
  61. package/dist/types/3d/world/probes.d.ts +39 -0
  62. package/dist/types/3d/world/release.d.ts +28 -0
  63. package/dist/types/3d/world/stage.d.ts +84 -0
  64. package/dist/types/core/format.d.ts +163 -0
  65. package/dist/types/core/live.d.ts +115 -0
  66. package/dist/types/core/model.d.ts +164 -0
  67. package/dist/types/core/playback.d.ts +82 -0
  68. package/dist/types/core/theme.d.ts +46 -0
  69. package/dist/types/index.d.ts +6 -0
  70. package/dist/types/maps/index.d.ts +258 -0
  71. package/dist/types/parse/index.d.ts +108 -0
  72. package/dist/types/ui/shell.d.ts +131 -0
  73. package/dist/types/ui/styles.d.ts +1 -0
  74. package/package.json +68 -4
@@ -0,0 +1,164 @@
1
+ import { type Replay, type ReplayBombEvent, type ReplayKill, type ReplayRound, type Side } from "./format";
2
+ /** Renderer-agnostic state of a replay at one moment. Positions are game units. */
3
+ export interface Snapshot {
4
+ /** Fractional frame. */
5
+ t: number;
6
+ /** The frame at or before t. */
7
+ frame: number;
8
+ /** Index into replay.rounds, -1 before the first round. */
9
+ roundIndex: number;
10
+ round: ReplayRound | null;
11
+ clock: Clock;
12
+ score: Score;
13
+ players: PlayerState[];
14
+ /** Grenades in the air, leaving a trail, or with an effect at t. */
15
+ grenades: GrenadeState[];
16
+ bomb: BombState;
17
+ /** Kills in the last few seconds (killFeedSeconds), oldest first. */
18
+ kills: KillState[];
19
+ }
20
+ export interface Clock {
21
+ phase: "" | "freeze" | "live" | "bomb" | "over";
22
+ /** What the game's round timer shows: "1:23", "C4 0:12", "freeze", "round over". */
23
+ text: string;
24
+ /** Seconds left on the round or bomb timer; 0 in other phases. */
25
+ remaining: number;
26
+ }
27
+ export interface Score {
28
+ t: number;
29
+ ct: number;
30
+ teamT: string;
31
+ teamCT: string;
32
+ }
33
+ export interface PlayerState {
34
+ index: number;
35
+ name: string;
36
+ steamId: string;
37
+ side: Side;
38
+ /** On the server in this frame. */
39
+ present: boolean;
40
+ alive: boolean;
41
+ /** Interpolated between samples while alive. */
42
+ x: number;
43
+ y: number;
44
+ z: number;
45
+ /** Degrees, 0 = +x, counter-clockwise seen from above. */
46
+ yaw: number;
47
+ hp: number;
48
+ armor: number;
49
+ weapon: string;
50
+ ducking: boolean;
51
+ blind: boolean;
52
+ hasBomb: boolean;
53
+ defusing: boolean;
54
+ scoped: boolean;
55
+ hasKit: boolean;
56
+ /** Where the player died in the current round, if they did. */
57
+ death: {
58
+ x: number;
59
+ y: number;
60
+ z: number;
61
+ side: Side;
62
+ frame: number;
63
+ } | null;
64
+ }
65
+ export type GrenadeKind = "smoke" | "flash" | "he" | "fire" | "decoy" | "other";
66
+ export interface GrenadeState {
67
+ index: number;
68
+ kind: GrenadeKind;
69
+ thrower: number;
70
+ throwerSide: Side | null;
71
+ /** The projectile, while it flies. */
72
+ projectile: {
73
+ x: number;
74
+ y: number;
75
+ z: number;
76
+ } | null;
77
+ /** The flight path drawn so far: the first `count` points of path (x, y, z each). */
78
+ trail: {
79
+ path: number[];
80
+ count: number;
81
+ fade: number;
82
+ } | null;
83
+ effect: GrenadeEffect | null;
84
+ }
85
+ export interface GrenadeEffect {
86
+ kind: GrenadeKind;
87
+ x: number;
88
+ y: number;
89
+ z: number;
90
+ /** Seconds since the effect started. */
91
+ age: number;
92
+ /** Seconds until it ends. */
93
+ remaining: number;
94
+ /** 0..1 over a flash/HE burst, otherwise 0. */
95
+ burst: number;
96
+ }
97
+ export interface BombState {
98
+ state: "hidden" | "carried" | "dropped" | "planted" | "defused" | "exploded";
99
+ x: number;
100
+ y: number;
101
+ z: number;
102
+ /** Player index of the carrier, -1 if not carried. */
103
+ carrier: number;
104
+ site: string | null;
105
+ /** Seconds since the plant while planted. */
106
+ sincePlant: number;
107
+ }
108
+ export interface KillState extends ReplayKill {
109
+ /** Seconds since the kill. */
110
+ age: number;
111
+ killerName: string | null;
112
+ victimName: string;
113
+ killerSide: Side | null;
114
+ victimSide: Side;
115
+ /** Positions a frame before the kill; null for world kills. */
116
+ killerPos: {
117
+ x: number;
118
+ y: number;
119
+ z: number;
120
+ } | null;
121
+ victimPos: {
122
+ x: number;
123
+ y: number;
124
+ z: number;
125
+ };
126
+ }
127
+ export interface ModelOptions {
128
+ /** Round timer in seconds, 115 (mp_roundtime 1.92) by default. */
129
+ roundTime?: number;
130
+ /** Bomb timer in seconds, 40 by default. */
131
+ bombTime?: number;
132
+ /** How long kills stay in snapshot.kills, 6 s by default. */
133
+ killFeedSeconds?: number;
134
+ }
135
+ export interface ReplayModel {
136
+ readonly replay: Replay;
137
+ /** Frames so far: a live replay grows (see refresh). */
138
+ readonly frames: number;
139
+ readonly hz: number;
140
+ /** Round index per frame; frames between rounds belong to the previous round. */
141
+ readonly roundOf: Int16Array;
142
+ readonly plants: ReplayBombEvent[];
143
+ /**
144
+ * Frame each grenade's effect ends (smoke fades, fire out), per replay.grenades index:
145
+ * effectEnd, but never past the next round's start (replays from older extractors
146
+ * kept smokes that a round restart removed until the end of the demo). 0 if none.
147
+ */
148
+ readonly effectEnds: Int32Array;
149
+ /** Round index at a frame, -1 before the first round. */
150
+ roundAt(frame: number): number;
151
+ sideAt(frame: number, player: number): Side;
152
+ /** Seconds of game time between two frames. */
153
+ seconds(from: number, to: number): number;
154
+ clock(frame: number): Clock;
155
+ snapshot(t: number): Snapshot;
156
+ /** Re-reads the replay after it grew (a live replay's update); the derived data covers the new frames. */
157
+ refresh(): void;
158
+ }
159
+ /** The frame a round ends at for timing: an open round (end -1, still being played) never ends. */
160
+ export declare const roundEnd: (rd: ReplayRound) => number;
161
+ export declare const grenadeKind: (type: string) => GrenadeKind;
162
+ export declare const lerpAngle: (a: number, b: number, k: number) => number;
163
+ export declare function formatClock(seconds: number): string;
164
+ export declare function createModel(replay: Replay, options?: ModelOptions): ReplayModel;
@@ -0,0 +1,82 @@
1
+ import type { ReplayModel } from "./model";
2
+ type Listener<T> = (value: T) => void;
3
+ export declare class Emitter<Events extends Record<string, unknown>> {
4
+ private listeners;
5
+ on<K extends keyof Events>(event: K, fn: Listener<Events[K]>): () => void;
6
+ protected emit<K extends keyof Events>(event: K, value: Events[K]): void;
7
+ protected clearListeners(): void;
8
+ }
9
+ export interface PlaybackEvents extends Record<string, unknown> {
10
+ /** The position changed (by playing or seeking). */
11
+ change: number;
12
+ play: void;
13
+ pause: void;
14
+ /** The round index changed. */
15
+ round: number;
16
+ speed: number;
17
+ /** Following the live edge started (true) or stopped (false). */
18
+ live: boolean;
19
+ }
20
+ export declare const DEFAULT_SPEEDS: number[];
21
+ /**
22
+ * Play/pause, speed and seeking over a replay, in frames. Advance it with tick().
23
+ *
24
+ * A live replay (`live` set, while it's being broadcast) keeps playing at its end,
25
+ * waiting for frames, and can follow the live edge (`goLive`): it then plays
26
+ * `liveDelay` seconds behind the newest frame, easing its rate so frames that arrive a
27
+ * few seconds at a time play back smoothly. Seeking, pausing or changing speed leaves
28
+ * the live edge; playing into it joins it again.
29
+ */
30
+ export declare class Playback extends Emitter<PlaybackEvents> {
31
+ readonly model: ReplayModel;
32
+ readonly speeds: number[];
33
+ private now;
34
+ private _t;
35
+ private _playing;
36
+ private _speed;
37
+ private _round;
38
+ private _live;
39
+ private _following;
40
+ /** Seconds behind the newest frame while following the live edge. */
41
+ liveDelay: number;
42
+ /** The newest frame count and when it arrived (ms, `now`), for where the live edge is between updates. */
43
+ private edge;
44
+ constructor(model: ReplayModel, speeds?: number[], now?: () => number);
45
+ /** The replay is still being broadcast: playing doesn't stop at its end. */
46
+ get live(): boolean;
47
+ set live(on: boolean);
48
+ /** Following the live edge. */
49
+ get following(): boolean;
50
+ private setFollowing;
51
+ /** The model grew (a live update arrived): call after model.refresh(). */
52
+ grew(): void;
53
+ /** Where following the live edge plays now: `liveDelay` behind the newest frame, moving on in real time between updates. */
54
+ liveTarget(): number;
55
+ /** Jumps to the live edge and follows it, playing at 1×. */
56
+ goLive(): void;
57
+ get t(): number;
58
+ get playing(): boolean;
59
+ get speed(): number;
60
+ set speed(s: number);
61
+ /** Steps through `speeds`: +1 faster, -1 slower. */
62
+ stepSpeed(direction: 1 | -1): void;
63
+ get roundIndex(): number;
64
+ play(): void;
65
+ pause(): void;
66
+ toggle(): void;
67
+ /** Moves to a (fractional) frame; leaves the live edge. */
68
+ seek(frame: number): void;
69
+ private move;
70
+ /** Moves by game seconds. */
71
+ skip(seconds: number): void;
72
+ /** Where a round starts playing: three seconds before freeze time ends. */
73
+ roundStart(index: number): number;
74
+ gotoRound(index: number): void;
75
+ /** Like a media player: back to this round's start, or to the previous round when already there. */
76
+ previousRound(): void;
77
+ nextRound(): void;
78
+ /** Advances by dt real seconds while playing. Returns whether the position changed. */
79
+ tick(dt: number): boolean;
80
+ dispose(): void;
81
+ }
82
+ export {};
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Colors and fonts of the viewers. Every value can be set three ways, in order
3
+ * of precedence: the `theme` option, a CSS custom property on the host element
4
+ * or any ancestor (e.g. `--replay-ct: var(--my-blue)`), or the default here.
5
+ * Canvas drawing uses the resolved values; the HTML panels use the same CSS
6
+ * properties, so host stylesheets (including dark mode) apply to both.
7
+ */
8
+ export interface Theme {
9
+ /** Counter-terrorists. */
10
+ ct: string;
11
+ /** Terrorists. */
12
+ t: string;
13
+ /** Behind the radar or map. */
14
+ background: string;
15
+ /** Panels: scoreboard, roster, kill feed, controls. */
16
+ panel: string;
17
+ border: string;
18
+ text: string;
19
+ muted: string;
20
+ /** Timeline rounds, alternating. */
21
+ track: string;
22
+ trackAlt: string;
23
+ /** Timeline playhead, focus rings. */
24
+ accent: string;
25
+ bomb: string;
26
+ hpHigh: string;
27
+ hpMid: string;
28
+ hpLow: string;
29
+ smoke: string;
30
+ flash: string;
31
+ he: string;
32
+ fire: string;
33
+ decoy: string;
34
+ font: string;
35
+ mono: string;
36
+ }
37
+ export type ThemeInput = Partial<Theme>;
38
+ export declare const defaultTheme: Theme;
39
+ /** The CSS custom property of each theme key. */
40
+ export declare const themeVars: Record<keyof Theme, string>;
41
+ /** Resolves the theme for an element: option, then inherited CSS property, then default. */
42
+ export declare function resolveTheme(el: Element | null, input?: ThemeInput): Theme;
43
+ /** Writes the theme as CSS custom properties on an element, for its HTML panels. */
44
+ export declare function applyThemeVars(el: HTMLElement, theme: Theme): void;
45
+ export declare const sideColor: (theme: Theme, side: "T" | "CT" | null | undefined) => string;
46
+ export declare const hpColor: (theme: Theme, hp: number) => string;
@@ -0,0 +1,6 @@
1
+ export * from "./core/format";
2
+ export { createModel, formatClock, grenadeKind, lerpAngle, roundEnd, type BombState, type Clock, type GrenadeEffect, type GrenadeKind, type GrenadeState, type KillState, type ModelOptions, type PlayerState, type ReplayModel, type Score, type Snapshot, } from "./core/model";
3
+ export { DEFAULT_SPEEDS, Emitter, Playback, type PlaybackEvents } from "./core/playback";
4
+ export { emptyReplay, isLiveUpdate, LiveReplay, readUpdate, UPDATE_VERSION, type GrenadeUpdate, type LiveEndReason, type LiveEvents, type LiveUpdate } from "./core/live";
5
+ export { defaultTheme, resolveTheme, themeVars, type Theme, type ThemeInput } from "./core/theme";
6
+ export type { Viewer, ViewerEvents, ViewerOptions } from "./ui/shell";
@@ -0,0 +1,258 @@
1
+ /**
2
+ * 3D maps as a site serves them (packed by scripts/pack-game-map.mjs and
3
+ * scripts/pack-greybox.mjs): finding a replay's map in the index, which game-look
4
+ * quality tiers a device can use, what a tier costs to download, and keeping
5
+ * downloaded maps on the device. No three.js: a page can show the choice before
6
+ * it loads the 3D viewer.
7
+ */
8
+ export type GameMapTier = "low" | "medium" | "high";
9
+ export declare const GAME_MAP_TIERS: readonly GameMapTier[];
10
+ /**
11
+ * "bc": Valve's BC6H/BC7/BC1 lightmaps (desktop GPUs). "compat": smaller RGB9E5/R8/PNG
12
+ * lightmaps for GPUs without those formats (phones), used by the low and medium tiers.
13
+ */
14
+ export type LightmapMode = "bc" | "compat";
15
+ export interface MapFile {
16
+ /** Relative to the manifest. */
17
+ file: string;
18
+ bytes: number;
19
+ }
20
+ export interface LightmapFile extends MapFile {
21
+ format: "bc6h" | "bc7" | "bc1" | "rgb9e5" | "r8" | "png";
22
+ width: number;
23
+ height: number;
24
+ }
25
+ export interface LightmapSet {
26
+ irradiance?: LightmapFile;
27
+ sunShadow?: LightmapFile;
28
+ directional?: LightmapFile;
29
+ }
30
+ export interface GameMapTierInfo {
31
+ /** Longest texture side. */
32
+ maxTexture: number;
33
+ /** Key into `lightmaps.bc`. */
34
+ lightmaps: string;
35
+ /** Offered without BC texture support (phones). */
36
+ compat: boolean;
37
+ /** Download size of the whole tier, by lightmap mode. */
38
+ bytes: {
39
+ bc: number;
40
+ compat?: number;
41
+ };
42
+ /** [texture id, file key, bytes], in load order (biggest surfaces first). */
43
+ textures: [string, string, number][];
44
+ }
45
+ /** maps/<map>/<build>/manifest.json */
46
+ export interface GameMapManifest {
47
+ format: "cs2-game-map";
48
+ version: 1;
49
+ map: string;
50
+ /** First 12 hex digits of the map VPK's SHA1. */
51
+ build: string;
52
+ vpkSha1: string;
53
+ /** CS2 patch the map was converted from, e.g. "1.41.9.0". */
54
+ patch?: string;
55
+ created: string;
56
+ /** Where texture files are, relative to the manifest: `${textureBase}${key}.ktx2`. */
57
+ textureBase: string;
58
+ geometry: MapFile;
59
+ /** Sky, reflection probes, light probes: every tier needs them. */
60
+ shared: MapFile[];
61
+ lightmaps: {
62
+ bc: Record<string, LightmapSet>;
63
+ compat: LightmapSet;
64
+ };
65
+ tiers: Partial<Record<GameMapTier, GameMapTierInfo>>;
66
+ stats?: {
67
+ drawCalls?: number;
68
+ triangles?: number;
69
+ textures?: number;
70
+ };
71
+ /** Set by fetchGameMapManifest: the URL relative paths resolve against. */
72
+ url?: string;
73
+ }
74
+ /**
75
+ * One build of a map in the index: its game look, its grey-box, or both. Paths are
76
+ * relative to the index until fetchGameMapIndex makes them absolute.
77
+ */
78
+ export interface GameMapBuild {
79
+ /** The game look's manifest.json. */
80
+ manifest?: string;
81
+ /** CS2 patch the build was converted at, e.g. "1.41.9.7". */
82
+ patch?: string;
83
+ /** When the build was first converted, YYYY-MM-DD. */
84
+ created: string;
85
+ /**
86
+ * When this version of the map went live, YYYY-MM-DD: the date of the game patch it
87
+ * was converted at (steam.inf's VersionDate) unless set by hand. Picking a build by
88
+ * `date` uses it, or `created` where it's missing.
89
+ */
90
+ released?: string;
91
+ /** The game look's download size per tier, by lightmap mode. */
92
+ tiers?: Partial<Record<GameMapTier, {
93
+ bc: number;
94
+ compat?: number;
95
+ }>>;
96
+ /** The grey-box GLB (createWorldViewer's `map` without a `look`). */
97
+ greybox?: {
98
+ file: string;
99
+ bytes: number;
100
+ };
101
+ }
102
+ /** maps/index.json: every map and build in the bucket. */
103
+ export interface GameMapIndex {
104
+ format: "cs2-game-map-index";
105
+ version: 1;
106
+ maps: Record<string, {
107
+ latest: string;
108
+ builds: Record<string, GameMapBuild>;
109
+ }>;
110
+ }
111
+ /** The index, with each build's `manifest` and `greybox.file` turned into absolute URLs. */
112
+ export declare function fetchGameMapIndex(url: string): Promise<GameMapIndex>;
113
+ /** Which build to use; see pickMapBuild. */
114
+ export interface MapBuildOptions {
115
+ /** A replay's `protocol`: the game patch without dots (14197 = 1.41.9.7). */
116
+ protocol?: number;
117
+ /** When the match was played: a Date, or a string starting with YYYY-MM-DD (its UTC day is used). */
118
+ date?: Date | string;
119
+ /** One build by name. */
120
+ build?: string;
121
+ }
122
+ /** "game": the game look (`manifest`), "greybox": the grey-box GLB. */
123
+ export type MapLook = "game" | "greybox";
124
+ /** A build picked from the index, with its name. */
125
+ export interface PickedMapBuild {
126
+ id: string;
127
+ build: GameMapBuild;
128
+ }
129
+ /**
130
+ * Which build of a map to load for a look, null if the index has no build of the map
131
+ * with that look. Only builds with the look count; in order:
132
+ *
133
+ * - `build`: that build, if it has the look.
134
+ * - `protocol`: the newest build converted at or before that patch, so an old demo
135
+ * plays on the map as it was.
136
+ * - `date`: the newest build released on or before that day (`released`, else
137
+ * `created`). Not the closest one: a match two days before a map update was
138
+ * played on the old map.
139
+ * - Neither: the latest build, or the newest one with the look.
140
+ *
141
+ * A protocol or date earlier than every build gets the oldest build, the closest there
142
+ * is to what was played. `protocol` wins over `date`; a protocol of 0 counts as none.
143
+ * Throws a RangeError for a date it can't read.
144
+ */
145
+ export declare function pickMapBuild(index: GameMapIndex, map: string, look: MapLook, opts?: MapBuildOptions): PickedMapBuild | null;
146
+ /**
147
+ * A map's game-look manifest URL from the index, null if the bucket doesn't have the
148
+ * map's game look. The build is pickMapBuild's: pass the replay's `protocol` (or the
149
+ * match's `date`) to get the map as the demo was played.
150
+ */
151
+ export declare function gameMapManifestUrl(index: GameMapIndex, map: string, opts?: MapBuildOptions): string | null;
152
+ /**
153
+ * A map's grey-box URL from the index (createWorldViewer's `map`), null if the bucket
154
+ * doesn't have a grey-box of the map. The build is pickMapBuild's, as for the game look.
155
+ */
156
+ export declare function greyboxMapUrl(index: GameMapIndex, map: string, opts?: MapBuildOptions): string | null;
157
+ export declare function fetchGameMapManifest(url: string, store?: GameMapStore | null): Promise<GameMapManifest>;
158
+ export interface GameMapFile {
159
+ url: string;
160
+ bytes: number;
161
+ kind: "geometry" | "shared" | "lightmap" | "texture";
162
+ }
163
+ /** Every file a tier downloads (each once), with absolute URLs. */
164
+ export declare function gameMapFiles(manifest: GameMapManifest, tier: GameMapTier, mode: LightmapMode): GameMapFile[];
165
+ export interface GameMapSupport {
166
+ /** The game look needs WebGL 2. */
167
+ webgl2: boolean;
168
+ /** BC6H, BC7 and BC1 textures (EXT_texture_compression_bptc + WEBGL_compressed_texture_s3tc): the "bc" lightmaps. */
169
+ bc: boolean;
170
+ lightmaps: LightmapMode;
171
+ mobile: boolean;
172
+ /** The GPU, as the browser reports it (may be vague). */
173
+ renderer: string;
174
+ /** navigator.deviceMemory (Chromium only), GB. */
175
+ deviceMemory?: number;
176
+ /** Tiers this device can use: all three with BC support, low and medium without. */
177
+ tiers: GameMapTier[];
178
+ /**
179
+ * The tier to load: "low", the one sites are offered (packed maps have only low unless
180
+ * built with more; see scripts/pack-game-map.mjs). null without WebGL 2.
181
+ */
182
+ recommended: GameMapTier | null;
183
+ }
184
+ /** What the game look can do on this device. Creates (and drops) a WebGL context. */
185
+ export declare function detectGameMapSupport(): GameMapSupport;
186
+ export interface StorageInfo {
187
+ /** Bytes the browser lets this site use, and has used (navigator.storage.estimate()); unknown in some browsers. */
188
+ quota?: number;
189
+ usage?: number;
190
+ /** quota − usage. */
191
+ free?: number;
192
+ /** Whether the browser keeps the site's storage under pressure (navigator.storage.persist()). */
193
+ persisted: boolean;
194
+ }
195
+ export interface TierStatus {
196
+ /** The whole tier. */
197
+ totalBytes: number;
198
+ /** Already on the device. */
199
+ cachedBytes: number;
200
+ /** Still to download. */
201
+ missingBytes: number;
202
+ /** Free storage, if the browser says. */
203
+ freeBytes?: number;
204
+ /** Whether the missing part fits, null when the browser doesn't say. */
205
+ fits: boolean | null;
206
+ }
207
+ export interface StoredMap {
208
+ map: string;
209
+ build: string;
210
+ patch?: string;
211
+ manifestUrl: string;
212
+ /** Per tier, how much of it is on the device (both lightmap modes counted). */
213
+ tiers: Partial<Record<GameMapTier, {
214
+ cachedBytes: number;
215
+ totalBytes: number;
216
+ complete: boolean;
217
+ }>>;
218
+ /** Bytes only this map uses (what remove() frees). */
219
+ ownBytes: number;
220
+ }
221
+ /**
222
+ * Downloaded map files in the browser's Cache Storage, so a map is downloaded once
223
+ * per device. Files are immutable (textures are named by content and shared by
224
+ * maps, builds and tiers), so nothing is ever revalidated.
225
+ *
226
+ * Browsers can evict the cache under storage pressure unless persist() was granted;
227
+ * Safari also clears a site's storage after 7 days without a visit. The viewer
228
+ * keeps working either way: missing files are downloaded again.
229
+ */
230
+ export declare class GameMapStore {
231
+ private cache;
232
+ /** Set once a write hit the storage quota; later downloads aren't stored. */
233
+ full: boolean;
234
+ /** Called the first time a write fails for lack of space. */
235
+ onFull: (() => void) | null;
236
+ private constructor();
237
+ /** null where Cache Storage isn't available (insecure origins, some private modes). */
238
+ static open(name?: string): Promise<GameMapStore | null>;
239
+ /** A file's bytes: from the cache, else downloaded (and stored). onBytes gets each chunk's size. */
240
+ fetch(url: string, onBytes?: (n: number) => void): Promise<ArrayBuffer>;
241
+ storage(): Promise<StorageInfo>;
242
+ /** Asks the browser not to evict stored maps. Chrome decides by engagement, Firefox asks the user. */
243
+ persist(): Promise<boolean>;
244
+ /** How much of a tier is on the device and whether the rest fits. */
245
+ status(manifest: GameMapManifest, tier: GameMapTier, mode: LightmapMode): Promise<TierStatus>;
246
+ /** Maps with files on the device (their manifests were stored by the viewer). */
247
+ list(): Promise<StoredMap[]>;
248
+ /** Deletes a map's files, except those other stored maps still use. Returns the bytes freed. */
249
+ remove(manifestUrl: string): Promise<number>;
250
+ /** Deletes every stored map. */
251
+ clear(): Promise<void>;
252
+ private cachedUrls;
253
+ private manifests;
254
+ }
255
+ /** A response body as one buffer, reporting each chunk. */
256
+ export declare function readBody(res: Response, onBytes?: (n: number) => void): Promise<ArrayBuffer>;
257
+ /** "312 MB", "1.2 GB": for showing download sizes. */
258
+ export declare function formatBytes(n: number): string;
@@ -0,0 +1,108 @@
1
+ import { type Replay, type ReplaySource } from "../core/format";
2
+ import { LiveReplay } from "../core/live";
3
+ export interface ParseProgress {
4
+ phase: "download" | "parse";
5
+ loaded: number;
6
+ /** Bytes in total, null when the server didn't say. */
7
+ total: number | null;
8
+ }
9
+ export interface ParseOptions {
10
+ /** Samples per second, 16 by default. */
11
+ hz?: number;
12
+ signal?: AbortSignal;
13
+ onProgress?: (progress: ParseProgress) => void;
14
+ /** Where the worker script is, if your bundler can't resolve it next to this module. */
15
+ workerUrl?: string | URL;
16
+ /** Passed to fetch when the source is a URL. */
17
+ fetch?: RequestInit;
18
+ }
19
+ /** What the extractor reports about a parsed demo. */
20
+ export interface ParseSummary {
21
+ map: string;
22
+ hz: number;
23
+ frames: number;
24
+ players: number;
25
+ rounds: number;
26
+ kills: number;
27
+ grenades: number;
28
+ bytes: number;
29
+ /** The demo ended in a parse error; everything before it was kept. */
30
+ warning?: string;
31
+ }
32
+ export interface ParsedDemo {
33
+ replay: Replay;
34
+ /** The replay file, e.g. to cache or upload so the next viewer doesn't parse again. */
35
+ bytes: Uint8Array;
36
+ summary: ParseSummary;
37
+ }
38
+ /** Parses a CS2 demo (.dem, or .dem.gz) into a replay. */
39
+ export declare function parseDemo(source: Blob | ArrayBuffer | Uint8Array | string | URL, options?: ParseOptions): Promise<ParsedDemo>;
40
+ /**
41
+ * Opens a replay or a demo, whichever the source is: replay files (also
42
+ * gzipped) are read directly, demos are parsed with parseDemo().
43
+ */
44
+ export declare function openReplay(source: ReplaySource, options?: ParseOptions): Promise<Replay>;
45
+ /** A relay's /sync answer: where the broadcast is. */
46
+ export interface PlaycastSync {
47
+ tick: number;
48
+ fragment: number;
49
+ signup_fragment: number;
50
+ tps: number;
51
+ keyframe_interval: number;
52
+ map: string;
53
+ protocol: number;
54
+ token_redirect?: string;
55
+ [key: string]: unknown;
56
+ }
57
+ export interface PlaycastOptions {
58
+ /**
59
+ * "live" (default): join at the live edge, with the state of the match at once but none of
60
+ * what happened before. "start": catch up from the first fragment the relay has, then
61
+ * follow; that downloads everything broadcast so far (about the size of the demo).
62
+ */
63
+ from?: "live" | "start";
64
+ /**
65
+ * A CORS pass-through for relays that don't send CORS headers (most third-party ones):
66
+ * each URL is fetched through it, percent-encoded in place of `{url}`, or appended when
67
+ * there's no `{url}`. E.g. "https://cs2-maps.matchomag.workers.dev/v1/playcast-proxy?url=".
68
+ */
69
+ proxy?: string;
70
+ /** Samples per second, 16 by default. */
71
+ hz?: number;
72
+ /** End the replay ("idle") after this many seconds without a new fragment, 30 by default. */
73
+ idleTimeout?: number;
74
+ signal?: AbortSignal;
75
+ /** Where the worker script is, if your bundler can't resolve it next to this module. */
76
+ workerUrl?: string | URL;
77
+ /** Passed to every fetch (headers, credentials…). Must be structured-cloneable. */
78
+ fetch?: RequestInit;
79
+ }
80
+ /** A live match: a LiveReplay that also knows where it comes from, and can be closed. */
81
+ export declare class LivePlaycast extends LiveReplay {
82
+ readonly url: string;
83
+ /** The relay's /sync answer when it was opened. */
84
+ sync: PlaycastSync | null;
85
+ /** The broadcast's URL after the relay's token redirect. */
86
+ base: string;
87
+ /** With reason "map": the new map's name. Open the same URL again to follow it. */
88
+ nextMap: string | null;
89
+ private worker;
90
+ constructor(url: string);
91
+ /** @internal */
92
+ attach(worker: Worker): void;
93
+ /** Stops following the broadcast; the replay keeps what it has (reason "closed"). */
94
+ close(): void;
95
+ /** @internal */
96
+ stop(): void;
97
+ }
98
+ /**
99
+ * Follows a live match from a CSTV+ playcast URL (what the game plays with
100
+ * `playcast "<url>"`): the parser runs in a worker, fetching the broadcast's
101
+ * fragments, and `live.replay` grows as they arrive. Give `live.replay` to a viewer
102
+ * and it follows the match, at the live edge, with seeking back over what it has.
103
+ *
104
+ * Resolves once the first frames are in. Rejects if the broadcast can't be read
105
+ * (not started yet, no CORS without `proxy`, …).
106
+ */
107
+ export declare function openPlaycast(url: string | URL, options?: PlaycastOptions): Promise<LivePlaycast>;
108
+ export { LiveReplay, type LiveEndReason } from "../core/live";