diff --git a/Source/Core/Common/Src/SysConf.h b/Source/Core/Common/Src/SysConf.h index c2db94fa3b..13cbbe5df1 100644 --- a/Source/Core/Common/Src/SysConf.h +++ b/Source/Core/Common/Src/SysConf.h @@ -55,6 +55,25 @@ struct SSysConfEntry template T GetData() { return *(T*)data; } + bool GetArrayData(u8* dest, u16 destSize) + { + if (dest && destSize >= dataLength) + { + memcpy(dest, data, dataLength); + return true; + } + return false; + } + bool SetArrayData(u8* buffer, u16 bufferSize) + { + + if (buffer && bufferSize == dataLength) + { + memcpy(data, buffer, dataLength); + return true; + } + return false; + } }; class SysConf @@ -95,6 +114,49 @@ public: return m_Entries.at(index).GetData(); } + bool GetArrayData(const char* sectionName, u8* dest, u16 destSize) + { + if (!m_IsValid) + { + PanicAlert("Trying to read from invalid SYSCONF"); + return 0; + } + + size_t index = 0; + for (; index < m_Entries.size() - 1; index++) + { + if (strcmp(m_Entries.at(index).name, sectionName) == 0) + break; + } + if (index == m_Entries.size() - 1) + { + PanicAlert("Section %s not found in SYSCONF", sectionName); + return 0; + } + + return m_Entries.at(index).GetArrayData(dest, destSize); + } + + bool SetArrayData(const char* sectionName, u8* buffer, u16 bufferSize) + { + if (!m_IsValid) + return false; + + size_t index = 0; + for (; index < m_Entries.size() - 1; index++) + { + if (strcmp(m_Entries.at(index).name, sectionName) == 0) + break; + } + if (index == m_Entries.size() - 1) + { + PanicAlert("Section %s not found in SYSCONF", sectionName); + return false; + } + + return m_Entries.at(index).SetArrayData(buffer, bufferSize); + } + template bool SetData(const char* sectionName, T newValue) { diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 8ed475a2e1..d835cb146a 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -22,7 +22,9 @@ #include "../HW/WII_IPC.h" #include "WII_IPC_HLE.h" #include "WII_IPC_HLE_Device_usb.h" - +#include "../ConfigManager.h" +#define WIIMOTESIZE 0x46 +#define BTDINFSIZE WIIMOTESIZE * 0x10 // The device class CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _DeviceID, const std::string& _rDeviceName) : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) @@ -33,10 +35,54 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De , m_NumCompPackets_Freq(0) { // Activate only first Wiimote by default - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 0, true)); - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 1)); - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 2)); - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 3)); + + u8 BT_DINF[BTDINFSIZE]; + u8 maxWM = 0; + if (!SConfig::GetInstance().m_SYSCONF->GetArrayData("BT.DINF", BT_DINF, BTDINFSIZE)) + { + PanicAlert("Trying to read from invalid SYSCONF\nWiimote bt ids are not available"); + } + else + { + maxWM = BT_DINF[0]; + bdaddr_t tmpBD;// = BDADDR_ANY; + u8 i = 0; + while (i < maxWM) + { + tmpBD.b[5] = BT_DINF[1 + (i * WIIMOTESIZE)]; + tmpBD.b[4] = BT_DINF[2 + (i * WIIMOTESIZE)]; + tmpBD.b[3] = BT_DINF[3 + (i * WIIMOTESIZE)]; + tmpBD.b[2] = BT_DINF[4 + (i * WIIMOTESIZE)]; + tmpBD.b[1] = BT_DINF[5 + (i * WIIMOTESIZE)]; + tmpBD.b[0] = BT_DINF[6 + (i * WIIMOTESIZE)]; + + INFO_LOG(WII_IPC_WIIMOTE, "Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); + m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, !i)); + i++; + } + while (i < 4) + { + const char * wmName = "Nintendo RVL-CNT-01"; + BT_DINF[0] = 4; + BT_DINF[1 + (i * WIIMOTESIZE)] = tmpBD.b[5] = i; + BT_DINF[2 + (i * WIIMOTESIZE)] = tmpBD.b[4] = 0x00; + BT_DINF[3 + (i * WIIMOTESIZE)] = tmpBD.b[3] = 0x79; + BT_DINF[4 + (i * WIIMOTESIZE)] = tmpBD.b[2] = 0x19; + BT_DINF[5 + (i * WIIMOTESIZE)] = tmpBD.b[1] = 0x02; + BT_DINF[6 + (i * WIIMOTESIZE)] = tmpBD.b[0] = 0x11; + memcpy((BT_DINF+7 + (i * WIIMOTESIZE)), wmName, 20); + + INFO_LOG(WII_IPC_WIIMOTE, "Adding to SYSConf Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); + m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, !i)); + i++; + } + if (BT_DINF[0] != maxWM) + { + // save now so that when games load sysconf file it includes the new wiimotes + if (!SConfig::GetInstance().m_SYSCONF->SetArrayData("BT.DINF", BT_DINF, BTDINFSIZE) || !SConfig::GetInstance().m_SYSCONF->Save()) + PanicAlert("Failed to write BT.DINF to SYSCONF"); + } + } // The BCM2045's btaddr: m_ControllerBD.b[0] = 0x11; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp index e8ca0a0370..0ada0bda7f 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp @@ -35,8 +35,9 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305* GetUsbPointer() return s_Usb; } -CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready) - : m_HIDControlChannel_Connected(false) +CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready) + : m_BD(_BD) + , m_HIDControlChannel_Connected(false) , m_HIDControlChannel_ConnectedWait(false) , m_HIDControlChannel_Config(false) , m_HIDControlChannel_ConfigWait(false) @@ -46,7 +47,6 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* , m_HIDInterruptChannel_ConfigWait(false) , m_Name("Nintendo RVL-CNT-01") , m_pHost(_pHost) - { DEBUG_LOG(WII_IPC_WIIMOTE, "Wiimote: #%i Constructed", _Number); @@ -56,13 +56,17 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* m_ConnectionHandle = 0x100 + _Number; memset(m_LinkKey, 0xA0 + _Number, 16); - m_BD.b[0] = 0x11; - m_BD.b[1] = 0x02; - m_BD.b[2] = 0x19; - m_BD.b[3] = 0x79; - m_BD.b[4] = 0x00; - m_BD.b[5] = _Number; + bdaddr_t _nullBD = BDADDR_ANY; + if (memcmp(&m_BD, &_nullBD, sizeof(bdaddr_t))==0) + { + m_BD.b[0] = 0x11; + m_BD.b[1] = 0x02; + m_BD.b[2] = 0x19; + m_BD.b[3] = 0x79; + m_BD.b[4] = 0x00; + m_BD.b[5] = _Number; + } uclass[0]= 0x00; uclass[1]= 0x04; uclass[2]= 0x48; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h index 50ba2eb414..21a7d7e1bd 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h @@ -49,7 +49,7 @@ private: class CWII_IPC_HLE_WiiMote { public: - CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready = false); + CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready = false); virtual ~CWII_IPC_HLE_WiiMote() {}