Added some missing news:s funcs and updated header.

Added some missing news:s funcs and updated header.
This commit is contained in:
Rinnegatamante 2016-01-23 12:47:14 +01:00
parent b364790a9a
commit 62c05ea73b
2 changed files with 125 additions and 12 deletions

View File

@ -4,6 +4,22 @@
*/ */
#pragma once #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. /// Initializes NEWS.
Result newsInit(void); Result newsInit(void);
@ -21,3 +37,38 @@ void newsExit(void);
* @param jpeg Whether the image is a JPEG or not. * @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); 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);

View File

@ -8,18 +8,6 @@
#include <3ds/services/news.h> #include <3ds/services/news.h>
#include <3ds/ipc.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 Handle newsHandle;
static int newsRefCount; static int newsRefCount;
static bool useNewsS; static bool useNewsS;
@ -75,3 +63,77 @@ Result NEWS_AddNotification(const u16* title, u32 titleLength, const u16* messag
return (Result)cmdbuf[1]; 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];
}