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 a40f091c6b
commit 8b2634f75e
9 changed files with 133 additions and 56 deletions

View File

@ -6,6 +6,7 @@
#include "patcher/hooks_patcher_static.h"
#include "plugin/PluginDataFactory.h"
#include "utils/WUPSBackendSettings.h"
#include "utils/input/VPADInput.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include "version.h"
@ -42,6 +43,22 @@ WUMS_INITIALIZE() {
}
}
VPadInput vpadInput;
vpadInput.update(1280, 720);
auto buttomComboSafeMode = Input::eButtons::BUTTON_L | Input::eButtons::BUTTON_UP | Input::eButtons::BUTTON_MINUS;
if ((vpadInput.data.buttons_h & (buttomComboSafeMode)) == buttomComboSafeMode) {
auto tobeIgnoredFilePath = getNonBaseAromaPluginFilenames(getPluginPath());
WUPSBackendSettings::LoadSettings();
std::set<std::string> inactivePlugins = WUPSBackendSettings::GetInactivePluginFilenames();
inactivePlugins.insert(tobeIgnoredFilePath.begin(), tobeIgnoredFilePath.end());
for (const auto &d : inactivePlugins) {
DEBUG_FUNCTION_LINE_INFO("%s should be ignores", d.c_str());
}
WUPSBackendSettings::SetInactivePluginFilenames(inactivePlugins);
WUPSBackendSettings::SaveSettings();
}
deinitLogging();
}

View File

@ -26,37 +26,18 @@
#include <set>
#include <sys/dirent.h>
std::vector<PluginLoadWrapper> PluginDataFactory::loadDir(std::string_view path, const std::vector<std::string> &inactivePluginsFilenames) {
std::vector<PluginLoadWrapper> PluginDataFactory::loadDir(const std::string_view path, const std::set<std::string> &inactivePluginsFilenames) {
std::vector<PluginLoadWrapper> result;
dirent *dp;
DIR *dfd;
if (path.empty()) {
DEBUG_FUNCTION_LINE_ERR("Failed to load Plugins from dir: Path was empty");
return result;
}
for (const auto &full_file_path : getPluginFilePaths(path)) {
std::string fileName = StringTools::FullpathToFilename(full_file_path.c_str());
if ((dfd = opendir(path.data())) == nullptr) {
DEBUG_FUNCTION_LINE_ERR("Couldn't open dir %s", path.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", path.data(), dp->d_name);
continue;
}
auto full_file_path = string_format("%s/%s", path.data(), dp->d_name);
DEBUG_FUNCTION_LINE("Loading plugin: %s", full_file_path.c_str());
if (auto pluginData = load(full_file_path)) {
bool shouldBeLoadedAndLinked = true;
if (std::ranges::find(inactivePluginsFilenames, dp->d_name) != inactivePluginsFilenames.end()) {
if (inactivePluginsFilenames.contains(fileName)) {
shouldBeLoadedAndLinked = false;
}
result.emplace_back(std::move(pluginData), shouldBeLoadedAndLinked);
@ -67,8 +48,6 @@ std::vector<PluginLoadWrapper> PluginDataFactory::loadDir(std::string_view path,
}
}
closedir(dfd);
return result;
}

View File

@ -25,7 +25,7 @@
class PluginDataFactory {
public:
static std::vector<PluginLoadWrapper> loadDir(std::string_view path, const std::vector<std::string> &inactivePluginsFilenames);
static std::vector<PluginLoadWrapper> loadDir(std::string_view path, const std::set<std::string> &inactivePluginsFilenames);
static std::unique_ptr<PluginData> load(std::string_view path);

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);