private int readNextBlock(byte[] dest, int offset) { if (idx >= _infos.Length) { throw new IndexOutOfRangeException(); } switch (_infos[idx].flag) { default: _reader.ReadBytes(dest, offset, _infos[idx].uncompressedSize); break; case 1: // LZMA throw new NotSupportedException("LZMA is not supported"); case 2: // LZ4 case 3: // LZ4HC _reader.ReadLZ4Data(_infos[idx].compressedSize, _infos[idx].uncompressedSize, dest, offset); break; } return(_infos[idx++].uncompressedSize); }
private void readFiles(UnityBinaryReader reader) { int compressedSize = reader.ReadIntBE(); int uncompressedSize = reader.ReadIntBE(); int flag = reader.ReadIntBE(); UnityBinaryReader inforeader; if ((flag & 0x80) != 0) // At end of file { throw new NotImplementedException("BlockInfos are at the end of file"); } // Decompress Infos (if needed) int compressiontype = flag & 0x3F; switch (compressiontype) { default: // None inforeader = reader; break; case 1: // LZMA(Not Supported) throw new NotSupportedException("LZMA is not supported"); case 2: //LZ4 case 3: //LZ4HC { byte[] infobytes = MemoryPool <AssetBundleFile> .GetBuffer(uncompressedSize); reader.ReadLZ4Data(compressedSize, uncompressedSize, infobytes, 0); inforeader = new UnityBinaryReader(infobytes, 0, uncompressedSize); break; } } // Read Block Infos inforeader.Position += 0x10; int blockcount = inforeader.ReadIntBE(); var blockinfos = new BlockInfo[blockcount]; blockinfos.Read(inforeader); // Read File Infos int filecount = inforeader.ReadIntBE(); Files = new FileType[filecount]; long[] fileoffsets = new long[filecount]; for (int i = 0; i < filecount; i++) { Files[i] = new FileType(); fileoffsets[i] = inforeader.ReadLongBE(); Files[i].Data = new byte[inforeader.ReadLongBE()]; flag = inforeader.ReadIntBE(); Files[i].Name = inforeader.ReadStringToNull(); } // Read Directories BlockReader blockreader = new BlockReader(blockinfos, reader); for (int i = 0; i < filecount; i++) { blockreader.Seek((int)fileoffsets[i]); blockreader.ReadBytes(Files[i].Data, 0, Files[i].Data.Length); } }