Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,10 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
// Elyby settings
m_settings->registerSetting("UseElySkins", 2);

// Injectors
m_settings->registerSetting("InjectorUid", "moe.yushi.authlibinjector");
m_settings->registerSetting("InjectorVersion", "");

// Legacy settings
m_settings->registerSetting("OnlineFixes", false);

Expand Down
9 changes: 5 additions & 4 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,8 @@ set(MINECRAFT_SOURCES

minecraft/launch/ApplyLibraryOverride.cpp
minecraft/launch/ApplyLibraryOverride.h
minecraft/launch/ApplyAuthlibInjector.cpp
minecraft/launch/ApplyAuthlibInjector.h
minecraft/launch/ApplyElyPatch.cpp
minecraft/launch/ApplyElyPatch.h
minecraft/launch/ApplyAuthPatch.cpp
minecraft/launch/ApplyAuthPatch.h
minecraft/launch/ClaimAccount.cpp
minecraft/launch/ClaimAccount.h
minecraft/launch/CreateGameFolders.cpp
Expand Down Expand Up @@ -872,6 +870,9 @@ SET(LAUNCHER_SOURCES
logs/AnonymizeLog.cpp
logs/AnonymizeLog.h

KnownJavaAgents.cpp
KnownJavaAgents.h

# GUI - windows
ui/GuiUtil.h
ui/GuiUtil.cpp
Expand Down
66 changes: 66 additions & 0 deletions launcher/KnownJavaAgents.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Freesm Launcher - Minecraft Launcher
* Copyright (C) 2026 so5iso4ka <so5iso4ka@icloud.com>
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <algorithm>

#include "KnownJavaAgents.h"

namespace {
const std::vector<Injectors::KnownJavaAgent>& javaAgents()
{
static const std::vector javaAgents{
Injectors::KnownJavaAgent{ .uid = "moe.yushi.authlibinjector", .prefix = "moe.yushi:authlibinjector", .name = "authlib-injector" },
Injectors::KnownJavaAgent{ .uid = "org.unmojang.loki", .prefix = "org.unmojang:Loki", .name = "Loki" }
};
return javaAgents;
}

template <typename Proj>
const Injectors::KnownJavaAgent* findBy(Proj proj, const QString& value)
{
auto& agents = javaAgents();
auto it = std::ranges::find(agents, value, proj);
if (it != agents.end()) {
return &*it;
}

return nullptr;
}
} // namespace

namespace Injectors {
const std::vector<KnownJavaAgent>& getJavaAgents()
{
return javaAgents();
}

const KnownJavaAgent* findByUid(const QString& uid)
{
return findBy(&KnownJavaAgent::uid, uid);
}

const KnownJavaAgent* findByPrefix(const QString& prefix)
{
return findBy(&KnownJavaAgent::prefix, prefix);
}

const KnownJavaAgent& fallback()
{
return javaAgents().front();
}
} // namespace Injectors
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

#pragma once

#include "ApplyLibraryOverride.h"
#include <QString>
#include <vector>

class ApplyAuthlibInjector : public ApplyLibraryOverride {
Q_OBJECT
public:
explicit ApplyAuthlibInjector(LaunchTask* parent, RuntimeContext& ctx, Net::Mode netMode);
~ApplyAuthlibInjector() override;

protected:
void executeTask() override;

protected slots:
void onMetaRequestDone(const Meta::VersionList::Ptr& versionList) override;
namespace Injectors {
struct KnownJavaAgent {
QString uid;
QString prefix;
QString name;
};

const std::vector<KnownJavaAgent>& getJavaAgents();
const KnownJavaAgent* findByUid(const QString& uid);
const KnownJavaAgent* findByPrefix(const QString& prefix);
const KnownJavaAgent& fallback();
} // namespace Injectors
16 changes: 10 additions & 6 deletions launcher/minecraft/MinecraftInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "Application.h"
#include "BuildConfig.h"
#include "Json.h"
#include "KnownJavaAgents.h"
#include "QObjectPtr.h"
#include "settings/Setting.h"
#include "settings/SettingsObject.h"
Expand All @@ -47,7 +48,6 @@
#include "MMCTime.h"
#include "java/JavaVersion.h"

#include "launch/ApplyAuthlibInjector.h"
#include "launch/LaunchTask.h"
#include "launch/SetDiscordActivity.h"
#include "launch/TaskStepWrapper.h"
Expand All @@ -58,8 +58,7 @@
#include "launch/steps/QuitAfterGameStop.h"
#include "launch/steps/TextPrint.h"

#include "minecraft/launch/ApplyAuthlibInjector.h"
#include "minecraft/launch/ApplyElyPatch.h"
#include "minecraft/launch/ApplyAuthPatch.h"
#include "minecraft/launch/AutoInstallJava.h"
#include "minecraft/launch/ClaimAccount.h"
#include "minecraft/launch/CreateGameFolders.h"
Expand Down Expand Up @@ -244,6 +243,11 @@ void MinecraftInstance::loadSpecificSettings()
auto elybyOverride = m_settings->registerSetting("OverrideElyby", false);
m_settings->registerOverride(global_settings->getSetting("UseElySkins"), elybyOverride);

// Injectors
auto injectorsOverride = m_settings->registerSetting("OverrideInjectors", false);
m_settings->registerOverride(global_settings->getSetting("InjectorUid"), injectorsOverride);
m_settings->registerOverride(global_settings->getSetting("InjectorVersion"), injectorsOverride);

// Legacy-related options
auto legacySettings = m_settings->registerSetting("OverrideLegacySettings", false);
m_settings->registerOverride(global_settings->getSetting("OnlineFixes"), legacySettings);
Expand Down Expand Up @@ -549,7 +553,7 @@ QStringList MinecraftInstance::extraArguments(AuthSessionPtr session)
QStringList jar, temp1, temp2, temp3;
agent.library->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
QString arg = agent.argument;
if (session && agent.library->artifactPrefix() == "moe.yushi:authlibinjector") {
if (session && Injectors::findByPrefix(agent.library->artifactPrefix()) != nullptr) {
arg = replaceTokensIn(arg, { { "authlib_injector_auth_url", session->authlib_injector_auth_url } });
}
list.append("-javaagent:" + jar[0] + (agent.argument.isEmpty() ? "" : "=" + arg));
Expand Down Expand Up @@ -1207,9 +1211,9 @@ LaunchTask* MinecraftInstance::createLaunchTask(AuthSessionPtr session, Minecraf
}

if (session->wants_ely_patch) {
process->appendStep(makeShared<ApplyElyPatch>(pptr, m_runtimeContext, mode));
process->appendStep(makeShared<ApplyAuthPatch>(pptr, m_runtimeContext, mode, ApplyAuthPatch::Stage::Ely));
} else if (session->wants_authlib_injector) {
process->appendStep(makeShared<ApplyAuthlibInjector>(pptr, m_runtimeContext, mode));
process->appendStep(makeShared<ApplyAuthPatch>(pptr, m_runtimeContext, mode, ApplyAuthPatch::Stage::Injector));
}

// if we aren't in offline mode
Expand Down
165 changes: 165 additions & 0 deletions launcher/minecraft/launch/ApplyAuthPatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Freesm Launcher - Minecraft Launcher
* Copyright (C) 2026 so5iso4ka <so5iso4ka@icloud.com>
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <algorithm>

#include "ApplyAuthPatch.h"

#include "KnownJavaAgents.h"
#include "launch/LaunchTask.h"
#include "minecraft/PackProfile.h"

ApplyAuthPatch::ApplyAuthPatch(LaunchTask* parent, RuntimeContext& ctx, Net::Mode netMode, Stage stage)
: ApplyLibraryOverride(parent, ctx, netMode), m_stage(stage)
{}

ApplyAuthPatch::~ApplyAuthPatch() = default;

void ApplyAuthPatch::executeTask()
{
emit logLine("", MessageLevel::Launcher);
switch (m_stage) {
case Stage::Ely: {
executeEly();
break;
}
case Stage::Injector: {
executeInjector();
break;
}
}
}

void ApplyAuthPatch::onMetaRequestDone(const Meta::VersionList::Ptr& versionList)
{
switch (m_stage) {
case Stage::Ely: {
auto libraries = m_instance->getPackProfile()->getProfile()->getLibraries();

auto authlibIt =
std::ranges::find_if(libraries, [](const LibraryPtr& p) { return p && p->artifactPrefix() == "com.mojang:authlib"; });
if (authlibIt == libraries.end()) {
emit logLine(tr("Could not apply ely patch: authlib not found; falling back to injector"), MessageLevel::Warning);
m_stage = Stage::Injector;
return executeInjector();
}

auto authlibVersion = (*authlibIt)->version();

auto patchedVersions = versionList->versions();

auto patchedAuthlibIt = std::ranges::find_if(
patchedVersions, [authlibVersion](const Meta::Version::Ptr& p) { return p->version() == authlibVersion; });
if (patchedAuthlibIt == patchedVersions.end()) {
emit logLine(tr("Could not apply ely patch: no suitable patched authlib found; falling back to injector"),
MessageLevel::Warning);
m_stage = Stage::Injector;
return executeInjector();
}

startApplyTask(*patchedAuthlibIt);
break;
}
case Stage::Injector: {
auto versions = versionList->versions();
Meta::Version::Ptr recommended;
Meta::Version::Ptr preferred;

std::ranges::for_each(versions, [this, &recommended, &preferred](const auto& version) {
if (!version) {
return;
}
if (!recommended && version->isRecommended()) {
recommended = version;
}
if (m_decidedInjectorVersion.has_value() && version->descriptor() == *m_decidedInjectorVersion) {
preferred = version;
}
});

auto decided = Injectors::findByUid(m_decidedInjectorUid);

if (!recommended && !preferred) {
if (m_decidedInjectorUid == Injectors::fallback().uid) {
emit logLine(tr("No suitable injector version could be found"), MessageLevel::Error);
emitFailed("No suitable injector version could be found");
return;
}

emit logLine(tr("No suitable %1 version could be found; falling back to %2")
.arg(decided ? decided->name : m_decidedInjectorUid, Injectors::fallback().name),
MessageLevel::Warning);
m_decidedInjectorUid = Injectors::fallback().uid;
m_decidedInjectorVersion.reset();

return startMetaTask(m_decidedInjectorUid);
}

if (!preferred && m_decidedInjectorVersion.has_value()) {
emit logLine(tr("No %1 %2 found; falling back to %3")
.arg(decided ? decided->name : m_decidedInjectorUid, *m_decidedInjectorVersion, recommended->descriptor()),
MessageLevel::Warning);
}

startApplyTask(preferred != nullptr ? preferred : recommended);
break;
}
}
}
void ApplyAuthPatch::apply(const Meta::Version::Ptr& version)
{
switch (m_stage) {
case Stage::Ely: {
QList<LibraryPtr>& libraries = m_instance->getPackProfile()->getProfile()->libraries();
auto it = std::ranges::find_if(libraries, [](const LibraryPtr& p) { return p && p->artifactPrefix() == "com.mojang:authlib"; });
if (it != libraries.end()) {
libraries.erase(it);
}
emit logLine(tr("Using ely patch version %1").arg(version->descriptor()), MessageLevel::Launcher);
ApplyLibraryOverride::apply(version);
break;
}
case Stage::Injector: {
emit logLine(tr("Using %1 %2").arg(version->name(), version->descriptor()), MessageLevel::Launcher);
ApplyLibraryOverride::apply(version);
break;
}
}
}

void ApplyAuthPatch::executeEly()
{
startMetaTask("by.ely.authlib");
}

void ApplyAuthPatch::executeInjector()
{
auto preferred = m_parent->instance()->settings()->get("InjectorUid").toString();
auto preferredVersion = m_parent->instance()->settings()->get("InjectorVersion").toString();

if (Injectors::findByUid(preferred) == nullptr) {
m_decidedInjectorUid = Injectors::fallback().uid;
} else {
m_decidedInjectorUid = preferred;
if (!preferredVersion.isEmpty()) {
m_decidedInjectorVersion = preferredVersion;
}
}

startMetaTask(m_decidedInjectorUid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

#pragma once

#include "minecraft/launch/ApplyLibraryOverride.h"
#include <QString>
#include <optional>

class ApplyElyPatch : public ApplyLibraryOverride {
#include "ApplyLibraryOverride.h"

class ApplyAuthPatch : public ApplyLibraryOverride {
Q_OBJECT
public:
explicit ApplyElyPatch(LaunchTask* parent, RuntimeContext& ctx, Net::Mode netMode);
~ApplyElyPatch() override;
enum class Stage { Ely, Injector };

explicit ApplyAuthPatch(LaunchTask* parent, RuntimeContext& ctx, Net::Mode netMode, Stage stage);
~ApplyAuthPatch() override;

protected:
void executeTask() override;
Expand All @@ -33,7 +38,11 @@ class ApplyElyPatch : public ApplyLibraryOverride {
void onMetaRequestDone(const Meta::VersionList::Ptr& versionList) override;
void apply(const Meta::Version::Ptr& version) override;

private:
void applyAuthlibInjector();
bool m_fallbackToAuthlibInjector = false;
private:
void executeEly();
void executeInjector();

Stage m_stage;
QString m_decidedInjectorUid;
std::optional<QString> m_decidedInjectorVersion;
};
Loading
Loading