saul / demofile-net

Blazing fast cross-platform demo parser library for Counter-Strike 2 and Valve's Deadlock, written in C#.
MIT License
111 stars 10 forks source link

Anyone else having trouble getting the TickByTick example working? #106

Closed Theoya closed 1 month ago

Theoya commented 1 month ago

Research

Description

Running it with the 14005.dem file, and just getting empty.

I've been able to somewhat parse it with the Basic example, but not the tick example

Code to reproduce

private async void ReadCSFile(string path = "C:\\Users\\taylo\\CSDeadlockDemofileReader\\CSDeadlockParser\\CSDeadlockParser\\DemoFiles\\14005.dem")
    {
        Console.WriteLine("Reading file...");
        var demo = new CsDemoParser();

        // Define the output file path
        string outputPath = "C:\\Users\\taylo\\CSDeadlockDemofileReader\\CSDeadlockParser\\CSDeadlockParser\\Output\\output.txt";

        // Create a StreamWriter to write to the output file
        using StreamWriter writer = new StreamWriter(outputPath);

        demo.Source1GameEvents.BulletImpact += e =>
        {
            Console.WriteLine($"{e.Player?.PlayerName} {e.PlayerPawn.Weapons}");
        };

        demo.Source1GameEvents.PlayerDeath += e =>
        {
            Console.WriteLine($"{e.Attacker?.PlayerName} [{e.Weapon}] {e.Player?.PlayerName}");
        };

        demo.Source1GameEvents.GameStart += e =>
        {
            if (e != null)
            {
                Console.WriteLine($"{e}");
            }
        };

        // Read 20 minutes of gameplay before stopping
        var readUntilTicks = DemoTick.Zero + TimeSpan.FromMinutes(20);

        var reader = DemoFileReader.Create(demo, File.OpenRead(path));
        await reader.StartReadingAsync(default(CancellationToken));
        while (demo.CurrentDemoTick < readUntilTicks)
        {
            if (!await reader.MoveNextAsync(default(CancellationToken)))
            {
                // We've reached the end of the demo file
                break;
            }
        }

        Console.WriteLine("File written...");
    }

Affected demos

14005.dem

saul commented 1 month ago

The demo is 453 KB, it's just used by the integration tests to ensure that backwards compatibility with older demos is not broken.

Instead can I suggest downloading a proper match demo from hltv.org and testing your code with that? You should see more output.

Theoya commented 1 month ago

Awesome, thanks for that man I appreciate it. Ill get on it