hots_replay_parser/lib.rs
1//! Offline Heroes of the Storm `.StormReplay` decoder: a Rust port of Blizzard's
2//! `heroprotocol` (schema-driven bit decoders) and `mpyq` (MPQ archive reader).
3//!
4//! Two phases, joined only by [`ReplayFiles`]:
5//! 1. [`mpq`]: archive → raw section bytes (no protocol, no JSON)
6//! 2. [`decode`]: raw section bytes + per-build protocol → JSON (no MPQ)
7//!
8//! On top of them, [`summary`] turns a decoded replay into a compact, typed
9//! [`ReplaySummary`](summary::ReplaySummary) for stats and charts.
10
11pub mod decode;
12mod error;
13pub mod mpq;
14mod replay;
15pub mod summary;
16
17use std::path::Path;
18
19pub use crate::decode::{
20 Attribute, AttributeEvents, BattleLobby, Event, LobbyPlayer, ParsedReplay, Toon, UserId,
21};
22pub use crate::error::Error;
23pub use crate::replay::{ReplayFiles, Sections};
24
25/// Open a `.StormReplay` file and decode every section: [`ReplayFiles::open`] then
26/// [`decode::decode_replay`].
27pub fn parse_replay(path: impl AsRef<Path>) -> Result<ParsedReplay, Error> {
28 let files = ReplayFiles::open(path)?;
29 decode::decode_replay(&files)
30}
31
32/// Open a `.StormReplay` file and [summarize](ParsedReplay::summary) it, decoding only
33/// the [`Sections::SUMMARY`] sections: game and message events, most of the file, are
34/// never decompressed nor decoded.
35pub fn summarize_replay(path: impl AsRef<Path>) -> Result<summary::ReplaySummary, Error> {
36 let files = ReplayFiles::open_with(path, Sections::SUMMARY)?;
37 Ok(decode::decode_replay_with(&files, Sections::SUMMARY)?.summary()?)
38}