nn_ac: Refactor and implement more API

Doesn't fix any issue as far as I know but it removes some of the unsupported API complaints in debug logging
This commit is contained in:
Exzap 2024-03-11 21:37:44 +01:00
parent dd7cb74cd2
commit 40d1eaeb72

View File

@ -8,83 +8,14 @@
// AC lib (manages internet connection) // AC lib (manages internet connection)
#define AC_STATUS_FAILED (-1) enum class AC_STATUS : uint32
#define AC_STATUS_OK (0)
void nn_acExport_ConnectAsync(PPCInterpreter_t* hCPU)
{ {
cemuLog_logDebug(LogType::Force, "nn_ac.ConnectAsync();"); FAILED = (uint32)-1,
uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0); OK = 0,
osLib_returnFromFunction(hCPU, nnResultCode); };
}
void nn_acExport_Connect(PPCInterpreter_t* hCPU)
{
cemuLog_logDebug(LogType::Force, "nn_ac.Connect();");
// Terraria expects this (or GetLastErrorCode) to return 0 on success
// investigate on the actual console
// maybe all success codes are always 0 and dont have any of the other fields set?
uint32 nnResultCode = 0;// BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0); // Splatoon freezes if this function fails?
osLib_returnFromFunction(hCPU, nnResultCode);
}
static_assert(TRUE == 1, "TRUE not 1"); static_assert(TRUE == 1, "TRUE not 1");
void nn_acExport_IsApplicationConnected(PPCInterpreter_t* hCPU)
{
//cemuLog_logDebug(LogType::Force, "nn_ac.IsApplicationConnected(0x{:08x})", hCPU->gpr[3]);
ppcDefineParamMEMPTR(connected, uint8, 0);
if (connected)
*connected = TRUE;
//memory_writeU8(hCPU->gpr[3], 1); // always return true regardless of actual online state
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
osLib_returnFromFunction(hCPU, nnResultCode);
}
void nn_acExport_GetConnectStatus(PPCInterpreter_t* hCPU)
{
ppcDefineParamMEMPTR(status, uint32, 0);
if (status)
*status = AC_STATUS_OK;
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
osLib_returnFromFunction(hCPU, nnResultCode);
}
void nn_acExport_GetLastErrorCode(PPCInterpreter_t* hCPU)
{
//cemuLog_logDebug(LogType::Force, "nn_ac.GetLastErrorCode();");
ppcDefineParamMEMPTR(errorCode, uint32, 0);
if (errorCode)
*errorCode = 0;
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
osLib_returnFromFunction(hCPU, nnResultCode);
}
void nn_acExport_GetStatus(PPCInterpreter_t* hCPU)
{
cemuLog_logDebug(LogType::Force, "nn_ac.GetStatus();");
ppcDefineParamMEMPTR(status, uint32, 0);
if (status)
*status = AC_STATUS_OK;
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
osLib_returnFromFunction(hCPU, nnResultCode);
}
void nn_acExport_GetConnectResult(PPCInterpreter_t* hCPU)
{
// GetConnectStatus__Q2_2nn2acFPQ3_2nn2ac6Status
cemuLog_logDebug(LogType::Force, "nn_ac.GetConnectResult(0x{:08x})", hCPU->gpr[3]);
ppcDefineParamMEMPTR(result, uint32, 0);
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
if (result)
*result = nnResultCode;
osLib_returnFromFunction(hCPU, nnResultCode);
}
void _GetLocalIPAndSubnetMaskFallback(uint32& localIp, uint32& subnetMask) void _GetLocalIPAndSubnetMaskFallback(uint32& localIp, uint32& subnetMask)
{ {
// default to some hardcoded values // default to some hardcoded values
@ -227,37 +158,127 @@ void nnAcExport_IsConfigExisting(PPCInterpreter_t* hCPU)
namespace nn_ac namespace nn_ac
{ {
nnResult Initialize()
{
return BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
}
nnResult ConnectAsync()
{
return BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
}
nnResult IsApplicationConnected(uint8be* connected)
{
if (connected)
*connected = TRUE;
return BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
}
uint32 Connect()
{
// Terraria expects this (or GetLastErrorCode) to return 0 on success
// investigate on the actual console
// maybe all success codes are always 0 and dont have any of the other fields set?
uint32 nnResultCode = 0;// BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0); // Splatoon freezes if this function fails?
return nnResultCode;
}
nnResult GetConnectStatus(betype<AC_STATUS>* status)
{
if (status)
*status = AC_STATUS::OK;
return BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
}
nnResult GetStatus(betype<AC_STATUS>* status)
{
return GetConnectStatus(status);
}
nnResult GetLastErrorCode(uint32be* errorCode)
{
if (errorCode)
*errorCode = 0;
return BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
}
nnResult GetConnectResult(uint32be* connectResult)
{
const uint32 nnResultCode = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_AC, 0);
if (connectResult)
*connectResult = nnResultCode;
return nnResultCode;
}
static_assert(sizeof(betype<AC_STATUS>) == 4);
static_assert(sizeof(betype<nnResult>) == 4);
nnResult ACInitialize()
{
return Initialize();
}
bool ACIsSuccess(betype<nnResult>* r) bool ACIsSuccess(betype<nnResult>* r)
{ {
return NN_RESULT_IS_SUCCESS(*r) ? 1 : 0; return NN_RESULT_IS_SUCCESS(*r) ? 1 : 0;
} }
nnResult ACGetConnectStatus(uint32be* connectionStatus) bool ACIsFailure(betype<nnResult>* r)
{ {
return NN_RESULT_IS_FAILURE(*r) ? 1 : 0;
}
*connectionStatus = 0; // 0 means connected? nnResult ACGetConnectStatus(betype<AC_STATUS>* connectionStatus)
{
return GetConnectStatus(connectionStatus);
}
return NN_RESULT_SUCCESS; nnResult ACGetStatus(betype<AC_STATUS>* connectionStatus)
{
return GetStatus(connectionStatus);
}
nnResult ACConnectAsync()
{
return ConnectAsync();
}
nnResult ACIsApplicationConnected(uint32be* connectedU32)
{
uint8be connected = 0;
nnResult r = IsApplicationConnected(&connected);
*connectedU32 = connected; // convert to uint32
return r;
} }
void load() void load()
{ {
cafeExportRegisterFunc(Initialize, "nn_ac", "Initialize__Q2_2nn2acFv", LogType::Placeholder);
cafeExportRegisterFunc(Connect, "nn_ac", "Connect__Q2_2nn2acFv", LogType::Placeholder);
cafeExportRegisterFunc(ConnectAsync, "nn_ac", "ConnectAsync__Q2_2nn2acFv", LogType::Placeholder);
cafeExportRegisterFunc(GetConnectResult, "nn_ac", "GetConnectResult__Q2_2nn2acFPQ2_2nn6Result", LogType::Placeholder);
cafeExportRegisterFunc(GetLastErrorCode, "nn_ac", "GetLastErrorCode__Q2_2nn2acFPUi", LogType::Placeholder);
cafeExportRegisterFunc(GetConnectStatus, "nn_ac", "GetConnectStatus__Q2_2nn2acFPQ3_2nn2ac6Status", LogType::Placeholder);
cafeExportRegisterFunc(GetStatus, "nn_ac", "GetStatus__Q2_2nn2acFPQ3_2nn2ac6Status", LogType::Placeholder);
cafeExportRegisterFunc(IsApplicationConnected, "nn_ac", "IsApplicationConnected__Q2_2nn2acFPb", LogType::Placeholder);
// AC also offers C-style wrappers
cafeExportRegister("nn_ac", ACInitialize, LogType::Placeholder);
cafeExportRegister("nn_ac", ACIsSuccess, LogType::Placeholder); cafeExportRegister("nn_ac", ACIsSuccess, LogType::Placeholder);
cafeExportRegister("nn_ac", ACIsFailure, LogType::Placeholder);
cafeExportRegister("nn_ac", ACGetConnectStatus, LogType::Placeholder); cafeExportRegister("nn_ac", ACGetConnectStatus, LogType::Placeholder);
cafeExportRegister("nn_ac", ACGetStatus, LogType::Placeholder);
cafeExportRegister("nn_ac", ACConnectAsync, LogType::Placeholder);
cafeExportRegister("nn_ac", ACIsApplicationConnected, LogType::Placeholder);
} }
} }
void nnAc_load() void nnAc_load()
{ {
osLib_addFunction("nn_ac", "Connect__Q2_2nn2acFv", nn_acExport_Connect);
osLib_addFunction("nn_ac", "ConnectAsync__Q2_2nn2acFv", nn_acExport_ConnectAsync);
osLib_addFunction("nn_ac", "IsApplicationConnected__Q2_2nn2acFPb", nn_acExport_IsApplicationConnected);
osLib_addFunction("nn_ac", "GetConnectStatus__Q2_2nn2acFPQ3_2nn2ac6Status", nn_acExport_GetConnectStatus);
osLib_addFunction("nn_ac", "GetConnectResult__Q2_2nn2acFPQ2_2nn6Result", nn_acExport_GetConnectResult);
osLib_addFunction("nn_ac", "GetLastErrorCode__Q2_2nn2acFPUi", nn_acExport_GetLastErrorCode);
osLib_addFunction("nn_ac", "GetStatus__Q2_2nn2acFPQ3_2nn2ac6Status", nn_acExport_GetStatus);
osLib_addFunction("nn_ac", "GetAssignedAddress__Q2_2nn2acFPUl", nnAcExport_GetAssignedAddress); osLib_addFunction("nn_ac", "GetAssignedAddress__Q2_2nn2acFPUl", nnAcExport_GetAssignedAddress);
osLib_addFunction("nn_ac", "GetAssignedSubnet__Q2_2nn2acFPUl", nnAcExport_GetAssignedSubnet); osLib_addFunction("nn_ac", "GetAssignedSubnet__Q2_2nn2acFPUl", nnAcExport_GetAssignedSubnet);