Beispiel #1
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 0 && fieldnum == 1)
                {
                    EntityIndex = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 2 && fieldnum == 2)
                {
                    Text = bitstream.ReadProtobufString();
                }
                else if (wireType == 0 && fieldnum == 3)
                {
                    _chat = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 4)
                {
                    _textAllChat = bitstream.ReadProtobufVarInt();
                }
                else
                {
                    throw new InvalidDataException();
                }
            }
            Raise(parser);
        }
Beispiel #2
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;
                if (wireType != 0)
                {
                    throw new InvalidDataException();
                }

                var val = (uint)bitstream.ReadProtobufVarInt();

                switch (fieldnum)
                {
                case 1:
                    Tick = val;
                    break;

                case 4:
                    HostComputationTime = val;
                    break;

                case 5:
                    HostComputationTimeStdDeviation = val;
                    break;

                case 6:
                    HostFramestartTimeStdDeviation = val;
                    break;
                }
            }
        }
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 0 && fieldnum == 1)
                {
                    AccountId = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 2)
                {
                    RankOld = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 3)
                {
                    RankNew = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 4)
                {
                    NumWins = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 5 && fieldnum == 5)
                {
                    RankChange = bitstream.ReadFloat();
                }
            }

            Raise(parser);
        }
Beispiel #4
0
            public void Parse(IBitStream bitstream)
            {
                var keys = new List <Key>();

                while (!bitstream.ChunkFinished)
                {
                    var desc     = bitstream.ReadProtobufVarInt();
                    var wireType = desc & 7;
                    var fieldnum = desc >> 3;
                    if (wireType == 0 && fieldnum == 1)
                    {
                        EventId = bitstream.ReadProtobufVarInt();
                    }
                    else if (wireType == 2 && fieldnum == 2)
                    {
                        Name = bitstream.ReadProtobufString();
                    }
                    else if (wireType == 2 && fieldnum == 3)
                    {
                        var length = bitstream.ReadProtobufVarInt();
                        bitstream.BeginChunk(length * 8);
                        var key = new Key();
                        key.Parse(bitstream);
                        keys.Add(key);
                        bitstream.EndChunk();
                    }
                    else
                    {
                        throw new InvalidDataException();
                    }
                }

                Keys = keys.ToArray();
            }
Beispiel #5
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 2 && fieldnum == 1)
                {
                    Name = bitstream.ReadProtobufString();
                }
                else if (wireType == 2 && fieldnum == 2)
                {
                    Value = bitstream.ReadProtobufString();
                }
                else if (wireType == 0 && fieldnum == 3)
                {
                    DictionaryName = (uint)bitstream.ReadProtobufVarInt();
                }
                else
                {
                    throw new InvalidDataException();
                }
            }

            Raise(parser);
        }
Beispiel #6
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished) {
                var desc = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;
                if (wireType != 0)
                    throw new InvalidDataException();

                var val = (uint)bitstream.ReadProtobufVarInt();

                switch (fieldnum) {
                case 1:
                    Tick = val;
                    break;
                case 4:
                    HostComputationTime = val;
                    break;
                case 5:
                    HostComputationTimeStdDeviation = val;
                    break;
                case 6:
                    HostFramestartTimeStdDeviation = val;
                    break;
                default:
                    // silently drop
                    break;
                }
            }

            parser.IngameTick = (int)Tick;
        }
		public void Parse(IBitStream bitstream, DemoParser parser)
		{
			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;

				if (wireType == 2) {
					if (fieldnum == 1) {
						Name = bitstream.ReadProtobufString();
						continue;
					} else if (fieldnum == 8) {
						// String data is special.
						// We'll simply hope that gaben is nice and sends
						// string_data last, just like he should.
						var len = bitstream.ReadProtobufVarInt();
						bitstream.BeginChunk(len * 8);
						DemoInfo.DP.Handler.CreateStringTableUserInfoHandler.Apply(this, bitstream, parser);
						bitstream.EndChunk();
						if (!bitstream.ChunkFinished)
							throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
						break;
					} else
						throw new InvalidDataException("yes I know we should drop this but we" +
							"probably want to know that they added a new big field");
				}

				if (wireType != 0)
					throw new InvalidDataException();

				var val = bitstream.ReadProtobufVarInt();

				switch (fieldnum) {
				case 2:
					MaxEntries = val;
					break;
				case 3:
					NumEntries = val;
					break;
				case 4:
					_UserDataFixedSize = val;
					break;
				case 5:
					UserDataSize = val;
					break;
				case 6:
					UserDataSizeBits = val;
					break;
				case 7:
					Flags = val;
					break;
				default:
					// silently drop
					break;
				}
			}
		}
