nsysnet: Implement inet_ntop

This commit is contained in:
Exzap 2023-06-15 22:36:25 +02:00
parent 0bead50065
commit 7886b594a2
5 changed files with 125 additions and 72 deletions

View File

@ -1581,7 +1581,7 @@ namespace coreinit
return __FSProcessAsyncResult(fsClient, fsCmdBlock, fsAsyncRet, errorMask); return __FSProcessAsyncResult(fsClient, fsCmdBlock, fsAsyncRet, errorMask);
} }
FSA_RESULT __FSPrepareCmd_MakeDir(iosu::fsa::FSAShimBuffer* fsaShimBuffer, IOSDevHandle devHandle, const uint8* path, uint32 uknVal660) FSA_RESULT __FSPrepareCmd_MakeDir(iosu::fsa::FSAShimBuffer* fsaShimBuffer, IOSDevHandle devHandle, const char* path, uint32 uknVal660)
{ {
if (fsaShimBuffer == NULL) if (fsaShimBuffer == NULL)
return FSA_RESULT::INVALID_BUFFER; return FSA_RESULT::INVALID_BUFFER;
@ -1608,7 +1608,7 @@ namespace coreinit
return FSA_RESULT::OK; return FSA_RESULT::OK;
} }
sint32 FSMakeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const uint8* dirPath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams) sint32 FSMakeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const char* dirPath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams)
{ {
// used by titles: XCX (via SAVEMakeDirAsync) // used by titles: XCX (via SAVEMakeDirAsync)
_FSCmdIntro(); _FSCmdIntro();
@ -1625,7 +1625,7 @@ namespace coreinit
return (FSStatus)FS_RESULT::SUCCESS; return (FSStatus)FS_RESULT::SUCCESS;
} }
sint32 FSMakeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const uint8* path, uint32 errorMask) sint32 FSMakeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const char* path, uint32 errorMask)
{ {
StackAllocator<FSAsyncParamsNew_t> asyncParams; StackAllocator<FSAsyncParamsNew_t> asyncParams;
__FSAsyncToSyncInit(fsClient, fsCmdBlock, asyncParams); __FSAsyncToSyncInit(fsClient, fsCmdBlock, asyncParams);
@ -2092,7 +2092,7 @@ namespace coreinit
return result; return result;
} }
FSA_RESULT FSAMakeDir(FSAClientHandle client, const uint8* path, uint32 uknVal660) FSA_RESULT FSAMakeDir(FSAClientHandle client, const char* path, uint32 uknVal660)
{ {
if (!FSAShimCheckClientHandle(client)) if (!FSAShimCheckClientHandle(client))
return FSA_RESULT::INVALID_CLIENT_HANDLE; return FSA_RESULT::INVALID_CLIENT_HANDLE;

View File

@ -286,8 +286,8 @@ namespace coreinit
sint32 FSRename(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* srcPath, char* dstPath, uint32 errorMask); sint32 FSRename(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* srcPath, char* dstPath, uint32 errorMask);
sint32 FSRemoveAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint8* filePath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams); sint32 FSRemoveAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint8* filePath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams);
sint32 FSRemove(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint8* filePath, uint32 errorMask); sint32 FSRemove(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint8* filePath, uint32 errorMask);
sint32 FSMakeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const uint8* dirPath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams); sint32 FSMakeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const char* dirPath, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams);
sint32 FSMakeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const uint8* path, uint32 errorMask); sint32 FSMakeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, const char* path, uint32 errorMask);
sint32 FSChangeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* path, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams); sint32 FSChangeDirAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* path, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams);
sint32 FSChangeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* path, uint32 errorMask); sint32 FSChangeDir(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* path, uint32 errorMask);
sint32 FSGetCwdAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* dirPathOut, sint32 dirPathMaxLen, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams); sint32 FSGetCwdAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, char* dirPathOut, sint32 dirPathMaxLen, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams);

View File

