Merge pull request #131 from Sporif/blacklist_v2

Blacklist: Add OpenGL and fix `mangohud steam`
pull/139/head
jackun 4 years ago committed by GitHub
commit ebdaa901b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,3 +8,4 @@ option('with_xnvctrl', type : 'feature', value : 'enabled', description: 'Enable
option('with_x11', type : 'feature', value : 'enabled')
option('with_wayland', type : 'feature', value : 'disabled')
option('with_dbus', type : 'feature', value : 'enabled')
option('with_dlsym', type : 'feature', value : 'disabled')

@ -0,0 +1,59 @@
#include <vector>
#include <string>
#include <algorithm>
#include "blacklist.h"
#include "string_utils.h"
#include "file_utils.h"
static std::string get_proc_name() {
#ifdef _GNU_SOURCE_OFF
std::string p(program_invocation_name);
std::string proc_name = p.substr(p.find_last_of("/\\") + 1);
#else
std::string p = get_exe_path();
std::string proc_name;
if (ends_with(p, "wine-preloader") || ends_with(p, "wine64-preloader")) {
get_wine_exe_name(proc_name, true);
} else {
proc_name = p.substr(p.find_last_of("/\\") + 1);
}
#endif
return proc_name;
}
static bool check_blacklisted() {
std::vector<std::string> blacklist {
"Battle.net.exe",
"BethesdaNetLauncher.exe",
"EpicGamesLauncher.exe",
"IGOProxy.exe",
"IGOProxy64.exe",
"Origin.exe",
"OriginThinSetupInternal.exe",
"steam",
"steamwebhelper",
"gldriverquery",
"vulkandriverquery",
"Steam.exe",
};
std::string proc_name = get_proc_name();
bool blacklisted = std::find(blacklist.begin(), blacklist.end(), proc_name) != blacklist.end();
#ifndef NDEBUG
std::cerr << "MANGOHUD: process " << proc_name << " is blacklisted: " << blacklisted << std::endl;
#endif
return blacklisted;
}
bool& is_blacklisted() {
static bool checked = false;
static bool blacklisted = false;
if (!checked) {
checked = true;
blacklisted = check_blacklisted();
}
return blacklisted;
}

@ -0,0 +1,3 @@
#pragma once
bool& is_blacklisted();

@ -4,6 +4,7 @@
#include "real_dlsym.h"
#include "mesa/util/macros.h"
#include "mesa/util/os_time.h"
#include "blacklist.h"
#include <chrono>
#include <iomanip>
@ -51,6 +52,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
if (!pfn_eglSwapBuffers)
pfn_eglSwapBuffers = reinterpret_cast<decltype(pfn_eglSwapBuffers)>(get_proc_address("eglSwapBuffers"));
if (!is_blacklisted()) {
static int (*pfn_eglQuerySurface)(void* dpy, void* surface, int attribute, int *value) = nullptr;
if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_proc_address("eglQuerySurface"));
@ -66,6 +68,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
imgui_render(width, height);
//std::cerr << "\t" << width << " x " << height << "\n";
}
return pfn_eglSwapBuffers(dpy, surf);
}
@ -83,6 +86,9 @@ static std::array<const func_ptr, 1> name_to_funcptr_map = {{
void *find_egl_ptr(const char *name)
{
if (is_blacklisted())
return nullptr;
for (auto& func : name_to_funcptr_map) {
if (strcmp(name, func.name) == 0)
return func.ptr;

@ -7,6 +7,7 @@
#include "loaders/loader_x11.h"
#include "mesa/util/macros.h"
#include "mesa/util/os_time.h"
#include "blacklist.h"
#include <chrono>
#include <iomanip>
@ -64,6 +65,8 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) {
#endif
int ret = glx.MakeCurrent(dpy, drawable, ctx);
if (!is_blacklisted()) {
if (ret)
imgui_set_context(ctx);
@ -75,12 +78,15 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) {
if (glx.SwapIntervalMESA)
glx.SwapIntervalMESA(params.gl_vsync);
}
}
return ret;
}
EXPORT_C_(void) glXSwapBuffers(void* dpy, void* drawable) {
glx.Load();
if (!is_blacklisted()) {
imgui_create(glx.GetCurrentContext());
unsigned int width = -1, height = -1;
@ -105,8 +111,11 @@ EXPORT_C_(void) glXSwapBuffers(void* dpy, void* drawable) {
height = vp[3];*/
imgui_render(width, height);
}
glx.SwapBuffers(dpy, drawable);
if (fps_limit_stats.targetFrameTime > 0){
if (!is_blacklisted() && fps_limit_stats.targetFrameTime > 0){
fps_limit_stats.frameStart = os_time_get_nano();
FpsLimiter(fps_limit_stats);
fps_limit_stats.frameEnd = os_time_get_nano();
@ -117,10 +126,11 @@ EXPORT_C_(void) glXSwapIntervalEXT(void *dpy, void *draw, int interval) {
#ifndef NDEBUG
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load();
if (params.gl_vsync >= 0)
if (!is_blacklisted() && params.gl_vsync >= 0)
interval = params.gl_vsync;
glx.SwapIntervalEXT(dpy, draw, interval);
}
@ -129,8 +139,10 @@ EXPORT_C_(int) glXSwapIntervalSGI(int interval) {
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load();
if (params.gl_vsync >= 0)
if (!is_blacklisted() && params.gl_vsync >= 0)
interval = params.gl_vsync;
return glx.SwapIntervalSGI(interval);
}
@ -139,16 +151,20 @@ EXPORT_C_(int) glXSwapIntervalMESA(unsigned int interval) {
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load();
if (params.gl_vsync >= 0)
if (!is_blacklisted() && params.gl_vsync >= 0)
interval = (unsigned int)params.gl_vsync;
return glx.SwapIntervalMESA(interval);
}
EXPORT_C_(int) glXGetSwapIntervalMESA() {
glx.Load();
static bool first_call = true;
int interval = glx.GetSwapIntervalMESA();
if (!is_blacklisted()) {
static bool first_call = true;
if (first_call) {
first_call = false;
if (params.gl_vsync >= 0) {
@ -156,6 +172,7 @@ EXPORT_C_(int) glXGetSwapIntervalMESA() {
glx.SwapIntervalMESA(interval);
}
}
}
#ifndef NDEBUG
std::cerr << __func__ << ": " << interval << std::endl;
@ -185,6 +202,9 @@ static std::array<const func_ptr, 9> name_to_funcptr_map = {{
void *find_glx_ptr(const char *name)
{
if (is_blacklisted())
return nullptr;
for (auto& func : name_to_funcptr_map) {
if (strcmp(name, func.name) == 0)
return func.ptr;

@ -42,6 +42,7 @@ vklayer_files = files(
'overlay.cpp',
'overlay_params.cpp',
'font_unispace.c',
'blacklist.cpp',
'cpu.cpp',
'loaders/loader_nvml.cpp',
'nvml.cpp',
@ -62,7 +63,9 @@ opengl_files = files(
'gl/inject_egl.cpp',
)
if get_option('with_dlsym').enabled()
pre_args += '-DHOOK_DLSYM'
endif
if get_option('with_xnvctrl').enabled()

@ -57,6 +57,7 @@
#include "loaders/loader_nvml.h"
#include "memory.h"
#include "notify.h"
#include "blacklist.h"
#ifdef HAVE_DBUS
#include "dbus_info.h"
@ -816,7 +817,10 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
}
void init_system_info(){
const char* ld_preload = getenv("LD_PRELOAD");
if (ld_preload)
unsetenv("LD_PRELOAD");
ram = exec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'");
trim(ram);
cpu = exec("cat /proc/cpuinfo | grep 'model name' | tail -n1 | sed 's/^.*: //' | sed 's/([^)]*)/()/g' | tr -d '(/)'");
@ -832,6 +836,8 @@ void init_system_info(){
trim(driver);
//driver = itox(device_data->properties.driverVersion);
if (ld_preload)
setenv("LD_PRELOAD", ld_preload, 1);
#ifndef NDEBUG
std::cout << "Ram:" << ram << "\n"
<< "Cpu:" << cpu << "\n"
@ -2503,10 +2509,12 @@ static VkResult overlay_CreateDevice(
get_device_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK);
device_data->set_device_loader_data = load_data_info->u.pfnSetDeviceLoaderData;
if (!is_blacklisted()) {
device_map_queues(device_data, pCreateInfo);
init_gpu_stats(device_data->properties.vendorID, instance_data->params);
init_system_info();
}
return result;
}
@ -2516,6 +2524,7 @@ static void overlay_DestroyDevice(
const VkAllocationCallbacks* pAllocator)
{
struct device_data *device_data = FIND(struct device_data, device);
if (!is_blacklisted())
device_unmap_queues(device_data);
device_data->vtable.DestroyDevice(device, pAllocator);
destroy_device_data(device_data);
@ -2531,6 +2540,7 @@ static VkResult overlay_CreateInstance(
std::string engineName, engineVersion;
if (!is_blacklisted()) {
const char* pEngineName = nullptr;
if (pCreateInfo->pApplicationInfo)
pEngineName = pCreateInfo->pApplicationInfo->pEngineName;
@ -2546,6 +2556,7 @@ static VkResult overlay_CreateInstance(
if (engineName == "vkd3d")
engineName = "VKD3D";
}
assert(chain_info->u.pLayerInfo);
PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
@ -2568,6 +2579,7 @@ static VkResult overlay_CreateInstance(
&instance_data->vtable);
instance_data_map_physical_devices(instance_data, true);
if (!is_blacklisted()) {
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
instance_data->notifier.params = &instance_data->params;
start_notifier(instance_data->notifier);
@ -2585,6 +2597,7 @@ static VkResult overlay_CreateInstance(
instance_data->engineName = engineName;
instance_data->engineVersion = engineVersion;
}
return result;
}
@ -2596,6 +2609,7 @@ static void overlay_DestroyInstance(
struct instance_data *instance_data = FIND(struct instance_data, instance);
instance_data_map_physical_devices(instance_data, false);
instance_data->vtable.DestroyInstance(instance, pAllocator);
if (!is_blacklisted())
stop_notifier(instance_data->notifier);
destroy_instance_data(instance_data);
}
@ -2630,42 +2644,11 @@ static const struct {
#undef ADD_HOOK
};
static bool checkBlacklisted()
{
std::vector<std::string> blacklist {
"Battle.net.exe",
"EpicGamesLauncher.exe",
"IGOProxy.exe",
"IGOProxy64.exe",
"Origin.exe",
"OriginThinSetupInternal.exe",
"Steam.exe",
"BethesdaNetLauncher.exe",
};
#ifdef _GNU_SOURCE_OFF
std::string p(program_invocation_name);
std::string procName = p.substr(p.find_last_of("/\\") + 1);
#else
std::string p = get_exe_path();
std::string procName;
if (ends_with(p, "wine-preloader") || ends_with(p, "wine64-preloader")) {
get_wine_exe_name(procName, true);
} else {
procName = p.substr(p.find_last_of("/\\") + 1);
}
#endif
return std::find(blacklist.begin(), blacklist.end(), procName) != blacklist.end();
}
static bool isBlacklisted = checkBlacklisted();
static void *find_ptr(const char *name)
{
std::string f(name);
if (isBlacklisted && (f != "vkCreateInstance" && f != "vkDestroyInstance" && f != "vkCreateDevice" && f != "vkDestroyDevice"))
if (is_blacklisted() && (f != "vkCreateInstance" && f != "vkDestroyInstance" && f != "vkCreateDevice" && f != "vkDestroyDevice"))
{
return NULL;
}

Loading…
Cancel
Save