百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

demofile-net

> 编程语言
开源

一个极其快速的跨平台演示解析库,用于《反恐精英 2》和 Valve 的《死锁》,采用 C# 编写。

182 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个极其快速的跨平台演示解析库,用于《反恐精英 2》和 Valve 的《死锁》,采用 C# 编写。

DemoFile.Net

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:

Features

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

Getting Started

Installation

Add the appropriate NuGet package to your project:

bash
# For Counter-Strike 2
dotnet add package DemoFile.Game.Cs

# For Deadlock
dotnet add package DemoFile.Game.Deadlock

Basic Usage

Here's a simple example that prints kill feed information from a CS2 demo:

csharp
using DemoFile;

internal class Program
{
    public static async Task Main(string[] args)
    {
        var path = args.SingleOrDefault() ?? throw new Exception("Expected a single argument: ");

        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!");
    }
}

Advanced Examples

Tracking Player Positions

You can track player positions and other entity data throughout the demo:

csharp
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();

Working with Game Events

DemoFile.Net provides strongly-typed access to game events:

csharp
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();

Parallel Processing for Maximum Performance

For maximum performance, parse demos in parallel using multiple CPU cores:

csharp
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

HTTP Broadcast Support

DemoFile.Net can parse live HTTP broadcasts:

csharp
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

Benchmarks

DemoFile.Net can read a full competitive game (just under 1 hour of game time) in under a second. When parsing across multiple threads, using the ReadAllParallelAsync method, this drops to 353 milliseconds. This includes parsing all entity data (player positions, velocities, weapon tracking, grenades, etc).

Apple M1 Pro, 1 CPU, 10 logical and 10 physical cores .NET 10.0.0 (10.0.25.52411), Arm64 RyuJIT AdvSIMD

Method Mean Gen0 Gen1 Gen2 Allocated
ParseDemo 903.0 ms 88000.0000 1000.0000 - 597.58 MB
ParseDemoParallel 353.2 ms 104000.0000 15000.0000 1000.0000 690.59 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:

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言