saul / demofile-net

Blazing fast cross-platform demo parser library for Counter-Strike 2, written in C#.
MIT License
76 stars 7 forks source link

CDemoFileInfo command is not invoked #26

Closed in0finite closed 6 months ago

in0finite commented 6 months ago

Research

Description

I was trying to get total duration (total tick count) of demo file, and found that CDemoFileInfo demo command has this info.

However, this command is never invoked. I am not sure if this is a bug in the library, or the command is simply not in demo file.

Anyway, is there any way to find out total duration of the match (without parsing entire file) ?

Code to reproduce

var demo = new DemoParser();
demo.DemoEvents.DemoFileInfo += (info) => Console.WriteLine("got DemoFileInfo");
await demo.Start(stream, default);

Affected demos

No response

saul commented 6 months ago

I don't believe this event is recorded in CS2 demos.

You'd have to read the whole file, keeping track of the last demo tick. Divide the ticks by 64 and you have the number seconds elapsed through the recording.

If you're really looking for speed, you can null out the PacketEntities parsing, which is the bulk of the parsing time. For example:

var demo = new DemoParser();
demo.PacketEvents.SvcPacketEntities = null;
await demo.Start(File.OpenRead(path));
var duration = demo.CurrentDemoTick.Value / 64.0f;
Console.WriteLine($"Demo is {duration:N1} secs long");
in0finite commented 6 months ago

Actually, I heard that CDemoFileInfo does exist, and it's located after DemStop command. Apparently, there is an offset to it in CDemoFileHeader. It doesn't make much sense ...

saul commented 6 months ago

You're right. PR for this here: https://github.com/saul/demofile-net/pull/31