Skip to content

Commit

Permalink
Add support for L4D1 newest
Browse files Browse the repository at this point in the history
Co-authored-by: Willian Henrique <[email protected]>
  • Loading branch information
UncraftedName and SirWillian committed Jan 24, 2023
1 parent ce10544 commit 214f5fb
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
62 changes: 62 additions & 0 deletions DemoParser/src/Parser/Components/Abstract/UserMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,67 @@ public abstract class UserMessage : DemoComponent {
UserMessageType.CallVoteFailed
};

public static readonly IReadOnlyList<UserMessageType> L4D1SteamTable = new[]
{
UserMessageType.Geiger,
UserMessageType.Train,
UserMessageType.HudText,
UserMessageType.SayText,
UserMessageType.SayText2,
UserMessageType.TextMsg,
UserMessageType.HUDMsg,
UserMessageType.ResetHUD,
UserMessageType.GameTitle,
UserMessageType.ItemPickup,
UserMessageType.ShowMenu,
UserMessageType.Shake,
UserMessageType.Fade,
UserMessageType.VGUIMenu,
UserMessageType.Rumble,
UserMessageType.CloseCaption,
UserMessageType.CloseCaptionDirect,
UserMessageType.SendAudio,
UserMessageType.RawAudio,
UserMessageType.VoiceMask,
UserMessageType.RequestState,
UserMessageType.BarTime,
UserMessageType.Damage,
UserMessageType.RadioText,
UserMessageType.HintText,
UserMessageType.KeyHintText,
UserMessageType.ReloadEffect,
UserMessageType.PlayerAnimEvent,
UserMessageType.AmmoDenied,
UserMessageType.UpdateRadar,
UserMessageType.KillCam,
UserMessageType.MarkAchievement,
UserMessageType.Splatter,
UserMessageType.SplatterClear,
UserMessageType.MessageText,
UserMessageType.TransitionRestore,
UserMessageType.Spawn,
UserMessageType.CreditsLine,
UserMessageType.CreditsMsg,
UserMessageType.StatsCrawlMsg,
UserMessageType.StatsSkipState,
UserMessageType.ShowStats,
UserMessageType.MusicCmd,
UserMessageType.WitchBloodSplatter,
UserMessageType.AchievementEvent,
UserMessageType.PZDmgMsg,
UserMessageType.AllPlayersConnectedGameStarting,
UserMessageType.VoteRegistered,
UserMessageType.DisconnectToLobby,
UserMessageType.CallVoteFailed,
UserMessageType.SteamWeaponStatData,
UserMessageType.SPHapWeapEvent,
UserMessageType.HapDmg,
UserMessageType.HapPunch,
UserMessageType.HapSetDrag,
UserMessageType.HapSetConst,
UserMessageType.HapMeleeContact,
};

#endregion

protected UserMessage(SourceDemo? demoRef, byte value) : base(demoRef) {
Expand Down Expand Up @@ -477,6 +538,7 @@ public static class SvcUserMessageFactory {
UserMessageType.HapSetDrag => new HapSetDrag (dRef, val),
UserMessageType.HapPunch => new HapPunch (dRef, val),
UserMessageType.SPHapWeapEvent => new SpHapWeaponEvent (dRef, val),
UserMessageType.WitchBloodSplatter => new WitchBloodSplatter(dRef, val),
_ => null // I do a check for this so that I don't have to allocate the unknown type twice
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Numerics;
using DemoParser.Parser.Components.Abstract;
using DemoParser.Utils;
using DemoParser.Utils.BitStreams;

namespace DemoParser.Parser.Components.Messages.UserMessages {

public class WitchBloodSplatter : UserMessage {

public Vector3 Pos;


public WitchBloodSplatter(SourceDemo? demoRef, byte value) : base(demoRef, value) {}

protected override void Parse(ref BitStreamReader bsr) {
bsr.ReadVectorCoord(out Pos);
}

public override void PrettyWrite(IPrettyWriter pw) {
pw.Append($"pos: {Pos}");
}
}
}
21 changes: 16 additions & 5 deletions DemoParser/src/Parser/DemoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class DemoInfo {
[(3, 24)] = PORTAL_1_1910503,
[(4, 37)] = L4D1_1005,
[(4, 1040)] = L4D1_1040,
[(4, 1041)] = L4D1_1040,
[(4, 2000)] = L4D2_2000,
[(4, 2001)] = PORTAL_2,
[(4, 2012)] = L4D2_2012,
Expand All @@ -75,13 +76,19 @@ public class DemoInfo {
};


// here we try to figure out as many demo specific constants just from the header as we can
public DemoInfo(SourceDemo demo) {
DemoHeader h = demo.Header;

if (!GameLookup.TryGetValue((h.DemoProtocol, h.NetworkProtocol), out Game)) {
Game = UNKNOWN;
demo.LogError($"\nUnknown game, demo might not parse correctly. Update in {GetType().FullName}.\n");
demo.DemoParseResult |= DemoParseResult.UnknownGame;
// multiple L4D1 network protocols parse the same way, so keep support for them
if (h.DemoProtocol == 4 && h.NetworkProtocol >= 1030 && h.NetworkProtocol <= 1050) {
Game = L4D1_1040;
} else {
Game = UNKNOWN;
demo.LogError($"\nUnknown game, demo might not parse correctly. Update in {GetType().FullName}.\n");
demo.DemoParseResult |= DemoParseResult.UnknownGame;
}
}

// provide default values in case of unknown game
Expand Down Expand Up @@ -109,7 +116,11 @@ public DemoInfo(SourceDemo demo) {
} else if (IsLeft4Dead()) {
TickInterval = 1f / 30;
MaxSplitscreenPlayers = 4;
UserMessageTypes = IsLeft4Dead1() ? UserMessage.L4D1OldTable : UserMessage.L4D2SteamTable;
if (IsLeft4Dead1()) {
UserMessageTypes = Game >= L4D1_1040 ? UserMessage.L4D1SteamTable : UserMessage.L4D1OldTable;
} else {
UserMessageTypes = UserMessage.L4D2SteamTable;
}
PacketTypes = DemoPacket.DemoProtocol4Table;
}

Expand Down Expand Up @@ -222,7 +233,7 @@ public enum SourceGame {
PORTAL_2,

L4D1_1005,
L4D1_1040, // latest steam version
L4D1_1040, // 1032/1040/1041 version

L4D2_2000,
L4D2_2012,
Expand Down
Binary file added Tests/sample demos/l4d1 1041.dem
Binary file not shown.
1 change: 1 addition & 0 deletions Tests/src/DemoParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class DemoParseTests {

new TestCaseData("l4d1 37 v1005.dem").SetName("Left 4 Dead 1 (version 1.0.0.5)"),
new TestCaseData("l4d1 1040.dem").SetName("Left 4 Dead 1 (version 1.0.4.0)"),
new TestCaseData("l4d1 1041.dem").SetName("Left 4 Dead 1 (version 1.0.4.1)"),
new TestCaseData("l4d2 2000.dem").SetName("Left 4 Dead 2 (version 2.0.0.0)"),
new TestCaseData("l4d2 2012.dem").SetName("Left 4 Dead 2 (version 2.0.1.2)"),
new TestCaseData("l4d2 2027.dem").SetName("Left 4 Dead 2 (version 2.0.2.7)"),
Expand Down

0 comments on commit 214f5fb

Please sign in to comment.