1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-04 02:24:12 +02:00

update to new bitreader

This commit is contained in:
Robin Appelman 2019-02-28 21:55:53 +01:00
commit e7b9f5ecbb
25 changed files with 378 additions and 590 deletions

View file

@ -0,0 +1,93 @@
/// Messages that consists only of primitives and string and can be derived
use bitstream_reader::BitRead;
use std::collections::HashMap;
#[derive(BitRead, Debug)]
pub struct FileMessage {
pub transfer_id: u32,
pub file_name: String,
pub requested: bool,
}
#[derive(BitRead, Debug)]
pub struct NetTickMessage {
pub tick: u32,
pub frame_time: u16,
pub std_dev: u16,
}
#[derive(BitRead, Debug)]
pub struct StringCmdMessage {
pub command: String
}
#[derive(BitRead, Debug)]
pub struct SigOnStateMessage {
pub state: u8,
pub count: u32,
}
#[derive(BitRead, Debug)]
pub struct PrintMessage {
pub value: String
}
#[derive(BitRead, Debug)]
pub struct ServerInfoMessage {
pub version: u16,
pub server_count: u32,
pub stv: bool,
pub dedicated: bool,
pub max_crc: u32,
pub max_classes: u16,
pub map_hash: u128,
pub player_count: u8,
pub max_player_count: u8,
pub interval_per_tick: f32,
#[size = 1]
pub platform: String,
pub game: String,
pub map: String,
pub skybox: String,
pub server_name: String,
pub replay: bool,
}
#[derive(BitRead, Debug)]
pub struct SetPauseMessage {
pub pause: bool
}
#[derive(BitRead, Debug)]
pub struct SetViewMessage {
#[size = 11]
pub index: u16
}
#[derive(BitRead, Debug)]
pub struct FixAngleMessage {
pub relative: bool,
pub x: u16,
pub y: u16,
pub z: u16,
}
#[derive(BitRead, Debug)]
pub struct PreFetchMessage {
#[size = 14]
pub index: u16
}
#[derive(BitRead, Debug)]
pub struct GetCvarMessage {
pub cookie: u32,
pub value: String,
}
#[derive(BitRead, Debug)]
pub struct SetConVarMessage {
#[size_bits = 8]
vars: HashMap<String, String>
}

51
src/demo/message/mod.rs Normal file
View file

@ -0,0 +1,51 @@
use enum_primitive_derive::Primitive;
use num_traits::FromPrimitive;
pub use generated::*;
use crate::{Parse, ParseError, ParserState, Result, Stream};
mod generated;
#[derive(Primitive, Debug)]
pub enum MessageType {
File = 2,
NetTick = 3,
StringCmd = 4,
SetConVar = 5,
SigOnState = 6,
Print = 7,
ServerInfo = 8,
ClassInfo = 10,
SetPause = 11,
CreateStringTable = 12,
UpdateStringTable = 13,
VoiceInit = 14,
VoiceData = 15,
ParseSounds = 17,
SetView = 18,
FixAngle = 19,
BspDecal = 21,
UserMessage = 23,
EntityMessage = 24,
GameEvent = 25,
PacketEntities = 26,
TempEntities = 27,
PreFetch = 28,
Menu = 29,
GameEventList = 30,
GetCvarValue = 31,
CmdKeyValues = 32,
}
impl Parse for MessageType {
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
let raw = stream.read_int(6)?;
let prop_type: Option<MessageType> = MessageType::from_u8(raw);
prop_type.ok_or(ParseError::InvalidMessageType(raw))
}
fn skip(stream: &mut Stream) -> Result<()> {
stream.skip(6).map_err(ParseError::from)
}
}