From fa25df27d00316f8c5e20f3900503073f058a35c Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 14 Sep 2019 19:25:54 -0400 Subject: [PATCH] Added support for friendsLa. Added friends.h. --- nx/include/switch.h | 2 + nx/include/switch/applets/friends_la.h | 93 ++++++++++++++++++++++++++ nx/include/switch/services/friends.h | 16 +++++ nx/source/applets/friends_la.c | 75 +++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 nx/include/switch/applets/friends_la.h create mode 100644 nx/include/switch/services/friends.h create mode 100644 nx/source/applets/friends_la.c diff --git a/nx/include/switch.h b/nx/include/switch.h index d2839b48..afdbaaa6 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -93,6 +93,7 @@ extern "C" { #include "switch/services/pctl.h" #include "switch/services/pdm.h" #include "switch/services/grc.h" +#include "switch/services/friends.h" #include "switch/display/binder.h" #include "switch/display/parcel.h" @@ -113,6 +114,7 @@ extern "C" { #include "switch/applets/libapplet.h" #include "switch/applets/album_la.h" +#include "switch/applets/friends_la.h" #include "switch/applets/pctlauth.h" #include "switch/applets/error.h" #include "switch/applets/swkbd.h" diff --git a/nx/include/switch/applets/friends_la.h b/nx/include/switch/applets/friends_la.h new file mode 100644 index 00000000..398fa353 --- /dev/null +++ b/nx/include/switch/applets/friends_la.h @@ -0,0 +1,93 @@ +/** + * @file friends_la.h + * @brief Wrapper for using the MyPage (friends) LibraryApplet. + * @author yellows8 + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../services/friends.h" + +/// Arg type values used with \ref FriendsLaArg. +typedef enum { + FriendsLaArgType_ShowFriendList = 0, ///< ShowFriendList. Launches the applet with the "Friend List" menu initially selected. + FriendsLaArgType_ShowUserDetailInfo = 1, ///< ShowUserDetailInfo + FriendsLaArgType_StartSendingFriendRequest = 2, ///< StartSendingFriendRequest + FriendsLaArgType_ShowMethodsOfSendingFriendRequest = 3, ///< ShowMethodsOfSendingFriendRequest. Launches the applet with the "Add Friend" menu initially selected. + FriendsLaArgType_StartFacedFriendRequest = 4, ///< StartFacedFriendRequest. Launches the applet where the "Search for Local Users" menu is initially shown. Returning from this menu will exit the applet. + FriendsLaArgType_ShowReceivedFriendRequestList = 5, ///< ShowReceivedFriendRequestList. Launches the applet where the "Received Friend Requests" menu is initially shown. Returning from this menu will exit the applet. + FriendsLaArgType_ShowBlockedUserList = 6, ///< ShowBlockedUserList. Launches the applet where the "Blocked-User List" menu is initially shown. Returning from this menu will exit the applet. + FriendsLaArgType_ShowMyProfile = 7, ///< ShowMyProfile. Launches the applet with the "Profile" menu initially selected. ShowMyProfileForHomeMenu is identical to this except for playStartupSound=true. +} FriendsLaArgType; + +/// Arg struct pushed for the applet input storage. +/// The fields following the userID are only set for ::FriendsLaArgType_ShowUserDetailInfo/::FriendsLaArgType_StartSendingFriendRequest, for everything else these are cleared. +typedef struct { + u32 type; ///< \ref FriendsLaArgType + u32 pad; ///< Padding. + union { u128 userID; } PACKED; ///< Account userID. + u64 networkServiceAccountId; ///< NetworkServiceAccountId for the other account. + FriendsInAppScreenName first_inAppScreenName; ///< First InAppScreenName. + FriendsInAppScreenName second_inAppScreenName; ///< Second InAppScreenName. +} FriendsLaArg; + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowFriendList, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaShowFriendList(u128 userID); + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowUserDetailInfo, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + * @param[in] networkServiceAccountId NetworkServiceAccountId for the user to show UserDetailInfo for. + * @param[in] first_inAppScreenName First \ref FriendsInAppScreenName. + * @param[in] second_inAppScreenName Second \ref FriendsInAppScreenName. + */ +Result friendsLaShowUserDetailInfo(u128 userID, u64 networkServiceAccountId, const FriendsInAppScreenName *first_inAppScreenName, const FriendsInAppScreenName *second_inAppScreenName); + +/** + * @brief Launches the applet with ::FriendsLaArgType_StartSendingFriendRequest, the specified input, and playStartupSound=false. On success, this will load the output Result from the output storage. + * @param[in] userID Account userID. + * @param[in] networkServiceAccountId NetworkServiceAccountId to send the friend request to. + * @param[in] first_inAppScreenName First \ref FriendsInAppScreenName. + * @param[in] second_inAppScreenName Second \ref FriendsInAppScreenName. + */ +Result friendsLaStartSendingFriendRequest(u128 userID, u64 networkServiceAccountId, const FriendsInAppScreenName *first_inAppScreenName, const FriendsInAppScreenName *second_inAppScreenName); + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowMethodsOfSendingFriendRequest, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaShowMethodsOfSendingFriendRequest(u128 userID); + +/** + * @brief Launches the applet with ::FriendsLaArgType_StartFacedFriendRequest, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaStartFacedFriendRequest(u128 userID); + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowReceivedFriendRequestList, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaShowReceivedFriendRequestList(u128 userID); + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowBlockedUserList, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaShowBlockedUserList(u128 userID); + +/** + * @brief Launches the applet with ::FriendsLaArgType_ShowMyProfile, the specified input, and playStartupSound=false. + * @param[in] userID Account userID. + */ +Result friendsLaShowMyProfile(u128 userID); + +/** + * @brief Same as \ref friendsLaShowMyProfile except with playStartupSound=true. + * @param[in] userID Account userID. + */ +Result friendsLaShowMyProfileForHomeMenu(u128 userID); + diff --git a/nx/include/switch/services/friends.h b/nx/include/switch/services/friends.h new file mode 100644 index 00000000..ecd09e12 --- /dev/null +++ b/nx/include/switch/services/friends.h @@ -0,0 +1,16 @@ +/** + * @file friend.h + * @brief Friends (friend:*) service IPC header. + * @author yellows8 + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../services/sm.h" + +/// InAppScreenName +typedef struct { + char name[0x40]; ///< UTF-8 string, NUL-terminated. + u64 languageCode; ///< LanguageCode, see set.h. +} FriendsInAppScreenName; + diff --git a/nx/source/applets/friends_la.c b/nx/source/applets/friends_la.c new file mode 100644 index 00000000..e1b11fdd --- /dev/null +++ b/nx/source/applets/friends_la.c @@ -0,0 +1,75 @@ +#include +#include "types.h" +#include "result.h" +#include "services/applet.h" +#include "applets/libapplet.h" +#include "applets/friends_la.h" + +static Result _friendsLaShow(const FriendsLaArg *arg, bool playStartupSound) { + Result rc=0; + Result rc2=0; + size_t readsize=0; + LibAppletArgs commonargs; + + libappletArgsCreate(&commonargs, 0x1); + libappletArgsSetPlayStartupSound(&commonargs, playStartupSound); + + if (arg->type != FriendsLaArgType_StartSendingFriendRequest) + rc = libappletLaunch(AppletId_myPage, &commonargs, arg, sizeof(*arg), NULL, 0, NULL); + else { + rc = libappletLaunch(AppletId_myPage, &commonargs, arg, sizeof(*arg), &rc2, sizeof(rc2), &readsize); + if (R_SUCCEEDED(rc) && readsize!=sizeof(rc2)) rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); + if (R_SUCCEEDED(rc)) rc = rc2; + } + + return rc; +} + +static Result _friendsLaShowSimple(FriendsLaArgType type, u128 userID, bool playStartupSound) { + FriendsLaArg arg = {.type = type, .userID = userID}; + + return _friendsLaShow(&arg, playStartupSound); +} + +static Result _friendsLaShowAll(FriendsLaArgType type, u128 userID, u64 networkServiceAccountId, const FriendsInAppScreenName *first_inAppScreenName, const FriendsInAppScreenName *second_inAppScreenName, bool playStartupSound) { + FriendsLaArg arg = {.type = type, .userID = userID, .networkServiceAccountId = networkServiceAccountId, .first_inAppScreenName = *first_inAppScreenName, .second_inAppScreenName = *second_inAppScreenName}; + + return _friendsLaShow(&arg, playStartupSound); +} + +Result friendsLaShowFriendList(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowFriendList, userID, false); +} + +Result friendsLaShowUserDetailInfo(u128 userID, u64 networkServiceAccountId, const FriendsInAppScreenName *first_inAppScreenName, const FriendsInAppScreenName *second_inAppScreenName) { + return _friendsLaShowAll(FriendsLaArgType_ShowUserDetailInfo, userID, networkServiceAccountId, first_inAppScreenName, second_inAppScreenName, false); +} + +Result friendsLaStartSendingFriendRequest(u128 userID, u64 networkServiceAccountId, const FriendsInAppScreenName *first_inAppScreenName, const FriendsInAppScreenName *second_inAppScreenName) { + return _friendsLaShowAll(FriendsLaArgType_StartSendingFriendRequest, userID, networkServiceAccountId, first_inAppScreenName, second_inAppScreenName, false); +} + +Result friendsLaShowMethodsOfSendingFriendRequest(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowMethodsOfSendingFriendRequest, userID, false); +} + +Result friendsLaStartFacedFriendRequest(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_StartFacedFriendRequest, userID, false); +} + +Result friendsLaShowReceivedFriendRequestList(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowReceivedFriendRequestList, userID, false); +} + +Result friendsLaShowBlockedUserList(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowBlockedUserList, userID, false); +} + +Result friendsLaShowMyProfile(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowMyProfile, userID, false); +} + +Result friendsLaShowMyProfileForHomeMenu(u128 userID) { + return _friendsLaShowSimple(FriendsLaArgType_ShowMyProfile, userID, true); +} +