NOISSUE Cleanup onesix launcher
This commit is contained in:
parent
4f417d527e
commit
07bebddac9
35
depends/launcher/org/multimc/onesix/MMCClassLoader.java
Normal file
35
depends/launcher/org/multimc/onesix/MMCClassLoader.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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.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;
|
||||||
|
}
|
||||||
|
}
|
@ -18,8 +18,8 @@ package org.multimc.onesix;
|
|||||||
import org.multimc.*;
|
import org.multimc.*;
|
||||||
|
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
import java.io.File;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -47,7 +47,7 @@ public class OneSixLauncher implements Launcher
|
|||||||
private String cwd;
|
private String cwd;
|
||||||
|
|
||||||
// the much abused system classloader, for convenience (for further abuse)
|
// the much abused system classloader, for convenience (for further abuse)
|
||||||
private ClassLoader cl;
|
private MMCClassLoader cl;
|
||||||
|
|
||||||
private void processParams(ParamBucket params) throws NotFoundException
|
private void processParams(ParamBucket params) throws NotFoundException
|
||||||
{
|
{
|
||||||
@ -79,8 +79,12 @@ public class OneSixLauncher implements Launcher
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
winSize = new Dimension(Integer.parseInt(dimStrings[0]), Integer.parseInt(dimStrings[1]));
|
winSize = new Dimension(Integer.parseInt(dimStrings[0]),
|
||||||
} catch (NumberFormatException ignored) {}
|
Integer.parseInt(dimStrings[1]));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +133,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
if (maximize)
|
if (maximize)
|
||||||
Utils.log("Window size: max (if available)");
|
Utils.log("Window size: max (if available)");
|
||||||
else
|
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();
|
Utils.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,9 +157,11 @@ public class OneSixLauncher implements Launcher
|
|||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
f.set(null, new File(cwd));
|
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);
|
e.printStackTrace(System.err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -172,7 +179,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
Applet mcappl = (Applet)MCAppletClass.newInstance();
|
Applet mcappl = (Applet)MCAppletClass.newInstance();
|
||||||
LegacyFrame mcWindow = new LegacyFrame(windowTitle);
|
LegacyFrame mcWindow = new LegacyFrame(windowTitle);
|
||||||
mcWindow.start(mcappl, userName, sessionId, winSize, maximize);
|
mcWindow.start(mcappl, userName, sessionId, winSize, maximize);
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utils.log("Applet wrapper failed:", "Error");
|
Utils.log("Applet wrapper failed:", "Error");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
@ -181,7 +189,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
mc.getMethod("main", String[].class).invoke(null, (Object)mcArgs);
|
mc.getMethod("main", String[].class).invoke(null, (Object)mcArgs);
|
||||||
} catch (Exception e1)
|
}
|
||||||
|
catch (Exception e1)
|
||||||
{
|
{
|
||||||
Utils.log("Failed to invoke the Minecraft main class:", "Fatal");
|
Utils.log("Failed to invoke the Minecraft main class:", "Fatal");
|
||||||
e1.printStackTrace(System.err);
|
e1.printStackTrace(System.err);
|
||||||
@ -213,7 +222,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
mc = cl.loadClass(mainClass);
|
mc = cl.loadClass(mainClass);
|
||||||
} catch (ClassNotFoundException e)
|
}
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to find Minecraft main class:");
|
System.err.println("Failed to find Minecraft main class:");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
@ -225,7 +235,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
meth = mc.getMethod("main", String[].class);
|
meth = mc.getMethod("main", String[].class);
|
||||||
} catch (NoSuchMethodException e)
|
}
|
||||||
|
catch (NoSuchMethodException e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to acquire the main method:");
|
System.err.println("Failed to acquire the main method:");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
@ -284,7 +295,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
{
|
{
|
||||||
// static method doesn't have an instance
|
// static method doesn't have an instance
|
||||||
meth.invoke(null, (Object)paramsArray);
|
meth.invoke(null, (Object)paramsArray);
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to start Minecraft:");
|
System.err.println("Failed to start Minecraft:");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
@ -293,40 +305,32 @@ public class OneSixLauncher implements Launcher
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int launch(ParamBucket params)
|
||||||
public int launch(ParamBucket params)
|
|
||||||
{
|
{
|
||||||
// get and process the launch script params
|
// get and process the launch script params
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
processParams(params);
|
processParams(params);
|
||||||
} catch (NotFoundException e)
|
}
|
||||||
|
catch (NotFoundException e)
|
||||||
{
|
{
|
||||||
System.err.println("Not enough arguments.");
|
System.err.println("Not enough arguments.");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do some horrible black magic with the classpath
|
|
||||||
{
|
|
||||||
List<String> allJars = new ArrayList<String>();
|
List<String> allJars = new ArrayList<String>();
|
||||||
allJars.addAll(mods);
|
allJars.addAll(mods);
|
||||||
allJars.addAll(libraries);
|
allJars.addAll(libraries);
|
||||||
|
|
||||||
if(!Utils.addToClassPath(allJars))
|
|
||||||
{
|
|
||||||
System.err.println("Halting launch due to previous errors.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// print the pretty things
|
// print the pretty things
|
||||||
printStats();
|
printStats();
|
||||||
|
|
||||||
// extract native libs (depending on platform here... java!)
|
// extract native libs (depending on platform here... java!)
|
||||||
Utils.log("Preparing native libraries...");
|
Utils.log("Preparing native libraries...");
|
||||||
String property = System.getProperty("os.arch");
|
String property = System.getProperty("os.arch");
|
||||||
boolean is_64 = property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64");
|
boolean is_64 =
|
||||||
|
property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64");
|
||||||
for (String extlib : extlibs)
|
for (String extlib : extlibs)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -335,7 +339,8 @@ public class OneSixLauncher implements Launcher
|
|||||||
File cleanlibf = new File(cleanlib);
|
File cleanlibf = new File(cleanlib);
|
||||||
Utils.log("Extracting " + cleanlibf.getName());
|
Utils.log("Extracting " + cleanlibf.getName());
|
||||||
Utils.unzipNatives(cleanlibf, new File(natives));
|
Utils.unzipNatives(cleanlibf, new File(natives));
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
System.err.println("Failed to extract native library:");
|
System.err.println("Failed to extract native library:");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
@ -344,26 +349,15 @@ public class OneSixLauncher implements Launcher
|
|||||||
}
|
}
|
||||||
Utils.log();
|
Utils.log();
|
||||||
|
|
||||||
// set the native libs path... the brute force way
|
// grab the system classloader and ...
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.setProperty("java.library.path", natives);
|
cl = new MMCClassLoader(natives, allJars);
|
||||||
System.setProperty("org.lwjgl.librarypath", natives);
|
}
|
||||||
System.setProperty("net.java.games.input.librarypath", natives);
|
catch (Exception e)
|
||||||
// by the power of reflection, initialize native libs again. DIRTY!
|
{
|
||||||
// this is SO BAD. imagine doing that to ld
|
e.printStackTrace();
|
||||||
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
|
|
||||||
fieldSysPath.setAccessible( true );
|
|
||||||
fieldSysPath.set( null, null );
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
System.err.println("Failed to set the native library path:");
|
|
||||||
e.printStackTrace(System.err);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab the system classloader and ...
|
|
||||||
cl = ClassLoader.getSystemClassLoader();
|
|
||||||
|
|
||||||
if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch"))
|
if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch"))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user