Fix a few FRD commands and minor consistency changes (#411)

This commit is contained in:
Joel 2019-01-01 17:35:12 -06:00 committed by fincs
parent 14fdf2dee4
commit a482822fb8
2 changed files with 86 additions and 91 deletions

View File

@ -5,9 +5,9 @@
#pragma once
#include <3ds.h>
#define FRIEND_SCREEN_NAME_SIZE 0x16 // 11 (0x16 because UTF-16)
#define FRIEND_COMMENT_SIZE 0x22 // 16 (0x21 because UTF-16 + null character)
#define FRIEND_LIST_SIZE 0x64 // 100 (Max. number of friends)
#define FRIEND_SCREEN_NAME_SIZE 0xB ///< 11-byte UTF-16 screen name
#define FRIEND_COMMENT_SIZE 0x21 ///< 33-byte UTF-16 comment
#define FRIEND_LIST_SIZE 0x64 ///< 100 (Max number of friends)
#pragma pack(push, 1)
@ -26,7 +26,6 @@ typedef struct
u32 version;
u32 unk;
} TitleData;
/// Structure containing basic Mii information.
typedef struct
{
@ -51,11 +50,11 @@ typedef struct
/// Friend profile data
typedef struct
{
u8 region; // The region code for the hardware.
u8 country; // Country code.
u8 area; // Area code.
u8 language; // Language code.
u8 platform; // Platform code.
u8 region; ///< The region code for the hardware.
u8 country; ///< Country code.
u8 area; ///< Area code.
u8 language; ///< Language code.
u8 platform; ///< Platform code.
u32 padding;
} FriendProfile;
@ -80,15 +79,15 @@ typedef struct
/// Enum to use with FRD_GetNotificationEvent
typedef enum
{
USER_WENT_ONLINE = 1, // Self went online
USER_WENT_OFFLINE, // Self went offline
FRIEND_WENT_ONLINE, // Friend Went Online
FRIEND_UPDATED_PRESENCE, // Friend Presence changed
FRIEND_UPDATED_MII, // Friend Mii changed
FRIEND_UPDATED_PROFILE, // Friend Profile changed
FRIEND_WENT_OFFLINE, // Friend went offline
FRIEND_REGISTERED_USER, // Friend registered self as friend
FRIEND_SENT_INVITATION // Friend Sent invitation
USER_WENT_ONLINE = 1, ///< Self went online
USER_WENT_OFFLINE, ///< Self went offline
FRIEND_WENT_ONLINE, ///< Friend Went Online
FRIEND_UPDATED_PRESENCE, ///< Friend Presence changed
FRIEND_UPDATED_MII, ///< Friend Mii changed
FRIEND_UPDATED_PROFILE, ///< Friend Profile changed
FRIEND_WENT_OFFLINE, ///< Friend went offline
FRIEND_REGISTERED_USER, ///< Friend registered self as friend
FRIEND_SENT_INVITATION ///< Friend Sent invitation
} NotificationTypes;
/// Initializes FRD service.
@ -145,7 +144,7 @@ Result FRD_GetMyProfile(FriendProfile *profile);
* @param name Pointer to write the current user's screen name to.
* @param max_size Max size of the screen name.
*/
Result FRD_GetMyScreenName(char *name, u32 max_size);
Result FRD_GetMyScreenName(char *name, size_t max_size);
/**
* @brief Gets the current user's Mii data.
@ -170,59 +169,55 @@ Result FRD_GetMyFavoriteGame(u64 *titleId);
* @param comment Pointer to write the current user's comment to.
* @param max_size Max size of the comment.
*/
Result FRD_GetMyComment(char *comment, u32 max_size);
Result FRD_GetMyComment(char *comment, size_t max_size);
/**
* @brief Gets the current user's friend key list
* @brief Gets the current user's friend key list.
* @param friendKeyList Pointer to write the friend key list to.
* @param num Stores the number of friend keys obtained.
* @param offset The index of the friend key to start with.
* @param count Number of entries to read (max is FRIEND_LIST_SIZE).
* @param size Size of the friend key list. (FRIEND_LIST_SIZE)
*/
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 count);
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 size);
/**
* @brief Gets current user's friends' Mii data
* @param miis Pointer to output the Miis to.
* @param keys Pointer to the friend key list.
* @param offset Starting offset.
* @param count Mii count.
* @brief Gets the current user's friends' Mii data.
* @param miiDataList Pointer to write Mii data to.
* @param friendKeyList Pointer to FriendKeys.
* @param size Number of Friendkeys.
*/
Result FRD_GetFriendMii(MiiData *miis, const FriendKey *keys, u32 offset, u32 count);
Result FRD_GetFriendMii(MiiData *miiDataList, const FriendKey *friendKeyList, size_t size);
/**
* @brief Get current user's friends' profile data.
* @brief Get the current user's friends' profile data.
* @param profile Pointer to write profile data to.
* @param keys Pointer to the friend key list.
* @param offset Starting offset.
* @param count Profile count.
* @param friendKeyList Pointer to FriendKeys.
* @param size Number of FriendKeys.
*/
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *keys, u32 offset, u32 count);
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *friendKeyList, size_t size);
/**
* @brief Get current user's friends' playing game.
* @brief Get the current user's friends' playing game.
* @param desc Pointer to write Game Description data to.
* @param keys Pointer to the friend key list.
* @param offset Starting offset.
* @param count Entry count.
* @param friendKeyList Pointer to FriendKeys,
* @param size Number Of FriendKeys.
*/
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count);
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *friendKeyList, size_t size);
/**
* @brief Get current user's friends' favourite game.
* @brief Get the current user's friends' favourite game.
* @param desc Pointer to write Game Description data to.
* @param keys Pointer to the friend key list.
* @param offset Starting offset.
* @param count Entry count.
* @param friendKeyList Pointer to FriendKeys,
* @param count Number Of FriendKeys.
*/
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count);
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *friendKeyList, u32 count);
/**
* @brief Gets whether a friend code is included on the user's friend list.
* @param friendCode Friend code to check.
* @param isFromList Pointer to output the result to.
* @brief Gets whether a friend key is included in the current user's friend list.
* @param friendKeyList Pointer to a list of friend keys.
* @param isFromList Pointer to a write the friendship status to.
*/
Result FRD_IsIncludedInFriendList(u64 friendCode, bool *isFromList);
Result FRD_IsInFriendList(FriendKey *friendKeyList, bool *isFromList);
/**
* @brief Updates the game mode description string.
@ -239,10 +234,10 @@ Result FRD_AttachToEventNotification(Handle event);
/**
* @brief Get Latest Event Notification
* @param event Pointer to write recieved notification event struct to.
* @param size Number of events
* @param count Number of events
* @param recievedNotifCount Number of notification reccieved.
*/
Result FRD_GetEventNotification(NotificationEvent *event, u32 size, u32 *recievedNotifCount);
Result FRD_GetEventNotification(NotificationEvent *event, u32 count, u32 *recievedNotifCount);
/**
* @brief Returns the friend code using the given principal ID.

View File

@ -142,9 +142,9 @@ Result FRD_GetMyPreference(bool *isPublicMode, bool *isShowGameName, bool *isSho
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
*isPublicMode = cmdbuf[2] & 0x1; // Public mode
*isShowGameName = cmdbuf[3] & 0x1; // Show current game
*isShowPlayedGame = cmdbuf[4] & 0x1; // Show game history.
*isPublicMode = cmdbuf[2] & 0xFF; // Public mode
*isShowGameName = cmdbuf[3] & 0xFF; // Show current game
*isShowPlayedGame = cmdbuf[4] & 0xFF; // Show game history.
return (Result)cmdbuf[1];
}
@ -163,7 +163,7 @@ Result FRD_GetMyProfile(FriendProfile *profile)
return (Result)cmdbuf[1];
}
Result FRD_GetMyScreenName(char *name, u32 max_size)
Result FRD_GetMyScreenName(char *name, size_t max_size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
@ -219,7 +219,7 @@ Result FRD_GetMyFavoriteGame(u64 *titleId)
return (Result)cmdbuf[1];
}
Result FRD_GetMyComment(char *comment, u32 max_size)
Result FRD_GetMyComment(char *comment, size_t max_size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
@ -233,15 +233,15 @@ Result FRD_GetMyComment(char *comment, u32 max_size)
return (Result)cmdbuf[1];
}
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 count)
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x11,2,0); // 0x110080
cmdbuf[1] = offset;
cmdbuf[2] = count;
cmdbuf[64] = (count << 18) | 2;
cmdbuf[2] = size;
cmdbuf[64] = (size << 18) | 2;
cmdbuf[65] = (u32)friendKeyList;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
@ -251,52 +251,52 @@ Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32
return (Result)cmdbuf[1];
}
Result FRD_GetFriendMii(MiiData *miis, const FriendKey *keys, u32 offset, u32 count)
Result FRD_GetFriendMii(MiiData *miiDataList, const FriendKey *friendKeyList, size_t size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x14,1,4); // 0x140044
cmdbuf[1] = offset;
cmdbuf[2] = (count << 18) | 2;
cmdbuf[3] = (u32)keys;
cmdbuf[4] = IPC_Desc_Buffer(count * sizeof(MiiData), IPC_BUFFER_W);
cmdbuf[5] = (u32)miis;
cmdbuf[1] = size;
cmdbuf[2] = (size << 18) | 2;
cmdbuf[3] = (u32)friendKeyList;
cmdbuf[4] = IPC_Desc_Buffer(size * sizeof(MiiData), IPC_BUFFER_W);
cmdbuf[5] = (u32)miiDataList;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
return (Result)cmdbuf[1];
}
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *keys, u32 offset, u32 count)
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *friendKeyList, size_t size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x15,1,2); // 0x150042
cmdbuf[1] = offset;
cmdbuf[2] = (count << 18) | 2;
cmdbuf[3] = (u32)keys;
cmdbuf[1] = size;
cmdbuf[2] = (size << 18) | 2;
cmdbuf[3] = (u32)friendKeyList;
u32 *staticbuf = getThreadStaticBuffers();
staticbuf[0] = (count << 17) | 2;
staticbuf[0] = (size << 17)|2;
staticbuf[1] = (u32)profile;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
return (Result)cmdbuf[1];
}
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count)
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *friendKeyList, size_t size)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x18,1,4); // 0x180044
cmdbuf[1] = offset;
cmdbuf[2] = (count << 18) | 2;
cmdbuf[3] = (u32)keys;
cmdbuf[4] = IPC_Desc_Buffer(count * sizeof(GameDescription), IPC_BUFFER_W);
cmdbuf[1] = size;
cmdbuf[2] = (size << 18) | 2;
cmdbuf[3] = (u32)friendKeyList;
cmdbuf[4] = IPC_Desc_Buffer(size * sizeof(GameDescription), IPC_BUFFER_W);
cmdbuf[5] = (u32)desc;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
@ -304,38 +304,38 @@ Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *keys, u3
return (Result)cmdbuf[1];
}
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count)
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *friendKeyList, u32 count)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x19,1,2); // 0x190042
cmdbuf[1] = offset;
cmdbuf[1] = count;
cmdbuf[2] = (count << 18) | 2;
cmdbuf[3] = (u32)keys;
cmdbuf[3] = (u32)friendKeyList;
u32 *staticbuf = getThreadStaticBuffers();
staticbuf[0] = (count << 18) | 2;
staticbuf[1] = (u32)desc;
if(R_FAILED(svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(svcSendSyncRequest(frdHandle))) return ret;
return (Result)cmdbuf[1];
}
Result FRD_IsIncludedInFriendList(u64 friendCode, bool *isFromList)
Result FRD_IsInFriendList(FriendKey *friendKeyList, bool *isFromList)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x1B,2,0); // 0x1B0080
cmdbuf[1] = (u32)(friendCode & 0xFFFFFFFF);
cmdbuf[2] = (u32)(friendCode >> 32);
cmdbuf[1] = (u32)(friendKeyList->localFriendCode & 0xFFFFFFFF);
cmdbuf[2] = (u32)(friendKeyList->localFriendCode >> 32);
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
*isFromList = cmdbuf[2] & 0x1;
*isFromList = cmdbuf[2] & 0xFF;
return (Result)cmdbuf[1];
}
@ -367,24 +367,24 @@ Result FRD_AttachToEventNotification(Handle event)
cmdbuf[1] = 0;
cmdbuf[2] = (u32)event;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
return (Result)cmdbuf[1];
}
Result FRD_GetEventNotification(NotificationEvent *event, u32 size, u32 *recievedNotifCount)
Result FRD_GetEventNotification(NotificationEvent *event, u32 count, u32 *recievedNotifCount)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x22,1,0); //0x220040
cmdbuf[1] = size;
cmdbuf[1] = count;
u32 *staticbuf = getThreadStaticBuffers();
staticbuf[0] = 0x60000 * size | 2;
staticbuf[0] = 0x60000 * count | 2;
staticbuf[1] = (u32)event;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
*recievedNotifCount = cmdbuf[3];
@ -461,7 +461,7 @@ Result FRD_AddFriendOnline(Handle event, u32 principalId)
cmdbuf[2] = 0;
cmdbuf[3] = (u32)event;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
return (Result)cmdbuf[1];
}
@ -475,7 +475,7 @@ Result FRD_RemoveFriend(u32 principalId, u64 localFriendCode)
cmdbuf[2] = localFriendCode & 0xffffffff;
cmdbuf[3] = (localFriendCode >> 32) & 0xffffffff;
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
return cmdbuf[1];
}