mirror of
https://codeberg.org/demostf/parser.git
synced 2026-11-30 10:40:50 +01:00
update to new bitreader
This commit is contained in:
parent
f5e236c58b
commit
e7b9f5ecbb
25 changed files with 378 additions and 590 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{Parse, ParseError, ParserState, Result, Stream};
|
||||
use bitstream_reader::{BitRead, LittleEndian};
|
||||
|
||||
use crate::{Parse, ParseError, ParserState, Result, Stream, ReadResult};
|
||||
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropType};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -23,32 +25,39 @@ pub struct DataTablePacket {
|
|||
server_classes: Vec<ServerClass>,
|
||||
}
|
||||
|
||||
impl<'a> Parse<'a> for DataTablePacket {
|
||||
fn parse(stream: &mut Stream<'a>, state: &ParserState<'a>) -> Result<Self> {
|
||||
let tick = stream.read(32)?;
|
||||
impl Parse for DataTablePacket {
|
||||
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
||||
let tick = stream.read()?;
|
||||
let start = stream.pos();
|
||||
let len = stream.read::<usize>(32)?;
|
||||
let len = stream.read_int::<usize>(32)?;
|
||||
let mut packet_data = stream.read_bits(len * 8)?;
|
||||
|
||||
let mut tables = vec![];
|
||||
while packet_data.read_bool()? {
|
||||
let needs_decoder = packet_data.read_bool()?;
|
||||
let name = packet_data.read_string(None)?;
|
||||
let prop_count = packet_data.read(10)?;
|
||||
let prop_count = packet_data.read_int(10)?;
|
||||
|
||||
let mut array_element_prop = None;
|
||||
let mut props = Vec::with_capacity(prop_count);
|
||||
|
||||
for i in 0..prop_count {
|
||||
let prop: SendPropDefinition = SendPropDefinition::parse(&mut packet_data, state, name.clone())?;
|
||||
let prop: SendPropDefinition =
|
||||
SendPropDefinition::read(&mut packet_data, name.clone())?;
|
||||
if prop.flags.contains(SendPropFlag::InsideArray) {
|
||||
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
|
||||
return Err(ParseError::InvalidSendPropArray("Array contents can't have the 'ChangesOften' flag".to_owned()));
|
||||
if array_element_prop.is_some()
|
||||
|| prop.flags.contains(SendPropFlag::ChangesOften)
|
||||
{
|
||||
return Err(ParseError::InvalidSendPropArray(
|
||||
"Array contents can't have the 'ChangesOften' flag".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = Some(prop);
|
||||
} else if let Some(array_element) = array_element_prop {
|
||||
if prop.prop_type != SendPropType::Array {
|
||||
return Err(ParseError::InvalidSendPropArray("Array contents can without array".to_owned()));
|
||||
return Err(ParseError::InvalidSendPropArray(
|
||||
"Array contents can without array".to_owned(),
|
||||
));
|
||||
}
|
||||
array_element_prop = None;
|
||||
props.push(prop.with_array_property(array_element));
|
||||
|
|
@ -68,10 +77,10 @@ impl<'a> Parse<'a> for DataTablePacket {
|
|||
|
||||
// TODO linked tables?
|
||||
|
||||
let server_class_count = packet_data.read(16)?;
|
||||
let server_class_count = packet_data.read_int(16)?;
|
||||
let mut server_classes = Vec::with_capacity(server_class_count);
|
||||
for i in 0..server_class_count {
|
||||
let id = packet_data.read(16)?;
|
||||
let id = packet_data.read_int(16)?;
|
||||
let name = packet_data.read_string(None)?;
|
||||
let data_table = packet_data.read_string(None)?;
|
||||
server_classes.push(ServerClass {
|
||||
|
|
@ -91,10 +100,4 @@ impl<'a> Parse<'a> for DataTablePacket {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn skip(stream: &mut Stream) -> Result<()> {
|
||||
let _ = stream.skip(32)?;
|
||||
let len = stream.read::<usize>(32)?;
|
||||
stream.skip(len * 8).map_err(ParseError::from)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue