mirror of
https://github.com/wiiu-env/SwipSwapMe.git
synced 2025-04-21 21:51:16 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f9bb2b7cc2 | ||
![]() |
e569a3eb64 | ||
![]() |
00fd88f360 | ||
![]() |
3b8db3ada6 | ||
![]() |
39ef5f1730 | ||
![]() |
67be2c7232 | ||
![]() |
0a4f828e4e | ||
![]() |
06dd4f3832 | ||
![]() |
13e28e135f | ||
![]() |
e967126645 | ||
![]() |
a2d070c68a | ||
![]() |
2f4f5cc811 | ||
![]() |
808b25ae9d | ||
![]() |
d7ea75f62c |
@ -1,6 +1,6 @@
|
|||||||
FROM ghcr.io/wiiu-env/devkitppc:20240505
|
FROM ghcr.io/wiiu-env/devkitppc:20241128
|
||||||
|
|
||||||
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240505 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20250208 /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/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
||||||
|
|
||||||
|
@ -33,15 +33,15 @@ Via the plugin config menu (press L, DPAD Down and Minus on the GamePad, Pro Con
|
|||||||
- **Button combos**
|
- **Button combos**
|
||||||
- Enable swap screen button combo: (Default is true)
|
- Enable swap screen button combo: (Default is true)
|
||||||
- Determines if the screen can be swapped with a button combo.
|
- Determines if the screen can be swapped with a button combo.
|
||||||
- Swap screen: (Default is the "TV" button)
|
- Swap screen: (Default is the **"TV" button + DPAD right**)
|
||||||
- Button combo to swap the TV and GamePad screen.
|
- Button combo to swap the TV and GamePad screen.
|
||||||
- Enable swap screen button combo: (Default is false)
|
- Enable swap change button combo: (Default is false)
|
||||||
- Determines if the screen can be changed with a button combo.
|
- Determines if the screen can be changed with a button combo.
|
||||||
- Change screen: (Default is "right stick button"/R3)
|
- Change screen: (Default is **TV Button + "right stick button"/R3**)
|
||||||
- Button combo to change screen mode.
|
- Button combo to change screen mode.
|
||||||
- Enable change audio mode button combo: (Default is false)
|
- Enable change audio mode button combo: (Default is false)
|
||||||
- Determines if the audio mode can be changed via a button combo.
|
- Determines if the audio mode can be changed via a button combo.
|
||||||
- Change audio: (Default is "left stick button"/L3)
|
- Change audio: (Default is **TV Button + "left stick button"/L3**)
|
||||||
- Button combo to change the audio mode.
|
- Button combo to change the audio mode.
|
||||||
|
|
||||||
#### Audio Modes
|
#### Audio Modes
|
||||||
|
@ -89,155 +89,8 @@ DECL_FUNCTION(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer,
|
|||||||
real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target);
|
real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *screenModeToStr(SwipSwapScreenMode mode) {
|
static int16_t sDRCCopy[0x120] = {};
|
||||||
switch (mode) {
|
static int16_t sTVCopy[0x120] = {};
|
||||||
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() {
|
|
||||||
if (gCurScreenMode == SCREEN_MODE_SWAP) {
|
|
||||||
gCurScreenMode = SCREEN_MODE_NONE;
|
|
||||||
} else {
|
|
||||||
gCurScreenMode = SCREEN_MODE_SWAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gShowNotifications && gNotificationModuleInitDone) {
|
|
||||||
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 = 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);
|
|
||||||
|
|
||||||
if (gEnabled && (gSwapScreenButtonComboEnabled || gChangeAudioModeButtonComboEnabled)) {
|
|
||||||
if (result > 0 && real_error == VPAD_READ_SUCCESS) {
|
|
||||||
// Fix games like TP HD
|
|
||||||
bool checkFullBuffer = VPADGetButtonProcMode(chan) == 1;
|
|
||||||
|
|
||||||
if (gChangeAudioModeButtonComboEnabled && checkButtonComboVPAD(buffer,
|
|
||||||
checkFullBuffer ? result : 1,
|
|
||||||
gSwapAudioButtonCombo,
|
|
||||||
sSwapVoicesWasHoldForXFrameGamePad)) {
|
|
||||||
SwapVoices();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gSwapScreenButtonComboEnabled && checkButtonComboVPAD(buffer,
|
|
||||||
checkFullBuffer ? result : 1,
|
|
||||||
gSwapScreenButtonCombo,
|
|
||||||
sSwapScreenWasHoldForXFrameGamePad)) {
|
|
||||||
SwapScreens();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gChangeScreenModeButtonComboEnabled && checkButtonComboVPAD(buffer,
|
|
||||||
checkFullBuffer ? result : 1,
|
|
||||||
gChangeScreenButtonCombo,
|
|
||||||
sChangeScreenWasHoldForXFrameGamePad)) {
|
|
||||||
ChangeScreens();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
*error = real_error;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *audioModeToStr(SwipSwapAudioMode mode) {
|
|
||||||
switch (mode) {
|
|
||||||
case AUDIO_MODE_NONE:
|
|
||||||
return "Audio mode: Normal";
|
|
||||||
case AUDIO_MODE_SWAP:
|
|
||||||
return "Audio mode: Swap TV and GamePad";
|
|
||||||
case AUDIO_MODE_MATCH_SCREEN:
|
|
||||||
return "Audio mode: Sound matches screen";
|
|
||||||
case AUDIO_MODE_COMBINE:
|
|
||||||
return "Audio mode: Combine TV and GamePad";
|
|
||||||
case AUDIO_MODE_LEFT_TV_RIGHT_DRC:
|
|
||||||
return "Audio mode: Left speaker TV, right speaker GamePad";
|
|
||||||
case AUDIO_MODE_MAX_VALUE:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return "Invalid audio mode";
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwapVoices() {
|
|
||||||
auto val = (uint32_t) gCurAudioMode;
|
|
||||||
val++;
|
|
||||||
if (val >= AUDIO_MODE_MAX_VALUE) {
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
gCurAudioMode = static_cast<SwipSwapAudioMode>(val);
|
|
||||||
if (gShowNotifications && gNotificationModuleInitDone) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (gEnabled && (gSwapScreenButtonComboEnabled || gChangeAudioModeButtonComboEnabled) && chan >= 0 && chan < 4) {
|
|
||||||
if (data && data[0].err == 0) {
|
|
||||||
if (data[0].extensionType != 0xFF) {
|
|
||||||
uint32_t curButtonHold = 0;
|
|
||||||
if (data[0].extensionType == WPAD_EXT_CORE || data[0].extensionType == WPAD_EXT_NUNCHUK) {
|
|
||||||
// button data is in the first 2 bytes for wiimotes
|
|
||||||
curButtonHold = remapWiiMoteButtons(((uint16_t *) data)[0]);
|
|
||||||
} else if (data[0].extensionType == WPAD_EXT_CLASSIC) {
|
|
||||||
curButtonHold = remapClassicButtons(((uint32_t *) data)[10] & 0xFFFF);
|
|
||||||
} else if (data[0].extensionType == WPAD_EXT_PRO_CONTROLLER) {
|
|
||||||
curButtonHold = remapProButtons(data[0].buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gSwapScreenButtonComboEnabled && checkButtonComboWPAD(curButtonHold, gSwapScreenButtonCombo, sSwapScreenWasHoldForXFrame[chan])) {
|
|
||||||
SwapScreens();
|
|
||||||
}
|
|
||||||
if (gChangeAudioModeButtonComboEnabled && checkButtonComboWPAD(curButtonHold, gSwapAudioButtonCombo, sSwapAudioWasHoldForXFrame[chan])) {
|
|
||||||
SwapVoices();
|
|
||||||
}
|
|
||||||
if (gChangeScreenModeButtonComboEnabled && checkButtonComboWPAD(curButtonHold, gChangeScreenButtonCombo, sChangeScreenWasHoldForXFrame[chan])) {
|
|
||||||
ChangeScreens();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t DRCCopy[0x120] = {};
|
|
||||||
int16_t TVCopy[0x120] = {};
|
|
||||||
typedef void (*AIInitDMAfn)(int16_t *addr, uint32_t size);
|
typedef void (*AIInitDMAfn)(int16_t *addr, uint32_t size);
|
||||||
void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFunc, AIInitDMAfn otherFunc) {
|
void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFunc, AIInitDMAfn otherFunc) {
|
||||||
auto sizeCpy = size > 576 ? 576 : size;
|
auto sizeCpy = size > 576 ? 576 : size;
|
||||||
@ -259,14 +112,14 @@ void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFu
|
|||||||
case SCREEN_MODE_MIRROR_TV:
|
case SCREEN_MODE_MIRROR_TV:
|
||||||
case SCREEN_MODE_MIRROR_DRC: {
|
case SCREEN_MODE_MIRROR_DRC: {
|
||||||
if (isDRC) {
|
if (isDRC) {
|
||||||
memcpy(DRCCopy, addr, sizeCpy);
|
memcpy(sDRCCopy, addr, sizeCpy);
|
||||||
} else {
|
} else {
|
||||||
memcpy(TVCopy, addr, sizeCpy);
|
memcpy(sTVCopy, addr, sizeCpy);
|
||||||
}
|
}
|
||||||
if (gCurScreenMode == SCREEN_MODE_MIRROR_TV) {
|
if (gCurScreenMode == SCREEN_MODE_MIRROR_TV) {
|
||||||
memcpy(addr, TVCopy, sizeCpy);
|
memcpy(addr, sTVCopy, sizeCpy);
|
||||||
} else if (gCurScreenMode == SCREEN_MODE_MIRROR_DRC) {
|
} else if (gCurScreenMode == SCREEN_MODE_MIRROR_DRC) {
|
||||||
memcpy(addr, DRCCopy, sizeCpy);
|
memcpy(addr, sDRCCopy, sizeCpy);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -279,14 +132,14 @@ void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFu
|
|||||||
case AUDIO_MODE_COMBINE:
|
case AUDIO_MODE_COMBINE:
|
||||||
case AUDIO_MODE_LEFT_TV_RIGHT_DRC: {
|
case AUDIO_MODE_LEFT_TV_RIGHT_DRC: {
|
||||||
if (isDRC) {
|
if (isDRC) {
|
||||||
memcpy(DRCCopy, addr, sizeCpy);
|
memcpy(sDRCCopy, addr, sizeCpy);
|
||||||
} else {
|
} else {
|
||||||
memcpy(TVCopy, addr, sizeCpy);
|
memcpy(sTVCopy, addr, sizeCpy);
|
||||||
}
|
}
|
||||||
if (gCurAudioMode == AUDIO_MODE_COMBINE) {
|
if (gCurAudioMode == AUDIO_MODE_COMBINE) {
|
||||||
for (uint32_t i = 0; i < 0x120; i += 2) {
|
for (uint32_t i = 0; i < 0x120; i += 2) {
|
||||||
// Combine left channel of TV and DRC
|
// Combine left channel of TV and DRC
|
||||||
auto val = (((int32_t) TVCopy[i] + (int32_t) DRCCopy[i]) >> 1);
|
auto val = (((int32_t) sTVCopy[i] + (int32_t) sDRCCopy[i]) >> 1);
|
||||||
if (val > 0x7FFF) {
|
if (val > 0x7FFF) {
|
||||||
val = 0x7FFF;
|
val = 0x7FFF;
|
||||||
} else if (val < -0x8000) {
|
} else if (val < -0x8000) {
|
||||||
@ -294,7 +147,7 @@ void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFu
|
|||||||
}
|
}
|
||||||
addr[i] = (int16_t) val;
|
addr[i] = (int16_t) val;
|
||||||
// Combine right channel of TV and DRC
|
// Combine right channel of TV and DRC
|
||||||
val = (((int32_t) TVCopy[i] + (int32_t) DRCCopy[i]) >> 1);
|
val = (((int32_t) sTVCopy[i + 1] + (int32_t) sDRCCopy[i + 1]) >> 1);
|
||||||
if (val > 0x7FFF) {
|
if (val > 0x7FFF) {
|
||||||
val = 0x7FFF;
|
val = 0x7FFF;
|
||||||
} else if (val < -0x8000) {
|
} else if (val < -0x8000) {
|
||||||
@ -305,21 +158,21 @@ void DoAudioMagic(int16_t *addr, uint32_t size, bool isDRC, AIInitDMAfn targetFu
|
|||||||
} else if (gCurAudioMode == AUDIO_MODE_LEFT_TV_RIGHT_DRC) {
|
} else if (gCurAudioMode == AUDIO_MODE_LEFT_TV_RIGHT_DRC) {
|
||||||
for (uint32_t i = 0; i < 0x120; i += 2) {
|
for (uint32_t i = 0; i < 0x120; i += 2) {
|
||||||
// Mix down TV to MONO and put it in the left channel
|
// Mix down TV to MONO and put it in the left channel
|
||||||
auto val = (((int32_t) TVCopy[i] + (int32_t) TVCopy[i + 1]) >> 1);
|
auto val = (((int32_t) sTVCopy[i] + (int32_t) sTVCopy[i + 1]) >> 1);
|
||||||
if (val > 0x7FFF) {
|
|
||||||
val = 0x7FFF;
|
|
||||||
} else if (val < -0x8000) {
|
|
||||||
val = 0x8000;
|
|
||||||
}
|
|
||||||
addr[i] = (int16_t) val;
|
|
||||||
// Mix down DRC to MONO and put it in the right channel
|
|
||||||
val = (((int32_t) DRCCopy[i] + (int32_t) DRCCopy[i + 1]) >> 1);
|
|
||||||
if (val > 0x7FFF) {
|
if (val > 0x7FFF) {
|
||||||
val = 0x7FFF;
|
val = 0x7FFF;
|
||||||
} else if (val < -0x8000) {
|
} else if (val < -0x8000) {
|
||||||
val = 0x8000;
|
val = 0x8000;
|
||||||
}
|
}
|
||||||
addr[i + 1] = (int16_t) val;
|
addr[i + 1] = (int16_t) val;
|
||||||
|
// Mix down DRC to MONO and put it in the right channel
|
||||||
|
val = (((int32_t) sDRCCopy[i] + (int32_t) sDRCCopy[i + 1]) >> 1);
|
||||||
|
if (val > 0x7FFF) {
|
||||||
|
val = 0x7FFF;
|
||||||
|
} else if (val < -0x8000) {
|
||||||
|
val = 0x8000;
|
||||||
|
}
|
||||||
|
addr[i] = (int16_t) val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -370,7 +223,7 @@ DECL_FUNCTION(void, AXUpdateDeviceModes2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(uint32_t, AVMGetTVAudioMode, uint32_t *mode) {
|
DECL_FUNCTION(uint32_t, AVMGetTVAudioMode, uint32_t *mode) {
|
||||||
auto res = real_AVMGetTVAudioMode(mode);
|
const auto res = real_AVMGetTVAudioMode(mode);
|
||||||
if (!gEnabled) {
|
if (!gEnabled) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -397,8 +250,6 @@ void UpdateAudioMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WUPS_MUST_REPLACE(GX2CopyColorBufferToScanBuffer, WUPS_LOADER_LIBRARY_GX2, GX2CopyColorBufferToScanBuffer);
|
WUPS_MUST_REPLACE(GX2CopyColorBufferToScanBuffer, WUPS_LOADER_LIBRARY_GX2, GX2CopyColorBufferToScanBuffer);
|
||||||
WUPS_MUST_REPLACE(VPADRead, WUPS_LOADER_LIBRARY_VPAD, VPADRead);
|
|
||||||
WUPS_MUST_REPLACE(WPADRead, WUPS_LOADER_LIBRARY_PADSCORE, WPADRead);
|
|
||||||
|
|
||||||
WUPS_MUST_REPLACE_FOR_PROCESS(AIInitDMA, WUPS_LOADER_LIBRARY_SND_CORE, AIInitDMA, WUPS_FP_TARGET_PROCESS_ALL);
|
WUPS_MUST_REPLACE_FOR_PROCESS(AIInitDMA, WUPS_LOADER_LIBRARY_SND_CORE, AIInitDMA, WUPS_FP_TARGET_PROCESS_ALL);
|
||||||
WUPS_MUST_REPLACE_FOR_PROCESS(AI2InitDMA, WUPS_LOADER_LIBRARY_SND_CORE, AI2InitDMA, WUPS_FP_TARGET_PROCESS_ALL);
|
WUPS_MUST_REPLACE_FOR_PROCESS(AI2InitDMA, WUPS_LOADER_LIBRARY_SND_CORE, AI2InitDMA, WUPS_FP_TARGET_PROCESS_ALL);
|
||||||
|
258
src/main.cpp
258
src/main.cpp
@ -16,11 +16,13 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "retain_vars.hpp"
|
#include "retain_vars.hpp"
|
||||||
#include "utils/WUPSConfigItemButtonCombo.h"
|
|
||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
#include <forward_list>
|
||||||
#include <notifications/notifications.h>
|
#include <notifications/notifications.h>
|
||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
#include <wups/button_combo/api.h>
|
||||||
|
|
||||||
// Mandatory plugin information.
|
// Mandatory plugin information.
|
||||||
WUPS_PLUGIN_NAME("SwipSwapMe");
|
WUPS_PLUGIN_NAME("SwipSwapMe");
|
||||||
@ -34,17 +36,232 @@ WUPS_USE_WUT_DEVOPTAB();
|
|||||||
|
|
||||||
WUPS_USE_STORAGE("SwipSwapMeAroma");
|
WUPS_USE_STORAGE("SwipSwapMeAroma");
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
uint32_t migrateButtonCombo(const uint32_t buttons) {
|
||||||
|
uint32_t conv_buttons = 0;
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_A) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_A;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_B) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_B;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_X) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_X;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_Y) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_LEFT) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_LEFT;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_RIGHT) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_RIGHT;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_UP) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_UP;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_DOWN) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_DOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_ZL) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_ZL;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_ZR) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_ZR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_L) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_L;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_R) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_R;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_PLUS) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_PLUS;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_MINUS) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_MINUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_STICK_R) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_STICK_R;
|
||||||
|
}
|
||||||
|
if (buttons & VPAD_BUTTON_STICK_L) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_STICK_L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons & VPAD_BUTTON_TV) {
|
||||||
|
conv_buttons |= WUPS_BUTTON_COMBO_BUTTON_TV;
|
||||||
|
}
|
||||||
|
|
||||||
|
return conv_buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *screenModeToStr(const 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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *audioModeToStr(const SwipSwapAudioMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case AUDIO_MODE_NONE:
|
||||||
|
return "Audio mode: Normal";
|
||||||
|
case AUDIO_MODE_SWAP:
|
||||||
|
return "Audio mode: Swap TV and GamePad";
|
||||||
|
case AUDIO_MODE_MATCH_SCREEN:
|
||||||
|
return "Audio mode: Sound matches screen";
|
||||||
|
case AUDIO_MODE_COMBINE:
|
||||||
|
return "Audio mode: Combine TV and GamePad";
|
||||||
|
case AUDIO_MODE_LEFT_TV_RIGHT_DRC:
|
||||||
|
return "Audio mode: Left speaker TV, right speaker GamePad";
|
||||||
|
case AUDIO_MODE_MAX_VALUE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "Invalid audio mode";
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
std::string string_format(const std::string &format, Args... args) {
|
||||||
|
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
||||||
|
auto size = static_cast<size_t>(size_s);
|
||||||
|
auto buf = std::make_unique<char[]>(size);
|
||||||
|
std::snprintf(buf.get(), size, format.c_str(), args...);
|
||||||
|
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
void SwapScreensCallback(WUPSButtonCombo_ControllerTypes, WUPSButtonCombo_ComboHandle, void *) {
|
||||||
|
if (!gEnabled || !gSwapScreenButtonComboEnabled) { return; }
|
||||||
|
if (gCurScreenMode == SCREEN_MODE_SWAP) {
|
||||||
|
gCurScreenMode = SCREEN_MODE_NONE;
|
||||||
|
} else {
|
||||||
|
gCurScreenMode = SCREEN_MODE_SWAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gShowNotifications && gNotificationModuleInitDone) {
|
||||||
|
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeScreensCallback(WUPSButtonCombo_ControllerTypes, WUPSButtonCombo_ComboHandle, void *) {
|
||||||
|
if (!gEnabled || !gChangeScreenModeButtonComboEnabled) { return; }
|
||||||
|
auto val = static_cast<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 ChangeVoicesCallback(WUPSButtonCombo_ControllerTypes, WUPSButtonCombo_ComboHandle, void *) {
|
||||||
|
if (!gEnabled || !gChangeAudioModeButtonComboEnabled) { return; }
|
||||||
|
auto val = static_cast<uint32_t>(gCurAudioMode);
|
||||||
|
val++;
|
||||||
|
if (val >= AUDIO_MODE_MAX_VALUE) {
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
|
gCurAudioMode = static_cast<SwipSwapAudioMode>(val);
|
||||||
|
if (gShowNotifications && gNotificationModuleInitDone) {
|
||||||
|
NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void migrateStorage() {
|
void migrateStorage() {
|
||||||
uint32_t doSwap = false;
|
uint32_t doSwap = false;
|
||||||
if (WUPSStorageAPI_GetU32(nullptr, SWAP_SCREENS_CONFIG_STRING_DEPRECATED, &doSwap) == WUPS_STORAGE_ERROR_SUCCESS) {
|
if (WUPSStorageAPI::Get(SWAP_SCREENS_CONFIG_STRING_DEPRECATED, doSwap) == WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
|
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
|
||||||
if (doSwap) {
|
if (doSwap) {
|
||||||
gCurScreenMode = SCREEN_MODE_SWAP;
|
gCurScreenMode = SCREEN_MODE_SWAP;
|
||||||
}
|
}
|
||||||
if (WUPSStorageAPI_DeleteItem(nullptr, SWAP_SCREENS_CONFIG_STRING_DEPRECATED) != WUPS_STORAGE_ERROR_SUCCESS) {
|
if (WUPSStorageAPI::DeleteItem(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);
|
DEBUG_FUNCTION_LINE_WARN("Failed to delete deprecated value: \"%s\" from storage", SWAP_SCREENS_CONFIG_STRING_DEPRECATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t oldButtonCombo = 0;
|
||||||
|
if (WUPSStorageAPI::Get(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED, oldButtonCombo) == WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
|
||||||
|
gSwapScreenButtonCombo = migrateButtonCombo(oldButtonCombo);
|
||||||
|
if (WUPSStorageAPI::DeleteItem(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Failed to delete deprecated value: \"%s\" from storage", SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (WUPSStorageAPI::Get(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING_DEPRECATED, oldButtonCombo) == WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
|
||||||
|
gSwapAudioButtonCombo = migrateButtonCombo(oldButtonCombo);
|
||||||
|
if (WUPSStorageAPI::DeleteItem(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING_DEPRECATED) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Failed to delete deprecated value: \"%s\" from storage", CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (WUPSStorageAPI::Get(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED, oldButtonCombo) == WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("Found deprecated config in storage. Storage will be migrated");
|
||||||
|
gChangeScreenButtonCombo = migrateButtonCombo(oldButtonCombo);
|
||||||
|
if (WUPSStorageAPI::DeleteItem(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Failed to delete deprecated value: \"%s\" from storage", CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showNotificationOnFirstBoot() {
|
||||||
|
uint32_t val;
|
||||||
|
if (WUPSStorageAPI::Get<uint32_t>(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, val) == WUPS_STORAGE_ERROR_NOT_FOUND) {
|
||||||
|
NotificationModule_AddInfoNotification("Press \ue089+\ue07C to swap the TV and Gamepad screen! You can change this button combination at any time in the config menu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::forward_list<WUPSButtonComboAPI::ButtonCombo> sButtonCombos;
|
||||||
|
|
||||||
|
WUPSButtonCombo_ComboHandle RegisterButtonCombo(const std::string_view label, const WUPSButtonCombo_Buttons buttonCombo, const WUPSButtonCombo_ComboCallback callback) {
|
||||||
|
const auto buttonComboLabel = string_format("SwipSwapMe: %s", label.data());
|
||||||
|
WUPSButtonCombo_ComboStatus status = WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS;
|
||||||
|
WUPSButtonCombo_Error err = WUPS_BUTTON_COMBO_ERROR_UNKNOWN_ERROR;
|
||||||
|
auto res = WUPSButtonComboAPI::CreateComboPressDown(buttonComboLabel,
|
||||||
|
buttonCombo,
|
||||||
|
callback,
|
||||||
|
nullptr,
|
||||||
|
status,
|
||||||
|
err);
|
||||||
|
if (!res || err != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
|
||||||
|
const std::string errorMsg = string_format("SwipSwapMe: Failed to register button combo \"%s\"", label.data());
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("%s", errorMsg.c_str());
|
||||||
|
NotificationModule_AddErrorNotification(errorMsg.c_str());
|
||||||
|
} else {
|
||||||
|
if (status == WUPS_BUTTON_COMBO_COMBO_STATUS_CONFLICT) {
|
||||||
|
const auto conflictMsg = string_format("SwipSwapMe: \"%s\"-combo was disabled due to a conflict. Please assign a different combo", label.data());
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("%s", conflictMsg.c_str());
|
||||||
|
NotificationModule_AddInfoNotification(conflictMsg.c_str());
|
||||||
|
} else if (status != WUPS_BUTTON_COMBO_COMBO_STATUS_VALID) {
|
||||||
|
const auto conflictMsg = string_format("SwipSwapMe: Unknown error happened while registering button combo \"%s\"", label.data());
|
||||||
|
DEBUG_FUNCTION_LINE_INFO("%s", conflictMsg.c_str());
|
||||||
|
NotificationModule_AddInfoNotification(conflictMsg.c_str());
|
||||||
|
}
|
||||||
|
const auto handle = res->getHandle();
|
||||||
|
sButtonCombos.emplace_front(std::move(*res));
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
return WUPSButtonCombo_ComboHandle(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets called once the loader exists.
|
// Gets called once the loader exists.
|
||||||
@ -58,8 +275,17 @@ INITIALIZE_PLUGIN() {
|
|||||||
DEBUG_FUNCTION_LINE_ERR("Failed to init notification lib");
|
DEBUG_FUNCTION_LINE_ERR("Failed to init notification lib");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, true);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 15.0f);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, true);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 15.0f);
|
||||||
|
|
||||||
gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE; // migrateStorage might override this
|
gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE; // migrateStorage might override this
|
||||||
|
gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE; // migrateStorage might override this
|
||||||
|
gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE; // migrateStorage might override this
|
||||||
|
gChangeScreenButtonCombo = DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE; // migrateStorage might override this
|
||||||
migrateStorage();
|
migrateStorage();
|
||||||
|
showNotificationOnFirstBoot();
|
||||||
|
|
||||||
WUPSStorageError err;
|
WUPSStorageError err;
|
||||||
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CONFIG_STRING, gEnabled, DEFAULT_ENABLED_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CONFIG_STRING, gEnabled, DEFAULT_ENABLED_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
@ -80,13 +306,13 @@ INITIALIZE_PLUGIN() {
|
|||||||
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications, DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
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);
|
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) {
|
if ((err = WUPSStorageAPI::GetOrStoreDefault(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapScreenButtonCombo, gSwapScreenButtonCombo)) != 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);
|
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) {
|
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo, gSwapAudioButtonCombo)) != 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);
|
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) {
|
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING, gChangeScreenButtonCombo, gChangeScreenButtonCombo)) != 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);
|
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) {
|
if ((err = WUPSStorageAPI::GetOrStoreDefault(AUDIO_MODE_CONFIG_STRING, gCurAudioMode, DEFAULT_AUDIO_MODE_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
@ -97,11 +323,30 @@ INITIALIZE_PLUGIN() {
|
|||||||
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
|
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gSwapScreenButtonComboHandle = RegisterButtonCombo("Swap Screens", static_cast<WUPSButtonCombo_Buttons>(gSwapScreenButtonCombo), SwapScreensCallback);
|
||||||
|
gSwapAudioButtonComboHandle = RegisterButtonCombo("Change Audio Mode", static_cast<WUPSButtonCombo_Buttons>(gSwapAudioButtonCombo), ChangeVoicesCallback);
|
||||||
|
gChangeScreenButtonComboHandle = RegisterButtonCombo("Change Screen Mode", static_cast<WUPSButtonCombo_Buttons>(gChangeScreenButtonCombo), ChangeScreensCallback);
|
||||||
|
|
||||||
WUPSConfigAPIOptionsV1 configOptions = {.name = "Swip Swap Me"};
|
WUPSConfigAPIOptionsV1 configOptions = {.name = "Swip Swap Me"};
|
||||||
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
|
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gEnabled && gShowNotifications && gNotificationModuleInitDone) {
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 5.0f);
|
||||||
|
if (gCurScreenMode != SCREEN_MODE_NONE) {
|
||||||
|
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
|
||||||
|
}
|
||||||
|
if (gCurAudioMode != AUDIO_MODE_NONE && gCurAudioMode != AUDIO_MODE_MATCH_SCREEN) {
|
||||||
|
NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 2.0f);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, false);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 2.0f);
|
||||||
|
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, false);
|
||||||
|
|
||||||
deinitLogging();
|
deinitLogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +355,7 @@ DEINITIALIZE_PLUGIN() {
|
|||||||
NotificationModule_DeInitLibrary();
|
NotificationModule_DeInitLibrary();
|
||||||
gNotificationModuleInitDone = false;
|
gNotificationModuleInitDone = false;
|
||||||
}
|
}
|
||||||
|
sButtonCombos.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SwipSwapAudioMode sAudioModeAtStart;
|
static SwipSwapAudioMode sAudioModeAtStart;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#define PLUGIN_VERSION "v0.1.2"
|
#define PLUGIN_VERSION "v0.1.3"
|
||||||
#define PLUGIN_VERSION_FULL PLUGIN_VERSION PLUGIN_VERSION_EXTRA
|
#define PLUGIN_VERSION_FULL PLUGIN_VERSION PLUGIN_VERSION_EXTRA
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "retain_vars.hpp"
|
#include "retain_vars.hpp"
|
||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
|
|
||||||
|
#include <wups/button_combo/defines.h>
|
||||||
|
|
||||||
bool gEnabled = DEFAULT_ENABLED_CONFIG_VALUE;
|
bool gEnabled = DEFAULT_ENABLED_CONFIG_VALUE;
|
||||||
uint32_t gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
|
uint32_t gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
|
||||||
uint32_t gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE;
|
uint32_t gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE;
|
||||||
@ -8,6 +10,9 @@ uint32_t gChangeScreenButtonCombo = DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CO
|
|||||||
bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE;
|
bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE;
|
||||||
bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE;
|
bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE;
|
||||||
bool gChangeScreenModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE;
|
bool gChangeScreenModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE;
|
||||||
|
WUPSButtonCombo_ComboHandle gSwapScreenButtonComboHandle = WUPSButtonCombo_ComboHandle(nullptr);
|
||||||
|
WUPSButtonCombo_ComboHandle gSwapAudioButtonComboHandle = WUPSButtonCombo_ComboHandle(nullptr);
|
||||||
|
WUPSButtonCombo_ComboHandle gChangeScreenButtonComboHandle = WUPSButtonCombo_ComboHandle(nullptr);
|
||||||
bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE;
|
bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE;
|
||||||
|
|
||||||
SwipSwapScreenMode gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE;
|
SwipSwapScreenMode gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <wups/button_combo/defines.h>
|
||||||
|
|
||||||
typedef enum SwipSwapAudioMode {
|
typedef enum SwipSwapAudioMode {
|
||||||
AUDIO_MODE_NONE = 0,
|
AUDIO_MODE_NONE = 0,
|
||||||
@ -25,6 +26,11 @@ extern uint32_t gChangeScreenButtonCombo;
|
|||||||
extern bool gSwapScreenButtonComboEnabled;
|
extern bool gSwapScreenButtonComboEnabled;
|
||||||
extern bool gChangeAudioModeButtonComboEnabled;
|
extern bool gChangeAudioModeButtonComboEnabled;
|
||||||
extern bool gChangeScreenModeButtonComboEnabled;
|
extern bool gChangeScreenModeButtonComboEnabled;
|
||||||
|
|
||||||
|
extern WUPSButtonCombo_ComboHandle gSwapScreenButtonComboHandle;
|
||||||
|
extern WUPSButtonCombo_ComboHandle gSwapAudioButtonComboHandle;
|
||||||
|
extern WUPSButtonCombo_ComboHandle gChangeScreenButtonComboHandle;
|
||||||
|
|
||||||
extern bool gEnabled;
|
extern bool gEnabled;
|
||||||
extern bool gShowNotifications;
|
extern bool gShowNotifications;
|
||||||
extern bool gNotificationModuleInitDone;
|
extern bool gNotificationModuleInitDone;
|
||||||
|
@ -1,298 +0,0 @@
|
|||||||
#include "WUPSConfigItemButtonCombo.h"
|
|
||||||
#include "utils/input.h"
|
|
||||||
#include <coreinit/debug.h>
|
|
||||||
#include <coreinit/thread.h>
|
|
||||||
#include <coreinit/time.h>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
|
||||||
#include <vpad/input.h>
|
|
||||||
#include <wups.h>
|
|
||||||
|
|
||||||
static const char *getButtonChar(VPADButtons value) {
|
|
||||||
std::string combo;
|
|
||||||
if (value & VPAD_BUTTON_A) {
|
|
||||||
return "\ue000";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_B) {
|
|
||||||
return "\ue001";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_X) {
|
|
||||||
return "\ue002";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_Y) {
|
|
||||||
return "\ue003";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_L) {
|
|
||||||
return "\ue083";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_R) {
|
|
||||||
return "\ue084";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_ZL) {
|
|
||||||
return "\ue085";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_ZR) {
|
|
||||||
return "\ue086";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_UP) {
|
|
||||||
return "\ue079";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_DOWN) {
|
|
||||||
return "\ue07A";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_LEFT) {
|
|
||||||
return "\ue07B";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_RIGHT) {
|
|
||||||
return "\ue07C";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_STICK_L) {
|
|
||||||
return "\ue081";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_STICK_R) {
|
|
||||||
return "\ue082";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_PLUS) {
|
|
||||||
return "\ue045";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_MINUS) {
|
|
||||||
return "\ue046";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_TV) {
|
|
||||||
return "\ue089";
|
|
||||||
}
|
|
||||||
if (value & VPAD_BUTTON_RESERVED_BIT) {
|
|
||||||
return "\ue01E";
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string getComboAsString(uint32_t value) {
|
|
||||||
char comboString[60];
|
|
||||||
memset(comboString, 0, sizeof(comboString));
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 32; i++) {
|
|
||||||
uint32_t bitMask = 1 << i;
|
|
||||||
if (value & bitMask) {
|
|
||||||
auto val = getButtonChar(static_cast<VPADButtons>(bitMask));
|
|
||||||
if (val[0] != '\0') {
|
|
||||||
strcat(comboString, val);
|
|
||||||
strcat(comboString, "+");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string res(comboString);
|
|
||||||
if (res.ends_with("+")) {
|
|
||||||
res.pop_back();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WUPSConfigItemButtonCombo_onCloseCallback(void *context) {
|
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
|
||||||
if (item->valueAtCreation != item->value && item->valueChangedCallback != nullptr) {
|
|
||||||
((ButtonComboValueChangedCallback) (item->valueChangedCallback))(item, item->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkForHold(ConfigItemButtonCombo *item) {
|
|
||||||
uint32_t lastHold = 0;
|
|
||||||
uint32_t holdFor = 0;
|
|
||||||
uint32_t holdForTarget = item->holdDurationInMs >> 4;
|
|
||||||
uint32_t holdAbortTarget = item->abortButtonHoldDurationInMs >> 4;
|
|
||||||
|
|
||||||
auto mask = VPAD_BUTTON_A | VPAD_BUTTON_B | VPAD_BUTTON_X | VPAD_BUTTON_Y | VPAD_BUTTON_L | VPAD_BUTTON_R |
|
|
||||||
VPAD_BUTTON_ZL | VPAD_BUTTON_ZR | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN | VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT |
|
|
||||||
VPAD_BUTTON_STICK_L | VPAD_BUTTON_STICK_R | VPAD_BUTTON_PLUS | VPAD_BUTTON_MINUS | VPAD_BUTTON_TV | VPAD_BUTTON_RESERVED_BIT;
|
|
||||||
|
|
||||||
KPADStatus kpad_data{};
|
|
||||||
KPADError kpad_error;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
uint32_t buttonsHold = 0;
|
|
||||||
VPADReadError vpad_error = VPAD_READ_UNINITIALIZED;
|
|
||||||
VPADStatus vpad_data = {};
|
|
||||||
if (VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error) > 0 && vpad_error == VPAD_READ_SUCCESS) {
|
|
||||||
buttonsHold = vpad_data.hold;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
memset(&kpad_data, 0, sizeof(kpad_data));
|
|
||||||
if (KPADReadEx((KPADChan) i, &kpad_data, 1, &kpad_error) > 0) {
|
|
||||||
if (kpad_error == KPAD_ERROR_OK && kpad_data.extensionType != 0xFF) {
|
|
||||||
if (kpad_data.extensionType == WPAD_EXT_CORE || kpad_data.extensionType == WPAD_EXT_NUNCHUK) {
|
|
||||||
buttonsHold |= remapWiiMoteButtons(kpad_data.hold);
|
|
||||||
} else if (kpad_data.extensionType == WPAD_EXT_PRO_CONTROLLER) {
|
|
||||||
buttonsHold |= remapProButtons(kpad_data.pro.hold);
|
|
||||||
} else {
|
|
||||||
buttonsHold |= remapClassicButtons(kpad_data.classic.hold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buttonsHold &= mask;
|
|
||||||
|
|
||||||
if (buttonsHold == lastHold) {
|
|
||||||
if (buttonsHold != 0) {
|
|
||||||
holdFor++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
holdFor = 0;
|
|
||||||
}
|
|
||||||
lastHold = buttonsHold;
|
|
||||||
|
|
||||||
if (holdFor >= holdAbortTarget && lastHold == item->abortButton) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (holdFor >= holdForTarget) {
|
|
||||||
item->value = lastHold;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
OSSleepTicks(OSMillisecondsToTicks(16));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WUPSConfigItemButtonCombo_onInput(void *context, WUPSConfigSimplePadData input) {
|
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
|
||||||
if (item->state == BUTTON_COMBO_STATE_NONE) {
|
|
||||||
if ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
|
|
||||||
item->state = BUTTON_COMBO_STATE_PREPARE_FOR_HOLD;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
item->state = BUTTON_COMBO_STATE_WAIT_FOR_HOLD;
|
|
||||||
snprintf(out_buf, out_size, "<Hold new combo for %dms; hold %s to abort>", item->holdDurationInMs, getButtonChar(item->abortButton));
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
checkForHold(item);
|
|
||||||
item->state = BUTTON_COMBO_STATE_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snprintf(out_buf, out_size, "(Press \ue000 to change) %s", getComboAsString(item->value).c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WUPSConfigItemButtonCombo_restoreDefault(void *context) {
|
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
|
||||||
item->value = item->defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WUPSConfigItemButtonCombo_Cleanup(ConfigItemButtonCombo *item) {
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free((void *) item->identifier);
|
|
||||||
free(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (identifier != nullptr) {
|
|
||||||
item->identifier = strdup(identifier);
|
|
||||||
} else {
|
|
||||||
item->identifier = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
item->abortButton = abortButton;
|
|
||||||
item->abortButtonHoldDurationInMs = abortButtonHoldDurationInMs;
|
|
||||||
item->holdDurationInMs = holdDurationInMs;
|
|
||||||
item->defaultValue = defaultComboInVPADButtons;
|
|
||||||
item->value = currentComboInVPADButtons;
|
|
||||||
item->valueAtCreation = currentComboInVPADButtons;
|
|
||||||
item->valueChangedCallback = (void *) callback;
|
|
||||||
item->state = BUTTON_COMBO_STATE_NONE;
|
|
||||||
|
|
||||||
WUPSConfigAPIItemCallbacksV2 callbacks = {
|
|
||||||
.getCurrentValueDisplay = &WUPSConfigItemButtonCombo_getCurrentValueDisplay,
|
|
||||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay,
|
|
||||||
.onSelected = nullptr,
|
|
||||||
.restoreDefault = &WUPSConfigItemButtonCombo_restoreDefault,
|
|
||||||
.isMovementAllowed = nullptr,
|
|
||||||
.onCloseCallback = &WUPSConfigItemButtonCombo_onCloseCallback,
|
|
||||||
.onInput = &WUPSConfigItemButtonCombo_onInput,
|
|
||||||
.onInputEx = nullptr,
|
|
||||||
.onDelete = &WUPSConfigItemButtonCombo_onDelete,
|
|
||||||
};
|
|
||||||
|
|
||||||
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");
|
|
||||||
WUPSConfigItemButtonCombo_Cleanup(item);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
*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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 *displayName, uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons, ButtonComboValueChangedCallback callback) {
|
|
||||||
return WUPSConfigItemButtonComboAddToCategoryEx(cat, displayName, defaultComboInVPADButtons, currentComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback);
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <vpad/input.h>
|
|
||||||
#include <wups.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum ButtonComboState {
|
|
||||||
BUTTON_COMBO_STATE_NONE,
|
|
||||||
BUTTON_COMBO_STATE_PREPARE_FOR_HOLD,
|
|
||||||
BUTTON_COMBO_STATE_WAIT_FOR_HOLD,
|
|
||||||
} ButtonComboState;
|
|
||||||
|
|
||||||
typedef struct ConfigItemButtonCombo {
|
|
||||||
const char *identifier;
|
|
||||||
WUPSConfigItemHandle handle;
|
|
||||||
uint32_t defaultValue;
|
|
||||||
uint32_t value;
|
|
||||||
uint32_t valueAtCreation;
|
|
||||||
uint32_t holdDurationInMs;
|
|
||||||
VPADButtons abortButton;
|
|
||||||
uint32_t abortButtonHoldDurationInMs;
|
|
||||||
ButtonComboState state;
|
|
||||||
void *valueChangedCallback;
|
|
||||||
} ConfigItemButtonCombo;
|
|
||||||
|
|
||||||
typedef void (*ButtonComboValueChangedCallback)(ConfigItemButtonCombo *item, uint32_t buttonComboInVPADButtons);
|
|
||||||
|
|
||||||
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 WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat,
|
|
||||||
const char *displayName,
|
|
||||||
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
|
||||||
ButtonComboValueChangedCallback callback);
|
|
||||||
|
|
||||||
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
|
|
@ -1,52 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
@ -1,8 +1,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "WUPSConfigItemButtonCombo.h"
|
|
||||||
|
#include "logger.h"
|
||||||
#include "retain_vars.hpp"
|
#include "retain_vars.hpp"
|
||||||
#include <map>
|
|
||||||
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
||||||
|
#include <wups/config/WUPSConfigItemButtonCombo.h>
|
||||||
#include <wups/config/WUPSConfigItemMultipleValues.h>
|
#include <wups/config/WUPSConfigItemMultipleValues.h>
|
||||||
|
#include <wups/storage.h>
|
||||||
|
|
||||||
extern void UpdateAudioMode();
|
extern void UpdateAudioMode();
|
||||||
|
|
||||||
@ -91,7 +95,6 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
|
|||||||
DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE, gShowNotifications,
|
DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE, gShowNotifications,
|
||||||
&boolItemChangedConfig));
|
&boolItemChangedConfig));
|
||||||
|
|
||||||
|
|
||||||
constexpr WUPSConfigItemMultipleValues::ValuePair screenModeMap[] = {
|
constexpr WUPSConfigItemMultipleValues::ValuePair screenModeMap[] = {
|
||||||
{SCREEN_MODE_NONE, "Normal"},
|
{SCREEN_MODE_NONE, "Normal"},
|
||||||
{SCREEN_MODE_SWAP, "Swap TV and GamePad"},
|
{SCREEN_MODE_SWAP, "Swap TV and GamePad"},
|
||||||
@ -127,7 +130,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
|
|||||||
|
|
||||||
buttonCombos.add(WUPSConfigItemButtonCombo::Create(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING,
|
buttonCombos.add(WUPSConfigItemButtonCombo::Create(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING,
|
||||||
"Swap screen",
|
"Swap screen",
|
||||||
DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gSwapScreenButtonCombo,
|
DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gSwapScreenButtonComboHandle,
|
||||||
&buttonComboItemChanged));
|
&buttonComboItemChanged));
|
||||||
|
|
||||||
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING,
|
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING,
|
||||||
@ -137,7 +140,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
|
|||||||
|
|
||||||
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING,
|
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING,
|
||||||
"Change screen",
|
"Change screen",
|
||||||
DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gChangeScreenButtonCombo,
|
DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gChangeScreenButtonComboHandle,
|
||||||
&buttonComboItemChanged));
|
&buttonComboItemChanged));
|
||||||
|
|
||||||
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING,
|
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING,
|
||||||
@ -147,7 +150,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
|
|||||||
|
|
||||||
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING,
|
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING,
|
||||||
"Change audio",
|
"Change audio",
|
||||||
DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE, gSwapAudioButtonCombo,
|
DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE, gSwapAudioButtonComboHandle,
|
||||||
&buttonComboItemChanged));
|
&buttonComboItemChanged));
|
||||||
root.add(std::move(buttonCombos));
|
root.add(std::move(buttonCombos));
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "logger.h"
|
|
||||||
#include "retain_vars.hpp"
|
#include <wups/button_combo/defines.h>
|
||||||
#include <string>
|
#include <wups/config.h>
|
||||||
#include <vpad/input.h>
|
|
||||||
#include <wups/config/WUPSConfigItemBoolean.h>
|
|
||||||
#include <wups/storage.h>
|
|
||||||
|
|
||||||
#define DEFAULT_ENABLED_CONFIG_VALUE true
|
#define DEFAULT_ENABLED_CONFIG_VALUE true
|
||||||
#define DEFAULT_ENABLED_SWAP_SCREENS_COMBO_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_SCREEN_COMBO_CONFIG_VALUE false
|
||||||
#define DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE false
|
#define DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE false
|
||||||
#define DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE true
|
#define DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE true
|
||||||
#define DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_TV
|
#define DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE ((WUPSButtonCombo_Buttons) (WUPS_BUTTON_COMBO_BUTTON_TV | WUPS_BUTTON_COMBO_BUTTON_RIGHT))
|
||||||
#define DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_L
|
#define DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE ((WUPSButtonCombo_Buttons) (WUPS_BUTTON_COMBO_BUTTON_TV | WUPS_BUTTON_COMBO_BUTTON_STICK_L))
|
||||||
#define DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_R
|
#define DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE ((WUPSButtonCombo_Buttons) (WUPS_BUTTON_COMBO_BUTTON_TV | WUPS_BUTTON_COMBO_BUTTON_STICK_R))
|
||||||
|
|
||||||
#define DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE
|
#define DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE
|
||||||
#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN
|
#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN
|
||||||
@ -25,11 +22,15 @@
|
|||||||
#define ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING "changeScreenComboEnabled"
|
#define ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING "changeScreenComboEnabled"
|
||||||
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
|
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
|
||||||
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
|
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
|
||||||
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
|
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED "screenButtonCombo"
|
||||||
#define CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenChangeButtonCombo"
|
#define CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING_DEPRECATED "screenChangeButtonCombo"
|
||||||
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
|
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING_DEPRECATED "audioButtonCombo"
|
||||||
|
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonComboNew"
|
||||||
|
#define CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenChangeButtonComboNew"
|
||||||
|
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonComboNew"
|
||||||
#define AUDIO_MODE_CONFIG_STRING "audioMode"
|
#define AUDIO_MODE_CONFIG_STRING "audioMode"
|
||||||
|
|
||||||
|
|
||||||
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);
|
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);
|
||||||
|
|
||||||
void ConfigMenuClosedCallback();
|
void ConfigMenuClosedCallback();
|
Loading…
x
Reference in New Issue
Block a user