mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
add serde support for packets
This commit is contained in:
parent
058ee0b96d
commit
03f8b8a424
27 changed files with 556 additions and 490 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,5 @@
|
|||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{GameEventError, Result, Stream};
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ use crate::demo::message::gameevent::GameEventTypeId;
|
|||
use parse_display::Display;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct GameEventDefinition {
|
||||
pub id: GameEventTypeId,
|
||||
pub event_type: GameEventType,
|
||||
|
|
@ -35,13 +36,13 @@ impl Ord for GameEventDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct GameEventEntry {
|
||||
pub name: String,
|
||||
pub kind: GameEventValueType,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Display)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Display, Serialize, Deserialize)]
|
||||
#[discriminant_bits = 3]
|
||||
pub enum GameEventValueType {
|
||||
None = 0,
|
||||
|
|
@ -54,7 +55,7 @@ pub enum GameEventValueType {
|
|||
Local = 7,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum GameEventValue {
|
||||
String(String),
|
||||
Float(f32),
|
||||
|
|
@ -154,7 +155,7 @@ impl EventValue for () {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RawGameEvent {
|
||||
pub event_type: GameEventType,
|
||||
pub values: Vec<GameEventValue>,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use bitbuffer::{BitRead, BitWrite};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Header {
|
||||
#[size = 8]
|
||||
pub demo_type: String,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::demo::sendprop::{read_bit_coord, write_bit_coord};
|
||||
use crate::demo::vector::Vector;
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct BSPDecalMessage {
|
||||
pub position: Vector,
|
||||
pub texture_index: u16,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use bitbuffer::{BitRead, BitReadSized, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::demo::message::stringtable::log_base2;
|
||||
use crate::{ReadResult, Stream};
|
||||
use std::cmp::min;
|
||||
|
||||
#[derive(BitReadSized, BitWriteSized, Debug, PartialEq)]
|
||||
#[derive(BitReadSized, BitWriteSized, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ClassInfoEntry {
|
||||
#[size = "input_size"]
|
||||
class_id: u16,
|
||||
|
|
@ -12,7 +13,7 @@ pub struct ClassInfoEntry {
|
|||
table_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ClassInfoMessage {
|
||||
count: u16,
|
||||
create: bool,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use parse_display::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::demo::gameevent_gen::GameEventType;
|
||||
use crate::demo::gamevent::{
|
||||
|
|
@ -8,7 +9,7 @@ use crate::demo::gamevent::{
|
|||
use crate::demo::parser::{Encode, ParseBitSkip};
|
||||
use crate::{GameEventError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct GameEventMessage {
|
||||
pub event_type_id: GameEventTypeId,
|
||||
pub event: GameEvent,
|
||||
|
|
@ -114,7 +115,21 @@ impl ParseBitSkip<'_> for GameEventMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display)]
|
||||
#[derive(
|
||||
BitRead,
|
||||
BitWrite,
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Display,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
pub struct GameEventTypeId(#[size = 9] u16);
|
||||
|
||||
impl From<GameEventTypeId> for usize {
|
||||
|
|
@ -129,7 +144,7 @@ impl From<GameEventTypeId> for u16 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct GameEventListMessage {
|
||||
pub event_list: Vec<GameEventDefinition>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
use crate::Stream;
|
||||
/// Messages that consists only of primitives and string and can be derived
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FileMessage {
|
||||
pub transfer_id: u32,
|
||||
pub file_name: String,
|
||||
pub requested: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NetTickMessage {
|
||||
pub tick: u32,
|
||||
pub frame_time: u16,
|
||||
pub std_dev: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct StringCmdMessage {
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SignOnStateMessage {
|
||||
pub state: u8,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PrintMessage {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ServerInfoMessage {
|
||||
pub version: u16,
|
||||
pub server_count: u32,
|
||||
|
|
@ -53,18 +54,18 @@ pub struct ServerInfoMessage {
|
|||
pub replay: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SetPauseMessage {
|
||||
pub pause: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SetViewMessage {
|
||||
#[size = 11]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FixAngleMessage {
|
||||
pub relative: bool,
|
||||
pub x: u16,
|
||||
|
|
@ -72,8 +73,9 @@ pub struct FixAngleMessage {
|
|||
pub z: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[endianness = "LittleEndian"]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct EntityMessage<'a> {
|
||||
#[size = 11]
|
||||
pub index: u16,
|
||||
|
|
@ -85,14 +87,15 @@ pub struct EntityMessage<'a> {
|
|||
pub data: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PreFetchMessage {
|
||||
#[size = 14]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[endianness = "LittleEndian"]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct MenuMessage<'a> {
|
||||
pub kind: u16,
|
||||
pub length: u16,
|
||||
|
|
@ -100,14 +103,15 @@ pub struct MenuMessage<'a> {
|
|||
pub index: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct GetCvarValueMessage {
|
||||
pub cookie: u32,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[endianness = "LittleEndian"]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct CmdKeyValuesMessage<'a> {
|
||||
pub length: u32,
|
||||
#[size = "length.saturating_mul(8)"]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::demo::message::voice::*;
|
|||
use crate::demo::parser::{Encode, ParseBitSkip};
|
||||
use crate::{Parse, ParserState, Result, Stream};
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
|
||||
pub mod bspdecal;
|
||||
|
|
@ -61,7 +62,8 @@ pub enum MessageType {
|
|||
CmdKeyValues = 32,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub enum Message<'a> {
|
||||
Empty,
|
||||
File(FileMessage),
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ pub enum PVS {
|
|||
Delete = 3,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PacketEntity {
|
||||
pub server_class: ClassId,
|
||||
pub entity_index: EntityId,
|
||||
|
|
@ -174,7 +174,7 @@ fn test_bit_var_roundtrip() {
|
|||
bit_var_normal(123456789);
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PacketEntitiesMessage {
|
||||
pub entities: Vec<PacketEntity>,
|
||||
pub removed_entities: Vec<EntityId>,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, Endianness};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::ReadResult;
|
||||
|
||||
#[derive(Debug, BitWrite, PartialEq)]
|
||||
#[derive(Debug, BitWrite, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ConVar {
|
||||
key: String,
|
||||
value: String,
|
||||
|
|
@ -20,7 +21,7 @@ impl<E: Endianness> BitRead<'_, E> for ConVar {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, BitRead, PartialEq)]
|
||||
#[derive(Debug, BitRead, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SetConVarMessage {
|
||||
length: u8,
|
||||
#[size = "length"]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use bitbuffer::{
|
|||
BitReadBuffer, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, LittleEndian,
|
||||
};
|
||||
use num_traits::{PrimInt, Unsigned};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use snap::raw::{decompress_len, Decoder};
|
||||
|
||||
use crate::demo::lzss::decompress;
|
||||
|
|
@ -13,12 +14,13 @@ use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
|||
use std::borrow::Cow;
|
||||
use std::cmp::min;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct CreateStringTableMessage<'a> {
|
||||
pub table: StringTable<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct StringTableMeta {
|
||||
pub max_entries: u16,
|
||||
pub fixed_userdata_size: Option<FixedUserDataSize>,
|
||||
|
|
@ -233,7 +235,8 @@ fn test_create_string_table_roundtrip() {
|
|||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct UpdateStringTableMessage<'a> {
|
||||
pub entries: Vec<(u16, StringTableEntry<'a>)>,
|
||||
pub table_id: u8,
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@ use crate::demo::sendprop::SendProp;
|
|||
use crate::Result;
|
||||
use crate::{Parse, ParseError, ParserState, Stream};
|
||||
use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TempEntitiesMessage {
|
||||
pub events: Vec<EventInfo>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EventInfo {
|
||||
pub class_id: ClassId,
|
||||
pub fire_delay: f32,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::demo::handle_utf8_error;
|
|||
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
#[discriminant_bits = 8]
|
||||
pub enum UserMessageType {
|
||||
|
|
@ -70,7 +70,8 @@ pub enum UserMessageType {
|
|||
Unknown = 255,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub enum UserMessage<'a> {
|
||||
SayText2(Box<SayText2Message>),
|
||||
Text(Box<TextMessage>),
|
||||
|
|
@ -204,7 +205,7 @@ impl BitWrite<LittleEndian> for ChatMessageKind {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SayText2Message {
|
||||
pub client: u8,
|
||||
pub raw: u8,
|
||||
|
|
@ -312,7 +313,7 @@ fn test_say_text2_roundtrip() {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[discriminant_bits = 8]
|
||||
pub enum HudTextLocation {
|
||||
PrintNotify = 1,
|
||||
|
|
@ -321,31 +322,31 @@ pub enum HudTextLocation {
|
|||
PrintCenter,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TextMessage {
|
||||
pub location: HudTextLocation,
|
||||
pub text: String,
|
||||
pub substitute: [String; 4],
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ResetHudMessage {
|
||||
pub data: u8,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TrainMessage {
|
||||
pub data: u8,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct VoiceSubtitleMessage {
|
||||
client: u8,
|
||||
menu: u8,
|
||||
item: u8,
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ShakeMessage {
|
||||
command: u8,
|
||||
amplitude: f32,
|
||||
|
|
@ -353,7 +354,8 @@ pub struct ShakeMessage {
|
|||
duration: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct UnknownUserMessage<'a> {
|
||||
data: Stream<'a>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct VoiceInitMessage {
|
||||
codec: String,
|
||||
quality: u8,
|
||||
|
|
@ -57,8 +58,9 @@ fn test_voice_init_roundtrip() {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[endianness = "LittleEndian"]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct VoiceDataMessage<'a> {
|
||||
client: u8,
|
||||
proximity: u8,
|
||||
|
|
@ -67,7 +69,8 @@ pub struct VoiceDataMessage<'a> {
|
|||
data: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct ParseSoundsMessage<'a> {
|
||||
pub reliable: bool,
|
||||
pub num: u8,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
|
||||
use crate::{ReadResult, Stream};
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ConsoleCmdPacket {
|
||||
pub tick: u32,
|
||||
pub command: String,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,20 @@ use std::convert::TryFrom;
|
|||
use std::iter::once;
|
||||
|
||||
#[derive(
|
||||
BitRead, BitWrite, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Display, FromStr,
|
||||
BitRead,
|
||||
BitWrite,
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
Display,
|
||||
FromStr,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
pub struct ClassId(u16);
|
||||
|
||||
|
|
@ -54,7 +67,7 @@ impl From<&str> for ServerClassName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ServerClass {
|
||||
pub id: ClassId,
|
||||
pub name: ServerClassName,
|
||||
|
|
@ -96,7 +109,7 @@ impl From<&str> for SendTableName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ParseSendTable {
|
||||
pub name: SendTableName,
|
||||
pub props: Vec<RawSendPropDefinition>,
|
||||
|
|
@ -318,7 +331,7 @@ impl ParseSendTable {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SendTable {
|
||||
pub name: SendTableName,
|
||||
pub needs_decoder: bool,
|
||||
|
|
@ -326,7 +339,7 @@ pub struct SendTable {
|
|||
pub flattened_props: Vec<SendPropDefinition>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DataTablePacket {
|
||||
pub tick: u32,
|
||||
pub tables: Vec<ParseSendTable>,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use bitbuffer::{bit_size_of, BitRead, BitWrite, BitWriteStream, Endianness, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::demo::message::{Message, MessageType};
|
||||
use crate::demo::parser::Encode;
|
||||
use crate::demo::vector::Vector;
|
||||
use crate::{Parse, ParserState, ReadResult, Result, Stream};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MessagePacketMeta {
|
||||
pub flags: u32, // TODO
|
||||
pub view_angles: ViewAngles,
|
||||
|
|
@ -13,14 +14,15 @@ pub struct MessagePacketMeta {
|
|||
pub sequence_out: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct MessagePacket<'a> {
|
||||
pub tick: u32,
|
||||
pub messages: Vec<Message<'a>>,
|
||||
pub meta: MessagePacketMeta,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Default)]
|
||||
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct ViewAngles {
|
||||
pub origin: (Vector, Vector),
|
||||
pub angles: (Vector, Vector),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use self::stringtable::StringTablePacket;
|
|||
use self::synctick::SyncTickPacket;
|
||||
use self::usercmd::UserCmdPacket;
|
||||
use crate::demo::parser::Encode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod consolecmd;
|
||||
pub mod datatable;
|
||||
|
|
@ -19,7 +20,8 @@ pub mod stringtable;
|
|||
pub mod synctick;
|
||||
pub mod usercmd;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub enum Packet<'a> {
|
||||
Sigon(MessagePacket<'a>),
|
||||
Message(MessagePacket<'a>),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use bitbuffer::{BitRead, BitWrite};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq, Serialize, Deserialize)]
|
||||
pub struct StopPacket {
|
||||
#[size = 24]
|
||||
pub tick: u32,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
use crate::demo::message::stringtable::StringTableMeta;
|
||||
use crate::demo::parser::Encode;
|
||||
|
|
@ -8,7 +8,7 @@ use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
|||
use std::borrow::{Borrow, Cow};
|
||||
use std::cmp::min;
|
||||
|
||||
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FixedUserDataSize {
|
||||
#[size = 12]
|
||||
pub size: u16,
|
||||
|
|
@ -16,7 +16,8 @@ pub struct FixedUserDataSize {
|
|||
pub bits: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct StringTable<'a> {
|
||||
pub name: Cow<'a, str>,
|
||||
pub entries: Vec<(u16, StringTableEntry<'a>)>,
|
||||
|
|
@ -144,8 +145,9 @@ fn test_string_table_roundtrip() {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Clone, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[endianness = "LittleEndian"]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct ExtraData<'a> {
|
||||
pub byte_len: u16,
|
||||
#[size = "byte_len.saturating_mul(8)"]
|
||||
|
|
@ -159,7 +161,8 @@ impl<'a> ExtraData<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq)]
|
||||
#[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct StringTableEntry<'a> {
|
||||
pub text: Option<Cow<'a, str>>,
|
||||
pub extra_data: Option<ExtraData<'a>>,
|
||||
|
|
@ -208,7 +211,8 @@ impl fmt::Debug for StringTableEntry<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "'a: 'static"))]
|
||||
pub struct StringTablePacket<'a> {
|
||||
pub tick: u32,
|
||||
pub tables: Vec<StringTable<'a>>,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use bitbuffer::{BitRead, BitWrite};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SyncTickPacket {
|
||||
pub tick: u32,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct UserCmdPacket {
|
||||
pub tick: u32,
|
||||
pub sequence_out: u32,
|
||||
|
|
@ -30,7 +31,7 @@ impl BitWrite<LittleEndian> for UserCmdPacket {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite)]
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite, Serialize, Deserialize)]
|
||||
pub struct UserCmd {
|
||||
command_number: Option<u32>,
|
||||
tick_count: Option<u32>,
|
||||
|
|
@ -43,7 +44,7 @@ pub struct UserCmd {
|
|||
mouse_dy: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite)]
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite, Serialize, Deserialize)]
|
||||
pub struct WeaponSelect {
|
||||
#[size = 11]
|
||||
select: u16,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@ use crate::demo::packet::stringtable::StringTableEntry;
|
|||
use crate::demo::sendprop::SendProp;
|
||||
use crate::nullhasher::NullHasherBuilder;
|
||||
use crate::{Result, Stream};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
pub struct DemoMeta {
|
||||
pub version: u16,
|
||||
pub game: String,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ impl From<&str> for SendPropName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RawSendPropDefinition {
|
||||
pub prop_type: SendPropType,
|
||||
pub name: SendPropName,
|
||||
|
|
@ -252,7 +252,7 @@ impl BitWrite<LittleEndian> for RawSendPropDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Copy, Clone, PartialEq, Debug, Display)]
|
||||
#[derive(BitRead, BitWrite, Copy, Clone, PartialEq, Debug, Display, Serialize, Deserialize)]
|
||||
#[discriminant_bits = 5]
|
||||
pub enum SendPropType {
|
||||
Int = 0,
|
||||
|
|
@ -310,7 +310,7 @@ pub enum SendPropFlag {
|
|||
NormalVarInt = 32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Default)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct SendPropFlags(BitFlags<SendPropFlag>);
|
||||
|
||||
impl BitOr<SendPropFlag> for SendPropFlags {
|
||||
|
|
@ -356,7 +356,7 @@ impl BitWrite<LittleEndian> for SendPropFlags {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum FloatDefinition {
|
||||
Coord,
|
||||
CoordMP,
|
||||
|
|
@ -398,7 +398,7 @@ impl FloatDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SendPropDefinition {
|
||||
pub identifier: SendPropIdentifier,
|
||||
pub parse_definition: SendPropParseDefinition,
|
||||
|
|
@ -416,7 +416,7 @@ impl TryFrom<&RawSendPropDefinition> for SendPropDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum SendPropParseDefinition {
|
||||
NormalVarInt {
|
||||
changes_often: bool,
|
||||
|
|
@ -1068,7 +1068,9 @@ impl<'a> TryFrom<&'a SendPropValue> for &'a [SendPropValue] {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Display)]
|
||||
#[derive(
|
||||
Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Display, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct SendPropIdentifier(u64);
|
||||
|
||||
impl SendPropIdentifier {
|
||||
|
|
@ -1084,7 +1086,7 @@ impl From<u64> for SendPropIdentifier {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Display, PartialEq)]
|
||||
#[derive(Debug, Clone, Display, PartialEq, Serialize, Deserialize)]
|
||||
#[display("{index} = {value}")]
|
||||
pub struct SendProp {
|
||||
pub index: u32,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::hash::{BuildHasher, Hasher};
|
||||
|
||||
/// A dummy hasher that maps simply returns the hashed u64
|
||||
|
|
@ -34,7 +35,7 @@ impl Hasher for NullHasher {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Serialize, Deserialize, Default)]
|
||||
pub struct NullHasherBuilder;
|
||||
|
||||
impl BuildHasher for NullHasherBuilder {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue