From 97e2dccd13236908e2e4601cdc60bfa168aeeefc Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Tue, 31 May 2016 04:03:08 -0400 Subject: [PATCH] Remove IFile from loader - it's just a wrapper, and uses up two pages for nothing useful --- external/loader/source/ifile.c | 77 ------------------- external/loader/source/ifile.h | 20 ----- external/loader/source/loader.c | 19 +++-- .../loader/source/patch/block_cart_update.c | 11 +-- .../loader/source/patch/block_eshop_update.c | 11 +-- .../loader/source/patch/block_nim_update.c | 11 +-- external/loader/source/patch/friends_ver.c | 11 +-- external/loader/source/patch/mset_str.c | 11 +-- external/loader/source/patch/patch.h | 10 +++ external/loader/source/patch/regionfree.c | 11 +-- external/loader/source/patch/ro_sigs.c | 11 +-- external/loader/source/patch/secinfo_sigs.c | 11 +-- external/loader/source/patcher.c | 36 ++++----- 13 files changed, 45 insertions(+), 205 deletions(-) delete mode 100644 external/loader/source/ifile.c delete mode 100644 external/loader/source/ifile.h diff --git a/external/loader/source/ifile.c b/external/loader/source/ifile.c deleted file mode 100644 index 746b02a..0000000 --- a/external/loader/source/ifile.c +++ /dev/null @@ -1,77 +0,0 @@ -#include <3ds.h> -#include "ifile.h" -#include "fsldr.h" - -// TODO - What exactly is the point of these? Can't we just use FSFILE directly? -// These are just shitty wrappers. - -Result -IFile_Open(IFile* file, FS_ArchiveID archiveId, FS_Path archivePath, - FS_Path filePath, u32 flags) -{ - Result res; - - res = FSLDR_OpenFileDirectly(&file->handle, archiveId, archivePath, - filePath, flags, 0); - file->pos = 0; - file->size = 0; - return res; -} - -Result -IFile_Close(IFile* file) -{ - return FSFILE_Close(file->handle); -} - -Result -IFile_GetSize(IFile* file, u64* size) -{ - Result res; - - res = FSFILE_GetSize(file->handle, size); - file->size = *size; - return res; -} - -Result -IFile_Read(IFile* file, u64* total, void* buffer, u32 len) -{ - u32 read; - u32 left; - char* buf; - u64 cur; - Result res; - - if (len == 0) { - *total = 0; - return 0; - } - - buf = (char*)buffer; - cur = 0; - left = len; - while (1) { - res = FSFILE_Read(file->handle, &read, file->pos, buf, left); - if (R_FAILED(res)) { - break; - } - - cur += read; - file->pos += read; - if (read == left) { - break; - } - buf += read; - left -= read; - } - - *total = cur; - return res; -} - -Result -IFile_Write(IFile* file, u64* total, void* buffer, u32 len) -{ - return 1; // FIXME - Not yet implemented. -} diff --git a/external/loader/source/ifile.h b/external/loader/source/ifile.h deleted file mode 100644 index 5cda305..0000000 --- a/external/loader/source/ifile.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __IFILE_H -#define __IFILE_H - -#include <3ds/types.h> - -typedef struct -{ - Handle handle; - u64 pos; - u64 size; -} IFile; - -Result IFile_Open(IFile* file, FS_ArchiveID archiveId, FS_Path archivePath, - FS_Path filePath, u32 flags); -Result IFile_Close(IFile* file); -Result IFile_GetSize(IFile* file, u64* size); -Result IFile_Read(IFile* file, u64* total, void* buffer, u32 len); -Result IFile_Write(IFile* file, u64* total, void* buffer, u32 len); - -#endif diff --git a/external/loader/source/loader.c b/external/loader/source/loader.c index 4db617f..a505053 100644 --- a/external/loader/source/loader.c +++ b/external/loader/source/loader.c @@ -1,7 +1,6 @@ #include <3ds.h> #include "patcher.h" #include "exheader.h" -#include "ifile.h" #include "fsldr.h" #include "fsreg.h" #include "pxipm.h" @@ -55,12 +54,12 @@ static Result load_code(u64 progid, prog_addrs_t* shared, prog_addrs_t* original, u64 prog_handle, int is_compressed) { - IFile file; + Handle handle; FS_Path archivePath; FS_Path path; Result res; u64 size; - u64 total; + u32 total; archivePath.type = PATH_BINARY; archivePath.data = &prog_handle; @@ -70,26 +69,26 @@ load_code(u64 progid, prog_addrs_t* shared, prog_addrs_t* original, path.data = CODE_PATH; path.size = sizeof(CODE_PATH); - if (R_FAILED(IFile_Open(&file, ARCHIVE_SAVEDATA_AND_CONTENT2, archivePath, - path, FS_OPEN_READ))) { + if (R_FAILED(FSLDR_OpenFileDirectly(&handle, ARCHIVE_SAVEDATA_AND_CONTENT2, archivePath, + path, FS_OPEN_READ, 0))) { svcBreak(USERBREAK_ASSERT); } // get file size - if (R_FAILED(IFile_GetSize(&file, &size))) { - IFile_Close(&file); + if (R_FAILED(FSFILE_GetSize(handle, &size))) { + FSFILE_Close(handle); svcBreak(USERBREAK_ASSERT); } // check size if (size > (u64)shared->total_size << 12) { - IFile_Close(&file); + FSFILE_Close(handle); return 0xC900464F; } // read code - res = IFile_Read(&file, &total, (void*)shared->text_addr, size); - IFile_Close(&file); // done reading + res = FSFILE_Read(handle, &total, 0, (void*)shared->text_addr, size); + FSFILE_Close(handle); // done reading if (R_FAILED(res)) { svcBreak(USERBREAK_ASSERT); } diff --git a/external/loader/source/patch/block_cart_update.c b/external/loader/source/patch/block_cart_update.c index 06e3adb..bf307c8 100644 --- a/external/loader/source/patch/block_cart_update.c +++ b/external/loader/source/patch/block_cart_update.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void disable_cart_updates(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/block_eshop_update.c b/external/loader/source/patch/block_eshop_update.c index edcaf31..d240154 100644 --- a/external/loader/source/patch/block_eshop_update.c +++ b/external/loader/source/patch/block_eshop_update.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void disable_eshop_updates(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/block_nim_update.c b/external/loader/source/patch/block_nim_update.c index 682b8f5..eee7d53 100644 --- a/external/loader/source/patch/block_nim_update.c +++ b/external/loader/source/patch/block_nim_update.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void disable_nim_updates(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/friends_ver.c b/external/loader/source/patch/friends_ver.c index ac8cfae..fc50ecb 100644 --- a/external/loader/source/patch/friends_ver.c +++ b/external/loader/source/patch/friends_ver.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void fake_friends_version(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/mset_str.c b/external/loader/source/patch/mset_str.c index daad227..9690879 100644 --- a/external/loader/source/patch/mset_str.c +++ b/external/loader/source/patch/mset_str.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void settings_string(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/patch.h b/external/loader/source/patch/patch.h index 90d8c2f..a9ed7ed 100644 --- a/external/loader/source/patch/patch.h +++ b/external/loader/source/patch/patch.h @@ -1,6 +1,16 @@ #ifndef __PATCH_PATCH_H #define __PATCH_PATCH_H +#include <3ds.h> +#include "../patcher.h" + +#ifndef PATH_MAX +#define PATH_MAX 255 +#define _MAX_LFN 255 +#endif +#include "../config.h" +#include "../../../../source/patch_format.h" + void disable_cart_updates(u64 progId, u8* code, u32 size); void disable_eshop_updates(u64 progId, u8* code, u32 size); void disable_nim_updates(u64 progId, u8* code, u32 size); diff --git a/external/loader/source/patch/regionfree.c b/external/loader/source/patch/regionfree.c index ee821ce..a50a00b 100644 --- a/external/loader/source/patch/regionfree.c +++ b/external/loader/source/patch/regionfree.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void region_patch(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/ro_sigs.c b/external/loader/source/patch/ro_sigs.c index c6c0fd1..c9985a2 100644 --- a/external/loader/source/patch/ro_sigs.c +++ b/external/loader/source/patch/ro_sigs.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void ro_sigpatch(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patch/secinfo_sigs.c b/external/loader/source/patch/secinfo_sigs.c index 11b37df..c7bd706 100644 --- a/external/loader/source/patch/secinfo_sigs.c +++ b/external/loader/source/patch/secinfo_sigs.c @@ -1,13 +1,4 @@ -#include <3ds.h> -#include "../patcher.h" -#include "../ifile.h" - -#ifndef PATH_MAX -#define PATH_MAX 255 -#define _MAX_LFN 255 -#endif -#include "../config.h" -#include "../../../../source/patch_format.h" +#include "patch.h" void secureinfo_sigpatch(u64 progId, u8* code, u32 size) diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index 115c85c..655911d 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -1,6 +1,6 @@ #include <3ds.h> #include "patcher.h" -#include "ifile.h" +#include "fsldr.h" #include "internal.h" #ifndef PATH_MAX @@ -93,7 +93,7 @@ strnlen(const char* string, size_t maxlen) } static int -fileOpen(IFile* file, FS_ArchiveID id, const char* path, int flags) +fileOpen(Handle* file, FS_ArchiveID id, const char* path, int flags) { FS_Path apath; FS_Path ppath; @@ -106,7 +106,7 @@ fileOpen(IFile* file, FS_ArchiveID id, const char* path, int flags) ppath.data = path; ppath.size = strnlen(path, PATH_MAX) + 1; - return IFile_Open(file, id, apath, ppath, flags); + return FSLDR_OpenFileDirectly(file, id, apath, ppath, flags, 0); } static struct config_file config; @@ -115,26 +115,25 @@ static int failed_load_config = 1; void load_config() { - static IFile file; - static u64 total; + static Handle file; + static u32 total; // Open file. - if (!R_SUCCEEDED( - fileOpen(&file, ARCHIVE_SDMC, PATH_CONFIG, FS_OPEN_READ))) { + if (!R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, PATH_CONFIG, FS_OPEN_READ))) { // Failed to open. return; } // Read file. if (!R_SUCCEEDED( - IFile_Read(&file, &total, &config, sizeof(struct config_file)))) { - IFile_Close(&file); // Read to memory. + FSFILE_Read(file, &total, 0, &config, sizeof(struct config_file)))) { + FSFILE_Close(file); // Read to memory. // Failed to read. return; } - IFile_Close(&file); // Read to memory. + FSFILE_Close(file); // Read to memory. if (config.magic[0] != 'O' || config.magic[1] != 'V' || config.magic[2] != 'A' || config.magic[3] != 'N') { @@ -152,7 +151,7 @@ load_config() return; } - +/* static int loadTitleLocaleConfig(u64 progId, u8* regionId, u8* languageId) { @@ -282,10 +281,10 @@ loadTitleLocaleConfig(u64 progId, u8* regionId, u8* languageId) static u8* getCfgOffsets(u8* code, u32 size, u32* CFGUHandleOffset) { - /* HANS: - Look for error code which is known to be stored near cfg:u handle - this way we can find the right candidate - (handle should also be stored right after end of candidate function) */ + // HANS: + // Look for error code which is known to be stored near cfg:u handle + // this way we can find the right candidate + // (handle should also be stored right after end of candidate function) u32 n = 0, possible[24]; @@ -408,7 +407,7 @@ patchCfgGetRegion(u8* code, u32 size, u8 regionId, u32 CFGUHandleOffset) } } } - +*/ static void adjust_cpu_settings(u64 progId, u8* code, u32 size) { @@ -435,6 +434,7 @@ adjust_cpu_settings(u64 progId, u8* code, u32 size) } } +/* void language_emu(u64 progId, u8* code, u32 size) { @@ -464,7 +464,7 @@ language_emu(u64 progId, u8* code, u32 size) } } } - +*/ void overlay_patch(u64 progId, u8* code, u32 size) { @@ -541,7 +541,7 @@ patch_text(u64 progId, u8* text, u32 size, u32 orig_size) } default: // Anything else. { - language_emu(progId, text, orig_size); + // language_emu(progId, text, orig_size); break; } } -- 2.39.5