Beispiel #8
0
        public IEnumerable <SendProp> Parse(IBitStream bitstream)
        {
            var sendprops = new List <SendProp>();

            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 2)
                {
                    if (fieldnum == 2)
                    {
                        NetTableName = bitstream.ReadProtobufString();
                    }
                    else if (fieldnum == 4)
                    {
                        // Props are special.
                        // We'll simply hope that gaben is nice and sends
                        // props last, just like he should.
                        var len = bitstream.ReadProtobufVarInt();
                        bitstream.BeginChunk(len * 8);
                        var sendprop = new SendProp();
                        sendprop.Parse(bitstream);
                        sendprops.Add(sendprop);
                        bitstream.EndChunk();
                    }
                    else
                    {
                        throw new InvalidDataException("yes I know we should drop this" +
                                                       "but we probably want to know that they added a new big field");
                    }
                }
                else if (wireType == 0)
                {
                    var val = bitstream.ReadProtobufVarInt();

                    switch (fieldnum)
                    {
                    case 1:
                        _IsEnd = val;
                        break;

                    case 3:
                        _NeedsDecoder = val;
                        break;
                    }
                }
                else
                {
                    throw new InvalidDataException();
                }
            }

            return(sendprops);
        }
Beispiel #9
0
			public void Parse(IBitStream bitstream)
			{
				while (!bitstream.ChunkFinished) {
					var desc = bitstream.ReadProtobufVarInt();
					var wireType = desc & 7;
					var fieldnum = desc >> 3;

					if (wireType == 2) {
						if (fieldnum == 2) {
							VarName = bitstream.ReadProtobufString();
						} else if (fieldnum == 5) {
							DtName = bitstream.ReadProtobufString();
						} else
							throw new InvalidDataException("yes I know we should drop this but we" +
								"probably want to know that they added a new big field");
					} else if (wireType == 0) {
						var val = bitstream.ReadProtobufVarInt();

						switch (fieldnum) {
						case 1:
							Type = val;
							break;
						case 3:
							Flags = val;
							break;
						case 4:
							Priority = val;
							break;
						case 6:
							NumElements = val;
							break;
						case 9:
							NumBits = val;
							break;
						default:
							// silently drop
							break;
						}
					} else if (wireType == 5) {
						var val = bitstream.ReadFloat();

						switch (fieldnum) {
						case 7:
							LowValue = val;
							break;
						case 8:
							HighValue = val;
							break;
						default:
							// silently drop
							break;
						}
					} else
						throw new InvalidDataException();
				}
			}
Beispiel #10
0
        public void ParsePacket(IBitStream bitstream)
        {
            while (true)
            {
                var type = (SVC_Messages)bitstream.ReadProtobufVarInt();
                if (type != SVC_Messages.svc_SendTable)
                {
                    throw new Exception("Expected SendTable, got " + type);
                }

                var size = bitstream.ReadProtobufVarInt();
                bitstream.BeginChunk(size * 8);
                var sendTable = new SendTable(bitstream);
                bitstream.EndChunk();

                if (sendTable.IsEnd)
                {
                    break;
                }

                DataTables.Add(sendTable);
            }

            int serverClassCount = checked ((int)bitstream.ReadInt(16));

            for (int i = 0; i < serverClassCount; i++)
            {
                ServerClass entry = new ServerClass();
                entry.ClassID = checked ((int)bitstream.ReadInt(16));

                if (entry.ClassID > serverClassCount)
                {
                    throw new Exception("Invalid class index");
                }

                entry.Name   = bitstream.ReadDataTableString();
                entry.DTName = bitstream.ReadDataTableString();

                entry.DataTableID = DataTables.FindIndex(a => a.Name == entry.DTName);

                if (ServerClasses.FirstOrDefault(sc => sc.Name == entry.Name && sc.DTName == entry.DTName) == null)
                {
                    ServerClasses.Add(entry);
                }
            }

            for (int i = 0; i < serverClassCount; i++)
            {
                FlattenDataTable(i);
            }
        }
		/// <summary>
		/// Parses a demo-packet. 
		/// </summary>
		/// <param name="bitstream">Bitstream.</param>
		/// <param name="demo">Demo.</param>
		public static void ParsePacket(IBitStream bitstream, DemoParser demo)
        {
			//As long as there is stuff to read
			while (!bitstream.ChunkFinished)
            {
				int cmd = bitstream.ReadProtobufVarInt(); //What type of packet is this?
				int length = bitstream.ReadProtobufVarInt(); //And how long is it?
				bitstream.BeginChunk(length * 8); //read length bytes
				if (cmd == (int)SVC_Messages.svc_PacketEntities) { //Parse packet entities
					new PacketEntities().Parse(bitstream, demo); 
				} else if (cmd == (int)SVC_Messages.svc_GameEventList) { //and all this other stuff
					new GameEventList().Parse(bitstream, demo);
				} else if (cmd == (int)SVC_Messages.svc_GameEvent) {
					new GameEvent().Parse(bitstream, demo);
				} else if (cmd == (int)SVC_Messages.svc_CreateStringTable) {
					new CreateStringTable().Parse(bitstream, demo);
				} else if (cmd == (int)SVC_Messages.svc_UpdateStringTable) {
					new UpdateStringTable().Parse(bitstream, demo);
				} else if (cmd == (int)NET_Messages.net_Tick) { //and all this other stuff
						new NETTick().Parse(bitstream, demo);
				} else {
					//You can use this flag to see what information the other packets contain, 
					//if you want. Then you can look into the objects. Has some advnatages, and some disdavantages (mostly speed), 
					//so we use our own lightning-fast parsing code. 
					#if SLOW_PROTOBUF 
					Type toParse = null;

					if (Enum.IsDefined(typeof(SVC_Messages), cmd)) {
						SVC_Messages msg = (SVC_Messages)cmd;
						toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CSVCMsg_" + msg.ToString().Substring(4));
					} else if (Enum.IsDefined(typeof(NET_Messages), cmd)) {
						NET_Messages msg = (NET_Messages)cmd;
						toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CNETMsg_" + msg.ToString().Substring(4));
					}

					var data = bitstream.ReadBytes(length);
					if (toParse == null)
						continue;

					ProtoBuf.IExtensible result;
					using (var memstream = new MemoryStream(data))
						result = memstream.ReadProtobufMessage(toParse);

					foreach (var parser in Parsers)
						if (parser.TryApplyMessage(result, demo) && (parser.Priority > 0))
							break;
					#endif
				}
				bitstream.EndChunk();
            }
        }
