diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index fc4ce72cb..053b7a581 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -828,5 +828,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);