From c19f6d4dcd0650f5f30c59a907d8022a4c642c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 14 Jul 2017 08:43:35 +0200 Subject: NOISSUE allow running legacy without the applet wrapper Add 'noapplet' as a trait to do that. --- .../org/multimc/onesix/OneSixLauncher.java | 93 ++++++---------------- 1 file changed, 25 insertions(+), 68 deletions(-) (limited to 'libraries') diff --git a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java b/libraries/launcher/org/multimc/onesix/OneSixLauncher.java index 61a30ede..f057e55a 100644 --- a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java +++ b/libraries/launcher/org/multimc/onesix/OneSixLauncher.java @@ -111,34 +111,37 @@ public class OneSixLauncher implements Launcher System.setProperty("minecraft.applet.TargetDirectory", cwd); - String[] mcArgs = new String[2]; - mcArgs[0] = userName; - mcArgs[1] = sessionId; + if(!traits.contains("noapplet")) + { + Utils.log("Launching with applet wrapper..."); + try + { + Class MCAppletClass = cl.loadClass(appletClass); + Applet mcappl = (Applet) MCAppletClass.newInstance(); + LegacyFrame mcWindow = new LegacyFrame(windowTitle); + mcWindow.start(mcappl, userName, sessionId, winSize, maximize); + return 0; + } catch (Exception e) + { + Utils.log("Applet wrapper failed:", "Error"); + e.printStackTrace(System.err); + Utils.log(); + Utils.log("Falling back to using main class."); + } + } - Utils.log("Launching with applet wrapper..."); + // init params for the main method to chomp on. + String[] paramsArray = mcparams.toArray(new String[mcparams.size()]); try { - Class MCAppletClass = cl.loadClass(appletClass); - Applet mcappl = (Applet) MCAppletClass.newInstance(); - LegacyFrame mcWindow = new LegacyFrame(windowTitle); - mcWindow.start(mcappl, userName, sessionId, winSize, maximize); + mc.getMethod("main", String[].class).invoke(null, (Object) paramsArray); + return 0; } catch (Exception e) { - Utils.log("Applet wrapper failed:", "Error"); + Utils.log("Failed to invoke the Minecraft main class:", "Fatal"); e.printStackTrace(System.err); - Utils.log(); - Utils.log("Falling back to compatibility mode."); - try - { - mc.getMethod("main", String[].class).invoke(null, (Object) mcArgs); - } catch (Exception e1) - { - Utils.log("Failed to invoke the Minecraft main class:", "Fatal"); - e1.printStackTrace(System.err); - return -1; - } + return -1; } - return 0; } int launchWithMainClass() @@ -181,53 +184,7 @@ public class OneSixLauncher implements Launcher e.printStackTrace(System.err); return -1; } - /* - final java.nio.ByteBuffer[] icons = IconLoader.load("icon.png"); - new Thread() { - public void run() { - ClassLoader cl = ClassLoader.getSystemClassLoader(); - try - { - Class Display; - Method isCreated; - Method setTitle; - Method setIcon; - Field fieldWindowCreated; - Boolean created = false; - Display = cl.loadClass("org.lwjgl.opengl.Display"); - fieldWindowCreated = Display.getDeclaredField("window_created"); - fieldWindowCreated.setAccessible( true ); - setTitle = Display.getMethod("setTitle", String.class); - setIcon = Display.getMethod("setIcon", java.nio.ByteBuffer[].class); - created = (Boolean) fieldWindowCreated.get( null ); - // set the window title? Maybe? - while(!created) - { - try - { - Thread.sleep(150); - created = (Boolean) fieldWindowCreated.get( null ); - } catch (InterruptedException ignored) {} - } - // Give it a bit more time ;) - Thread.sleep(150); - // set the title - setTitle.invoke(null,windowTitle); - // only set icon when there's actually something to set... - if(icons.length > 0) - { - setIcon.invoke(null,(Object)icons); - } - } - catch (Exception e) - { - System.err.println("Couldn't set window icon or title."); - e.printStackTrace(System.err); - } - } - } - .start(); - */ + // init params for the main method to chomp on. String[] paramsArray = mcparams.toArray(new String[mcparams.size()]); try -- cgit v1.2.3