Skip to content

Commit

Permalink
SendTable parsing wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
abenea committed Jan 1, 2024
1 parent 27312a3 commit fa5b04f
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 5 deletions.
72 changes: 72 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions cs2-demo/proto/netmessages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,34 @@ message CSVCMsg_ServerInfo {
optional .CSVCMsg_GameSessionConfiguration game_session_config = 19;
optional bytes game_session_manifest = 20;
}

message ProtoFlattenedSerializerField_t {
message polymorphic_field_t {
optional int32 polymorphic_field_serializer_name_sym = 1;
optional int32 polymorphic_field_serializer_version = 2;
}

optional int32 var_type_sym = 1;
optional int32 var_name_sym = 2;
optional int32 bit_count = 3;
optional float low_value = 4;
optional float high_value = 5;
optional int32 encode_flags = 6;
optional int32 field_serializer_name_sym = 7;
optional int32 field_serializer_version = 8;
optional int32 send_node_sym = 9;
optional int32 var_encoder_sym = 10;
repeated .ProtoFlattenedSerializerField_t.polymorphic_field_t polymorphic_types = 11;
}

message ProtoFlattenedSerializer_t {
optional int32 serializer_name_sym = 1;
optional int32 serializer_version = 2;
repeated int32 fields_index = 3;
}

message CSVCMsg_FlattenedSerializer {
repeated .ProtoFlattenedSerializer_t serializers = 1;
repeated string symbols = 2;
repeated .ProtoFlattenedSerializerField_t fields = 3;
}
9 changes: 6 additions & 3 deletions cs2-demo/src/demo_command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::packet::Packet;
use super::proto::demo::{CDemoFileHeader, CDemoPacket, CDemoSendTables};
use super::send_tables::SendTables;
use super::{Error, Result};
use crate::proto::demo::{CDemoFullPacket, CDemoStringTables};
use crate::string_table::{parse_string_tables, StringTable};
Expand All @@ -16,7 +17,7 @@ pub enum DemoCommand {
FileInfo,
/// A sync tick. It contains no data.
SyncTick,
SendTables(CDemoSendTables),
SendTables(SendTables),
ClassInfo,
StringTables(Vec<StringTable>),
Packet(Packet),
Expand All @@ -37,7 +38,9 @@ impl DemoCommand {
1 => DemoCommand::FileHeader(CDemoFileHeader::parse_from_bytes(data)?),
2 => DemoCommand::FileInfo,
3 => DemoCommand::SyncTick,
4 => DemoCommand::SendTables(CDemoSendTables::parse_from_bytes(data)?),
4 => DemoCommand::SendTables(SendTables::try_new(CDemoSendTables::parse_from_bytes(
data,
)?)?),
5 => DemoCommand::ClassInfo,
6 => DemoCommand::StringTables(parse_string_tables(
CDemoStringTables::parse_from_bytes(data)?,
Expand Down Expand Up @@ -68,7 +71,7 @@ impl fmt::Display for DemoCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DemoCommand::FileHeader(m) => write!(f, "FileHeader {}", m),
DemoCommand::SendTables(m) => write!(f, "SendTables {} bytes", m.data().len()),
DemoCommand::SendTables(_) => write!(f, "SendTables"),
_ => write!(f, "{:?}", self),
}
}
Expand Down
3 changes: 3 additions & 0 deletions cs2-demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod demo_command;
mod message;
mod packet;
pub mod proto;
mod send_tables;
mod string_table;

use crate::proto::demo::EDemoCommands;
Expand Down Expand Up @@ -32,6 +33,8 @@ pub enum Error {
MissingPacket,
#[error("cannot parse string table player index")]
InvalidPlayerIndex,
#[error("cannot parse sendtables")]
InvalidSendTables,
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down
35 changes: 35 additions & 0 deletions cs2-demo/src/send_tables.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::proto::demo::CDemoSendTables;
use crate::proto::netmessages::CSVCMsg_FlattenedSerializer;
use crate::{Error, Result};
use protobuf::CodedInputStream;

#[derive(Debug)]
pub struct SendTables {
_flattened_serializer: CSVCMsg_FlattenedSerializer,
}

impl SendTables {
pub(crate) fn try_new(msg: CDemoSendTables) -> Result<Self> {
let mut data = msg.data();
let _flattened_serializer: CSVCMsg_FlattenedSerializer = CodedInputStream::new(&mut data)
.read_message()
.or(Err(Error::InvalidSendTables))?;
Ok(Self {
_flattened_serializer,
})
}
}

#[cfg(test)]
mod tests {
use protobuf::Message;

use super::*;

#[test]
fn test() {
let binpb = include_bytes!("testdata/cdemosendtables.binpb");
let dst = CDemoSendTables::parse_from_bytes(binpb).unwrap();
SendTables::try_new(dst).unwrap();
}
}
Binary file added cs2-demo/src/testdata/cdemosendtables.binpb
Binary file not shown.
4 changes: 2 additions & 2 deletions csdemoparser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ edition = "2021"
tracing = ["dep:tracing-subscriber"]

[dependencies]
anyhow = "1.0"
anyhow = { version = "1.0", features = ["backtrace"] }
bitstream-io.workspace = true
byteorder = "1.4"
byteorder.workspace = true
csgo-demo = { path = "../csgo-demo" }
cs2-demo = { path = "../cs2-demo" }
demo-format = { path = "../demo-format" }
Expand Down
1 change: 1 addition & 0 deletions csdemoparser/src/cs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn parse(read: &mut dyn io::Read) -> anyhow::Result<DemoInfo> {
}
}
DemoCommand::StringTables(st) => state.handle_string_tables(st)?,
// DemoCommand::SendTables(send) => state.handle_send_tables(send)?,
_ => {}
}
}
Expand Down

0 comments on commit fa5b04f

Please sign in to comment.