Skip to content

Commit

Permalink
Merge pull request #241 from igor725/savedata-fix
Browse files Browse the repository at this point in the history
Fix savedata and iterator
  • Loading branch information
SysRay authored Jun 16, 2024
2 parents 4f1f596 + f0ca854 commit f50bbee
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
10 changes: 4 additions & 6 deletions core/fileManager/fileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,34 +227,32 @@ class FileManager: public IFileManager {

#pragma pack(pop, 1)

auto count = dir->count;
int n = 0;
int n = 0;

while (n < nbytes - sizeof(DataStruct)) {
auto item = (DataStruct*)(buf + n);

auto const filename = (*dir->m_file)->path().filename().string();
if (sizeof(DataStruct) + std::min(filename.size(), 255llu) >= nbytes) break;

item->fileno = count;
item->fileno = ++dir->count;
item->type = ((*dir->m_file)->is_regular_file() ? 8 : 4);
item->namlen = filename.copy(item->name, 255);
item->name[item->namlen] = '\0';

n += sizeof(DataStruct);
item->reclen = sizeof(DataStruct);

LOG_DEBUG(L"KernelGetdirentries[%d]: %S %u offset:%u count:%u", handle, item->name, item->type, n, count);
LOG_DEBUG(L"KernelGetdirentries[%d]: %S %u offset:%u count:%u", handle, item->name, item->type, n, dir->count);

std::error_code err;
(*dir->m_file).increment(err);
count = ++dir->count;

if ((*dir->m_file) == endDir || err) break;
};

if (basep != nullptr) {
*basep = count;
*basep = dir->count;
}
return n;
}
Expand Down
23 changes: 18 additions & 5 deletions core/runtime/exports/intern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void init() {
initIntercepts();
}

/*
void SYSV_ABI logfunc(const char* str, void* args) {
char sanitize[1024] = "gamelogger| ";
for (int i = 12; i < 1024; ++i) {
Expand All @@ -35,13 +34,27 @@ void SYSV_ABI logfunc(const char* str, void* args) {
}
vprintf(sanitize, (va_list)&args);
}
*/

/**
* @brief List of game logger addresses:
*
* <Game name>:
* <Version>: <binary>:<offset>, <interceptor>
*
*
* NieR: Automata:
* v01.06: eboot.bin:0xbe09e0, logfunc
*
* Worms W.M.D
* v01.00: eboot.bin:0x428b70, logfunc
*
*/

void post() {
/*
// NieR: Automata v01.06 internal game logger interception example:
auto mp = accessRuntimeLinker().accessMainProg();
accessRuntimeLinker().interceptInternal(mp, 0xbe09e0, (uint64_t)&logfunc);
// Use addresses above to intercept game's function
auto prg = accessRuntimeLinker().accessMainProg(); // or findProgramById() for prx libs
accessRuntimeLinker().interceptInternal(prg, <offset there>, (uint64_t)&<your function name there>);
*/
}

Expand Down
6 changes: 4 additions & 2 deletions modules/external/libSceSaveData/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ int saveDataMount(int32_t userId, const char* dirName, SceSaveDataMountMode moun

mountResult->mountStatus = 0;

bool doCreate = ((uint32_t)mountMode & ((uint32_t)SceSaveDataMountMode::CREATE) | (uint32_t)SceSaveDataMountMode::CREATE2) > 0;
bool doOpen = ((uint32_t)mountMode & ((uint32_t)SceSaveDataMountMode::READ_ONLY) | (uint32_t)SceSaveDataMountMode::READ_WRITE) > 0;
bool doCreate = ((uint32_t)mountMode & ((uint32_t)SceSaveDataMountMode::CREATE | (uint32_t)SceSaveDataMountMode::CREATE2)) > 0;
bool doOpen = ((uint32_t)mountMode & ((uint32_t)SceSaveDataMountMode::READ_ONLY | (uint32_t)SceSaveDataMountMode::READ_WRITE)) > 0;

if (doOpen || doCreate) {
if (!accessFileManager().getMountPoint(MountType::Save, dirSaveFiles.filename().string()).empty()) {
Expand All @@ -48,6 +48,8 @@ int saveDataMount(int32_t userId, const char* dirName, SceSaveDataMountMode moun
if (!std::filesystem::exists(dirSaveFiles)) {
std::filesystem::create_directories(dirSaveFiles);
mountResult->mountStatus = (uint32_t)SceSaveDataMountStatus::CREATED;
} else if ((uint32_t)mountMode & (uint32_t)SceSaveDataMountMode::CREATE) {
return Err::SaveData::EXISTS;
}
}

Expand Down
15 changes: 9 additions & 6 deletions modules/external/libSceUsbd/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ EXPORT const char* MODULE_NAME = "libSceUsbd";

EXPORT SYSV_ABI int sceUsbdInit() {
LOG_USE_MODULE(libSceUsbd);
LOG_ERR(L"todo %S", __FUNCTION__);
LOG_TRACE(L"todo %S", __FUNCTION__);
return Ok;
}

EXPORT SYSV_ABI uint64_t sceUsbdGetDeviceList(SceUsbdDevice*** list) {
EXPORT SYSV_ABI int64_t sceUsbdGetDeviceList(SceUsbdDevice*** list) {
LOG_USE_MODULE(libSceUsbd);
LOG_ERR(L"todo %S", __FUNCTION__);
return Ok;
LOG_TRACE(L"todo %S", __FUNCTION__);
static SceUsbdDevice* headDevice = nullptr;

*list = &headDevice;
return 0;
}

EXPORT SYSV_ABI void sceUsbdFreeDeviceList(SceUsbdDevice** list, int unrefDevices) {
LOG_USE_MODULE(libSceUsbd);
LOG_ERR(L"todo %S", __FUNCTION__);
LOG_TRACE(L"todo %S", __FUNCTION__);
}

EXPORT SYSV_ABI int32_t sceUsbdHandleEvents() {
Expand All @@ -40,7 +43,7 @@ EXPORT SYSV_ABI int32_t sceUsbdHandleEventsTimeout(struct timeval* tv) {

EXPORT SYSV_ABI int32_t sceUsbdOpenDeviceWithVidPid(uint16_t vendorId, uint16_t productId) {
LOG_USE_MODULE(libSceUsbd);
LOG_ERR(L"todo %S", __FUNCTION__);
LOG_TRACE(L"todo %S", __FUNCTION__);
return Ok;
}
}

0 comments on commit f50bbee

Please sign in to comment.