Skip to content

Commit

Permalink
Merge pull request #19972 from Nemoumbra/scenet_lib
Browse files Browse the repository at this point in the history
Adding sceNet_lib
  • Loading branch information
hrydgard authored Feb 12, 2025
2 parents 29a0835 + c5d69d5 commit dc3e929
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/HLE/sceMpeg.h
Core/HLE/sceNet.cpp
Core/HLE/sceNet.h
Core/HLE/sceNet_lib.cpp
Core/HLE/sceNet_lib.h
Core/HLE/sceNetAdhoc.cpp
Core/HLE/sceNetAdhoc.h
Core/HLE/sceNetAdhocMatching.cpp
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
<ClCompile Include="HLE\sceKernelVTimer.cpp" />
<ClCompile Include="HLE\sceMpeg.cpp" />
<ClCompile Include="HLE\sceNet.cpp" />
<ClCompile Include="HLE\sceNet_lib.cpp" />
<ClCompile Include="HLE\sceNetAdhoc.cpp" />
<ClCompile Include="HLE\sceNetAdhocMatching.cpp" />
<ClCompile Include="HLE\sceNp.cpp" />
Expand Down Expand Up @@ -1303,6 +1304,7 @@
<ClInclude Include="HLE\sceKernelTime.h" />
<ClInclude Include="HLE\sceMpeg.h" />
<ClInclude Include="HLE\sceNet.h" />
<ClInclude Include="HLE\sceNet_lib.h" />
<ClInclude Include="HLE\sceNetAdhoc.h" />
<ClInclude Include="HLE\sceNetAdhocMatching.h" />
<ClInclude Include="HLE\sceNp.h" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
<ClCompile Include="HLE\sceNet.cpp">
<Filter>HLE\Libraries</Filter>
</ClCompile>
<ClCompile Include="HLE\sceNet_lib.cpp">
<Filter>HLE\Libraries</Filter>
</ClCompile>
<ClCompile Include="HLE\scePower.cpp">
<Filter>HLE\Libraries</Filter>
</ClCompile>
Expand Down Expand Up @@ -1503,6 +1506,9 @@
<ClInclude Include="HLE\sceNet.h">
<Filter>HLE\Libraries</Filter>
</ClInclude>
<ClInclude Include="HLE\sceNet_lib.h">
<Filter>HLE\Libraries</Filter>
</ClInclude>
<ClInclude Include="HLE\scePower.h">
<Filter>HLE\Libraries</Filter>
</ClInclude>
Expand Down
35 changes: 35 additions & 0 deletions Core/HLE/FunctionWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ template<int func(const char *, u32, int)> void WrapI_CUI() {
RETURN(retval);
}

template<u32 func(const char *, u32, int)> void WrapU_CUI() {
u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
RETURN(retval);
}

template<int func(int, const char *, int, u32)> void WrapI_ICIU() {
int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
RETURN(retval);
Expand Down Expand Up @@ -864,3 +869,33 @@ template<int func(void *, u32, int)> void WrapI_VUI(){
u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1), PARAM(2));
RETURN(retval);
}

template<u32 func(void *, u32, u32)> void WrapU_VUU() {
u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1), PARAM(2));
RETURN(retval);
}

template<u32 func(void *, const char *)> void WrapU_VC() {
u32 retval = func(Memory::GetPointerWrite(PARAM(0)), Memory::GetCharPointer(PARAM(1)));
RETURN(retval);
}

template<int func(const char *, const char*, u32)> void WrapI_CCU() {
int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2));
RETURN(retval);
}

template<int func(const char *, const char*)> void WrapI_CC() {
int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)));
RETURN(retval);
}

template<u32 func(void *, const char *, u32)> void WrapU_VCU() {
u32 retval = func(Memory::GetPointerWrite(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2));
RETURN(retval);
}

template<u32 func(void *, int)> void WrapU_VI() {
u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1));
RETURN(retval);
}
2 changes: 2 additions & 0 deletions Core/HLE/HLETables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "sceNetInet.h"
#include "sceNetResolver.h"
// #include "sceNp2.h"
#include "sceNet_lib.h"

#define N(s) s

