From 5f23142b2dc7644d4ce97cd5e7d2374539830f4e Mon Sep 17 00:00:00 2001 From: "Daniel K. O." Date: Sun, 1 Dec 2024 05:13:16 -0300 Subject: [PATCH] Add `WUPSConfigAPI_Menu_GetStatus()` function. (#89) * Add `WUPSConfigAPI_Menu_GetStatus()` function. --HG-- branch : menu-status-api-hg * Indentation fix. --HG-- branch : menu-status-api-hg --------- Co-authored-by: Daniel K. O. (dkosmari) --- Dockerfile | 2 +- source/config/WUPSConfigAPI.cpp | 11 +++++++++++ source/globals.cpp | 3 ++- source/globals.h | 3 ++- source/patcher/hooks_patcher_static.cpp | 17 ++++++++--------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14f4ce6..c9d9c87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ghcr.io/wiiu-env/devkitppc:20241128 COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240505 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.2-dev-20241128-1ac579a /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libwupsbackend:20240425 /artifacts $DEVKITPRO diff --git a/source/config/WUPSConfigAPI.cpp b/source/config/WUPSConfigAPI.cpp index d1660a5..0200239 100644 --- a/source/config/WUPSConfigAPI.cpp +++ b/source/config/WUPSConfigAPI.cpp @@ -315,7 +315,18 @@ namespace WUPSConfigAPIBackend { return WUPSCONFIG_API_RESULT_SUCCESS; } + WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *status) { + if (status == nullptr) { + return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT; + } + *status = gConfigMenuOpened + ? WUPSCONFIG_API_MENU_STATUS_OPENED + : WUPSCONFIG_API_MENU_STATUS_CLOSED; + return WUPSCONFIG_API_RESULT_SUCCESS; + } + WUMS_EXPORT_FUNCTION(WUPSConfigAPI_GetVersion); + WUMS_EXPORT_FUNCTION(WUPSConfigAPI_Menu_GetStatus); WUMS_EXPORT_FUNCTION_EX(WUPSConfigAPIBackend::InitEx, WUPSConfigAPI_InitEx); WUMS_EXPORT_FUNCTION_EX(WUPSConfigAPIBackend::Category::Create, WUPSConfigAPI_Category_CreateEx); diff --git a/source/globals.cpp b/source/globals.cpp index 9046d00..d9fa09d 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -18,4 +18,5 @@ bool gNotificationModuleLoaded = false; OSThread *gOnlyAcceptFromThread = nullptr; -bool gConfigMenuShouldClose = false; \ No newline at end of file +bool gConfigMenuShouldClose = false; +bool gConfigMenuOpened = false; diff --git a/source/globals.h b/source/globals.h index 786c5d2..41b8165 100644 --- a/source/globals.h +++ b/source/globals.h @@ -34,4 +34,5 @@ extern bool gNotificationModuleLoaded; extern OSThread *gOnlyAcceptFromThread; -extern bool gConfigMenuShouldClose; \ No newline at end of file +extern bool gConfigMenuShouldClose; +extern bool gConfigMenuOpened; diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index 13d1c11..9d6331b 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -10,16 +10,15 @@ #include static uint8_t sVpadPressCooldown = 0xFF; -static bool sConfigMenuOpened = false; static bool sWantsToOpenConfigMenu = false; DECL_FUNCTION(void, GX2SwapScanBuffers, void) { real_GX2SwapScanBuffers(); - if (sWantsToOpenConfigMenu && !sConfigMenuOpened) { - sConfigMenuOpened = true; + if (sWantsToOpenConfigMenu && !gConfigMenuOpened) { + gConfigMenuOpened = true; ConfigUtils::openConfigMenu(); - sConfigMenuOpened = false; + gConfigMenuOpened = false; sWantsToOpenConfigMenu = false; } } @@ -48,7 +47,7 @@ static uint32_t lastData0 = 0; DECL_FUNCTION(BOOL, OSSendMessage, OSMessageQueue *queue, OSMessage *message, OSMessageFlags flags) { - if (sConfigMenuOpened && queue == OSGetSystemMessageQueue()) { + if (gConfigMenuOpened && queue == OSGetSystemMessageQueue()) { if (message != nullptr) { if (message->args[0] == 0xfacebacc) { // Release foreground gConfigMenuShouldClose = true; @@ -83,7 +82,7 @@ DECL_FUNCTION(void, OSReleaseForeground) { } DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) { - if (sConfigMenuOpened) { + if (gConfigMenuOpened) { // Ignore reading vpad input only from other threads if the config menu is opened if (OSGetCurrentThread() != gOnlyAcceptFromThread) { return 0; @@ -92,7 +91,7 @@ DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buff VPADReadError real_error = VPAD_READ_SUCCESS; const int32_t result = real_VPADRead(chan, buffer, buffer_size, &real_error); - if (result > 0 && real_error == VPAD_READ_SUCCESS && buffer && ((buffer[0].hold & 0xFFFFF) == (VPAD_BUTTON_L | VPAD_BUTTON_DOWN | VPAD_BUTTON_MINUS)) && sVpadPressCooldown == 0 && !sConfigMenuOpened) { + if (result > 0 && real_error == VPAD_READ_SUCCESS && buffer && ((buffer[0].hold & 0xFFFFF) == (VPAD_BUTTON_L | VPAD_BUTTON_DOWN | VPAD_BUTTON_MINUS)) && sVpadPressCooldown == 0 && !gConfigMenuOpened) { sWantsToOpenConfigMenu = true; sVpadPressCooldown = 0x3C; @@ -111,8 +110,8 @@ DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buff DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatus *data) { real_WPADRead(chan, data); - if (!sConfigMenuOpened && data && data[0].error == 0) { - if (const auto extensionType = data[0].extensionType; extensionType != 0xFF) { + if (!gConfigMenuOpened && data && data->error == 0) { + if (const auto extensionType = data->extensionType; extensionType != 0xFF) { if (extensionType == WPAD_EXT_CORE || extensionType == WPAD_EXT_NUNCHUK || extensionType == WPAD_EXT_MPLUS || extensionType == WPAD_EXT_MPLUS_NUNCHUK) { if (data->buttons == (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_MINUS)) {