Пример #1
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var metaOffset     = BlockSize;
            var blockOffset    = metaOffset + _header.entryCount * MetaSize;
            var blockOffsetEnd = blockOffset + BlockOffsetHeaderSize + files.Count * BlockOffsetSize;
            var fileOffset     = (blockOffsetEnd + (BlockSize - 1)) & ~(BlockSize - 1);

            // Write files
            var blockOffsets = new List <NlpBlockOffset>();
            var metas        = Enumerable.Repeat(new NlpMeta(), _header.entryCount).ToArray();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <NlpArchiveFileInfo>())
            {
                // Write file
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);
                bw.WriteAlignment(BlockSize);

                // Update meta entry
                AdjustMeta(file);
                metas[file.Id] = file.Meta;

                // Add block offset entry
                blockOffsets.Add(new NlpBlockOffset
                {
                    metaId = file.Id,
                    offset = (filePosition - BlockSize) / BlockSize
                });

                filePosition += (int)((writtenSize + (BlockSize - 1)) & ~(BlockSize - 1));
            }

            // Write metas
            output.Position = metaOffset;
            bw.WriteMultiple(metas);

            // Write block offsets
            output.Position = blockOffset;
            bw.WriteType(new NlpBlockOffsetHeader
            {
                entryCount = files.Count,
                offset     = blockOffset + BlockOffsetHeaderSize - BlockSize
            });
            bw.WriteMultiple(blockOffsets);
            bw.WriteAlignment(BlockSize);

            // Write header
            output.Position = 0;

            _header.fileBlockOffset    = (fileOffset - BlockSize) / BlockSize;
            _header.entryCount         = metas.Length;
            _header.blockEntriesOffset = blockOffset - BlockSize;
            _header.unkOffset          = blockOffsetEnd - BlockSize;
            bw.WriteType(_header);
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="output"></param>
 /// <returns></returns>
 public bool Save(Stream output)
 {
     using (var bw = new BinaryWriterX(output, true))
     {
         bw.WriteType(_header);
         bw.BaseStream.Position = 0x40;
         bw.WriteMultiple(_padding);
         var offsetTablePos = bw.BaseStream.Position;
         bw.BaseStream.Position += (0x14 * _header.FileCount);
         foreach (var b in Bitmaps)
         {
             bw.WriteString(b.Name, System.Text.Encoding.ASCII, false, true);
         }
         var newOffsets = new List <OffsetEntry>();
         foreach (var b in Bitmaps)
         {
             var kbi = b as KsltBitmapInfo;
             newOffsets.Add(new OffsetEntry()
             {
                 Offset = (int)bw.BaseStream.Position
             });
             kbi.Header.Width    = (short)kbi.Image.Width;
             kbi.Header.Height   = (short)kbi.Image.Height;
             kbi.Header.DataSize = kbi.ImageData.Length;
             bw.WriteType(kbi.Header);
             bw.Write(kbi.ImageData);
         }
         bw.BaseStream.Position = offsetTablePos;
         bw.WriteMultiple(newOffsets);
     }
     return(true);
 }
Пример #3
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var entryOffset = 0x20;
            var fileOffset  = (entryOffset + 4 + files.Count * 8 + 0x7F) & ~0x7F;

            // Write files
            var offsets = new List <int>();
            var sizes   = new List <int>();

            output.Position = fileOffset;
            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                fileOffset = (int)output.Position;
                var writtenSize = file.SaveFileData(output);

                bw.WriteAlignment(0x80);

                offsets.Add(fileOffset);
                sizes.Add((int)writtenSize);
            }

            // Write entries
            output.Position = entryOffset;

            bw.Write(files.Count);
            bw.WriteMultiple(offsets);
            bw.WriteMultiple(sizes);

            // Write header
            output.Position = 0;
            bw.Write(_header);
        }
