diff --git a/src/xenia/hid/input_system.cc b/src/xenia/hid/input_system.cc index e1a575ce7..731237821 100644 --- a/src/xenia/hid/input_system.cc +++ b/src/xenia/hid/input_system.cc @@ -100,6 +100,10 @@ X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE* out_state) { if (result == X_ERROR_SUCCESS) { UpdateUsedSlot(driver.get(), user_index, any_connected); AdjustDeadzoneLevels(user_index, &out_state->gamepad); + + if (out_state->gamepad.buttons != 0) { + last_used_slot = user_index; + } return result; } } diff --git a/src/xenia/hid/input_system.h b/src/xenia/hid/input_system.h index fa6f5dbc5..b1c0db52d 100644 --- a/src/xenia/hid/input_system.h +++ b/src/xenia/hid/input_system.h @@ -53,6 +53,8 @@ class InputSystem { return connected_slots; } + uint32_t GetLastUsedSlot() const { return last_used_slot; } + std::unique_lock lock(); private: @@ -73,6 +75,7 @@ class InputSystem { std::bitset connected_slots = {}; std::array, XUserMaxUserCount> controllers_max_joystick_value = {}; + uint32_t last_used_slot = 0; xe_unlikely_mutex lock_; }; diff --git a/src/xenia/kernel/xam/profile_manager.cc b/src/xenia/kernel/xam/profile_manager.cc index f0fce63aa..98ab18a12 100644 --- a/src/xenia/kernel/xam/profile_manager.cc +++ b/src/xenia/kernel/xam/profile_manager.cc @@ -15,6 +15,7 @@ #include "third_party/fmt/include/fmt/format.h" #include "xenia/base/logging.h" #include "xenia/emulator.h" +#include "xenia/hid/input_system.h" #include "xenia/kernel/kernel_state.h" #include "xenia/kernel/util/crypto_utils.h" #include "xenia/vfs/devices/host_path_device.h" @@ -149,6 +150,10 @@ UserProfile* ProfileManager::GetProfile(const uint64_t xuid) const { } UserProfile* ProfileManager::GetProfile(uint8_t user_index) const { + if (user_index == XUserIndexLatest) { + user_index = kernel_state_->emulator()->input_system()->GetLastUsedSlot(); + } + if (user_index == XUserIndexNone) { return nullptr; }