示例#1
0
        private void ReadPre530Metadata(BundleReader reader, out Stream dataStream, out long metadataOffset)
        {
            switch (Header.Type)
            {
            case BundleType.UnityRaw:
            {
                Metadata.Read(reader);
                dataStream     = reader.BaseStream;
                metadataOffset = Header.HeaderSize;
            }
            break;

            case BundleType.UnityWeb:
            {
                // read only last chunk. wtf?
                ChunkInfo    chunkInfo = Header.ChunkInfos[Header.ChunkInfos.Count - 1];
                MemoryStream stream    = new MemoryStream(new byte[chunkInfo.DecompressedSize]);
                SevenZipHelper.DecompressLZMASizeStream(reader.BaseStream, chunkInfo.CompressedSize, stream);
                using (BundleReader decompressReader = new BundleReader(stream, reader.EndianType, reader.Type, reader.Generation))
                {
                    Metadata.Read(decompressReader);
                }
                dataStream     = stream;
                metadataOffset = 0;
            }
            break;

            default:
                throw new NotSupportedException($"Bundle type {Header.Type} isn't supported for pre530 generation");
            }
        }
示例#2
0
        private void ReadScheme()
        {
            using (PartialStream stream = new PartialStream(m_stream, m_offset, m_size))
            {
                using (EndianReader reader = new EndianReader(stream, EndianType.BigEndian))
                {
                    Header.Read(reader);
                }

                long headerSize = stream.Position;
                using (BundleReader reader = new BundleReader(stream, EndianType.BigEndian, Header.Generation))
                {
                    if (reader.Generation < BundleGeneration.BF_530_x)
                    {
                        using (SmartStream dataStream = ReadPre530Metadata(reader))
                        {
                            ReadPre530Blocks(dataStream);
                        }
                    }
                    else
                    {
                        using (SmartStream dataStream = Read530Metadata(reader, headerSize))
                        {
                            Read530Blocks(dataStream, headerSize);
                        }
                    }
                }
            }
        }
示例#3
0
        private SmartStream ReadPre530Metadata(BundleReader reader)
        {
            switch (Header.Type)
            {
            case BundleType.UnityRaw:
            {
                Metadata.Read(reader);
                return(m_stream.CreateReference());
            }

            case BundleType.UnityWeb:
            {
                // read only last chunk. wtf?
                ChunkInfo chunkInfo = Header.ChunkInfos[Header.ChunkInfos.Count - 1];
                using (SmartStream stream = SmartStream.CreateMemory(new byte[chunkInfo.DecompressedSize]))
                {
                    SevenZipHelper.DecompressLZMASizeStream(reader.BaseStream, chunkInfo.CompressedSize, stream);
                    using (BundleReader decompressReader = new BundleReader(stream, reader.EndianType, reader.Generation))
                    {
                        Metadata.Read(decompressReader);
                    }
                    return(stream.CreateReference());
                }
            }

            default:
                throw new NotSupportedException($"Bundle type {Header.Type} isn't supported before 530 generation");
            }
        }
示例#4
0
        public void Read(BundleReader reader)
        {
            if (HasBlockInfo(reader.Type, reader.Generation))
            {
                Unknown0   = reader.ReadInt32();
                Unknown1   = reader.ReadInt32();
                Unknown2   = reader.ReadInt32();
                Unknown3   = reader.ReadInt32();
                BlockInfos = reader.ReadBundleArray <BlockInfo>();
            }

            Entries = reader.ReadBundleArray <BundleFileEntry>();
        }
示例#5
0
 public void Read(BundleReader reader)
 {
     if (HasBlocksInfo(reader.Signature))
     {
         BlocksInfo.Read(reader);
         if (reader.Flags.IsBlocksAndDirectoryInfoCombined())
         {
             DirectoryInfo.Read(reader);
         }
     }
     else
     {
         DirectoryInfo.Read(reader);
         reader.AlignStream();
     }
 }
        private void ReadMetadata(Stream stream, int metadataSize)
        {
            long metadataPosition = stream.Position;

            using (BundleReader reader = new BundleReader(stream, EndianType.BigEndian, Header.Signature, Header.Version, Header.Flags))
            {
                Metadata.Read(reader);
            }
            if (metadataSize > 0)
            {
                if (stream.Position - metadataPosition != metadataSize)
                {
                    throw new Exception($"Read {stream.Position - metadataPosition} but expected {metadataSize}");
                }
            }
        }
示例#7
0
 public void Read(BundleReader reader)
 {
     if (HasBlobIndex(reader.Generation))
     {
         Offset     = reader.ReadInt64();
         Size       = reader.ReadInt64();
         BlobIndex  = reader.ReadInt32();
         NameOrigin = reader.ReadStringZeroTerm();
     }
     else
     {
         NameOrigin = reader.ReadStringZeroTerm();
         Offset     = reader.ReadInt32();
         Size       = reader.ReadInt32();
     }
     Name = FilenameUtils.FixFileIdentifier(NameOrigin);
 }
示例#8
0
 public void Read(BundleReader reader)
 {
     if (HasBlobIndex(reader.Signature))
     {
         Offset     = reader.ReadInt64();
         Size       = reader.ReadInt64();
         BlobIndex  = reader.ReadInt32();
         PathOrigin = reader.ReadStringZeroTerm();
     }
     else
     {
         PathOrigin = reader.ReadStringZeroTerm();
         Offset     = reader.ReadInt32();
         Size       = reader.ReadInt32();
     }
     Path = FilenameUtils.FixFileIdentifier(PathOrigin);
 }
