Exemplo n.º 1
0
        /* Compression types in order:
         *  10 = BZip2
         *   8 = PKLib
         *   2 = ZLib
         *   1 = Huffman
         *  80 = IMA ADPCM Stereo
         *  40 = IMA ADPCM Mono
         */
        private static byte[] DecompressMulti(byte[] Input, int OutputLength)
        {
            Stream sinput = new MemoryStream(Input);

            byte comptype = (byte)sinput.ReadByte();

            /*
             * // BZip2
             * if ((comptype & 0x10) != 0)
             * {
             *  byte[] result = BZip2Decompress(sinput, OutputLength);
             *  comptype &= 0xEF;
             *  if (comptype == 0) return result;
             *  sinput = new MemoryStream(result);
             * }
             */

            // PKLib
            if ((comptype & 8) != 0)
            {
                byte[] result = PKDecompress(sinput, OutputLength);
                comptype &= 0xF7;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            // ZLib
            if ((comptype & 2) != 0)
            {
                byte[] result = ZlibDecompress(sinput, OutputLength);
                comptype &= 0xFD;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            if ((comptype & 1) != 0)
            {
                byte[] result = MpqHuffman.Decompress(sinput);
                comptype &= 0xfe;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            if ((comptype & 0x80) != 0)
            {
                byte[] result = MpqWavCompression.Decompress(sinput, 2);
                comptype &= 0x7f;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            if ((comptype & 0x40) != 0)
            {
                byte[] result = MpqWavCompression.Decompress(sinput, 1);
                comptype &= 0xbf;
                if (comptype == 0)
                {
                    return(result);
                }
            }
            throw new MpqParserException(String.Format("Unhandled compression flags: 0x{0:X}", comptype));
        }
Exemplo n.º 2
0
        /* Compression types in order:
         *  10 = BZip2
         *   8 = PKLib
         *   2 = ZLib
         *   1 = Huffman
         *  80 = IMA ADPCM Stereo
         *  40 = IMA ADPCM Mono
         */
        private static byte[] DecompressMulti(byte[] Input, int OutputLength)
        {
            Stream sinput = new MemoryStream(Input);

            byte comptype = (byte)sinput.ReadByte();

#if WITH_BZIP
            // BZip2
            if ((comptype & 0x10) != 0)
            {
                byte[] result = BZip2Decompress(sinput, OutputLength);
                comptype &= 0xEF;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }
#endif

            // PKLib
            if ((comptype & 8) != 0)
            {
                byte[] result = PKDecompress(sinput, OutputLength);
                comptype &= 0xF7;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

#if WITH_ZLIB
            // ZLib
            if ((comptype & 2) != 0)
            {
                byte[] result = ZlibDecompress(sinput, OutputLength);
                comptype &= 0xFD;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }
#endif

            if ((comptype & 1) != 0)
            {
                byte[] result = MpqHuffman.Decompress(sinput);
                comptype &= 0xfe;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            if ((comptype & 0x80) != 0)
            {
                byte[] result = MpqWavCompression.Decompress(sinput, 2);
                comptype &= 0x7f;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }

            if ((comptype & 0x40) != 0)
            {
                byte[] result = MpqWavCompression.Decompress(sinput, 1);
                comptype &= 0xbf;
                if (comptype == 0)
                {
                    return(result);
                }
                sinput = new MemoryStream(result);
            }
            throw new Exception(String.Format("Unhandled compression flags: 0x{0:X}", comptype));
        }