From c0b8c53e6960de48c6a43796b413d1780f681a3a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sat, 29 Oct 2022 15:05:43 +0100 Subject: Attempt to sort out copyright headers Signed-off-by: TheKodeToad --- .../prismlauncher/exception/ParseException.java | 58 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 51d25a62..8904f9ee 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,17 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only /* - * Copyright 2012-2021 MultiMC Contributors + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 icelimetea + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 Samisafool * - * 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 . + * + * 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 org.prismlauncher.exception; -- cgit From dabb84f62a35ea67793425f9118ea6a5bca96e00 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Tue, 1 Nov 2022 12:27:04 -0400 Subject: Cleanup launcher classes Cleanup a bunch of the code in launcher classes - Migrate the majority of the reflection to ReflectionUtils - Decrease logic in AbstractLauncher - Add logging to launcher classes at FINE level - make mcParams in AbstractLauncher an immutable list to prevent runtime manipulation - StandardLauncher instead copies the list to modify it Signed-off-by: solonovamax --- libraries/launcher/CMakeLists.txt | 1 + .../exception/ParameterNotFoundException.java | 22 +++- .../prismlauncher/exception/ParseException.java | 21 ++++ .../launcher/impl/AbstractLauncher.java | 67 ++++------- .../launcher/impl/StandardLauncher.java | 36 ++++-- .../launcher/impl/legacy/LegacyLauncher.java | 80 ++++--------- .../org/prismlauncher/utils/Parameters.java | 4 +- .../org/prismlauncher/utils/ReflectionUtils.java | 131 +++++++++++++++++++++ 8 files changed, 248 insertions(+), 114 deletions(-) create mode 100644 libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index f85c2354..45a43b93 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -18,6 +18,7 @@ set(SRC org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java org/prismlauncher/utils/Parameters.java + org/prismlauncher/utils/ReflectionUtils.java net/minecraft/Launcher.java ) add_jar(NewLaunch ${SRC}) diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index c083e02a..3dd6efc3 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -54,10 +54,28 @@ package org.prismlauncher.exception; + +@SuppressWarnings("serial") public final class ParameterNotFoundException extends IllegalArgumentException { - public ParameterNotFoundException(String key) { - super("Unknown parameter name: " + key); + public ParameterNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ParameterNotFoundException(Throwable cause) { + super(cause); + } + + public ParameterNotFoundException(String message) { + super(message); + } + + public ParameterNotFoundException() { + super(); + } + + public static ParameterNotFoundException forParameterName(String parameterName) { + return new ParameterNotFoundException(String.format("Unknown parameter name '%s'", parameterName)); } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 8904f9ee..2243f23f 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -54,10 +54,31 @@ package org.prismlauncher.exception; + +@SuppressWarnings({ "serial", "unused" }) public final class ParseException extends IllegalArgumentException { public ParseException(String message) { super(message); } + public ParseException(String message, Throwable cause) { + super(message, cause); + } + + public ParseException(Throwable cause) { + super(cause); + } + + public ParseException() { + super(); + } + + public static ParseException forInputString(String inputString) { + return new ParseException(String.format("Could not parse input string '%s'", inputString)); + } + + public static ParseException forInputString(String inputString, Throwable cause) { + return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); + } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index c572db10..9dd7df10 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -55,81 +55,66 @@ package org.prismlauncher.launcher.impl; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.util.ArrayList; +import java.util.Collections; import java.util.List; + public abstract class AbstractLauncher implements Launcher { private static final int DEFAULT_WINDOW_WIDTH = 854; + private static final int DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket protected final List mcParams; - private final String mainClass; // secondary parameters protected final int width; + protected final int height; + protected final boolean maximize; - protected final String serverAddress, serverPort; + protected final String serverAddress; - protected final ClassLoader classLoader; + protected final String serverPort; - protected AbstractLauncher(Parameters params) { - classLoader = ClassLoader.getSystemClassLoader(); + protected final String mainClassName; - mcParams = params.getList("param", new ArrayList()); - mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft"); + protected AbstractLauncher(Parameters params) { + this.mcParams = Collections.unmodifiableList(params.getList("param", new ArrayList())); + this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); - serverAddress = params.getString("serverAddress", null); - serverPort = params.getString("serverPort", null); + this.serverAddress = params.getString("serverAddress", null); + this.serverPort = params.getString("serverPort", null); String windowParams = params.getString("windowParams", null); - if ("max".equals(windowParams) || windowParams == null) { - maximize = windowParams != null; + this.maximize = "max".equalsIgnoreCase(windowParams); - width = DEFAULT_WINDOW_WIDTH; - height = DEFAULT_WINDOW_HEIGHT; - } else { - maximize = false; - + if (windowParams != null && !"max".equalsIgnoreCase(windowParams)) { String[] sizePair = StringUtils.splitStringPair('x', windowParams); - + if (sizePair != null) { try { - width = Integer.parseInt(sizePair[0]); - height = Integer.parseInt(sizePair[1]); - return; - } catch (NumberFormatException ignored) { + this.width = Integer.parseInt(sizePair[0]); + this.height = Integer.parseInt(sizePair[1]); + } catch (NumberFormatException e) { + throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), e); } + } else { + throw new ParseException(String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); } - - throw new ParseException("Invalid window size parameter value: " + windowParams); + } else { + this.width = DEFAULT_WINDOW_WIDTH; + this.height = DEFAULT_WINDOW_HEIGHT; } } - - protected Class loadMain() throws ClassNotFoundException { - return classLoader.loadClass(mainClass); - } - - protected void loadAndInvokeMain() throws Throwable { - invokeMain(loadMain()); - } - - protected void invokeMain(Class mainClass) throws Throwable { - MethodHandle method = MethodHandles.lookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); - - method.invokeExact(mcParams.toArray(new String[0])); - } - } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 24b12c95..fc0c9823 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -58,9 +58,17 @@ package org.prismlauncher.launcher.impl; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; + +import java.lang.invoke.MethodHandle; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public final class StandardLauncher extends AbstractLauncher { + private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); + public StandardLauncher(Parameters params) { super(params); @@ -78,21 +86,27 @@ public final class StandardLauncher extends AbstractLauncher { // the following often breaks linux screen setups // mcparams.add("--fullscreen"); - if (!maximize) { - mcParams.add("--width"); - mcParams.add(Integer.toString(width)); - mcParams.add("--height"); - mcParams.add(Integer.toString(height)); + List launchParameters = new ArrayList<>(this.mcParams); + + if (!this.maximize) { + launchParameters.add("--width"); + launchParameters.add(Integer.toString(width)); + launchParameters.add("--height"); + launchParameters.add(Integer.toString(height)); } - if (serverAddress != null) { - mcParams.add("--server"); - mcParams.add(serverAddress); - mcParams.add("--port"); - mcParams.add(serverPort); + if (this.serverAddress != null) { + launchParameters.add("--server"); + launchParameters.add(serverAddress); + launchParameters.add("--port"); + launchParameters.add(serverPort); } - loadAndInvokeMain(); + LOGGER.info("Launching minecraft using the main class entrypoint"); + + MethodHandle method = ReflectionUtils.findMainEntrypoint(this.mainClassName); + + method.invokeExact((Object[]) launchParameters.toArray(new String[0])); } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index e342e788..0ce3c57b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -60,14 +60,11 @@ import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; -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.lang.reflect.Modifier; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -87,7 +84,7 @@ public final class LegacyLauncher extends AbstractLauncher { private final String appletClass; - private final boolean noApplet; + private final boolean usesApplet; private final String cwd; @@ -100,8 +97,9 @@ public final class LegacyLauncher extends AbstractLauncher { appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); List traits = params.getList("traits", Collections.emptyList()); - noApplet = traits.contains("noapplet"); + usesApplet = !traits.contains("noapplet"); + //noinspection AccessOfSystemProperties cwd = System.getProperty("user.dir"); } @@ -109,74 +107,40 @@ public final class LegacyLauncher extends AbstractLauncher { return new LegacyLauncherProvider(); } - /** - * Finds a field that looks like a Minecraft base folder in a supplied class - * - * @param clazz the class to scan - * - * @return The found field. - */ - private static Field getMinecraftGameDirField(Class clazz) { - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : clazz.getDeclaredFields()) { - // Has to be File - if (field.getType() != File.class) - continue; - - // And Private Static. - if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) - continue; - - return field; - } - - return null; - } - @Override public void launch() throws Throwable { - Class main = loadMain(); - Field gameDirField = getMinecraftGameDirField(main); + Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); + Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); if (gameDirField == null) { - LOGGER.warning("Could not find Mineraft path field."); + LOGGER.warning("Could not find Minecraft path field"); } else { gameDirField.setAccessible(true); - gameDirField.set(null, new File(cwd)); + gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); } - if (!noApplet) { - LOGGER.info("Launching with applet wrapper..."); + if (this.usesApplet) { + LOGGER.info("Launching legacy minecraft using 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); + LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(this.appletClass)); window.start( - user, - session, - width, - height, - maximize, - serverAddress, - serverPort, - mcParams.contains("--demo") + this.user, + this.session, + this.width, this.height, this.maximize, + this.serverAddress, this.serverPort, + this.mcParams.contains("--demo") ); - - return; } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Applet wrapper failed:", e); - - LOGGER.warning("Falling back to using main class."); + LOGGER.log(Level.SEVERE, "Running applet wrapper failed with exception", e); } - } + } else { + LOGGER.info("Launching legacy minecraft using the main class entrypoint"); + MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - invokeMain(main); + method.invokeExact((Object[]) mcParams.toArray(new String[0])); + } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 5596e88a..6fbd0ef1 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -83,7 +83,7 @@ public final class Parameters { List params = map.get(key); if (params == null) - throw new ParameterNotFoundException(key); + throw ParameterNotFoundException.forParameterName(key); return params; } @@ -101,7 +101,7 @@ public final class Parameters { List list = getList(key); if (list.isEmpty()) - throw new ParameterNotFoundException(key); + throw ParameterNotFoundException.forParameterName(key); return list.get(0); } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java new file mode 100644 index 00000000..484e0d8a --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -0,0 +1,131 @@ +package org.prismlauncher.utils; + + +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.lang.reflect.Modifier; +import java.util.logging.Level; +import java.util.logging.Logger; + + +public final class ReflectionUtils { + private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); + + private ReflectionUtils() { + } + + /** + * Instantiate an applet class by name + * + * @param appletClassName The name of the applet class to resolve + * + * @return The instantiated applet class + * + * @throws ClassNotFoundException if the provided class name cannot be found + * @throws NoSuchMethodException if the no-args constructor cannot be found + * @throws IllegalAccessException if the constructor cannot be accessed via method handles + * @throws Throwable any exceptions from the class's constructor + */ + public static Applet createAppletClass(String appletClassName) throws Throwable { + Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); + + MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, MethodType.methodType(void.class)); + return (Applet) appletConstructor.invoke(); + } + + /** + * Finds a field that looks like a Minecraft base folder in a supplied class + * + * @param minecraftMainClass the class to scan + * + * @return The found field. + */ + public static Field getMinecraftGameDirField(Class minecraftMainClass) { + LOGGER.fine("Resolving minecraft game directory field"); + // Field we're looking for is always + // private static File obfuscatedName = null; + for (Field field : minecraftMainClass.getDeclaredFields()) { + // Has to be File + if (field.getType() != File.class) { + continue; + } + + int fieldModifiers = field.getModifiers(); + + + // Must be static + if (!Modifier.isStatic(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is not static", field.getName()); + continue; + } + + // Must be private + if (!Modifier.isPrivate(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is not private", field.getName()); + continue; + } + + // Must not be final + if (Modifier.isFinal(fieldModifiers)) { + LOGGER.log(Level.FINE, "Rejecting field {0} because it is final", field.getName()); + continue; + } + + LOGGER.log(Level.FINE, "Identified field {0} to match conditions for minecraft game directory field", field.getName()); + + return field; + } + + return null; + } + + /** + * Resolve main entrypoint and returns method handle for it. + *

+ * Resolves a method that matches the following signature + * + * public static void main(String[] args) { + *

+ * } + * + * + * @param entrypointClass The entrypoint class to resolve the method from + * + * @return The method handle for the resolved entrypoint + * + * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws IllegalAccessException If method handles cannot access the entrypoint + */ + public static MethodHandle findMainEntrypoint(Class entrypointClass) throws NoSuchMethodException, IllegalAccessException { + return MethodHandles.lookup().findStatic(entrypointClass, "main", MethodType.methodType(void.class, String[].class)); + } + + /** + * Resolve main entrypoint and returns method handle for it. + *

+ * Resolves a method that matches the following signature + * + * public static void main(String[] args) { + *

+ * } + * + * + * @param entrypointClassName The name of the entrypoint class to resolve the method from + * + * @return The method handle for the resolved entrypoint + * + * @throws ClassNotFoundException If a class cannot be found with the provided name + * @throws NoSuchMethodException If no method matching the correct signature can be found + * @throws IllegalAccessException If method handles cannot access the entrypoint + */ + public static MethodHandle findMainEntrypoint(String entrypointClassName) throws + ClassNotFoundException, + NoSuchMethodException, + IllegalAccessException { + return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); + } +} -- cgit From afe088dba18b83ae1ea79e3b31ef5026f68b7b6d Mon Sep 17 00:00:00 2001 From: solonovamax Date: Wed, 2 Nov 2022 15:10:05 -0400 Subject: Fix license headers - Update license headers in several files to remove multimc apache reference, when unneeded - LauncherFactory: we've entirely rewritten this class at this point, so it's fully under GPL code - Launcher: this interface contains zero logic, and only a single method named `launch`, so I doubt you can actually copyright that - LauncherProvider: same as above - ParseException, ParameterNotFoundException: same as above; this class contains almost no logic (And the logic that was added is under GPL) - ReflectionUtils, StringUtils: add license header - Everything else: modify the program name in the license header from "PolyMC - Minecraft Launcher" to "Prism Launcher" Signed-off-by: solonovamax --- libraries/launcher/net/minecraft/Launcher.java | 3 +- .../launcher/org/prismlauncher/EntryPoint.java | 3 +- .../exception/ParameterNotFoundException.java | 20 ++--------- .../prismlauncher/exception/ParseException.java | 20 ++--------- .../org/prismlauncher/launcher/Launcher.java | 20 ++--------- .../prismlauncher/launcher/LauncherFactory.java | 20 ++--------- .../prismlauncher/launcher/LauncherProvider.java | 20 ++--------- .../launcher/impl/AbstractLauncher.java | 3 +- .../launcher/impl/StandardLauncher.java | 3 +- .../launcher/impl/legacy/LegacyFrame.java | 7 ++-- .../launcher/impl/legacy/LegacyLauncher.java | 3 +- .../org/prismlauncher/utils/Parameters.java | 3 +- .../org/prismlauncher/utils/ReflectionUtils.java | 38 ++++++++++++++++++++ .../org/prismlauncher/utils/StringUtils.java | 40 ++++++++++++++++++++-- 14 files changed, 103 insertions(+), 100 deletions(-) (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 147c727e..8dff5692 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 07af4e55..444e665f 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 3dd6efc3..48bf9f4c 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -33,23 +34,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * 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 org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 2243f23f..0d5f3c10 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -33,23 +34,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * 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 org.prismlauncher.exception; diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 7bf9ba0d..d54cfd5c 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -35,23 +36,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * 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 org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 6f9be63c..03a76d29 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool @@ -35,23 +36,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * 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 org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java index 66d23c0f..73d0cdc5 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * @@ -32,23 +33,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * 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 org.prismlauncher.launcher; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 9dd7df10..ac7a6223 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index fc0c9823..61709bf7 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 12196fd4..391aa702 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 flow @@ -56,11 +57,13 @@ package org.prismlauncher.launcher.impl.legacy; + import net.minecraft.Launcher; import javax.imageio.ImageIO; import java.applet.Applet; -import java.awt.*; +import java.awt.Dimension; +import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 0ce3c57b..17cdeb08 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 6fbd0ef1..d019aa41 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher + * * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 484e0d8a..b0eefec7 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -1,3 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher + * + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad + * Copyright (C) 2022 icelimetea + * + * 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. + * + * 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. + * + * 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 . + */ + package org.prismlauncher.utils; diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index 9058e4b3..d470624c 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -1,15 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher + * + * Copyright (C) 2022 solonovamax + * + * 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. + * + * 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. + * + * 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 . + */ + package org.prismlauncher.utils; public final class StringUtils { private StringUtils() { } - + public static String[] splitStringPair(char splitChar, String input) { int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; - + return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; } } -- cgit From 8ce78dcc54a8ed3e6292a8650692fa9c520a993d Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 3 Nov 2022 16:40:23 +0000 Subject: Try to improve consistency - Makes code formatting more consistent with the C++ codebase. Probably removes some trailing whitespace. Maybe it would be best to commit an Eclipse or IntelliJ code format preferences file? - Removes obscure suppressions. I personally think it's better to only suppress warnings that javac complains about. Suppressing a lot of non-standardised warnings (many of them turned off by default even in IntelliJ) just creates needless clutter. - Fixes some trivial warnings instead of suppressing them. serialVersionUID is sort of stupid, but I'd rather mentally ignore it or just fix it if it's really that annoying. Signed-off-by: TheKodeToad --- libraries/launcher/net/minecraft/Launcher.java | 12 ++++++------ libraries/launcher/org/prismlauncher/EntryPoint.java | 14 +++++--------- .../exception/ParameterNotFoundException.java | 7 ++++--- .../org/prismlauncher/exception/ParseException.java | 7 +++++-- .../org/prismlauncher/launcher/LauncherFactory.java | 4 ++-- .../org/prismlauncher/launcher/impl/AbstractLauncher.java | 14 +++----------- .../org/prismlauncher/launcher/impl/StandardLauncher.java | 9 +++------ .../prismlauncher/launcher/impl/legacy/LegacyFrame.java | 5 ++--- .../prismlauncher/launcher/impl/legacy/LegacyLauncher.java | 13 +++---------- .../launcher/org/prismlauncher/utils/ReflectionUtils.java | 9 ++++----- .../launcher/org/prismlauncher/utils/StringUtils.java | 5 +++-- 11 files changed, 40 insertions(+), 59 deletions(-) (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 8dff5692..796e4829 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -72,12 +72,12 @@ import java.util.TreeMap; */ public final class Launcher extends Applet implements AppletStub { + private static final long serialVersionUID = 1L; + private final Map params = new TreeMap<>(); private Applet wrappedApplet; - private final URL documentBase; - private boolean active = false; public Launcher(Applet applet) { @@ -85,11 +85,11 @@ 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"); - this.wrappedApplet = applet; + wrappedApplet = applet; try { if (documentBase != null) { @@ -109,12 +109,12 @@ public final class Launcher extends Applet implements AppletStub { } public void replace(Applet applet) { - this.wrappedApplet = applet; + wrappedApplet = applet; applet.setStub(this); applet.setSize(getWidth(), getHeight()); - this.setLayout(new BorderLayout()); + setLayout(new BorderLayout()); this.add(applet, "Center"); applet.init(); diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 444e665f..be180d6a 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -55,7 +55,6 @@ package org.prismlauncher; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherFactory; @@ -69,7 +68,6 @@ 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"); @@ -92,11 +90,11 @@ public final class EntryPoint { throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); - if ("launch".equalsIgnoreCase(input)) { + if ("launch".equalsIgnoreCase(input)) return PreLaunchAction.LAUNCH; - } else if ("abort".equalsIgnoreCase(input)) { + else if ("abort".equalsIgnoreCase(input)) return PreLaunchAction.ABORT; - } else { + else { String[] pair = StringUtils.splitStringPair(' ', input); if (pair == null) throw new ParseException(String.format( @@ -119,11 +117,10 @@ public final class EntryPoint { while (preLaunchAction == PreLaunchAction.PROCEED) { //noinspection NestedAssignment - if ((line = reader.readLine()) != null) { + if ((line = reader.readLine()) != null) preLaunchAction = parseLine(line, parameters); - } else { + else preLaunchAction = PreLaunchAction.ABORT; - } } } catch (IOException | ParseException e) { LOGGER.log(Level.SEVERE, "Launcher abort due to exception", e); @@ -165,7 +162,6 @@ public final class EntryPoint { ABORT } - private enum ExitCode { NORMAL(0), ABORT(1), diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 48bf9f4c..ad973ace 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * 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 @@ -38,10 +40,10 @@ package org.prismlauncher.exception; - -@SuppressWarnings("serial") public final class ParameterNotFoundException extends IllegalArgumentException { + private static final long serialVersionUID = 1L; + public ParameterNotFoundException(String message, Throwable cause) { super(message, cause); } @@ -55,7 +57,6 @@ public final class ParameterNotFoundException extends IllegalArgumentException { } public ParameterNotFoundException() { - super(); } public static ParameterNotFoundException forParameterName(String parameterName) { diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 0d5f3c10..2fd693e7 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * 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 @@ -38,10 +40,10 @@ package org.prismlauncher.exception; - -@SuppressWarnings({ "serial", "unused" }) public final class ParseException extends IllegalArgumentException { + private static final long serialVersionUID = 1L; + public ParseException(String message) { super(message); } @@ -65,4 +67,5 @@ public final class ParseException extends IllegalArgumentException { public static ParseException forInputString(String inputString, Throwable cause) { return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 03a76d29..4844a774 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -40,13 +40,12 @@ package org.prismlauncher.launcher; - import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.utils.Parameters; - public final class LauncherFactory { + private LauncherFactory() { } @@ -78,4 +77,5 @@ public final class LauncherFactory { return launcherProvider; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index ac7a6223..8aec7c28 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -56,7 +56,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; @@ -66,26 +65,18 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - public abstract class AbstractLauncher implements Launcher { private static final int DEFAULT_WINDOW_WIDTH = 854; - private static final int DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket protected final List mcParams; // secondary parameters - protected final int width; - - protected final int height; - + protected final int width, height; protected final boolean maximize; - - protected final String serverAddress; - - protected final String serverPort; + protected final String serverAddress, serverPort; protected final String mainClassName; @@ -118,4 +109,5 @@ public abstract class AbstractLauncher implements Launcher { this.height = DEFAULT_WINDOW_HEIGHT; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 61709bf7..a3ea2f4a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -55,7 +55,6 @@ package org.prismlauncher.launcher.impl; - import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.utils.Parameters; @@ -66,10 +65,9 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; - public final class StandardLauncher extends AbstractLauncher { - private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); + private static final Logger LOGGER = Logger.getLogger("LegacyLauncher"); public StandardLauncher(Parameters params) { super(params); @@ -105,16 +103,15 @@ public final class StandardLauncher extends AbstractLauncher { LOGGER.info("Launching minecraft using the main class entrypoint"); - MethodHandle method = ReflectionUtils.findMainEntrypoint(this.mainClassName); - + MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); method.invokeExact((Object[]) launchParameters.toArray(new String[0])); } - private static class StandardLauncherProvider implements LauncherProvider { @Override public Launcher provide(Parameters parameters) { return new StandardLauncher(parameters); } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 391aa702..96b422b2 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -57,7 +57,6 @@ package org.prismlauncher.launcher.impl.legacy; - import net.minecraft.Launcher; import javax.imageio.ImageIO; @@ -77,7 +76,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -public final class LegacyFrame extends Frame { +public final class LegacyFrame extends Frame /* TODO consider JFrame */ { private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); @@ -163,7 +162,7 @@ public final class LegacyFrame extends Frame { setResizable(true); if (maximize) - this.setExtendedState(MAXIMIZED_BOTH); + setExtendedState(MAXIMIZED_BOTH); validate(); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 17cdeb08..71e4bc8d 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -56,7 +56,6 @@ package org.prismlauncher.launcher.impl.legacy; - import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.impl.AbstractLauncher; @@ -71,7 +70,6 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; - /** * Used to launch old versions that support applets. */ @@ -80,13 +78,9 @@ 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 usesApplet; - private final String cwd; public LegacyLauncher(Parameters params) { @@ -100,7 +94,6 @@ public final class LegacyLauncher extends AbstractLauncher { List traits = params.getList("traits", Collections.emptyList()); usesApplet = !traits.contains("noapplet"); - //noinspection AccessOfSystemProperties cwd = System.getProperty("user.dir"); } @@ -113,9 +106,9 @@ public final class LegacyLauncher extends AbstractLauncher { Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); - if (gameDirField == null) { + if (gameDirField == null) LOGGER.warning("Could not find Minecraft path field"); - } else { + else { gameDirField.setAccessible(true); gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); } @@ -144,11 +137,11 @@ public final class LegacyLauncher extends AbstractLauncher { } } - private static class LegacyLauncherProvider implements LauncherProvider { @Override public Launcher provide(Parameters parameters) { return new LegacyLauncher(parameters); } } + } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index b0eefec7..ad9e57fd 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -49,8 +49,8 @@ import java.lang.reflect.Modifier; import java.util.logging.Level; import java.util.logging.Logger; - public final class ReflectionUtils { + private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); private ReflectionUtils() { @@ -160,10 +160,9 @@ public final class ReflectionUtils { * @throws NoSuchMethodException If no method matching the correct signature can be found * @throws IllegalAccessException If method handles cannot access the entrypoint */ - public static MethodHandle findMainEntrypoint(String entrypointClassName) throws - ClassNotFoundException, - NoSuchMethodException, - IllegalAccessException { + public static MethodHandle findMainMethod(String entrypointClassName) + throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); } + } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index d470624c..a371b0cb 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -36,8 +36,8 @@ package org.prismlauncher.utils; - public final class StringUtils { + private StringUtils() { } @@ -46,6 +46,7 @@ public final class StringUtils { if (splitPoint == -1) return null; - return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; + return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) }; } + } -- cgit From 1ea2e854156820ee5ba3c59d0c99fe4465566b9c Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 16:29:19 +0000 Subject: Implicit is generally prefered Signed-off-by: TheKodeToad --- libraries/launcher/org/prismlauncher/EntryPoint.java | 2 +- libraries/launcher/org/prismlauncher/exception/ParseException.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 0fa3691d..512b01a9 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -157,7 +157,7 @@ public final class EntryPoint { LOGGER.log(Level.SEVERE, "Wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { + } catch (ReflectiveOperationException e) { LOGGER.log(Level.SEVERE, "Caught reflection exception from launcher", e); return ExitCode.ERROR; diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 2fd693e7..49f5b006 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -57,7 +57,6 @@ public final class ParseException extends IllegalArgumentException { } public ParseException() { - super(); } public static ParseException forInputString(String inputString) { -- cgit From e6dc34fe102f183e6857744283ee86c620091d08 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 4 Nov 2022 17:18:17 +0000 Subject: More license fixing Signed-off-by: TheKodeToad --- .../exception/ParameterNotFoundException.java | 2 -- .../org/prismlauncher/exception/ParseException.java | 2 -- .../launcher/org/prismlauncher/launcher/Launcher.java | 2 -- .../prismlauncher/launcher/impl/AbstractLauncher.java | 1 - .../launcher/impl/legacy/LegacyFrame.java | 2 -- .../launcher/org/prismlauncher/utils/Parameters.java | 2 -- .../org/prismlauncher/utils/ReflectionUtils.java | 19 ++++++++++++++++++- 7 files changed, 18 insertions(+), 12 deletions(-) (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index ad973ace..52c2a368 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad * diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 49f5b006..80709c56 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad * diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index d54cfd5c..1a6577e0 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 938e3403..7ae7568c 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -3,7 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 28f85aa2..15da0371 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -3,9 +3,7 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 flow - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index d019aa41..8286bd70 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -3,8 +3,6 @@ * Prism Launcher * * Copyright (C) 2022 icelimetea - * Copyright (C) 2022 Sefa Eyeoglu - * Copyright (C) 2022 Samisafool * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax * diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 99df70c3..1d2383a4 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -2,9 +2,9 @@ /* * Prism Launcher * + * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad - * Copyright (C) 2022 icelimetea * * 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 @@ -34,6 +34,23 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * 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 org.prismlauncher.utils; -- cgit From 32c2ad2bbd087b83fe5e1cfe03926410ec95bcca Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 8 Nov 2022 17:51:18 +0000 Subject: A lot more cleanup Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 25 +- launcher/minecraft/MinecraftInstance.h | 4 +- libraries/README.md | 66 +--- libraries/launcher/CMakeLists.txt | 4 +- libraries/launcher/formatting-profile.xml | 399 --------------------- libraries/launcher/net/minecraft/Launcher.java | 87 ++--- .../launcher/org/prismlauncher/EntryPoint.java | 105 +++--- .../exception/ParameterNotFoundException.java | 22 +- .../prismlauncher/exception/ParseException.java | 26 +- .../org/prismlauncher/launcher/Launcher.java | 3 +- .../launcher/impl/AbstractLauncher.java | 48 ++- .../launcher/impl/StandardLauncher.java | 38 +- .../launcher/impl/legacy/LegacyFrame.java | 99 +++-- .../launcher/impl/legacy/LegacyLauncher.java | 53 +-- .../org/prismlauncher/utils/Parameters.java | 23 +- .../org/prismlauncher/utils/ReflectionUtils.java | 103 ++---- .../org/prismlauncher/utils/StringUtils.java | 11 +- .../org/prismlauncher/utils/logging/Level.java | 11 +- .../org/prismlauncher/utils/logging/Log.java | 52 +-- .../utils/logging/LogPrintStream.java | 99 +++++ 20 files changed, 417 insertions(+), 861 deletions(-) delete mode 100644 libraries/launcher/formatting-profile.xml create mode 100644 libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java (limited to 'libraries/launcher/org/prismlauncher/exception/ParseException.java') diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 39a7198c..a5b19f09 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Jamie Mansfield * Copyright (C) 2022 TheKodeToad @@ -438,6 +438,17 @@ QStringList MinecraftInstance::javaArguments() return args; } +QString MinecraftInstance::getLauncher() +{ + auto profile = m_components->getProfile(); + + // use legacy launcher if the traits are set + if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch")) + return "legacy"; + + return "standard"; +} + QMap MinecraftInstance::getVariables() { QMap out; @@ -634,15 +645,7 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS launchScript += "traits " + trait + "\n"; } - launchScript += "launcher "; - - // use legacy launcher if the traits are set - if (profile->getTraits().contains("legacyLaunch") || profile->getTraits().contains("alphaLaunch")) - launchScript += "legacy"; - else - launchScript += "standard"; - - launchScript += "\n"; + launchScript += "launcher " + getLauncher() + "\n"; // qDebug() << "Generated launch script:" << launchScript; return launchScript; @@ -779,6 +782,8 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr out << "Window size: " + QString::number(width) + " x " + QString::number(height); } out << ""; + out << "Launcher: " + getLauncher(); + out << ""; return out; } diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h index 1895d187..1bbd7b83 100644 --- a/launcher/minecraft/MinecraftInstance.h +++ b/launcher/minecraft/MinecraftInstance.h @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad * * 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 @@ -130,6 +131,7 @@ public: QString createLaunchScript(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin); /// get arguments passed to java QStringList javaArguments(); + QString getLauncher(); /// get variables for launch command variable substitution/environment QMap getVariables() override; diff --git a/libraries/README.md b/libraries/README.md index 2971e32b..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 `standard` launchers are available. +The `standard` and `legacy` launchers are available. -- `legacy` is intended for use with Minecraft versions < 1.6 and is deprecated. - `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. 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,57 +82,10 @@ 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 standard ``` diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 90adcd3d..1d22a93e 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -9,10 +9,10 @@ set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7) set(SRC org/prismlauncher/EntryPoint.java org/prismlauncher/launcher/Launcher.java - org/prismlauncher/launcher/impl/legacy/LegacyFrame.java - org/prismlauncher/launcher/impl/legacy/LegacyLauncher.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 diff --git a/libraries/launcher/formatting-profile.xml b/libraries/launcher/formatting-profile.xml deleted file mode 100644 index 1b334838..00000000 --- a/libraries/launcher/formatting-profile.xml +++ /dev/null @@ -1,399 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index b895d5b7..a721495a 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -62,8 +61,10 @@ 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; + +import org.prismlauncher.utils.logging.Log; /** * WARNING: This class is reflectively accessed by legacy Forge versions. @@ -75,7 +76,7 @@ public final class Launcher extends Applet implements AppletStub { private static final long serialVersionUID = 1L; - private final Map params = new TreeMap<>(); + private final Map params = new HashMap<>(); private Applet wrappedApplet; private final URL documentBase; @@ -88,75 +89,75 @@ public final class Launcher extends Applet implements AppletStub { public Launcher(Applet applet, URL documentBase) { setLayout(new BorderLayout()); - this.add(applet, "Center"); + add(applet, "Center"); wrappedApplet = applet; try { - if (documentBase != null) { - this.documentBase = documentBase; - } else if (applet.getClass().getPackage().getName().startsWith("com.mojang.")) { - // Special case only for Classic versions - - // TODO: 2022-10-27 Can this be changed to https - this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); - } else { - // TODO: 2022-10-27 Can this be changed to https? - 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); + // handle gracefully - it won't happen, but Java requires that it is caught + Log.error("Failed to parse document base URL", e); } + + this.documentBase = documentBase; } public void replace(Applet applet) { wrappedApplet = applet; applet.setStub(this); - applet.setSize(this.getWidth(), this.getHeight()); + applet.setSize(getWidth(), getHeight()); setLayout(new BorderLayout()); - this.add(applet, "Center"); + add(applet, "Center"); applet.init(); - this.active = true; + active = true; applet.start(); - this.validate(); + validate(); } @Override public boolean isActive() { - return this.active; + return active; } @Override public URL getDocumentBase() { - return this.documentBase; + return documentBase; } @Override public URL getCodeBase() { try { - // TODO: 2022-10-27 Can this be changed to https? return new URL("http://www.minecraft.net/game/"); } catch (MalformedURLException e) { - throw new RuntimeException(e); + Log.error("Failed to parse codebase URL", e); + return null; } } @Override - public String getParameter(String name) { - String param = this.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; @@ -164,49 +165,49 @@ public final class Launcher extends Applet implements AppletStub { @Override public void resize(int width, int height) { - this.wrappedApplet.resize(width, height); + wrappedApplet.resize(width, height); } @Override public void resize(Dimension size) { - this.wrappedApplet.resize(size); + wrappedApplet.resize(size); } @Override public void init() { - if (this.wrappedApplet != null) - this.wrappedApplet.init(); + if (wrappedApplet != null) + wrappedApplet.init(); } @Override public void start() { - this.wrappedApplet.start(); + wrappedApplet.start(); - this.active = true; + active = true; } @Override public void stop() { - this.wrappedApplet.stop(); + wrappedApplet.stop(); - this.active = false; + active = false; } @Override public void destroy() { - this.wrappedApplet.destroy(); + wrappedApplet.destroy(); } @Override public void appletResize(int width, int height) { - this.wrappedApplet.resize(width, height); + wrappedApplet.resize(width, height); } @Override public void setVisible(boolean visible) { super.setVisible(visible); - this.wrappedApplet.setVisible(visible); + wrappedApplet.setVisible(visible); } @Override @@ -217,8 +218,12 @@ public final class Launcher extends Applet implements AppletStub { public void update(Graphics graphics) { } - public void setParameter(String name, String value) { - this.params.put(name, value); + public void setParameter(String key, String value) { + params.put(key, value); + } + + 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 34e65672..f6567468 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -56,7 +55,6 @@ package org.prismlauncher; import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -70,63 +68,40 @@ import org.prismlauncher.utils.logging.Log; public final class EntryPoint { - private EntryPoint() { - } - public static void main(String[] args) { - ExitCode exitCode = listen(); + ExitCode code = listen(); - if (exitCode != ExitCode.NORMAL) { - Log.fatal("Exiting with " + exitCode); + if (code != ExitCode.NORMAL) { + Log.fatal("Exiting with " + code); - System.exit(exitCode.numericalCode); - } - } - - private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { - if (input.isEmpty()) - return PreLaunchAction.PROCEED; - - if ("launch".equalsIgnoreCase(input)) - return PreLaunchAction.LAUNCH; - else if ("abort".equalsIgnoreCase(input)) - return PreLaunchAction.ABORT; - else { - String[] pair = StringUtils.splitStringPair(' ', input); - - if (pair == null) - throw new ParseException(String.format( - "Could not split input string '%s' by space. All input provided from stdin must be either 'launch', 'abort', or " - + "in the format '[param name] [param]'.", - input)); - - params.add(pair[0], pair[1]); - - return PreLaunchAction.PROCEED; + System.exit(code.numeric); } } private static ExitCode listen() { - Parameters parameters = new Parameters(); - PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; + Parameters params = new Parameters(); + PreLaunchAction action = PreLaunchAction.PROCEED; try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) { String line; - while (preLaunchAction == PreLaunchAction.PROCEED) { + while (action == PreLaunchAction.PROCEED) { if ((line = reader.readLine()) != null) - preLaunchAction = parseLine(line, parameters); + action = parseLine(line, params); else - preLaunchAction = PreLaunchAction.ABORT; + action = PreLaunchAction.ABORT; } - } catch (IOException | ParseException e) { - Log.fatal("Launcher abort due to exception", e); + } catch (IllegalArgumentException e) { + Log.fatal("Aborting due to wrong argument", e); return ExitCode.ILLEGAL_ARGUMENT; + } catch (Throwable e) { + Log.fatal("Aborting due to exception", e); + + return ExitCode.ABORT; } - // Main loop - if (preLaunchAction == PreLaunchAction.ABORT) { + if (action == PreLaunchAction.ABORT) { Log.fatal("Launch aborted by the launcher"); return ExitCode.ABORT; @@ -134,33 +109,28 @@ public final class EntryPoint { try { Launcher launcher; - String type = parameters.getString("launcher"); + String type = params.getString("launcher"); switch (type) { case "standard": - launcher = new StandardLauncher(parameters); + launcher = new StandardLauncher(params); break; + case "legacy": - launcher = new LegacyLauncher(parameters); + launcher = new LegacyLauncher(params); break; + default: throw new IllegalArgumentException("Invalid launcher type: " + type); } - Log.launcher("Using " + type + " launcher"); - Log.blankLine(); - launcher.launch(); return ExitCode.NORMAL; } catch (IllegalArgumentException e) { - Log.fatal("Wrong argument", e); + Log.fatal("Illegal argument", e); return ExitCode.ILLEGAL_ARGUMENT; - } catch (ReflectiveOperationException e) { - Log.fatal("Caught reflection exception from launcher", e); - - return ExitCode.ERROR; } catch (Throwable e) { Log.fatal("Exception caught from launcher", e); @@ -168,6 +138,29 @@ public final class EntryPoint { } } + private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException { + switch (input) { + case "": + break; + + case "launch": + return PreLaunchAction.LAUNCH; + + case "abort": + return PreLaunchAction.ABORT; + + default: + String[] pair = StringUtils.splitStringPair(' ', input); + + if (pair == null) + throw new ParseException(input, "[key] [value]"); + + params.add(pair[0], pair[1]); + } + + return PreLaunchAction.PROCEED; + } + private enum PreLaunchAction { PROCEED, LAUNCH, ABORT } @@ -175,10 +168,10 @@ public final class EntryPoint { private enum ExitCode { NORMAL(0), ABORT(1), ERROR(2), ILLEGAL_ARGUMENT(65); - private final int numericalCode; + private final int numeric; - ExitCode(int numericalCode) { - this.numericalCode = numericalCode; + ExitCode(int numeric) { + this.numeric = numeric; } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 52c2a368..524076ff 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -42,23 +41,8 @@ public final class ParameterNotFoundException extends IllegalArgumentException { private static final long serialVersionUID = 1L; - public ParameterNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public ParameterNotFoundException(Throwable cause) { - super(cause); - } - - public ParameterNotFoundException(String message) { - super(message); - } - - public ParameterNotFoundException() { - } - - public static ParameterNotFoundException forParameterName(String parameterName) { - return new ParameterNotFoundException(String.format("Unknown parameter name '%s'", parameterName)); + public ParameterNotFoundException(String key) { + super(String.format("Required parameter '%s' was not found", key)); } } diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 80709c56..4608fdd1 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -42,27 +41,8 @@ public final class ParseException extends IllegalArgumentException { private static final long serialVersionUID = 1L; - public ParseException(String message) { - super(message); - } - - public ParseException(String message, Throwable cause) { - super(message, cause); - } - - public ParseException(Throwable cause) { - super(cause); - } - - public ParseException() { - } - - public static ParseException forInputString(String inputString) { - return new ParseException(String.format("Could not parse input string '%s'", inputString)); - } - - public static ParseException forInputString(String inputString, Throwable cause) { - return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); + public ParseException(String input, String format) { + super(String.format("For input '%s' - should match '%s'", input, format)); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java index 1a6577e0..049a83d8 100644 --- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java +++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index 7ae7568c..585d55f1 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,21 +54,20 @@ package org.prismlauncher.launcher.impl; +import java.util.ArrayList; +import java.util.List; + import org.prismlauncher.exception.ParseException; import org.prismlauncher.launcher.Launcher; import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.StringUtils; -import java.util.ArrayList; -import java.util.List; - public abstract class AbstractLauncher implements Launcher { - private static final int DEFAULT_WINDOW_WIDTH = 854; - private static final int DEFAULT_WINDOW_HEIGHT = 480; + private static final int DEFAULT_WINDOW_WIDTH = 854, DEFAULT_WINDOW_HEIGHT = 480; // parameters, separated from ParamBucket - protected final List mcParams; + protected final List gameArgs; // secondary parameters protected final int width, height; @@ -79,34 +77,34 @@ public abstract class AbstractLauncher implements Launcher { protected final String mainClassName; protected AbstractLauncher(Parameters params) { - this.mcParams = params.getList("param", new ArrayList()); - this.mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); + gameArgs = params.getList("param", new ArrayList()); + mainClassName = params.getString("mainClass", "net.minecraft.client.Minecraft"); - this.serverAddress = params.getString("serverAddress", null); - this.serverPort = params.getString("serverPort", null); + serverAddress = params.getString("serverAddress", null); + serverPort = params.getString("serverPort", null); String windowParams = params.getString("windowParams", null); - this.maximize = "max".equalsIgnoreCase(windowParams); + if ("max".equals(windowParams) || windowParams == null) { + maximize = windowParams != null; + + width = DEFAULT_WINDOW_WIDTH; + height = DEFAULT_WINDOW_HEIGHT; + } else { + maximize = false; - if (windowParams != null && !"max".equalsIgnoreCase(windowParams)) { String[] sizePair = StringUtils.splitStringPair('x', windowParams); if (sizePair != null) { try { - this.width = Integer.parseInt(sizePair[0]); - this.height = Integer.parseInt(sizePair[1]); - } catch (NumberFormatException e) { - throw new ParseException(String.format("Could not parse window parameters from '%s'", windowParams), - e); + width = Integer.parseInt(sizePair[0]); + height = Integer.parseInt(sizePair[1]); + return; + } catch (NumberFormatException ignored) { } - } else { - throw new ParseException( - String.format("Invalid window size parameters '%s'. Format: [height]x[width]", windowParams)); } - } else { - this.width = DEFAULT_WINDOW_WIDTH; - this.height = DEFAULT_WINDOW_HEIGHT; + + throw new ParseException(windowParams, "[width]x[height]"); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 0f6fcf34..9436ff15 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,11 +54,11 @@ package org.prismlauncher.launcher.impl; +import java.lang.invoke.MethodHandle; + import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.ReflectionUtils; -import java.lang.invoke.MethodHandle; - public final class StandardLauncher extends AbstractLauncher { public StandardLauncher(Parameters params) { @@ -69,27 +68,24 @@ public final class StandardLauncher extends AbstractLauncher { @Override public void launch() throws Throwable { // window size, title and state - - // FIXME: there is no good way to maximize the minecraft window from here. - // the following often breaks linux screen setups - // mcparams.add("--fullscreen"); - - if (!this.maximize) { - this.mcParams.add("--width"); - this.mcParams.add(Integer.toString(this.width)); - this.mcParams.add("--height"); - this.mcParams.add(Integer.toString(this.height)); + // FIXME doesn't support maximisation + if (!maximize) { + gameArgs.add("--width"); + gameArgs.add(Integer.toString(width)); + gameArgs.add("--height"); + gameArgs.add(Integer.toString(height)); } - if (this.serverAddress != null) { - this.mcParams.add("--server"); - this.mcParams.add(this.serverAddress); - this.mcParams.add("--port"); - this.mcParams.add(this.serverPort); + if (serverAddress != null) { + gameArgs.add("--server"); + gameArgs.add(serverAddress); + gameArgs.add("--port"); + gameArgs.add(serverPort); } - MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName); - method.invokeExact(this.mcParams.toArray(new String[0])); + // find and invoke the main method + MethodHandle method = ReflectionUtils.findMainMethod(mainClassName); + method.invokeExact(gameArgs.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 8ff64ced..c215e7fe 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad @@ -55,13 +54,6 @@ package org.prismlauncher.launcher.impl.legacy; -import net.minecraft.Launcher; - -import javax.imageio.ImageIO; -import javax.swing.JFrame; - -import org.prismlauncher.utils.logging.Log; - import java.applet.Applet; import java.awt.Dimension; import java.awt.event.WindowAdapter; @@ -75,6 +67,13 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.List; +import javax.imageio.ImageIO; +import javax.swing.JFrame; + +import org.prismlauncher.utils.logging.Log; + +import net.minecraft.Launcher; + public final class LegacyFrame extends JFrame { private static final long serialVersionUID = 1L; @@ -84,85 +83,85 @@ public final class LegacyFrame extends JFrame { public LegacyFrame(String title, Applet applet) { super(title); - this.launcher = new Launcher(applet); + launcher = new Launcher(applet); - applet.setStub(this.launcher); + applet.setStub(launcher); try { - this.setIconImage(ImageIO.read(new File("icon.png"))); + setIconImage(ImageIO.read(new File("icon.png"))); } catch (IOException e) { - Log.error("Unable to read Minecraft icon", e); + Log.error("Failed to read window icon", e); } - this.addWindowListener(new ForceExitHandler()); + addWindowListener(new ForceExitHandler()); } public void start(String user, String session, int width, int height, boolean maximize, String serverAddress, - String serverPort, boolean isDemo) { + String serverPort, boolean demo) { // 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"); + // mpticket file generated by an external program and stored in the instance's + // root folder. + Path instanceFolder = Paths.get(".."); + Path mpticket = instanceFolder.resolve("mpticket"); + Path mpticketCorrupt = instanceFolder.resolve("mpticket.corrupt"); - Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt"); - - if (Files.exists(mpticketFile)) { + if (Files.exists(mpticket)) { try { - List lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8); + List lines = Files.readAllLines(mpticket, StandardCharsets.UTF_8); if (lines.size() < 3) { - Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING); + Files.move(mpticket, mpticketCorrupt, StandardCopyOption.REPLACE_EXISTING); - Log.warning("Mpticket file is corrupted!"); + Log.warning("mpticket file is corrupted"); } else { // Assumes parameters are valid and in the correct order - this.launcher.setParameter("server", lines.get(0)); - this.launcher.setParameter("port", lines.get(1)); - this.launcher.setParameter("mppass", lines.get(2)); + launcher.setParameter("server", lines.get(0)); + launcher.setParameter("port", lines.get(1)); + launcher.setParameter("mppass", lines.get(2)); } } catch (IOException e) { - Log.error("Unable to read mpticket file", e); + Log.error("Failed to read mpticket file", e); } } if (serverAddress != null) { - this.launcher.setParameter("server", serverAddress); - this.launcher.setParameter("port", serverPort); + launcher.setParameter("server", serverAddress); + launcher.setParameter("port", serverPort); } - this.launcher.setParameter("username", user); - this.launcher.setParameter("sessionid", session); - this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work? - this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. - this.launcher.setParameter("demo", isDemo ? "true" : "false"); - this.launcher.setParameter("fullscreen", "false"); + launcher.setParameter("username", user); + launcher.setParameter("sessionid", session); + launcher.setParameter("stand-alone", true); // Show the quit button. TODO: why won't this work? + launcher.setParameter("haspaid", true); // Some old versions need this for world saves to work. + launcher.setParameter("demo", demo); + launcher.setParameter("fullscreen", false); - this.add(this.launcher); + add(launcher); - this.launcher.setPreferredSize(new Dimension(width, height)); + launcher.setPreferredSize(new Dimension(width, height)); - this.pack(); + pack(); - this.setLocationRelativeTo(null); - this.setResizable(true); + setLocationRelativeTo(null); + setResizable(true); if (maximize) setExtendedState(MAXIMIZED_BOTH); - this.validate(); + validate(); - this.launcher.init(); - this.launcher.start(); + launcher.init(); + launcher.start(); - this.setVisible(true); + setVisible(true); } private final class ForceExitHandler extends WindowAdapter { @Override public void windowClosing(WindowEvent event) { + // FIXME better solution + new Thread(new Runnable() { @Override public void run() { @@ -177,9 +176,9 @@ public final class LegacyFrame extends JFrame { } }).start(); - if (LegacyFrame.this.launcher != null) { - LegacyFrame.this.launcher.stop(); - LegacyFrame.this.launcher.destroy(); + if (launcher != null) { + launcher.stop(); + launcher.destroy(); } // old minecraft versions can hang without this >_< diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 5ffa9ec5..d349177b 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 flow * Copyright (C) 2022 TheKodeToad @@ -56,17 +55,17 @@ package org.prismlauncher.launcher.impl.legacy; -import org.prismlauncher.launcher.impl.AbstractLauncher; -import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.ReflectionUtils; -import org.prismlauncher.utils.logging.Log; - import java.io.File; import java.lang.invoke.MethodHandle; import java.lang.reflect.Field; import java.util.Collections; import java.util.List; +import org.prismlauncher.launcher.impl.AbstractLauncher; +import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.ReflectionUtils; +import org.prismlauncher.utils.logging.Log; + /** * Used to launch old versions that support applets. */ @@ -75,51 +74,53 @@ public final class LegacyLauncher extends AbstractLauncher { private final String user, session; private final String title; private final String appletClass; - private final boolean usesApplet; - private final String cwd; + private final boolean useApplet; + private final String gameDir; public LegacyLauncher(Parameters params) { super(params); - this.user = params.getString("userName"); - this.session = params.getString("sessionId"); - this.title = params.getString("windowTitle", "Minecraft"); - this.appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); + user = params.getString("userName"); + session = params.getString("sessionId"); + title = params.getString("windowTitle", "Minecraft"); + appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); List traits = params.getList("traits", Collections.emptyList()); - this.usesApplet = !traits.contains("noapplet"); + useApplet = !traits.contains("noapplet"); - this.cwd = System.getProperty("user.dir"); + gameDir = System.getProperty("user.dir"); } @Override public void launch() throws Throwable { - Class main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); - Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); + Class main = ClassLoader.getSystemClassLoader().loadClass(mainClassName); + Field gameDirField = ReflectionUtils.findMinecraftGameDirField(main); if (gameDirField == null) - Log.warning("Could not find Minecraft path field"); + Log.warning("Could not find Minecraft folder field"); else { gameDirField.setAccessible(true); - gameDirField.set(null /* field is static, so instance is null */, new File(this.cwd)); + gameDirField.set(null, new File(gameDir)); } - if (this.usesApplet) { - Log.launcher("Launching with applet wrapper..."); + if (useApplet) { + System.setProperty("minecraft.applet.TargetDirectory", gameDir); try { - LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass)); + LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(appletClass)); - window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress, - this.serverPort, this.mcParams.contains("--demo")); + window.start(user, session, width, height, maximize, serverAddress, serverPort, + gameArgs.contains("--demo")); return; } catch (Throwable e) { Log.error("Running applet wrapper failed with exception; falling back to main class", e); } } - MethodHandle method = ReflectionUtils.findMainEntrypoint(main); - method.invokeExact(this.mcParams.toArray(new String[0])); + // find and invoke the main method, this time without size parameters + // in all versions that support applets, these are ignored + MethodHandle method = ReflectionUtils.findMainMethod(main); + method.invokeExact(gameArgs.toArray(new String[0])); } } diff --git a/libraries/launcher/org/prismlauncher/utils/Parameters.java b/libraries/launcher/org/prismlauncher/utils/Parameters.java index 7af3c5e8..6365753e 100644 --- a/libraries/launcher/org/prismlauncher/utils/Parameters.java +++ b/libraries/launcher/org/prismlauncher/utils/Parameters.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 TheKodeToad * Copyright (C) 2022 solonovamax @@ -55,40 +54,40 @@ package org.prismlauncher.utils; -import org.prismlauncher.exception.ParameterNotFoundException; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.prismlauncher.exception.ParameterNotFoundException; + public final class Parameters { private final Map> map = new HashMap<>(); public void add(String key, String value) { - List params = this.map.get(key); + List params = map.get(key); if (params == null) { params = new ArrayList<>(); - this.map.put(key, params); + map.put(key, params); } params.add(value); } public List getList(String key) throws ParameterNotFoundException { - List params = this.map.get(key); + List params = map.get(key); if (params == null) - throw ParameterNotFoundException.forParameterName(key); + throw new ParameterNotFoundException(key); return params; } public List getList(String key, List def) { - List params = this.map.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; @@ -97,16 +96,16 @@ public final class Parameters { } public String getString(String key) throws ParameterNotFoundException { - List list = this.getList(key); + List list = getList(key); if (list.isEmpty()) - throw ParameterNotFoundException.forParameterName(key); + throw new ParameterNotFoundException(key); return list.get(0); } public String getString(String key, String def) { - List params = this.map.get(key); + List params = map.get(key); if (params == null || params.isEmpty()) return def; diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index 3b299615..dd212ef9 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 icelimetea * Copyright (C) 2022 solonovamax * Copyright (C) 2022 TheKodeToad @@ -67,68 +66,57 @@ import org.prismlauncher.utils.logging.Log; public final class ReflectionUtils { - private ReflectionUtils() { - } + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + private static final ClassLoader LOADER = ClassLoader.getSystemClassLoader(); /** - * Instantiate an applet class by name - * - * @param appletClassName The name of the applet class to resolve + * Construct a Java applet by its class name. * - * @return The instantiated applet class - * - * @throws ClassNotFoundException if the provided class name cannot be found - * @throws NoSuchMethodException if the no-args constructor cannot be found - * @throws IllegalAccessException if the constructor cannot be accessed via - * method handles - * @throws Throwable any exceptions from the class's constructor + * @param clazz The class name + * @return The applet instance + * @throws Throwable */ - public static Applet createAppletClass(String appletClassName) throws Throwable { - Class appletClass = ClassLoader.getSystemClassLoader().loadClass(appletClassName); + public static Applet createAppletClass(String clazz) throws Throwable { + Class appletClass = LOADER.loadClass(clazz); - MethodHandle appletConstructor = MethodHandles.lookup().findConstructor(appletClass, - MethodType.methodType(void.class)); + MethodHandle appletConstructor = LOOKUP.findConstructor(appletClass, MethodType.methodType(void.class)); return (Applet) appletConstructor.invoke(); } /** - * Finds a field that looks like a Minecraft base folder in a supplied class - * - * @param minecraftMainClass the class to scan + * Best guess of the game directory field within net.minecraft.client.Minecraft. + * Designed for legacy versions - newer versions do not use a static field. * - * @return The found field. + * @param clazz The class + * @return The first field matching criteria */ - public static Field getMinecraftGameDirField(Class minecraftMainClass) { + public static Field findMinecraftGameDirField(Class clazz) { Log.debug("Resolving minecraft game directory field"); - // Field we're looking for is always - // private static File obfuscatedName = null; - for (Field field : minecraftMainClass.getDeclaredFields()) { - // Has to be File + + // search for private static File + for (Field field : clazz.getDeclaredFields()) { if (field.getType() != File.class) { continue; } int fieldModifiers = field.getModifiers(); - // Must be static if (!Modifier.isStatic(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is not static"); continue; } - // Must be private if (!Modifier.isPrivate(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is not private"); continue; } - // Must not be final if (Modifier.isFinal(fieldModifiers)) { Log.debug("Rejecting field " + field.getName() + " because it is final"); continue; } - Log.debug("Identified field " + field.getName() + " to match conditions for minecraft game directory field"); + Log.debug("Identified field " + field.getName() + " to match conditions for game directory field"); return field; } @@ -137,51 +125,30 @@ public final class ReflectionUtils { } /** - * Resolve main entrypoint and returns method handle for it. - *

- * Resolves a method that matches the following signature - * public static void main(String[] args) { - *

- * } - * - * - * @param entrypointClass The entrypoint class to resolve the method from - * - * @return The method handle for the resolved entrypoint + * Gets the main method within a class. * - * @throws NoSuchMethodException If no method matching the correct signature - * can be found - * @throws IllegalAccessException If method handles cannot access the entrypoint + * @param clazz The class + * @return A method matching the descriptor of a main method + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws IllegalAccessException */ - public static MethodHandle findMainEntrypoint(Class entrypointClass) - throws NoSuchMethodException, IllegalAccessException { - return MethodHandles.lookup().findStatic(entrypointClass, "main", - MethodType.methodType(void.class, String[].class)); + public static MethodHandle findMainMethod(Class clazz) throws NoSuchMethodException, IllegalAccessException { + return LOOKUP.findStatic(clazz, "main", MethodType.methodType(void.class, String[].class)); } /** - * Resolve main entrypoint and returns method handle for it. - *

- * Resolves a method that matches the following signature - * public static void main(String[] args) { - *

- * } - * - * - * @param entrypointClassName The name of the entrypoint class to resolve the - * method from - * - * @return The method handle for the resolved entrypoint + * Gets the main method within a class by its name. * - * @throws ClassNotFoundException If a class cannot be found with the provided - * name - * @throws NoSuchMethodException If no method matching the correct signature - * can be found - * @throws IllegalAccessException If method handles cannot access the entrypoint + * @param clazz The class name + * @return A method matching the descriptor of a main method + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws IllegalAccessException */ - public static MethodHandle findMainMethod(String entrypointClassName) + public static MethodHandle findMainMethod(String clazz) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException { - return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); + return findMainMethod(LOADER.loadClass(clazz)); } } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index a371b0cb..dfd1634b 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * Prism Launcher - * + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 solonovamax * * This program is free software: you can redistribute it and/or modify @@ -38,15 +37,13 @@ package org.prismlauncher.utils; public final class StringUtils { - private StringUtils() { - } + public static String[] splitStringPair(char splitChar, String str) { + int splitPoint = str.indexOf(splitChar); - public static String[] splitStringPair(char splitChar, String input) { - int splitPoint = input.indexOf(splitChar); if (splitPoint == -1) return null; - return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) }; + return new String[] { str.substring(0, splitPoint), str.substring(splitPoint + 1) }; } } diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Level.java b/libraries/launcher/org/prismlauncher/utils/logging/Level.java index 330cec28..552b0b55 100644 --- a/libraries/launcher/org/prismlauncher/utils/logging/Level.java +++ b/libraries/launcher/org/prismlauncher/utils/logging/Level.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -36,8 +36,13 @@ package org.prismlauncher.utils.logging; public enum Level { - LAUNCHER("Launcher"), DEBUG("Debug"), INFO("Info"), MESSAGE("Message"), - WARNING("Warning"), ERROR("Error", true), FATAL("Fatal", true); + LAUNCHER("Launcher"), + DEBUG("Debug"), + INFO("Info"), + MESSAGE("Message"), + WARNING("Warning"), + ERROR("Error", true), + FATAL("Fatal", true); String name; boolean stderr; diff --git a/libraries/launcher/org/prismlauncher/utils/logging/Log.java b/libraries/launcher/org/prismlauncher/utils/logging/Log.java index e1961991..374a8107 100644 --- a/libraries/launcher/org/prismlauncher/utils/logging/Log.java +++ b/libraries/launcher/org/prismlauncher/utils/logging/Log.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -44,37 +44,12 @@ import java.io.PrintStream; */ public final class Log { - private static final PrintStream ERROR_PREFIX = new PrintStream(System.err) { - @Override - public void println(String x) { - error(x); - } - - @Override - public void println(Object x) { - error(String.valueOf(x)); - } - }, FATAL_PREFIX = new PrintStream(System.err) { - @Override - public void println(String x) { - fatal(x); - } - - @Override - public void println(Object x) { - fatal(String.valueOf(x)); - } - }; - + // original before overridden + private static final PrintStream OUT = new PrintStream(System.out), ERR = new PrintStream(System.err); + private static final PrintStream ERROR_PREFIX = new LogPrintStream(System.err, Level.ERROR), + FATAL_PREFIX = new LogPrintStream(System.err, Level.FATAL); private static final boolean DEBUG = Boolean.getBoolean("org.prismlauncher.debug"); - private Log() { - } - - public static void blankLine() { - System.out.println(); - } - public static void launcher(String message) { log(message, Level.LAUNCHER); } @@ -84,16 +59,9 @@ public final class Log { } public static void debug(String message) { - if (!DEBUG) - return; - log(message, Level.DEBUG); } - public static void info(String message) { - log(message, Level.INFO); - } - public static void warning(String message) { log(message, Level.WARNING); } @@ -113,12 +81,16 @@ public final class Log { } /** - * Logs a message with the prefix !![LEVEL]!. + * Logs a message with the prefix !![LEVEL]!. This is picked up by + * the log viewer to give it nice colours. * * @param message The message * @param level The level */ public static void log(String message, Level level) { + if (!DEBUG && level == Level.DEBUG) + return; + String prefix = "!![" + level.name + "]!"; // prefix first line message = prefix + message; @@ -126,9 +98,9 @@ public final class Log { message = message.replace("\n", "\n" + prefix); if (level.stderr) - System.err.println(message); + ERR.println(message); else - System.out.println(message); + OUT.println(message); } } diff --git a/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java b/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java new file mode 100644 index 00000000..8a182817 --- /dev/null +++ b/libraries/launcher/org/prismlauncher/utils/logging/LogPrintStream.java @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 TheKodeToad + * + * 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. + * + * 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. + * + * 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 . + */ + +package org.prismlauncher.utils.logging; + +import java.io.OutputStream; +import java.io.PrintStream; + +/** + * Used to create a print stream that redirects to Log. + */ +final class LogPrintStream extends PrintStream { + + private final Level level; + + public LogPrintStream(OutputStream out, Level level) { + super(out); + + this.level = level; + } + + @Override + public void println(String x) { + Log.log(x, level); + } + + @Override + public void println(Object x) { + println(String.valueOf(x)); + } + + @Override + public void println(boolean x) { + println(String.valueOf(x)); + } + + @Override + public void println(char x) { + println(String.valueOf(x)); + } + + @Override + public void println(int x) { + println(String.valueOf(x)); + } + + @Override + public void println(long x) { + println(String.valueOf(x)); + } + + @Override + public void println(float x) { + println(String.valueOf(x)); + } + + @Override + public void println(double x) { + println(String.valueOf(x)); + } + + @Override + public void println(char[] x) { + println(String.valueOf(x)); + } + +} \ No newline at end of file -- cgit