Skip to content

Commit

Permalink
Revamped code & removed Cead
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSpeedruns committed Apr 7, 2024
1 parent cd540a6 commit 0b348fc
Show file tree
Hide file tree
Showing 8 changed files with 2,918 additions and 87 deletions.
Binary file removed Cead.dll
Binary file not shown.
Binary file removed CsRestbl.dll
Binary file not shown.
202 changes: 149 additions & 53 deletions Form1.cs

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions HashTable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ZstdSharp;
using Cead;
using static System.Runtime.InteropServices.JavaScript.JSType;
using SarcLibrary;
using ZstdSharp;

namespace TotkRSTB
{
Expand All @@ -16,7 +15,7 @@ public static class HashTable
public static Decompressor _mapDecompressor = new();
public static Compressor _mapCompressor = new(16);

private static Sarc sarcFiles;
private static Sarc sarcFile;

Check warning on line 18 in HashTable.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'sarcFile' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 18 in HashTable.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'sarcFile' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 18 in HashTable.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'sarcFile' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

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

_commonDecompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
_commonCompressor.LoadDictionary(sarcFiles["pack.zsdic"]);
_commonDecompressor.LoadDictionary(sarcFile["pack.zsdic"]);
_commonCompressor.LoadDictionary(sarcFile["pack.zsdic"]);

_commonDecompressorOther.LoadDictionary(sarcFiles["zs.zsdic"]);
_commonDecompressorOther.LoadDictionary(sarcFile["zs.zsdic"]);

_mapDecompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
_mapCompressor.LoadDictionary(sarcFiles["bcett.byml.zsdic"]);
_mapDecompressor.LoadDictionary(sarcFile["bcett.byml.zsdic"]);
_mapCompressor.LoadDictionary(sarcFile["bcett.byml.zsdic"]);
}

public static byte[] DecompressFile(byte[] data)
Expand Down
88 changes: 88 additions & 0 deletions MurMurHash3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Text;

namespace TotkRandomizer
{
public static class MurMurHash3
{
private const uint Seed = 0;

public static uint Hash(string s)
{
var ss = new MemoryStream(Encoding.UTF8.GetBytes(s));
return Hash(ss);
}

public static uint Hash(Stream stream)
{
const uint c1 = 0xcc9e2d51;
const uint c2 = 0x1b873593;

var h1 = Seed;
uint streamLength = 0;

using (var reader = new BinaryReader(stream))
{
var chunk = reader.ReadBytes(4);
while (chunk.Length > 0)
{
streamLength += (uint)chunk.Length;
uint k1;
switch (chunk.Length)
{
case 4:
k1 = (uint)(chunk[0] | chunk[1] << 8 | chunk[2] << 16 | chunk[3] << 24);
k1 *= c1;
k1 = Rot(k1, 15);
k1 *= c2;
h1 ^= k1;
h1 = Rot(h1, 13);
h1 = h1 * 5 + 0xe6546b64;
break;
case 3:
k1 = (uint)(chunk[0] | chunk[1] << 8 | chunk[2] << 16);
k1 *= c1;
k1 = Rot(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 2:
k1 = (uint)(chunk[0] | chunk[1] << 8);
k1 *= c1;
k1 = Rot(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 1:
k1 = (chunk[0]);
k1 *= c1;
k1 = Rot(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
}
chunk = reader.ReadBytes(4);
}
}

h1 ^= streamLength;
h1 = Mix(h1);

return h1;
}

private static uint Rot(uint x, byte r)
{
return (x << r) | (x >> (32 - r));
}

private static uint Mix(uint h)
{
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
}
}
Binary file removed Native.IO.dll
Binary file not shown.
Loading

0 comments on commit 0b348fc

Please sign in to comment.