Пример #4
0
        /// <summary>
        /// Saves the metadata and files into a PAC archive.
        /// </summary>
        /// <param name="output">An output stream for a PAC archive.</param>
        /// <param name="files">The files to save.</param>
        /// <returns>True if successful.</returns>
        public bool Save(Stream output, IList <ArchiveFileInfo> files)
        {
            using (var bw = new BinaryWriterX(output, true))
            {
                // Header
                bw.WriteType(_header);
                var offsetPosition = bw.BaseStream.Position;

                // Skip Offsets
                bw.BaseStream.Position += _header.FileCount * sizeof(int);
                bw.WriteAlignment(EntryAlignment);

                // Entries
                bw.WriteMultiple(_entries);
                bw.WriteAlignment(FileAlignment);

                // Files
                var offsets = new List <int>();
                foreach (var afi in files)
                {
                    offsets.Add((int)bw.BaseStream.Position);
                    bw.Write((int)afi.FileSize);
                    bw.Write(FileAlignment);
                    bw.WriteAlignment(FileAlignment);
                    afi.SaveFileData(bw.BaseStream, null);
                    bw.WriteAlignment(FileAlignment);
                }

                // Offsets
                bw.BaseStream.Position = offsetPosition;
                bw.WriteMultiple(offsets);
            }

            return(true);
        }
Пример #5
0
        public void Save(Stream binOutput, Stream arcOutput, IList <IArchiveFileInfo> files)
        {
            using var binBw = new BinaryWriterX(binOutput);
            using var arcBw = new BinaryWriterX(arcOutput);

            // Calculate offsets
            var fileOffset    = 0x10;
            var entryOffset   = 0x20;
            var offsetsOffset = entryOffset + files.Count * EntrySize;
            var stringOffset  = offsetsOffset + ((files.Count * 4 + 0xF) & ~0xF);

            // Write files
            var offsets = new List <int>();
            var entries = new List <PaaEntry>();

            var filePosition   = fileOffset;
            var stringPosition = stringOffset;

            foreach (var file in files.Cast <PaaArchiveFileInfo>())
            {
                arcOutput.Position = filePosition;
                var writtenSize = file.SaveFileData(arcOutput);
                arcBw.WriteAlignment();

                file.Entry.size       = (int)writtenSize;
                file.Entry.nameOffset = stringPosition;

                offsets.Add(filePosition);
                entries.Add(file.Entry);

                filePosition   += ((int)writtenSize + 0xF) & ~0xF;
                stringPosition += (file.FilePath.ToRelative().FullName.Length + 1 + 0xF) & ~0xF;
            }

            // Write strings
            binOutput.Position = stringOffset;
            foreach (var file in files)
            {
                binBw.WriteString(file.FilePath.ToRelative().FullName, Encoding.ASCII, false);
                binBw.WriteAlignment();
            }

            // Write offsets
            binOutput.Position = offsetsOffset;
            binBw.WriteMultiple(offsets);

            // Write entries
            binOutput.Position = entryOffset;
            binBw.WriteMultiple(entries);

            // Write header
            binOutput.Position = 0;

            _header.fileCount     = files.Count;
            _header.entryOffset   = entryOffset;
            _header.offsetsOffset = offsetsOffset;
            _header.unk2          = _header.fileCount / 2;
            binBw.WriteType(_header);
        }
Пример #6
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output, _header.byteOrder);

            // Calculate offsets
            var sizeOffset         = HeaderSize;
            var unknownValueOffset = sizeOffset + files.Count * 4;
            var dataOffset         = unknownValueOffset + files.Count * 8;

            // Write files
            var offsets = new List <int>();

            foreach (var file in files.Cast <PackArchiveFileInfo>())
            {
                offsets.Add(dataOffset);

                // Write file name
                output.Position = dataOffset + 8;
                bw.WriteString(file.FilePath.GetName(), Encoding.ASCII, false);

                // Pad to file start
                var alignment = PackSupport.GetAlignment(file.FilePath.GetExtensionWithDot());
                output.Position = dataOffset + 0x28;
                bw.WriteAlignment(alignment);
                file.Entry.fileStart = (short)(output.Position - dataOffset);

                // Write file data
                output.Position = dataOffset + file.Entry.fileStart;
                var writtenSize = file.SaveFileData(output);
                var nextOffset  = output.Position;

                // Write file entry
                file.Entry.fileSize = (uint)writtenSize;
                output.Position     = dataOffset;
                bw.WriteType(file.Entry);

                dataOffset = (int)nextOffset;
            }

            // Write unknown values
            output.Position = unknownValueOffset;
            bw.WriteMultiple(_unknownValues);

            // Write offsets
            output.Position = sizeOffset;
            bw.WriteMultiple(offsets);

            // Write header
            _header.fileCount = (short)files.Count;
            _header.size      = (int)output.Length;

            output.Position = 0;
            bw.WriteType(_header);
        }
