From 70b658ae74c33c76a8f292a1536b140b9d999409 Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Fri, 22 Jan 2016 23:59:02 +0100 Subject: [PATCH 1/4] Added some missing news:s functions. Added some missing news:s functions. --- libctru/include/3ds/services/news.h | 48 ++++++++++++++++ libctru/source/services/news.c | 86 +++++++++++++++++++++++++---- 2 files changed, 122 insertions(+), 12 deletions(-) diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h index 5c265f6..d6986da 100644 --- a/libctru/include/3ds/services/news.h +++ b/libctru/include/3ds/services/news.h @@ -4,6 +4,19 @@ */ #pragma once +/// Notification header data. +typedef struct { + bool dataSet; + bool unread; + bool enableJPEG; + u8 unkFlag1; + u8 unkFlag2; + u64 processID; + u8 unkData[24]; + u64 time; + u16 title[32]; +} NotificationHeader; + /// Initializes NEWS. Result newsInit(void); @@ -21,3 +34,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 Notification header to set. + */ +Result NEWS_SetNotificationHeader(u32 news_id, 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 message 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 id, u8* buffer, u32* size); diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c index c2108cc..2622e3e 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, 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, u8* 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]; +} From 0e8d7b98f0666801ab65f630c69941ff635c0cee Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sat, 23 Jan 2016 00:01:16 +0100 Subject: [PATCH 2/4] Update news.h --- libctru/include/3ds/services/news.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h index d6986da..8a68c29 100644 --- a/libctru/include/3ds/services/news.h +++ b/libctru/include/3ds/services/news.h @@ -65,7 +65,7 @@ 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 message Pointer where MPO image of the notification will be saved. + * @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 id, u8* buffer, u32* size); From aca0b1a82940adaa267fb7b1490305c27fc1805a Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sat, 23 Jan 2016 00:19:30 +0100 Subject: [PATCH 3/4] Syntax changes. Syntax changes. --- libctru/include/3ds/services/news.h | 6 +++--- libctru/source/services/news.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h index 8a68c29..501d03b 100644 --- a/libctru/include/3ds/services/news.h +++ b/libctru/include/3ds/services/news.h @@ -44,9 +44,9 @@ Result NEWS_GetTotalNotifications(u32* num); /** * @brief Sets a custom header for a specific notification. * @param news_id Identification number of the notification. - * @param header Notification header to set. + * @param header Pointer to the notification header to set. */ -Result NEWS_SetNotificationHeader(u32 news_id, NotificationHeader header); +Result NEWS_SetNotificationHeader(u32 news_id, const NotificationHeader* header); /** * @brief Gets the header of a specific notification. @@ -68,4 +68,4 @@ Result NEWS_GetNotificationMessage(u32 news_id, u16* message); * @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 id, u8* buffer, u32* size); +Result NEWS_GetNotificationImage(u32 news_id, void* buffer, u32* size); diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c index 2622e3e..93e50a9 100644 --- a/libctru/source/services/news.c +++ b/libctru/source/services/news.c @@ -77,7 +77,7 @@ Result NEWS_GetTotalNotifications(u32* num) return (Result)cmdbuf[1]; } -Result NEWS_SetNotificationHeader(u32 news_id, NotificationHeader header) +Result NEWS_SetNotificationHeader(u32 news_id, const NotificationHeader* header) { Result ret = 0; u32 *cmdbuf = getThreadCommandBuffer(); @@ -86,7 +86,7 @@ Result NEWS_SetNotificationHeader(u32 news_id, NotificationHeader header) cmdbuf[1] = news_id; cmdbuf[2] = sizeof(NotificationHeader); cmdbuf[3] = IPC_Desc_Buffer(sizeof(NotificationHeader),IPC_BUFFER_R); - cmdbuf[4] = (u32)&header; + cmdbuf[4] = (u32)header; if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret; return (Result)cmdbuf[1]; From 057267694cf58bb347d48fda2bedc118d917d1c4 Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sat, 23 Jan 2016 00:21:17 +0100 Subject: [PATCH 4/4] Using void* instead of u8* Using void* instead of u8* --- libctru/source/services/news.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c index 93e50a9..0cf5719 100644 --- a/libctru/source/services/news.c +++ b/libctru/source/services/news.c @@ -122,7 +122,7 @@ Result NEWS_GetNotificationMessage(u32 news_id, u16* message) return (Result)cmdbuf[1]; } -Result NEWS_GetNotificationImage(u32 news_id, u8* buffer, u32* size) +Result NEWS_GetNotificationImage(u32 news_id, void* buffer, u32* size) { Result ret = 0; u32 *cmdbuf = getThreadCommandBuffer();