source2-demo
source2-demo is a Rust library for parsing Source 2 engine demo files.
Supported Games
- Dota 2
- Deadlock
- Counter-Strike 2
Installation
Add the following to your Cargo.toml and enable the feature for the game you want to parse:
[]
# For Dota 2
= { = "0.3", = ["dota"] }
# For Deadlock
# source2-demo = { version = "0.3", features = ["deadlock"] }
# For Counter-Strike 2
# source2-demo = { version = "0.3", features = ["cs2"] }
Quick Start: Parsing Chat Messages
Here's a simple program that prints chat messages from a Dota 2 replay. It handles the CDotaUserMsgChatMessage protobuf message and prints the player's name and their message.
More examples can be found in the d2-examples and dl-examples directories.
use *;
use *;
// Create a struct that implements the Default trait
;
// Mark the impl block with the observer attribute
Building Examples
To build the examples, clone the repository and use Cargo:
git clone https://github.com/Rupas1k/source2-demo
cd source2-demo
# Build examples for a specific game
cd dl-examples # d2-examples
cargo build --release
Features
The crate supports the following cargo features:
dota- Enable Dota 2 replay parsing (includes Dota 2 protobufs)deadlock- Enable Deadlock replay parsing (includes Citadel protobufs)cs2- Enable Counter-Strike 2 replay parsing (includes CS2 protobufs)mimalloc(default) - Use mimalloc as the global allocator for improved performance
You can enable multiple game features if needed:
= { = "*", = ["dota", "cs2"] }
You can disable mimalloc if it causes issues on your platform (e.g., WebAssembly):
= { = "*", = false }
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
This project was inspired by and builds upon the work of other Source 2 demo parsers:
License
This project is dual-licensed under either:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.