diff --git a/src/main/assets/lwjgl/version b/src/main/assets/lwjgl/version index 83082427..e6dc9596 100644 --- a/src/main/assets/lwjgl/version +++ b/src/main/assets/lwjgl/version @@ -1 +1 @@ -1728465869857 \ No newline at end of file +1730624021613 \ No newline at end of file diff --git a/src/main/java/pojlib/API.java b/src/main/java/pojlib/API.java index 9ac78916..c9abd7cc 100644 --- a/src/main/java/pojlib/API.java +++ b/src/main/java/pojlib/API.java @@ -5,6 +5,8 @@ import android.net.ConnectivityManager; import android.net.NetworkCapabilities; +import androidx.annotation.Nullable; + import com.google.gson.JsonObject; import pojlib.account.MinecraftAccount; @@ -35,6 +37,7 @@ public class API { public static String currentDownload; public static String profileImage; public static String profileName; + public static String profileUUID; public static String memoryValue = "1800"; public static boolean developerMods; public static MinecraftAccount currentAcc; @@ -130,14 +133,7 @@ public static boolean deleteInstance(MinecraftInstances instances, MinecraftInst * @throws IOException Throws if download of library or asset fails */ public static MinecraftInstances.Instance createNewInstance(Activity activity, MinecraftInstances instances, String instanceName, boolean useDefaultMods, String minecraftVersion, String imageURL) throws IOException { - - if(ignoreInstanceName) { - return InstanceHandler.create(activity, instances, instanceName, Constants.USER_HOME, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, imageURL); - } else if (instanceName.contains("/") || instanceName.contains("!")) { - throw new IOException("You cannot use special characters (!, /, ., etc) when creating instances."); - } else { - return InstanceHandler.create(activity, instances, instanceName, Constants.USER_HOME, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, imageURL); - } + return InstanceHandler.create(activity, instances, instanceName, Constants.USER_HOME, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, imageURL); } /** @@ -187,13 +183,14 @@ public static void launchInstance(Activity activity, MinecraftAccount account, M } /** - * Logs the user out + * Removes the user account * * @param activity The base directory where minecraft should be setup - * @return True if logout was successful + * @param username The username of the profile to remove + * @return True if removal was successful */ - public static boolean logout(Activity activity) { - return MinecraftAccount.logout(activity); + public static boolean removeAccount(Activity activity, String username) { + return MinecraftAccount.removeAccount(activity, username); } /** @@ -201,7 +198,7 @@ public static boolean logout(Activity activity) { * * @param activity Android activity object */ - public static void login(Activity activity) + public static void login(Activity activity, @Nullable String accountName) { ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkCapabilities capabilities = connManager.getNetworkCapabilities(connManager.getActiveNetwork()); @@ -212,19 +209,21 @@ public static void login(Activity activity) hasWifi = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); } - MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts"); + MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", accountName); if(acc != null && (acc.expiresOn >= System.currentTimeMillis() || !hasWifi || acc.isDemoMode)) { currentAcc = acc; API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc); API.profileName = API.currentAcc.username; + API.profileUUID = API.currentAcc.uuid; return; } else if(acc != null && acc.expiresOn < System.currentTimeMillis()) { - currentAcc = LoginHelper.refreshAccount(activity); + currentAcc = LoginHelper.refreshAccount(activity, currentAcc.username); if(currentAcc == null) { LoginHelper.login(activity); } else { API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc); API.profileName = API.currentAcc.username; + API.profileUUID = API.currentAcc.uuid; return; } } diff --git a/src/main/java/pojlib/account/LoginHelper.java b/src/main/java/pojlib/account/LoginHelper.java index 97cba7a6..a2b8f72c 100644 --- a/src/main/java/pojlib/account/LoginHelper.java +++ b/src/main/java/pojlib/account/LoginHelper.java @@ -63,7 +63,7 @@ public class LoginHelper { SCOPES.add("XboxLive.offline_access"); } - public static MinecraftAccount refreshAccount(Activity activity) { + public static MinecraftAccount refreshAccount(Activity activity, String uuid) { Set accountsInCache = pca.getAccounts().join(); IAccount account = accountsInCache.iterator().next(); @@ -76,7 +76,7 @@ public static MinecraftAccount refreshAccount(Activity activity) { result = pca.acquireTokenSilently(silentParameters).join(); MinecraftAccount acc = new Msa(activity).performLogin(result.accessToken()); - GsonUtils.objectToJsonFile(activity.getFilesDir() + "/accounts/account.json", acc); + GsonUtils.objectToJsonFile(activity.getFilesDir() + "/accounts/" + uuid + ".json", acc); return acc; } catch (Exception ex) { Logger.getInstance().appendToLog("Couldn't refresh token! " + ex); @@ -102,6 +102,7 @@ public static void login(Activity activity) { } API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc); API.profileName = API.currentAcc.username; + API.profileUUID = API.currentAcc.uuid; } catch (ExecutionException | InterruptedException e) { Logger.getInstance().appendToLog("MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers."); API.msaMessage = "MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers."; diff --git a/src/main/java/pojlib/account/MinecraftAccount.java b/src/main/java/pojlib/account/MinecraftAccount.java index 46a6cd52..b1873140 100644 --- a/src/main/java/pojlib/account/MinecraftAccount.java +++ b/src/main/java/pojlib/account/MinecraftAccount.java @@ -29,20 +29,20 @@ public static MinecraftAccount login(Activity activity, String gameDir, String m Msa instance = new Msa(activity); MinecraftAccount account = instance.performLogin(msToken); - GsonUtils.objectToJsonFile(gameDir + "/account.json", account); + GsonUtils.objectToJsonFile(gameDir + "/" + account.uuid + ".json", account); return account; } - public static boolean logout(Activity activity) { - File accountFile = new File(activity.getFilesDir() + "/accounts/account.json"); + public static boolean removeAccount(Activity activity, String uuid) { + File accountFile = new File(activity.getFilesDir() + "/accounts/" + uuid + ".json"); File accountCache = new File(Constants.USER_HOME + "/cache_data"); return accountFile.delete() && accountCache.delete(); } //Try this before using login - the account will have been saved to disk if previously logged in - public static MinecraftAccount load(String path) { - return GsonUtils.jsonFileToObject(path + "/account.json", MinecraftAccount.class); + public static MinecraftAccount load(String path, String uuid) { + return GsonUtils.jsonFileToObject(path + "/" + uuid + ".json", MinecraftAccount.class); } public static String getSkinFaceUrl(MinecraftAccount account) { diff --git a/src/main/java/pojlib/account/Msa.java b/src/main/java/pojlib/account/Msa.java index 3eb33e0b..2b404cb1 100644 --- a/src/main/java/pojlib/account/Msa.java +++ b/src/main/java/pojlib/account/Msa.java @@ -66,7 +66,7 @@ public MinecraftAccount performLogin(String msToken) throws MSAException { fetchOwnedItems(mcToken); checkMcProfile(mcToken); - MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts"); + MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", mcName); if (acc == null) acc = new MinecraftAccount(); if (doesOwnGame) { acc.accessToken = mcToken; diff --git a/src/main/java/pojlib/util/DownloadUtils.java b/src/main/java/pojlib/util/DownloadUtils.java index ebd087e0..7df79bea 100644 --- a/src/main/java/pojlib/util/DownloadUtils.java +++ b/src/main/java/pojlib/util/DownloadUtils.java @@ -58,7 +58,6 @@ private static void download(URL url, OutputStream os) throws IOException { public static void downloadFile(String url, File out) throws IOException { Objects.requireNonNull(out.getParentFile()).mkdirs(); File tempOut = File.createTempFile(out.getName(), ".part", out.getParentFile()); - BufferedOutputStream bos = null; try { OutputStream bos2 = new BufferedOutputStream(Files.newOutputStream(tempOut.toPath())); try { @@ -76,6 +75,7 @@ public static void downloadFile(String url, File out) throws IOException { throw th3; } } + public static boolean compareSHA1(File f, @Nullable String sourceSHA) { try { String sha1_dst;