Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Commit

Permalink
Implemented Instance-Baseline Parsing.
Browse files Browse the repository at this point in the history
#fancy.
  • Loading branch information
moritzuehling committed Nov 23, 2014
1 parent e61fc17 commit 9672e10
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
27 changes: 18 additions & 9 deletions DemoInfo/DP/Handler/CreateStringTableUserInfoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateStringTableUserInfoHandler : IMessageParser
public bool TryApplyMessage(IExtensible message, DemoParser parser)
{
var create = message as CSVCMsg_CreateStringTable;
if ((create == null) || (create.name != "userinfo"))
if ((create == null))
return false;

ParseStringTableUpdate(create, parser);
Expand All @@ -32,7 +32,6 @@ public void ParseStringTableUpdate(CSVCMsg_CreateStringTable table, DemoParser p
while ((nTemp >>= 1) != 0)
++nEntryBits;


List<string> history = new List<string>();

int lastEntry = -1;
Expand Down Expand Up @@ -70,6 +69,8 @@ public void ParseStringTableUpdate(CSVCMsg_CreateStringTable table, DemoParser p
if (entry == null)
entry = "";

history.Add(entry);

// Read in the user data.
byte[] userdata = new byte[0];
if (reader.ReadBit()) {
Expand All @@ -85,14 +86,22 @@ public void ParseStringTableUpdate(CSVCMsg_CreateStringTable table, DemoParser p
if (userdata.Length == 0)
break;

// Now we'll parse the players out of it.
BinaryReader playerReader = new BinaryReader(new MemoryStream(userdata));
PlayerInfo info = PlayerInfo.ParseFrom(playerReader);
if (table.name == "userinfo") {

// Now we'll parse the players out of it.
BinaryReader playerReader = new BinaryReader(new MemoryStream(userdata));
PlayerInfo info = PlayerInfo.ParseFrom(playerReader);

if (entryIndex < parser.RawPlayers.Count)
parser.RawPlayers[entryIndex] = info;
else
parser.RawPlayers.Add(info);
if (entryIndex < parser.RawPlayers.Count)
parser.RawPlayers[entryIndex] = info;
else
parser.RawPlayers.Add(info);

} else if (table.name == "instancebaseline") {
int classid = int.Parse(entry); //wtf volvo?

parser.instanceBaseline[classid] = userdata;

This comment has been minimized.

Copy link
@0BuRner

0BuRner Dec 5, 2014

Contributor

What's the purpose of instanceBaseline ?

This comment has been minimized.

Copy link
@moritzuehling

moritzuehling via email Dec 5, 2014

Author Contributor
}
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions DemoInfo/DP/Handler/PacketEntitesHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace DemoInfo.DP.Handler
{
Expand All @@ -27,13 +28,11 @@ public bool TryApplyMessage(ProtoBuf.IExtensible message, DemoParser parser)
// enter flag
if (reader.ReadBit()) {
var e = ReadEnterPVS(reader, currentEntity, parser);

e.ApplyUpdate(reader);
} else {
// preserve
Entity e = parser.entites[currentEntity];
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("Entity #" + e.ID + ": " + e.ServerClass.Name);
//Console.ResetColor();
e.ApplyUpdate(reader);
}
} else {
Expand Down Expand Up @@ -65,6 +64,13 @@ public Entity ReadEnterPVS(IBitStream reader, int id, DemoParser parser)

parser.entites[newEntity.ID] = newEntity;



MemoryStream ms = new MemoryStream(parser.instanceBaseline[serverClassID]);
ms.Seek(0, SeekOrigin.Begin);
newEntity.ApplyUpdate(BitStreamUtil.Create(ms));
ms.Close();

This comment has been minimized.

Copy link
@main--

main-- Nov 23, 2014

Contributor
using (var ms = new MemoryStream(parser.instanceBaseline[serverClassID])) {
    ms.Position = 0;
    newEntity.ApplyUpdate(BitStreamUtil.Create(ms));
}
  1. Beauty (obvious)
  2. Safety (using ensures correct disposal even if ApplyUpdate throws)
  3. It doesn't matter anyways because it's just a MemoryStream

return newEntity;
}

Expand Down
2 changes: 2 additions & 0 deletions DemoInfo/DemoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public string Map
internal List<Player> GEH_BlindPlayers = new List<Player>();
#endregion

internal Dictionary<int, byte[]> instanceBaseline = new Dictionary<int, byte[]>();

public float TickRate
{
get { return this.Header.PlaybackFrames / this.Header.PlaybackTime; }
Expand Down
23 changes: 13 additions & 10 deletions DemoInfo/ST/StringTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public void ParsePacket(Stream stream, DemoParser parser)
for (int i = 0; i < numTables; i++) {
string tableName = reader.ReadString();

ParseStringTable(reader, tableName == "userinfo", parser);
ParseStringTable(reader, tableName, parser);
}
}
}

public void ParseStringTable(IBitStream reader, bool isUserInfo, DemoParser parser)
{
if (isUserInfo)
parser.RawPlayers.Clear();
public void ParseStringTable(IBitStream reader, string tableName, DemoParser parser)
{
if (tableName == "userinfo")
parser.RawPlayers.Clear();

int numStrings = (int)reader.ReadInt(16);

Expand All @@ -43,12 +43,15 @@ public void ParseStringTable(IBitStream reader, bool isUserInfo, DemoParser pars

byte[] data = reader.ReadBytes(userDataSize);

if (isUserInfo && data.Length >= 340)
{
PlayerInfo info = PlayerInfo.ParseFrom(new BinaryReader(new MemoryStream(data)));
if (tableName == "userinfo") {
PlayerInfo info = PlayerInfo.ParseFrom(new BinaryReader(new MemoryStream(data)));

parser.RawPlayers.Add(info);
} else if (tableName == "instancebaseline") {
int classid = int.Parse(stringName); //wtf volvo?

parser.RawPlayers.Add(info);
}
parser.instanceBaseline[classid] = data;
}
}
}

Expand Down

0 comments on commit 9672e10

Please sign in to comment.