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

dont stop prop and table name in sendprop

This commit is contained in:
Robin Appelman 2021-02-13 14:48:55 +01:00
commit 35519d5fce
7 changed files with 215 additions and 216 deletions

View file

@ -2,8 +2,7 @@ use bitbuffer::BitRead;
use crate::demo::parser::MalformedSendPropDefinitionError;
use crate::demo::sendprop::{
RawSendPropDefinition, SendPropDefinition, SendPropDefinitionIndex, SendPropFlag, SendPropName,
SendPropType,
RawSendPropDefinition, SendPropDefinition, SendPropFlag, SendPropIdentifier, SendPropType,
};
use crate::{Parse, ParseError, ParserState, Result, Stream};
use parse_display::{Display, FromStr};
@ -81,12 +80,12 @@ impl From<String> for SendTableName {
#[derive(Debug, Clone)]
pub struct ParseSendTable {
pub name: SendTableName,
pub props: Vec<Rc<RawSendPropDefinition>>,
pub props: Vec<RawSendPropDefinition>,
pub needs_decoder: bool,
}
impl ParseSendTable {
fn parse(stream: &mut Stream, _state: &ParserState, table_index: usize) -> Result<Self> {
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
let needs_decoder = stream.read()?;
let raw_name: String = stream.read()?;
let name: SendTableName = raw_name.into();
@ -95,10 +94,8 @@ impl ParseSendTable {
let mut array_element_prop = None;
let mut props = Vec::with_capacity(min(prop_count, 128));
for prop_index in 0..prop_count {
let definition_index = SendPropDefinitionIndex::new(table_index, prop_index);
let prop: RawSendPropDefinition =
RawSendPropDefinition::read(stream, name.clone(), definition_index)?;
for _ in 0..prop_count {
let prop: RawSendPropDefinition = RawSendPropDefinition::read(stream, name.clone())?;
if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
@ -109,9 +106,9 @@ impl ParseSendTable {
return Err(MalformedSendPropDefinitionError::UntypedArray.into());
}
array_element_prop = None;
props.push(Rc::new(prop.with_array_property(array_element)));
props.push(prop.with_array_property(array_element));
} else {
props.push(Rc::new(prop));
props.push(prop);
}
}
@ -124,7 +121,7 @@ impl ParseSendTable {
}
impl ParseSendTable {
pub fn flatten_props(&self, tables: &[ParseSendTable]) -> Vec<Rc<RawSendPropDefinition>> {
pub fn flatten_props(&self, tables: &[ParseSendTable]) -> Vec<RawSendPropDefinition> {
let mut flat = Vec::with_capacity(32);
self.get_all_props(tables, &self.get_excludes(tables), &mut flat);
@ -139,18 +136,18 @@ impl ParseSendTable {
}
}
flat.into_iter().map(|prop| Rc::clone(&prop)).collect()
flat
}
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<Exclude<'a>> {
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<SendPropIdentifier> {
let mut excludes = Vec::with_capacity(8);
for prop in self.props.iter() {
if let Some(exclude_table) = prop.get_exclude_table() {
excludes.push(Exclude {
table: exclude_table,
prop: &prop.identifier.name,
})
excludes.push(SendPropIdentifier::new(
exclude_table.as_str(),
prop.name.as_str(),
))
} else if let Some(table) = prop.get_data_table(tables) {
excludes.extend_from_slice(&table.get_excludes(tables));
}
@ -163,8 +160,8 @@ impl ParseSendTable {
fn get_all_props(
&self,
tables: &[ParseSendTable],
excludes: &[Exclude],
props: &mut Vec<Rc<RawSendPropDefinition>>,
excludes: &[SendPropIdentifier],
props: &mut Vec<RawSendPropDefinition>,
) {
let mut local_props = Vec::new();
@ -175,14 +172,14 @@ impl ParseSendTable {
fn get_all_props_iterator_props(
&self,
tables: &[ParseSendTable],
excludes: &[Exclude],
local_props: &mut Vec<Rc<RawSendPropDefinition>>,
props: &mut Vec<Rc<RawSendPropDefinition>>,
excludes: &[SendPropIdentifier],
local_props: &mut Vec<RawSendPropDefinition>,
props: &mut Vec<RawSendPropDefinition>,
) {
self.props
.iter()
.filter(|prop| !prop.is_exclude())
.filter(|prop| !excludes.iter().any(|exclude| exclude.matches(prop)))
.filter(|prop| !excludes.iter().any(|exclude| *exclude == prop.identifier()))
.for_each(|prop| {
if let Some(table) = prop.get_data_table(tables) {
if prop.flags.contains(SendPropFlag::Collapsible) {
@ -191,24 +188,12 @@ impl ParseSendTable {
table.get_all_props(tables, excludes, props);
}
} else {
local_props.push(Rc::clone(prop));
local_props.push(prop.clone());
}
})
}
}
#[derive(Clone)]
struct Exclude<'a> {
table: &'a SendTableName,
prop: &'a SendPropName,
}
impl<'a> Exclude<'a> {
pub fn matches(&self, prop: &RawSendPropDefinition) -> bool {
self.table == &prop.identifier.owner_table && *self.prop == prop.identifier.name
}
}
#[derive(Debug, Clone)]
pub struct SendTable {
pub name: SendTableName,
@ -230,10 +215,8 @@ impl Parse<'_> for DataTablePacket {
let mut packet_data = stream.read_bits(len * 8)?;
let mut tables = Vec::new();
let mut table_index = 0;
while packet_data.read_bool()? {
let table = ParseSendTable::parse(&mut packet_data, state, table_index)?;
table_index += 1;
let table = ParseSendTable::parse(&mut packet_data, state)?;
tables.push(table);
}