mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 02:24:12 +02:00
entity write fixes
This commit is contained in:
parent
6f80468b6d
commit
577a998baa
17 changed files with 129 additions and 35 deletions
|
|
@ -2,37 +2,37 @@ use crate::Stream;
|
|||
/// Messages that consists only of primitives and string and can be derived
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct FileMessage {
|
||||
pub transfer_id: u32,
|
||||
pub file_name: String,
|
||||
pub requested: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct NetTickMessage {
|
||||
pub tick: u32,
|
||||
pub frame_time: u16,
|
||||
pub std_dev: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct StringCmdMessage {
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct SigOnStateMessage {
|
||||
pub state: u8,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct PrintMessage {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct ServerInfoMessage {
|
||||
pub version: u16,
|
||||
pub server_count: u32,
|
||||
|
|
@ -53,18 +53,18 @@ pub struct ServerInfoMessage {
|
|||
pub replay: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct SetPauseMessage {
|
||||
pub pause: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct SetViewMessage {
|
||||
#[size = 11]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct FixAngleMessage {
|
||||
pub relative: bool,
|
||||
pub x: u16,
|
||||
|
|
@ -72,7 +72,7 @@ pub struct FixAngleMessage {
|
|||
pub z: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct EntityMessage<'a> {
|
||||
#[size = 11]
|
||||
|
|
@ -85,13 +85,13 @@ pub struct EntityMessage<'a> {
|
|||
pub data: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct PreFetchMessage {
|
||||
#[size = 14]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct MenuMessage<'a> {
|
||||
pub kind: u16,
|
||||
|
|
@ -100,13 +100,13 @@ pub struct MenuMessage<'a> {
|
|||
pub index: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct GetCvarValueMessage {
|
||||
pub cookie: u32,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct CmdKeyValuesMessage<'a> {
|
||||
pub length: u32,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub enum MessageType {
|
|||
CmdKeyValues = 32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Message<'a> {
|
||||
Empty,
|
||||
File(FileMessage),
|
||||
|
|
|
|||
|
|
@ -94,10 +94,10 @@ impl PacketEntity {
|
|||
}
|
||||
|
||||
pub fn diff_from_baseline<'a>(
|
||||
&self,
|
||||
&'a self,
|
||||
baseline: &'a [SendProp],
|
||||
) -> impl Iterator<Item = &'a SendProp> + 'a {
|
||||
baseline.iter().filter(move |prop| {
|
||||
self.props.iter().filter(move |prop| {
|
||||
!baseline
|
||||
.iter()
|
||||
.any(|base_prop| base_prop.index == prop.index && base_prop.value == prop.value)
|
||||
|
|
@ -213,6 +213,7 @@ impl Parse<'_> for PacketEntitiesMessage {
|
|||
let updated_entries: u16 = stream.read_sized(11)?;
|
||||
let length: u32 = stream.read_sized(20)?;
|
||||
let updated_base_line = stream.read()?;
|
||||
|
||||
let mut data = stream.read_bits(length as usize)?;
|
||||
|
||||
let mut entities = Vec::with_capacity(min(updated_entries, 128) as usize);
|
||||
|
|
@ -319,7 +320,7 @@ impl Encode for PacketEntitiesMessage {
|
|||
|
||||
let length_end = stream.bit_len();
|
||||
|
||||
(length_end - length_start).write_sized(length_stream, 11)?;
|
||||
(length_end - length_start).write_sized(length_stream, 20)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -558,6 +559,24 @@ fn test_packet_entitier_message_roundtrip() {
|
|||
serial_number: 0,
|
||||
delay: None,
|
||||
},
|
||||
PacketEntity {
|
||||
server_class: ClassId::from(1),
|
||||
entity_index: EntityId::from(5),
|
||||
props: vec![
|
||||
SendProp {
|
||||
index: SendPropIdentifier::new("table2", "prop1"),
|
||||
value: SendPropValue::Integer(4),
|
||||
},
|
||||
SendProp {
|
||||
index: SendPropIdentifier::new("table2", "prop3"),
|
||||
value: SendPropValue::Float(1.0),
|
||||
},
|
||||
],
|
||||
in_pvs: true,
|
||||
pvs: PVS::Enter,
|
||||
serial_number: 0,
|
||||
delay: None,
|
||||
},
|
||||
],
|
||||
removed_entities: vec![],
|
||||
max_entries: 4,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use super::stringtable::read_var_int;
|
|||
use crate::demo::message::stringtable::write_var_int;
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct TempEntitiesMessage<'a> {
|
||||
pub count: u8,
|
||||
pub data: Stream<'a>,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ fn test_voice_init_roundtrip() {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct VoiceDataMessage<'a> {
|
||||
client: u8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue