diff --git a/src/models/battle_results_dat.rs b/src/models/battle_results_dat.rs index 973a92a..7d8579c 100644 --- a/src/models/battle_results_dat.rs +++ b/src/models/battle_results_dat.rs @@ -10,14 +10,22 @@ use crate::result::Result; /// Represents un-pickled `battle_results.dat`. #[derive(Debug, Deserialize)] -pub struct BattleResultsDat( - /// No idea what this is. - /// My best guess – some kind of checksum, - /// but none of MD5, SHA1, SHA224, SHA256, SHA384, SHA512, nor CRC64 over the buffer have matched. - pub u64, +#[serde(from = "(u64, ByteBuf)")] +pub struct BattleResultsDat { + pub arena_unique_id: u64, + /// Protobuf-serialized battle results. - pub ByteBuf, -); + pub buffer: ByteBuf, +} + +impl From<(u64, ByteBuf)> for BattleResultsDat { + fn from((arena_unique_id, buffer): (u64, ByteBuf)) -> Self { + Self { + arena_unique_id, + buffer, + } + } +} impl BattleResultsDat { /// Parses the pickled structure from the reader which contains `battle_results.dat`. @@ -30,7 +38,7 @@ impl BattleResultsDat { /// Decodes the battle results from the internal buffer. pub fn decode_battle_results(&self) -> Result { - BattleResults::decode(self.1.as_ref()).map_err(Error::DecodeFailed) + BattleResults::decode(self.buffer.as_ref()).map_err(Error::DecodeFailed) } } diff --git a/tests/battle_results.rs b/tests/battle_results.rs index 48ebcbf..08b485a 100644 --- a/tests/battle_results.rs +++ b/tests/battle_results.rs @@ -5,8 +5,10 @@ use wotbreplay_parser::prelude::*; #[test] fn player_results_ok() -> Result<()> { - let battle_results = Replay::open(File::open("tests/replays/player_results.wotbreplay")?)? - .read_battle_results()?; + let battle_results_dat = Replay::open(File::open("tests/replays/player_results.wotbreplay")?)? + .read_battle_results_dat()?; + assert_eq!(battle_results_dat.arena_unique_id, 1661909200500084); + let battle_results = battle_results_dat.decode_battle_results()?; let snak_the_ripper_info = &battle_results.player_results[3].info; assert_eq!(snak_the_ripper_info.base_xp, 929);