From 125d104df4f1d5eafcf7e367b4d15fc41f543a1e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 21 Nov 2020 13:54:31 +1000 Subject: [PATCH] Pad: Fix controller state not being ignored in state load --- src/core/pad.cpp | 75 +++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/src/core/pad.cpp b/src/core/pad.cpp index 5e0c4fb7e..b8b0a5314 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -54,49 +54,66 @@ bool Pad::DoState(StateWrapper& sw) ControllerType state_controller_type = controller_type; sw.Do(&state_controller_type); - if (controller_type != state_controller_type) + if (g_settings.load_devices_from_save_states) { - if (g_settings.load_devices_from_save_states) + if (controller_type != state_controller_type) { - g_host_interface->AddFormattedOSDMessage( - 10.0f, - g_host_interface->TranslateString( - "OSDMessage", "Save state contains controller type %s in port %u, but %s is used. Switching."), - Settings::GetControllerTypeName(state_controller_type), i + 1u, - Settings::GetControllerTypeName(controller_type)); - - m_controllers[i].reset(); - if (state_controller_type != ControllerType::None) + if (g_settings.load_devices_from_save_states) { - m_controllers[i] = Controller::Create(state_controller_type, i); - if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) - return false; + g_host_interface->AddFormattedOSDMessage( + 10.0f, + g_host_interface->TranslateString( + "OSDMessage", "Save state contains controller type %s in port %u, but %s is used. Switching."), + Settings::GetControllerTypeName(state_controller_type), i + 1u, + Settings::GetControllerTypeName(controller_type)); + + m_controllers[i].reset(); + if (state_controller_type != ControllerType::None) + { + m_controllers[i] = Controller::Create(state_controller_type, i); + if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) + return false; + } + } + else + { + g_host_interface->AddFormattedOSDMessage( + 10.0f, + g_host_interface->TranslateString("OSDMessage", "Ignoring mismatched controller type %s in port %u."), + Settings::GetControllerTypeName(state_controller_type), i + 1u); + + // we still need to read the save state controller state + if (state_controller_type != ControllerType::None) + { + std::unique_ptr dummy_controller = Controller::Create(state_controller_type, i); + if (dummy_controller) + { + if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw)) + return false; + } + } } } else { - g_host_interface->AddFormattedOSDMessage( - 10.0f, g_host_interface->TranslateString("OSDMessage", "Ignoring mismatched controller type %s in port %u."), - Settings::GetControllerTypeName(state_controller_type), i + 1u); - - // we still need to read the save state controller state - if (state_controller_type != ControllerType::None) + if (m_controllers[i]) { - std::unique_ptr dummy_controller = Controller::Create(state_controller_type, i); - if (dummy_controller) - { - if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw)) - return false; - } + if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) + return false; } } } else { - if (m_controllers[i]) + // we still need to read the save state controller state + if (state_controller_type != ControllerType::None) { - if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) - return false; + std::unique_ptr dummy_controller = Controller::Create(state_controller_type, i); + if (dummy_controller) + { + if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw)) + return false; + } } }