From 62c05ea73b102d52400558818617e04652eddfc8 Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sat, 23 Jan 2016 12:47:14 +0100 Subject: [PATCH] Added some missing news:s funcs and updated header. Added some missing news:s funcs and updated header. --- libctru/include/3ds/services/news.h | 51 +++++++++++++++++ libctru/source/services/news.c | 86 +++++++++++++++++++++++++---- 2 files changed, 125 insertions(+), 12 deletions(-) diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h index 5c265f6..15c54ae 100644 --- a/libctru/include/3ds/services/news.h +++ b/libctru/include/3ds/services/news.h @@ -4,6 +4,22 @@ */ #pragma once +/// Notification header data. +typedef struct { + bool dataSet; + bool unread; + bool enableJPEG; + bool isSpotPass; + bool isOptedOut; + u8 unkData[3]; + u64 processID; + u8 unkData2[8]; + u64 jumpParam; + u8 unkData3[8]; + u64 time; + u16 title[32]; +} NotificationHeader; + /// Initializes NEWS. Result newsInit(void); @@ -21,3 +37,38 @@ void newsExit(void); * @param jpeg Whether the image is a JPEG or not. */ Result NEWS_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg); + +/** + * @brief Gets current total notifications number. + * @param num Pointer where total number will be saved. + */ +Result NEWS_GetTotalNotifications(u32* num); + +/** + * @brief Sets a custom header for a specific notification. + * @param news_id Identification number of the notification. + * @param header Pointer to notification header to set. + */ +Result NEWS_SetNotificationHeader(u32 news_id, const NotificationHeader* header); + +/** + * @brief Gets the header of a specific notification. + * @param news_id Identification number of the notification. + * @param header Pointer where header of the notification will be saved. + */ +Result NEWS_GetNotificationHeader(u32 news_id, NotificationHeader* header); + +/** + * @brief Gets the message of a specific notification. + * @param news_id Identification number of the notification. + * @param message Pointer where UTF-16 message of the notification will be saved. + */ +Result NEWS_GetNotificationMessage(u32 news_id, u16* message); + +/** + * @brief Gets the image of a specific notification. + * @param news_id Identification number of the notification. + * @param buffer Pointer where MPO image of the notification will be saved. + * @param size Pointer where size of the image data will be saved in bytes. + */ +Result NEWS_GetNotificationImage(u32 news_id, void* buffer, u32* size); \ No newline at end of file diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c index c2108cc..206d1b4 100644 --- a/libctru/source/services/news.c +++ b/libctru/source/services/news.c @@ -8,18 +8,6 @@ #include <3ds/services/news.h> #include <3ds/ipc.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; static int newsRefCount; static bool useNewsS; @@ -75,3 +63,77 @@ Result NEWS_AddNotification(const u16* title, u32 titleLength, const u16* messag return (Result)cmdbuf[1]; } + +Result NEWS_GetTotalNotifications(u32* num) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x5,0,0); + + if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; + + *num = cmdbuf[2]; + return (Result)cmdbuf[1]; +} + +Result NEWS_SetNotificationHeader(u32 news_id, const NotificationHeader* header) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x7,2,2); + cmdbuf[1] = news_id; + cmdbuf[2] = sizeof(NotificationHeader); + cmdbuf[3] = IPC_Desc_Buffer(sizeof(NotificationHeader),IPC_BUFFER_R); + cmdbuf[4] = (u32)header; + + if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; + return (Result)cmdbuf[1]; +} + +Result NEWS_GetNotificationHeader(u32 news_id, NotificationHeader* header) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xB,2,2); + cmdbuf[1] = news_id; + cmdbuf[2] = sizeof(NotificationHeader); + cmdbuf[3] = IPC_Desc_Buffer(sizeof(NotificationHeader),IPC_BUFFER_W); + cmdbuf[4] = (u32)header; + + if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; + return (Result)cmdbuf[1]; +} + +Result NEWS_GetNotificationMessage(u32 news_id, u16* message) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xC,2,2); + cmdbuf[1] = news_id; + cmdbuf[2] = 0x1780; // Default size used by Notifications Applet + cmdbuf[3] = IPC_Desc_Buffer((size_t)0x1780,IPC_BUFFER_W); + cmdbuf[4] = (u32)message; + + if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; + return (Result)cmdbuf[1]; +} + +Result NEWS_GetNotificationImage(u32 news_id, void* buffer, u32* size) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xD,2,2); + cmdbuf[1] = news_id; + cmdbuf[2] = 0x10000; // Default size used by Notifications Applet + cmdbuf[3] = IPC_Desc_Buffer((size_t)0x10000,IPC_BUFFER_W); + cmdbuf[4] = (u32)buffer; + + if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; + *size = cmdbuf[2]; + return (Result)cmdbuf[1]; +} \ No newline at end of file