Expand Down Expand Up @@ -319,6 +320,7 @@ void RegisterAllModules() {
Register_mp4msv();
Register_InterruptManagerForKernel();
Register_sceSircs();
Register_sceNet_lib();
// Not ready to enable this due to apparent softlocks in Patapon 3.
// Register_sceNpMatching2();

Expand Down
137 changes: 137 additions & 0 deletions Core/HLE/sceNet_lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (c) 2025- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.


#include "Core/HLE/sceNet_lib.h"

#include "Core/HLE/FunctionWrappers.h"
#include "Core/HLE/HLE.h"

#include <cstring>


// This is one of the firmware modules (pspnet.prx), the official PSP games can't call these funcs


u32 sceNetStrtoul(const char *str, u32 strEndAddrPtr, int base) {
// Redirect that to libc
char* str_end = nullptr;
u32 res = std::strtoul(str, &str_end, base);

// Remap the pointer
u32 psp_str_end = Memory::GetAddressFromHostPointer(str_end);
Memory::Write_U32(psp_str_end, strEndAddrPtr);

return hleLogDebug(Log::sceNet, res);
}

u32 sceNetMemmove(void* dest, u32 srcPtr, u32 count) {
// Redirect that to libc
void* host_ptr = std::memmove(
dest, Memory::GetPointer(srcPtr), count
);

// Remap the pointer
u32 res = Memory::GetAddressFromHostPointer(host_ptr);
return hleLogDebug(Log::sceNet, res);
}

u32 sceNetStrcpy(void* dest, const char *src) {
// Redirect that to libc
char* host_ptr = std::strcpy(static_cast<char*>(dest), src);

// Remap the pointer
u32 res = Memory::GetAddressFromHostPointer(host_ptr);
return hleLogDebug(Log::sceNet, res);
}

s32 sceNetStrncmp(const char *lhs, const char *rhs, u32 count) {
// Redirect that to libc
s32 res = std::strncmp(lhs, rhs, count);

return hleLogDebug(Log::sceNet, res);
}

s32 sceNetStrcasecmp(const char *lhs, const char *rhs) {
// Redirect that to eh... what is this, a libc extension?
s32 res = strcasecmp(lhs, rhs);

return hleLogDebug(Log::sceNet, res);
}

s32 sceNetStrcmp(const char *lhs, const char *rhs) {
// Redirect that to libc
s32 res = std::strcmp(lhs, rhs);

return hleLogDebug(Log::sceNet, res);
}

u32 sceNetStrncpy(void *dest, const char *src, u32 count) {
// Redirect that to libc
char* host_ptr = std::strncpy(static_cast<char*>(dest), src, count);

// Remap the pointer
u32 res = Memory::GetAddressFromHostPointer(host_ptr);
return hleLogDebug(Log::sceNet, res);
}

u32 sceNetStrchr(void *str, int ch) {
// For some reason it doesn't build for me if I make 'str' a const char *
// At the same time I can't make it char *, because then WrapU_CI won't work

// Redirect that to libc
char* host_ptr = std::strchr(static_cast<char*>(str), ch);

// Remap the pointer
u32 res = Memory::GetAddressFromHostPointer(host_ptr);
return hleLogDebug(Log::sceNet, res);
}

u32 sceNetStrlen(const char* str) {
// Redirect that to libc
u32 res = std::strlen(str);

return hleLogDebug(Log::sceNet, res);
}

s32 sceNetMemcmp(u32 lhsPtr, u32 rhsPtr, u32 count) {
// Redirect that to libc
s32 res = std::memcmp(Memory::GetPointer(lhsPtr), Memory::GetPointer(rhsPtr), count);

return hleLogDebug(Log::sceNet, res);
}


const HLEFunction sceNet_lib[] = {
{0X1858883D, nullptr, "sceNetRand", 'i', "" },
{0X2A73ADDC, &WrapU_CUI<sceNetStrtoul>, "sceNetStrtoul", 'i', "sxi" },
{0X4753D878, &WrapU_VUU<sceNetMemmove>, "sceNetMemmove", 'i', "xxx" },
{0X80C9F02A, &WrapU_VC<sceNetStrcpy>, "sceNetStrcpy", 'i', "xs" },
{0X94DCA9F0, &WrapI_CCU<sceNetStrncmp>, "sceNetStrncmp", 'i', "ssx" },
{0X9CFBC7E3, &WrapI_CC<sceNetStrcasecmp>, "sceNetStrcasecmp", 'i', "ss" },
{0XA0F16ABD, &WrapI_CC<sceNetStrcmp>, "sceNetStrcmp", 'i', "ss" },
{0XB5CE388A, &WrapU_VCU<sceNetStrncpy>, "sceNetStrncpy", 'i', "xsx" },
{0XBCBE14CF, &WrapU_VI<sceNetStrchr>, "sceNetStrchr", 'i', "si" },
{0XCF705E46, nullptr, "sceNetSprintf", 'i', "" },
{0XD8722983, &WrapU_C<sceNetStrlen>, "sceNetStrlen", 'i', "s" },
{0XE0A81C7C, &WrapI_UUU<sceNetMemcmp>, "sceNetMemcmp", 'i', "xxx" },
};


void Register_sceNet_lib() {
RegisterModule("sceNet_lib", ARRAY_SIZE(sceNet_lib), sceNet_lib);
}
19 changes: 19 additions & 0 deletions Core/HLE/sceNet_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2025- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.


void Register_sceNet_lib();
2 changes: 2 additions & 0 deletions UWP/CoreUWP/CoreUWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<ClInclude Include="..\..\Core\HLE\sceMpeg.h" />
<ClInclude Include="..\..\Core\HLE\sceMt19937.h" />
<ClInclude Include="..\..\Core\HLE\sceNet.h" />
<ClInclude Include="..\..\Core\HLE\sceNet_lib.h" />
<ClInclude Include="..\..\Core\HLE\sceNetAdhoc.h" />
<ClInclude Include="..\..\Core\HLE\sceNetAdhocMatching.h" />
<ClInclude Include="..\..\Core\HLE\sceNp.h" />
Expand Down Expand Up @@ -493,6 +494,7 @@
<ClCompile Include="..\..\Core\HLE\sceMpeg.cpp" />
<ClCompile Include="..\..\Core\HLE\sceMt19937.cpp" />
<ClCompile Include="..\..\Core\HLE\sceNet.cpp" />
<ClCompile Include="..\..\Core\HLE\sceNet_lib.cpp" />
<ClCompile Include="..\..\Core\HLE\sceNetAdhoc.cpp" />
<ClCompile Include="..\..\Core\HLE\sceNetAdhocMatching.cpp" />
<ClCompile Include="..\..\Core\HLE\sceNp.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions UWP/CoreUWP/CoreUWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@
<ClCompile Include="..\..\Core\HLE\sceNet.cpp">
<Filter>HLE</Filter>
</ClCompile>
<ClCompile Include="..\..\Core\HLE\sceNet_lib.cpp">
<Filter>HLE</Filter>
</ClCompile>
<ClCompile Include="..\..\Core\HLE\sceNetAdhoc.cpp">
<Filter>HLE</Filter>
</ClCompile>
Expand Down Expand Up @@ -1546,6 +1549,9 @@
<ClInclude Include="..\..\Core\HLE\sceNet.h">
<Filter>HLE</Filter>
</ClInclude>
<ClInclude Include="..\..\Core\HLE\sceNet_lib.h">
<Filter>HLE</Filter>
</ClInclude>
<ClInclude Include="..\..\Core\HLE\sceNetAdhoc.h">
<Filter>HLE</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/HLE/sceMp4.cpp \
$(SRC)/Core/HLE/sceMp3.cpp \
$(SRC)/Core/HLE/sceNet.cpp \
$(SRC)/Core/HLE/sceNet_lib.cpp \
$(SRC)/Core/HLE/proAdhoc.cpp \
$(SRC)/Core/HLE/proAdhocServer.cpp \
$(SRC)/Core/HLE/sceNetAdhoc.cpp \
Expand Down
1 change: 1 addition & 0 deletions libretro/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ SOURCES_CXX += \
$(COREDIR)/HLE/sceKernelVTimer.cpp \
$(COREDIR)/HLE/sceMpeg.cpp \
$(COREDIR)/HLE/sceNet.cpp \
$(COREDIR)/HLE/sceNet_lib.cpp \
$(COREDIR)/HLE/sceNetAdhoc.cpp \
$(COREDIR)/HLE/sceNetAdhocMatching.cpp \
$(COREDIR)/HLE/sceNetApctl.cpp \
Expand Down

0 comments on commit dc3e929

Please sign in to comment.