[FEATURE] Isolate minecraft

This commit is contained in:
Gravita 2022-05-19 00:38:12 +07:00
parent 4ff13a67b9
commit 857901a667
2 changed files with 10 additions and 1 deletions

View file

@ -7,6 +7,7 @@
import java.net.URLClassLoader; import java.net.URLClassLoader;
public class ClientClassLoader extends URLClassLoader { public class ClientClassLoader extends URLClassLoader {
private static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
public String nativePath; public String nativePath;
/** /**
@ -58,6 +59,14 @@ public ClientClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent); super(urls, parent);
} }
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if(name != null && (name.startsWith("pro.gravit.launcher.") || name.startsWith("pro.gravit.utils."))) {
return SYSTEM_CLASS_LOADER.loadClass(name);
}
return super.loadClass(name, resolve);
}
@Override @Override
public String findLibrary(String name) { public String findLibrary(String name) {
return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx());

View file

@ -145,7 +145,7 @@ public static void main(String[] args) throws Throwable {
} }
ClientProfile.ClassLoaderConfig classLoaderConfig = profile.getClassLoaderConfig(); ClientProfile.ClassLoaderConfig classLoaderConfig = profile.getClassLoaderConfig();
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) { if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) {
ClientClassLoader classLoader = new ClientClassLoader(classpathURLs.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); ClientClassLoader classLoader = new ClientClassLoader(classpathURLs.toArray(new URL[0]), ClientLauncherEntryPoint.class.getClassLoader());
System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator))); System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)));
ClientLauncherEntryPoint.classLoader = classLoader; ClientLauncherEntryPoint.classLoader = classLoader;
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);