From efc3cd4a09e435fdcc2fd5a42696fff48a20e855 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 01:37:18 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=98=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= =?UTF-8?q?=20proguard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientClassLoader.java | 90 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 6 +- .../authlib/yggdrasil/CompatBridge.java | 3 +- .../YggdrasilGameProfileRepository.java | 5 +- .../gravit/utils/PublicURLClassLoader.java | 35 -------- 5 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java new file mode 100644 index 00000000..682d0ec1 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java @@ -0,0 +1,90 @@ +package pro.gravit.launcher.client; + +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; + +import java.net.URL; +import java.net.URLClassLoader; + +public class ClientClassLoader extends URLClassLoader { + public String nativePath; + + /** + * Constructs a new URLClassLoader for the specified URLs using the + * default delegation parent {@code ClassLoader}. The URLs will + * be searched in the order specified for classes and resources after + * first searching in the parent class loader. Any URL that ends with + * a '/' is assumed to refer to a directory. Otherwise, the URL is + * assumed to refer to a JAR file which will be downloaded and opened + * as needed. + * + *

If there is a security manager, this method first + * calls the security manager's {@code checkCreateClassLoader} method + * to ensure creation of a class loader is allowed. + * + * @param urls the URLs from which to load classes and resources + * @throws SecurityException if a security manager exists and its + * {@code checkCreateClassLoader} method doesn't allow + * creation of a class loader. + * @throws NullPointerException if {@code urls} is {@code null}. + * @see SecurityManager#checkCreateClassLoader + */ + public ClientClassLoader(URL[] urls) { + super(urls); + } + + /** + * Constructs a new URLClassLoader for the given URLs. The URLs will be + * searched in the order specified for classes and resources after first + * searching in the specified parent class loader. Any {@code jar:} + * scheme URL is assumed to refer to a JAR file. Any {@code file:} scheme + * URL that ends with a '/' is assumed to refer to a directory. Otherwise, + * the URL is assumed to refer to a JAR file which will be downloaded and + * opened as needed. + * + *

If there is a security manager, this method first + * calls the security manager's {@code checkCreateClassLoader} method + * to ensure creation of a class loader is allowed. + * + * @param urls the URLs from which to load classes and resources + * @param parent the parent class loader for delegation + * @throws SecurityException if a security manager exists and its + * {@code checkCreateClassLoader} method doesn't allow + * creation of a class loader. + * @throws NullPointerException if {@code urls} is {@code null}. + * @see SecurityManager#checkCreateClassLoader + */ + public ClientClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + @Override + public String findLibrary(String name) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); + } + public String getNativeEx() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return ".dll"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return ".so"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return ".dylib"; + return ""; + } + public String getNativePrefix() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return "lib"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return "lib"; + return ""; + } + + @Override + public void addURL(URL url) { + super.addURL(url); + } +} + diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 23412318..4e85be4d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -10,7 +10,6 @@ import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; -import pro.gravit.launcher.hwid.OshiHWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -163,7 +162,7 @@ public void write(HOutput output) throws IOException { // Constants private static final Path NATIVES_DIR = IOHelper.toPath("natives"); private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks"); - private static PublicURLClassLoader classLoader; + private static ClientClassLoader classLoader; public static class ClientUserProperties { @LauncherAPI @@ -481,10 +480,9 @@ public static void main(String... args) throws Throwable { } }); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); - classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); + classLoader = new ClientClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); - PublicURLClassLoader.systemclassloader = classLoader; // Start client with WatchService monitoring boolean digest = !profile.isUpdateFastCheck(); LogHelper.debug("Restore sessions"); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java index bc11fa25..7d35a319 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; import pro.gravit.launcher.request.uuid.ProfileByUUIDRequest; import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest; -import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; import java.util.UUID; @@ -15,7 +14,7 @@ // Used to bypass Launcher's class name obfuscation and access API @LauncherAPI public class CompatBridge { - public static final int PROFILES_MAX_BATCH_SIZE = SerializeLimits.MAX_BATCH_SIZE; + public static final int PROFILES_MAX_BATCH_SIZE = 128; public static CompatProfile checkServer(String username, String serverID) throws Exception { LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 9ccad1b2..7282a47f 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -6,7 +6,6 @@ import com.mojang.authlib.ProfileLookupCallback; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; -import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; @@ -37,8 +36,8 @@ public YggdrasilGameProfileRepository() { public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCallback callback) { int offset = 0; while (offset < usernames.length) { - String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + SerializeLimits.MAX_BATCH_SIZE, usernames.length)); - offset += SerializeLimits.MAX_BATCH_SIZE; + String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + 128, usernames.length)); + offset += 128; // Batch Username-To-UUID request PlayerProfile[] sliceProfiles; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java index 0879d53a..c5082afc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java @@ -1,21 +1,9 @@ package pro.gravit.utils; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; - import java.net.URL; import java.net.URLClassLoader; public class PublicURLClassLoader extends URLClassLoader { - @LauncherAPI - public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); - public String nativePath; - - @LauncherAPI - public static ClassLoader getSystemClassLoader() { - return systemclassloader; - } /** * Constructs a new URLClassLoader for the specified URLs using the @@ -66,29 +54,6 @@ public PublicURLClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); } - @Override - public String findLibrary(String name) { - return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); - } - public String getNativeEx() - { - if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) - return ".dll"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) - return ".so"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) - return ".dylib"; - return ""; - } - public String getNativePrefix() - { - if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) - return "lib"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) - return "lib"; - return ""; - } - @Override public void addURL(URL url) { super.addURL(url);