diff --git a/include/ctr/FS.h b/include/ctr/FS.h index 0f5cbce..583fbe9 100644 --- a/include/ctr/FS.h +++ b/include/ctr/FS.h @@ -48,6 +48,7 @@ Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *buffer, u32 size, u32 flushFlags); Result FSFILE_GetSize(Handle handle, u64 *size); Result FSFILE_SetSize(Handle handle, u64 size); +Result FSFILE_Flush(Handle handle); Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer); Result FSDIR_Close(Handle handle); diff --git a/release/OnionFS.plg b/release/OnionFS.plg index 0a9d4df..994bc1e 100644 Binary files a/release/OnionFS.plg and b/release/OnionFS.plg differ diff --git a/release/OnionFS_debug.plg b/release/OnionFS_debug.plg index 752377b..08112db 100644 Binary files a/release/OnionFS_debug.plg and b/release/OnionFS_debug.plg differ diff --git a/source/libctru/FS.c b/source/libctru/FS.c index 3734935..fbab49a 100644 --- a/source/libctru/FS.c +++ b/source/libctru/FS.c @@ -204,6 +204,18 @@ Result FSFILE_SetSize(Handle handle, u64 size) return cmdbuf[1]; } +Result FSFILE_Flush(Handle handle) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x8090000; + + Result ret = 0; + if((ret = svc_sendSyncRequest(handle))) return ret; + + return cmdbuf[1]; +} + Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer) { u32 *cmdbuf=getThreadCommandBuffer(); diff --git a/source/log.c b/source/log.c index 7a91e87..4b4c0f1 100644 --- a/source/log.c +++ b/source/log.c @@ -50,7 +50,9 @@ void WriteLog(const char *log) u32 size = (u32)strnlen(log, 0x100); u32 bytes; - if (!FSFILE_Write(g_logFile, &bytes, g_offset, (u32 *)log, size, 0x0)) - g_offset += bytes; + if (!FSFILE_Flush(g_logFile)) { + if (!FSFILE_Write(g_logFile, &bytes, g_offset, (u32 *)log, size, 0x0)) + g_offset += bytes; + } } #endif \ No newline at end of file diff --git a/source/main.c b/source/main.c index 2e850db..cd013c1 100644 --- a/source/main.c +++ b/source/main.c @@ -48,6 +48,7 @@ u64 currposs = 0; FS_archive debugsdmcArchive = {0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; Handle debugfileout; u64 lastcurrposs = 0; +u8 safewritedebug = 1; #endif int InitFS(void) @@ -110,36 +111,57 @@ u8 checkarchive(u8* path, u8 size) { void addarchive(u8* path) { u8 len = 0; + #ifdef DEBUG_MODE + LOG("Registering new archive: %s... ", path); + #endif while(*(path + len)) len++; if (!(checkarchive(path, len)) && (archivecount < 20)) { strCat(archivelist + (10*archivecount), path); archivecount++; + #ifdef DEBUG_MODE + LOG("success\r\n"); + #endif } + #ifdef DEBUG_MODE + else { + LOG("skipped, already registered\r\n"); + } + #endif } u32 fsRegArchiveCallback(u8* path, u32 ptr, u32 isAddOnContent, u32 isAlias) { + #ifdef DEBUG_MODE + while (!safewritedebug){ + svc_sleepThread(1000000); + } + safewritedebug = 0; + #endif u32 ret, ret2; static u32 isFisrt = 1; u32 sdmcArchive = 0; - - nsDbgPrint("regArchive: %s, %08x, %08x, %08x\n", path, ptr, isAddOnContent, isAlias); ret = ((fsRegArchiveTypeDef)regArchiveHook.callCode)(path, ptr, isAddOnContent, isAlias); addarchive(path); if (isFisrt) { isFisrt = 0; - - ((fsMountArchiveTypeDef)fsMountArchive)(&sdmcArchive, 9); - #ifdef LOG_FILES - nsDbgPrint("sdmcArchive: %08x\n", sdmcArchive); + #ifdef DEBUG_MODE + LOG("Trying to open SD archive... "); #endif + ((fsMountArchiveTypeDef)fsMountArchive)(&sdmcArchive, 9); if (sdmcArchive) { ret2 = ((fsRegArchiveTypeDef)regArchiveHook.callCode)("ram:", sdmcArchive, 0, 0); - #ifdef LOG_FILES - nsDbgPrint("regArchive ret: %08x\n", ret2); + #ifdef DEBUG_MODE + if (ret2 != 0) { + LOG("failed: 0x%08X\r\n", ret2); + } else { + LOG("success.\r\n"); + } #endif } } + #ifdef DEBUG_MODE + safewritedebug = 1; + #endif return ret; } @@ -180,29 +202,41 @@ u8 findu8character(u8* in, char character) { } u32 userFsTryOpenFileCallback(u32 a1, u16 * fileName, u32 mode) { + #ifdef DEBUG_MODE + while (!safewritedebug){ + svc_sleepThread(1000000); + } + safewritedebug = 0; + #endif u16 buf[300]; u32 ret; convertUnicodeToAnsi(fileName, (u8*) buf); u8 chara = findu8character((u8*) buf, '/'); -#ifdef LOG_FILES - nsDbgPrint("path: %s\n", buf); -#endif - if ((chara) && checkarchive((u8*) buf, chara)) { - // accessing rom:/ file + #ifdef DEBUG_MODE + LOG("File %s ", (u8*)buf); + #endif buf[0] = 0; ustrCat(buf, ustrRootPath); ustrCat(buf, &fileName[chara + 1]); ret = ((userFsTryOpenFileTypeDef)userFsTryOpenFileHook.callCode)(a1, buf, 1); -#ifdef LOG_FILES - nsDbgPrint("ret: %08x\n", ret); -#endif if (ret == 0) { + #ifdef DEBUG_MODE + LOG("found in SD, redirected.\r\n"); + safewritedebug = 1; + #endif return ret; } + #ifdef DEBUG_MODE + else if (ret == 0xC8804478) {LOG("not found in SD, skipping.\r\n");} + else {LOG("returned unknown result: 0x%08X.\r\n", ret);} + #endif } + #ifdef DEBUG_MODE + safewritedebug = 1; + #endif return ((userFsTryOpenFileTypeDef)userFsTryOpenFileHook.callCode)(a1, fileName, mode); } @@ -651,10 +685,8 @@ int main() { rtEnableHook(&cfgGetRegionHook); #endif #ifdef DEBUG_MODE - LOG("\r\nFinished patching, launching game... Bye!"); - ExitLog(); + LOG("\r\nFinished patching, launching game...\r\n\r\n"); #endif - InitFS(); return 0; }