From 884bd8549537cb67a9e59c83ab4ca761491ff27b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 23 Dec 2022 09:35:29 +0000 Subject: [PATCH] Skin fix -> online fixes Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 8 +-- .../pages/instance/InstanceSettingsPage.cpp | 8 +-- .../ui/pages/instance/InstanceSettingsPage.ui | 6 +- libraries/launcher/CMakeLists.txt | 6 +- .../launcher/org/prismlauncher/fix/Fixes.java | 21 +------ .../fix/{Fix.java => online/Handler.java} | 38 ++++++------ .../SkinFix.java => online/OnlineFixes.java} | 26 ++------- .../Handler.java => online/SkinFix.java} | 58 ++----------------- 8 files changed, 44 insertions(+), 127 deletions(-) rename libraries/launcher/org/prismlauncher/fix/{Fix.java => online/Handler.java} (73%) rename libraries/launcher/org/prismlauncher/fix/{skins/SkinFix.java => online/OnlineFixes.java} (82%) rename libraries/launcher/org/prismlauncher/fix/{skins/Handler.java => online/SkinFix.java} (56%) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 378af0e10..ec916f26f 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("OnlineFixes", true); qDebug() << "Instance-type specific settings were loaded!"; @@ -440,7 +440,7 @@ QStringList MinecraftInstance::javaArguments() args << "-Duser.language=en"; - if (javaVersion.isModular() && traits().contains("legacySkins") && settings()->get("LegacySkinFix").toBool()) + if (javaVersion.isModular() && traits().contains("legacyServices") && settings()->get("OnlineFixes").toBool()) // allow reflective access to java.net - required by the skin fix args << "--add-opens" << "java.base/java.net=ALL-UNNAMED"; @@ -665,8 +665,8 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS launchScript += "traits " + trait + "\n"; } - if (profile->getTraits().contains("legacySkins") && settings()->get("LegacySkinFix").toBool()) - launchScript += "fixes legacySkinFix\n"; + if (profile->getTraits().contains("legacyServices") && settings()->get("OnlineFixes").toBool()) + launchScript += "onlineFixes true\n"; launchScript += "launcher " + getLauncher() + "\n"; diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 537271a2c..23299b1dc 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -276,8 +276,8 @@ void InstanceSettingsPage::applySettings() m_settings->reset("JoinServerOnLaunchAddress"); } - bool legacySkinFix = ui->legacySkinFix->isChecked(); - m_settings->set("LegacySkinFix", legacySkinFix); + bool onlineFixes = ui->onlineFixes->isChecked(); + m_settings->set("OnlineFixes", onlineFixes); // FIXME: This should probably be called by a signal instead m_instance->updateRuntimeContext(); @@ -377,8 +377,8 @@ void InstanceSettingsPage::loadSettings() ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool()); ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString()); - ui->legacySkinFix->setChecked(m_settings->get("LegacySkinFix").toBool()); - ui->legacySkinFix->setVisible(m_instance->traits().contains("legacySkins")); + ui->onlineFixes->setChecked(m_settings->get("OnlineFixes").toBool()); + ui->onlineFixes->setVisible(m_instance->traits().contains("legacyServices")); } void InstanceSettingsPage::on_javaDetectBtn_clicked() diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index ca49cbbe5..7b42b8397 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -609,12 +609,12 @@ - + - Enables support for modern skins on old versions. + <html><head/><body><p>Fixes usages of old online services which are no longer operating by emulating them or redirecting to their modern counterparts.</p><p>This currently only allows modern skins to be used.</p></body></html> - Enable legacy skin fix + Enable online fixes diff --git a/libraries/launcher/CMakeLists.txt b/libraries/launcher/CMakeLists.txt index acc276218..71996ae33 100644 --- a/libraries/launcher/CMakeLists.txt +++ b/libraries/launcher/CMakeLists.txt @@ -15,10 +15,10 @@ set(SRC org/prismlauncher/launcher/impl/legacy/LegacyFrame.java org/prismlauncher/exception/ParameterNotFoundException.java org/prismlauncher/exception/ParseException.java - org/prismlauncher/fix/Fix.java org/prismlauncher/fix/Fixes.java - org/prismlauncher/fix/skins/SkinFix.java - org/prismlauncher/fix/skins/Handler.java + org/prismlauncher/fix/online/OnlineFixes.java + org/prismlauncher/fix/online/SkinFix.java + org/prismlauncher/fix/online/Handler.java org/prismlauncher/utils/Base64.java org/prismlauncher/utils/JsonParser.java org/prismlauncher/utils/Parameters.java diff --git a/libraries/launcher/org/prismlauncher/fix/Fixes.java b/libraries/launcher/org/prismlauncher/fix/Fixes.java index e85bcfd42..429964ad9 100644 --- a/libraries/launcher/org/prismlauncher/fix/Fixes.java +++ b/libraries/launcher/org/prismlauncher/fix/Fixes.java @@ -35,29 +35,14 @@ package org.prismlauncher.fix; -import java.util.Collections; -import java.util.List; - -import org.prismlauncher.fix.skins.SkinFix; +import org.prismlauncher.fix.online.OnlineFixes; import org.prismlauncher.utils.Parameters; -import org.prismlauncher.utils.logging.Log; public final class Fixes { - private static final Fix[] FIXES = { new SkinFix() }; - public static void apply(Parameters params) { - List fixes = params.getList("fixes", Collections.emptyList()); - - for (Fix fix : FIXES) { - if (fixes.contains(fix.getName()) && fix.isApplicable(params)) { - try { - fix.apply(); - } catch (Throwable e) { - Log.error("Could not apply " + fix.getName(), e); - } - } - } + if ("true".equalsIgnoreCase(params.getString("onlineFixes", null))) + OnlineFixes.apply(); } } diff --git a/libraries/launcher/org/prismlauncher/fix/Fix.java b/libraries/launcher/org/prismlauncher/fix/online/Handler.java similarity index 73% rename from libraries/launcher/org/prismlauncher/fix/Fix.java rename to libraries/launcher/org/prismlauncher/fix/online/Handler.java index 3ecd2e90a..b5b4de28e 100644 --- a/libraries/launcher/org/prismlauncher/fix/Fix.java +++ b/libraries/launcher/org/prismlauncher/fix/online/Handler.java @@ -33,31 +33,27 @@ * along with this program. If not, see . */ -package org.prismlauncher.fix; +package org.prismlauncher.fix.online; -import org.prismlauncher.utils.Parameters; +import java.io.IOException; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; -public interface Fix { +import org.prismlauncher.utils.UrlUtils; - /** - * Gets the name of the fix. If the name isn't passed into the program, the fix - * won't run. - * - * @return The name - */ - String getName(); +final class Handler extends URLStreamHandler { - /** - * Determines whether the fix will be run. This is additional to the name check. - * - * @param params The parameters - * @return true to proceed to applying the fix - */ - boolean isApplicable(Parameters params); + @Override + protected URLConnection openConnection(URL address) throws IOException { + return openConnection(address, null); + } - /** - * Applies the fix. - */ - void apply(); + @Override + protected URLConnection openConnection(URL address, Proxy proxy) throws IOException { + address = SkinFix.redirect(address); + return UrlUtils.openHttpConnection(address, proxy); + } } diff --git a/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java b/libraries/launcher/org/prismlauncher/fix/online/OnlineFixes.java similarity index 82% rename from libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java rename to libraries/launcher/org/prismlauncher/fix/online/OnlineFixes.java index 3dd747376..c344a8e73 100644 --- a/libraries/launcher/org/prismlauncher/fix/skins/SkinFix.java +++ b/libraries/launcher/org/prismlauncher/fix/online/OnlineFixes.java @@ -33,15 +33,13 @@ * along with this program. If not, see . */ -package org.prismlauncher.fix.skins; +package org.prismlauncher.fix.online; import java.net.URL; import java.net.URLStreamHandler; 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; @@ -51,31 +49,19 @@ import org.prismlauncher.utils.logging.Log; * @see {@link Handler} * @see {@link UrlUtils} */ -public final class SkinFix implements Fix, URLStreamHandlerFactory { +public final class OnlineFixes implements URLStreamHandlerFactory { - @Override - public String getName() { - return "legacySkinFix"; - } - - @Override - public boolean isApplicable(Parameters params) { + public static void apply() { if (!UrlUtils.isSupported() || !Base64.isSupported()) { Log.warning("Cannot access the necessary Java internals for skin fix"); Log.warning("Turning off legacy skin fix in Settings > Miscellaneous will silence the warnings"); - return false; + return; } - return true; - } - - @Override - public void apply() { try { - URL.setURLStreamHandlerFactory(this); + URL.setURLStreamHandlerFactory(new OnlineFixes()); } catch (Error e) { - Log.warning("Cannot apply skin fix"); - Log.warning("URLStreamHandlerFactory is already set"); + Log.warning("Cannot apply skin fix: URLStreamHandlerFactory is already set"); Log.warning("Turning off legacy skin fix in Settings > Miscellaneous will silence the warnings"); } } diff --git a/libraries/launcher/org/prismlauncher/fix/skins/Handler.java b/libraries/launcher/org/prismlauncher/fix/online/SkinFix.java similarity index 56% rename from libraries/launcher/org/prismlauncher/fix/skins/Handler.java rename to libraries/launcher/org/prismlauncher/fix/online/SkinFix.java index fa306ed44..f1e480776 100644 --- a/libraries/launcher/org/prismlauncher/fix/skins/Handler.java +++ b/libraries/launcher/org/prismlauncher/fix/online/SkinFix.java @@ -1,56 +1,17 @@ -// 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.fix.skins; +package org.prismlauncher.fix.online; import java.io.IOException; import java.io.InputStream; -import java.net.Proxy; import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; import java.util.Map; import org.prismlauncher.utils.Base64; import org.prismlauncher.utils.JsonParser; -import org.prismlauncher.utils.UrlUtils; @SuppressWarnings("unchecked") -final class Handler extends URLStreamHandler { +final class SkinFix { - private URL redirect(URL address) throws IOException { + static URL redirect(URL address) throws IOException { String skinOwner = findSkinOwner(address); if (skinOwner != null) return convert(skinOwner, "SKIN"); @@ -62,18 +23,7 @@ final class Handler extends URLStreamHandler { return address; } - @Override - protected URLConnection openConnection(URL address) throws IOException { - return openConnection(address, null); - } - - @Override - protected URLConnection openConnection(URL address, Proxy proxy) throws IOException { - address = redirect(address); - return UrlUtils.openHttpConnection(address, proxy); - } - - private URL convert(String owner, String name) throws IOException { + private static URL convert(String owner, String name) throws IOException { Map textures = getTextures(owner); if (textures != null) {