Skip to content

Commit a482822

Browse files
joel16fincs
authored andcommitted
Fix a few FRD commands and minor consistency changes (#411)
1 parent 14fdf2d commit a482822

2 files changed

Lines changed: 86 additions & 91 deletions

File tree

  • libctru

libctru/include/3ds/services/frd.h

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#pragma once
66
#include <3ds.h>
77

8-
#define FRIEND_SCREEN_NAME_SIZE 0x16 // 11 (0x16 because UTF-16)
9-
#define FRIEND_COMMENT_SIZE 0x22 // 16 (0x21 because UTF-16 + null character)
10-
#define FRIEND_LIST_SIZE 0x64 // 100 (Max. number of friends)
8+
#define FRIEND_SCREEN_NAME_SIZE 0xB ///< 11-byte UTF-16 screen name
9+
#define FRIEND_COMMENT_SIZE 0x21 ///< 33-byte UTF-16 comment
10+
#define FRIEND_LIST_SIZE 0x64 ///< 100 (Max number of friends)
1111

1212
#pragma pack(push, 1)
1313

@@ -26,7 +26,6 @@ typedef struct
2626
u32 version;
2727
u32 unk;
2828
} TitleData;
29-
3029
/// Structure containing basic Mii information.
3130
typedef struct
3231
{
@@ -51,11 +50,11 @@ typedef struct
5150
/// Friend profile data
5251
typedef struct
5352
{
54-
u8 region; // The region code for the hardware.
55-
u8 country; // Country code.
56-
u8 area; // Area code.
57-
u8 language; // Language code.
58-
u8 platform; // Platform code.
53+
u8 region; ///< The region code for the hardware.
54+
u8 country; ///< Country code.
55+
u8 area; ///< Area code.
56+
u8 language; ///< Language code.
57+
u8 platform; ///< Platform code.
5958
u32 padding;
6059
} FriendProfile;
6160

@@ -80,15 +79,15 @@ typedef struct
8079
/// Enum to use with FRD_GetNotificationEvent
8180
typedef enum
8281
{
83-
USER_WENT_ONLINE = 1, // Self went online
84-
USER_WENT_OFFLINE, // Self went offline
85-
FRIEND_WENT_ONLINE, // Friend Went Online
86-
FRIEND_UPDATED_PRESENCE, // Friend Presence changed
87-
FRIEND_UPDATED_MII, // Friend Mii changed
88-
FRIEND_UPDATED_PROFILE, // Friend Profile changed
89-
FRIEND_WENT_OFFLINE, // Friend went offline
90-
FRIEND_REGISTERED_USER, // Friend registered self as friend
91-
FRIEND_SENT_INVITATION // Friend Sent invitation
82+
USER_WENT_ONLINE = 1, ///< Self went online
83+
USER_WENT_OFFLINE, ///< Self went offline
84+
FRIEND_WENT_ONLINE, ///< Friend Went Online
85+
FRIEND_UPDATED_PRESENCE, ///< Friend Presence changed
86+
FRIEND_UPDATED_MII, ///< Friend Mii changed
87+
FRIEND_UPDATED_PROFILE, ///< Friend Profile changed
88+
FRIEND_WENT_OFFLINE, ///< Friend went offline
89+
FRIEND_REGISTERED_USER, ///< Friend registered self as friend
90+
FRIEND_SENT_INVITATION ///< Friend Sent invitation
9291
} NotificationTypes;
9392

9493
/// Initializes FRD service.
@@ -145,7 +144,7 @@ Result FRD_GetMyProfile(FriendProfile *profile);
145144
* @param name Pointer to write the current user's screen name to.
146145
* @param max_size Max size of the screen name.
147146
*/
148-
Result FRD_GetMyScreenName(char *name, u32 max_size);
147+
Result FRD_GetMyScreenName(char *name, size_t max_size);
149148

150149
/**
151150
* @brief Gets the current user's Mii data.
@@ -170,59 +169,55 @@ Result FRD_GetMyFavoriteGame(u64 *titleId);
170169
* @param comment Pointer to write the current user's comment to.
171170
* @param max_size Max size of the comment.
172171
*/
173-
Result FRD_GetMyComment(char *comment, u32 max_size);
172+
Result FRD_GetMyComment(char *comment, size_t max_size);
174173

175174
/**
176-
* @brief Gets the current user's friend key list
175+
* @brief Gets the current user's friend key list.
177176
* @param friendKeyList Pointer to write the friend key list to.
178177
* @param num Stores the number of friend keys obtained.
179178
* @param offset The index of the friend key to start with.
180-
* @param count Number of entries to read (max is FRIEND_LIST_SIZE).
179+
* @param size Size of the friend key list. (FRIEND_LIST_SIZE)
181180
*/
182-
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 count);
181+
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 size);
183182