Пример #7
0
        public void Save(Stream output, IList <ImageInfo> imageInfos)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var unkRegionOffset = HeaderSize;
            var offsetsOffset   = unkRegionOffset + imageInfos.Count * 4;
            var dataOffset      = offsetsOffset + imageInfos.Count * 4;

            // Write image data
            var offsets = new List <int>();

            output.Position = dataOffset;
            foreach (var imageInfo in imageInfos.Cast <G1tImageInfo>())
            {
                offsets.Add((int)(output.Position - offsetsOffset));

                // Update entry
                imageInfo.Entry.Width  = imageInfo.ImageSize.Width;
                imageInfo.Entry.Height = imageInfo.ImageSize.Height;
                imageInfo.Entry.format = (byte)imageInfo.ImageFormat;

                // Write entry
                bw.WriteType(imageInfo.Entry);

                // Write image data
                bw.Write(imageInfo.ImageData);

                // Write mips
                if (imageInfo.MipMapCount > 0)
                {
                    foreach (var mip in imageInfo.MipMapData)
                    {
                        bw.Write(mip);
                    }
                }
            }

            // Write offsets
            output.Position = offsetsOffset;
            bw.WriteMultiple(offsets);

            // Write unknown region
            output.Position = unkRegionOffset;
            bw.WriteMultiple(_unkRegion);

            // Write header
            _header.dataOffset = offsetsOffset;
            _header.texCount   = imageInfos.Count;
            _header.fileSize   = (int)output.Length;

            output.Position = 0;
            bw.WriteType(_header);
        }
Пример #8
0
        public static long Build(Stream output, IList <IArchiveFileInfo> files)
        {
            var hash = new Kryptography.Hash.Sha256();

            using var bw = new BinaryWriterX(output, true);

            var inOffset = output.Position;

            // Write file data
            bw.BaseStream.Position = inOffset + _exeFsHeaderSize;
            var filePosition = bw.BaseStream.Position;

            IList <NcchExeFsFileEntry>     fileEntries = new List <NcchExeFsFileEntry>(MaxFiles_);
            IList <NcchExeFsFileEntryHash> fileHashes  = new List <NcchExeFsFileEntryHash>(MaxFiles_);
            var fileOffset = 0;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                var writtenSize = file.SaveFileData(bw.BaseStream);

                bw.WriteAlignment(MediaSize_);

                fileEntries.Add(new NcchExeFsFileEntry
                {
                    name   = file.FilePath.GetName().PadRight(8, '\0'),
                    offset = fileOffset,
                    size   = (int)writtenSize
                });
                fileHashes.Add(new NcchExeFsFileEntryHash
                {
                    hash = hash.Compute(new SubStream(output, filePosition + fileOffset, writtenSize))
                });

                fileOffset = (int)(bw.BaseStream.Position - filePosition);
            }

            var finalSize = bw.BaseStream.Position - inOffset;

            // Write file entries
            bw.BaseStream.Position = inOffset;
            bw.WriteMultiple(fileEntries);
            bw.WritePadding(_exeFsFileEntrySize * (MaxFiles_ - fileEntries.Count));

            // Write reserved data
            bw.WritePadding(0x20);

            // Write file entry hashes
            bw.WritePadding(_exeFsFileEntryHashSize * (MaxFiles_ - fileEntries.Count));
            bw.WriteMultiple(fileHashes.Reverse());

            output.Position = inOffset + finalSize;
            return(finalSize);
        }
