From 09218ee68a1db92e4dd8e1cd94191a3dae30729e Mon Sep 17 00:00:00 2001 From: Celegans12 <53881228+Celegans12@users.noreply.github.com> Date: Mon, 5 Oct 2026 09:24:55 +0200 Subject: [PATCH] feat(msgdialog): implement sceMsgDialogClose in libSceMsgDialog.native A title that loads libSceMsgDialog.native without libSceMsgDialog imports sceMsgDialogClose from it, so without the export it stops at startup on an unresolved import. Close turns a running dialog into a finished one and returns NOT_RUNNING in every other state, as libSceMsgDialog's Close does. The module keeps its own dialog status, so it cannot reuse that export. Open in this module finishes the dialog at once, so Close after Open returns NOT_RUNNING and leaves the result unchanged. The module is now listed under silent stubs in TechnicalDebt, and a CMakeLists.txt registers the guest_msg_dialog_native test. Co-Authored-By: Claude Opus 5.5 --- .../prx/libSceMsgDialog.native/CMakeLists.txt | 20 ++++++++ .../prx/libSceMsgDialog.native/Export.cpp | 8 +++ core/libs/tests/GuestMsgDialogNative.cpp | 49 +++++++++++++++++++ docs/dev/TechnicalDebt.md | 1 + 4 files changed, 78 insertions(+) create mode 100644 core/libs/prx/libSceMsgDialog.native/CMakeLists.txt create mode 100644 core/libs/tests/GuestMsgDialogNative.cpp diff --git a/core/libs/prx/libSceMsgDialog.native/CMakeLists.txt b/core/libs/prx/libSceMsgDialog.native/CMakeLists.txt new file mode 100644 index 000000000..111746d44 --- /dev/null +++ b/core/libs/prx/libSceMsgDialog.native/CMakeLists.txt @@ -0,0 +1,20 @@ +add_library(libSceMsgDialog.native SHARED EXCLUDE_FROM_ALL Export.cpp) +target_include_directories(libSceMsgDialog.native PRIVATE ${LIBS_INCLUDE_DIR}) +configure_windows_unwind(libSceMsgDialog.native) + +if(MINGW) + foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static) + string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + endforeach() +endif() + +if(BUILD_TESTING) + add_test_executable(guest_msg_dialog_native_tests ${LIBS_INCLUDE_DIR}/tests/GuestMsgDialogNative.cpp) + target_include_directories(guest_msg_dialog_native_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_msg_dialog_native_tests PRIVATE libSceMsgDialog.native) + add_test(NAME guest_msg_dialog_native COMMAND guest_msg_dialog_native_tests) + if(WIN32) + set_tests_properties(guest_msg_dialog_native PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() +endif() diff --git a/core/libs/prx/libSceMsgDialog.native/Export.cpp b/core/libs/prx/libSceMsgDialog.native/Export.cpp index 1423e8fed..027eff38d 100644 --- a/core/libs/prx/libSceMsgDialog.native/Export.cpp +++ b/core/libs/prx/libSceMsgDialog.native/Export.cpp @@ -8,10 +8,12 @@ namespace { std::atomic g_status{0}; +constexpr int COMMON_DIALOG_STATUS_RUNNING = 2; constexpr int COMMON_DIALOG_STATUS_FINISHED = 3; constexpr int COMMON_DIALOG_RESULT_OK = 0; constexpr int COMMON_DIALOG_ERROR_NOT_INITIALIZED = static_cast(0x80B80003u); constexpr int COMMON_DIALOG_ERROR_NOT_FINISHED = static_cast(0x80B80005u); +constexpr int COMMON_DIALOG_ERROR_NOT_RUNNING = static_cast(0x80B8000Bu); constexpr int COMMON_DIALOG_ERROR_ARG_NULL = static_cast(0x80B8000Du); constexpr int BUTTON_ID_OK = 1; } @@ -20,6 +22,12 @@ extern "C" { int SceMsgDialogNativeModuleLoaded_nid_no_patch = 1; +int APS5_VABI sceMsgDialogClose(void) { + int expected = COMMON_DIALOG_STATUS_RUNNING; + if (!g_status.compare_exchange_strong(expected, COMMON_DIALOG_STATUS_FINISHED)) return COMMON_DIALOG_ERROR_NOT_RUNNING; + return 0; +} + int APS5_VABI sceMsgDialogGetResult(MsgDialogResult* result) { const int status = g_status.load(); if (status == 0) return COMMON_DIALOG_ERROR_NOT_INITIALIZED; diff --git a/core/libs/tests/GuestMsgDialogNative.cpp b/core/libs/tests/GuestMsgDialogNative.cpp new file mode 100644 index 000000000..6e3b757e2 --- /dev/null +++ b/core/libs/tests/GuestMsgDialogNative.cpp @@ -0,0 +1,49 @@ +#include "SceTypes.hpp" +#include "prx/libc/include/general/VabiMacros.hpp" +#include +#include + +extern "C" { +int APS5_VABI sceMsgDialogInitialize(void); +int APS5_VABI sceMsgDialogOpen(const void* param); +int APS5_VABI sceMsgDialogUpdateStatus(void); +int APS5_VABI sceMsgDialogGetResult(MsgDialogResult* result); +int APS5_VABI sceMsgDialogClose(void); +int APS5_VABI sceMsgDialogTerminate(void); +} + +namespace { + +void Require(bool value) { if (!value) std::abort(); } + +constexpr int kStatusInitialized = 1; +constexpr int kStatusFinished = 3; +constexpr int kErrNotRunning = static_cast(0x80B8000Bu); +constexpr int kButtonIdOk = 1; + +} + +int main() { + std::uint8_t param[0x60]{}; + + Require(sceMsgDialogClose() == kErrNotRunning); + Require(sceMsgDialogUpdateStatus() == 0); + + Require(sceMsgDialogInitialize() == 0); + Require(sceMsgDialogClose() == kErrNotRunning); + Require(sceMsgDialogUpdateStatus() == kStatusInitialized); + + Require(sceMsgDialogOpen(param) == 0); + Require(sceMsgDialogUpdateStatus() == kStatusFinished); + Require(sceMsgDialogClose() == kErrNotRunning); + Require(sceMsgDialogUpdateStatus() == kStatusFinished); + + MsgDialogResult result{}; + result.button_id = -1; + Require(sceMsgDialogGetResult(&result) == 0); + Require(result.result == 0); + Require(result.button_id == kButtonIdOk); + + Require(sceMsgDialogTerminate() == 0); + Require(sceMsgDialogClose() == kErrNotRunning); +} diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index a84ead929..7f30b5d62 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -12,6 +12,7 @@ Throughout the project, every function at every stage either **does exactly what it's supposed to or throws an exception**. Everywhere... except: - [libSceSaveDataDialog.native](../../core/libs/prx/libSceSaveDataDialog.native/Export.cpp) +- [libSceMsgDialog.native](../../core/libs/prx/libSceMsgDialog.native/Export.cpp) - dialogs finish at `sceMsgDialogOpen` without UI and answer with button 1, so `sceMsgDialogClose` returns `NOT_RUNNING`; its result before `sceMsgDialogInitialize` follows libSceMsgDialog - [libSceCommonDialog](../../core/libs/prx/libSceCommonDialog/Export.cpp) - [libSceErrorDialog](../../core/libs/prx/libSceErrorDialog/Export.cpp) - the error dialog runs the state machine but shows nothing; the error code passed to `sceErrorDialogOpen` is only logged - [libSceHmd](../../core/libs/prx/libSceHmd/Export.cpp) implements only the disconnected-headset path: initialization succeeds, device queries report `NotDetected`, and opening a device returns `DeviceDisconnected`. Headset support, tracking, rendering and additional HMD exports are not implemented; SDK-level ABI compatibility and in-game behaviour remain unverified.