aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Compression
diff options
context:
space:
mode:
authorElise <elisezerotwo@gmail.com>2020-04-08 00:41:02 +0200
committerGitHub <noreply@github.com>2020-04-07 19:41:02 -0300
commitdc144d2e190e03729b16e402da9c36eec5aaf53f (patch)
tree00728f4639cc9642c25031aff6ae9a6d465f4fe7 /Ryujinx.HLE/Loaders/Compression
parent468d8f841ffcbebf4130371eb64ab04165bce3e9 (diff)
Use libhac for loading NSO and KIP (#1047)
* Use libhac for loading NSOs and KIPs * Fix formatting * Refactor KIP and NSO executables for libhac * Fix up formatting * Remove Ryujinx.HLE.Loaders.Compression * Remove reference to Ryujinx.HLE.Loaders.Compression in NxStaticObject.cs * Remove reference to Ryujinx.HLE.Loaders.Compression in KernelInitialProcess.cs * Rename classes in Ryujinx.HLE.Loaders.Executables * Fix space alignment * Fix up formatting
Diffstat (limited to 'Ryujinx.HLE/Loaders/Compression')
-rw-r--r--Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs107
-rw-r--r--Ryujinx.HLE/Loaders/Compression/Lz4.cs78
2 files changed, 0 insertions, 185 deletions
diff --git a/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs b/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs
deleted file mode 100644
index 0a76dc95..00000000
--- a/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs
+++ /dev/null
@@ -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];
- }
- }
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.HLE/Loaders/Compression/Lz4.cs b/Ryujinx.HLE/Loaders/Compression/Lz4.cs
deleted file mode 100644
index 2001a8dc..00000000
--- a/Ryujinx.HLE/Loaders/Compression/Lz4.cs
+++ /dev/null
@@ -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;
- }
- }
-} \ No newline at end of file