From cafc2aa9d01e2b89927bfb71f7d144da1167b500 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Mon, 26 Jan 2026 10:37:59 +0100 Subject: [PATCH] Implement sceNpMatching2GetMemoryInfo --- rpcs3/Emu/Cell/Modules/sceNp2.cpp | 12 ++++++++++-- rpcs3/Emu/NP/np_allocator.h | 12 ++++++++++++ rpcs3/Emu/NP/np_handler.cpp | 12 ++++++++++++ rpcs3/Emu/NP/np_handler.h | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sceNp2.cpp b/rpcs3/Emu/Cell/Modules/sceNp2.cpp index b6ad47b846..0c8f97fc2f 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp2.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp2.cpp @@ -616,9 +616,9 @@ error_code sceNpMatching2CreateServerContext( return CELL_OK; } -error_code sceNpMatching2GetMemoryInfo(vm::ptr memInfo) // TODO +error_code sceNpMatching2GetMemoryInfo(vm::ptr memInfo) { - sceNp2.todo("sceNpMatching2GetMemoryInfo(memInfo=*0x%x)", memInfo); + sceNp2.warning("sceNpMatching2GetMemoryInfo(memInfo=*0x%x)", memInfo); auto& nph = g_fxo->get>(); @@ -627,6 +627,14 @@ error_code sceNpMatching2GetMemoryInfo(vm::ptr memInfo return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED; } + if (!memInfo) + { + return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT; + } + + SceNpMatching2MemoryInfo mem_info = nph.get_memory_info(); + *memInfo = mem_info; + return CELL_OK; } diff --git a/rpcs3/Emu/NP/np_allocator.h b/rpcs3/Emu/NP/np_allocator.h index ee8017cb72..76445a4274 100644 --- a/rpcs3/Emu/NP/np_allocator.h +++ b/rpcs3/Emu/NP/np_allocator.h @@ -39,6 +39,11 @@ namespace np m_allocs.clear(); } + std::tuple get_stats() const + { + return {m_size, m_size - m_avail, m_max_usage}; + } + u32 allocate(u32 size) { std::lock_guard lock(m_mutex); @@ -82,6 +87,12 @@ namespace np m_allocs.emplace(last_free, alloc_size); m_avail -= alloc_size; + const u32 usage = m_size - m_avail; + if (usage > m_max_usage) + { + m_max_usage = usage; + } + memset((static_cast(m_pool.get_ptr())) + last_free, 0, alloc_size); np_mem_allocator.trace("Allocation off:%d size:%d psize:%d, pavail:%d", last_free, alloc_size, m_size, m_avail); @@ -121,6 +132,7 @@ namespace np vm::ptr m_pool{}; u32 m_size = 0; u32 m_avail = 0; + u32 m_max_usage = 0; std::map m_allocs{}; // offset/size }; } // namespace np diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index c55c16afec..777301abbb 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -1764,4 +1764,16 @@ namespace np } } + SceNpMatching2MemoryInfo np_handler::get_memory_info() const + { + auto [m_size, m_usage, m_max_usage] = np_memory.get_stats(); + + SceNpMatching2MemoryInfo mem_info{}; + mem_info.totalMemSize = m_size; + mem_info.curMemUsage = m_usage; + mem_info.maxMemUsage = m_max_usage; + + return mem_info; + } + } // namespace np diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index a5f8014538..51d510b854 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -262,6 +262,7 @@ namespace np u32 add_players_to_history(const SceNpId* npids, const char* description, u32 count); u32 get_players_history_count(u32 options); bool get_player_history_entry(u32 options, u32 index, SceNpId* npid); + SceNpMatching2MemoryInfo get_memory_info() const; error_code abort_request(u32 req_id); // For signaling