Пример #9
0
        public void Save(Stream viwStream, Stream infStream, Stream dataStream, IList <IArchiveFileInfo> files)
        {
            using var infBw = new BinaryWriterX(infStream);
            using var viwBw = new BinaryWriterX(viwStream);

            // Calculate offset
            var entryOffset = InfHeaderSize;
            var metaOffset  = entryOffset + files.Count * InfEntrySize;

            // Write files
            var entries = new List <ViwInfEntry>();

            var filePosition = 0;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                dataStream.Position = filePosition;
                var writtenSize = file.SaveFileData(dataStream);

                entries.Add(new ViwInfEntry
                {
                    offset   = filePosition,
                    compSize = (int)writtenSize
                });

                filePosition += (int)((writtenSize + 3) & ~3);
            }

            // Write metas
            infStream.Position = metaOffset;
            infBw.WriteMultiple(_metas);

            // Write entries
            infStream.Position = entryOffset;
            infBw.WriteMultiple(entries);

            // Write inf header
            infStream.Position = 0;
            infBw.WriteType(new ViwInfHeader
            {
                fileCount   = files.Count,
                metaCount   = _metas.Count,
                entryOffset = entryOffset,
                metaOffset  = metaOffset
            });

            // Write name entries
            viwBw.WriteMultiple(_nameEntries);
        }
Пример #10
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            var dataPosition = (_headerSize + (files.Count + 1) * 4 + 0x7F) & ~0x7F;

            using var bw = new BinaryWriterX(output);

            // Write files
            bw.BaseStream.Position = dataPosition;

            var offsets = new List <uint>();

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                offsets.Add((uint)bw.BaseStream.Position);

                file.SaveFileData(bw.BaseStream, null);
                bw.WriteAlignment(0x80);
            }

            // Write offsets
            bw.BaseStream.Position = _headerSize;
            bw.WriteMultiple(offsets);
            bw.Write(bw.BaseStream.Length);

            // Write header
            bw.BaseStream.Position = 0;
            bw.WriteType(new PcHeader
            {
                entryCount = (short)files.Count
            });
        }
Пример #11
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            // Wrap encryption
            output = new XorStream(output, _selectedKey);

            using var bw = new BinaryWriterX(output, ByteOrder.BigEndian);

            // Calculate offsets
            var sizeOffset = 2 + files.Sum(x => Encoding.UTF8.GetByteCount(x.FilePath.ToRelative().FullName)) + files.Count * 2;
            var dataOffset = sizeOffset + 2 + files.Count * 4;

            // Write files
            output.Position = dataOffset;
            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                file.SaveFileData(output);
            }

            // Write sizes
            output.Position = sizeOffset;
            bw.Write((short)files.Count);
            bw.WriteMultiple(files.Select(x => (int)x.FileSize));

            // Write names
            output.Position = 0;
            bw.Write((short)files.Count);
            foreach (var file in files)
            {
                var name = file.FilePath.ToRelative().FullName;

                bw.Write((short)Encoding.UTF8.GetByteCount(name));
                bw.WriteString(name, Encoding.UTF8, false, false);
            }
        }
Пример #12
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var sizeOffset = HeaderSize;
            var fileOffset = (sizeOffset + files.Count * 4 + 0xF) & ~0xF;

            // Write files
            var sizes = new List <int>();

            output.Position = fileOffset;
            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                var writtenSize = file.SaveFileData(output);
                sizes.Add((int)writtenSize);
            }

            // Write sizes
            output.Position = sizeOffset;
            bw.WriteMultiple(sizes);

            // Write header
            output.Position = 0;
            bw.WriteType(new FbinHeader
            {
                fileCount  = files.Count,
                dataOffset = fileOffset
            });
        }
Пример #13
0
        public void Save(StreamInfo output, PhysicalDirectoryNode fileSystem, int versionIndex = 0)
        {
            fileSystem.AddFile("archive.data");
            var dataStream = fileSystem.GetFileNode("archive.data").Open();

            using (var bwData = new BinaryWriterX(dataStream, false))
                using (var bw = new BinaryWriterX(output.FileData, LeaveOpen))
                {
                    var header = new Header {
                        fileCount = Files.Count
                    };
                    var entries = new List <FileEntry>();

                    var offset = 0;
                    foreach (var file in Files)
                    {
                        file.FileData.CopyTo(bwData.BaseStream);
                        entries.Add(new FileEntry
                        {
                            offset     = offset,
                            size       = (int)file.FileData.Length,
                            name       = Path.GetFileName(file.FileName),
                            nameLength = Encoding.UTF8.GetByteCount(Path.GetFileName(file.FileName))
                        });

                        offset += (int)file.FileData.Length;
                    }

                    bw.WriteType(header);
                    bw.WriteMultiple(entries);
                }
        }
