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

Incorrect round results #50

Closed in0finite closed 3 months ago

in0finite commented 4 months ago

Research

Description

Some demos are reporting wrong round results.

Both RoundEnd event and GameRules.CSRoundResults give the same result, but that result doesn't match the one from HLTV.

Example : (map Vertigo) https://www.hltv.org/matches/2369946/ence-vs-astralis-pgl-cs2-major-copenhagen-2024-europe-rmr-b official : 13 - 6 parser : 10 - 9

Code to reproduce

var path = "test.dem";

var demo = new DemoParser();

var winnerCounts = new Dictionary<int, int>();

demo.Source1GameEvents.RoundEnd += e =>
{
    Console.WriteLine($"Round end: winner {(CSTeamNumber)e.Winner}");

    if (winnerCounts.TryGetValue(e.Winner, out int count))
        winnerCounts[e.Winner] = count + 1;
    else
        winnerCounts[e.Winner] = 1;
};

await demo.StartReadingAsync(File.OpenRead(path), default);

while (await demo.MoveNextAsync(default))
{
}

Console.WriteLine();

foreach (var pair in winnerCounts)
{
    Console.WriteLine($"winner {pair.Key}: {pair.Value}");
}

Console.WriteLine();
Console.WriteLine("Game rules round results:");
Console.WriteLine(string.Join("\n", demo.GameRules.CSRoundResults));

Console.WriteLine("\nFinished!");

Affected demos

No response

laPeregrin commented 3 months ago

Your algorithm of tracking rounds wrong, i think. In second phase every team swap his sides, defender to protector. So you have for example 6 wins by ct and 3wins by t, after swap t won but you track this win to wrong team cuz you re not to swap wins. All gona work if you swap winners score when become second phase.

in0finite commented 3 months ago

Thank you very much. I totally forgot about team switching. Should be using CTeam.Score property.