Crate d2_stampede

Source
Expand description

§D2-Stampede

Dota 2 replay parser written in Rust.

§Quick Start

use d2_stampede::prelude::*;
use d2_stampede::proto::*;

// Create struct that implements Default trait
#[derive(Default)]
struct Chat;

// Mark impl block with observer attribute
#[observer]
impl Chat {
    #[on_message] // Use on_message attribute to mark protobuf message handler
    fn handle_chat_msg(
        &mut self,
        ctx: &Context,
        chat_msg: CDotaUserMsgChatMessage, // Use any protobuf message as an argument
    ) -> ObserverResult {
        if let Ok(pr) = ctx.entities().get_by_class_name("CDOTA_PlayerResource") {
            let name: String = property!(
                pr,
                "m_vecPlayerData.{:04}.m_iszPlayerName",
                chat_msg.source_player_id()
            );
            println!("{}: {}", name, chat_msg.message_text());
        }
        Ok(())
    }
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read replay file
    let replay = unsafe { memmap2::Mmap::map(&std::fs::File::open("replay.dem")?)? };

    // Create parser 
    let mut parser = Parser::new(&replay)?;

    // Register observers
    parser.register_observer::<Chat>();

    // Parse replay from start to end
    parser.run_to_end()?;

    // Or parse only parts of replay
    parser.jump_to_tick(10000)?;
    parser.run_to_tick(11000)?;

    Ok(())
}

§Examples

d2-stampede-examples

§Download and Build
git clone https://github.com/Rupas1k/d2-stampede.git
cd d2-stampede
cargo build --release

odota-rust - copy of OpenDota parser in Rust
d2wm-parser - wards parser with bindings for Python

Modules§

error
prelude
proto

Macros§

property
Macro for getting property from Entity.
try_property
Same as property but returns None if property doesn’t exist for given Entity or cannot be converted into given type.

Structs§

Class
Entity class
Classes
Container for classes.
CombatLogEntry
Wrapper for CMsgDotaCombatLogEntry
Context
Current replay state.
Entities
Container for entities.
Entity
Parser
StringTable
StringTableRow
StringTables
String tables container.

Enums§

EntityEvents
FieldValue
Special type for Entity field value that can be converted into Rust type using try_into.

Traits§

Observer
A trait defining methods for handling game events and protobuf messages. Can be attached to Parser instance with Parser::register_observer method.

Type Aliases§

ObserverResult
Result type for observers (anyhow::Result)

Attribute Macros§

observer
on_combat_log
on_entity
on_message
on_tick_end
on_tick_start