Пример #14
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var entryOffset = 4;
            var fileOffset  = entryOffset + files.Count * EntrySize;

            // Write files
            var entries = new List <TD1Entry>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                entries.Add(new TD1Entry
                {
                    offset = filePosition >> 2,
                    size   = (int)writtenSize
                });

                filePosition += (int)((writtenSize + 3) & ~3);
            }

            // Write entries
            output.Position = entryOffset;
            bw.WriteMultiple(entries);

            // Write file count
            output.Position = 0;
            bw.WriteType(files.Count);
        }
Пример #15
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var entryOffset = HeaderSize;
            var fileOffset  = entryOffset + files.Count * EntrySize;

            // Write files
            var entries = new List <ObbEntry>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ObbArchiveFileInfo>())
            {
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                file.Entry.offset = filePosition;
                file.Entry.size   = (int)writtenSize;
                entries.Add(file.Entry);

                filePosition += (int)writtenSize;
            }

            // Write entries
            output.Position = entryOffset;
            bw.WriteMultiple(entries);

            // Write header
            output.Position = 0;

            _header.fileCount = files.Count;
            bw.WriteType(_header);
        }
Пример #16
0
        public void Save(Stream output, IArchiveFileInfo file)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var sizeOffset = HeaderSize;
            var blockCount = file.ContentChanged ? (int)Math.Ceiling(file.FileSize / (float)_header.decompBlockSize) : _blockSizes.Count;
            var dataOffset = (sizeOffset + blockCount * 4 + 0x7F) & ~0x7F;

            // Chunk stream into blocks
            output.Position = dataOffset;
            var blockSizes = _blockSizes;

            if (file.ContentChanged)
            {
                blockSizes         = GzStream.ChunkStream(file.GetFileData().Result, output, _header.decompBlockSize, 0x80);
                _header.decompSize = (int)file.FileSize;
            }
            else
            {
                _origStream.Position = 0;
                _origStream.CopyTo(output);
            }

            // Write header
            _header.blockCount = blockSizes.Count;

            output.Position = 0;
            bw.WriteType(_header);

            // Write block sizes
            bw.WriteMultiple(blockSizes);
        }
Пример #17
0
        public void Save(Stream idxStream, Stream binStream, IList <IArchiveFileInfo> files)
        {
            // Write files
            var entries = new List <IdxEntry>();

            var dataPosition = 0;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                // Write file data
                binStream.Position = dataPosition;
                var writtenSize = file.SaveFileData(binStream);

                // Add entry
                entries.Add(new IdxEntry {
                    offset = dataPosition, size = (int)writtenSize
                });

                dataPosition += (int)writtenSize;
            }

            // Write entries
            using var bw = new BinaryWriterX(idxStream);
            bw.WriteMultiple(entries);
        }
Пример #18
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var fileOffset = Math.Max(0x30, (files.Count * EntrySize + 0xF) & ~0xF);

            // Write files
            var entries = new List <UMSBTEntry>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                entries.Add(new UMSBTEntry
                {
                    offset = filePosition,
                    size   = (int)writtenSize
                });

                filePosition += (int)writtenSize;
            }

            // Write entries
            output.Position = 0;
            bw.WriteMultiple(entries);
        }
Пример #19
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var entryOffset = HeaderSize;
            var fileOffset  = entryOffset + (files.Count + 1) * 4;

            // Write files
            var offsets = new List <int>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                offsets.Add(filePosition);

                filePosition += (int)writtenSize;
            }
            offsets.Add((int)output.Length);

            // Write offsets
            output.Position = entryOffset;
            bw.WriteMultiple(offsets);

            // Write header
            output.Position  = 0;
            _header.fileSize = (int)output.Length;
            bw.WriteType(_header);
        }
