s2protocol 3.5.3

A parser for Starcraft II - Replay format, exports to different target formats
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
//! Decodes the Game Events.
//! These are stored in an embedded file in the MPQ file called 'replay.game.events'

use serde::{Deserialize, Serialize};
pub mod state;
pub use state::*;
pub mod iterator;
pub use iterator::*;
pub mod ability;
pub use ability::*;
#[cfg(feature = "dep_arrow")]
pub mod arrow_store;
#[cfg(feature = "dep_arrow")]
pub use arrow_store::*;

#[cfg(feature = "dep_arrow")]
use arrow_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};

use crate::SC2ReplayFilters;

pub type TUserId = u8;
pub type GameTUnitTag = u32;
pub type GameTUnitLink = u16;
pub type GameTPlayerId = i64;
pub type GameTMapCoordFixedBits = i64;
pub type GameTFixedBits = i32;
pub type GameTAbilLink = u16;
pub type GameTFixedMiniBitsSigned = i16;
pub type GameTFixedMiniBitsUnsigned = i64;
pub type GameTControlGroupId = u8;
pub type GameTSubgroupIndex = u16;
pub type GameTSelectionIndex = u16;
pub type GameTSubgroupPriority = u8;
pub type GameTSelectionCount = u16;
pub type GameTSubgroupCount = u16;
pub type GameTControlGroupIndex = u8;
pub type GameTControlGroupCount = u8;
pub type GameTSyncChecksum = u32;
pub type GameTButtonLink = u16;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameEvent {
    pub delta: i64,
    pub user_id: i64,
    pub event: ReplayGameEvent,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum ReplayGameEvent {
    DropUser(DropUserEvent),
    CameraSave(CameraSaveEvent),
    Cmd(GameSCmdEvent),
    SelectionDelta(GameSSelectionDeltaEvent),
    ControlGroupUpdate(GameSControlGroupUpdateEvent),
    SelectionSyncCheck(GameSSelectionSyncCheckEvent),
    TriggerChatMessage(GameSTriggerChatMessageEvent),
    UnitClick(GameSUnitClickEvent),
    UnitHighlight(GameSUnitHighlightEvent),
    TriggerReplySelected(GameSTriggerReplySelectedEvent),
    CameraUpdate(CameraUpdateEvent),
    TriggerMouseClicked(GameSTriggerMouseClickedEvent),
    TriggerMouseMoved(GameSTriggerMouseMovedEvent),
    TriggerHotkeyPressed(GameSTriggerHotkeyPressedEvent),
    TriggerTargetModeUpdate(GameSTriggerTargetModeUpdateEvent),
    TriggerKeyPressed(GameSTriggerKeyPressedEvent),
    TriggerMouseWheel(GameSTriggerMouseWheelEvent),
    TriggerButtonPressed(GameSTriggerButtonPressedEvent),
    /*GameUserLeave(GameSGameUserLeaveEvent),
    GameUserJoin(GameSGameUserJoinEvent),*/
    CommandManagerState(GameSCommandManagerStateEvent),
    CmdUpdateTargetPoint(GameSCmdUpdateTargetPointEvent),
    CmdUpdateTargetUnit(GameSCmdUpdateTargetUnitEvent),
    /*TriggerAnimLengthQueryByName(GameSTriggerAnimLengthQueryByNameEvent),
    TriggerAnimLengthQueryByProps(GameSTriggerAnimLengthQueryByPropsEvent),*/
}

impl ReplayGameEvent {
    pub fn should_skip(&self, _filters: &SC2ReplayFilters) -> bool {
        // for now we do not filter GameEvents
        false
    }
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum ELeaveReason {
    UserLeft,
    UserDropped,
    UserBanned,
    UserVictory,
    UserDefeat,
    UserTied,
    UserDesynced,
    UserOutOfTime,
    WeWereUnresponsive,
    WeContinuedAlone,
    ReplayDesynced,
    UserTimeout,
    UserDisconnected,
    Unrecoverable,
    UserCatchupDesynced,
    TakeCommandDropped,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct DropUserEvent {
    pub m_drop_session_user_id: TUserId,
    pub m_reason: ELeaveReason,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct CameraSaveEvent {
    pub m_which: i64,
    pub m_target: GameSPointMini,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct CameraUpdateEvent {
    pub m_target: Option<GameSPointMini>,
    pub m_distance: Option<GameTFixedMiniBitsUnsigned>,
    pub m_pitch: Option<GameTFixedMiniBitsUnsigned>,
    pub m_yaw: Option<GameTFixedMiniBitsUnsigned>,
    pub m_reason: Option<i8>,
    pub m_follow: bool,
}

#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSPointMini {
    pub x: GameTFixedMiniBitsUnsigned,
    pub y: GameTFixedMiniBitsUnsigned,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCmdEvent {
    pub m_cmd_flags: i64,
    pub m_abil: Option<GameSCmdAbil>,
    pub m_data: GameSCmdData,
    pub m_sequence: i64,
    pub m_other_unit: Option<GameTUnitTag>,
    pub m_unit_group: Option<u32>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCmdAbil {
    pub m_abil_link: GameTAbilLink,
    pub ability: String,
    pub m_abil_cmd_index: i64,
    pub m_abil_cmd_data: Option<u8>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum GameSCmdData {
    None,
    TargetPoint(GameSMapCoord3D),
    TargetUnit(GameSCmdDataTargetUnit),
    Data(u32),
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSMapCoord3D {
    pub x: GameTMapCoordFixedBits,
    pub y: GameTMapCoordFixedBits,
    pub z: GameTFixedBits,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCmdDataTargetUnit {
    pub m_target_unit_flags: u16,
    pub m_timer: u8,
    pub m_tag: GameTUnitTag,
    pub m_snapshot_unit_link: GameTUnitLink,
    pub m_snapshot_control_player_id: Option<GameTPlayerId>,
    pub m_snapshot_upkeep_player_id: Option<GameTPlayerId>,
    pub m_snapshot_point: GameSMapCoord3D,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCmdUpdateTargetPointEvent {
    pub m_target: GameSMapCoord3D,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCmdUpdateTargetUnitEvent {
    pub m_target: GameSCmdDataTargetUnit,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerMouseClickedEvent {
    pub m_button: u32,
    pub m_down: bool,
    pub m_pos_ui: GameSuiCoord,
    pub m_pos_world: GameSMapCoord3D,
    pub m_flags: i8,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerMouseMovedEvent {
    pub m_pos_ui: GameSuiCoord,
    pub m_pos_world: GameSMapCoord3D,
    pub m_flags: i8,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSuiCoord {
    pub x: u16,
    pub y: u16,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerMouseWheelEvent {
    pub m_wheel_spin: GameTFixedMiniBitsSigned,
    pub m_flags: i8,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSUnitClickEvent {
    pub m_unit_tag: GameTUnitTag,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSUnitHighlightEvent {
    pub m_unit_tag: GameTUnitTag,
    pub m_flags: u8,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSSelectionDeltaEvent {
    pub m_control_group_id: GameTControlGroupId,
    pub m_delta: GameSSelectionDelta,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSSelectionDelta {
    pub m_subgroup_index: GameTSubgroupIndex,
    pub m_remove_mask: GameSSelectionMask,
    pub m_add_subgroups: Vec<GameSSelectionDeltaSubgroup>,
    pub m_add_unit_tags: Vec<GameTUnitTag>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSSelectionDeltaSubgroup {
    pub m_unit_link: GameTUnitLink,
    pub m_subgroup_priority: GameTSubgroupPriority,
    pub m_intra_subgroup_priority: GameTSubgroupPriority,
    pub m_count: GameTSelectionCount,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum GameSSelectionMask {
    None,
    Mask(GameSelectionMaskType),
    OneIndices(GameSelectionIndexArrayType),
    ZeroIndices(GameSelectionIndexArrayType),
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSelectionMaskType {
    pub value: Vec<u8>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSelectionIndexArrayType {
    pub value: Vec<GameTSelectionIndex>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSSelectionSyncCheckEvent {
    pub m_control_group_id: GameTControlGroupId,
    pub m_selection_sync_data: GameSSelectionSyncData,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSSelectionSyncData {
    pub m_count: GameTSelectionCount,
    pub m_subgroup_count: GameTSubgroupCount,
    pub m_active_subgroup_index: GameTSubgroupIndex,
    pub m_unit_tags_checksum: GameTSyncChecksum,
    pub m_subgroup_indices_checksum: GameTSyncChecksum,
    pub m_subgroups_checksum: GameTSyncChecksum,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSControlGroupUpdateEvent {
    pub m_control_group_index: GameTControlGroupIndex,
    pub m_control_group_update: GameEControlGroupUpdate,
    pub m_mask: GameSSelectionMask,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum GameEControlGroupUpdate {
    ESet,
    EAppend,
    ERecall,
    EClear,
    ESetAndSteal,
    EAppendAndSteal,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerChatMessageEvent {
    pub m_chat_message: String,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerReplySelectedEvent {
    pub m_conversation_id: i32,
    pub m_reply_id: i32,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerHotkeyPressedEvent {
    pub m_hotkey: u32,
    pub m_down: bool,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerTargetModeUpdateEvent {
    pub m_abil_link: GameTAbilLink,
    pub ability: String,
    pub m_abil_cmd_index: i64,
    pub m_state: i8,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerKeyPressedEvent {
    pub m_key: i8,
    pub m_flags: i8,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSTriggerButtonPressedEvent {
    pub m_button: GameTButtonLink,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
pub struct GameSCommandManagerStateEvent {
    pub m_state: GameECommandManagerState,
    pub m_sequence: Option<i64>,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
    feature = "dep_arrow",
    derive(ArrowField, ArrowSerialize, ArrowDeserialize)
)]
#[cfg_attr(feature = "dep_arrow", arrow_field(type = "sparse"))]
pub enum GameECommandManagerState {
    EFireDone,
    EFireOnce,
    EFireMany,
}