Exemplo n.º 1
0
void VerifyAt(const std::string& filename)
{
	bool wasUnpaused = Core::PauseAndLock(true);

	std::vector<u8> buffer;
	LoadFileStateData(filename, buffer);

	if (!buffer.empty())
	{
		u8 *ptr = &buffer[0];
		PointerWrap p(&ptr, PointerWrap::MODE_VERIFY);
		DoState(p);

		if (p.GetMode() == PointerWrap::MODE_VERIFY)
			Core::DisplayMessage(StringFromFormat("Verified state at %s", filename.c_str()).c_str(), 2000);
		else
			Core::DisplayMessage("Unable to Verify : Can't verify state from other revisions !", 4000);
	}

	Core::PauseAndLock(false, wasUnpaused);
}
Exemplo n.º 2
0
void LoadAs(const std::string& filename)
{
	// Stop the core while we load the state
	bool wasUnpaused = Core::PauseAndLock(true);

#if defined _DEBUG && defined _WIN32
	// we use _CRTDBG_DELAY_FREE_MEM_DF (as a speed hack?),
	// but it was causing us to leak gigantic amounts of memory here,
	// enough that only a few savestates could be loaded before crashing,
	// so let's disable it temporarily.
	int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	if (g_loadDepth == 0)
		_CrtSetDbgFlag(tmpflag & ~_CRTDBG_DELAY_FREE_MEM_DF);
#endif

	g_loadDepth++;

	// Save temp buffer for undo load state
	{
		std::lock_guard<std::mutex> lk(g_cs_undo_load_buffer);
		SaveToBuffer(g_undo_load_buffer);
	}

	bool loaded = false;
	bool loadedSuccessfully = false;

	// brackets here are so buffer gets freed ASAP
	{
		std::vector<u8> buffer;
		LoadFileStateData(filename, buffer);

		if (!buffer.empty())
		{
			u8 *ptr = &buffer[0];
			PointerWrap p(&ptr, PointerWrap::MODE_READ);
			DoState(p);
			loaded = true;
			loadedSuccessfully = (p.GetMode() == PointerWrap::MODE_READ);
		}
	}

	if (loaded)
	{
		if (loadedSuccessfully)
		{
			Core::DisplayMessage(StringFromFormat("Loaded state from %s", filename.c_str()).c_str(), 2000);
			if (File::Exists(filename + ".dtm"))
				Movie::LoadInput((filename + ".dtm").c_str());
			else if (!Movie::IsJustStartingRecordingInputFromSaveState())
				Movie::EndPlayInput(false);
		}
		else
		{
			// failed to load
			Core::DisplayMessage("Unable to Load : Can't load state from other revisions !", 4000);

			// since we could be in an inconsistent state now (and might crash or whatever), undo.
			if (g_loadDepth < 2)
				UndoLoadState();
		}
	}

	if (g_onAfterLoadCb)
		g_onAfterLoadCb();

	g_loadDepth--;

#if defined _DEBUG && defined _WIN32
	// restore _CRTDBG_DELAY_FREE_MEM_DF
	if (g_loadDepth == 0)
		_CrtSetDbgFlag(tmpflag);
#endif

	// resume dat core
	Core::PauseAndLock(false, wasUnpaused);
}
Exemplo n.º 3
0
void LoadAs(const std::string& filename)
{
  if (!Core::IsRunning())
  {
    return;
  }
  else if (NetPlay::IsNetPlayRunning())
  {
    OSD::AddMessage("Loading savestates is disabled in Netplay to prevent desyncs");
    return;
  }

  // Stop the core while we load the state
  bool wasUnpaused = Core::PauseAndLock(true);

  g_loadDepth++;

  // Save temp buffer for undo load state
  if (!Movie::IsJustStartingRecordingInputFromSaveState())
  {
    std::lock_guard<std::mutex> lk(g_cs_undo_load_buffer);
    SaveToBuffer(g_undo_load_buffer);
    if (Movie::IsMovieActive())
      Movie::SaveRecording(File::GetUserPath(D_STATESAVES_IDX) + "undo.dtm");
    else if (File::Exists(File::GetUserPath(D_STATESAVES_IDX) + "undo.dtm"))
      File::Delete(File::GetUserPath(D_STATESAVES_IDX) + "undo.dtm");
  }

  bool loaded = false;
  bool loadedSuccessfully = false;
  std::string version_created_by;

  // brackets here are so buffer gets freed ASAP
  {
    std::vector<u8> buffer;
    LoadFileStateData(filename, buffer);

    if (!buffer.empty())
    {
      u8* ptr = &buffer[0];
      PointerWrap p(&ptr, PointerWrap::MODE_READ);
      version_created_by = DoState(p);
      loaded = true;
      loadedSuccessfully = (p.GetMode() == PointerWrap::MODE_READ);
    }
  }

  if (loaded)
  {
    if (loadedSuccessfully)
    {
      Core::DisplayMessage(StringFromFormat("Loaded state from %s", filename.c_str()), 2000);
      if (File::Exists(filename + ".dtm"))
        Movie::LoadInput(filename + ".dtm");
      else if (!Movie::IsJustStartingRecordingInputFromSaveState() &&
               !Movie::IsJustStartingPlayingInputFromSaveState())
        Movie::EndPlayInput(false);
    }
    else
    {
      // failed to load
      Core::DisplayMessage("Unable to load: Can't load state from other versions!", 4000);
      if (!version_created_by.empty())
        Core::DisplayMessage("The savestate was created using " + version_created_by, 4000);

      // since we could be in an inconsistent state now (and might crash or whatever), undo.
      if (g_loadDepth < 2)
        UndoLoadState();
    }
  }

  if (g_onAfterLoadCb)
    g_onAfterLoadCb();

  g_loadDepth--;

  // resume dat core
  Core::PauseAndLock(false, wasUnpaused);
}