diff options
Diffstat (limited to 'launcher/minecraft/MinecraftInstance.cpp')
-rw-r--r-- | launcher/minecraft/MinecraftInstance.cpp | 402 |
1 files changed, 144 insertions, 258 deletions
diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index f8ed5214..305bff67 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -4,6 +4,7 @@ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me> + * Copyright (c) 2023 seth <getchoo at tuta dot io> * * 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 @@ -36,33 +37,32 @@ */ #include "MinecraftInstance.h" +#include "Application.h" #include "BuildConfig.h" #include "minecraft/launch/CreateGameFolders.h" #include "minecraft/launch/ExtractNatives.h" #include "minecraft/launch/PrintInstanceInfo.h" #include "settings/Setting.h" #include "settings/SettingsObject.h" -#include "Application.h" -#include "pathmatcher/RegexpMatcher.h" -#include "pathmatcher/MultiMatcher.h" #include "FileSystem.h" -#include "java/JavaVersion.h" #include "MMCTime.h" +#include "java/JavaVersion.h" +#include "pathmatcher/MultiMatcher.h" +#include "pathmatcher/RegexpMatcher.h" #include "launch/LaunchTask.h" +#include "launch/steps/CheckJava.h" #include "launch/steps/LookupServerAddress.h" #include "launch/steps/PostLaunchCommand.h" -#include "launch/steps/Update.h" #include "launch/steps/PreLaunchCommand.h" -#include "launch/steps/TextPrint.h" -#include "launch/steps/CheckJava.h" #include "launch/steps/QuitAfterGameStop.h" +#include "launch/steps/TextPrint.h" +#include "launch/steps/Update.h" +#include "minecraft/launch/ClaimAccount.h" #include "minecraft/launch/LauncherPartLaunch.h" -#include "minecraft/launch/DirectJavaLaunch.h" #include "minecraft/launch/ModMinecraftJar.h" -#include "minecraft/launch/ClaimAccount.h" #include "minecraft/launch/ReconstructAssets.h" #include "minecraft/launch/ScanModFolders.h" #include "minecraft/launch/VerifyJavaInstall.h" @@ -81,10 +81,10 @@ #include "WorldList.h" -#include "PackProfile.h" #include "AssetsUtils.h" -#include "MinecraftUpdate.h" #include "MinecraftLoadAndCheck.h" +#include "MinecraftUpdate.h" +#include "PackProfile.h" #include "minecraft/gameoptions/GameOptions.h" #include "minecraft/update/FoldersTask.h" @@ -96,14 +96,10 @@ // all of this because keeping things compatible with deprecated old settings // if either of the settings {a, b} is true, this also resolves to true -class OrSetting : public Setting -{ +class OrSetting : public Setting { Q_OBJECT -public: - OrSetting(QString id, std::shared_ptr<Setting> a, std::shared_ptr<Setting> b) - :Setting({id}, false), m_a(a), m_b(b) - { - } + public: + OrSetting(QString id, std::shared_ptr<Setting> a, std::shared_ptr<Setting> b) : Setting({ id }, false), m_a(a), m_b(b) {} virtual QVariant get() const { bool a = m_a->get().toBool(); @@ -112,12 +108,13 @@ public: } virtual void reset() {} virtual void set(QVariant value) {} -private: + + private: std::shared_ptr<Setting> m_a; std::shared_ptr<Setting> m_b; }; -MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) +MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir) : BaseInstance(globalSettings, settings, rootDir) { m_components.reset(new PackProfile(this)); @@ -148,7 +145,7 @@ void MinecraftInstance::loadSpecificSettings() m_settings->registerOverride(global_settings->getSetting("IgnoreJavaCompatibility"), javaOrLocation); // special! - m_settings->registerPassthrough(global_settings->getSetting("JavaTimestamp"), javaOrLocation); + m_settings->registerPassthrough(global_settings->getSetting("JavaSignature"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaArchitecture"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaRealArchitecture"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaVersion"), javaOrLocation); @@ -166,10 +163,6 @@ void MinecraftInstance::loadSpecificSettings() m_settings->registerOverride(global_settings->getSetting("MaxMemAlloc"), memorySetting); m_settings->registerOverride(global_settings->getSetting("PermGen"), memorySetting); - // Minecraft launch method - auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false); - m_settings->registerOverride(global_settings->getSetting("MCLaunchMethod"), launchMethodOverride); - // Native library workarounds auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false); m_settings->registerOverride(global_settings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride); @@ -186,6 +179,10 @@ void MinecraftInstance::loadSpecificSettings() m_settings->registerOverride(global_settings->getSetting("CloseAfterLaunch"), miscellaneousOverride); m_settings->registerOverride(global_settings->getSetting("QuitAfterGameStop"), miscellaneousOverride); + // Mod loader specific options + auto modLoaderSettings = m_settings->registerSetting("OverrideModLoaderSettings", false); + m_settings->registerOverride(global_settings->getSetting("DisableQuiltBeacon"), modLoaderSettings); + m_settings->set("InstanceType", "OneSix"); } @@ -222,14 +219,12 @@ std::shared_ptr<PackProfile> MinecraftInstance::getPackProfile() const QSet<QString> MinecraftInstance::traits() const { auto components = getPackProfile(); - if (!components) - { - return {"version-incomplete"}; + if (!components) { + return { "version-incomplete" }; } auto profile = components->getProfile(); - if (!profile) - { - return {"version-incomplete"}; + if (!profile) { + return { "version-incomplete" }; } return profile->getTraits(); } @@ -264,7 +259,7 @@ QString MinecraftInstance::getLocalLibraryPath() const bool MinecraftInstance::supportsDemo() const { - Version instance_ver { getPackProfile()->getComponentVersion("net.minecraft") }; + Version instance_ver{ getPackProfile()->getComponentVersion("net.minecraft") }; // Demo mode was introduced in 1.3.1: https://minecraft.fandom.com/wiki/Demo_mode#History // FIXME: Due to Version constraints atm, this can't handle well non-release versions return instance_ver >= Version("1.3.1"); @@ -375,21 +370,24 @@ QStringList MinecraftInstance::extraArguments() if (!version) return list; auto jarMods = getJarMods(); - if (!jarMods.isEmpty()) - { - list.append({"-Dfml.ignoreInvalidMinecraftCertificates=true", - "-Dfml.ignorePatchDiscrepancies=true"}); + if (!jarMods.isEmpty()) { + list.append({ "-Dfml.ignoreInvalidMinecraftCertificates=true", "-Dfml.ignorePatchDiscrepancies=true" }); } auto addn = m_components->getProfile()->getAddnJvmArguments(); if (!addn.isEmpty()) { list.append(addn); } auto agents = m_components->getProfile()->getAgents(); - for (auto agent : agents) - { + for (auto agent : agents) { QStringList jar, temp1, temp2, temp3; agent->library()->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath()); - list.append("-javaagent:"+jar[0]+(agent->argument().isEmpty() ? "" : "="+agent->argument())); + list.append("-javaagent:" + jar[0] + (agent->argument().isEmpty() ? "" : "=" + agent->argument())); + } + + { + const auto loaders = version->getModLoaders(); + if (loaders.has_value() && loaders.value() & ResourceAPI::Quilt && settings()->get("DisableQuiltBeacon").toBool()) + list.append("-Dloader.disable_beacon=true"); } return list; } @@ -410,38 +408,33 @@ QStringList MinecraftInstance::javaArguments() // HACK: fix issues on macOS with 1.13 snapshots // NOTE: Oracle Java option. if there are alternate jvm implementations, this would be the place to customize this for them #ifdef Q_OS_MAC - if(traits_.contains("FirstThreadOnMacOS")) - { + if (traits_.contains("FirstThreadOnMacOS")) { args << QString("-XstartOnFirstThread"); } #endif // HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767 #ifdef Q_OS_WIN32 - args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" - "minecraft.exe.heapdump"); + args << QString( + "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" + "minecraft.exe.heapdump"); #endif int min = settings()->get("MinMemAlloc").toInt(); int max = settings()->get("MaxMemAlloc").toInt(); - if(min < max) - { + if (min < max) { args << QString("-Xms%1m").arg(min); args << QString("-Xmx%1m").arg(max); - } - else - { + } else { args << QString("-Xms%1m").arg(max); args << QString("-Xmx%1m").arg(min); } // No PermGen in newer java. JavaVersion javaVersion = getJavaVersion(); - if(javaVersion.requiresPermGen()) - { + if (javaVersion.requiresPermGen()) { auto permgen = settings()->get("PermGen").toInt(); - if (permgen != 64) - { + if (permgen != 64) { args << QString("-XX:PermSize=%1m").arg(permgen); } } @@ -481,8 +474,7 @@ QProcessEnvironment MinecraftInstance::createEnvironment() // export some infos auto variables = getVariables(); - for (auto it = variables.begin(); it != variables.end(); ++it) - { + for (auto it = variables.begin(); it != variables.end(); ++it) { env.insert(it.key(), it.value()); } return env; @@ -494,15 +486,12 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment() QProcessEnvironment env = createEnvironment(); #ifdef Q_OS_LINUX - if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud) - { - + if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud) { auto preloadList = env.value("LD_PRELOAD").split(QLatin1String(":")); auto libPaths = env.value("LD_LIBRARY_PATH").split(QLatin1String(":")); auto mangoHudLibString = MangoHud::getLibraryString(); - if (!mangoHudLibString.isEmpty()) - { + if (!mangoHudLibString.isEmpty()) { QFileInfo mangoHudLib(mangoHudLibString); // dlsym variant is only needed for OpenGL and not included in the vulkan layer @@ -515,8 +504,7 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment() env.insert("MANGOHUD", "1"); } - if (settings()->get("UseDiscreteGpu").toBool()) - { + if (settings()->get("UseDiscreteGpu").toBool()) { // Open Source Drivers env.insert("DRI_PRIME", "1"); // Proprietary Nvidia Drivers @@ -537,14 +525,12 @@ static QString replaceTokensIn(QString text, QMap<QString, QString> with) QStringList list; QRegularExpressionMatchIterator i = token_regexp.globalMatch(text); int lastCapturedEnd = 0; - while (i.hasNext()) - { + while (i.hasNext()) { QRegularExpressionMatch match = i.next(); result.append(text.mid(lastCapturedEnd, match.capturedStart())); QString key = match.captured(1); auto iter = with.find(key); - if (iter != with.end()) - { + if (iter != with.end()) { result.append(*iter); } lastCapturedEnd = match.capturedEnd(); @@ -553,25 +539,22 @@ static QString replaceTokensIn(QString text, QMap<QString, QString> with) return result; } -QStringList MinecraftInstance::processMinecraftArgs( - AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) const +QStringList MinecraftInstance::processMinecraftArgs(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) const { auto profile = m_components->getProfile(); QString args_pattern = profile->getMinecraftArguments(); - for (auto tweaker : profile->getTweakers()) - { + for (auto tweaker : profile->getTweakers()) { args_pattern += " --tweakClass " + tweaker; } - if (serverToJoin && !serverToJoin->address.isEmpty()) - { + if (serverToJoin && !serverToJoin->address.isEmpty()) { args_pattern += " --server " + serverToJoin->address; args_pattern += " --port " + QString::number(serverToJoin->port); } QMap<QString, QString> token_mapping; // yggdrasil! - if(session) { + if (session) { // token_mapping["auth_username"] = session->username; token_mapping["auth_session"] = session->session; token_mapping["auth_access_token"] = session->access_token; @@ -579,7 +562,7 @@ QStringList MinecraftInstance::processMinecraftArgs( token_mapping["auth_uuid"] = session->uuid; token_mapping["user_properties"] = session->serializeUserProperties(); token_mapping["user_type"] = session->user_type; - if(session->demo) { + if (session->demo) { args_pattern += " --demo"; } } @@ -603,8 +586,7 @@ QStringList MinecraftInstance::processMinecraftArgs( #else QStringList parts = args_pattern.split(' ', QString::SkipEmptyParts); #endif - for (int i = 0; i < parts.length(); i++) - { + for (int i = 0; i < parts.length(); i++) { parts[i] = replaceTokensIn(parts[i], token_mapping); } return parts; @@ -617,32 +599,26 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS if (!m_components) return QString(); auto profile = m_components->getProfile(); - if(!profile) + if (!profile) return QString(); auto mainClass = getMainClass(); - if (!mainClass.isEmpty()) - { + if (!mainClass.isEmpty()) { launchScript += "mainClass " + mainClass + "\n"; } auto appletClass = profile->getAppletClass(); - if (!appletClass.isEmpty()) - { + if (!appletClass.isEmpty()) { launchScript += "appletClass " + appletClass + "\n"; } - if (serverToJoin && !serverToJoin->address.isEmpty()) - { + if (serverToJoin && !serverToJoin->address.isEmpty()) { launchScript += "serverAddress " + serverToJoin->address + "\n"; launchScript += "serverPort " + QString::number(serverToJoin->port) + "\n"; } // generic minecraft params - for (auto param : processMinecraftArgs( - session, - nullptr /* When using a launch script, the server parameters are handled by it*/ - )) - { + for (auto param : processMinecraftArgs(session, nullptr /* When using a launch script, the server parameters are handled by it*/ + )) { launchScript += "param " + param + "\n"; } @@ -652,22 +628,19 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS if (settings()->get("LaunchMaximized").toBool()) windowParams = "max"; else - windowParams = QString("%1x%2") - .arg(settings()->get("MinecraftWinWidth").toInt()) - .arg(settings()->get("MinecraftWinHeight").toInt()); + windowParams = + QString("%1x%2").arg(settings()->get("MinecraftWinWidth").toInt()).arg(settings()->get("MinecraftWinHeight").toInt()); launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "windowParams " + windowParams + "\n"; } // legacy auth - if(session) - { + if (session) { launchScript += "userName " + session->player_name + "\n"; launchScript += "sessionId " + session->session + "\n"; } - for (auto trait : profile->getTraits()) - { + for (auto trait : profile->getTraits()) { launchScript += "traits " + trait + "\n"; } @@ -680,17 +653,17 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) { QStringList out; - out << "Main Class:" << " " + getMainClass() << ""; - out << "Native path:" << " " + getNativePath() << ""; + out << "Main Class:" + << " " + getMainClass() << ""; + out << "Native path:" + << " " + getNativePath() << ""; auto profile = m_components->getProfile(); auto alltraits = traits(); - if(alltraits.size()) - { + if (alltraits.size()) { out << "Traits:"; - for (auto trait : alltraits) - { + for (auto trait : alltraits) { out << "traits " + trait; } out << ""; @@ -699,8 +672,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr auto settings = this->settings(); bool nativeOpenAL = settings->get("UseNativeOpenAL").toBool(); bool nativeGLFW = settings->get("UseNativeGLFW").toBool(); - if (nativeOpenAL || nativeGLFW) - { + if (nativeOpenAL || nativeGLFW) { if (nativeOpenAL) out << "Using system OpenAL."; if (nativeGLFW) @@ -713,34 +685,27 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr out << "Libraries:"; QStringList jars, nativeJars; profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot()); - auto printLibFile = [&](const QString & path) - { + auto printLibFile = [&](const QString& path) { QFileInfo info(path); - if(info.exists()) - { + if (info.exists()) { out << " " + path; - } - else - { + } else { out << " " + path + " (missing)"; } }; - for(auto file: jars) - { + for (auto file : jars) { printLibFile(file); } out << ""; out << "Native libraries:"; - for(auto file: nativeJars) - { + for (auto file : nativeJars) { printLibFile(file); } out << ""; } - auto printModList = [&](const QString & label, ModFolderModel & model) { - if(model.size()) - { + auto printModList = [&](const QString& label, ModFolderModel& model) { + if (model.size()) { out << QString("%1:").arg(label); auto modList = model.allMods(); std::sort(modList.begin(), modList.end(), [](auto a, auto b) { @@ -748,21 +713,17 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr auto bName = b->fileinfo().completeBaseName(); return aName.localeAwareCompare(bName) < 0; }); - for(auto mod: modList) - { - if(mod->type() == ResourceType::FOLDER) - { + for (auto mod : modList) { + if (mod->type() == ResourceType::FOLDER) { out << u8" [🖿] " + mod->fileinfo().completeBaseName() + " (folder)"; continue; } - if(mod->enabled()) { + if (mod->enabled()) { out << u8" [✔] " + mod->fileinfo().completeBaseName(); - } - else { + } else { out << u8" [✘] " + mod->fileinfo().completeBaseName() + " (disabled)"; } - } out << ""; } @@ -771,20 +732,15 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr printModList("Mods", *(loaderModList().get())); printModList("Core Mods", *(coreModList().get())); - auto & jarMods = profile->getJarMods(); - if(jarMods.size()) - { + auto& jarMods = profile->getJarMods(); + if (jarMods.size()) { out << "Jar Mods:"; - for(auto & jarmod: jarMods) - { + for (auto& jarmod : jarMods) { auto displayname = jarmod->displayName(runtimeContext()); auto realname = jarmod->filename(runtimeContext()); - if(displayname != realname) - { + if (displayname != realname) { out << " " + displayname + " (" + realname + ")"; - } - else - { + } else { out << " " + realname; } } @@ -797,12 +753,9 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr out << ""; QString windowParams; - if (settings->get("LaunchMaximized").toBool()) - { + if (settings->get("LaunchMaximized").toBool()) { out << "Window size: max (if available)"; - } - else - { + } else { auto width = settings->get("MinecraftWinWidth").toInt(); auto height = settings->get("MinecraftWinHeight").toInt(); out << "Window size: " + QString::number(width) + " x " + QString::number(height); @@ -815,27 +768,23 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr QMap<QString, QString> MinecraftInstance::createCensorFilterFromSession(AuthSessionPtr session) { - if(!session) - { + if (!session) { return QMap<QString, QString>(); } - auto & sessionRef = *session.get(); + auto& sessionRef = *session.get(); QMap<QString, QString> filter; - auto addToFilter = [&filter](QString key, QString value) - { - if(key.trimmed().size()) - { + auto addToFilter = [&filter](QString key, QString value) { + if (key.trimmed().size()) { filter[key] = value; } }; - if (sessionRef.session != "-") - { + if (sessionRef.session != "-") { addToFilter(sessionRef.session, tr("<SESSION ID>")); } - if (sessionRef.access_token != "offline") { + if (sessionRef.access_token != "0") { addToFilter(sessionRef.access_token, tr("<ACCESS TOKEN>")); } - if(sessionRef.client_token.size()) { + if (sessionRef.client_token.size()) { addToFilter(sessionRef.client_token, tr("<CLIENT TOKEN>")); } addToFilter(sessionRef.uuid, tr("<PROFILE ID>")); @@ -843,31 +792,28 @@ QMap<QString, QString> MinecraftInstance::createCensorFilterFromSession(AuthSess return filter; } -MessageLevel::Enum MinecraftInstance::guessLevel(const QString &line, MessageLevel::Enum level) +MessageLevel::Enum MinecraftInstance::guessLevel(const QString& line, MessageLevel::Enum level) { QRegularExpression re("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\]"); auto match = re.match(line); - if(match.hasMatch()) - { + if (match.hasMatch()) { // New style logs from log4j QString timestamp = match.captured("timestamp"); QString levelStr = match.captured("level"); - if(levelStr == "INFO") + if (levelStr == "INFO") level = MessageLevel::Message; - if(levelStr == "WARN") + if (levelStr == "WARN") level = MessageLevel::Warning; - if(levelStr == "ERROR") + if (levelStr == "ERROR") level = MessageLevel::Error; - if(levelStr == "FATAL") + if (levelStr == "FATAL") level = MessageLevel::Fatal; - if(levelStr == "TRACE" || levelStr == "DEBUG") + if (levelStr == "TRACE" || levelStr == "DEBUG") level = MessageLevel::Debug; - } - else - { + } else { // Old style forge logs - if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || - line.contains("[FINER]") || line.contains("[FINEST]")) + if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || + line.contains("[FINEST]")) level = MessageLevel::Message; if (line.contains("[SEVERE]") || line.contains("[STDERR]")) level = MessageLevel::Error; @@ -878,14 +824,12 @@ MessageLevel::Enum MinecraftInstance::guessLevel(const QString &line, MessageLev } if (line.contains("overwriting existing")) return MessageLevel::Fatal; - //NOTE: this diverges from the real regexp. no unicode, the first section is + instead of * + // NOTE: this diverges from the real regexp. no unicode, the first section is + instead of * static const QString javaSymbol = "([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$][a-zA-Z\\d_$]*"; - if (line.contains("Exception in thread") - || line.contains(QRegularExpression("\\s+at " + javaSymbol)) - || line.contains(QRegularExpression("Caused by: " + javaSymbol)) - || line.contains(QRegularExpression("([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$]?[a-zA-Z\\d_$]*(Exception|Error|Throwable)")) - || line.contains(QRegularExpression("... \\d+ more$")) - ) + if (line.contains("Exception in thread") || line.contains(QRegularExpression("\\s+at " + javaSymbol)) || + line.contains(QRegularExpression("Caused by: " + javaSymbol)) || + line.contains(QRegularExpression("([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$]?[a-zA-Z\\d_$]*(Exception|Error|Throwable)")) || + line.contains(QRegularExpression("... \\d+ more$"))) return MessageLevel::Error; return level; } @@ -908,14 +852,12 @@ QString MinecraftInstance::getLogFileRoot() QString MinecraftInstance::getStatusbarDescription() { QStringList traits; - if (hasVersionBroken()) - { + if (hasVersionBroken()) { traits.append(tr("broken")); } QString mcVersion = m_components->getComponentVersion("net.minecraft"); - if (mcVersion.isEmpty()) - { + if (mcVersion.isEmpty()) { // Load component info if needed m_components->reload(Net::Mode::Offline); mcVersion = m_components->getComponentVersion("net.minecraft"); @@ -923,8 +865,7 @@ QString MinecraftInstance::getStatusbarDescription() QString description; description.append(tr("Minecraft %1").arg(mcVersion)); - if(m_settings->get("ShowGameTime").toBool()) - { + if (m_settings->get("ShowGameTime").toBool()) { if (lastTimePlayed() > 0) { QDateTime lastLaunchTime = QDateTime::fromMSecsSinceEpoch(lastLaunch()); description.append(tr(", last played on %1 for %2") @@ -936,8 +877,7 @@ QString MinecraftInstance::getStatusbarDescription() description.append(tr(", total played for %1").arg(Time::prettifyDuration(totalTimePlayed()))); } } - if(hasCrashed()) - { + if (hasCrashed()) { description.append(tr(", has crashed.")); } return description; @@ -946,14 +886,11 @@ QString MinecraftInstance::getStatusbarDescription() Task::Ptr MinecraftInstance::createUpdateTask(Net::Mode mode) { updateRuntimeContext(); - switch (mode) - { - case Net::Mode::Offline: - { + switch (mode) { + case Net::Mode::Offline: { return Task::Ptr(new MinecraftLoadAndCheck(this)); } - case Net::Mode::Online: - { + case Net::Mode::Online: { return Task::Ptr(new MinecraftUpdate(this)); } } @@ -979,28 +916,17 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt process->appendStep(makeShared<CheckJava>(pptr)); } - // check launch method - QStringList validMethods = {"LauncherPart", "DirectJava"}; - QString method = launchMethod(); - if(!validMethods.contains(method)) - { - process->appendStep(makeShared<TextPrint>(pptr, "Selected launch method \"" + method + "\" is not valid.\n", MessageLevel::Fatal)); - return process; - } - // create the .minecraft folder and server-resource-packs (workaround for Minecraft bug MCL-3732) { process->appendStep(makeShared<CreateGameFolders>(pptr)); } - if (!serverToJoin && settings()->get("JoinServerOnLaunch").toBool()) - { + if (!serverToJoin && settings()->get("JoinServerOnLaunch").toBool()) { QString fullAddress = settings()->get("JoinServerOnLaunchAddress").toString(); serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(fullAddress))); } - if(serverToJoin && serverToJoin->port == 25565) - { + if (serverToJoin && serverToJoin->port == 25565) { // Resolve server address to join on launch auto step = makeShared<LookupServerAddress>(pptr); step->setLookupAddress(serverToJoin->address); @@ -1009,23 +935,19 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt } // run pre-launch command if that's needed - if(getPreLaunchCommand().size()) - { + if (getPreLaunchCommand().size()) { auto step = makeShared<PreLaunchCommand>(pptr); step->setWorkingDirectory(gameRoot()); process->appendStep(step); } // if we aren't in offline mode,. - if(session->status != AuthSession::PlayableOffline) - { - if(!session->demo) { + if (session->status != AuthSession::PlayableOffline) { + if (!session->demo) { process->appendStep(makeShared<ClaimAccount>(pptr, session)); } process->appendStep(makeShared<Update>(pptr, Net::Mode::Online)); - } - else - { + } else { process->appendStep(makeShared<Update>(pptr, Net::Mode::Offline)); } @@ -1061,38 +983,23 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt { // actually launch the game - auto method = launchMethod(); - if(method == "LauncherPart") - { - auto step = makeShared<LauncherPartLaunch>(pptr); - step->setWorkingDirectory(gameRoot()); - step->setAuthSession(session); - step->setServerToJoin(serverToJoin); - process->appendStep(step); - } - else if (method == "DirectJava") - { - auto step = makeShared<DirectJavaLaunch>(pptr); - step->setWorkingDirectory(gameRoot()); - step->setAuthSession(session); - step->setServerToJoin(serverToJoin); - process->appendStep(step); - } + auto step = makeShared<LauncherPartLaunch>(pptr); + step->setWorkingDirectory(gameRoot()); + step->setAuthSession(session); + step->setServerToJoin(serverToJoin); + process->appendStep(step); } // run post-exit command if that's needed - if(getPostExitCommand().size()) - { + if (getPostExitCommand().size()) { auto step = makeShared<PostLaunchCommand>(pptr); step->setWorkingDirectory(gameRoot()); process->appendStep(step); } - if (session) - { + if (session) { process->setCensorFilter(createCensorFilterFromSession(session)); } - if(m_settings->get("QuitAfterGameStop").toBool()) - { + if (m_settings->get("QuitAfterGameStop").toBool()) { process->appendStep(makeShared<QuitAfterGameStop>(pptr)); } m_launchProcess = process; @@ -1100,11 +1007,6 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt return m_launchProcess; } -QString MinecraftInstance::launchMethod() -{ - return settings()->get("MCLaunchMethod").toString(); -} - JavaVersion MinecraftInstance::getJavaVersion() { return JavaVersion(settings()->get("JavaVersion").toString()); @@ -1112,44 +1014,34 @@ JavaVersion MinecraftInstance::getJavaVersion() std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList() { - if (!m_loader_mod_list) - { + if (!m_loader_mod_list) { bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); m_loader_mod_list.reset(new ModFolderModel(modsRoot(), this, is_indexed)); - m_loader_mod_list->disableInteraction(isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &ModFolderModel::disableInteraction); } return m_loader_mod_list; } std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList() { - if (!m_core_mod_list) - { + if (!m_core_mod_list) { bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); m_core_mod_list.reset(new ModFolderModel(coreModsDir(), this, is_indexed)); - m_core_mod_list->disableInteraction(isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &ModFolderModel::disableInteraction); } return m_core_mod_list; } std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList() { - if (!m_nil_mod_list) - { + if (!m_nil_mod_list) { bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), this, is_indexed, false)); - m_nil_mod_list->disableInteraction(isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_nil_mod_list.get(), &ModFolderModel::disableInteraction); } return m_nil_mod_list; } std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList() { - if (!m_resource_pack_list) - { + if (!m_resource_pack_list) { m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir(), this)); } return m_resource_pack_list; @@ -1157,8 +1049,7 @@ std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList() std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList() { - if (!m_texture_pack_list) - { + if (!m_texture_pack_list) { m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir(), this)); } return m_texture_pack_list; @@ -1166,8 +1057,7 @@ std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList() std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList() { - if (!m_shader_pack_list) - { + if (!m_shader_pack_list) { m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir(), this)); } return m_shader_pack_list; @@ -1175,8 +1065,7 @@ std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList() std::shared_ptr<WorldList> MinecraftInstance::worldList() { - if (!m_world_list) - { + if (!m_world_list) { m_world_list.reset(new WorldList(worldDir(), this)); } return m_world_list; @@ -1184,8 +1073,7 @@ std::shared_ptr<WorldList> MinecraftInstance::worldList() std::shared_ptr<GameOptions> MinecraftInstance::gameOptionsModel() { - if (!m_game_options) - { + if (!m_game_options) { m_game_options.reset(new GameOptions(FS::PathCombine(gameRoot(), "options.txt"))); } return m_game_options; @@ -1195,8 +1083,7 @@ QList<Mod*> MinecraftInstance::getJarMods() const { auto profile = m_components->getProfile(); QList<Mod*> mods; - for (auto jarmod : profile->getJarMods()) - { + for (auto jarmod : profile->getJarMods()) { QStringList jar, temp1, temp2, temp3; jarmod->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, jarmodsPath().absolutePath()); // QString filePath = jarmodsPath().absoluteFilePath(jarmod->filename(currentSystem)); @@ -1205,5 +1092,4 @@ QList<Mod*> MinecraftInstance::getJarMods() const return mods; } - #include "MinecraftInstance.moc" |