mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
minor cleanip
This commit is contained in:
parent
c9781dc15e
commit
a333e26a6d
5 changed files with 54 additions and 55 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.dem
|
*.dem
|
||||||
|
*.svg
|
||||||
|
*.data*
|
||||||
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -3,16 +3,14 @@
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitstream_reader"
|
name = "bitstream_reader"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitstream_reader_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitstream_reader_derive 0.4.0",
|
||||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitstream_reader_derive"
|
name = "bitstream_reader_derive"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
@ -177,7 +175,7 @@ dependencies = [
|
||||||
name = "tf-demo-parser"
|
name = "tf-demo-parser"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitstream_reader 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitstream_reader 0.4.0",
|
||||||
"enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"enumflags2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"enumflags2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"enumflags2_derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"enumflags2_derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
@ -199,8 +197,6 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum bitstream_reader 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d3433dad8c395743f514171664564ae4348b425ca8f2894c218e5c9a9c4c2a7"
|
|
||||||
"checksum bitstream_reader_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "567ca1132e573c5e163a990aaf0e0e2b117da516d9e351398b7410597ab1e3e7"
|
|
||||||
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
|
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
|
||||||
"checksum enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b90e520ec62c1864c8c78d637acbfe8baf5f63240f2fb8165b8325c07812dd"
|
"checksum enum-primitive-derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b90e520ec62c1864c8c78d637acbfe8baf5f63240f2fb8165b8325c07812dd"
|
||||||
"checksum enumflags2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "801303a673e02d2110a196d70e4a807f0ff0a68ce1060eebc1e6a0d598db65e8"
|
"checksum enumflags2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "801303a673e02d2110a196d70e4a807f0ff0a68ce1060eebc1e6a0d598db65e8"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ name = "parse_demo"
|
||||||
path = "src/bin/main.rs"
|
path = "src/bin/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitstream_reader = "0.4"
|
bitstream_reader = { version = "0.4", path = "../../bitbuffer" }
|
||||||
enum-primitive-derive = "0.1.2"
|
enum-primitive-derive = "0.1.2"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
enumflags2 = "0.5"
|
enumflags2 = "0.5"
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,49 @@ pub struct SendTable {
|
||||||
pub flattened_props: Option<Vec<SendPropDefinition>>,
|
pub flattened_props: Option<Vec<SendPropDefinition>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parse for SendTable {
|
||||||
|
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
||||||
|
let needs_decoder = stream.read()?;
|
||||||
|
let name: String = stream.read()?;
|
||||||
|
let prop_count = stream.read_int(10)?;
|
||||||
|
|
||||||
|
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())?;
|
||||||
|
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(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
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(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
array_element_prop = None;
|
||||||
|
props.push(prop.with_array_property(array_element));
|
||||||
|
} else {
|
||||||
|
props.push(prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(SendTable {
|
||||||
|
name,
|
||||||
|
flattened_props: None,
|
||||||
|
needs_decoder,
|
||||||
|
props,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DataTablePacket {
|
pub struct DataTablePacket {
|
||||||
pub tick: u32,
|
pub tick: u32,
|
||||||
|
|
@ -26,51 +69,14 @@ pub struct DataTablePacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for DataTablePacket {
|
impl Parse for DataTablePacket {
|
||||||
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
|
fn parse(stream: &mut Stream, state: &ParserState) -> Result<Self> {
|
||||||
let tick = stream.read()?;
|
let tick = stream.read()?;
|
||||||
let len = stream.read_int::<usize>(32)?;
|
let len = stream.read_int::<usize>(32)?;
|
||||||
let mut packet_data = stream.read_bits(len * 8)?;
|
let mut packet_data = stream.read_bits(len * 8)?;
|
||||||
|
|
||||||
let mut tables = vec![];
|
let mut tables = Vec::new();
|
||||||
while packet_data.read_bool()? {
|
while packet_data.read_bool()? {
|
||||||
let needs_decoder = packet_data.read()?;
|
let table = SendTable::parse(&mut packet_data, state)?;
|
||||||
let name: String = packet_data.read()?;
|
|
||||||
let prop_count = packet_data.read_int(10)?;
|
|
||||||
|
|
||||||
let mut array_element_prop = None;
|
|
||||||
let mut props = Vec::with_capacity(prop_count);
|
|
||||||
|
|
||||||
for _ in 0..prop_count {
|
|
||||||
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(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
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(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
array_element_prop = None;
|
|
||||||
props.push(prop.with_array_property(array_element));
|
|
||||||
} else {
|
|
||||||
props.push(prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let table = SendTable {
|
|
||||||
name,
|
|
||||||
flattened_props: None,
|
|
||||||
needs_decoder,
|
|
||||||
props,
|
|
||||||
};
|
|
||||||
tables.push(table);
|
tables.push(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,15 +87,10 @@ impl DemoParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn read<T: Parse>(&mut self) -> Result<T> {
|
|
||||||
T::parse(&mut self.stream, self.handler.get_parser_state())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_demo(mut self) -> Result<(Header, MatchState)> {
|
pub fn parse_demo(mut self) -> Result<(Header, MatchState)> {
|
||||||
let header = self.read::<Header>()?;
|
let header = Header::read(&mut self.stream)?;
|
||||||
loop {
|
loop {
|
||||||
let packet = self.read::<Packet>()?;
|
let packet = Packet::parse(&mut self.stream, self.handler.get_parser_state())?;
|
||||||
match packet {
|
match packet {
|
||||||
Packet::Stop(_) => break,
|
Packet::Stop(_) => break,
|
||||||
packet => self.handler.handle_packet(packet),
|
packet => self.handler.handle_packet(packet),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue