Exemple #1
0
        /// <summary>
        /// Decompress a pak file
        /// </summary>
        /// <param name="p_intManifestLocation">The position of the manifest in the pak file</param>
        /// <returns></returns>
        public UnpackedFile DecompressFile(int p_intManifestLocation)
        {
            if (p_intManifestLocation > (m_hdrPSHeader.TocEntries - 1))
            {
                return(new UnpackedFile());
            }

            byte[] outFile = null;
            m_erReader.BaseStream.Position = (long)TOC[p_intManifestLocation].StartOffset; // From manifest

            UInt16 isZipped = m_erReader.ReadUInt16();

            m_erReader.BaseStream.Position -= 2;    // Rewind 2 bytes

            ulong cBlockSize = m_hdrPSHeader.BlockSize;

            ulong zBlocks = (uint)(Math.Ceiling(TOC[p_intManifestLocation].OriginalSize / (double)cBlockSize));

            if (isZipped == 0x78da || isZipped == 0x7801) // Stream is compressed
            {
                ulong fileSize = zBlocks * cBlockSize;    // Only pass a part of the whole archive stream to be inflated.
                outFile = ZlibUtils.Inflate(m_erReader.ReadBytes((int)fileSize), (uint)zBlocks, (uint)cBlockSize, TOC[p_intManifestLocation].OriginalSize);
            }
            else
            {
                outFile = m_erReader.ReadBytes((int)TOC[p_intManifestLocation].OriginalSize);
            }

            if (TOC[p_intManifestLocation].OriginalSize != (ulong)outFile.LongLength)
            {
                throw new InvalidDataException(string.Format("Expected size: {0}, Actual size: {1}", TOC[p_intManifestLocation].OriginalSize, outFile.LongLength));
            }

            var output = new UnpackedFile();

            output.FileName   = TOC[p_intManifestLocation].FileName;
            output.BinaryFile = outFile;

            var output2 = new UnpackedFile(TOC[p_intManifestLocation].FileName, outFile);

            return(output);
        }
Exemple #2
0
        public PackedFile CompressFile(String fileName, byte[] binaryFile)
        {
            var tmpHeader = new Header(true);
            var tmpEntry  = new TOCEntry();

            tmpEntry.FileName       = fileName.Replace('\\', '/');
            tmpEntry.MD5            = new byte[16];
            tmpEntry.OriginalSize   = (ulong)binaryFile.LongLength;
            tmpEntry.StartOffset    = 0;
            tmpEntry.BlockListStart = (uint)(Math.Ceiling(tmpEntry.OriginalSize / (double)tmpHeader.BlockSize));

            try
            {
                byte[] compressedFile = ZlibUtils.Deflate(binaryFile, tmpHeader.BlockSize);
                return(new PackedFile(tmpEntry, compressedFile));
            }
            catch { }

            return(new PackedFile());
        }