예제 #1
0
            public void Read(UnityBinaryReader reader)
            {
                signature = reader.ReadStringToNull();
                format    = reader.ReadIntBE();

                versionPlayer = reader.ReadStringToNull();
                versionEngine = reader.ReadStringToNull();
                bundleSize    = reader.ReadLongBE();
            }
예제 #2
0
        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);
            }
        }