Compare commits

...

21 Commits

Author SHA1 Message Date
Maschell
d7ea75f62c Update README.md 2024-05-08 21:35:56 +02:00
Maschell
0178383d33 Fix button combo detection for non-gamepad inputs, fix read change screen butto combo from config 2024-05-05 20:09:53 +02:00
Maschell
11dd5cde0a Add optional button combo to change screen mode 2024-05-05 18:28:08 +02:00
Maschell
835b89e8c0 Update Dockerfile 2024-05-05 18:00:46 +02:00
Maschell
0068582247 Update README 2024-04-27 14:33:49 +02:00
Maschell
de51a480d5 asdasd 2024-04-27 14:33:49 +02:00
Maschell
26283f918b Bump version 2024-04-27 14:33:49 +02:00
Maschell
09170c6010 Bump actions/checkout from 3 to 4 2024-04-27 14:33:49 +02:00
Maschell
09b5fefefa Bump softprops/action-gh-release from 1 to 2 2024-04-27 14:33:49 +02:00
Maschell
aba9be5e42 Update Dockerfile 2024-04-27 14:33:49 +02:00
Maschell
0221a05d96 Add support for mirroring the TV/DRC 2024-04-27 14:33:49 +02:00
Maschell
709868e825 Make sure to init static variables 2024-04-27 14:33:49 +02:00
Maschell
a75839ba27 Fix button combo checking in games that use ButtonProcMode 1 2024-04-27 14:33:49 +02:00
Maschell
52ce023982 Log actuall error code on error 2024-04-27 14:33:49 +02:00
Maschell
508cc5e03e Only update storage at application end if the value actually changed 2024-04-27 14:33:49 +02:00
Maschell
039263864f Refactor the config callbacks 2024-04-27 14:33:49 +02:00
Maschell
19fa1e0fe2 Add base settings to the root of the config 2024-04-27 14:33:49 +02:00
Maschell
fa1421f33b Update .gitignore to ignore zip files 2024-04-27 14:33:49 +02:00
Maschell
68da7df659 WUPS 0.8.0 support 2024-04-27 14:33:49 +02:00
Maschell
0fad651cd2 Create dependabot.yml 2023-07-24 10:12:20 +02:00
Maschell
411cf238e3 Bump version 2023-07-19 19:34:53 +02:00
18 changed files with 609 additions and 254 deletions

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

View File

@ -9,7 +9,7 @@ jobs:
clang-format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src --exclude ./src/utils/json.hpp
@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: create version.h
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
@ -48,7 +48,7 @@ jobs:
- name: zip artifact
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps
- name: Create Release
uses: "softprops/action-gh-release@v1"
uses: "softprops/action-gh-release@v2"
with:
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
draft: false

View File

@ -6,7 +6,7 @@ jobs:
clang-format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src --exclude ./src/utils/json.hpp
@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: build binary with logging
run: |
docker build . -t builder
@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: create version.h
run: |
git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}")

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ cmake-build-debug/
*.wps
*.elf
CMakeLists.txt
*.zip

View File

@ -1,7 +1,7 @@
FROM ghcr.io/wiiu-env/devkitppc:20230621
FROM ghcr.io/wiiu-env/devkitppc:20240505
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libnotifications:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240505 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libnotifications:20240426 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
WORKDIR project

View File

@ -34,7 +34,7 @@ CFLAGS := -Wall -O2 -ffunction-sections \
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti
CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUPSSPECS)

View File

