From caec4ef96c7df8b1d7216cf12be76f213ca34ac2 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 25 Jan 2026 17:04:47 +0500 Subject: [PATCH] feat: allow overriding URL for downloading legacy FML libs Signed-off-by: Octol1ttle --- launcher/Application.cpp | 23 +++++----- .../update/LegacyFMLLibrariesTask.cpp | 12 ++++- .../minecraft/update/LegacyFMLLibrariesTask.h | 3 ++ launcher/ui/pages/global/APIPage.cpp | 44 ++++++++++--------- launcher/ui/pages/global/APIPage.ui | 28 ++++++++++++ 5 files changed, 76 insertions(+), 34 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 7bed94c07..cf0d1e000 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -862,23 +862,20 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } } { + auto resetIfInvalid = [this](const Setting* setting) { + if (const QUrl url(setting->get().toString()); !url.isValid() || (url.scheme() != "http" && url.scheme() != "https")) { + m_settings->reset(setting->id()); + } + }; + // Meta URL - m_settings->registerSetting("MetaURLOverride", ""); - - QUrl metaUrl(m_settings->get("MetaURLOverride").toString()); - - // get rid of invalid meta urls - if (!metaUrl.isValid() || (metaUrl.scheme() != "http" && metaUrl.scheme() != "https")) - m_settings->reset("MetaURLOverride"); + resetIfInvalid(m_settings->registerSetting("MetaURLOverride", "").get()); // Resource URL - m_settings->registerSetting({ "ResourceURLOverride", "ResourceURL" }, ""); + resetIfInvalid(m_settings->registerSetting({ "ResourceURLOverride", "ResourceURL" }, "").get()); - QUrl resourceUrl(m_settings->get("ResourceURLOverride").toString()); - - // get rid of invalid resource urls - if (!resourceUrl.isValid() || (resourceUrl.scheme() != "http" && resourceUrl.scheme() != "https")) - m_settings->reset("ResourceURLOverride"); + // Legacy FML libs URL + resetIfInvalid(m_settings->registerSetting("LegacyFMLLibsURLOverride", "").get()); } m_settings->registerSetting("CloseAfterLaunch", false); diff --git a/launcher/minecraft/update/LegacyFMLLibrariesTask.cpp b/launcher/minecraft/update/LegacyFMLLibrariesTask.cpp index 12f8f89c4..bd817a572 100644 --- a/launcher/minecraft/update/LegacyFMLLibrariesTask.cpp +++ b/launcher/minecraft/update/LegacyFMLLibrariesTask.cpp @@ -61,9 +61,10 @@ void LegacyFMLLibrariesTask::executeTask() NetJob::Ptr dljob{ new NetJob("FML libraries", APPLICATION->network()) }; auto metacache = APPLICATION->metacache(); Net::Download::Options options = Net::Download::Option::MakeEternal; + const QString base = baseUrl(); for (auto& lib : fmlLibsToProcess) { auto entry = metacache->resolveEntry("fmllibs", lib.filename); - QString urlString = BuildConfig.LEGACY_FMLLIBS_BASE_URL + lib.filename; + QString urlString = base + lib.filename; dljob->addNetAction(Net::ApiDownload::makeCached(QUrl(urlString), entry, options)); } @@ -123,3 +124,12 @@ bool LegacyFMLLibrariesTask::abort() } return true; } + +QString LegacyFMLLibrariesTask::baseUrl() +{ + if (const QString urlOverride = APPLICATION->settings()->get("LegacyFMLLibsURLOverride").toString(); !urlOverride.isEmpty()) { + return urlOverride; + } + + return BuildConfig.LEGACY_FMLLIBS_BASE_URL; +} diff --git a/launcher/minecraft/update/LegacyFMLLibrariesTask.h b/launcher/minecraft/update/LegacyFMLLibrariesTask.h index 8aa416d72..2591f7c9f 100644 --- a/launcher/minecraft/update/LegacyFMLLibrariesTask.h +++ b/launcher/minecraft/update/LegacyFMLLibrariesTask.h @@ -22,6 +22,9 @@ class LegacyFMLLibrariesTask : public Task { public slots: bool abort() override; + private: + static QString baseUrl(); + private: MinecraftInstance* m_inst; NetJob::Ptr downloadJob; diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index adc779daf..0cfe0c3b0 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -77,10 +77,12 @@ APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage) ui->metaURL->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->metaURL)); ui->resourceURL->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->resourceURL)); ui->baseURLEntry->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->baseURLEntry)); + ui->legacyFMLLibsURL->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->legacyFMLLibsURL)); ui->msaClientID->setValidator(new QRegularExpressionValidator(s_validMSAClientID, ui->msaClientID)); ui->metaURL->setPlaceholderText(BuildConfig.META_URL); ui->resourceURL->setPlaceholderText(BuildConfig.DEFAULT_RESOURCE_BASE); + ui->legacyFMLLibsURL->setPlaceholderText(BuildConfig.LEGACY_FMLLIBS_BASE_URL); ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT); loadSettings(); @@ -139,6 +141,8 @@ void APIPage::loadSettings() ui->metaURL->setText(metaURL); QString resourceURL = s->get("ResourceURLOverride").toString(); ui->resourceURL->setText(resourceURL); + QString fmlLibsURL = s->get("LegacyFMLLibsURLOverride").toString(); + ui->legacyFMLLibsURL->setText(fmlLibsURL); QString flameKey = s->get("FlameKeyOverride").toString(); ui->flameKey->setText(flameKey); QString modrinthToken = s->get("ModrinthToken").toString(); @@ -159,34 +163,34 @@ void APIPage::applySettings() s->set("MSAClientIDOverride", msaClientID); QUrl metaURL(ui->metaURL->text()); QUrl resourceURL(ui->resourceURL->text()); - // Add required trailing slash - if (!metaURL.isEmpty() && !metaURL.path().endsWith('/')) { - QString path = metaURL.path(); - path.append('/'); - metaURL.setPath(path); - } + QUrl fmlLibsURL(ui->legacyFMLLibsURL->text()); - if (!resourceURL.isEmpty() && !resourceURL.path().endsWith('/')) { - QString path = resourceURL.path(); - path.append('/'); - resourceURL.setPath(path); - } + auto addRequiredTrailingSlash = [](QUrl& url) { + if (!url.isEmpty() && !url.path().endsWith('/')) { + QString path = url.path(); + path.append('/'); + url.setPath(path); + } + }; + addRequiredTrailingSlash(metaURL); + addRequiredTrailingSlash(resourceURL); + addRequiredTrailingSlash(fmlLibsURL); auto isLocalhost = [](const QUrl& url) { return url.host() == "localhost" || url.host() == "127.0.0.1" || url.host() == "::1"; }; auto isUnsafe = [isLocalhost](const QUrl& url) { return !url.isEmpty() && url.scheme() == "http" && !isLocalhost(url); }; + auto upgradeToHTTPS = [isUnsafe](QUrl& url) { + if (isUnsafe(url)) { + url.setScheme("https"); + } + }; - // Don't allow HTTP, since meta is basically RCE with all the jar files. - if (isUnsafe(metaURL)) { - metaURL.setScheme("https"); - } - - // Also don't allow HTTP - if (isUnsafe(resourceURL)) { - resourceURL.setScheme("https"); - } + upgradeToHTTPS(metaURL); + upgradeToHTTPS(resourceURL); + upgradeToHTTPS(fmlLibsURL); s->set("MetaURLOverride", metaURL.toString()); s->set("ResourceURLOverride", resourceURL.toString()); + s->set("LegacyFMLLibsURLOverride", fmlLibsURL.toString()); QString flameKey = ui->flameKey->text(); s->set("FlameKeyOverride", flameKey); QString modrinthToken = ui->modrinthToken->text(); diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 834eebb96..5b46cd6d7 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -161,6 +161,34 @@ + + + + Legacy FML Libraries Server + + + + + + You can set this to another server if you have problems with downloading legacy FML libraries (Minecraft 1.5.2 and earlier). + + + Qt::RichText + + + true + + + true + + + + + + + + +