devkitPro / libctru

Homebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)

Home Page:https://libctru.devkitpro.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow choosing between "news:u" and "news:s"

pabmoflo opened this issue · comments

The current news init code defaults to using "news:u" to use the news service. If both services are available, and according to 3dbrew, there is no way to use the "news:s" service calls.

The following code would allow using both services:

Result newsInit(bool useNewsSService) {
	Result res;
	if (AtomicPostIncrement(&newsRefCount)) return 0;
	useNewsS = useNewsSService;
	const char* services = {"news:u", "news:s"};
	res = srvGetServiceHandle(&newsHandle, services[(int)useNewsS]);
	if (R_FAILED(res)) AtomicDecrement(&newsRefCount);
	return res;
}

Or if compatibility is needed:

static bool forceNewsS = false;

void newsForceNewsSInit(bool forceNewsSInit) {
	forceNewsS = forceNewsSInit;
}

Result newsInit(void) {
	Result res = 0;
	if (AtomicPostIncrement(&newsRefCount)) return 0;
	if (!forceNewsS)
		res = srvGetServiceHandle(&newsHandle, "news:u");
	useNewsS = R_FAILED(res) || forceNewsS ;
	if (useNewsS) res = srvGetServiceHandle(&newsHandle, "news:s");
	if (R_FAILED(res)) AtomicDecrement(&newsRefCount);
	return res;
}