Skip to content

Commit

Permalink
nn_nfp: Avoid current app from showing up as "???" for others in Frie…
Browse files Browse the repository at this point in the history
…nd List + View friends' status (cemu-project#1157)
  • Loading branch information
primaviera authored Apr 8, 2024
1 parent 7b635e7 commit 33a74c2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
33 changes: 28 additions & 5 deletions src/Cafe/IOSU/legacy/iosu_fpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ namespace iosu
friendData->friendExtraData.gameKey.ukn08 = frd->presence.gameKey.ukn;
NexPresenceToGameMode(&frd->presence, &friendData->friendExtraData.gameMode);

auto fixed_presence_msg = '\0' + frd->presence.msg; // avoid first character of comment from being cut off
friendData->friendExtraData.gameModeDescription.assignFromUTF8(fixed_presence_msg);

auto fixed_comment = '\0' + frd->comment.commentString; // avoid first character of comment from being cut off
friendData->friendExtraData.comment.assignFromUTF8(fixed_comment);

// set valid dates
friendData->uknDate.year = 2018;
friendData->uknDate.day = 1;
Expand Down Expand Up @@ -750,9 +756,18 @@ namespace iosu
{
if(numVecIn != 0 || numVecOut != 1)
return FPResult_InvalidIPCParam;
SelfPlayingGame selfPlayingGame{0};
cemuLog_log(LogType::Force, "GetMyPlayingGame is todo");
return WriteValueOutput<SelfPlayingGame>(vecOut, selfPlayingGame);
GameKey selfPlayingGame
{
CafeSystem::GetForegroundTitleId(),
CafeSystem::GetForegroundTitleVersion(),
{0,0,0,0,0,0}
};
if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) != 0x00050000)
{
selfPlayingGame.titleId = 0;
selfPlayingGame.ukn08 = 0;
}
return WriteValueOutput<GameKey>(vecOut, selfPlayingGame);
}

nnResult CallHandler_GetFriendAccountId(FPDClient* fpdClient, IPCIoctlVector* vecIn, uint32 numVecIn, IPCIoctlVector* vecOut, uint32 numVecOut)
Expand Down Expand Up @@ -1410,8 +1425,16 @@ namespace iosu
act::getCountryIndex(currentSlot, &countryCode);
// init presence
g_fpd.myPresence.isOnline = 1;
g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) == 0x00050000)
{
g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
}
else
{
g_fpd.myPresence.gameKey.titleId = 0; // icon will not be ??? or invalid to others
g_fpd.myPresence.gameKey.ukn = 0;
}
// resolve potential domain to IP address
struct addrinfo hints = {0}, *addrs;
hints.ai_family = AF_INET;
Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/IOSU/legacy/iosu_fpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace iosu
/* +0x1EC */ uint8 isOnline;
/* +0x1ED */ uint8 _padding1ED[3];
// some other sub struct?
/* +0x1F0 */ char comment[36]; // pops up every few seconds in friend list
/* +0x1F0 */ CafeWideString<0x12> comment; // pops up every few seconds in friend list
/* +0x214 */ uint32be _padding214;
/* +0x218 */ FPDDate approvalTime;
/* +0x220 */ FPDDate lastOnline;
Expand Down Expand Up @@ -263,4 +263,4 @@ namespace iosu

IOSUModule* GetModule();
}
}
}
13 changes: 13 additions & 0 deletions src/Cemu/nex/nexFriends.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prudp.h"
#include "nex.h"
#include "nexFriends.h"
#include "Cafe/CafeSystem.h"

static const int NOTIFICATION_SRV_FRIEND_OFFLINE = 0x0A; // the opposite event (friend online) is notified via _PRESENCE_CHANGE
static const int NOTIFICATION_SRV_FRIEND_PRESENCE_CHANGE = 0x18;
Expand Down Expand Up @@ -912,6 +913,18 @@ void NexFriends::markFriendRequestsAsReceived(uint64* messageIdList, sint32 coun
void NexFriends::updateMyPresence(nexPresenceV2& myPresence)
{
this->myPresence = myPresence;

if (GetTitleIdHigh(CafeSystem::GetForegroundTitleId()) == 0x00050000)
{
myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
}
else
{
myPresence.gameKey.titleId = 0; // icon will not be ??? or invalid to others
myPresence.gameKey.ukn = 0;
}

if (nexCon == nullptr || nexCon->getState() != nexService::STATE_CONNECTED)
{
// not connected
Expand Down
4 changes: 2 additions & 2 deletions src/Cemu/nex/nexFriends.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,15 @@ class nexFriend : public nexType
{
nnaInfo.readData(pb);
presence.readData(pb);
gameModeMessage.readData(pb);
comment.readData(pb);
friendsSinceTimestamp = pb->readU64();
lastOnlineTimestamp = pb->readU64();
ukn6 = pb->readU64();
}
public:
nexNNAInfo nnaInfo;
nexPresenceV2 presence;
nexComment gameModeMessage;
nexComment comment;
uint64 friendsSinceTimestamp;
uint64 lastOnlineTimestamp;
uint64 ukn6;
Expand Down

0 comments on commit 33a74c2

Please sign in to comment.