示例#9
0
        private void ReadScheme(Stream stream)
        {
            using (EndianReader reader = new EndianReader(stream, EndianType.BigEndian))
            {
                Header.Read(reader);
            }

            using (BundleReader reader = new BundleReader(stream, EndianType.BigEndian, Header.Generation))
            {
                if (reader.Generation < BundleGeneration.BF_530_x)
                {
                    ReadPre530Metadata(reader, out Stream dataStream, out long metadataOffset);
                    ReadPre530Data(dataStream, metadataOffset);
                }
                else
                {
                    long headerSize = stream.Position;
                    Read530Metadata(reader, headerSize);
                    Read530Data(stream, headerSize);
                }
            }
        }
示例#10
0
    void OnGUI()
    {
        bundleName = GUI.TextField(new Rect(0, 0, 256, 32), bundleName);
        assetName = GUI.TextField(new Rect(256, 0, 256, 32), assetName);
        if (GUI.Button(new Rect(512, 0, 64, 32), "Load"))
        {
            BundleReader.GetInstance().AsyncLoad(bundleName, assetName, delegate(AssetRef ar)
            {
                if(ar!=null)
                {
                    go = GameObject.Instantiate(ar.asset) as GameObject ;
                    this.ar = ar;
                }
                else
                {
                    Debug.LogWarning("Load fail");
                }
            });
        }

        if (GUI.Button(new Rect(576, 0, 64, 32), "Delete"))
        {
            if(go != null)
            {
                GameObject.Destroy(go);
                ar.Release();
                go = null;
                ar = null;
            }
        }

        if (GUI.Button(new Rect(0, 64, 64, 32), "Print"))
        {
            BundleReader.GetInstance().PrintBundles();
        }
    }
示例#11
0
 public void Read(BundleReader reader)
 {
     DecompressedSize = reader.ReadUInt32();
     CompressedSize   = reader.ReadUInt32();
     Flags            = (BundleFlag)reader.ReadUInt16();
 }
 public void Read(BundleReader reader)
 {
     Nodes = reader.ReadBundleArray <Node>();
 }
示例#13
0
        private void Read530Metadata(BundleReader reader, long headerSize)
        {
            if (Header.Flags.IsMetadataAtTheEnd())
            {
                reader.BaseStream.Position = Header.BundleSize - Header.MetadataCompressedSize;
            }

            BundleCompressType metaCompression = Header.Flags.GetCompression();

            switch (metaCompression)
            {
            case BundleCompressType.None:
            {
                Metadata.Read(reader);
                long expectedPosition = Header.Flags.IsMetadataAtTheEnd() ? Header.BundleSize : headerSize + Header.MetadataDecompressedSize;
                if (reader.BaseStream.Position != expectedPosition)
                {
                    throw new Exception($"Read {reader.BaseStream.Position - headerSize} but expected {Header.MetadataDecompressedSize}");
                }
            }
            break;

            case BundleCompressType.LZMA:
            {
                using (MemoryStream stream = new MemoryStream(new byte[Header.MetadataDecompressedSize]))
                {
                    SevenZipHelper.DecompressLZMASizeStream(reader.BaseStream, Header.MetadataCompressedSize, stream);
                    using (BundleReader decompressReader = new BundleReader(stream, reader.EndianType, reader.Type, reader.Generation))
                    {
                        Metadata.Read(decompressReader);
                    }
                    if (stream.Position != Header.MetadataDecompressedSize)
                    {
                        throw new Exception($"Read {stream.Position} but expected {Header.MetadataDecompressedSize}");
                    }
                }
            }
            break;

            case BundleCompressType.LZ4:
            case BundleCompressType.LZ4HZ:
            {
                using (MemoryStream stream = new MemoryStream(new byte[Header.MetadataDecompressedSize]))
                {
                    using (Lz4DecodeStream decodeStream = new Lz4DecodeStream(reader.BaseStream, Header.MetadataCompressedSize))
                    {
                        decodeStream.ReadBuffer(stream, Header.MetadataDecompressedSize);
                    }

                    stream.Position = 0;
                    using (BundleReader decompressReader = new BundleReader(stream, reader.EndianType, reader.Type, reader.Generation))
                    {
                        Metadata.Read(decompressReader);
                    }
                    if (stream.Position != Header.MetadataDecompressedSize)
                    {
                        throw new Exception($"Read {stream.Position} but expected {Header.MetadataDecompressedSize}");
                    }
                }
            }
            break;

            default:
                throw new NotSupportedException($"Bundle compression '{metaCompression}' isn't supported");
            }
        }
示例#14
0
 public void Read(BundleReader reader)
 {
     Read((EndianReader)reader);
 }
示例#15
0
 public void Read(BundleReader reader)
 {
     UncompressedSize = reader.ReadUInt32();
     CompressedSize   = reader.ReadUInt32();
     Flags            = (StorageBlockFlags)reader.ReadUInt16();
 }
示例#16
0
 public void Awake()
 {
     instance = this;
     InitDepMap();
 }