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 855b308..6a214e6 100644 --- a/include/wups/config_api.h +++ b/include/wups/config_api.h @@ -208,6 +208,23 @@ 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. + * + * @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 `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_Menu_GetStatus(WUPSConfigAPIMenuStatus *status); + #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..008d6e3 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 WUPSConfigAPIStatus (*sAPIMenuGetStatus)(WUPSConfigAPIMenuStatus *status) = 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_Menu_GetStatus", (void **) &sAPIMenuGetStatus); 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 +} + +WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *out) { + if (sConfigAPIVersion == WUPS_CONFIG_API_VERSION_ERROR) { + return WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED; + } + if (sAPIMenuGetStatus == nullptr) { + return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT; + } + return sAPIMenuGetStatus(out); +}