public void ParseStringTable(IBitStream reader, string tableName, DemoParser parser) { int numStrings = (int)reader.ReadInt(16); if (tableName == "modelprecache") { parser.modelprecache.Clear (); } for (int i = 0; i < numStrings; i++) { string stringName = reader.ReadString(); if (stringName.Length >= 100) throw new Exception("Roy said I should throw this."); if (reader.ReadBit()) { int userDataSize = (int)reader.ReadInt(16); byte[] data = reader.ReadBytes(userDataSize); if (tableName == "userinfo") { PlayerInfo info = PlayerInfo.ParseFrom(new BinaryReader(new MemoryStream(data))); parser.RawPlayers[int.Parse(stringName)] = info; } else if (tableName == "instancebaseline") { int classid = int.Parse(stringName); //wtf volvo? parser.instanceBaseline[classid] = data; } else if (tableName == "modelprecache") { parser.modelprecache.Add (stringName); } } } // Client side stuff if ( reader.ReadBit() ) { int numstrings = (int)reader.ReadInt(16); for ( int i = 0 ; i < numstrings; i++ ) { reader.ReadString(); // stringname if ( reader.ReadBit() ) { int userDataSize = ( int )reader.ReadInt(16); reader.ReadBytes( userDataSize ); } else { } } } }
public static Vector DecodeVector(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Normal)) { } Vector v = new Vector(); v.X = DecodeFloat(prop, reader); v.Y = DecodeFloat(prop, reader); if (!prop.Flags.HasFlagFast(SendPropertyFlags.Normal)) { v.Z = DecodeFloat(prop, reader); } else { bool isNegative = reader.ReadBit(); //v0v0v1v1 in original instead of margin. float absolute = v.X * v.X + v.Y * v.Y; if (absolute < 1.0f) { v.Z = (float)Math.Sqrt(1 - absolute); } else { v.Z = 0f; } if (isNegative) v.Z *= -1; } return v; }
/// <summary> /// Decodes the bytes in the packet-entites message. /// </summary> /// <param name="packetEntities">Packet entities.</param> /// <param name="reader">Reader.</param> /// <param name="parser">Parser.</param> public static void Apply(PacketEntities packetEntities, IBitStream reader, DemoParser parser) { int currentEntity = -1; for (int i = 0; i < packetEntities.UpdatedEntries; i++) { //First read which entity is updated currentEntity += 1 + (int)reader.ReadUBitInt(); //Find out whether we should create, destroy or update it. // Leave flag if (!reader.ReadBit()) { // enter flag if (reader.ReadBit()) { //create it var e = ReadEnterPVS(reader, currentEntity, parser); parser.Entities[currentEntity] = e; e.ApplyUpdate(reader); } else { // preserve / update Entity e = parser.Entities[currentEntity]; e.ApplyUpdate(reader); } } else { // leave / destroy parser.Entities [currentEntity].Leave (); parser.Entities[currentEntity] = null; //dunno, but you gotta read this. if (reader.ReadBit()) { } } } }
static float ReadBitNormal(IBitStream reader) { bool isNegative = reader.ReadBit(); uint fractVal = reader.ReadInt(NORMAL_FRACTIONAL_BITS); float value = (float)fractVal * NORMAL_RESOLUTION; if (isNegative) value *= -1; return value; }
static float ReadBitCoordMP(IBitStream reader, bool isIntegral, bool isLowPrecision) { int intval = 0, fractval = 0; float value = 0.0f; bool isNegative = false; bool inBounds = reader.ReadBit(); if (isIntegral) { // Read the required integer and fraction flags intval = reader.ReadBit() ? 1 : 0; // If we got either parse them, otherwise it's a zero. if (intval == 1) { // Read the sign bit isNegative = reader.ReadBit(); // If there's an integer, read it in // Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE] if (inBounds) { value = (float)( reader.ReadInt(11) + 1 ); } else { value = (float)( reader.ReadInt(14) + 1 ); } } } else { // Read the required integer and fraction flags intval = reader.ReadBit() ? 1 : 0; // Read the sign bit isNegative = reader.ReadBit(); // If we got either parse them, otherwise it's a zero. if (intval == 1) { // If there's an integer, read it in // Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE] if (inBounds) { value = (float)( reader.ReadInt(11) + 1 ); } else { value = (float)( reader.ReadInt(14) + 1 ); } } // If there's a fraction, read it in fractval = (int)reader.ReadInt(isLowPrecision ? 3 : 5); // Calculate the correct floating point value value = intval + ( (float)fractval * ( isLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION ) ); } if (isNegative) value = -value; return value; }
static float ReadBitCoord(IBitStream reader) { int intVal, fractVal; float value = 0; bool isNegative = false; // Read the required integer and fraction flags intVal = (int)reader.ReadInt(1); fractVal = (int)reader.ReadInt(1); // If we got either parse them, otherwise it's a zero. if (( intVal | fractVal ) != 0) { // Read the sign bit isNegative = reader.ReadBit(); // If there's an integer, read it in if (intVal == 1) { // Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE] intVal = (int)reader.ReadInt(14) + 1; //14 --> Coord int bits } //If there's a fraction, read it in if (fractVal == 1) { fractVal = (int)reader.ReadInt(COORD_FRACTIONAL_BITS); } value = intVal + ( (float)fractVal * COORD_RESOLUTION ); } if (isNegative) value *= -1; return value; }
public static void Apply(CreateStringTable table, IBitStream reader, DemoParser parser) { if (table.Name == "modelprecache") { while (parser.modelprecache.Count < table.MaxEntries) { parser.modelprecache.Add(null); } } if (reader.ReadBit()) throw new NotImplementedException("Encoded with dictionaries, unable to decode"); int nTemp = table.MaxEntries; int nEntryBits = 0; while ((nTemp >>= 1) != 0) ++nEntryBits; List<string> history = new List<string>(); int lastEntry = -1; for (int i = 0; i < table.NumEntries; i++) { int entryIndex = lastEntry + 1; // d in the entity-index if (!reader.ReadBit()) { entryIndex = (int)reader.ReadInt(nEntryBits); } lastEntry = entryIndex; // Read the name of the string into entry. string entry = ""; if (entryIndex < 0 || entryIndex >= table.MaxEntries) { throw new InvalidDataException("bogus string index"); } if (reader.ReadBit()) { bool substringcheck = reader.ReadBit(); if (substringcheck) { int index = (int)reader.ReadInt(5); int bytestocopy = (int)reader.ReadInt(5); entry = history[index].Substring(0, bytestocopy); entry += reader.ReadString(1024); } else { entry = reader.ReadString(1024); } } if (entry == null) entry = ""; if (history.Count > 31) history.RemoveAt(0); history.Add(entry); // Read in the user data. byte[] userdata = new byte[0]; if (reader.ReadBit()) { if (table.UserDataFixedSize) { userdata = reader.ReadBits(table.UserDataSizeBits); } else { int bytesToRead = (int)reader.ReadInt(14); userdata = reader.ReadBytes(bytesToRead); } } if (userdata.Length == 0) break; 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); parser.RawPlayers[entryIndex] = info; } else if (table.Name == "instancebaseline") { int classid = int.Parse(entry); //wtf volvo? parser.instanceBaseline[classid] = userdata; } else if (table.Name == "modelprecache") { parser.modelprecache[entryIndex] = entry; } } parser.stringTables.Add(table); }
public static void Apply(CreateStringTable table, IBitStream reader, DemoParser parser) { if (table.Name == "modelprecache") { while (parser.modelprecache.Count < table.MaxEntries) { parser.modelprecache.Add(null); } } if (reader.ReadBit()) { throw new NotImplementedException("Encoded with dictionaries, unable to decode"); } var nTemp = table.MaxEntries; var nEntryBits = 0; while ((nTemp >>= 1) != 0) { ++nEntryBits; } var history = new List <string>(); var lastEntry = -1; for (var i = 0; i < table.NumEntries; i++) { var entryIndex = lastEntry + 1; // d in the entity-index if (!reader.ReadBit()) { entryIndex = (int)reader.ReadInt(nEntryBits); } lastEntry = entryIndex; // Read the name of the string into entry. var entry = ""; if (entryIndex < 0 || entryIndex >= table.MaxEntries) { throw new InvalidDataException("bogus string index"); } if (reader.ReadBit()) { var substringcheck = reader.ReadBit(); if (substringcheck) { var index = (int)reader.ReadInt(5); var bytestocopy = (int)reader.ReadInt(5); entry = history[index].Substring(0, bytestocopy); entry += reader.ReadString(1024); } else { entry = reader.ReadString(1024); } } if (entry == null) { entry = ""; } if (history.Count > 31) { history.RemoveAt(0); } history.Add(entry); // Read in the user data. var userdata = new byte[0]; if (reader.ReadBit()) { if (table.UserDataFixedSize) { userdata = reader.ReadBits(table.UserDataSizeBits); } else { var bytesToRead = (int)reader.ReadInt(14); userdata = reader.ReadBytes(bytesToRead); } } if (userdata.Length == 0) { break; } if (table.Name == "userinfo") { // Now we'll parse the players out of it. var playerReader = new BinaryReader(new MemoryStream(userdata)); var info = PlayerInfo.ParseFrom(playerReader); parser.RawPlayers[entryIndex] = info; } else if (table.Name == "instancebaseline") { var classid = int.Parse(entry); //wtf volvo? parser.instanceBaseline[classid] = userdata; } else if (table.Name == "modelprecache") { parser.modelprecache[entryIndex] = entry; } } parser.stringTables.Add(table); }
/// <summary> /// Decodes a coarse format TIS-B airborne position message. /// </summary> /// <param name="message"></param> private void DecodeCoarseTisbAirbornePosition(AdsbMessage message) { message.MessageFormat = MessageFormat.CoarseTisbAirbornePosition; var subMessage = message.CoarseTisbAirbornePosition = new CoarseTisbAirbornePosition(); message.TisbIcaoModeAFlag = _BitStream.ReadByte(1); subMessage.SurveillanceStatus = (SurveillanceStatus)_BitStream.ReadByte(2); subMessage.ServiceVolumeID = _BitStream.ReadByte(4); var rawAltitude = _BitStream.ReadUInt16(12); var acCode = ((rawAltitude & 0xfe0) >> 1) | (rawAltitude & 0x0f); if ((rawAltitude & 0x10) != 0) { subMessage.BarometricAltitude = ModeSAltitudeConversion.CalculateBinaryAltitude(acCode); } else { subMessage.BarometricAltitude = ModeSAltitudeConversion.LookupGillhamAltitude(acCode); } var groundTrackValid = _BitStream.ReadBit(); var groundTrack = _BitStream.ReadByte(5); var groundSpeed = _BitStream.ReadByte(6); if (groundTrackValid) { subMessage.GroundTrack = (double)groundTrack * 11.25; } subMessage.GroundSpeed = (double)groundSpeed * 16.0; subMessage.CompactPosition = ExtractCprCoordinate(message, 12, ignoreMessageType: true); }
public void ParseStringTable(IBitStream reader, string tableName, DemoParser parser) { int numStrings = (int)reader.ReadInt(16); if (tableName == "modelprecache") { parser.modelprecache.Clear(); } for (int i = 0; i < numStrings; i++) { string stringName = reader.ReadString(); if (stringName.Length >= 100) { throw new Exception("Roy said I should throw this."); } if (reader.ReadBit()) { int userDataSize = (int)reader.ReadInt(16); byte[] data = reader.ReadBytes(userDataSize); if (tableName == "userinfo") { PlayerInfo info = PlayerInfo.ParseFrom(new BinaryReader(new MemoryStream(data))); parser.RawPlayers[int.Parse(stringName)] = info; } else if (tableName == "instancebaseline") { int classid = int.Parse(stringName); //wtf volvo? parser.instanceBaseline[classid] = data; } else if (tableName == "modelprecache") { parser.modelprecache.Add(stringName); } } } // Client side stuff if (reader.ReadBit()) { int numstrings = (int)reader.ReadInt(16); for (int i = 0; i < numstrings; i++) { reader.ReadString(); // stringname if (reader.ReadBit()) { int userDataSize = ( int )reader.ReadInt(16); reader.ReadBytes(userDataSize); } else { } } } }
public void ParseStringTableMessage(CSVCMsg_CreateStringTable table, DemoParser parser) { using (IBitStream reader = BitStreamUtil.Create(table.string_data)) { if (reader.ReadBit()) { throw new NotImplementedException("Encoded with dictionaries, unable to decode"); } int nTemp = table.max_entries; int nEntryBits = 0; while ((nTemp >>= 1) != 0) { ++nEntryBits; } List <string> history = new List <string>(); int lastEntry = -1; for (int i = 0; i < table.num_entries; i++) { int entryIndex = lastEntry + 1; // read in the entity-index if (!reader.ReadBit()) { entryIndex = (int)reader.ReadInt(nEntryBits); } lastEntry = entryIndex; // Read the name of the string into entry. string entry = ""; if (entryIndex < 0 || entryIndex >= table.max_entries) { throw new InvalidDataException("bogus string index"); } if (reader.ReadBit()) { bool substringcheck = reader.ReadBit(); if (substringcheck) { int index = (int)reader.ReadInt(5); int bytestocopy = (int)reader.ReadInt(5); entry = history[index].Substring(0, bytestocopy); entry += reader.ReadString(1024); } else { entry = reader.ReadString(1024); } } if (entry == null) { entry = ""; } if (history.Count > 31) { history.RemoveAt(0); } // Read in the user data. byte[] userdata = new byte[0]; if (reader.ReadBit()) { if (table.user_data_fixed_size) { userdata = reader.ReadBits(table.user_data_size_bits); } else { int bytesToRead = (int)reader.ReadInt(14); userdata = reader.ReadBytes(bytesToRead); } } 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); UpdatePlayer(info, parser); } } }
private static float ReadBitCoordMP(IBitStream reader, bool isIntegral, bool isLowPrecision) { int intval = 0, fractval = 0; var value = 0.0f; var isNegative = false; var inBounds = reader.ReadBit(); if (isIntegral) { // Read the required integer and fraction flags intval = reader.ReadBit() ? 1 : 0; // If we got either parse them, otherwise it's a zero. if (intval == 1) { // Read the sign bit isNegative = reader.ReadBit(); // If there's an integer, read it in // Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE] if (inBounds) { value = reader.ReadInt(11) + 1; } else { value = reader.ReadInt(14) + 1; } } } else { // Read the required integer and fraction flags intval = reader.ReadBit() ? 1 : 0; // Read the sign bit isNegative = reader.ReadBit(); // If we got either parse them, otherwise it's a zero. if (intval == 1) { // If there's an integer, read it in // Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE] if (inBounds) { value = reader.ReadInt(11) + 1; } else { value = reader.ReadInt(14) + 1; } } // If there's a fraction, read it in fractval = (int)reader.ReadInt(isLowPrecision ? 3 : 5); // Calculate the correct floating point value value = intval + (fractval * (isLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION)); } if (isNegative) { value = -value; } return(value); }