Skip to content

Commit

Permalink
Expose replay header.
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxu committed Feb 13, 2024
1 parent 49fff89 commit ae3940c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/w3replay/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use flo_util::binary::*;
use flo_util::dword_string::DwordString;
use flo_util::{BinDecode, BinEncode};

#[derive(Debug, BinEncode, BinDecode)]
#[derive(Debug, BinEncode, BinDecode, Clone)]
pub struct Header {
#[bin(eq = SIGNATURE)]
_sig: [u8; 28],
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Header {
}
}

#[derive(Debug, BinEncode, BinDecode)]
#[derive(Debug, BinEncode, BinDecode, Clone)]
pub struct GameVersion {
#[bin(eq = b"W3XP")]
pub product: DwordString,
Expand Down
13 changes: 10 additions & 3 deletions crates/w3replay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use replay::*;

#[derive(Debug)]
pub struct W3Replay<R> {
_header: Header,
header: Header,
blocks: Blocks<R>,
}

Expand All @@ -38,12 +38,17 @@ impl W3Replay<BufReader<File>> {
let header = Header::decode(&mut buf_slice).map_err(|e| e.context("header"))?;
Ok(W3Replay {
blocks: Blocks::new(r, header.num_blocks as usize, len - Header::MIN_SIZE),
_header: header,
header,
})
}

pub fn header(&self) -> &Header {
&self.header
}

pub fn inspect<P: AsRef<Path>>(path: P) -> Result<(ReplayInfo, RecordIter<BufReader<File>>)> {
let replay = Self::open(path)?;
let header = replay.header().clone();
let mut game = None;
let mut players = vec![];
let mut slots = None;
Expand All @@ -59,6 +64,7 @@ impl W3Replay<BufReader<File>> {
}
Ok((
ReplayInfo {
header,
game: game.ok_or_else(|| Error::NoGameInfoRecord)?,
players,
slots: slots.ok_or_else(|| Error::NoSlotInfoRecord)?,
Expand All @@ -77,7 +83,7 @@ where
let header = Header::decode(&mut buf).map_err(|e| e.context("header"))?;
Ok(W3Replay {
blocks: Blocks::from_buf(buf, header.num_blocks as usize),
_header: header,
header,
})
}
}
Expand All @@ -90,6 +96,7 @@ impl<R> W3Replay<R> {

#[derive(Debug)]
pub struct ReplayInfo {
pub header: Header,
pub game: GameInfo,
pub players: Vec<PlayerInfo>,
pub slots: SlotInfo,
Expand Down

0 comments on commit ae3940c

Please sign in to comment.