Skin fix -> online fixes
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
94067f34cf
commit
884bd85495
@ -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";
|
||||
|
||||
|
@ -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()
|
||||
|
@ -609,12 +609,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="legacySkinFix">
|
||||
<widget class="QCheckBox" name="onlineFixes">
|
||||
<property name="toolTip">
|
||||
<string>Enables support for modern skins on old versions.</string>
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable legacy skin fix</string>
|
||||
<string>Enable online fixes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -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
|
||||
|
@ -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<String> fixes = params.getList("fixes", Collections.<String>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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,31 +33,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <code>true</code> 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);
|
||||
}
|
||||
|
||||
}
|
@ -33,15 +33,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
@ -1,56 +1,17 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, Object> textures = getTextures(owner);
|
||||
|
||||
if (textures != null) {
|
Loading…
Reference in New Issue
Block a user