From 6f37ad03f7c5e4115b4e75771fe201741816288c Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Tue, 14 Apr 2015 09:45:51 -0700 Subject: [PATCH] Add news:u commands. --- libctru/include/3ds.h | 1 + libctru/include/3ds/services/news.h | 22 +++++++++++ libctru/source/services/news.c | 59 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 libctru/include/3ds/services/news.h create mode 100644 libctru/source/services/news.c diff --git a/libctru/include/3ds.h b/libctru/include/3ds.h index 1d8f6fa..91ef308 100644 --- a/libctru/include/3ds.h +++ b/libctru/include/3ds.h @@ -34,6 +34,7 @@ extern "C" { #include <3ds/services/soc.h> #include <3ds/services/mic.h> #include <3ds/services/mvd.h> +#include <3ds/services/news.h> #include <3ds/services/qtm.h> #include <3ds/services/hb.h> diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h new file mode 100644 index 0000000..bf1c825 --- /dev/null +++ b/libctru/include/3ds/services/news.h @@ -0,0 +1,22 @@ +#pragma once + +/* + Requires access to "news:u" service. +*/ + + +Result newsInit(); +Result newsExit(); + +/* NEWSU_AddNotification() +About: Adds a notification to the home menu Notifications applet. + + title UTF-16 title of the notification. + titleLength Number of characters in the title, not including the null-terminator. + title UTF-16 message of the notification, or NULL for no message. + titleLength Number of characters in the message, not including the null-terminator. + image Data of the image to show in the notification, or NULL for no image. + imageSize Size of the image data in bytes. + jpeg Whether the image is a JPEG or not. +*/ +Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg); diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c new file mode 100644 index 0000000..51a8cea --- /dev/null +++ b/libctru/source/services/news.c @@ -0,0 +1,59 @@ +#include +#include <3ds/types.h> +#include <3ds/os.h> +#include <3ds/svc.h> +#include <3ds/srv.h> +#include <3ds/services/news.h> + +typedef struct { + bool dataSet; + bool unread; + bool enableJPEG; + u8 unkFlag1; + u8 unkFlag2; + u64 processID; + u8 unkData[24]; + u64 time; + u16 title[32]; +} NotificationHeader; + +static Handle newsHandle = 0; + +Result newsInit() { + return srvGetServiceHandle(&newsHandle, "news:u"); +} + +Result newsExit() { + return svcCloseHandle(newsHandle); +} + +Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg) +{ + NotificationHeader header = { 0 }; + header.dataSet = true; + header.unread = true; + header.enableJPEG = jpeg; + header.processID = 0; // Filled automatically from FS:GetProgramLaunchInfo + header.time = osGetTime(); + memcpy(header.title, title, (titleLength < 32 ? titleLength + 1 : 32) * sizeof(u16)); + + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x000100C8; + cmdbuf[1] = sizeof(NotificationHeader); + cmdbuf[2] = (messageLength + 1) * sizeof(u16); + cmdbuf[3] = imageSize; + cmdbuf[4] = 0x20; + cmdbuf[5] = 0; // Process ID, Filled automatically by the ARM11 kernel. + cmdbuf[6] = (sizeof(NotificationHeader) << 4) | 10; + cmdbuf[7] = (u32) &header; + cmdbuf[8] = (((messageLength + 1) * sizeof(u16)) << 4) | 10; + cmdbuf[9] = (u32) message; + cmdbuf[10] = (imageSize << 4) | 10; + cmdbuf[11] = (u32) imageData; + + if((ret = svcSendSyncRequest(newsHandle))!=0) return ret; + + return (Result)cmdbuf[1]; +}