Skip to content

Instantly share code, notes, and snippets.

@rakion99
Last active April 25, 2024 14:12
Show Gist options
  • Save rakion99/b5a2e4f75c2f142df691c18f2405acd1 to your computer and use it in GitHub Desktop.
Save rakion99/b5a2e4f75c2f142df691c18f2405acd1 to your computer and use it in GitHub Desktop.
Generate an offline minecraft UUID v3 based on the case sensitive player name, based on https://gist.github.com/games647/2b6a00a8fc21fd3b88375f03c9e2e603
private string GetOfflinePlayerUUID(string username)
{
//new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
byte[] rawresult = System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes($"OfflinePlayer:{username}"));
//set the version to 3 -> Name based md5 hash
rawresult[6] = (byte)(rawresult[6] & 0x0f | 0x30);
//IETF variant
rawresult[8] = (byte)(rawresult[8] & 0x3f | 0x80);
//convert to string and remove any - if any
string finalresult = BitConverter.ToString(rawresult).Replace("-", "");
//formatting
finalresult = finalresult.Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-");
return finalresult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment