Merge branch 'develop' into better-launch
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -37,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/LauncherPartLaunch.h"
|
||||
#include "minecraft/launch/DirectJavaLaunch.h"
|
||||
#include "minecraft/launch/ModMinecraftJar.h"
|
||||
#include "minecraft/launch/ClaimAccount.h"
|
||||
#include "minecraft/launch/LauncherPartLaunch.h"
|
||||
#include "minecraft/launch/ModMinecraftJar.h"
|
||||
#include "minecraft/launch/ReconstructAssets.h"
|
||||
#include "minecraft/launch/ScanModFolders.h"
|
||||
#include "minecraft/launch/VerifyJavaInstall.h"
|
||||
@ -82,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"
|
||||
|
||||
@ -101,14 +100,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();
|
||||
@ -117,12 +112,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));
|
||||
@ -171,10 +167,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);
|
||||
@ -231,14 +223,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();
|
||||
}
|
||||
@ -319,7 +309,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");
|
||||
@ -430,21 +420,18 @@ 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()));
|
||||
}
|
||||
|
||||
{
|
||||
@ -471,38 +458,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);
|
||||
}
|
||||
}
|
||||
@ -542,8 +524,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;
|
||||
@ -555,15 +536,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
|
||||
@ -576,8 +554,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
|
||||
@ -598,14 +575,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();
|
||||
@ -614,25 +589,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;
|
||||
@ -640,7 +612,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";
|
||||
}
|
||||
}
|
||||
@ -664,8 +636,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;
|
||||
@ -678,32 +649,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";
|
||||
}
|
||||
|
||||
@ -713,22 +678,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";
|
||||
}
|
||||
|
||||
@ -741,17 +703,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 << "";
|
||||
@ -760,8 +722,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)
|
||||
@ -774,34 +735,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) {
|
||||
@ -809,21 +763,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 << "";
|
||||
}
|
||||
@ -832,20 +782,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;
|
||||
}
|
||||
}
|
||||
@ -858,12 +803,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);
|
||||
@ -876,27 +818,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>"));
|
||||
@ -904,31 +842,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;
|
||||
@ -939,14 +874,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;
|
||||
}
|
||||
@ -969,14 +902,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");
|
||||
@ -984,8 +915,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")
|
||||
@ -997,8 +927,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;
|
||||
@ -1007,14 +936,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));
|
||||
}
|
||||
}
|
||||
@ -1040,28 +966,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);
|
||||
@ -1070,23 +985,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));
|
||||
}
|
||||
|
||||
@ -1122,38 +1033,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;
|
||||
@ -1161,11 +1057,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());
|
||||
@ -1200,8 +1091,7 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList()
|
||||
|
||||
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;
|
||||
@ -1209,8 +1099,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;
|
||||
@ -1218,8 +1107,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;
|
||||
@ -1227,8 +1115,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;
|
||||
@ -1236,8 +1123,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;
|
||||
@ -1247,8 +1133,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));
|
||||
@ -1257,5 +1142,4 @@ QList<Mod*> MinecraftInstance::getJarMods() const
|
||||
return mods;
|
||||
}
|
||||
|
||||
|
||||
#include "MinecraftInstance.moc"
|
||||
|
Reference in New Issue
Block a user