Skip to content

Instantly share code, notes, and snippets.

@ZeroSkill1
Created April 16, 2025 07:55
Show Gist options
  • Save ZeroSkill1/a0ee6128e90d9ef998e89708259fb231 to your computer and use it in GitHub Desktop.
Save ZeroSkill1/a0ee6128e90d9ef998e89708259fb231 to your computer and use it in GitHub Desktop.
Handling friends sysmodule logout via NDM
#include "3ds/result.h"
#include "3ds/services/ndm.h"
#include "3ds/svc.h"
#include <3ds/services/frd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <3ds.h>
int main(int argc, char* argv[])
{
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
frdInit(false);
ndmuInit();
Handle event = 0;
Result res = NDMU_EnterExclusiveState(NDM_EXCLUSIVE_STATE_LOCAL_COMMUNICATIONS);
printf("%08lX enter exclusive state\n", res);
if (R_FAILED(svcCreateEvent(&event, RESET_ONESHOT)))
svcBreak(0);
res = FRD_SetNotificationMask(MASK_USER_WENT_OFFLINE);
printf("%08lX set notification mask\n", res);
res = FRD_AttachToEventNotification(event);
printf("%08lX attach notification\n", res);
bool exit = false;
while (1) {
if (exit) break;
Result wres = svcWaitSynchronization(event, 5 * 1000000000LL);
if (R_FAILED(wres))
svcBreak(0);
else if (R_SUCCEEDED(wres) && R_DESCRIPTION(wres) != RD_TIMEOUT) {
NotificationEvent events[10] = { 0 };
u32 numEvents = 0;
res = FRD_GetEventNotification(events, 10, &numEvents);
printf("%08lX got %ld notifs\n", res, numEvents);
for (u32 i = 0; i < numEvents; i++) {
printf("received: %d\n", events[i].type);
if (events[i].type == USER_WENT_OFFLINE)
{
printf("successfully disconnected from friends services\n");
exit = true;
continue;
}
}
}
else {
bool is_online = true;
FRD_IsOnline(&is_online);
if (is_online) {
printf("system is still online, retrying\n");
FRD_Logout(); // just in case
continue;
}
printf("system is no longer online\n");
printf("successfully disconnected from friends services\n");
break;
}
}
// Main loop
while (aptMainLoop())
{
gspWaitForVBlank();
gfxSwapBuffers();
hidScanInput();
// Your code goes here
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
}
res = NDMU_LeaveExclusiveState();
printf("%08lX leave exclusive state\n", res);
svcCloseHandle(event);
frdExit();
ndmuExit();
gfxExit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment