Last active
May 7, 2024 10:10
-
-
Save games647/2b6a00a8fc21fd3b88375f03c9e2e603 to your computer and use it in GitHub Desktop.
Generate an offline minecraft UUID v3 based on the case sensitive player name
This file contains 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
<? | |
/** | |
* Generates a offline-mode player UUID. | |
* | |
* @param $username string | |
* @return string | |
*/ | |
public static function constructOfflinePlayerUuid($username) { | |
//extracted from the java code: | |
//new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name)); | |
$data = hex2bin(md5("OfflinePlayer:" . $username)); | |
//set the version to 3 -> Name based md5 hash | |
$data[6] = chr(ord($data[6]) & 0x0f | 0x30); | |
//IETF variant | |
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); | |
return self::createJavaUuid(bin2hex($data)); | |
} | |
public static function createJavaUuid($striped) { | |
//example: 069a79f4-44e9-4726-a5be-fca90e38aaf5 | |
$components = array( | |
substr($striped, 0, 8), | |
substr($striped, 8, 4), | |
substr($striped, 12, 4), | |
substr($striped, 16, 4), | |
substr($striped, 20), | |
); | |
return implode('-', $components); | |
} | |
?> |
Hello! I made Python translation :)
https://gist.github.com/Nikdoge/474f74688b52865bf8d682a97fd4f2fe
C# version if someone need it: https://gist.github.com/rakion99/b5a2e4f75c2f142df691c18f2405acd1
Adapted for SQL (MariaDB): https://gist.github.com/Wector11211/1f95e573123f18b4a3cd0d05266037aa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dart version (may be useful for other more modern languages as well): https://gist.github.com/RedyAu/bba8774189e7841f09523f474f21bb61