@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.
- package/FORMAT.md +350 -0
- package/README.md +453 -2
- package/bin/demo-replay-darwin-amd64 +0 -0
- package/bin/demo-replay-darwin-arm64 +0 -0
- package/bin/demo-replay-linux-amd64 +0 -0
- package/bin/demo-replay-linux-arm64 +0 -0
- package/bin/demo-replay-windows-amd64.exe +0 -0
- package/bin/demo-replay.js +22 -0
- package/dist/2d/index.js +1 -0
- package/dist/3d/index.js +11 -0
- package/dist/chunks/actors-EZRYEB4I.js +177 -0
- package/dist/chunks/chunk-5BFKVD63.js +1 -0
- package/dist/chunks/chunk-D5ST2XVO.js +106 -0
- package/dist/chunks/chunk-DQPOBPMK.js +1 -0
- package/dist/chunks/chunk-FBSLUYGT.js +1 -0
- package/dist/chunks/chunk-Q37CWKZX.js +12 -0
- package/dist/chunks/chunk-VSIECNZM.js +1 -0
- package/dist/chunks/chunk-YJG3LSSB.js +1 -0
- package/dist/chunks/chunk-YO73RW3Y.js +1 -0
- package/dist/chunks/look-2WBUGHMJ.js +669 -0
- package/dist/index.js +1 -0
- package/dist/maps/index.js +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/wasm/replay.wasm +0 -0
- package/dist/parse/worker.js +1 -0
- package/dist/types/2d/index.d.ts +17 -0
- package/dist/types/2d/radar.d.ts +35 -0
- package/dist/types/3d/actors.d.ts +90 -0
- package/dist/types/3d/characters/anim.d.ts +93 -0
- package/dist/types/3d/characters/ao.d.ts +3 -0
- package/dist/types/3d/characters/body.d.ts +37 -0
- package/dist/types/3d/characters/builder.d.ts +82 -0
- package/dist/types/3d/characters/index.d.ts +74 -0
- package/dist/types/3d/characters/rig.d.ts +73 -0
- package/dist/types/3d/characters/textures.d.ts +4 -0
- package/dist/types/3d/characters/viewmodel.d.ts +51 -0
- package/dist/types/3d/characters/weapons.d.ts +25 -0
- package/dist/types/3d/follow.d.ts +43 -0
- package/dist/types/3d/fx/batch.d.ts +87 -0
- package/dist/types/3d/fx/context.d.ts +34 -0
- package/dist/types/3d/fx/explosion.d.ts +14 -0
- package/dist/types/3d/fx/fire.d.ts +11 -0
- package/dist/types/3d/fx/index.d.ts +84 -0
- package/dist/types/3d/fx/lights.d.ts +25 -0
- package/dist/types/3d/fx/meshes.d.ts +18 -0
- package/dist/types/3d/fx/misc.d.ts +15 -0
- package/dist/types/3d/fx/random.d.ts +21 -0
- package/dist/types/3d/fx/smoke.d.ts +10 -0
- package/dist/types/3d/fx/textures.d.ts +29 -0
- package/dist/types/3d/fx/types.d.ts +117 -0
- package/dist/types/3d/greybox.d.ts +22 -0
- package/dist/types/3d/index.d.ts +127 -0
- package/dist/types/3d/look.d.ts +49 -0
- package/dist/types/3d/markers.d.ts +23 -0
- package/dist/types/3d/smoke/volume.d.ts +95 -0
- package/dist/types/3d/smoke/voxels.d.ts +87 -0
- package/dist/types/3d/world/index.d.ts +179 -0
- package/dist/types/3d/world/look.d.ts +16 -0
- package/dist/types/3d/world/material.d.ts +128 -0
- package/dist/types/3d/world/post.d.ts +75 -0
- package/dist/types/3d/world/probes.d.ts +39 -0
- package/dist/types/3d/world/release.d.ts +28 -0
- package/dist/types/3d/world/stage.d.ts +84 -0
- package/dist/types/core/format.d.ts +163 -0
- package/dist/types/core/live.d.ts +115 -0
- package/dist/types/core/model.d.ts +164 -0
- package/dist/types/core/playback.d.ts +82 -0
- package/dist/types/core/theme.d.ts +46 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/maps/index.d.ts +258 -0
- package/dist/types/parse/index.d.ts +108 -0
- package/dist/types/ui/shell.d.ts +131 -0
- package/dist/types/ui/styles.d.ts +1 -0
- package/package.json +68 -4
package/FORMAT.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Replay file format (`CSRP`, version 1)
|
|
2
|
+
|
|
3
|
+
A replay is a compact timeline of one map of a CS2 demo: where every player
|
|
4
|
+
was and what state they were in, sampled at a fixed rate, plus the round,
|
|
5
|
+
kill, grenade and bomb events. It's what the viewers of `@matchomag/cs2-replay`
|
|
6
|
+
play. The extractor (`extractor/replay/extract.go`) writes it, either natively
|
|
7
|
+
(`demo-replay`) or in the browser (`parseDemo()`). `readReplay()` in
|
|
8
|
+
`src/core/format.ts` reads it.
|
|
9
|
+
|
|
10
|
+
For the 305 MB, 16-round sample demo, the replay is 8.0 MB, or 2.5 MB gzipped.
|
|
11
|
+
A replay is **not plain JSON**. It's a small binary container: a JSON header
|
|
12
|
+
with everything that happens once, followed by flat typed arrays with
|
|
13
|
+
everything that happens every frame.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
offset size content
|
|
17
|
+
0 4 magic "CSRP" (ASCII)
|
|
18
|
+
4 4 u32 format version (1)
|
|
19
|
+
8 4 u32 byte length of the JSON header (n)
|
|
20
|
+
12 n JSON header, UTF-8
|
|
21
|
+
12+n 0–3 zero padding to a multiple of 4
|
|
22
|
+
ticks 4 × F i32 ticks[F]
|
|
23
|
+
pos 16 × F × P f32 pos[F][P][4] x, y, z, yaw
|
|
24
|
+
state 4 × F × P u8 state[F][P][4] hp, flags, weapon, armor
|
|
25
|
+
0–3 zero padding to a multiple of 4
|
|
26
|
+
bomb 12 × F f32 bomb[F][3] x, y, z
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`F` is `header.frames` and `P` is `header.players.length`. All numbers are
|
|
30
|
+
little endian. The start of each array (`ticks`, `pos`, `state`, `bomb`) is
|
|
31
|
+
`header.offsets`, in bytes from the start of the file. Use the offsets rather
|
|
32
|
+
than computing them, so a reader keeps working if padding changes. Every
|
|
33
|
+
offset is a multiple of 4, so the arrays can be read as typed-array views on
|
|
34
|
+
the file's buffer without copying.
|
|
35
|
+
|
|
36
|
+
Files are often stored or served gzipped (`.replay.gz`, or
|
|
37
|
+
`Content-Encoding: gzip`). `loadReplay()` handles both.
|
|
38
|
+
|
|
39
|
+
## Conventions
|
|
40
|
+
|
|
41
|
+
- **Frames.** A frame is one sample. Frame `i` is at in-game tick `ticks[i]`.
|
|
42
|
+
Samples are taken every `tickRate / hz` ticks (4 ticks at 64 tick and
|
|
43
|
+
16 Hz), but the spacing can vary slightly, so use `ticks` for time. The
|
|
44
|
+
seconds between frames `a` and `b` are `(ticks[b] - ticks[a]) / tickRate`.
|
|
45
|
+
- **Event frames.** An event's frame (`f`, `start`, `live`, `end`, `effectAt`,
|
|
46
|
+
…) is the index of the first frame sampled *after* the event. So the event
|
|
47
|
+
happened between frame `f - 1` and frame `f`. Positions "at the moment of a
|
|
48
|
+
kill" are best taken from frame `f - 1`.
|
|
49
|
+
- **Players** are referenced by their index in `header.players`. `-1` means
|
|
50
|
+
nobody (the world, no assister, no thrower).
|
|
51
|
+
- **Coordinates** are game units (1 unit = 1 inch), in the map's own world
|
|
52
|
+
coordinates, Z up. Player positions are at the feet.
|
|
53
|
+
- **Yaw** is in degrees, `0` = +x, increasing counter-clockwise seen from
|
|
54
|
+
above (towards +y), in `(-180, 180]`. Interpolate it the short way round
|
|
55
|
+
(`lerpAngle()`).
|
|
56
|
+
- **Recording** starts at the first round start after warmup. If the match is
|
|
57
|
+
restarted (`mp_restartgame`, e.g. after a knife round), the rounds recorded
|
|
58
|
+
until then are dropped from `rounds`, but their frames stay. So frames before
|
|
59
|
+
`rounds[0].start` belong to no round.
|
|
60
|
+
- **Optional fields** are left out when they're false, zero or unknown, as noted
|
|
61
|
+
below.
|
|
62
|
+
|
|
63
|
+
## JSON header
|
|
64
|
+
|
|
65
|
+
Example, from the sample replay (arrays shortened):
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"map": "de_overpass",
|
|
70
|
+
"server": "MatchZy | Team_A vs Team_B",
|
|
71
|
+
"protocol": 14163,
|
|
72
|
+
"tickRate": 64,
|
|
73
|
+
"hz": 16,
|
|
74
|
+
"frames": 32727,
|
|
75
|
+
"players": [
|
|
76
|
+
{ "name": "xelex", "steamId": "76561198998266210" },
|
|
77
|
+
{ "name": "Lake", "steamId": "76561198337484196" }
|
|
78
|
+
],
|
|
79
|
+
"weapons": ["", "USP-S", "C4", "Glock-18", "Knife", "Smoke Grenade"],
|
|
80
|
+
"rounds": [
|
|
81
|
+
{ "num": 1, "start": 0, "live": 424, "end": 2192, "winner": "CT", "reason": "elimination",
|
|
82
|
+
"scoreT": 0, "scoreCT": 0, "teamT": "M80", "teamCT": "MOUZ" }
|
|
83
|
+
],
|
|
84
|
+
"kills": [
|
|
85
|
+
{ "f": 726, "killer": 9, "victim": 8, "assister": -1, "weapon": "USP-S", "hs": true }
|
|
86
|
+
],
|
|
87
|
+
"grenades": [
|
|
88
|
+
{ "type": "Smoke Grenade", "thrower": 3, "start": 462,
|
|
89
|
+
"path": [-2101.3, 974.5, 589.3, -2077, 944.8, 623.2],
|
|
90
|
+
"effectAt": 584, "effectEnd": 937, "effectPos": [-548.4, -730.4, 16.2] }
|
|
91
|
+
],
|
|
92
|
+
"bomb": [
|
|
93
|
+
{ "f": 8665, "event": "plant", "player": 1, "site": "B", "pos": [-1251.9, 5, 103.5] }
|
|
94
|
+
],
|
|
95
|
+
"offsets": { "ticks": 964848, "pos": 1095756, "state": 6332076, "bomb": 7641156 }
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Top level
|
|
100
|
+
|
|
101
|
+
| Field | Type | Meaning |
|
|
102
|
+
| --- | --- | --- |
|
|
103
|
+
| `map` | string | Map name from the demo header, e.g. `de_overpass`. |
|
|
104
|
+
| `server` | string | Server name from the demo header. |
|
|
105
|
+
| `protocol` | number | The demo's network protocol, which is the game's patch version without dots (14163 = 1.41.6.3). It tells you which version of the map the demo was played on. |
|
|
106
|
+
| `tickRate` | number | Server ticks per second, usually 64. |
|
|
107
|
+
| `hz` | number | Samples per second, 16 unless the extractor ran with `-hz`. |
|
|
108
|
+
| `frames` | number | Number of frames, `F`. |
|
|
109
|
+
| `players` | [Player] | Everyone who played on T or CT, in the order first seen. |
|
|
110
|
+
| `weapons` | [string] | Weapon names, referenced by index from `state`. Index 0 is `""`, no weapon. |
|
|
111
|
+
| `rounds` | [Round] | Rounds in order. |
|
|
112
|
+
| `kills` | [Kill] | Kills in order. |
|
|
113
|
+
| `grenades` | [Grenade] | Thrown grenades in the order thrown. |
|
|
114
|
+
| `bomb` | [BombEvent] | Plants, defuses and explosions in order. |
|
|
115
|
+
| `shots` | Shots? | Every weapon fired, as parallel arrays. Left out by older extractors. |
|
|
116
|
+
| `hurts` | Hurts? | Every time a player took damage, as parallel arrays. Left out by older extractors. |
|
|
117
|
+
| `offsets` | object | Byte offsets of the arrays: `ticks`, `pos`, `state`, `bomb`. |
|
|
118
|
+
|
|
119
|
+
### Player
|
|
120
|
+
|
|
121
|
+
| Field | Type | Meaning |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| `name` | string | Last name seen in the demo. |
|
|
124
|
+
| `steamId` | string | SteamID64 as a decimal string. Bots have `""` and are told apart by name. |
|
|
125
|
+
|
|
126
|
+
### Round
|
|
127
|
+
|
|
128
|
+
| Field | Type | Meaning |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| `num` | number | Round number as the game counts it, from 1. Overtime rounds continue the count. |
|
|
131
|
+
| `start` | frame | Round start: freeze time begins. |
|
|
132
|
+
| `live` | frame | Freeze time ends, or `-1` if it never did. |
|
|
133
|
+
| `end` | frame | The round's winner is known. For a round that never ended, it's the next round's `start` or, at the end of the demo, the last frame. `-1` in a live replay while the round is being played. |
|
|
134
|
+
| `winner` | `"T"` \| `"CT"` | The side that won. Left out if the round never ended. |
|
|
135
|
+
| `reason` | string | How it was won: `elimination`, `bomb` (exploded), `defuse`, `time`, `surrender`, or the game's reason number as a string. Left out if the round never ended. |
|
|
136
|
+
| `scoreT`, `scoreCT` | number | Each side's score at the start of the round. Add 1 to the winner's after `end`. |
|
|
137
|
+
| `teamT`, `teamCT` | string | Team names by side in this round, which swap at halftime. `""` when the server set none. |
|
|
138
|
+
|
|
139
|
+
Frames from `end` up to the next round's `start` are the time after the round
|
|
140
|
+
is won.
|
|
141
|
+
|
|
142
|
+
### Kill
|
|
143
|
+
|
|
144
|
+
| Field | Type | Meaning |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
| `f` | frame | When the kill happened. |
|
|
147
|
+
| `killer` | player | `-1` for the world (fall damage, the bomb). Equal to `victim` for a suicide. |
|
|
148
|
+
| `victim` | player | |
|
|
149
|
+
| `assister` | player | `-1` if none. |
|
|
150
|
+
| `weapon` | string | E.g. `AK-47`, `AWP`, `HE Grenade`. `""` if unknown. |
|
|
151
|
+
| `hs` | true? | Headshot. |
|
|
152
|
+
| `wb` | true? | Through a wall (wallbang). |
|
|
153
|
+
| `smoke` | true? | Through a smoke. |
|
|
154
|
+
| `noscope` | true? | Scoped weapon fired without scope. |
|
|
155
|
+
| `flash` | true? | The victim was flashed by an assisting teammate. |
|
|
156
|
+
|
|
157
|
+
### Grenade
|
|
158
|
+
|
|
159
|
+
| Field | Type | Meaning |
|
|
160
|
+
| --- | --- | --- |
|
|
161
|
+
| `type` | string | `Smoke Grenade`, `Flashbang`, `HE Grenade`, `Molotov`, `Incendiary Grenade` or `Decoy Grenade`. |
|
|
162
|
+
| `thrower` | player | `-1` if unknown. |
|
|
163
|
+
| `start` | frame | When it was thrown: the frame of the first path point. |
|
|
164
|
+
| `path` | [number] | The projectile's position, `x, y, z` for each frame from `start` while it existed. Point `k` is at frame `start + k`, so `path.length / 3` points in all. Empty for a fire whose throw happened before recording started. |
|
|
165
|
+
| `effectAt` | frame? | When it went off: smoke spreads, fire starts, flash or HE explodes, decoy starts. Left out if it never did. |
|
|
166
|
+
| `effectEnd` | frame? | When the effect ended: smoke fades, fire burns out, decoy stops. Equal to `effectAt` for flashes and HEs. |
|
|
167
|
+
| `effectPos` | [x, y, z]? | Where it went off. |
|
|
168
|
+
| `voxels` | SmokeVoxels? | Smokes: the game's own voxel cloud. Left out for other grenades and for replays from older extractors. |
|
|
169
|
+
|
|
170
|
+
The projectile flies from `start` until `min(effectAt, start + path.length/3 - 1)`.
|
|
171
|
+
|
|
172
|
+
### SmokeVoxels
|
|
173
|
+
|
|
174
|
+
CS2 networks each smoke's cloud on its projectile (`m_VoxelFrameData`): an
|
|
175
|
+
append-only log of the flood fill's seed cells and of 4×4×4 bricks of world
|
|
176
|
+
geometry, sent as the cloud reaches them. The grid is 32³ cells of 20 game
|
|
177
|
+
units, centred on `origin` (cell `i` spans `origin + (i - 16) * 20` to
|
|
178
|
+
`origin + (i - 15) * 20` on each axis). Clients fill the cloud from the seeds
|
|
179
|
+
through open cells; bricks never sent were never reached.
|
|
180
|
+
|
|
181
|
+
| Field | Type | Meaning |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| `origin` | [x, y, z] | Grid centre, game units (`m_vSmokeDetonationPos`, within a unit of `effectPos`). |
|
|
184
|
+
| `data` | base64 | The log merged into one keyframe in the game's layout, little endian: `u8 0`, `u8 3`, `u8 seeds`, then `seeds` × 8 bytes `[x, y, z, density, 0, 0, 0, 0]` (cells; density 0 means unused), `u16 bricks`, then `bricks` × 10 bytes `[u16 brick, u64 solid]`, then `u8 0`. A brick index is the Morton code (bits x, y, z, x, y, z, …) of the brick in the 8³ brick grid; bit `k` of `solid` is the cell whose Morton code within the brick is `k`. A set bit is world geometry. |
|
|
185
|
+
|
|
186
|
+
The viewer's fill (`src/3d/smoke/voxels.ts`) is fitted to which bricks the
|
|
187
|
+
server sent: a Dijkstra fill over 26 neighbours with Euclidean step costs,
|
|
188
|
+
upward steps costing double, no corner cutting, reaching 6 cells from the
|
|
189
|
+
seeds.
|
|
190
|
+
|
|
191
|
+
### BombEvent
|
|
192
|
+
|
|
193
|
+
| Field | Type | Meaning |
|
|
194
|
+
| --- | --- | --- |
|
|
195
|
+
| `f` | frame | When it happened. |
|
|
196
|
+
| `event` | `"plant"` \| `"defuse"` \| `"explode"` | |
|
|
197
|
+
| `player` | player | Who planted or defused, `-1` for explosions. |
|
|
198
|
+
| `site` | `"A"` \| `"B"`? | The bomb site. |
|
|
199
|
+
| `pos` | [x, y, z] | Where the bomb was. |
|
|
200
|
+
|
|
201
|
+
### Shots
|
|
202
|
+
|
|
203
|
+
One entry per `weapon_fire` event: gunshots (one per bullet), knife swings,
|
|
204
|
+
grenade throws, the Zeus. Stored as parallel arrays, so entry `i` is
|
|
205
|
+
`tick[i]`, `p[i]`, … They are in tick order.
|
|
206
|
+
|
|
207
|
+
| Field | Type | Meaning |
|
|
208
|
+
| --- | --- | --- |
|
|
209
|
+
| `tick` | [number] | In-game tick of the shot. Shots fall between frames: find the frame with `ticks`. |
|
|
210
|
+
| `p` | [player] | Who fired. |
|
|
211
|
+
| `w` | [number] | Weapon, an index into `weapons`. |
|
|
212
|
+
| `yaw` | [number] | View yaw at the shot, degrees, like the per-frame yaw. |
|
|
213
|
+
| `pitch` | [number] | View pitch at the shot, degrees in `(-180, 180]`; positive looks down. |
|
|
214
|
+
|
|
215
|
+
### Hurts
|
|
216
|
+
|
|
217
|
+
One entry per `player_hurt` event, as parallel arrays in tick order.
|
|
218
|
+
|
|
219
|
+
| Field | Type | Meaning |
|
|
220
|
+
| --- | --- | --- |
|
|
221
|
+
| `tick` | [number] | In-game tick. |
|
|
222
|
+
| `victim` | [player] | Who was hurt. |
|
|
223
|
+
| `attacker` | [player] | Who did it; `-1` for the world (falls, the bomb). |
|
|
224
|
+
| `dmg` | [number] | Health lost. |
|
|
225
|
+
| `hit` | [number] | Hit group: 0 generic, 1 head, 2 chest, 3 stomach, 4 left arm, 5 right arm, 6 left leg, 7 right leg, 8 neck. |
|
|
226
|
+
|
|
227
|
+
## Per-frame arrays
|
|
228
|
+
|
|
229
|
+
**`ticks[F]`** (i32): the in-game tick of each frame.
|
|
230
|
+
|
|
231
|
+
**`pos[F][P][4]`** (f32): for frame `f` and player `p`, the values start at
|
|
232
|
+
`(f * P + p) * 4`: `x, y, z, yaw`. Dead players keep a position (usually where
|
|
233
|
+
they died), so check the alive flag before drawing them. A player who isn't on
|
|
234
|
+
the server, or is spectating, is all zeros in that frame.
|
|
235
|
+
|
|
236
|
+
**`state[F][P][4]`** (u8): at the same index as `pos`:
|
|
237
|
+
|
|
238
|
+
| Byte | Meaning |
|
|
239
|
+
| --- | --- |
|
|
240
|
+
| 0 | Health, 0–100. |
|
|
241
|
+
| 1 | Flags, see below. |
|
|
242
|
+
| 2 | Active weapon, an index into `weapons` (0 = none). |
|
|
243
|
+
| 3 | Armor, 0–100. |
|
|
244
|
+
|
|
245
|
+
| Flag bit | Value | Meaning |
|
|
246
|
+
| --- | --- | --- |
|
|
247
|
+
| 0 | 1 | Alive |
|
|
248
|
+
| 1 | 2 | Counter-terrorist (otherwise terrorist) |
|
|
249
|
+
| 2 | 4 | Ducking |
|
|
250
|
+
| 3 | 8 | Blinded by a flash |
|
|
251
|
+
| 4 | 16 | Carrying the bomb |
|
|
252
|
+
| 5 | 32 | Defusing |
|
|
253
|
+
| 6 | 64 | Scoped |
|
|
254
|
+
| 7 | 128 | Has a defuse kit |
|
|
255
|
+
|
|
256
|
+
A player's side is in their flags, frame by frame, so it changes at halftime
|
|
257
|
+
and in overtime.
|
|
258
|
+
|
|
259
|
+
**`bomb[F][3]`** (f32): the bomb's position, which is the carrier's position
|
|
260
|
+
while carried. All zeros when there is no bomb (e.g. before it's given out).
|
|
261
|
+
|
|
262
|
+
## Versions
|
|
263
|
+
|
|
264
|
+
The version after the magic changes when the binary layout or the meaning of
|
|
265
|
+
an existing field changes. Readers must reject versions newer than they know
|
|
266
|
+
(`readReplay()` throws). New optional JSON fields may be added without a new
|
|
267
|
+
version, so readers should ignore fields they don't know.
|
|
268
|
+
|
|
269
|
+
## Live updates (`CSRU`)
|
|
270
|
+
|
|
271
|
+
A live match (a CSTV+ broadcast) arrives as a stream of updates instead of one
|
|
272
|
+
file. The extractor's live mode writes one every few seconds, whenever it has
|
|
273
|
+
parsed everything the broadcast has sent so far. Applied in order, the updates
|
|
274
|
+
add up to the replay above: same header fields, same frames.
|
|
275
|
+
|
|
276
|
+
An update has the replay's layout, with its own magic and version:
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
"CSRU" | u32 version (1) | u32 jsonLen | JSON | pad
|
|
280
|
+
i32 ticks[F] | f32 pos[F][P][4] | u8 state[F][P][4] | pad | f32 bomb[F][3]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`F` is the update's `frames` and `P` its `players.length`. The JSON:
|
|
284
|
+
|
|
285
|
+
| Field | Type | Meaning |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| `map`, `server`, `protocol`, `tickRate`, `hz` | | As in the replay. A broadcast has no file header: the map comes from the playcast, the server is its CSTV name, and `protocol` is the server's network protocol. |
|
|
288
|
+
| `start` | number | Index of this update's first frame: the frame count before it. |
|
|
289
|
+
| `frames` | number | Frames in this update. |
|
|
290
|
+
| `players`, `weapons` | arrays | The whole lists so far. Players only join: a player's index never changes, and earlier frames have zeros in a new player's slot. |
|
|
291
|
+
| `rounds` | `{ from, items }` | Rounds from index `from` on are replaced by `items` (the current round changes as it's played; a restart drops the rounds before it). |
|
|
292
|
+
| `kills`, `bomb` | `{ from, items }` | Added to the list at index `from` (its length before). |
|
|
293
|
+
| `shots`, `hurts` | `{ from, …arrays }` | The parallel arrays, added at index `from`. |
|
|
294
|
+
| `grenades` | array | Grenades that changed: each a grenade with its index `i`, and its path from point `pathFrom` on (`path` holds only the new points). `voxels` is there only when they changed: a smoke's cloud is sent again as it spreads. |
|
|
295
|
+
| `final` | boolean | The broadcast is over; nothing follows. The last round and lasting effects are closed in it. |
|
|
296
|
+
| `offsets` | object | Byte offsets of the four blocks, as in the replay. |
|
|
297
|
+
|
|
298
|
+
Lists an update doesn't change are left out. In a live replay the current
|
|
299
|
+
round has `end` `-1`, and a smoke or fire still burning has no `effectEnd`.
|
|
300
|
+
|
|
301
|
+
`LiveReplay` from this package applies updates to one `Replay` object that
|
|
302
|
+
grows in place (`openPlaycast()` does this for you):
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
import { LiveReplay } from "@matchomag/cs2-replay";
|
|
306
|
+
|
|
307
|
+
const live = new LiveReplay();
|
|
308
|
+
for (const chunk of updates) live.apply(chunk); // Uint8Array, "CSRU"
|
|
309
|
+
live.replay; // the replay so far
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Reading a replay
|
|
313
|
+
|
|
314
|
+
In JavaScript, with this package:
|
|
315
|
+
|
|
316
|
+
```js
|
|
317
|
+
import { readReplay, FLAG } from "@matchomag/cs2-replay";
|
|
318
|
+
|
|
319
|
+
const replay = readReplay(new Uint8Array(await file.arrayBuffer()));
|
|
320
|
+
const P = replay.players.length;
|
|
321
|
+
const f = replay.rounds[0].live, p = 0;
|
|
322
|
+
const [x, y, z, yaw] = replay.pos.subarray((f * P + p) * 4, (f * P + p) * 4 + 4);
|
|
323
|
+
const alive = (replay.state[(f * P + p) * 4 + 1] & FLAG.Alive) !== 0;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
`createModel(replay).snapshot(frame)` gives the same data already interpreted:
|
|
327
|
+
interpolated positions, the round clock, the bomb state, grenades in the air
|
|
328
|
+
and kills in the last few seconds.
|
|
329
|
+
|
|
330
|
+
Without it, e.g. in Python with only the standard library:
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
import gzip, json, struct
|
|
334
|
+
|
|
335
|
+
data = open("match.replay", "rb").read()
|
|
336
|
+
if data[:2] == b"\x1f\x8b":
|
|
337
|
+
data = gzip.decompress(data)
|
|
338
|
+
assert data[:4] == b"CSRP" and struct.unpack_from("<I", data, 4)[0] == 1
|
|
339
|
+
n = struct.unpack_from("<I", data, 8)[0]
|
|
340
|
+
header = json.loads(data[12 : 12 + n])
|
|
341
|
+
F, P, o = header["frames"], len(header["players"]), header["offsets"]
|
|
342
|
+
|
|
343
|
+
def player(f, p):
|
|
344
|
+
x, y, z, yaw = struct.unpack_from("<4f", data, o["pos"] + (f * P + p) * 16)
|
|
345
|
+
hp, flags, weapon, armor = data[o["state"] + (f * P + p) * 4 : o["state"] + (f * P + p) * 4 + 4]
|
|
346
|
+
return {"x": x, "y": y, "z": z, "yaw": yaw, "hp": hp, "alive": bool(flags & 1),
|
|
347
|
+
"side": "CT" if flags & 2 else "T", "weapon": header["weapons"][weapon], "armor": armor}
|
|
348
|
+
|
|
349
|
+
print(header["map"], player(header["rounds"][0]["live"], 0))
|
|
350
|
+
```
|