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 |
Add the appropriate NuGet package to your project:
# For Counter-Strike 2
dotnet add package DemoFile.Game.Cs
# For Deadlock
dotnet add package DemoFile.Game.Deadlock
Here's a simple example that prints kill feed information from a CS2 demo:
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!");
}
}
You can track player positions and other entity data throughout the demo:
var demo = new CsDemoParser();
// Subscribe to tick events to get data at specific points in time
demo.TickEnd += (_, tick) =>
{
// Get all active players
foreach (var player in demo.Entities.Players)
{
if (player.Pawn is { } pawn)
{
Console.WriteLine($"Player {player.PlayerName} is at position {pawn.CBodyComponent?.Position}");
}
}
};
var reader = DemoFileReader.Create(demo, File.OpenRead(demoPath));
await reader.ReadAllAsync();
DemoFile.Net provides strongly-typed access to game events:
var demo = new CsDemoParser();
// Track round wins
demo.Source1GameEvents.RoundEnd += e =>
{
Console.WriteLine($"Round ended. Winner: {e.Winner}. Reason: {e.Reason}");
};
// Track bomb events
demo.Source1GameEvents.BombPlanted += e =>
{
Console.WriteLine($"Bomb planted by {e.Player?.PlayerName} at site {e.Site}");
};
demo.Source1GameEvents.BombDefused += e =>
{
Console.WriteLine($"Bomb defused by {e.Player?.PlayerName}");
};
var reader = DemoFileReader.Create(demo, File.OpenRead(demoPath));
await reader.ReadAllAsync();
For maximum performance, parse demos in parallel using multiple CPU cores:
var demo = new CsDemoParser();
// Set up your event handlers...
var reader = DemoFileReader.Create(demo, File.OpenRead(demoPath));
await reader.ReadAllParallelAsync(); // Uses all available CPU cores
DemoFile.Net can parse live HTTP broadcasts:
var demo = new CsDemoParser();
// Set up your event handlers...
var reader = HttpBroadcastReader.Create(demo, "http://localhost:8080/broadcast");
await reader.ReadAllAsync();
See the examples/ folder for more complete examples:
- Basic - Simple demo parsing
- MultiThreaded - Parallel processing for maximum performance
- PlayerPositions - Tracking player positions and movements
- HttpBroadcast - Parsing live HTTP broadcasts
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.