Beispiel #12
0
		public void Parse(IBitStream bitstream, DemoParser parser)
		{
			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;

				if ((fieldnum == 7) && (wireType == 2)) {
					// Entity data is special.
					// We'll simply hope that gaben is nice and sends
					// entity_data last, just like he should.

					var len = bitstream.ReadProtobufVarInt();
					bitstream.BeginChunk(len * 8);
					DemoInfo.DP.Handler.PacketEntitesHandler.Apply(this, bitstream, parser);
					bitstream.EndChunk();
					if (!bitstream.ChunkFinished)
						throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
					break;
				}

				if (wireType != 0)
					throw new InvalidDataException();

				var val = bitstream.ReadProtobufVarInt();

				switch (fieldnum) {
				case 1:
					MaxEntries = val;
					break;
				case 2:
					UpdatedEntries = val;
					break;
				case 3:
					_IsDelta = val;
					break;
				case 4:
					_UpdateBaseline = val;
					break;
				case 5:
					Baseline = val;
					break;
				case 6:
					DeltaFrom = val;
					break;
				default:
					// silently drop
					break;
				}
			}
		}
Beispiel #13
0
			public void Parse(IBitStream bitstream)
			{
				while (!bitstream.ChunkFinished) {
					var desc = bitstream.ReadProtobufVarInt();
					var wireType = desc & 7;
					var fieldnum = desc >> 3;
					if ((wireType == 0) && (fieldnum == 1)) {
						Type = bitstream.ReadProtobufVarInt();
					} else if ((wireType == 2) && (fieldnum == 2)) {
						Name = bitstream.ReadProtobufString();
					} else
						throw new InvalidDataException();
				}
			}
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 0 && fieldnum == 1)
                {
                    MsgType = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 3)
                {
                    PassThrough = bitstream.ReadProtobufVarInt();
                }
                else if (fieldnum == 2)
                {
                    // msg data
                    if (wireType == 2)
                    {
                        bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);
                        switch (MsgType)
                        {
                        // This is where you can add others UserMessage parsing logic
                        case (int)User_Messages.um_SayText:
                            new SayText().Parse(bitstream, parser);
                            break;

                        case (int)User_Messages.um_SayText2:
                            new SayText2().Parse(bitstream, parser);
                            break;

                        case (int)User_Messages.um_ServerRankUpdate:
                            new ServerRankUpdate().Parse(bitstream, parser);
                            break;
                        }

                        bitstream.EndChunk();
                        if (!bitstream.ChunkFinished)
                        {
                            throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
                        }
                    }
                }
            }
        }
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if ((wireType == 2) && (fieldnum == 3))
                {
                    // String data is special.
                    // We'll simply hope that gaben is nice and sends
                    // string_data last, just like he should.
                    var len = bitstream.ReadProtobufVarInt();
                    bitstream.BeginChunk(len * 8);
                    DemoInfo.DP.Handler.UpdateStringTableUserInfoHandler.Apply(this, bitstream, parser);
                    bitstream.EndChunk();
                    if (!bitstream.ChunkFinished)
                    {
                        throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
                    }
                    break;
                }

                if (wireType != 0)
                {
                    throw new Exception();
                }

                var val = bitstream.ReadProtobufVarInt();

                switch (fieldnum)
                {
                case 1:
                    TableId = val;
                    break;

                case 2:
                    NumChangedEntries = val;
                    break;

                default:
                    // silently drop
                    break;
                }
            }
        }
