2019-01-26 00:39:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using LZ4;
|
|
|
|
|
|
|
|
|
|
namespace Roblox.BinaryFormat
|
|
|
|
|
{
|
|
|
|
|
public class RobloxBinaryChunk
|
|
|
|
|
{
|
|
|
|
|
public readonly string ChunkType;
|
|
|
|
|
|
|
|
|
|
public readonly int CompressedSize;
|
|
|
|
|
public readonly byte[] CompressedData;
|
|
|
|
|
|
|
|
|
|
public readonly int Size;
|
|
|
|
|
public readonly int Reserved;
|
|
|
|
|
public readonly byte[] Data;
|
|
|
|
|
|
|
|
|
|
public bool HasCompressedData => (CompressedSize > 0);
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2019-01-29 09:50:55 +00:00
|
|
|
|
return ChunkType + " Chunk [" + Size + " bytes]";
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RobloxBinaryReader GetReader(string chunkType)
|
|
|
|
|
{
|
|
|
|
|
if (ChunkType == chunkType)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream buffer = new MemoryStream(Data);
|
|
|
|
|
return new RobloxBinaryReader(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception("Expected " + chunkType + " ChunkType from the input RobloxBinaryChunk");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RobloxBinaryChunk(RobloxBinaryReader reader)
|
|
|
|
|
{
|
|
|
|
|
byte[] bChunkType = reader.ReadBytes(4);
|
|
|
|
|
ChunkType = Encoding.ASCII.GetString(bChunkType);
|
|
|
|
|
|
|
|
|
|
CompressedSize = reader.ReadInt32();
|
|
|
|
|
Size = reader.ReadInt32();
|
|
|
|
|
Reserved = reader.ReadInt32();
|
|
|
|
|
|
|
|
|
|
if (HasCompressedData)
|
|
|
|
|
{
|
|
|
|
|
CompressedData = reader.ReadBytes(CompressedSize);
|
|
|
|
|
Data = LZ4Codec.Decode(CompressedData, 0, CompressedSize, Size);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Data = reader.ReadBytes(Size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|