aboutsummaryrefslogtreecommitdiff
path: root/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2022-10-24 18:21:26 +0100
committerTheKodeToad <TheKodeToad@proton.me>2022-11-08 16:24:55 +0000
commite68dcea6bcb5830659d17db40fc9a83a4eca9cc0 (patch)
tree9684169f7752919d05a70445abd1ec0b4e9dde7a /libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java
parente4e0c27e1c8317b7287a84dc24b274674c359615 (diff)
downloadPrismLauncher-e68dcea6bcb5830659d17db40fc9a83a4eca9cc0.tar.gz
PrismLauncher-e68dcea6bcb5830659d17db40fc9a83a4eca9cc0.tar.bz2
PrismLauncher-e68dcea6bcb5830659d17db40fc9a83a4eca9cc0.zip
Various tweaks to the Java component of the launcher
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java')
-rw-r--r--libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java
new file mode 100644
index 00000000..30a4dba7
--- /dev/null
+++ b/libraries/launcher/org/prismlauncher/impl/LegacyLauncher.java
@@ -0,0 +1,104 @@
+/* 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.impl;
+
+import java.applet.Applet;
+import java.io.File;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.prismlauncher.applet.LegacyFrame;
+import org.prismlauncher.utils.Parameters;
+import org.prismlauncher.utils.Utils;
+
+@SuppressWarnings("removal")
+public final class LegacyLauncher extends AbstractLauncher {
+
+ private static final Logger LOGGER = Logger.getLogger("LegacyLauncher");
+
+ private final String user, session;
+ private final String title;
+ private final String appletClass;
+
+ private final boolean noApplet;
+ private final String cwd;
+
+ public LegacyLauncher(Parameters params) {
+ super(params);
+
+ user = params.first("userName");
+ session = params.first("sessionId");
+ title = params.firstSafe("windowTitle", "Minecraft");
+ appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
+
+ List<String> traits = params.allSafe("traits", Collections.<String>emptyList());
+ noApplet = traits.contains("noapplet");
+
+ cwd = System.getProperty("user.dir");
+ }
+
+ @Override
+ public void launch() throws Throwable {
+ Class<?> main = loadMain();
+ Field gameDirField = Utils.getMinecraftGameDirField(main);
+
+ if (gameDirField == null) {
+ LOGGER.warning("Could not find Mineraft path field.");
+ } else {
+ gameDirField.setAccessible(true);
+ gameDirField.set(null, new File(cwd));
+ }
+
+ if (!noApplet) {
+ LOGGER.info("Launching with applet wrapper...");
+
+ try {
+ Class<?> appletClass = classLoader.loadClass(this.appletClass);
+
+ MethodHandle constructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class));
+ Applet applet = (Applet) constructor.invoke();
+
+ LegacyFrame window = new LegacyFrame(title, applet);
+
+ window.start(
+ user,
+ session,
+ width,
+ height,
+ maximize,
+ serverAddress,
+ serverPort,
+ mcParams.contains("--demo")
+ );
+
+ return;
+ } catch (Throwable e) {
+ LOGGER.log(Level.SEVERE, "Applet wrapper failed:", e);
+
+ LOGGER.warning("Falling back to using main class.");
+ }
+ }
+
+ invokeMain(main);
+ }
+
+}