-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nn_fp: Implement GetMyComment and UpdateCommentAsync #1173
Conversation
gf2p8affineqb
commented
Apr 12, 2024
- When starting a friend session, myComment (nexComment) will be stored in the session (NexFriends) variable
- Using GetMyComment will then get session->myComment and convert the commentString to UTF16
- Implemented nexComment.writeData
- UpdateCommentAsync and UpdatePreferenceAsync are incredibly similiar to each other, so most of the code is copied over from that in order to make it work
…_2nn2fpFPCwPFQ2_2nn6ResultPv_vPv
… CallHandler_GetMyComment and add CallHandler_UpdateCommentAsync
…mment, add getMyComment and updateCommentAsync functions
…NexFriends::getMyComment and NexFriends::updateCommentAsync
I'll have to convert this as a draft for now, still seems to have a few issues and I opened this PR a bit too soon. |
Something I have noticed, this does not work too well without nn_fp.rpl placed in cafeLibs/, GetMyComment doesn't get called (meaning you can't read your own comment) and UpdateCommentAsync seems to corrupt myPresence->GameKey on the client (comment still updates for other friends and the title remains untouched serverside), I'm not exactly sure on what to do about this. |
src/Cafe/OS/libs/nn_fp/nn_fp.cpp
Outdated
{ | ||
FP_API_BASE(); | ||
auto ipcCtx = std::make_unique<FPIpcContext>(iosu::fpd::FPD_REQUEST_ID::UpdateCommentAsync); | ||
ipcCtx->AddInput(newComment, 36); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newComment
is a null-terminated big-endian wide string and our current convention for those is to define them as uint16be*
But also I took a quick look into nn_fp.rpl and it behaves differently here. The length passed to AddInput
is dynamically calculated. I think this is how its implemented:
uint32 commentLen = CafeStringHelpers::Length(newComment, 17);
if(commentLen>=17)
return FPResult_InvalidIPCParam;
ipcCtx->AddInput(newComment, sizeof(uint16be) * (commentLen + 1));
So it seems to work similar to how UpdateGameModeWithUnusedParam
passes it's string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked nn_fp.rpl and yeah, that implementation is accurate, though commentLen is added by 2 instead of 1
src/Cafe/IOSU/legacy/iosu_fpd.cpp
Outdated
return FPResult_InvalidIPCParam; | ||
if (!g_fpd.nexFriendSession) | ||
return FPResult_RequestFailed; | ||
DeclareInputPtr(newComment, char16_t, (vecOut[0].size / 2), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char16_t
should be uint16be
The way this reads the string from the buffer doesn't match IOSU behavior. Take a look at CallHandler_UpdateGameMode
for the general pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the code using CallHandler_UpdateGameMode
as a reference, and it works fine
src/Cafe/IOSU/legacy/iosu_fpd.cpp
Outdated
DeclareInputPtr(newComment, char16_t, (vecOut[0].size / 2), 0); | ||
IPCCommandBody* cmd = ServiceCallDelayCurrentResponse(); | ||
|
||
auto utf8_comment = StringHelpers::ToUtf8((const uint16be*)newComment, vecIn[0].size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are passing the size in bytes to ToUtf8
, but it wants the size in wide characters.
There seem to be some out of bounds reads but no bad writes (unless MY_COMMENT_LENGTH is wrong or we are using it in the wrong places?) So not sure what could be causing the corruption. The call to |
Is there a clear indicator to find where that state is? |
Not much progress has been done lately, however, |
Another note, the |
I know it has been a really long time since I last pushed a commit, I'd say the PR is almost finished, the only problem I have seen is that the comment doesn't update for the client in Friend List (it still updates for every other friend and if you restart the app the comment does change), I have a feeling this has something to do with the graphics and not the nn_fp library itself, I even tried patching out some friend list functions on real hardware to see where the text gets updated but I wasn't able to find anything. |
src/Cafe/OS/libs/nn_fp/nn_fp.cpp
Outdated
{ | ||
FP_API_BASE(); | ||
auto ipcCtx = std::make_unique<FPIpcContext>(iosu::fpd::FPD_REQUEST_ID::GetMyComment); | ||
ipcCtx->AddOutput(myPreference, sizeof(uint16be)*0x12); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use MY_COMMENT_LENGTH
here instead of hardcoding 0x12. The definition of MY_COMMENT_LENGTH
would have to be moved from CallHandler_GetMyComment
into iosu_fpd.h
Is this ready to be merged or is more work being done? Asking since it's still marked as draft. |