diff --git a/CMakeLists.txt b/CMakeLists.txt index 828838513..9db1b98dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -611,6 +611,7 @@ set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp src/core/libraries/screenshot/screenshot.h src/core/libraries/move/move.cpp src/core/libraries/move/move.h + src/core/libraries/move/move_error.h src/core/libraries/ulobjmgr/ulobjmgr.cpp src/core/libraries/ulobjmgr/ulobjmgr.h src/core/libraries/signin_dialog/signindialog.cpp diff --git a/src/core/libraries/move/move.cpp b/src/core/libraries/move/move.cpp index f63142615..7d3062e7c 100644 --- a/src/core/libraries/move/move.cpp +++ b/src/core/libraries/move/move.cpp @@ -4,47 +4,133 @@ #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" +#include "core/libraries/move/move.h" +#include "core/libraries/move/move_error.h" #include "move.h" namespace Libraries::Move { -int PS4_SYSV_ABI sceMoveOpen() { - LOG_TRACE(Lib_Move, "(STUBBED) called"); - return ORBIS_FAIL; -} +static bool g_library_initialized = false; -int PS4_SYSV_ABI sceMoveGetDeviceInfo() { - LOG_ERROR(Lib_Move, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceMoveInit() { + if (g_library_initialized) { + return ORBIS_MOVE_ERROR_ALREADY_INIT; + } + LOG_WARNING(Lib_Move, "Move controllers are not supported yet"); + g_library_initialized = true; return ORBIS_OK; } -int PS4_SYSV_ABI sceMoveReadStateLatest() { - LOG_TRACE(Lib_Move, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceMoveOpen(Libraries::UserService::OrbisUserServiceUserId user_id, s32 type, + s32 index) { + LOG_DEBUG(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + // Even when no controllers are connected, this returns a proper handle. + static s32 handle = 1; + return handle++; +} + +s32 PS4_SYSV_ABI sceMoveGetDeviceInfo(s32 handle, OrbisMoveDeviceInfo* info) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + if (info == nullptr) { + return ORBIS_MOVE_ERROR_INVALID_ARG; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveReadStateLatest(s32 handle, OrbisMoveData* data) { + LOG_TRACE(Lib_Move, "(called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + if (data == nullptr) { + return ORBIS_MOVE_ERROR_INVALID_ARG; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveReadStateRecent(s32 handle, s64 timestamp, OrbisMoveData* data, + s32* out_count) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + if (timestamp < 0 || data == nullptr || out_count == nullptr) { + return ORBIS_MOVE_ERROR_INVALID_ARG; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveGetExtensionPortInfo(s32 handle, void* data) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + if (data == nullptr) { + return ORBIS_MOVE_ERROR_INVALID_ARG; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveSetVibration(s32 handle, u8 intensity) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveSetLightSphere(s32 handle, u8 red, u8 green, u8 blue) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + return ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED; +} + +s32 PS4_SYSV_ABI sceMoveResetLightSphere(s32 handle) { + LOG_TRACE(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + // Returns success, even if no controllers are connected. return ORBIS_OK; } -int PS4_SYSV_ABI sceMoveReadStateRecent() { - LOG_TRACE(Lib_Move, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceMoveClose(s32 handle) { + LOG_DEBUG(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } return ORBIS_OK; } -int PS4_SYSV_ABI sceMoveTerm() { - LOG_ERROR(Lib_Move, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceMoveInit() { - LOG_ERROR(Lib_Move, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceMoveTerm() { + LOG_DEBUG(Lib_Move, "called"); + if (!g_library_initialized) { + return ORBIS_MOVE_ERROR_NOT_INIT; + } + g_library_initialized = false; return ORBIS_OK; } void RegisterLib(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("j1ITE-EoJmE", "libSceMove", 1, "libSceMove", 1, 1, sceMoveInit); LIB_FUNCTION("HzC60MfjJxU", "libSceMove", 1, "libSceMove", 1, 1, sceMoveOpen); LIB_FUNCTION("GWXTyxs4QbE", "libSceMove", 1, "libSceMove", 1, 1, sceMoveGetDeviceInfo); LIB_FUNCTION("ttU+JOhShl4", "libSceMove", 1, "libSceMove", 1, 1, sceMoveReadStateLatest); LIB_FUNCTION("f2bcpK6kJfg", "libSceMove", 1, "libSceMove", 1, 1, sceMoveReadStateRecent); + LIB_FUNCTION("y5h7f8H1Jnk", "libSceMove", 1, "libSceMove", 1, 1, sceMoveGetExtensionPortInfo); + LIB_FUNCTION("IFQwtT2CeY0", "libSceMove", 1, "libSceMove", 1, 1, sceMoveSetVibration); + LIB_FUNCTION("T8KYHPs1JE8", "libSceMove", 1, "libSceMove", 1, 1, sceMoveSetLightSphere); + LIB_FUNCTION("zuxWAg3HAac", "libSceMove", 1, "libSceMove", 1, 1, sceMoveResetLightSphere); + LIB_FUNCTION("XX6wlxpHyeo", "libSceMove", 1, "libSceMove", 1, 1, sceMoveClose); LIB_FUNCTION("tsZi60H4ypY", "libSceMove", 1, "libSceMove", 1, 1, sceMoveTerm); - LIB_FUNCTION("j1ITE-EoJmE", "libSceMove", 1, "libSceMove", 1, 1, sceMoveInit); }; } // namespace Libraries::Move \ No newline at end of file diff --git a/src/core/libraries/move/move.h b/src/core/libraries/move/move.h index 8ae6c545c..7300226e3 100644 --- a/src/core/libraries/move/move.h +++ b/src/core/libraries/move/move.h @@ -4,6 +4,7 @@ #pragma once #include "common/types.h" +#include "core/libraries/system/userservice.h" namespace Core::Loader { class SymbolsResolver; @@ -11,11 +12,36 @@ class SymbolsResolver; namespace Libraries::Move { -int PS4_SYSV_ABI sceMoveOpen(); -int PS4_SYSV_ABI sceMoveGetDeviceInfo(); -int PS4_SYSV_ABI sceMoveReadStateRecent(); -int PS4_SYSV_ABI sceMoveTerm(); -int PS4_SYSV_ABI sceMoveInit(); +struct OrbisMoveDeviceInfo { + float sphere_radius; + float accelerometer_offset[3]; +}; + +struct OrbisMoveButtonData { + u16 button_data; + u16 trigger_data; +}; + +struct OrbisMoveExtensionPortData { + u16 status; + u16 digital0; + u16 digital1; + u16 analog_right_x; + u16 analog_right_y; + u16 analog_left_x; + u16 analog_left_y; + unsigned char custom[5]; +}; + +struct OrbisMoveData { + float accelerometer[3]; + float gyro[3]; + OrbisMoveButtonData button_data; + OrbisMoveExtensionPortData extension_data; + s64 timestamp; + s32 count; + float temperature; +}; void RegisterLib(Core::Loader::SymbolsResolver* sym); } // namespace Libraries::Move \ No newline at end of file diff --git a/src/core/libraries/move/move_error.h b/src/core/libraries/move/move_error.h new file mode 100644 index 000000000..2ba4285d7 --- /dev/null +++ b/src/core/libraries/move/move_error.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/types.h" + +constexpr s32 ORBIS_MOVE_ERROR_NO_CONTROLLER_CONNECTED = 1; + +constexpr s32 ORBIS_MOVE_ERROR_NOT_INIT = 0x80EE0001; +constexpr s32 ORBIS_MOVE_ERROR_ALREADY_INIT = 0x80EE0002; +constexpr s32 ORBIS_MOVE_ERROR_INVALID_ARG = 0x80EE0003; +constexpr s32 ORBIS_MOVE_ERROR_INVALID_HANDLE = 0x80EE0004; +constexpr s32 ORBIS_MOVE_ERROR_MAX_CONTROLLERS_EXCEEDED = 0x80EE0005; +constexpr s32 ORBIS_MOVE_ERROR_INVALID_PORT = 0x80EE0006; +constexpr s32 ORBIS_MOVE_ERROR_ALREADY_OPENED = 0x80EE0007; +constexpr s32 ORBIS_MOVE_ERROR_FATAL = 0x80EE00FF; \ No newline at end of file