From 1e1b1116782f8b54c5d459ab848ef9396182e21b Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 13 May 2022 00:03:28 +0200 Subject: [PATCH] sceNp: register custom menu --- rpcs3/Emu/Cell/Modules/sceNp.cpp | 58 ++++++++++++++++++++++++++++++-- rpcs3/Emu/NP/np_handler.h | 15 +++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index 4a0648f4c5..bb280ac9a0 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -2243,6 +2243,8 @@ error_code sceNpCustomMenuRegisterActions(vm::cptr menu, vm::pt { sceNp.todo("sceNpCustomMenuRegisterActions(menu=*0x%x, handler=*0x%x, userArg=*0x%x, options=0x%x)", menu, handler, userArg, options); + // TODO: Is there any error if options is not 0 ? + auto& nph = g_fxo->get>(); if (!nph.is_NP_init) @@ -2260,6 +2262,8 @@ error_code sceNpCustomMenuRegisterActions(vm::cptr menu, vm::pt return SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX; } + std::vector actions; + for (u32 i = 0; i < menu->numActions; i++) { if (!menu->actions[i].name) @@ -2267,12 +2271,38 @@ error_code sceNpCustomMenuRegisterActions(vm::cptr menu, vm::pt return SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT; } + // TODO: Is there any error if menu->actions[i].options is not 0 ? + + // TODO: check name + if (false) + { + return SCE_NP_UTIL_ERROR_INVALID_CHARACTER; + } + if (!memchr(menu->actions[i].name.get_ptr(), '\0', SCE_NP_CUSTOM_MENU_ACTION_CHARACTER_MAX)) { return SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX; } + + np::np_handler::custom_menu_action action{}; + action.id = static_cast(actions.size()); + action.mask = menu->actions[i].mask; + action.name = menu->actions[i].name.get_ptr(); + + sceNp.notice("Registering menu action: id=%d, mask=0x%x, name=%s", action.id, action.mask, action.name); + + actions.push_back(std::move(action)); } + // TODO: add the custom menu to the friendlist and profile dialogs + std::lock_guard lock(nph.mutex_custom_menu); + nph.custom_menu_handler = handler; + nph.custom_menu_user_arg = userArg; + nph.custom_menu_actions = std::move(actions); + nph.custom_menu_registered = true; + nph.custom_menu_activation = {}; + nph.custom_menu_exception_list = {}; + return CELL_OK; } @@ -2280,6 +2310,8 @@ error_code sceNpCustomMenuActionSetActivation(vm::cptrget>(); if (!nph.is_NP_init) @@ -2287,13 +2319,20 @@ error_code sceNpCustomMenuActionSetActivation(vm::cptrget>(); if (!nph.is_NP_init) @@ -2308,7 +2349,12 @@ error_code sceNpCustomMenuRegisterExceptionList(vm::cptr SCE_NP_CUSTOM_MENU_EXCEPTION_ITEMS_MAX) { @@ -2320,6 +2366,14 @@ error_code sceNpCustomMenuRegisterExceptionList(vm::cptr custom_menu_handler{}; + vm::ptr custom_menu_user_arg{}; + std::vector custom_menu_actions; + SceNpCustomMenuIndexArray custom_menu_activation{}; + std::vector custom_menu_exception_list{}; + // Mutex for NP status change shared_mutex mutex_status;