mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
add hashing stuff
This commit is contained in:
parent
97f3043350
commit
0d665847a1
33
postinit.js
33
postinit.js
@ -952,4 +952,37 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
ModAPI.events.newEvent(eventName, "patcher");
|
||||
});
|
||||
}
|
||||
|
||||
function qhash(txt, arr) {
|
||||
var interval = 4095 - arr.length;
|
||||
var x = 1;
|
||||
for (let i = 0; i < txt.length; i++) {
|
||||
x += txt.charCodeAt(i);
|
||||
x = x << txt.charCodeAt(i);
|
||||
x = Math.abs(x);
|
||||
x = x % interval;
|
||||
}
|
||||
var hash = x + arr.length;
|
||||
while (arr.includes(hash)) {
|
||||
hash = (hash + 1) % (interval + arr.length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
ModAPI.keygen = {};
|
||||
var registryNamespaceMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.util.RegistryNamespaced", "register")];
|
||||
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.util.RegistryNamespaced", "register")] = function (...args) {
|
||||
args[0].$modapi_specmap ||= new Map();
|
||||
args[0].$modapi_specmap.set(args[2], args[1]);
|
||||
return registryNamespaceMethod.apply(this, args);
|
||||
}
|
||||
ModAPI.keygen.item = function (item) {
|
||||
var values = [...ModAPI.reflect.getClassById("net.minecraft.item.Item").staticVariables.itemRegistry.$modapi_specmap.values()];
|
||||
return qhash(item, values);
|
||||
}
|
||||
ModAPI.keygen.block = function () {
|
||||
var values = [...ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry.$modapi_specmap.values()];
|
||||
return qhash(item, values);
|
||||
}
|
||||
}).toString() + ")();";
|
||||
|
Loading…
x
Reference in New Issue
Block a user