cellGame: Improvements

This commit is contained in:
Eladash 2020-08-29 21:20:37 +03:00 committed by Ani
parent c436ef0c6f
commit ed032dc985

View File

@ -126,6 +126,7 @@ struct content_permission final
stx::init_mutex init;
atomic_t<u32> can_create = 0;
atomic_t<bool> exists = false;
atomic_t<bool> restrict_sfo_params = true;
content_permission() = default;
@ -134,6 +135,16 @@ struct content_permission final
content_permission& operator=(const content_permission&) = delete;
void reset()
{
dir.clear();
sfo.clear();
temp.clear();
can_create = 0;
exists = false;
restrict_sfo_params = true;
}
~content_permission()
{
bool success = false;
@ -388,9 +399,6 @@ error_code cellGameBootCheck(vm::ptr<u32> type, vm::ptr<u32> attributes, vm::ptr
perm->dir = std::move(dir);
perm->sfo = std::move(sfo);
perm->temp.clear();
perm->can_create = 0;
return CELL_OK;
}
@ -427,9 +435,6 @@ error_code cellGamePatchCheck(vm::ptr<CellGameContentSize> size, vm::ptr<void> r
perm->dir = Emu.GetTitleID();
perm->sfo = std::move(sfo);
perm->temp.clear();
perm->can_create = 0;
return CELL_OK;
}
@ -473,8 +478,6 @@ error_code cellGameDataCheck(u32 type, vm::cptr<char> dirName, vm::ptr<CellGameC
}
perm->dir = std::move(name);
perm->sfo.clear();
perm->temp.clear();
if (type == CELL_GAME_GAMETYPE_GAMEDATA)
{
@ -489,6 +492,7 @@ error_code cellGameDataCheck(u32 type, vm::cptr<char> dirName, vm::ptr<CellGameC
return not_an_error(CELL_GAME_RET_NONE);
}
perm->exists = true;
perm->sfo = psf::load_object(fs::file(vfs::get(dir + "/PARAM.SFO")));
return CELL_OK;
}
@ -515,6 +519,7 @@ error_code cellGameContentPermit(vm::ptr<char[CELL_GAME_PATH_MAX]> contentInfoPa
if (perm->can_create && perm->temp.empty() && !fs::is_dir(vfs::get(dir)))
{
perm->reset();
strcpy_trunc(*contentInfoPath, "");
strcpy_trunc(*usrdirPath, "");
return CELL_OK;
@ -539,6 +544,9 @@ error_code cellGameContentPermit(vm::ptr<char[CELL_GAME_PATH_MAX]> contentInfoPa
}
}
// Cleanup
perm->reset();
strcpy_trunc(*contentInfoPath, dir);
strcpy_trunc(*usrdirPath, dir + "/USRDIR");
return CELL_OK;
@ -694,6 +702,11 @@ error_code cellGameCreateGameData(vm::ptr<CellGameSetInitParams> init, vm::ptr<c
{
cellGame.error("cellGameCreateGameData(init=*0x%x, tmp_contentInfoPath=*0x%x, tmp_usrdirPath=*0x%x)", init, tmp_contentInfoPath, tmp_usrdirPath);
if (!init)
{
return CELL_GAME_ERROR_PARAM;
}
const auto prm = g_fxo->get<content_permission>();
const auto _init = prm->init.access();
@ -708,6 +721,11 @@ error_code cellGameCreateGameData(vm::ptr<CellGameSetInitParams> init, vm::ptr<c
return CELL_GAME_ERROR_NOTSUPPORTED;
}
if (prm->exists)
{
return CELL_GAME_ERROR_EXIST;
}
std::string dirname = "_GDATA_" + std::to_string(steady_clock::now().time_since_epoch().count());
std::string tmp_contentInfo = "/dev_hdd0/game/" + dirname;
std::string tmp_usrdir = "/dev_hdd0/game/" + dirname + "/USRDIR";
@ -894,7 +912,7 @@ error_code cellGameGetParamString(s32 id, vm::ptr<char> buf, u32 bufsize)
error_code cellGameSetParamString(s32 id, vm::cptr<char> buf)
{
cellGame.warning("cellGameSetParamString(id=%d, buf=*0x%x)", id, buf);
cellGame.warning("cellGameSetParamString(id=%d, buf=*0x%x %s)", id, buf, buf);
if (!buf)
{