Skip to content

Commit 0b348fc

Browse files
Revamped code & removed Cead
1 parent cd540a6 commit 0b348fc

8 files changed

Lines changed: 2918 additions & 87 deletions

File tree

Cead.dll

-4.87 MB
Binary file not shown.

CsRestbl.dll

-2.36 MB
Binary file not shown.

Form1.cs

Lines changed: 149 additions & 53 deletions
Large diffs are not rendered by default.

HashTable.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using ZstdSharp;
2-
using Cead;
3-
using static System.Runtime.InteropServices.JavaScript.JSType;
1+
using SarcLibrary;
2+
using ZstdSharp;
43

54
namespace TotkRSTB
65
{
@@ -16,7 +15,7 @@ public static class HashTable
1615
public static Decompressor _mapDecompressor = new();
1716
public static Compressor _mapCompressor = new(16);
1817

19-
private static Sarc sarcFiles;
18+
private static Sarc sarcFile;
2019

2120
private static Dictionary<uint, string> _hashStringList { get; } = new();
2221
private static Dictionary<string, uint> _stringHashList { get; } = new();
@@ -27,15 +26,15 @@ public static class HashTable
2726
public static void InitHashTable(string dicPath)
2827
{
2928
Span<byte> data = _commonDecompressor.Unwrap(File.ReadAllBytes(dicPath));
30-
sarcFiles = Sarc.FromBinary(data.ToArray());
29+
sarcFile = Sarc.FromBinary(data.ToArray());
3130

32-
_commonDecompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
33-
_commonCompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
31+
_commonDecompressor.LoadDictionary(sarcFile["pack.zsdic"]);
32+
_commonCompressor.LoadDictionary(sarcFile["pack.zsdic"]);
3433

35-
_commonDecompressorOther.LoadDictionary(sarcFiles["zs.zsdic"]);
34+
_commonDecompressorOther.LoadDictionary(sarcFile["zs.zsdic"]);
3635

37-
_mapDecompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
38-
_mapCompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
36+
_mapDecompressor.LoadDictionary(sarcFile["bcett.byml.zsdic"]);
37+
_mapCompressor.LoadDictionary(sarcFile["bcett.byml.zsdic"]);
3938
}
4039

4140
public static byte[] DecompressFile(byte[] data)

MurMurHash3.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System.Text;
2+
3+
namespace TotkRandomizer
4+
{
5+
public static class MurMurHash3
6+
{
7+
private const uint Seed = 0;
8+
9+
public static uint Hash(string s)
10+
{
11+
var ss = new MemoryStream(Encoding.UTF8.GetBytes(s));
12+
return Hash(ss);
13+
}
14+
15+
public static uint Hash(Stream stream)
16+
{
17+
const uint c1 = 0xcc9e2d51;
18+
const uint c2 = 0x1b873593;
19+
20+
var h1 = Seed;
21+
uint streamLength = 0;
22+
23+
using (var reader = new BinaryReader(stream))
24+
{
25+
var chunk = reader.ReadBytes(4);
26+
while (chunk.Length > 0)
27+
{
28+
streamLength += (uint)chunk.Length;
29+
uint k1;
30+
switch (chunk.Length)
31+
{
32+
case 4:
33+
k1 = (uint)(chunk[0] | chunk[1] << 8 | chunk[2] << 16 | chunk[3] << 24);
34+
k1 *= c1;
35+
k1 = Rot(k1, 15);
36+
k1 *= c2;
37+
h1 ^= k1;
38+
h1 = Rot(h1, 13);
39+
h1 = h1 * 5 + 0xe6546b64;
40+
break;
41+
case 3:
42+
k1 = (uint)(chunk[0] | chunk[1] << 8 | chunk[2] << 16);
43+
k1 *= c1;
44+
k1 = Rot(k1, 15);
45+
k1 *= c2;
46+
h1 ^= k1;
47+
break;
48+
case 2:
49+
k1 = (uint)(chunk[0] | chunk[1] << 8);
50+
k1 *= c1;
51+
k1 = Rot(k1, 15);
52+
k1 *= c2;
53+
h1 ^= k1;
54+
break;
55+
case 1:
56+
k1 = (chunk[0]);
57+
k1 *= c1;
58+
k1 = Rot(k1, 15);
59+
k1 *= c2;
60+
h1 ^= k1;
61+
break;
62+
}
63+
chunk = reader.ReadBytes(4);
64+
}
65+
}
66+
67+
h1 ^= streamLength;
68+
h1 = Mix(h1);
69+
70+
return h1;
71+
}
72+
73+
private static uint Rot(uint x, byte r)
74+
{
75+
return (x << r) | (x >> (32 - r));
76+
}
77+
78+
private static uint Mix(uint h)
79+
{
80+
h ^= h >> 16;
81+
h *= 0x85ebca6b;
82+
h ^= h >> 13;
83+
h *= 0xc2b2ae35;
84+
h ^= h >> 16;
85+
return h;
86+
}
87+
}
88+
}

Native.IO.dll

-66 KB
Binary file not shown.

0 commit comments

Comments
 (0)