diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-08-14 23:30:12 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-08-14 23:30:12 +0200 |
commit | d7b3887fe1e754aa0ec5970a175e439aa5c8fe86 (patch) | |
tree | 29a1cda18e804793eaf3fbeac30a0d373abd493b /depends/launcher/org/multimc/onesix | |
parent | 0adb572a07d13a35bdb378ba024655de6a9967b3 (diff) | |
download | MultiMC-d7b3887fe1e754aa0ec5970a175e439aa5c8fe86.tar MultiMC-d7b3887fe1e754aa0ec5970a175e439aa5c8fe86.tar.gz MultiMC-d7b3887fe1e754aa0ec5970a175e439aa5c8fe86.tar.lz MultiMC-d7b3887fe1e754aa0ec5970a175e439aa5c8fe86.tar.xz MultiMC-d7b3887fe1e754aa0ec5970a175e439aa5c8fe86.zip |
Revert "NOISSUE redo the launcher part"
This reverts commit c1f7dda8fe412263ccd82fbf3d56687bd291c73c.
Diffstat (limited to 'depends/launcher/org/multimc/onesix')
-rw-r--r-- | depends/launcher/org/multimc/onesix/MMCClassLoader.java | 42 | ||||
-rw-r--r-- | depends/launcher/org/multimc/onesix/OneSixLauncher.java | 162 |
2 files changed, 96 insertions, 108 deletions
diff --git a/depends/launcher/org/multimc/onesix/MMCClassLoader.java b/depends/launcher/org/multimc/onesix/MMCClassLoader.java deleted file mode 100644 index 6c768ffe..00000000 --- a/depends/launcher/org/multimc/onesix/MMCClassLoader.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.multimc.onesix; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.List; - -public class MMCClassLoader extends URLClassLoader -{ - public MMCClassLoader(String natives, List<String> allJars) - throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, - InvocationTargetException, IllegalAccessException, NoSuchFieldException - { - super(process(allJars)); - Method setProperty = loadClass("java.lang.System").getMethod("setProperty", String.class, String.class); - setProperty.invoke(null, "java.library.path", natives); - setProperty.invoke(null, "org.lwjgl.librarypath", natives); - setProperty.invoke(null, "net.java.games.input.librarypath", natives); - } - - private static URL[] process(List<String> allJars) throws MalformedURLException - { - URL[] urls = new URL[allJars.size()]; - for (int i = 0; i < allJars.size(); i++) - { - String jar = allJars.get(i); - urls[i] = new File(jar).toURI().toURL(); - } - return urls; - } - - // TODO: use this method to use custom log configs - // @Override - // public URL findResource(String name) - // { - // return super.findResource(name); - // } -} diff --git a/depends/launcher/org/multimc/onesix/OneSixLauncher.java b/depends/launcher/org/multimc/onesix/OneSixLauncher.java index 6f9ce874..8ef6376d 100644 --- a/depends/launcher/org/multimc/onesix/OneSixLauncher.java +++ b/depends/launcher/org/multimc/onesix/OneSixLauncher.java @@ -18,8 +18,8 @@ package org.multimc.onesix; import org.multimc.*; import java.applet.Applet; -import java.awt.*; import java.io.File; +import java.awt.*; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -49,13 +49,13 @@ public class OneSixLauncher implements Launcher private String cwd; // the much abused system classloader, for convenience (for further abuse) - private MMCClassLoader cl; + private ClassLoader cl; private void processParams(ParamBucket params) throws NotFoundException { libraries = params.all("cp"); extlibs = params.all("ext"); - mcparams = params.allSafe("param", new ArrayList<String>()); + mcparams = params.allSafe("param", new ArrayList<String>() ); mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft"); appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet"); mods = params.allSafe("mod", new ArrayList<String>()); @@ -84,10 +84,7 @@ public class OneSixLauncher implements Launcher try { winSize = new Dimension(Integer.parseInt(dimStrings[0]), Integer.parseInt(dimStrings[1])); - } - catch (NumberFormatException ignored) - { - } + } catch (NumberFormatException ignored) {} } } @@ -120,7 +117,7 @@ public class OneSixLauncher implements Launcher } Utils.log(); - if (mods.size() > 0) + if(mods.size() > 0) { Utils.log("Mods:"); for (String s : mods) @@ -153,14 +150,10 @@ public class OneSixLauncher implements Launcher Utils.log("Params:"); Utils.log(" " + mcparams.toString()); Utils.log(); - if (maximize) - { + if(maximize) Utils.log("Window size: max (if available)"); - } else - { Utils.log("Window size: " + Integer.toString(winSize.width) + " x " + Integer.toString(winSize.height)); - } Utils.log(); } @@ -183,8 +176,7 @@ public class OneSixLauncher implements Launcher f.setAccessible(true); f.set(null, new File(cwd)); } - } - catch (Exception e) + } catch (Exception e) { System.err.println("Could not set base folder. Failed to find/access Minecraft main class:"); e.printStackTrace(System.err); @@ -201,11 +193,10 @@ public class OneSixLauncher implements Launcher try { Class<?> MCAppletClass = cl.loadClass(appletClass); - Applet mcappl = (Applet)MCAppletClass.newInstance(); + Applet mcappl = (Applet) MCAppletClass.newInstance(); LegacyFrame mcWindow = new LegacyFrame(windowTitle); mcWindow.start(mcappl, userName, sessionId, winSize, maximize); - } - catch (Exception e) + } catch (Exception e) { Utils.log("Applet wrapper failed:", "Error"); e.printStackTrace(System.err); @@ -213,9 +204,8 @@ public class OneSixLauncher implements Launcher Utils.log("Falling back to compatibility mode."); try { - mc.getMethod("main", String[].class).invoke(null, (Object)mcArgs); - } - catch (Exception e1) + 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); @@ -247,8 +237,7 @@ public class OneSixLauncher implements Launcher try { mc = cl.loadClass(mainClass); - } - catch (ClassNotFoundException e) + } catch (ClassNotFoundException e) { System.err.println("Failed to find Minecraft main class:"); e.printStackTrace(System.err); @@ -260,22 +249,66 @@ public class OneSixLauncher implements Launcher try { meth = mc.getMethod("main", String[].class); - } - catch (NoSuchMethodException e) + } catch (NoSuchMethodException e) { System.err.println("Failed to acquire the main method:"); 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 { // static method doesn't have an instance - meth.invoke(null, (Object)paramsArray); - } - catch (Exception e) + meth.invoke(null, (Object) paramsArray); + } catch (Exception e) { System.err.println("Failed to start Minecraft:"); e.printStackTrace(System.err); @@ -284,29 +317,35 @@ public class OneSixLauncher implements Launcher return 0; } - @Override public int launch(ParamBucket params) + @Override + public int launch(ParamBucket params) { // get and process the launch script params try { processParams(params); - } - catch (NotFoundException e) + } catch (NotFoundException e) { System.err.println("Not enough arguments."); e.printStackTrace(System.err); return -1; } + // add libraries to classpath + if(!Utils.addToClassPath(libraries)) + { + System.err.println("Halting launch due to previous errors."); + return -1; + } + // print the pretty things printStats(); // extract native libs (depending on platform here... java!) Utils.log("Preparing native libraries..."); String property = System.getProperty("os.arch"); - boolean is_64 = - property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64"); - for (String extlib : extlibs) + boolean is_64 = property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64"); + for(String extlib: extlibs) { try { @@ -314,8 +353,7 @@ public class OneSixLauncher implements Launcher File cleanlibf = new File(cleanlib); Utils.log("Extracting " + cleanlibf.getName()); Utils.unzipNatives(cleanlibf, new File(natives)); - } - catch (IOException e) + } catch (IOException e) { System.err.println("Failed to extract native library:"); e.printStackTrace(System.err); @@ -324,44 +362,36 @@ public class OneSixLauncher implements Launcher } Utils.log(); + // set the native libs path... the brute force way try { - cl = new MMCClassLoader(natives, libraries); - } - catch (Exception e) + System.setProperty("java.library.path", natives); + System.setProperty("org.lwjgl.librarypath", natives); + System.setProperty("net.java.games.input.librarypath", natives); + // by the power of reflection, initialize native libs again. DIRTY! + // this is SO BAD. imagine doing that to ld + Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); + fieldSysPath.setAccessible( true ); + fieldSysPath.set( null, null ); + } catch (Exception e) { - e.printStackTrace(); + System.err.println("Failed to set the native library path:"); + e.printStackTrace(System.err); + return -1; } - final int[] result = {-1}; + // grab the system classloader and ... + cl = ClassLoader.getSystemClassLoader(); - // fix log4j by sticking it in a thread with custom contextclassloader - Thread t = new Thread("main") - { - @Override public void run() - { - if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch")) - { - // legacy launch uses the applet wrapper - result[0] = legacyLaunch(); - } - else - { - // normal launch just calls main() - result[0] = launchWithMainClass(); - } - } - }; - t.setContextClassLoader(cl); - t.start(); - try + if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch") ) { - t.join(); + // legacy launch uses the applet wrapper + return legacyLaunch(); } - catch (InterruptedException e) + else { - e.printStackTrace(); + // normal launch just calls main() + return launchWithMainClass(); } - return result[0]; } } |