Skip to content

Commit

Permalink
Fixed texts; add options to disable overlay functions to be compatibl…
Browse files Browse the repository at this point in the history
…e with CTRPF-based plugins
  • Loading branch information
xzn committed Jan 18, 2024
1 parent 6f675c4 commit 61d2df0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/ns/ns.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct _NS_CONFIG {
u32 rpConfigLock;
u32 rpGamePid;
u32 plgNoLoaderMem;
u32 plgCTRPFCompat;
} NS_CONFIG;

#define NS_INITMODE_FROMBOOT 0
Expand Down
1 change: 1 addition & 0 deletions include/ntr_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct _NTR_CONFIG {
/* BootNTR's NTR_CONFIG ends here */
u32 debugMore;
u32 gameHasPlugins;
u32 ctrpfCompat;
} NTR_CONFIG;

#define NTR_MEMMODE_DEFAULT (0)
Expand Down
3 changes: 1 addition & 2 deletions source/ns/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,11 +2310,10 @@ static int nsInitRemotePlay(RP_CONFIG *config, u32 skipControl) {
goto final;
}


u8 desiredHeader[16] = { 0x04, 0x00, 0x2D, 0xE5, 0x4F, 0x00, 0x00, 0xEF, 0x00, 0x20, 0x9D, 0xE5, 0x00, 0x10, 0x82, 0xE5 };
u8 buf[16] = { 0 };
if (!(ntrConfig->isNew3DS)) {
nsDbgPrint("remoteplay is available on new3ds only\n");
nsDbgPrint("Remote Play is available on New 3DS only.", 0, 0);
ret = -1;
goto final;
}
Expand Down
49 changes: 44 additions & 5 deletions source/plg.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,25 @@ static void plgChangeNoLoaderMem(void) {
g_nsConfig->plgNoLoaderMem = noLoaderMem;
}

static void plgChangeCTRPFCompat(void) {
static Handle hPMProcess = 0;
s32 ret = 0;
if (hPMProcess == 0) {
ret = svc_openProcess(&hPMProcess, ntrConfig->PMPid);
if (ret != 0) {
showDbg("Open pm process failed: %08x", ret, 0);
return;
}
}
u32 CTRPFCompat = !g_nsConfig->plgCTRPFCompat;
ret = copyRemoteMemory(hPMProcess, (u8 *)NS_CONFIGURE_ADDR + offsetof(NS_CONFIG, plgCTRPFCompat), CURRENT_PROCESS_HANDLE, &CTRPFCompat, sizeof(g_nsConfig->plgCTRPFCompat));
if (ret != 0) {
showDbg("Update CTRPF compat option failed: %08x", ret, 0);
return;
}
g_nsConfig->plgCTRPFCompat = CTRPFCompat;
}

