Skip to content

Commit

Permalink
Fix Mode3 and 3dsx
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohackandglitch committed Nov 9, 2019
1 parent f8a2742 commit b138e1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -43,7 +43,7 @@ LIBRARIES := citro3d ctru png z m

VERSION_MAJOR := 2
VERSION_MINOR := 13
VERSION_MICRO := 1
VERSION_MICRO := 2



Expand Down
2 changes: 1 addition & 1 deletion source/main.h
Expand Up @@ -87,7 +87,7 @@ static const char * const s_error[] =
"USER_ABORT",
"FILE_COPY_ERROR",
"LOAD_AND_EXECUTE",
"NTR is already running"
"NTR is already running",
"CUSTOM_PM_PATCH_FAIL"
};

Expand Down
2 changes: 1 addition & 1 deletion source/mainMenu.c
Expand Up @@ -100,7 +100,7 @@ int mainMenu(void)
bool noTimer;

static bool first = true;
if (first) {
if (first && !bnConfig->isMode3) {
V32Button->show(V32Button);
V33Button->show(V33Button);
V36Button->show(V36Button);
Expand Down
39 changes: 23 additions & 16 deletions source/ntr_launcher.c
Expand Up @@ -53,12 +53,12 @@ u32 findCustomPMsvcRunPattern(u32* outaddr)
{
return res;
}
res = svcMapProcessMemoryEx(prochand, 0x0B000000, (u32)addr, (u32)info); //map PM process memory into this process @ 0x08000000
res = svcMapProcessMemoryEx(prochand, 0x28000000, (u32)addr, (u32)info); //map PM process memory into this process @ 0x08000000
if (res)
{
return res;
}
addr = (u32*)0x0B000000;
addr = (u32*)0x28000000;
u32* endAddr = (u32*)((u32)addr + (u32)info);
while (addr < endAddr)
{
Expand All @@ -68,19 +68,34 @@ u32 findCustomPMsvcRunPattern(u32* outaddr)
while (*addr2 != 0xE92D0030 && (u32)addr - (u32)addr2 < 0x100) addr2--; // Find start of the svc function
if ((u32)addr - (u32)addr2 < 0x100)
{
*outaddr = ((u32)addr2 - 0x0B000000) + textStart;
*outaddr = ((u32)addr2 - 0x28000000) + textStart;
}
else res = -1;
break;
}
addr++;
}
if (addr >= endAddr) res = -1;
svcUnmapProcessMemoryEx(prochand, 0x0B000000, (u32)info);
svcUnmapProcessMemoryEx(CURRENT_PROCESS_HANDLE, 0x28000000, (u32)info);
svcCloseHandle(prochand);
return res;
}

Result bnPatchCustomPM() { // If cfw is Luma3DS 10 and higher, patch custom PM sysmodule
Result ret = 0;
s64 out;
if (R_SUCCEEDED(ret = svcGetSystemInfo(&out, 0x10000, 0))
&& GET_VERSION_MAJOR((u32)out) >= 10)
{
u32 patchAddr;
check_prim(ret = findCustomPMsvcRunPattern(&patchAddr), CUSTOM_PM_PATCH_FAIL);
ntrConfig->PMSvcRunAddr = patchAddr;
}
else ret = 0;
error:
return ret;
}

Result bnPatchAccessCheck(void)
{
s64 out;
Expand All @@ -98,21 +113,10 @@ Result bnPatchAccessCheck(void)
ret = patchRemoteProcess(bnConfig->FSPid, bnConfig->FSPatchAddr, (u8 *)&fsPatchValue, 4);
check_sec(ret, FSPATCH_FAILURE);

// If cfw is Luma3DS 10 and higher, let NTR handle the PM patch
if (R_SUCCEEDED(ret = svcGetSystemInfo(&out, 0x10000, 0))
&& GET_VERSION_MAJOR((u32)out) >= 10)
{
u32 patchAddr;
u32 patchAddrRes = findCustomPMsvcRunPattern(&patchAddr);
check_sec(patchAddrRes, CUSTOM_PM_PATCH_FAIL);
ntrConfig->PMSvcRunAddr = patchAddr;
}

// If cfw is Luma3DS 9 and higher, skip sm patch
if (R_SUCCEEDED(ret) && GET_VERSION_MAJOR((u32)out) >= 9)
if (R_SUCCEEDED(ret = svcGetSystemInfo(&out, 0x10000, 0)) && GET_VERSION_MAJOR((u32)out) >= 9)
return (0);


ret = patchRemoteProcess(bnConfig->SMPid, bnConfig->SMPatchAddr, smPatchBuf, 8);
check_sec(ret, SMPATCH_FAILURE);
return (0);
Expand Down Expand Up @@ -226,6 +230,9 @@ Result bnBootNTR(void)
// Patch services
ret = bnPatchAccessCheck();
check_prim(ret, ACCESSPATCH_FAILURE);
// Patch custom PM
ret = bnPatchCustomPM();
check_prim(ret, CUSTOM_PM_PATCH_FAIL);

// Init home menu params
check_sec(bnInitParamsByHomeMenu(), UNKNOWN_HOMEMENU);
Expand Down

0 comments on commit b138e1c

Please sign in to comment.