From e3aff6d3359927313306ade814472b201307144b Mon Sep 17 00:00:00 2001 From: emoose Date: Fri, 3 Jan 2020 11:31:52 +0000 Subject: [PATCH] [XAM/User] Add UserIndex enum, handle special UserIndexes inside KernelState::user_profile --- src/xenia/kernel/kernel_state.cc | 39 +++++++++++++++++++++++++++++ src/xenia/kernel/kernel_state.h | 18 +------------ src/xenia/kernel/xam/user_profile.h | 6 +++++ 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index 321d571fd..5ee4c45f6 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -835,5 +835,44 @@ bool KernelState::Restore(ByteStream* stream) { return true; } +xam::UserProfile* KernelState::user_profile(uint32_t user_index, + bool allow_signed_out) const { + auto index_enum = static_cast(user_index); + bool use_any_profile = index_enum == xam::UserProfile::UserIndex::kAny; + + // TODO: how to handle these two cases? + if (index_enum == xam::UserProfile::UserIndex::kFocus) { + assert_always(); + use_any_profile = true; // temp + } + if (index_enum == xam::UserProfile::UserIndex::kNone) { + assert_always(); + return nullptr; + } + + // TODO: any callers that use kAny need to be updated so they'll apply to all + // profiles! + if (use_any_profile) { + for (auto& user : user_profiles_) { + if (allow_signed_out || user->signed_in()) { + return user.get(); + } + } + return nullptr; + } + + if (user_index >= xam::kMaxNumUsers) { + return nullptr; + } + + auto user = &user_profiles_[user_index]; + if (!allow_signed_out) { + if (!user->get()->signed_in()) { + return nullptr; + } + } + return user->get(); +} + } // namespace kernel } // namespace xe diff --git a/src/xenia/kernel/kernel_state.h b/src/xenia/kernel/kernel_state.h index bdfbdd92e..d25f959a8 100644 --- a/src/xenia/kernel/kernel_state.h +++ b/src/xenia/kernel/kernel_state.h @@ -108,23 +108,7 @@ class KernelState { // (unless allow_signed_out is true, to allow for code dealing with sign-ins // etc) xam::UserProfile* user_profile(uint32_t user_index, - bool allow_signed_out = false) const { - if (user_index == 0xFF) { - user_index = 0; - } - - if (user_index >= xam::kMaxNumUsers) { - return nullptr; - } - - auto user = &user_profiles_[user_index]; - if (!allow_signed_out) { - if (!user->get()->signed_in()) { - return nullptr; - } - } - return user->get(); - } + bool allow_signed_out = false) const; uint32_t num_profiles() const { return xam::kMaxNumUsers; } diff --git a/src/xenia/kernel/xam/user_profile.h b/src/xenia/kernel/xam/user_profile.h index b204547e6..c37d88023 100644 --- a/src/xenia/kernel/xam/user_profile.h +++ b/src/xenia/kernel/xam/user_profile.h @@ -166,6 +166,12 @@ struct X_XAMACCOUNTINFO { class UserProfile { public: + enum class UserIndex { + kAny = 0xFF, // applies to any or all signed-in users + kNone = 0xFE, // this isn't tied to any signed-in user + kFocus = 0xFD, // whichever user last acted / was last in focus + }; + static void CreateUsers(KernelState* kernel_state, std::unique_ptr* profiles);