| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- namespace OpenVIII
- {
- public class LZSSold
- {
- /// <summary>
- /// Decompiles LZSS. You have to know the OutputSize. [DEPRECATED]
- /// </summary>
- /// <param name="data">buffer</param>
- /// <param name="fileSize">Original filesize of compressed file</param>
- /// <param name="size">Filesize of final file</param>
- /// <returns>Byte array</returns>
- [Obsolete("This method proved to be broken. Please use DecompressAllNew")]
- public static byte[] DecompressAll(byte[] data, uint fileSize, int size = 0)
- {
- try
- {
- bool bDynamic = false;
- if (size == 0)
- {
- size = 0x4000000; //64MB
- bDynamic = true;
- }
- byte[] result = new byte[size];
- int curResult = 0;
- int curBuff = 4078, flagByte = 0;
- int fileData = 4,
- endFileData = (int)fileSize;
- byte[] textBuf = new byte[4113];
- while (true)
- {
- if (fileData + 1 >= endFileData) return !bDynamic ? result : ReturnDynamic(result, curResult);
- if (((flagByte >>= 1) & 256) == 0)
- flagByte = data[fileData++] | 0xff00;
- if (fileData >= endFileData)
- return !bDynamic ? result : ReturnDynamic(result, curResult);
- if ((flagByte & 1) > 0)
- {
- result[curResult] = textBuf[curBuff] = data[fileData++];
- curBuff = (curBuff + 1) & 4095;
- ++curResult;
- }
- else
- {
- if (fileData + 1 >= endFileData)
- return !bDynamic ? result : ReturnDynamic(result, curResult);
- int offset = (byte)BitConverter.ToChar(data, fileData++);
- if (fileData + 1 >= endFileData)
- return !bDynamic ? result : ReturnDynamic(result, curResult);
- int length = (byte)BitConverter.ToChar(data, fileData++);
- offset |= (length & 0xF0) << 4;
- length = (length & 0xF) + 2 + offset;
- int e;
- for (e = offset; e <= length; e++)
- {
- textBuf[curBuff] = result[curResult] = textBuf[e & 4095];
- curBuff = (curBuff + 1) & 4095;
- ++curResult;
- }
- }
- }
- }
- catch
- {
- return null;
- }
- }
- private static byte[] ReturnDynamic(byte[] result, int curResult)
- {
- byte[] buffer = new byte[curResult];
- Array.Copy(result, buffer, buffer.Length);
- return buffer;
- }
- }
- }
|