Add simple "safe mode" which disable all non-basearoma plugins

This commit is contained in:
Maschell
2024-08-09 16:41:29 +02:00
parent 284f41db54
commit bb8e84088c
9 changed files with 133 additions and 56 deletions

View File

@@ -9,7 +9,7 @@
namespace WUPSBackendSettings {
namespace {
std::vector<std::string> sInactivePlugins;
std::set<std::string> sInactivePlugins;
}
#define INACTIVE_PLUGINS_KEY "inactive_plugins"
@@ -20,14 +20,14 @@ namespace WUPSBackendSettings {
std::string filePath = folderPath + "wupsbackend.json";
if (!ParseJsonFromFile(filePath, j)) {
sInactivePlugins.clear();
return false;
}
sInactivePlugins.clear();
if (j.contains(INACTIVE_PLUGINS_KEY) && j[INACTIVE_PLUGINS_KEY].is_array()) {
for (auto &cur : j[INACTIVE_PLUGINS_KEY]) {
if (cur.is_string()) {
sInactivePlugins.push_back(cur);
sInactivePlugins.insert(cur);
}
}
}
@@ -63,14 +63,15 @@ namespace WUPSBackendSettings {
return true;
}
void SetInactivePluginFilenames(std::span<std::string> filenames) {
void ClearInactivePluginFilenames() {
sInactivePlugins.clear();
for (const auto &filename : filenames) {
sInactivePlugins.emplace_back(filename);
}
}
const std::vector<std::string> &GetInactivePluginFilenames() {
void AddInactivePluginFilename(const std::string &filename) {
sInactivePlugins.insert(filename);
}
const std::set<std::string> &GetInactivePluginFilenames() {
return sInactivePlugins;
}

View File

@@ -1,15 +1,25 @@
#pragma once
#include <set>
#include <span>
#include <string>
#include <vector>
namespace WUPSBackendSettings {
bool LoadSettings();
bool SaveSettings();
void SetInactivePluginFilenames(std::span<std::string> filenames);
void ClearInactivePluginFilenames();
const std::vector<std::string> &GetInactivePluginFilenames();
void AddInactivePluginFilename(const std::string &filename);
template<typename Iterable>
void SetInactivePluginFilenames(const Iterable &filenames) {
ClearInactivePluginFilenames();
for (const auto &cur : filenames) {
AddInactivePluginFilename(cur);
}
}
const std::set<std::string> &GetInactivePluginFilenames();
}; // namespace WUPSBackendSettings

View File

@@ -6,8 +6,6 @@
#include "utils/logger.h"
#include "utils/utils.h"
#include <coreinit/title.h>
ConfigRenderer::ConfigRenderer(std::vector<ConfigDisplayItem> &&vec) : mConfigs(std::move(vec)) {
std::copy(mConfigs.begin(), mConfigs.end(),
std::back_inserter(mAllConfigs));
@@ -153,7 +151,6 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
return SUB_STATE_RUNNING;
}
void ConfigRenderer::RenderStateMain() const {
auto &configs = GetConfigList();
@@ -193,7 +190,7 @@ void ConfigRenderer::RenderStateMain() const {
// draw top bar
DrawUtils::setFontSize(24);
if (mSetActivePluginsMode) {
DrawUtils::print(16, 6 + 24, "Please select the plugin that should be active");
DrawUtils::print(16, 6 + 24, "Please select the plugins that should be active");
} else {
DrawUtils::print(16, 6 + 24, "Wii U Plugin System Config Menu");

View File

@@ -17,6 +17,8 @@
****************************************************************************/
#include "Input.h"
#include <coreinit/thread.h>
#include <vpad/input.h>
class VPadInput final : public Input {
@@ -31,23 +33,28 @@ public:
lastData = data;
data = {};
vpadError = VPAD_READ_NO_SAMPLES;
vpadError = VPAD_READ_UNINITIALIZED;
if (VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
data.buttons_r = vpad.release;
data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger;
data.validPointer = !vpad.tpNormal.validity;
data.touched = vpad.tpNormal.touched;
int maxAttempts = 100;
do {
if (VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
data.buttons_r = vpad.release;
data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger;
data.validPointer = !vpad.tpNormal.validity;
data.touched = vpad.tpNormal.touched;
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
//! calculate the screen offsets
data.x = -(width >> 1) + (int32_t) (((float) tpCalib.x / 1280.0f) * (float) width);
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
//! calculate the screen offsets
data.x = -(width >> 1) + (int32_t) (((float) tpCalib.x / 1280.0f) * (float) width);
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
return true;
}
return true;
} else {
OSSleepTicks(OSMillisecondsToTicks(1));
}
} while (--maxAttempts > 0 && vpadError == VPAD_READ_NO_SAMPLES);
return false;
}

View File

@@ -1,4 +1,6 @@
#include "utils.h"
#include "StringTools.h"
#include "fs/CFile.hpp"
#include "globals.h"
#include "json.hpp"
@@ -8,6 +10,7 @@
#include <coreinit/ios.h>
#include <malloc.h>
#include <string>
#include <sys/dirent.h>
#include <wups/storage.h>
static std::string sPluginPath;
@@ -132,4 +135,63 @@ bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) {
file.close();
free(json_data);
return result;
}
std::vector<std::string> getPluginFilePaths(std::string_view basePath) {
std::vector<std::string> result;
struct dirent *dp;
DIR *dfd;
if (basePath.empty()) {
DEBUG_FUNCTION_LINE_ERR("Failed to scan plugin dir: Path was empty");
return result;
}
if ((dfd = opendir(basePath.data())) == nullptr) {
DEBUG_FUNCTION_LINE_ERR("Couldn't open dir %s", basePath.data());
return result;
}
while ((dp = readdir(dfd)) != nullptr) {
if (dp->d_type == DT_DIR) {
continue;
}
if (std::string_view(dp->d_name).starts_with('.') || std::string_view(dp->d_name).starts_with('_') || !std::string_view(dp->d_name).ends_with(".wps")) {
DEBUG_FUNCTION_LINE_WARN("Skip file %s/%s", basePath.data(), dp->d_name);
continue;
}
auto full_file_path = string_format("%s/%s", basePath.data(), dp->d_name);
result.push_back(full_file_path);
}
closedir(dfd);
return result;
}
std::vector<std::string> getNonBaseAromaPluginFilenames(std::string_view basePath) {
std::vector<std::string> result;
for (const auto &filePath : getPluginFilePaths(basePath)) {
std::string fileName = StringTools::FullpathToFilename(filePath.c_str());
const char *baseAromaFileNames[] = {
"AromaBasePlugin.wps",
"drc_region_free.wps",
"homebrew_on_menu.wps",
"regionfree.wps",
};
bool found = false;
for (const auto &cur : baseAromaFileNames) {
if (fileName == cur) {
found = true;
break;
}
}
if (!found) {
result.push_back(fileName);
}
}
return result;
}

View File

@@ -144,4 +144,8 @@ OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr);
void CustomDynLoadFree(void *addr);
bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson);
bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson);
std::vector<std::string> getPluginFilePaths(std::string_view basePath);
std::vector<std::string> getNonBaseAromaPluginFilenames(std::string_view basePath);