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.
This commit is contained in:
Léo Lam 2017-07-16 22:11:53 +08:00
parent c759739ee9
commit 02f32a9b26
3 changed files with 7 additions and 7 deletions

View File

@ -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<u8>& 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;

View File

@ -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");

View File

@ -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)
};