Skip to content

Commit

Permalink
chore: replace naive mangohud preload with vklayer detection
Browse files Browse the repository at this point in the history
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
  • Loading branch information
Jan200101 committed Dec 9, 2022
1 parent ab0d445 commit 1210957
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions launcher/minecraft/MinecraftInstance.cpp
Expand Up @@ -43,6 +43,7 @@
#include "settings/Setting.h"
#include "settings/SettingsObject.h"
#include "Application.h"
#include "MangoHud.h"

#include "pathmatcher/RegexpMatcher.h"
#include "pathmatcher/MultiMatcher.h"
Expand Down Expand Up @@ -482,12 +483,22 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
#ifdef Q_OS_LINUX
if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud)
{
auto preload = env.value("LD_PRELOAD", "") + ":libMangoHud_dlsym.so:libMangoHud.so";
// $LIB/mangohud is a supported lib path by upstream, do not remove
auto lib_path = env.value("LD_LIBRARY_PATH", "") + ":/usr/local/$LIB/mangohud/:/usr/$LIB/mangohud/";

env.insert("LD_PRELOAD", preload);
env.insert("LD_LIBRARY_PATH", lib_path);
auto preloadList = env.value("LD_PRELOAD").split(QLatin1String(":"));
auto libPaths = env.value("LD_LIBRARY_PATH").split(QLatin1String(":"));

auto mangoHudLibString = MangoHud::getLibraryString();
if (!mangoHudLibString.isEmpty())
{
QFileInfo mangoHudLib(mangoHudLibString);

// dlsym variant is only needed for OpenGL and not included in the vulkan layer
preloadList << "libMangoHud_dlsym.so" << mangoHudLib.fileName();
libPaths << mangoHudLib.absolutePath();
}

env.insert("LD_PRELOAD", preloadList.join(QLatin1String(":")));
env.insert("LD_LIBRARY_PATH", libPaths.join(QLatin1String(":")));
env.insert("MANGOHUD", "1");
}

Expand Down

0 comments on commit 1210957

Please sign in to comment.