From a1d2a72a78fdd858248c4371c2aa08be4f612c20 Mon Sep 17 00:00:00 2001 From: Florin9doi Date: Tue, 4 Jun 2024 23:12:44 +0300 Subject: [PATCH] USB: GunCon3 updates -Process the mouse buttons even when x/y_max aren't yet determined. -Allows to start the calibration without shaking the mouse before. -Extend support to 4 players. The games can't use more than 2, but it allows more flexibility to mix DS3 and GC3. -Avoid OOB for unsupported Pads --- rpcs3/Emu/Io/GunCon3.cpp | 18 +++++++++++++----- rpcs3/Emu/Io/guncon3_config.h | 4 ++-- rpcs3/Input/pad_thread.cpp | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Io/GunCon3.cpp b/rpcs3/Emu/Io/GunCon3.cpp index db456dab00..ee9694447c 100644 --- a/rpcs3/Emu/Io/GunCon3.cpp +++ b/rpcs3/Emu/Io/GunCon3.cpp @@ -220,6 +220,13 @@ void usb_device_guncon3::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, return; } + if (m_controller_index >= g_cfg_guncon3.players.size()) + { + guncon3_log.warning("GunCon3 controllers are only supported for Player1 to Player%d", g_cfg_guncon3.players.size()); + guncon3_encode(&gc, buf, m_key.data()); + return; + } + const auto input_callback = [&gc](guncon3_btn btn, u16 value, bool pressed) { if (!pressed) @@ -261,15 +268,18 @@ void usb_device_guncon3::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, auto& mouse_handler = g_fxo->get(); std::lock_guard mouse_lock(mouse_handler.mutex); - mouse_handler.Init(2); + mouse_handler.Init(4); - if (m_controller_index >= mouse_handler.GetMice().size()) + const u32 mouse_index = g_cfg.io.mouse == mouse_handler::basic ? 0 : m_controller_index; + if (mouse_index >= mouse_handler.GetMice().size()) { guncon3_encode(&gc, buf, m_key.data()); return; } - const Mouse& mouse_data = ::at32(mouse_handler.GetMice(), m_controller_index); + const Mouse& mouse_data = ::at32(mouse_handler.GetMice(), mouse_index); + cfg->handle_input(mouse_data, input_callback); + if (mouse_data.x_max <= 0 || mouse_data.y_max <= 0) { guncon3_encode(&gc, buf, m_key.data()); @@ -279,8 +289,6 @@ void usb_device_guncon3::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, // Expand 0..+wh to -32767..+32767 gc.gun_x = (mouse_data.x_pos * USHRT_MAX / mouse_data.x_max) - SHRT_MAX; gc.gun_y = (mouse_data.y_pos * -USHRT_MAX / mouse_data.y_max) + SHRT_MAX; - - cfg->handle_input(mouse_data, input_callback); } guncon3_encode(&gc, buf, m_key.data()); diff --git a/rpcs3/Emu/Io/guncon3_config.h b/rpcs3/Emu/Io/guncon3_config.h index 4a385b32f9..6224fa856c 100644 --- a/rpcs3/Emu/Io/guncon3_config.h +++ b/rpcs3/Emu/Io/guncon3_config.h @@ -42,9 +42,9 @@ struct cfg_gc3 final : public emulated_pad_config cfg_pad_btn bs_y{this, "B-stick Y-Axis", guncon3_btn::bs_y, pad_button::rs_y}; }; -struct cfg_guncon3 final : public emulated_pads_config +struct cfg_guncon3 final : public emulated_pads_config { - cfg_guncon3() : emulated_pads_config("guncon3") {}; + cfg_guncon3() : emulated_pads_config("guncon3") {}; }; extern cfg_guncon3 g_cfg_guncon3; diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index a3a81b4c65..756d83df2f 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -191,7 +191,7 @@ void pad_thread::Init() } m_pads[i]->is_fake_pad = (g_cfg.io.move == move_handler::fake && i >= (static_cast(CELL_PAD_MAX_PORT_NUM) - static_cast(CELL_GEM_MAX_NUM))) - || (m_pads[i]->m_class_type >= CELL_PAD_FAKE_TYPE_FIRST && m_pads[i]->m_class_type <= CELL_PAD_FAKE_TYPE_LAST); + || (m_pads[i]->m_class_type >= CELL_PAD_FAKE_TYPE_FIRST && m_pads[i]->m_class_type < CELL_PAD_FAKE_TYPE_LAST); connect_usb_controller(i, input::get_product_by_vid_pid(m_pads[i]->m_vendor_id, m_pads[i]->m_product_id)); } }