Skip to content

Commit

Permalink
Implement a whitelist/enabledApps
Browse files Browse the repository at this point in the history
  • Loading branch information
Erimelowo committed Dec 28, 2024
1 parent 78149f8 commit d5889d4
Showing 1 changed file with 68 additions and 21 deletions.
89 changes: 68 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace ImGui
using namespace std::chrono_literals;
using namespace vr;

static constexpr const char *version = "v1.1.0";
static constexpr const char *version = "v1.2.0";

static constexpr const char *iconPath = "icon.png";

Expand All @@ -78,12 +78,15 @@ int minimizeOnStart = 0;
// General
int resChangeDelayMs = 3000;
int dataAverageSamples = 128;
std::string disabledApps = "steam.app.620980 steam.app.658920 steam.app.2177750 steam.app.2177760"; // Beat Saber and HL2VR
std::set<std::string> disabledAppsSet = {"steam.app.620980", "steam.app.658920", "steam.app.2177750", "steam.app.2177760"};
std::string blacklistApps = "steam.app.620980 steam.app.658920 steam.app.2177750 steam.app.2177760"; // Beat Saber and HL2VR
std::set<std::string> blacklistAppsSet = {"steam.app.620980", "steam.app.658920", "steam.app.2177750", "steam.app.2177760"};
bool whitelistEnabled = false;
std::string whitelistApps = "";
std::set<std::string> whitelistAppsSet = {};
// Resolution
int initialRes = 100;
int minRes = 70;
int maxRes = 250;
int maxRes = 200;
int resIncreaseThreshold = 80;
int resDecreaseThreshold = 88;
int resIncreaseMin = 3;
Expand Down Expand Up @@ -147,14 +150,22 @@ bool loadSettings()
// Startup
autoStart = std::stoi(ini.GetValue("Startup", "autoStart", std::to_string(autoStart).c_str()));
minimizeOnStart = std::stoi(ini.GetValue("Startup", "minimizeOnStart", std::to_string(minimizeOnStart).c_str()));

// General
resChangeDelayMs = std::stoi(ini.GetValue("General", "resChangeDelayMs", std::to_string(resChangeDelayMs).c_str()));
dataAverageSamples = std::stoi(ini.GetValue("General", "dataAverageSamples", std::to_string(dataAverageSamples).c_str()));
if (dataAverageSamples > 128)
dataAverageSamples = 128; // Max stored by OpenVR
disabledApps = ini.GetValue("General", "disabledApps", disabledApps.c_str());
std::replace(disabledApps.begin(), disabledApps.end(), ' ', '\n');
disabledAppsSet = multilineStringToSet(disabledApps);
// blacklist
blacklistApps = ini.GetValue("General", "disabledApps", blacklistApps.c_str());
std::replace(blacklistApps.begin(), blacklistApps.end(), ' ', '\n');
blacklistAppsSet = multilineStringToSet(blacklistApps);
// whitelist
whitelistEnabled = std::stoi(ini.GetValue("General", "whitelistEnabled", std::to_string(whitelistEnabled).c_str()));
whitelistApps = ini.GetValue("General", "whitelistApps", blacklistApps.c_str());
std::replace(whitelistApps.begin(), whitelistApps.end(), ' ', '\n');
whitelistAppsSet = multilineStringToSet(whitelistApps);

// Resolution
initialRes = std::stoi(ini.GetValue("Resolution", "initialRes", std::to_string(initialRes).c_str()));
minRes = std::stoi(ini.GetValue("Resolution", "minRes", std::to_string(minRes).c_str()));
Expand All @@ -167,15 +178,18 @@ bool loadSettings()
resDecreaseScale = std::stoi(ini.GetValue("Resolution", "resDecreaseScale", std::to_string(resDecreaseScale).c_str()));
minCpuTimeThreshold = std::stof(ini.GetValue("Resolution", "minCpuTimeThreshold", std::to_string(minCpuTimeThreshold).c_str()));
resetOnThreshold = std::stoi(ini.GetValue("Resolution", "resetOnThreshold", std::to_string(resetOnThreshold).c_str()));

