diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 67b2d4c3e9..1880d2beff 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -575,12 +575,28 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, } }; - // TODO: Callbacks - // From RE-ing a game's state machine, it seems the possible order is one of the following: - // * Install (Not installed) - Setup - Progress * ? - Finalize - Complete - Installed - // * Reinstall (Corrupted) - Setup - Progress * ? - Finalize - Complete - Installed - // * Update (Required update) - Setup - Progress * ? - Finalize - Complete - Installed - // * Installed + // open trophy pack file + std::string trp_path = vfs::get(Emu.GetDir() + "TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP"); + fs::file stream(trp_path); + + if (!stream && Emu.GetCat() == "GD") + { + sceNpTrophy.warning("sceNpTrophyRegisterContext failed to open trophy file from boot path: '%s' (%s)", trp_path, fs::g_tls_error); + trp_path = vfs::get("/dev_bdvd/PS3_GAME/TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP"); + stream.open(trp_path); + } + + // check if exists and opened + if (!stream) + { + const std::string msg = fmt::format("Failed to open trophy file: '%s' (%s)", trp_path, fs::g_tls_error); + return {SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, msg}; + } + + // TODO: + // SCE_NP_TROPHY_STATUS_DATA_CORRUPT -> reinstall + // SCE_NP_TROPHY_STATUS_REQUIRES_UPDATE -> reinstall (for example if a patch has updates for the trophy data) + // SCE_NP_TROPHY_STATUS_CHANGES_DETECTED -> reinstall (only possible in dev mode) const std::string trophyPath = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name; const s32 trp_status = fs::is_dir(vfs::get(trophyPath)) ? SCE_NP_TROPHY_STATUS_INSTALLED : SCE_NP_TROPHY_STATUS_NOT_INSTALLED; @@ -589,6 +605,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, sceNpTrophy.notice("sceNpTrophyRegisterContext(): Callback is being called (trp_status=%u)", trp_status); + // "Ask permission" to install the trophy data. // The callback is called once and then if it returns >= 0 the cb is called through events(coming from vsh) that are passed to the CB through cellSysutilCheckCallback if (statusCb(ppu, context, trp_status, 0, 0, arg) < 0) { @@ -628,24 +645,6 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE; } - // open trophy pack file - std::string trp_path = vfs::get(Emu.GetDir() + "TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP"); - fs::file stream(trp_path); - - if (!stream && Emu.GetCat() == "GD") - { - sceNpTrophy.warning("sceNpTrophyRegisterContext failed to open trophy file from boot path: '%s' (%s)", trp_path, fs::g_tls_error); - trp_path = vfs::get("/dev_bdvd/PS3_GAME/TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP"); - stream.open(trp_path); - } - - // check if exists and opened - if (!stream) - { - const std::string msg = fmt::format("Failed to open trophy file: '%s' (%s)", trp_path, fs::g_tls_error); - return {SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, msg}; - } - TRPLoader trp(stream); if (!trp.LoadHeader()) { @@ -725,6 +724,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, { sysutil_register_cb([statusCb, status, context, completed, arg, wkptr](ppu_thread& cb_ppu) -> s32 { + // TODO: it is possible that we need to check the return value here as well. statusCb(cb_ppu, context, status.first, completed, status.second, arg); const auto queued = wkptr.lock();