diff options
author | nea <nea@nea.moe> | 2023-11-01 18:50:11 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-11-01 18:50:11 +0100 |
commit | 297cb01f220a617dd08096467978b2fccbc27695 (patch) | |
tree | d467f358313ce3648063da41b66361a840fa7864 /src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java | |
parent | d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4 (diff) | |
download | ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.tar.gz ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.tar.bz2 ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.zip |
Add documentation
Diffstat (limited to 'src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java')
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java b/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java deleted file mode 100644 index ec27694..0000000 --- a/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java +++ /dev/null @@ -1,102 +0,0 @@ -package moe.nea.modernjava.launch; - -import net.minecraft.launchwrapper.Launch; -import net.minecraftforge.fml.common.launcher.FMLTweaker; -import net.minecraftforge.fml.nea.moe.modernjava.IAMFML; - -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class FCPRelauncher { - public static void relaunch() { - - List<String> originalArgs = new ArrayList<>(); - - // Provided by FML - // This is highly processed so there might be some arguments that become lost, but almost everything should be in here. - // Namely non -- arguments get lost. I don't know any of these arguments that the vanilla launcher uses, so it should be fine? - // Also some tweakers are missing. But we can fix this. - Map<String, String> launchArgs = WellKnownBlackboard.launchArgs(); - if ("UnknownFMLProfile".equals(launchArgs.get("--version"))) { - launchArgs.remove("--version"); - } - for (Map.Entry<String, String> argument : launchArgs.entrySet()) { - originalArgs.add(argument.getKey()); - originalArgs.add(argument.getValue()); - } - - - originalArgs.add("--tweakClass"); - originalArgs.add(FMLTweaker.class.getName()); - - System.out.println("Reconstructed original minecraft arguments: " + originalArgs); - - String modernJavaPath = "/home/nea/.sdkman/candidates/java/16.0.2-tem/bin/java"; - - - String thisJarFile = FCPEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getFile(); - thisJarFile = "/home/nea/src/ModernJavaLauncher/target/build/libs/target.jar"; - System.out.println("Found modern java jar at: " + thisJarFile); - - System.out.println("Located modern minecraft at: " + modernJavaPath); - - ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.inheritIO(); - processBuilder.directory(null); - - - List<String> moduleOpens = new ArrayList<>(); - moduleOpens.add("java.base/java.util=ALL-UNNAMED"); - moduleOpens.add("java.base/jdk.internal.loader=ALL-UNNAMED"); - moduleOpens.add("java.base/java.lang.reflect=ALL-UNNAMED"); - - - List<String> fullCommandLine = new ArrayList<>(); - fullCommandLine.add(modernJavaPath); - fullCommandLine.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments()); - fullCommandLine.add("-Dmodernjava.hasrelaunched=true"); - fullCommandLine.add("-Dmodernjava.relaunchclasspath=" + thisJarFile + File.pathSeparator + ManagementFactory.getRuntimeMXBean().getClassPath()); - fullCommandLine.add("--illegal-access=permit"); - for (String open : moduleOpens) { - fullCommandLine.add("--add-opens"); - fullCommandLine.add(open); - } - fullCommandLine.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"); - fullCommandLine.add("-javaagent:" + thisJarFile); - fullCommandLine.add("--add-modules=ALL-MODULE-PATH,ALL-SYSTEM,ALL-DEFAULT,java.sql"); - fullCommandLine.add("-Xbootclasspath/a:" + thisJarFile); - fullCommandLine.add("moe.nea.modernjava.target.RelaunchEntryPoint"); - fullCommandLine.addAll(originalArgs); - - System.out.println("Full relaunch commandline: " + fullCommandLine); - - - processBuilder.command(fullCommandLine); - int exitCode; - try { - try { - Process process = processBuilder.start(); - exitCode = process.waitFor(); - } finally { - try { - new FileOutputStream(FileDescriptor.out).flush(); - new FileOutputStream(FileDescriptor.err).flush(); - } catch (IOException ignored) { - } - } - } catch (IOException | InterruptedException e) { - throw new RuntimeException("Failed to relaunch with old java version", e); - } - - - System.out.println("Exiting outer relaunch layer"); - IAMFML.shutdown(exitCode); - } - -} |