mirror of
https://github.com/eigenein/wotbreplay-parser.git
synced 2026-10-21 10:27:01 +02:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1830536224 |
No files matched your search
+2
-3
@@ -1,10 +1,9 @@
|
||||
//! `data.wotreplay` models.
|
||||
//! Models for `data.wotreplay` contents.
|
||||
|
||||
pub mod base_player_create;
|
||||
pub mod entity_method;
|
||||
pub mod packet;
|
||||
pub mod payload;
|
||||
pub mod type_0;
|
||||
pub mod update_arena;
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Looks like some sort of replay summary.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Type0 {
|
||||
pub struct BasePlayerCreate {
|
||||
#[serde(rename(deserialize = "playersBattleCategoriesIds"))]
|
||||
pub players_battle_categories_ids: HashMap<u32, (u8, u32)>,
|
||||
|
||||
@@ -4,16 +4,19 @@ use prost::Message;
|
||||
use serde::Serialize;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use self::update_arena::UpdateArena;
|
||||
use crate::models::data::read_quirky_length;
|
||||
use crate::models::data::update_arena::UpdateArena;
|
||||
use crate::result::Result;
|
||||
|
||||
pub mod update_arena;
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum EntityMethod {
|
||||
Subtype2F {
|
||||
/// Subtype `0x2F`.
|
||||
UpdateArena {
|
||||
field_number: u64,
|
||||
sub_type_2f: UpdateArena,
|
||||
arguments: UpdateArena,
|
||||
|
||||
/// Original payload for investigation.
|
||||
#[serde_as(as = "serde_with::hex::Hex")]
|
||||
@@ -31,6 +34,7 @@ pub enum EntityMethod {
|
||||
}
|
||||
|
||||
impl EntityMethod {
|
||||
/// Parse the entity method payload.
|
||||
pub fn new(payload: Vec<u8>) -> Result<Self> {
|
||||
let mut reader = payload.as_slice();
|
||||
|
||||
@@ -43,9 +47,9 @@ impl EntityMethod {
|
||||
|
||||
let field_number = decode_varint(&mut reader)?;
|
||||
let message_length = read_quirky_length(&mut reader)?;
|
||||
Self::Subtype2F {
|
||||
Self::UpdateArena {
|
||||
field_number,
|
||||
sub_type_2f: UpdateArena::decode(&reader[..message_length])?,
|
||||
arguments: UpdateArena::decode(&reader[..message_length])?,
|
||||
payload,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use prost::Message;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Subtype `0x2F`.
|
||||
#[derive(Message, Serialize)]
|
||||
pub struct UpdateArena {
|
||||
#[prost(message, tag = "1")]
|
||||
@@ -4,22 +4,23 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use serde::Serialize;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use crate::models::data::base_player_create::BasePlayerCreate;
|
||||
use crate::models::data::entity_method::EntityMethod;
|
||||
use crate::models::data::type_0::Type0;
|
||||
use crate::models::data::{read_pickled, read_quirky_length, read_string};
|
||||
use crate::result::Result;
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum Payload {
|
||||
/// Looks like some sort of replay summary.
|
||||
Type0 {
|
||||
/// Type 0.
|
||||
BasePlayerCreate {
|
||||
author_nickname: String,
|
||||
arena_unique_id: u64,
|
||||
arena_type_id: u32,
|
||||
type_0: Box<Type0>,
|
||||
arguments: Box<BasePlayerCreate>,
|
||||
},
|
||||
|
||||
/// Type 8.
|
||||
EntityMethod(EntityMethod),
|
||||
|
||||
/// Default payload when type is not known by the parser.
|
||||
@@ -46,8 +47,8 @@ impl Payload {
|
||||
let pickled_length = read_quirky_length(&mut reader)?;
|
||||
read_pickled(&mut reader, pickled_length)?
|
||||
};
|
||||
Self::Type0 {
|
||||
type_0,
|
||||
Self::BasePlayerCreate {
|
||||
arguments: type_0,
|
||||
author_nickname,
|
||||
arena_unique_id,
|
||||
arena_type_id,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Models for `meta.json` contents.
|
||||
#![cfg(feature = "meta")]
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
+3
-3
@@ -29,11 +29,11 @@ fn type0_ok() -> Result<()> {
|
||||
.packets
|
||||
.iter()
|
||||
.filter_map(|packet| {
|
||||
if let Payload::Type0 {
|
||||
if let Payload::BasePlayerCreate {
|
||||
author_nickname,
|
||||
arena_unique_id,
|
||||
arena_type_id,
|
||||
type_0,
|
||||
arguments: type_0,
|
||||
} = &packet.payload
|
||||
{
|
||||
Some((author_nickname, arena_unique_id, arena_type_id, type_0))
|
||||
@@ -74,7 +74,7 @@ fn subtype_2f_players_ok() -> Result<()> {
|
||||
.packets
|
||||
.iter()
|
||||
.filter_map(|packet| match &packet.payload {
|
||||
Payload::EntityMethod(EntityMethod::Subtype2F { sub_type_2f, .. }) => {
|
||||
Payload::EntityMethod(EntityMethod::UpdateArena { arguments: sub_type_2f, .. }) => {
|
||||
sub_type_2f.players.as_ref()
|
||||
}
|
||||
_ => None,
|
||||
|
||||
Reference in new issue
Block a user