From 7c80dc53efa95718f1cec9b41814f05af625c2d0 Mon Sep 17 00:00:00 2001 From: Alessandro Toia Date: Sat, 14 Nov 2020 21:58:01 -0800 Subject: [PATCH] Allow users to add a new item to the blacklist from config file --- README.md | 1 + bin/MangoHud.conf | 3 +++ src/blacklist.cpp | 47 ++++++++++++++++++++++++------------------ src/blacklist.h | 4 +++- src/overlay_params.cpp | 1 + src/overlay_params.h | 2 ++ src/vulkan.cpp | 11 +++++++++- 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b983248a..a9519f70 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu | `cellpadding_y` | Set the vertical cellpadding, default is `-0.085` | | `frametime` | Display frametime next to fps text | | `table_columns` | Set the number of table columns for ImGui, defaults to 3 | +| `blacklist` | Add a program to the blacklist. e.g `blacklist=vkcube,WatchDogs2.exe` | Example: `MANGOHUD_CONFIG=cpu_temp,gpu_temp,position=top-right,height=500,font_size=32` diff --git a/bin/MangoHud.conf b/bin/MangoHud.conf index 390ab594..6248c3d1 100644 --- a/bin/MangoHud.conf +++ b/bin/MangoHud.conf @@ -132,6 +132,9 @@ background_alpha=0.5 ### Set to 'domain:bus:slot.function' # pci_dev = 0:0a:0.0 +### Blacklist +#blacklist = + ################## INTERACTION ################# ### Change toggle keybinds for the hud & logging diff --git a/src/blacklist.cpp b/src/blacklist.cpp index 661eb4f8..378d6fcd 100644 --- a/src/blacklist.cpp +++ b/src/blacklist.cpp @@ -22,27 +22,28 @@ static std::string get_proc_name() { return proc_name; } -static bool check_blacklisted() { - static const std::vector blacklist { - "Battle.net.exe", - "BethesdaNetLauncher.exe", - "EpicGamesLauncher.exe", - "IGOProxy.exe", - "IGOProxy64.exe", - "Origin.exe", - "OriginThinSetupInternal.exe", - "steam", - "steamwebhelper", - "gldriverquery", - "vulkandriverquery", - "Steam.exe", - "ffxivlauncher.exe", - "ffxivlauncher64.exe", - "LeagueClient.exe", - "LeagueClientUxRender.exe", - "SocialClubHelper.exe", - }; +static std::vector blacklist { + "Battle.net.exe", + "BethesdaNetLauncher.exe", + "EpicGamesLauncher.exe", + "IGOProxy.exe", + "IGOProxy64.exe", + "Origin.exe", + "OriginThinSetupInternal.exe", + "steam", + "steamwebhelper", + "gldriverquery", + "vulkandriverquery", + "Steam.exe", + "ffxivlauncher.exe", + "ffxivlauncher64.exe", + "LeagueClient.exe", + "LeagueClientUxRender.exe", + "SocialClubHelper.exe", +}; + +static bool check_blacklisted() { std::string proc_name = get_proc_name(); bool blacklisted = std::find(blacklist.begin(), blacklist.end(), proc_name) != blacklist.end(); @@ -59,3 +60,9 @@ bool is_blacklisted(bool force_recheck) { blacklisted = check_blacklisted(); return blacklisted; } + +void add_blacklist(std::string new_item) { + blacklist.push_back (new_item); + is_blacklisted(true); +} + diff --git a/src/blacklist.h b/src/blacklist.h index b4105df3..5f505a2c 100644 --- a/src/blacklist.h +++ b/src/blacklist.h @@ -1,7 +1,9 @@ #pragma once #ifndef MANGOHUD_BLACKLIST_H #define MANGOHUD_BLACKLIST_H - +#include bool is_blacklisted(bool force_recheck = false); +void add_blacklist(std::string); + #endif //MANGOHUD_BLACKLIST_H diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index a7d10627..1ee204cb 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -362,6 +362,7 @@ parse_font_glyph_ranges(const char *str) #define parse_cpu_load_color(s) parse_load_color(s) #define parse_gpu_load_value(s) parse_load_value(s) #define parse_cpu_load_value(s) parse_load_value(s) +#define parse_blacklist(s) parse_str(s) static bool parse_help(const char *str) diff --git a/src/overlay_params.h b/src/overlay_params.h index 8904a434..5666b2b2 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -117,6 +117,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_CUSTOM(cpu_load_color) \ OVERLAY_PARAM_CUSTOM(cellpadding_y) \ OVERLAY_PARAM_CUSTOM(table_columns) \ + OVERLAY_PARAM_CUSTOM(blacklist) \ enum overlay_param_position { LAYER_POSITION_TOP_LEFT, @@ -197,6 +198,7 @@ struct overlay_params { std::string pci_dev; std::string media_player_name; std::string cpu_text, gpu_text; + std::string blacklist; unsigned log_interval; std::vector media_player_order; std::vector benchmark_percentiles; diff --git a/src/vulkan.cpp b/src/vulkan.cpp index 1358be9b..3dadf2a8 100644 --- a/src/vulkan.cpp +++ b/src/vulkan.cpp @@ -2079,8 +2079,17 @@ static VkResult overlay_CreateInstance( &instance_data->vtable); instance_data_map_physical_devices(instance_data, true); + parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG")); + + //check for blacklist item in the config file + std::stringstream ss(instance_data->params.blacklist); + std::string token; + while (std::getline(ss, token, ',')) { + trim(token); + add_blacklist(token); + } + if (!is_blacklisted()) { - parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG")); #ifdef __gnu_linux__ instance_data->notifier.params = &instance_data->params; start_notifier(instance_data->notifier);