Skip to content

Commit

Permalink
Add barebones parsing and timing for Portal Revolution
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWillian committed Apr 21, 2024
1 parent 5a77a69 commit 11ab034
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ConsoleApp/src/DemoArgProcessing/DemoParserSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ private void EnableTimeOptionDefault(DemoParsingSetupInfo setupInfo) {
((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
SourceGame.L4D2_2203, SourceGame.PORTAL_1_3420, SourceGame.PORTAL_1_5135, SourceGame.PORTAL_1_1910503,
SourceGame.PORTAL_REVOLUTION
});
} else {
throw new ArgProcessProgrammerException("listdemo option not passed to demo sub-command.");
Expand Down
3 changes: 3 additions & 0 deletions DemoParser/src/Parser/Components/MessageStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public MessageStream(SourceDemo? demoRef) : base(demoRef) {}
protected override void Parse(ref BitStreamReader bsr) {
BitStreamReader mBsr = bsr.ForkAndSkip((int)(bsr.ReadUInt() * 8));
Messages = new List<DemoMessage>();
// not bothering with protobuf message parsing at all at the moment
// TODO: implement protobuf Some Day:tm:
if (DemoInfo.Game == SourceGame.PORTAL_REVOLUTION) return;
byte messageValue;
DemoMessage? demoMessage;
do {
Expand Down
41 changes: 35 additions & 6 deletions DemoParser/src/Parser/Components/Packets/DataTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,38 @@ protected override void Parse(ref BitStreamReader bsr) {
BitStreamReader dBsr = bsr.ForkAndSkip(bsr.ReadSInt() * 8);

Tables = new List<SendTable>();
while (dBsr.ReadBool() && !dBsr.HasOverflowed) {
var table = new SendTable(DemoRef);
Tables.Add(table);
table.ParseStream(ref dBsr);
if (DemoInfo.Game == SourceGame.PORTAL_REVOLUTION) {
while (!dBsr.HasOverflowed) {
var table = new SendTable(DemoRef);
Tables.Add(table);
// minimal protobuf parsing just to skip over the payloads
// there's a dummy table at the end of the list that indicates
// if we should stop parsing
uint type = dBsr.ReadVarUInt32(); // protobuf message type
int size = (int)dBsr.ReadVarUInt32(); // size of message
// coincidentally, the first message member is the one we are looking for (is_end member)
// it's an optional member but it's always set on the dummy final table
// every member begins with a tag byte formatted as (field_number << 3) | wire_type
// is_end has field_number 1 and wire_type 0
// if needed in the future, net_table_name has field number 2 and wire_type 2
int tag = dBsr.ReadByte();
if (tag != (1 << 3)) {
dBsr.SkipBytes(size - 1);
continue;
}
byte is_end = dBsr.ReadByte();
dBsr.SkipBytes(size - 2);
if (is_end == 1) {
break;
}
}
}
else {
while (dBsr.ReadBool() && !dBsr.HasOverflowed) {
var table = new SendTable(DemoRef);
Tables.Add(table);
table.ParseStream(ref dBsr);
}
}

ushort classCount = dBsr.ReadUShort();
Expand All @@ -129,7 +157,8 @@ protected override void Parse(ref BitStreamReader bsr) {

// create the prop list for each class
GameState.DataTablesManager = new DataTablesManager(DemoRef!, this);
GameState.DataTablesManager.FlattenClasses(true);
if (DemoInfo.Game != SourceGame.PORTAL_REVOLUTION)
GameState.DataTablesManager.FlattenClasses(true);
}


Expand Down Expand Up @@ -191,7 +220,7 @@ protected override void Parse(ref BitStreamReader bsr) {

public override void PrettyWrite(IPrettyWriter pw) {
pw.Append($"{Name}{(NeedsDecoder ? "*" : "")} (");
if (SendProps.Count > 0) {
if (SendProps?.Count > 0) {
pw.Append($"{SendProps.Count} prop{(SendProps.Count > 1 ? "s" : "")}):");
pw.FutureIndent++;
foreach (SendTableProp sendProp in SendProps) {
Expand Down
7 changes: 6 additions & 1 deletion DemoParser/src/Parser/DemoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class DemoInfo {
[(4, 2027)] = L4D2_2027,
[(4, 2042)] = L4D2_2042,
[(4, 2100)] = L4D2_2203,
[(4, 13703)] = PORTAL_REVOLUTION,
};


Expand Down Expand Up @@ -106,7 +107,7 @@ public DemoInfo(SourceDemo demo) {
UserMessageTypes = UserMessage.Portal5135Table;
else
UserMessageTypes = UserMessage.Portal1SteamTable;
} else if (Game == PORTAL_2 || (Game == UNKNOWN && h.DemoProtocol == 4)) {
} else if (Game == PORTAL_2 || Game == PORTAL_REVOLUTION || (Game == UNKNOWN && h.DemoProtocol == 4)) {
TickInterval = 1f / 60;
MaxSplitscreenPlayers = 2;
if (Game == PORTAL_2)
Expand Down Expand Up @@ -253,6 +254,10 @@ public enum SourceGame {
L4D2_2091, // 2042 protocol, version 2091 (yes, same protocol version, but has to be distinguished)
L4D2_2147, // 2042 protocol, version 2147 (yet again, has to be distinguished without any protocol version indicating that)
L4D2_2203, // 2100 protocol, version 2203. compatible with latest steam version (2220)

// Strata Source games
PORTAL_REVOLUTION,

UNKNOWN
}
}
20 changes: 20 additions & 0 deletions DemoParser/src/Parser/TimingAdjustment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public static IReadOnlyList<AdjustmentType> AdjustmentTypeFromMap(string mapName
return new[] {Portal2CoopMapStart, Portal2CoopMapEnd};
}
break;
case PORTAL_REVOLUTION:
switch(mapName) {
case "sp_a1_begin":
return new[] {PortalRevolutionBegin};
case "sp_a4_finale":
return new[] {PortalRevolutionEnd};
}
break;
case L4D1_1005:
case L4D1_1040:
case L4D2_2000:
Expand Down Expand Up @@ -262,6 +270,7 @@ public static void AdjustFromPacket(Packet packet) {
return;
case L4DBegin when L4DControlGainCheck(packet):
case Portal2CoopBegin when !start.HasValue && Portal2CoopStartCheck(packet):
case PortalRevolutionBegin when !start.HasValue && PortalRevolutionStartCheck(packet):
start = packet.Tick;
return;
case Portal1GenericWakeup when Portal1WakeupCheck(packet):
Expand All @@ -280,6 +289,7 @@ public static void AdjustFromPacket(Packet packet) {
end = packet.Tick + 1;
return;
case Portal2End when Portal2PortalOnMoon(packet):
case PortalRevolutionEnd when !end.HasValue && PortalRevolutionEndCheck(packet):
case L4DEnd when L4DEscapeTriggeredCheck(packet):
end = packet.Tick;
return;
Expand Down Expand Up @@ -314,6 +324,13 @@ private static bool Portal2CoopStartCheck(Packet packet) {
packet.PacketInfo[0].ViewOrigin == new Vector3(-11168f, -4384f, 3040.03125f);
}

private static bool PortalRevolutionStartCheck(Packet packet) {
return packet.PacketInfo[0].ViewOrigin == new Vector3(-1891.20654f, 1322.52161f, 128.03125f);
}

private static bool PortalRevolutionEndCheck(Packet packet) {
return packet.PacketInfo[0].ViewOrigin == new Vector3(1216f, 1152f, 512f);
}

private static bool Portal1VanillaWakeupCheck(Packet packet) {
return packet.FilterForMessage<SvcFixAngle>()
Expand Down Expand Up @@ -475,6 +492,9 @@ public enum AdjustmentType {
Portal2CoopEnd,
Portal2CoopEndCourse6,

PortalRevolutionBegin,
PortalRevolutionEnd,

TfvEnd,
RexauraEnd,
Portal1GenericWakeup,
Expand Down

0 comments on commit 11ab034

Please sign in to comment.