@ -346,7 +346,7 @@ namespace save
{ {
char fullPath[SAVE_MAX_PATH_SIZE]; char fullPath[SAVE_MAX_PATH_SIZE];
if (GetAbsoluteFullPath(persistentId, path, fullPath)) if (GetAbsoluteFullPath(persistentId, path, fullPath))
result = coreinit::FSMakeDirAsync(client, block, (uint8*)fullPath, errHandling, (FSAsyncParamsNew_t*)asyncParams); result = coreinit::FSMakeDirAsync(client, block, fullPath, errHandling, (FSAsyncParamsNew_t*)asyncParams);
} }
else else
result = (FSStatus)FS_RESULT::NOT_FOUND; result = (FSStatus)FS_RESULT::NOT_FOUND;

View File

@ -55,6 +55,7 @@
#define WU_SO_ECONNRESET 0x0008 #define WU_SO_ECONNRESET 0x0008
#define WU_SO_EINVAL 0x000B #define WU_SO_EINVAL 0x000B
#define WU_SO_EINPROGRESS 0x0016 #define WU_SO_EINPROGRESS 0x0016
#define WU_SO_EAFNOSUPPORT 0x0021
#define WU_SO_ESHUTDOWN 0x000F #define WU_SO_ESHUTDOWN 0x000F
@ -90,15 +91,12 @@ uint32* __gh_errno_ptr()
void _setSockError(sint32 errCode) void _setSockError(sint32 errCode)
{ {
// todo -> Call __gh_errno_ptr and then write 32bit error code *(uint32be*)__gh_errno_ptr() = (uint32)errCode;
*(uint32*)__gh_errno_ptr() = _swapEndianU32(errCode);
//coreinitData->ghsErrno = _swapEndianU32(errCode);
} }
sint32 _getSockError() sint32 _getSockError()
{ {
return (sint32)_swapEndianU32(*(uint32*)__gh_errno_ptr()); return (sint32)*(uint32be*)__gh_errno_ptr();
//return (sint32)_swapEndianU32(coreinitData->ghsErrno);
} }
// error translation modes for _translateError // error translation modes for _translateError
@ -644,6 +642,16 @@ void nsysnetExport_getsockopt(PPCInterpreter_t* hCPU)
*(uint32*)optval = _swapEndianU32(optvalLE); *(uint32*)optval = _swapEndianU32(optvalLE);
// used by Lost Reavers after some loading screens // used by Lost Reavers after some loading screens
} }
else if (optname == WU_SO_NONBLOCK)
{
if (memory_readU32(optlenMPTR) != 4)
assert_dbg();
int optvalLE = 0;
socklen_t optlenLE = 4;
memory_writeU32(optlenMPTR, 4);
*(uint32*)optval = _swapEndianU32(vs->isNonBlocking ? 1 : 0);
r = WU_SO_SUCCESS;
}
else else
{ {
cemu_assert_debug(false); cemu_assert_debug(false);
@ -712,13 +720,10 @@ void nsysnetExport_inet_pton(PPCInterpreter_t* hCPU)
invalidIp = true; invalidIp = true;
if (d3 < 0 || d3 > 255) if (d3 < 0 || d3 > 255)
invalidIp = true; invalidIp = true;
#ifdef CEMU_DEBUG_ASSERT
if (invalidIp)
assert_dbg();
#endif
if (invalidIp) if (invalidIp)
{ {
cemuLog_log(LogType::Socket, "inet_pton({}, \"{}\", 0x{:08x}) -> Invalid ip", af, ip, hCPU->gpr[5]); cemuLog_log(LogType::Socket, "inet_pton({}, \"{}\", 0x{:08x}) -> Invalid ip", af, ip, hCPU->gpr[5]);
_setSockError(WU_SO_EAFNOSUPPORT);
osLib_returnFromFunction(hCPU, 0); // 0 -> invalid address osLib_returnFromFunction(hCPU, 0); // 0 -> invalid address
return; return;
} }
@ -729,6 +734,32 @@ void nsysnetExport_inet_pton(PPCInterpreter_t* hCPU)
osLib_returnFromFunction(hCPU, 1); // 1 -> success osLib_returnFromFunction(hCPU, 1); // 1 -> success
} }
namespace nsysnet
{
const char* inet_ntop(sint32 af, const void* src, char* dst, uint32 size)
{
if( af != WU_AF_INET)
{
// set error
_setSockError(WU_SO_EAFNOSUPPORT);
return nullptr;
}
const uint8* ip = (const uint8*)src;
char buf[32];
sprintf(buf, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
size_t bufLen = strlen(buf);
if( (bufLen+1) > size )
{
// set error
_setSockError(WU_SO_EAFNOSUPPORT);
return nullptr;
}
strcpy(dst, buf);
cemuLog_log(LogType::Socket, "inet_ntop -> {}", buf);
return dst;
}
}
MEMPTR<char> _ntoa_tempString = nullptr; MEMPTR<char> _ntoa_tempString = nullptr;
void nsysnetExport_inet_ntoa(PPCInterpreter_t* hCPU) void nsysnetExport_inet_ntoa(PPCInterpreter_t* hCPU)
@ -2122,13 +2153,22 @@ namespace nsysnet
} }
namespace nsysnet
{
void Initialize()
{
cafeExportRegister("nsysnet", inet_ntop, LogType::Socket);
}
}
// register nsysnet functions // register nsysnet functions
void nsysnet_load() void nsysnet_load()
{ {
nsysnet::Initialize();
osLib_addFunction("nsysnet", "socket_lib_init", nsysnetExport_socket_lib_init);
// the below code is the old way of registering API which is deprecated
osLib_addFunction("nsysnet", "socket_lib_init", nsysnetExport_socket_lib_init);
osLib_addFunction("nsysnet", "socket_lib_finish", nsysnetExport_socket_lib_finish); osLib_addFunction("nsysnet", "socket_lib_finish", nsysnetExport_socket_lib_finish);
// socket API // socket API

View File

@ -48,52 +48,57 @@ TextureRelationViewerWindow::TextureRelationViewerWindow(wxFrame& parent)
textureRelationListA->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Courier New"));//wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT)); textureRelationListA->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Courier New"));//wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT));
// add columns // add columns
wxListItem col0; wxListItem colType;
sint32 columnIndex = 0; sint32 columnIndex = 0;
col0.SetId(columnIndex); columnIndex++; colType.SetId(columnIndex); columnIndex++;
col0.SetText("Type"); colType.SetText("Type");
col0.SetWidth(85); colType.SetWidth(85);
textureRelationListA->InsertColumn(columnIndex-1, col0); textureRelationListA->InsertColumn(columnIndex-1, colType);
wxListItem col1; wxListItem colPhysAddr;
col1.SetId(columnIndex); columnIndex++; colPhysAddr.SetId(columnIndex); columnIndex++;
col1.SetText("PhysAddr"); colPhysAddr.SetText("PhysAddr");
col1.SetWidth(80); colPhysAddr.SetWidth(80);
textureRelationListA->InsertColumn(columnIndex-1, col1); textureRelationListA->InsertColumn(columnIndex-1, colPhysAddr);
wxListItem col2; wxListItem colPhysMipAddr;
col2.SetId(columnIndex); columnIndex++; colPhysMipAddr.SetId(columnIndex); columnIndex++;
col2.SetText("Dim"); colPhysMipAddr.SetText("MipPAddr");
col2.SetWidth(80); colPhysMipAddr.SetWidth(80);
textureRelationListA->InsertColumn(columnIndex-1, col2); textureRelationListA->InsertColumn(columnIndex-1, colPhysMipAddr);
wxListItem col3; wxListItem colDim;
col3.SetId(columnIndex); columnIndex++; colDim.SetId(columnIndex); columnIndex++;
col3.SetText("Resolution"); colDim.SetText("Dim");
col3.SetWidth(110); colDim.SetWidth(80);
textureRelationListA->InsertColumn(columnIndex-1, col3); textureRelationListA->InsertColumn(columnIndex-1, colDim);
wxListItem col5; wxListItem colResolution;
col5.SetId(columnIndex); columnIndex++; colResolution.SetId(columnIndex); columnIndex++;
col5.SetText("Format"); colResolution.SetText("Resolution");
col5.SetWidth(70); colResolution.SetWidth(110);
textureRelationListA->InsertColumn(columnIndex-1, col5); textureRelationListA->InsertColumn(columnIndex-1, colResolution);
wxListItem colPriority; wxListItem colFormat;
colPriority.SetId(columnIndex); columnIndex++; colFormat.SetId(columnIndex); columnIndex++;
colPriority.SetText("Pitch"); colFormat.SetText("Format");
colPriority.SetWidth(80); colFormat.SetWidth(70);
textureRelationListA->InsertColumn(columnIndex-1, colPriority); textureRelationListA->InsertColumn(columnIndex-1, colFormat);
wxListItem col6; wxListItem colPitch;
col6.SetId(columnIndex); columnIndex++; colPitch.SetId(columnIndex); columnIndex++;
col6.SetText("Tilemode"); colPitch.SetText("Pitch");
col6.SetWidth(80); colPitch.SetWidth(80);
textureRelationListA->InsertColumn(columnIndex-1, col6); textureRelationListA->InsertColumn(columnIndex-1, colPitch);
wxListItem col7; wxListItem colTilemode;
col7.SetId(columnIndex); columnIndex++; colTilemode.SetId(columnIndex); columnIndex++;
col7.SetText("SliceRange"); colTilemode.SetText("Tilemode");
col7.SetWidth(90); colTilemode.SetWidth(80);
textureRelationListA->InsertColumn(columnIndex-1, col7); textureRelationListA->InsertColumn(columnIndex-1, colTilemode);
wxListItem col8; wxListItem colSliceRange;
col8.SetId(columnIndex); columnIndex++; colSliceRange.SetId(columnIndex); columnIndex++;
col8.SetText("MipRange"); colSliceRange.SetText("SliceRange");
col8.SetWidth(90); colSliceRange.SetWidth(90);
textureRelationListA->InsertColumn(columnIndex-1, col8); textureRelationListA->InsertColumn(columnIndex-1, colSliceRange);
wxListItem colMipRange;
colMipRange.SetId(columnIndex); columnIndex++;
colMipRange.SetText("MipRange");
colMipRange.SetWidth(90);
textureRelationListA->InsertColumn(columnIndex-1, colMipRange);
wxListItem colAge; wxListItem colAge;
colAge.SetId(columnIndex); columnIndex++; colAge.SetId(columnIndex); columnIndex++;
colAge.SetText("Last access"); colAge.SetText("Last access");
@ -186,10 +191,14 @@ void TextureRelationViewerWindow::_setTextureRelationListItemTexture(wxListCtrl*
uiList->InsertItem(item); uiList->InsertItem(item);
sint32 columnIndex = 1; sint32 columnIndex = 1;
// phys address // phys address
sprintf(tempStr, "%08X", texInfo->physAddress); sprintf(tempStr, "%08X", texInfo->physAddress);
uiList->SetItem(rowIndex, columnIndex, tempStr); uiList->SetItem(rowIndex, columnIndex, tempStr);
columnIndex++; columnIndex++;
// phys mip address
sprintf(tempStr, "%08X", texInfo->physMipAddress);
uiList->SetItem(rowIndex, columnIndex, tempStr);
columnIndex++;
// dim // dim
if (texInfo->dim == Latte::E_DIM::DIM_2D) if (texInfo->dim == Latte::E_DIM::DIM_2D)
strcpy(tempStr, "2D"); strcpy(tempStr, "2D");
@ -278,10 +287,14 @@ void TextureRelationViewerWindow::_setTextureRelationListItemView(wxListCtrl* ui
uiList->InsertItem(item); uiList->InsertItem(item);
//uiList->SetItemPtrData(item, (wxUIntPtr)viewInfo); //uiList->SetItemPtrData(item, (wxUIntPtr)viewInfo);
sint32 columnIndex = 1; sint32 columnIndex = 1;
// phys address // phys address
sprintf(tempStr, ""); sprintf(tempStr, "");
uiList->SetItem(rowIndex, columnIndex, tempStr); uiList->SetItem(rowIndex, columnIndex, tempStr);
columnIndex++; columnIndex++;
// phys mip address
sprintf(tempStr, "");
uiList->SetItem(rowIndex, columnIndex, tempStr);
columnIndex++;
// dim // dim
if (viewInfo->dim == Latte::E_DIM::DIM_2D) if (viewInfo->dim == Latte::E_DIM::DIM_2D)
strcpy(tempStr, "2D"); strcpy(tempStr, "2D");