From ff67fd10c33fa99423b5a43dcbd30494b4c40dc5 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 17 Jul 2023 10:57:41 +0200 Subject: [PATCH 1/7] feat: implement override for GLFW/OpenAL with split natives Fixes PrismLauncher/PrismLauncher#513 Signed-off-by: Sefa Eyeoglu --- launcher/MangoHud.cpp | 43 ++++++++++++++++++++ launcher/MangoHud.h | 4 +- launcher/minecraft/MinecraftInstance.cpp | 18 ++++++++ launcher/minecraft/launch/ExtractNatives.cpp | 10 ++--- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/launcher/MangoHud.cpp b/launcher/MangoHud.cpp index 5758da3aa..ab79f418b 100644 --- a/launcher/MangoHud.cpp +++ b/launcher/MangoHud.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -26,6 +27,15 @@ #include "Json.h" #include "MangoHud.h" +#ifdef __GLIBC__ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#define UNDEF_GNU_SOURCE +#endif +#include +#include +#endif + namespace MangoHud { QString getLibraryString() @@ -106,4 +116,37 @@ QString getLibraryString() return QString(); } + +QString findLibrary(QString libName) +{ +#ifdef __GLIBC__ + const char* library = libName.toLocal8Bit().constData(); + + void* handle = dlopen(library, RTLD_NOW); + if (!handle) { + qCritical() << "dlopen() failed:" << dlerror(); + return {}; + } + + char path[PATH_MAX]; + if (dlinfo(handle, RTLD_DI_ORIGIN, path) == -1) { + qCritical() << "dlinfo() failed:" << dlerror(); + dlclose(handle); + return {}; + } + + auto fullPath = FS::PathCombine(QString(path), libName); + + dlclose(handle); + return fullPath; +#else + qWarning() << "MangoHud::findLibrary is not implemented on this platform"; + return {}; +#endif +} } // namespace MangoHud + +#ifdef UNDEF_GNU_SOURCE +#undef _GNU_SOURCE +#undef UNDEF_GNU_SOURCE +#endif diff --git a/launcher/MangoHud.h b/launcher/MangoHud.h index 7b7c2849c..5361999b4 100644 --- a/launcher/MangoHud.h +++ b/launcher/MangoHud.h @@ -24,4 +24,6 @@ namespace MangoHud { QString getLibraryString(); -} + +QString findLibrary(QString libName); +} // namespace MangoHud diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 305bff67b..40fde6cb3 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -389,6 +389,24 @@ QStringList MinecraftInstance::extraArguments() if (loaders.has_value() && loaders.value() & ResourceAPI::Quilt && settings()->get("DisableQuiltBeacon").toBool()) list.append("-Dloader.disable_beacon=true"); } + +#ifdef Q_OS_LINUX + { + QString openALPath; + QString glfwPath; + + if (settings()->get("UseNativeOpenAL").toBool()) + openALPath = MangoHud::findLibrary("libopenal.so"); + if (settings()->get("UseNativeGLFW").toBool()) + glfwPath = MangoHud::findLibrary("libglfw.so"); + + if (!openALPath.isEmpty()) + list.append("-Dorg.lwjgl.openal.libname=" + openALPath); + if (!glfwPath.isEmpty()) + list.append("-Dorg.lwjgl.glfw.libname=" + glfwPath); + } +#endif + return list; } diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index cebeaedd4..1aa4dccc4 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -39,7 +39,7 @@ static QString replaceSuffix(QString target, const QString& suffix, const QStrin return target + replacement; } -static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack, bool nativeOpenAL, bool nativeGLFW) +static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack, bool nativeOpenAL) { QuaZip zip(source); if (!zip.open(QuaZip::mdUnzip)) { @@ -52,9 +52,6 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH do { QString name = zip.getCurrentFileName(); auto lowercase = name.toLower(); - if (nativeGLFW && name.contains("glfw")) { - continue; - } if (nativeOpenAL && name.contains("openal")) { continue; } @@ -83,14 +80,15 @@ void ExtractNatives::executeTask() return; } auto settings = minecraftInstance->settings(); + + // We only need OpenAL here, as modern versions of LWJGL (3+) are handled by JVM args, while older versions (2) didn't have GLFW bool nativeOpenAL = settings->get("UseNativeOpenAL").toBool(); - bool nativeGLFW = settings->get("UseNativeGLFW").toBool(); auto outputPath = minecraftInstance->getNativePath(); auto javaVersion = minecraftInstance->getJavaVersion(); bool jniHackEnabled = javaVersion.major() >= 8; for (const auto& source : toExtract) { - if (!unzipNatives(source, outputPath, jniHackEnabled, nativeOpenAL, nativeGLFW)) { + if (!unzipNatives(source, outputPath, jniHackEnabled, nativeOpenAL)) { const char* reason = QT_TR_NOOP("Couldn't extract native jar '%1' to destination '%2'"); emit logLine(QString(reason).arg(source, outputPath), MessageLevel::Fatal); emitFailed(tr(reason).arg(source, outputPath)); From 83aa0062c7d831ca42ed4d82e5f6162ac8793be8 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 13:45:08 +0200 Subject: [PATCH 2/7] feat: add custom native library path settings Signed-off-by: Sefa Eyeoglu --- CMakeLists.txt | 12 +++++ buildconfig/BuildConfig.cpp.in | 3 ++ buildconfig/BuildConfig.h | 3 ++ launcher/Application.cpp | 13 ++++++ launcher/Application.h | 4 ++ launcher/minecraft/MinecraftInstance.cpp | 20 ++++++--- launcher/ui/pages/global/MinecraftPage.cpp | 35 ++++++++++++++- launcher/ui/pages/global/MinecraftPage.h | 3 ++ launcher/ui/pages/global/MinecraftPage.ui | 40 +++++++++++++++-- .../pages/instance/InstanceSettingsPage.cpp | 34 +++++++++++++- .../ui/pages/instance/InstanceSettingsPage.h | 3 ++ .../ui/pages/instance/InstanceSettingsPage.ui | 44 ++++++++++++++++--- 12 files changed, 196 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2853cb5a..a8dd7a73d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,6 +216,18 @@ set(Launcher_SUBREDDIT_URL "https://prismlauncher.org/reddit" CACHE STRING "URL set(Launcher_FORCE_BUNDLED_LIBS OFF CACHE BOOL "Prevent using system libraries, if they are available as submodules") set(Launcher_QT_VERSION_MAJOR "6" CACHE STRING "Major Qt version to build against") +# Native libraries +if(UNIX AND APPLE) + set(Launcher_GLFW_LIBRARY_NAME "libglfw.dylib" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "libopenal.dylib" CACHE STRING "Name of native glfw library") +elseif(UNIX) + set(Launcher_GLFW_LIBRARY_NAME "libglfw.so" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "libopenal.so" CACHE STRING "Name of native glfw library") +elseif(WIN32) + set(Launcher_GLFW_LIBRARY_NAME "glfw.dll" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "OpenAL.dll" CACHE STRING "Name of native glfw library") +endif() + # API Keys # NOTE: These API keys are here for convenience. If you rebrand this software or intend to break the terms of service # of these platforms, please change these API keys beforehand. diff --git a/buildconfig/BuildConfig.cpp.in b/buildconfig/BuildConfig.cpp.in index d7662a7a4..1eb0022b8 100644 --- a/buildconfig/BuildConfig.cpp.in +++ b/buildconfig/BuildConfig.cpp.in @@ -110,6 +110,9 @@ Config::Config() FLAME_API_KEY = "@Launcher_CURSEFORGE_API_KEY@"; META_URL = "@Launcher_META_URL@"; + GLFW_LIBRARY_NAME = "@Launcher_GLFW_LIBRARY_NAME@"; + OPENAL_LIBRARY_NAME = "@Launcher_OPENAL_LIBRARY_NAME@"; + BUG_TRACKER_URL = "@Launcher_BUG_TRACKER_URL@"; TRANSLATIONS_URL = "@Launcher_TRANSLATIONS_URL@"; MATRIX_URL = "@Launcher_MATRIX_URL@"; diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 387f494f3..a5649b98f 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -134,6 +134,9 @@ class Config { */ QString META_URL; + QString GLFW_LIBRARY_NAME; + QString OPENAL_LIBRARY_NAME; + QString BUG_TRACKER_URL; QString TRANSLATIONS_URL; QString MATRIX_URL; diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a13935101..6daa5a84b 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -582,7 +582,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) // Native library workarounds m_settings->registerSetting("UseNativeOpenAL", false); + m_settings->registerSetting("CustomOpenALPath", ""); m_settings->registerSetting("UseNativeGLFW", false); + m_settings->registerSetting("CustomGLFWPath", ""); // Peformance related options m_settings->registerSetting("EnableFeralGamemode", false); @@ -842,6 +844,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) updateCapabilities(); + detectLibraries(); + if (createSetupWizard()) { return; } @@ -1412,6 +1416,15 @@ void Application::updateCapabilities() #endif } +void Application::detectLibraries() +{ +#ifdef Q_OS_LINUX + m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME); + m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME); + qDebug() << m_detectedGLFWPath << m_detectedOpenALPath; +#endif +} + QString Application::getJarPath(QString jarFile) { QStringList potentialPaths = { diff --git a/launcher/Application.h b/launcher/Application.h index 6bc332749..5807107cf 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -142,6 +142,8 @@ class Application : public QApplication { void updateCapabilities(); + void detectLibraries(); + /*! * Finds and returns the full path to a jar file. * Returns a null-string if it could not be found. @@ -275,6 +277,8 @@ class Application : public QApplication { SetupWizard* m_setupWizard = nullptr; public: + QString m_detectedGLFWPath; + QString m_detectedOpenALPath; QString m_instanceIdToLaunch; QString m_serverToJoin; QString m_profileToUse; diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 40fde6cb3..bfc4ad98a 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -166,7 +166,9 @@ void MinecraftInstance::loadSpecificSettings() // Native library workarounds auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false); m_settings->registerOverride(global_settings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("CustomOpenALPath"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("CustomGLFWPath"), nativeLibraryWorkaroundsOverride); // Peformance related options auto performanceOverride = m_settings->registerSetting("OverridePerformance", false); @@ -390,22 +392,28 @@ QStringList MinecraftInstance::extraArguments() list.append("-Dloader.disable_beacon=true"); } -#ifdef Q_OS_LINUX { QString openALPath; QString glfwPath; - if (settings()->get("UseNativeOpenAL").toBool()) - openALPath = MangoHud::findLibrary("libopenal.so"); - if (settings()->get("UseNativeGLFW").toBool()) - glfwPath = MangoHud::findLibrary("libglfw.so"); + if (settings()->get("UseNativeOpenAL").toBool()) { + auto customPath = settings()->get("CustomOpenALPath").toString(); + openALPath = APPLICATION->m_detectedOpenALPath; + if (!customPath.isEmpty()) + openALPath = customPath; + } + if (settings()->get("UseNativeGLFW").toBool()) { + auto customPath = settings()->get("CustomGLFWPath").toString(); + glfwPath = APPLICATION->m_detectedGLFWPath; + if (!customPath.isEmpty()) + glfwPath = customPath; + } if (!openALPath.isEmpty()) list.append("-Dorg.lwjgl.openal.libname=" + openALPath); if (!glfwPath.isEmpty()) list.append("-Dorg.lwjgl.glfw.libname=" + glfwPath); } -#endif return list; } diff --git a/launcher/ui/pages/global/MinecraftPage.cpp b/launcher/ui/pages/global/MinecraftPage.cpp index 866a4121c..1c7747210 100644 --- a/launcher/ui/pages/global/MinecraftPage.cpp +++ b/launcher/ui/pages/global/MinecraftPage.cpp @@ -35,6 +35,7 @@ */ #include "MinecraftPage.h" +#include "BuildConfig.h" #include "ui_MinecraftPage.h" #include @@ -44,9 +45,15 @@ #include "Application.h" #include "settings/SettingsObject.h" +#ifdef Q_OS_LINUX +#include "MangoHud.h" +#endif + MinecraftPage::MinecraftPage(QWidget* parent) : QWidget(parent), ui(new Ui::MinecraftPage) { ui->setupUi(this); + connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeGLFWChanged); + connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeOpenALChanged); loadSettings(); updateCheckboxStuff(); } @@ -74,6 +81,16 @@ void MinecraftPage::on_maximizedCheckBox_clicked(bool checked) updateCheckboxStuff(); } +void MinecraftPage::onUseNativeGLFWChanged(bool checked) +{ + ui->lineEditGLFWPath->setEnabled(checked); +} + +void MinecraftPage::onUseNativeOpenALChanged(bool checked) +{ + ui->lineEditOpenALPath->setEnabled(checked); +} + void MinecraftPage::applySettings() { auto s = APPLICATION->settings(); @@ -84,8 +101,10 @@ void MinecraftPage::applySettings() s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); // Native library workarounds - s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); + s->set("CustomGLFWPath", ui->lineEditGLFWPath->text()); + s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); + s->set("CustomOpenALPath", ui->lineEditOpenALPath->text()); // Peformance related options s->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked()); @@ -114,8 +133,20 @@ void MinecraftPage::loadSettings() ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); - ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool()); ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool()); + ui->lineEditGLFWPath->setText(s->get("CustomGLFWPath").toString()); + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME)); +#ifdef Q_OS_LINUX + if (!APPLICATION->m_detectedGLFWPath.isEmpty()) + ui->lineEditGLFWPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedGLFWPath)); +#endif + ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool()); + ui->lineEditOpenALPath->setText(s->get("CustomOpenALPath").toString()); + ui->lineEditOpenALPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME)); +#ifdef Q_OS_LINUX + if (!APPLICATION->m_detectedOpenALPath.isEmpty()) + ui->lineEditOpenALPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedOpenALPath)); +#endif ui->enableFeralGamemodeCheck->setChecked(s->get("EnableFeralGamemode").toBool()); ui->enableMangoHud->setChecked(s->get("EnableMangoHud").toBool()); diff --git a/launcher/ui/pages/global/MinecraftPage.h b/launcher/ui/pages/global/MinecraftPage.h index 28c31b5d8..5facfbb3f 100644 --- a/launcher/ui/pages/global/MinecraftPage.h +++ b/launcher/ui/pages/global/MinecraftPage.h @@ -70,6 +70,9 @@ class MinecraftPage : public QWidget, public BasePage { private slots: void on_maximizedCheckBox_clicked(bool checked); + void onUseNativeGLFWChanged(bool checked); + void onUseNativeOpenALChanged(bool checked); + private: Ui::MinecraftPage* ui; }; diff --git a/launcher/ui/pages/global/MinecraftPage.ui b/launcher/ui/pages/global/MinecraftPage.ui index 393b0f358..98e90e4ec 100644 --- a/launcher/ui/pages/global/MinecraftPage.ui +++ b/launcher/ui/pages/global/MinecraftPage.ui @@ -214,21 +214,55 @@ Native library workarounds - - + + Use system installation of &GLFW - + + + + &GLFW library path + + + lineEditGLFWPath + + + + Use system installation of &OpenAL + + + + &OpenAL library path + + + lineEditOpenALPath + + + + + + + false + + + + + + + false + + + diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index f7be91684..d603237b6 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -66,6 +66,10 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent) connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings); connect(ui->instanceAccountSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &InstanceSettingsPage::changeInstanceAccount); + + connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeGLFWChanged); + connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeOpenALChanged); + loadSettings(); updateThresholds(); @@ -198,11 +202,15 @@ void InstanceSettingsPage::applySettings() bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked(); m_settings->set("OverrideNativeWorkarounds", workarounds); if (workarounds) { - m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); + m_settings->set("CustomGLFWPath", ui->lineEditGLFWPath->text()); + m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); + m_settings->set("CustomOpenALPath", ui->lineEditOpenALPath->text()); } else { - m_settings->reset("UseNativeOpenAL"); m_settings->reset("UseNativeGLFW"); + m_settings->reset("CustomGLFWPath"); + m_settings->reset("UseNativeOpenAL"); + m_settings->reset("CustomOpenALPath"); } // Performance @@ -312,7 +320,19 @@ void InstanceSettingsPage::loadSettings() // Workarounds ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool()); ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool()); + ui->lineEditGLFWPath->setText(m_settings->get("CustomGLFWPath").toString()); +#ifdef Q_OS_LINUX + ui->lineEditGLFWPath->setPlaceholderText(APPLICATION->m_detectedGLFWPath); +#else + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME)); +#endif ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool()); + ui->lineEditOpenALPath->setText(m_settings->get("CustomOpenALPath").toString()); +#ifdef Q_OS_LINUX + ui->lineEditOpenALPath->setPlaceholderText(APPLICATION->m_detectedOpenALPath); +#else + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME)); +#endif // Performance ui->perfomanceGroupBox->setChecked(m_settings->get("OverridePerformance").toBool()); @@ -408,6 +428,16 @@ void InstanceSettingsPage::on_javaTestBtn_clicked() checker->run(); } +void InstanceSettingsPage::onUseNativeGLFWChanged(bool checked) +{ + ui->lineEditGLFWPath->setEnabled(checked); +} + +void InstanceSettingsPage::onUseNativeOpenALChanged(bool checked) +{ + ui->lineEditOpenALPath->setEnabled(checked); +} + void InstanceSettingsPage::updateAccountsMenu() { ui->instanceAccountSelector->clear(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 21ecbaf8e..8b78dcb7f 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -71,6 +71,9 @@ class InstanceSettingsPage : public QWidget, public BasePage { void on_javaBrowseBtn_clicked(); void on_maxMemSpinBox_valueChanged(int i); + void onUseNativeGLFWChanged(bool checked); + void onUseNativeOpenALChanged(bool checked); + void applySettings(); void loadSettings(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 380d8c88c..fcc2a5d0a 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -443,18 +443,52 @@ false - - + + + + + Use system installation of OpenAL + + + + + + + &GLFW library path + + + lineEditGLFWPath + + + + Use system installation of GLFW - - + + + + false + + + + + - Use system installation of OpenAL + &OpenAL library path + + + lineEditOpenALPath + + + + + + + false From 4c446ccd500f7a0bc136b66b554fd7880c6f5168 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 13:47:50 +0200 Subject: [PATCH 3/7] fix: remove meta OpenAL workaround LWJGL 2 doesn't have a separate zip for OpenAL. So there is no reason for this code. Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/launch/ExtractNatives.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index 1aa4dccc4..8f3cac4d1 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -39,7 +39,7 @@ static QString replaceSuffix(QString target, const QString& suffix, const QStrin return target + replacement; } -static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack, bool nativeOpenAL) +static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack) { QuaZip zip(source); if (!zip.open(QuaZip::mdUnzip)) { @@ -52,9 +52,6 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH do { QString name = zip.getCurrentFileName(); auto lowercase = name.toLower(); - if (nativeOpenAL && name.contains("openal")) { - continue; - } if (applyJnilibHack) { name = replaceSuffix(name, ".jnilib", ".dylib"); } @@ -81,14 +78,11 @@ void ExtractNatives::executeTask() } auto settings = minecraftInstance->settings(); - // We only need OpenAL here, as modern versions of LWJGL (3+) are handled by JVM args, while older versions (2) didn't have GLFW - bool nativeOpenAL = settings->get("UseNativeOpenAL").toBool(); - auto outputPath = minecraftInstance->getNativePath(); auto javaVersion = minecraftInstance->getJavaVersion(); bool jniHackEnabled = javaVersion.major() >= 8; for (const auto& source : toExtract) { - if (!unzipNatives(source, outputPath, jniHackEnabled, nativeOpenAL)) { + if (!unzipNatives(source, outputPath, jniHackEnabled)) { const char* reason = QT_TR_NOOP("Couldn't extract native jar '%1' to destination '%2'"); emit logLine(QString(reason).arg(source, outputPath), MessageLevel::Fatal); emitFailed(tr(reason).arg(source, outputPath)); From f1c3da6583d004273e5812a0b40977200ce330d6 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 13:49:59 +0200 Subject: [PATCH 4/7] fix: fix typo Signed-off-by: Sefa Eyeoglu --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8dd7a73d..638fba051 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,13 +219,13 @@ set(Launcher_QT_VERSION_MAJOR "6" CACHE STRING "Major Qt version to build agains # Native libraries if(UNIX AND APPLE) set(Launcher_GLFW_LIBRARY_NAME "libglfw.dylib" CACHE STRING "Name of native glfw library") - set(Launcher_OPENAL_LIBRARY_NAME "libopenal.dylib" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "libopenal.dylib" CACHE STRING "Name of native openal library") elseif(UNIX) set(Launcher_GLFW_LIBRARY_NAME "libglfw.so" CACHE STRING "Name of native glfw library") - set(Launcher_OPENAL_LIBRARY_NAME "libopenal.so" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "libopenal.so" CACHE STRING "Name of native openal library") elseif(WIN32) set(Launcher_GLFW_LIBRARY_NAME "glfw.dll" CACHE STRING "Name of native glfw library") - set(Launcher_OPENAL_LIBRARY_NAME "OpenAL.dll" CACHE STRING "Name of native glfw library") + set(Launcher_OPENAL_LIBRARY_NAME "OpenAL.dll" CACHE STRING "Name of native openal library") endif() # API Keys From b927e58126440d735803251caa3e03d29e4a0547 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 13:51:13 +0200 Subject: [PATCH 5/7] fix: improve debug message Signed-off-by: Sefa Eyeoglu --- launcher/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 6daa5a84b..0f25589ed 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1421,7 +1421,7 @@ void Application::detectLibraries() #ifdef Q_OS_LINUX m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME); m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME); - qDebug() << m_detectedGLFWPath << m_detectedOpenALPath; + qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath; #endif } From c2d6a137aba6d41df709c73096f4521df3779304 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 13:56:23 +0200 Subject: [PATCH 6/7] fix: only add native library overrides if files exist Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/MinecraftInstance.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index bfc4ad98a..62d22019f 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -397,22 +397,25 @@ QStringList MinecraftInstance::extraArguments() QString glfwPath; if (settings()->get("UseNativeOpenAL").toBool()) { - auto customPath = settings()->get("CustomOpenALPath").toString(); openALPath = APPLICATION->m_detectedOpenALPath; + auto customPath = settings()->get("CustomOpenALPath").toString(); if (!customPath.isEmpty()) openALPath = customPath; } if (settings()->get("UseNativeGLFW").toBool()) { - auto customPath = settings()->get("CustomGLFWPath").toString(); glfwPath = APPLICATION->m_detectedGLFWPath; + auto customPath = settings()->get("CustomGLFWPath").toString(); if (!customPath.isEmpty()) glfwPath = customPath; } - if (!openALPath.isEmpty()) - list.append("-Dorg.lwjgl.openal.libname=" + openALPath); - if (!glfwPath.isEmpty()) - list.append("-Dorg.lwjgl.glfw.libname=" + glfwPath); + QFileInfo openALInfo(openALPath); + QFileInfo glfwInfo(glfwPath); + + if (!openALPath.isEmpty() && openALInfo.exists()) + list.append("-Dorg.lwjgl.openal.libname=" + openALInfo.absoluteFilePath()); + if (!glfwPath.isEmpty() && glfwInfo.exists()) + list.append("-Dorg.lwjgl.glfw.libname=" + glfwInfo.absoluteFilePath()); } return list; From 06aba530d7154f0cff76b2d5dc650a428ff1a54e Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 14:22:55 +0200 Subject: [PATCH 7/7] fix: add missing header Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/instance/InstanceSettingsPage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index d603237b6..108f2c274 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -48,6 +48,7 @@ #include "ui/widgets/CustomCommands.h" #include "Application.h" +#include "BuildConfig.h" #include "JavaCommon.h" #include "minecraft/auth/AccountList.h"