private int GetPayloadLength() { int length = 0; length = FastBitConverter.ToInt32(_messageBuffer, 0); return(length); }
public override void FromBinary(byte[] value) { if (value.Length > Pointer.Length) { throw new IndexOutOfRangeException(); } byte[] val = new byte[Pointer.Length]; Array.Copy(value, val, value.Length); this.value = FastBitConverter.ToInt32(val, 0); }
/// <summary> /// Creates a MapResources object from a byte array /// </summary> /// <param name="rawData">raw map resources file data</param> /// <returns>the parsed MapResources object</returns> public static MapResourcesFile Parse(byte[] rawData) { MapResourcesFile mapResourcesFile = new MapResourcesFile(); using (var memoryStream = new MemoryStream(rawData)) { using (var binaryReader = new BinaryReader(memoryStream, Encoding.Default, true)) { // Read the magic mapResourcesFile.Magic = binaryReader.ReadInt32(); // Read layer count (big-endian) var layerCountBytes = binaryReader.ReadBytes(4); int layerCount = FastBitConverter.ToInt32(layerCountBytes, 0, true); // Read layers for (int i = 0; i < layerCount; i++) { int stringLength = binaryReader.ReadInt32(); mapResourcesFile.Layers.Add(Encoding.UTF8.GetString(binaryReader.ReadBytes(stringLength))); } // Read asset type count (big-endian) var assetTypeCountBytes = binaryReader.ReadBytes(8); long assetTypeCount = FastBitConverter.ToInt64(assetTypeCountBytes, 0, true); // Read asset types for (int i = 0; i < assetTypeCount; i++) { int stringLength = binaryReader.ReadInt32(); mapResourcesFile.AssetTypes.Add(Encoding.UTF8.GetString(binaryReader.ReadBytes(stringLength))); } // Read assets count (big-endian) var assetCountBytes = binaryReader.ReadBytes(4); int assetCount = FastBitConverter.ToInt32(assetCountBytes, 0, true); // Read assets for (int i = 0; i < assetCount; i++) { var mapAsset = new MapAsset(); var assetTypeIndexBytes = binaryReader.ReadBytes(4); mapAsset.AssetTypeIndex = FastBitConverter.ToInt32(assetTypeIndexBytes, 0, true); int stringLength = binaryReader.ReadInt32(); mapAsset.Name = Encoding.UTF8.GetString(binaryReader.ReadBytes(stringLength)); // Read unknown data mapAsset.UnknownData1 = binaryReader.ReadInt32(); // Read the remaining unknown data (big-endian) var unknownData2Bytes = binaryReader.ReadBytes(4); mapAsset.UnknownData2 = FastBitConverter.ToInt32(unknownData2Bytes, 0, true); var unknownData3Bytes = binaryReader.ReadBytes(8); mapAsset.UnknownData3 = FastBitConverter.ToInt64(unknownData3Bytes, 0, true); var unknownData4Bytes = binaryReader.ReadBytes(8); mapAsset.UnknownData4 = FastBitConverter.ToInt64(unknownData4Bytes, 0, true); mapResourcesFile.Assets.Add(mapAsset); } // Read map count (big-endian) var mapCountBytes = binaryReader.ReadBytes(4); int mapCount = FastBitConverter.ToInt32(mapCountBytes, 0, true); // Read asset types for (int i = 0; i < mapCount; i++) { int stringLength = binaryReader.ReadInt32(); mapResourcesFile.Maps.Add(Encoding.UTF8.GetString(binaryReader.ReadBytes(stringLength))); } } } return(mapResourcesFile); }