@ -26,6 +26,8 @@ Via the plugin config menu (press L, DPAD Down and Minus on the GamePad, Pro Con
- Displays notifications when swapping the screens or changing the audio mode.
- Swap screens: (Default is false)
- Swaps the TV and GamePad screen when set to true.
- Screen mode: (Default is "Normal")
- Sets the screen mode. See "Screen modes" for more details.
- Audio mode: (Default is "Sound matches screen")
- Sets the audio mode. See "Audio modes" for more details.
- **Button combos**
@ -33,6 +35,10 @@ Via the plugin config menu (press L, DPAD Down and Minus on the GamePad, Pro Con
- Determines if the screen can be swapped with a button combo.
- Swap screen: (Default is the "TV" button)
- Button combo to swap the TV and GamePad screen.
- Enable swap change button combo: (Default is false)
- Determines if the screen can be changed with a button combo.
- Change screen: (Default is "right stick button"/R3)
- Button combo to change screen mode.
- Enable change audio mode button combo: (Default is false)
- Determines if the audio mode can be changed via a button combo.
- Change audio: (Default is "left stick button"/L3)
@ -53,6 +59,19 @@ SwipSwapme does not only allow you to swap the screen, it also offers multiple a
- **Left: TV; Right: GamePad**
- Outputs the TV sound on the left speaker, and the GamePad sound on the right speaker.
#### Screen Modes
SwipSwapme does not only allow you to swap the screen, it also offers multiple screen modes:
- **Normal**
- The screen output is not touched at all.
- **Swap TV and GamePad**
- Swaps the TV and GamePad screen.
- **Mirror TV**
- Mirrors the TV screen onto the GamePad.
- **Mirror GamePad**
- Mirrors the GamePad screen onto the TV.
## Building
For building you need:

View File

@ -29,12 +29,36 @@
void UpdateAudioMode();
DECL_FUNCTION(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer, GX2ScanTarget scan_target) {
if (gEnabled && gDoScreenSwap) {
if (scan_target == GX2_SCAN_TARGET_TV) {
scan_target = GX2_SCAN_TARGET_DRC;
} else if (scan_target == GX2_SCAN_TARGET_DRC) {
scan_target = GX2_SCAN_TARGET_TV;
if (gEnabled && gCurScreenMode != SCREEN_MODE_NONE) {
switch (gCurScreenMode) {
case SCREEN_MODE_SWAP: {
if (scan_target == GX2_SCAN_TARGET_TV) {
scan_target = GX2_SCAN_TARGET_DRC;
} else if (scan_target == GX2_SCAN_TARGET_DRC) {
scan_target = GX2_SCAN_TARGET_TV;
}
break;
}
case SCREEN_MODE_MIRROR_TV: {
if (scan_target == GX2_SCAN_TARGET_TV) {
scan_target = GX2_SCAN_TARGET_TV | GX2_SCAN_TARGET_DRC;
} else if (scan_target == GX2_SCAN_TARGET_DRC) {
return;
}
break;
}
case SCREEN_MODE_MIRROR_DRC: {
if (scan_target == GX2_SCAN_TARGET_DRC) {
scan_target = GX2_SCAN_TARGET_TV | GX2_SCAN_TARGET_DRC;
} else if (scan_target == GX2_SCAN_TARGET_TV) {
return;
}
break;
}
default:
break;
}
if (colorBuffer->surface.aa != GX2_AA_MODE1X) {
// If AA is enabled, we need to resolve the AA buffer.
GX2Surface tempSurface;
@ -65,23 +89,52 @@ DECL_FUNCTION(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer,
real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target);
}
const char *screenModeToStr(SwipSwapScreenMode mode) {
switch (mode) {
case SCREEN_MODE_NONE:
return "Screen mode: Normal";
case SCREEN_MODE_SWAP:
return "Screen mode: Swapping TV and GamePad";
case SCREEN_MODE_MIRROR_TV:
return "Screen mode: Mirror TV to GamePad";
case SCREEN_MODE_MIRROR_DRC:
return "Screen mode: Mirror GamePad to TV";
case SCREEN_MODE_MAX_VALUE:
break;
}
return "Invalid screen mode";
}
void SwapScreens() {
gDoScreenSwap = !gDoScreenSwap;
if (gCurScreenMode == SCREEN_MODE_SWAP) {
gCurScreenMode = SCREEN_MODE_NONE;
} else {
gCurScreenMode = SCREEN_MODE_SWAP;
}
if (gShowNotifications && gNotificationModuleInitDone) {
if (gDoScreenSwap) {
NotificationModule_AddInfoNotification("Swapping TV and GamePad screen");
} else {
NotificationModule_AddInfoNotification("Stop swapping TV and GamePad screen");
}
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
}
}
void ChangeScreens() {
auto val = (uint32_t) gCurScreenMode;
val++;
if (val >= SCREEN_MODE_MAX_VALUE) {
val = 0;
}
gCurScreenMode = static_cast<SwipSwapScreenMode>(val);
if (gShowNotifications && gNotificationModuleInitDone) {
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
}
}
void SwapVoices();
extern "C" uint32_t VPADGetButtonProcMode(VPADChan chan);
static uint32_t sSwapScreenWasHoldForXFrameGamePad;
static uint32_t sSwapVoicesWasHoldForXFrameGamePad;
static uint32_t sSwapScreenWasHoldForXFrameGamePad = 0;
static uint32_t sChangeScreenWasHoldForXFrameGamePad = 0;
static uint32_t sSwapVoicesWasHoldForXFrameGamePad = 0;
DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) {
VPADReadError real_error;
int32_t result = real_VPADRead(chan, buffer, buffer_size, &real_error);
@ -92,18 +145,25 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
bool checkFullBuffer = VPADGetButtonProcMode(chan) == 1;
if (gChangeAudioModeButtonComboEnabled && checkButtonComboVPAD(buffer,
checkFullBuffer ? buffer_size : 1,
checkFullBuffer ? result : 1,
gSwapAudioButtonCombo,
sSwapVoicesWasHoldForXFrameGamePad)) {
SwapVoices();
}
if (gSwapScreenButtonComboEnabled && checkButtonComboVPAD(buffer,
checkFullBuffer ? buffer_size : 1,
checkFullBuffer ? result : 1,
gSwapScreenButtonCombo,
sSwapScreenWasHoldForXFrameGamePad)) {
SwapScreens();
}
if (gChangeScreenModeButtonComboEnabled && checkButtonComboVPAD(buffer,
checkFullBuffer ? result : 1,
gChangeScreenButtonCombo,
sChangeScreenWasHoldForXFrameGamePad)) {
ChangeScreens();
}
}
}
@ -113,7 +173,7 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
return result;
}
const char *modeToStr(SwipSwapAudioMode mode) {
const char *audioModeToStr(SwipSwapAudioMode mode) {
switch (mode) {
case AUDIO_MODE_NONE:
return "Audio mode: Normal";
@ -139,11 +199,12 @@ void SwapVoices() {
}
gCurAudioMode = static_cast<SwipSwapAudioMode>(val);
if (gShowNotifications && gNotificationModuleInitDone) {
NotificationModule_AddInfoNotification(modeToStr(gCurAudioMode));
NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode));
}
}
static uint32_t sSwapScreenWasHoldForXFrame[4];
static uint32_t sChangeScreenWasHoldForXFrame[4];
static uint32_t sSwapAudioWasHoldForXFrame[4];
DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
real_WPADRead(chan, data);
@ -167,6 +228,9 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
if (gChangeAudioModeButtonComboEnabled && checkButtonComboWPAD(curButtonHold, gSwapAudioButtonCombo, sSwapAudioWasHoldForXFrame[chan])) {
SwapVoices();
}
if (gChangeScreenModeButtonComboEnabled && checkButtonComboWPAD(curButtonHold, gChangeScreenButtonCombo, sChangeScreenWasHoldForXFrame[chan])) {
ChangeScreens();
}
}
}
}
@ -188,9 +252,27 @@ void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFu
otherFunc(addr, sizeCpy);
return;
case AUDIO_MODE_MATCH_SCREEN: {
if (gDoScreenSwap) {
otherFunc(addr, sizeCpy);
return;
switch (gCurScreenMode) {
case SCREEN_MODE_SWAP:
otherFunc(addr, sizeCpy);
return;
case SCREEN_MODE_MIRROR_TV:
case SCREEN_MODE_MIRROR_DRC: {
if (isDRC) {
memcpy(DRCCopy, addr, sizeCpy);
} else {
memcpy(TVCopy, addr, sizeCpy);
}
if (gCurScreenMode == SCREEN_MODE_MIRROR_TV) {
memcpy(addr, TVCopy, sizeCpy);
} else if (gCurScreenMode == SCREEN_MODE_MIRROR_DRC) {
memcpy(addr, DRCCopy, sizeCpy);
}
break;
}
case SCREEN_MODE_NONE:
case SCREEN_MODE_MAX_VALUE:
break;
}
break;
}

View File

@ -20,7 +20,6 @@
#include "utils/config.h"
#include "utils/logger.h"
#include <notifications/notifications.h>
#include <string>
#include <wups.h>
// Mandatory plugin information.
@ -35,6 +34,19 @@ WUPS_USE_WUT_DEVOPTAB();
WUPS_USE_STORAGE("SwipSwapMeAroma");
void migrateStorage() {
uint32_t doSwap = false;
if (WUPSStorageAPI_GetU32(nullptr, SWAP_SCREENS_CONFIG_STRING_DEPRECATED, &doSwap) == WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
if (doSwap) {
gCurScreenMode = SCREEN_MODE_SWAP;
}
if (WUPSStorageAPI_DeleteItem(nullptr, SWAP_SCREENS_CONFIG_STRING_DEPRECATED) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to delete deprecated value: \"%s\" from storage", SWAP_SCREENS_CONFIG_STRING_DEPRECATED);
}
}
}
// Gets called once the loader exists.
INITIALIZE_PLUGIN() {
initLogging();
@ -46,25 +58,50 @@ INITIALIZE_PLUGIN() {
DEBUG_FUNCTION_LINE_ERR("Failed to init notification lib");
}
// Open storage to read values
WUPSStorageError storageRes = WUPS_OpenStorage();
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
} else {
LOAD_BOOL_FROM_STORAGE(ENABLED_CONFIG_STRING, gEnabled);
LOAD_BOOL_FROM_STORAGE(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap);
LOAD_BOOL_FROM_STORAGE(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled);
LOAD_BOOL_FROM_STORAGE(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled);
LOAD_BOOL_FROM_STORAGE(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications);
LOAD_INT_FROM_STORAGE(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapScreenButtonCombo);
LOAD_INT_FROM_STORAGE(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo);
LOAD_INT_FROM_STORAGE(SCREEN_MODE_CONFIG_STRING, gCurAudioMode);
gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE; // migrateStorage might override this
migrateStorage();
// Close storage
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
WUPSStorageError err;
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CONFIG_STRING, gEnabled, DEFAULT_ENABLED_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(SCREEN_MODE_CONFIG_STRING, gCurScreenMode, gCurScreenMode)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", SCREEN_MODE_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled, DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled, DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING, gChangeScreenModeButtonComboEnabled, DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications, DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLE_NOTIFICATIONS_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapScreenButtonCombo, (uint32_t) DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo, (uint32_t) DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING, gChangeScreenButtonCombo, (uint32_t) DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(AUDIO_MODE_CONFIG_STRING, gCurAudioMode, DEFAULT_AUDIO_MODE_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", AUDIO_MODE_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
WUPSConfigAPIOptionsV1 configOptions = {.name = "Swip Swap Me"};
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
}
deinitLogging();
}
@ -75,24 +112,32 @@ DEINITIALIZE_PLUGIN() {
}
}
static SwipSwapAudioMode sAudioModeAtStart;
static SwipSwapScreenMode sScreenModeAtStart;
// Called whenever an application was started.
ON_APPLICATION_START() {
initLogging();
sAudioModeAtStart = gCurAudioMode;
sScreenModeAtStart = gCurScreenMode;
}
ON_APPLICATION_REQUESTS_EXIT() {
// Open storage to write current config
WUPSStorageError storageRes = WUPS_OpenStorage();
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
} else {
WUPS_StoreInt(nullptr, SCREEN_MODE_CONFIG_STRING, (int32_t) gCurAudioMode);
WUPS_StoreBool(nullptr, SWAP_SCREENS_CONFIG_STRING, (int32_t) gDoScreenSwap);
if (sAudioModeAtStart != gCurAudioMode || sScreenModeAtStart != gCurScreenMode) {
WUPSStorageError err;
if ((err = WUPSStorageAPI::Store(AUDIO_MODE_CONFIG_STRING, gCurAudioMode)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store audio mode to storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
// Close storage
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
if ((err = WUPSStorageAPI::Store(SCREEN_MODE_CONFIG_STRING, gCurScreenMode)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
}
deinitLogging();
}

View File

@ -1,5 +1,5 @@
#pragma once
#include "version.h"
#define PLUGIN_VERSION "v0.1"
#define PLUGIN_VERSION "v0.1.2"
#define PLUGIN_VERSION_FULL PLUGIN_VERSION PLUGIN_VERSION_EXTRA

View File

@ -1,12 +1,16 @@
#include "retain_vars.hpp"
#include <vpad/input.h>
#include "utils/config.h"
uint32_t gSwapScreenButtonCombo = VPAD_BUTTON_TV;
uint32_t gSwapAudioButtonCombo = VPAD_BUTTON_STICK_L;
bool gSwapScreenButtonComboEnabled = true;
bool gChangeAudioModeButtonComboEnabled = false;
bool gEnabled = true;
bool gDoScreenSwap = false;
bool gShowNotifications = true;
bool gNotificationModuleInitDone = true;
SwipSwapAudioMode gCurAudioMode = AUDIO_MODE_MATCH_SCREEN;
bool gEnabled = DEFAULT_ENABLED_CONFIG_VALUE;
uint32_t gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
uint32_t gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE;
uint32_t gChangeScreenButtonCombo = DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE;
bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE;
bool gChangeScreenModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE;
bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE;
SwipSwapScreenMode gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE;
SwipSwapAudioMode gCurAudioMode = DEFAULT_AUDIO_MODE_CONFIG_VALUE;
bool gNotificationModuleInitDone = true;

View File

@ -11,12 +11,23 @@ typedef enum SwipSwapAudioMode {
AUDIO_MODE_MAX_VALUE = 5
} SwipSwapAudioMode;
typedef enum SwipSwapScreenMode {
SCREEN_MODE_NONE = 0,
SCREEN_MODE_SWAP = 1,
SCREEN_MODE_MIRROR_TV = 2,
SCREEN_MODE_MIRROR_DRC = 3,
SCREEN_MODE_MAX_VALUE = 4
} SwipSwapScreenMode;
extern uint32_t gSwapScreenButtonCombo;
extern uint32_t gSwapAudioButtonCombo;
extern uint32_t gChangeScreenButtonCombo;
extern bool gSwapScreenButtonComboEnabled;
extern bool gChangeAudioModeButtonComboEnabled;
extern bool gChangeScreenModeButtonComboEnabled;
extern bool gEnabled;
extern bool gDoScreenSwap;
extern bool gShowNotifications;
extern bool gNotificationModuleInitDone;
extern SwipSwapScreenMode gCurScreenMode;
extern SwipSwapAudioMode gCurAudioMode;

View File

@ -10,7 +10,7 @@
#include <vpad/input.h>
#include <wups.h>
const char *getButtonChar(VPADButtons value) {
static const char *getButtonChar(VPADButtons value) {
std::string combo;
if (value & VPAD_BUTTON_A) {
return "\ue000";
@ -69,7 +69,7 @@ const char *getButtonChar(VPADButtons value) {
return "";
}
std::string getComboAsString(uint32_t value) {
static std::string getComboAsString(uint32_t value) {
char comboString[60];
memset(comboString, 0, sizeof(comboString));
@ -90,22 +90,20 @@ std::string getComboAsString(uint32_t value) {
return res;
}
int32_t WUPSConfigItemButtonCombo_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
static int32_t WUPSConfigItemButtonCombo_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
auto *item = (ConfigItemButtonCombo *) context;
snprintf(out_buf, out_size, "%s", getComboAsString(item->value).c_str());
return 0;
}
bool WUPSConfigItemButtonCombo_callCallback(void *context) {
static void WUPSConfigItemButtonCombo_onCloseCallback(void *context) {
auto *item = (ConfigItemButtonCombo *) context;
if (item->callback != nullptr) {
((ButtonComboValueChangedCallback) (item->callback))(item, item->value);
return true;
if (item->valueAtCreation != item->value && item->valueChangedCallback != nullptr) {
((ButtonComboValueChangedCallback) (item->valueChangedCallback))(item, item->value);
}
return false;
}
void checkForHold(ConfigItemButtonCombo *item) {
static void checkForHold(ConfigItemButtonCombo *item) {
uint32_t lastHold = 0;
uint32_t holdFor = 0;
uint32_t holdForTarget = item->holdDurationInMs >> 4;
@ -121,9 +119,8 @@ void checkForHold(ConfigItemButtonCombo *item) {
while (true) {
uint32_t buttonsHold = 0;
VPADReadError vpad_error = VPAD_READ_UNINITIALIZED;
VPADStatus vpad_data;
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error);
if (vpad_error == VPAD_READ_SUCCESS) {
VPADStatus vpad_data = {};
if (VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error) > 0 && vpad_error == VPAD_READ_SUCCESS) {
buttonsHold = vpad_data.hold;
}
@ -165,20 +162,16 @@ void checkForHold(ConfigItemButtonCombo *item) {
}
}
void WUPSConfigItemButtonCombo_onButtonPressed(void *context, WUPSConfigButtons buttons) {
static void WUPSConfigItemButtonCombo_onInput(void *context, WUPSConfigSimplePadData input) {
auto *item = (ConfigItemButtonCombo *) context;
if (item->state == BUTTON_COMBO_STATE_NONE) {
if ((buttons & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
if ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
item->state = BUTTON_COMBO_STATE_PREPARE_FOR_HOLD;
}
}
}
bool WUPSConfigItemButtonCombo_isMovementAllowed(void *context) {
return true;
}
int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
static int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
auto *item = (ConfigItemButtonCombo *) context;
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD || item->state == BUTTON_COMBO_STATE_WAIT_FOR_HOLD) {
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD) {
@ -194,72 +187,112 @@ int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context,
return 0;
}
void WUPSConfigItemButtonCombo_restoreDefault(void *context) {
static void WUPSConfigItemButtonCombo_restoreDefault(void *context) {
auto *item = (ConfigItemButtonCombo *) context;
item->value = item->defaultValue;
}
void WUPSConfigItemButtonCombo_onSelected(void *context, bool isSelected) {
}
void WUPSConfigItemButtonCombo_onDelete(void *context) {
auto *item = (ConfigItemButtonCombo *) context;
if (item->configId) {
free(item->configId);
static void WUPSConfigItemButtonCombo_Cleanup(ConfigItemButtonCombo *item) {
if (!item) {
return;
}
free((void *) item->identifier);
free(item);
}
extern "C" bool
WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs, ButtonComboValueChangedCallback callback) {
if (cat == 0) {
return false;
static void WUPSConfigItemButtonCombo_onDelete(void *context) {
WUPSConfigItemButtonCombo_Cleanup((ConfigItemButtonCombo *) context);
}
extern "C" WUPSConfigAPIStatus
WUPSConfigItemButtonCombo_CreateEx(const char *identifier,
const char *displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs,
VPADButtons abortButton,
uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback,
WUPSConfigItemHandle *outHandle) {
if (outHandle == nullptr) {
return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
}
auto *item = (ConfigItemButtonCombo *) malloc(sizeof(ConfigItemButtonCombo));
if (item == nullptr) {
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to allocate memory for item data.\n");
return false;
return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
}
if (configID != nullptr) {
item->configId = strdup(configID);
if (identifier != nullptr) {
item->identifier = strdup(identifier);
} else {
item->configId = nullptr;
item->identifier = nullptr;
}
item->abortButton = abortButton;
item->abortButtonHoldDurationInMs = abortButtonHoldDurationInMs;
item->holdDurationInMs = holdDurationInMs;
item->defaultValue = defaultComboInVPADButtons;
item->value = defaultComboInVPADButtons;
item->callback = (void *) callback;
item->value = currentComboInVPADButtons;
item->valueAtCreation = currentComboInVPADButtons;
item->valueChangedCallback = (void *) callback;
item->state = BUTTON_COMBO_STATE_NONE;
WUPSConfigCallbacks_t callbacks = {
WUPSConfigAPIItemCallbacksV2 callbacks = {
.getCurrentValueDisplay = &WUPSConfigItemButtonCombo_getCurrentValueDisplay,
.getCurrentValueSelectedDisplay = &WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay,
.onSelected = &WUPSConfigItemButtonCombo_onSelected,
.onSelected = nullptr,
.restoreDefault = &WUPSConfigItemButtonCombo_restoreDefault,
.isMovementAllowed = &WUPSConfigItemButtonCombo_isMovementAllowed,
.callCallback = &WUPSConfigItemButtonCombo_callCallback,
.onButtonPressed = &WUPSConfigItemButtonCombo_onButtonPressed,
.onDelete = &WUPSConfigItemButtonCombo_onDelete};
.isMovementAllowed = nullptr,
.onCloseCallback = &WUPSConfigItemButtonCombo_onCloseCallback,
.onInput = &WUPSConfigItemButtonCombo_onInput,
.onInputEx = nullptr,
.onDelete = &WUPSConfigItemButtonCombo_onDelete,
};
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
WUPSConfigAPIItemOptionsV2 options = {
.displayName = displayName,
.context = item,
.callbacks = callbacks,
};
WUPSConfigAPIStatus err;
if ((err = WUPSConfigAPI_Item_Create(options, &item->handle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to create config item.\n");
free(item);
return false;
WUPSConfigItemButtonCombo_Cleanup(item);
return err;
}
if (WUPSConfigCategory_AddItem(cat, item->handle) < 0) {
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to add item to category.\n");
WUPSConfigItem_Destroy(item->handle);
return false;
*outHandle = item->handle;
return WUPSCONFIG_API_RESULT_SUCCESS;
}
extern "C" WUPSConfigAPIStatus
WUPSConfigItemButtonCombo_AddToCategoryEx(WUPSConfigCategoryHandle cat,
const char *identifier,
const char *displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback) {
WUPSConfigItemHandle itemHandle;
WUPSConfigAPIStatus res;
if ((res = WUPSConfigItemButtonCombo_CreateEx(identifier,
displayName,
defaultComboInVPADButtons, currentComboInVPADButtons,
holdDurationInMs, abortButton, abortButtonHoldDurationInMs,
callback, &itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
return res;
}
return true;
if ((res = WUPSConfigAPI_Category_AddItem(cat, itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
WUPSConfigAPI_Item_Destroy(itemHandle);
return res;
}
return WUPSCONFIG_API_RESULT_SUCCESS;
}
extern "C" bool
WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, uint32_t defaultComboInVPADButtons, ButtonComboValueChangedCallback callback) {
return WUPSConfigItemButtonComboAddToCategoryEx(cat, configID, displayName, defaultComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback);
WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons, ButtonComboValueChangedCallback callback) {
return WUPSConfigItemButtonComboAddToCategoryEx(cat, displayName, defaultComboInVPADButtons, currentComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback);
}

View File

@ -13,31 +13,82 @@ typedef enum ButtonComboState {
} ButtonComboState;
typedef struct ConfigItemButtonCombo {
char *configId;
const char *identifier;
WUPSConfigItemHandle handle;
uint32_t defaultValue;
uint32_t value;
uint32_t valueAtCreation;
uint32_t holdDurationInMs;
VPADButtons abortButton;
uint32_t abortButtonHoldDurationInMs;
void *callback;
ButtonComboState state;
void *valueChangedCallback;
} ConfigItemButtonCombo;
typedef void (*ButtonComboValueChangedCallback)(ConfigItemButtonCombo *item, uint32_t buttonComboInVPADButtons);
bool WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, uint32_t defaultComboInVPADButtons, ButtonComboValueChangedCallback callback);
extern "C" WUPSConfigAPIStatus
WUPSConfigItemButtonCombo_CreateEx(const char *identifier,
const char *displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback,
WUPSConfigItemHandle *outHandle);
bool WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs, ButtonComboValueChangedCallback callback);
bool WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat,
const char *displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
ButtonComboValueChangedCallback callback);
#define WUPSConfigItemButtonCombo_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultComboInVPADButtons__, __callback__) \
do { \
if (!WUPSConfigItemButtonComboAddToCategory(__cat__, __configID__, __displayName__, __defaultComboInVPADButtons__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)
bool WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat,
const char *displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs,
VPADButtons abortButton,
uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <optional>
#include <stdexcept>
#include <string>
#include <wups/config/WUPSConfigItem.h>
#include <wups/config_api.h>
class WUPSConfigItemButtonCombo : public WUPSConfigItem {
public:
static std::optional<WUPSConfigItemButtonCombo> CreateEx(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback,
WUPSConfigAPIStatus &err) noexcept;
static WUPSConfigItemButtonCombo CreateEx(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback);
static std::optional<WUPSConfigItemButtonCombo> Create(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
ButtonComboValueChangedCallback callback,
WUPSConfigAPIStatus &err) noexcept;
static WUPSConfigItemButtonCombo Create(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
ButtonComboValueChangedCallback callback);
private:
explicit WUPSConfigItemButtonCombo(WUPSConfigItemHandle itemHandle) : WUPSConfigItem(itemHandle) {
}
};
#endif

View File

@ -0,0 +1,52 @@
#include "WUPSConfigItemButtonCombo.h"
std::optional<WUPSConfigItemButtonCombo> WUPSConfigItemButtonCombo::CreateEx(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback,
WUPSConfigAPIStatus &err) noexcept {
WUPSConfigItemHandle itemHandle;
if ((err = WUPSConfigItemButtonCombo_CreateEx(identifier ? identifier->data() : nullptr,
displayName.data(),
defaultComboInVPADButtons, currentComboInVPADButtons,
holdDurationInMs, abortButton, abortButtonHoldDurationInMs,
callback,
&itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
return std::nullopt;
}
return WUPSConfigItemButtonCombo(itemHandle);
}
WUPSConfigItemButtonCombo WUPSConfigItemButtonCombo::CreateEx(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
ButtonComboValueChangedCallback callback) {
WUPSConfigAPIStatus err;
auto result = CreateEx(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, holdDurationInMs, abortButton, abortButtonHoldDurationInMs, callback, err);
if (!result) {
throw std::runtime_error(std::string("Failed to create WUPSConfigItemButtonCombo: ").append(WUPSConfigAPI_GetStatusStr(err)));
}
return std::move(*result);
}
std::optional<WUPSConfigItemButtonCombo> WUPSConfigItemButtonCombo::Create(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
ButtonComboValueChangedCallback callback,
WUPSConfigAPIStatus &err) noexcept {
return CreateEx(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback, err);
}
WUPSConfigItemButtonCombo WUPSConfigItemButtonCombo::Create(std::optional<std::string> identifier,
std::string_view displayName,
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
ButtonComboValueChangedCallback callback) {
WUPSConfigAPIStatus err = WUPSCONFIG_API_RESULT_UNKNOWN_ERROR;
auto res = Create(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, callback, err);
if (!res) {
throw std::runtime_error(std::string("Failed to create WUPSConfigItemButtonCombo: ").append(WUPSConfigAPI_GetStatusStr(err)));
}
return std::move(*res);
}

View File

@ -3,102 +3,165 @@
#include "retain_vars.hpp"
#include <map>
#include <wups/config/WUPSConfigItemMultipleValues.h>
extern void UpdateAudioMode();
void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) {
if (std::string_view(item->configId) == ENABLED_CONFIG_STRING) {
DEBUG_FUNCTION_LINE("New value in %s: %d", ENABLED_CONFIG_STRING, newValue);
gEnabled = newValue;
WUPS_StoreInt(nullptr, ENABLED_CONFIG_STRING, gEnabled);
UpdateAudioMode();
static void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) {
if (!item || !item->identifier) {
DEBUG_FUNCTION_LINE_WARN("Invalid item or identifier in bool item callback");
return;
}
PROCESS_BOOL_ITEM_CHANGED(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap);
PROCESS_BOOL_ITEM_CHANGED(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled);
PROCESS_BOOL_ITEM_CHANGED(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled);
PROCESS_BOOL_ITEM_CHANGED(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications);
}
void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValue) {
if (item && item->configId) {
if (std::string_view(item->configId) == SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING) {
gSwapScreenButtonCombo = newValue;
WUPS_StoreInt(nullptr, item->configId, (int32_t) gSwapScreenButtonCombo);
} else if (std::string_view(item->configId) == CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING) {
gSwapAudioButtonCombo = newValue;
WUPS_StoreInt(nullptr, item->configId, (int32_t) gSwapAudioButtonCombo);
}
DEBUG_FUNCTION_LINE_VERBOSE("New value in %s changed: %d", item->identifier, newValue);
if (std::string_view(ENABLED_CONFIG_STRING) == item->identifier) {
gEnabled = newValue;
UpdateAudioMode();
} else if (std::string_view(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING) == item->identifier) {
gSwapScreenButtonComboEnabled = newValue;
} else if (std::string_view(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING) == item->identifier) {
gChangeAudioModeButtonComboEnabled = newValue;
} else if (std::string_view(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING) == item->identifier) {
gChangeScreenModeButtonComboEnabled = newValue;
} else if (std::string_view(ENABLE_NOTIFICATIONS_CONFIG_STRING) == item->identifier) {
gShowNotifications = newValue;
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected boolean item: %s", item->identifier);
return;
}
WUPSStorageError err;
if ((err = WUPSStorageAPI::Store(item->identifier, newValue)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to store value %d to storage item \"%s\": %s (%d)", newValue, item->identifier, WUPSStorageAPI_GetStatusStr(err), err);
}
}
void getConfigInfoForMap(std::map<SwipSwapAudioMode, const char *> &curMap, ConfigItemMultipleValuesPair *pair, uint32_t default_lang, uint32_t *default_index, uint32_t *len) {
uint32_t i = 0;
for (auto &curEntry : curMap) {
if (default_lang == curEntry.first) {
*default_index = i;
}
pair[i].value = curEntry.first;
pair[i].valueName = (char *) curEntry.second;
i++;
static void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValue) {
if (!item || !item->identifier) {
DEBUG_FUNCTION_LINE_WARN("Invalid item or identifier in button combo item callback");
return;
}
DEBUG_FUNCTION_LINE_VERBOSE("New value in %s changed: %d", item->identifier, newValue);
if (std::string_view(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
gSwapScreenButtonCombo = newValue;
} else if (std::string_view(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
gSwapAudioButtonCombo = newValue;
} else if (std::string_view(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
gChangeScreenButtonCombo = newValue;
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected button combo item: %s", item->identifier);
return;
}
WUPSStorageError err;
if ((err = WUPSStorageAPI::Store(item->identifier, newValue)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to store value %d to storage item \"%s\": %s (%d)", newValue, item->identifier, WUPSStorageAPI_GetStatusStr(err), err);
}
*len = i;
}
static void multiItemChanged(ConfigItemMultipleValues *item, uint32_t newValue) {
if (!item || !item->identifier) {
DEBUG_FUNCTION_LINE_WARN("Invalid item or identifier in multi item callback");
return;
}
DEBUG_FUNCTION_LINE_VERBOSE("New value in %s changed: %d", item->identifier, newValue);
void default_lang_changed(ConfigItemMultipleValues *item, uint32_t newValue) {
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
if (strcmp(item->configId, SCREEN_MODE_CONFIG_STRING) == 0) {
if (std::string_view(AUDIO_MODE_CONFIG_STRING) == item->identifier) {
gCurAudioMode = static_cast<SwipSwapAudioMode>(newValue);
WUPS_StoreInt(nullptr, item->configId, (int32_t) gCurAudioMode);
} else if (std::string_view(SCREEN_MODE_CONFIG_STRING) == item->identifier) {
gCurScreenMode = static_cast<SwipSwapScreenMode>(newValue);
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected button combo item: %s", item->identifier);
return;
}
WUPSStorageError err;
if ((err = WUPSStorageAPI::Store(item->identifier, newValue)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to store value %d to storage item \"%s\": %s (%d)", newValue, item->identifier, WUPSStorageAPI_GetStatusStr(err), err);
}
}
WUPS_GET_CONFIG() {
// We open the storage, so we can persist the configuration the user did.
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to open storage");
return 0;
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
try {
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
root.add(WUPSConfigItemBoolean::Create(ENABLED_CONFIG_STRING,
"Plugin enabled",
DEFAULT_ENABLED_CONFIG_VALUE, gEnabled,
&boolItemChangedConfig));
root.add(WUPSConfigItemBoolean::Create(ENABLE_NOTIFICATIONS_CONFIG_STRING,
"Show notifications",
DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE, gShowNotifications,
&boolItemChangedConfig));
constexpr WUPSConfigItemMultipleValues::ValuePair screenModeMap[] = {
{SCREEN_MODE_NONE, "Normal"},
{SCREEN_MODE_SWAP, "Swap TV and GamePad"},
{SCREEN_MODE_MIRROR_TV, "Mirror TV"},
{SCREEN_MODE_MIRROR_DRC, "Mirror GamePad"},
};
root.add(WUPSConfigItemMultipleValues::CreateFromValue(SCREEN_MODE_CONFIG_STRING,
"Screen mode:",
DEFAULT_SCREEN_MODE_CONFIG_VALUE, gCurScreenMode,
screenModeMap,
&multiItemChanged));
constexpr WUPSConfigItemMultipleValues::ValuePair audioModeMap[] = {
{AUDIO_MODE_NONE, "Normal"},
{AUDIO_MODE_SWAP, "Swap TV and GamePad sound"},
{AUDIO_MODE_MATCH_SCREEN, "Sound matches screen"},
{AUDIO_MODE_COMBINE, "Combine TV and GamePad sound"},
{AUDIO_MODE_LEFT_TV_RIGHT_DRC, "Left: TV; Right: GamePad"}};
root.add(WUPSConfigItemMultipleValues::CreateFromValue(AUDIO_MODE_CONFIG_STRING,
"Audio mode:",
DEFAULT_AUDIO_MODE_CONFIG_VALUE, gCurAudioMode,
audioModeMap,
&multiItemChanged));
auto buttonCombos = WUPSConfigCategory::Create("Button Combos");
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING,
"Enable swap screen button combo",
DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE, gSwapScreenButtonComboEnabled,
&boolItemChangedConfig));
buttonCombos.add(WUPSConfigItemButtonCombo::Create(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING,
"Swap screen",
DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gSwapScreenButtonCombo,
&buttonComboItemChanged));
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING,
"Enable change screen button combo",
DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE, gChangeScreenModeButtonComboEnabled,
&boolItemChangedConfig));
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING,
"Change screen",
DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gChangeScreenButtonCombo,
&buttonComboItemChanged));
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING,
"Enable change audio mode button combo",
DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE, gChangeAudioModeButtonComboEnabled,
&boolItemChangedConfig));
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING,
"Change audio",
DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE, gSwapAudioButtonCombo,
&buttonComboItemChanged));
root.add(std::move(buttonCombos));
} catch (std::exception &e) {
OSReport("Exception: %s\n", e.what());
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}
WUPSConfigHandle config;
WUPSConfig_CreateHandled(&config, "SwipSwapMe");
WUPSConfigCategoryHandle setting;
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &setting);
WUPSConfigCategoryHandle combos;
WUPSConfig_AddCategoryByNameHandled(config, "Button combos", &combos);
std::map<SwipSwapAudioMode, const char *> audioModeMap{
{AUDIO_MODE_NONE, "Normal"},
{AUDIO_MODE_SWAP, "Swap TV and GamePad sound"},
{AUDIO_MODE_MATCH_SCREEN, "Sound matches screen"},
{AUDIO_MODE_COMBINE, "Combine TV and GamePad sound"},
{AUDIO_MODE_LEFT_TV_RIGHT_DRC, "Left: TV; Right: GamePad"}};
ConfigItemMultipleValuesPair audioModePairs[audioModeMap.size()];
uint32_t number_values = 0;
uint32_t default_index = 0;
getConfigInfoForMap(audioModeMap, audioModePairs, gCurAudioMode, &default_index, &number_values);
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, ENABLED_CONFIG_STRING, "Plugin enabled", gEnabled, &boolItemChangedConfig);
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, ENABLE_NOTIFICATIONS_CONFIG_STRING, "Show notifications", gShowNotifications, &boolItemChangedConfig);
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, SWAP_SCREENS_CONFIG_STRING, "Swap screens", gDoScreenSwap, &boolItemChangedConfig);
WUPSConfigItemMultipleValues_AddToCategoryHandled(config, setting, SCREEN_MODE_CONFIG_STRING, "Audio mode:", default_index, audioModePairs, number_values,
&default_lang_changed);
WUPSConfigItemBoolean_AddToCategoryHandled(config, combos, ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, "Enable swap screen button combo", gSwapScreenButtonComboEnabled, &boolItemChangedConfig);
WUPSConfigItemButtonCombo_AddToCategoryHandled(config, combos, SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, "Swap screen", gSwapScreenButtonCombo, &buttonComboItemChanged);
WUPSConfigItemBoolean_AddToCategoryHandled(config, combos, ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, "Enable change audio mode button combo", gChangeAudioModeButtonComboEnabled, &boolItemChangedConfig);
WUPSConfigItemButtonCombo_AddToCategoryHandled(config, combos, CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, "Change audio", gSwapAudioButtonCombo, &buttonComboItemChanged);
return config;
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
}
WUPS_CONFIG_CLOSED() {
void ConfigMenuClosedCallback() {
// Save all changes
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
WUPSStorageError err;
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
}

View File

@ -1,53 +1,35 @@
#pragma once
#include "logger.h"
#include "retain_vars.hpp"
#include <string>
#include <vpad/input.h>
#include <wups/config/WUPSConfigItemBoolean.h>
#include <wups/storage.h>
#define ENABLED_CONFIG_STRING "enabled"
#define SWAP_SCREENS_CONFIG_STRING "swapScreens"
#define ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING "swapScreensComboEnabled"
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
#define SCREEN_MODE_CONFIG_STRING "audioMode"
#define DEFAULT_ENABLED_CONFIG_VALUE true
#define DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE true
#define DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE false
#define DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE false
#define DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE true
#define DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_TV
#define DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_L
#define DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_R
#define LOAD_BOOL_FROM_STORAGE(config_name, __variable__) \
if ((storageRes = WUPS_GetBool(nullptr, config_name, &__variable__)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
if (WUPS_StoreBool(nullptr, config_name, __variable__) != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to store bool"); \
} \
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
} \
while (0)
#define DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE
#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN
#define LOAD_STRING_FROM_STORAGE(config_name, __string, __string_length) \
if ((storageRes = WUPS_GetString(nullptr, config_name, __string, __string_length)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
if (WUPS_StoreString(nullptr, config_name, __string) != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to store string"); \
} \
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
} \
while (0)
#define ENABLED_CONFIG_STRING "enabled"
#define SWAP_SCREENS_CONFIG_STRING_DEPRECATED "swapScreens"
#define SCREEN_MODE_CONFIG_STRING "screenMode"
#define ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING "swapScreensComboEnabled"
#define ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING "changeScreenComboEnabled"
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
#define CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenChangeButtonCombo"
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
#define AUDIO_MODE_CONFIG_STRING "audioMode"
#define LOAD_INT_FROM_STORAGE(config_name, __intValue) \
if ((storageRes = WUPS_GetInt(nullptr, config_name, (int32_t *) &__intValue)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
if (WUPS_StoreInt(nullptr, config_name, (int32_t) __intValue) != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to store int"); \
} \
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
DEBUG_FUNCTION_LINE_WARN("Failed to get int %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
} \
while (0)
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);
#define PROCESS_BOOL_ITEM_CHANGED(__config__name, __variable__) \
if (std::string_view(item->configId) == __config__name) { \
DEBUG_FUNCTION_LINE_ERR("New value in %s: %d", __config__name, newValue); \
__variable__ = newValue; \
WUPS_StoreInt(nullptr, __config__name, __variable__); \
return; \
} \
while (0)
void ConfigMenuClosedCallback();

View File

@ -39,6 +39,7 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##INFO ## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
@ -54,6 +55,7 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARN ## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##INFO ## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);