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

sendtablename wip

This commit is contained in:
Robin Appelman 2019-07-10 14:03:58 +02:00
commit 1f35e4d04c
6 changed files with 114 additions and 24 deletions

View file

@ -8,7 +8,8 @@ fn main() -> std::result::Result<(), Box<ParseError>> {
let args: Vec<_> = env::args().collect();
if args.len() < 2 {
panic!("1 argument required");
println!("1 argument required");
return Ok(());
}
let path = args[1].clone();
let file = fs::read(path).expect("Unable to read file");

View file

@ -1,7 +1,8 @@
use bitstream_reader::BitRead;
use bitstream_reader::{BitRead, LittleEndian};
use crate::demo::sendprop::{RawSendPropDefinition, SendPropFlag, SendPropType};
use crate::{Parse, ParseError, ParserState, Result, Stream};
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropType};
use crate::{Parse, ParseError, ParserState, Result, Stream, ReadResult};
use strum_macros::{EnumString, Display};
#[derive(BitRead, Debug)]
pub struct ServerClass {
@ -10,12 +11,30 @@ pub struct ServerClass {
pub data_table: String,
}
#[derive(PartialEq, Eq, Hash, Debug, Clone, EnumString, Display)]
pub enum SendTableName {
#[strum(default = "true")]
Other(String)
}
impl From<String> for SendTableName {
fn from(value: String) -> Self {
value.parse().unwrap()
}
}
impl BitRead<LittleEndian> for SendTableName {
fn read(stream: &mut Stream) -> ReadResult<Self> {
String::read(stream).map(SendTableName::from)
}
}
#[derive(Debug)]
pub struct SendTable {
pub name: String,
pub props: Vec<RawSendPropDefinition>,
pub name: SendTableName,
pub props: Vec<SendPropDefinition>,
pub needs_decoder: bool,
pub flattened_props: Option<Vec<RawSendPropDefinition>>,
pub flattened_props: Option<Vec<SendPropDefinition>>,
}
impl Parse for SendTable {
@ -28,8 +47,8 @@ impl Parse for SendTable {
let mut props = Vec::with_capacity(prop_count);
for _ in 0..prop_count {
let prop: RawSendPropDefinition =
RawSendPropDefinition::read(stream)?;
let prop: SendPropDefinition =
SendPropDefinition::read(stream)?;
if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some()
|| prop.flags.contains(SendPropFlag::ChangesOften)
@ -53,7 +72,7 @@ impl Parse for SendTable {
}
Ok(SendTable {
name,
name: SendTableName::from(name),
flattened_props: None,
needs_decoder,
props,
@ -61,6 +80,36 @@ impl Parse for SendTable {
}
}
//impl SendTable {
// fn get_excludes(&self) -> ExcludesIterator {
// ExcludesIterator {
// table: self,
// index: 0,
// }
// }
//}
//
//struct ExcludesIterator<'a> {
// table: &'a SendTable,
// index: usize,
//}
//
//impl<'a> Iterator for ExcludesIterator<'a> {
// type Item = &'a SendPropDefinition;
//
// fn next(&mut self) -> Option<Self::Item> {
// while let Some(prop) = self.table.props.get(index) {
// index += 1;
// if prop.flags.contains(SendPropFlag::Exclude) {
// return Some(prop);
// } else if prop.prop_type == SendPropType::DataTable {
// if let Some(table)
// }
// }
// None
// }
//}
#[derive(Debug)]
pub struct DataTablePacket {
pub tick: u32,

View file

@ -5,7 +5,7 @@ use crate::demo::message::{Message, MessageType};
use crate::demo::message::gameevent::GameEventTypeId;
use crate::demo::message::packetentities::EntityId;
use crate::demo::message::stringtable::StringTableMeta;
use crate::demo::packet::datatable::{SendTable, ServerClass};
use crate::demo::packet::datatable::{SendTable, ServerClass, SendTableName};
use crate::demo::packet::stringtable::StringTableEntry;
use crate::demo::parser::analyser::Analyser;
use crate::demo::parser::handler::MessageHandler;
@ -24,7 +24,7 @@ pub struct ParserState {
pub event_definitions: HashMap<GameEventTypeId, GameEventDefinition>,
pub string_tables: Vec<StringTableMeta>,
pub entity_classes: HashMap<EntityId, ServerClass>,
pub send_tables: HashMap<String, SendTable>,
pub send_tables: HashMap<SendTableName, SendTable>,
pub server_classes: Vec<ServerClass>,
pub instance_baselines: [HashMap<EntityId, Vec<SendProp>>; 2],
pub demo_meta: DemoMeta,

View file

@ -6,24 +6,24 @@ use crate::{ReadResult, Result, Stream, Parse};
use super::packet::datatable::SendTable;
use super::vector::{Vector, VectorXY};
use crate::demo::packet::datatable::SendTableName;
#[derive(Debug)]
pub struct RawSendPropDefinition {
pub struct SendPropDefinition {
pub prop_type: SendPropType,
pub name: String,
pub flags: SendPropFlags,
pub table_name: Option<String>,
pub table_name: Option<SendTableName>,
pub low_value: Option<f32>,
pub high_value: Option<f32>,
pub bit_count: Option<u32>,
pub original_bit_count: Option<u32>,
pub element_count: Option<u16>,
pub array_property: Option<Box<RawSendPropDefinition>>,
pub array_property: Option<Box<SendPropDefinition>>,
}
impl RawSendPropDefinition {
impl SendPropDefinition {
pub fn with_array_property(self, array_property: Self) -> Self {
RawSendPropDefinition {
SendPropDefinition {
prop_type: self.prop_type,
name: self.name,
flags: self.flags,
@ -31,14 +31,18 @@ impl RawSendPropDefinition {
low_value: self.low_value,
high_value: self.high_value,
bit_count: self.bit_count,
original_bit_count: self.original_bit_count,
element_count: self.element_count,
array_property: Some(Box::new(array_property)),
}
}
pub fn get_data_table<'a>(&self, tables: &'a [SendTable]) -> Option<&'a SendTable> {
self.table_name.as_ref()
.and_then(|name| tables.iter().find(|table| table.name == *name))
}
}
impl BitRead<LittleEndian> for RawSendPropDefinition {
impl BitRead<LittleEndian> for SendPropDefinition {
fn read(stream: &mut Stream) -> ReadResult<Self> {
let prop_type = SendPropType::read(stream)?;
let name = stream.read_string(None)?;
@ -61,7 +65,6 @@ impl BitRead<LittleEndian> for RawSendPropDefinition {
bit_count = Some(stream.read_int(7)?);
}
}
let original_bit_count = bit_count;
if flags.contains(SendPropFlag::NoScale) {
if prop_type == SendPropType::Float {
@ -73,7 +76,7 @@ impl BitRead<LittleEndian> for RawSendPropDefinition {
}
}
Ok(RawSendPropDefinition {
Ok(SendPropDefinition {
prop_type,
name,
flags,
@ -81,7 +84,6 @@ impl BitRead<LittleEndian> for RawSendPropDefinition {
low_value,
high_value,
bit_count,
original_bit_count,
element_count,
array_property: None,
})
@ -192,7 +194,7 @@ pub enum SendPropValue {
#[derive(Debug)]
pub struct SendProp {
definition: RawSendPropDefinition,
definition: SendPropDefinition,
value: SendPropValue,
}