squadreplay 0.1.0-alpha.1

Library-first Rust parser and CLI for Squad UE5 replay files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
//! Data model for parsed Squad replay bundles.
//!
//! [`Bundle`] is the top-level container returned by [`crate::parse_file`]
//! and [`crate::parse_bytes`]. It holds every piece of data extracted from
//! a Squad `.replay` file.

#![allow(missing_docs)]

use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::sync::Arc;

/// Schema metadata embedded in serialized bundles.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SchemaInfo {
    pub name: String,
    pub version: u16,
    pub profile: String,
}

impl Default for SchemaInfo {
    fn default() -> Self {
        Self {
            name: "sqrj".to_string(),
            version: 1,
            profile: "canonical".to_string(),
        }
    }
}

/// Source file identity (name, size, hash).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ReplaySourceInfo {
    pub file_name: String,
    pub size_bytes: u64,
    pub sha256: String,
}

/// Unreal Engine version and network metadata.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ReplayEngineInfo {
    pub engine_version: Option<String>,
    pub net_version: Option<u32>,
    pub notes: Vec<String>,
}

/// Top-level replay metadata (source, engine, map, duration).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ReplayInfoSection {
    pub source: ReplaySourceInfo,
    pub engine: ReplayEngineInfo,
    pub map_name: Option<String>,
    pub layer_name: Option<String>,
    pub friendly_name: Option<String>,
    pub squad_version: Option<String>,
    pub duration_ms: u64,
    pub started_at: Option<String>,
    pub notes: Vec<String>,
}

/// A team in the match (e.g. US Army, Russian Ground Forces).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Team {
    pub id: u32,
    pub name: Option<String>,
    pub faction: Option<String>,
    pub faction_setup_id: Option<String>,
    pub tickets: Option<u32>,
    pub commander_state_guid: Option<u32>,
    pub team_state_guid: Option<u32>,
    pub notes: Vec<String>,
}

/// A squad within a team.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Squad {
    pub id: u32,
    pub raw_team_id: Option<u32>,
    pub team_id: Option<u32>,
    pub faction: Option<String>,
    pub squad_state_guid: Option<u32>,
    pub name: Option<String>,
    pub leader_player_state_guid: Option<u32>,
    pub leader_name: Option<String>,
    pub leader_steam_id: Option<String>,
    pub leader_eos_id: Option<String>,
    pub creator_name: Option<String>,
    pub creator_identity_raw: Option<String>,
    pub creator_steam_id: Option<String>,
    pub creator_eos_id: Option<String>,
    pub notes: Vec<String>,
}

/// An individual player observed during the match.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Player {
    pub player_state_guid: u32,
    pub name: Option<String>,
    pub steam_id: Option<String>,
    pub eos_id: Option<String>,
    pub online_user_id: Option<String>,
    pub identity_raw: Option<String>,
    pub soldier_guid: Option<u32>,
    pub current_pawn_guid: Option<u32>,
    pub team_id: Option<u32>,
    pub faction: Option<String>,
    pub team_state_guid: Option<u32>,
    pub squad_id: Option<u32>,
    pub squad_state_guid: Option<u32>,
    pub current_role_id: Option<i32>,
    pub current_role_name: Option<String>,
    pub deploy_role_id: Option<i32>,
    pub deploy_role_name: Option<String>,
    pub player_type_name: Option<String>,
    pub squad_leader_name: Option<String>,
    pub squad_creator_name: Option<String>,
    pub squad_creator_steam_id: Option<String>,
    pub squad_creator_eos_id: Option<String>,
    pub start_time_ms: Option<u64>,
    pub notes: Vec<String>,
}

/// 3-D position vector.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub struct Vec3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

/// Euler rotation (pitch / yaw / roll).
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub struct Rotator {
    pub pitch: f64,
    pub yaw: f64,
    pub roll: f64,
}

/// Replicated movement state for a networked actor.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RepMovement {
    pub location: Option<Vec3>,
    pub rotation: Option<Rotator>,
    pub linear_velocity: Option<Vec3>,
    pub angular_velocity: Option<Vec3>,
    pub server_frame: Option<u32>,
    pub server_handle: Option<u32>,
    pub rep_physics: bool,
}

/// Decoded value of a single replicated property.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DecodedPropertyValue {
    pub bits: u32,
    pub int_packed: Option<u32>,
    pub int32: Option<i32>,
    pub float32: Option<f32>,
    pub boolean: Option<bool>,
    pub string: Option<String>,
    // Boxed because RepMovement is ~150 bytes but most events don't carry
    // movement data. Inlining it roughly doubled PropertyEvent for no gain.
    pub rep_movement: Option<Box<RepMovement>>,
}

