Exemplo n.º 1
0
        public byte[] DecompressChunk(Stream fs, int offset, int rev)
        {
            //CPK_MAX_DECOMP_BUFFER_SIZE = 0x10000
            helper help = new helper();

            fs.Seek(offset, 0);
            uint DecompressedSize, Flag, CompressedSize;

            if (rev == 0)
            {
                DecompressedSize = help.ReadU16(fs);
                Flag             = help.ReadU16(fs);
                CompressedSize   = help.ReadU16(fs);
            }
            else
            {
                DecompressedSize = help.ReverseUInt16(help.ReadU16(fs));
                Flag             = help.ReverseUInt16(help.ReadU16(fs));
                CompressedSize   = help.ReverseUInt16(help.ReadU16(fs));
            }
            byte[] buff = new byte[CompressedSize];
            fs.Read(buff, 0, (int)CompressedSize);
            byte[] tmp = { };
            try
            {
                tmp = DecompressZlib(buff);
            }
            catch
            {
                tmp = buff;
            }
            return(tmp);
        }
Exemplo n.º 2
0
            public static Dictionary <uint, CompressedSectorChunk> ReadSectors(Stream s)
            {
                helper help = new helper();
                CompressedSectorChunk csc = new CompressedSectorChunk();
                uint  ChunkNumber         = 0;
                ulong doffset             = 0;

                s.Seek(Header.FirstSectorPosition, 0);
                Dictionary <uint, CompressedSectorChunk> result = new Dictionary <uint, CompressedSectorChunk>();

                if (Header.MagicNumber.ToString("X8").Equals("A1B2C3D4"))
                {
                    help.ReadU16(s); help.ReadU16(s); s.Seek(help.ReadU16(s), SeekOrigin.Current);
                }
                if (Header.MagicNumber.ToString("X8").Equals("D4C3B2A1"))
                {
                    help.ReverseUInt16(help.ReadU16(s)); help.ReverseUInt16(help.ReadU16(s)); s.Seek(help.ReverseUInt16(help.ReadU16(s)), SeekOrigin.Current);
                }

                for (uint sector = 0; sector <= Header.CompSectorCount; sector++)
                {
                    uint SectorStartPosition = Header.FirstSectorPosition + sector * Header.CompSectorSize;
                    uint NextSectorPosition  = SectorStartPosition + Header.CompSectorSize;
                    s.Seek(SectorStartPosition, 0);
                    while (s.Position + 0xf < NextSectorPosition)
                    {
                        csc          = new CompressedSectorChunk();
                        csc.position = (uint)s.Position;
                        ushort Size          = help.ReadU16(s);
                        ushort flag          = help.ReadU16(s);
                        ushort CompChunkSize = help.ReadU16(s);
                        csc.nr                = ChunkNumber;
                        csc.CompChunkSize     = CompChunkSize;
                        csc.DecompChunkSize   = Size;
                        csc.flag              = flag;
                        csc.CompSector        = sector;
                        doffset              += Size;
                        csc.StartDecompOffset = doffset - Size;
                        result.Add(ChunkNumber, csc);
                        ChunkNumber++;
                        s.Seek(CompChunkSize, SeekOrigin.Current);
                    }
                }
                return(result);
            }