diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 3e72f1af..e2b7068e 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -107,6 +107,7 @@ void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* c std::qsort(ptr, count, size, qsort_compair); } + void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); @@ -119,6 +120,7 @@ void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::atexit); LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::printf); + LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::vsnprintf); LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand); LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin); diff --git a/src/Emulator/HLE/Libraries/LibC/libc.cpp b/src/Emulator/HLE/Libraries/LibC/libc.cpp index 5da7112e..c5ecb8cf 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.cpp +++ b/src/Emulator/HLE/Libraries/LibC/libc.cpp @@ -12,6 +12,8 @@ PS4_SYSV_ABI int printf(VA_ARGS) { return printf_ctx(&ctx); } +int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); } + PS4_SYSV_ABI void exit(int code) { std::exit(code); } PS4_SYSV_ABI int atexit(void (*func)()) { diff --git a/src/Emulator/HLE/Libraries/LibC/libc.h b/src/Emulator/HLE/Libraries/LibC/libc.h index 365b01c0..2c5412a1 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.h +++ b/src/Emulator/HLE/Libraries/LibC/libc.h @@ -8,6 +8,7 @@ namespace Emulator::HLE::Libraries::LibC { // HLE functions PS4_SYSV_ABI int printf(VA_ARGS); +int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg); PS4_SYSV_ABI void exit(int code); PS4_SYSV_ABI int atexit(void (*func)()); int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n); diff --git a/src/Emulator/HLE/Libraries/LibC/printf.h b/src/Emulator/HLE/Libraries/LibC/printf.h index 1ed0cd84..9a1a33e7 100644 --- a/src/Emulator/HLE/Libraries/LibC/printf.h +++ b/src/Emulator/HLE/Libraries/LibC/printf.h @@ -56,7 +56,7 @@ #include #include #include - +#include #include "va_ctx.h" namespace Emulator::HLE::Libraries::LibC { @@ -693,4 +693,10 @@ static int printf_ctx(VaCtx* ctx) { return result; } +static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) { + char buffer[n]; + int result = _vsnprintf(_out_buffer, buffer, format, arg); + std::strcpy(s, buffer); + return result; +} } // namespace Emulator::HLE::Libraries::LibC