From ed1a9480b0233e424ae3c266467b6d821c801793 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Sat, 19 Jan 2013 15:02:02 -0500 Subject: [PATCH] Misc movie fixes. Fix setting memory cards on playback. Fix saving revision to header. Herpa derp lets open a file while it's still open in another function, and not even check if it fails to load. Fix an assumption that wii games are using a wiimote. --- Source/Core/Core/Src/HW/EXI.cpp | 8 ++++- Source/Core/Core/Src/Movie.cpp | 52 ++++++++++++++++----------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Source/Core/Core/Src/HW/EXI.cpp b/Source/Core/Core/Src/HW/EXI.cpp index 8800ea6095..1e86bd1b90 100644 --- a/Source/Core/Core/Src/HW/EXI.cpp +++ b/Source/Core/Core/Src/HW/EXI.cpp @@ -25,6 +25,7 @@ #include "EXI.h" #include "Sram.h" +#include "../Movie.h" SRAM g_SRAM; namespace ExpansionInterface @@ -44,7 +45,12 @@ void Init() for (u32 i = 0; i < NUM_CHANNELS; i++) g_Channels[i] = new CEXIChannel(i); - g_Channels[0]->AddDevice(SConfig::GetInstance().m_EXIDevice[0], 0); // SlotA + if (Movie::IsPlayingInput() && Movie::IsUsingMemcard() && Movie::IsConfigSaved()) + g_Channels[0]->AddDevice(EXIDEVICE_MEMORYCARD, 0); // SlotA + else if(Movie::IsPlayingInput() && !Movie::IsUsingMemcard() && Movie::IsConfigSaved()) + g_Channels[0]->AddDevice(EXIDEVICE_NONE, 0); // SlotA + else + g_Channels[0]->AddDevice(SConfig::GetInstance().m_EXIDevice[0], 0); // SlotA g_Channels[0]->AddDevice(EXIDEVICE_MASKROM, 1); g_Channels[0]->AddDevice(SConfig::GetInstance().m_EXIDevice[2], 2); // Serial Port 1 g_Channels[1]->AddDevice(SConfig::GetInstance().m_EXIDevice[1], 0); // SlotB diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index 316181d449..752e367431 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -736,16 +736,6 @@ bool PlayInput(const char *filename) goto cleanup; } - // Load savestate (and skip to frame data) - if(tmpHeader.bFromSaveState) - { - const std::string stateFilename = std::string(filename) + ".sav"; - if(File::Exists(stateFilename)) - Core::SetStateFileName(stateFilename); - g_bRecordingFromSaveState = true; - Movie::LoadInput(filename); - } - ReadHeader(); g_totalFrames = tmpHeader.frameCount; g_totalLagCount = tmpHeader.lagCount; @@ -762,6 +752,16 @@ bool PlayInput(const char *filename) g_currentByte = 0; g_recordfd.Close(); + // Load savestate (and skip to frame data) + if(tmpHeader.bFromSaveState) + { + const std::string stateFilename = std::string(filename) + ".sav"; + if(File::Exists(stateFilename)) + Core::SetStateFileName(stateFilename); + g_bRecordingFromSaveState = true; + Movie::LoadInput(filename); + } + return true; cleanup: @@ -786,7 +786,13 @@ void DoState(PointerWrap &p) void LoadInput(const char *filename) { - File::IOFile t_record(filename, "r+b"); + File::IOFile t_record; + if (!t_record.Open(filename, "r+b")) + { + PanicAlertT("Failed to read %s", filename); + EndPlayInput(false); + return; + } t_record.ReadArray(&tmpHeader, 1); @@ -849,7 +855,7 @@ void LoadInput(const char *filename) { // this is a "you did something wrong" alert for the user's benefit. // we'll try to say what's going on in excruciating detail, otherwise the user might not believe us. - if(Core::g_CoreStartupParameter.bWii) + if(IsUsingWiimote(1)) { // TODO: more detail PanicAlertT("Warning: You loaded a save whose movie mismatches on byte %d (0x%X). You should load another save before continuing, or load this state with read-only mode off. Otherwise you'll probably get a desync.", i+256, i+256); @@ -925,18 +931,6 @@ void PlayController(SPADStatus *PadStatus, int controllerID) if (!IsPlayingInput() || !IsUsingPad(controllerID) || tmpInput == NULL) return; - if (g_currentFrame == 1) - { - if (tmpHeader.bMemcard) - { - ExpansionInterface::ChangeDevice(0, EXIDEVICE_MEMORYCARD, 0); - } - else if (!tmpHeader.bMemcard) - { - ExpansionInterface::ChangeDevice(0, EXIDEVICE_NONE, 0); - } - } - if (g_currentByte + 8 > g_totalBytes) { PanicAlertT("Premature movie end in PlayController. %u + 8 > %u", (u32)g_currentByte, (u32)g_totalBytes); @@ -1194,9 +1188,13 @@ void GetSettings() g_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); bMemcard = SConfig::GetInstance().m_EXIDevice[0] == EXIDEVICE_MEMORYCARD; - std::stringstream ss; - ss << std::hex << SCM_REV_STR; - ss >> revision; + int temp; + + for(int i = 0; i < 4; ++i ) + { + sscanf(SCM_REV_STR + 2 * i, "%2x", &temp ); + revision[i] = temp; + } } void CheckMD5()