From 6ae8fd0d347c96b6a28694608bb14bb30a6b513f Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 27 Nov 2019 13:39:38 +0300 Subject: [PATCH] ds4: Add workarounds for some 3rd party controllers --- rpcs3/ds4_pad_handler.cpp | 16 ++++++++++++++-- rpcs3/ds4_pad_handler.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rpcs3/ds4_pad_handler.cpp b/rpcs3/ds4_pad_handler.cpp index f695939bb6..6893b71522 100644 --- a/rpcs3/ds4_pad_handler.cpp +++ b/rpcs3/ds4_pad_handler.cpp @@ -407,7 +407,7 @@ bool ds4_pad_handler::GetCalibrationData(const std::shared_ptr& ds4De ds4Dev->calibData[DS4CalibIndex::ROLL].bias = GetS16LEData(&buf[5]); s16 pitchPlus, pitchNeg, rollPlus, rollNeg, yawPlus, yawNeg; - if (ds4Dev->btCon) + if (ds4Dev->btCon || ds4Dev->unAuthentic) { pitchPlus = GetS16LEData(&buf[7]); yawPlus = GetS16LEData(&buf[9]); @@ -479,8 +479,20 @@ void ds4_pad_handler::CheckAddDevice(hid_device* hidDevice, hid_device_info* hid // Let's try getting 0x81 feature report, which should will return mac address on wired, and should error on bluetooth std::array buf{}; buf[0] = 0x81; - if (hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x81_SIZE) > 0) + if (const auto length = hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x81_SIZE); length > 0) { + if (length != DS4_FEATURE_REPORT_0x81_SIZE) + { + // Controller may not be genuine. These controllers do not have feature 0x81 implemented and calibration data is in bluetooth format even in USB mode! + ds4Dev->unAuthentic = true; + LOG_WARNING(HLE, "DS4 controller may not be genuine. Workaround enabled."); + + // Read feature report 0x12 instead which is what the console uses. + buf[0] = 0x12; + buf[1] = 0; + hid_get_feature_report(hidDevice, buf.data(), 16); + } + serial = fmt::format("%x%x%x%x%x%x", buf[6], buf[5], buf[4], buf[3], buf[2], buf[1]); } else diff --git a/rpcs3/ds4_pad_handler.h b/rpcs3/ds4_pad_handler.h index c4b81b8c1a..2ee140d8cb 100644 --- a/rpcs3/ds4_pad_handler.h +++ b/rpcs3/ds4_pad_handler.h @@ -81,6 +81,7 @@ class ds4_pad_handler final : public PadHandlerBase std::string path{ "" }; bool btCon{ false }; bool hasCalibData{ false }; + bool unAuthentic{ false }; std::array calibData{}; bool newVibrateData{ true }; u8 largeVibrate{ 0 };