/// A single property replication event from the network stream.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PropertyEvent {
    pub t_ms: u64,
    pub second: u32,
    pub channel_index: u32,
    pub actor_guid: Option<u32>,
    // Very low cardinality across a replay (a few dozen unique values for
    // millions of events). Arc<str> lets them share backing storage via the
    // interner on ParseState.
    pub group_path: Arc<str>,
    pub property_name: Arc<str>,
    pub sub_object_net_guid: Option<u32>,
    pub decoded: DecodedPropertyValue,
}

/// A networked actor (vehicle, deployable, etc.) observed in the replay.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ActorEntity {
    pub actor_guid: u32,
    pub channel_index: u32,
    pub class_name: Option<String>,
    pub archetype_path: Option<String>,
    pub open_time_ms: u64,
    pub close_time_ms: Option<u64>,
    pub initial_location: Option<Vec3>,
    pub initial_rotation: Option<Rotator>,
    pub team: Option<i64>,
    pub build_state: Option<i64>,
    pub health: Option<f64>,
    pub owner: Option<u32>,
    pub notes: Vec<String>,
}

/// A sub-object component attached to an actor.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ComponentEntity {
    pub component_guid: u32,
    pub owner_actor_guid: Option<u32>,
    pub class_name: Option<String>,
    #[serde(default)]
    pub component_class: Option<String>,
    pub path_hint: Option<String>,
    #[serde(default)]
    pub group_path: Option<String>,
    pub first_seen_ms: u64,
    pub notes: Vec<String>,
}

/// Categorized collections of actors extracted from the replay.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ActorGroups {
    pub vehicles: Vec<ActorEntity>,
    pub helicopters: Vec<ActorEntity>,
    pub deployables: Vec<ActorEntity>,
    pub components: Vec<ComponentEntity>,
}

/// A single timestamped 3-D position sample.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TrackSample3 {
    pub t_ms: u64,
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

/// A named position track (series of [`TrackSample3`] samples).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Track3 {
    pub key: String,
    pub actor_guid: Option<u32>,
    pub player_state_guid: Option<u32>,
    pub class_name: Option<String>,
    pub source: String,
    pub samples: Vec<TrackSample3>,
}

/// Categorized position tracks (players, vehicles, helicopters).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TrackGroups {
    pub players: Vec<Track3>,
    pub vehicles: Vec<Track3>,
    pub helicopters: Vec<Track3>,
}

/// A kill or incapacitation event.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct KillEvent {
    pub t_ms: u64,
    pub second: u32,
    pub victim_name: Option<String>,
    pub killer_name: Option<String>,
    pub victim_guid: Option<u32>,
    pub killer_guid: Option<u32>,
    pub was_incap: Option<bool>,
}

/// A deployable placement event (FOB, HAB, etc.).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DeploymentEvent {
    pub t_ms: u64,
    pub second: u32,
    pub actor_guid: Option<u32>,
    pub deployment_type: String,
    pub class_name: Option<String>,
    pub x: Option<f64>,
    pub y: Option<f64>,
    pub z: Option<f64>,
}

/// A vehicle seat change (enter, exit, swap).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SeatChangeEvent {
    pub t_ms: u64,
    pub second: u32,
    pub actor_guid: Option<u32>,
    pub component_guid: Option<u32>,
    pub player_state_guid: Option<u32>,
    pub vehicle_class: Option<String>,
    pub seat_attach_socket: Option<String>,
    pub attach_socket_name: Option<String>,
    pub occupant_name: Option<String>,
    pub value: Option<String>,
}

/// A state change on a component sub-object.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ComponentStateEvent {
    pub t_ms: u64,
    pub second: u32,
    pub component_guid: Option<u32>,
    pub owner_actor_guid: Option<u32>,
    pub component_type: String,
    #[serde(default)]
    pub component_name: Option<String>,
    #[serde(default)]
    pub component_class: Option<String>,
    #[serde(default)]
    pub group_path: String,
    pub property_name: String,
    #[serde(default)]
    pub decoded: DecodedPropertyValue,
    pub value_int: Option<i64>,
    pub value_float: Option<f64>,
    pub value_bool: Option<bool>,
    pub value_string: Option<String>,
}

/// A state change on a vehicle actor.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct VehicleStateEvent {
    pub t_ms: u64,
    pub second: u32,
    pub actor_guid: Option<u32>,
    #[serde(default)]
    pub actor_class: Option<String>,
    #[serde(default)]
    pub sub_object_net_guid: Option<u32>,
    #[serde(default)]
    pub group_path: String,
    pub property_name: String,
    #[serde(default)]
    pub decoded: DecodedPropertyValue,
    pub value_int: Option<i64>,
    pub value_float: Option<f64>,
    pub value_bool: Option<bool>,
    pub value_string: Option<String>,
}

