public Header(BitStream bitStream) { this.FileType = bitStream.ReadString(); this.DemoProtocol = bitStream.ReadInt32(); this.NetworkProtocol = bitStream.ReadInt32(); this.ServerName = bitStream.ReadString(260); this.ClientName = bitStream.ReadString(260); this.MapName = bitStream.ReadString(260); this.GameDirectory = bitStream.ReadString(260); this.PlaybackTime = bitStream.ReadFloat(); this.PlaybackTicks = bitStream.ReadInt32(); this.PlaybackFrames = bitStream.ReadInt32(); this.SignOnLength = bitStream.ReadInt32(); }
private bool ReadSpecialFloat(BitStream bitStream, DataTableProperty dataTableProperty, out float result) { if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.Coord)) { result = ReadBitCoord(bitStream); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CoordMp)) { result = ReadBitCoordMP(bitStream, false, false); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CoordMpLowPrecision)) { result = ReadBitCoordMP(bitStream, false, true); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CoordMpIntegral)) { result = ReadBitCoordMP(bitStream, true, false); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.NoScale)) { result = bitStream.ReadFloat(); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.Normal)) { result = ReadBitNormal(bitStream); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CellCoord)) { result = ReadBitCellCoord(bitStream, dataTableProperty.NumberOfBits, false, false); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CellCoordLowPrecision)) { result = ReadBitCellCoord(bitStream, dataTableProperty.NumberOfBits, false, true); return true; } else if (dataTableProperty.Flags.HasFlag(DataTablePropertyFlags.CellCoordIntegral)) { result = ReadBitCellCoord(bitStream, dataTableProperty.NumberOfBits, true, false); return true; } result = 0; return false; }
public ProtoMessage(byte[] protoMessageData) { this.Values = new Dictionary<String, List<Object>>(); BitStream bitStream = new BitStream(protoMessageData); while ((bitStream.PositionInBytes) < bitStream.LengthInBytes) { int key = bitStream.ReadVarint32(); int fieldNumber = key >> 3; int wireType = key & 7; object value = null; switch (wireType) { case 0: { value = bitStream.ReadVarint32(); break; } case 1: { Console.WriteLine("ProtoMessage WireType 1"); bitStream.SeekBytes(0, SeekOrigin.End); break; } case 2: { int length = bitStream.ReadVarint32(); byte[] buffer = bitStream.ReadBytes(length); value = buffer; break; } case 5: { value = bitStream.ReadFloat(); break; } default: { Console.WriteLine("Unknown ProtoMessage WireType: {0}", wireType); bitStream.SeekBytes(0, SeekOrigin.End); return; } } if (value != null) { List<Object> fieldValues; if (this.Values.TryGetValue(fieldNumber.ToString(), out fieldValues)) { fieldValues.Add(value); } else { fieldValues = new List<Object>(); fieldValues.Add(value); this.Values.Add(fieldNumber.ToString(), fieldValues); } } } }