Beispiel #16
0
        public int ReadProtobufVarInt()
        {
            var a = A.ReadProtobufVarInt();
            var b = B.ReadProtobufVarInt();

            Verify(a, b);
            return(a);
        }
Beispiel #17
0
		private IEnumerable<Descriptor> ReadDescriptors(IBitStream bitstream)
		{
			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;
				if ((wireType != 2) || (fieldnum != 1))
					throw new InvalidDataException();

				var length = bitstream.ReadProtobufVarInt();
				bitstream.BeginChunk(length * 8);
				var descriptor = new Descriptor();
				descriptor.Parse(bitstream);
				yield return descriptor;
				bitstream.EndChunk();
			}
		}
Beispiel #18
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 2 && fieldnum == 1)
                {
                    bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);
                    new RankUpdate().Parse(bitstream, parser);
                    bitstream.EndChunk();
                }
                else
                {
                    throw new InvalidDataException();
                }
            }
        }
Beispiel #19
0
 public void Parse(IBitStream bitstream)
 {
     while (!bitstream.ChunkFinished)
     {
         var desc     = bitstream.ReadProtobufVarInt();
         var wireType = desc & 7;
         var fieldnum = desc >> 3;
         if (wireType == 0 && fieldnum == 1)
         {
             Type = bitstream.ReadProtobufVarInt();
         }
         else if (wireType == 2 && fieldnum == 2)
         {
             Name = bitstream.ReadProtobufString();
         }
         else
         {
             throw new InvalidDataException();
         }
     }
 }
Beispiel #20
0
        private IEnumerable <Descriptor> ReadDescriptors(IBitStream bitstream)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;
                if (wireType != 2 || fieldnum != 1)
                {
                    throw new InvalidDataException();
                }

                var length = bitstream.ReadProtobufVarInt();
                bitstream.BeginChunk(length * 8);
                var descriptor = new Descriptor();
                descriptor.Parse(bitstream);
                yield return(descriptor);

                bitstream.EndChunk();
            }
        }
Beispiel #21
0
		public void ParsePacket(IBitStream bitstream)
        {
			while (true)
            {
				var type = (SVC_Messages)bitstream.ReadProtobufVarInt();
				if (type != SVC_Messages.svc_SendTable)
					throw new Exception("Expected SendTable, got " + type);

				var size = bitstream.ReadProtobufVarInt();
				bitstream.BeginChunk(size * 8);
				var sendTable = new SendTable(bitstream);
				bitstream.EndChunk();

                if (sendTable.IsEnd)
                    break;

				DataTables.Add(sendTable);
            }

			int serverClassCount = checked((int)bitstream.ReadInt(16));

            for (int i = 0; i < serverClassCount; i++)
            {
                ServerClass entry = new ServerClass();
				entry.ClassID = checked((int)bitstream.ReadInt(16));

                if (entry.ClassID > serverClassCount)
                    throw new Exception("Invalid class index");

				entry.Name = bitstream.ReadDataTableString();
				entry.DTName = bitstream.ReadDataTableString();

                entry.DataTableID = DataTables.FindIndex(a => a.Name == entry.DTName);

                ServerClasses.Add(entry);
            }

            for (int i = 0; i < serverClassCount; i++)
                FlattenDataTable(i);
        }
Beispiel #22
0
        /// <summary>
        ///     Parses a demo-packet.
        /// </summary>
        /// <param name="bitstream">Bitstream.</param>
        /// <param name="demo">Demo.</param>
        public static void ParsePacket(IBitStream bitstream, DemoParser demo)
        {
            //As long as there is stuff to read
            while (!bitstream.ChunkFinished)
            {
                var cmd    = bitstream.ReadProtobufVarInt(); //What type of packet is this?
                var length = bitstream.ReadProtobufVarInt(); //And how long is it?
                bitstream.BeginChunk(length * 8);            //read length bytes
                if (cmd == (int)SVC_Messages.svc_PacketEntities)
                {
                    //Parse packet entities
                    new PacketEntities().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_GameEventList)
                {
                    //and all this other stuff
                    new GameEventList().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_GameEvent)
                {
                    new GameEvent().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_CreateStringTable)
                {
                    new CreateStringTable().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_UpdateStringTable)
                {
                    new UpdateStringTable().Parse(bitstream, demo);
                }
                else if (cmd == (int)NET_Messages.net_Tick)
                {
                    //and all this other stuff
                    new NETTick().Parse(bitstream, demo);
                }

                bitstream.EndChunk();
            }
        }
