Problem is in CompressedChunkBlock.Deserialize - you can't read BlockCompressedData directly after reading BlockHeader, because first is BlockCount * BlockHeader then BlockCount * BlockCompressedData.
Compressed UE package:
// LZOChunk:
UncompressedOffset
UncompressedSize
CompressedOffset
CompressedSize
// CompressedChunk:
Signature
BlockSize
CompressedChunkSize
UncompressedChunkSize
// CompressedBlock:
// BlockCount * CompressedBlockHeader
CompressedBlockSize;
UncompressedBlockSize;
// BlockCount * CompressedBlockData
CompressedBlockData;
Try this:
Compressed UE package:
// LZOChunk:
UncompressedOffset
UncompressedSize
CompressedOffset
CompressedSize
// CompressedChunk:
Signature
BlockSize
CompressedChunkSize
UncompressedChunkSize
// CompressedBlock:
// BlockCount * CompressedBlockHeader
CompressedBlockSize;
UncompressedBlockSize;
// BlockCount * CompressedBlockData
CompressedBlockData;
Try this:
Code:
public struct CompressedChunkHeader : IUnrealDeserializableClass
{
private uint _Signature;
private int _BlockSize;
private int _CompressedSize;
private int _UncompressedSize;
public CompressedChunkBlock[] Blocks;//UArray<CompressedChunkBlock> Blocks;
public void Deserialize(BinaryReader stream)//IUnrealStream stream)
{
_Signature = stream.ReadUInt32();
if (_Signature != 2653586369)//UnrealPackage.Signature)
throw new System.IO.FileLoadException("Unrecognized signature!");
_BlockSize = stream.ReadInt32();
_CompressedSize = stream.ReadInt32();
_UncompressedSize = stream.ReadInt32();
int BlockCount = (int)Math.Ceiling(_UncompressedSize / (float)_BlockSize);
Blocks = new CompressedChunkBlock[BlockCount];//UArray<CompressedChunkBlock>(stream, blockCount);
int BlockHeaderOffset = (int)stream.BaseStream.Position;
int CompressedBlockOffset = BlockHeaderOffset + BlockCount * 8;
// Bypass of your UArray...
for (int i = 0; i < Blocks.Length; i++)
{
CompressedChunkBlock inBlock = new CompressedChunkBlock();
stream.BaseStream.Position = BlockHeaderOffset;
inBlock.Deserialize(stream);
BlockHeaderOffset += 8;
stream.BaseStream.Position = CompressedBlockOffset;
inBlock._CompressedData = stream.ReadBytes(inBlock._CompressedSize);
CompressedBlockOffset += inBlock._CompressedSize;
Blocks[i] = inBlock;
}
}
public struct CompressedChunkBlock : IUnrealDeserializableClass
{
public int _CompressedSize;
public int _UncompressedSize;
public byte[] _CompressedData;
public void Deserialize(BinaryReader stream)//IUnrealStream stream)
{
_CompressedSize = stream.ReadInt32();
_UncompressedSize = stream.ReadInt32();
}
public byte[] Decompress()
{
var _DecompressedData = new byte[_UncompressedSize];
ManagedLZO.MiniLZO.Decompress( _CompressedData, _DecompressedData );
return _DecompressedData;
}
}
}