diff --git a/README.md b/README.md index 63652b5..2a2c03f 100644 --- a/README.md +++ b/README.md @@ -35,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 screen 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) diff --git a/src/function_patcher.cpp b/src/function_patcher.cpp index c1cd048..e2ea9e4 100644 --- a/src/function_patcher.cpp +++ b/src/function_patcher.cpp @@ -89,6 +89,22 @@ 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() { if (gCurScreenMode == SCREEN_MODE_SWAP) { gCurScreenMode = SCREEN_MODE_NONE; @@ -97,19 +113,28 @@ void SwapScreens() { } if (gShowNotifications && gNotificationModuleInitDone) { - if (gCurScreenMode) { - 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(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 sSwapVoicesWasHoldForXFrameGamePad = 0; +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); @@ -132,6 +157,13 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf sSwapScreenWasHoldForXFrameGamePad)) { SwapScreens(); } + + if (gChangeScreenModeButtonComboEnabled && checkButtonComboVPAD(buffer, + checkFullBuffer ? result : 1, + gChangeScreenButtonCombo, + sChangeScreenWasHoldForXFrameGamePad)) { + ChangeScreens(); + } } } @@ -141,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"; @@ -167,7 +199,7 @@ void SwapVoices() { } gCurAudioMode = static_cast(val); if (gShowNotifications && gNotificationModuleInitDone) { - NotificationModule_AddInfoNotification(modeToStr(gCurAudioMode)); + NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode)); } } diff --git a/src/main.cpp b/src/main.cpp index ceeda6f..3fb71ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,6 +74,9 @@ INITIALIZE_PLUGIN() { 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, gChangeAudioModeButtonComboEnabled, 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); } @@ -83,11 +86,13 @@ INITIALIZE_PLUGIN() { 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, gSwapAudioButtonCombo, (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); } diff --git a/src/retain_vars.cpp b/src/retain_vars.cpp index c888768..c81bb43 100644 --- a/src/retain_vars.cpp +++ b/src/retain_vars.cpp @@ -1,12 +1,14 @@ #include "retain_vars.hpp" #include "utils/config.h" -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; -bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE; -bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE; -bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE; +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; diff --git a/src/retain_vars.hpp b/src/retain_vars.hpp index 1859e37..ec91fd8 100644 --- a/src/retain_vars.hpp +++ b/src/retain_vars.hpp @@ -21,8 +21,10 @@ typedef enum 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 gShowNotifications; extern bool gNotificationModuleInitDone; diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 3a6b04c..3da4e05 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -19,6 +19,8 @@ static void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) { 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 { @@ -41,6 +43,8 @@ static void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValu 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; @@ -117,7 +121,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro auto buttonCombos = WUPSConfigCategory::Create("Button Combos"); buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, - "Enable change swap screen button combo", + "Enable swap screen button combo", DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE, gSwapScreenButtonComboEnabled, &boolItemChangedConfig)); @@ -126,6 +130,16 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro 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, diff --git a/src/utils/config.h b/src/utils/config.h index c24e2ca..35495c4 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -6,25 +6,29 @@ #include #include -#define DEFAULT_ENABLED_CONFIG_VALUE true -#define DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE true -#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_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 DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE -#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN +#define DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE +#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN -#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_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 AUDIO_MODE_CONFIG_STRING "audioMode" +#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" WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);