Skip to content
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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rewfs98
Copy link
Contributor

@rewfs98 rewfs98 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

@rewfs98 rewfs98 marked this pull request as draft April 12, 2024 22:12
@rewfs98
Copy link
Contributor Author

rewfs98 commented Apr 12, 2024

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.

@rewfs98
Copy link
Contributor Author

rewfs98 commented Apr 12, 2024

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.

{
FP_API_BASE();
auto ipcCtx = std::make_unique<FPIpcContext>(iosu::fpd::FPD_REQUEST_ID::UpdateCommentAsync);
ipcCtx->AddInput(newComment, 36);
Copy link
Contributor

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.

return FPResult_InvalidIPCParam;
if (!g_fpd.nexFriendSession)
return FPResult_RequestFailed;
DeclareInputPtr(newComment, char16_t, (vecOut[0].size / 2), 0);
Copy link
Contributor

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.

DeclareInputPtr(newComment, char16_t, (vecOut[0].size / 2), 0);
IPCCommandBody* cmd = ServiceCallDelayCurrentResponse();

auto utf8_comment = StringHelpers::ToUtf8((const uint16be*)newComment, vecIn[0].size);
Copy link
Contributor

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.

@Exzap
Copy link
Contributor

Exzap commented Apr 13, 2024

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 GetMyComment probably depends on some other state from the friend lib that we provide incorrectly/differently.

@rewfs98
Copy link
Contributor Author

rewfs98 commented Apr 13, 2024

The call to GetMyComment probably depends on some other state from the friend lib that we provide incorrectly/differently.

Is there a clear indicator to find where that state is?

@rewfs98
Copy link
Contributor Author

rewfs98 commented Apr 19, 2024

Not much progress has been done lately, however, GetMyComment wasn't being called because it wasn't defined in nn_fp.cpp, also, the last 2 commits seems to have broken UpdateCommentAsync further by giving out an error when it gets called (both without nn_fp.rpl), so there needs to be more work done.

@rewfs98
Copy link
Contributor Author

rewfs98 commented Apr 20, 2024

Another note, the GameKey corruption seems to come from UpdatePresenceAsync and not from UpdateCommentAsync, not sure what part exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants