Skip to main content

source2_demo/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(html_root_url = "https://docs.rs/source2-demo/0.3.2")]
3#![warn(missing_docs)]
4#![allow(clippy::too_many_arguments)]
5
6
7mod display;
8mod entity;
9pub mod error;
10mod event;
11mod macros;
12mod parser;
13mod reader;
14mod string_table;
15
16/// Protocol buffer definitions for Source 2 games.
17///
18/// This module re-exports all protobuf message types used by the parser.
19/// The available messages depend on which game feature is enabled.
20///
21/// # Examples
22///
23/// ```no_run
24/// use source2_demo::proto::*;
25///
26/// // Decode a protobuf message
27/// let msg = CDemoFileInfo::decode(bytes)?;
28/// # Ok::<(), Box<dyn std::error::Error>>(())
29/// ```
30pub mod proto {
31    pub use source2_demo_protobufs::prost::Message;
32    pub use source2_demo_protobufs::*;
33}
34
35/// Prelude module for convenient imports.
36///
37/// Import this module to get access to all commonly used types and traits:
38///
39/// ```
40/// use source2_demo::prelude::*;
41/// ```
42///
43/// This includes:
44/// - Core types: [`Parser`], [`Context`], [`Entity`], [`Observer`]
45/// - Traits and macros: [`observer`], [`on_message`], [`property!`]
46/// - Protobuf enums: Message type enumerations for each game
47pub mod prelude {
48    pub use crate::entity::{Entity, EntityEvents};
49    pub use crate::event::{EventValue, GameEvent, GameEventList};
50    pub use crate::parser::*;
51    pub use crate::string_table::*;
52    pub use crate::{property, try_property};
53
54    pub use source2_demo_macros::*;
55
56    pub use source2_demo_protobufs::prost::Message;
57    pub use source2_demo_protobufs::EBaseGameEvents;
58    pub use source2_demo_protobufs::EBaseUserMessages;
59    pub use source2_demo_protobufs::EDemoCommands;
60    pub use source2_demo_protobufs::NetMessages;
61    pub use source2_demo_protobufs::SvcMessages;
62
63    #[cfg(feature = "dota")]
64    pub use crate::event::CombatLogEntry;
65    #[cfg(feature = "dota")]
66    pub use crate::proto::EDotaUserMessages;
67
68    #[cfg(feature = "deadlock")]
69    pub use crate::proto::CitadelUserMessageIds;
70    #[cfg(feature = "deadlock")]
71    pub use crate::proto::ECitadelGameEvents;
72
73    #[cfg(feature = "cs2")]
74    pub use crate::proto::ECstrike15UserMessages;
75    #[cfg(feature = "cs2")]
76    pub use crate::proto::ECsgoGameEvents;
77}
78
79// Re-export commonly used types at the crate root
80pub use crate::entity::field::FieldValue;
81pub use crate::entity::*;
82pub use crate::event::*;
83pub use crate::parser::*;
84pub use crate::string_table::*;
85pub use source2_demo_macros::*;
86
87/// Fast hash map using FxHash algorithm.
88///
89/// This type alias is used throughout the crate for better performance
90/// compared to the standard library's `HashMap`.
91pub type HashMap<K, V> =
92hashbrown::HashMap<K, V, rustc_hash::FxBuildHasher>;
93
94/// Fast hash set using FxHash algorithm.
95///
96/// This type alias is used throughout the crate for better performance
97/// compared to the standard library's `HashSet`.
98pub type HashSet<T> =
99hashbrown::HashSet<T, rustc_hash::FxBuildHasher>;
100
101
102#[cfg(feature = "dota")]
103pub use crate::event::CombatLogEntry;
104
105#[cfg(feature = "mimalloc")]
106use mimalloc::MiMalloc;
107#[cfg(feature = "mimalloc")]
108#[global_allocator]
109static GLOBAL: MiMalloc = MiMalloc;