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

Demos broken with the latest update. #60

Closed xGuysOG closed 2 months ago

xGuysOG commented 2 months ago

Research

Description

The new update broke demos again. Here are some of the parsing errors:

  1. Exception: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'msgType') Actual value was DemMax.

  2. DemoFile.InvalidDemoException: Unexpected demo command: 81

Code to reproduce

public static class Program
{
    //public static string flashNoWork = "C:\\Users\\xguys\\Desktop\\Flash issues\\crystal_vulture.dem";
    public static string flashWork = "C:\\Users\\xguys\\Desktop\\demoinfo\\661577d64c197423489bdd0f_0_1714410167560.dem";

    public static async Task Main(string[] args)
    {
        try
        {
            Stopwatch stopwatch3 = new Stopwatch();
            stopwatch3.Start();
            MemoryStream _fileStream;
            byte[] _demoBytes;
            //_demoBytes = File.ReadAllBytes(demoFilePath);
            _demoBytes = await File.ReadAllBytesAsync(flashWork);
            _fileStream = new MemoryStream(_demoBytes);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var demo = new DemoParser();

            demo.Source1GameEvents.BombExploded += e =>
            {
                Console.WriteLine("Bomb exploded");
            };

            demo.Source1GameEvents.PlayerBlind += e =>
            {
                Console.WriteLine("Player blind");

            };

            demo.Source1GameEvents.TrPlayerFlashbanged += e =>
            {
                Console.WriteLine("Player flashbanged");
            };

            //demo.Source1GameEvents.FlashbangDetonate += e =>
            //{
            //    Console.WriteLine("Flashbang detonate");
            //};

            demo.Source1GameEvents.RoundStart += e =>
            {

                if (!demo.GameRules.HasMatchStarted)
                {
                    //PowerLigaManager.Log("ROund end called but we have an issue, it seems match was not started yet");
                    return;
                }
                Console.WriteLine("Round start called at round ct:" + demo.TeamCounterTerrorist.Score + " and t:" + demo.TeamTerrorist.Score);
                Debug.WriteLine("Round start called at round ct:" + demo.TeamCounterTerrorist.Score + " and t:" + demo.TeamTerrorist.Score);
            };

            demo.Source1GameEvents.CsWinPanelMatch += e =>
            {
                Console.WriteLine("WIn match has ended");
            };
            await demo.ReadAllAsync(_fileStream);
            stopwatch3.Stop();

            stopwatch.Stop();
            Console.WriteLine("Time elapsed after file data: {0}", stopwatch.Elapsed);
            Console.WriteLine("Time elapsed: {0}", stopwatch3.Elapsed);
            Console.WriteLine("\nFinished!");
        } catch (Exception e)
        { 
            Console.WriteLine("Exception: " + e.Message.ToString());
        }

        Console.ReadKey();
    }

Affected demos

https://drive.google.com/file/d/1xPpl-ZU_IljuPnEW3X-jKrm4-XRhiGk9/view?usp=sharing

saul commented 2 months ago

PR to fix here: https://github.com/saul/demofile-net/pull/61