aboutsummaryrefslogtreecommitdiff
path: root/libraries/launcher/org/multimc
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/launcher/org/multimc')
-rw-r--r--libraries/launcher/org/multimc/EntryPoint.java138
-rw-r--r--libraries/launcher/org/multimc/Launcher.java22
-rw-r--r--libraries/launcher/org/multimc/LegacyFrame.java176
-rw-r--r--libraries/launcher/org/multimc/NotFoundException.java21
-rw-r--r--libraries/launcher/org/multimc/ParamBucket.java85
-rw-r--r--libraries/launcher/org/multimc/ParseException.java25
-rw-r--r--libraries/launcher/org/multimc/Utils.java86
-rw-r--r--libraries/launcher/org/multimc/onesix/OneSixLauncher.java256
8 files changed, 0 insertions, 809 deletions
diff --git a/libraries/launcher/org/multimc/EntryPoint.java b/libraries/launcher/org/multimc/EntryPoint.java
deleted file mode 100644
index b626d095..00000000
--- a/libraries/launcher/org/multimc/EntryPoint.java
+++ /dev/null
@@ -1,138 +0,0 @@
-package org.multimc;/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.multimc.onesix.OneSixLauncher;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class EntryPoint
-{
-
- private static final Logger LOGGER = Logger.getLogger("EntryPoint");
-
- private final ParamBucket params = new ParamBucket();
-
- private org.multimc.Launcher launcher;
-
- public static void main(String[] args)
- {
- EntryPoint listener = new EntryPoint();
-
- int retCode = listener.listen();
-
- if (retCode != 0)
- {
- LOGGER.info("Exiting with " + retCode);
-
- System.exit(retCode);
- }
- }
-
- private Action parseLine(String inData) throws ParseException
- {
- String[] tokens = inData.split("\\s+", 2);
-
- if (tokens.length == 0)
- throw new ParseException("Unexpected empty string!");
-
- switch (tokens[0]) {
- case "launch": {
- return Action.Launch;
- }
-
- case "abort": {
- return Action.Abort;
- }
-
- case "launcher": {
- if (tokens.length != 2)
- throw new ParseException("Expected 2 tokens, got " + tokens.length);
-
- if (tokens[1].equals("onesix")) {
- launcher = new OneSixLauncher();
-
- LOGGER.info("Using onesix launcher.");
-
- return Action.Proceed;
- } else {
- throw new ParseException("Invalid launcher type: " + tokens[1]);
- }
- }
-
- default: {
- if (tokens.length != 2)
- throw new ParseException("Error while parsing:" + inData);
-
- params.add(tokens[0], tokens[1]);
-
- return Action.Proceed;
- }
- }
- }
-
- public int listen()
- {
- Action action = Action.Proceed;
-
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(
- System.in,
- StandardCharsets.UTF_8
- ))) {
- String line;
-
- while (action == Action.Proceed) {
- if ((line = reader.readLine()) != null) {
- action = parseLine(line);
- } else {
- action = Action.Abort;
- }
- }
- } catch (IOException | ParseException e) {
- LOGGER.log(Level.SEVERE, "Launcher ABORT due to exception:", e);
-
- return 1;
- }
-
- // Main loop
- if (action == Action.Abort)
- {
- LOGGER.info("Launch aborted by the launcher.");
-
- return 1;
- }
-
- if (launcher != null)
- {
- return launcher.launch(params);
- }
-
- LOGGER.log(Level.SEVERE, "No valid launcher implementation specified.");
-
- return 1;
- }
-
- private enum Action {
- Proceed,
- Launch,
- Abort
- }
-
-}
diff --git a/libraries/launcher/org/multimc/Launcher.java b/libraries/launcher/org/multimc/Launcher.java
deleted file mode 100644
index c5e8fbc1..00000000
--- a/libraries/launcher/org/multimc/Launcher.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc;
-
-public interface Launcher
-{
- int launch(ParamBucket params);
-}
diff --git a/libraries/launcher/org/multimc/LegacyFrame.java b/libraries/launcher/org/multimc/LegacyFrame.java
deleted file mode 100644
index 985a10e6..00000000
--- a/libraries/launcher/org/multimc/LegacyFrame.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package org.multimc;/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import net.minecraft.Launcher;
-
-import javax.imageio.ImageIO;
-import java.applet.Applet;
-import java.awt.*;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Scanner;
-
-public class LegacyFrame extends Frame implements WindowListener
-{
- private Launcher appletWrap = null;
- public LegacyFrame(String title)
- {
- super ( title );
- BufferedImage image;
- try {
- image = ImageIO.read ( new File ( "icon.png" ) );
- setIconImage ( image );
- } catch ( IOException e ) {
- e.printStackTrace();
- }
- this.addWindowListener ( this );
- }
-
- public void start (
- Applet mcApplet,
- String user,
- String session,
- int winSizeW,
- int winSizeH,
- boolean maximize,
- String serverAddress,
- String serverPort
- )
- {
- try {
- appletWrap = new Launcher( mcApplet, new URL ( "http://www.minecraft.net/game" ) );
- } catch ( MalformedURLException ignored ) {}
-
- // Implements support for launching in to multiplayer on classic servers using a mpticket
- // file generated by an external program and stored in the instance's root folder.
- File mpticketFile = null;
- Scanner fileReader = null;
- try {
- mpticketFile = new File(System.getProperty("user.dir") + "/../mpticket").getCanonicalFile();
- fileReader = new Scanner(new FileInputStream(mpticketFile), "ascii");
- String[] mpticketParams = new String[3];
-
- for(int i=0;i<3;i++) {
- if(fileReader.hasNextLine()) {
- mpticketParams[i] = fileReader.nextLine();
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- // Assumes parameters are valid and in the correct order
- appletWrap.setParameter("server", mpticketParams[0]);
- appletWrap.setParameter("port", mpticketParams[1]);
- appletWrap.setParameter("mppass", mpticketParams[2]);
-
- fileReader.close();
- mpticketFile.delete();
- }
- catch (FileNotFoundException e) {}
- catch (IllegalArgumentException e) {
-
- fileReader.close();
- File mpticketFileCorrupt = new File(System.getProperty("user.dir") + "/../mpticket.corrupt");
- if(mpticketFileCorrupt.exists()) {
- mpticketFileCorrupt.delete();
- }
- mpticketFile.renameTo(mpticketFileCorrupt);
-
- System.err.println("Malformed mpticket file, missing argument.");
- e.printStackTrace(System.err);
- System.exit(-1);
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- System.exit(-1);
- }
-
- if (serverAddress != null)
- {
- appletWrap.setParameter("server", serverAddress);
- appletWrap.setParameter("port", serverPort);
- }
-
- appletWrap.setParameter ( "username", user );
- appletWrap.setParameter ( "sessionid", session );
- appletWrap.setParameter ( "stand-alone", "true" ); // Show the quit button.
- appletWrap.setParameter ( "haspaid", "true" ); // Some old versions need this for world saves to work.
- appletWrap.setParameter ( "demo", "false" );
- appletWrap.setParameter ( "fullscreen", "false" );
- mcApplet.setStub(appletWrap);
- this.add ( appletWrap );
- appletWrap.setPreferredSize ( new Dimension (winSizeW, winSizeH) );
- this.pack();
- this.setLocationRelativeTo ( null );
- this.setResizable ( true );
- if ( maximize ) {
- this.setExtendedState ( MAXIMIZED_BOTH );
- }
- validate();
- appletWrap.init();
- appletWrap.start();
- setVisible ( true );
- }
-
- @Override
- public void windowActivated ( WindowEvent e ) {}
-
- @Override
- public void windowClosed ( WindowEvent e ) {}
-
- @Override
- public void windowClosing ( WindowEvent e )
- {
- new Thread() {
- public void run() {
- try {
- Thread.sleep ( 30000L );
- } catch ( InterruptedException localInterruptedException ) {
- localInterruptedException.printStackTrace();
- }
- System.out.println ( "FORCING EXIT!" );
- System.exit ( 0 );
- }
- }
- .start();
-
- if ( appletWrap != null ) {
- appletWrap.stop();
- appletWrap.destroy();
- }
- // old minecraft versions can hang without this >_<
- System.exit ( 0 );
- }
-
- @Override
- public void windowDeactivated ( WindowEvent e ) {}
-
- @Override
- public void windowDeiconified ( WindowEvent e ) {}
-
- @Override
- public void windowIconified ( WindowEvent e ) {}
-
- @Override
- public void windowOpened ( WindowEvent e ) {}
-}
diff --git a/libraries/launcher/org/multimc/NotFoundException.java b/libraries/launcher/org/multimc/NotFoundException.java
deleted file mode 100644
index ba12951d..00000000
--- a/libraries/launcher/org/multimc/NotFoundException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc;
-
-public class NotFoundException extends Exception
-{
-}
diff --git a/libraries/launcher/org/multimc/ParamBucket.java b/libraries/launcher/org/multimc/ParamBucket.java
deleted file mode 100644
index 8ff03ddc..00000000
--- a/libraries/launcher/org/multimc/ParamBucket.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ParamBucket
-{
-
- private final Map<String, List<String>> paramsMap = new HashMap<>();
-
- public void add(String key, String value)
- {
- paramsMap.computeIfAbsent(key, k -> new ArrayList<>())
- .add(value);
- }
-
- public List<String> all(String key) throws NotFoundException
- {
- List<String> params = paramsMap.get(key);
-
- if (params == null)
- throw new NotFoundException();
-
- return params;
- }
-
- public List<String> allSafe(String key, List<String> def)
- {
- List<String> params = paramsMap.get(key);
-
- if (params == null || params.isEmpty())
- return def;
-
- return params;
- }
-
- public List<String> allSafe(String key)
- {
- return allSafe(key, new ArrayList<>());
- }
-
- public String first(String key) throws NotFoundException
- {
- List<String> list = all(key);
-
- if (list.isEmpty())
- throw new NotFoundException();
-
- return list.get(0);
- }
-
- public String firstSafe(String key, String def)
- {
- List<String> params = paramsMap.get(key);
-
- if (params == null || params.isEmpty())
- return def;
-
- return params.get(0);
- }
-
- public String firstSafe(String key)
- {
- return firstSafe(key, "");
- }
-
-}
diff --git a/libraries/launcher/org/multimc/ParseException.java b/libraries/launcher/org/multimc/ParseException.java
deleted file mode 100644
index 7ea44c1f..00000000
--- a/libraries/launcher/org/multimc/ParseException.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc;
-
-public class ParseException extends java.lang.Exception
-{
- public ParseException() { super(); }
- public ParseException(String message) {
- super(message);
- }
-}
diff --git a/libraries/launcher/org/multimc/Utils.java b/libraries/launcher/org/multimc/Utils.java
deleted file mode 100644
index e48029c2..00000000
--- a/libraries/launcher/org/multimc/Utils.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.List;
-
-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();
- }
-
- /**
- * 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();
-
- 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;
- }
-
-}
-
diff --git a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java b/libraries/launcher/org/multimc/onesix/OneSixLauncher.java
deleted file mode 100644
index 0058bd43..00000000
--- a/libraries/launcher/org/multimc/onesix/OneSixLauncher.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/* Copyright 2012-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.multimc.onesix;
-
-import org.multimc.*;
-
-import java.applet.Applet;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class OneSixLauncher implements Launcher
-{
-
- private static final Logger LOGGER = Logger.getLogger("OneSixLauncher");
-
- // 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;
-
- private String serverAddress;
- private String serverPort;
-
- // 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");
-
- serverAddress = params.firstSafe("serverAddress", null);
- serverPort = params.firstSafe("serverPort", null);
-
- 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)
- {
- LOGGER.warning("Could not find Minecraft path field.");
- }
- else
- {
- f.setAccessible(true);
- f.set(null, new File(cwd));
- }
- } catch (Exception e)
- {
- LOGGER.log(
- Level.SEVERE,
- "Could not set base folder. Failed to find/access Minecraft main class:",
- e
- );
-
- return -1;
- }
-
- System.setProperty("minecraft.applet.TargetDirectory", cwd);
-
- if(!traits.contains("noapplet"))
- {
- LOGGER.info("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, serverAddress, serverPort);
- return 0;
- } catch (Exception e)
- {
- LOGGER.log(Level.SEVERE, "Applet wrapper failed:", e);
-
- LOGGER.warning("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)
- {
- LOGGER.log(Level.SEVERE, "Failed to invoke the Minecraft main class:", e);
-
- 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));
- }
-
- if (serverAddress != null)
- {
- mcparams.add("--server");
- mcparams.add(serverAddress);
- mcparams.add("--port");
- mcparams.add(serverPort);
- }
-
- // Get the Minecraft Class.
- Class<?> mc;
- try
- {
- mc = cl.loadClass(mainClass);
- } catch (ClassNotFoundException e)
- {
- LOGGER.log(Level.SEVERE, "Failed to find Minecraft main class:", e);
-
- return -1;
- }
-
- // get the main method.
- Method meth;
- try
- {
- meth = mc.getMethod("main", String[].class);
- } catch (NoSuchMethodException e)
- {
- LOGGER.log(Level.SEVERE, "Failed to acquire the main method:", e);
-
- 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)
- {
- LOGGER.log(Level.SEVERE, "Failed to start Minecraft:", e);
-
- return -1;
- }
- return 0;
- }
-
- @Override
- public int launch(ParamBucket params)
- {
- // get and process the launch script params
- try
- {
- processParams(params);
- } catch (NotFoundException e)
- {
- LOGGER.log(Level.SEVERE, "Not enough arguments!");
-
- 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();
- }
- }
-
-}