void plgShowMainMenu(void) {
typedef u32(*funcType)();

Expand All @@ -320,13 +339,23 @@ void plgShowMainMenu(void) {
u32 mainEntries;
u32 localaddr = gethostid();

char *enableCTRPFCompatText = plgTranslate("CTRPF Compat Mode (Disabled)");
char *disableCTRPFCompatText = plgTranslate("CTRPF Compat Mode (Enabled)");
char *enableLoaderMemText = plgTranslate("Loader Mem Compat (Disabled)");
char *disableLoaderMemText = plgTranslate("Loader Mem Compat (Enabled)");

// debounceKey();
entries[0] = plgTranslate("Remote Play");

entries[0] = plgTranslate("Remote Play (New 3DS)");
entries[1] = plgTranslate("Process Manager");
#if 0
entries[2] = plgTranslate("Enable Debugger");
#endif
entries[2] = g_nsConfig->plgCTRPFCompat ? disableCTRPFCompatText : enableCTRPFCompatText;
descs[2] = plgTranslate("Avoid crash in CTRPF based plugins\nby disabling all overlay functions\nincluding night shift screen filters");
entries[3] = plgTranslate("Set Hotkey");
entries[4] = g_nsConfig->plgNoLoaderMem ? plgTranslate("Enable Loader Mem") : plgTranslate("Disable Loader Mem");
descs[4] = plgTranslate("Affect game plugins only. Keep enabled for higher compatibility.");
entries[4] = g_nsConfig->plgNoLoaderMem ? enableLoaderMemText : disableLoaderMemText;
descs[4] = plgTranslate("Affect game plugins only.\nKeep enabled for higher compatibility.\nSome plugins will crash when disabled\nothers will hang when switching games\nif enabled");
mainEntries = 5;
if (mainEntriesMax < mainEntries) {
showDbg("Error: too many menu items", 0, 0);
Expand Down Expand Up @@ -373,6 +402,7 @@ void plgShowMainMenu(void) {
else if (r == 1) {
processManager();
}
#if 0
else if (r == 2) {
if (g_nsConfig->hSOCU) {
showMsg(plgTranslate("Debugger has already been enabled."));
Expand All @@ -383,14 +413,21 @@ void plgShowMainMenu(void) {
break;
}
}
#endif
else if (r == 2) {
releaseVideo();
plgChangeCTRPFCompat();
entries[2] = g_nsConfig->plgCTRPFCompat ? disableCTRPFCompatText : enableCTRPFCompatText;
acquireVideo();
}
else if (r == 3) {
plgSetHotkeyUi();
}
else if (r == 4) {
releaseVideo();
plgChangeNoLoaderMem();
entries[4] = g_nsConfig->plgNoLoaderMem ? enableLoaderMemText : disableLoaderMemText;
acquireVideo();
break;
}
}

Expand Down Expand Up @@ -585,6 +622,7 @@ u32 plgLoadPluginToRemoteProcess(u32 hProcess) {

memcpy(&cfg.ntrConfig, ntrConfig, sizeof(NTR_CONFIG));
cfg.ntrConfig.gameHasPlugins = gameHasPlugins;
cfg.ntrConfig.ctrpfCompat = g_nsConfig->plgCTRPFCompat;
ret = nsAttachProcess(hProcess, 0x00100000, &cfg, 1);
if (ret != 0) {
nsDbgPrint("attach process failed: %08x\n", ret);
Expand Down Expand Up @@ -1100,7 +1138,8 @@ void initFromInjectGame(void) {
typedef void(*funcType)();
u32 i;

plgInitScreenOverlay();
if (!ntrConfig->ctrpfCompat)
plgInitScreenOverlay();

if (!ntrConfig->gameHasPlugins)
return;
Expand Down
12 changes: 8 additions & 4 deletions source/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ u32 nightShiftUi() {
int configUpdated = 0;
acquireVideo();
char* entries[11];
int r;
int r = 0;
entries[0] = plgTranslate("Disabled");
entries[1] = plgTranslate("Reduce Blue Light Level 1");
entries[2] = plgTranslate("Reduce Blue Light Level 2");
Expand All @@ -780,10 +780,14 @@ u32 nightShiftUi() {
entries[5] = plgTranslate("Reduce Blue Light Level 5");
entries[6] = plgTranslate("Invert Colors");
entries[7] = plgTranslate("Grayscale");
entries[8] = plgTranslate("Hint: Must be enabled before starting game. Will set CPU to L2+804MHz on New3DS.");
entries[8] = plgTranslate(
"Hint: Must be enabled before "
"starting game. Will set CPU to "
"L2 + 804MHz on New 3DS."
);
while (1) {
blank(0, 0, 320, 240);
r = showMenu(plgTranslate("Screen Filter"), 8, entries);
r = showMenuEx(plgTranslate("Screen Filter"), 9, entries, NULL, r);
if (r == -1) {
break;

Expand Down Expand Up @@ -815,7 +819,7 @@ void screenshotMain(void) {
nsDbgPrint("bmp index is: %d", bmp_index);

if (ntrConfig->isNew3DS) {
plgRegisterMenuEntry(1, plgTranslate("CPU Clock (New3DS Only)"), cpuClockUi);
plgRegisterMenuEntry(1, plgTranslate("CPU Clock (New 3DS)"), cpuClockUi);
}
plgRegisterMenuEntry(1, plgTranslate("Power"), powerMenu);
if (checkBacklightSupported()){
Expand Down

0 comments on commit 61d2df0

Please sign in to comment.