It tooks me hours trying to figure out how to mimic the exact decompression in this project: https://github.com/crimsoncantab/aok-hotkeys/blob/master/modules/hkizip.py but to no avail.
If you go to this website: http://aokhotkeys.appspot.com/ you can click any preset and download it to see for yourself.
The decompression is supposed to output a .hki file to text file
This is my attempt, which may not be as accurate as in the python project linked above:
private string ZlibCodecDecompress(byte[] compressed)
{
int outputSize = 2048;
byte[] output = new Byte[outputSize];
// If you have a ZLIB stream, set this to true. If you have
// a bare DEFLATE stream, set this to false.
bool expectRfc1950Header = false;
using (MemoryStream ms = new MemoryStream())
{
ZlibCodec compressor = new ZlibCodec();
compressor.InitializeInflate(expectRfc1950Header);
compressor.InputBuffer = compressed;
compressor.AvailableBytesIn = compressed.Length;
compressor.NextIn = 0;
compressor.CompressLevel = Ionic.Zlib.CompressionLevel.Level8;
compressor.OutputBuffer = output;
foreach (var f in new FlushType[] { FlushType.None, FlushType.Finish })
{
int bytesToWrite = 0;
do
{
compressor.AvailableBytesOut = outputSize;
compressor.NextOut = 0;
compressor.Inflate(f);
bytesToWrite = outputSize - compressor.AvailableBytesOut;
if (bytesToWrite > 0)
ms.Write(output, 0, bytesToWrite);
}
while ((f == FlushType.None && (compressor.AvailableBytesIn != 0 || compressor.AvailableBytesOut == 0)) ||
(f == FlushType.Finish && bytesToWrite != 0));
}
compressor.EndInflate();
return UTF8Encoding.UTF8.GetString(ms.ToArray());
}
}
This method returns: "Ionic.Zlib.ZlibException: Bad state"
I'd appreciate any help.