Skip to content

Commit

Permalink
Add editors support for third party servers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasluqui committed Nov 15, 2024
1 parent 5414fc3 commit 50dbfda
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
1 change: 1 addition & 0 deletions assets/lang/lang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ error.flamingo_offline="Could not connect to Flamingo.\nSome launcher functional
error.no_compatible_jvm="No compatible Java VM to start the editor with."
error.folders_within_mods_folder="There are folders within the mods folder.\nYou do not need to extract the .zip files, simply drag and drop the .zip files inside the mods folder."
error.unsupported_64bit="Your system does not support a 64-bit Java VM."
error.not_supported="Not supported."

# Discord RPC strings
presence.using="Using Knight Launcher"
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/luuqui/launcher/LauncherEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ public static void selectedServerChanged(ActionEvent event) {
LauncherGUI.playerCountTooltipButton.setVisible(true);
LauncherGUI.serverInfoButton.setEnabled(false);
LauncherGUI.serverInfoButton.setVisible(false);
LauncherGUI.editorsButton.setEnabled(true);
LauncherGUI.editorsButton.setVisible(true);
} else {
LauncherGUI.launchButton.setEnabled(selectedServer.enabled == 1);
if(!selectedServer.isInstalled()) {
Expand All @@ -335,10 +333,6 @@ public static void selectedServerChanged(ActionEvent event) {

// TODO: Fetch player count.
LauncherGUI.playerCountLabel.setVisible(false);

// TODO: Editors support for third party servers.
LauncherGUI.editorsButton.setEnabled(false);
LauncherGUI.editorsButton.setVisible(false);
}
LauncherApp.selectedServer = selectedServer;

Expand Down
76 changes: 53 additions & 23 deletions src/main/java/com/luuqui/launcher/editor/EditorsEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.luuqui.launcher.editor;

import com.luuqui.dialog.Dialog;
import com.luuqui.launcher.LauncherApp;
import com.luuqui.launcher.LauncherGlobals;
import com.luuqui.launcher.Locale;
import com.luuqui.launcher.ModuleLoader;
Expand All @@ -10,6 +11,8 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static com.luuqui.launcher.editor.Log.log;

Expand All @@ -18,7 +21,7 @@ public class EditorsEventHandler {
public static boolean isBooting = false;
public static boolean spiralviewExtracted = false;

private static void startEditor(String editor, String arg) {
private static void startEditor(String editor, String arg, boolean thirdparty) {
if(!spiralviewExtracted) {
ModuleLoader.loadSpiralview();
spiralviewExtracted = true;
Expand All @@ -41,45 +44,72 @@ private static void startEditor(String editor, String arg) {
Dialog.push(Locale.getValue("error.no_compatible_jvm"), Locale.getValue("b.editors"), JOptionPane.ERROR_MESSAGE);
}

String[] editorCmdLine = new String[] {
javaVMPath,
"-classpath",
LauncherGlobals.USER_DIR + File.separator + "./KnightLauncher/modules/spiralview/spiralview.jar" + libSeparator +
LauncherGlobals.USER_DIR + File.separator + "./code/projectx-config.jar" + libSeparator +
LauncherGlobals.USER_DIR + File.separator + "./code/projectx-pcode.jar" + libSeparator +
LauncherGlobals.USER_DIR + File.separator + "./code/lwjgl_util.jar" + libSeparator +
LauncherGlobals.USER_DIR + File.separator + "./code/lwjgl.jar",
"-Xms2G",
"-Xmx2G",
"-Dappdir=" + LauncherGlobals.USER_DIR + File.separator + "./",
"-Dresource_dir=" + LauncherGlobals.USER_DIR + File.separator + "./rsrc",
"-Djava.library.path=" + LauncherGlobals.USER_DIR + File.separator + "./native",
editor,
arg
};

ProcessUtil.runFromDirectory(editorCmdLine, LauncherGlobals.USER_DIR, true);
String classpath = "";
String rootDir = LauncherApp.selectedServer.getRootDirectory();
if(!thirdparty) classpath += rootDir + File.separator + "./KnightLauncher/modules/spiralview/spiralview.jar" + libSeparator;
if(thirdparty) classpath += LauncherGlobals.USER_DIR + File.separator + "./KnightLauncher.jar" + libSeparator;
classpath += rootDir + File.separator + "./code/projectx-config.jar" + libSeparator;
classpath += rootDir + File.separator + "./code/projectx-pcode.jar" + libSeparator;
classpath += rootDir + File.separator + "./code/lwjgl_util.jar" + libSeparator;
classpath += rootDir + File.separator + "./code/lwjgl.jar";

List<String> editorCmdLine = new ArrayList<>();
editorCmdLine.add(javaVMPath);
editorCmdLine.add("-classpath");
editorCmdLine.add(classpath);
editorCmdLine.add("-Xms2G");
editorCmdLine.add("-Xmx2G");
if(thirdparty) {
editorCmdLine.add("-Dcom.threerings.getdown=false");
editorCmdLine.add("-XX:SoftRefLRUPolicyMSPerMB=10");
editorCmdLine.add("-Dorg.lwjgl.util.NoChecks=true");
editorCmdLine.add("-Dsun.java2d.d3d=false");
editorCmdLine.add("-XX:+AggressiveOpts");
}
editorCmdLine.add("-Dappdir=" + rootDir + File.separator + "./");
editorCmdLine.add("-Dresource_dir=" + rootDir + File.separator + "./rsrc");
editorCmdLine.add("-Djava.library.path=" + rootDir + File.separator + "./native");
editorCmdLine.add(editor);
editorCmdLine.add(arg);

ProcessUtil.runFromDirectory(editorCmdLine.toArray(new String[editorCmdLine.size()]), rootDir, true);
}
}

public static void startModelViewer(ActionEvent actionEvent) {
EditorsGUI.editorLaunchFakeProgressBar.setMaximum(150);
startEditor("com.luuqui.spiralview.ModelViewerHook", "rsrc/character/pc/model.dat");
if(LauncherApp.selectedServer.isOfficial()) {
startEditor("com.luuqui.spiralview.ModelViewerHook", "rsrc/character/pc/model.dat", false);
} else {
startEditor("com.threerings.opengl.model.tools.ModelViewer", LauncherApp.selectedServer.getRootDirectory() + "rsrc/character/pc/model.dat", true);
}
}

public static void startSceneEditor(ActionEvent actionEvent) {
EditorsGUI.editorLaunchFakeProgressBar.setMaximum(155);
startEditor("com.luuqui.spiralview.SceneEditorHook", "");
if(LauncherApp.selectedServer.isOfficial()) {
startEditor("com.luuqui.spiralview.SceneEditorHook", "", false);
} else {
startEditor("com.threerings.tudey.tools.SceneEditor", "", true);
}
}

public static void startInterfaceTester(ActionEvent actionEvent) {
EditorsGUI.editorLaunchFakeProgressBar.setMaximum(110);
startEditor("com.luuqui.spiralview.InterfaceTesterHook", "");
if(LauncherApp.selectedServer.isOfficial()) {
startEditor("com.luuqui.spiralview.InterfaceTesterHook", "", false);
} else {
Dialog.push(Locale.getValue("error.not_supported"), Locale.getValue("t.error"), JOptionPane.ERROR_MESSAGE);
}
}

public static void startParticleEditor(ActionEvent actionEvent) {
EditorsGUI.editorLaunchFakeProgressBar.setMaximum(125);
startEditor("com.luuqui.spiralview.ParticleEditorHook", "");
if(LauncherApp.selectedServer.isOfficial()) {
startEditor("com.luuqui.spiralview.ParticleEditorHook", "", false);
} else {
startEditor("com.threerings.opengl.effect.tools.ParticleEditor", "", true);
}
}

protected static void startedBooting() {
Expand Down

0 comments on commit 50dbfda

Please sign in to comment.