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

35
Cargo.lock generated
View file

@ -184,6 +184,14 @@ name = "fuchsia-cprng"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.4" version = "0.4.4"
@ -523,6 +531,22 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "strum"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strum_macros"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "0.11.11" version = "0.11.11"
@ -585,6 +609,8 @@ dependencies = [
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_repr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_repr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -600,6 +626,11 @@ name = "ucd-util"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-segmentation"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.5" version = "0.1.5"
@ -663,6 +694,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum enumflags2 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8c30a444d141611c4826a1a2e7eba9a494458edf14754945fa37c9c20f6f7563" "checksum enumflags2 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8c30a444d141611c4826a1a2e7eba9a494458edf14754945fa37c9c20f6f7563"
"checksum enumflags2_derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e015b3dfedc096cb55cdc5d022d6b4e6b94547212fb94ad2d9ece20bcd88fe3" "checksum enumflags2_derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e015b3dfedc096cb55cdc5d022d6b4e6b94547212fb94ad2d9ece20bcd88fe3"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" "checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
@ -705,6 +737,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum serde_repr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "29a734c298df0346c4cd5919595981c266dabbf12dc747c85e1a95e96077a52b" "checksum serde_repr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "29a734c298df0346c4cd5919595981c266dabbf12dc747c85e1a95e96077a52b"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "95d697d63d44ad8b78b8d235bf85b34022a78af292c8918527c5f0cffdde7f43" "checksum snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "95d697d63d44ad8b78b8d235bf85b34022a78af292c8918527c5f0cffdde7f43"
"checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f"
"checksum strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47cd23f5c7dee395a00fa20135e2ec0fffcdfa151c56182966d7a3261343432e"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c" "checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
@ -712,6 +746,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" "checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"

View file

@ -6,6 +6,7 @@ edition = "2018"
[lib] [lib]
name = "tf_demo_parser" name = "tf_demo_parser"
path = "src/lib.rs"
[[bin]] [[bin]]
name = "parse_demo" name = "parse_demo"
@ -22,6 +23,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
serde_repr = "0.1" serde_repr = "0.1"
better-panic = "0.1" better-panic = "0.1"
strum = "0.15"
strum_macros = "0.15"
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.6" pretty_assertions = "0.6"

View file

@ -8,7 +8,8 @@ fn main() -> std::result::Result<(), Box<ParseError>> {
let args: Vec<_> = env::args().collect(); let args: Vec<_> = env::args().collect();
if args.len() < 2 { if args.len() < 2 {
panic!("1 argument required"); println!("1 argument required");
return Ok(());
} }
let path = args[1].clone(); let path = args[1].clone();
let file = fs::read(path).expect("Unable to read file"); 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::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropType};
use crate::{Parse, ParseError, ParserState, Result, Stream}; use crate::{Parse, ParseError, ParserState, Result, Stream, ReadResult};
use strum_macros::{EnumString, Display};
#[derive(BitRead, Debug)] #[derive(BitRead, Debug)]
pub struct ServerClass { pub struct ServerClass {
@ -10,12 +11,30 @@ pub struct ServerClass {
pub data_table: String, 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)] #[derive(Debug)]
pub struct SendTable { pub struct SendTable {
pub name: String, pub name: SendTableName,
pub props: Vec<RawSendPropDefinition>, pub props: Vec<SendPropDefinition>,
pub needs_decoder: bool, pub needs_decoder: bool,
pub flattened_props: Option<Vec<RawSendPropDefinition>>, pub flattened_props: Option<Vec<SendPropDefinition>>,
} }
impl Parse for SendTable { impl Parse for SendTable {
@ -28,8 +47,8 @@ impl Parse for SendTable {
let mut props = Vec::with_capacity(prop_count); let mut props = Vec::with_capacity(prop_count);
for _ in 0..prop_count { for _ in 0..prop_count {
let prop: RawSendPropDefinition = let prop: SendPropDefinition =
RawSendPropDefinition::read(stream)?; SendPropDefinition::read(stream)?;
if prop.flags.contains(SendPropFlag::InsideArray) { if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some() if array_element_prop.is_some()
|| prop.flags.contains(SendPropFlag::ChangesOften) || prop.flags.contains(SendPropFlag::ChangesOften)
@ -53,7 +72,7 @@ impl Parse for SendTable {
} }
Ok(SendTable { Ok(SendTable {
name, name: SendTableName::from(name),
flattened_props: None, flattened_props: None,
needs_decoder, needs_decoder,
props, 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)] #[derive(Debug)]
pub struct DataTablePacket { pub struct DataTablePacket {
pub tick: u32, 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::gameevent::GameEventTypeId;
use crate::demo::message::packetentities::EntityId; use crate::demo::message::packetentities::EntityId;
use crate::demo::message::stringtable::StringTableMeta; 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::packet::stringtable::StringTableEntry;
use crate::demo::parser::analyser::Analyser; use crate::demo::parser::analyser::Analyser;
use crate::demo::parser::handler::MessageHandler; use crate::demo::parser::handler::MessageHandler;
@ -24,7 +24,7 @@ pub struct ParserState {
pub event_definitions: HashMap<GameEventTypeId, GameEventDefinition>, pub event_definitions: HashMap<GameEventTypeId, GameEventDefinition>,
pub string_tables: Vec<StringTableMeta>, pub string_tables: Vec<StringTableMeta>,
pub entity_classes: HashMap<EntityId, ServerClass>, pub entity_classes: HashMap<EntityId, ServerClass>,
pub send_tables: HashMap<String, SendTable>, pub send_tables: HashMap<SendTableName, SendTable>,
pub server_classes: Vec<ServerClass>, pub server_classes: Vec<ServerClass>,
pub instance_baselines: [HashMap<EntityId, Vec<SendProp>>; 2], pub instance_baselines: [HashMap<EntityId, Vec<SendProp>>; 2],
pub demo_meta: DemoMeta, pub demo_meta: DemoMeta,

View file

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