diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/Main.java b/src/main/java/io/github/zekerzhayard/forgewrapper/Main.java index 7ac1802..146c970 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/Main.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/Main.java @@ -3,6 +3,7 @@ package io.github.zekerzhayard.forgewrapper; import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -11,6 +12,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import cpw.mods.modlauncher.Launcher; +import io.github.zekerzhayard.forgewrapper.converter.Converter; import io.github.zekerzhayard.forgewrapper.installer.Download; public class Main { @@ -18,12 +20,14 @@ public class Main { URL[] urls = Utils.getURLs(new ArrayList<>()); Pattern pattern = Pattern.compile("forge-(?[0-9.]+)-(?[0-9.]+)\\.jar"); String version = ""; + String installerFileStr = ""; for (URL url : urls) { Matcher matcher = pattern.matcher(url.getFile()); if (matcher.find() && url.getFile().endsWith(matcher.group(0))) { version = matcher.group("mcVersion") + "-" + matcher.group("forgeVersion"); String installerUrl = String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar", version, version); - Download.download(installerUrl, String.format("./.forgewrapper/forge-%s-installer.jar", version)); + installerFileStr = String.format("./.forgewrapper/forge-%s-installer.jar", version); + Download.download(installerUrl, installerFileStr); break; } } @@ -31,7 +35,7 @@ public class Main { URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { Main.class.getProtectionDomain().getCodeSource().getLocation(), Launcher.class.getProtectionDomain().getCodeSource().getLocation(), - new File(String.format("./.forgewrapper/forge-%s-installer.jar", version)).toURI().toURL() + new File(installerFileStr).toURI().toURL() }, null); Class installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer"); @@ -39,16 +43,7 @@ public class Main { return; } List argsList = Stream.of(args).collect(Collectors.toList()); - argsList.add("--launchTarget"); - argsList.add("fmlclient"); - argsList.add("--fml.forgeVersion"); - argsList.add((String) installer.getMethod("getForgeVersion").invoke(null)); - argsList.add("--fml.mcVersion"); - argsList.add((String) installer.getMethod("getMcVersion").invoke(null)); - argsList.add("--fml.forgeGroup"); - argsList.add("net.minecraftforge"); - argsList.add("--fml.mcpVersion"); - argsList.add((String) installer.getMethod("getMcpVersion").invoke(null)); + argsList.addAll(Converter.getAdditionalArgs(Paths.get(installerFileStr))); Launcher.main(argsList.toArray(new String[0])); } diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/converter/Converter.java b/src/main/java/io/github/zekerzhayard/forgewrapper/converter/Converter.java index e3e0653..f9737eb 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/converter/Converter.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/converter/Converter.java @@ -10,6 +10,7 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.zip.ZipEntry; @@ -24,10 +25,7 @@ import com.google.gson.JsonParser; public class Converter { public static void convert(Path installerPath, Path targetDir) throws Exception { JsonObject installer = getInstallerJson(installerPath); - - ArrayList arguments = new ArrayList<>(); - - getElement(installer.getAsJsonObject("arguments"), "game").getAsJsonArray().iterator().forEachRemaining(je -> arguments.add(je.getAsString())); + List arguments = getAdditionalArgs(installer); String mcVersion = arguments.get(arguments.indexOf("--fml.mcVersion") + 1); String forgeVersion = arguments.get(arguments.indexOf("--fml.forgeVersion") + 1); String forgeFullVersion = "forge-" + mcVersion + "-" + forgeVersion; @@ -60,7 +58,18 @@ public class Converter { Files.copy(installerPath, forgeWrapperPath.resolve(forgeFullVersion + "-installer.jar"), StandardCopyOption.REPLACE_EXISTING); } - private static JsonObject getInstallerJson(Path installerPath) { + public static List getAdditionalArgs(Path installerPath) { + JsonObject installer = getInstallerJson(installerPath); + return getAdditionalArgs(installer); + } + + public static List getAdditionalArgs(JsonObject installer) { + List args = new ArrayList<>(); + getElement(installer.getAsJsonObject("arguments"), "game").getAsJsonArray().iterator().forEachRemaining(je -> args.add(je.getAsString())); + return args; + } + + public static JsonObject getInstallerJson(Path installerPath) { try { ZipFile zf = new ZipFile(installerPath.toFile()); ZipEntry versionFile = zf.getEntry("version.json"); diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java index c1c7d8d..ad60ad7 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java @@ -5,11 +5,9 @@ import net.minecraftforge.installer.json.Install; import net.minecraftforge.installer.json.Util; public class Installer { - private static Install install; - public static boolean install() { ProgressCallback monitor = ProgressCallback.withOutputs(System.out); - install = Util.loadInstallProfile(); + Install install = Util.loadInstallProfile(); if (System.getProperty("java.net.preferIPv4Stack") == null) { System.setProperty("java.net.preferIPv4Stack", "true"); } @@ -20,16 +18,4 @@ public class Installer { monitor.message("java.net.preferIPv4Stack=" + System.getProperty("java.net.preferIPv4Stack")); return new ClientInstall4MultiMC(install, monitor).run(null, input -> true); } - - public static String getForgeVersion() { - return install.getVersion().substring(install.getVersion().lastIndexOf("-") + 1); - } - - public static String getMcVersion() { - return install.getMinecraft(); - } - - public static String getMcpVersion() { - return install.getData(true).get("MCP_VERSION").replace("'", ""); - } }