diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 460d4fccc9..2a5abb8ba4 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -331,7 +331,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr reqspace, u64 options) { - sceNpTrophy.todo("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options); + sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options); if (!reqspace) { @@ -352,12 +352,18 @@ error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE; } - // TODO: This is not accurate. It's just an approximation of the real value - // The real value can be obtained in TRP.cpp: - // m_headers.trp_file_size - sizeof(m_headers) - (m_headers.trp_files_count * m_headers.trp_element_size); - // TODO: eventually this should be set to 0 when trophys are detected as already installed, setting to 0 now causes some games to not call registerContext, which leads to trophys never getting installed - *reqspace = ctxt->trp_stream.size(); + if (!fs::is_dir("/dev_hdd0/home/00000001/trophy/" + ctxt->trp_name)) + { + TRPLoader trp(ctxt->trp_stream); + if (trp.LoadHeader()) + { + *reqspace = trp.GetRequiredSpace(); + return CELL_OK; + } + } + + *reqspace = 0; return CELL_OK; } diff --git a/rpcs3/Loader/TRP.cpp b/rpcs3/Loader/TRP.cpp index fe43740d03..23d81c3067 100644 --- a/rpcs3/Loader/TRP.cpp +++ b/rpcs3/Loader/TRP.cpp @@ -103,6 +103,14 @@ bool TRPLoader::LoadHeader(bool show) return true; } +u64 TRPLoader::GetRequiredSpace() const +{ + const u64 file_size = m_header.trp_file_size; + const u64 file_element_size = u64{1} * m_header.trp_files_count * m_header.trp_element_size; + + return file_size - sizeof(m_header) - file_element_size; +} + bool TRPLoader::ContainsEntry(const char *filename) { for (const TRPEntry& entry : m_entries) diff --git a/rpcs3/Loader/TRP.h b/rpcs3/Loader/TRP.h index 4418e805b0..8df4a7679d 100644 --- a/rpcs3/Loader/TRP.h +++ b/rpcs3/Loader/TRP.h @@ -32,6 +32,7 @@ public: bool Install(const std::string& dest, bool show = false); bool LoadHeader(bool show = false); + u64 GetRequiredSpace() const; bool ContainsEntry(const char *filename); void RemoveEntry(const char *filename);