// Reprojection
alwaysReproject = std::stoi(ini.GetValue("Reprojection", "alwaysReproject", std::to_string(alwaysReproject).c_str()));
preferReprojection = std::stoi(ini.GetValue("Reprojection", "preferReprojection", std::to_string(preferReprojection).c_str()));
ignoreCpuTime = std::stoi(ini.GetValue("Reprojection", "ignoreCpuTime", std::to_string(ignoreCpuTime).c_str()));

// VRAM
vramMonitorEnabled = std::stoi(ini.GetValue("VRAM", "vramMonitorEnabled", std::to_string(vramMonitorEnabled).c_str()));
vramOnlyMode = std::stoi(ini.GetValue("VRAM", "vramOnlyMode", std::to_string(vramOnlyMode).c_str()));
vramTarget = std::stoi(ini.GetValue("VRAM", "vramTarget", std::to_string(vramTarget).c_str()));
vramLimit = std::stoi(ini.GetValue("VRAM", "vramLimit", std::to_string(vramLimit).c_str()));

return true;
}
catch (...)
Expand All @@ -192,10 +206,14 @@ void saveSettings()
// Startup
ini.SetValue("Startup", "autoStart", std::to_string(autoStart).c_str());
ini.SetValue("Startup", "minimizeOnStart", std::to_string(minimizeOnStart).c_str());

// General
ini.SetValue("General", "resChangeDelayMs", std::to_string(resChangeDelayMs).c_str());
ini.SetValue("General", "dataAverageSamples", std::to_string(dataAverageSamples).c_str());
ini.SetValue("General", "disabledApps", setToConfigString(disabledAppsSet).c_str());
ini.SetValue("General", "disabledApps", setToConfigString(blacklistAppsSet).c_str());
ini.SetValue("General", "whitelistEnabled", std::to_string(whitelistEnabled).c_str());
ini.SetValue("General", "whitelistApps", setToConfigString(whitelistAppsSet).c_str());

// Resolution
ini.SetValue("Resolution", "initialRes", std::to_string(initialRes).c_str());
ini.SetValue("Resolution", "minRes", std::to_string(minRes).c_str());
Expand All @@ -208,10 +226,12 @@ void saveSettings()
ini.SetValue("Resolution", "resDecreaseScale", std::to_string(resDecreaseScale).c_str());
ini.SetValue("Resolution", "minCpuTimeThreshold", std::to_string(minCpuTimeThreshold).c_str());
ini.SetValue("Resolution", "resetOnThreshold", std::to_string(resetOnThreshold).c_str());

// Reprojection
ini.SetValue("Reprojection", "alwaysReproject", std::to_string(alwaysReproject).c_str());
ini.SetValue("Reprojection", "preferReprojection", std::to_string(preferReprojection).c_str());
ini.SetValue("Reprojection", "ignoreCpuTime", std::to_string(ignoreCpuTime).c_str());

// VRAM
ini.SetValue("VRAM", "vramMonitorEnabled", std::to_string(vramMonitorEnabled).c_str());
ini.SetValue("VRAM", "vramOnlyMode", std::to_string(vramOnlyMode).c_str());
Expand Down Expand Up @@ -302,19 +322,24 @@ std::string getCurrentApplicationKey()
return {applicationKey};
}

bool isApplicationDisabled(std::string appKey)
bool isApplicationBlacklisted(std::string appKey)
{
return disabledAppsSet.find(appKey) != disabledAppsSet.end() || appKey == "";
return appKey == "" || blacklistAppsSet.find(appKey) != blacklistAppsSet.end();
}

bool isApplicationWhitelisted(std::string appKey)
{
return appKey != "" && whitelistAppsSet.find(appKey) != whitelistAppsSet.end();
}

