Skip to content

Commit

Permalink
Fix p1 4104 and individual demos not timing with tick 0
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Oct 10, 2024
1 parent c801c82 commit be79ca1
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 75 deletions.
6 changes: 1 addition & 5 deletions ConsoleApp/src/DemoArgProcessing/DemoParserSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ private void EnableTimeOptionDefault(DemoParsingSetupInfo setupInfo) {
// Due to the portal community's love for hundreds of saveloads, the time option will time w/ first tick by default
// for p1 and l4d (because hindsight or something). This is a hack for now and will hopefully by improved with a
// more advanced timing system in the utopian future.
((OptTime)option).SetForceFirstTickTiming(new[] {
SourceGame.L4D1_1005, SourceGame.L4D1_1040, SourceGame.L4D2_2000, SourceGame.L4D2_2011,
SourceGame.L4D2_2012, SourceGame.L4D2_2027, SourceGame.L4D2_2042, SourceGame.L4D2_2091, SourceGame.L4D2_2147,
SourceGame.L4D2_2203, SourceGame.PORTAL_1_3420, SourceGame.PORTAL_1_5135, SourceGame.PORTAL_1_1910503
});
((OptTime)option).SetForceFirstTickTiming((SourceGame game) => game.IsPortal1() || game.IsLeft4Dead());
} else {
throw new ArgProcessProgrammerException("listdemo option not passed to demo sub-command.");
}
Expand Down
26 changes: 10 additions & 16 deletions ConsoleApp/src/DemoArgProcessing/Options/OptTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public class OptTime : DemoOption<OptTime.TimeFlags> {

private const int FmtIdt = -25;

// a hack to allow only p1 & l4d to time w/ first tick
private ISet<SourceGame> _forceFirstTickTiming = null!;


[Flags]
public enum TimeFlags {
Expand Down Expand Up @@ -51,7 +48,6 @@ public OptTime() : base(
public override void Reset() {
base.Reset();
_sdt = null!;
_forceFirstTickTiming = new HashSet<SourceGame>();
}


Expand All @@ -71,7 +67,7 @@ protected override void Process(DemoParsingInfo infoObj, TimeFlags arg, bool isD
WriteAdjustedTime(
infoObj.CurrentDemo,
Console.Out,
(arg & TimeFlags.TimeFirstTick) != 0 || _forceFirstTickTiming.Contains(infoObj.CurrentDemo.DemoInfo.Game)
(arg & TimeFlags.TimeFirstTick) != 0 || _sdt.TimeFirstTick
);
Console.WriteLine();
}
Expand Down Expand Up @@ -207,15 +203,15 @@ public static void WriteAdjustedTime(SourceDemo demo, TextWriter tw, bool timeFi
tw.WriteLine($"{"Measured ticks ",FmtIdt}: {demo.TickCount(tfs)}");

// hack before we implement proper timing strategies
if (demo.DemoInfo.IsLeft4Dead1() && demo.SequenceType == TimingAdjustment.SequenceType.SingleDemo && demo.StartAdjustmentTick.HasValue) {
if (demo.DemoInfo.Game.IsLeft4Dead1() && demo.SequenceType == TimingAdjustment.SequenceType.SingleDemo && demo.StartAdjustmentTick.HasValue) {
// all maps except finales will have a map_transition event at the end if the map was completed
(var gameEvent, int? endTick) = demo.FilterForMessage<SvcGameEvent>().FirstOrDefault(ev => ev.message.EventDescription!.Name == "map_transition");

// assume it's a finale if we don't find a map_transition event and copy the end adjustment tick
if (gameEvent == null)
endTick = demo.EndAdjustmentTick;
if (endTick.HasValue) {
int mapTime = endTick.Value - demo.StartAdjustmentTick.Value + 1;
int mapTime = endTick!.Value - demo.StartAdjustmentTick.Value + 1;
tw.WriteLine($"{"Individual Map time ",FmtIdt}: {Utils.FormatTime(mapTime * tickInterval)}");
tw.Write($"{"Individual Map ticks ",FmtIdt}: {mapTime}");
tw.WriteLine($" ({demo.StartAdjustmentTick}-{endTick})");
Expand All @@ -229,7 +225,7 @@ public static void WriteAdjustedTime(SourceDemo demo, TextWriter tw, bool timeFi
}

// another hack until we time things better :)
if (demo.DemoInfo.IsPortal2()) {
if (demo.DemoInfo.Game.IsPortal2()) {
ScoreboardTempUpdate? lastScoreBoard =
demo.FilterForUserMessage<ScoreboardTempUpdate>()
.Select(tuple => tuple.userMessage)
Expand All @@ -249,10 +245,8 @@ public static void WriteAdjustedTime(SourceDemo demo, TextWriter tw, bool timeFi


// a hack to allow only p1 & l4d to time w/ first tick
internal void SetForceFirstTickTiming(IEnumerable<SourceGame> games) {
var gameSet = games.ToImmutableHashSet();
_forceFirstTickTiming = gameSet;
_sdt.SetForceFirstTickTiming(gameSet);
internal void SetForceFirstTickTiming(Predicate<SourceGame> pred) {
_sdt.SetForceFirstTickTiming(pred);
}
}

Expand Down Expand Up @@ -286,14 +280,14 @@ public SimpleDemoInfo(SourceDemo demo) {

// a hack to allow only p1 & l4d to time w/ first tick
private SourceDemo _curDemo = null!;
private ISet<SourceGame> _forceFirstTickTiming;
public bool TimeFirstTick => _timeFirstTick || _forceFirstTickTiming.Contains(_curDemo.DemoInfo.Game);
private Predicate<SourceGame> _forceFirstTickTiming;
public bool TimeFirstTick => _timeFirstTick || _forceFirstTickTiming(_curDemo.DemoInfo.Game);


public SimpleDemoTimer(bool timeFirstTick) {
_timeFirstTick = timeFirstTick;
ValidFlags = Flags.TotalTimeValid | Flags.AdjustedTimeValid;
_forceFirstTickTiming = new HashSet<SourceGame>();
_forceFirstTickTiming = (SourceGame) => false;
_simpleDemoDifferences = new HashSet<string>();
}

Expand All @@ -304,7 +298,7 @@ public SimpleDemoTimer(IEnumerable<SourceDemo> demos, bool timeFirstTick) : this
}


internal void SetForceFirstTickTiming(IEnumerable<SourceGame> games) => _forceFirstTickTiming = games.ToImmutableHashSet();
internal void SetForceFirstTickTiming(Predicate<SourceGame> pred) => _forceFirstTickTiming = pred;


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override void Parse(ref BitStreamReader bsr) {
TableName = bsr.ReadNullTerminatedString();
MaxEntries = (short)bsr.ReadUShort();
NumEntries = (int)bsr.ReadUInt(ParserUtils.HighestBitIndex((uint)MaxEntries) + 1);
uint dataLen = bsr.ReadUInt(DemoInfo.IsLeft4Dead2() ? 21 : 20);
uint dataLen = bsr.ReadUInt(DemoInfo.Game.IsLeft4Dead2() ? 21 : 20);
UserDataFixedSize = bsr.ReadBool();
UserDataSize = (int)(UserDataFixedSize ? bsr.ReadUInt(12) : 0);
UserDataSizeBits = (int)(UserDataFixedSize ? bsr.ReadUInt(4) : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override void Parse(ref BitStreamReader bsr) {
Updates.Add(update);
};
if (IsDelta) {
if (DemoInfo.IsLeft4Dead2() && DemoInfo.Game >= SourceGame.L4D2_2091) {
if (DemoInfo.Game.IsLeft4Dead2() && DemoInfo.Game >= SourceGame.L4D2_2091) {
idx = -1;
uint deletionCount = entBsr.ReadUBitInt();
for (int i = 0; i < deletionCount; i++) {
Expand Down
2 changes: 1 addition & 1 deletion DemoParser/src/Parser/Components/Messages/SvcPrefetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SvcPrefetch(SourceDemo? demoRef, byte value) : base(demoRef, value) {}


protected override void Parse(ref BitStreamReader bsr) {
var soundIndexBits = DemoInfo.IsLeft4Dead2() ? DemoInfo.Game >= SourceGame.L4D2_2091 ? 15 : 14 : 13;
var soundIndexBits = DemoInfo.Game.IsLeft4Dead2() ? DemoInfo.Game >= SourceGame.L4D2_2091 ? 15 : 14 : 13;
SoundIndex = (int)bsr.ReadUInt(soundIndexBits);

var mgr = GameState.StringTablesManager;
Expand Down
4 changes: 2 additions & 2 deletions DemoParser/src/Parser/Components/Messages/SvcServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void Parse(ref BitStreamReader bsr) {
ServerCount = bsr.ReadUInt();
IsHltv = bsr.ReadBool();
IsDedicated = bsr.ReadBool();
if (DemoInfo.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
if (DemoInfo.Game.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
RestrictWorkshopAddons = bsr.ReadBool();
ClientCrc = bsr.ReadSInt();
if (DemoInfo.NewDemoProtocol)
Expand All @@ -61,7 +61,7 @@ protected override void Parse(ref BitStreamReader bsr) {
MapName = bsr.ReadNullTerminatedString();
SkyName = bsr.ReadNullTerminatedString();
HostName = bsr.ReadNullTerminatedString();
if (DemoInfo.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
if (DemoInfo.Game.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
{
MissionName = bsr.ReadNullTerminatedString();
MutationName = bsr.ReadNullTerminatedString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void Parse(ref BitStreamReader bsr) {
EntryCount = bsr.ReadByte();
uint bitLen = DemoInfo.Game is SourceGame.PORTAL_1_1910503 or SourceGame.TF2
? bsr.ReadVarUInt32()
: bsr.ReadUInt(DemoInfo.IsLeft4Dead2() ? 18 : 17);
: bsr.ReadUInt(DemoInfo.Game.IsLeft4Dead2() ? 18 : 17);
_data = bsr.ForkAndSkip((int)bitLen);

// todo
Expand Down
2 changes: 1 addition & 1 deletion DemoParser/src/Parser/Components/Messages/SvcVoiceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override void Parse(ref BitStreamReader bsr) {
FromClient = bsr.ReadByte();
Proximity = bsr.ReadByte() != 0;
BitLen = bsr.ReadUShort();
if (DemoRef.DemoInfo.IsLeft4Dead()) {
if (DemoRef.DemoInfo.Game.IsLeft4Dead()) {
Unknown = new bool[4];
for (int i = 0; i < 4; i++)
Unknown[i] = bsr.ReadBool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PlayerInfo(SourceDemo? demoRef, int? decompressedIndex = null) : base(dem

// we're reading a player_info_t, so take alignment into account
protected override void Parse(ref BitStreamReader bsr) {
if (DemoInfo.NewDemoProtocol && !DemoInfo.IsLeft4Dead1())
if (DemoInfo.NewDemoProtocol && !DemoInfo.Game.IsLeft4Dead1())
SteamId = (CSteamId)bsr.ReadULong();
Name = bsr.ReadStringOfLength(MaxPlayerNameLength);
UserId = bsr.ReadSInt();
Expand Down
Loading

0 comments on commit be79ca1

Please sign in to comment.