aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs
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/BackwardsLz.cs
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/BackwardsLz.cs')
-rw-r--r--Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs107
1 files changed, 0 insertions, 107 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