Skip to content

Instantly share code, notes, and snippets.

@reo-ar
Created August 18, 2020 06:33
Show Gist options
  • Save reo-ar/44ebfce8199f366b111ab83231b3b127 to your computer and use it in GitHub Desktop.
Save reo-ar/44ebfce8199f366b111ab83231b3b127 to your computer and use it in GitHub Desktop.
import os
def curse_hasher(mod):
with open(mod, "rb") as mod_file:
file_bytes = mod_file.read()
length = sum(byte not in (0x9, 0xA, 0xD, 0x20) for byte in file_bytes)
seed = 1
h = seed ^ length
k = 0x0
m = 0x5BD1E995
r = 24
shift = 0x0
for byte in file_bytes:
if byte in (0x9, 0xA, 0xD, 0x20):
continue
k |= byte << shift
shift += 0x8
if shift == 0x20:
k = (k * m) & 0xFFFFFFFF
k ^= k >> r
k = (k * m) & 0xFFFFFFFF
h = (h * m) & 0xFFFFFFFF
h ^= k
k = 0x0
shift = 0x0
if shift > 0:
h ^= k
h = (h * m) & 0xFFFFFFFF
h ^= h >> 13
h = (h * m) & 0xFFFFFFFF
h ^= h >> 15
mod_hash = str(h)
print(mod.name, mod_hash)
return mod_hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment