-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRE Engine Hash generator.cs
More file actions
132 lines (119 loc) · 4.28 KB
/
RE Engine Hash generator.cs
File metadata and controls
132 lines (119 loc) · 4.28 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MurMur3Tests
{
public static class MurMurHash3
{
//Change to suit your needs
const uint seed = 0xFFFFFFFF;
public static uint Hash(Stream stream)
{
const uint c1 = 0xcc9e2d51;
const uint c2 = 0x1b873593;
uint h1 = seed;
uint k1 = 0;
uint streamLength = 0;
using (BinaryReader reader = new BinaryReader(stream))
{
byte[] chunk = reader.ReadBytes(4);
while (chunk.Length > 0)
{
streamLength += (uint)chunk.Length;
switch (chunk.Length)
{
case 4:
/* Get four bytes from the input into an uint */
k1 = (uint)
(chunk[0]
| chunk[1] << 8
| chunk[2] << 16
| chunk[3] << 24);
/* bitmagic hash */
k1 *= c1;
k1 = rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
h1 = rotl32(h1, 13);
h1 = h1 * 5 + 0xe6546b64;
break;
case 3:
k1 = (uint)
(chunk[0]
| chunk[1] << 8
| chunk[2] << 16);
k1 *= c1;
k1 = rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 2:
k1 = (uint)
(chunk[0]
| chunk[1] << 8);
k1 *= c1;
k1 = rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 1:
k1 = (uint)(chunk[0]);
k1 *= c1;
k1 = rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
}
chunk = reader.ReadBytes(4);
}
}
// finalization, magic chants to wrap it all up
h1 ^= streamLength;
h1 = fmix(h1);
return h1;
}
private static uint rotl32(uint x, byte r)
{
return (x << r) | (x >> (32 - r));
}
private static uint fmix(uint h)
{
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
}
public class Program
{
public static void Main(string[] args)
{
if (args.Length > 0 && File.Exists(args[0]))
{
string path = args[0];
string output = Path.GetDirectoryName(path) + "\\re3_pak_names_release.list";
if (File.Exists(output))
{
File.Delete(output);
}
using (StreamReader sr = new StreamReader(path))
using (TextWriter writer = File.CreateText(output))
{
var lines = File.ReadLines(path);
foreach (var line in lines)
using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(line.ToString())))
{
uint hashed = MurMurHash3.Hash(stream);
Console.WriteLine(hashed + " " + line.ToString());
writer.WriteLine(hashed + " " + line.ToString());
}
}
}
}
}
}