bool shouldAdjustResolution(std::string appKey, bool manualRes, float cpuTime)
{
// Check if the SteamVR dashboard is open
bool inDashboard = vr::VROverlay()->IsDashboardVisible();
// Check that we're in a supported application
bool isCurrentAppDisabled = isApplicationDisabled(appKey);
bool isCurrentAppSupported = !isApplicationBlacklisted(appKey) && (!whitelistEnabled || isApplicationWhitelisted(appKey));
// Only adjust resolution if not in dashboard, in a supported application. user didn't pause res and cpu time isn't below threshold
return !inDashboard && !isCurrentAppDisabled && !manualRes && !(resetOnThreshold && cpuTime < minCpuTimeThreshold);
return !inDashboard && isCurrentAppSupported && !manualRes && !(resetOnThreshold && cpuTime < minCpuTimeThreshold);
}

void printLine(std::string text, long duration)
Expand Down Expand Up @@ -472,8 +497,10 @@ int main(int argc, char *argv[])
#pragma endregion

// Load settings from ini file
if (!loadSettings())
if (!loadSettings()) {
std::replace(blacklistApps.begin(), blacklistApps.end(), ' ', '\n'); // Set blacklist newlines
saveSettings(); // Restore settings
}

// Set auto-start
int autoStartResult = handle_setup(autoStart);
Expand Down Expand Up @@ -927,19 +954,39 @@ int main(int argc, char *argv[])
}
addTooltip("Number of frames' frametimes to average out.");

if (ImGui::InputTextMultiline("Disabled applications", &disabledApps, ImVec2(130, 60)))
disabledAppsSet = multilineStringToSet(disabledApps);
addTooltip("List of OpenVR application keys that should be ignored for resolution adjustment in the format \'steam.app.APPID\' (e.g. steam.app.620980 for Beat Saber). One per line.");
if (ImGui::Button("Disable current application", ImVec2(200, 26)))
ImGui::Text("Blacklist");
addTooltip("Don't allow resolution changes in blacklisted applications.");
if (ImGui::InputTextMultiline("Blacklisted apps", &blacklistApps, ImVec2(130, 60), ImGuiInputTextFlags_CharsNoBlank))
blacklistAppsSet = multilineStringToSet(blacklistApps);
addTooltip("List of OpenVR application keys that should be blacklisted for resolution adjustment in the format \'steam.app.APPID\' (e.g. \'steam.app.620980\' for Beat Saber). One per line.");
if (ImGui::Button("Blacklist current app", ImVec2(160, 26)))
{
std::string appKey = getCurrentApplicationKey();
if (!isApplicationBlacklisted(appKey))
{
blacklistAppsSet.insert(appKey);
if (blacklistApps != "") blacklistApps += "\n";
blacklistApps += appKey;
}
}
addTooltip("Adds the current application to the blacklist.");

ImGui::Checkbox("Enable whitelist", &whitelistEnabled);
addTooltip("Only allow resolution changes in whitelisted applications.");
if (ImGui::InputTextMultiline("Whitelisted apps", &whitelistApps, ImVec2(130, 60), ImGuiInputTextFlags_CharsNoBlank))
whitelistAppsSet = multilineStringToSet(whitelistApps);
addTooltip("List of OpenVR application keys that should be whitelisted for resolution adjustment in the format \'steam.app.APPID\' (e.g. \'steam.app.620980\' for Beat Saber). One per line.");
if (ImGui::Button("Whitelist current app", ImVec2(164, 26)))
{
std::string appKey = getCurrentApplicationKey();
if (!isApplicationDisabled(appKey))
if (!isApplicationWhitelisted(appKey))
{
disabledAppsSet.insert(appKey);
disabledApps += "\n" + appKey;
whitelistAppsSet.insert(appKey);
if (whitelistApps != "") whitelistApps += "\n";
whitelistApps += appKey;
}
}
addTooltip("Adds the current application to the list of disable applications.");
addTooltip("Adds the current application to the whitelist.");
}

if (ImGui::CollapsingHeader("Resolution"))
Expand Down

0 comments on commit d5889d4

Please sign in to comment.