mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-18 23:07:07 -05:00
fix(libSceMsgDialog.native): return error codes instead of throwing in initialize and terminate
This commit is contained in:
3 files changed
+34
-32
No files matched your search
@@ -1,6 +1,5 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <cstddef>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
@@ -11,6 +10,7 @@ std::atomic<int> 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_ALREADY_INITIALIZED = static_cast<int>(0x80B80004u);
|
||||
constexpr int COMMON_DIALOG_ERROR_NOT_INITIALIZED = static_cast<int>(0x80B80003u);
|
||||
constexpr int COMMON_DIALOG_ERROR_NOT_FINISHED = static_cast<int>(0x80B80005u);
|
||||
constexpr int COMMON_DIALOG_ERROR_NOT_RUNNING = static_cast<int>(0x80B8000Bu);
|
||||
@@ -23,41 +23,38 @@ 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 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;
|
||||
if (result == nullptr) return COMMON_DIALOG_ERROR_ARG_NULL;
|
||||
if (status != COMMON_DIALOG_STATUS_FINISHED) return COMMON_DIALOG_ERROR_NOT_FINISHED;
|
||||
*result = MsgDialogResult{};
|
||||
result->result = COMMON_DIALOG_RESULT_OK;
|
||||
result->button_id = BUTTON_ID_OK;
|
||||
return 0;
|
||||
const int status = g_status.load();
|
||||
if (status == 0) return COMMON_DIALOG_ERROR_NOT_INITIALIZED;
|
||||
if (result == nullptr) return COMMON_DIALOG_ERROR_ARG_NULL;
|
||||
if (status != COMMON_DIALOG_STATUS_FINISHED) return COMMON_DIALOG_ERROR_NOT_FINISHED;
|
||||
*result = MsgDialogResult{};
|
||||
result->result = COMMON_DIALOG_RESULT_OK;
|
||||
result->button_id = BUTTON_ID_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogInitialize(void) {
|
||||
int expected = 0;
|
||||
if (!g_status.compare_exchange_strong(expected, 1)) throw std::logic_error("sceMsgDialogInitialize: already initialized");
|
||||
if (!g_status.compare_exchange_strong(expected, 1)) return COMMON_DIALOG_ERROR_ALREADY_INITIALIZED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogOpen(const void* param) {
|
||||
const int status = g_status.load();
|
||||
if (status == 0) return COMMON_DIALOG_ERROR_NOT_INITIALIZED;
|
||||
if (param == nullptr) return COMMON_DIALOG_ERROR_ARG_NULL;
|
||||
g_status = COMMON_DIALOG_STATUS_FINISHED;
|
||||
return 0;
|
||||
const int status = g_status.load();
|
||||
if (status == 0) return COMMON_DIALOG_ERROR_NOT_INITIALIZED;
|
||||
if (param == nullptr) return COMMON_DIALOG_ERROR_ARG_NULL;
|
||||
g_status = COMMON_DIALOG_STATUS_FINISHED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogTerminate(void) {
|
||||
int expected = 1;
|
||||
if (g_status.compare_exchange_strong(expected, 0)) return 0;
|
||||
expected = COMMON_DIALOG_STATUS_FINISHED;
|
||||
if (!g_status.compare_exchange_strong(expected, 0)) throw std::logic_error("sceMsgDialogTerminate: not initialized or still running");
|
||||
if (g_status.exchange(0) == 0) return COMMON_DIALOG_ERROR_NOT_INITIALIZED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,21 +63,21 @@ int APS5_VABI sceMsgDialogUpdateStatus(void) {
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogProgressBarInc(int target, std::uint32_t delta) {
|
||||
(void)target;
|
||||
(void)delta;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
(void)target;
|
||||
(void)delta;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogProgressBarSetMsg(int target, const char* msg) {
|
||||
(void)target;
|
||||
(void)msg;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
(void)target;
|
||||
(void)msg;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogProgressBarSetValue(int target, std::uint32_t rate) {
|
||||
(void)target;
|
||||
(void)rate;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
(void)target;
|
||||
(void)rate;
|
||||
return g_status.load() == COMMON_DIALOG_STATUS_RUNNING ? 0 : COMMON_DIALOG_ERROR_NOT_RUNNING;
|
||||
}
|
||||
|
||||
int APS5_VABI sceMsgDialogGetStatus(void) {
|
||||
|
||||
@@ -22,6 +22,8 @@ void Require(bool value) { if (!value) std::abort(); }
|
||||
|
||||
constexpr int kStatusInitialized = 1;
|
||||
constexpr int kStatusFinished = 3;
|
||||
constexpr int kErrAlreadyInitialized = static_cast<int>(0x80B80004u);
|
||||
constexpr int kErrNotInitialized = static_cast<int>(0x80B80003u);
|
||||
constexpr int kErrNotRunning = static_cast<int>(0x80B8000Bu);
|
||||
constexpr int kButtonIdOk = 1;
|
||||
|
||||
@@ -30,11 +32,13 @@ constexpr int kButtonIdOk = 1;
|
||||
int main() {
|
||||
std::uint8_t param[0x60]{};
|
||||
|
||||
Require(sceMsgDialogTerminate() == kErrNotInitialized);
|
||||
Require(sceMsgDialogClose() == kErrNotRunning);
|
||||
Require(sceMsgDialogUpdateStatus() == 0);
|
||||
Require(sceMsgDialogGetStatus() == 0);
|
||||
|
||||
Require(sceMsgDialogInitialize() == 0);
|
||||
Require(sceMsgDialogInitialize() == kErrAlreadyInitialized);
|
||||
Require(sceMsgDialogClose() == kErrNotRunning);
|
||||
Require(sceMsgDialogUpdateStatus() == kStatusInitialized);
|
||||
Require(sceMsgDialogGetStatus() == kStatusInitialized);
|
||||
@@ -57,6 +61,7 @@ int main() {
|
||||
Require(result.button_id == kButtonIdOk);
|
||||
|
||||
Require(sceMsgDialogTerminate() == 0);
|
||||
Require(sceMsgDialogTerminate() == kErrNotInitialized);
|
||||
Require(sceMsgDialogClose() == kErrNotRunning);
|
||||
Require(sceMsgDialogGetStatus() == 0);
|
||||
}
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
### Silent stubs
|
||||
|
||||
- [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
|
||||
- [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. `sceMsgDialogTerminate` resets running or finished dialogs and returns OK, rejecting uninitialized calls with `COMMON_DIALOG_ERROR_NOT_INITIALIZED` following shadPS4.
|
||||
Reference in new issue
Block a user