From a1ce43211cec633ab49d398e44531b831045e157 Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Tue, 27 Aug 2024 08:47:55 -0300 Subject: [PATCH 1/3] Add `WUPSConfigAPI_IsMenuOpen()` to detect if the config menu is open. --- include/wups/config_api.h | 14 +++++++++++++- libraries/libwups/config_api.cpp | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/wups/config_api.h b/include/wups/config_api.h index 855b308..a514416 100644 --- a/include/wups/config_api.h +++ b/include/wups/config_api.h @@ -208,6 +208,18 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle); */ const char *WUPSConfigAPI_GetStatusStr(WUPSConfigAPIStatus status); +/** + * @brief Checks if the WUPS config menu is open. + * + * Use this function if you want to change the behavior of a function replacement while + * the user is interacting with the WUPS config menu. + * + * Note: if the backend is too old to export this function, the result is always false. + * + * @return true if the menu is open, false if the menu is closed. + */ +BOOL WUPSConfigAPI_IsMenuOpen(void); + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/libraries/libwups/config_api.cpp b/libraries/libwups/config_api.cpp index 1fdbc76..33bfa3d 100644 --- a/libraries/libwups/config_api.cpp +++ b/libraries/libwups/config_api.cpp @@ -13,6 +13,7 @@ static WUPSConfigAPIStatus (*sAPICategoryAddCategory)(WUPSConfigCategoryHandle p static WUPSConfigAPIStatus (*sAPICategoryAddItem)(WUPSConfigCategoryHandle parentHandle, WUPSConfigItemHandle itemHandle) = nullptr; static WUPSConfigAPIStatus (*sAPIItemCreateEx)(WUPSConfigAPICreateItemOptions options, WUPSConfigItemHandle *out) = nullptr; static WUPSConfigAPIStatus (*sAPIItemDestroy)(WUPSConfigItemHandle handle) = nullptr; +static BOOL (*sAPIIsMenuOpen)(void) = nullptr; static WUPSConfigAPIVersion sConfigAPIVersion = WUPS_CONFIG_API_VERSION_ERROR; @@ -101,6 +102,8 @@ extern "C" WUPSConfigAPIStatus WUPSConfigAPI_InitLibrary_Internal(wups_loader_in WUPS_DEBUG_REPORT("libwups: FindExport WUPSConfigAPI_Item_Destroy failed.\n"); return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; } + // This one is allowed to fail. + OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_IsMenuOpen", (void **) &sAPIIsMenuOpen); sConfigLibInitDone = true; sConfigPluginIdentifier = args.plugin_identifier; @@ -242,4 +245,14 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle) { } return sAPIItemDestroy(handle); -} \ No newline at end of file +} + +BOOL WUPSConfigAPI_IsMenuOpen(void) { + if (sConfigAPIVersion == WUPS_CONFIG_API_VERSION_ERROR) { + return false; + } + if (sAPIIsMenuOpen == nullptr) { + return false; + } + return sAPIIsMenuOpen(); +} From 2201a961770759fd1779cb2745bb45b66cbab946 Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Tue, 27 Aug 2024 12:57:25 -0300 Subject: [PATCH 2/3] Changed function signature and name to match other functions. --- include/wups/config_api.h | 11 +++++++---- libraries/libwups/config_api.cpp | 14 +++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/wups/config_api.h b/include/wups/config_api.h index a514416..4e497e1 100644 --- a/include/wups/config_api.h +++ b/include/wups/config_api.h @@ -214,11 +214,14 @@ const char *WUPSConfigAPI_GetStatusStr(WUPSConfigAPIStatus status); * Use this function if you want to change the behavior of a function replacement while * the user is interacting with the WUPS config menu. * - * Note: if the backend is too old to export this function, the result is always false. - * - * @return true if the menu is open, false if the menu is closed. + * @param[out] isOpen Pointer to a BOOL variable to write the result, true if the menu is open. + * @return WUPSConfigAPIStatus The status code indicating the result of the operation: + * - WUPSCONFIG_API_RESULT_SUCCESS: The result was written successfully to the isOpen argument. + * - WUPSCONFIG_API_RESULT_INVALID_ARGUMENT: The isOpen argument is a null pointer. + * - WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED: The WUPSConfig API is not initialized. + * - WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT: The function WUPSConfigAPI_GetMenuOpen was not found in the module. */ -BOOL WUPSConfigAPI_IsMenuOpen(void); +WUPSConfigAPIStatus WUPSConfigAPI_GetMenuOpen(BOOL *isOpen); #ifdef __cplusplus } diff --git a/libraries/libwups/config_api.cpp b/libraries/libwups/config_api.cpp index 33bfa3d..eabdae1 100644 --- a/libraries/libwups/config_api.cpp +++ b/libraries/libwups/config_api.cpp @@ -13,7 +13,7 @@ static WUPSConfigAPIStatus (*sAPICategoryAddCategory)(WUPSConfigCategoryHandle p static WUPSConfigAPIStatus (*sAPICategoryAddItem)(WUPSConfigCategoryHandle parentHandle, WUPSConfigItemHandle itemHandle) = nullptr; static WUPSConfigAPIStatus (*sAPIItemCreateEx)(WUPSConfigAPICreateItemOptions options, WUPSConfigItemHandle *out) = nullptr; static WUPSConfigAPIStatus (*sAPIItemDestroy)(WUPSConfigItemHandle handle) = nullptr; -static BOOL (*sAPIIsMenuOpen)(void) = nullptr; +static WUPSConfigAPIStatus (*sAPIGetMenuOpen)(BOOL *out) = nullptr; static WUPSConfigAPIVersion sConfigAPIVersion = WUPS_CONFIG_API_VERSION_ERROR; @@ -103,7 +103,7 @@ extern "C" WUPSConfigAPIStatus WUPSConfigAPI_InitLibrary_Internal(wups_loader_in return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; } // This one is allowed to fail. - OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_IsMenuOpen", (void **) &sAPIIsMenuOpen); + OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_GetMenuOpen", (void **) &sAPIGetMenuOpen); sConfigLibInitDone = true; sConfigPluginIdentifier = args.plugin_identifier; @@ -247,12 +247,12 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle) { return sAPIItemDestroy(handle); } -BOOL WUPSConfigAPI_IsMenuOpen(void) { +WUPSConfigAPIStatus WUPSConfigAPI_GetMenuOpen(BOOL *out) { if (sConfigAPIVersion == WUPS_CONFIG_API_VERSION_ERROR) { - return false; + return WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED; } - if (sAPIIsMenuOpen == nullptr) { - return false; + if (sAPIGetMenuOpen == nullptr) { + return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; } - return sAPIIsMenuOpen(); + return sAPIGetMenuOpen(out); } From d2b16401e77ec0bc2336fe4479e5d8dfca6722d2 Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Wed, 27 Nov 2024 23:03:58 -0300 Subject: [PATCH 3/3] - Renamed function from `WUPSConfigAPI_GetMenuOpen()` to `WUPSConfigAPI_GetMenuOpen()`. - Changed result type from `BOOL` to `WUPSConfigAPIMenuStatus` enum. --- include/wups/config.h | 5 +++++ include/wups/config_api.h | 10 ++++++---- libraries/libwups/config_api.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/wups/config.h b/include/wups/config.h index c7d8b55..387119e 100644 --- a/include/wups/config.h +++ b/include/wups/config.h @@ -294,3 +294,8 @@ typedef struct wups_loader_init_config_args_t { uint32_t arg_version; uint32_t plugin_identifier; } wups_loader_init_config_args_t; + +typedef enum WUPSConfigAPIMenuStatus { + WUPSCONFIG_API_MENU_STATUS_CLOSED = 0, + WUPSCONFIG_API_MENU_STATUS_OPENED = 1, +} WUPSConfigAPIMenuStatus; diff --git a/include/wups/config_api.h b/include/wups/config_api.h index 4e497e1..6a214e6 100644 --- a/include/wups/config_api.h +++ b/include/wups/config_api.h @@ -214,14 +214,16 @@ const char *WUPSConfigAPI_GetStatusStr(WUPSConfigAPIStatus status); * Use this function if you want to change the behavior of a function replacement while * the user is interacting with the WUPS config menu. * - * @param[out] isOpen Pointer to a BOOL variable to write the result, true if the menu is open. + * @param[out] status Pointer to a variable to write the menu status: + * - `WUPSCONFIG_API_MENU_STATUS_CLOSED` + * - `WUPSCONFIG_API_MENU_STATUS_OPENED` * @return WUPSConfigAPIStatus The status code indicating the result of the operation: - * - WUPSCONFIG_API_RESULT_SUCCESS: The result was written successfully to the isOpen argument. - * - WUPSCONFIG_API_RESULT_INVALID_ARGUMENT: The isOpen argument is a null pointer. + * - WUPSCONFIG_API_RESULT_SUCCESS: The result was written successfully to the `status` argument. + * - WUPSCONFIG_API_RESULT_INVALID_ARGUMENT: The `status` argument is a null pointer. * - WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED: The WUPSConfig API is not initialized. * - WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT: The function WUPSConfigAPI_GetMenuOpen was not found in the module. */ -WUPSConfigAPIStatus WUPSConfigAPI_GetMenuOpen(BOOL *isOpen); +WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *status); #ifdef __cplusplus } diff --git a/libraries/libwups/config_api.cpp b/libraries/libwups/config_api.cpp index eabdae1..008d6e3 100644 --- a/libraries/libwups/config_api.cpp +++ b/libraries/libwups/config_api.cpp @@ -13,7 +13,7 @@ static WUPSConfigAPIStatus (*sAPICategoryAddCategory)(WUPSConfigCategoryHandle p static WUPSConfigAPIStatus (*sAPICategoryAddItem)(WUPSConfigCategoryHandle parentHandle, WUPSConfigItemHandle itemHandle) = nullptr; static WUPSConfigAPIStatus (*sAPIItemCreateEx)(WUPSConfigAPICreateItemOptions options, WUPSConfigItemHandle *out) = nullptr; static WUPSConfigAPIStatus (*sAPIItemDestroy)(WUPSConfigItemHandle handle) = nullptr; -static WUPSConfigAPIStatus (*sAPIGetMenuOpen)(BOOL *out) = nullptr; +static WUPSConfigAPIStatus (*sAPIMenuGetStatus)(WUPSConfigAPIMenuStatus *status) = nullptr; static WUPSConfigAPIVersion sConfigAPIVersion = WUPS_CONFIG_API_VERSION_ERROR; @@ -103,7 +103,7 @@ extern "C" WUPSConfigAPIStatus WUPSConfigAPI_InitLibrary_Internal(wups_loader_in return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; } // This one is allowed to fail. - OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_GetMenuOpen", (void **) &sAPIGetMenuOpen); + OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_Menu_GetStatus", (void **) &sAPIMenuGetStatus); sConfigLibInitDone = true; sConfigPluginIdentifier = args.plugin_identifier; @@ -247,12 +247,12 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle) { return sAPIItemDestroy(handle); } -WUPSConfigAPIStatus WUPSConfigAPI_GetMenuOpen(BOOL *out) { +WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *out) { if (sConfigAPIVersion == WUPS_CONFIG_API_VERSION_ERROR) { return WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED; } - if (sAPIGetMenuOpen == nullptr) { + if (sAPIMenuGetStatus == nullptr) { return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; } - return sAPIGetMenuOpen(out); + return sAPIMenuGetStatus(out); }