From 1a8ec31a5beaf9769fc6c7abebe171a222f4450b Mon Sep 17 00:00:00 2001 From: Gravita Date: Sun, 11 Jul 2021 13:44:57 +0700 Subject: [PATCH] [FEATURE] SYSTEM_ARGS classLoaderConfig --- .../client/ClientLauncherEntryPoint.java | 32 +++++++++++-------- .../client/ClientLauncherProcess.java | 3 ++ .../launcher/profiles/ClientProfile.java | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 8bfe5f27..0646f59f 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -110,13 +110,7 @@ public static void main(String[] args) throws Throwable { // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); - List classpath = new LinkedList<>(); - resolveClassPathStream(clientDir, params.profile.getClassPath()).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); - - for (OptionalAction a : params.actions) { - if (a instanceof OptionalActionClassPath) - resolveClassPathStream(clientDir, ((OptionalActionClassPath) a).args).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); - } + List classpath = resolveClassPath(clientDir, params.actions, params.profile).map(IOHelper::toURL).collect(Collectors.toList()); // Start client with WatchService monitoring boolean digest = !profile.isUpdateFastCheck(); LogHelper.debug("Restore sessions"); @@ -132,19 +126,18 @@ public static void main(String[] args) throws Throwable { throw new RequestException("Connection failed", e); } }; - if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.LAUNCHER) { + ClientProfile.ClassLoaderConfig classLoaderConfig = profile.getClassLoaderConfig(); + if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) { ClientClassLoader classLoader = new ClientClassLoader(classpath.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); ClientLauncherEntryPoint.classLoader = classLoader; Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = clientDir.resolve("natives").toString(); LauncherEngine.modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(engine, classLoader, profile)); - AuthService.username = params.playerProfile.username; - AuthService.uuid = params.playerProfile.uuid; ClientService.classLoader = classLoader; ClientService.nativePath = classLoader.nativePath; classLoader.addURL(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL()); ClientService.baseURLs = classLoader.getURLs(); - } else if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) { + } else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) { ClientLauncherEntryPoint.classLoader = ClassLoader.getSystemClassLoader(); classpath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL()); for (URL url : classpath) { @@ -153,11 +146,15 @@ public static void main(String[] args) throws Throwable { ClientService.instrumentation = LauncherAgent.inst; ClientService.nativePath = clientDir.resolve("natives").toString(); LauncherEngine.modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(engine, classLoader, profile)); - AuthService.username = params.playerProfile.username; - AuthService.uuid = params.playerProfile.uuid; ClientService.classLoader = classLoader; ClientService.baseURLs = classpath.toArray(new URL[0]); + } else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) { + ClientLauncherEntryPoint.classLoader = ClassLoader.getSystemClassLoader(); + ClientService.classLoader = ClassLoader.getSystemClassLoader(); + ClientService.baseURLs = classpath.toArray(new URL[0]); } + AuthService.username = params.playerProfile.username; + AuthService.uuid = params.playerProfile.uuid; if (params.profile.getRuntimeInClientConfig() != ClientProfile.RuntimeInClientConfig.NONE) { CommonHelper.newThread("Client Launcher Thread", true, () -> { try { @@ -269,6 +266,15 @@ private static Stream resolveClassPathStream(Path clientDir, String... cla return builder.build(); } + public static Stream resolveClassPath(Path clientDir, Set actions, ClientProfile profile) throws IOException { + Stream result = resolveClassPathStream(clientDir, profile.getClassPath()); + for (OptionalAction a : actions) { + if (a instanceof OptionalActionClassPath) + result = Stream.concat(result, resolveClassPathStream(clientDir, ((OptionalActionClassPath) a).args)); + } + return result; + } + private static void launch(ClientProfile profile, ClientLauncherProcess.ClientParams params) throws Throwable { // Add client args Collection args = new LinkedList<>(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 58b7037e..ac25b06e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; +import java.util.stream.Collectors; public class ClientLauncherProcess { public final ClientParams params = new ClientParams(); @@ -152,6 +153,8 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { //ADD CLASSPATH if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) { processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString())); + } else if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) { + systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(workDir, params.actions, params.profile).map(Path::toString).collect(Collectors.toList())); } if (useLegacyJavaClassPathProperty) { processArgs.add("-Djava.class.path=".concat(String.join(getPathSeparator(), systemClassPath))); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index f923b168..36eee3c0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -521,7 +521,7 @@ public enum SecurityManagerConfig { } public enum ClassLoaderConfig { - AGENT, LAUNCHER + AGENT, LAUNCHER, SYSTEM_ARGS } public enum SignedClientConfig {