From 3a0418e279a358663d290e2993e298236f3e9ebb Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Fri, 29 May 2020 23:31:05 +0200 Subject: [PATCH] loader: revert to use the NS patch due to a Nintendo bug: https://www.3dbrew.org/wiki/NCCH/Extended_Header#Flag1 --- sysmodules/loader/source/loader.c | 10 ---------- sysmodules/loader/source/patcher.c | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/sysmodules/loader/source/loader.c b/sysmodules/loader/source/loader.c index e6d133b..d9f1dfc 100644 --- a/sysmodules/loader/source/loader.c +++ b/sysmodules/loader/source/loader.c @@ -184,16 +184,6 @@ static Result GetProgramInfo(ExHeader_Info *exheaderInfo, u64 programHandle) u64 originaltitleId = exheaderInfo->aci.local_caps.title_id; if(CONFIG(PATCHGAMES) && loadTitleExheaderInfo(exheaderInfo->aci.local_caps.title_id, exheaderInfo)) exheaderInfo->aci.local_caps.title_id = originaltitleId; - - if(isN3DS) - { - u32 cpuSetting = MULTICONFIG(NEWCPU); - - if(cpuSetting & 0x1) - exheaderInfo->aci.local_caps.core_info.use_cpu_clockrate_804MHz = true; - if(cpuSetting & 0x2) - exheaderInfo->aci.local_caps.core_info.enable_l2c = true; - } } return res; diff --git a/sysmodules/loader/source/patcher.c b/sysmodules/loader/source/patcher.c index 3fc143b..f38e3a4 100644 --- a/sysmodules/loader/source/patcher.c +++ b/sysmodules/loader/source/patcher.c @@ -698,6 +698,28 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro if(ret == 0 || (ret == 1 && progVer > 0xB)) goto error; } + if(isN3DS) + { + u32 cpuSetting = MULTICONFIG(NEWCPU); + + if(cpuSetting != 0) + { + static const u8 pattern[] = { + 0x0C, 0x00, 0x94, 0x15 + }; + + u32 *off = (u32 *)memsearch(code, pattern, textSize, sizeof(pattern)); + + if(off == NULL) goto error; + + //Patch N3DS CPU Clock and L2 cache setting + *(off - 4) = *(off - 3); + *(off - 3) = *(off - 1); + memmove(off - 1, off, 16); + *(off + 3) = 0xE3800000 | cpuSetting; + } + } + if(progVer > 0x12) { static const u8 pattern[] = {