summaryrefslogtreecommitdiffstats
path: root/libraries/launcher
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/launcher')
-rw-r--r--libraries/launcher/CMakeLists.txt18
-rw-r--r--libraries/launcher/net/minecraft/Launcher.java268
-rw-r--r--libraries/launcher/org/multimc/EntryPoint.java232
-rw-r--r--libraries/launcher/org/multimc/Launcher.java2
-rw-r--r--libraries/launcher/org/multimc/ParamBucket.java108
-rw-r--r--libraries/launcher/org/multimc/Utils.java150
-rw-r--r--libraries/launcher/org/multimc/onesix/OneSixLauncher.java408
7 files changed, 593 insertions, 593 deletions
diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt
index a4f52edb..a64c601d 100644
--- a/libraries/launcher/CMakeLists.txt
+++ b/libraries/launcher/CMakeLists.txt
@@ -7,15 +7,15 @@ set(CMAKE_JAVA_JAR_ENTRY_POINT org.multimc.EntryPoint)
set(CMAKE_JAVA_COMPILE_FLAGS -target 1.6 -source 1.6 -Xlint:deprecation -Xlint:unchecked)
set(SRC
- org/multimc/EntryPoint.java
- org/multimc/Launcher.java
- org/multimc/LegacyFrame.java
- org/multimc/NotFoundException.java
- org/multimc/ParamBucket.java
- org/multimc/ParseException.java
- org/multimc/Utils.java
- org/multimc/onesix/OneSixLauncher.java
- net/minecraft/Launcher.java
+ org/multimc/EntryPoint.java
+ org/multimc/Launcher.java
+ org/multimc/LegacyFrame.java
+ org/multimc/NotFoundException.java
+ org/multimc/ParamBucket.java
+ org/multimc/ParseException.java
+ org/multimc/Utils.java
+ org/multimc/onesix/OneSixLauncher.java
+ net/minecraft/Launcher.java
)
add_jar(NewLaunch ${SRC})
install_jar(NewLaunch "${JARS_DEST_DIR}")
diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java
index 0c991cf5..0a4bebcd 100644
--- a/libraries/launcher/net/minecraft/Launcher.java
+++ b/libraries/launcher/net/minecraft/Launcher.java
@@ -28,138 +28,138 @@ import java.net.MalformedURLException;
public class Launcher extends Applet implements AppletStub
{
- private Applet wrappedApplet;
- private URL documentBase;
- private boolean active = false;
- private final Map<String, String> params;
-
- public Launcher(Applet applet, URL documentBase)
- {
- params = new TreeMap<String, String>();
-
- this.setLayout(new BorderLayout());
- this.add(applet, "Center");
- this.wrappedApplet = applet;
- this.documentBase = documentBase;
- }
-
- public void setParameter(String name, String value)
- {
- params.put(name, value);
- }
-
- public void replace(Applet applet)
- {
- this.wrappedApplet = applet;
-
- applet.setStub(this);
- applet.setSize(getWidth(), getHeight());
-
- this.setLayout(new BorderLayout());
- this.add(applet, "Center");
-
- applet.init();
- active = true;
- applet.start();
- validate();
- }
-
- @Override
- public String getParameter(String name)
- {
- String param = params.get(name);
- if (param != null)
- return param;
- try
- {
- return super.getParameter(name);
- } catch (Exception ignore){}
- return null;
- }
-
- @Override
- public boolean isActive()
- {
- return active;
- }
-
- @Override
- public void appletResize(int width, int height)
- {
- wrappedApplet.resize(width, height);
- }
-
- @Override
- public void resize(int width, int height)
- {
- wrappedApplet.resize(width, height);
- }
-
- @Override
- public void resize(Dimension d)
- {
- wrappedApplet.resize(d);
- }
-
- @Override
- public void init()
- {
- if (wrappedApplet != null)
- {
- wrappedApplet.init();
- }
- }
-
- @Override
- public void start()
- {
- wrappedApplet.start();
- active = true;
- }
-
- @Override
- public void stop()
- {
- wrappedApplet.stop();
- active = false;
- }
-
- public void destroy()
- {
- wrappedApplet.destroy();
- }
-
- @Override
- public URL getCodeBase() {
- try {
- return new URL("http://www.minecraft.net/game/");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- @Override
- public URL getDocumentBase()
- {
- try {
- return new URL("http://www.minecraft.net/game/");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- @Override
- public void setVisible(boolean b)
- {
- super.setVisible(b);
- wrappedApplet.setVisible(b);
- }
- public void update(Graphics paramGraphics)
- {
- }
- public void paint(Graphics paramGraphics)
- {
- }
+ private Applet wrappedApplet;
+ private URL documentBase;
+ private boolean active = false;
+ private final Map<String, String> params;
+
+ public Launcher(Applet applet, URL documentBase)
+ {
+ params = new TreeMap<String, String>();
+
+ this.setLayout(new BorderLayout());
+ this.add(applet, "Center");
+ this.wrappedApplet = applet;
+ this.documentBase = documentBase;
+ }
+
+ public void setParameter(String name, String value)
+ {
+ params.put(name, value);
+ }
+
+ public void replace(Applet applet)
+ {
+ this.wrappedApplet = applet;
+
+ applet.setStub(this);
+ applet.setSize(getWidth(), getHeight());
+
+ this.setLayout(new BorderLayout());
+ this.add(applet, "Center");
+
+ applet.init();
+ active = true;
+ applet.start();
+ validate();
+ }
+
+ @Override
+ public String getParameter(String name)
+ {
+ String param = params.get(name);
+ if (param != null)
+ return param;
+ try
+ {
+ return super.getParameter(name);
+ } catch (Exception ignore){}
+ return null;
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return active;
+ }
+
+ @Override
+ public void appletResize(int width, int height)
+ {
+ wrappedApplet.resize(width, height);
+ }
+
+ @Override
+ public void resize(int width, int height)
+ {
+ wrappedApplet.resize(width, height);
+ }
+
+ @Override
+ public void resize(Dimension d)
+ {
+ wrappedApplet.resize(d);
+ }
+
+ @Override
+ public void init()
+ {
+ if (wrappedApplet != null)
+ {
+ wrappedApplet.init();
+ }
+ }
+
+ @Override
+ public void start()
+ {
+ wrappedApplet.start();
+ active = true;
+ }
+
+ @Override
+ public void stop()
+ {
+ wrappedApplet.stop();
+ active = false;
+ }
+
+ public void destroy()
+ {
+ wrappedApplet.destroy();
+ }
+
+ @Override
+ public URL getCodeBase() {
+ try {
+ return new URL("http://www.minecraft.net/game/");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public URL getDocumentBase()
+ {
+ try {
+ return new URL("http://www.minecraft.net/game/");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public void setVisible(boolean b)
+ {
+ super.setVisible(b);
+ wrappedApplet.setVisible(b);
+ }
+ public void update(Graphics paramGraphics)
+ {
+ }
+ public void paint(Graphics paramGraphics)
+ {
+ }
} \ No newline at end of file
diff --git a/libraries/launcher/org/multimc/EntryPoint.java b/libraries/launcher/org/multimc/EntryPoint.java
index 8c9b8074..c4ae2a86 100644
--- a/libraries/launcher/org/multimc/EntryPoint.java
+++ b/libraries/launcher/org/multimc/EntryPoint.java
@@ -21,131 +21,131 @@ import java.nio.charset.Charset;
public class EntryPoint
{
- private enum Action
- {
- Proceed,
- Launch,
- Abort
- }
+ private enum Action
+ {
+ Proceed,
+ Launch,
+ Abort
+ }
- public static void main(String[] args)
- {
- EntryPoint listener = new EntryPoint();
- int retCode = listener.listen();
- if (retCode != 0)
- {
- System.out.println("Exiting with " + retCode);
- System.exit(retCode);
- }
- }
+ public static void main(String[] args)
+ {
+ EntryPoint listener = new EntryPoint();
+ int retCode = listener.listen();
+ if (retCode != 0)
+ {
+ System.out.println("Exiting with " + retCode);
+ System.exit(retCode);
+ }
+ }
- private Action parseLine(String inData) throws ParseException
- {
- String[] pair = inData.split(" ", 2);
+ private Action parseLine(String inData) throws ParseException
+ {
+ String[] pair = inData.split(" ", 2);
- if(pair.length == 1)
- {
- String command = pair[0];
- if (pair[0].equals("launch"))
- return Action.Launch;
+ if(pair.length == 1)
+ {
+ String command = pair[0];
+ if (pair[0].equals("launch"))
+ return Action.Launch;
- else if (pair[0].equals("abort"))
- return Action.Abort;
+ else if (pair[0].equals("abort"))
+ return Action.Abort;
- else throw new ParseException();
- }
+ else throw new ParseException();
+ }
- if(pair.length != 2)
- throw new ParseException();
+ if(pair.length != 2)
+ throw new ParseException();
- String command = pair[0];
- String param = pair[1];
+ String command = pair[0];
+ String param = pair[1];
- if(command.equals("launcher"))
- {
- if(param.equals("onesix"))
- {
- m_launcher = new OneSixLauncher();
- Utils.log("Using onesix launcher.");
- Utils.log();
- return Action.Proceed;
- }
- else
- throw new ParseException();
- }
+ if(command.equals("launcher"))
+ {
+ if(param.equals("onesix"))
+ {
+ m_launcher = new OneSixLauncher();
+ Utils.log("Using onesix launcher.");
+ Utils.log();
+ return Action.Proceed;
+ }
+ else
+ throw new ParseException();
+ }
- m_params.add(command, param);
- //System.out.println(command + " : " + param);
- return Action.Proceed;
- }
+ m_params.add(command, param);
+ //System.out.println(command + " : " + param);
+ return Action.Proceed;
+ }
- public int listen()
- {
- BufferedReader buffer;
- try
- {
- buffer = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
- } catch (UnsupportedEncodingException e)
- {
- System.err.println("For some reason, your java does not support UTF-8. Consider living in the current century.");
- e.printStackTrace();
- return 1;
- }
- boolean isListening = true;
- boolean isAborted = false;
- // Main loop
- while (isListening)
- {
- String inData;
- try
- {
- // Read from the pipe one line at a time
- inData = buffer.readLine();
- if (inData != null)
- {
- Action a = parseLine(inData);
- if(a == Action.Abort)
- {
- isListening = false;
- isAborted = true;
- }
- if(a == Action.Launch)
- {
- isListening = false;
- }
- }
- else
- {
- isListening = false;
- isAborted = true;
- }
- }
- catch (IOException e)
- {
- System.err.println("Launcher ABORT due to IO exception:");
- e.printStackTrace();
- return 1;
- }
- catch (ParseException e)
- {
- System.err.println("Launcher ABORT due to PARSE exception:");
- e.printStackTrace();
- return 1;
- }
- }
- if(isAborted)
- {
- System.err.println("Launch aborted by MultiMC.");
- return 1;
- }
- if(m_launcher != null)
- {
- return m_launcher.launch(m_params);
- }
- System.err.println("No valid launcher implementation specified.");
- return 1;
- }
+ public int listen()
+ {
+ BufferedReader buffer;
+ try
+ {
+ buffer = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
+ } catch (UnsupportedEncodingException e)
+ {
+ System.err.println("For some reason, your java does not support UTF-8. Consider living in the current century.");
+ e.printStackTrace();
+ return 1;
+ }
+ boolean isListening = true;
+ boolean isAborted = false;
+ // Main loop
+ while (isListening)
+ {
+ String inData;
+ try
+ {
+ // Read from the pipe one line at a time
+ inData = buffer.readLine();
+ if (inData != null)
+ {
+ Action a = parseLine(inData);
+ if(a == Action.Abort)
+ {
+ isListening = false;
+ isAborted = true;
+ }
+ if(a == Action.Launch)
+ {
+ isListening = false;
+ }
+ }
+ else
+ {
+ isListening = false;
+ isAborted = true;
+ }
+ }
+ catch (IOException e)
+ {
+ System.err.println("Launcher ABORT due to IO exception:");
+ e.printStackTrace();
+ return 1;
+ }
+ catch (ParseException e)
+ {
+ System.err.println("Launcher ABORT due to PARSE exception:");
+ e.printStackTrace();
+ return 1;
+ }
+ }
+ if(isAborted)
+ {
+ System.err.println("Launch aborted by MultiMC.");
+ return 1;
+ }
+ if(m_launcher != null)
+ {
+ return m_launcher.launch(m_params);
+ }
+ System.err.println("No valid launcher implementation specified.");
+ return 1;
+ }
- private ParamBucket m_params = new ParamBucket();
- private org.multimc.Launcher m_launcher;
+ private ParamBucket m_params = new ParamBucket();
+ private org.multimc.Launcher m_launcher;
}
diff --git a/libraries/launcher/org/multimc/Launcher.java b/libraries/launcher/org/multimc/Launcher.java
index 2e851d18..d19ef7b2 100644
--- a/libraries/launcher/org/multimc/Launcher.java
+++ b/libraries/launcher/org/multimc/Launcher.java
@@ -18,5 +18,5 @@ package org.multimc;
public interface Launcher
{
- abstract int launch(ParamBucket params);
+ abstract int launch(ParamBucket params);
}
diff --git a/libraries/launcher/org/multimc/ParamBucket.java b/libraries/launcher/org/multimc/ParamBucket.java
index 5e9c3ff6..e198706b 100644
--- a/libraries/launcher/org/multimc/ParamBucket.java
+++ b/libraries/launcher/org/multimc/ParamBucket.java
@@ -22,65 +22,65 @@ import java.util.List;
public class ParamBucket
{
- public void add(String key, String value)
- {
- List<String> coll = null;
- if(!m_params.containsKey(key))
- {
- coll = new ArrayList<String>();
- m_params.put(key, coll);
- }
- else
- {
- coll = m_params.get(key);
- }
- coll.add(value);
- }
+ public void add(String key, String value)
+ {
+ List<String> coll = null;
+ if(!m_params.containsKey(key))
+ {
+ coll = new ArrayList<String>();
+ m_params.put(key, coll);
+ }
+ else
+ {
+ coll = m_params.get(key);
+ }
+ coll.add(value);
+ }
- public List<String> all(String key) throws NotFoundException
- {
- if(!m_params.containsKey(key))
- throw new NotFoundException();
- return m_params.get(key);
- }
+ public List<String> all(String key) throws NotFoundException
+ {
+ if(!m_params.containsKey(key))
+ throw new NotFoundException();
+ return m_params.get(key);
+ }
- public List<String> allSafe(String key, List<String> def)
- {
- if(!m_params.containsKey(key) || m_params.get(key).size() < 1)
- {
- return def;
- }
- return m_params.get(key);
- }
+ public List<String> allSafe(String key, List<String> def)
+ {
+ if(!m_params.containsKey(key) || m_params.get(key).size() < 1)
+ {
+ return def;
+ }
+ return m_params.get(key);
+ }
- public List<String> allSafe(String key)
- {
- return allSafe(key, new ArrayList<String>());
- }
+ public List<String> allSafe(String key)
+ {
+ return allSafe(key, new ArrayList<String>());
+ }
- public String first(String key) throws NotFoundException
- {
- List<String> list = all(key);
- if(list.size() < 1)
- {
- throw new NotFoundException();
- }
- return list.get(0);
- }
+ public String first(String key) throws NotFoundException
+ {
+ List<String> list = all(key);
+ if(list.size() < 1)
+ {
+ throw new NotFoundException();
+ }
+ return list.get(0);
+ }
- public String firstSafe(String key, String def)
- {
- if(!m_params.containsKey(key) || m_params.get(key).size() < 1)
- {
- return def;
- }
- return m_params.get(key).get(0);
- }
+ public String firstSafe(String key, String def)
+ {
+ if(!m_params.containsKey(key) || m_params.get(key).size() < 1)
+ {
+ return def;
+ }
+ return m_params.get(key).get(0);
+ }
- public String firstSafe(String key)
- {
- return firstSafe(key, "");
- }
+ public String firstSafe(String key)
+ {
+ return firstSafe(key, "");
+ }
- private HashMap<String, List<String>> m_params = new HashMap<String, List<String>>();
+ private HashMap<String, List<String>> m_params = new HashMap<String, List<String>>();
}
diff --git a/libraries/launcher/org/multimc/Utils.java b/libraries/launcher/org/multimc/Utils.java
index c5292eaf..d6f254a1 100644
--- a/libraries/launcher/org/multimc/Utils.java
+++ b/libraries/launcher/org/multimc/Utils.java
@@ -34,86 +34,86 @@ import java.util.zip.ZipFile;
public class Utils
{
- /**
- * Combine two parts of a path.
- *
- * @param path1
- * @param path2
- * @return the paths, combined
- */
- public static String combine(String path1, String path2)
- {
- File file1 = new File(path1);
- File file2 = new File(file1, path2);
- return file2.getPath();
- }
+ /**
+ * Combine two parts of a path.
+ *
+ * @param path1
+ * @param path2
+ * @return the paths, combined
+ */
+ public static String combine(String path1, String path2)
+ {
+ File file1 = new File(path1);
+ File file2 = new File(file1, path2);
+ return file2.getPath();
+ }
- /**
- * Join a list of strings into a string using a separator!
- *
- * @param strings the string list to join
- * @param separator the glue
- * @return the result.
- */
- public static String join(List<String> strings, String separator)
- {
- StringBuilder sb = new StringBuilder();
- String sep = "";
- for (String s : strings)
- {
- sb.append(sep).append(s);
- sep = separator;
- }
- return sb.toString();
- }
+ /**
+ * Join a list of strings into a string using a separator!
+ *
+ * @param strings the string list to join
+ * @param separator the glue
+ * @return the result.
+ */
+ public static String join(List<String> strings, String separator)
+ {
+ StringBuilder sb = new StringBuilder();
+ String sep = "";
+ for (String s : strings)
+ {
+ sb.append(sep).append(s);
+ sep = separator;
+ }
+ return sb.toString();
+ }
- /**
- * Finds a field that looks like a Minecraft base folder in a supplied class
- *
- * @param mc the class to scan
- */
- public static Field getMCPathField(Class<?> mc)
- {
- Field[] fields = mc.getDeclaredFields();
+ /**
+ * Finds a field that looks like a Minecraft base folder in a supplied class
+ *
+ * @param mc the class to scan
+ */
+ public static Field getMCPathField(Class<?> mc)
+ {
+ Field[] fields = mc.getDeclaredFields();
- for (Field f : fields)
- {
- if (f.getType() != File.class)
- {
- // Has to be File
- continue;
- }
- if (f.getModifiers() != (Modifier.PRIVATE + Modifier.STATIC))
- {
- // And Private Static.
- continue;
- }
- return f;
- }
- return null;
- }
+ for (Field f : fields)
+ {
+ if (f.getType() != File.class)
+ {
+ // Has to be File
+ continue;
+ }
+ if (f.getModifiers() != (Modifier.PRIVATE + Modifier.STATIC))
+ {
+ // And Private Static.
+ continue;
+ }
+ return f;
+ }
+ return null;
+ }
- /**
- * Log to the MultiMC console
- *
- * @param message A String containing the message
- * @param level A String containing the level name. See MinecraftLauncher::getLevel()
- */
- public static void log(String message, String level)
- {
- // Kinda dirty
- String tag = "!![" + level + "]!";
- System.out.println(tag + message.replace("\n", "\n" + tag));
- }
+ /**
+ * Log to the MultiMC console
+ *
+ * @param message A String containing the message
+ * @param level A String containing the level name. See MinecraftLauncher::getLevel()
+ */
+ public static void log(String message, String level)
+ {
+ // Kinda dirty
+ String tag = "!![" + level + "]!";
+ System.out.println(tag + message.replace("\n", "\n" + tag));
+ }
- public static void log(String message)
- {
- log(message, "MultiMC");
- }
+ public static void log(String message)
+ {
+ log(message, "MultiMC");
+ }
- public static void log()
- {
- System.out.println();
- }
+ public static void log()
+ {
+ System.out.println();
+ }
}
diff --git a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java b/libraries/launcher/org/multimc/onesix/OneSixLauncher.java
index 9667297d..48baba2e 100644
--- a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java
+++ b/libraries/launcher/org/multimc/onesix/OneSixLauncher.java
@@ -27,208 +27,208 @@ import java.util.List;
public class OneSixLauncher implements Launcher
{
- // parameters, separated from ParamBucket
- private List<String> libraries;
- private List<String> mcparams;
- private List<String> mods;
- private List<String> jarmods;
- private List<String> coremods;
- private List<String> traits;
- private String appletClass;
- private String mainClass;
- private String nativePath;
- private String userName, sessionId;
- private String windowTitle;
- private String windowParams;
-
- // secondary parameters
- private int winSizeW;
- private int winSizeH;
- private boolean maximize;
- private String cwd;
-
- // the much abused system classloader, for convenience (for further abuse)
- private ClassLoader cl;
-
- private void processParams(ParamBucket params) throws NotFoundException
- {
- libraries = params.all("cp");
- mcparams = params.allSafe("param", new ArrayList<String>() );
- mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
- appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
- traits = params.allSafe("traits", new ArrayList<String>());
- nativePath = params.first("natives");
-
- userName = params.first("userName");
- sessionId = params.first("sessionId");
- windowTitle = params.firstSafe("windowTitle", "Minecraft");
- windowParams = params.firstSafe("windowParams", "854x480");
-
- cwd = System.getProperty("user.dir");
-
- winSizeW = 854;
- winSizeH = 480;
- maximize = false;
-
- String[] dimStrings = windowParams.split("x");
-
- if (windowParams.equalsIgnoreCase("max"))
- {
- maximize = true;
- }
- else if (dimStrings.length == 2)
- {
- try
- {
- winSizeW = Integer.parseInt(dimStrings[0]);
- winSizeH = Integer.parseInt(dimStrings[1]);
- } catch (NumberFormatException ignored) {}
- }
- }
-
- int legacyLaunch()
- {
- // Get the Minecraft Class and set the base folder
- Class<?> mc;
- try
- {
- mc = cl.loadClass(mainClass);
-
- Field f = Utils.getMCPathField(mc);
-
- if (f == null)
- {
- System.err.println("Could not find Minecraft path field.");
- }
- else
- {
- f.setAccessible(true);
- f.set(null, new File(cwd));
- }
- } catch (Exception e)
- {
- System.err.println("Could not set base folder. Failed to find/access Minecraft main class:");
- e.printStackTrace(System.err);
- return -1;
- }
-
- System.setProperty("minecraft.applet.TargetDirectory", cwd);
-
- 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, winSizeW, winSizeH, 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.");
- }
- }
-
- // init params for the main method to chomp on.
- String[] paramsArray = mcparams.toArray(new String[mcparams.size()]);
- try
- {
- mc.getMethod("main", String[].class).invoke(null, (Object) paramsArray);
- return 0;
- } catch (Exception e)
- {
- Utils.log("Failed to invoke the Minecraft main class:", "Fatal");
- e.printStackTrace(System.err);
- return -1;
- }
- }
-
- int launchWithMainClass()
- {
- // window size, title and state, onesix
- if (maximize)
- {
- // FIXME: there is no good way to maximize the minecraft window in onesix.
- // the following often breaks linux screen setups
- // mcparams.add("--fullscreen");
- }
- else
- {
- mcparams.add("--width");
- mcparams.add(Integer.toString(winSizeW));
- mcparams.add("--height");
- mcparams.add(Integer.toString(winSizeH));
- }
-
- // Get the Minecraft Class.
- Class<?> mc;
- try
- {
- mc = cl.loadClass(mainClass);
- } catch (ClassNotFoundException e)
- {
- System.err.println("Failed to find Minecraft main class:");
- e.printStackTrace(System.err);
- return -1;
- }
-
- // get the main method.
- Method meth;
- try
- {
- meth = mc.getMethod("main", String[].class);
- } catch (NoSuchMethodException e)
- {
- System.err.println("Failed to acquire the main method:");
- e.printStackTrace(System.err);
- return -1;
- }
-
- // 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)
- {
- System.err.println("Failed to start Minecraft:");
- e.printStackTrace(System.err);
- return -1;
- }
- return 0;
- }
-
- @Override
- public int launch(ParamBucket params)
- {
- // get and process the launch script params
- try
- {
- processParams(params);
- } catch (NotFoundException e)
- {
- System.err.println("Not enough arguments.");
- e.printStackTrace(System.err);
- return -1;
- }
-
- // grab the system classloader and ...
- cl = ClassLoader.getSystemClassLoader();
-
- if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch") )
- {
- // legacy launch uses the applet wrapper
- return legacyLaunch();
- }
- else
- {
- // normal launch just calls main()
- return launchWithMainClass();
- }
- }
+ // parameters, separated from ParamBucket
+ private List<String> libraries;
+ private List<String> mcparams;
+ private List<String> mods;
+ private List<String> jarmods;
+ private List<String> coremods;
+ private List<String> traits;
+ private String appletClass;
+ private String mainClass;
+ private String nativePath;
+ private String userName, sessionId;
+ private String windowTitle;
+ private String windowParams;
+
+ // secondary parameters
+ private int winSizeW;
+ private int winSizeH;
+ private boolean maximize;
+ private String cwd;
+
+ // the much abused system classloader, for convenience (for further abuse)
+ private ClassLoader cl;
+
+ private void processParams(ParamBucket params) throws NotFoundException
+ {
+ libraries = params.all("cp");
+ mcparams = params.allSafe("param", new ArrayList<String>() );
+ mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
+ appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
+ traits = params.allSafe("traits", new ArrayList<String>());
+ nativePath = params.first("natives");
+
+ userName = params.first("userName");
+ sessionId = params.first("sessionId");
+ windowTitle = params.firstSafe("windowTitle", "Minecraft");
+ windowParams = params.firstSafe("windowParams", "854x480");
+
+ cwd = System.getProperty("user.dir");
+
+ winSizeW = 854;
+ winSizeH = 480;
+ maximize = false;
+
+ String[] dimStrings = windowParams.split("x");
+
+ if (windowParams.equalsIgnoreCase("max"))
+ {
+ maximize = true;
+ }
+ else if (dimStrings.length == 2)
+ {
+ try
+ {
+ winSizeW = Integer.parseInt(dimStrings[0]);
+ winSizeH = Integer.parseInt(dimStrings[1]);
+ } catch (NumberFormatException ignored) {}
+ }
+ }
+
+ int legacyLaunch()
+ {
+ // Get the Minecraft Class and set the base folder
+ Class<?> mc;
+ try
+ {
+ mc = cl.loadClass(mainClass);
+
+ Field f = Utils.getMCPathField(mc);
+
+ if (f == null)
+ {
+ System.err.println("Could not find Minecraft path field.");
+ }
+ else
+ {
+ f.setAccessible(true);
+ f.set(null, new File(cwd));
+ }
+ } catch (Exception e)
+ {
+ System.err.println("Could not set base folder. Failed to find/access Minecraft main class:");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+
+ System.setProperty("minecraft.applet.TargetDirectory", cwd);
+
+ 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, winSizeW, winSizeH, 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.");
+ }
+ }
+
+ // init params for the main method to chomp on.
+ String[] paramsArray = mcparams.toArray(new String[mcparams.size()]);
+ try
+ {
+ mc.getMethod("main", String[].class).invoke(null, (Object) paramsArray);
+ return 0;
+ } catch (Exception e)
+ {
+ Utils.log("Failed to invoke the Minecraft main class:", "Fatal");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+ }
+
+ int launchWithMainClass()
+ {
+ // window size, title and state, onesix
+ if (maximize)
+ {
+ // FIXME: there is no good way to maximize the minecraft window in onesix.
+ // the following often breaks linux screen setups
+ // mcparams.add("--fullscreen");
+ }
+ else
+ {
+ mcparams.add("--width");
+ mcparams.add(Integer.toString(winSizeW));
+ mcparams.add("--height");
+ mcparams.add(Integer.toString(winSizeH));
+ }
+
+ // Get the Minecraft Class.
+ Class<?> mc;
+ try
+ {
+ mc = cl.loadClass(mainClass);
+ } catch (ClassNotFoundException e)
+ {
+ System.err.println("Failed to find Minecraft main class:");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+
+ // get the main method.
+ Method meth;
+ try
+ {
+ meth = mc.getMethod("main", String[].class);
+ } catch (NoSuchMethodException e)
+ {
+ System.err.println("Failed to acquire the main method:");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+
+ // 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)
+ {
+ System.err.println("Failed to start Minecraft:");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+ return 0;
+ }
+
+ @Override
+ public int launch(ParamBucket params)
+ {
+ // get and process the launch script params
+ try
+ {
+ processParams(params);
+ } catch (NotFoundException e)
+ {
+ System.err.println("Not enough arguments.");
+ e.printStackTrace(System.err);
+ return -1;
+ }
+
+ // grab the system classloader and ...
+ cl = ClassLoader.getSystemClassLoader();
+
+ if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch") )
+ {
+ // legacy launch uses the applet wrapper
+ return legacyLaunch();
+ }
+ else
+ {
+ // normal launch just calls main()
+ return launchWithMainClass();
+ }
+ }
}