Misc Fixes 10 (#781)
Some checks are pending
Reuse / reuse (push) Waiting to run
Clang Format / clang-format (push) Waiting to run
Linux-Qt / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS-Qt / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows-Qt / build (push) Waiting to run
Windows / build (push) Waiting to run

* libSceRazorCpu needed for gravity rush

* libSceCesCs needed for blue reflection

* clang format fix

* set scePadSetVibration to log debug

* initial sceNetCtl module implementation

* improved error codes in file system

* some intial work on netctl callbacks (helps a bit CUSA10135)

* misc

* improved callbacks handling in sceNetCtl

* small fixes

* added libSceRudp.sprx to lle modules

* draft work for npcallbacks
This commit is contained in:
georgemoralis 2024-09-11 16:48:16 +03:00 committed by GitHub
parent 1c0dfc60a1
commit 0ebae4ca6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 290 additions and 30 deletions

View file

@ -212,6 +212,9 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp
src/core/libraries/network/net.cpp
src/core/libraries/network/netctl.cpp
src/core/libraries/network/netctl.h
src/core/libraries/network/net_ctl_obj.cpp
src/core/libraries/network/net_ctl_obj.h
src/core/libraries/network/net_ctl_codes.h
src/core/libraries/network/net.h
src/core/libraries/network/ssl.cpp
src/core/libraries/network/ssl.h

View file

@ -150,7 +150,6 @@ int PS4_SYSV_ABI posix_close(int d) {
return -1;
}
return result;
return ORBIS_OK;
}
size_t PS4_SYSV_ABI sceKernelWrite(int d, const void* buf, size_t nbytes) {
@ -367,8 +366,17 @@ s64 PS4_SYSV_ABI sceKernelPread(int d, void* buf, size_t nbytes, s64 offset) {
int PS4_SYSV_ABI sceKernelFStat(int fd, OrbisKernelStat* sb) {
LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd);
if (fd < 3) {
return ORBIS_KERNEL_ERROR_EPERM;
}
if (sb == nullptr) {
return ORBIS_KERNEL_ERROR_EFAULT;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF;
}
std::memset(sb, 0, sizeof(OrbisKernelStat));
if (file->is_directory) {
@ -421,15 +429,24 @@ int PS4_SYSV_ABI sceKernelFtruncate(int fd, s64 length) {
}
static int GetDents(int fd, char* buf, int nbytes, s64* basep) {
// TODO error codes
ASSERT(buf != nullptr);
if (fd < 3) {
return ORBIS_KERNEL_ERROR_EBADF;
}
if (buf == nullptr) {
return ORBIS_KERNEL_ERROR_EFAULT;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF;
}
if (file->dirents_index == file->dirents.size()) {
return ORBIS_OK;
}
if (!file->is_directory || nbytes < 512 || file->dirents_index > file->dirents.size()) {
return ORBIS_KERNEL_ERROR_EINVAL;
}
const auto& entry = file->dirents.at(file->dirents_index++);
auto str = entry.name;
auto str_size = str.size() - 1;

View file

@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
// error codes
constexpr int ORBIS_NET_CTL_ERROR_CALLBACK_MAX = 0x80412103;
constexpr int ORBIS_NET_CTL_ERROR_ID_NOT_FOUND = 0x80412104;
constexpr int ORBIS_NET_CTL_ERROR_INVALID_ID = 0x80412105;
constexpr int ORBIS_NET_CTL_ERROR_INVALID_ADDR = 0x80412107;
constexpr int ORBIS_NET_CTL_ERROR_NOT_CONNECTED = 0x80412108;
constexpr int ORBIS_NET_CTL_ERROR_NOT_AVAIL = 0x80412109;
constexpr int ORBIS_NET_CTL_ERROR_NETWORK_DISABLED = 0x8041210D;
constexpr int ORBIS_NET_CTL_ERROR_DISCONNECT_REQ = 0x8041210E;
constexpr int ORBIS_NET_CTL_ERROR_ETHERNET_PLUGOUT = 0x80412115;
constexpr int ORBIS_NET_CTL_ERROR_WIFI_DEAUTHED = 0x80412116;
constexpr int ORBIS_NET_CTL_ERROR_WIFI_BEACON_LOST = 0x80412117;
// state codes
constexpr int ORBIS_NET_CTL_STATE_DISCONNECTED = 0;
constexpr int ORBIS_NET_CTL_STATE_CONNECTING = 1;
constexpr int ORBIS_NET_CTL_STATE_IPOBTAINING = 2;
constexpr int ORBIS_NET_CTL_STATE_IPOBTAINED = 3;
// event type
constexpr int ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED = 1;
constexpr int ORBIS_SCE_NET_CTL_EVENT_TYPE_DISCONNECT_REQ_FINISHED = 2;
constexpr int ORBIS_NET_CTL_EVENT_TYPE_IPOBTAINED = 3;

View file

@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "net_ctl_codes.h"
#include "net_ctl_obj.h"
Libraries::NetCtl::NetCtlInternal::NetCtlInternal() {
callbacks.fill({nullptr, nullptr});
nptoolCallbacks.fill({nullptr, nullptr});
}
Libraries::NetCtl::NetCtlInternal::~NetCtlInternal() {}
s32 Libraries::NetCtl::NetCtlInternal::registerCallback(OrbisNetCtlCallback func, void* arg) {
std::unique_lock lock{m_mutex};
// Find the next available slot
int next_id = 0;
for (const auto& callback : callbacks) {
if (callback.func == nullptr) {
break;
}
next_id++;
}
if (next_id == 8) {
return ORBIS_NET_CTL_ERROR_CALLBACK_MAX;
}
callbacks[next_id].func = func;
callbacks[next_id].arg = arg;
return next_id;
}
s32 Libraries::NetCtl::NetCtlInternal::registerNpToolkitCallback(
OrbisNetCtlCallbackForNpToolkit func, void* arg) {
std::unique_lock lock{m_mutex};
// Find the next available slot
int next_id = 0;
for (const auto& callback : nptoolCallbacks) {
if (callback.func == nullptr) {
break;
}
next_id++;
}
if (next_id == 8) {
return ORBIS_NET_CTL_ERROR_CALLBACK_MAX;
}
nptoolCallbacks[next_id].func = func;
nptoolCallbacks[next_id].arg = arg;
return next_id;
}
void Libraries::NetCtl::NetCtlInternal::checkCallback() {
std::unique_lock lock{m_mutex};
for (auto& callback : callbacks) {
if (callback.func != nullptr) {
callback.func(ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, callback.arg);
}
}
}
void Libraries::NetCtl::NetCtlInternal::checkNpToolkitCallback() {
std::unique_lock lock{m_mutex};
for (auto& callback : nptoolCallbacks) {
if (callback.func != nullptr) {
callback.func(ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, callback.arg);
}
}
}

View file

@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <condition_variable>
#include <mutex>
#include "common/types.h"
namespace Libraries::NetCtl {
using OrbisNetCtlCallback = PS4_SYSV_ABI void (*)(int eventType, void* arg);
using OrbisNetCtlCallbackForNpToolkit = PS4_SYSV_ABI void (*)(int eventType, void* arg);
struct NetCtlCallback {
OrbisNetCtlCallback func;
void* arg;
};
struct NetCtlCallbackForNpToolkit {
OrbisNetCtlCallbackForNpToolkit func;
void* arg;
};
class NetCtlInternal {
public:
NetCtlInternal();
~NetCtlInternal();
s32 registerCallback(OrbisNetCtlCallback func, void* arg);
s32 registerNpToolkitCallback(OrbisNetCtlCallbackForNpToolkit func, void* arg);
void checkCallback();
void checkNpToolkitCallback();
public:
std::array<NetCtlCallback, 8> nptoolCallbacks;
std::array<NetCtlCallbackForNpToolkit, 8> callbacks;
std::mutex m_mutex;
};
} // namespace Libraries::NetCtl

View file

@ -2,8 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
#include "core/libraries/network/net_ctl_codes.h"
#include "core/libraries/network/netctl.h"
namespace Libraries::NetCtl {
@ -79,7 +81,8 @@ int PS4_SYSV_ABI sceNetCtlUnregisterCallbackV6() {
}
int PS4_SYSV_ABI sceNetCtlCheckCallback() {
LOG_TRACE(Lib_NetCtl, "(STUBBED) called");
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
netctl->checkCallback();
return ORBIS_OK;
}
@ -143,7 +146,17 @@ int PS4_SYSV_ABI sceNetCtlGetIfStat() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNetCtlGetInfo() {
int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info) {
switch (code) {
case ORBIS_NET_CTL_INFO_DEVICE:
info->device = 0;
break;
case ORBIS_NET_CTL_INFO_LINK:
info->link = 0; // disconnected
break;
default:
LOG_ERROR(Lib_NetCtl, "{} unsupported code", code);
}
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
return ORBIS_OK;
}
@ -173,8 +186,9 @@ int PS4_SYSV_ABI sceNetCtlGetNetEvConfigInfoIpcInt() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNetCtlGetResult() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlGetResult(int eventType, int* errorCode) {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called eventType = {} ", eventType);
*errorCode = 0;
return ORBIS_OK;
}
@ -213,8 +227,8 @@ int PS4_SYSV_ABI sceNetCtlGetScanInfoForSsidScanIpcInt() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNetCtlGetState() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlGetState(int* state) {
*state = ORBIS_NET_CTL_STATE_DISCONNECTED;
return ORBIS_OK;
}
@ -248,8 +262,17 @@ int PS4_SYSV_ABI sceNetCtlIsBandwidthManagementEnabledIpcInt() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNetCtlRegisterCallback() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlRegisterCallback(OrbisNetCtlCallback func, void* arg, int* cid) {
if (!func || !cid) {
return ORBIS_NET_CTL_ERROR_INVALID_ADDR;
}
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
s32 result = netctl->registerCallback(func, arg);
if (result < 0) {
return result;
} else {
*cid = result;
}
return ORBIS_OK;
}
@ -319,7 +342,8 @@ int PS4_SYSV_ABI Func_D8DCB6973537A3DC() {
}
int PS4_SYSV_ABI sceNetCtlCheckCallbackForNpToolkit() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
netctl->checkNpToolkitCallback();
return ORBIS_OK;
}
@ -328,8 +352,18 @@ int PS4_SYSV_ABI sceNetCtlClearEventForNpToolkit() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit(OrbisNetCtlCallbackForNpToolkit func,
void* arg, int* cid) {
if (!func || !cid) {
return ORBIS_NET_CTL_ERROR_INVALID_ADDR;
}
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
s32 result = netctl->registerNpToolkitCallback(func, arg);
if (result < 0) {
return result;
} else {
*cid = result;
}
return ORBIS_OK;
}

View file

@ -4,6 +4,7 @@
#pragma once
#include "common/types.h"
#include "net_ctl_obj.h"
namespace Core::Loader {
class SymbolsResolver;
@ -11,6 +12,45 @@ class SymbolsResolver;
namespace Libraries::NetCtl {
constexpr int ORBIS_NET_ETHER_ADDR_LEN = 6;
struct OrbisNetEtherAddr {
u8 data[ORBIS_NET_ETHER_ADDR_LEN];
};
constexpr int ORBIS_NET_CTL_SSID_LEN = 32 + 1;
constexpr int ORBIS_NET_CTL_HOSTNAME_LEN = 255 + 1;
constexpr int ORBIS_NET_CTL_AUTH_NAME_LEN = 127 + 1;
constexpr int ORBIS_NET_CTL_IPV4_ADDR_STR_LEN = 16;
typedef union OrbisNetCtlInfo {
u32 device;
OrbisNetEtherAddr ether_addr;
u32 mtu;
u32 link;
OrbisNetEtherAddr bssid;
char ssid[ORBIS_NET_CTL_SSID_LEN];
u32 wifi_security;
u8 rssi_dbm;
uint8_t rssi_percentage;
u8 channel;
u32 ip_config;
char dhcp_hostname[ORBIS_NET_CTL_HOSTNAME_LEN];
char pppoe_auth_name[ORBIS_NET_CTL_AUTH_NAME_LEN];
char ip_address[ORBIS_NET_CTL_IPV4_ADDR_STR_LEN];
char netmask[ORBIS_NET_CTL_IPV4_ADDR_STR_LEN];
char default_route[ORBIS_NET_CTL_IPV4_ADDR_STR_LEN];
char primary_dns[ORBIS_NET_CTL_IPV4_ADDR_STR_LEN];
char secondary_dns[ORBIS_NET_CTL_IPV4_ADDR_STR_LEN];
u32 http_proxy_config;
char http_proxy_server[ORBIS_NET_CTL_HOSTNAME_LEN];
u16 http_proxy_port;
} SceNetCtlInfo;
// GetInfo codes
constexpr int ORBIS_NET_CTL_INFO_DEVICE = 1;
constexpr int ORBIS_NET_CTL_INFO_LINK = 4;
int PS4_SYSV_ABI sceNetBweCheckCallbackIpcInt();
int PS4_SYSV_ABI sceNetBweClearEventIpcInt();
int PS4_SYSV_ABI sceNetBweFinishInternetConnectionTestIpcInt();
@ -38,13 +78,13 @@ int PS4_SYSV_ABI sceNetCtlEnableBandwidthManagementIpcInt();
int PS4_SYSV_ABI sceNetCtlGetBandwidthInfoIpcInt();
int PS4_SYSV_ABI sceNetCtlGetEtherLinkMode();
int PS4_SYSV_ABI sceNetCtlGetIfStat();
int PS4_SYSV_ABI sceNetCtlGetInfo();
int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info);
int PS4_SYSV_ABI sceNetCtlGetInfoIpcInt();
int PS4_SYSV_ABI sceNetCtlGetInfoV6IpcInt();
int PS4_SYSV_ABI sceNetCtlGetNatInfo();
int PS4_SYSV_ABI sceNetCtlGetNatInfoIpcInt();
int PS4_SYSV_ABI sceNetCtlGetNetEvConfigInfoIpcInt();
int PS4_SYSV_ABI sceNetCtlGetResult();
int PS4_SYSV_ABI sceNetCtlGetResult(int eventType, int* errorCode);
int PS4_SYSV_ABI sceNetCtlGetResultIpcInt();
int PS4_SYSV_ABI sceNetCtlGetResultV6IpcInt();
int PS4_SYSV_ABI sceNetCtlGetScanInfoBssidForSsidListScanIpcInt();
@ -52,14 +92,14 @@ int PS4_SYSV_ABI sceNetCtlGetScanInfoBssidIpcInt();
int PS4_SYSV_ABI sceNetCtlGetScanInfoByBssidIpcInt();
int PS4_SYSV_ABI sceNetCtlGetScanInfoForSsidListScanIpcInt();
int PS4_SYSV_ABI sceNetCtlGetScanInfoForSsidScanIpcInt();
int PS4_SYSV_ABI sceNetCtlGetState();
int PS4_SYSV_ABI sceNetCtlGetState(int* state);
int PS4_SYSV_ABI sceNetCtlGetState2IpcInt();
int PS4_SYSV_ABI sceNetCtlGetStateIpcInt();
int PS4_SYSV_ABI sceNetCtlGetStateV6IpcInt();
int PS4_SYSV_ABI sceNetCtlGetWifiType();
int PS4_SYSV_ABI sceNetCtlInit();
int PS4_SYSV_ABI sceNetCtlIsBandwidthManagementEnabledIpcInt();
int PS4_SYSV_ABI sceNetCtlRegisterCallback();
int PS4_SYSV_ABI sceNetCtlRegisterCallback(OrbisNetCtlCallback func, void* arg, int* cid);
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForLibIpcInt();
int PS4_SYSV_ABI sceNetCtlRegisterCallbackIpcInt();
int PS4_SYSV_ABI sceNetCtlRegisterCallbackV6IpcInt();
@ -75,7 +115,8 @@ int PS4_SYSV_ABI sceNetCtlUnsetStunWithPaddingFlagIpcInt();
int PS4_SYSV_ABI Func_D8DCB6973537A3DC();
int PS4_SYSV_ABI sceNetCtlCheckCallbackForNpToolkit();
int PS4_SYSV_ABI sceNetCtlClearEventForNpToolkit();
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit();
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit(OrbisNetCtlCallbackForNpToolkit func,
void* arg, int* cid);
int PS4_SYSV_ABI sceNetCtlUnregisterCallbackForNpToolkit();
int PS4_SYSV_ABI sceNetCtlApCheckCallback();
int PS4_SYSV_ABI sceNetCtlApClearEvent();

View file

@ -874,8 +874,16 @@ int PS4_SYSV_ABI sceNpCheckCallback() {
return ORBIS_OK;
}
struct NpStateCallbackForNpToolkit {
OrbisNpStateCallbackForNpToolkit func;
void* userdata;
};
NpStateCallbackForNpToolkit NpStateCbForNp;
int PS4_SYSV_ABI sceNpCheckCallbackForLib() {
LOG_ERROR(Lib_NpManager, "(STUBBED) called");
// LOG_ERROR(Lib_NpManager, "(STUBBED) called");
NpStateCbForNp.func(0, ORBIS_NP_STATE_SIGNED_OUT, NpStateCbForNp.userdata);
return ORBIS_OK;
}
@ -2507,9 +2515,12 @@ int PS4_SYSV_ABI Func_FF966E4351E564D6() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit() {
int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit(OrbisNpStateCallbackForNpToolkit callback,
void* userdata) {
LOG_ERROR(Lib_NpManager, "(STUBBED) called");
return ORBIS_OK;
NpStateCbForNp.func = callback;
NpStateCbForNp.userdata = userdata;
return 1;
}
int PS4_SYSV_ABI sceNpUnregisterStateCallbackForToolkit() {

View file

@ -11,6 +11,15 @@ class SymbolsResolver;
namespace Libraries::NpManager {
enum OrbisNpState {
ORBIS_NP_STATE_UNKNOWN = 0,
ORBIS_NP_STATE_SIGNED_OUT,
ORBIS_NP_STATE_SIGNED_IN
};
using OrbisNpStateCallbackForNpToolkit = PS4_SYSV_ABI void (*)(s32 userId, OrbisNpState state,
void* userdata);
constexpr int ORBIS_NP_ONLINEID_MAX_LENGTH = 16;
typedef int OrbisUserServiceUserId;
@ -526,7 +535,8 @@ int PS4_SYSV_ABI Func_F91B5B25CC9B30D9();
int PS4_SYSV_ABI Func_FC335B7102A585B3();
int PS4_SYSV_ABI Func_FCEAC354CA8B206E();
int PS4_SYSV_ABI Func_FF966E4351E564D6();
int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit();
int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit(OrbisNpStateCallbackForNpToolkit callback,
void* userdata);
int PS4_SYSV_ABI sceNpUnregisterStateCallbackForToolkit();
void RegisterlibSceNpManager(Core::Loader::SymbolsResolver* sym);

View file

@ -522,8 +522,8 @@ int PS4_SYSV_ABI scePadSetUserColor() {
int PS4_SYSV_ABI scePadSetVibration(s32 handle, const OrbisPadVibrationParam* pParam) {
if (pParam != nullptr) {
LOG_INFO(Lib_Pad, "scePadSetVibration called handle = {} data = {} , {}", handle,
pParam->smallMotor, pParam->largeMotor);
LOG_DEBUG(Lib_Pad, "scePadSetVibration called handle = {} data = {} , {}", handle,
pParam->smallMotor, pParam->largeMotor);
auto* controller = Common::Singleton<Input::GameController>::Instance();
controller->SetVibration(pParam->smallMotor, pParam->largeMotor);
return ORBIS_OK;

View file

@ -205,7 +205,7 @@ void Emulator::Run(const std::filesystem::path& file) {
}
void Emulator::LoadSystemModules(const std::filesystem::path& file) {
constexpr std::array<SysModules, 10> ModulesToLoad{
constexpr std::array<SysModules, 13> ModulesToLoad{
{{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},
{"libSceFiber.sprx", nullptr},
{"libSceUlt.sprx", nullptr},
@ -215,8 +215,10 @@ void Emulator::LoadSystemModules(const std::filesystem::path& file) {
{"libSceDiscMap.sprx", &Libraries::DiscMap::RegisterlibSceDiscMap},
{"libSceRtc.sprx", &Libraries::Rtc::RegisterlibSceRtc},
{"libSceJpegEnc.sprx", nullptr},
{"libSceFont.sprx", nullptr}},
};
{"libSceFont.sprx", nullptr},
{"libSceRazorCpu.sprx", nullptr},
{"libSceCesCs.sprx", nullptr},
{"libSceRudp.sprx", nullptr}}};
std::vector<std::filesystem::path> found_modules;
const auto& sys_module_path = Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir);