Home

Awesome

DemoFile.Net NuGet Build status

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:

GameNuGet packageGetting started
Counter-Strike 2DemoFile.Game.Csnew CsDemoParser()
DeadlockDemoFile.Game.Deadlocknew 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.

Screenshot of DemoFile.Net

Easy discoverability of available data through your IDE's inbuilt autocompletion:

Features

FeatureAvailability
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

Examples

[!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.

Benchmarks

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).

MethodMeanErrorStdDevAllocated
ParseDemo1,294.6 ms3.68 ms2.88 ms491.48 MB
ParseDemoParallel540.1 ms23.99 ms22.44 ms600.67 MB

Author and acknowledgements

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:

A modified version of Source2Gen by neverlosecc is used to statically generate the game schema classes and enums.

See ACKNOWLEDGEMENTS for license information.