sceNpTrophyRegisterContext: add read_only check

This commit is contained in:
Megamouse 2022-05-05 18:47:41 +02:00
parent 6c7f49d563
commit 1f745c4588
1 changed files with 9 additions and 3 deletions

View File

@ -36,7 +36,7 @@ struct trophy_context_t
std::string trp_name;
std::unique_ptr<TROPUSRLoader> tropusr;
bool read_only = false; // TODO
bool read_only = false;
};
struct trophy_handle_t
@ -54,7 +54,7 @@ struct sce_np_trophy_manager
atomic_t<bool> is_initialized = false;
// Get context + check handle given
static std::pair<trophy_context_t*, SceNpTrophyError> get_context_ex(u32 context, u32 handle)
static std::pair<trophy_context_t*, SceNpTrophyError> get_context_ex(u32 context, u32 handle, bool test_writeable = false)
{
decltype(get_context_ex(0, 0)) res{};
auto& [ctxt, error] = res;
@ -75,6 +75,12 @@ struct sce_np_trophy_manager
return res;
}
if (test_writeable && ctxt->read_only)
{
error = SCE_NP_TROPHY_ERROR_INVALID_CONTEXT;
return res;
}
if (handle < trophy_handle_t::id_base ||
handle >= trophy_handle_t::id_base + trophy_handle_t::id_count)
{
@ -440,7 +446,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle,
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle, true);
const auto handle_ptr = idm::get<trophy_handle_t>(handle);
if (error)