Skip to content

Commit

Permalink
Add portal count to --time option
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Jun 23, 2023
1 parent dbc2e0a commit 3200691
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,25 +197,58 @@ 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<SvcPacketEntities>()
} else*/ {
/*var cmTimes = demo.FilterForMessage<SvcPacketEntities>()
.SelectMany(tuple => tuple.message.Updates!)
.OfType<Delta>()
.Where(delta => delta.EntIndex == 1)
.SelectMany(delta => delta.Props)
.Select(tuple => tuple.prop)
.OfType<SingleEntProp<float>>()
.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<ScoreboardTempUpdate>()
.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<ScoreboardTempUpdate>()
.Select(tuple => tuple.userMessage.NumPortals).LastOrDefault(-1);

tw.WriteLine($"{"Portal count ",FmtIdt}: {numPortals}");

/*int numPortalsSelf = demo.FilterForMessage<SvcPacketEntities>()
.SelectMany(tuple => tuple.message.Updates!)
.OfType<Delta>()
.Where(delta => delta.EntIndex == 1)
.SelectMany(delta => delta.Props)
.Select(tuple => tuple.prop)
.OfType<SingleEntProp<int>>()
.Where(prop => prop.Name == "m_StatsThisLevel.iNumPortalsPlaced")
.Select(prop => prop.Value)
.LastOrDefault(0);
int numPortalsAll = demo.FilterForMessage<SvcPacketEntities>()
.SelectMany(tuple => tuple.message.Updates!)
.OfType<Delta>()
.Where(delta => delta.ServerClass!.ClassName == "CPortalMPGameRulesProxy")
.SelectMany(delta => delta.Props)
.Select(tuple => tuple.prop)
.OfType<SingleEntProp<int>>()
.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)) {
Expand Down

0 comments on commit 3200691

Please sign in to comment.