From 6912f0a18c45522309f72c78465895af79321979 Mon Sep 17 00:00:00 2001 From: "baby.lueshi" Date: Sat, 12 Feb 2011 00:06:58 +0000 Subject: [PATCH] Fix crash on loading savestate with an input movie attatched to it in Gamecube games. Fixed Gamecube controllers being disconnected for a couple ingame seconds when loading a savestate with an input movie attatched. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7141 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/OnFrame.cpp | 21 ++++++++++++++------- Source/Core/Core/Src/OnFrame.h | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/Src/OnFrame.cpp b/Source/Core/Core/Src/OnFrame.cpp index ee33536bc7..5cd83a1030 100644 --- a/Source/Core/Core/Src/OnFrame.cpp +++ b/Source/Core/Core/Src/OnFrame.cpp @@ -132,19 +132,24 @@ bool IsPlayingInput() bool IsUsingPad(int controller) { - return (g_numPads & (1 << controller)); + return ((g_numPads & (1 << controller)) != 0); } bool IsUsingWiimote(int wiimote) { - return (g_numPads & (1 << (wiimote + 4))); + return ((g_numPads & (1 << (wiimote + 4))) != 0); } -void ChangePads() +void ChangePads(bool instantly) { if (Core::GetState() != Core::CORE_UNINITIALIZED) + { for (int i = 0; i < 4; i++) - SerialInterface::ChangeDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i); + if (instantly) // Changes from savestates need to be instantaneous + SerialInterface::AddDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i); + else + SerialInterface::ChangeDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i); + } } void ChangeWiiPads() @@ -301,8 +306,10 @@ void LoadInput(const char *filename) g_numPads = header.numControllers; - ChangePads(); - ChangeWiiPads(); + ChangePads(true); + + if (Core::g_CoreStartupParameter.bWii) + ChangeWiiPads(); if (g_recordfd) fclose(g_recordfd); @@ -420,7 +427,7 @@ void SaveRecording(const char *filename) header.filetype[0] = 'D'; header.filetype[1] = 'T'; header.filetype[2] = 'M'; header.filetype[3] = 0x1A; strncpy((char *)header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6); header.bWii = Core::g_CoreStartupParameter.bWii; - header.numControllers = g_numPads; + header.numControllers = g_numPads & (Core::g_CoreStartupParameter.bWii ? 0xFF : 0x0F); header.bFromSaveState = false; // TODO: add the case where it's true header.frameCount = g_frameCounter; diff --git a/Source/Core/Core/Src/OnFrame.h b/Source/Core/Core/Src/OnFrame.h index feefe821c4..4d9ab488c0 100644 --- a/Source/Core/Core/Src/OnFrame.h +++ b/Source/Core/Core/Src/OnFrame.h @@ -100,7 +100,7 @@ bool IsPlayingInput(); bool IsUsingPad(int controller); bool IsUsingWiimote(int wiimote); -void ChangePads(); +void ChangePads(bool instantly = false); void ChangeWiiPads(); void SetFrameStepping(bool bEnabled);