Exemple #1
0
        /// <summary>
        /// Unpacks all the files inside the BG file into a folder.
        /// </summary>
        public void Unpack()
        {
            Files.Clear();
            List <int> indices = Header.RealIndices;

            using (BinaryReader reader = new BinaryReader(new FileStream(FilePath, FileMode.Open)))
            {
                int fileCount  = Header.FileCount;
                int lastOffset = 64;
                reader.BaseStream.Seek(64, SeekOrigin.Begin);
                for (int i = 0; i < fileCount; i++)
                {
                    int    endOffset = indices[i] + 64;
                    int    length    = endOffset - lastOffset;
                    byte[] buffer    = reader.ReadBytes(length);
                    string directory = Path.GetDirectoryName(FilePath) + "\\" + Path.GetFileNameWithoutExtension(FilePath);
                    Directory.CreateDirectory(directory);
                    string fileName = directory + "\\" + i + "." + HeaderList.GetExtensionFromBuffer(buffer);
                    using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create)))
                    {
                        writer.Write(buffer);
                    }
                    Files.Add(HeaderList.GetTypeFromFile(fileName));
                    lastOffset = indices[i] + 64;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Unpacks all the files inside the PB file into a folder.
        /// </summary>
        public void Unpack()
        {
            Files.Clear();
            int index = 0;

            using (BinaryReader reader = new BinaryReader(new FileStream(FilePath, FileMode.Open)))
            {
                reader.BaseStream.Seek(8, SeekOrigin.Begin);
                while (reader.BaseStream.Length != reader.BaseStream.Position)
                {
                    byte[]       headerBytes = reader.ReadBytes(17);
                    PBFileHeader header      = new PBFileHeader(headerBytes);
                    if (header.Length == 0x00F7FFFF)
                    {
                        return;
                    }
                    byte[] buffer    = reader.ReadBytes(header.Length - 17);
                    string directory = Path.GetDirectoryName(FilePath) + "\\" + Path.GetFileNameWithoutExtension(FilePath);
                    Directory.CreateDirectory(directory);
                    string fileName = directory + "\\" + index + "." + HeaderList.GetExtensionFromBuffer(buffer);
                    using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create)))
                    {
                        writer.Write(buffer);
                    }
                    Files.Add(new PBFileEntry(header, HeaderList.GetTypeFromFile(fileName)));
                    index++;
                }
            }
            foreach (PBFileEntry file in Files)
            {
                if (file.File.GetType() == typeof(LZBFile))
                {
                    LZBFile lzb = (LZBFile)file.File;
                    lzb.Decompress();
                }
            }
        }