From 3200691a06f7f5414d4b78e9c6f646ccb556fc9f Mon Sep 17 00:00:00 2001 From: UncraftedName Date: Tue, 20 Jun 2023 09:32:24 -0700 Subject: [PATCH] Add portal count to --time option --- .../src/DemoArgProcessing/Options/OptTime.cs | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs b/ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs index 1fee743..5186c17 100644 --- a/ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs +++ b/ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs @@ -8,6 +8,7 @@ using DemoParser.Parser; using DemoParser.Parser.Components; using DemoParser.Parser.Components.Messages; +using DemoParser.Parser.Components.Messages.UserMessages; using DemoParser.Parser.EntityStuff; using DemoParser.Utils; using static System.Text.RegularExpressions.RegexOptions; @@ -196,12 +197,13 @@ public static void WriteAdjustedTime(SourceDemo demo, TextWriter tw, bool timeFi tw.WriteLine($"{"Measured time ",FmtIdt}: {Utils.FormatTime(demo.TickCount(tfs) * tickInterval)}"); tw.WriteLine($"{"Measured ticks ",FmtIdt}: {demo.TickCount(tfs)}"); - if ((demo.DemoParseResult & DemoParseResult.EntParsingFailed) != 0) { + /*if ((demo.DemoParseResult & DemoParseResult.EntParsingFailed) != 0) { Utils.PushForegroundColor(ConsoleColor.Red); - tw.Write($"{"CM time ",FmtIdt}: INVALID"); + tw.WriteLine($"{"CM time ",FmtIdt}: UNKNOWN"); + tw.WriteLine($"{"Portal count ",FmtIdt}: UNKNOWN"); Utils.PopForegroundColor(); - } else { - var cmTimes = demo.FilterForMessage() + } else*/ { + /*var cmTimes = demo.FilterForMessage() .SelectMany(tuple => tuple.message.Updates!) .OfType() .Where(delta => delta.EntIndex == 1) @@ -209,12 +211,44 @@ public static void WriteAdjustedTime(SourceDemo demo, TextWriter tw, bool timeFi .Select(tuple => tuple.prop) .OfType>() .Where(prop => prop.Name == "m_StatsThisLevel.fNumSecondsTaken") - .Select(prop => prop.Value); + .Select(prop => prop.Value);*/ - float cmTime = cmTimes.LastOrDefault(-666); + // float cmTime = cmTimes.LastOrDefault(-666); - if (Math.Abs(cmTime - demo.TickCount(false) * tickInterval) < 2) - tw.Write($"{"CM time ",FmtIdt}: {Utils.FormatTime(cmTime)}"); + var cmTime = demo.FilterForUserMessage() + .Select(tuple => tuple.userMessage.TimeTaken).LastOrDefault(-666) / 100f; + + tw.WriteLine($"{"CM time ",FmtIdt}: {Utils.FormatTime(cmTime)}"); + tw.WriteLine($"{"CM ticks ",FmtIdt}: {(int)Math.Round(cmTime / tickInterval)}"); + + var numPortals = demo.FilterForUserMessage() + .Select(tuple => tuple.userMessage.NumPortals).LastOrDefault(-1); + + tw.WriteLine($"{"Portal count ",FmtIdt}: {numPortals}"); + + /*int numPortalsSelf = demo.FilterForMessage() + .SelectMany(tuple => tuple.message.Updates!) + .OfType() + .Where(delta => delta.EntIndex == 1) + .SelectMany(delta => delta.Props) + .Select(tuple => tuple.prop) + .OfType>() + .Where(prop => prop.Name == "m_StatsThisLevel.iNumPortalsPlaced") + .Select(prop => prop.Value) + .LastOrDefault(0); + + int numPortalsAll = demo.FilterForMessage() + .SelectMany(tuple => tuple.message.Updates!) + .OfType() + .Where(delta => delta.ServerClass!.ClassName == "CPortalMPGameRulesProxy") + .SelectMany(delta => delta.Props) + .Select(tuple => tuple.prop) + .OfType>() + .Where(prop => prop.Name == "portalmp_gamerules_data.m_nNumPortalsPlaced") + .Select(prop => prop.Value) + .LastOrDefault(0); + + tw.WriteLine($"{"Portal count ",FmtIdt}: {Math.Max(numPortalsSelf, numPortalsAll)}");*/ } if (demo.TickCount(tfs) != demo.AdjustedTickCount(tfs)) {