From 02f32a9b2670ec7df3e8ae947b1b755d6933b5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 16 Jul 2017 22:11:53 +0800 Subject: [PATCH] Handle BT.DINF properly The section is 0x461 bytes long, not 0x460. The config data is also now initialised to zero to avoid garbage being written to the SYSCONF. Because our handling has been wrong forever, we discard older BT.DINF section backups as using them would result in the section being the wrong size / incomplete again. --- Source/Core/Core/IOS/USB/Bluetooth/BTBase.cpp | 8 ++++---- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp | 4 ++-- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTBase.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTBase.cpp index ddf887c32e..75e8fef2a0 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTBase.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTBase.cpp @@ -21,7 +21,7 @@ namespace HLE { void BackUpBTInfoSection(const SysConf* sysconf) { - const std::string filename = File::GetUserPath(D_SESSION_WIIROOT_IDX) + DIR_SEP WII_BTDINF_BACKUP; + const std::string filename = File::GetUserPath(D_CONFIG_IDX) + DIR_SEP WII_BTDINF_BACKUP; if (File::Exists(filename)) return; File::IOFile backup(filename, "wb"); @@ -31,18 +31,18 @@ void BackUpBTInfoSection(const SysConf* sysconf) return; const std::vector& section = btdinf->bytes; - if (!backup.WriteBytes(section.data(), section.size() - 1)) + if (!backup.WriteBytes(section.data(), section.size())) ERROR_LOG(IOS_WIIMOTE, "Failed to back up BT.DINF section"); } void RestoreBTInfoSection(SysConf* sysconf) { - const std::string filename = File::GetUserPath(D_SESSION_WIIROOT_IDX) + DIR_SEP WII_BTDINF_BACKUP; + const std::string filename = File::GetUserPath(D_CONFIG_IDX) + DIR_SEP WII_BTDINF_BACKUP; File::IOFile backup(filename, "rb"); if (!backup) return; auto& section = sysconf->GetOrAddEntry("BT.DINF", SysConf::Entry::Type::BigArray)->bytes; - if (!backup.ReadBytes(section.data(), section.size() - 1)) + if (!backup.ReadBytes(section.data(), section.size())) { ERROR_LOG(IOS_WIIMOTE, "Failed to read backed up BT.DINF section"); return; diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index dd2feab4c6..0761720c9c 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -47,7 +47,7 @@ BluetoothEmu::BluetoothEmu(Kernel& ios, const std::string& device_name) if (!Core::WantsDeterminism()) BackUpBTInfoSection(&sysconf); - _conf_pads BT_DINF; + _conf_pads BT_DINF{}; bdaddr_t tmpBD; u8 i = 0; while (i < MAX_BBMOTES) @@ -79,7 +79,7 @@ BluetoothEmu::BluetoothEmu(Kernel& ios, const std::string& device_name) // save now so that when games load sysconf file it includes the new Wii Remotes // and the correct order for connected Wii Remotes auto& section = sysconf.GetOrAddEntry("BT.DINF", SysConf::Entry::Type::BigArray)->bytes; - section.resize(sizeof(_conf_pads) + 1); + section.resize(sizeof(_conf_pads)); std::memcpy(section.data(), &BT_DINF, sizeof(_conf_pads)); if (!sysconf.Save()) PanicAlertT("Failed to write BT.DINF to SYSCONF"); diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h index c772ce6a50..0e6f4d0173 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h @@ -191,7 +191,7 @@ private: u8 num_registered; _conf_pad_device registered[CONF_PAD_MAX_REGISTERED]; _conf_pad_device active[MAX_BBMOTES]; - u8 unknown[0x45]; + _conf_pad_device unknown; }; #pragma pack(pop) };