Remove Ryujinx.HLE.Loaders.Compression

This commit is contained in:
EliseZeroTwo 2020-03-27 08:48:28 +01:00
commit 376df6f47f
2 changed files with 0 additions and 185 deletions

View file

@ -1,107 +0,0 @@
using System;
namespace Ryujinx.HLE.Loaders.Compression
{
static class BackwardsLz
{
private class BackwardsReader
{
private byte[] _data;
private int _position;
public int Position => _position;
public BackwardsReader(byte[] data, int end)
{
_data = data;
_position = end;
}
public void SeekCurrent(int offset)
{
_position += offset;
}
public byte ReadByte()
{
return _data[--_position];
}
public short ReadInt16()
{
return (short)((ReadByte() << 8) | (ReadByte() << 0));
}
public int ReadInt32()
{
return ((ReadByte() << 24) |
(ReadByte() << 16) |
(ReadByte() << 8) |
(ReadByte() << 0));
}
}
public static void DecompressInPlace(byte[] buffer, int headerEnd)
{
BackwardsReader reader = new BackwardsReader(buffer, headerEnd);
int additionalDecLength = reader.ReadInt32();
int startOffset = reader.ReadInt32();
int compressedLength = reader.ReadInt32();
reader.SeekCurrent(12 - startOffset);
int decBase = headerEnd - compressedLength;
int decPos = compressedLength + additionalDecLength;
byte mask = 0;
byte header = 0;
while (decPos > 0)
{
if ((mask >>= 1) == 0)
{
header = reader.ReadByte();
mask = 0x80;
}
if ((header & mask) == 0)
{
buffer[decBase + --decPos] = reader.ReadByte();
}
else
{
ushort pair = (ushort)reader.ReadInt16();
int length = (pair >> 12) + 3;
int position = (pair & 0xfff) + 3;
if (length > decPos)
{
length = decPos;
}
decPos -= length;
int dstPos = decBase + decPos;
if (length <= position)
{
int srcPos = dstPos + position;
Buffer.BlockCopy(buffer, srcPos, buffer, dstPos, length);
}
else
{
for (int offset = 0; offset < length; offset++)
{
buffer[dstPos + offset] = buffer[dstPos + position + offset];
}
}
}
}
}
}
}

View file

@ -1,78 +0,0 @@
using System;
namespace Ryujinx.HLE.Loaders.Compression
{
static class Lz4
{
public static byte[] Decompress(byte[] cmp, int decLength)
{
byte[] dec = new byte[decLength];
int cmpPos = 0;
int decPos = 0;
int GetLength(int length)
{
byte sum;
if (length == 0xf)
{
do
{
length += (sum = cmp[cmpPos++]);
}
while (sum == 0xff);
}
return length;
}
do
{
byte token = cmp[cmpPos++];
int encCount = (token >> 0) & 0xf;
int litCount = (token >> 4) & 0xf;
// Copy literal chunk
litCount = GetLength(litCount);
Buffer.BlockCopy(cmp, cmpPos, dec, decPos, litCount);
cmpPos += litCount;
decPos += litCount;
if (cmpPos >= cmp.Length)
{
break;
}
// Copy compressed chunk
int back = cmp[cmpPos++] << 0 |
cmp[cmpPos++] << 8;
encCount = GetLength(encCount) + 4;
int encPos = decPos - back;
if (encCount <= back)
{
Buffer.BlockCopy(dec, encPos, dec, decPos, encCount);
decPos += encCount;
}
else
{
while (encCount-- > 0)
{
dec[decPos++] = dec[encPos++];
}
}
}
while (cmpPos < cmp.Length &&
decPos < dec.Length);
return dec;
}
}
}