Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some stuff to add/remove...
#9
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:
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;
                    }
                }
            }
Reply


Messages In This Thread
Some stuff to add/remove... - by VendorX - 07-01-2013, 03:26 AM
RE: Some stuff to add/remove... - by eliot - 07-01-2013, 07:32 AM
RE: Some stuff to add/remove... - by VendorX - 07-01-2013, 09:25 AM
RE: Some stuff to add/remove... - by eliot - 07-01-2013, 09:38 AM
RE: Some stuff to add/remove... - by VendorX - 07-01-2013, 10:22 AM
RE: Some stuff to add/remove... - by eliot - 07-01-2013, 10:40 AM
RE: Some stuff to add/remove... - by VendorX - 07-01-2013, 11:19 AM
RE: Some stuff to add/remove... - by eliot - 07-06-2013, 02:33 PM
RE: Some stuff to add/remove... - by VendorX - 07-07-2013, 05:54 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)