Skip to content

Commit

Permalink
sceNpTrophy: Add LV2 sleep, mimicking VSH waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Aug 10, 2022
1 parent 297c40f commit 18bae5c
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,10 @@ error_code sceNpTrophyAbortHandle(u32 handle)
return CELL_OK;
}

error_code sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunicationId> commId, vm::cptr<SceNpCommunicationSignature> commSign, u64 options)
error_code sceNpTrophyCreateContext(ppu_thread& ppu, vm::ptr<u32> context, vm::cptr<SceNpCommunicationId> commId, vm::cptr<SceNpCommunicationSignature> commSign, u64 options)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyCreateContext(context=*0x%x, commId=*0x%x, commSign=*0x%x, options=0x%llx)", context, commId, commSign, options);

if (!commSign)
Expand Down Expand Up @@ -447,6 +449,8 @@ error_code sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunic
return SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID;
}

lv2_obj::sleep(ppu);

// NOTE: commId->term is unused in our code (at least until someone finds out if we need to account for it)

// generate trophy context name, limited to 9 characters
Expand Down Expand Up @@ -725,8 +729,10 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle,
return CELL_OK;
}

error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64> reqspace, u64 options)
error_code sceNpTrophyGetRequiredDiskSpace(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<u64> reqspace, u64 options)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options);

if (!reqspace)
Expand Down Expand Up @@ -755,6 +761,8 @@ error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64>
return error;
}

lv2_obj::sleep(ppu);

u64 space = 0;

if (!fs::is_dir(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name)))
Expand Down Expand Up @@ -798,8 +806,10 @@ error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64>
return CELL_OK;
}

error_code sceNpTrophySetSoundLevel(u32 context, u32 handle, u32 level, u64 options)
error_code sceNpTrophySetSoundLevel(ppu_thread& ppu, u32 context, u32 handle, u32 level, u64 options)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.todo("sceNpTrophySetSoundLevel(context=0x%x, handle=0x%x, level=%d, options=0x%llx)", context, handle, level, options);

if (level > 100 || level < 20)
Expand Down Expand Up @@ -828,11 +838,14 @@ error_code sceNpTrophySetSoundLevel(u32 context, u32 handle, u32 level, u64 opti
return error;
}

lv2_obj::sleep(ppu);
return CELL_OK;
}

error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptr<SceNpTrophyGameDetails> details, vm::ptr<SceNpTrophyGameData> data)
error_code sceNpTrophyGetGameInfo(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<SceNpTrophyGameDetails> details, vm::ptr<SceNpTrophyGameData> data)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetGameInfo(context=0x%x, handle=0x%x, details=*0x%x, data=*0x%x)", context, handle, details, data);

auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
Expand Down Expand Up @@ -862,6 +875,8 @@ error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptr<SceNpTrophyGa
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}

lv2_obj::sleep(ppu);

const std::string config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM");

fs::file config(config_path);
Expand Down Expand Up @@ -950,6 +965,8 @@ error_code sceNpTrophyGetLatestTrophies()

error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::ptr<u32> platinumId)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyUnlockTrophy(context=0x%x, handle=0x%x, trophyId=%d, platinumId=*0x%x)", context, handle, trophyId, platinumId);

auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
Expand Down Expand Up @@ -1029,8 +1046,10 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt
return CELL_OK;
}

error_code sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, vm::ptr<SceNpTrophyFlagArray> flags, vm::ptr<u32> count)
error_code sceNpTrophyGetTrophyUnlockState(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<SceNpTrophyFlagArray> flags, vm::ptr<u32> count)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetTrophyUnlockState(context=0x%x, handle=0x%x, flags=*0x%x, count=*0x%x)", context, handle, flags, count);

if (!flags || !count)
Expand All @@ -1054,6 +1073,8 @@ error_code sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, vm::ptr<SceN
return error;
}

lv2_obj::sleep(ppu);

TROPUSRLoader* tropusr = nullptr;
TROPUSRLoader local_tropusr{};

Expand Down Expand Up @@ -1108,9 +1129,10 @@ error_code sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, vm::ptr<SceN
return CELL_OK;
}

error_code sceNpTrophyGetTrophyDetails()
error_code sceNpTrophyGetTrophyDetails(ppu_thread& ppu)
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
lv2_obj::sleep(ppu);
return CELL_OK;
}

Expand Down Expand Up @@ -1225,6 +1247,9 @@ static error_code NpTrophyGetTrophyInfo(const trophy_context_t* ctxt, s32 trophy

error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::ptr<SceNpTrophyDetails> details, vm::ptr<SceNpTrophyData> data)
{
const auto cpu = cpu_thread::get_current();
cpu->state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetTrophyInfo(context=0x%x, handle=0x%x, trophyId=%d, details=*0x%x, data=*0x%x)", context, handle, trophyId, details, data);

if (trophyId < 0 || trophyId > 127) // max 128 trophies
Expand All @@ -1248,10 +1273,11 @@ error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::p
return error;
}

lv2_obj::sleep(*cpu);
return NpTrophyGetTrophyInfo(ctxt, trophyId, details ? details.get_ptr() : nullptr, data ? data.get_ptr() : nullptr);
}

error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> percentage)
error_code sceNpTrophyGetGameProgress(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<s32> percentage)
{
sceNpTrophy.warning("sceNpTrophyGetGameProgress(context=0x%x, handle=0x%x, percentage=*0x%x)", context, handle, percentage);

Expand All @@ -1276,6 +1302,8 @@ error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> perc
return error;
}

lv2_obj::sleep(ppu);

if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
Expand All @@ -1296,8 +1324,10 @@ error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> perc
return CELL_OK;
}

error_code sceNpTrophyGetGameIcon(u32 context, u32 handle, vm::ptr<void> buffer, vm::ptr<u32> size)
error_code sceNpTrophyGetGameIcon(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<void> buffer, vm::ptr<u32> size)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetGameIcon(context=0x%x, handle=0x%x, buffer=*0x%x, size=*0x%x)", context, handle, buffer, size);

auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
Expand All @@ -1321,6 +1351,8 @@ error_code sceNpTrophyGetGameIcon(u32 context, u32 handle, vm::ptr<void> buffer,
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}

lv2_obj::sleep(ppu);

fs::file icon_file(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/ICON0.PNG"));

if (!icon_file)
Expand All @@ -1346,8 +1378,10 @@ error_code sceNpTrophyGetUserInfo()
return CELL_OK;
}

error_code sceNpTrophyGetTrophyIcon(u32 context, u32 handle, s32 trophyId, vm::ptr<void> buffer, vm::ptr<u32> size)
error_code sceNpTrophyGetTrophyIcon(ppu_thread& ppu, u32 context, u32 handle, s32 trophyId, vm::ptr<void> buffer, vm::ptr<u32> size)
{
ppu.state += cpu_flag::wait;

sceNpTrophy.warning("sceNpTrophyGetTrophyIcon(context=0x%x, handle=0x%x, trophyId=%d, buffer=*0x%x, size=*0x%x)", context, handle, trophyId, buffer, size);

auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
Expand All @@ -1371,6 +1405,8 @@ error_code sceNpTrophyGetTrophyIcon(u32 context, u32 handle, s32 trophyId, vm::p
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}

lv2_obj::sleep(ppu);

if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
Expand Down

0 comments on commit 18bae5c

Please sign in to comment.