mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] SYSTEM_ARGS classLoaderConfig
This commit is contained in:
parent
b901a5b9e4
commit
1a8ec31a5b
3 changed files with 23 additions and 14 deletions
|
@ -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<URL> 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<URL> 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<Path> resolveClassPathStream(Path clientDir, String... cla
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
public static Stream<Path> resolveClassPath(Path clientDir, Set<OptionalAction> actions, ClientProfile profile) throws IOException {
|
||||
Stream<Path> 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<String> args = new LinkedList<>();
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -521,7 +521,7 @@ public enum SecurityManagerConfig {
|
|||
}
|
||||
|
||||
public enum ClassLoaderConfig {
|
||||
AGENT, LAUNCHER
|
||||
AGENT, LAUNCHER, SYSTEM_ARGS
|
||||
}
|
||||
|
||||
public enum SignedClientConfig {
|
||||
|
|
Loading…
Reference in a new issue