Files
shadPS4/src/core/libraries/move/move.cpp
Stephen Miller 68e35d57d2 Libraries: Better libSceMove stubs (#3433)
* Improved libSceMove stubs

These should more accurately represent how an actual PS4 behaves when a game calls libSceMove functions while no move controllers are connected.

* Clang

* Change sceMoveGetExtensionPortInfo stub

Not entirely sure the ExtensionPortData struct is for this one, but the struct itself isn't exactly important for now anyway.

* Fix sceMoveTerm

* Update move.cpp
2025-08-18 17:41:50 -07:00

136 lines
4.5 KiB
C++

// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#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 {
static bool g_library_initialized = false;
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;
}
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;
}
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;
}
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);
};
} // namespace Libraries::Move