From b2ed47c44fb0f5d4a2b5315d2fdd59e7c0173f93 Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Tue, 9 Jun 2020 22:52:42 +0200 Subject: [PATCH] [Save State] Make sure g_Disk exists --- Source/Project64-core/N64System/N64Class.cpp | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Project64-core/N64System/N64Class.cpp b/Source/Project64-core/N64System/N64Class.cpp index cddb24639..48375220f 100644 --- a/Source/Project64-core/N64System/N64Class.cpp +++ b/Source/Project64-core/N64System/N64Class.cpp @@ -1749,10 +1749,10 @@ bool CN64System::SaveState() zipOpenNewFileInZip(file, SaveFile.GetNameExtension().c_str(), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION); zipWriteInFileInZip(file, &SaveID_0, sizeof(SaveID_0)); zipWriteInFileInZip(file, &RdramSize, sizeof(uint32_t)); - if (!g_Settings->LoadBool(Setting_EnableDisk)) - zipWriteInFileInZip(file, g_Rom->GetRomAddress(), 0x40); - else + if (g_Settings->LoadBool(Setting_EnableDisk) && g_Disk) zipWriteInFileInZip(file, g_Disk->GetDiskAddressID(), 0x40); + else + zipWriteInFileInZip(file, g_Rom->GetRomAddress(), 0x40); zipWriteInFileInZip(file, &NextViTimer, sizeof(uint32_t)); zipWriteInFileInZip(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(int64_t) * 32); @@ -1806,10 +1806,10 @@ bool CN64System::SaveState() hSaveFile.SeekToBegin(); hSaveFile.Write(&SaveID_0, sizeof(uint32_t)); hSaveFile.Write(&RdramSize, sizeof(uint32_t)); - if (!g_Settings->LoadBool(Setting_EnableDisk)) - hSaveFile.Write(g_Rom->GetRomAddress(), 0x40); - else + if (g_Settings->LoadBool(Setting_EnableDisk) && g_Disk) hSaveFile.Write(g_Disk->GetDiskAddressID(), 0x40); + else + hSaveFile.Write(g_Rom->GetRomAddress(), 0x40); hSaveFile.Write(&NextViTimer, sizeof(uint32_t)); hSaveFile.Write(&m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); hSaveFile.Write(m_Reg.m_GPR, sizeof(int64_t) * 32); @@ -1981,9 +1981,9 @@ bool CN64System::LoadState(const char * FileName) uint8_t LoadHeader[64]; unzReadCurrentFile(file, LoadHeader, 0x40); - if (!g_Settings->LoadBool(Setting_EnableDisk)) + if (g_Settings->LoadBool(Setting_EnableDisk) && g_Disk) { - if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 && + if (memcmp(LoadHeader, g_Disk->GetDiskAddressID(), 0x40) != 0 && !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) { return false; @@ -1991,7 +1991,7 @@ bool CN64System::LoadState(const char * FileName) } else { - if (memcmp(LoadHeader, g_Disk->GetDiskAddressID(), 0x40) != 0 && + if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 && !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) { return false; @@ -2060,9 +2060,9 @@ bool CN64System::LoadState(const char * FileName) //Check header uint8_t LoadHeader[64]; hSaveFile.Read(LoadHeader, 0x40); - if (!g_Settings->LoadBool(Setting_EnableDisk)) + if (g_Settings->LoadBool(Setting_EnableDisk) && g_Disk) { - if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 && + if (memcmp(LoadHeader, g_Disk->GetDiskAddressID(), 0x40) != 0 && !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) { return false; @@ -2070,7 +2070,7 @@ bool CN64System::LoadState(const char * FileName) } else { - if (memcmp(LoadHeader, g_Disk->GetDiskAddressID(), 0x40) != 0 && + if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 && !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) { return false;