From bc6da641d6f45257285098a2f0eddc391573860a Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:08:22 +0700 Subject: [PATCH] [FEATURE] Support autobuild lwjgl3ify --- .../helper/MakeProfileHelper.java | 75 +++++++++++++------ .../client/ClientLauncherEntryPoint.java | 18 ++++- 2 files changed, 66 insertions(+), 27 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java index 7f81329a..d627d3ed 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -27,6 +27,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setMainClass(getMainClassByVersion(version, options)); builder.setServers(List.of(new ClientProfile.ServerProfile(title, "localhost", 25565))); // ------------ + var lwjgl3ify = findOption(options, Lwjgl3ifyOption.class); builder.setUpdateVerify(List.of("libraries", "natives", "mods", "minecraft.jar", "forge.jar", "liteloader.jar")); { List classPath = new ArrayList<>(5); @@ -44,8 +45,40 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti jvmArgs.add("-XX:+DisableAttachMechanism"); // Official Mojang launcher java arguments if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) { - jvmArgs.add("-XX:+UseConcMarkSweepGC"); - jvmArgs.add("-XX:+CMSIncrementalMode"); + // lwjgl3ify arguments https://github.com/GTNewHorizons/lwjgl3ify + jvmArgs.add("-Djava.security.manager=allow"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/jdk.internal.loader=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.net=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.nio=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.io=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.lang=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.lang.reflect=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.text=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.util=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/jdk.internal.reflect=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/sun.nio.ch=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED,java.naming"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/sun.awt=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/sun.awt.image=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/com.sun.imageio.plugins.png=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("jdk.dynalink/jdk.dynalink.beans=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.sql.rowset/javax.sql.rowset.serial=ALL-UNNAMED"); } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) <= 0) { // 1.13 - 1.16.5 jvmArgs.add("-XX:+UseG1GC"); jvmArgs.add("-XX:+UnlockExperimentalVMOptions"); @@ -116,14 +149,8 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti } } } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_17) >= 0 && version.compareTo(ClientProfileVersions.MINECRAFT_1_18) < 0) { - builder.setMinJavaVersion(16); - builder.setRecommendJavaVersion(16); - } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) { - builder.setMinJavaVersion(17); - builder.setRecommendJavaVersion(17); - } + builder.setMinJavaVersion(17); + builder.setRecommendJavaVersion(17); if(version.compareTo(ClientProfileVersions.MINECRAFT_1_20_3) >= 0) { builder.setMinJavaVersion(21); builder.setRecommendJavaVersion(21); @@ -133,7 +160,10 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setJvmArgs(jvmArgs); builder.setUpdateOptional(optionals); List clientArgs = new ArrayList<>(); - if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) == 0) { + jvmArgs.add("-Drfb.skipClassLoaderCheck=true"); + } + if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent() || findOption(options, MakeProfileRfbOption.class).isPresent()) { if (findOption(options, MakeProfileOptionLiteLoader.class).isPresent()) { clientArgs.add("--tweakClass"); clientArgs.add("com.mumfrey.liteloader.launch.LiteLoaderTweaker"); @@ -145,20 +175,9 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti } else { clientArgs.add("cpw.mods.fml.common.launcher.FMLTweaker"); } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) { - builder.setMinJavaVersion(8); - builder.setRecommendJavaVersion(8); - builder.setMaxJavaVersion(8); - } } } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) { - if (forge.isPresent()) { - clientArgs.addAll(forge.get().makeClientArgs()); - builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.SYSTEM_ARGS); - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_16_5) <= 0) { - builder.setMaxJavaVersion(15); - } - } + forge.ifPresent(makeProfileOptionForge -> clientArgs.addAll(makeProfileOptionForge.makeClientArgs())); } builder.setClientArgs(clientArgs); @@ -171,6 +190,9 @@ private static Optional findOption(MakeProfileOption[] options, Class } public static String getMainClassByVersion(ClientProfile.Version version, MakeProfileOption... options) { + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) == 0) { + return "com.gtnewhorizons.retrofuturabootstrap.Main"; + } if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { return "net.minecraft.launchwrapper.Launch"; } @@ -320,6 +342,13 @@ public static class MakeProfileOptionLaunchWrapper implements MakeProfileOption } + public static class MakeProfileRfbOption implements MakeProfileOption { + + } + + public record Lwjgl3ifyOption(String lwjgl3ifyForgePatches) implements MakeProfileOption { + } + public static class MakeProfileOptionFabric implements MakeProfileOption { public String jimfsPath; public String guavaPath; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index e67726dc..6c83934e 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -121,6 +121,11 @@ private static void realMain(String[] args) throws Throwable { List classpath = resolveClassPath(clientDir, params.actions, params.profile) .filter(x -> !profile.getModulePath().contains(clientDir.relativize(x).toString())) .collect(Collectors.toCollection(ArrayList::new)); + if(LogHelper.isDevEnabled()) { + for(var e : classpath) { + LogHelper.dev("Classpath entry %s", e); + } + } List classpathURLs = classpath.stream().map(IOHelper::toURL).collect(Collectors.toList()); // Start client with WatchService monitoring RequestService service; @@ -256,7 +261,12 @@ private static Stream resolveClassPathStream(Path clientDir, String... cla for (String classPathEntry : classPath) { Path path = clientDir.resolve(IOHelper.toPath(classPathEntry.replace(IOHelper.CROSS_SEPARATOR, IOHelper.PLATFORM_SEPARATOR))); if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(builder), false); + List jars = new ArrayList<>(32); + IOHelper.walk(path, new ClassPathFileVisitor(jars), false); + Collections.sort(jars); + for(var e : jars) { + builder.accept(e); + } continue; } builder.accept(path); @@ -322,16 +332,16 @@ private static void launch(ClientProfile profile, ClientParams params) throws Th } private static final class ClassPathFileVisitor extends SimpleFileVisitor { - private final Stream.Builder result; + private final List result; - private ClassPathFileVisitor(Stream.Builder result) { + private ClassPathFileVisitor(List result) { this.result = result; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (IOHelper.hasExtension(file, "jar") || IOHelper.hasExtension(file, "zip")) - result.accept(file); + result.add(file); return super.visitFile(file, attrs); } }