@matchomag/cs2-replay 0.0.0-stage → 0.3.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.
Files changed (73) hide show
  1. package/README.md +9 -2
  2. package/bin/demo-replay-darwin-amd64 +0 -0
  3. package/bin/demo-replay-darwin-arm64 +0 -0
  4. package/bin/demo-replay-linux-amd64 +0 -0
  5. package/bin/demo-replay-linux-arm64 +0 -0
  6. package/bin/demo-replay-windows-amd64.exe +0 -0
  7. package/bin/demo-replay.js +22 -0
  8. package/dist/2d/index.js +1 -0
  9. package/dist/3d/index.js +11 -0
  10. package/dist/chunks/actors-EZRYEB4I.js +177 -0
  11. package/dist/chunks/chunk-5BFKVD63.js +1 -0
  12. package/dist/chunks/chunk-D5ST2XVO.js +106 -0
  13. package/dist/chunks/chunk-DQPOBPMK.js +1 -0
  14. package/dist/chunks/chunk-FBSLUYGT.js +1 -0
  15. package/dist/chunks/chunk-Q37CWKZX.js +12 -0
  16. package/dist/chunks/chunk-VSIECNZM.js +1 -0
  17. package/dist/chunks/chunk-YJG3LSSB.js +1 -0
  18. package/dist/chunks/chunk-YO73RW3Y.js +1 -0
  19. package/dist/chunks/look-2WBUGHMJ.js +669 -0
  20. package/dist/index.js +1 -0
  21. package/dist/maps/index.js +1 -0
  22. package/dist/parse/index.js +1 -0
  23. package/dist/parse/wasm/replay.wasm +0 -0
  24. package/dist/parse/worker.js +1 -0
  25. package/dist/types/2d/index.d.ts +17 -0
  26. package/dist/types/2d/radar.d.ts +35 -0
  27. package/dist/types/3d/actors.d.ts +90 -0
  28. package/dist/types/3d/characters/anim.d.ts +93 -0
  29. package/dist/types/3d/characters/ao.d.ts +3 -0
  30. package/dist/types/3d/characters/body.d.ts +37 -0
  31. package/dist/types/3d/characters/builder.d.ts +82 -0
  32. package/dist/types/3d/characters/index.d.ts +74 -0
  33. package/dist/types/3d/characters/rig.d.ts +73 -0
  34. package/dist/types/3d/characters/textures.d.ts +4 -0
  35. package/dist/types/3d/characters/viewmodel.d.ts +51 -0
  36. package/dist/types/3d/characters/weapons.d.ts +25 -0
  37. package/dist/types/3d/follow.d.ts +43 -0
  38. package/dist/types/3d/fx/batch.d.ts +87 -0
  39. package/dist/types/3d/fx/context.d.ts +34 -0
  40. package/dist/types/3d/fx/explosion.d.ts +14 -0
  41. package/dist/types/3d/fx/fire.d.ts +11 -0
  42. package/dist/types/3d/fx/index.d.ts +84 -0
  43. package/dist/types/3d/fx/lights.d.ts +25 -0
  44. package/dist/types/3d/fx/meshes.d.ts +18 -0
  45. package/dist/types/3d/fx/misc.d.ts +15 -0
  46. package/dist/types/3d/fx/random.d.ts +21 -0
  47. package/dist/types/3d/fx/smoke.d.ts +10 -0
  48. package/dist/types/3d/fx/textures.d.ts +29 -0
  49. package/dist/types/3d/fx/types.d.ts +117 -0
  50. package/dist/types/3d/greybox.d.ts +22 -0
  51. package/dist/types/3d/index.d.ts +127 -0
  52. package/dist/types/3d/look.d.ts +49 -0
  53. package/dist/types/3d/markers.d.ts +23 -0
  54. package/dist/types/3d/smoke/volume.d.ts +95 -0
  55. package/dist/types/3d/smoke/voxels.d.ts +87 -0
  56. package/dist/types/3d/world/index.d.ts +179 -0
  57. package/dist/types/3d/world/look.d.ts +16 -0
  58. package/dist/types/3d/world/material.d.ts +128 -0
  59. package/dist/types/3d/world/post.d.ts +75 -0
  60. package/dist/types/3d/world/probes.d.ts +39 -0
  61. package/dist/types/3d/world/release.d.ts +28 -0
  62. package/dist/types/3d/world/stage.d.ts +84 -0
  63. package/dist/types/core/format.d.ts +163 -0
  64. package/dist/types/core/live.d.ts +115 -0
  65. package/dist/types/core/model.d.ts +164 -0
  66. package/dist/types/core/playback.d.ts +82 -0
  67. package/dist/types/core/theme.d.ts +46 -0
  68. package/dist/types/index.d.ts +6 -0
  69. package/dist/types/maps/index.d.ts +258 -0
  70. package/dist/types/parse/index.d.ts +108 -0
  71. package/dist/types/ui/shell.d.ts +131 -0
  72. package/dist/types/ui/styles.d.ts +1 -0
  73. package/package.json +68 -4