Beispiel #23
0
			public void Parse(IBitStream bitstream)
			{
				var keys = new List<Key>();
				while (!bitstream.ChunkFinished) {
					var desc = bitstream.ReadProtobufVarInt();
					var wireType = desc & 7;
					var fieldnum = desc >> 3;
					if ((wireType == 0) && (fieldnum == 1)) {
						EventId = bitstream.ReadProtobufVarInt();
					} else if ((wireType == 2) && (fieldnum == 2)) {
						Name = bitstream.ReadProtobufString();
					} else if ((wireType == 2) && (fieldnum == 3)) {
						var length = bitstream.ReadProtobufVarInt();
						bitstream.BeginChunk(length * 8);
						var key = new Key();
						key.Parse(bitstream);
						keys.Add(key);
						bitstream.EndChunk();
					} else
						throw new InvalidDataException();
				}
				Keys = keys.ToArray();
			}
Beispiel #24
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            Params = new List <string>();
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 0 && fieldnum == 1)
                {
                    EntIdx = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 0 && fieldnum == 2)
                {
                    _chat = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 2 && fieldnum == 3)
                {
                    MsgName = bitstream.ReadProtobufString();
                }
                else if (wireType == 0 && fieldnum == 5)
                {
                    _textAllChat = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 2 && fieldnum == 4)
                {
                    Params.Add(bitstream.ReadProtobufString());
                }
                else
                {
                    throw new InvalidDataException();
                }
            }
            Raise(parser);
        }
Beispiel #25
0
 public static string ReadProtobufString(this IBitStream reader)
 {
     return(Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadProtobufVarInt())));
 }
Beispiel #26
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if ((fieldnum == 7) && (wireType == 2))
                {
                    // Entity data is special.
                    // We'll simply hope that gaben is nice and sends
                    // entity_data last, just like he should.

                    var len = bitstream.ReadProtobufVarInt();
                    bitstream.BeginChunk(len * 8);
                    DemoInfo.DP.Handler.PacketEntitesHandler.Apply(this, bitstream, parser);
                    bitstream.EndChunk();
                    if (!bitstream.ChunkFinished)
                    {
                        throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
                    }
                    break;
                }

                if (wireType != 0)
                {
                    throw new Exception();
                }

                var val = bitstream.ReadProtobufVarInt();

                switch (fieldnum)
                {
                case 1:
                    MaxEntries = val;
                    break;

                case 2:
                    UpdatedEntries = val;
                    break;

                case 3:
                    _IsDelta = val;
                    break;

                case 4:
                    _UpdateBaseline = val;
                    break;

                case 5:
                    Baseline = val;
                    break;

                case 6:
                    DeltaFrom = val;
                    break;

                default:
                    // silently drop
                    break;
                }
            }
        }
        public static void ParsePacket(IBitStream bitstream, DemoParser demo)
        {
            while (!bitstream.ChunkFinished)
            {
                int cmd    = bitstream.ReadProtobufVarInt();
                int length = bitstream.ReadProtobufVarInt();
                bitstream.BeginChunk(length * 8);
                if (cmd == (int)NET_Messages.net_Tick)
                {
                    new NETTick().Parse(bitstream);
                }
                else if (cmd == (int)SVC_Messages.svc_PacketEntities)
                {
                    new PacketEntities().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_EncryptedData)
                {
                    // TODO: maybe one day find the key for this?
                }
                else if (cmd == (int)SVC_Messages.svc_GameEventList)
                {
                    new GameEventList().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_GameEvent)
                {
                    new GameEvent().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_CreateStringTable)
                {
                    new CreateStringTable().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_UpdateStringTable)
                {
                    new UpdateStringTable().Parse(bitstream, demo);
                }
                else
                {
                                        #if SLOW_PROTOBUF
                    Type toParse = null;

                    if (Enum.IsDefined(typeof(SVC_Messages), cmd))
                    {
                        SVC_Messages msg = (SVC_Messages)cmd;
                        toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CSVCMsg_" + msg.ToString().Substring(4));
                    }
                    else if (Enum.IsDefined(typeof(NET_Messages), cmd))
                    {
                        NET_Messages msg = (NET_Messages)cmd;
                        toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CNETMsg_" + msg.ToString().Substring(4));
                    }

                    var data = bitstream.ReadBytes(length);
                    if (toParse == null)
                    {
                        continue;
                    }

                    ProtoBuf.IExtensible result;
                    using (var memstream = new MemoryStream(data))
                        result = memstream.ReadProtobufMessage(toParse);

                    foreach (var parser in Parsers)
                    {
                        if (parser.TryApplyMessage(result, demo) && (parser.Priority > 0))
                        {
                            break;
                        }
                    }
                                        #endif
                }
                bitstream.EndChunk();
            }
        }
