コード例 #1
0
        private void Decompress()
        {
            PacHeader header = _input.EnsureRead <PacHeader>();

            header.Check();

            PacEntry[] entries = _input.EnsureRead <PacEntry>(header.FileCount);

            Int64 beginPosition           = _output.Position;
            Int32 headerSize              = PacHeader.StructSize + PacEntry.StructSize * entries.Length;
            Int64 decompressedArchiveSize = headerSize + entries.Sum(e => (Int64)e.UncompressedSize);
            Int64 totalSize = beginPosition + decompressedArchiveSize;

            if (totalSize > UInt32.MaxValue)
            {
                throw new NotSupportedException("The game cannot address more than 4 GB of files. You can unpack this file, but you cannot decompress it.");
            }

            _output.SetLength(totalSize);
            _output.Seek(headerSize, SeekOrigin.Current);

            Int64 dataPosition = _output.Position;

            for (Int32 index = 0; index < entries.Length; index++)
            {
                ref var     entry        = ref entries[index];
                Boolean     isCompressed = IsCompressed(entry.CompressionType);
                Span <Byte> data         = _reader.Read(_input, entry.CompressedSize, entry.UncompressedSize, isCompressed);

                entry.Offset          = checked ((UInt32)(_output.Position - dataPosition));
                entry.CompressedSize  = entry.UncompressedSize;
                entry.CompressionType = PakCompression.None;

                _output.Write(data);
            }
コード例 #2
0
ファイル: PacUnpacker.cs プロジェクト: kurigohan0/Inaba
        public void Unpack()
        {
            PacHeader header = _input.EnsureRead <PacHeader>();

            header.Check();

            PacEntry[] entries      = _input.EnsureRead <PacEntry>(header.FileCount);
            Int64      dataPosition = _input.Position;

            for (Int32 index = 0; index < entries.Length; index++)
            {
                ref var entry        = ref entries[index];
                Boolean isCompressed = PacDecompressor.IsCompressed(entry.CompressionType);

                _input.SetPosition(dataPosition + entry.Offset);
                Span <Byte> data = _reader.Read(_input, entry.CompressedSize, entry.UncompressedSize, isCompressed);

                String outputPath = _pathBuilder.GetOutputPath(entry.RelativePath, entry.FileId);
                FileSystem.CreateFileDirectory(outputPath);

                using (var output = File.Create(outputPath))
                    output.Write(data);
            }