Skip to content

Commit

Permalink
Fix saving and some more logging
Browse files Browse the repository at this point in the history
Fixes Shin Hayarigami (BLJS10279).
  • Loading branch information
tambry committed Jul 13, 2015
1 parent 3896c39 commit 66cf864
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
45 changes: 37 additions & 8 deletions rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ never_inline s32 savedata_op(

if (!lock)
{
cellSysutil.Error("savedata_op(): failed to lock the mutex.");
return CELL_SAVEDATA_ERROR_BUSY;
}

Expand Down Expand Up @@ -191,6 +192,7 @@ never_inline s32 savedata_op(

if (result->result < 0)
{
cellSysutil.Error("savedata_op(): funcList returned result < 0.");
return CELL_SAVEDATA_ERROR_CBRESULT;
}

Expand Down Expand Up @@ -302,6 +304,7 @@ never_inline s32 savedata_op(

if (result->result < 0)
{
cellSysutil.Error("savedata_op(): funcFixed returned result < 0.");
return CELL_SAVEDATA_ERROR_CBRESULT;
}

Expand Down Expand Up @@ -343,10 +346,39 @@ never_inline s32 savedata_op(

PSFLoader psf;

// Create save directory if necessary
if (save_entry.isNew)
{
if (!Emu.GetVFS().ExistsDir(dir_path) && !Emu.GetVFS().CreateDir(dir_path))
{
// Let's ignore this error for now
}
else
{
std::string rSfo_path = "/dev_hdd0/game/" + save_entry.dirName.substr(0, 9) + "/PS3_GAME/PARAM.SFO"; // The real SFO path
if (!Emu.GetVFS().ExistsFile(rSfo_path))
{
rSfo_path = "/dev_hdd0/game/" + save_entry.dirName.substr(0, 9) + "/PARAM.SFO";
}

vfsFile rSfo(rSfo_path);
PSFLoader rPsf(rSfo);
psf.Clear();
psf.SetInteger("ATTRIBUTE", rPsf.GetInteger("ATTRIBUTE"));
psf.SetString("TITLE", rPsf.GetString("TITLE"));
psf.SetString("SUB_TITLE", rPsf.GetString("SUB_TITLE"));
psf.SetString("DETAIL", rPsf.GetString("DETAIL"));
psf.SetString("SAVEDATA_LIST_PARAM", rPsf.GetString("SAVEDATA_LIST_PARAM"));
}
}

// Load PARAM.SFO
{
vfsFile f(sfo_path);
psf.Load(f);
if (!save_entry.isNew)
{
vfsFile f(sfo_path);
psf.Load(f);
}
}

// Get save stats
Expand Down Expand Up @@ -436,6 +468,7 @@ never_inline s32 savedata_op(

if (result->result < 0)
{
cellSysutil.Error("savedata_op(): funcStat returned result < 0.");
return CELL_SAVEDATA_ERROR_CBRESULT;
}

Expand Down Expand Up @@ -485,12 +518,6 @@ never_inline s32 savedata_op(
}
}

// Create save directory if necessary
if (save_entry.isNew && !Emu.GetVFS().CreateDir(dir_path))
{
// Let's ignore this error for now
}

// Enter the loop where the save files are read/created/deleted
vm::stackvar<CellSaveDataFileGet> fileGet(CPU);
vm::stackvar<CellSaveDataFileSet> fileSet(CPU);
Expand All @@ -504,6 +531,7 @@ never_inline s32 savedata_op(

if (result->result < 0)
{
cellSysutil.Error("savedata_op(): funcFile returned result < 0.");
return CELL_SAVEDATA_ERROR_CBRESULT;
}

Expand Down Expand Up @@ -605,6 +633,7 @@ never_inline s32 savedata_op(
// Write PARAM.SFO
if (psf)
{
cellSysutil.Error("psf: true");
vfsFile f(sfo_path, vfsWriteNew);
psf.Save(f);
}
Expand Down
18 changes: 2 additions & 16 deletions rpcs3/Emu/SysCalls/Modules/sceNp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,7 @@ s32 sceNpDrmGetTimelimit(vm::ptr<const char> path, vm::ptr<u64> time_remain)

s32 sceNpDrmProcessExitSpawn(vm::cptr<char> path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags)
{
sceNp.Warning("sceNpDrmProcessExitSpawn()");
sceNp.Warning("path: %s", path.get_ptr());
sceNp.Warning("argv: 0x%x", argv_addr);
sceNp.Warning("envp: 0x%x", envp_addr);
sceNp.Warning("data: 0x%x", data_addr);
sceNp.Warning("data_size: 0x%x", data_size);
sceNp.Warning("prio: %d", prio);
sceNp.Warning("flags: %d", flags);
sceNp.Warning("sceNpDrmProcessExitSpawn() -> sys_game_process_exitspawn");

sys_game_process_exitspawn(path, argv_addr, envp_addr, data_addr, data_size, prio, flags);

Expand All @@ -207,14 +200,7 @@ s32 sceNpDrmProcessExitSpawn(vm::cptr<char> path, u32 argv_addr, u32 envp_addr,

s32 sceNpDrmProcessExitSpawn2(vm::cptr<char> path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags)
{
sceNp.Warning("sceNpDrmProcessExitSpawn2()");
sceNp.Warning("path: %s", path.get_ptr());
sceNp.Warning("argv: 0x%x", argv_addr);
sceNp.Warning("envp: 0x%x", envp_addr);
sceNp.Warning("data: 0x%x", data_addr);
sceNp.Warning("data_size: 0x%x", data_size);
sceNp.Warning("prio: %d", prio);
sceNp.Warning("flags: %d", flags);
sceNp.Warning("sceNpDrmProcessExitSpawn2() -> sys_game_process_exitspawn2");

sys_game_process_exitspawn2(path, argv_addr, envp_addr, data_addr, data_size, prio, flags);

Expand Down
24 changes: 19 additions & 5 deletions rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,50 +157,64 @@ s32 sceNpTrophyRegisterContext(PPUThread& CPU, u32 context, u32 handle, vm::ptr<

if (!ctxt)
{
sceNpTrophy.Error("sceNpTrophyRegisterContext(): SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT");
return SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT;
}

const auto hndl = Emu.GetIdManager().get<trophy_handle_t>(handle);

if (!hndl)
{
sceNpTrophy.Error("sceNpTrophyRegisterContext(): SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE");
return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
}

TRPLoader trp(*ctxt->trp_stream);
if (!trp.LoadHeader())
{
sceNpTrophy.Error("sceNpTrophyRegisterContext(): SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE");
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}

// Rename or discard certain entries based on the files found
const size_t kTargetBufferLength = 31;
char target[kTargetBufferLength+1];
char target[kTargetBufferLength + 1];
target[kTargetBufferLength] = 0;
strcpy_trunc(target, fmt::Format("TROP_%02d.SFM", Ini.SysLanguage.GetValue()));

if (trp.ContainsEntry(target)) {
if (trp.ContainsEntry(target))
{
trp.RemoveEntry("TROPCONF.SFM");
trp.RemoveEntry("TROP.SFM");
trp.RenameEntry(target, "TROPCONF.SFM");
}
else if (trp.ContainsEntry("TROP.SFM")) {
else if (trp.ContainsEntry("TROP.SFM"))
{
trp.RemoveEntry("TROPCONF.SFM");
trp.RenameEntry("TROP.SFM", "TROPCONF.SFM");
}
else if (!trp.ContainsEntry("TROPCONF.SFM")) {
else if (!trp.ContainsEntry("TROPCONF.SFM"))
{
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}

// Discard unnecessary TROP_XX.SFM files
for (s32 i=0; i<=18; i++) {
for (s32 i = 0; i <= 18; i++)
{
strcpy_trunc(target, fmt::Format("TROP_%02d.SFM", i));
if (i != Ini.SysLanguage.GetValue())
{
trp.RemoveEntry(target);
}
}

// TODO: Get the path of the current user
std::string trophyPath = "/dev_hdd0/home/00000001/trophy/" + ctxt->trp_name;
if (!trp.Install(trophyPath))
{
sceNpTrophy.Error("sceNpTrophyRegisterContext(): SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE");
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}

TROPUSRLoader* tropusr = new TROPUSRLoader();
std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Loader/TRP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TRPLoader::~TRPLoader()

bool TRPLoader::Install(std::string dest, bool show)
{
if(!trp_f.IsOpened())
if (!trp_f.IsOpened())
return false;

if (!dest.empty() && dest.back() != '/')
Expand Down

0 comments on commit 66cf864

Please sign in to comment.