Beispiel #28
0
		public void Parse(IBitStream bitstream, DemoParser parser)
		{
			Keys = new List<object>();
			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;
				if ((wireType == 2) && (fieldnum == 1)) {
					EventName = bitstream.ReadProtobufString();
				} else if ((wireType == 0) && (fieldnum == 2)) {
					EventId = bitstream.ReadProtobufVarInt();
				} else if ((wireType == 2) && (fieldnum == 3)) {
					bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);
					/*
					 * Hope and pray that gaben is once again nice to us and
					 * sends 'type' first, then the respective member, then NOTHING.
					 */
					desc = bitstream.ReadProtobufVarInt();
					wireType = desc & 7;
					fieldnum = desc >> 3;
					if ((wireType != 0) || (fieldnum != 1))
						throw new InvalidDataException("Lord Gaben wasn't nice to us :/");

					var typeMember = bitstream.ReadProtobufVarInt();
					desc = bitstream.ReadProtobufVarInt();
					wireType = desc & 7;
					fieldnum = desc >> 3;

					if (fieldnum != (typeMember + 1))
						throw new InvalidDataException("Lord Gaben wasn't nice to us :/ (srsly wtf!?)");

					switch (typeMember) {
					case 1: // string
						if (wireType != 2)
							throw new InvalidDataException("proto definition differs");
						Keys.Add(bitstream.ReadProtobufString());
						break;
					case 2: // float
						if (wireType != 5)
							throw new InvalidDataException("proto definition differs");
						Keys.Add(bitstream.ReadFloat());
						break;
					case 3: // long
					case 4: // short
					case 5: // byte
						if (wireType != 0)
							throw new InvalidDataException("proto definition differs");
						Keys.Add(bitstream.ReadProtobufVarInt());
						break;
					case 6: // bool
						if (wireType != 0)
							throw new InvalidDataException("proto definition differs");
						Keys.Add(bitstream.ReadProtobufVarInt() != 0);
						break;
					default:
						throw new InvalidDataException("Looks like they introduced a new type");
					}

					if (!bitstream.ChunkFinished)
						throw new InvalidDataException("Lord Gaben tricked us! D:");

					bitstream.EndChunk();
				} else
					throw new InvalidDataException();
			}

			GameEventHandler.Apply(this, parser);
		}
