mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2025-01-09 11:09:22 +01:00
Add ButtonComboAPI support
This commit is contained in:
parent
b273a0cc21
commit
eb12f209ce
@ -1,10 +1,11 @@
|
|||||||
FROM ghcr.io/wiiu-env/devkitppc:20241128
|
FROM ghcr.io/wiiu-env/devkitppc:20241128
|
||||||
|
|
||||||
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.2-dev-20241128-1ac579a /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.2-dev-20241226-f71cb8c /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libwupsbackend:20240425 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libwupsbackend:20240425 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libnotifications:20240426 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libnotifications:20240426 /artifacts $DEVKITPRO
|
||||||
|
COPY --from=ghcr.io/wiiu-env/libbuttoncombo:20241226-12d1594 /artifacts $DEVKITPRO
|
||||||
|
|
||||||
WORKDIR project
|
WORKDIR project
|
||||||
|
5
Makefile
5
Makefile
@ -31,7 +31,8 @@ SOURCES := source \
|
|||||||
source/utils \
|
source/utils \
|
||||||
source/utils/config \
|
source/utils/config \
|
||||||
source/utils/storage \
|
source/utils/storage \
|
||||||
source/uitls/input
|
source/utils/buttoncombo \
|
||||||
|
source/utils/input
|
||||||
DATA := data
|
DATA := data
|
||||||
INCLUDES := source
|
INCLUDES := source
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
|||||||
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBS := -lwums -lwups -lwut -lfunctionpatcher -lmappedmemory -lz -lnotifications
|
LIBS := -lwums -lwups -lwut -lfunctionpatcher -lmappedmemory -lz -lnotifications -lbuttoncombo
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level
|
# list of directories containing libraries, this must be the top level
|
||||||
|
@ -186,6 +186,7 @@ bool PluginManagement::DoFunctionPatches(std::vector<PluginContainer> &plugins)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PluginManagement::callInitHooks(const std::vector<PluginContainer> &plugins, const std::function<bool(const PluginContainer &)> &pred) {
|
void PluginManagement::callInitHooks(const std::vector<PluginContainer> &plugins, const std::function<bool(const PluginContainer &)> &pred) {
|
||||||
|
CallHook(plugins, WUPS_LOADER_HOOK_INIT_BUTTON_COMBO, pred);
|
||||||
CallHook(plugins, WUPS_LOADER_HOOK_INIT_CONFIG, pred);
|
CallHook(plugins, WUPS_LOADER_HOOK_INIT_CONFIG, pred);
|
||||||
CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE_DEPRECATED, pred);
|
CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE_DEPRECATED, pred);
|
||||||
CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE, pred);
|
CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE, pred);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include "hooks.h"
|
#include "hooks.h"
|
||||||
#include "plugin/PluginContainer.h"
|
#include "plugin/PluginContainer.h"
|
||||||
#include "utils/StorageUtilsDeprecated.h"
|
#include "utils/StorageUtilsDeprecated.h"
|
||||||
|
#include "utils/buttoncombo/ButtonComboUtils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/storage/StorageUtils.h"
|
#include "utils/storage/StorageUtils.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <wups/button_combo.h>
|
||||||
|
#include <wups/button_combo_internal.h>
|
||||||
#include <wups/storage.h>
|
#include <wups/storage.h>
|
||||||
|
|
||||||
static const char **hook_names = (const char *[]){
|
static const char **hook_names = (const char *[]){
|
||||||
@ -126,6 +129,35 @@ void CallHook(const PluginContainer &plugin, wups_loader_hook_type_t hook_type)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case WUPS_LOADER_HOOK_INIT_BUTTON_COMBO: {
|
||||||
|
if (plugin.getMetaInformation().getWUPSVersion() <= WUPSVersion(0, 8, 1)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wups_loader_init_button_combo_args_t args;
|
||||||
|
args.version = WUPS_BUTTON_COMBO_CUR_API_VERSION;
|
||||||
|
args.identifier = reinterpret_cast<void *>(plugin.getButtonComboManagerHandle());
|
||||||
|
args.add_button_combo_function_ptr = &ButtonComboUtils::API::AddButtonCombo;
|
||||||
|
args.remove_button_combo_function_ptr = &ButtonComboUtils::API::RemoveButtonCombo;
|
||||||
|
args.get_button_combo_status_function_ptr = &ButtonComboUtils::API::GetButtonComboStatus;
|
||||||
|
args.update_button_combo_meta_function_ptr = &ButtonComboUtils::API::UpdateButtonComboMeta;
|
||||||
|
args.update_button_combo_callback_function_ptr = &ButtonComboUtils::API::UpdateButtonComboCallback;
|
||||||
|
args.update_controller_mask_function_ptr = &ButtonComboUtils::API::UpdateControllerMask;
|
||||||
|
args.update_button_combo_function_ptr = &ButtonComboUtils::API::UpdateButtonCombo;
|
||||||
|
args.update_hold_duration_function_ptr = &ButtonComboUtils::API::UpdateHoldDuration;
|
||||||
|
args.get_button_combo_meta_function_ptr = &ButtonComboUtils::API::GetButtonComboMeta;
|
||||||
|
args.get_button_combo_callback_function_ptr = &ButtonComboUtils::API::GetButtonComboCallback;
|
||||||
|
args.get_button_combo_info_ex_function_ptr = &ButtonComboUtils::API::GetButtonComboInfoEx;
|
||||||
|
args.check_button_combo_available_function_ptr = &ButtonComboUtils::API::CheckComboAvailable;
|
||||||
|
args.detect_button_combo_blocking_function_ptr = &ButtonComboUtils::API::DetectButtonCombo_Blocking;
|
||||||
|
|
||||||
|
auto res = ((WUPSButtonCombo_Error(*)(wups_loader_init_button_combo_args_t))((uint32_t *) func_ptr))(args);
|
||||||
|
// clang-format on
|
||||||
|
if (res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
|
||||||
|
// TODO: More error handling? Notification?
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("WUPS_LOADER_HOOK_INIT_BUTTON_COMBO failed for plugin %s: %s", plugin.getMetaInformation().getName().c_str(), WUPSButtonComboAPI_GetStatusStr(res));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
DEBUG_FUNCTION_LINE_ERR("######################################");
|
DEBUG_FUNCTION_LINE_ERR("######################################");
|
||||||
DEBUG_FUNCTION_LINE_ERR("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);
|
DEBUG_FUNCTION_LINE_ERR("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#include <buttoncombo/manager.h>
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
#include <notifications/notifications.h>
|
#include <notifications/notifications.h>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@ -32,6 +33,10 @@ WUMS_INITIALIZE() {
|
|||||||
OSFatal("homebrew_wupsbackend: FunctionPatcher_InitLibrary failed");
|
OSFatal("homebrew_wupsbackend: FunctionPatcher_InitLibrary failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ButtonComboModule_InitLibrary() != BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
|
||||||
|
OSFatal("homebrew_wupsbackend: ButtonComboModule_InitLibrary failed");
|
||||||
|
}
|
||||||
|
|
||||||
if (const NotificationModuleStatus res = NotificationModule_InitLibrary(); res != NOTIFICATION_MODULE_RESULT_SUCCESS) {
|
if (const NotificationModuleStatus res = NotificationModule_InitLibrary(); res != NOTIFICATION_MODULE_RESULT_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to init NotificationModule: %s (%d)", NotificationModule_GetStatusStr(res), res);
|
DEBUG_FUNCTION_LINE_ERR("Failed to init NotificationModule: %s (%d)", NotificationModule_GetStatusStr(res), res);
|
||||||
gNotificationModuleLoaded = false;
|
gNotificationModuleLoaded = false;
|
||||||
@ -207,14 +212,6 @@ WUMS_APPLICATION_STARTS() {
|
|||||||
std::vector<PluginContainer> pluginsToDeinit = std::move(gLoadedPlugins);
|
std::vector<PluginContainer> pluginsToDeinit = std::move(gLoadedPlugins);
|
||||||
gLoadedPlugins = std::move(pluginsToKeep);
|
gLoadedPlugins = std::move(pluginsToKeep);
|
||||||
|
|
||||||
for (const auto &p : pluginsToKeep) {
|
|
||||||
DEBUG_FUNCTION_LINE_INFO("KEEP: %s", p.getMetaInformation().getName().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &p : pluginsToDeinit) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("DEINIT: %s", p.getMetaInformation().getName().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("Deinit unused plugins");
|
DEBUG_FUNCTION_LINE("Deinit unused plugins");
|
||||||
CleanupPlugins(std::move(pluginsToDeinit));
|
CleanupPlugins(std::move(pluginsToDeinit));
|
||||||
|
|
||||||
@ -255,6 +252,7 @@ WUMS_APPLICATION_STARTS() {
|
|||||||
if (const WUPSStorageError err = plugin.OpenStorage(); err != WUPS_STORAGE_ERROR_SUCCESS) {
|
if (const WUPSStorageError err = plugin.OpenStorage(); err != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to open storage for plugin: %s. (%s)", plugin.getMetaInformation().getName().c_str(), WUPSStorageAPI_GetStatusStr(err));
|
DEBUG_FUNCTION_LINE_ERR("Failed to open storage for plugin: %s. (%s)", plugin.getMetaInformation().getName().c_str(), WUPSStorageAPI_GetStatusStr(err));
|
||||||
}
|
}
|
||||||
|
plugin.InitButtonComboData();
|
||||||
}
|
}
|
||||||
PluginManagement::callInitHooks(gLoadedPlugins, needsInitsCheck);
|
PluginManagement::callInitHooks(gLoadedPlugins, needsInitsCheck);
|
||||||
|
|
||||||
@ -287,9 +285,11 @@ void CleanupPlugins(std::vector<PluginContainer> &&pluginsToDeinit) {
|
|||||||
PluginManagement::RestoreFunctionPatches(pluginsToDeinit);
|
PluginManagement::RestoreFunctionPatches(pluginsToDeinit);
|
||||||
|
|
||||||
for (auto &plugin : pluginsToDeinit) {
|
for (auto &plugin : pluginsToDeinit) {
|
||||||
|
if (!plugin.isInitDone()) { continue; }
|
||||||
if (const WUPSStorageError err = plugin.CloseStorage(); err != WUPS_STORAGE_ERROR_SUCCESS) {
|
if (const WUPSStorageError err = plugin.CloseStorage(); err != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to close storage for plugin: %s", plugin.getMetaInformation().getName().c_str());
|
DEBUG_FUNCTION_LINE_ERR("Failed to close storage for plugin: %s", plugin.getMetaInformation().getName().c_str());
|
||||||
}
|
}
|
||||||
|
plugin.DeinitButtonComboData();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &pluginContainer : pluginsToDeinit) {
|
for (const auto &pluginContainer : pluginsToDeinit) {
|
||||||
|
575
source/plugin/ButtonComboManager.cpp
Normal file
575
source/plugin/ButtonComboManager.cpp
Normal file
@ -0,0 +1,575 @@
|
|||||||
|
#include "ButtonComboManager.h"
|
||||||
|
#include <buttoncombo/manager.h>
|
||||||
|
#include <utils/logger.h>
|
||||||
|
#include <utils/utils.h>
|
||||||
|
#include <wups/button_combo_internal.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
WUPSButtonCombo_Error convertError(const ButtonComboModule_Error other) {
|
||||||
|
switch (other) {
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_SUCCESS:
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_INVALID_COMBO:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_INVALID_COMBO_TYPE:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_DURATION_MISSING:
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_INCOMPATIBLE_OPTIONS_VERSION:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_MODULE_NOT_FOUND:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_MODULE_MISSING_EXPORT:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_API_VERSION:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND:
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED:
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INTERNAL_INVALID_VERSION;
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR:
|
||||||
|
break;
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_HANDLE_NOT_FOUND:
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
case BUTTON_COMBO_MODULE_ERROR_ABORTED:
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_ABORTED;
|
||||||
|
}
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_ControllerTypes convert(const WUPSButtonCombo_ControllerTypes other) {
|
||||||
|
ButtonComboModule_ControllerTypes res = BUTTON_COMBO_MODULE_CONTROLLER_NONE;
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_VPAD_0;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_VPAD_1;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_0;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_1;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_2;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_3;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_4;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_5;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6) {
|
||||||
|
res |= BUTTON_COMBO_MODULE_CONTROLLER_WPAD_6;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_ControllerTypes convert(const ButtonComboModule_ControllerTypes other) {
|
||||||
|
WUPSButtonCombo_ControllerTypes res = WUPS_BUTTON_COMBO_CONTROLLER_NONE;
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_VPAD_0) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_VPAD_1) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_0) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_1) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_2) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_3) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_4) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_5) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5;
|
||||||
|
}
|
||||||
|
if (other & BUTTON_COMBO_MODULE_CONTROLLER_WPAD_6) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_Buttons convert(const WUPSButtonCombo_Buttons other) {
|
||||||
|
uint32_t res = 0;
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_A) {
|
||||||
|
res |= BCMPAD_BUTTON_A;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_B) {
|
||||||
|
res |= BCMPAD_BUTTON_B;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_X) {
|
||||||
|
res |= BCMPAD_BUTTON_X;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_Y) {
|
||||||
|
res |= BCMPAD_BUTTON_Y;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_LEFT) {
|
||||||
|
res |= BCMPAD_BUTTON_LEFT;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_RIGHT) {
|
||||||
|
res |= BCMPAD_BUTTON_RIGHT;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_UP) {
|
||||||
|
res |= BCMPAD_BUTTON_UP;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_DOWN) {
|
||||||
|
res |= BCMPAD_BUTTON_DOWN;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_ZL) {
|
||||||
|
res |= BCMPAD_BUTTON_ZL;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_ZR) {
|
||||||
|
res |= BCMPAD_BUTTON_ZR;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_L) {
|
||||||
|
res |= BCMPAD_BUTTON_L;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_R) {
|
||||||
|
res |= BCMPAD_BUTTON_R;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_PLUS) {
|
||||||
|
res |= BCMPAD_BUTTON_PLUS;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_MINUS) {
|
||||||
|
res |= BCMPAD_BUTTON_MINUS;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_STICK_R) {
|
||||||
|
res |= BCMPAD_BUTTON_STICK_R;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_STICK_L) {
|
||||||
|
res |= BCMPAD_BUTTON_STICK_L;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_TV) {
|
||||||
|
res |= BCMPAD_BUTTON_TV;
|
||||||
|
}
|
||||||
|
if (other & WUPS_BUTTON_COMBO_BUTTON_RESERVED_BIT) {
|
||||||
|
res |= BCMPAD_BUTTON_RESERVED_BIT;
|
||||||
|
}
|
||||||
|
return static_cast<ButtonComboModule_Buttons>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Buttons convert(const ButtonComboModule_Buttons other) {
|
||||||
|
uint32_t res = 0;
|
||||||
|
if (other & BCMPAD_BUTTON_A) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_A;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_B) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_B;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_X) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_B;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_Y) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_B;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_LEFT) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_LEFT;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_RIGHT) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_RIGHT;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_UP) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_UP;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_DOWN) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_DOWN;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_ZL) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_ZL;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_ZR) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_ZR;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_L) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_L;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_R) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_R;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_PLUS) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_PLUS;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_MINUS) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_MINUS;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_STICK_R) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_STICK_R;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_STICK_L) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_STICK_L;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_TV) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_TV;
|
||||||
|
}
|
||||||
|
if (other & BCMPAD_BUTTON_RESERVED_BIT) {
|
||||||
|
res |= WUPS_BUTTON_COMBO_BUTTON_RESERVED_BIT;
|
||||||
|
}
|
||||||
|
return static_cast<WUPSButtonCombo_Buttons>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_ComboType convertType(const WUPSButtonCombo_ComboType other) {
|
||||||
|
switch (other) {
|
||||||
|
case WUPS_BUTTON_COMBO_COMBO_TYPE_INVALID:
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_INVALID;
|
||||||
|
case WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD:
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_HOLD;
|
||||||
|
case WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN:
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN;
|
||||||
|
case WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER:
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_HOLD_OBSERVER;
|
||||||
|
case WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN_OBSERVER:
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN_OBSERVER;
|
||||||
|
}
|
||||||
|
return BUTTON_COMBO_MODULE_TYPE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_ComboType convertType(const ButtonComboModule_ComboType other) {
|
||||||
|
switch (other) {
|
||||||
|
case BUTTON_COMBO_MODULE_TYPE_INVALID:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_INVALID;
|
||||||
|
case BUTTON_COMBO_MODULE_TYPE_HOLD:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD;
|
||||||
|
case BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN;
|
||||||
|
case BUTTON_COMBO_MODULE_TYPE_HOLD_OBSERVER:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER;
|
||||||
|
case BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN_OBSERVER:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN_OBSERVER;
|
||||||
|
}
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_TYPE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_ComboStatus convertStatus(const ButtonComboModule_ComboStatus other) {
|
||||||
|
switch (other) {
|
||||||
|
case BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
case BUTTON_COMBO_MODULE_COMBO_STATUS_VALID:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_STATUS_VALID;
|
||||||
|
case BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT:
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_STATUS_CONFLICT;
|
||||||
|
}
|
||||||
|
return WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_MetaOptions convert(const WUPSButtonCombo_MetaOptions &other) {
|
||||||
|
ButtonComboModule_MetaOptions options;
|
||||||
|
options.label = other.label;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_ButtonComboInfoEx convert(const WUPSButtonCombo_ButtonComboInfoEx &other) {
|
||||||
|
ButtonComboModule_ButtonComboInfoEx options;
|
||||||
|
options.basicCombo.combo = convert(other.basicCombo.combo);
|
||||||
|
options.basicCombo.controllerMask = convert(other.basicCombo.controllerMask);
|
||||||
|
options.type = convertType(other.type);
|
||||||
|
options.optionalHoldForXFrames = other.optionalHoldForXFrames;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx convert(const ButtonComboModule_ButtonComboInfoEx &other) {
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx options;
|
||||||
|
options.type = convertType(other.type);
|
||||||
|
options.basicCombo.combo = convert(other.basicCombo.combo);
|
||||||
|
options.basicCombo.controllerMask = convert(other.basicCombo.controllerMask);
|
||||||
|
options.optionalHoldForXFrames = other.optionalHoldForXFrames;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_ButtonComboOptions convert(const WUPSButtonCombo_ButtonComboOptions &other) {
|
||||||
|
ButtonComboModule_ButtonComboOptions options;
|
||||||
|
options.combo = convert(other.combo);
|
||||||
|
options.controllerMask = convert(other.controllerMask);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboModule_DetectButtonComboOptions convert(const WUPSButtonCombo_DetectButtonComboOptions &other) {
|
||||||
|
ButtonComboModule_DetectButtonComboOptions options;
|
||||||
|
options.controllerMask = convert(other.controllerMask);
|
||||||
|
options.abortButtonCombo = convert(other.abortButtonCombo);
|
||||||
|
options.holdAbortForInMs = other.holdAbortForInMs;
|
||||||
|
options.holdComboForInMs = other.holdComboForInMs;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ComboCallbackWrapperData {
|
||||||
|
WUPSButtonCombo_ComboCallback callback = nullptr;
|
||||||
|
void *context = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ButtonComboCallbackWrapper(const ButtonComboModule_ComboHandle handle, void *context) {
|
||||||
|
const auto *data = static_cast<ComboCallbackWrapperData *>(context);
|
||||||
|
data->callback(WUPSButtonCombo_ComboHandle(handle.handle), data->context);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
class ButtonComboWrapper {
|
||||||
|
public:
|
||||||
|
ButtonComboWrapper(const WUPSButtonCombo_ComboOptions &otherOptions, WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
// Abuse this as a stable handle that references itself and survives std::move
|
||||||
|
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
|
||||||
|
|
||||||
|
ButtonComboModule_ComboStatus status = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
mContextData = std::make_unique<ComboCallbackWrapperData>(otherOptions.callbackOptions.callback, otherOptions.callbackOptions.context);
|
||||||
|
ButtonComboModule_ComboOptions convertedOptions;
|
||||||
|
convertedOptions.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
|
||||||
|
convertedOptions.metaOptions = convert(otherOptions.metaOptions);
|
||||||
|
convertedOptions.callbackOptions = {.callback = ButtonComboCallbackWrapper, .context = mContextData.get()};
|
||||||
|
convertedOptions.buttonComboOptions = convert(otherOptions.buttonComboOptions);
|
||||||
|
mCreationError = ButtonComboModule_AddButtonCombo(&convertedOptions, &mButtonComboHandle, &status);
|
||||||
|
outStatus = convertStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ButtonComboWrapper() {
|
||||||
|
if (mButtonComboHandle != nullptr) {
|
||||||
|
if (const auto res = ButtonComboModule_RemoveButtonCombo(mButtonComboHandle); res != BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("ButtonComboModule_RemoveButtonCombo for %08X returned: %s", mButtonComboHandle, ButtonComboModule_GetStatusStr(res));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboWrapper(const ButtonComboWrapper &) = delete;
|
||||||
|
|
||||||
|
ButtonComboWrapper(ButtonComboWrapper &&src) noexcept : mCreationError(src.mCreationError),
|
||||||
|
mButtonComboHandle(src.mButtonComboHandle),
|
||||||
|
mContextData(std::move(src.mContextData)),
|
||||||
|
mHandle(std::move(src.mHandle)) {
|
||||||
|
this->mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
||||||
|
this->mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboWrapper &operator=(ButtonComboWrapper &&src) noexcept {
|
||||||
|
if (this != &src) {
|
||||||
|
this->mCreationError = src.mCreationError;
|
||||||
|
this->mButtonComboHandle = src.mButtonComboHandle;
|
||||||
|
this->mContextData = std::move(src.mContextData);
|
||||||
|
this->mHandle = std::move(src.mHandle);
|
||||||
|
|
||||||
|
this->mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
||||||
|
this->mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_ComboHandle getHandle() const {
|
||||||
|
return WUPSButtonCombo_ComboHandle(reinterpret_cast<void *>(*mHandle));
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboStatus(WUPSButtonCombo_ComboStatus &outStatus) const {
|
||||||
|
ButtonComboModule_ComboStatus status = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
const auto res = ButtonComboModule_GetButtonComboStatus(mButtonComboHandle, &status);
|
||||||
|
if (res == BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
|
||||||
|
outStatus = convertStatus(status);
|
||||||
|
}
|
||||||
|
return convertError(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error UpdateButtonComboMeta(const WUPSButtonCombo_MetaOptions &metaOptions) const {
|
||||||
|
const auto convertedOptions = convert(metaOptions);
|
||||||
|
return convertError(ButtonComboModule_UpdateButtonComboMeta(mButtonComboHandle, &convertedOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error UpdateButtonComboCallback(const WUPSButtonCombo_CallbackOptions &callbackOptions) const {
|
||||||
|
mContextData->callback = callbackOptions.callback;
|
||||||
|
mContextData->context = callbackOptions.context;
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error UpdateControllerMask(const WUPSButtonCombo_ControllerTypes controllerMask,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) const {
|
||||||
|
ButtonComboModule_ComboStatus comboStatus = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
const auto res = convertError(ButtonComboModule_UpdateControllerMask(mButtonComboHandle, convert(controllerMask), &comboStatus));
|
||||||
|
outStatus = convertStatus(comboStatus);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error UpdateButtonCombo(const WUPSButtonCombo_Buttons combo,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) const {
|
||||||
|
ButtonComboModule_ComboStatus comboStatus = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
const auto res = convertError(ButtonComboModule_UpdateButtonCombo(mButtonComboHandle, convert(combo), &comboStatus));
|
||||||
|
outStatus = convertStatus(comboStatus);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error UpdateHoldDuration(const uint32_t holdDurationInFrames) const {
|
||||||
|
return convertError(ButtonComboModule_UpdateHoldDuration(mButtonComboHandle, holdDurationInFrames));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] WUPSButtonCombo_Error GetButtonComboMeta(WUPSButtonCombo_MetaOptionsOut &outOptions) const {
|
||||||
|
ButtonComboModule_MetaOptionsOut options = {.labelBuffer = outOptions.labelBuffer, .labelBufferLength = outOptions.labelBufferLength};
|
||||||
|
return convertError(ButtonComboModule_GetButtonComboMeta(mButtonComboHandle, &options));
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboCallback(WUPSButtonCombo_CallbackOptions &outOptions) const {
|
||||||
|
outOptions.callback = mContextData->callback;
|
||||||
|
outOptions.context = mContextData->context;
|
||||||
|
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboInfoEx(WUPSButtonCombo_ButtonComboInfoEx &outOptions) const {
|
||||||
|
ButtonComboModule_ButtonComboInfoEx tmpOptions;
|
||||||
|
const auto res = convertError(ButtonComboModule_GetButtonComboInfoEx(mButtonComboHandle, &tmpOptions));
|
||||||
|
outOptions = convert(tmpOptions);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetCreationError() const {
|
||||||
|
return convertError(mCreationError);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ButtonComboModule_Error mCreationError;
|
||||||
|
ButtonComboModule_ComboHandle mButtonComboHandle;
|
||||||
|
std::unique_ptr<ComboCallbackWrapperData> mContextData;
|
||||||
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
|
};
|
||||||
|
|
||||||
|
ButtonComboManager::ButtonComboManager() {
|
||||||
|
// Abuse this as a stable handle that references itself and survives std::move
|
||||||
|
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboManager::~ButtonComboManager() = default;
|
||||||
|
|
||||||
|
ButtonComboManager::ButtonComboManager(ButtonComboManager &&src) : mComboWrappers(std::move(src.mComboWrappers)), mHandle(std::move(src.mHandle)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonComboManager &ButtonComboManager::operator=(ButtonComboManager &&src) {
|
||||||
|
if (this != &src) {
|
||||||
|
this->mHandle = std::move(src.mHandle);
|
||||||
|
this->mComboWrappers = std::move(src.mComboWrappers);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::AddButtonComboHandle(const WUPSButtonCombo_ComboOptions &options,
|
||||||
|
WUPSButtonCombo_ComboHandle &outHandle,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
mComboWrappers.emplace_back(options, outStatus);
|
||||||
|
const auto &addedItem = mComboWrappers.back();
|
||||||
|
const auto handle = addedItem.getHandle();
|
||||||
|
if (const auto res = addedItem.GetCreationError(); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
|
||||||
|
if (!remove_first_if(mComboWrappers, [&handle](const auto &comboWrapper) { return comboWrapper.getHandle() == handle; })) {
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("Failed to re removed from mComboWrappers");
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
outHandle = handle;
|
||||||
|
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::RemoveButtonCombo(const WUPSButtonCombo_ComboHandle handle) {
|
||||||
|
if (remove_first_if(mComboWrappers, [&handle](const auto &comboWrapper) { return comboWrapper.getHandle() == handle; })) {
|
||||||
|
// Destructor removes it from the button combo module
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Could not remove button combo: not found! %08X", handle);
|
||||||
|
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::GetButtonComboStatus(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.GetButtonComboStatus(outStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::UpdateButtonComboMeta(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_MetaOptions &metaOptions) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.UpdateButtonComboMeta(metaOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::UpdateButtonComboCallback(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_CallbackOptions &callbackOptions) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.UpdateButtonComboCallback(callbackOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::UpdateControllerMask(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_ControllerTypes controllerMask,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.UpdateControllerMask(controllerMask, outStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::UpdateButtonCombo(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_Buttons combo,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.UpdateButtonCombo(combo, outStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::UpdateHoldDuration(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const uint32_t holdDurationInFrames) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.UpdateHoldDuration(holdDurationInFrames);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::GetButtonComboMeta(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_MetaOptionsOut &outOptions) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.GetButtonComboMeta(outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::GetButtonComboCallback(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_CallbackOptions &outOptions) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.GetButtonComboCallback(outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::GetButtonComboInfoEx(const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx &outOptions) {
|
||||||
|
return ExecuteForWrapper(handle, [&](const ButtonComboWrapper &wrapper) {
|
||||||
|
return wrapper.GetButtonComboInfoEx(outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::CheckComboAvailable(const WUPSButtonCombo_ButtonComboOptions &options,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
|
const auto convertedOptions = convert(options);
|
||||||
|
ButtonComboModule_ComboStatus status = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
const auto res = convertError(ButtonComboModule_CheckComboAvailable(&convertedOptions, &status));
|
||||||
|
outStatus = convertStatus(status);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::DetectButtonCombo_Blocking(const WUPSButtonCombo_DetectButtonComboOptions &options, WUPSButtonCombo_Buttons &outButtonCombo) {
|
||||||
|
const auto convertedOptions = convert(options);
|
||||||
|
auto combo = static_cast<ButtonComboModule_Buttons>(0);
|
||||||
|
const auto res = convertError(ButtonComboModule_DetectButtonCombo_Blocking(&convertedOptions, &combo));
|
||||||
|
outButtonCombo = convert(combo);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ButtonComboManager::ExecuteForWrapper(const WUPSButtonCombo_ComboHandle &handle, const std::function<WUPSButtonCombo_Error(ButtonComboWrapper &)> &callback) {
|
||||||
|
if (handle == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
for (auto &wrapper : mComboWrappers) {
|
||||||
|
if (wrapper.getHandle() == handle) {
|
||||||
|
return callback(wrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ButtonComboManager::getHandle() const {
|
||||||
|
return *mHandle;
|
||||||
|
}
|
73
source/plugin/ButtonComboManager.h
Normal file
73
source/plugin/ButtonComboManager.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <buttoncombo/defines.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <wups/button_combo.h>
|
||||||
|
|
||||||
|
|
||||||
|
class ButtonComboWrapper;
|
||||||
|
|
||||||
|
class ButtonComboManager {
|
||||||
|
public:
|
||||||
|
explicit ButtonComboManager();
|
||||||
|
~ButtonComboManager();
|
||||||
|
|
||||||
|
|
||||||
|
ButtonComboManager(const ButtonComboManager &) = delete;
|
||||||
|
|
||||||
|
ButtonComboManager(ButtonComboManager &&src) noexcept;
|
||||||
|
|
||||||
|
ButtonComboManager &operator=(ButtonComboManager &&src) noexcept;
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error AddButtonComboHandle(const WUPSButtonCombo_ComboOptions &options,
|
||||||
|
WUPSButtonCombo_ComboHandle &outHandle,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error RemoveButtonCombo(WUPSButtonCombo_ComboHandle handle);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboStatus(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboMeta(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_MetaOptions &metaOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboCallback(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_CallbackOptions &callbackOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateControllerMask(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ControllerTypes controllerMask,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonCombo(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_Buttons combo,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateHoldDuration(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
uint32_t holdDurationInFrames);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboMeta(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_MetaOptionsOut &outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboCallback(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_CallbackOptions &outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboInfoEx(WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx &outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error CheckComboAvailable(const WUPSButtonCombo_ButtonComboOptions &options,
|
||||||
|
WUPSButtonCombo_ComboStatus &outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error DetectButtonCombo_Blocking(const WUPSButtonCombo_DetectButtonComboOptions &options,
|
||||||
|
WUPSButtonCombo_Buttons &outButtonCombo);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error ExecuteForWrapper(const WUPSButtonCombo_ComboHandle &handle, const std::function<WUPSButtonCombo_Error(ButtonComboWrapper &)> &callback);
|
||||||
|
|
||||||
|
[[nodiscard]] uint32_t getHandle() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ButtonComboWrapper> mComboWrappers;
|
||||||
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
|
};
|
@ -1,36 +1,43 @@
|
|||||||
#include "PluginContainer.h"
|
#include "PluginContainer.h"
|
||||||
#include "utils/storage/StorageUtils.h"
|
#include "utils/storage/StorageUtils.h"
|
||||||
|
|
||||||
|
#include <utils/buttoncombo/ButtonComboUtils.h>
|
||||||
|
|
||||||
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData)
|
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData)
|
||||||
: mMetaInformation(std::move(metaInformation)),
|
: mMetaInformation(std::move(metaInformation)),
|
||||||
mPluginLinkInformation(std::move(pluginLinkInformation)),
|
mPluginLinkInformation(std::move(pluginLinkInformation)),
|
||||||
mPluginData(std::move(pluginData)) {
|
mPluginData(std::move(pluginData)) {
|
||||||
|
// Abuse this as a stable handle that references itself and survives std::move
|
||||||
|
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginContainer::PluginContainer(PluginContainer &&src) noexcept : mMetaInformation(std::move(src.mMetaInformation)),
|
||||||
PluginContainer::PluginContainer(PluginContainer &&src) : mMetaInformation(std::move(src.mMetaInformation)),
|
mPluginLinkInformation(std::move(src.mPluginLinkInformation)),
|
||||||
mPluginLinkInformation(std::move(src.mPluginLinkInformation)),
|
mPluginData(std::move(src.mPluginData)),
|
||||||
mPluginData(std::move(src.mPluginData)),
|
mHandle(std::move(src.mHandle)),
|
||||||
mPluginConfigData(std::move(src.mPluginConfigData)),
|
mPluginConfigData(std::move(src.mPluginConfigData)),
|
||||||
mStorageRootItem(src.mStorageRootItem),
|
mStorageRootItem(src.mStorageRootItem),
|
||||||
mInitDone(src.mInitDone)
|
mInitDone(src.mInitDone),
|
||||||
|
mButtonComboManagerHandle(src.mButtonComboManagerHandle) {
|
||||||
{
|
src.mHandle = {};
|
||||||
src.mStorageRootItem = {};
|
src.mStorageRootItem = {};
|
||||||
src.mInitDone = {};
|
src.mInitDone = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginContainer &PluginContainer::operator=(PluginContainer &&src) noexcept {
|
PluginContainer &PluginContainer::operator=(PluginContainer &&src) noexcept {
|
||||||
if (this != &src) {
|
if (this != &src) {
|
||||||
this->mMetaInformation = std::move(src.mMetaInformation);
|
this->mMetaInformation = std::move(src.mMetaInformation);
|
||||||
this->mPluginLinkInformation = std::move(src.mPluginLinkInformation);
|
this->mPluginLinkInformation = std::move(src.mPluginLinkInformation);
|
||||||
this->mPluginData = std::move(src.mPluginData);
|
this->mPluginData = std::move(src.mPluginData);
|
||||||
this->mPluginConfigData = std::move(src.mPluginConfigData);
|
this->mPluginConfigData = std::move(src.mPluginConfigData);
|
||||||
this->mStorageRootItem = src.mStorageRootItem;
|
this->mHandle = std::move(src.mHandle);
|
||||||
this->mInitDone = src.mInitDone;
|
this->mStorageRootItem = src.mStorageRootItem;
|
||||||
|
this->mInitDone = src.mInitDone;
|
||||||
|
this->mButtonComboManagerHandle = src.mButtonComboManagerHandle;
|
||||||
|
|
||||||
src.mStorageRootItem = nullptr;
|
src.mStorageRootItem = nullptr;
|
||||||
src.mInitDone = false;
|
src.mInitDone = false;
|
||||||
|
src.mButtonComboManagerHandle = false;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -39,7 +46,6 @@ const PluginMetaInformation &PluginContainer::getMetaInformation() const {
|
|||||||
return this->mMetaInformation;
|
return this->mMetaInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const PluginLinkInformation &PluginContainer::getPluginLinkInformation() const {
|
const PluginLinkInformation &PluginContainer::getPluginLinkInformation() const {
|
||||||
return this->mPluginLinkInformation;
|
return this->mPluginLinkInformation;
|
||||||
}
|
}
|
||||||
@ -53,7 +59,7 @@ std::shared_ptr<PluginData> PluginContainer::getPluginDataCopy() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PluginContainer::getHandle() const {
|
uint32_t PluginContainer::getHandle() const {
|
||||||
return reinterpret_cast<uint32_t>(this);
|
return *mHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::optional<PluginConfigData> &PluginContainer::getConfigData() const {
|
const std::optional<PluginConfigData> &PluginContainer::getConfigData() const {
|
||||||
@ -104,4 +110,21 @@ void PluginContainer::setInitDone(const bool val) {
|
|||||||
|
|
||||||
bool PluginContainer::isInitDone() const {
|
bool PluginContainer::isInitDone() const {
|
||||||
return mInitDone;
|
return mInitDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginContainer::InitButtonComboData() {
|
||||||
|
if (getMetaInformation().getWUPSVersion() < WUPSVersion(0, 8, 2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mButtonComboManagerHandle = ButtonComboUtils::API::Internal::CreateButtonComboData();
|
||||||
|
}
|
||||||
|
void PluginContainer::DeinitButtonComboData() {
|
||||||
|
if (getMetaInformation().getWUPSVersion() < WUPSVersion(0, 8, 2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ButtonComboUtils::API::Internal::RemoveButtonComboData(mButtonComboManagerHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t PluginContainer::getButtonComboManagerHandle() const {
|
||||||
|
return mButtonComboManagerHandle;
|
||||||
}
|
}
|
@ -32,9 +32,9 @@ public:
|
|||||||
|
|
||||||
PluginContainer(const PluginContainer &) = delete;
|
PluginContainer(const PluginContainer &) = delete;
|
||||||
|
|
||||||
PluginContainer(PluginContainer &&src);
|
PluginContainer(PluginContainer &&src) noexcept;
|
||||||
|
|
||||||
PluginContainer &operator=(PluginContainer &&src);
|
PluginContainer &operator=(PluginContainer &&src) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const;
|
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const;
|
||||||
|
|
||||||
@ -62,12 +62,20 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] bool isInitDone() const;
|
[[nodiscard]] bool isInitDone() const;
|
||||||
|
|
||||||
|
void InitButtonComboData();
|
||||||
|
void DeinitButtonComboData();
|
||||||
|
|
||||||
|
[[nodiscard]] uint32_t getButtonComboManagerHandle() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginMetaInformation mMetaInformation;
|
PluginMetaInformation mMetaInformation;
|
||||||
PluginLinkInformation mPluginLinkInformation;
|
PluginLinkInformation mPluginLinkInformation;
|
||||||
std::shared_ptr<PluginData> mPluginData;
|
std::shared_ptr<PluginData> mPluginData;
|
||||||
|
|
||||||
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
|
|
||||||
std::optional<PluginConfigData> mPluginConfigData = std::nullopt;
|
std::optional<PluginConfigData> mPluginConfigData = std::nullopt;
|
||||||
wups_storage_root_item mStorageRootItem = nullptr;
|
wups_storage_root_item mStorageRootItem = nullptr;
|
||||||
bool mInitDone = false;
|
bool mInitDone = false;
|
||||||
|
uint32_t mButtonComboManagerHandle = 0;
|
||||||
};
|
};
|
||||||
|
@ -1,26 +1,29 @@
|
|||||||
#include "PluginData.h"
|
#include "PluginData.h"
|
||||||
|
|
||||||
PluginData::PluginData(std::vector<uint8_t> &&buffer, const std::string_view source) : mBuffer(std::move(buffer)), mSource(source) {
|
PluginData::PluginData(std::vector<uint8_t> &&buffer, const std::string_view source) : mBuffer(std::move(buffer)), mSource(source) {
|
||||||
|
// Abuse this as a stable handle that references itself and survives std::move
|
||||||
|
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginData::PluginData(std::span<uint8_t> buffer, const std::string_view source) : mBuffer(buffer.begin(), buffer.end()), mSource(source) {
|
PluginData::PluginData(std::span<uint8_t> buffer, const std::string_view source) : PluginData(std::vector(buffer.begin(), buffer.end()), source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData(PluginData &&src) : mBuffer(std::move(src.mBuffer)),
|
PluginData::PluginData(PluginData &&src) : mBuffer(std::move(src.mBuffer)),
|
||||||
mSource(std::move(src.mSource)) {
|
mSource(std::move(src.mSource)),
|
||||||
|
mHandle(std::move(src.mHandle)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginData &PluginData::operator=(PluginData &&src) noexcept {
|
PluginData &PluginData::operator=(PluginData &&src) noexcept {
|
||||||
if (this != &src) {
|
if (this != &src) {
|
||||||
this->mBuffer = std::move(src.mBuffer);
|
this->mBuffer = std::move(src.mBuffer);
|
||||||
this->mSource = std::move(src.mSource);
|
this->mSource = std::move(src.mSource);
|
||||||
|
this->mHandle = std::move(src.mHandle);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PluginData::getHandle() const {
|
uint32_t PluginData::getHandle() const {
|
||||||
return reinterpret_cast<uint32_t>(this);
|
return *mHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::span<const uint8_t> PluginData::getBuffer() const {
|
std::span<const uint8_t> PluginData::getBuffer() const {
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::vector<uint8_t> mBuffer;
|
std::vector<uint8_t> mBuffer;
|
||||||
std::string mSource;
|
std::string mSource;
|
||||||
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PluginDataSharedPtrComparator {
|
struct PluginDataSharedPtrComparator {
|
||||||
|
@ -113,6 +113,8 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(st
|
|||||||
pluginInfo.setWUPSVersion(0, 7, 1);
|
pluginInfo.setWUPSVersion(0, 7, 1);
|
||||||
} else if (value == "0.8.1") {
|
} else if (value == "0.8.1") {
|
||||||
pluginInfo.setWUPSVersion(0, 8, 1);
|
pluginInfo.setWUPSVersion(0, 8, 1);
|
||||||
|
} else if (value == "0.8.2") {
|
||||||
|
pluginInfo.setWUPSVersion(0, 8, 2);
|
||||||
} else {
|
} else {
|
||||||
error = PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION;
|
error = PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION;
|
||||||
DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
|
DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
HeapMemoryFixedSize::HeapMemoryFixedSize() = default;
|
HeapMemoryFixedSize::HeapMemoryFixedSize() = default;
|
||||||
|
|
||||||
HeapMemoryFixedSize::HeapMemoryFixedSize(std::size_t size) : mData(make_unique_nothrow<uint8_t[]>(size)), mSize(mData ? size : 0) {}
|
HeapMemoryFixedSize::HeapMemoryFixedSize(const std::size_t size) : mData(make_unique_nothrow<uint8_t[]>(size)), mSize(mData ? size : 0) {}
|
||||||
|
|
||||||
HeapMemoryFixedSize::HeapMemoryFixedSize(HeapMemoryFixedSize &&other) noexcept
|
HeapMemoryFixedSize::HeapMemoryFixedSize(HeapMemoryFixedSize &&other) noexcept
|
||||||
: mData(std::move(other.mData)), mSize(other.mSize) {
|
: mData(std::move(other.mData)), mSize(other.mSize) {
|
||||||
|
200
source/utils/buttoncombo/ButtonComboUtils.cpp
Normal file
200
source/utils/buttoncombo/ButtonComboUtils.cpp
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
#include "ButtonComboUtils.h"
|
||||||
|
|
||||||
|
#include <forward_list>
|
||||||
|
#include <mutex>
|
||||||
|
#include <plugin/ButtonComboManager.h>
|
||||||
|
#include <plugin/PluginContainer.h>
|
||||||
|
#include <utils/logger.h>
|
||||||
|
#include <utils/utils.h>
|
||||||
|
|
||||||
|
namespace ButtonComboUtils::API {
|
||||||
|
static std::forward_list<ButtonComboManager> sButtonComboManager;
|
||||||
|
static std::mutex sButtonComboMutex;
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
uint32_t CreateButtonComboData() {
|
||||||
|
std::lock_guard lock(sButtonComboMutex);
|
||||||
|
sButtonComboManager.emplace_front();
|
||||||
|
return sButtonComboManager.front().getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveButtonComboData(uint32_t buttonComboManagerHandle) {
|
||||||
|
if (!remove_locked_first_if(sButtonComboMutex, sButtonComboManager, [buttonComboManagerHandle](const ButtonComboManager &buttonComboData) { return buttonComboData.getHandle() == buttonComboManagerHandle; })) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Tried to remove ButtonComboManager by invalid handle: %08X", buttonComboManagerHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
WUPSButtonCombo_Error ExecuteForIdentifierLocked(void *identifier, const std::function<WUPSButtonCombo_Error(ButtonComboManager &)> &callback) {
|
||||||
|
if (identifier == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
std::lock_guard lock(sButtonComboMutex);
|
||||||
|
for (auto &manager : sButtonComboManager) {
|
||||||
|
if (manager.getHandle() == reinterpret_cast<uint32_t>(identifier)) {
|
||||||
|
return callback(manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error AddButtonCombo(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboOptions *options,
|
||||||
|
WUPSButtonCombo_ComboHandle *outHandle,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus) {
|
||||||
|
if (options == nullptr || outHandle == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
WUPSButtonCombo_ComboStatus tmpStatus;
|
||||||
|
const auto res = ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.AddButtonComboHandle(*options, *outHandle, tmpStatus);
|
||||||
|
});
|
||||||
|
if (outStatus) { *outStatus = tmpStatus; }
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error RemoveButtonCombo(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle) {
|
||||||
|
if (identifier == nullptr || handle == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.RemoveButtonCombo(handle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboStatus(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus) {
|
||||||
|
if (identifier == nullptr || handle == nullptr || outStatus == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.GetButtonComboStatus(handle, *outStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboMeta(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_MetaOptions *metaOptions) {
|
||||||
|
if (metaOptions == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.UpdateButtonComboMeta(handle, *metaOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboCallback(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_CallbackOptions *callbackOptions) {
|
||||||
|
if (callbackOptions == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.UpdateButtonComboCallback(handle, *callbackOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateControllerMask(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_ControllerTypes controllerMask,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus) {
|
||||||
|
WUPSButtonCombo_ComboStatus tmpStatus;
|
||||||
|
const auto res = ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.UpdateControllerMask(handle, controllerMask, tmpStatus);
|
||||||
|
});
|
||||||
|
if (outStatus) { *outStatus = tmpStatus; }
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonCombo(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_Buttons combo,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus) {
|
||||||
|
WUPSButtonCombo_ComboStatus tmpStatus;
|
||||||
|
const auto res = ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.UpdateButtonCombo(handle, combo, tmpStatus);
|
||||||
|
});
|
||||||
|
if (outStatus) { *outStatus = tmpStatus; }
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateHoldDuration(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const uint32_t holdDurationInFrames) {
|
||||||
|
const auto res = ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.UpdateHoldDuration(handle, holdDurationInFrames);
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboMeta(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_MetaOptionsOut *outOptions) {
|
||||||
|
if (outOptions == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.GetButtonComboMeta(handle, *outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
WUPSButtonCombo_Error GetButtonComboCallback(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_CallbackOptions *outOptions) {
|
||||||
|
|
||||||
|
if (outOptions == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.GetButtonComboCallback(handle, *outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboInfoEx(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx *outOptions) {
|
||||||
|
if (outOptions == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.GetButtonComboInfoEx(handle, *outOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error CheckComboAvailable(void *identifier,
|
||||||
|
const WUPSButtonCombo_ButtonComboOptions *options,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus) {
|
||||||
|
if (outStatus == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.CheckComboAvailable(*options, *outStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
WUPSButtonCombo_Error DetectButtonCombo_Blocking(void *identifier,
|
||||||
|
const WUPSButtonCombo_DetectButtonComboOptions *options,
|
||||||
|
WUPSButtonCombo_Buttons *outButtonCombo) {
|
||||||
|
if (options == nullptr || outButtonCombo == nullptr) {
|
||||||
|
return WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
return ExecuteForIdentifierLocked(identifier,
|
||||||
|
[&](ButtonComboManager &manager) {
|
||||||
|
return manager.DetectButtonCombo_Blocking(*options, *outButtonCombo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace ButtonComboUtils::API
|
65
source/utils/buttoncombo/ButtonComboUtils.h
Normal file
65
source/utils/buttoncombo/ButtonComboUtils.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <wups/button_combo.h>
|
||||||
|
|
||||||
|
namespace ButtonComboUtils::API {
|
||||||
|
namespace Internal {
|
||||||
|
uint32_t CreateButtonComboData();
|
||||||
|
void RemoveButtonComboData(uint32_t buttonComboManagerHandle);
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error AddButtonCombo(void *identifier,
|
||||||
|
const WUPSButtonCombo_ComboOptions *options,
|
||||||
|
WUPSButtonCombo_ComboHandle *outHandle,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error RemoveButtonCombo(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboStatus(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboMeta(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_MetaOptions *metaOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonComboCallback(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
const WUPSButtonCombo_CallbackOptions *callbackOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateControllerMask(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ControllerTypes controllerMask,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateButtonCombo(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_Buttons combo,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error UpdateHoldDuration(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
uint32_t holdDurationInFrames);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboMeta(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_MetaOptionsOut *outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboCallback(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_CallbackOptions *outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error GetButtonComboInfoEx(void *identifier,
|
||||||
|
WUPSButtonCombo_ComboHandle handle,
|
||||||
|
WUPSButtonCombo_ButtonComboInfoEx *outOptions);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error CheckComboAvailable(void *identifier,
|
||||||
|
const WUPSButtonCombo_ButtonComboOptions *options,
|
||||||
|
WUPSButtonCombo_ComboStatus *outStatus);
|
||||||
|
|
||||||
|
WUPSButtonCombo_Error DetectButtonCombo_Blocking(void *identifier,
|
||||||
|
const WUPSButtonCombo_DetectButtonComboOptions *options,
|
||||||
|
WUPSButtonCombo_Buttons *outButtonCombo);
|
||||||
|
|
||||||
|
} // namespace ButtonComboUtils::API
|
@ -108,12 +108,10 @@ void ConfigUtils::displayMenu() {
|
|||||||
for (const auto &hook : plugin.getPluginLinkInformation().getHookDataList()) {
|
for (const auto &hook : plugin.getPluginLinkInformation().getHookDataList()) {
|
||||||
if (hook.getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) {
|
if (hook.getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) {
|
||||||
if (hook.getFunctionPointer() == nullptr) {
|
if (hook.getFunctionPointer() == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Hook had invalid ptr");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto cur_config_handle = ((void *(*) ())((uint32_t *) hook.getFunctionPointer()))();
|
auto cur_config_handle = ((void *(*) ())((uint32_t *) hook.getFunctionPointer()))();
|
||||||
if (cur_config_handle == nullptr) {
|
if (cur_config_handle == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE_WARN("Hook returned empty handle");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
config = WUPSConfigAPIBackend::Intern::PopConfigByHandle(WUPSConfigHandle(cur_config_handle));
|
config = WUPSConfigAPIBackend::Intern::PopConfigByHandle(WUPSConfigHandle(cur_config_handle));
|
||||||
@ -238,11 +236,6 @@ void ConfigUtils::displayMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_FUNCTION_LINE_INFO("Save new plugin list");
|
|
||||||
for (const auto &cur : newActivePluginsList) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("%08X %s", cur.getPluginData()->getHandle(), cur.isLoadAndLink() ? "active" : "inactive");
|
|
||||||
}
|
|
||||||
DEBUG_FUNCTION_LINE_INFO("===");
|
|
||||||
gLoadOnNextLaunch = newActivePluginsList;
|
gLoadOnNextLaunch = newActivePluginsList;
|
||||||
WUPSBackendSettings::SetInactivePluginFilenames(newInactivePluginsList);
|
WUPSBackendSettings::SetInactivePluginFilenames(newInactivePluginsList);
|
||||||
if (!WUPSBackendSettings::SaveSettings()) {
|
if (!WUPSBackendSettings::SaveSettings()) {
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
StorageItem::StorageItem(const std::string_view key) : mKey(key) {
|
StorageItem::StorageItem(const std::string_view key) : mKey(key) {
|
||||||
|
// Abuse this as a stable handle that references itself and survives std::move
|
||||||
|
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t StorageItem::getHandle() const {
|
uint32_t StorageItem::getHandle() const {
|
||||||
return reinterpret_cast<uint32_t>(this);
|
return *mHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageItem::setValue(const std::string &value) {
|
void StorageItem::setValue(const std::string &value) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -78,4 +79,6 @@ private:
|
|||||||
std::string mKey = {};
|
std::string mKey = {};
|
||||||
|
|
||||||
bool mBinaryConversionDone = true;
|
bool mBinaryConversionDone = true;
|
||||||
|
|
||||||
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user