Пример #20
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            // Calculate offset
            var fileOffset = files.Count * 4;

            // Write files
            var offsets = new List <int>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                offsets.Add(filePosition);

                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                filePosition += (int)((writtenSize + 3) & ~3);
            }

            // Write offsets
            using var bw = new BinaryWriterX(output);

            output.Position = 0;
            bw.WriteMultiple(offsets);
        }
Пример #21
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var dataOffset = 4 + files.Count * 4;

            // Write files
            var offsets = new List <int>();

            var dataPosition = dataOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                // Write file data
                output.Position = dataPosition;
                var writtenSize = file.SaveFileData(output);

                offsets.Add(dataPosition);
                dataPosition += (int)writtenSize;
            }

            // Write offsets
            output.Position = 0;
            bw.Write(files.Count);
            bw.WriteMultiple(offsets);
        }
Пример #22
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var dataOffset = (4 + files.Count * FileEntrySize + 0x7F) & ~0x7F;

            // Write files
            var entries = new List <FntFileEntry>();

            output.Position = dataOffset;
            foreach (var file in files.Cast <FntArchiveFileInfo>())
            {
                var fileOffset  = output.Position;
                var writtenSize = file.SaveFileData(output);

                entries.Add(new FntFileEntry
                {
                    offset    = (int)fileOffset,
                    endOffset = (int)(fileOffset + writtenSize)
                });
            }

            // Write entries
            bw.BaseStream.Position = 0;
            bw.Write(files.Count);
            bw.WriteMultiple(entries);
        }
Пример #23
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offset
            var entryOffset = 4;
            var dataOffset  = entryOffset + files.Count * EntrySize;

            // Write files
            var entries = new List <PackEntry>();

            var dataPosition = dataOffset;

            foreach (var file in files.Cast <PackArchiveFileInfo>().OrderBy(x => x.Entry.offset))
            {
                // Write file data
                output.Position = dataPosition;
                var writtenSize = file.SaveFileData(output);

                // Add entry
                entries.Add(new PackEntry {
                    offset = dataPosition, size = (int)writtenSize, hash = file.Entry.hash
                });

                dataPosition += (int)((writtenSize + 3) & ~3);
            }

            // Write entries
            output.Position = entryOffset;
            bw.WriteMultiple(entries.OrderBy(x => x.hash));

            // Write file count
            output.Position = 0;
            bw.Write(files.Count);
        }
Пример #24
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var fileOffset = ((files.Count + 1) * 4 + 0x7F) & ~0x7F;

            // Write files
            var filePosition = fileOffset;

            var offsets = new List <int>();

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                output.Position = filePosition;
                var writtenSize = file.SaveFileData(output);

                offsets.Add(filePosition);

                filePosition = (filePosition + (int)writtenSize + 0x7F) & ~0x7F;
            }
            offsets.Add(filePosition);

            // Write offsets
            output.Position = 0;
            bw.WriteMultiple(offsets);
        }
Пример #25
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var entryOffset = 8;
            var fileOffset  = entryOffset + files.Count * 4;

            // Write files
            var offsets = new List <int>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                offsets.Add(filePosition);
                output.Position = filePosition;

                // Write size
                bw.Write((int)file.FileSize);

                // Write file data
                file.SaveFileData(output);

                filePosition += (int)(4 + file.FileSize);
            }

            // Write offsets
            output.Position = entryOffset;
            bw.WriteMultiple(offsets);

            // Write header data
            output.Position = 0;
            bw.Write(fileOffset - 4);
        }
Пример #26
0
        public void Save(Stream segStream, Stream binStream, Stream sizeStream, IList <IArchiveFileInfo> files)
        {
            using var binBw = new BinaryWriterX(binStream);
            using var segBw = new BinaryWriterX(segStream);

            // Write files
            var offsets           = new List <int>();
            var decompressedSizes = new List <int>();

            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                offsets.Add((int)binStream.Position);
                decompressedSizes.Add((int)file.FileSize);

                file.SaveFileData(binStream);
                binBw.WriteAlignment();
            }

            // Write offsets
            segBw.WriteMultiple(offsets);
            segBw.Write((int)binStream.Length);

            // Write decompressed sizes
            if (sizeStream != null)
            {
                using var sizeBw = new BinaryWriterX(sizeStream);

                sizeBw.WriteMultiple(decompressedSizes);
                sizeBw.Write(0);
            }
        }
