From c9ec561697f7646bff8a5d122a97a251e59fbcdb Mon Sep 17 00:00:00 2001 From: Pouare514 Date: Fri, 2 Oct 2026 01:31:06 +0200 Subject: [PATCH] feat(libScePlayGoDialog): add PlayGo install dialog --- core/libs/SceTypes.hpp | 5 ++ .../prx/libScePlayGoDialog/CMakeLists.txt | 22 ++++++ core/libs/prx/libScePlayGoDialog/Export.cpp | 77 +++++++++++++++++++ core/libs/tests/GuestPlayGoDialog.cpp | 46 +++++++++++ 4 files changed, 150 insertions(+) create mode 100644 core/libs/prx/libScePlayGoDialog/CMakeLists.txt create mode 100644 core/libs/prx/libScePlayGoDialog/Export.cpp create mode 100644 core/libs/tests/GuestPlayGoDialog.cpp diff --git a/core/libs/SceTypes.hpp b/core/libs/SceTypes.hpp index 86bd95651..674780302 100644 --- a/core/libs/SceTypes.hpp +++ b/core/libs/SceTypes.hpp @@ -1491,6 +1491,11 @@ union PlayGoOptionalChunk { std::uint64_t scenarios; }; +struct PlayGoDialogResult { + std::int32_t result; + std::int32_t reserved[9]; +}; + using RudpEventHandler = void (*)(int ctx_id, int event_id, int error_code, void* arg); struct SystemServiceStatus { diff --git a/core/libs/prx/libScePlayGoDialog/CMakeLists.txt b/core/libs/prx/libScePlayGoDialog/CMakeLists.txt new file mode 100644 index 000000000..e1be3b728 --- /dev/null +++ b/core/libs/prx/libScePlayGoDialog/CMakeLists.txt @@ -0,0 +1,22 @@ +add_library(libScePlayGoDialog SHARED EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp) +target_include_directories(libScePlayGoDialog PRIVATE ${LIBS_INCLUDE_DIR}) +set_target_properties(libScePlayGoDialog PROPERTIES CXX_EXTENSIONS OFF) +configure_windows_unwind(libScePlayGoDialog) + +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_playgo_dialog_tests ${LIBS_INCLUDE_DIR}/tests/GuestPlayGoDialog.cpp) + target_include_directories(guest_playgo_dialog_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_playgo_dialog_tests PRIVATE libScePlayGoDialog libc) + configure_windows_unwind(guest_playgo_dialog_tests) + add_test(NAME guest_playgo_dialog COMMAND guest_playgo_dialog_tests) + if(WIN32) + set_tests_properties(guest_playgo_dialog PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() +endif() diff --git a/core/libs/prx/libScePlayGoDialog/Export.cpp b/core/libs/prx/libScePlayGoDialog/Export.cpp new file mode 100644 index 000000000..4b5c15a5f --- /dev/null +++ b/core/libs/prx/libScePlayGoDialog/Export.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include "SceTypes.hpp" +#include "prx/libc/include/General.hpp" + +static_assert(sizeof(PlayGoDialogResult) == 40); + +namespace { + +constexpr std::int32_t STATUS_NONE = 0; +constexpr std::int32_t STATUS_INITIALIZED = 1; +constexpr std::int32_t STATUS_RUNNING = 2; +constexpr std::int32_t STATUS_FINISHED = 3; + +constexpr std::int32_t RESULT_OK = 0; + +constexpr std::int32_t ERROR_NOT_INITIALIZED = static_cast(0x80ED0001); +constexpr std::int32_t ERROR_ALREADY_INITIALIZED = static_cast(0x80ED0002); +constexpr std::int32_t ERROR_PARAM_INVALID = static_cast(0x80ED0003); +constexpr std::int32_t ERROR_INVALID_STATE = static_cast(0x80ED0005); + +std::atomic g_status{STATUS_NONE}; + +} // namespace + +extern "C" { + +int APS5_VABI scePlayGoDialogInitialize(void) { + int expected = STATUS_NONE; + if (!g_status.compare_exchange_strong(expected, STATUS_INITIALIZED)) return ERROR_ALREADY_INITIALIZED; + return 0; +} + +int APS5_VABI scePlayGoDialogTerminate(void) { + int expected = STATUS_INITIALIZED; + if (!g_status.compare_exchange_strong(expected, STATUS_NONE)) { + expected = STATUS_FINISHED; + if (!g_status.compare_exchange_strong(expected, STATUS_NONE)) return ERROR_NOT_INITIALIZED; + } + return 0; +} + +int APS5_VABI scePlayGoDialogOpen(const void* param) { + if (!param) return ERROR_PARAM_INVALID; + int expected = STATUS_INITIALIZED; + if (!g_status.compare_exchange_strong(expected, STATUS_FINISHED)) { + expected = STATUS_FINISHED; + if (!g_status.compare_exchange_strong(expected, STATUS_FINISHED)) return ERROR_INVALID_STATE; + } + return 0; +} + +int APS5_VABI scePlayGoDialogClose(void) { + if (g_status.load() == STATUS_NONE) return ERROR_NOT_INITIALIZED; + g_status.store(STATUS_FINISHED); + return 0; +} + +int APS5_VABI scePlayGoDialogUpdateStatus(void) { + int expected = STATUS_RUNNING; + g_status.compare_exchange_strong(expected, STATUS_FINISHED); + return g_status.load(); +} + +int APS5_VABI scePlayGoDialogGetResult(void* result) { + if (g_status.load() == STATUS_NONE) return ERROR_NOT_INITIALIZED; + if (!result) return ERROR_PARAM_INVALID; + auto* r = static_cast(result); + std::memset(r, 0, sizeof(*r)); + r->result = RESULT_OK; + return 0; +} + +} diff --git a/core/libs/tests/GuestPlayGoDialog.cpp b/core/libs/tests/GuestPlayGoDialog.cpp new file mode 100644 index 000000000..9c313bda1 --- /dev/null +++ b/core/libs/tests/GuestPlayGoDialog.cpp @@ -0,0 +1,46 @@ +#include "SceTypes.hpp" +#include "prx/libc/include/general/VabiMacros.hpp" +#include +#include +#include + +extern "C" { +int APS5_VABI scePlayGoDialogInitialize(void); +int APS5_VABI scePlayGoDialogTerminate(void); +int APS5_VABI scePlayGoDialogOpen(const void* param); +int APS5_VABI scePlayGoDialogClose(void); +int APS5_VABI scePlayGoDialogUpdateStatus(void); +int APS5_VABI scePlayGoDialogGetResult(void* result); +} + +static void Require(bool value) { if (!value) std::abort(); } + +int main() { + constexpr std::int32_t notInitialized = static_cast(0x80ED0001); + constexpr std::int32_t alreadyInitialized = static_cast(0x80ED0002); + constexpr std::int32_t paramInvalid = static_cast(0x80ED0003); + constexpr std::int32_t invalidState = static_cast(0x80ED0005); + + Require(scePlayGoDialogTerminate() == notInitialized); + Require(scePlayGoDialogOpen(nullptr) == paramInvalid); + Require(scePlayGoDialogGetResult(nullptr) == notInitialized); + + const int openParam = 1; + Require(scePlayGoDialogOpen(&openParam) == invalidState); + + Require(scePlayGoDialogInitialize() == 0); + Require(scePlayGoDialogInitialize() == alreadyInitialized); + Require(scePlayGoDialogOpen(nullptr) == paramInvalid); + Require(scePlayGoDialogUpdateStatus() == 1); + + Require(scePlayGoDialogOpen(&openParam) == 0); + Require(scePlayGoDialogUpdateStatus() == 3); + + PlayGoDialogResult result{}; + Require(scePlayGoDialogGetResult(&result) == 0); + Require(result.result == 0); + Require(scePlayGoDialogClose() == 0); + Require(scePlayGoDialogTerminate() == 0); + Require(scePlayGoDialogTerminate() == notInitialized); + return 0; +}