From 98b7aac9fdbb89598a533e1bec7072038c373f52 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 12 Jan 2019 12:01:46 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20optionalJVMArgs,=20optionalClientAr?= =?UTF-8?q?gs=20=D0=B8=20optionalClassPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/defaults/profile1.10.2.cfg | 3 + .../launchserver/defaults/profile1.11.2.cfg | 3 + .../launchserver/defaults/profile1.12.2.cfg | 3 + .../launchserver/defaults/profile1.13.1.cfg | 3 + .../launchserver/defaults/profile1.13.cfg | 3 + .../launchserver/defaults/profile1.4.7.cfg | 3 + .../launchserver/defaults/profile1.5.2.cfg | 3 + .../launchserver/defaults/profile1.6.4.cfg | 3 + .../launchserver/defaults/profile1.7.10.cfg | 3 + .../launchserver/defaults/profile1.7.2.cfg | 3 + .../launchserver/defaults/profile1.8.9.cfg | 3 + .../launchserver/defaults/profile1.9.4.cfg | 3 + .../launcher/client/ClientLauncher.java | 72 ++++++++++++++++++- .../launcher/profiles/ClientProfile.java | 31 ++++++++ 14 files changed, 137 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.10.2.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.10.2.cfg index 07170de9..423bfe49 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.10.2.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.10.2.cfg @@ -38,5 +38,8 @@ "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.11.2.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.11.2.cfg index 843a1e45..77a61146 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.11.2.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.11.2.cfg @@ -38,5 +38,8 @@ "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.12.2.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.12.2.cfg index cd7bec95..b4b2a11f 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.12.2.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.12.2.cfg @@ -38,5 +38,8 @@ "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.1.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.1.cfg index e1af045c..12f2ccae 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.1.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.1.cfg @@ -36,5 +36,8 @@ "classPath": ["forge.jar", "liteloader.jar", "minecraft.jar", "libraries"], "clientArgs": [ ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.cfg index dc542e2c..19afb377 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.13.cfg @@ -36,5 +36,8 @@ "classPath": ["forge.jar", "liteloader.jar", "minecraft.jar", "libraries"], "clientArgs": [ ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.4.7.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.4.7.cfg index 1b6e2956..81857091 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.4.7.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.4.7.cfg @@ -31,5 +31,8 @@ ], "classPath": ["minecraft.jar", "libraries"], "clientArgs": [], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.5.2.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.5.2.cfg index 2dfb92b6..cbc38a43 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.5.2.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.5.2.cfg @@ -31,5 +31,8 @@ ], "classPath": ["minecraft.jar", "libraries"], "clientArgs": [], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.6.4.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.6.4.cfg index ed069739..9e2af4dc 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.6.4.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.6.4.cfg @@ -36,5 +36,8 @@ "--tweakClass", "cpw.mods.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.10.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.10.cfg index 08b81277..fa35d761 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.10.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.10.cfg @@ -34,5 +34,8 @@ "--tweakClass", "cpw.mods.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.2.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.2.cfg index f4ea8501..089b7a85 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.2.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.7.2.cfg @@ -34,5 +34,8 @@ "--tweakClass", "cpw.mods.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.8.9.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.8.9.cfg index cb632342..0550c3de 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.8.9.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.8.9.cfg @@ -34,5 +34,8 @@ "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.9.4.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.9.4.cfg index e38fb8bb..3dff6561 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.9.4.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/profile1.9.4.cfg @@ -34,5 +34,8 @@ "--tweakClass", "net.minecraftforge.fml.common.launcher.FMLTweaker", "--tweakClass", "com.mumfrey.liteloader.launch.LiteLoaderTweaker" ], + "optionalJVMArgs": [], + "optionalClientArgs": [], + "optionalClassPath": [], "whitelist": [] } \ No newline at end of file diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 86531160..00ba27d6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -69,6 +69,10 @@ public static final class Params extends StreamObject { @LauncherAPI public final Set updateOptional; @LauncherAPI + public final Set optionalClientArgs; + @LauncherAPI + public final Set optionalClassPath; + @LauncherAPI public final String accessToken; @LauncherAPI public final boolean autoEnter; @@ -89,9 +93,19 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil boolean autoEnter, boolean fullScreen, int ram, int width, int height) { this.launcherDigest = launcherDigest.clone(); this.updateOptional = new HashSet<>(); + this.optionalClientArgs = new HashSet<>(); + this.optionalClassPath = new HashSet<>(); for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) { if (s.mark) updateOptional.add(s); } + for(ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClientArgs()) + { + if(s.mark) optionalClientArgs.add(s); + } + for(ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClassPath()) + { + if(s.mark) optionalClassPath.add(s); + } // Client paths this.assetDir = assetDir; this.clientDir = clientDir; @@ -114,9 +128,29 @@ public Params(HInput input) throws Exception { assetDir = IOHelper.toPath(input.readString(0)); clientDir = IOHelper.toPath(input.readString(0)); updateOptional = new HashSet<>(); + optionalClientArgs = new HashSet<>(); + optionalClassPath = new HashSet<>(); int len = input.readLength(128); for (int i = 0; i < len; ++i) { - updateOptional.add(new ClientProfile.OptionalFile(input.readString(512), true)); + String file = input.readString(512); + boolean mark = input.readBoolean(); + updateOptional.add(new ClientProfile.OptionalFile(file, mark)); + } + len = input.readLength(256); + for (int i = 0; i < len; ++i) { + int len2 = input.readLength(16); + boolean mark = input.readBoolean(); + String[] optArgs = new String[len]; + for(int j=0;j args, ClientProfile profile Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); } - + for(ClientProfile.OptionalArgs optionalArgs : params.optionalClientArgs) + { + if(optionalArgs.mark) Collections.addAll(args,optionalArgs.args); + } // Add window size args if (params.fullScreen) Collections.addAll(args, "--fullscreen", Boolean.toString(true)); @@ -375,6 +427,13 @@ public static Process launch( // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); Collections.addAll(args, profile.getJvmArgs()); + if(profile.getOptionalJVMArgs() != null) + { + for(ClientProfile.OptionalArgs addArgs : profile.getOptionalJVMArgs()) + { + if(addArgs.mark) Collections.addAll(args,addArgs.args); + } + } Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-javaagent:".concat(pathLauncher)); if (wrapper) @@ -456,6 +515,15 @@ public static void main(String... args) throws Throwable { for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } + for(ClientProfile.OptionalArgs optionalArgs : params.optionalClassPath) + { + if(!optionalArgs.mark) continue; + LinkedList optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args); + for (Path classpathURL : optionalClassPath) { + LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); + } + } + URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index 6f6c1945..93ab5517 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -143,6 +143,18 @@ public int hashCode() { return Objects.hash(file); } } + public static class OptionalArgs + { + @LauncherAPI + public boolean mark; + @LauncherAPI + public String[] args; + + public OptionalArgs(String[] args, boolean mark) { + this.mark = mark; + this.args = args; + } + } // Updater and client watch service @LauncherAPI @@ -170,6 +182,12 @@ public int hashCode() { private final List clientArgs = new ArrayList<>(); @LauncherAPI private final List whitelist = new ArrayList<>(); + @LauncherAPI + private final List optionalJVMArgs = new ArrayList<>(); + @LauncherAPI + private final List optionalClientArgs = new ArrayList<>(); + @LauncherAPI + private final List optionalClassPath = new ArrayList<>(); @Override public int compareTo(ClientProfile o) { @@ -191,6 +209,19 @@ public String[] getClassPath() { return classPath.toArray(new String[0]); } + @LauncherAPI + public List getOptionalJVMArgs() { + return optionalJVMArgs; + } + @LauncherAPI + public List getOptionalClientArgs() { + return optionalClientArgs; + } + @LauncherAPI + public List getOptionalClassPath() { + return optionalClassPath; + } + @LauncherAPI public String[] getClientArgs() { return clientArgs.toArray(new String[0]);