Пример #27
0
        public void Save(Stream lstStream, Stream arcStream, IList <IArchiveFileInfo> files)
        {
            using var lstBw = new BinaryWriterX(lstStream);

            // Write files
            var entries = new List <IrarcFileEntry>();

            foreach (var file in files.Cast <IrarcArchiveFileInfo>())
            {
                var offset      = arcStream.Position;
                var writtenSize = file.SaveFileData(arcStream);

                entries.Add(new IrarcFileEntry
                {
                    id    = file.Entry.id,
                    flags = file.Entry.flags,

                    offset = (int)offset,
                    size   = (int)writtenSize
                });
            }

            // Write entries
            lstBw.Write(entries.Count);
            lstBw.WriteMultiple(entries);
        }
Пример #28
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            // Calculate offsets
            var fileOffset = (files.Count + 1) * EntrySize;

            // Write files
            var fileEntries = new List <Gk2Arc1Entry>();

            var filePosition = fileOffset;

            foreach (var file in files.Cast <Gk2Arc1ArchiveFileInfo>())
            {
                output.Position = filePosition;

                var writtenSize = file.SaveFileData(output);

                file.Entry.offset   = filePosition;
                file.Entry.FileSize = (uint)file.FileSize;
                fileEntries.Add(file.Entry);

                filePosition += (int)((writtenSize + 3) & ~3);
            }

            fileEntries.Add(new Gk2Arc1Entry
            {
                offset = (int)output.Length
            });

            // Write entries
            using var bw = new BinaryWriterX(output);

            output.Position = 0;
            bw.WriteMultiple(fileEntries);
        }
Пример #29
0
        public void Save(Stream texStream, Stream texListStream, IList <IArchiveFileInfo> files)
        {
            using var texBw     = new BinaryWriterX(texStream);
            using var texListBw = new BinaryWriterX(texListStream, Encoding.Unicode);

            // Write files
            var dataPosition = 0;

            var entries = new List <Sor4Entry>();

            foreach (var file in files.Cast <Sor4ArchiveFileInfo>())
            {
                // Write data
                texStream.Position = dataPosition;
                texBw.Write((int)file.FileSize);
                var writtenSize = file.SaveFileData(texStream);

                // Update entry
                file.Entry.compSize = (int)writtenSize + 4;
                file.Entry.offset   = dataPosition;
                entries.Add(file.Entry);

                dataPosition = (int)(dataPosition + 4 + writtenSize + 0xF) & ~0xF;
            }

            // Write entries
            texListBw.WriteMultiple(entries);
        }
Пример #30
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var nameOffset  = HeaderSize;
            var entryOffset = nameOffset + _dirs.Count * NameSize;
            var dataOffset  = (entryOffset + _entries.Count * EntrySize + 0x1F) & ~0x1F;

            // Write files
            var dataPosition = dataOffset;

            foreach (var file in files.Cast <PacArchiveFileInfo>())
            {
                // Write data
                output.Position = dataPosition;
                var writtenSize = file.SaveFileData(output);
                bw.WriteAlignment(0x20);

                // Update entry
                file.Entry.offset = dataPosition / 0x20;
                file.Entry.size   = (int)((file.Entry.flags & 0x100) == 0 ? writtenSize / 0x20 : writtenSize);

                dataPosition += (int)((writtenSize + 0x1F) & ~0x1F);
            }

            // Write entries
            output.Position = entryOffset;
            bw.WriteMultiple(_entries);

            // Write dirs
            output.Position = nameOffset;
            bw.WriteMultiple(_dirs);

            // Write header
            _header.nameOffset  = _dirs.Count > 0 ? nameOffset : 0;
            _header.nameCount   = _dirs.Count;
            _header.entryOffset = entryOffset;
            _header.entryCount  = _entries.Count;
            _header.dataSize    = (int)(output.Length - 0x10);
            _header.fileSize    = (int)output.Length;
            _header.blockCount  = (int)(output.Length / 0x20);

            output.Position = 0;
            bw.WriteType(_header);
        }