Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional button combo to change screen mode #22

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 41 additions & 9 deletions src/function_patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<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 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);
Expand All @@ -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();
}
}
}

Expand All @@ -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";
Expand All @@ -167,7 +199,7 @@ void SwapVoices() {
}
gCurAudioMode = static_cast<SwipSwapAudioMode>(val);
if (gShowNotifications && gNotificationModuleInitDone) {
NotificationModule_AddInfoNotification(modeToStr(gCurAudioMode));
NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions src/retain_vars.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/retain_vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion src/utils/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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,
Expand Down
38 changes: 21 additions & 17 deletions src/utils/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
#include <wups/config/WUPSConfigItemBoolean.h>
#include <wups/storage.h>

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

Expand Down