private static byte[] DecompressMulti(byte[] input, int outputLength) { Stream data = new MemoryStream(input); byte num = (byte)data.ReadByte(); switch (num) { case 0x10: return(BZip2Decompress(data, outputLength)); case 0x12: throw new MpqParserException("LZMA compression is not yet supported"); case 0x22: throw new MpqParserException("Sparse compression + Deflate compression is not yet supported"); case 1: return(MpqHuffman.Decompress(data).ToArray()); case 2: return(ZlibDecompress(data, outputLength)); case 8: return(PKDecompress(data, outputLength)); case 0x40: return(MpqWavCompression.Decompress(data, 1)); case 0x41: return(MpqWavCompression.Decompress(MpqHuffman.Decompress(data), 1)); case 0x30: throw new MpqParserException("Sparse compression + BZip2 compression is not yet supported"); case 0x80: return(MpqWavCompression.Decompress(data, 2)); case 0x81: return(MpqWavCompression.Decompress(MpqHuffman.Decompress(data), 2)); case 0x88: return(MpqWavCompression.Decompress(new MemoryStream(PKDecompress(data, outputLength)), 2)); case 0x48: return(MpqWavCompression.Decompress(new MemoryStream(PKDecompress(data, outputLength)), 1)); } throw new MpqParserException("Compression is not yet supported: 0x" + num.ToString("X")); }
/* 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(); // WC3 onward mosly use Zlib // Starcraft 1 mostly uses PKLib, plus types 41 and 81 for audio files switch (comptype) { case 1: // Huffman return(MpqHuffman.Decompress(sinput).ToArray()); case 2: // ZLib/Deflate return(ZlibDecompress(sinput, outputLength)); case 8: // PKLib/Impode return(PKDecompress(sinput, outputLength)); case 0x10: // BZip2 return(BZip2Decompress(sinput, outputLength)); case 0x80: // IMA ADPCM Stereo return(MpqWavCompression.Decompress(sinput, 2)); case 0x40: // IMA ADPCM Mono return(MpqWavCompression.Decompress(sinput, 1)); case 0x12: // TODO: LZMA throw new MpqParserException("LZMA compression is not yet supported"); // Combos case 0x22: // TODO: sparse then zlib throw new MpqParserException("Sparse compression + Deflate compression is not yet supported"); case 0x30: // TODO: sparse then bzip2 throw new MpqParserException("Sparse compression + BZip2 compression is not yet supported"); case 0x41: sinput = MpqHuffman.Decompress(sinput); return(MpqWavCompression.Decompress(sinput, 1)); case 0x48: { byte[] result = PKDecompress(sinput, outputLength); return(MpqWavCompression.Decompress(new MemoryStream(result), 1)); } case 0x81: sinput = MpqHuffman.Decompress(sinput); return(MpqWavCompression.Decompress(sinput, 2)); case 0x88: { byte[] result = PKDecompress(sinput, outputLength); return(MpqWavCompression.Decompress(new MemoryStream(result), 2)); } default: throw new MpqParserException("Compression is not yet supported: 0x" + comptype.ToString("X")); } }