Beispiel #1
0
        private byte[] ReadCompressedData(UnityDataReader reader, int ciblockSize, int uiblockSize, CompressionType compression)
        {
            if (compression == CompressionType.None)
            {
                return(reader.ReadBytes(ciblockSize));
            }

            if (compression == CompressionType.Lz4 || compression == CompressionType.Lz4hc)
            {
                var compressedData = reader.ReadBytes(ciblockSize);
                return(LZ4Codec.Decode(compressedData, 0, ciblockSize, uiblockSize));
            }
            throw new DecompressionException("Unsupported compression type: " + compression.ToString());
        }
Beispiel #2
0
        private void LoadRaw(UnityDataReader reader)
        {
            rawDescriptor            = new RawDescriptor();
            rawDescriptor.fileSize   = reader.ReadUInt32();
            rawDescriptor.headerSize = reader.ReadInt32();
            rawDescriptor.fileCount  = reader.ReadInt32();

            if (FormatVersion >= 2)
            {
                rawDescriptor.bundleSize = reader.ReadUInt32();

                if (FormatVersion >= 3)
                {
                    rawDescriptor.uncompressedBundleSize = reader.ReadUInt32();
                }
            }

            if (rawDescriptor.headerSize >= 60)
            {
                rawDescriptor.compressedFileSize = reader.ReadUInt32();
                rawDescriptor.assetHeaderSize    = reader.ReadUInt32();
            }

            reader.ReadInt32();
            reader.ReadBytes(1);
            Name = reader.ReadString();
        }
Beispiel #3
0
        public override byte[] ReadBytes(int count)
        {
            List <byte> buf  = new List <byte>();
            var         size = count;

            while (size != 0 && cursor < maxPos)
            {
                if (!IsInCurrentBlock(cursor))
                {
                    SeekToBlock(cursor);
                }
                var part = currentStream.ReadBytes(size);
                if (size > 0)
                {
                    Debug.Assert(part.Length != 0, "EOF error while reading and AssetBlockStorage");
                    size -= part.Length;
                }
                cursor += part.Length;
                buf.AddRange(part);
            }
            return(buf.ToArray());
        }
Beispiel #4
0
        void SeekToBlock(long pos)
        {
            Int32 baseOffset = 0;
            Int32 offset     = 0;

            foreach (var b in blocks)
            {
                if ((offset + b.UncompressedSize) > pos)
                {
                    currentBlock = b;
                    break;
                }
                baseOffset += b.compressedSize;
                offset     += b.UncompressedSize;
            }

            this.reader.Seek(basePos + baseOffset);
            if (currentBlock != null)
            {
                var buf = reader.ReadBytes(currentBlock.compressedSize);

                currentStream = new UnityDataArrayReader(currentBlock.Decompress(buf));
            }
        }