184183
/**
185-
* @brief Gets current user's friends' Mii data
186-
* @param miis Pointer to output the Miis to.
187-
* @param keys Pointer to the friend key list.
188-
* @param offset Starting offset.
189-
* @param count Mii count.
184+
* @brief Gets the current user's friends' Mii data.
185+
* @param miiDataList Pointer to write Mii data to.
186+
* @param friendKeyList Pointer to FriendKeys.
187+
* @param size Number of Friendkeys.
190188
*/
191-
Result FRD_GetFriendMii(MiiData *miis, const FriendKey *keys, u32 offset, u32 count);
189+
Result FRD_GetFriendMii(MiiData *miiDataList, const FriendKey *friendKeyList, size_t size);
192190

193191
/**
194-
* @brief Get current user's friends' profile data.
192+
* @brief Get the current user's friends' profile data.
195193
* @param profile Pointer to write profile data to.
196-
* @param keys Pointer to the friend key list.
197-
* @param offset Starting offset.
198-
* @param count Profile count.
194+
* @param friendKeyList Pointer to FriendKeys.
195+
* @param size Number of FriendKeys.
199196
*/
200-
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *keys, u32 offset, u32 count);
197+
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *friendKeyList, size_t size);
201198

202199
/**
203-
* @brief Get current user's friends' playing game.
200+
* @brief Get the current user's friends' playing game.
204201
* @param desc Pointer to write Game Description data to.
205-
* @param keys Pointer to the friend key list.
206-
* @param offset Starting offset.
207-
* @param count Entry count.
202+
* @param friendKeyList Pointer to FriendKeys,
203+
* @param size Number Of FriendKeys.
208204
*/
209-
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count);
205+
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *friendKeyList, size_t size);
210206

211207
/**
212-
* @brief Get current user's friends' favourite game.
208+
* @brief Get the current user's friends' favourite game.
213209
* @param desc Pointer to write Game Description data to.
214-
* @param keys Pointer to the friend key list.
215-
* @param offset Starting offset.
216-
* @param count Entry count.
210+
* @param friendKeyList Pointer to FriendKeys,
211+
* @param count Number Of FriendKeys.
217212
*/
218-
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count);
213+
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *friendKeyList, u32 count);
219214

220215
/**
221-
* @brief Gets whether a friend code is included on the user's friend list.
222-
* @param friendCode Friend code to check.
223-
* @param isFromList Pointer to output the result to.
216+
* @brief Gets whether a friend key is included in the current user's friend list.
217+
* @param friendKeyList Pointer to a list of friend keys.
218+
* @param isFromList Pointer to a write the friendship status to.
224219
*/
225-
Result FRD_IsIncludedInFriendList(u64 friendCode, bool *isFromList);
220+
Result FRD_IsInFriendList(FriendKey *friendKeyList, bool *isFromList);
226221

227222
/**
228223
* @brief Updates the game mode description string.
@@ -239,10 +234,10 @@ Result FRD_AttachToEventNotification(Handle event);
239234
/**
240235
* @brief Get Latest Event Notification
241236
* @param event Pointer to write recieved notification event struct to.
242-
* @param size Number of events
237+
* @param count Number of events
243238
* @param recievedNotifCount Number of notification reccieved.
244239
*/
245-
Result FRD_GetEventNotification(NotificationEvent *event, u32 size, u32 *recievedNotifCount);
240+
Result FRD_GetEventNotification(NotificationEvent *event, u32 count, u32 *recievedNotifCount);
246241