Beispiel #29
0
		public IEnumerable<SendProp> Parse(IBitStream bitstream) {
			var sendprops = new List<SendProp>();

			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;

				if (wireType == 2) {
					if (fieldnum == 2) {
						NetTableName = bitstream.ReadProtobufString();
					} else if (fieldnum == 4) {
						// Props are special.
						// We'll simply hope that gaben is nice and sends
						// props last, just like he should.
						var len = bitstream.ReadProtobufVarInt();
						bitstream.BeginChunk(len * 8);
						var sendprop = new SendProp();
						sendprop.Parse(bitstream);
						sendprops.Add(sendprop);
						bitstream.EndChunk();
					} else
						throw new InvalidDataException("yes I know we should drop this" +
							"but we probably want to know that they added a new big field");
				} else if (wireType == 0) {
					var val = bitstream.ReadProtobufVarInt();

					switch (fieldnum) {
					case 1:
						_IsEnd = val;
						break;
					case 3:
						_NeedsDecoder = val;
						break;
					default:
						// silently drop
						break;
					}
				} else
					throw new InvalidDataException();
			}

			return sendprops;
		}
        /// <summary>
        /// Parses a demo-packet.
        /// </summary>
        /// <param name="bitstream">Bitstream.</param>
        /// <param name="demo">Demo.</param>
        public static void ParsePacket(IBitStream bitstream, DemoParser demo)
        {
            //As long as there is stuff to read
            while (!bitstream.ChunkFinished)
            {
                int cmd    = bitstream.ReadProtobufVarInt();      //What type of packet is this?
                int length = bitstream.ReadProtobufVarInt();      //And how long is it?
                bitstream.BeginChunk(length * 8);                 //read length bytes
                if (cmd == (int)SVC_Messages.svc_PacketEntities)  //Parse packet entities
                {
                    new PacketEntities().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_GameEventList)                     //and all this other stuff
                {
                    new GameEventList().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_GameEvent)
                {
                    new GameEvent().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_CreateStringTable)
                {
                    new CreateStringTable().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_UpdateStringTable)
                {
                    new UpdateStringTable().Parse(bitstream, demo);
                }
                else if (cmd == (int)NET_Messages.net_Tick)                     //and all this other stuff
                {
                    new NETTick().Parse(bitstream, demo);
                }
                else if (cmd == (int)SVC_Messages.svc_UserMessage)
                {
                    new UserMessage().Parse(bitstream, demo);
                }
                else
                {
                    //You can use this flag to see what information the other packets contain,
                    //if you want. Then you can look into the objects. Has some advnatages, and some disdavantages (mostly speed),
                    //so we use our own lightning-fast parsing code.
                                        #if SLOW_PROTOBUF
                    Type toParse = null;

                    if (Enum.IsDefined(typeof(SVC_Messages), cmd))
                    {
                        SVC_Messages msg = (SVC_Messages)cmd;
                        toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CSVCMsg_" + msg.ToString().Substring(4));
                    }
                    else if (Enum.IsDefined(typeof(NET_Messages), cmd))
                    {
                        NET_Messages msg = (NET_Messages)cmd;
                        toParse = Assembly.GetExecutingAssembly().GetType("DemoInfo.Messages.CNETMsg_" + msg.ToString().Substring(4));
                    }

                    var data = bitstream.ReadBytes(length);
                    if (toParse == null)
                    {
                        continue;
                    }

                    ProtoBuf.IExtensible result;
                    using (var memstream = new MemoryStream(data))
                        result = memstream.ReadProtobufMessage(toParse);

                    foreach (var parser in Parsers)
                    {
                        if (parser.TryApplyMessage(result, demo) && (parser.Priority > 0))
                        {
                            break;
                        }
                    }
                                        #endif
                }
                bitstream.EndChunk();
            }
        }
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 2)
                {
                    if (fieldnum == 1)
                    {
                        Name = bitstream.ReadProtobufString();
                        continue;
                    }
                    else if (fieldnum == 8)
                    {
                        // String data is special.
                        // We'll simply hope that gaben is nice and sends
                        // string_data last, just like he should.
                        var len = bitstream.ReadProtobufVarInt();
                        bitstream.BeginChunk(len * 8);
                        DemoInfo.DP.Handler.CreateStringTableUserInfoHandler.Apply(this, bitstream, parser);
                        bitstream.EndChunk();
                        if (!bitstream.ChunkFinished)
                        {
                            throw new NotImplementedException("Lord Gaben wasn't nice to us :/");
                        }
                        break;
                    }
                    else
                    {
                        throw new Exception("yes I know we should drop this but we" +
                                            "probably want to know that they added a new big field");
                    }
                }

                if (wireType != 0)
                {
                    throw new Exception();
                }

                var val = bitstream.ReadProtobufVarInt();

                switch (fieldnum)
                {
                case 2:
                    MaxEntries = val;
                    break;

                case 3:
                    NumEntries = val;
                    break;

                case 4:
                    _UserDataFixedSize = val;
                    break;

                case 5:
                    UserDataSize = val;
                    break;

                case 6:
                    UserDataSizeBits = val;
                    break;

                case 7:
                    Flags = val;
                    break;

                default:
                    // silently drop
                    break;
                }
            }
        }
Beispiel #32
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            Keys = new List <object>();
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;
                if (wireType == 2 && fieldnum == 1)
                {
                    EventName = bitstream.ReadProtobufString();
                }
                else if (wireType == 0 && fieldnum == 2)
                {
                    EventId = bitstream.ReadProtobufVarInt();
                }
                else if (wireType == 2 && fieldnum == 3)
                {
                    bitstream.BeginChunk(bitstream.ReadProtobufVarInt() * 8);

                    /*
                     * Hope and pray that gaben is once again nice to us and
                     * sends 'type' first, then the respective member, then NOTHING.
                     */
                    desc     = bitstream.ReadProtobufVarInt();
                    wireType = desc & 7;
                    fieldnum = desc >> 3;
                    if (wireType != 0 || fieldnum != 1)
                    {
                        throw new InvalidDataException("Lord Gaben wasn't nice to us :/");
                    }

                    var typeMember = bitstream.ReadProtobufVarInt();
                    desc     = bitstream.ReadProtobufVarInt();
                    wireType = desc & 7;
                    fieldnum = desc >> 3;

                    if (fieldnum != typeMember + 1)
                    {
                        throw new InvalidDataException("Lord Gaben wasn't nice to us :/ (srsly wtf!?)");
                    }

                    switch (typeMember)
                    {
                    case 1:     // string
                        if (wireType != 2)
                        {
                            throw new InvalidDataException("proto definition differs");
                        }

                        Keys.Add(bitstream.ReadProtobufString());
                        break;

                    case 2:     // float
                        if (wireType != 5)
                        {
                            throw new InvalidDataException("proto definition differs");
                        }

                        Keys.Add(bitstream.ReadFloat());
                        break;

                    case 3:     // long
                    case 4:     // short
                    case 5:     // byte
                        if (wireType != 0)
                        {
                            throw new InvalidDataException("proto definition differs");
                        }

                        Keys.Add(bitstream.ReadProtobufVarInt());
                        break;

                    case 6:     // bool
                        if (wireType != 0)
                        {
                            throw new InvalidDataException("proto definition differs");
                        }

                        Keys.Add(bitstream.ReadProtobufVarInt() != 0);
                        break;

                    default:
                        throw new InvalidDataException("Looks like they introduced a new type");
                    }

                    if (!bitstream.ChunkFinished)
                    {
                        throw new InvalidDataException("Lord Gaben tricked us! D:");
                    }

                    bitstream.EndChunk();
                }
                else
                {
                    throw new InvalidDataException();
                }
            }

            GameEventHandler.Apply(this, parser);
        }
