Browse Source

fix new versions uuid argument

Veloe 1 year ago
parent
commit
9a12e677ad
1 changed files with 14 additions and 1 deletions
  1. 14 1
      VeloeMinecraftLauncher/Utils/StartCommandBuilder.cs

+ 14 - 1
VeloeMinecraftLauncher/Utils/StartCommandBuilder.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
+using System.Security.Cryptography;
 using System.Text;
 using System.Text.Json;
 using VeloeMinecraftLauncher.Entity.Version;
@@ -315,7 +316,7 @@ internal static class StartCommandBuilder
                         returnString.Append(" --assetIndex " + inheritsFrom.Assets);
                     break;
                 case "--uuid":
-                    returnString.Append(" --uuid sample_token");
+                    returnString.Append($" --uuid {NameUUIDFromBytes(Encoding.UTF8.GetBytes($"OfflinePlayer:{username}")).ToString()}");
                     break;
                 case "--accessToken":
                     returnString.Append(" --accessToken sample_token");
@@ -365,4 +366,16 @@ internal static class StartCommandBuilder
 #endif
         return libPath;
     }
+
+    public static string NameUUIDFromBytes(byte[] input)
+    {
+        MD5 md5 = MD5.Create();
+        byte[] hash = md5.ComputeHash(input);
+        hash[6] &= 0x0f;
+        hash[6] |= 0x30;
+        hash[8] &= 0x3f;
+        hash[8] |= 0x80;
+        string hex = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
+        return hex.Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-");
+    }
 }