-
Research
DescriptionGameRule "HasMatchStarted" turns to false before match has really ended. As you can see in my debugs the last round end is called after, so is win match. and while i can create my own method to check this, i feel like it should be fixed in the main Lib. Debugs from the code: Finished! Code to reproducepublic static class Program
{
//public static string flashNoWork = "C:\\Users\\xguys\\Desktop\\Flash issues\\crystal_vulture.dem";
public static string flashWork = "C:\\Users\\xguys\\Desktop\\demTest\\661577d74c197423489bdd75_0_1717614880949.dem";
public static async Task Main(string[] args)
{
Console.WriteLine("Starting the Socket Client...");
//SocketClient client = new SocketClient();
//// Initialize and connect the client
//await client.InitializeConnection();
//Console.WriteLine("Press any key to exit...");
//Console.ReadKey();
//return;
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.EntityEvents.CCSGameRulesProxy.AddChangeCallback(proxy => proxy.GameRules?.RoundEndCount, (proxy, _, _) =>
{
if (!demo.GameRules.HasMatchStarted)
{
Console.WriteLine("ROund end called but we have an issue, it seems match was not started yet");
return;
}
Console.WriteLine("Round End called at round ct:" + demo.TeamCounterTerrorist.Score + " and t:" + demo.TeamTerrorist.Score);
});
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.RoundEnd += e =>
{
if (!demo.GameRules.HasMatchStarted)
{
Console.WriteLine("ROund end called but we have an issue, it seems match was not started yet ct:" + demo.TeamCounterTerrorist.Score + " and t: " + demo.TeamTerrorist.Score);
return;
}
// Convert the integer to the corresponding enum value
CSRoundEndReason reasonEnum = (CSRoundEndReason)e.Reason;
// Convert the enum value to its string representation
string reasonString = reasonEnum.ToString();
CSTeamNumber winnerEnum = (CSTeamNumber)e.Winner;
string winnerString = winnerEnum.ToString();
Console.WriteLine("Round end called at round ct:" + demo.TeamCounterTerrorist.Score +
" and t:" + demo.TeamTerrorist.Score +
" winner? " + winnerString +
" Reason " + reasonString +
" message " + e.Message);
Debug.WriteLine("Round end called at round ct:" + demo.TeamCounterTerrorist.Score +
" and t:" + demo.TeamTerrorist.Score +
" winner? " + winnerString +
" Reason " + reasonString +
" message " + e.Message);
};
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 demoshttps://drive.google.com/file/d/1kmBKcxTRMJMc9kcLWSC9-8Q2ZBP4EQvd/view?usp=sharing |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Does HasMatchEnded change to false and the RoundEnd event fire on the same tick? If so, this is expected. On any given tick, entity properties (including game rules) change before events are fired. As the library is just exposing the data in the demo file itself, I'm not too keen to add workarounds to the core. |
Beta Was this translation helpful? Give feedback.
-
There sadly is no "HasMatchEnded" in the gamerules, i did some tick tests and you are correct it happens on the same tick. How annoying, since i use "HasMatchStarted" to know if i should track stats or not track stats. I guess id have to make a check on round start, and see if the next round might be the last round, and track the stats that way. Unless there is a better way then to track"HasMatchStarted"? |
Beta Was this translation helpful? Give feedback.
-
This is not a problem of the library, this is simply the way how server updates
Yes, there is an equivalent : However, you don't need that. The proper way to detect if match has started would be something like this : bool hasMatchEverStarted = false;
demo.EntityEvents.CCSGameRulesProxy.AddChangeCallback(proxy => proxy.GameRules?.HasMatchStarted, (proxy, _, _) =>
{
hasMatchEverStarted |= demo.GameRules.HasMatchStarted;
}); |
Beta Was this translation helpful? Give feedback.
This is not a problem of the library, this is simply the way how server updates
GameRules
entity properties.Yes, there is an equivalent :
GameRules.GamePhase
==CSGamePhase.MatchEnded
.However, you don't need that. The proper way to detect if match has started would be something like this :