Beispiel #33
0
            public void Parse(IBitStream bitstream)
            {
                while (!bitstream.ChunkFinished)
                {
                    var desc     = bitstream.ReadProtobufVarInt();
                    var wireType = desc & 7;
                    var fieldnum = desc >> 3;

                    if (wireType == 2)
                    {
                        if (fieldnum == 2)
                        {
                            VarName = bitstream.ReadProtobufString();
                        }
                        else if (fieldnum == 5)
                        {
                            DtName = bitstream.ReadProtobufString();
                        }
                        else
                        {
                            throw new InvalidDataException("yes I know we should drop this but we" +
                                                           "probably want to know that they added a new big field");
                        }
                    }
                    else if (wireType == 0)
                    {
                        var val = bitstream.ReadProtobufVarInt();

                        switch (fieldnum)
                        {
                        case 1:
                            Type = val;
                            break;

                        case 3:
                            Flags = val;
                            break;

                        case 4:
                            Priority = val;
                            break;

                        case 6:
                            NumElements = val;
                            break;

                        case 9:
                            NumBits = val;
                            break;
                        }
                    }
                    else if (wireType == 5)
                    {
                        var val = bitstream.ReadFloat();

                        switch (fieldnum)
                        {
                        case 7:
                            LowValue = val;
                            break;

                        case 8:
                            HighValue = val;
                            break;
                        }
                    }
                    else
                    {
                        throw new InvalidDataException();
                    }
                }
            }
Beispiel #34
0
        public void Parse(IBitStream bitstream, DemoParser parser)
        {
            while (!bitstream.ChunkFinished)
            {
                var desc     = bitstream.ReadProtobufVarInt();
                var wireType = desc & 7;
                var fieldnum = desc >> 3;

                if (wireType == 5)
                {
                    if (fieldnum == 14)
                    {
                        parser.TickInterval = bitstream.ReadFloat();
                    }
                    else
                    {
                        var val = bitstream.ReadInt(32);
                        switch (fieldnum)
                        {
                        case 8:
                            MapCrc = val;
                            break;

                        case 9:
                            ClientCrc = val;
                            break;

                        case 10:
                            StringTableCrc = val;
                            break;
                        }
                    }
                }
                else if (wireType == 2)
                {
                    var val = bitstream.ReadProtobufString();

                    switch (fieldnum)
                    {
                    case 15:
                        GameDir = val;
                        break;

                    case 16:
                        MapName = val;
                        break;

                    case 17:
                        MapGroupName = val;
                        break;

                    case 18:
                        SkyName = val;
                        break;

                    case 19:
                        HostName = val;
                        break;
                    }
                }
                else if (wireType == 0)
                {
                    var val     = bitstream.ReadProtobufVarInt();
                    var boolval = (val == 0) ? false : true;

                    switch (fieldnum)
                    {
                    case 1:
                        Protocol = val;
                        break;

                    case 2:
                        ServerCount = val;
                        break;

                    case 3:
                        IsDedicated = boolval;
                        break;

                    case 4:
                        IsOfficialValveServer = boolval;
                        break;

                    case 5:
                        IsHltv = boolval;
                        break;

                    case 6:
                        IsReplay = boolval;
                        break;

                    case 7:
                        COs = val;
                        break;

                    case 11:
                        MaxClients = val;
                        break;

                    case 12:
                        MaxClasses = val;
                        break;

                    case 13:
                        PlayerSlot = val;
                        break;

                    case 20:
                        PublicIp = (uint)val;
                        break;

                    case 21:
                        IsRedirectingToProxyRelay = boolval;
                        break;

                    case 22:
                        UgcMapId = (uint)val;
                        break;
                    }
                }
            }
        }