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

track spawns

This commit is contained in:
Robin Appelman 2019-03-04 20:56:12 +01:00
commit 6a47c91636
6 changed files with 176 additions and 58 deletions

View file

@ -1,12 +1,19 @@
use bitstream_reader::{BitRead, BitReadSized, LittleEndian};
use serde::Serialize;
use crate::demo::packet::datatable::ServerClass;
use crate::demo::sendprop::SendProp;
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct EntityId(u32);
impl EntityId {
pub fn new(num: u32) -> Self {
EntityId(num)
}
}
#[derive(BitRead, Clone, Copy, Debug)]
#[discriminant_bits = 3]
pub enum PVS {

View file

@ -240,10 +240,7 @@ fn read_table_entry(
} else {
None
}
.map(|stream| ExtraData {
len: stream.bit_len() as u16 / 8,
data: stream,
});
.map(ExtraData::new);
Ok(match existing_entry {
Some(existing_entry) => {

View file

@ -100,21 +100,21 @@ impl BitRead<LittleEndian> for UserMessage {
}
#[derive(Debug, Clone, Serialize)]
pub enum SayText2Kind {
pub enum ChatMessageKind {
ChatAll,
ChatTeam,
ChatAllDead,
NameChange,
}
impl BitRead<LittleEndian> for SayText2Kind {
impl BitRead<LittleEndian> for ChatMessageKind {
fn read(stream: &mut Stream) -> ReadResult<Self> {
let raw: String = stream.read()?;
Ok(match raw.as_str() {
"TF_Chat_Team" => SayText2Kind::ChatTeam,
"TF_Chat_AllDead" => SayText2Kind::ChatAllDead,
"#TF_Name_Change" => SayText2Kind::NameChange,
_ => SayText2Kind::ChatAll,
"TF_Chat_Team" => ChatMessageKind::ChatTeam,
"TF_Chat_AllDead" => ChatMessageKind::ChatAllDead,
"#TF_Name_Change" => ChatMessageKind::NameChange,
_ => ChatMessageKind::ChatAll,
})
}
}
@ -123,7 +123,7 @@ impl BitRead<LittleEndian> for SayText2Kind {
pub struct SayText2Message {
pub client: u8,
pub raw: u8,
pub kind: SayText2Kind,
pub kind: ChatMessageKind,
pub from: String,
pub text: String,
}
@ -132,7 +132,7 @@ impl BitRead<LittleEndian> for SayText2Message {
fn read(stream: &mut Stream) -> ReadResult<Self> {
let client = stream.read()?;
let raw = stream.read()?;
let (kind, from, text): (SayText2Kind, String, String) = if stream.read::<u8>()? == 1 {
let (kind, from, text): (ChatMessageKind, String, String) = if stream.read::<u8>()? == 1 {
let first = stream.read::<u8>()?;
if first == 7 {
let _color = stream.read_string(Some(6))?;
@ -149,10 +149,10 @@ impl BitRead<LittleEndian> for SayText2Message {
text.bytes().skip(start + 1).take(end - start - 1).collect(),
)?;
let text: String = String::from_utf8(text.bytes().skip(end + 5).collect())?;
let kind = SayText2Kind::ChatAllDead;
let kind = ChatMessageKind::ChatAllDead;
(kind, from, text)
} else {
(SayText2Kind::ChatAll, "".to_owned(), text)
(ChatMessageKind::ChatAll, "".to_owned(), text)
}
} else {
let _ = stream.set_pos(stream.pos() - 8)?;