From 94067f34cf8a42c735c264ca30740bfec6f5af3a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Wed, 21 Dec 2022 18:13:41 +0000 Subject: [PATCH] Try to make some of the suggested changes Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 6 +- libraries/launcher/CMakeLists.txt | 3 +- .../org/prismlauncher/fix/skins/Handler.java | 7 +- .../org/prismlauncher/fix/skins/SkinFix.java | 2 +- .../utils/{url => }/UrlUtils.java | 14 ++-- .../utils/url/NullConnection.java | 66 ------------------- 6 files changed, 14 insertions(+), 84 deletions(-) rename libraries/launcher/org/prismlauncher/utils/{url => }/UrlUtils.java (91%) delete mode 100644 libraries/launcher/org/prismlauncher/utils/url/NullConnection.java diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 4434936f0..378af0e10 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -192,7 +192,7 @@ void MinecraftInstance::loadSpecificSettings() m_settings->registerSetting("JoinServerOnLaunch", false); m_settings->registerSetting("JoinServerOnLaunchAddress", ""); - m_settings->registerSetting("LegacySkinFix", true); + m_settings->registerSetting("LegacySkinFix", true); qDebug() << "Instance-type specific settings were loaded!"; @@ -441,7 +441,9 @@ QStringList MinecraftInstance::javaArguments() args << "-Duser.language=en"; if (javaVersion.isModular() && traits().contains("legacySkins") && settings()->get("LegacySkinFix").toBool()) - args << "--add-opens" << "java.base/java.net=ALL-UNNAMED"; + // allow reflective access to java.net - required by the skin fix + args << "--add-opens" + << "java.base/java.net=ALL-UNNAMED"; return args; } diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index 65a8241eb..acc276218 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -23,8 +23,7 @@ set(SRC org/prismlauncher/utils/JsonParser.java org/prismlauncher/utils/Parameters.java org/prismlauncher/utils/ReflectionUtils.java - org/prismlauncher/utils/url/NullConnection.java - org/prismlauncher/utils/url/UrlUtils.java + org/prismlauncher/utils/UrlUtils.java org/prismlauncher/utils/logging/Level.java org/prismlauncher/utils/logging/Log.java net/minecraft/Launcher.java diff --git a/libraries/launcher/org/prismlauncher/fix/skins/Handler.java b/libraries/launcher/org/prismlauncher/fix/skins/Handler.java index 0f5b556f8..fa306ed44 100644 --- a/libraries/launcher/org/prismlauncher/fix/skins/Handler.java +++ b/libraries/launcher/org/prismlauncher/fix/skins/Handler.java @@ -45,8 +45,7 @@ import java.util.Map; import org.prismlauncher.utils.Base64; import org.prismlauncher.utils.JsonParser; -import org.prismlauncher.utils.url.NullConnection; -import org.prismlauncher.utils.url.UrlUtils; +import org.prismlauncher.utils.UrlUtils; @SuppressWarnings("unchecked") final class Handler extends URLStreamHandler { @@ -71,10 +70,6 @@ final class Handler extends URLStreamHandler { @Override protected URLConnection openConnection(URL address, Proxy proxy) throws IOException { address = redirect(address); - - if (address == null) - return NullConnection.INSTANCE; - return UrlUtils.openHttpConnection(address, proxy); } diff --git a/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java b/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java index 19b15605a..3dd747376 100644 --- a/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java +++ b/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java @@ -42,8 +42,8 @@ import java.net.URLStreamHandlerFactory; import org.prismlauncher.fix.Fix; import org.prismlauncher.utils.Base64; import org.prismlauncher.utils.Parameters; +import org.prismlauncher.utils.UrlUtils; import org.prismlauncher.utils.logging.Log; -import org.prismlauncher.utils.url.UrlUtils; /** * Fixes skins by redirecting to other URLs. diff --git a/libraries/launcher/org/prismlauncher/utils/url/UrlUtils.java b/libraries/launcher/org/prismlauncher/utils/UrlUtils.java similarity index 91% rename from libraries/launcher/org/prismlauncher/utils/url/UrlUtils.java rename to libraries/launcher/org/prismlauncher/utils/UrlUtils.java index 05912d005..1ab0eb918 100644 --- a/libraries/launcher/org/prismlauncher/utils/url/UrlUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/UrlUtils.java @@ -33,7 +33,7 @@ * along with this program. If not, see . */ -package org.prismlauncher.utils.url; +package org.prismlauncher.utils; import java.io.IOException; import java.lang.invoke.MethodHandle; @@ -47,8 +47,8 @@ import java.net.URLStreamHandler; import org.prismlauncher.utils.logging.Log; /** - * A utility class for URLs which uses reflection to access hidden methods. - * Unfortunately not supported on newer Java versions. + * A utility class for URLs which uses reflection to access constructors for + * internal classes. */ public final class UrlUtils { @@ -57,12 +57,12 @@ public final class UrlUtils { static { try { - // invoke URL.getURLStreamHandler to obtain some of the default handlers before - // they are overridden + // we first obtain the stock URLStreamHandler for http as we overwrite it later Method getURLStreamHandler = URL.class.getDeclaredMethod("getURLStreamHandler", String.class); getURLStreamHandler.setAccessible(true); http = (URLStreamHandler) getURLStreamHandler.invoke(null, "http"); + // we next find the openConnection method Method openConnectionReflect = URLStreamHandler.class.getDeclaredMethod("openConnection", URL.class, Proxy.class); openConnectionReflect.setAccessible(true); @@ -97,8 +97,8 @@ public final class UrlUtils { } catch (IOException | Error | RuntimeException e) { throw e; // rethrow if possible } catch (Throwable e) { - throw new Error(e); // otherwise, wrap in Error + throw new AssertionError(e); // oh dear! this isn't meant to happen } } -} +} \ No newline at end of file diff --git a/libraries/launcher/org/prismlauncher/utils/url/NullConnection.java b/libraries/launcher/org/prismlauncher/utils/url/NullConnection.java deleted file mode 100644 index 628488e8d..000000000 --- a/libraries/launcher/org/prismlauncher/utils/url/NullConnection.java +++ /dev/null @@ -1,66 +0,0 @@ -// 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.url; - -import java.io.IOException; -import java.net.HttpURLConnection; - -/** - * Spoof 404 response from server to avoid unnecessary requests. - */ -public final class NullConnection extends HttpURLConnection { - - public static final NullConnection INSTANCE = new NullConnection(); - - public NullConnection() { - super(null); - } - - @Override - public void connect() throws IOException { - responseCode = 404; - } - - @Override - public void disconnect() { - } - - @Override - public boolean usingProxy() { - return false; - } - -}