[Project64] Get load save state to use cfile

This commit is contained in:
zilmar 2016-04-21 07:21:15 +10:00
parent 112ea9d8da
commit 4e0103b897
5 changed files with 91 additions and 63 deletions

View File

@ -343,7 +343,7 @@ void CSystemTimer::SaveData(CFile & file) const
file.Write((void *)&m_Current, sizeof(m_Current));
}
void CSystemTimer::LoadData(void * file)
void CSystemTimer::LoadData(zipFile & file)
{
uint32_t TimerDetailsSize, Entries;
@ -367,6 +367,30 @@ void CSystemTimer::LoadData(void * file)
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)
{
if (m_LastUpdate != rSystemTimer.m_LastUpdate)

View File

@ -53,7 +53,8 @@ public:
void SaveData(zipFile & 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);

View File

@ -1408,7 +1408,11 @@ bool CN64System::SaveState()
SaveFile.SetName(g_Settings->LoadStringVal(Game_GoodName).c_str());
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);
ExtraInfo.SetExtension(".dat");
@ -1584,19 +1588,16 @@ bool CN64System::LoadState(const char * FileName)
old_dacrate = g_Reg->AI_DACRATE_REG;
WriteTrace(TraceN64System, TraceDebug, "(%s): Start", FileName);
CPath SaveFile(FileName);
char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
_splitpath(FileName, drive, dir, fname, ext);
stdstr FileNameStr(FileName);
if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(ext, ".zip") == 0)
if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(SaveFile.GetExtension().c_str(), ".zip") == 0)
{
//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;
if (file != NULL)
{
@ -1635,16 +1636,11 @@ bool CN64System::LoadState(const char * FileName)
uint8_t LoadHeader[64];
unzReadCurrentFile(file, LoadHeader, 0x40);
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0)
{
//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)
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 &&
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
{
return false;
}
}
Reset(false, true);
g_MMU->UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
@ -1688,64 +1684,67 @@ bool CN64System::LoadState(const char * FileName)
}
if (!LoadedZipFile)
{
HANDLE hSaveFile = CreateFile(FileNameStr.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
if (hSaveFile == INVALID_HANDLE_VALUE)
CFile hSaveFile(SaveFile, CFileBase::modeRead);
if (!hSaveFile.IsOpen())
{
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;
}
hSaveFile.SeekToBegin();
SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN);
DWORD dwRead;
ReadFile(hSaveFile, &Value, sizeof(Value), &dwRead, NULL);
hSaveFile.Read(&Value, sizeof(Value));
if (Value != 0x23D8A6C8)
{
return false;
}
ReadFile(hSaveFile, &SaveRDRAMSize, sizeof(SaveRDRAMSize), &dwRead, NULL);
hSaveFile.Read(&SaveRDRAMSize, sizeof(SaveRDRAMSize));
//Check header
uint8_t LoadHeader[64];
ReadFile(hSaveFile, LoadHeader, 0x40, &dwRead, NULL);
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0)
{
//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)
hSaveFile.Read(LoadHeader, 0x40);
if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0 &&
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
{
return false;
}
}
Reset(false, true);
m_MMU_VM.UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4);
m_MMU_VM.UnProtectMemory(0xA4000000, 0xA4001FFC);
g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize);
ReadFile(hSaveFile, &NextVITimer, sizeof(NextVITimer), &dwRead, NULL);
ReadFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_GPR, sizeof(int64_t) * 32, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_FPR, sizeof(int64_t) * 32, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_CP0, sizeof(uint32_t) * 32, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_FPCR, sizeof(uint32_t) * 32, &dwRead, NULL);
ReadFile(hSaveFile, &m_Reg.m_HI, sizeof(int64_t), &dwRead, NULL);
ReadFile(hSaveFile, &m_Reg.m_LO, sizeof(int64_t), &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8, &dwRead, NULL);
ReadFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4, &dwRead, NULL);
ReadFile(hSaveFile, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwRead, NULL);
ReadFile(hSaveFile, m_MMU_VM.PifRam(), 0x40, &dwRead, NULL);
ReadFile(hSaveFile, m_MMU_VM.Rdram(), SaveRDRAMSize, &dwRead, NULL);
ReadFile(hSaveFile, m_MMU_VM.Dmem(), 0x1000, &dwRead, NULL);
ReadFile(hSaveFile, m_MMU_VM.Imem(), 0x1000, &dwRead, NULL);
CloseHandle(hSaveFile);
hSaveFile.Read(&NextVITimer, sizeof(NextVITimer));
hSaveFile.Read(&m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
hSaveFile.Read(m_Reg.m_GPR, sizeof(int64_t) * 32);
hSaveFile.Read(m_Reg.m_FPR, sizeof(int64_t) * 32);
hSaveFile.Read(m_Reg.m_CP0, sizeof(uint32_t) * 32);
hSaveFile.Read(m_Reg.m_FPCR, sizeof(uint32_t) * 32);
hSaveFile.Read(&m_Reg.m_HI, sizeof(int64_t));
hSaveFile.Read(&m_Reg.m_LO, sizeof(int64_t));
hSaveFile.Read(m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
hSaveFile.Read(m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
hSaveFile.Read(m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
hSaveFile.Read((void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
hSaveFile.Read(m_MMU_VM.PifRam(), 0x40);
hSaveFile.Read(m_MMU_VM.Rdram(), SaveRDRAMSize);
hSaveFile.Read(m_MMU_VM.Dmem(), 0x1000);
hSaveFile.Read(m_MMU_VM.Imem(), 0x1000);
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
@ -1817,14 +1816,14 @@ bool CN64System::LoadState(const char * FileName)
m_LastSuccessSyncPC[i] = 0;
}
m_SyncCPU->SetActiveSystem(true);
m_SyncCPU->LoadState(FileNameStr.c_str());
m_SyncCPU->LoadState(FileName);
SetActiveSystem(true);
SyncCPU(m_SyncCPU);
}
}
WriteTrace(TraceN64System, TraceDebug, "13");
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");
return true;
}

View File

@ -0,0 +1 @@
#include "../stdafx.h"

View File

@ -275,7 +275,10 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SaveGame);
}
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:
{
char Directory[255], SaveFile[255];
@ -302,7 +305,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
_splitpath(SaveFile, drive, dir, fname, ext);
_makepath(SaveDir, drive, dir, NULL, NULL);
UISettingsSaveString(Directory_LastSave, SaveDir);
g_System->LoadState();
g_BaseSystem->ExternalEvent(SysEvent_LoadMachineState);
}
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_LoadGame);
}