diff --git a/CMakeLists.txt b/CMakeLists.txt index aaea44780..848d5081e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,13 +96,13 @@ file (GLOB CXBXR_HEADER_GUIv1 "${CXBXR_ROOT_DIR}/src/common/input/EmuDevice.h" "${CXBXR_ROOT_DIR}/src/common/input/InputWindow.h" "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgDukeControllerConfig.h" + "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgSBControllerConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgAbout.h" "${CXBXR_ROOT_DIR}/src/gui/DlgAudioConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgInputConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgEepromConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgLoggingConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgNetworkConfig.h" - "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgSBControllerConfig.h" "${CXBXR_ROOT_DIR}/src/gui/DlgVideoConfig.h" "${CXBXR_ROOT_DIR}/src/gui/Wnd.h" "${CXBXR_ROOT_DIR}/src/gui/WndMain.h" @@ -242,13 +242,13 @@ file (GLOB CXBXR_SOURCE_GUIv1 "${CXBXR_ROOT_DIR}/src/common/input/EmuDevice.cpp" "${CXBXR_ROOT_DIR}/src/common/input/InputWindow.cpp" "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgDukeControllerConfig.cpp" + "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgSBControllerConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgAbout.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgAudioConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgInputConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgEepromConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgLoggingConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgNetworkConfig.cpp" - "${CXBXR_ROOT_DIR}/src/gui/controllers/DlgSBControllerConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/DlgVideoConfig.cpp" "${CXBXR_ROOT_DIR}/src/gui/WinMain.cpp" "${CXBXR_ROOT_DIR}/src/gui/Wnd.cpp" diff --git a/src/common/Settings.cpp b/src/common/Settings.cpp index dc72916b3..d7ea2cb38 100644 --- a/src/common/Settings.cpp +++ b/src/common/Settings.cpp @@ -474,27 +474,27 @@ bool Settings::LoadConfig() std::array, to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)> control_names; for (int device = 0; device < to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX); device++) { - int num_buttons = dev_num_buttons[device]; - if (num_buttons == 0) { + if (dev_num_buttons[device] == 0) { continue; } auto &lambda = [&control_names, &device](int num_buttons, const char *const ctrl_names[]) { for (int i = 0; i < num_buttons; i++) { - char control_name[BUF_NAME_LENGTH]; + char control_name[XBOX_BUTTON_NAME_LENGTH]; std::sprintf(control_name, sect_input_profiles.control, ctrl_names[i]); control_names[device].push_back(control_name); } }; - switch (num_buttons) + switch (device) { - case XBOX_CTRL_NUM_BUTTONS: - lambda(XBOX_CTRL_NUM_BUTTONS, button_xbox_ctrl_names); + case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE): + case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S): + lambda(dev_num_buttons[device], button_xbox_ctrl_names); break; - case SBC_NUM_BUTTONS: - lambda(SBC_NUM_BUTTONS, button_sbc_names); + case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): + lambda(dev_num_buttons[device], button_sbc_names); break; } @@ -634,27 +634,27 @@ bool Settings::Save(std::string file_path) std::array, to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)> control_names; for (int device = 0; device < to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX); device++) { - int num_buttons = dev_num_buttons[device]; - if (num_buttons == 0) { + if (dev_num_buttons[device] == 0) { continue; } auto &lambda = [&control_names, &device](int num_buttons, const char *const ctrl_names[]) { for (int i = 0; i < num_buttons; i++) { - char control_name[BUF_NAME_LENGTH]; + char control_name[XBOX_BUTTON_NAME_LENGTH]; std::sprintf(control_name, sect_input_profiles.control, ctrl_names[i]); control_names[device].push_back(control_name); } }; - switch (num_buttons) + switch (device) { - case XBOX_CTRL_NUM_BUTTONS: - lambda(XBOX_CTRL_NUM_BUTTONS, button_xbox_ctrl_names); + case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE): + case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S): + lambda(dev_num_buttons[device], button_xbox_ctrl_names); break; - case SBC_NUM_BUTTONS: - lambda(SBC_NUM_BUTTONS, button_sbc_names); + case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): + lambda(dev_num_buttons[device], button_sbc_names); break; } @@ -752,7 +752,7 @@ void Settings::SyncToEmulator() return false; }); if (it != m_input_profiles[m_input_port[i].Type].end()) { - char controls_name[HIGHEST_NUM_BUTTONS][30]; + char controls_name[HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; for (int index = 0; index < dev_num_buttons[m_input_port[i].Type]; index++) { strncpy(controls_name[index], it->ControlList[index].c_str(), 30); } diff --git a/src/common/input/Button.h b/src/common/input/Button.h index 984246a4c..7ed520884 100644 --- a/src/common/input/Button.h +++ b/src/common/input/Button.h @@ -35,6 +35,8 @@ #define SBC_NUM_BUTTONS 56 #define HIGHEST_NUM_BUTTONS SBC_NUM_BUTTONS +#define XBOX_BUTTON_NAME_LENGTH 30 +#define HOST_BUTTON_NAME_LENGTH 30 /* Represents the gui buttons of the xbox device currently being configured */ class Button diff --git a/src/common/input/EmuDevice.cpp b/src/common/input/EmuDevice.cpp index 5e91f825f..8fd311d1e 100644 --- a/src/common/input/EmuDevice.cpp +++ b/src/common/input/EmuDevice.cpp @@ -50,7 +50,6 @@ EmuDevice::EmuDevice(int type, HWND hwnd, void *wnd) case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): { for (size_t i = 0; i < ARRAY_SIZE(button_sbc_id); i++) { - printf("button id: %d, button idx: %d\n", button_sbc_id[i], i); m_buttons.push_back(new Button(button_sbc_id[i], i, hwnd, wnd)); // Install the subclass for the button control diff --git a/src/common/input/InputManager.cpp b/src/common/input/InputManager.cpp index 64662331f..8b067cee1 100644 --- a/src/common/input/InputManager.cpp +++ b/src/common/input/InputManager.cpp @@ -323,7 +323,7 @@ void InputDeviceManager::DisconnectDevice(int port, int usb_port, bool ack) void InputDeviceManager::BindHostDevice(int port, int usb_port, int type) { char dev_name[50]; - char dev_control_names[HIGHEST_NUM_BUTTONS][30]; + char dev_control_names[HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; g_EmuShared->GetInputDevNameSettings(dev_name, port); g_EmuShared->GetInputBindingsSettings(dev_control_names, dev_num_buttons[type], port); diff --git a/src/common/input/InputManager.h b/src/common/input/InputManager.h index 4118356a3..922a28421 100644 --- a/src/common/input/InputManager.h +++ b/src/common/input/InputManager.h @@ -39,6 +39,13 @@ extern int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)]; +inline XBOX_INPUT_DEVICE input_support_list[] = { + XBOX_INPUT_DEVICE::DEVICE_INVALID, + XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE, + XBOX_INPUT_DEVICE::MS_CONTROLLER_S, + XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER, +}; + #pragma pack(1) // xpad in/out buffers stripped of the first two bytes diff --git a/src/common/input/InputWindow.cpp b/src/common/input/InputWindow.cpp index 11c2527d9..dbd185ed1 100644 --- a/src/common/input/InputWindow.cpp +++ b/src/common/input/InputWindow.cpp @@ -158,7 +158,7 @@ void InputWindow::BindButton(int ControlID) // Don't block the message processing loop std::thread([this, dev, ControlID]() { EnableWindow(m_hwnd_window, FALSE); - char current_text[30]; + char current_text[HOST_BUTTON_NAME_LENGTH]; Button* xbox_button = m_DeviceConfig->FindButtonById(ControlID); xbox_button->GetText(current_text, sizeof(current_text)); xbox_button->UpdateText("..."); @@ -227,7 +227,7 @@ bool InputWindow::SaveProfile(const std::string& name) profile.ProfileName = name; profile.DeviceName = m_host_dev; for (int index = 0; index < m_max_num_buttons; index++) { - char dev_button[30]; + char dev_button[HOST_BUTTON_NAME_LENGTH]; m_DeviceConfig->FindButtonByIndex(index)->GetText(dev_button, sizeof(dev_button)); profile.ControlList.push_back(dev_button); } diff --git a/src/common/input/layout_xbox_device.h b/src/common/input/layout_xbox_device.h index a8bb59e50..69318f121 100644 --- a/src/common/input/layout_xbox_device.h +++ b/src/common/input/layout_xbox_device.h @@ -27,8 +27,6 @@ #pragma once -#define BUF_NAME_LENGTH 30 - #ifndef CXBXR_EMU_EXPORTS #include "gui/resource/ResCxbx.h" @@ -215,7 +213,7 @@ constexpr bool check_button_name_size(unsigned max_num_buttons) { case XBOX_CTRL_NUM_BUTTONS: { for (unsigned i = 0; i < max_num_buttons; i++) { - if (std::char_traits::length(button_xbox_ctrl_names[i]) > (BUF_NAME_LENGTH - 1)) { + if (std::char_traits::length(button_xbox_ctrl_names[i]) > (XBOX_BUTTON_NAME_LENGTH - 1)) { return false; } } @@ -224,7 +222,7 @@ constexpr bool check_button_name_size(unsigned max_num_buttons) case SBC_NUM_BUTTONS: { for (unsigned i = 0; i < max_num_buttons; i++) { - if (std::char_traits::length(button_sbc_names[i]) > (BUF_NAME_LENGTH - 1)) { + if (std::char_traits::length(button_sbc_names[i]) > (XBOX_BUTTON_NAME_LENGTH - 1)) { return false; } } diff --git a/src/common/win32/EmuShared.h b/src/common/win32/EmuShared.h index c854d5c7e..d32f41879 100644 --- a/src/common/win32/EmuShared.h +++ b/src/common/win32/EmuShared.h @@ -130,21 +130,21 @@ class EmuShared : public Mutex void SetInputDevTypeSettings(const int* type, int port) { Lock(); m_DeviceType[port] = *type; Unlock(); } void GetInputDevNameSettings(char* name, int port) { Lock(); strncpy(name, m_DeviceName[port], 50); Unlock(); } void SetInputDevNameSettings(const char* name, int port) { Lock(); strncpy(m_DeviceName[port], name, 50); Unlock(); } - void GetInputBindingsSettings(char button_str[][30], int max_num_buttons, int port) + void GetInputBindingsSettings(char button_str[][HOST_BUTTON_NAME_LENGTH], int max_num_buttons, int port) { assert(max_num_buttons <= HIGHEST_NUM_BUTTONS); Lock(); for (int i = 0; i < max_num_buttons; i++) { - strncpy(button_str[i], m_DeviceControlNames[port][i], 30); + strncpy(button_str[i], m_DeviceControlNames[port][i], HOST_BUTTON_NAME_LENGTH); } Unlock(); } - void SetInputBindingsSettings(const char button_str[][30], int max_num_buttons, int port) + void SetInputBindingsSettings(const char button_str[][HOST_BUTTON_NAME_LENGTH], int max_num_buttons, int port) { assert(max_num_buttons <= HIGHEST_NUM_BUTTONS); Lock(); for (int i = 0; i < max_num_buttons; i++) { - strncpy(m_DeviceControlNames[port][i], button_str[i], 30); + strncpy(m_DeviceControlNames[port][i], button_str[i], HOST_BUTTON_NAME_LENGTH); } Unlock(); } @@ -303,7 +303,7 @@ class EmuShared : public Mutex bool m_bReserved4; unsigned int m_dwKrnlProcID; // Only used for kernel mode level. int m_DeviceType[4]; - char m_DeviceControlNames[4][HIGHEST_NUM_BUTTONS][30]; + char m_DeviceControlNames[4][HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; char m_DeviceName[4][50]; long m_MoAxisRange; long m_MoWheelRange; diff --git a/src/core/hle/XAPI/Xapi.cpp b/src/core/hle/XAPI/Xapi.cpp index 759f62f63..90f2ac10b 100644 --- a/src/core/hle/XAPI/Xapi.cpp +++ b/src/core/hle/XAPI/Xapi.cpp @@ -51,14 +51,14 @@ xbox::PXPP_DEVICE_TYPE g_DeviceType_SBC = nullptr; // Flag is unset after initialize devices is done by simulate LLE USB thread. std::atomic g_bIsDevicesInitializing = true; std::atomic g_bIsDevicesEmulating = false; -static CXBX_XINPUT_IN_STATE InState[4]; +static CXBX_XINPUT_IN_STATE g_InState[4]; // Global bridge for xbox controller to host, 4 elements for 4 ports. CXBX_CONTROLLER_HOST_BRIDGE g_XboxControllerHostBridge[4] = { - { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &InState[0], false, false, false, { 0, 0, 0, 0, 0 } }, - { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &InState[1], false, false, false, { 0, 0, 0, 0, 0 } }, - { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &InState[2], false, false, false, { 0, 0, 0, 0, 0 } }, - { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &InState[3], false, false, false, { 0, 0, 0, 0, 0 } }, + { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &g_InState[0], false, false, false, { 0, 0, 0, 0, 0 } }, + { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &g_InState[1], false, false, false, { 0, 0, 0, 0, 0 } }, + { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &g_InState[2], false, false, false, { 0, 0, 0, 0, 0 } }, + { NULL, PORT_INVALID, XBOX_INPUT_DEVICE::DEVICE_INVALID, &g_InState[3], false, false, false, { 0, 0, 0, 0, 0 } }, }; @@ -100,7 +100,7 @@ bool operator!=(xbox::PXPP_DEVICE_TYPE XppType, XBOX_INPUT_DEVICE XidType) bool ConstructHleInputDevice(int Type, int Port) { g_bIsDevicesEmulating = true; - bool ret; + bool ret = true; switch (Type) { @@ -115,7 +115,6 @@ bool ConstructHleInputDevice(int Type, int Port) g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucInputStateSize = sizeof(XpadInput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucFeedbackSize = sizeof(XpadOutput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.dwPacketNumber = 0; - ret = true; } break; @@ -130,7 +129,6 @@ bool ConstructHleInputDevice(int Type, int Port) g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucInputStateSize = sizeof(XpadInput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucFeedbackSize = sizeof(XpadOutput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.dwPacketNumber = 0; - ret = true; } break; @@ -148,7 +146,6 @@ bool ConstructHleInputDevice(int Type, int Port) g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucInputStateSize = sizeof(SBCInput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucFeedbackSize = sizeof(SBCOutput); g_XboxControllerHostBridge[Port].XboxDeviceInfo.dwPacketNumber = 0; - ret = true; } break; @@ -184,7 +181,7 @@ void DestructHleInputDevice(int Port) g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucInputStateSize = 0; g_XboxControllerHostBridge[Port].XboxDeviceInfo.ucFeedbackSize = 0; g_XboxControllerHostBridge[Port].XboxDeviceInfo.dwPacketNumber = 0; - std::memset(&InState[Port], 0, sizeof(CXBX_XINPUT_IN_STATE)); + std::memset(&g_InState[Port], 0, sizeof(CXBX_XINPUT_IN_STATE)); g_bIsDevicesEmulating = false; } diff --git a/src/gui/DlgInputConfig.cpp b/src/gui/DlgInputConfig.cpp index 823825617..71249682a 100644 --- a/src/gui/DlgInputConfig.cpp +++ b/src/gui/DlgInputConfig.cpp @@ -65,7 +65,7 @@ void SyncInputSettings(int port_num, int dev_type, bool is_opt) return false; }); if (it != g_Settings->m_input_profiles[dev_type].end()) { - char controls_name[HIGHEST_NUM_BUTTONS][30]; + char controls_name[HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; for (int index = 0; index < dev_num_buttons[dev_type]; index++) { strncpy(controls_name[index], it->ControlList[index].c_str(), 30); } @@ -116,12 +116,7 @@ INT_PTR CALLBACK DlgInputConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR for (int i = 0, j = 0; i != 4; i++) { HWND hHandle = GetDlgItem(hWndDlg, IDC_DEVICE_PORT1 + i); - for (auto dev_type : { - XBOX_INPUT_DEVICE::DEVICE_INVALID, - XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE, - XBOX_INPUT_DEVICE::MS_CONTROLLER_S, - XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER - }) { + for (auto dev_type : input_support_list) { LRESULT index = SendMessage(hHandle, CB_ADDSTRING, 0, reinterpret_cast(GetInputDeviceName(to_underlying(dev_type)).c_str())); SendMessage(hHandle, CB_SETITEMDATA, index, to_underlying(dev_type)); if (g_Settings->m_input_port[i].Type == to_underlying(dev_type)) { diff --git a/src/gui/controllers/DlgDukeControllerConfig.cpp b/src/gui/controllers/DlgDukeControllerConfig.cpp index cdd463092..a071f2a9d 100644 --- a/src/gui/controllers/DlgDukeControllerConfig.cpp +++ b/src/gui/controllers/DlgDukeControllerConfig.cpp @@ -121,7 +121,7 @@ void DukeInputWindow::UpdateRumble(int command) switch (command) { case RUMBLE_SET: { - char rumble[30]; + char rumble[HOST_BUTTON_NAME_LENGTH]; SendMessage(m_hwnd_rumble_list, WM_GETTEXT, sizeof(rumble), reinterpret_cast(rumble)); m_rumble = rumble; }