com.wallstop-studios.unity-helpers 2.0.0-rc79 → 2.0.0-rc79.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll +0 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll +0 -0
- package/Runtime/Utils/LZMA.cs +53 -0
- package/Runtime/Utils/LZMA.cs.meta +3 -0
- package/Runtime/Utils/SevenZip/Common/CRC.cs +61 -0
- package/Runtime/Utils/SevenZip/Common/CRC.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Common/InBuffer.cs +71 -0
- package/Runtime/Utils/SevenZip/Common/InBuffer.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Common/OutBuffer.cs +65 -0
- package/Runtime/Utils/SevenZip/Common/OutBuffer.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Common.meta +3 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/IMatchFinder.cs +28 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/IMatchFinder.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzBinTree.cs +404 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzBinTree.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzInWindow.cs +153 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzInWindow.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzOutWindow.cs +110 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzOutWindow.cs.meta +11 -0
- package/Runtime/{Protobuf-Net/System.Collections.Immutable.xml.meta → Utils/SevenZip/Compress/LZ.meta} +3 -2
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaBase.cs +101 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaBase.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaDecoder.cs +464 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaDecoder.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaEncoder.cs +1669 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaEncoder.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA.meta +8 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoder.cs +233 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoder.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBit.cs +137 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBit.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBitTree.cs +170 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBitTree.cs.meta +11 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder.meta +8 -0
- package/Runtime/{Protobuf-Net/System.Runtime.CompilerServices.Unsafe.xml.meta → Utils/SevenZip/Compress.meta} +3 -2
- package/Runtime/Utils/SevenZip/ICoder.cs +177 -0
- package/Runtime/Utils/SevenZip/ICoder.cs.meta +11 -0
- package/Runtime/Utils/SevenZip.meta +3 -0
- package/package.json +2 -1
- package/Runtime/Protobuf-Net/System.Buffers.dll +0 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll.meta +0 -33
- package/Runtime/Protobuf-Net/System.Collections.Immutable.xml +0 -6812
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll +0 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll.meta +0 -33
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.xml +0 -342
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Utils
|
|
2
|
+
{
|
|
3
|
+
// LzmaHelper.cs - A wrapper for the LZMA SDK
|
|
4
|
+
using System;
|
|
5
|
+
using System.IO;
|
|
6
|
+
using System.Threading;
|
|
7
|
+
using SevenZip.Compression.LZMA;
|
|
8
|
+
|
|
9
|
+
public static class LZMA
|
|
10
|
+
{
|
|
11
|
+
private static readonly ThreadLocal<Decoder> Decoders = new(() => new Decoder());
|
|
12
|
+
private static readonly ThreadLocal<Encoder> Encoders = new(() => new Encoder());
|
|
13
|
+
private static readonly ThreadLocal<byte[]> Properties = new(() => new byte[5]);
|
|
14
|
+
private static readonly ThreadLocal<byte[]> FileLengths = new(() => new byte[8]);
|
|
15
|
+
|
|
16
|
+
public static byte[] Compress(byte[] input)
|
|
17
|
+
{
|
|
18
|
+
Encoder encoder = Encoders.Value;
|
|
19
|
+
using MemoryStream inStream = new(input, writable: false);
|
|
20
|
+
using MemoryStream outStream = new();
|
|
21
|
+
encoder.WriteCoderProperties(outStream);
|
|
22
|
+
|
|
23
|
+
// Write original file size
|
|
24
|
+
outStream.Write(BitConverter.GetBytes(inStream.Length), 0, 8);
|
|
25
|
+
|
|
26
|
+
// Compress the data
|
|
27
|
+
encoder.Code(inStream, outStream, inStream.Length, -1, null);
|
|
28
|
+
return outStream.ToArray();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static byte[] Decompress(byte[] input)
|
|
32
|
+
{
|
|
33
|
+
Decoder decoder = Decoders.Value;
|
|
34
|
+
using MemoryStream inStream = new(input, writable: false);
|
|
35
|
+
using MemoryStream outStream = new();
|
|
36
|
+
// Read decoder properties
|
|
37
|
+
byte[] properties = Properties.Value;
|
|
38
|
+
Array.Clear(properties, 0, properties.Length);
|
|
39
|
+
inStream.Read(properties, 0, properties.Length);
|
|
40
|
+
decoder.SetDecoderProperties(properties);
|
|
41
|
+
|
|
42
|
+
// Read original file size
|
|
43
|
+
byte[] fileLengthBytes = FileLengths.Value;
|
|
44
|
+
Array.Clear(fileLengthBytes, 0, fileLengthBytes.Length);
|
|
45
|
+
inStream.Read(fileLengthBytes, 0, 8);
|
|
46
|
+
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
|
|
47
|
+
|
|
48
|
+
// Decompress the data
|
|
49
|
+
decoder.Code(inStream, outStream, inStream.Length, fileLength, null);
|
|
50
|
+
return outStream.ToArray();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Common/CRC.cs
|
|
2
|
+
|
|
3
|
+
namespace SevenZip
|
|
4
|
+
{
|
|
5
|
+
class CRC
|
|
6
|
+
{
|
|
7
|
+
public static readonly uint[] Table;
|
|
8
|
+
|
|
9
|
+
static CRC()
|
|
10
|
+
{
|
|
11
|
+
Table = new uint[256];
|
|
12
|
+
const uint kPoly = 0xEDB88320;
|
|
13
|
+
for (uint i = 0; i < 256; i++)
|
|
14
|
+
{
|
|
15
|
+
uint r = i;
|
|
16
|
+
for (int j = 0; j < 8; j++)
|
|
17
|
+
if ((r & 1) != 0)
|
|
18
|
+
r = (r >> 1) ^ kPoly;
|
|
19
|
+
else
|
|
20
|
+
r >>= 1;
|
|
21
|
+
Table[i] = r;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
uint _value = 0xFFFFFFFF;
|
|
26
|
+
|
|
27
|
+
public void Init()
|
|
28
|
+
{
|
|
29
|
+
_value = 0xFFFFFFFF;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public void UpdateByte(byte b)
|
|
33
|
+
{
|
|
34
|
+
_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void Update(byte[] data, uint offset, uint size)
|
|
38
|
+
{
|
|
39
|
+
for (uint i = 0; i < size; i++)
|
|
40
|
+
_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public uint GetDigest()
|
|
44
|
+
{
|
|
45
|
+
return _value ^ 0xFFFFFFFF;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static uint CalculateDigest(byte[] data, uint offset, uint size)
|
|
49
|
+
{
|
|
50
|
+
CRC crc = new CRC();
|
|
51
|
+
// crc.Init();
|
|
52
|
+
crc.Update(data, offset, size);
|
|
53
|
+
return crc.GetDigest();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
|
|
57
|
+
{
|
|
58
|
+
return (CalculateDigest(data, offset, size) == digest);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// InBuffer.cs
|
|
2
|
+
|
|
3
|
+
namespace SevenZip.Buffer
|
|
4
|
+
{
|
|
5
|
+
public class InBuffer
|
|
6
|
+
{
|
|
7
|
+
byte[] m_Buffer;
|
|
8
|
+
uint m_Pos;
|
|
9
|
+
uint m_Limit;
|
|
10
|
+
uint m_BufferSize;
|
|
11
|
+
System.IO.Stream m_Stream;
|
|
12
|
+
bool m_StreamWasExhausted;
|
|
13
|
+
ulong m_ProcessedSize;
|
|
14
|
+
|
|
15
|
+
public InBuffer(uint bufferSize)
|
|
16
|
+
{
|
|
17
|
+
m_Buffer = new byte[bufferSize];
|
|
18
|
+
m_BufferSize = bufferSize;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public void Init(System.IO.Stream stream)
|
|
22
|
+
{
|
|
23
|
+
m_Stream = stream;
|
|
24
|
+
m_ProcessedSize = 0;
|
|
25
|
+
m_Limit = 0;
|
|
26
|
+
m_Pos = 0;
|
|
27
|
+
m_StreamWasExhausted = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public bool ReadBlock()
|
|
31
|
+
{
|
|
32
|
+
if (m_StreamWasExhausted)
|
|
33
|
+
return false;
|
|
34
|
+
m_ProcessedSize += m_Pos;
|
|
35
|
+
int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);
|
|
36
|
+
m_Pos = 0;
|
|
37
|
+
m_Limit = (uint)aNumProcessedBytes;
|
|
38
|
+
m_StreamWasExhausted = (aNumProcessedBytes == 0);
|
|
39
|
+
return (!m_StreamWasExhausted);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public void ReleaseStream()
|
|
43
|
+
{
|
|
44
|
+
// m_Stream.Close();
|
|
45
|
+
m_Stream = null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public bool ReadByte(byte b) // check it
|
|
49
|
+
{
|
|
50
|
+
if (m_Pos >= m_Limit)
|
|
51
|
+
if (!ReadBlock())
|
|
52
|
+
return false;
|
|
53
|
+
b = m_Buffer[m_Pos++];
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public byte ReadByte()
|
|
58
|
+
{
|
|
59
|
+
// return (byte)m_Stream.ReadByte();
|
|
60
|
+
if (m_Pos >= m_Limit)
|
|
61
|
+
if (!ReadBlock())
|
|
62
|
+
return 0xFF;
|
|
63
|
+
return m_Buffer[m_Pos++];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public ulong GetProcessedSize()
|
|
67
|
+
{
|
|
68
|
+
return m_ProcessedSize + m_Pos;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// OutBuffer.cs
|
|
2
|
+
|
|
3
|
+
namespace SevenZip.Buffer
|
|
4
|
+
{
|
|
5
|
+
public class OutBuffer
|
|
6
|
+
{
|
|
7
|
+
byte[] m_Buffer;
|
|
8
|
+
uint m_Pos;
|
|
9
|
+
uint m_BufferSize;
|
|
10
|
+
System.IO.Stream m_Stream;
|
|
11
|
+
ulong m_ProcessedSize;
|
|
12
|
+
|
|
13
|
+
public OutBuffer(uint bufferSize)
|
|
14
|
+
{
|
|
15
|
+
m_Buffer = new byte[bufferSize];
|
|
16
|
+
m_BufferSize = bufferSize;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public void SetStream(System.IO.Stream stream)
|
|
20
|
+
{
|
|
21
|
+
m_Stream = stream;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public void FlushStream()
|
|
25
|
+
{
|
|
26
|
+
m_Stream.Flush();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public void CloseStream()
|
|
30
|
+
{
|
|
31
|
+
m_Stream.Close();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public void ReleaseStream()
|
|
35
|
+
{
|
|
36
|
+
m_Stream = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public void Init()
|
|
40
|
+
{
|
|
41
|
+
m_ProcessedSize = 0;
|
|
42
|
+
m_Pos = 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public void WriteByte(byte b)
|
|
46
|
+
{
|
|
47
|
+
m_Buffer[m_Pos++] = b;
|
|
48
|
+
if (m_Pos >= m_BufferSize)
|
|
49
|
+
FlushData();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public void FlushData()
|
|
53
|
+
{
|
|
54
|
+
if (m_Pos == 0)
|
|
55
|
+
return;
|
|
56
|
+
m_Stream.Write(m_Buffer, 0, (int)m_Pos);
|
|
57
|
+
m_Pos = 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public ulong GetProcessedSize()
|
|
61
|
+
{
|
|
62
|
+
return m_ProcessedSize + m_Pos;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// IMatchFinder.cs
|
|
2
|
+
|
|
3
|
+
using System;
|
|
4
|
+
|
|
5
|
+
namespace SevenZip.Compression.LZ
|
|
6
|
+
{
|
|
7
|
+
interface IInWindowStream
|
|
8
|
+
{
|
|
9
|
+
void SetStream(System.IO.Stream inStream);
|
|
10
|
+
void Init();
|
|
11
|
+
void ReleaseStream();
|
|
12
|
+
Byte GetIndexByte(Int32 index);
|
|
13
|
+
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);
|
|
14
|
+
UInt32 GetNumAvailableBytes();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IMatchFinder : IInWindowStream
|
|
18
|
+
{
|
|
19
|
+
void Create(
|
|
20
|
+
UInt32 historySize,
|
|
21
|
+
UInt32 keepAddBufferBefore,
|
|
22
|
+
UInt32 matchMaxLen,
|
|
23
|
+
UInt32 keepAddBufferAfter
|
|
24
|
+
);
|
|
25
|
+
UInt32 GetMatches(UInt32[] distances);
|
|
26
|
+
void Skip(UInt32 num);
|
|
27
|
+
}
|
|
28
|
+
}
|