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 dbd450785d..8b9ffa4c5e 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 @@ -24,6 +24,7 @@ #include "WII_IPC_HLE.h" #include "WII_IPC_HLE_Device_usb.h" #include "../ConfigManager.h" +#include "../Movie.h" #include "CoreTiming.h" // The device class @@ -104,7 +105,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::~CWII_IPC_HLE_Device_usb_oh1_57e_305() void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) { /* - //things that do not get saved: + //things that do not get saved: (why not?) std::vector m_WiiMotes; @@ -120,25 +121,70 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) p.Do(m_ScanEnable); m_acl_pool.DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) { - m_EventQueue.clear(); - } - if (p.GetMode() == PointerWrap::MODE_READ && - SConfig::GetInstance().m_WiimoteReconnectOnLoad) + bool storeFullData = (Movie::IsRecordingInput() || Movie::IsPlayingInput()); + p.Do(storeFullData); + p.DoMarker("storeFullData in CWII_IPC_HLE_Device_usb_oh1_57e_305"); + + if (!storeFullData) { - // Reset the connection of all connected wiimotes - for (unsigned int i = 0; i < 4; i++) - { - if (!m_WiiMotes[i].IsInactive()) - { - m_WiiMotes[i].Activate(false); - m_WiiMotes[i].Activate(true); - } - else - { - m_WiiMotes[i].Activate(false); - } - } + if (p.GetMode() == PointerWrap::MODE_READ) + { + m_EventQueue.clear(); + + if (SConfig::GetInstance().m_WiimoteReconnectOnLoad) + { + // Reset the connection of all connected wiimotes + for (unsigned int i = 0; i < 4; i++) + { + if (!m_WiiMotes[i].IsInactive()) + { + m_WiiMotes[i].Activate(false); + m_WiiMotes[i].Activate(true); + } + else + { + m_WiiMotes[i].Activate(false); + } + } + } + } + } + else + { + // I'm not sure why these things aren't normally saved, but I think they can affect the emulation state, + // so if sync matters (e.g. if a movie is active), we really should save them. + // also, it's definitely not safe to do the above auto-reconnect hack either. + // (unless we can do it without changing anything that affects emulation state, which is not currently the case) + + p.Do(m_EventQueue); + p.DoMarker("m_EventQueue"); + + // m_WiiMotes is kind of annoying to save. maybe this could be done in a more general way. + u32 vec_size = (u32)m_WiiMotes.size(); + p.Do(vec_size); + for (u32 i = 0; i < vec_size; ++i) + { + if (i < m_WiiMotes.size()) + { + CWII_IPC_HLE_WiiMote& wiimote = m_WiiMotes[i]; + wiimote.DoState(p); + } + else + { + bdaddr_t tmpBD = BDADDR_ANY; + CWII_IPC_HLE_WiiMote wiimote = CWII_IPC_HLE_WiiMote(this, i, tmpBD, false); + wiimote.DoState(p); + if (p.GetMode() == PointerWrap::MODE_READ) + { + m_WiiMotes.push_back(wiimote); + _dbg_assert_(WII_IPC_WIIMOTE, m_WiiMotes.size() == i); + } + } + } + if (p.GetMode() == PointerWrap::MODE_READ) + while ((u32)m_WiiMotes.size() > vec_size) + m_WiiMotes.pop_back(); + p.DoMarker("m_WiiMotes"); } } @@ -1881,4 +1927,4 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::LOG_LinkKey(const u8* _pLinkKey) , _pLinkKey[0], _pLinkKey[1], _pLinkKey[2], _pLinkKey[3], _pLinkKey[4], _pLinkKey[5], _pLinkKey[6], _pLinkKey[7] , _pLinkKey[8], _pLinkKey[9], _pLinkKey[10], _pLinkKey[11], _pLinkKey[12], _pLinkKey[13], _pLinkKey[14], _pLinkKey[15]); -} +} \ No newline at end of file diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h index c8b1feb87f..61c439a7ec 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -41,6 +41,12 @@ struct SQueuedEvent } memset(m_buffer, 0, 1024); } + + SQueuedEvent() + : m_size(0) + , m_connectionHandle(0) + { + } }; 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 1acf496a1a..8445eeffdc 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 @@ -53,7 +53,7 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* m_ConnectionState = (ready) ? CONN_READY : CONN_INACTIVE; m_ConnectionHandle = 0x100 + _Number; - memset(m_LinkKey, 0xA0 + _Number, 16); + memset(m_LinkKey, 0xA0 + _Number, HCI_KEY_SIZE); bdaddr_t _nullBD = BDADDR_ANY; if (memcmp(&m_BD, &_nullBD, sizeof(bdaddr_t))==0) @@ -84,7 +84,28 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* void CWII_IPC_HLE_WiiMote::DoState(PointerWrap &p) { + // this function is usually not called... see CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState + p.Do(m_ConnectionState); + + p.Do(m_HIDControlChannel_Connected); + p.Do(m_HIDControlChannel_ConnectedWait); + p.Do(m_HIDControlChannel_Config); + p.Do(m_HIDControlChannel_ConfigWait); + p.Do(m_HIDInterruptChannel_Connected); + p.Do(m_HIDInterruptChannel_ConnectedWait); + p.Do(m_HIDInterruptChannel_Config); + p.Do(m_HIDInterruptChannel_ConfigWait); + + p.Do(m_BD); + p.Do(m_ConnectionHandle); + p.Do(uclass); + p.Do(features); + p.Do(lmp_version); + p.Do(m_LinkKey); + p.Do(m_Name); + + p.Do(m_Channel); } //