Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12034 from MaverickAmon02/controller-update-race
Fix unsafe netplay code in SI_DeviceGCController
  • Loading branch information
AdmiralCurtiss committed Jul 9, 2023
2 parents 7bb04ff + d122492 commit 80c44ea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/SI/SI.cpp
Expand Up @@ -568,7 +568,7 @@ void SerialInterfaceManager::UpdateDevices()
NetPlay::SetSIPollBatching(false);
}

SIDevices SerialInterfaceManager::GetDeviceType(int channel)
SIDevices SerialInterfaceManager::GetDeviceType(int channel) const
{
if (channel < 0 || channel >= MAX_SI_CHANNELS || !m_channel[channel].device)
return SIDEVICE_NONE;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/SI/SI.h
Expand Up @@ -63,7 +63,7 @@ class SerialInterfaceManager

void ChangeDevice(SIDevices device, int channel);

SIDevices GetDeviceType(int channel);
SIDevices GetDeviceType(int channel) const;

u32 GetPollXLines();

Expand Down
20 changes: 2 additions & 18 deletions Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
Expand Up @@ -14,6 +14,7 @@
#include "Core/CoreTiming.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/SI/SI.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/HW/SystemTimers.h"
#include "Core/Movie.h"
Expand All @@ -36,14 +37,6 @@ CSIDevice_GCController::CSIDevice_GCController(Core::System& system, SIDevices d
m_origin.origin_stick_y = GCPadStatus::MAIN_STICK_CENTER_Y;
m_origin.substick_x = GCPadStatus::C_STICK_CENTER_X;
m_origin.substick_y = GCPadStatus::C_STICK_CENTER_Y;

m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
}

CSIDevice_GCController::~CSIDevice_GCController()
{
Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
}

int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
Expand Down Expand Up @@ -316,7 +309,7 @@ void CSIDevice_GCController::SendCommand(u32 command, u8 poll)

if (pad_num < 4)
{
const SIDevices device = m_config_si_devices[pad_num];
const SIDevices device = m_system.GetSerialInterface().GetDeviceType(pad_num);
if (type == 1)
CSIDevice_GCController::Rumble(pad_num, 1.0, device);
else
Expand Down Expand Up @@ -346,15 +339,6 @@ void CSIDevice_GCController::DoState(PointerWrap& p)
p.Do(m_last_button_combo);
}

void CSIDevice_GCController::RefreshConfig()
{
for (int i = 0; i < 4; ++i)
{
const SerialInterface::SIDevices device = Config::Get(Config::GetInfoForSIDevice(i));
m_config_si_devices[i] = device;
}
}

CSIDevice_TaruKonga::CSIDevice_TaruKonga(Core::System& system, SIDevices device, int device_number)
: CSIDevice_GCController(system, device, device_number)
{
Expand Down
7 changes: 0 additions & 7 deletions Source/Core/Core/HW/SI/SI_DeviceGCController.h
Expand Up @@ -54,7 +54,6 @@ class CSIDevice_GCController : public ISIDevice
public:
// Constructor
CSIDevice_GCController(Core::System& system, SIDevices device, int device_number);
~CSIDevice_GCController() override;

// Run the SI Buffer
int RunBuffer(u8* buffer, int request_length) override;
Expand Down Expand Up @@ -83,12 +82,6 @@ class CSIDevice_GCController : public ISIDevice

protected:
void SetOrigin(const GCPadStatus& pad_status);

private:
void RefreshConfig();

std::array<SIDevices, 4> m_config_si_devices{};
size_t m_config_changed_callback_id;
};

// "TaruKonga", the DK Bongo controller
Expand Down

0 comments on commit 80c44ea

Please sign in to comment.