Misc cleanup and fixes for some of the bad code i've written.

Fixes a buffer overflow in the sscanf, move the movie.raw to the GC folder, and stops calling GetSettings() twice.
This commit is contained in:
Rachel Bryk 2013-07-01 17:44:42 -04:00
parent e4846de692
commit de369dcc60
3 changed files with 12 additions and 26 deletions

View File

@ -129,8 +129,8 @@ bool BootCore(const std::string& _rFilename)
StartUp.bSyncGPU = Movie::IsSyncGPU(); StartUp.bSyncGPU = Movie::IsSyncGPU();
if (Movie::IsUsingMemcard() && Movie::IsStartingFromClearSave() && !StartUp.bWii) if (Movie::IsUsingMemcard() && Movie::IsStartingFromClearSave() && !StartUp.bWii)
{ {
if (File::Exists("Movie.raw")) if (File::Exists(File::GetUserPath(D_GCUSER_IDX) + "Movie.raw"))
File::Delete("Movie.raw"); File::Delete(File::GetUserPath(D_GCUSER_IDX) + "Movie.raw");
} }
} }

View File

@ -48,7 +48,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index)
{ {
m_strFilename = (card_index == 0) ? SConfig::GetInstance().m_strMemoryCardA : SConfig::GetInstance().m_strMemoryCardB; m_strFilename = (card_index == 0) ? SConfig::GetInstance().m_strMemoryCardA : SConfig::GetInstance().m_strMemoryCardB;
if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsUsingMemcard() && Movie::IsStartingFromClearSave()) if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsUsingMemcard() && Movie::IsStartingFromClearSave())
m_strFilename = "Movie.raw"; m_strFilename = File::GetUserPath(D_GCUSER_IDX) + "Movie.raw";
// we're potentially leaking events here, since there's no UnregisterEvent until emu shutdown, but I guess it's inconsequential // we're potentially leaking events here, since there's no UnregisterEvent until emu shutdown, but I guess it's inconsequential
et_this_card = CoreTiming::RegisterEvent((card_index == 0) ? "memcardFlushA" : "memcardFlushB", FlushCallback); et_this_card = CoreTiming::RegisterEvent((card_index == 0) ? "memcardFlushA" : "memcardFlushB", FlushCallback);

View File

@ -432,9 +432,9 @@ bool BeginRecordingInput(int controllers)
Movie::g_bClearSave = true; Movie::g_bClearSave = true;
} }
std::thread md5thread(GetMD5); std::thread md5thread(GetMD5);
GetSettings();
} }
g_playMode = MODE_RECORDING; g_playMode = MODE_RECORDING;
GetSettings();
author = SConfig::GetInstance().m_strMovieAuthor; author = SConfig::GetInstance().m_strMovieAuthor;
EnsureTmpInputSize(1); EnsureTmpInputSize(1);
@ -687,23 +687,9 @@ void ReadHeader()
GetSettings(); GetSettings();
} }
videoBackend.resize(ARRAYSIZE(tmpHeader.videoBackend)); videoBackend = (char*) tmpHeader.videoBackend;
for (unsigned int i = 0; i < ARRAYSIZE(tmpHeader.videoBackend);i++) g_discChange = (char*) tmpHeader.discChange;
{ author = (char*) tmpHeader.author;
videoBackend[i] = tmpHeader.videoBackend[i];
}
g_discChange.resize(ARRAYSIZE(tmpHeader.discChange));
for (unsigned int i = 0; i < ARRAYSIZE(tmpHeader.discChange);i++)
{
g_discChange[i] = tmpHeader.discChange[i];
}
author.resize(ARRAYSIZE(tmpHeader.author));
for (unsigned int i = 0; i < ARRAYSIZE(tmpHeader.author);i++)
{
author[i] = tmpHeader.author[i];
}
memcpy(MD5, tmpHeader.md5, 16); memcpy(MD5, tmpHeader.md5, 16);
} }
@ -1075,7 +1061,7 @@ void EndPlayInput(bool cont)
g_currentByte = 0; g_currentByte = 0;
g_playMode = MODE_NONE; g_playMode = MODE_NONE;
Core::DisplayMessage("Movie End.", 2000); Core::DisplayMessage("Movie End.", 2000);
g_bRecordingFromSaveState = 0; g_bRecordingFromSaveState = false;
// we don't clear these things because otherwise we can't resume playback if we load a movie state later // we don't clear these things because otherwise we can't resume playback if we load a movie state later
//g_totalFrames = g_totalBytes = 0; //g_totalFrames = g_totalBytes = 0;
//delete tmpInput; //delete tmpInput;
@ -1183,10 +1169,11 @@ void GetSettings()
if (!Core::g_CoreStartupParameter.bWii) if (!Core::g_CoreStartupParameter.bWii)
g_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); g_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA);
bMemcard = SConfig::GetInstance().m_EXIDevice[0] == EXIDEVICE_MEMORYCARD; bMemcard = SConfig::GetInstance().m_EXIDevice[0] == EXIDEVICE_MEMORYCARD;
u8 tmp[21];
for (int i = 0; i < 20; ++i) for (int i = 0; i < 20; ++i)
{ {
sscanf(SCM_REV_STR + 2 * i, "%02hhx", &revision[i]); sscanf(SCM_REV_STR + 2 * i, "%02hhx", &tmp[i]);
revision[i] = tmp[i];
} }
} }
@ -1216,8 +1203,7 @@ void CheckMD5()
void GetMD5() void GetMD5()
{ {
Core::DisplayMessage("Calculating checksum of game file...", 2000); Core::DisplayMessage("Calculating checksum of game file...", 2000);
for (int i = 0; i < 16; i++) memset(MD5, 0, sizeof(MD5));
MD5[i] = 0;
char game[255]; char game[255];
memcpy(game, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strFilename.c_str(),SConfig::GetInstance().m_LocalCoreStartupParameter.m_strFilename.size()); memcpy(game, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strFilename.c_str(),SConfig::GetInstance().m_LocalCoreStartupParameter.m_strFilename.size());
md5_file(game, MD5); md5_file(game, MD5);