forked from MelonSpeedruns/TotkRandomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashTable.cs
80 lines (63 loc) · 2.7 KB
/
HashTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using ZstdSharp;
using Cead;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace TotkRSTB
{
//Core code from https://github.com/EXKing-Editor/EXKing-Editor/blob/master/src/ExKingEditor.Core/Models/HashTable.cs
public static class HashTable
{
public static Decompressor _commonDecompressorOther = new();
public static Compressor _commonCompressorOther = new(16);
public static Decompressor _commonDecompressor = new();
public static Compressor _commonCompressor = new(16);
public static Decompressor _mapDecompressor = new();
public static Compressor _mapCompressor = new(16);
private static Sarc sarcFiles;
private static Dictionary<uint, string> _hashStringList { get; } = new();
private static Dictionary<string, uint> _stringHashList { get; } = new();
public static Dictionary<uint, string> Strings => _hashStringList;
public static Dictionary<string, uint> Hashes => _stringHashList;
public static void InitHashTable(string dicPath)
{
Span<byte> data = _commonDecompressor.Unwrap(File.ReadAllBytes(dicPath));
sarcFiles = Sarc.FromBinary(data.ToArray());
_commonDecompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
_commonCompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
_commonDecompressorOther.LoadDictionary(sarcFiles["zs.zsdic"]);
_mapDecompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
_mapCompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
}
public static byte[] DecompressFile(byte[] data)
{
return _commonDecompressor.Unwrap(data).ToArray();
}
public static byte[] DecompressFile(string file)
{
Span<byte> src = File.ReadAllBytes(file);
return _commonDecompressor.Unwrap(src).ToArray();
}
public static byte[] CompressDataOther(byte[] file)
{
Span<byte> src = file;
return _commonCompressorOther.Wrap(src).ToArray();
}
public static byte[] DecompressDataOther(byte[] data)
{
return _commonDecompressorOther.Unwrap(data).ToArray();
}
public static byte[] CompressData(byte[] file)
{
Span<byte> src = file;
return _commonCompressor.Wrap(src).ToArray();
}
public static byte[] DecompressMapData(byte[] data)
{
return _mapDecompressor.Unwrap(data).ToArray();
}
public static byte[] CompressMapData(byte[] file)
{
Span<byte> src = file;
return _mapCompressor.Wrap(src).ToArray();
}
}
}