From 1f2bed2ef119094bdc156aa3a206b93dea5081d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 16 Jun 2016 02:20:23 +0200 Subject: NOISSUE implement direct java launch Just running the Java process and giving it params on the command line --- api/logic/BaseInstance.h | 5 + api/logic/CMakeLists.txt | 10 +- api/logic/NullInstance.h | 6 + api/logic/java/JavaVersion.cpp | 48 ++-- api/logic/java/JavaVersion.h | 24 +- api/logic/java/JavaVersion_test.cpp | 10 +- api/logic/java/launch/CheckJava.cpp | 26 +- api/logic/java/launch/CheckJava.h | 3 + api/logic/minecraft/MinecraftInstance.cpp | 110 ++++++++- api/logic/minecraft/MinecraftInstance.h | 18 +- api/logic/minecraft/MinecraftProfile.cpp | 20 ++ api/logic/minecraft/MinecraftProfile.h | 1 + api/logic/minecraft/launch/DirectJavaLaunch.cpp | 149 ++++++++++++ api/logic/minecraft/launch/DirectJavaLaunch.h | 47 ++++ api/logic/minecraft/launch/ExtractNatives.cpp | 86 +++++++ api/logic/minecraft/launch/ExtractNatives.h | 37 +++ api/logic/minecraft/launch/LaunchMinecraft.cpp | 155 ------------ api/logic/minecraft/launch/LaunchMinecraft.h | 48 ---- api/logic/minecraft/launch/LauncherPartLaunch.cpp | 157 ++++++++++++ api/logic/minecraft/launch/LauncherPartLaunch.h | 49 ++++ api/logic/minecraft/launch/PrintInstanceInfo.cpp | 25 ++ api/logic/minecraft/launch/PrintInstanceInfo.h | 38 +++ api/logic/minecraft/legacy/LegacyInstance.cpp | 198 ++++++++++----- api/logic/minecraft/legacy/LegacyInstance.h | 18 +- api/logic/minecraft/onesix/OneSixInstance.cpp | 284 ++++++++++++++-------- api/logic/minecraft/onesix/OneSixInstance.h | 17 +- 26 files changed, 1165 insertions(+), 424 deletions(-) create mode 100644 api/logic/minecraft/launch/DirectJavaLaunch.cpp create mode 100644 api/logic/minecraft/launch/DirectJavaLaunch.h create mode 100644 api/logic/minecraft/launch/ExtractNatives.cpp create mode 100644 api/logic/minecraft/launch/ExtractNatives.h delete mode 100644 api/logic/minecraft/launch/LaunchMinecraft.cpp delete mode 100644 api/logic/minecraft/launch/LaunchMinecraft.h create mode 100644 api/logic/minecraft/launch/LauncherPartLaunch.cpp create mode 100644 api/logic/minecraft/launch/LauncherPartLaunch.h create mode 100644 api/logic/minecraft/launch/PrintInstanceInfo.cpp create mode 100644 api/logic/minecraft/launch/PrintInstanceInfo.h (limited to 'api') diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h index 5e587c48..f0fb6096 100644 --- a/api/logic/BaseInstance.h +++ b/api/logic/BaseInstance.h @@ -210,6 +210,11 @@ public: virtual bool reload(); + /** + * 'print' a verbose desription of the instance into a QStringList + */ + virtual QStringList verboseDescription(AuthSessionPtr session) = 0; + signals: /*! * \brief Signal emitted when properties relevant to the instance view change diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 1048e091..87908363 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -202,8 +202,14 @@ set(MINECRAFT_SOURCES minecraft/onesix/OneSixVersionFormat.h minecraft/launch/ModMinecraftJar.cpp minecraft/launch/ModMinecraftJar.h - minecraft/launch/LaunchMinecraft.cpp - minecraft/launch/LaunchMinecraft.h + minecraft/launch/DirectJavaLaunch.cpp + minecraft/launch/DirectJavaLaunch.h + minecraft/launch/ExtractNatives.cpp + minecraft/launch/ExtractNatives.h + minecraft/launch/LauncherPartLaunch.cpp + minecraft/launch/LauncherPartLaunch.h + minecraft/launch/PrintInstanceInfo.cpp + minecraft/launch/PrintInstanceInfo.h minecraft/legacy/LegacyModList.h minecraft/legacy/LegacyModList.cpp minecraft/legacy/LegacyUpdate.h diff --git a/api/logic/NullInstance.h b/api/logic/NullInstance.h index fbb2d985..d87fb6f7 100644 --- a/api/logic/NullInstance.h +++ b/api/logic/NullInstance.h @@ -87,4 +87,10 @@ public: { return false; } + QStringList verboseDescription(AuthSessionPtr session) override + { + QStringList out; + out << "Null instance - placeholder."; + return out; + } }; diff --git a/api/logic/java/JavaVersion.cpp b/api/logic/java/JavaVersion.cpp index 84fc48a4..8c1bb430 100644 --- a/api/logic/java/JavaVersion.cpp +++ b/api/logic/java/JavaVersion.cpp @@ -6,7 +6,7 @@ JavaVersion & JavaVersion::operator=(const QString & javaVersionString) { - string = javaVersionString; + m_string = javaVersionString; auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int { @@ -28,12 +28,12 @@ JavaVersion & JavaVersion::operator=(const QString & javaVersionString) pattern = QRegularExpression("(?[0-9]+)([.](?[0-9]+))?([.](?[0-9]+))?(-(?[a-zA-Z0-9]+))?"); } - auto match = pattern.match(string); - parseable = match.hasMatch(); - major = getCapturedInteger(match, "major"); - minor = getCapturedInteger(match, "minor"); - security = getCapturedInteger(match, "security"); - prerelease = match.captured("prerelease"); + auto match = pattern.match(m_string); + m_parseable = match.hasMatch(); + m_major = getCapturedInteger(match, "major"); + m_minor = getCapturedInteger(match, "minor"); + m_security = getCapturedInteger(match, "security"); + m_prerelease = match.captured("prerelease"); return *this; } @@ -44,38 +44,38 @@ JavaVersion::JavaVersion(const QString &rhs) QString JavaVersion::toString() { - return string; + return m_string; } bool JavaVersion::requiresPermGen() { - if(parseable) + if(m_parseable) { - return major < 8; + return m_major < 8; } return true; } bool JavaVersion::operator<(const JavaVersion &rhs) { - if(parseable && rhs.parseable) + if(m_parseable && rhs.m_parseable) { - if(major < rhs.major) + if(m_major < rhs.m_major) return true; - if(major > rhs.major) + if(m_major > rhs.m_major) return false; - if(minor < rhs.minor) + if(m_minor < rhs.m_minor) return true; - if(minor > rhs.minor) + if(m_minor > rhs.m_minor) return false; - if(security < rhs.security) + if(m_security < rhs.m_security) return true; - if(security > rhs.security) + if(m_security > rhs.m_security) return false; // everything else being equal, consider prerelease status - bool thisPre = !prerelease.isEmpty(); - bool rhsPre = !rhs.prerelease.isEmpty(); + bool thisPre = !m_prerelease.isEmpty(); + bool rhsPre = !rhs.m_prerelease.isEmpty(); if(thisPre && !rhsPre) { // this is a prerelease and the other one isn't -> lesser @@ -89,21 +89,21 @@ bool JavaVersion::operator<(const JavaVersion &rhs) else if(thisPre && rhsPre) { // both are prereleases - use natural compare... - return Strings::naturalCompare(prerelease, rhs.prerelease, Qt::CaseSensitive) < 0; + return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0; } // neither is prerelease, so they are the same -> this cannot be less than rhs return false; } - else return Strings::naturalCompare(string, rhs.string, Qt::CaseSensitive) < 0; + else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0; } bool JavaVersion::operator==(const JavaVersion &rhs) { - if(parseable && rhs.parseable) + if(m_parseable && rhs.m_parseable) { - return major == rhs.major && minor == rhs.minor && security == rhs.security && prerelease == rhs.prerelease; + return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease; } - return string == rhs.string; + return m_string == rhs.m_string; } bool JavaVersion::operator>(const JavaVersion &rhs) diff --git a/api/logic/java/JavaVersion.h b/api/logic/java/JavaVersion.h index f9a733d3..deba5654 100644 --- a/api/logic/java/JavaVersion.h +++ b/api/logic/java/JavaVersion.h @@ -20,11 +20,23 @@ public: QString toString(); + int major() + { + return m_major; + } + int minor() + { + return m_minor; + } + int security() + { + return m_security; + } private: - QString string; - int major = 0; - int minor = 0; - int security = 0; - bool parseable = false; - QString prerelease; + QString m_string; + int m_major = 0; + int m_minor = 0; + int m_security = 0; + bool m_parseable = false; + QString m_prerelease; }; diff --git a/api/logic/java/JavaVersion_test.cpp b/api/logic/java/JavaVersion_test.cpp index 9dae0ba6..e719ffc8 100644 --- a/api/logic/java/JavaVersion_test.cpp +++ b/api/logic/java/JavaVersion_test.cpp @@ -34,12 +34,12 @@ slots: QFETCH(QString, prerelease); JavaVersion test(string); - QCOMPARE(test.string, string); + QCOMPARE(test.m_string, string); QCOMPARE(test.toString(), string); - QCOMPARE(test.major, major); - QCOMPARE(test.minor, minor); - QCOMPARE(test.security, security); - QCOMPARE(test.prerelease, prerelease); + QCOMPARE(test.m_major, major); + QCOMPARE(test.m_minor, minor); + QCOMPARE(test.m_security, security); + QCOMPARE(test.m_prerelease, prerelease); } void test_Sort_data() diff --git a/api/logic/java/launch/CheckJava.cpp b/api/logic/java/launch/CheckJava.cpp index a4eaa307..41bb6398 100644 --- a/api/logic/java/launch/CheckJava.cpp +++ b/api/logic/java/launch/CheckJava.cpp @@ -53,20 +53,25 @@ void CheckJava::executeTask() QFileInfo javaInfo(realJavaPath); qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch(); auto storedUnixTime = settings->get("JavaTimestamp").toLongLong(); + auto storedArchitecture = settings->get("JavaArchitecture").toString(); + auto storedVersion = settings->get("JavaVersion").toString(); m_javaUnixTime = javaUnixTime; - // if they are not the same, check! - if (javaUnixTime != storedUnixTime) + // if timestamps are not the same, or something is missing, check! + if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0) { m_JavaChecker = std::make_shared(); - QString errorLog; - QString version; emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC); - connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, - &CheckJava::checkJavaFinished); + connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished); m_JavaChecker->m_path = realJavaPath; m_JavaChecker->performCheck(); return; } + else + { + auto verString = instance->settings()->get("JavaVersion").toString(); + auto archString = instance->settings()->get("JavaArchitecture").toString(); + printJavaInfo(verString, archString); + } emitSucceeded(); } @@ -83,10 +88,15 @@ void CheckJava::checkJavaFinished(JavaCheckResult result) else { auto instance = m_parent->instance(); - emit logLine(tr("Java version is %1!\n").arg(result.javaVersion.toString()), - MessageLevel::MultiMC); + printJavaInfo(result.javaVersion.toString(), result.mojangPlatform); instance->settings()->set("JavaVersion", result.javaVersion.toString()); + instance->settings()->set("JavaArchitecture", result.mojangPlatform); instance->settings()->set("JavaTimestamp", m_javaUnixTime); emitSucceeded(); } } + +void CheckJava::printJavaInfo(const QString& version, const QString& architecture) +{ + emit logLine(tr("Java is version %1, using %2-bit architecture.\n\n").arg(version, architecture), MessageLevel::MultiMC); +} diff --git a/api/logic/java/launch/CheckJava.h b/api/logic/java/launch/CheckJava.h index b63dd4f4..118da225 100644 --- a/api/logic/java/launch/CheckJava.h +++ b/api/logic/java/launch/CheckJava.h @@ -34,6 +34,9 @@ public: private slots: void checkJavaFinished(JavaCheckResult result); +private: + void printJavaInfo(const QString & version, const QString & architecture); + private: QString m_javaPath; qlonglong m_javaUnixTime; diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index 405ccd26..8cc4f805 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -1,4 +1,6 @@ #include "MinecraftInstance.h" +#include +#include #include #include "settings/SettingsObject.h" #include "Env.h" @@ -9,6 +11,15 @@ #include #include +#include "launch/LaunchTask.h" +#include "launch/steps/PostLaunchCommand.h" +#include "launch/steps/Update.h" +#include "launch/steps/PreLaunchCommand.h" +#include "launch/steps/TextPrint.h" +#include "minecraft/launch/LauncherPartLaunch.h" +#include "minecraft/launch/ModMinecraftJar.h" +#include "java/launch/CheckJava.h" + #define IBUS "@im=ibus" // all of this because keeping things compatible with deprecated old settings @@ -52,6 +63,7 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO // special! m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation); m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation); + m_settings->registerPassthrough(globalSettings->getSetting("JavaArchitecture"), javaOrLocation); // Window Size auto windowSetting = m_settings->registerSetting("OverrideWindow", false); @@ -64,6 +76,10 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc"), memorySetting); m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc"), memorySetting); m_settings->registerOverride(globalSettings->getSetting("PermGen"), memorySetting); + + // Minecraft launch method + auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false); + m_settings->registerOverride(globalSettings->getSetting("MCLaunchMethod"), launchMethodOverride); } QString MinecraftInstance::minecraftRoot() const @@ -105,7 +121,7 @@ QStringList MinecraftInstance::javaArguments() const args << QString("-Xmx%1m").arg(settings()->get("MaxMemAlloc").toInt()); // No PermGen in newer java. - JavaVersion javaVersion(settings()->get("JavaVersion").toString()); + JavaVersion javaVersion = getJavaVersion(); if(javaVersion.requiresPermGen()) { auto permgen = settings()->get("PermGen").toInt(); @@ -116,7 +132,6 @@ QStringList MinecraftInstance::javaArguments() const } args << "-Duser.language=en"; - args << "-jar" << FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar"); return args; } @@ -366,4 +381,95 @@ QString MinecraftInstance::getStatusbarDescription() return description; } +std::shared_ptr MinecraftInstance::createLaunchTask(AuthSessionPtr session) +{ + auto process = LaunchTask::create(std::dynamic_pointer_cast(getSharedPtr())); + auto pptr = process.get(); + + // print a header + { + process->appendStep(std::make_shared(pptr, "Minecraft folder is:\n" + minecraftRoot() + "\n\n", MessageLevel::MultiMC)); + } + + // check java + { + auto step = std::make_shared(pptr); + process->appendStep(step); + } + + // check launch method + QStringList validMethods = validLaunchMethods(); + QString method = launchMethod(); + if(!validMethods.contains(method)) + { + process->appendStep(std::make_shared(pptr, "Selected launch method \"" + method + "\" is not valid.\n", MessageLevel::Fatal)); + return process; + } + + // run pre-launch command if that's needed + if(getPreLaunchCommand().size()) + { + auto step = std::make_shared(pptr); + step->setWorkingDirectory(minecraftRoot()); + process->appendStep(step); + } + + // if we aren't in offline mode,. + if(session->status != AuthSession::PlayableOffline) + { + process->appendStep(std::make_shared(pptr)); + } + + // if there are any jar mods + if(getJarMods().size()) + { + auto step = std::make_shared(pptr); + process->appendStep(step); + } + + // print some instance info here... + { + auto step = std::make_shared(pptr, session); + process->appendStep(step); + } + + // extract native jars if needed + auto jars = getNativeJars(); + if(jars.size()) + { + auto step = std::make_shared(pptr); + process->appendStep(step); + } + + { + // actually launch the game + auto step = createMainLaunchStep(pptr, session); + process->appendStep(step); + } + + // run post-exit command if that's needed + if(getPostExitCommand().size()) + { + auto step = std::make_shared(pptr); + step->setWorkingDirectory(minecraftRoot()); + process->appendStep(step); + } + if (session) + { + process->setCensorFilter(createCensorFilterFromSession(session)); + } + return process; +} + +QString MinecraftInstance::launchMethod() +{ + return m_settings->get("MCLaunchMethod").toString(); +} + +JavaVersion MinecraftInstance::getJavaVersion() const +{ + return JavaVersion(settings()->get("JavaVersion").toString()); +} + + #include "MinecraftInstance.moc" diff --git a/api/logic/minecraft/MinecraftInstance.h b/api/logic/minecraft/MinecraftInstance.h index cd3a8d90..3aef2969 100644 --- a/api/logic/minecraft/MinecraftInstance.h +++ b/api/logic/minecraft/MinecraftInstance.h @@ -1,5 +1,6 @@ #pragma once #include "BaseInstance.h" +#include #include "minecraft/Mod.h" #include @@ -7,6 +8,7 @@ class ModList; class WorldList; +class LaunchStep; class MULTIMC_LOGIC_EXPORT MinecraftInstance: public BaseInstance { @@ -36,7 +38,7 @@ public: return QList(); } - /// get the launch script to be used with this + virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) override; virtual QString createLaunchScript(AuthSessionPtr session) = 0; //FIXME: nuke? @@ -60,8 +62,22 @@ public: virtual QString getStatusbarDescription() override; + virtual QStringList getClassPath() const = 0; + virtual QStringList getNativeJars() const = 0; + + virtual QString getMainClass() const = 0; + + virtual QString getNativePath() const = 0; + + virtual QStringList processMinecraftArgs(AuthSessionPtr account) const = 0; + + virtual JavaVersion getJavaVersion() const; + protected: QMap createCensorFilterFromSession(AuthSessionPtr session); + virtual QStringList validLaunchMethods() = 0; + virtual QString launchMethod(); + virtual std::shared_ptr createMainLaunchStep(LaunchTask *parent, AuthSessionPtr session) = 0; private: QString prettifyTimeDuration(int64_t duration); }; diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index 70d0cee4..19127a54 100644 --- a/api/logic/minecraft/MinecraftProfile.cpp +++ b/api/logic/minecraft/MinecraftProfile.cpp @@ -573,6 +573,26 @@ const QList & MinecraftProfile::getLibraries() const return m_libraries; } +void MinecraftProfile::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars) const +{ + QStringList native32, native64; + jars.clear(); + nativeJars.clear(); + for (auto lib : getLibraries()) + { + lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64); + } + if(architecture == "32") + { + nativeJars.append(native32); + } + else if(architecture == "64") + { + nativeJars.append(native64); + } +} + + QString MinecraftProfile::getMainJarUrl() const { auto iter = mojangDownloads.find("client"); diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h index ca9288ad..cc9b89b1 100644 --- a/api/logic/minecraft/MinecraftProfile.h +++ b/api/logic/minecraft/MinecraftProfile.h @@ -110,6 +110,7 @@ public: /* getters for profile variables */ const QStringList & getTweakers() const; const QList & getJarMods() const; const QList & getLibraries() const; + void getLibraryFiles(const QString & architecture, QStringList & jars, QStringList & nativeJars) const; QString getMainJarUrl() const; bool hasTrait(const QString & trait) const; ProblemSeverity getProblemSeverity() const; diff --git a/api/logic/minecraft/launch/DirectJavaLaunch.cpp b/api/logic/minecraft/launch/DirectJavaLaunch.cpp new file mode 100644 index 00000000..c46cdcd4 --- /dev/null +++ b/api/logic/minecraft/launch/DirectJavaLaunch.cpp @@ -0,0 +1,149 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "DirectJavaLaunch.h" +#include +#include +#include +#include + +DirectJavaLaunch::DirectJavaLaunch(LaunchTask *parent) : LaunchStep(parent) +{ + connect(&m_process, &LoggedProcess::log, this, &DirectJavaLaunch::logLines); + connect(&m_process, &LoggedProcess::stateChanged, this, &DirectJavaLaunch::on_state); +} + +void DirectJavaLaunch::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + QStringList args = minecraftInstance->javaArguments(); + + // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created. + if(!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->minecraftRoot(), "server-resource-packs"))) + { + emit logLine(tr("Couldn't create the 'server-resource-packs' folder"), MessageLevel::Error); + } + + args.append("-Djava.library.path=" + minecraftInstance->getNativePath()); + + auto classPathEntries = minecraftInstance->getClassPath(); + args.append("-cp"); + QString classpath; +#ifdef Q_OS_WIN32 + classpath = classPathEntries.join(';'); +#else + classpath = classPathEntries.join(':'); +#endif + args.append(classpath); + args.append(minecraftInstance->getMainClass()); + + QString allArgs = args.join(", "); + emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); + + auto javaPath = FS::ResolveExecutable(instance->settings()->get("JavaPath").toString()); + + m_process.setProcessEnvironment(instance->createEnvironment()); + + auto mcArgs = minecraftInstance->processMinecraftArgs(m_session); + args.append(mcArgs); + + QString wrapperCommand = instance->getWrapperCommand(); + if(!wrapperCommand.isEmpty()) + { + auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); + if (realWrapperCommand.isEmpty()) + { + QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); + args.prepend(javaPath); + m_process.start(wrapperCommand, args); + } + else + { + m_process.start(javaPath, args); + } +} + +void DirectJavaLaunch::on_state(LoggedProcess::State state) +{ + switch(state) + { + case LoggedProcess::FailedToStart: + { + //: Error message displayed if instace can't start + QString reason = tr("Could not launch minecraft!"); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + case LoggedProcess::Aborted: + case LoggedProcess::Crashed: + + { + m_parent->setPid(-1); + emitFailed("Game crashed."); + return; + } + case LoggedProcess::Finished: + { + m_parent->setPid(-1); + // if the exit code wasn't 0, report this as a crash + auto exitCode = m_process.exitCode(); + if(exitCode != 0) + { + emitFailed("Game crashed."); + return; + } + //FIXME: make this work again + // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); + // run post-exit + emitSucceeded(); + break; + } + case LoggedProcess::Running: + emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); + m_parent->setPid(m_process.processId()); + m_parent->instance()->setLastLaunch(); + break; + default: + break; + } +} + +void DirectJavaLaunch::setWorkingDirectory(const QString &wd) +{ + m_process.setWorkingDirectory(wd); +} + +void DirectJavaLaunch::proceed() +{ + // nil +} + +bool DirectJavaLaunch::abort() +{ + auto state = m_process.state(); + if (state == LoggedProcess::Running || state == LoggedProcess::Starting) + { + m_process.kill(); + } + return true; +} + diff --git a/api/logic/minecraft/launch/DirectJavaLaunch.h b/api/logic/minecraft/launch/DirectJavaLaunch.h new file mode 100644 index 00000000..0e3d66cc --- /dev/null +++ b/api/logic/minecraft/launch/DirectJavaLaunch.h @@ -0,0 +1,47 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +class DirectJavaLaunch: public LaunchStep +{ + Q_OBJECT +public: + explicit DirectJavaLaunch(LaunchTask *parent); + virtual void executeTask(); + virtual bool abort(); + virtual void proceed(); + virtual bool canAbort() const + { + return true; + } + void setWorkingDirectory(const QString &wd); + void setAuthSession(AuthSessionPtr session) + { + m_session = session; + } +private slots: + void on_state(LoggedProcess::State state); + +private: + LoggedProcess m_process; + QString m_command; + AuthSessionPtr m_session; +}; + diff --git a/api/logic/minecraft/launch/ExtractNatives.cpp b/api/logic/minecraft/launch/ExtractNatives.cpp new file mode 100644 index 00000000..089e2559 --- /dev/null +++ b/api/logic/minecraft/launch/ExtractNatives.cpp @@ -0,0 +1,86 @@ +/* Copyright 2013-2016 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ExtractNatives.h" +#include +#include + +#include +#include +#include +#include "MMCZip.h" +#include "FileSystem.h" +#include + +static QString replaceSuffix (QString target, const QString &suffix, const QString &replacement) +{ + if (!target.endsWith(suffix)) + { + return target; + } + target.resize(target.length() - suffix.length()); + return target + replacement; +} + +static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack) +{ + QuaZip zip(source); + if(!zip.open(QuaZip::mdUnzip)) + { + return false; + } + QDir directory(targetFolder); + if (!zip.goToFirstFile()) + { + return false; + } + do + { + QString name = zip.getCurrentFileName(); + if(applyJnilibHack) + { + name = replaceSuffix(name, ".jnilib", ".dylib"); + } + QString absFilePath = directory.absoluteFilePath(name); + if (!MMCZip::extractFile(&zip, "", absFilePath)) + { + return false; + } + } while (zip.goToNextFile()); + zip.close(); + if(zip.getZipError()!=0) + { + return false; + } + return true; +} + +void ExtractNatives::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + auto outputPath = minecraftInstance->getNativePath(); + auto toExtract = minecraftInstance->getNativeJars(); + auto javaVersion = minecraftInstance->getJavaVersion(); + bool jniHackEnabled = javaVersion.major() >= 8; + for(const auto &source: toExtract) + { + if(!unzipNatives(source, outputPath, jniHackEnabled)) + { + emitFailed(tr("Couldn't extract native jar '%1' to destination '%2'").arg(source, outputPath)); + } + } + emitSucceeded(); +} diff --git a/api/logic/minecraft/launch/ExtractNatives.h b/api/logic/minecraft/launch/ExtractNatives.h new file mode 100644 index 00000000..699657d7 --- /dev/null +++ b/api/logic/minecraft/launch/ExtractNatives.h @@ -0,0 +1,37 @@ +/* Copyright 2013-2016 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include "minecraft/auth/AuthSession.h" + +// FIXME: temporary wrapper for existing task. +class ExtractNatives: public LaunchStep +{ + Q_OBJECT +public: + explicit ExtractNatives(LaunchTask *parent) : LaunchStep(parent){}; + virtual ~ExtractNatives(){}; + + virtual void executeTask(); + virtual bool canAbort() const + { + return false; + } +}; + + diff --git a/api/logic/minecraft/launch/LaunchMinecraft.cpp b/api/logic/minecraft/launch/LaunchMinecraft.cpp deleted file mode 100644 index 9b8cc0fb..00000000 --- a/api/logic/minecraft/launch/LaunchMinecraft.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LaunchMinecraft.h" -#include -#include -#include -#include - -LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent) -{ - connect(&m_process, &LoggedProcess::log, this, &LaunchMinecraft::logLines); - connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchMinecraft::on_state); -} - -void LaunchMinecraft::executeTask() -{ - auto instance = m_parent->instance(); - std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); - - m_launchScript = minecraftInstance->createLaunchScript(m_session); - - QStringList args = minecraftInstance->javaArguments(); - - // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created. - if(!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->minecraftRoot(), "server-resource-packs"))) - { - emit logLine(tr("Couldn't create the 'server-resource-packs' folder"), MessageLevel::Error); - } - - QString allArgs = args.join(", "); - emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); - - auto javaPath = FS::ResolveExecutable(instance->settings()->get("JavaPath").toString()); - - m_process.setProcessEnvironment(instance->createEnvironment()); - - QString wrapperCommand = instance->getWrapperCommand(); - if(!wrapperCommand.isEmpty()) - { - auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); - if (realWrapperCommand.isEmpty()) - { - QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); - emit logLine(reason, MessageLevel::Fatal); - emitFailed(reason); - return; - } - emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); - args.prepend(javaPath); - m_process.start(wrapperCommand, args); - } - else - { - m_process.start(javaPath, args); - } -} - -void LaunchMinecraft::on_state(LoggedProcess::State state) -{ - switch(state) - { - case LoggedProcess::FailedToStart: - { - //: Error message displayed if instace can't start - QString reason = tr("Could not launch minecraft!"); - emit logLine(reason, MessageLevel::Fatal); - emitFailed(reason); - return; - } - case LoggedProcess::Aborted: - case LoggedProcess::Crashed: - - { - m_parent->setPid(-1); - emitFailed("Game crashed."); - return; - } - case LoggedProcess::Finished: - { - m_parent->setPid(-1); - // if the exit code wasn't 0, report this as a crash - auto exitCode = m_process.exitCode(); - if(exitCode != 0) - { - emitFailed("Game crashed."); - return; - } - //FIXME: make this work again - // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); - // run post-exit - emitSucceeded(); - break; - } - case LoggedProcess::Running: - emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); - m_parent->setPid(m_process.processId()); - m_parent->instance()->setLastLaunch(); - // send the launch script to the launcher part - m_process.write(m_launchScript.toUtf8()); - qDebug() << m_launchScript; - - mayProceed = true; - emit readyForLaunch(); - break; - default: - break; - } -} - -void LaunchMinecraft::setWorkingDirectory(const QString &wd) -{ - m_process.setWorkingDirectory(wd); -} - -void LaunchMinecraft::proceed() -{ - if(mayProceed) - { - QString launchString("launch\n"); - m_process.write(launchString.toUtf8()); - mayProceed = false; - } -} - -bool LaunchMinecraft::abort() -{ - if(mayProceed) - { - mayProceed = false; - QString launchString("abort\n"); - m_process.write(launchString.toUtf8()); - } - else - { - auto state = m_process.state(); - if (state == LoggedProcess::Running || state == LoggedProcess::Starting) - { - m_process.kill(); - } - } - return true; -} diff --git a/api/logic/minecraft/launch/LaunchMinecraft.h b/api/logic/minecraft/launch/LaunchMinecraft.h deleted file mode 100644 index 6b9f7919..00000000 --- a/api/logic/minecraft/launch/LaunchMinecraft.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -class LaunchMinecraft: public LaunchStep -{ - Q_OBJECT -public: - explicit LaunchMinecraft(LaunchTask *parent); - virtual void executeTask(); - virtual bool abort(); - virtual void proceed(); - virtual bool canAbort() const - { - return true; - } - void setWorkingDirectory(const QString &wd); - void setAuthSession(AuthSessionPtr session) - { - m_session = session; - } -private slots: - void on_state(LoggedProcess::State state); - -private: - LoggedProcess m_process; - QString m_command; - QString m_launchScript; - AuthSessionPtr m_session; - bool mayProceed = false; -}; diff --git a/api/logic/minecraft/launch/LauncherPartLaunch.cpp b/api/logic/minecraft/launch/LauncherPartLaunch.cpp new file mode 100644 index 00000000..5f233700 --- /dev/null +++ b/api/logic/minecraft/launch/LauncherPartLaunch.cpp @@ -0,0 +1,157 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LauncherPartLaunch.h" +#include +#include +#include +#include +#include + +LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent) +{ + connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines); + connect(&m_process, &LoggedProcess::stateChanged, this, &LauncherPartLaunch::on_state); +} + +void LauncherPartLaunch::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + + m_launchScript = minecraftInstance->createLaunchScript(m_session); + QStringList args = minecraftInstance->javaArguments(); + + // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created. + if(!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->minecraftRoot(), "server-resource-packs"))) + { + emit logLine(tr("Couldn't create the 'server-resource-packs' folder"), MessageLevel::Error); + } + + QString allArgs = args.join(", "); + emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); + + auto javaPath = FS::ResolveExecutable(instance->settings()->get("JavaPath").toString()); + + m_process.setProcessEnvironment(instance->createEnvironment()); + + args << "-jar" << FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar"); + + QString wrapperCommand = instance->getWrapperCommand(); + if(!wrapperCommand.isEmpty()) + { + auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); + if (realWrapperCommand.isEmpty()) + { + QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); + args.prepend(javaPath); + m_process.start(wrapperCommand, args); + } + else + { + m_process.start(javaPath, args); + } +} + +void LauncherPartLaunch::on_state(LoggedProcess::State state) +{ + switch(state) + { + case LoggedProcess::FailedToStart: + { + //: Error message displayed if instace can't start + QString reason = tr("Could not launch minecraft!"); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + case LoggedProcess::Aborted: + case LoggedProcess::Crashed: + + { + m_parent->setPid(-1); + emitFailed("Game crashed."); + return; + } + case LoggedProcess::Finished: + { + m_parent->setPid(-1); + // if the exit code wasn't 0, report this as a crash + auto exitCode = m_process.exitCode(); + if(exitCode != 0) + { + emitFailed("Game crashed."); + return; + } + //FIXME: make this work again + // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); + // run post-exit + emitSucceeded(); + break; + } + case LoggedProcess::Running: + emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); + m_parent->setPid(m_process.processId()); + m_parent->instance()->setLastLaunch(); + // send the launch script to the launcher part + m_process.write(m_launchScript.toUtf8()); + qDebug() << m_launchScript; + + mayProceed = true; + emit readyForLaunch(); + break; + default: + break; + } +} + +void LauncherPartLaunch::setWorkingDirectory(const QString &wd) +{ + m_process.setWorkingDirectory(wd); +} + +void LauncherPartLaunch::proceed() +{ + if(mayProceed) + { + QString launchString("launch\n"); + m_process.write(launchString.toUtf8()); + mayProceed = false; + } +} + +bool LauncherPartLaunch::abort() +{ + if(mayProceed) + { + mayProceed = false; + QString launchString("abort\n"); + m_process.write(launchString.toUtf8()); + } + else + { + auto state = m_process.state(); + if (state == LoggedProcess::Running || state == LoggedProcess::Starting) + { + m_process.kill(); + } + } + return true; +} diff --git a/api/logic/minecraft/launch/LauncherPartLaunch.h b/api/logic/minecraft/launch/LauncherPartLaunch.h new file mode 100644 index 00000000..209902e0 --- /dev/null +++ b/api/logic/minecraft/launch/LauncherPartLaunch.h @@ -0,0 +1,49 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +class LauncherPartLaunch: public LaunchStep +{ + Q_OBJECT +public: + explicit LauncherPartLaunch(LaunchTask *parent); + virtual void executeTask(); + virtual bool abort(); + virtual void proceed(); + virtual bool canAbort() const + { + return true; + } + void setWorkingDirectory(const QString &wd); + void setAuthSession(AuthSessionPtr session) + { + m_session = session; + } + +private slots: + void on_state(LoggedProcess::State state); + +private: + LoggedProcess m_process; + QString m_command; + AuthSessionPtr m_session; + QString m_launchScript; + bool mayProceed = false; +}; diff --git a/api/logic/minecraft/launch/PrintInstanceInfo.cpp b/api/logic/minecraft/launch/PrintInstanceInfo.cpp new file mode 100644 index 00000000..b863eb98 --- /dev/null +++ b/api/logic/minecraft/launch/PrintInstanceInfo.cpp @@ -0,0 +1,25 @@ +/* Copyright 2013-2016 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "PrintInstanceInfo.h" +#include + +void PrintInstanceInfo::executeTask() +{ + auto instance = m_parent->instance(); + auto lines = instance->verboseDescription(m_session); + logLines(lines, MessageLevel::MultiMC); + emitSucceeded(); +} diff --git a/api/logic/minecraft/launch/PrintInstanceInfo.h b/api/logic/minecraft/launch/PrintInstanceInfo.h new file mode 100644 index 00000000..5dd2bdb3 --- /dev/null +++ b/api/logic/minecraft/launch/PrintInstanceInfo.h @@ -0,0 +1,38 @@ +/* Copyright 2013-2016 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include "minecraft/auth/AuthSession.h" + +// FIXME: temporary wrapper for existing task. +class PrintInstanceInfo: public LaunchStep +{ + Q_OBJECT +public: + explicit PrintInstanceInfo(LaunchTask *parent, AuthSessionPtr session) : LaunchStep(parent), m_session(session) {}; + virtual ~PrintInstanceInfo(){}; + + virtual void executeTask(); + virtual bool canAbort() const + { + return false; + } +private: + AuthSessionPtr m_session; +}; + diff --git a/api/logic/minecraft/legacy/LegacyInstance.cpp b/api/logic/minecraft/legacy/LegacyInstance.cpp index 28fd8872..7c552369 100644 --- a/api/logic/minecraft/legacy/LegacyInstance.cpp +++ b/api/logic/minecraft/legacy/LegacyInstance.cpp @@ -14,6 +14,7 @@ */ #include +#include #include #include @@ -21,14 +22,6 @@ #include "minecraft/legacy/LegacyUpdate.h" #include "minecraft/legacy/LegacyModList.h" -#include "launch/LaunchTask.h" -#include -#include -#include -#include -#include "minecraft/launch/LaunchMinecraft.h" -#include "minecraft/launch/ModMinecraftJar.h" -#include "java/launch/CheckJava.h" #include "minecraft/ModList.h" #include "minecraft/WorldList.h" #include @@ -102,58 +95,6 @@ std::shared_ptr LegacyInstance::createUpdateTask() return std::shared_ptr(new LegacyUpdate(this, this)); } -std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr session) -{ - auto process = LaunchTask::create(std::dynamic_pointer_cast(getSharedPtr())); - auto pptr = process.get(); - - // print a header - { - process->appendStep(std::make_shared(pptr, "Minecraft folder is:\n" + minecraftRoot() + "\n\n", MessageLevel::MultiMC)); - } - { - auto step = std::make_shared(pptr); - process->appendStep(step); - } - // run pre-launch command if that's needed - if(getPreLaunchCommand().size()) - { - auto step = std::make_shared(pptr); - step->setWorkingDirectory(minecraftRoot()); - process->appendStep(step); - } - // if we aren't in offline mode,. - if(session->status != AuthSession::PlayableOffline) - { - process->appendStep(std::make_shared(pptr)); - } - // if there are any jar mods - if(getJarMods().size()) - { - auto step = std::make_shared(pptr); - process->appendStep(step); - } - // actually launch the game - { - auto step = std::make_shared(pptr); - step->setWorkingDirectory(minecraftRoot()); - step->setAuthSession(session); - process->appendStep(step); - } - // run post-exit command if that's needed - if(getPostExitCommand().size()) - { - auto step = std::make_shared(pptr); - step->setWorkingDirectory(minecraftRoot()); - process->appendStep(step); - } - if (session) - { - process->setCensorFilter(createCensorFilterFromSession(session)); - } - return process; -} - std::shared_ptr LegacyInstance::createJarModdingTask() { class JarModTask : public Task @@ -255,11 +196,35 @@ QString LegacyInstance::createLaunchScript(AuthSessionPtr session) launchScript += "sessionId " + session->session + "\n"; launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "windowParams " + windowParams + "\n"; - launchScript += "lwjgl " + lwjgl + "\n"; - launchScript += "launcher legacy\n"; + launchScript += "cp bin/minecraft.jar\n"; + launchScript += "cp " + lwjgl + "/lwjgl.jar\n"; + launchScript += "cp " + lwjgl + "/lwjgl_util.jar\n"; + launchScript += "cp " + lwjgl + "/jinput.jar\n"; + launchScript += "natives " + lwjgl + "/natives\n"; + launchScript += "traits legacyLaunch\n"; + launchScript += "launcher onesix\n"; return launchScript; } +std::shared_ptr LegacyInstance::createMainLaunchStep(LaunchTask * parent, AuthSessionPtr session) +{ + auto step = std::make_shared(parent); + step->setWorkingDirectory(minecraftRoot()); + step->setAuthSession(session); + return step; +} + +QString LegacyInstance::launchMethod() +{ + return "Legacy"; +} + +QStringList LegacyInstance::validLaunchMethods() +{ + return {"Legacy"}; +} + + void LegacyInstance::cleanupAfterRun() { // FIXME: delete the launcher and icons and whatnot. @@ -452,3 +417,112 @@ QString LegacyInstance::typeName() const { return tr("Legacy"); } + +QStringList LegacyInstance::verboseDescription(AuthSessionPtr session) +{ + QStringList out; + + auto alltraits = traits(); + if(alltraits.size()) + { + out << "Traits:"; + for (auto trait : alltraits) + { + out << " " + trait; + } + out << ""; + } + + if(loaderModList()->size()) + { + out << "Mods:"; + for(auto & mod: loaderModList()->allMods()) + { + if(!mod.enabled()) + continue; + if(mod.type() == Mod::MOD_FOLDER) + continue; + // TODO: proper implementation would need to descend into folders. + + out << " " + mod.filename().completeBaseName(); + } + out << ""; + } + + if(coreModList()->size()) + { + out << "Core Mods:"; + for(auto & coremod: coreModList()->allMods()) + { + if(!coremod.enabled()) + continue; + if(coremod.type() == Mod::MOD_FOLDER) + continue; + // TODO: proper implementation would need to descend into folders. + + out << " " + coremod.filename().completeBaseName(); + } + out << ""; + } + + if(jarModList()->size()) + { + out << "Jar Mods:"; + for(auto & jarmod: jarModList()->allMods()) + { + out << " " + jarmod.name() + " (" + jarmod.filename().filePath() + ")"; + } + out << ""; + } + + QString windowParams; + if (settings()->get("LaunchMaximized").toBool()) + { + out << "Window size: max (if available)"; + } + else + { + auto width = settings()->get("MinecraftWinWidth").toInt(); + auto height = settings()->get("MinecraftWinHeight").toInt(); + out << "Window size: " + QString::number(width) + " x " + QString::number(height); + } + out << ""; + return out; +} + +QStringList LegacyInstance::getClassPath() const +{ + QString launchScript; + QString lwjgl = getNativePath(); + QStringList out = + { + "bin/minecraft.jar", + lwjgl + "/lwjgl.jar", + lwjgl + "/lwjgl_util.jar", + lwjgl + "/jinput.jar" + }; + return out; +} + +QString LegacyInstance::getMainClass() const +{ + return "net.minecraft.client.Minecraft"; +} + +QString LegacyInstance::getNativePath() const +{ + return QDir(m_lwjglFolderSetting->get().toString() + "/" + lwjglVersion()).absolutePath(); +} + +QStringList LegacyInstance::getNativeJars() const +{ + return {}; +} + +QStringList LegacyInstance::processMinecraftArgs(AuthSessionPtr account) const +{ + QStringList out; + out.append(account->player_name); + out.append(account->session); + return out; +} diff --git a/api/logic/minecraft/legacy/LegacyInstance.h b/api/logic/minecraft/legacy/LegacyInstance.h index 88db5360..f1cefbcc 100644 --- a/api/logic/minecraft/legacy/LegacyInstance.h +++ b/api/logic/minecraft/legacy/LegacyInstance.h @@ -114,11 +114,7 @@ public: virtual bool shouldUpdate() const override; virtual void setShouldUpdate(bool val) override; virtual std::shared_ptr createUpdateTask() override; - - virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) override; - virtual std::shared_ptr createJarModdingTask() override; - virtual QString createLaunchScript(AuthSessionPtr session) override; virtual void cleanupAfterRun() override; @@ -130,6 +126,20 @@ public: return true; } + QStringList getClassPath() const override; + QString getMainClass() const override; + + QStringList getNativeJars() const override; + QString getNativePath() const override; + + QStringList processMinecraftArgs(AuthSessionPtr account) const override; + QStringList verboseDescription(AuthSessionPtr session) override; + +protected: + std::shared_ptr createMainLaunchStep(LaunchTask *parent, AuthSessionPtr session) override; + QStringList validLaunchMethods() override; + QString launchMethod() override; + protected: mutable std::shared_ptr jar_mod_list; mutable std::shared_ptr core_mod_list; diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp index a96704c8..8b5491e2 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.cpp +++ b/api/logic/minecraft/onesix/OneSixInstance.cpp @@ -14,6 +14,8 @@ */ #include +#include +#include #include #include "OneSixInstance.h" @@ -22,14 +24,7 @@ #include "minecraft/MinecraftProfile.h" #include "minecraft/VersionBuildError.h" -#include "launch/LaunchTask.h" -#include "launch/steps/PreLaunchCommand.h" -#include "launch/steps/Update.h" -#include "launch/steps/PostLaunchCommand.h" -#include "launch/steps/TextPrint.h" -#include "minecraft/launch/LaunchMinecraft.h" #include "minecraft/launch/ModMinecraftJar.h" -#include "java/launch/CheckJava.h" #include "MMCZip.h" #include "minecraft/AssetsUtils.h" @@ -94,7 +89,7 @@ QString replaceTokensIn(QString text, QMap with) return result; } -QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) +QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) const { QString args_pattern = m_profile->getMinecraftArguments(); for (auto tweaker : m_profile->getTweakers()) @@ -104,11 +99,16 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) QMap token_mapping; // yggdrasil! - token_mapping["auth_username"] = session->username; - token_mapping["auth_session"] = session->session; - token_mapping["auth_access_token"] = session->access_token; - token_mapping["auth_player_name"] = session->player_name; - token_mapping["auth_uuid"] = session->uuid; + if(session) + { + token_mapping["auth_username"] = session->username; + token_mapping["auth_session"] = session->session; + token_mapping["auth_access_token"] = session->access_token; + token_mapping["auth_player_name"] = session->player_name; + token_mapping["auth_uuid"] = session->uuid; + token_mapping["user_properties"] = session->serializeUserProperties(); + token_mapping["user_type"] = session->user_type; + } // blatant self-promotion. token_mapping["profile_name"] = token_mapping["version_name"] = "MultiMC5"; @@ -127,9 +127,6 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) auto assets = m_profile->getMinecraftAssets(); token_mapping["game_assets"] = AssetsUtils::reconstructAssets(assets->id).absolutePath(); - token_mapping["user_properties"] = session->serializeUserProperties(); - token_mapping["user_type"] = session->user_type; - // 1.7.3+ assets tokens token_mapping["assets_root"] = absAssetsDir; token_mapping["assets_index_name"] = assets->id; @@ -142,41 +139,34 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) return parts; } -QString OneSixInstance::createLaunchScript(AuthSessionPtr session) +QString OneSixInstance::getNativePath() const { - QString launchScript; - - if (!m_profile) - return nullptr; + QDir natives_dir(FS::PathCombine(instanceRoot(), "natives/")); + return natives_dir.absolutePath(); +} - for(auto & mod: loaderModList()->allMods()) +QString OneSixInstance::mainJarPath() const +{ + auto jarMods = getJarMods(); + if (!jarMods.isEmpty()) { - if(!mod.enabled()) - continue; - if(mod.type() == Mod::MOD_FOLDER) - continue; - // TODO: proper implementation would need to descend into folders. - - launchScript += "mod " + mod.filename().completeBaseName() + "\n";; + return QDir(instanceRoot()).absoluteFilePath("minecraft.jar"); } - - for(auto & coremod: coreModList()->allMods()) + else { - if(!coremod.enabled()) - continue; - if(coremod.type() == Mod::MOD_FOLDER) - continue; - // TODO: proper implementation would need to descend into folders. - - launchScript += "coremod " + coremod.filename().completeBaseName() + "\n";; + QString relpath = m_profile->getMinecraftVersion() + "/" + m_profile->getMinecraftVersion() + ".jar"; + return versionsPath().absoluteFilePath(relpath); } +} - for(auto & jarmod: m_profile->getJarMods()) - { - launchScript += "jarmod " + jarmod->originalName + " (" + jarmod->name + ")\n"; - } +QString OneSixInstance::createLaunchScript(AuthSessionPtr session) +{ + QString launchScript; - auto mainClass = m_profile->getMainClass(); + if (!m_profile) + return nullptr; + + auto mainClass = getMainClass(); if (!mainClass.isEmpty()) { launchScript += "mainClass " + mainClass + "\n"; @@ -207,6 +197,7 @@ QString OneSixInstance::createLaunchScript(AuthSessionPtr session) } // legacy auth + if(session) { launchScript += "userName " + session->player_name + "\n"; launchScript += "sessionId " + session->session + "\n"; @@ -214,44 +205,21 @@ QString OneSixInstance::createLaunchScript(AuthSessionPtr session) // libraries and class path. { - auto libs = m_profile->getLibraries(); - - QStringList jar, native, native32, native64; - for (auto lib : libs) - { - lib->getApplicableFiles(currentSystem, jar, native, native32, native64); - } - for(auto file: jar) + QStringList jars, nativeJars; + auto javaArchitecture = settings()->get("JavaArchitecture").toString(); + m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars); + for(auto file: jars) { launchScript += "cp " + file + "\n"; } - for(auto file: native) + launchScript += "cp " + mainJarPath() + "\n"; + for(auto file: nativeJars) { launchScript += "ext " + file + "\n"; } - for(auto file: native32) - { - launchScript += "ext32 " + file + "\n"; - } - for(auto file: native64) - { - launchScript += "ext64 " + file + "\n"; - } - QDir natives_dir(FS::PathCombine(instanceRoot(), "natives/")); - launchScript += "natives " + natives_dir.absolutePath() + "\n"; - auto jarMods = getJarMods(); - if (!jarMods.isEmpty()) - { - launchScript += "cp " + QDir(instanceRoot()).absoluteFilePath("minecraft.jar") + "\n"; - } - else - { - QString relpath = m_profile->getMinecraftVersion() + "/" + m_profile->getMinecraftVersion() + ".jar"; - launchScript += "cp " + versionsPath().absoluteFilePath(relpath) + "\n"; - } + launchScript += "natives " + getNativePath() + "\n"; } - // traits. including legacyLaunch and others ;) for (auto trait : m_profile->getTraits()) { launchScript += "traits " + trait + "\n"; @@ -260,58 +228,139 @@ QString OneSixInstance::createLaunchScript(AuthSessionPtr session) return launchScript; } -std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr session) +QStringList OneSixInstance::verboseDescription(AuthSessionPtr session) { - auto process = LaunchTask::create(std::dynamic_pointer_cast(getSharedPtr())); - auto pptr = process.get(); + QStringList out; + out << "Main Class:" << " " + getMainClass() << ""; + out << "Native path:" << " " + getNativePath() << ""; - // print a header + + auto alltraits = traits(); + if(alltraits.size()) { - process->appendStep(std::make_shared(pptr, "Minecraft folder is:\n" + minecraftRoot() + "\n\n", MessageLevel::MultiMC)); + out << "Traits:"; + for (auto trait : alltraits) + { + out << "traits " + trait; + } + out << ""; + } + + // libraries and class path. + { + out << "Libraries:"; + QStringList jars, nativeJars; + auto javaArchitecture = settings()->get("JavaArchitecture").toString(); + m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars); + auto printLibFile = [&](const QString & path) + { + QFileInfo info(path); + if(info.exists()) + { + out << " " + path; + } + else + { + out << " " + path + " (missing)"; + } + }; + for(auto file: jars) + { + printLibFile(file); + } + printLibFile(mainJarPath()); + for(auto file: nativeJars) + { + printLibFile(file); + } + out << ""; } + + if(loaderModList()->size()) { - auto step = std::make_shared(pptr); - process->appendStep(step); + out << "Mods:"; + for(auto & mod: loaderModList()->allMods()) + { + if(!mod.enabled()) + continue; + if(mod.type() == Mod::MOD_FOLDER) + continue; + // TODO: proper implementation would need to descend into folders. + + out << " " + mod.filename().completeBaseName(); + } + out << ""; } - // run pre-launch command if that's needed - if(getPreLaunchCommand().size()) + + if(coreModList()->size()) { - auto step = std::make_shared(pptr); - step->setWorkingDirectory(minecraftRoot()); - process->appendStep(step); + out << "Core Mods:"; + for(auto & coremod: coreModList()->allMods()) + { + if(!coremod.enabled()) + continue; + if(coremod.type() == Mod::MOD_FOLDER) + continue; + // TODO: proper implementation would need to descend into folders. + + out << " " + coremod.filename().completeBaseName(); + } + out << ""; } - // if we aren't in offline mode,. - if(session->status != AuthSession::PlayableOffline) + + auto & jarMods = m_profile->getJarMods(); + if(jarMods.size()) { - process->appendStep(std::make_shared(pptr)); + out << "Jar Mods:"; + for(auto & jarmod: jarMods) + { + out << " " + jarmod->originalName + " (" + jarmod->name + ")"; + } + out << ""; } - // if there are any jar mods - if(getJarMods().size()) + + auto params = processMinecraftArgs(nullptr); + out << "Params:"; + out << " " + params.join(' '); + out << ""; + + QString windowParams; + if (settings()->get("LaunchMaximized").toBool()) { - auto step = std::make_shared(pptr); - process->appendStep(step); + out << "Window size: max (if available)"; } - // actually launch the game + else { - auto step = std::make_shared(pptr); - step->setWorkingDirectory(minecraftRoot()); - step->setAuthSession(session); - process->appendStep(step); + auto width = settings()->get("MinecraftWinWidth").toInt(); + auto height = settings()->get("MinecraftWinHeight").toInt(); + out << "Window size: " + QString::number(width) + " x " + QString::number(height); } - // run post-exit command if that's needed - if(getPostExitCommand().size()) + out << ""; + return out; +} + + +std::shared_ptr OneSixInstance::createMainLaunchStep(LaunchTask * parent, AuthSessionPtr session) +{ + auto method = launchMethod(); + if(method == "LauncherPart") { - auto step = std::make_shared(pptr); + auto step = std::make_shared(parent); + step->setAuthSession(session); step->setWorkingDirectory(minecraftRoot()); - process->appendStep(step); + return step; } - if (session) + else if (method == "DirectJava") { - process->setCensorFilter(createCensorFilterFromSession(session)); + auto step = std::make_shared(parent); + step->setWorkingDirectory(minecraftRoot()); + step->setAuthSession(session); + return step; } - return process; + return nullptr; } + std::shared_ptr OneSixInstance::createJarModdingTask() { class JarModTask : public Task @@ -595,3 +644,30 @@ QString OneSixInstance::typeName() const { return tr("OneSix"); } + +QStringList OneSixInstance::validLaunchMethods() +{ + return {"LauncherPart", "DirectJava"}; +} + +QStringList OneSixInstance::getClassPath() const +{ + QStringList jars, nativeJars; + auto javaArchitecture = settings()->get("JavaArchitecture").toString(); + m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars); + jars.append(mainJarPath()); + return jars; +} + +QString OneSixInstance::getMainClass() const +{ + return m_profile->getMainClass(); +} + +QStringList OneSixInstance::getNativeJars() const +{ + QStringList jars, nativeJars; + auto javaArchitecture = settings()->get("JavaArchitecture").toString(); + m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars); + return nativeJars; +} diff --git a/api/logic/minecraft/onesix/OneSixInstance.h b/api/logic/minecraft/onesix/OneSixInstance.h index 2dfab48c..1a917e79 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.h +++ b/api/logic/minecraft/onesix/OneSixInstance.h @@ -53,10 +53,9 @@ public: virtual QString instanceConfigFolder() const override; virtual std::shared_ptr createUpdateTask() override; - virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) override; virtual std::shared_ptr createJarModdingTask() override; - virtual QString createLaunchScript(AuthSessionPtr session) override; + QStringList verboseDescription(AuthSessionPtr session) override; virtual void cleanupAfterRun() override; @@ -99,11 +98,23 @@ public: return true; } + QStringList getClassPath() const override; + QString getMainClass() const override; + + QStringList getNativeJars() const override; + QString getNativePath() const override; + + QStringList processMinecraftArgs(AuthSessionPtr account) const override; + +protected: + std::shared_ptr createMainLaunchStep(LaunchTask *parent, AuthSessionPtr session) override; + QStringList validLaunchMethods() override; + signals: void versionReloaded(); private: - QStringList processMinecraftArgs(AuthSessionPtr account); + QString mainJarPath() const; protected: std::shared_ptr m_profile; -- cgit v1.2.3