diff --git a/rpcs3/Input/raw_mouse_handler.cpp b/rpcs3/Input/raw_mouse_handler.cpp index 18f4f5ceb0..0be5dc9e31 100644 --- a/rpcs3/Input/raw_mouse_handler.cpp +++ b/rpcs3/Input/raw_mouse_handler.cpp @@ -45,6 +45,8 @@ raw_mouse::~raw_mouse() void raw_mouse::reload_config() { + m_buttons.clear(); + if (m_index < ::size32(g_cfg_raw_mouse.players)) { if (const auto& player = ::at32(g_cfg_raw_mouse.players, m_index)) @@ -63,6 +65,12 @@ void raw_mouse::reload_config() } } +void raw_mouse::set_index(u32 index) +{ + m_index = index; + reload_requested = true; +} + std::pair raw_mouse::get_mouse_button(const cfg::string& button) { const std::string value = button.to_string(); @@ -131,7 +139,10 @@ void raw_mouse::update_values(const RAWMOUSE& state) const auto get_button_pressed = [this](u8 button, int button_flags) { - const auto& [down, up] = ::at32(m_buttons, button); + const auto it = m_buttons.find(button); + if (it == m_buttons.cend()) return; + + const auto& [down, up] = it->second; // Only update the value if either down or up flags are present if ((button_flags & down)) @@ -328,12 +339,12 @@ void raw_mouse_handler::update_devices() const std::string device_name = player->device.to_string(); // Check if the configured device for this player is connected - if (auto it = std::find_if(enumerated.begin(), enumerated.end(), [&device_name](const auto& entry){ return entry.second.device_name() == device_name; }); - it != enumerated.end()) + if (const auto it = std::find_if(enumerated.begin(), enumerated.end(), [&device_name](const auto& entry){ return entry.second.device_name() == device_name; }); + it != enumerated.cend()) { // Check if the device was already known - auto it_exists = m_raw_mice.find(it->first); - const bool exists = it_exists != m_raw_mice.end(); + const auto it_exists = m_raw_mice.find(it->first); + const bool exists = it_exists != m_raw_mice.cend(); // Copy by value to allow for the same device for multiple players raw_mouse& mouse = updated_mice[it->first]; diff --git a/rpcs3/Input/raw_mouse_handler.h b/rpcs3/Input/raw_mouse_handler.h index 41f84572d3..9cba938bec 100644 --- a/rpcs3/Input/raw_mouse_handler.h +++ b/rpcs3/Input/raw_mouse_handler.h @@ -42,7 +42,7 @@ public: const std::string& device_name() const { return m_device_name; } u32 index() const { return m_index; } - void set_index(u32 index) { m_index = index; } + void set_index(u32 index); void request_reload() { reload_requested = true; } private: