diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-12-12 12:37:08 +0100 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-12-12 13:05:38 +0100 |
commit | 1c773c0869b95d749613e08301637a0b80f1bbc9 (patch) | |
tree | d2a3f0736acd3fd0e043cbeae58ed5b7183344e9 | |
parent | Merge pull request #5183 from lioncash/alias2 (diff) | |
download | yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar.gz yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar.bz2 yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar.lz yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar.xz yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.tar.zst yuzu-1c773c0869b95d749613e08301637a0b80f1bbc9.zip |
-rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 41 | ||||
-rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 4 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 66c4fe60a..f6a0770bf 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -116,6 +116,31 @@ u32 Controller_NPad::IndexToNPad(std::size_t index) { } } +bool Controller_NPad::IsNpadIdValid(u32 npad_id) { + switch (npad_id) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case NPAD_UNKNOWN: + case NPAD_HANDHELD: + return true; + default: + LOG_ERROR(Service_HID, "Invalid npad id {}", npad_id); + return false; + } +} + +bool Controller_NPad::IsDeviceHandleValid(const DeviceHandle& device_handle) { + return IsNpadIdValid(device_handle.npad_id) && + device_handle.npad_type < NpadType::MaxNpadType && + device_handle.device_index < DeviceIndex::MaxDeviceIndex; +} + Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system), system(system) {} Controller_NPad::~Controller_NPad() { @@ -742,6 +767,10 @@ bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, std::size void Controller_NPad::VibrateController(const DeviceHandle& vibration_device_handle, const VibrationValue& vibration_value) { + if (!IsDeviceHandleValid(vibration_device_handle)) { + return; + } + if (!Settings::values.vibration_enabled.GetValue() && !permit_vibration_session_enabled) { return; } @@ -798,12 +827,20 @@ void Controller_NPad::VibrateControllers(const std::vector<DeviceHandle>& vibrat Controller_NPad::VibrationValue Controller_NPad::GetLastVibration( const DeviceHandle& vibration_device_handle) const { + if (!IsDeviceHandleValid(vibration_device_handle)) { + return {}; + } + const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); return latest_vibration_values[npad_index][device_index]; } void Controller_NPad::InitializeVibrationDevice(const DeviceHandle& vibration_device_handle) { + if (!IsDeviceHandleValid(vibration_device_handle)) { + return; + } + const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); InitializeVibrationDeviceAtIndex(npad_index, device_index); @@ -824,6 +861,10 @@ void Controller_NPad::SetPermitVibrationSession(bool permit_vibration_session) { } bool Controller_NPad::IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const { + if (!IsDeviceHandleValid(vibration_device_handle)) { + return false; + } + const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); return vibration_devices_mounted[npad_index][device_index]; diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 96f319294..9fac00231 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -56,12 +56,14 @@ public: JoyconLeft = 6, JoyconRight = 7, Pokeball = 9, + MaxNpadType = 10, }; enum class DeviceIndex : u8 { Left = 0, Right = 1, None = 2, + MaxDeviceIndex = 3, }; enum class GyroscopeZeroDriftMode : u32 { @@ -213,6 +215,8 @@ public: static Settings::ControllerType MapNPadToSettingsType(Controller_NPad::NPadControllerType type); static std::size_t NPadIdToIndex(u32 npad_id); static u32 IndexToNPad(std::size_t index); + static bool IsNpadIdValid(u32 npad_id); + static bool IsDeviceHandleValid(const DeviceHandle& device_handle); private: struct CommonHeader { |