From 229a6bc788fe4601fbe00288fcccdedb9396340f Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Thu, 10 Sep 2020 16:59:35 +0200 Subject: [PATCH] Correctly implement FindPluginPath for Linux --- src/mupenplus/CommonAPIImpl_mupenplus.cpp | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mupenplus/CommonAPIImpl_mupenplus.cpp b/src/mupenplus/CommonAPIImpl_mupenplus.cpp index bc3c06d4..6bab61f6 100644 --- a/src/mupenplus/CommonAPIImpl_mupenplus.cpp +++ b/src/mupenplus/CommonAPIImpl_mupenplus.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "../PluginAPI.h" #include "../RSP.h" @@ -71,6 +72,32 @@ void PluginAPI::FindPluginPath(wchar_t * _strPath) GetModuleFileNameW(nullptr, _strPath, PLUGIN_PATH_SIZE); _cutLastPathSeparator(_strPath); #elif defined(OS_LINUX) + std::ifstream maps; + std::string line; + std::size_t loc; + maps.open("/proc/self/maps"); + + if (maps.is_open()) + { + while (getline(maps, line)) + { + loc = line.find('/'); + if (loc == std::string::npos) + continue; + + line = line.substr(loc); + + if (line.find("GLideN64") != std::string::npos) + { + _getWSPath(line.c_str(), _strPath); + maps.close(); + return; + } + } + + maps.close(); + } + char path[512]; int res = readlink("/proc/self/exe", path, 510); if (res != -1) {