DemoFile.Net is a blazing fast demo parser library for Source 2 games, written in C#. It is cross-platform, and can be used on Windows, Mac or Linux. This parser currently supports:
Game | NuGet package | Getting started |
---|---|---|
Counter-Strike 2 | ✅ DemoFile.Game.Cs | new CsDemoParser() |
Deadlock | ✅ DemoFile.Game.Deadlock | new DeadlockDemoParser() |
Important
DemoFile
is the base, core library and does not provide support for parsing any specific game.
Add a reference to one of the DemoFile.Game.*
packages instead.
Easy discoverability of available data through your IDE's inbuilt autocompletion:
Feature | Availability |
---|---|
CSTV / GOTV demos | ✅ Full support |
POV demos | ✅ Full support |
HTTP broadcasts | ✅ Full support |
Game events (e.g. player_death ) |
✅ Full support |
Entity updates (player positions, grenades, etc.) | ✅ Full support |
Seeking forwards/backwards through the demo | ✅ Full support |
Warning
This library is still under development and the API is liable to change until v1.0
using DemoFile;
internal class Program
{
public static async Task Main(string[] args)
{
var path = args.SingleOrDefault() ?? throw new Exception("Expected a single argument: <path to .dem>");
var demo = new CsDemoParser();
demo.Source1GameEvents.PlayerDeath += e =>
{
Console.WriteLine($"{e.Attacker?.PlayerName} [{e.Weapon}] {e.Player?.PlayerName}");
};
var reader = DemoFileReader.Create(demo, File.OpenRead(path));
await reader.ReadAllAsync();
Console.WriteLine("\nFinished!");
}
}
See also the examples/ folder.
For maximum performance, a given demo file can be parsed in sections in parallel. This utilises all available CPU cores. For example usage, take a look at DemoFile.Example.MultiThreaded.
On an M1 MacBook Pro, DemoFile.Net can read a full competitive game (just under 1 hour of game time) in 1.3 seconds.
When parsing across multiple threads, using the ReadAllParallelAsync
method, this drops to nearly 500 milliseconds.
This includes parsing all entity data (player positions, velocities, weapon tracking, grenades, etc).
Method | Mean | Error | StdDev | Allocated |
---|---|---|---|---|
ParseDemo | 1,294.6 ms | 3.68 ms | 2.88 ms | 491.48 MB |
ParseDemoParallel | 540.1 ms | 23.99 ms | 22.44 ms | 600.67 MB |
DemoFile.Net is developed by Saul Rennison. The development of this library would not have been possible without demoparser by LaihoE and Manta by Dotabuff, the latter of which depends on the efforts of a number of people:
- Michael Fellinger built Dotabuff's Source 1 parser yasha.
- Robin Dietrich built the C++ parser Alice.
- Martin Schrodt built the Java parser clarity.
- Drew Schleck built an original C++ parser edith.
A modified version of Source2Gen by neverlosecc is used to statically generate the game schema classes and enums.
See ACKNOWLEDGEMENTS for license information.