[Project64] Get load save state to use cfile
This commit is contained in:
parent
112ea9d8da
commit
4e0103b897
|
@ -343,7 +343,7 @@ void CSystemTimer::SaveData(CFile & file) const
|
||||||
file.Write((void *)&m_Current, sizeof(m_Current));
|
file.Write((void *)&m_Current, sizeof(m_Current));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSystemTimer::LoadData(void * file)
|
void CSystemTimer::LoadData(zipFile & file)
|
||||||
{
|
{
|
||||||
uint32_t TimerDetailsSize, Entries;
|
uint32_t TimerDetailsSize, Entries;
|
||||||
|
|
||||||
|
@ -367,6 +367,30 @@ void CSystemTimer::LoadData(void * file)
|
||||||
unzReadCurrentFile(file, (void *)&m_Current, sizeof(m_Current));
|
unzReadCurrentFile(file, (void *)&m_Current, sizeof(m_Current));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSystemTimer::LoadData(CFile & file)
|
||||||
|
{
|
||||||
|
uint32_t TimerDetailsSize, Entries;
|
||||||
|
|
||||||
|
file.Read(&TimerDetailsSize, sizeof(TimerDetailsSize));
|
||||||
|
file.Read(&Entries, sizeof(Entries));
|
||||||
|
|
||||||
|
if (TimerDetailsSize != sizeof(TIMER_DETAILS))
|
||||||
|
{
|
||||||
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Entries != sizeof(m_TimerDetatils) / sizeof(m_TimerDetatils[0]))
|
||||||
|
{
|
||||||
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.Read((void *)&m_TimerDetatils, sizeof(m_TimerDetatils));
|
||||||
|
file.Read((void *)&m_LastUpdate, sizeof(m_LastUpdate));
|
||||||
|
file.Read(&m_NextTimer, sizeof(m_NextTimer));
|
||||||
|
file.Read((void *)&m_Current, sizeof(m_Current));
|
||||||
|
}
|
||||||
|
|
||||||
void CSystemTimer::RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer)
|
void CSystemTimer::RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer)
|
||||||
{
|
{
|
||||||
if (m_LastUpdate != rSystemTimer.m_LastUpdate)
|
if (m_LastUpdate != rSystemTimer.m_LastUpdate)
|
||||||
|
|
|
@ -53,7 +53,8 @@ public:
|
||||||
|
|
||||||
void SaveData(zipFile & file) const;
|
void SaveData(zipFile & file) const;
|
||||||
void SaveData(CFile & file) const;
|
void SaveData(CFile & file) const;
|
||||||
void LoadData(void * file);
|
void LoadData(zipFile & file);
|
||||||
|
void LoadData(CFile & file);
|
||||||
|
|
||||||
void RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer);
|
void RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer);
|
||||||
|
|
||||||
|
|
|
@ -1408,7 +1408,11 @@ bool CN64System::SaveState()
|
||||||
SaveFile.SetName(g_Settings->LoadStringVal(Game_GoodName).c_str());
|
SaveFile.SetName(g_Settings->LoadStringVal(Game_GoodName).c_str());
|
||||||
g_Settings->SaveDword(Game_LastSaveSlot, g_Settings->LoadDword(Game_CurrentSaveState));
|
g_Settings->SaveDword(Game_LastSaveSlot, g_Settings->LoadDword(Game_CurrentSaveState));
|
||||||
}
|
}
|
||||||
SaveFile.SetExtension(stdstr_f("pj%s", Slot != 0 ? stdstr_f("%d", Slot).c_str() : "").c_str());
|
stdstr_f target_ext("pj%s", Slot != 0 ? stdstr_f("%d", Slot).c_str() : "");
|
||||||
|
if (_stricmp(SaveFile.GetExtension().c_str(), target_ext.c_str()) != 0)
|
||||||
|
{
|
||||||
|
SaveFile.SetNameExtension(stdstr_f("%s.%s", SaveFile.GetNameExtension().c_str(), target_ext.c_str()).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
CPath ExtraInfo(SaveFile);
|
CPath ExtraInfo(SaveFile);
|
||||||
ExtraInfo.SetExtension(".dat");
|
ExtraInfo.SetExtension(".dat");
|
||||||
|
@ -1584,19 +1588,16 @@ bool CN64System::LoadState(const char * FileName)
|
||||||
old_dacrate = g_Reg->AI_DACRATE_REG;
|
old_dacrate = g_Reg->AI_DACRATE_REG;
|
||||||
|
|
||||||
WriteTrace(TraceN64System, TraceDebug, "(%s): Start", FileName);
|
WriteTrace(TraceN64System, TraceDebug, "(%s): Start", FileName);
|
||||||
|
CPath SaveFile(FileName);
|
||||||
|
|
||||||
char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
|
if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(SaveFile.GetExtension().c_str(), ".zip") == 0)
|
||||||
_splitpath(FileName, drive, dir, fname, ext);
|
|
||||||
|
|
||||||
stdstr FileNameStr(FileName);
|
|
||||||
if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(ext, ".zip") == 0)
|
|
||||||
{
|
{
|
||||||
//If ziping save add .zip on the end
|
//If ziping save add .zip on the end
|
||||||
if (_stricmp(ext, ".zip") != 0)
|
if (!SaveFile.Exists() && _stricmp(SaveFile.GetExtension().c_str(), ".zip") != 0)
|
||||||
{
|
{
|
||||||
FileNameStr += ".zip";
|
SaveFile.SetNameExtension(stdstr_f("%s.zip", SaveFile.GetNameExtension().c_str()).c_str());
|
||||||
}
|
}
|
||||||
unzFile file = unzOpen(FileNameStr.c_str());
|
unzFile file = unzOpen(SaveFile);
|
||||||
int port = -1;
|
int port = -1;
|
||||||
if (file != NULL)
|
if (file != NULL)
|
||||||
{
|
{
|
||||||
|
@ -1635,16 +1636,11 @@ bool CN64System::LoadState(const char * FileName)
|
||||||
|
|
||||||
uint8_t LoadHeader[64];
|
uint8_t LoadHeader[64];
|
||||||
unzReadCurrentFile(file, LoadHeader, 0x40);
|
unzReadCurrentFile(file, LoadHeader, 0x40);
|
||||||
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0)
|
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 &&
|
||||||
{
|
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
|
||||||
//if (inFullScreen) { return false; }
|
|
||||||
int result = MessageBoxW(NULL, wGS(MSG_SAVE_STATE_HEADER).c_str(), wGS(MSG_MSGBOX_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2);
|
|
||||||
|
|
||||||
if (result == IDNO)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reset(false, true);
|
Reset(false, true);
|
||||||
|
|
||||||
g_MMU->UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
|
g_MMU->UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
|
||||||
|
@ -1688,64 +1684,67 @@ bool CN64System::LoadState(const char * FileName)
|
||||||
}
|
}
|
||||||
if (!LoadedZipFile)
|
if (!LoadedZipFile)
|
||||||
{
|
{
|
||||||
HANDLE hSaveFile = CreateFile(FileNameStr.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL,
|
CFile hSaveFile(SaveFile, CFileBase::modeRead);
|
||||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
if (!hSaveFile.IsOpen())
|
||||||
if (hSaveFile == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
{
|
||||||
g_Notify->DisplayMessage(5, stdstr_f("%s %s", GS(MSG_UNABLED_LOAD_STATE), FileNameStr.c_str()).c_str());
|
g_Notify->DisplayMessage(5, stdstr_f("%s %s", GS(MSG_UNABLED_LOAD_STATE), FileName).c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
hSaveFile.SeekToBegin();
|
||||||
|
|
||||||
SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN);
|
hSaveFile.Read(&Value, sizeof(Value));
|
||||||
DWORD dwRead;
|
|
||||||
ReadFile(hSaveFile, &Value, sizeof(Value), &dwRead, NULL);
|
|
||||||
if (Value != 0x23D8A6C8)
|
if (Value != 0x23D8A6C8)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadFile(hSaveFile, &SaveRDRAMSize, sizeof(SaveRDRAMSize), &dwRead, NULL);
|
hSaveFile.Read(&SaveRDRAMSize, sizeof(SaveRDRAMSize));
|
||||||
|
|
||||||
//Check header
|
//Check header
|
||||||
uint8_t LoadHeader[64];
|
uint8_t LoadHeader[64];
|
||||||
ReadFile(hSaveFile, LoadHeader, 0x40, &dwRead, NULL);
|
hSaveFile.Read(LoadHeader, 0x40);
|
||||||
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0)
|
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 &&
|
||||||
{
|
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
|
||||||
//if (inFullScreen) { return false; }
|
|
||||||
int result = MessageBoxW(NULL, wGS(MSG_SAVE_STATE_HEADER).c_str(), wGS(MSG_MSGBOX_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2);
|
|
||||||
|
|
||||||
if (result == IDNO)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reset(false, true);
|
Reset(false, true);
|
||||||
m_MMU_VM.UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
|
m_MMU_VM.UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
|
||||||
m_MMU_VM.UnProtectMemory(0xA4000000, 0xA4001FFC);
|
m_MMU_VM.UnProtectMemory(0xA4000000, 0xA4001FFC);
|
||||||
g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize);
|
g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize);
|
||||||
|
|
||||||
ReadFile(hSaveFile, &NextVITimer, sizeof(NextVITimer), &dwRead, NULL);
|
hSaveFile.Read(&NextVITimer, sizeof(NextVITimer));
|
||||||
ReadFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwRead, NULL);
|
hSaveFile.Read(&m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
|
||||||
ReadFile(hSaveFile, m_Reg.m_GPR, sizeof(int64_t) * 32, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_GPR, sizeof(int64_t) * 32);
|
||||||
ReadFile(hSaveFile, m_Reg.m_FPR, sizeof(int64_t) * 32, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_FPR, sizeof(int64_t) * 32);
|
||||||
ReadFile(hSaveFile, m_Reg.m_CP0, sizeof(uint32_t) * 32, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_CP0, sizeof(uint32_t) * 32);
|
||||||
ReadFile(hSaveFile, m_Reg.m_FPCR, sizeof(uint32_t) * 32, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_FPCR, sizeof(uint32_t) * 32);
|
||||||
ReadFile(hSaveFile, &m_Reg.m_HI, sizeof(int64_t), &dwRead, NULL);
|
hSaveFile.Read(&m_Reg.m_HI, sizeof(int64_t));
|
||||||
ReadFile(hSaveFile, &m_Reg.m_LO, sizeof(int64_t), &dwRead, NULL);
|
hSaveFile.Read(&m_Reg.m_LO, sizeof(int64_t));
|
||||||
ReadFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
|
||||||
ReadFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
|
||||||
ReadFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
|
||||||
ReadFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
|
||||||
ReadFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
|
||||||
ReadFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
|
||||||
ReadFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
|
||||||
ReadFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
|
||||||
ReadFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4, &dwRead, NULL);
|
hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
|
||||||
ReadFile(hSaveFile, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwRead, NULL);
|
hSaveFile.Read((void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
|
||||||
ReadFile(hSaveFile, m_MMU_VM.PifRam(), 0x40, &dwRead, NULL);
|
hSaveFile.Read(m_MMU_VM.PifRam(), 0x40);
|
||||||
ReadFile(hSaveFile, m_MMU_VM.Rdram(), SaveRDRAMSize, &dwRead, NULL);
|
hSaveFile.Read(m_MMU_VM.Rdram(), SaveRDRAMSize);
|
||||||
ReadFile(hSaveFile, m_MMU_VM.Dmem(), 0x1000, &dwRead, NULL);
|
hSaveFile.Read(m_MMU_VM.Dmem(), 0x1000);
|
||||||
ReadFile(hSaveFile, m_MMU_VM.Imem(), 0x1000, &dwRead, NULL);
|
hSaveFile.Read(m_MMU_VM.Imem(), 0x1000);
|
||||||
CloseHandle(hSaveFile);
|
hSaveFile.Close();
|
||||||
|
|
||||||
|
CPath ExtraInfo(SaveFile);
|
||||||
|
ExtraInfo.SetExtension(".dat");
|
||||||
|
CFile hExtraInfo(ExtraInfo, CFileBase::modeWrite | CFileBase::modeCreate);
|
||||||
|
if (hExtraInfo.IsOpen())
|
||||||
|
{
|
||||||
|
m_SystemTimer.LoadData(hExtraInfo);
|
||||||
|
hExtraInfo.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fix losing audio in certain games with certain plugins
|
//Fix losing audio in certain games with certain plugins
|
||||||
|
@ -1817,14 +1816,14 @@ bool CN64System::LoadState(const char * FileName)
|
||||||
m_LastSuccessSyncPC[i] = 0;
|
m_LastSuccessSyncPC[i] = 0;
|
||||||
}
|
}
|
||||||
m_SyncCPU->SetActiveSystem(true);
|
m_SyncCPU->SetActiveSystem(true);
|
||||||
m_SyncCPU->LoadState(FileNameStr.c_str());
|
m_SyncCPU->LoadState(FileName);
|
||||||
SetActiveSystem(true);
|
SetActiveSystem(true);
|
||||||
SyncCPU(m_SyncCPU);
|
SyncCPU(m_SyncCPU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WriteTrace(TraceN64System, TraceDebug, "13");
|
WriteTrace(TraceN64System, TraceDebug, "13");
|
||||||
std::string LoadMsg = g_Lang->GetString(MSG_LOADED_STATE);
|
std::string LoadMsg = g_Lang->GetString(MSG_LOADED_STATE);
|
||||||
g_Notify->DisplayMessage(5, stdstr_f("%s %s", LoadMsg.c_str(), stdstr(CPath(FileNameStr).GetNameExtension()).c_str()).c_str());
|
g_Notify->DisplayMessage(5, stdstr_f("%s %s", LoadMsg.c_str(), stdstr(SaveFile.GetNameExtension()).c_str()).c_str());
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Done");
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
#include "../stdafx.h"
|
|
@ -275,7 +275,10 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
|
||||||
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SaveGame);
|
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SaveGame);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ID_SYSTEM_RESTORE: WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_RESTORE"); g_BaseSystem->ExternalEvent(SysEvent_LoadMachineState); break;
|
case ID_SYSTEM_RESTORE:
|
||||||
|
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_RESTORE");
|
||||||
|
g_BaseSystem->ExternalEvent(SysEvent_LoadMachineState);
|
||||||
|
break;
|
||||||
case ID_SYSTEM_LOAD:
|
case ID_SYSTEM_LOAD:
|
||||||
{
|
{
|
||||||
char Directory[255], SaveFile[255];
|
char Directory[255], SaveFile[255];
|
||||||
|
@ -302,7 +305,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
|
||||||
_splitpath(SaveFile, drive, dir, fname, ext);
|
_splitpath(SaveFile, drive, dir, fname, ext);
|
||||||
_makepath(SaveDir, drive, dir, NULL, NULL);
|
_makepath(SaveDir, drive, dir, NULL, NULL);
|
||||||
UISettingsSaveString(Directory_LastSave, SaveDir);
|
UISettingsSaveString(Directory_LastSave, SaveDir);
|
||||||
g_System->LoadState();
|
g_BaseSystem->ExternalEvent(SysEvent_LoadMachineState);
|
||||||
}
|
}
|
||||||
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_LoadGame);
|
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_LoadGame);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue