Skip to content

Commit 33a74c2

Browse files
authored
nn_nfp: Avoid current app from showing up as "???" for others in Friend List + View friends' status (cemu-project#1157)
1 parent 7b635e7 commit 33a74c2

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/Cafe/IOSU/legacy/iosu_fpd.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ namespace iosu
214214
friendData->friendExtraData.gameKey.ukn08 = frd->presence.gameKey.ukn;
215215
NexPresenceToGameMode(&frd->presence, &friendData->friendExtraData.gameMode);
216216

217+
auto fixed_presence_msg = '\0' + frd->presence.msg; // avoid first character of comment from being cut off
218+
friendData->friendExtraData.gameModeDescription.assignFromUTF8(fixed_presence_msg);
219+
220+
auto fixed_comment = '\0' + frd->comment.commentString; // avoid first character of comment from being cut off
221+
friendData->friendExtraData.comment.assignFromUTF8(fixed_comment);
222+
217223
// set valid dates
218224
friendData->uknDate.year = 2018;
219225
friendData->uknDate.day = 1;
@@ -750,9 +756,18 @@ namespace iosu
750756
{
751757
if(numVecIn != 0 || numVecOut != 1)
752758
return FPResult_InvalidIPCParam;
753-
SelfPlayingGame selfPlayingGame{0};
754-
cemuLog_log(LogType::Force, "GetMyPlayingGame is todo");
755-
return WriteValueOutput<SelfPlayingGame>(vecOut, selfPlayingGame);
759+
GameKey selfPlayingGame
760+
{
761+
CafeSystem::GetForegroundTitleId(),
762+
CafeSystem::GetForegroundTitleVersion(),
763+
{0,0,0,0,0,0}
764+
};
765+
if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) != 0x00050000)
766+
{
767+
selfPlayingGame.titleId = 0;
768+
selfPlayingGame.ukn08 = 0;
769+
}
770+
return WriteValueOutput<GameKey>(vecOut, selfPlayingGame);
756771
}
757772

758773
nnResult CallHandler_GetFriendAccountId(FPDClient* fpdClient, IPCIoctlVector* vecIn, uint32 numVecIn, IPCIoctlVector* vecOut, uint32 numVecOut)
@@ -1410,8 +1425,16 @@ namespace iosu
14101425
act::getCountryIndex(currentSlot, &countryCode);
14111426
// init presence
14121427
g_fpd.myPresence.isOnline = 1;
1413-
g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
1414-
g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
1428+
if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) == 0x00050000)
1429+
{
1430+
g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
1431+
g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
1432+
}
1433+
else
1434+
{
1435+
g_fpd.myPresence.gameKey.titleId = 0; // icon will not be ??? or invalid to others
1436+
g_fpd.myPresence.gameKey.ukn = 0;
1437+
}
14151438
// resolve potential domain to IP address
14161439
struct addrinfo hints = {0}, *addrs;
14171440
hints.ai_family = AF_INET;

src/Cafe/IOSU/legacy/iosu_fpd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace iosu
9494
/* +0x1EC */ uint8 isOnline;
9595
/* +0x1ED */ uint8 _padding1ED[3];
9696
// some other sub struct?
97-
/* +0x1F0 */ char comment[36]; // pops up every few seconds in friend list
97+
/* +0x1F0 */ CafeWideString<0x12> comment; // pops up every few seconds in friend list
9898
/* +0x214 */ uint32be _padding214;
9999
/* +0x218 */ FPDDate approvalTime;
100100
/* +0x220 */ FPDDate lastOnline;
@@ -263,4 +263,4 @@ namespace iosu
263263

264264
IOSUModule* GetModule();
265265
}
266-
}
266+
}

src/Cemu/nex/nexFriends.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "prudp.h"
22
#include "nex.h"
33
#include "nexFriends.h"
4+
#include "Cafe/CafeSystem.h"
45

56
static const int NOTIFICATION_SRV_FRIEND_OFFLINE = 0x0A; // the opposite event (friend online) is notified via _PRESENCE_CHANGE
67
static const int NOTIFICATION_SRV_FRIEND_PRESENCE_CHANGE = 0x18;
@@ -912,6 +913,18 @@ void NexFriends::markFriendRequestsAsReceived(uint64* messageIdList, sint32 coun
912913
void NexFriends::updateMyPresence(nexPresenceV2& myPresence)
913914
{
914915
this->myPresence = myPresence;
916+
917+
if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) == 0x00050000)
918+
{
919+
myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
920+
myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
921+
}
922+
else
923+
{
924+
myPresence.gameKey.titleId = 0; // icon will not be ??? or invalid to others
925+
myPresence.gameKey.ukn = 0;
926+
}
927+
915928
if (nexCon == nullptr || nexCon->getState() != nexService::STATE_CONNECTED)
916929
{
917930
// not connected

src/Cemu/nex/nexFriends.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ class nexFriend : public nexType
431431
{
432432
nnaInfo.readData(pb);
433433
presence.readData(pb);
434-
gameModeMessage.readData(pb);
434+
comment.readData(pb);
435435
friendsSinceTimestamp = pb->readU64();
436436
lastOnlineTimestamp = pb->readU64();
437437
ukn6 = pb->readU64();
438438
}
439439
public:
440440
nexNNAInfo nnaInfo;
441441
nexPresenceV2 presence;
442-
nexComment gameModeMessage;
442+
nexComment comment;
443443
uint64 friendsSinceTimestamp;
444444
uint64 lastOnlineTimestamp;
445445
uint64 ukn6;

0 commit comments

Comments
 (0)