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

save definition id in sendpropdefinition

This commit is contained in:
Robin Appelman 2019-08-29 12:45:39 +02:00
commit e1f1f6c201
2 changed files with 29 additions and 7 deletions

View file

@ -1,7 +1,9 @@
use bitstream_reader::{BitRead, LittleEndian};
use crate::demo::parser::MalformedSendPropDefinitionError;
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropName, SendPropType};
use crate::demo::sendprop::{
SendPropDefinition, SendPropDefinitionIndex, SendPropFlag, SendPropName, SendPropType,
};
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
use parse_display::Display;
use serde::{Deserialize, Serialize};
@ -70,8 +72,8 @@ pub struct ParseSendTable {
pub needs_decoder: bool,
}
impl Parse for ParseSendTable {
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
impl ParseSendTable {
fn parse(stream: &mut Stream, _state: &ParserState, table_index: usize) -> Result<Self> {
let needs_decoder = stream.read()?;
let raw_name: String = stream.read()?;
let name: SendTableName = raw_name.into();
@ -80,8 +82,10 @@ impl Parse for ParseSendTable {
let mut array_element_prop = None;
let mut props = Vec::with_capacity(prop_count);
for _ in 0..prop_count {
let prop: SendPropDefinition = SendPropDefinition::read(stream, name.clone())?;
for prop_index in 0..prop_count {
let definition_index = SendPropDefinitionIndex::new(table_index, prop_index);
let prop: SendPropDefinition =
SendPropDefinition::read(stream, name.clone(), definition_index)?;
if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
@ -214,8 +218,10 @@ impl Parse for DataTablePacket {
let mut packet_data = stream.read_bits(len * 8)?;
let mut parse_tables = Vec::new();
let mut table_index = 0;
while packet_data.read_bool()? {
let table = ParseSendTable::parse(&mut packet_data, state)?;
let table = ParseSendTable::parse(&mut packet_data, state, table_index)?;
table_index += 1;
parse_tables.push(table);
}

View file

@ -44,6 +44,7 @@ pub struct SendPropDefinition {
pub bit_count: Option<u32>,
pub element_count: Option<u16>,
pub array_property: Option<Box<SendPropDefinition>>,
pub index: SendPropDefinitionIndex,
}
impl PartialEq for SendPropDefinition {
@ -129,6 +130,7 @@ impl SendPropDefinition {
element_count: self.element_count,
array_property: Some(Box::new(array_property)),
owner_table: self.owner_table,
index: self.index,
}
}
@ -145,7 +147,11 @@ impl SendPropDefinition {
}
}
pub fn read(stream: &mut Stream, owner_table: SendTableName) -> ReadResult<Self> {
pub fn read(
stream: &mut Stream,
owner_table: SendTableName,
index: SendPropDefinitionIndex,
) -> ReadResult<Self> {
let prop_type = SendPropType::read(stream)?;
let name = stream.read_string(None)?.into();
let flags = SendPropFlags::read(stream)?;
@ -189,6 +195,7 @@ impl SendPropDefinition {
element_count,
array_property: None,
owner_table,
index,
})
}
@ -521,6 +528,15 @@ impl From<Vec<SendPropValue>> for SendPropValue {
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct SendPropDefinitionIndex(usize, usize);
impl SendPropDefinitionIndex {
pub fn new(table: usize, prop: usize) -> Self {
SendPropDefinitionIndex(table, prop)
}
}
#[derive(Debug, Clone, Display)]
#[display("{definition.owner_table}::{definition.name} = {value}")]
pub struct SendProp {