switchbrew / nx-hbloader

Host process for loading Switch homebrew NROs
ISC License
339 stars 72 forks source link

share preselected UserID as a ConfigEntry #18

Closed p-sam closed 5 years ago

p-sam commented 5 years ago

When using hb over an app which makes you choose the user before launch, you retrieve the userID with accountGetPreselectedUser. However subsequent calls will fail as it can only be retrieved once per process, meaning if you would return to hbmenu and launch again an nro, you would not be able to get it unless you quit game and run it again. I wanted to discuss here the possible approach to making it available to hb. Would adding a ConfigEntry with that userid (if app) be something we can add to hbloader?

hb would then try to retrieve that config entry, and if not present launch playerSelectApplet and get the current active user

yellows8 commented 5 years ago

Would this matter when the profile-selector applet is eventually supported?

p-sam commented 5 years ago

yes, for applications that have the user be preselected before launch

yellows8 commented 5 years ago

As in, just use profile-selector without accountGetPreselectedUser().

p-sam commented 5 years ago

Well you would have to select it two times

p-sam commented 5 years ago

Also, most of the games i used as donor title would do that

yellows8 commented 5 years ago

accountGetActiveUser does the same thing though.

p-sam commented 5 years ago

From what I could try, accountGetActiveUser would return account_selected = false, and not the preselected user, so what you would be suggest is for hb to call the playerSelect applet "again" (once in hb, but effectively shown twice for the user), to populate the userId return of accountGetActiveUser ?

yellows8 commented 5 years ago

Code? AFAIK accountGetActiveUser works fine with preselected-user...

p-sam commented 5 years ago

So I ran the following code on my end :

bool account_selected = false;
u128 userID = 0;
Result rc = accountInitialize();
if (R_FAILED(rc)) {
    printf("accountInitialize() failed: 0x%x\n", rc);
}

if(R_SUCCEEDED(rc)) {
    rc = accountGetActiveUser(&userID, &account_selected);

    if (R_FAILED(rc)) {
        printf("accountGetActiveUser() failed: 0x%x\n", rc);
    }
    else if(!account_selected) {
        printf("accountGetActiveUser: No user is currently selected.\n");
    } else {
        printf("accountGetActiveUser: Current userID is %lx%lx\n", (u64)(userID>>64), (u64)userID);
    }

    rc = accountGetPreselectedUser(&userID);

    if (R_FAILED(rc)) {
        printf("accountGetPreselectedUser() failed: 0x%x\n", rc);
    } else {
        printf("accountGetPreselectedUser: Current userID is %lx%lx\n", (u64)(userID>>64), (u64)userID);
    }
}

accountExit();

and here's what is outputted: (%userid% is my first user id here, irrelevant to the case)

So it exhibits the behavior I described, but it didn't match with your last comment, so I tried calling accountGetPreselectedUser before accountGetActiveUser, which leads to significant result changes:

That means that issue can be closed, because there is no need then to try to keep around a reference to a userID we can obtain by calling accountGetPreselectedUser first. At best we can directly obtain the userID from that call, and else it will be returned via accountGetActiveUser anyway. However, I'd add a note of that behavior on accountGetActiveUser header comment on libnx below of :

/// An user is only selected when the user-account selection applet was used to select an user at least once before.

Since from what I gather, it would only work if accountGetPreselectedUser was called at least once before (once in the process? or in the nro hb? I have not tested yet).

Closing as the issue does not belong in hbloader anymore.

yellows8 commented 5 years ago

switch-examples/account/ works fine AFAIK when nothing account-related was done previously besides applet user-preselect (unless that changed with a newer sysver?).

p-sam commented 5 years ago

If i'm not mistaken, the current example would just print "No user is currently selected"

yellows8 commented 5 years ago

Works on v2.x :|

p-sam commented 5 years ago

I see, I'm on 7.x right now, which may explain the diff behavior

yellows8 commented 5 years ago

2a0d4a7713b0b2af2cece59596854bab7e0c55e3 https://github.com/switchbrew/libnx/commit/773111b3f2fa4a54ead4e7ee9cfefbd786799b7d

p-sam commented 5 years ago

👍