/// A state change on a weapon actor.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct WeaponStateEvent {
    pub t_ms: u64,
    pub second: u32,
    pub actor_guid: Option<u32>,
    #[serde(default)]
    pub actor_class: Option<String>,
    #[serde(default)]
    pub sub_object_net_guid: Option<u32>,
    #[serde(default)]
    pub group_path: String,
    pub property_name: String,
    #[serde(default)]
    pub decoded: DecodedPropertyValue,
    pub value_int: Option<i64>,
    pub value_float: Option<f64>,
    pub value_bool: Option<bool>,
    pub value_string: Option<String>,
}

/// All classified game events extracted from the replay.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EventGroups {
    pub kills: Vec<KillEvent>,
    pub deployments: Vec<DeploymentEvent>,
    pub seat_changes: Vec<SeatChangeEvent>,
    pub component_states: Vec<ComponentStateEvent>,
    pub vehicle_states: Vec<VehicleStateEvent>,
    pub weapon_states: Vec<WeaponStateEvent>,
    pub properties: Vec<PropertyEvent>,
}

/// Raw string inventory collected during parsing.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct StringInventory {
    pub ascii_strings: Vec<String>,
    pub utf16_strings: Vec<String>,
    pub class_paths: Vec<String>,
    pub ids: Vec<String>,
}

/// Provenance record for a piece of extracted data.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ProvenanceEntry {
    pub family: String,
    pub provenance: String,
    #[serde(default)]
    pub notes: Vec<String>,
}

/// Parser diagnostics and statistics.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Diagnostics {
    pub frames_processed: u64,
    pub packets_processed: u64,
    pub actor_opens: u64,
    pub export_groups_discovered: usize,
    pub guid_to_path_size: usize,
    pub property_replications: u64,
    pub position_samples: u64,
    pub vehicle_position_samples: u64,
    pub replay_data_chunks: usize,
    pub warnings: Vec<String>,
    pub string_inventory: StringInventory,
    #[serde(default)]
    pub provenance_report: Vec<ProvenanceEntry>,
}

/// Server and match configuration derived from game-state replication.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct GameStateInfo {
    // Match identity
    pub server_name: Option<String>,
    pub game_mode: Option<String>,
    pub match_state: Option<String>,
    pub match_id: Option<String>,
    pub map_name: Option<String>,

    // Server info
    pub max_players: Option<u32>,
    pub motd: Option<String>,
    pub server_tick_rate: Option<f32>,
    pub server_start_timestamp: Option<String>,
    pub startup_layer: Option<String>,

    // Match config
    pub is_ticket_based: Option<bool>,
    pub authority_num_teams: Option<u32>,
    pub num_reserved_slots: Option<u32>,
    pub public_queue_limit: Option<u32>,
    pub num_players_diff_for_team_changes: Option<u32>,
    pub low_player_count_threshold: Option<u32>,
    pub community_admin_access: Option<bool>,

    // Timing
    pub no_team_change_timer: Option<f32>,
    pub server_message_interval: Option<f32>,
    pub time_between_matches: Option<f32>,
    pub time_before_vote: Option<f32>,

    // Rotation & voting
    pub map_rotation_mode: Option<u32>,
    pub use_vote_level: Option<bool>,
    pub use_vote_layer: Option<bool>,
    pub layer_options_number: Option<u32>,
    pub faction_options_number: Option<u32>,
    pub map_skip_rounds: Option<u32>,
    pub layer_skip_rounds: Option<u32>,
    pub faction_skip_rounds: Option<u32>,
    pub faction_setup_skip_rounds: Option<u32>,
    pub display_votes: Option<bool>,
    pub unique_map_vote: Option<bool>,

    // Availability flags (mode-specific, all optional)
    pub vehicle_claiming_disabled: Option<bool>,
    pub commander_disabled: Option<bool>,
    pub force_all_role_availability: Option<bool>,
    pub helicopters_available: Option<bool>,
    pub boats_available: Option<bool>,
    pub tanks_available: Option<bool>,
    pub force_all_vehicle_availability: Option<bool>,
    pub force_all_deployable_availability: Option<bool>,
    pub force_all_action_availability: Option<bool>,
    pub force_allow_commander_actions: Option<bool>,
    pub force_no_commander_cooldowns: Option<bool>,
    pub no_respawn_timer: Option<bool>,
    pub vehicle_team_requirement_disabled: Option<bool>,
    pub vehicle_kit_requirement_disabled: Option<bool>,

    // Arrays (accumulated from repeated property events)
    pub server_tags: Vec<String>,
    pub level_rotation: Vec<String>,
    pub layer_rotation: Vec<String>,
    pub layer_rotation_low_players: Vec<String>,
    pub layer_vote_list: Vec<String>,
    pub excluded_levels: Vec<String>,
    pub excluded_layers: Vec<String>,

    pub notes: Vec<String>,
}

