From d246e3bc70292b2034ff153feb5ee0ac73cff97b Mon Sep 17 00:00:00 2001 From: Gliniak Date: Sat, 21 Sep 2024 22:35:03 +0200 Subject: [PATCH] [XAM] XamShowSigninUI: Send signin and UI close notification with delay from separate thread This is to prevent situation when game waits for notification, but receives it beforehand --- src/xenia/kernel/xam/xam_user.cc | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/xenia/kernel/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc index ebe7a9643..6aee7123d 100644 --- a/src/xenia/kernel/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -548,23 +548,30 @@ dword_result_t XamShowSigninUI_entry(dword_t users_needed, dword_t unk_mask) { kernel_state()->UpdateUsedUserProfiles(); // Mask values vary. Probably matching user types? Local/remote? // Games seem to sit and loop until we trigger this notification: - uint32_t user_mask = 0; - uint32_t active_users = 0; - for (uint32_t i = 0; i < 4; i++) { - if (kernel_state()->IsUserSignedIn(i)) { - user_mask |= (1 << i); - active_users++; - if (active_users >= users_needed) break; + auto run = [users_needed]() -> void { + uint32_t user_mask = 0; + uint32_t active_users = 0; + + for (uint32_t i = 0; i < 4; i++) { + if (kernel_state()->IsUserSignedIn(i)) { + user_mask |= (1 << i); + active_users++; + if (active_users >= users_needed) break; + } } - } - // XN_SYS_SIGNINCHANGED (players) - kernel_state()->BroadcastNotification(kXNotificationIDSystemSignInChanged, - user_mask); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + // XN_SYS_SIGNINCHANGED (players) + kernel_state()->BroadcastNotification(kXNotificationIDSystemSignInChanged, + user_mask); + // XN_SYS_UI (off) + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, 0); + }; + + std::thread thread(run); + thread.detach(); - // XN_SYS_UI (off) - kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, 0); return X_ERROR_SUCCESS; } DECLARE_XAM_EXPORT1(XamShowSigninUI, kUserProfiles, kStub);