@@ -0,0 +1,128 @@
1
+ import * as THREE from "three";
2
+ /** One texture slot of a CS2 material: a texture file, or a constant colour. */
3
+ export interface Cs2Slot {
4
+ /** PNG, relative to the glTF. */
5
+ uri?: string;
6
+ /** GPU-compressed copy (KTX2/UASTC), when the converter made one. */
7
+ ktx2?: string;
8
+ /** Packed maps (scripts/pack-game-map.mjs): texture id, a file per tier in the manifest. */
9
+ tex?: string;
10
+ /** Colour data (sRGB); everything else is linear. */
11
+ srgb?: boolean;
12
+ value?: number[];
13
+ }
14
+ export interface Cs2UvXform {
15
+ scale: number[];
16
+ offset: number[];
17
+ rotation: number;
18
+ center: number[];
19
+ }
20
+ export interface Cs2Layer {
21
+ color?: Cs2Slot | null;
22
+ normal?: Cs2Slot | null;
23
+ height?: Cs2Slot | null;
24
+ tint?: number[];
25
+ metal?: boolean;
26
+ /** 0: vertex colour everywhere, 1: masked by height.g, 2: never. */
27
+ vertexColorMode?: number;
28
+ uv?: Cs2UvXform;
29
+ /** Roughness brightness, contrast. */
30
+ roughness?: number[];
31
+ heightScale?: number;
32
+ heightZero?: number;
33
+ metalness?: number;
34
+ roughnessValue?: number;
35
+ uvScale2?: number[];
36
+ }
37
+ /** What scripts/game-map.mjs writes into each material's extras.cs2. */
38
+ export interface Cs2MaterialDesc {
39
+ family: "layered" | "twoway" | "standard" | "glass" | "unlit";
40
+ name: string;
41
+ shader?: string;
42
+ layers: Cs2Layer[];
43
+ lightmapped?: boolean;
44
+ tint?: number[];
45
+ alphaTest?: number;
46
+ translucent?: boolean;
47
+ mod2x?: boolean;
48
+ decal?: boolean;
49
+ doubleSided?: boolean;
50
+ vertexColor?: boolean;
51
+ opacity?: number;
52
+ blendSoftness?: number;
53
+ mask?: Cs2Slot | null;
54
+ ao?: Cs2Slot | null;
55
+ metalnessMap?: Cs2Slot | null;
56
+ metalness?: number;
57
+ tintMask?: Cs2Slot | null;
58
+ selfIllum?: {
59
+ mask?: Cs2Slot | null;
60
+ brightness?: number;
61
+ scale?: number;
62
+ tint?: number[];
63
+ };
64
+ foliage?: boolean;
65
+ /** Foliage vertex animation: [amount, speed, falloff, noise scale] for sway (vertex r) and flutter (vertex b). */
66
+ wind?: {
67
+ sway: number[];
68
+ flutter: number[];
69
+ mask?: "all";
70
+ };
71
+ black?: boolean;
72
+ glassTint?: Cs2Slot | null;
73
+ }
74
+ /** Uniforms every world material shares (lightmaps, debug switches). */
75
+ export interface WorldUniforms {
76
+ cs2Irradiance: THREE.IUniform<THREE.Texture | null>;
77
+ cs2Directional: THREE.IUniform<THREE.Texture | null>;
78
+ cs2SunShadow: THREE.IUniform<THREE.Texture | null>;
79
+ /** Multiplies lightmap irradiance (π: three.js divides diffuse by π, CS2 doesn't). */
80
+ cs2LightmapScale: THREE.IUniform<number>;
81
+ /** 0..1: how much the directional lightmap shapes normal-mapped surfaces. */
82
+ cs2Directionality: THREE.IUniform<number>;
83
+ /** Image-based reflections strength. */
84
+ cs2EnvStrength: THREE.IUniform<number>;
85
+ /** 0 normal, 1 albedo, 2 lighting only, 3 normals, 4 lightmap UV checker, 5 sun visibility. */
86
+ cs2Debug: THREE.IUniform<number>;
87
+ /** Flip the green channel of normal maps (DirectX vs OpenGL convention). */
88
+ cs2NormalFlipY: THREE.IUniform<number>;
89
+ /** Reflection probes (scripts/game-map.mjs): octahedral atlas, volumes, lookup grid. */
90
+ cs2EnvAtlas: THREE.IUniform<THREE.Texture | null>;
91
+ cs2EnvVol: THREE.IUniform<THREE.Texture | null>;
92
+ cs2EnvGrid: THREE.IUniform<THREE.Texture | null>;
93
+ cs2EnvGridOrigin: THREE.IUniform<THREE.Vector3>;
94
+ cs2EnvGridDims: THREE.IUniform<THREE.Vector3>;
95
+ cs2EnvGridCell: THREE.IUniform<number>;
96
+ /** 1/width, 1/height, tile width, tile height. */
97
+ cs2EnvAtlasInfo: THREE.IUniform<THREE.Vector4>;
98
+ cs2EnvCols: THREE.IUniform<number>;
99
+ cs2EnvLevels: THREE.IUniform<THREE.Vector3[]>;
100
+ /** 0: reflections from the sky only (probes not loaded yet). */
101
+ cs2EnvProbes: THREE.IUniform<number>;
102
+ /** Wind: direction x, z (world), strength (1 = env_wind's base speed), time (s). */
103
+ cs2Wind: THREE.IUniform<THREE.Vector4>;
104
+ }
105
+ export declare function createWorldUniforms(): WorldUniforms;
106
+ /** Resolves texture slots to textures; returns a placeholder until the image arrives. */
107
+ export type SlotTexture = (slot: Cs2Slot, kind: "color" | "linear") => {
108
+ texture: THREE.Texture;
109
+ uniform?: never;
110
+ } | null;
111
+ /**
112
+ * Builds the material for one CS2 world material. A MeshStandardMaterial (so three.js
113
+ * lights, shadows, fog and the environment map keep working) whose texture sampling
114
+ * and indirect lighting are replaced:
115
+ * - CS2 channel packing: color.a = AO (environment shaders), normal.a = roughness,
116
+ * height = (height, tint mask, -, metalness).
117
+ * - Two-layer blending by vertex paint (_BLEND.x) shaped by the height maps, or by
118
+ * a mask texture (simple 2-way blend).
119
+ * - Baked lighting from the map's lightmaps on uv1: irradiance, its dominant
120
+ * direction (so normal maps still read in shade) and the sun's baked shadow,
121
+ * which masks the real-time sun.
122
+ */
123
+ export declare function createWorldMaterial(desc: Cs2MaterialDesc, shared: WorldUniforms, tex: (slot: Cs2Slot | null | undefined, kind: "color" | "linear") => THREE.Texture | null, opts: {
124
+ hasColor: boolean;
125
+ hasBlend: boolean;
126
+ hasUv2: boolean;
127
+ envProbes?: boolean;
128
+ }): THREE.Material;
@@ -0,0 +1,75 @@
1
+ import * as THREE from "three";
2
+ import { Pass } from "three/addons/postprocessing/Pass.js";
3
+ /**
4
+ * CS2's post-processing, from the map's post_processing_volume and its .vpost:
5
+ *
6
+ * - Tone mapping is Source 2's filmic curve (Hable's form, with the layer's own shoulder,
7
+ * linear and toe parameters and white point): out = F(x · exposure · 2^bias) / F(W).
8
+ * With Overpass's settings (shoulder 0, linear 0.001, toe 1/1/1, white 1.5) that is a
9
+ * near-linear ramp clipping at 1.5, which is why CS2's highlights look the way they do.
10
+ * - Auto exposure: average scene luminance drives the exposure towards a key, clamped
11
+ * to the volume's min/max and adapting at its speeds.
12
+ * - Bloom: a soft threshold (threshold, threshold width), five blurred levels with the
13
+ * layer's weights and tints, screen-blended at its strength.
14
+ */
15
+ export interface Cs2PostSettings {
16
+ tonemap: {
17
+ exposureBias: number;
18
+ shoulderStrength: number;
19
+ linearStrength: number;
20
+ linearAngle: number;
21
+ toeStrength: number;
22
+ toeNum: number;
23
+ toeDenom: number;
24
+ whitePoint: number;
25
+ };
26
+ exposure: {
27
+ min: number;
28
+ max: number;
29
+ speedUp: number;
30
+ speedDown: number;
31
+ compensation: number;
32
+ };
33
+ bloom: {
34
+ screenStrength: number;
35
+ addStrength: number;
36
+ threshold: number;
37
+ thresholdWidth: number;
38
+ weights: number[];
39
+ tints: [number, number, number][];
40
+ };
41
+ }
42
+ export declare const DEFAULT_POST: Cs2PostSettings;
43
+ /**
44
+ * Average scene luminance (linear, CS2 lighting units) that auto exposure maps to 1.
45
+ * CS2 doesn't document its target; this puts Overpass's sunlit outdoors at ~1, as its
46
+ * 0.8–1.2 range suggests it was lit for.
47
+ */
48
+ export declare const EXPOSURE_KEY = 0.2;
49
+ export declare class Cs2PostPass extends Pass {
50
+ settings: Cs2PostSettings;
51
+ /** Seconds per frame for exposure adaptation; null uses the real frame time. */
52
+ fixedDelta: number | null;
53
+ /** Freeze auto exposure at this value (null: automatic). */
54
+ exposureOverride: number | null;
55
+ private quad;
56
+ private lum;
57
+ private adapt;
58
+ private bright;
59
+ private blurTmp;
60
+ private lumMat;
61
+ private adaptMat;
62
+ private brightMat;
63
+ private downMat;
64
+ private blurMat;
65
+ private finalMat;
66
+ private first;
67
+ private last;
68
+ constructor(width: number, height: number, settings?: Cs2PostSettings);
69
+ setSize(width: number, height: number): void;
70
+ private draw;
71
+ render(renderer: THREE.WebGLRenderer, writeBuffer: THREE.WebGLRenderTarget, readBuffer: THREE.WebGLRenderTarget): void;
72
+ /** Exposure, bloom and tone mapping of `input` (linear HDR) into `target` (null: the canvas). */
73
+ renderTexture(renderer: THREE.WebGLRenderer, input: THREE.Texture, target: THREE.WebGLRenderTarget | null): void;
74
+ dispose(): void;
75
+ }
@@ -0,0 +1,39 @@
1
+ import * as THREE from "three";
2
+ export interface ProbeSample {
3
+ /** Linear irradiance arriving at the floor (CS2 lightmap units). */
4
+ ambient: THREE.Color;
5
+ /** 0..1: how much of a standing body sees the sun. */
6
+ sun: number;
7
+ }
8
+ /**
9
+ * Light probes baked by scripts/game-map.mjs on a regular XZ grid, several per column
10
+ * on multi-level maps. sample() interpolates the four columns around a point, each
11
+ * at the floor the point stands on.
12
+ */
13
+ export declare class ProbeGrid {
14
+ private data;
15
+ private step;
16
+ private bounds;
17
+ private cells;
18
+ private nx;
19
+ constructor(data: Float32Array, step: number, bounds: [number, number, number, number]);
20
+ private key;
21
+ /** The probe in a column whose floor is the one at `y` (feet), or -1. */
22
+ private floorIn;
23
+ sample(pos: THREE.Vector3, out: ProbeSample): boolean;
24
+ }
25
+ /** probes.bin (game-map.mjs): 7 floats per floor probe. */
26
+ export declare function loadProbes(buf: ArrayBuffer, step: number, bounds: [number, number, number, number]): ProbeGrid;
27
+ /** Per-object probe lighting: the sun scaled by visibility, ambient from the probe. */
28
+ export interface ProbeLit {
29
+ readonly ambient: THREE.Color;
30
+ sun: number;
31
+ /** Reflection strength, dimmed indoors. */
32
+ spec: number;
33
+ }
34
+ /**
35
+ * Makes every lit material under `root` take its lighting from a probe instead of the
36
+ * scene-wide hemisphere/IBL fill: materials are cloned per object (so each player has
37
+ * its own values) and patched. Returns the values to update each frame.
38
+ */
39
+ export declare function applyProbeLighting(root: THREE.Object3D): ProbeLit;
@@ -0,0 +1,28 @@
1
+ import * as THREE from "three";
2
+ /**
3
+ * Frees each mesh's vertex and index arrays once three.js has uploaded them. Bounds are
4
+ * computed first: frustum culling, sorting and Box3.setFromObject read them. For meshes
5
+ * `keepPositions` accepts, the positions and indices stay (arrays shared with other meshes
6
+ * stay if any of them keeps them).
7
+ */
8
+ export declare function freeGeometryOnUpload(meshes: THREE.Mesh[], keepPositions?: ((mesh: THREE.Mesh) => boolean) | null): void;
9
+ /**
10
+ * Uploads every mesh under `root` now, instead of when each first comes into view, so the
11
+ * arrays freeGeometryOnUpload watches are freed during loading. It goes through a normal
12
+ * render (three.js has no other way to upload a buffer): unculled, into a 1×1 target, with
13
+ * one material for everything and an empty draw range, so nothing is drawn or compiled
14
+ * beyond that material. It works through the meshes about `chunkBytes` at a time, letting
15
+ * the page draw a frame in between (a map's geometry is a few hundred MB).
16
+ */
17
+ export declare function uploadGeometry(gl: THREE.WebGLRenderer, root: THREE.Object3D, chunkBytes?: number): Promise<void>;
18
+ /** Frees a texture's pixels once three.js has uploaded it (Texture.onUpdate). Width and height stay. */
19
+ export declare function freeTextureOnUpload(t: THREE.Texture): void;
20
+ /** Drops a texture's CPU-side pixels: compressed mip levels, DataTexture data or an ImageBitmap. */
21
+ export declare function freeTexturePixels(t: THREE.Texture): void;
22
+ /**
23
+ * Runs `fn` (a glTF parse) with meshopt decoding on a worker that's closed afterwards. On
24
+ * the page, the decoder's WebAssembly memory grows to the biggest buffer it decoded (tens of
25
+ * MB for a map's index buffer) and never shrinks. MeshoptDecoder is shared, so concurrent
26
+ * loads share the worker.
27
+ */
28
+ export declare function withMeshoptWorker<T>(fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,84 @@
1
+ import * as THREE from "three";
2
+ import { SmokeVolumes } from "../smoke/volume";
3
+ import { type GameMap, type GameMapOptions } from "./index";
4
+ import { Cs2PostPass } from "./post";
5
+ export interface StageOptions extends GameMapOptions {
6
+ /** Shadow map size for the sun (players cast real-time shadows). Default 2048. */
7
+ shadowMapSize?: number;
8
+ /** Half-size of the sun's shadow frustum around the camera, metres. */
9
+ shadowExtent?: number;
10
+ /** MSAA samples of the HDR target. */
11
+ samples?: number;
12
+ /** Fixed exposure instead of CS2's auto exposure. */
13
+ exposure?: number;
14
+ /** "low": fewer smoke ray-march steps. */
15
+ quality?: "high" | "low";
16
+ }
17
+ /** Called once a map is loaded, before it's shown (e.g. to add players, whose lights change every shader). */
18
+ export type StagePrepare = (map: GameMap) => void | Promise<void>;
19
+ /**
20
+ * The "game look" around a loaded CS2 map: the map's sky as background and image-based
21
+ * lighting, its sun (shadow-mapped near the camera, for players), gradient fog, wind,
22
+ * and an HDR pipeline: MSAA scene → volumetric smoke (against the scene's depth, only
23
+ * while one is on screen) → CS2's auto exposure, bloom and tone curve (post.ts).
24
+ *
25
+ * A loaded map is shown once its shaders are compiled (in parallel where the browser
26
+ * can), so the page doesn't freeze compiling them on the first frames.
27
+ */
28
+ export declare class GameStage {
29
+ private gl;
30
+ private scene;
31
+ private camera;
32
+ private opts;
33
+ readonly sun: THREE.DirectionalLight;
34
+ /** Fill light for things without lightmaps (players, props): the sky's ambient. */
35
+ readonly fill: THREE.HemisphereLight;
36
+ /** The map on stage; null until loaded, and while it loads again after a lost WebGL context. */
37
+ map: GameMap | null;
38
+ /** Volumetric smoke; effects feed it (EffectsSystem.setSmokeVolumes). */
39
+ readonly smoke: SmokeVolumes;
40
+ readonly post: Cs2PostPass;
41
+ /** Seconds per frame for wind and exposure; null uses real time (set it when rendering frame by frame). */
42
+ fixedDelta: number | null;
43
+ /** Wind and foliage clock, seconds. */
44
+ time: number;
45
+ private lastFrame;
46
+ /** The scene's HDR target: MSAA colour, and a depth texture for the smoke. */
47
+ private target;
48
+ private pmrem;
49
+ private envRT;
50
+ private skyRT;
51
+ private v;
52
+ private url;
53
+ private loads;
54
+ private disposed;
55
+ private latest;
56
+ private onLost;
57
+ private onRestored;
58
+ constructor(gl: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.PerspectiveCamera, opts?: StageOptions);
59
+ /**
60
+ * Loads a map and puts it on stage, replacing (and disposing) the one before. If another
61
+ * load starts before this one finishes, this one resolves to the newer map. `prepare`
62
+ * runs once the map is loaded, before its shaders compile and it's shown.
63
+ */
64
+ load(url: string, prepare?: StagePrepare | null): Promise<GameMap>;
65
+ /**
66
+ * Compiles the shaders of `root` (not yet in the scene) and of everything in the scene,
67
+ * as they'll render: against the scene's lights, fog and environment, into the HDR
68
+ * target. With KHR_parallel_shader_compile this doesn't block the page.
69
+ */
70
+ private precompile;
71
+ /** Lights, sky, fog and smoke for a loaded map; the map itself goes into the scene once compiled. */
72
+ private setMap;
73
+ /** Background and image-based lighting from the map's sky. */
74
+ private setSky;
75
+ /** env_wind's strength at time t: 1 at its base speed, gusts on a fixed schedule. */
76
+ windStrength(t: number): number;
77
+ /** Keeps the sun's shadow frustum centred in front of the camera. */
78
+ update(): void;
79
+ /** The HDR target the scene renders into (for pre-compiling materials in the right variant). */
80
+ get renderTarget(): THREE.WebGLRenderTarget<THREE.Texture<unknown, THREE.TextureEventMap>>;
81
+ render(): void;
82
+ setSize(w: number, h: number): void;
83
+ dispose(): void;
84
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * The replay file written by the extractor (extractor/replay/extract.go):
3
+ *
4
+ * "CSRP" | u32 version | u32 jsonLen | JSON header | zero pad to 4 bytes
5
+ * i32 ticks[frames]
6
+ * f32 pos[frames][players][4] x, y, z (game units), yaw (degrees)
7
+ * u8 state[frames][players][4] hp, flags (see FLAG), weapon index, armor
8
+ * f32 bomb[frames][3] bomb position
9
+ *
10
+ * All little endian. Positions are game units (inches, Z up). A player that
11
+ * isn't on the server in a frame is all zeros there.
12
+ */
13
+ export declare const FLAG: {
14
+ readonly Alive: 1;
15
+ readonly CT: 2;
16
+ readonly Duck: 4;
17
+ readonly Blind: 8;
18
+ readonly Bomb: 16;
19
+ readonly Defusing: 32;
20
+ readonly Scoped: 64;
21
+ readonly Kit: 128;
22
+ };
23
+ export type Side = "T" | "CT";
24
+ export interface ReplayPlayer {
25
+ name: string;
26
+ /** SteamID64 as a string, "" for bots. */
27
+ steamId: string;
28
+ }
29
+ export interface ReplayRound {
30
+ /** Round number as shown in game, starting at 1. */
31
+ num: number;
32
+ /** Frame of the round start (freeze time starts). */
33
+ start: number;
34
+ /** Frame freeze time ended, -1 if it never did. */
35
+ live: number;
36
+ /** Frame the winner was known. */
37
+ end: number;
38
+ winner?: Side;
39
+ /** bomb, defuse, elimination, time, surrender, or the game's reason number. */
40
+ reason?: string;
41
+ /** Scores at the start of the round. */
42
+ scoreT: number;
43
+ scoreCT: number;
44
+ /** Team names by side in this round; they swap at halftime. */
45
+ teamT: string;
46
+ teamCT: string;
47
+ }
48
+ export interface ReplayKill {
49
+ f: number;
50
+ /** Player index, -1 for the world. */
51
+ killer: number;
52
+ victim: number;
53
+ assister: number;
54
+ weapon: string;
55
+ hs?: boolean;
56
+ wb?: boolean;
57
+ smoke?: boolean;
58
+ noscope?: boolean;
59
+ flash?: boolean;
60
+ }
61
+ export type GrenadeTypeName = "Smoke Grenade" | "Flashbang" | "HE Grenade" | "Molotov" | "Incendiary Grenade" | "Decoy Grenade";
62
+ export interface ReplayGrenade {
63
+ type: GrenadeTypeName | (string & {});
64
+ thrower: number;
65
+ /** Frame of the first path point. */
66
+ start: number;
67
+ /** x, y, z per frame from start. */
68
+ path: number[];
69
+ effectAt?: number;
70
+ effectEnd?: number;
71
+ effectPos?: [number, number, number];
72
+ /**
73
+ * Smokes: the game's voxel cloud data (CS2's m_VoxelFrameData merged into one
74
+ * keyframe, base64) and its grid centre in game units. See FORMAT.md.
75
+ */
76
+ voxels?: {
77
+ origin: [number, number, number];
78
+ data: string;
79
+ };
80
+ }
81
+ export interface ReplayBombEvent {
82
+ f: number;
83
+ event: "plant" | "defuse" | "explode";
84
+ player: number;
85
+ site?: string;
86
+ pos: [number, number, number];
87
+ }
88
+ /**
89
+ * weapon_fire events (gunshots, knife swings, grenade throws) as parallel arrays.
90
+ * Optional: replays from older extractors don't have them.
91
+ */
92
+ export interface ReplayShots {
93
+ /** In-game tick (sub-frame precision; map to time with `ticks`). */
94
+ tick: number[];
95
+ /** Player index. */
96
+ p: number[];
97
+ /** Index into `weapons`. */
98
+ w: number[];
99
+ /** View angles at the shot, degrees; pitch > 0 looks down. */
100
+ yaw: number[];
101
+ pitch: number[];
102
+ }
103
+ /** player_hurt events as parallel arrays. Optional, like shots. */
104
+ export interface ReplayHurts {
105
+ tick: number[];
106
+ victim: number[];
107
+ /** -1 for the world (fall damage, the bomb). */
108
+ attacker: number[];
109
+ /** Health damage taken. */
110
+ dmg: number[];
111
+ /** 0 generic, 1 head, 2 chest, 3 stomach, 4 left arm, 5 right arm, 6 left leg, 7 right leg, 8 neck. */
112
+ hit: number[];
113
+ }
114
+ export interface ReplayHeader {
115
+ map: string;
116
+ server: string;
117
+ protocol: number;
118
+ tickRate: number;
119
+ hz: number;
120
+ frames: number;
121
+ players: ReplayPlayer[];
122
+ /** Weapon names; index 0 is "no weapon". */
123
+ weapons: string[];
124
+ rounds: ReplayRound[];
125
+ kills: ReplayKill[];
126
+ grenades: ReplayGrenade[];
127
+ bomb: ReplayBombEvent[];
128
+ shots?: ReplayShots;
129
+ hurts?: ReplayHurts;
130
+ }
131
+ export interface Replay extends ReplayHeader {
132
+ version: number;
133
+ ticks: Int32Array;
134
+ /** [frames][players][x, y, z, yaw] */
135
+ pos: Float32Array;
136
+ /** [frames][players][hp, flags, weapon, armor] */
137
+ state: Uint8Array;
138
+ /** [frames][x, y, z] */
139
+ bombPos: Float32Array;
140
+ }
141
+ /** The newest file format version this build reads. */
142
+ export declare const FORMAT_VERSION = 1;
143
+ export declare class ReplayFormatError extends Error {
144
+ name: string;
145
+ }
146
+ export type ReplaySource = string | URL | Blob | ArrayBuffer | Uint8Array | Response;
147
+ /** "CSRP" */
148
+ export declare const isReplayFile: (bytes: Uint8Array) => boolean;
149
+ /** "PBDEMS2\0", a CS2 demo. */
150
+ export declare const isDemoFile: (bytes: Uint8Array) => boolean;
151
+ export declare const isGzip: (bytes: Uint8Array) => boolean;
152
+ /** Reads a replay file. The typed arrays are views on the given buffer. */
153
+ export declare function readReplay(data: ArrayBuffer | Uint8Array): Replay;
154
+ /** Decompresses gzip data (a .replay.gz or .dem.gz without Content-Encoding). */
155
+ export declare function gunzip(bytes: Uint8Array): Promise<Uint8Array>;
156
+ /** Fetches or reads the source into memory. */
157
+ export declare function readSource(source: ReplaySource, init?: RequestInit): Promise<Uint8Array>;
158
+ /**
159
+ * Loads a replay file from a URL, Response, Blob or buffer. Gzipped files are
160
+ * decompressed (servers that send Content-Encoding: gzip are handled by fetch).
161
+ * Demos are rejected: use openReplay() from @matchomag/cs2-replay/parse for those.
162
+ */
163
+ export declare function loadReplay(source: ReplaySource, init?: RequestInit): Promise<Replay>;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Live replays: a Replay that grows while a match is broadcast. The extractor's live
3
+ * mode (extractor/replay/live.go) sends updates in the replay file's own layout:
4
+ *
5
+ * "CSRU" | u32 version | u32 jsonLen | JSON | zero pad to 4 bytes
6
+ * i32 ticks[frames] | f32 pos[frames][players][4] | u8 state[frames][players][4] | pad | f32 bomb[frames][3]
7
+ *
8
+ * The JSON says where the frames go (`start`) and what changed in the header (see
9
+ * FORMAT.md). LiveReplay applies them to one Replay object in place, so viewers and
10
+ * models built on it see it grow. No DOM here: it runs anywhere.
11
+ */
12
+ import { Emitter } from "./playback";
13
+ import type { Replay, ReplayBombEvent, ReplayGrenade, ReplayHurts, ReplayKill, ReplayPlayer, ReplayRound, ReplayShots } from "./format";
14
+ /** The newest live update format version this build reads. */
15
+ export declare const UPDATE_VERSION = 1;
16
+ interface ListPatch<T> {
17
+ from: number;
18
+ items: T[];
19
+ }
20
+ /** A grenade in an update: its path from `pathFrom` on, and `voxels` only when they changed. */
21
+ export interface GrenadeUpdate extends Omit<ReplayGrenade, "path"> {
22
+ i: number;
23
+ pathFrom: number;
24
+ path: number[];
25
+ }
26
+ /** One decoded live update. */
27
+ export interface LiveUpdate {
28
+ map: string;
29
+ server: string;
30
+ protocol: number;
31
+ tickRate: number;
32
+ hz: number;
33
+ /** Index of the first frame in this update. */
34
+ start: number;
35
+ frames: number;
36
+ /** The whole lists, as of this update. */
37
+ players: ReplayPlayer[];
38
+ weapons: string[];
39
+ /** Rounds from `from` on are replaced; the others are added to from `from`. */
40
+ rounds?: ListPatch<ReplayRound>;
41
+ kills?: ListPatch<ReplayKill>;
42
+ bomb?: ListPatch<ReplayBombEvent>;
43
+ grenades?: GrenadeUpdate[];
44
+ shots?: ReplayShots & {
45
+ from: number;
46
+ };
47
+ hurts?: ReplayHurts & {
48
+ from: number;
49
+ };
50
+ /** The broadcast is over: nothing follows. */
51
+ final?: boolean;
52
+ ticks: Int32Array;
53
+ /** [frames][players.length][x, y, z, yaw] */
54
+ pos: Float32Array;
55
+ state: Uint8Array;
56
+ bombPos: Float32Array;
57
+ }
58
+ /** "CSRU" */
59
+ export declare const isLiveUpdate: (b: Uint8Array) => boolean;
60
+ /** Decodes a live update. The typed arrays are copies, so the buffer can go. */
61
+ export declare function readUpdate(data: ArrayBuffer | Uint8Array): LiveUpdate;
62
+ /** An empty replay to grow, before the first update. */
63
+ export declare function emptyReplay(map?: string): Replay;
64
+ /**
65
+ * Why a live replay stopped growing. "over": the broadcast ended. "map": it ended and
66
+ * the same playcast URL now broadcasts another map (open it again to follow).
67
+ * "idle": nothing new arrived for a while (the server or relay went away). "error":
68
+ * see `error`. "closed": close() was called or the signal aborted.
69
+ */
70
+ export type LiveEndReason = "over" | "map" | "idle" | "error" | "closed";
71
+ export interface LiveEvents extends Record<string, unknown> {
72
+ /** New frames or events arrived (the replay has grown). */
73
+ update: {
74
+ frames: number;
75
+ revision: number;
76
+ };
77
+ /** No more updates. */
78
+ end: {
79
+ reason: LiveEndReason;
80
+ error?: Error;
81
+ };
82
+ }
83
+ /**
84
+ * A replay being broadcast. `replay` is one object that grows in place: its arrays are
85
+ * replaced by longer views and its lists are added to, so read them from `replay` each
86
+ * time rather than keeping them. Viewers given `replay` follow it (LiveReplay.of).
87
+ */
88
+ export declare class LiveReplay extends Emitter<LiveEvents> {
89
+ readonly replay: Replay;
90
+ /** Bumped by every update; renderers compare it to see whether to pick up new data. */
91
+ revision: number;
92
+ ended: boolean;
93
+ endReason: LiveEndReason | null;
94
+ /** End ("over") with the update marked final. Off when something else knows better why it ended (openPlaycast). */
95
+ protected endOnFinal: boolean;
96
+ /** Seconds of play per broadcast fragment (the playcast's keyframe_interval): updates arrive about this often. */
97
+ fragmentSeconds: number;
98
+ error: Error | null;
99
+ private cap;
100
+ private ticksBuf;
101
+ private posBuf;
102
+ private stateBuf;
103
+ private bombBuf;
104
+ private stride;
105
+ constructor(replay?: Replay);
106
+ /** The live replay behind a replay object, if it is one. */
107
+ static of(replay: Replay | null | undefined): LiveReplay | null;
108
+ /** Applies an update (bytes as the extractor sends them, or decoded). */
109
+ apply(update: LiveUpdate | Uint8Array | ArrayBuffer): void;
110
+ /** Ends the replay (no more updates); `apply` ignores anything after. */
111
+ end(reason: LiveEndReason, error?: Error): void;
112
+ /** Makes room for `frames` frames of `np` players, repacking when the player count grew. */
113
+ private grow;
114
+ }
115
+ export {};