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(); }
private void LoadUnityFs(UnityDataReader reader) { unityfsDescriptor = new UnityfsDescriptor(); unityfsDescriptor.fsFileSize = reader.ReadInt64(); unityfsDescriptor.ciblockSize = reader.ReadUInt32(); unityfsDescriptor.uiblockSize = reader.ReadUInt32(); var flags = reader.ReadUInt32(); var compression = (CompressionType)(flags & 0x3F); var blk = new UnityDataArrayReader(ReadCompressedData(reader, (int)unityfsDescriptor.ciblockSize, (int)unityfsDescriptor.uiblockSize, compression)); blk.ReadBytes(16); // guid // read Archive block infos var numBlocks = blk.ReadInt32(); ArchiveBlockInfo[] blocks = new ArchiveBlockInfo[numBlocks]; for (int i = 0; i < numBlocks; i++) { var busize = blk.ReadInt32(); var bcsize = blk.ReadInt32(); var bflags = blk.ReadInt16(); blocks[i] = new ArchiveBlockInfo(busize, bcsize, bflags); } // Read Asset data infos var numNodes = blk.ReadInt32(); AssetDataInfo[] nodes = new AssetDataInfo[numNodes]; for (int i = 0; i < numNodes; i++) { var offset = blk.ReadInt64(); var size = blk.ReadInt64(); var status = blk.ReadInt32(); var name = blk.ReadString(); nodes[i] = new AssetDataInfo(offset, size, status, name); } // read block storage var storage = new ArchiveBlockStorage(blocks, reader); foreach (var info in nodes) { storage.Seek(info.Offset); var asset = new Asset(this, storage, info.Name); Assets.Add(asset); } if (Assets.Count > 0) { Name = Assets[0].Name; } }
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()); }
public ArchiveBlockStorage(ArchiveBlockInfo[] blocks, UnityDataReader reader) { this.blocks = blocks; this.reader = reader; basePos = reader.Tell(); // sum up all block uncompressed sizes maxPos = 0; foreach (var block in blocks) { maxPos += block.UncompressedSize; } sought = false; Seek(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)); } }
public Asset(AssetBundle bundle, UnityDataReader reader, string name = "") { }