summaryrefslogtreecommitdiffstats
path: root/depends/launcher/org/multimc/onesix/OneSixLauncher.java
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-04-25 15:32:38 +0200
committerPetr Mrázek <peterix@gmail.com>2015-04-25 15:32:38 +0200
commitdc279fbfdc01c7653ae3e70a870c4a0c0f08c263 (patch)
tree186a00d96676169b6ef800784888c183ff9dff82 /depends/launcher/org/multimc/onesix/OneSixLauncher.java
parent8fa58dc24401206c9bf1726bb171d7ee928b1363 (diff)
downloadMultiMC-dc279fbfdc01c7653ae3e70a870c4a0c0f08c263.tar
MultiMC-dc279fbfdc01c7653ae3e70a870c4a0c0f08c263.tar.gz
MultiMC-dc279fbfdc01c7653ae3e70a870c4a0c0f08c263.tar.lz
MultiMC-dc279fbfdc01c7653ae3e70a870c4a0c0f08c263.tar.xz
MultiMC-dc279fbfdc01c7653ae3e70a870c4a0c0f08c263.zip
Revert "NOISSUE Cleanup onesix launcher"
This reverts commit 07bebddac960bdee82c0a48a6925a49555f661ac.
Diffstat (limited to 'depends/launcher/org/multimc/onesix/OneSixLauncher.java')
-rw-r--r--depends/launcher/org/multimc/onesix/OneSixLauncher.java116
1 files changed, 61 insertions, 55 deletions
diff --git a/depends/launcher/org/multimc/onesix/OneSixLauncher.java b/depends/launcher/org/multimc/onesix/OneSixLauncher.java
index eaefbb89..6314ef0e 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;
@@ -40,20 +40,20 @@ public class OneSixLauncher implements Launcher
private String userName, sessionId;
private String windowTitle;
private String windowParams;
-
+
// secondary parameters
private Dimension winSize;
private boolean maximize;
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("mods", new ArrayList<String>());
@@ -64,7 +64,7 @@ public class OneSixLauncher implements Launcher
sessionId = params.first("sessionId");
windowTitle = params.firstSafe("windowTitle", "Minecraft");
windowParams = params.firstSafe("windowParams", "854x480");
-
+
cwd = System.getProperty("user.dir");
winSize = new Dimension(854, 480);
maximize = false;
@@ -79,12 +79,8 @@ public class OneSixLauncher implements Launcher
{
try
{
- winSize = new Dimension(Integer.parseInt(dimStrings[0]),
- Integer.parseInt(dimStrings[1]));
- }
- catch (NumberFormatException ignored)
- {
- }
+ winSize = new Dimension(Integer.parseInt(dimStrings[0]), Integer.parseInt(dimStrings[1]));
+ } catch (NumberFormatException ignored) {}
}
}
@@ -117,7 +113,7 @@ public class OneSixLauncher implements Launcher
}
Utils.log();
- if (mods.size() > 0)
+ if(mods.size() > 0)
{
Utils.log("Class Path Mods:");
for (String s : mods)
@@ -130,11 +126,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("Window size: " + Integer.toString(winSize.width) + " x " + Integer.toString(winSize.height));
Utils.log();
}
@@ -157,11 +152,9 @@ 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:");
+ System.err.println("Could not set base folder. Failed to find/access Minecraft main class:");
e.printStackTrace(System.err);
return -1;
}
@@ -176,11 +169,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);
@@ -188,9 +180,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);
@@ -199,7 +190,7 @@ public class OneSixLauncher implements Launcher
}
return 0;
}
-
+
int launchWithMainClass()
{
// window size, title and state, onesix
@@ -216,14 +207,13 @@ public class OneSixLauncher implements Launcher
mcparams.add("--height");
mcparams.add(Integer.toString(winSize.height));
}
-
+
// Get the Minecraft Class.
Class<?> mc;
try
{
mc = cl.loadClass(mainClass);
- }
- catch (ClassNotFoundException e)
+ } catch (ClassNotFoundException e)
{
System.err.println("Failed to find Minecraft main class:");
e.printStackTrace(System.err);
@@ -235,8 +225,7 @@ 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);
@@ -294,9 +283,8 @@ public class OneSixLauncher implements Launcher
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);
@@ -304,24 +292,33 @@ 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;
}
- List<String> allJars = new ArrayList<String>();
- allJars.addAll(mods);
- allJars.addAll(libraries);
+ // do some horrible black magic with the classpath
+ {
+ List<String> allJars = new ArrayList<String>();
+ allJars.addAll(mods);
+ allJars.addAll(libraries);
+
+ if(!Utils.addToClassPath(allJars))
+ {
+ System.err.println("Halting launch due to previous errors.");
+ return -1;
+ }
+ }
// print the pretty things
printStats();
@@ -329,9 +326,8 @@ public class OneSixLauncher implements Launcher
// 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
{
@@ -339,8 +335,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);
@@ -348,18 +343,29 @@ public class OneSixLauncher implements Launcher
}
}
Utils.log();
-
- // grab the system classloader and ...
+
+ // set the native libs path... the brute force way
try
{
- cl = new MMCClassLoader(natives, allJars);
- }
- 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;
}
-
- if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch"))
+
+ // grab the system classloader and ...
+ cl = ClassLoader.getSystemClassLoader();
+
+ if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch") )
{
// legacy launch uses the applet wrapper
return legacyLaunch();