aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-11-19 18:45:15 +0100
committerGitHub <noreply@github.com>2022-11-19 18:45:15 +0100
commit30607c34a153fd32085712e18827983772d77f7b (patch)
tree64d51d8ad8dfb6aa6042d8296e95f44ac5864d46 /libraries
parent817947c9284fecbe4dd5c0cd82186e5b8a4637e3 (diff)
parent70fa92f22ca8d013e7e101645d4ef60a21a52223 (diff)
downloadPrismLauncher-30607c34a153fd32085712e18827983772d77f7b.tar.gz
PrismLauncher-30607c34a153fd32085712e18827983772d77f7b.tar.bz2
PrismLauncher-30607c34a153fd32085712e18827983772d77f7b.zip
Merge pull request #291 from TheKodeToad/betterjavalauncher
Diffstat (limited to 'libraries')
-rw-r--r--libraries/README.md68
-rw-r--r--libraries/launcher/.gitignore1
-rw-r--r--libraries/launcher/CMakeLists.txt15
-rw-r--r--libraries/launcher/net/minecraft/Launcher.java181
-rw-r--r--libraries/launcher/org/prismlauncher/EntryPoint.java160
-rw-r--r--libraries/launcher/org/prismlauncher/Launcher.java23
-rw-r--r--libraries/launcher/org/prismlauncher/applet/LegacyFrame.java163
-rw-r--r--libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java45
-rw-r--r--libraries/launcher/org/prismlauncher/exception/ParseException.java47
-rw-r--r--libraries/launcher/org/prismlauncher/impl/OneSixLauncher.java190
-rw-r--r--libraries/launcher/org/prismlauncher/launcher/Launcher.java44
-rw-r--r--libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java110
-rw-r--r--libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java91
-rw-r--r--libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java190
-rw-r--r--libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java126
-rw-r--r--libraries/launcher/org/prismlauncher/utils/Parameters.java84
-rw-r--r--libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java154
-rw-r--r--libraries/launcher/org/prismlauncher/utils/Utils.java49
-rw-r--r--libraries/launcher/org/prismlauncher/utils/logging/Level.java (renamed from libraries/launcher/org/prismlauncher/LauncherFactory.java)57
-rw-r--r--libraries/launcher/org/prismlauncher/utils/logging/Log.java104
20 files changed, 1192 insertions, 710 deletions
diff --git a/libraries/README.md b/libraries/README.md
index dc38477b..ac5a3618 100644
--- a/libraries/README.md
+++ b/libraries/README.md
@@ -42,19 +42,20 @@ MIT licensed.
Java launcher part for Minecraft.
-It:
+It does the following:
-- Starts a process
-- Waits for a launch script on stdin
-- Consumes the launch script you feed it
-- Proceeds with launch when it gets the `launcher` command
+- Waits for a launch script on stdin.
+- Consumes the launch script you feed it.
+- Proceeds with launch when it gets the `launcher` command.
+
+If "abort" is sent, the process will exit.
This means the process is essentially idle until the final command is sent. You can, for example, attach a profiler before you send it.
-A `legacy` and `onesix` launchers are available.
+The `standard` and `legacy` launchers are available.
+- `standard` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title).
- `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated.
-- `onesix` can handle launching any Minecraft version, at the cost of some extra features `legacy` enables (custom window icon and title).
Example (some parts have been censored):
@@ -64,7 +65,7 @@ mainClass net.minecraft.launchwrapper.Launch
param --username
param CENSORED
param --version
-param MultiMC5
+param Prism Launcher
param --gameDir
param /home/peterix/minecraft/FTB/17ForgeTest/minecraft
param --assetsDir
@@ -81,58 +82,11 @@ param --userType
param mojang
param --tweakClass
param cpw.mods.fml.common.launcher.FMLTweaker
-windowTitle MultiMC: 172ForgeTest
+windowTitle Prism Launcher: 172ForgeTest
windowParams 854x480
userName CENSORED
sessionId token:CENSORED:CENSORED
-cp /home/peterix/minecraft/FTB/libraries/com/mojang/realms/1.3.5/realms-1.3.5.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar
-cp /home/peterix/minecraft/FTB/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar
-cp /home/peterix/minecraft/FTB/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar
-cp /home/peterix/minecraft/FTB/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar
-cp /home/peterix/minecraft/FTB/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar
-cp /home/peterix/minecraft/FTB/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar
-cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar
-cp /home/peterix/minecraft/FTB/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar
-cp /home/peterix/minecraft/FTB/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar
-cp /home/peterix/minecraft/FTB/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar
-cp /home/peterix/minecraft/FTB/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar
-cp /home/peterix/minecraft/FTB/libraries/io/netty/netty-all/4.0.10.Final/netty-all-4.0.10.Final.jar
-cp /home/peterix/minecraft/FTB/libraries/com/google/guava/guava/16.0/guava-16.0.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar
-cp /home/peterix/minecraft/FTB/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar
-cp /home/peterix/minecraft/FTB/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar
-cp /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar
-cp /home/peterix/minecraft/FTB/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar
-cp /home/peterix/minecraft/FTB/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
-cp /home/peterix/minecraft/FTB/libraries/com/mojang/authlib/1.5.16/authlib-1.5.16.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar
-cp /home/peterix/minecraft/FTB/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar
-cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar
-cp /home/peterix/minecraft/FTB/libraries/tv/twitch/twitch/5.16/twitch-5.16.jar
-cp /home/peterix/minecraft/FTB/libraries/net/minecraftforge/forge/1.7.10-10.13.0.1178/forge-1.7.10-10.13.0.1178.jar
-cp /home/peterix/minecraft/FTB/libraries/net/minecraft/launchwrapper/1.9/launchwrapper-1.9.jar
-cp /home/peterix/minecraft/FTB/libraries/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar
-cp /home/peterix/minecraft/FTB/libraries/com/typesafe/akka/akka-actor_2.11/2.3.3/akka-actor_2.11-2.3.3.jar
-cp /home/peterix/minecraft/FTB/libraries/com/typesafe/config/1.2.1/config-1.2.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-actors-migration_2.11/1.1.0/scala-actors-migration_2.11-1.1.0.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-library_2.11/1.0.2/scala-continuations-library_2.11-1.0.2.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/plugins/scala-continuations-plugin_2.11.1/1.0.2/scala-continuations-plugin_2.11.1-1.0.2.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-parser-combinators_2.11/1.0.1/scala-parser-combinators_2.11-1.0.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-swing_2.11/1.0.1/scala-swing_2.11-1.0.1.jar
-cp /home/peterix/minecraft/FTB/libraries/org/scala-lang/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar
-cp /home/peterix/minecraft/FTB/libraries/lzma/lzma/0.0.1/lzma-0.0.1.jar
-ext /home/peterix/minecraft/FTB/libraries/org/lwjgl/lwjgl/lwjgl-platform/2.9.1/lwjgl-platform-2.9.1-natives-linux.jar
-ext /home/peterix/minecraft/FTB/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar
-natives /home/peterix/minecraft/FTB/17ForgeTest/natives
-cp /home/peterix/minecraft/FTB/versions/1.7.10/1.7.10.jar
-launcher onesix
+launcher standard
```
Available under `GPL-3.0-only` (with classpath exception), sublicensed from its original `Apache-2.0` codebase
diff --git a/libraries/launcher/.gitignore b/libraries/launcher/.gitignore
index cc1c52bf..dda456e3 100644
--- a/libraries/launcher/.gitignore
+++ b/libraries/launcher/.gitignore
@@ -4,3 +4,4 @@ out
.classpath
.idea
.project
+bin/
diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt
index df25414f..55ed5875 100644
--- a/libraries/launcher/CMakeLists.txt
+++ b/libraries/launcher/CMakeLists.txt
@@ -4,18 +4,21 @@ find_package(Java 1.7 REQUIRED COMPONENTS Development)
include(UseJava)
set(CMAKE_JAVA_JAR_ENTRY_POINT org.prismlauncher.EntryPoint)
-set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unchecked)
+set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7)
set(SRC
org/prismlauncher/EntryPoint.java
- org/prismlauncher/Launcher.java
- org/prismlauncher/LauncherFactory.java
- org/prismlauncher/impl/OneSixLauncher.java
- org/prismlauncher/applet/LegacyFrame.java
+ org/prismlauncher/launcher/Launcher.java
+ org/prismlauncher/launcher/impl/AbstractLauncher.java
+ org/prismlauncher/launcher/impl/StandardLauncher.java
+ org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java
+ org/prismlauncher/launcher/impl/legacy/LegacyFrame.java
org/prismlauncher/exception/ParameterNotFoundException.java
org/prismlauncher/exception/ParseException.java
org/prismlauncher/utils/Parameters.java
- org/prismlauncher/utils/Utils.java
+ org/prismlauncher/utils/ReflectionUtils.java
+ org/prismlauncher/utils/logging/Level.java
+ org/prismlauncher/utils/logging/Log.java
net/minecraft/Launcher.java
)
add_jar(NewLaunch ${SRC})
diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java
index 6bf671be..646e2e3e 100644
--- a/libraries/launcher/net/minecraft/Launcher.java
+++ b/libraries/launcher/net/minecraft/Launcher.java
@@ -1,41 +1,83 @@
+// SPDX-License-Identifier: GPL-3.0-only
/*
- * Copyright 2012-2021 MultiMC Contributors
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
+ * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
*
- * 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
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * 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.
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give
+ * you permission to link this library with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also meet,
+ * for each linked independent module, the terms and conditions of the
+ * license of that module. An independent module is a module which is
+ * not derived from or based on this library. If you modify this
+ * library, you may extend this exception to your version of the
+ * library, but you are not obliged to do so. If you do not wish to do
+ * so, delete this exception statement from your version.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-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 net.minecraft;
import java.applet.Applet;
import java.applet.AppletStub;
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
import java.util.Map;
-import java.util.TreeMap;
-/*
+/**
* WARNING: This class is reflectively accessed by legacy Forge versions.
- * Changing field and method declarations without further testing is not recommended.
+ * <p>
+ * Changing field and method declarations without further testing is not
+ * recommended.
*/
public final class Launcher extends Applet implements AppletStub {
- private final Map<String, String> params = new TreeMap<>();
-
- private Applet wrappedApplet;
+ private static final long serialVersionUID = 1L;
- private URL documentBase;
+ private final Map<String, String> params = new HashMap<>();
+ private Applet wrappedApplet;
+ private final URL documentBase;
private boolean active = false;
public Launcher(Applet applet) {
@@ -43,35 +85,36 @@ public final class Launcher extends Applet implements AppletStub {
}
public Launcher(Applet applet, URL documentBase) {
- this.setLayout(new BorderLayout());
+ setLayout(new BorderLayout());
- this.add(applet, "Center");
+ add(applet, "Center");
- this.wrappedApplet = applet;
+ wrappedApplet = applet;
try {
- if (documentBase != null) {
- this.documentBase = documentBase;
- } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) {
- // Special case only for Classic versions
-
- this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/");
- } else {
- this.documentBase = new URL("http://www.minecraft.net/game/");
+ if (documentBase == null) {
+ if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) {
+ // Special case only for Classic versions
+ documentBase = new URL("http://www.minecraft.net:80/game/");
+ } else {
+ documentBase = new URL("http://www.minecraft.net/game/");
+ }
}
} catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ throw new AssertionError(e);
}
+
+ this.documentBase = documentBase;
}
public void replace(Applet applet) {
- this.wrappedApplet = applet;
+ wrappedApplet = applet;
applet.setStub(this);
applet.setSize(getWidth(), getHeight());
- this.setLayout(new BorderLayout());
- this.add(applet, "Center");
+ setLayout(new BorderLayout());
+ add(applet, "Center");
applet.init();
@@ -82,42 +125,48 @@ public final class Launcher extends Applet implements AppletStub {
validate();
}
- public void setParameter(String name, String value) {
- params.put(name, value);
+ @Override
+ public boolean isActive() {
+ return active;
+ }
+
+ @Override
+ public URL getDocumentBase() {
+ return documentBase;
+ }
+
+ @Override
+ public URL getCodeBase() {
+ try {
+ return new URL("http://www.minecraft.net/game/");
+ } catch (MalformedURLException e) {
+ throw new AssertionError(e);
+ }
}
@Override
- public String getParameter(String name) {
- String param = params.get(name);
+ public String getParameter(String key) {
+ String param = params.get(key);
if (param != null)
return param;
try {
- return super.getParameter(name);
- } catch (Exception ignored) {}
+ return super.getParameter(key);
+ } catch (Throwable ignored) {
+ }
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);
+ public void resize(Dimension size) {
+ wrappedApplet.resize(size);
}
@Override
@@ -140,33 +189,37 @@ public final class Launcher extends Applet implements AppletStub {
active = false;
}
+ @Override
public void destroy() {
wrappedApplet.destroy();
}
@Override
- public URL getCodeBase() {
- try {
- return new URL("http://www.minecraft.net/game/");
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
+ public void appletResize(int width, int height) {
+ wrappedApplet.resize(width, height);
}
@Override
- public URL getDocumentBase() {
- return documentBase;
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+
+ wrappedApplet.setVisible(visible);
}
@Override
- public void setVisible(boolean b) {
- super.setVisible(b);
+ public void paint(Graphics graphics) {
+ }
- wrappedApplet.setVisible(b);
+ @Override
+ public void update(Graphics graphics) {
}
- public void update(Graphics paramGraphics) {}
+ public void setParameter(String key, String value) {
+ params.put(key, value);
+ }
- public void paint(Graphics paramGraphics) {}
+ public void setParameter(String key, boolean value) {
+ setParameter(key, value ? "true" : "false");
+ }
}
diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java
index 9144e1f1..78804b3e 100644
--- a/libraries/launcher/org/prismlauncher/EntryPoint.java
+++ b/libraries/launcher/org/prismlauncher/EntryPoint.java
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
- * Copyright (C) 2022 icelimetea, <fr3shtea@outlook.com>
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
+ * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -52,113 +54,125 @@
package org.prismlauncher;
-import org.prismlauncher.exception.ParseException;
-import org.prismlauncher.utils.Parameters;
-
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 final class EntryPoint {
- private static final Logger LOGGER = Logger.getLogger("EntryPoint");
+import org.prismlauncher.exception.ParseException;
+import org.prismlauncher.launcher.Launcher;
+import org.prismlauncher.launcher.impl.StandardLauncher;
+import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
+import org.prismlauncher.utils.Parameters;
+import org.prismlauncher.utils.logging.Log;
- private final Parameters params = new Parameters();
+public final class EntryPoint {
public static void main(String[] args) {
- EntryPoint listener = new EntryPoint();
-
- int retCode = listener.listen();
+ ExitCode code = listen();
- if (retCode != 0) {
- LOGGER.info("Exiting with " + retCode);
+ if (code != ExitCode.NORMAL) {
+ Log.fatal("Exiting with " + code);
- System.exit(retCode);
+ System.exit(code.numeric);
}
}
- private Action parseLine(String inData) throws ParseException {
- String[] tokens = inData.split("\\s+", 2);
+ private static ExitCode listen() {
+ Parameters params = new Parameters();
+ PreLaunchAction action = PreLaunchAction.PROCEED;
- if (tokens.length == 0)
- throw new ParseException("Unexpected empty string!");
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) {
+ String line;
- switch (tokens[0]) {
- case "launch": {
- return Action.Launch;
+ while (action == PreLaunchAction.PROCEED) {
+ if ((line = reader.readLine()) != null)
+ action = parseLine(line, params);
+ else
+ action = PreLaunchAction.ABORT;
}
+ } catch (IllegalArgumentException e) {
+ Log.fatal("Aborting due to wrong argument", e);
- case "abort": {
- return Action.Abort;
- }
+ return ExitCode.ILLEGAL_ARGUMENT;
+ } catch (Throwable e) {
+ Log.fatal("Aborting due to exception", e);
- default: {
- if (tokens.length != 2)
- throw new ParseException("Error while parsing:" + inData);
+ return ExitCode.ABORT;
+ }
- params.add(tokens[0], tokens[1]);
+ if (action == PreLaunchAction.ABORT) {
+ Log.fatal("Launch aborted by the launcher");
- return Action.Proceed;
- }
+ return ExitCode.ABORT;
}
- }
- public int listen() {
- Action action = Action.Proceed;
+ try {
+ Launcher launcher;
+ String type = params.getString("launcher");
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(
- System.in,
- StandardCharsets.UTF_8
- ))) {
- String line;
+ switch (type) {
+ case "standard":
+ launcher = new StandardLauncher(params);
+ break;
- while (action == Action.Proceed) {
- if ((line = reader.readLine()) != null) {
- action = parseLine(line);
- } else {
- action = Action.Abort;
- }
+ case "legacy":
+ launcher = new LegacyLauncher(params);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Invalid launcher type: " + type);
}
- } catch (IOException | ParseException e) {
- LOGGER.log(Level.SEVERE, "Launcher ABORT due to exception:", e);
- return 1;
- }
+ launcher.launch();
+
+ return ExitCode.NORMAL;
+ } catch (IllegalArgumentException e) {
+ Log.fatal("Illegal argument", e);
- // Main loop
- if (action == Action.Abort) {
- LOGGER.info("Launch aborted by the launcher.");
+ return ExitCode.ILLEGAL_ARGUMENT;
+ } catch (Throwable e) {
+ Log.fatal("Exception caught from launcher", e);
- return 1;
+ return ExitCode.ERROR;
}
+ }
- try {
- Launcher launcher =
- LauncherFactory
- .getInstance()
- .createLauncher(params);
+ private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException {
+ switch (input) {
+ case "":
+ break;
- launcher.launch();
+ case "launch":
+ return PreLaunchAction.LAUNCH;
- return 0;
- } catch (IllegalArgumentException e) {
- LOGGER.log(Level.SEVERE, "Wrong argument.", e);
+ case "abort":
+ return PreLaunchAction.ABORT;
- return 1;
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
+ default:
+ String[] pair = input.split(" ", 2);
- return 1;
+ if (pair.length != 2)
+ throw new ParseException(input, "[key] [value]");
+
+ params.add(pair[0], pair[1]);
}
+
+ return PreLaunchAction.PROCEED;
+ }
+
+ private enum PreLaunchAction {
+ PROCEED, LAUNCH, ABORT
}
- private enum Action {
- Proceed,
- Launch,
- Abort
+ private enum ExitCode {
+ NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65);
+
+ private final int numeric;
+
+ ExitCode(int numeric) {
+ this.numeric = numeric;
+ }
+
}
}
diff --git a/libraries/launcher/org/prismlauncher/Launcher.java b/libraries/launcher/org/prismlauncher/Launcher.java
deleted file mode 100644
index 7f25717b..00000000
--- a/libraries/launcher/org/prismlauncher/Launcher.java
+++ /dev/null
@@ -1,23 +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.prismlauncher;
-
-public interface Launcher {
-
- void launch() throws Exception;
-
-}
diff --git a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java b/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java
deleted file mode 100644
index 4413efa8..00000000
--- a/libraries/launcher/org/prismlauncher/applet/LegacyFrame.java
+++ /dev/null
@@ -1,163 +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.prismlauncher.applet;
-
-import net.minecraft.Launcher;
-
-import javax.imageio.ImageIO;
-import java.applet.Applet;
-import java.awt.*;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public final class LegacyFrame extends Frame {
-
- private static final Logger LOGGER = Logger.getLogger("LegacyFrame");
-
- private final Launcher appletWrap;
-
- public LegacyFrame(String title, Applet mcApplet) {
- super(title);
-
- appletWrap = new Launcher(mcApplet);
-
- mcApplet.setStub(appletWrap);
-
- try {
- setIconImage(ImageIO.read(new File("icon.png")));
- } catch (IOException e) {
- LOGGER.log(Level.WARNING, "Unable to read Minecraft icon!", e);
- }
-
- addWindowListener(new ForceExitHandler());
- }
-
- public void start (
- String user,
- String session,
- int winSizeW,
- int winSizeH,
- boolean maximize,
- String serverAddress,
- String serverPort,
- boolean isDemo
- ) {
- // 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.
-
- Path mpticketFile =
- Paths.get(System.getProperty("user.dir"), "..", "mpticket");
-
- Path mpticketFileCorrupt =
- Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
-
- if (Files.exists(mpticketFile)) {
- try {
- List<String> lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8);
-
- if (lines.size() < 3) {
- Files.move(
- mpticketFile,
- mpticketFileCorrupt,
- StandardCopyOption.REPLACE_EXISTING
- );
-
- LOGGER.warning("Mpticket file is corrupted!");
- } else {
- // Assumes parameters are valid and in the correct order
- appletWrap.setParameter("server", lines.get(0));
- appletWrap.setParameter("port", lines.get(1));
- appletWrap.setParameter("mppass", lines.get(2));
- }
- } catch (IOException e) {
- LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e);
- }
- }
-
- 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", isDemo ? "true" : "false");
- appletWrap.setParameter("fullscreen", "false");
-
- add(appletWrap);
-
- appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH));
-
- pack();
-
- setLocationRelativeTo(null);
- setResizable(true);
-
- if (maximize)
- this.se