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

Commit 2523b23

Browse files
committed
Merge remote-tracking branch 'origin' into headerfix
Conflicts: DemoInfo/Events.cs
2 parents 68bc538 + 3d28ea9 commit 2523b23

File tree

15 files changed

+509
-200
lines changed

15 files changed

+509
-200
lines changed

DemoInfo/BitStream/UnsafeBitStream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private void RefillBuffer()
107107
* as we overran the stream and wanna hit the throw above.
108108
*/
109109
Offset -= BitsInBuffer + 1;
110+
LazyGlobalPosition += BitsInBuffer + 1;
110111
*(uint*)PBuffer = 0; // safety
111112
BitsInBuffer = 0;
112113
continue;

DemoInfo/DP/DemoPacketParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using DemoInfo.DP.FastNetmessages;
910

1011
namespace DemoInfo.DP
1112
{
@@ -47,6 +48,8 @@ public static void ParsePacket(IBitStream bitstream, DemoParser demo)
4748
new ServerInfo().Parse(bitstream, demo);
4849
} else if (cmd == (int)NET_Messages.net_Tick) { //and all this other stuff
4950
new NETTick().Parse(bitstream, demo);
51+
} else if (cmd == (int)SVC_Messages.svc_UserMessage) {
52+
new UserMessage().Parse(bitstream, demo);
5053
} else {
5154
//You can use this flag to see what information the other packets contain,
5255
//if you want. Then you can look into the objects. Has some advnatages, and some disdavantages (mostly speed),
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace DemoInfo.DP.FastNetmessages
2+
{
3+
/// <summary>
4+
/// FastNetMessage adaptation of CCSUsrMsg_ServerRankUpdate.RankUpdate protobuf message
5+
/// </summary>
6+
public class RankUpdate
7+
{
8+
private const long VALVE_MAGIC_NUMBER = 76561197960265728;
9+
10+
public int AccountId;
11+
public int RankOld;
12+
public int RankNew;
13+
public int NumWins;
14+
public float RankChange;
15+
16+
public void Parse(IBitStream bitstream, DemoParser parser)
17+
{
18+
while (!bitstream.ChunkFinished)
19+
{
20+
var desc = bitstream.ReadProtobufVarInt();
21+
var wireType = desc & 7;
22+
var fieldnum = desc >> 3;
23+
24+
if (wireType == 0 && fieldnum == 1)
25+
{
26+
AccountId = bitstream.ReadProtobufVarInt();
27+
}
28+
else if(wireType == 0 && fieldnum == 2)
29+
{
30+
RankOld = bitstream.ReadProtobufVarInt();
31+
}
32+
else if (wireType == 0 && fieldnum == 3)
33+
{
34+
RankNew = bitstream.ReadProtobufVarInt();
35+
}
36+
else if (wireType == 0 && fieldnum == 4)
37+
{
38+
NumWins = bitstream.ReadProtobufVarInt();
39+
}
40+
else if (wireType == 5 && fieldnum == 5)
41+
{
42+
RankChange = bitstream.ReadFloat();
43+
}
44+
}
45+
46+
Raise(parser);
47+
}
48+
49+
private void Raise(DemoParser parser)
50+
{
51+
RankUpdateEventArgs e = new RankUpdateEventArgs
52+
{
53+
SteamId = AccountId + VALVE_MAGIC_NUMBER,
54+
RankOld = RankOld,
55+
RankNew = RankNew,
56+
WinCount = NumWins,
57+
RankChange = RankChange
58+
};
59+
60+
parser.RaiseRankUpdate(e);
61+
}
62+
}
63+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.IO;
2+
3+
namespace DemoInfo.DP.FastNetmessages
4+
{
5+
/// <summary>
6+
/// FastNetMessage adaptation of CCSUsrMsg_SayText protobuf message
7+
/// </summary>
8+
public struct SayText
9+
{
10+
public int EntityIndex;
11+
public string Text;
12+
private int _chat;
13+
public bool Chat => _chat != 0;
14+
private int _textAllChat;
15+
public bool TextAllChat => _textAllChat != 0;
16+
17+
public void Parse(IBitStream bitstream, DemoParser parser)
18+
{
19+
while (!bitstream.ChunkFinished)
20+
{
21+
var desc = bitstream.ReadProtobufVarInt();
22+
var wireType = desc & 7;
23+
var fieldnum = desc >> 3;
24+
25+
if (wireType == 0 && fieldnum == 1)
26+
{
27+
EntityIndex = bitstream.ReadProtobufVarInt();
28+
}
29+
else if (wireType == 2 && fieldnum == 2)
30+
{
31+
Text = bitstream.ReadProtobufString();
32+
}
33+
else if (wireType == 0 && fieldnum == 3)
34+
{
35+
_chat = bitstream.ReadProtobufVarInt();
36+
}
37+
else if (wireType == 0 && fieldnum == 4)
38+
{
39+
_textAllChat = bitstream.ReadProtobufVarInt();
40+
}
41+
else
42+
throw new InvalidDataException();
43+
}
44+
Raise(parser);
45+
}
46+
47+
private void Raise(DemoParser parser)
48+
{
49+
SayTextEventArgs e = new SayTextEventArgs
50+
{
51+
EntityIndex = EntityIndex,
52+
Text = Text,
53+
IsChat = Chat,
54+
IsChatAll = TextAllChat
55+
};
56+
57+
parser.RaiseSayText(e);
58+
}
59+
}
60+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
5+
namespace DemoInfo.DP.FastNetmessages
6+
{
7+
/// <summary>
8+
/// FastNetMessage adaptation of CCSUsrMsg_SayText2 protobuf message
9+
/// </summary>
10+
public struct SayText2
11+
{
12+
public int EntIdx;
13+
private int _chat;
14+
public bool Chat => _chat != 0;
15+
private int _textAllChat;
16+
public bool TextAllChat => _textAllChat != 0;
17+
// Params is a 4 length array but only 2 are used [0] = sender nickname [1] = message text
18+
public IList<string> Params;
19+
public string MsgName;
20+
21+
public void Parse(IBitStream bitstream, DemoParser parser)
22+
{
23+
Params = new List<string>();
24+
while (!bitstream.ChunkFinished)
25+
{
26+
var desc = bitstream.ReadProtobufVarInt();
27+
var wireType = desc & 7;
28+
var fieldnum = desc >> 3;
29+
30+
if (wireType == 0 && fieldnum == 1)
31+
{
32+
EntIdx = bitstream.ReadProtobufVarInt();
33+
}
34+
else if (wireType == 0 && fieldnum == 2)
35+
{
36+
_chat = bitstream.ReadProtobufVarInt();
37+
}
38+
else if (wireType == 2 && fieldnum == 3)
39+
{
40+
MsgName = bitstream.ReadProtobufString();
41+
}
42+
else if (wireType == 0 && fieldnum == 5)
43+
{
44+
_textAllChat = bitstream.ReadProtobufVarInt();
45+
}
46+
else if (wireType == 2 && fieldnum == 4)
47+
{
48+
Params.Add(bitstream.ReadProtobufString());
49+
}
50+
else
51+
throw new InvalidDataException();
52+
}
53+
Raise(parser);
54+
}
55+
56+
private void Raise(DemoParser parser)
57+
{
58+
// struct methods are called with a hidden ref to "this",
59+
// I have to make a local copy to be able to use it in the lambda expression
60+
IList<string> parameters = Params;
61+
SayText2EventArgs e = new SayText2EventArgs
62+
{
63+
Sender = parser.Players.Values.FirstOrDefault(x => x.Name == parameters[0]),
64+
Text = Params[1],
65+
IsChat = Chat,
66+
IsChatAll = TextAllChat
67+
};
68+
69+
parser.RaiseSayText2(e);
70+
}
71+
}
72+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.IO;
2+
3+
namespace DemoInfo.DP.FastNetmessages
4+
{
5+
/// <summary>
6+
/// FastNetMessage adaptation of CCSUsrMsg_ServerRankUpdate protobuf message
7+
/// We don't raise this event but instead each RankUpdate events that it contains
8+
/// </summary>
9+
public struct ServerRankUpdate
10+
{
11+
public void Parse(IBitStream bitstream, DemoParser parser)
12+
{
13+
while (!bitstream.ChunkFinished)
14+
{
15+
var desc = bitstream.ReadProtobufVarInt();
16+
var wireType = desc & 7;
17+
var fieldnum = desc >> 3;
18+
19+
if (wireType == 2 && fieldnum == 1)
20+
{
21+
bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);
22+
new RankUpdate().Parse(bitstream, parser);
23+
bitstream.EndChunk();
24+
}
25+
else
26+
throw new InvalidDataException();
27+
}
28+
}
29+
}
30+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using DemoInfo.Messages;
3+
4+
namespace DemoInfo.DP.FastNetmessages
5+
{
6+
/// <summary>
7+
/// FastNetMessage adaptation of CSVCMsg_UserMessage protobuf message
8+
/// </summary>
9+
public struct UserMessage
10+
{
11+
/// <summary>
12+
/// Correspond to User_Messages enum values
13+
/// </summary>
14+
public int MsgType;
15+
/// <summary>
16+
/// Don't what is it?
17+
/// </summary>
18+
public int PassThrough;
19+
20+
public void Parse(IBitStream bitstream, DemoParser parser)
21+
{
22+
while (!bitstream.ChunkFinished)
23+
{
24+
var desc = bitstream.ReadProtobufVarInt();
25+
var wireType = desc & 7;
26+
var fieldnum = desc >> 3;
27+
28+
if (wireType == 0 && fieldnum == 1)
29+
{
30+
MsgType = bitstream.ReadProtobufVarInt();
31+
}
32+
else if (wireType == 0 && fieldnum == 3)
33+
{
34+
PassThrough = bitstream.ReadProtobufVarInt();
35+
} else if (fieldnum == 2) {
36+
// msg data
37+
if (wireType == 2)
38+
{
39+
bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);
40+
switch (MsgType)
41+
{
42+
// This is where you can add others UserMessage parsing logic
43+
case (int)User_Messages.um_SayText:
44+
new SayText().Parse(bitstream, parser);
45+
break;
46+
case (int)User_Messages.um_SayText2:
47+
new SayText2().Parse(bitstream, parser);
48+
break;
49+
case (int)User_Messages.um_ServerRankUpdate:
50+
new ServerRankUpdate().Parse(bitstream, parser);
51+
break;
52+
}
53+
54+
bitstream.EndChunk();
55+
if (!bitstream.ChunkFinished)
56+
throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}

DemoInfo/DP/Handler/GameEventHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public static void Apply(GameEvent rawEvent, DemoParser parser)
109109
if (eventDescriptor.Name == "begin_new_match")
110110
parser.RaiseMatchStarted ();
111111

112+
if (eventDescriptor.Name == "round_announce_match_start")
113+
parser.RaiseRoundAnnounceMatchStarted();
114+
112115
if (eventDescriptor.Name == "round_freeze_end")
113116
parser.RaiseFreezetimeEnded ();
114117

0 commit comments

Comments
 (0)