/// Top-level container holding all data extracted from a Squad replay.
///
/// Returned by [`crate::parse_file`] and [`crate::parse_bytes`], and
/// (de)serializable to `.sqrj.json` / `.sqrb` via the [`crate::sqrj`] and
/// [`crate::sqrb`] modules.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Bundle {
    pub schema: SchemaInfo,
    pub replay: ReplayInfoSection,
    pub game_state: GameStateInfo,
    pub teams: Vec<Team>,
    pub squads: Vec<Squad>,
    pub players: Vec<Player>,
    pub actors: ActorGroups,
    pub tracks: TrackGroups,
    pub events: EventGroups,
    pub diagnostics: Diagnostics,
}

/// Legacy-format kill event for [`CompatMatch`].
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompatKillEvent {
    pub timestamp: u32,
    #[serde(rename = "victimName")]
    pub victim_name: String,
    #[serde(rename = "killerName")]
    pub killer_name: String,
    #[serde(rename = "victimGuidStr")]
    pub victim_guid_str: String,
    #[serde(rename = "killerGuidStr")]
    pub killer_guid_str: String,
    #[serde(rename = "wasIncap")]
    pub was_incap: bool,
}

/// Aggregated kill/death stats in the legacy format.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompatPlayerStat {
    pub kills: u32,
    pub deaths: u32,
}

/// Legacy-format deployable placement event.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompatDeployableEvent {
    pub r#type: String,
    #[serde(rename = "classPath")]
    pub class_path: String,
    pub second: u32,
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

/// Parser statistics in the legacy JSON shape.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompatDebugStats {
    #[serde(rename = "framesProcessed")]
    pub frames_processed: u64,
    #[serde(rename = "packetsProcessed")]
    pub packets_processed: u64,
    #[serde(rename = "actorOpens")]
    pub actor_opens: u64,
    #[serde(rename = "propReplications")]
    pub prop_replications: u64,
    #[serde(rename = "positionSamples")]
    pub position_samples: u64,
    #[serde(rename = "vehiclePositionSamples")]
    pub vehicle_position_samples: u64,
    #[serde(rename = "deployableEvents")]
    pub deployable_events: usize,
    #[serde(rename = "exportGroupsDiscovered")]
    pub export_groups_discovered: usize,
    #[serde(rename = "guidToPathSize")]
    pub guid_to_path_size: usize,
}

/// Legacy match JSON produced by [`crate::compat::from_bundle`].
///
/// Mirrors the shape expected by older Squad replay tools.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompatMatch {
    #[serde(rename = "mapName")]
    pub map_name: String,
    #[serde(rename = "squadVersion")]
    pub squad_version: String,
    #[serde(rename = "matchDurationSeconds")]
    pub match_duration_seconds: u32,
    pub kills: Vec<CompatKillEvent>,
    #[serde(rename = "killsBySecond")]
    pub kills_by_second: BTreeMap<String, Vec<CompatKillEvent>>,
    #[serde(rename = "playerStats")]
    pub player_stats: BTreeMap<String, CompatPlayerStat>,
    #[serde(rename = "positionsPerSecond")]
    pub positions_per_second: BTreeMap<String, BTreeMap<String, [f64; 3]>>,
    #[serde(rename = "helicopterPositionsPerSecond")]
    pub helicopter_positions_per_second: BTreeMap<String, BTreeMap<String, [f64; 3]>>,
    #[serde(rename = "vehiclePositionsPerSecond")]
    pub vehicle_positions_per_second: BTreeMap<String, BTreeMap<String, [f64; 3]>>,
    #[serde(rename = "deployableEvents")]
    pub deployable_events: Vec<CompatDeployableEvent>,
    #[serde(rename = "debugStats")]
    pub debug_stats: CompatDebugStats,
}

/// Options controlling replay parsing behavior.
#[derive(Debug, Clone)]
pub struct ParseOptions {
    pub include_property_events: bool,
}

impl Default for ParseOptions {
    fn default() -> Self {
        Self {
            include_property_events: true,
        }
    }
}