diff --git a/src/main/java/com/luuqui/launcher/JVMPatcher.java b/src/main/java/com/luuqui/launcher/JVMPatcher.java index afaa78c..74eee74 100644 --- a/src/main/java/com/luuqui/launcher/JVMPatcher.java +++ b/src/main/java/com/luuqui/launcher/JVMPatcher.java @@ -216,8 +216,8 @@ private static void patch() { jvmPatcherProgressBar.setValue(2); jvmPatcherState.setText(Locale.getValue("m.jvm_patcher_delete")); try { - if (!FileUtil.fileExists(LauncherGlobals.USER_DIR + File.separator + "java_vm_unpatched")) { - FileUtils.moveDirectory(new File(LauncherGlobals.USER_DIR, "java_vm"), new File(LauncherGlobals.USER_DIR, "java_vm_unpatched")); + if (!FileUtil.fileExists(LauncherApp.javaVMPatchDir + File.separator + "java_vm_unpatched")) { + FileUtils.moveDirectory(new File(LauncherApp.javaVMPatchDir, "java_vm"), new File(LauncherApp.javaVMPatchDir, "java_vm_unpatched")); } } catch (IOException e) { log.error(e); @@ -225,8 +225,8 @@ private static void patch() { jvmPatcherProgressBar.setValue(3); jvmPatcherState.setText(Locale.getValue("m.jvm_patcher_extract")); - Compressor.unzip(LauncherGlobals.USER_DIR + File.separator + "jvm_pack.zip", LauncherGlobals.USER_DIR, false); - new File(LauncherGlobals.USER_DIR, "jvm_pack.zip").delete(); + Compressor.unzip(LauncherApp.javaVMPatchDir + File.separator + "jvm_pack.zip", LauncherApp.javaVMPatchDir, false); + new File(LauncherApp.javaVMPatchDir, "jvm_pack.zip").delete(); jvmPatcherProgressBar.setValue(4); jvmPatcherState.setText(Locale.getValue("m.jvm_patcher_finish")); @@ -249,7 +249,7 @@ private static void downloadPackagedJVM() { try { FileUtils.copyURLToFile( new URL(downloadUrl), - new File(LauncherGlobals.USER_DIR, "jvm_pack.zip"), + new File(LauncherApp.javaVMPatchDir, "jvm_pack.zip"), 0, 0 ); diff --git a/src/main/java/com/luuqui/launcher/LauncherApp.java b/src/main/java/com/luuqui/launcher/LauncherApp.java index 3515cb7..9cf9a56 100644 --- a/src/main/java/com/luuqui/launcher/LauncherApp.java +++ b/src/main/java/com/luuqui/launcher/LauncherApp.java @@ -52,6 +52,8 @@ public class LauncherApp { public static Server selectedServer = null; public static boolean flamingoOnline = false; + public static String javaVMPatchDir = null; + public static void main(String[] args) { LauncherApp app = new LauncherApp(); @@ -331,7 +333,12 @@ private void logGameVMInfo() { private boolean requiresJVMPatch() { // First of all see if we're being forced to patch. - if(_args.length > 0 && _args[0].equals("forceJVMPatch")) return true; + if(_args.length > 0 && _args[0].equals("forceJVMPatch")) { + // set the path dir to wherever we're being forced to patch to. + // this is primarily used for patching when third party servers were selected. + javaVMPatchDir = _args[1]; + return true; + } // You need a 64-bit system to begin with. if(!SystemUtil.is64Bit()) return false; @@ -348,6 +355,8 @@ private boolean requiresJVMPatch() { return false; } + javaVMPatchDir = LauncherGlobals.USER_DIR; + return true; } diff --git a/src/main/java/com/luuqui/launcher/LauncherEventHandler.java b/src/main/java/com/luuqui/launcher/LauncherEventHandler.java index f340982..6f045fc 100644 --- a/src/main/java/com/luuqui/launcher/LauncherEventHandler.java +++ b/src/main/java/com/luuqui/launcher/LauncherEventHandler.java @@ -17,6 +17,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -264,7 +265,6 @@ public static void selectedServerChanged(ActionEvent event) { SettingsGUI.switchUseIngameRPC.setEnabled(true); SettingsGUI.choicePlatform.setEnabled(true); SettingsGUI.forceRebuildButton.setEnabled(true); - SettingsGUI.jvmPatchButton.setEnabled(true); SettingsGUI.argumentsPane.setEnabled(true); SettingsGUI.labelDisclaimer.setVisible(false); SettingsGUI.serverAddressTextField.setEnabled(true); @@ -292,7 +292,6 @@ public static void selectedServerChanged(ActionEvent event) { SettingsGUI.switchUseIngameRPC.setEnabled(false); SettingsGUI.choicePlatform.setEnabled(false); SettingsGUI.forceRebuildButton.setEnabled(false); - SettingsGUI.jvmPatchButton.setEnabled(false); SettingsGUI.argumentsPane.setEnabled(false); SettingsGUI.labelDisclaimer.setVisible(true); SettingsGUI.serverAddressTextField.setEnabled(false); @@ -309,6 +308,7 @@ public static void selectedServerChanged(ActionEvent event) { } updateBanner(); + updateGameJavaVMData(); saveSelectedServer(); } @@ -359,6 +359,17 @@ public static void updateBanner() { refreshThread.start(); } + public static void updateGameJavaVMData() { + Thread thread = new Thread(() -> { + SettingsGUI.javaVMBadge.setText("Your Java VM: " + JavaUtil.getReadableGameJVMData()); + + boolean is64Bit = JavaUtil.getJVMArch(JavaUtil.getGameJVMExePath()) == 64; + SettingsGUI.memorySlider.setMaximum(is64Bit ? 4096 : 1024); + SettingsEventHandler.memoryChangeEvent(SettingsGUI.memorySlider.getValue()); + }); + thread.start(); + } + public static void updateLauncher() { // delete any existing updaters from previous updates new File(LauncherGlobals.USER_DIR + "/updater.jar").delete(); @@ -380,66 +391,66 @@ public static void showLatestChangelog() { } private static String[] getThirdPartyClientStartCommand(Server server, boolean altMode) { - String[] args; + List argsList = new ArrayList<>(); String sanitizedServerName = LauncherApp.getSanitizedServerName(server.name); + if(SystemUtil.isWindows()) { - args = new String[]{ - LauncherGlobals.USER_DIR + File.separator + "thirdparty" + File.separator + sanitizedServerName + File.separator + "java_vm" + File.separator + "bin" + File.separator + "java", - "-classpath", - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/config.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/projectx-config.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/projectx-pcode.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/lwjgl.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/lwjgl_util.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/jinput.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/jshortcut.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-beanutils.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-digester.jar;" + - LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-logging.jar;", - "-Dcom.threerings.getdown=false", - Settings.gameDisableExplicitGC ? "-XX:+DisableExplicitGC" : "", - Settings.gameUseCustomGC && Settings.gameGarbageCollector.equalsIgnoreCase("ParallelOld") ? "-XX:+UseParallelGC" : "", - Settings.gameUseCustomGC ? "-XX:+Use" + Settings.gameGarbageCollector + "GC" : "", - altMode ? "-Xms256M" : Settings.gameGarbageCollector.equalsIgnoreCase("G1") ? "-Xms" + Settings.gameMemory + "M" : "-Xms" + Settings.gameMemory / 2 + "M", - altMode ? "-Xmx512M" : "-Xmx" + Settings.gameMemory + "M", - "-XX:+AggressiveOpts", - "-XX:SoftRefLRUPolicyMSPerMB=10", - "-Djava.library.path=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./native", - "-Dorg.lwjgl.util.NoChecks=true", - "-Dsun.java2d.d3d=false", - "-Dappdir=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + ".", - "-Dresource_dir=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./rsrc", - "com.threerings.projectx.client.ProjectXApp", - }; + argsList.add(LauncherGlobals.USER_DIR + File.separator + "thirdparty" + File.separator + sanitizedServerName + File.separator + "java_vm" + File.separator + "bin" + File.separator + "java"); + argsList.add("-classpath"); + argsList.add(LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/config.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/projectx-config.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/projectx-pcode.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/lwjgl.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/lwjgl_util.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/jinput.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/jshortcut.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-beanutils.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-digester.jar;" + + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./code/commons-logging.jar;"); + argsList.add("-Dcom.threerings.getdown=false"); + if(Settings.gameDisableExplicitGC) argsList.add("-XX:+DisableExplicitGC"); + if(Settings.gameUseCustomGC && Settings.gameGarbageCollector.equalsIgnoreCase("ParallelOld")) argsList.add("-XX:+UseParallelGC"); + if(Settings.gameUseCustomGC) argsList.add("-XX:+Use" + Settings.gameGarbageCollector + "GC"); + argsList.add(altMode ? "-Xms256M" : Settings.gameGarbageCollector.equalsIgnoreCase("G1") ? "-Xms" + Settings.gameMemory + "M" : "-Xms" + Settings.gameMemory / 2 + "M"); + argsList.add(altMode ? "-Xmx512M" : "-Xmx" + Settings.gameMemory + "M"); + argsList.add("-XX:+AggressiveOpts"); + argsList.add("-XX:SoftRefLRUPolicyMSPerMB=10"); + argsList.add("-Djava.library.path=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./native"); + argsList.add("-Dorg.lwjgl.util.NoChecks=true"); + argsList.add("-Dsun.java2d.d3d=false"); + argsList.add("-Dappdir=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "."); + argsList.add("-Dresource_dir=" + LauncherGlobals.USER_DIR + "\\thirdparty\\" + sanitizedServerName + File.separator + "./rsrc"); + argsList.add("com.threerings.projectx.client.ProjectXApp"); } else { - args = new String[]{ - LauncherGlobals.USER_DIR + File.separator + "thirdparty" + File.separator + sanitizedServerName + File.separator + "java" + File.separator + "bin" + File.separator + "java", - "-classpath", - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/config.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/projectx-config.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/projectx-pcode.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/lwjgl.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/lwjgl_util.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/jinput.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/jshortcut.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-beanutils.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-digester.jar:" + - LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-logging.jar:", - "-Dcom.threerings.getdown=false", - altMode ? "-Xms256M" : "-Xms512M", - altMode ? "-Xmx512M" : "-Xmx1024M", - "-XX:+AggressiveOpts", - "-XX:SoftRefLRUPolicyMSPerMB=10", - "-Djava.library.path=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "native", - "-Dorg.lwjgl.util.NoChecks=true", - "-Dsun.java2d.d3d=false", - "-Dappdir=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator, - "-Dresource_dir=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "rsrc", - "com.threerings.projectx.client.ProjectXApp", - }; + argsList.add(LauncherGlobals.USER_DIR + File.separator + "thirdparty" + File.separator + sanitizedServerName + File.separator + "java" + File.separator + "bin" + File.separator + "java"); + argsList.add("-classpath"); + argsList.add(LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/config.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/projectx-config.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/projectx-pcode.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/lwjgl.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/lwjgl_util.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/jinput.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/jshortcut.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-beanutils.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-digester.jar:" + + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "code/commons-logging.jar:"); + argsList.add("-Dcom.threerings.getdown=false"); + if(Settings.gameDisableExplicitGC) argsList.add("-XX:+DisableExplicitGC"); + if(Settings.gameUseCustomGC && Settings.gameGarbageCollector.equalsIgnoreCase("ParallelOld")) argsList.add("-XX:+UseParallelGC"); + if(Settings.gameUseCustomGC) argsList.add("-XX:+Use" + Settings.gameGarbageCollector + "GC"); + argsList.add(altMode ? "-Xms256M" : Settings.gameGarbageCollector.equalsIgnoreCase("G1") ? "-Xms" + Settings.gameMemory + "M" : "-Xms" + Settings.gameMemory / 2 + "M"); + argsList.add(altMode ? "-Xmx512M" : "-Xmx" + Settings.gameMemory + "M"); + argsList.add("-XX:+AggressiveOpts"); + argsList.add("-XX:SoftRefLRUPolicyMSPerMB=10"); + argsList.add("-Djava.library.path=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "native"); + argsList.add("-Dorg.lwjgl.util.NoChecks=true"); + argsList.add("-Dsun.java2d.d3d=false"); + argsList.add("-Dappdir=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator); + argsList.add("-Dresource_dir=" + LauncherGlobals.USER_DIR + "/thirdparty/" + sanitizedServerName + File.separator + "rsrc"); + argsList.add("com.threerings.projectx.client.ProjectXApp"); } - return args; + return argsList.toArray(new String[argsList.size()]); } private static void checkGameLaunched() { diff --git a/src/main/java/com/luuqui/launcher/setting/SettingsEventHandler.java b/src/main/java/com/luuqui/launcher/setting/SettingsEventHandler.java index d16c86e..5310bcf 100644 --- a/src/main/java/com/luuqui/launcher/setting/SettingsEventHandler.java +++ b/src/main/java/com/luuqui/launcher/setting/SettingsEventHandler.java @@ -121,7 +121,11 @@ public static void autoUpdateChangeEvent(ActionEvent action) { public static void jvmPatchEvent(ActionEvent action) { SettingsProperties.setValue("launcher.jvm_patched", "false"); - ProcessUtil.run(new String[] { "java", "-jar", LauncherGlobals.USER_DIR + File.separator + "KnightLauncher.jar", "forceJVMPatch"}, true); + String javaVMPatchDir = LauncherGlobals.USER_DIR; + if(!LauncherApp.selectedServer.name.equalsIgnoreCase("Official")) { + javaVMPatchDir += File.separator + "thirdparty" + File.separator + LauncherApp.getSanitizedServerName(LauncherApp.selectedServer.name); + } + ProcessUtil.run(new String[] { "java", "-jar", LauncherGlobals.USER_DIR + File.separator + "KnightLauncher.jar", "forceJVMPatch", javaVMPatchDir}, true); SettingsGUI.settingsGUIFrame.dispose(); System.exit(1); } diff --git a/src/main/java/com/luuqui/launcher/setting/SettingsGUI.java b/src/main/java/com/luuqui/launcher/setting/SettingsGUI.java index 27a2872..f3eb8a1 100644 --- a/src/main/java/com/luuqui/launcher/setting/SettingsGUI.java +++ b/src/main/java/com/luuqui/launcher/setting/SettingsGUI.java @@ -48,6 +48,7 @@ public class SettingsGUI extends BaseGUI { public static JButton betaCodeRevalidateButton; public static JButton betaCodeClearLocalButton; public static JButton resetGameSettingsButton; + public static JLabel javaVMBadge = new JLabel(); public SettingsGUI(LauncherApp app) { super(); @@ -311,7 +312,7 @@ protected JPanel createGamePanel() { headerLabel.setFont(Fonts.fontMedGiant); gamePanel.add(headerLabel); - JLabel javaVMBadge = new JLabel("Your Java VM: " + JavaUtil.getReadableGameJVMData()); + javaVMBadge = new JLabel("Your Java VM: " + JavaUtil.getReadableGameJVMData()); javaVMBadge.setBounds(370, 35, 235, 18); javaVMBadge.setHorizontalAlignment(SwingConstants.CENTER); javaVMBadge.setFont(Fonts.fontRegSmall); diff --git a/src/main/java/com/luuqui/util/JavaUtil.java b/src/main/java/com/luuqui/util/JavaUtil.java index 64377fd..caaf2b4 100644 --- a/src/main/java/com/luuqui/util/JavaUtil.java +++ b/src/main/java/com/luuqui/util/JavaUtil.java @@ -1,5 +1,6 @@ package com.luuqui.util; +import com.luuqui.launcher.LauncherApp; import com.luuqui.launcher.LauncherGlobals; import java.io.File; @@ -118,11 +119,19 @@ public static String getReadableGameJVMData() { } public static String getGameJavaDirPath() { - File javaVMDir = new File(LauncherGlobals.USER_DIR, "/java_vm"); + String startingDirPath = LauncherGlobals.USER_DIR; + + if(LauncherApp.selectedServer != null) { + if(!LauncherApp.selectedServer.name.equalsIgnoreCase("Official")) { + startingDirPath += File.separator + "thirdparty" + File.separator + LauncherApp.getSanitizedServerName(LauncherApp.selectedServer.name); + } + } + + File javaVMDir = new File(startingDirPath, "/java_vm"); if (javaVMDir.exists() && javaVMDir.isDirectory()) { return javaVMDir.getAbsolutePath(); } - File javaDir = new File(LauncherGlobals.USER_DIR, "/java"); + File javaDir = new File(startingDirPath, "/java"); if (javaDir.exists() && javaDir.isDirectory()) { return javaDir.getAbsolutePath(); }