247242
/**
248243
* @brief Returns the friend code using the given principal ID.

libctru/source/services/frd.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Result FRD_GetMyPreference(bool *isPublicMode, bool *isShowGameName, bool *isSho
142142

143143
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
144144

145-
*isPublicMode = cmdbuf[2] & 0x1; // Public mode
146-
*isShowGameName = cmdbuf[3] & 0x1; // Show current game
147-
*isShowPlayedGame = cmdbuf[4] & 0x1; // Show game history.
145+
*isPublicMode = cmdbuf[2] & 0xFF; // Public mode
146+
*isShowGameName = cmdbuf[3] & 0xFF; // Show current game
147+
*isShowPlayedGame = cmdbuf[4] & 0xFF; // Show game history.
148148

149149
return (Result)cmdbuf[1];
150150
}
@@ -163,7 +163,7 @@ Result FRD_GetMyProfile(FriendProfile *profile)
163163
return (Result)cmdbuf[1];
164164
}
165165

166-
Result FRD_GetMyScreenName(char *name, u32 max_size)
166+
Result FRD_GetMyScreenName(char *name, size_t max_size)
167167
{
168168
Result ret = 0;
169169
u32 *cmdbuf = getThreadCommandBuffer();
@@ -219,7 +219,7 @@ Result FRD_GetMyFavoriteGame(u64 *titleId)
219219
return (Result)cmdbuf[1];
220220
}
221221

222-
Result FRD_GetMyComment(char *comment, u32 max_size)
222+
Result FRD_GetMyComment(char *comment, size_t max_size)
223223
{
224224
Result ret = 0;
225225
u32 *cmdbuf = getThreadCommandBuffer();
@@ -233,15 +233,15 @@ Result FRD_GetMyComment(char *comment, u32 max_size)
233233
return (Result)cmdbuf[1];
234234
}
235235

236-
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 count)
236+
Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32 size)
237237
{
238238
Result ret = 0;
239239
u32 *cmdbuf = getThreadCommandBuffer();
240240

241241
cmdbuf[0] = IPC_MakeHeader(0x11,2,0); // 0x110080
242242
cmdbuf[1] = offset;
243-
cmdbuf[2] = count;
244-
cmdbuf[64] = (count << 18) | 2;
243+
cmdbuf[2] = size;
244+
cmdbuf[64] = (size << 18) | 2;
245245
cmdbuf[65] = (u32)friendKeyList;
246246

247247
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
@@ -251,91 +251,91 @@ Result FRD_GetFriendKeyList(FriendKey *friendKeyList, u32 *num, u32 offset, u32
251251
return (Result)cmdbuf[1];
252252
}
253253

254-
Result FRD_GetFriendMii(MiiData *miis, const FriendKey *keys, u32 offset, u32 count)
254+
Result FRD_GetFriendMii(MiiData *miiDataList, const FriendKey *friendKeyList, size_t size)
255255
{
256256
Result ret = 0;
257257
u32 *cmdbuf = getThreadCommandBuffer();
258258

259259
cmdbuf[0] = IPC_MakeHeader(0x14,1,4); // 0x140044
260-
cmdbuf[1] = offset;
261-
cmdbuf[2] = (count << 18) | 2;
262-
cmdbuf[3] = (u32)keys;
263-
cmdbuf[4] = IPC_Desc_Buffer(count * sizeof(MiiData), IPC_BUFFER_W);
264-
cmdbuf[5] = (u32)miis;
260+
cmdbuf[1] = size;
261+
cmdbuf[2] = (size << 18) | 2;
262+
cmdbuf[3] = (u32)friendKeyList;
263+
cmdbuf[4] = IPC_Desc_Buffer(size * sizeof(MiiData), IPC_BUFFER_W);
264+
cmdbuf[5] = (u32)miiDataList;
265265

266-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
266+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
267267

268268
return (Result)cmdbuf[1];
269269
}
270270

271-
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *keys, u32 offset, u32 count)
271+
Result FRD_GetFriendProfile(FriendProfile *profile, const FriendKey *friendKeyList, size_t size)
272272
{
273273
Result ret = 0;
274274
u32 *cmdbuf = getThreadCommandBuffer();
275275

276276
cmdbuf[0] = IPC_MakeHeader(0x15,1,2); // 0x150042
277-
cmdbuf[1] = offset;
278-
cmdbuf[2] = (count << 18) | 2;
279-
cmdbuf[3] = (u32)keys;
277+
cmdbuf[1] = size;
278+
cmdbuf[2] = (size << 18) | 2;
279+
cmdbuf[3] = (u32)friendKeyList;
280280

281281
u32 *staticbuf = getThreadStaticBuffers();
282-
staticbuf[0] = (count << 17) | 2;
282+
staticbuf[0] = (size << 17)|2;
283283
staticbuf[1] = (u32)profile;
284284

285-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
285+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
286286

287287
return (Result)cmdbuf[1];
288288
}
289289

290-
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count)
290+
Result FRD_GetFriendPlayingGame(GameDescription *desc, const FriendKey *friendKeyList, size_t size)
291291
{
292292
Result ret = 0;
293293
u32 *cmdbuf = getThreadCommandBuffer();
294294

295295
cmdbuf[0] = IPC_MakeHeader(0x18,1,4); // 0x180044
296-
cmdbuf[1] = offset;
297-
cmdbuf[2] = (count << 18) | 2;
298-
cmdbuf[3] = (u32)keys;
299-
cmdbuf[4] = IPC_Desc_Buffer(count * sizeof(GameDescription), IPC_BUFFER_W);
296+
cmdbuf[1] = size;
297+
cmdbuf[2] = (size << 18) | 2;
298+
cmdbuf[3] = (u32)friendKeyList;
299+
cmdbuf[4] = IPC_Desc_Buffer(size * sizeof(GameDescription), IPC_BUFFER_W);
300300
cmdbuf[5] = (u32)desc;
301301

302302
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
303303

304304
return (Result)cmdbuf[1];
305305
}
306306

307-
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *keys, u32 offset, u32 count)
307+
Result FRD_GetFriendFavouriteGame(GameDescription *desc, const FriendKey *friendKeyList, u32 count)
308308
{
309309
Result ret = 0;
310310
u32 *cmdbuf = getThreadCommandBuffer();
311311

312312
cmdbuf[0] = IPC_MakeHeader(0x19,1,2); // 0x190042
313-
cmdbuf[1] = offset;
313+
cmdbuf[1] = count;
314314
cmdbuf[2] = (count << 18) | 2;
315-
cmdbuf[3] = (u32)keys;
315+
cmdbuf[3] = (u32)friendKeyList;
316316

317317
u32 *staticbuf = getThreadStaticBuffers();
318318

319319
staticbuf[0] = (count << 18) | 2;
320320
staticbuf[1] = (u32)desc;
321321

322-
if(R_FAILED(svcSendSyncRequest(frdHandle))) return ret;
322+
if (R_FAILED(svcSendSyncRequest(frdHandle))) return ret;
323323

324324
return (Result)cmdbuf[1];
325325
}
326326

327-
Result FRD_IsIncludedInFriendList(u64 friendCode, bool *isFromList)
327+
Result FRD_IsInFriendList(FriendKey *friendKeyList, bool *isFromList)
328328
{
329329
Result ret = 0;
330330
u32 *cmdbuf = getThreadCommandBuffer();
331331

332332
cmdbuf[0] = IPC_MakeHeader(0x1B,2,0); // 0x1B0080
333-
cmdbuf[1] = (u32)(friendCode & 0xFFFFFFFF);
334-
cmdbuf[2] = (u32)(friendCode >> 32);
333+
cmdbuf[1] = (u32)(friendKeyList->localFriendCode & 0xFFFFFFFF);
334+
cmdbuf[2] = (u32)(friendKeyList->localFriendCode >> 32);
335335

336336
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
337337

338-
*isFromList = cmdbuf[2] & 0x1;
338+
*isFromList = cmdbuf[2] & 0xFF;
339339

340340
return (Result)cmdbuf[1];
341341
}
@@ -367,24 +367,24 @@ Result FRD_AttachToEventNotification(Handle event)
367367
cmdbuf[1] = 0;
368368
cmdbuf[2] = (u32)event;
369369

370-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
370+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
371371

372372
return (Result)cmdbuf[1];
373373
}
374374

375-
Result FRD_GetEventNotification(NotificationEvent *event, u32 size, u32 *recievedNotifCount)
375+
Result FRD_GetEventNotification(NotificationEvent *event, u32 count, u32 *recievedNotifCount)
376376
{
377377
Result ret = 0;
378378

379379
u32 *cmdbuf = getThreadCommandBuffer();
380380
cmdbuf[0] = IPC_MakeHeader(0x22,1,0); //0x220040
381-
cmdbuf[1] = size;
381+
cmdbuf[1] = count;
382382

383383
u32 *staticbuf = getThreadStaticBuffers();
384-
staticbuf[0] = 0x60000 * size | 2;
384+
staticbuf[0] = 0x60000 * count | 2;
385385
staticbuf[1] = (u32)event;
386386

387-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
387+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
388388

389389
*recievedNotifCount = cmdbuf[3];
390390

@@ -461,7 +461,7 @@ Result FRD_AddFriendOnline(Handle event, u32 principalId)
461461
cmdbuf[2] = 0;
462462
cmdbuf[3] = (u32)event;
463463

464-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
464+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
465465

466466
return (Result)cmdbuf[1];
467467
}
@@ -475,7 +475,7 @@ Result FRD_RemoveFriend(u32 principalId, u64 localFriendCode)
475475
cmdbuf[2] = localFriendCode & 0xffffffff;
476476
cmdbuf[3] = (localFriendCode >> 32) & 0xffffffff;
477477

478-
if(R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
478+
if (R_FAILED(ret = svcSendSyncRequest(frdHandle))) return ret;
479479

480480
return cmdbuf[1];
481481
}

0 commit comments

Comments
 (0)