pub struct Context { /* private fields */ }Expand description
Current replay state accessible to observers.
The context is passed to all observer callbacks and provides access to:
- Entity state and properties
- String tables
- Game event definitions
- Current tick and timing information
- Replay metadata
§Examples
§Accessing entities
use source2_demo::prelude::*;
#[derive(Default)]
struct HeroStats;
#[observer]
#[uses_entities]
impl HeroStats {
#[on_tick_start]
fn on_tick_start(&mut self, ctx: &Context) -> ObserverResult {
for entity in ctx.entities().iter() {
if entity.class().name().starts_with("CDOTA_Unit_Hero_") {
let health: i32 = property!(entity, "m_iHealth");
println!("{}: {}", entity.class().name(), health);
}
}
Ok(())
}
}§Accessing string tables
use source2_demo::prelude::*;
#[derive(Default)]
struct TableReader;
#[observer]
#[uses_string_tables]
impl TableReader {
#[on_tick_start]
fn on_tick_start(&mut self, ctx: &Context) -> ObserverResult {
if let Ok(table) = ctx.string_tables().get_by_name("ActiveModifiers") {
println!("Active modifiers: {}", table.iter().count());
}
Ok(())
}
}Implementations§
Source§impl Context
impl Context
Sourcepub fn classes(&self) -> &Classes
pub fn classes(&self) -> &Classes
Returns a reference to the entity container.
Use this to access all entities in the game and query their properties.
§Examples
use source2_demo::prelude::*;
// Get entity by index
let entity = ctx.entities().get_by_index(0)?;
// Find entity by class name
let player_resource = ctx.entities().get_by_class_name("CDOTA_PlayerResource")?;
// Iterate all entities
for entity in ctx.entities().iter() {
println!("{}", entity.class().name());
}Sourcepub fn entities(&self) -> &Entities
pub fn entities(&self) -> &Entities
Returns a reference to the entity container.
Provides access to all game entities and their properties.
Requires Interests::ENABLE_ENTITY to be populated.
Sourcepub fn string_tables(&self) -> &StringTables
pub fn string_tables(&self) -> &StringTables
Returns a reference to the string tables.
String tables contain game data like hero names, item names, etc.
Requires Interests::ENABLE_STRINGTAB to be populated.
Sourcepub fn game_events(&self) -> &GameEventList
pub fn game_events(&self) -> &GameEventList
Returns a reference to the game event list.
Contains definitions for all game events in the replay.
Sourcepub fn tick(&self) -> u32
pub fn tick(&self) -> u32
Returns the current tick number.
The tick represents the current game simulation step. Typically runs at 30 ticks per second.
Sourcepub fn net_tick(&self) -> u32
pub fn net_tick(&self) -> u32
Returns the current network tick.
The network tick from the last processed packet.
Sourcepub fn game_build(&self) -> u32
pub fn game_build(&self) -> u32
Returns the game build number.
Identifies the specific version of the game that created this replay.
Sourcepub fn replay_info(&self) -> &CDemoFileInfo
pub fn replay_info(&self) -> &CDemoFileInfo
Returns replay file metadata.
Contains information about the replay including duration, map, and game info.