Skip to content
Permalink
Browse files

NetPlay: Sync Wiimote extension

Small addition of NetPlay code in Core.cpp was needed to set the
extensions at the right time, as init would override them otherwise.
This solution is more elegant than modifying the user's INI files on
game start.
  • Loading branch information...
Techjar committed Nov 22, 2018
1 parent 4e5f83d commit 2e19efa8d5bc64cea8ea5164bcc2ef74c291fac9
@@ -498,6 +498,9 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
{
Wiimote::LoadConfig();
}

if (NetPlay::IsNetPlayRunning())
NetPlay::SetupWiimotes();
}

Common::ScopeGuard controller_guard{[init_controllers] {
@@ -52,7 +52,9 @@
#include "Core/Movie.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/WiiRoot.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/GCAdapter.h"
#include "InputCommon/InputConfig.h"
#include "UICommon/GameFile.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h"
@@ -558,11 +560,12 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
packet >> m_net_settings.m_OCFactor;
packet >> m_net_settings.m_ReducePollingRate;

int tmp;
packet >> tmp;
m_net_settings.m_EXIDevice[0] = static_cast<ExpansionInterface::TEXIDevices>(tmp);
packet >> tmp;
m_net_settings.m_EXIDevice[1] = static_cast<ExpansionInterface::TEXIDevices>(tmp);
for (auto& device : m_net_settings.m_EXIDevice)
{
int tmp;
packet >> tmp;
device = static_cast<ExpansionInterface::TEXIDevices>(tmp);
}

packet >> m_net_settings.m_EFBAccessEnable;
packet >> m_net_settings.m_BBoxEnable;
@@ -611,6 +614,9 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
packet >> m_net_settings.m_SyncCodes;
packet >> m_net_settings.m_SyncAllWiiSaves;

for (int& extension : m_net_settings.m_WiimoteExtension)
packet >> extension;

m_net_settings.m_IsHosting = m_local_player->IsHost();
m_net_settings.m_HostInputAuthority = m_host_input_authority;
}
@@ -2173,6 +2179,23 @@ bool IsSyncingAllWiiSaves()
return false;
}

void SetupWiimotes()
{
ASSERT(IsNetPlayRunning());
const NetSettings& netplay_settings = netplay_client->GetNetSettings();
const PadMappingArray& wiimote_map = netplay_client->GetWiimoteMapping();
for (int i = 0; i < netplay_settings.m_WiimoteExtension.size(); i++)
{
if (wiimote_map[i] > 0)
{
static_cast<ControllerEmu::Extension*>(
static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(i))
->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Extension))
->switch_extension = netplay_settings.m_WiimoteExtension[i];
}
}
}

void NetPlay_Enable(NetPlayClient* const np)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
@@ -36,7 +36,7 @@ struct NetSettings
bool m_ReducePollingRate;
bool m_OCEnable;
float m_OCFactor;
ExpansionInterface::TEXIDevices m_EXIDevice[2];
std::array<ExpansionInterface::TEXIDevices, 2> m_EXIDevice;
bool m_EFBAccessEnable;
bool m_BBoxEnable;
bool m_ForceProgressive;
@@ -80,6 +80,7 @@ struct NetSettings
bool m_SyncCodes;
std::string m_SaveDataRegion;
bool m_SyncAllWiiSaves;
std::array<int, 4> m_WiimoteExtension;
bool m_IsHosting;
bool m_HostInputAuthority;
};
@@ -209,4 +210,5 @@ void ClearWiiSyncData();
void SetSIPollBatching(bool state);
void SendPowerButtonEvent();
bool IsSyncingAllWiiSaves();
void SetupWiimotes();
} // namespace NetPlay
@@ -42,12 +42,16 @@
#include "Core/HW/Sram.h"
#include "Core/HW/WiiSave.h"
#include "Core/HW/WiiSaveStructs.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/IOS/ES/ES.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOS.h"
#include "Core/NetPlayClient.h" //for NetPlayUI
#include "DiscIO/Enums.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/GCPadStatus.h"
#include "InputCommon/InputConfig.h"
#include "UICommon/GameFile.h"

#if !defined(_WIN32)
@@ -1159,8 +1163,10 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_OCEnable;
spac << m_settings.m_OCFactor;
spac << m_settings.m_ReducePollingRate;
spac << m_settings.m_EXIDevice[0];
spac << m_settings.m_EXIDevice[1];

for (auto& device : m_settings.m_EXIDevice)
spac << device;

spac << m_settings.m_EFBAccessEnable;
spac << m_settings.m_BBoxEnable;
spac << m_settings.m_ForceProgressive;
@@ -1206,6 +1212,16 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_SyncCodes;
spac << m_settings.m_SyncAllWiiSaves;

for (int i = 0; i < m_settings.m_WiimoteExtension.size(); i++)
{
const int extension =
static_cast<ControllerEmu::Extension*>(
static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(i))
->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Extension))
->switch_extension;
spac << extension;
}

SendAsyncToClients(std::move(spac));

m_start_pending = false;

0 comments on commit 2e19efa

Please sign in to comment.
You can’t perform that action at this time.