Created
July 3, 2022 05:05
-
-
Save ErnestoRB/f407757ca49390b4a09ede1f4435fa03 to your computer and use it in GitHub Desktop.
Generate Minecraft OfflinePlayer UUID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exit } = require("process"); | |
const createHash = require("crypto").createHash; | |
// Reads from cli | |
if (process.argv.length < 3) { | |
process.stdout.write("\n"); | |
exit(1); | |
} | |
const hash = createHash("md5"); // v3 | |
hash.once("readable", () => { | |
const data = hash.read(); | |
const uuid = [...data]; | |
// https://www.rfc-editor.org/rfc/rfc4122#section-4.3 | |
uuid[6] = (data[6] & 0x0f) | 0x30; // v3 | |
uuid[8] = (data[8] & 0x3f) | 0x80; | |
process.stdout.write(splittedUUID(toHexString(uuid))); | |
}); | |
function toHexString(byteArray) { | |
return byteArray | |
.map((byte) => ("0" + (byte & 0xff).toString(16)).slice(-2)) | |
.join(""); | |
} | |
function splittedUUID(uuid) { | |
return [ | |
uuid.substring(0, 8), | |
uuid.substring(8, 12), | |
uuid.substring(12, 16), | |
uuid.substring(16, 20), | |
uuid.substring(20, 32) | |
].join("-"); | |
} | |
hash.write("OfflinePlayer:" + process.argv[2]); | |
hash.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here you go @siraly1636