Skip to content

Commit

Permalink
Savestates: Save build version and creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Dec 28, 2023
1 parent 1604268 commit 2062fea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions rpcs3/Emu/System.cpp
Expand Up @@ -36,6 +36,8 @@
#include "Loader/ELF.h"
#include "Loader/disc.h"

#include "rpcs3_version.h"

#include "Utilities/StrUtil.h"

#include "../Crypto/unself.h"
Expand Down Expand Up @@ -964,6 +966,9 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,

const bool from_dev_flash = IsPathInsideDir(m_path, g_cfg_vfs.get_dev_flash());

std::string savestate_build_version;
std::string savestate_creation_date;

if (m_ar)
{
struct file_header
Expand Down Expand Up @@ -991,13 +996,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,

g_cfg.savestate.state_inspection_mode.set(header.state_inspection_support);

bool is_incompatible = false;

if (header.flag_versions_is_following_data)
{
ensure(header.offset == m_ar->pos);

if (!is_savestate_version_compatible(m_ar->pop<std::vector<version_entry>>(), true))
{
return game_boot_result::savestate_version_unsupported;
is_incompatible = true;
}
}
else
Expand All @@ -1010,14 +1017,33 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,

if (!is_savestate_version_compatible(ar_temp.pop<std::vector<version_entry>>(), true))
{
return game_boot_result::savestate_version_unsupported;
is_incompatible = true;
}

// Restore file handler
ar_temp.swap_handler(*m_ar);
}

if (!load_and_check_reserved(*m_ar, header.flag_versions_is_following_data ? 32 : 31))
const bool contains_version = m_ar->pop<b8>();

if (contains_version)
{
savestate_build_version = m_ar->pop<std::string>();
savestate_creation_date = m_ar->pop<std::string>();

(is_incompatible ? sys_log.error : sys_log.notice)("Savestate information: creation time: %s, RPCS3 build: '%s'", savestate_creation_date, savestate_build_version);
}

if (is_incompatible)
{
return game_boot_result::savestate_version_unsupported;
}

usz reserved_count = 32;
reserved_count -= (header.flag_versions_is_following_data ? 0 : 1);
reserved_count -= (contains_version ? 0 : 1);

if (!load_and_check_reserved(*m_ar, reserved_count))
{
return game_boot_result::savestate_version_unsupported;
}
Expand Down Expand Up @@ -3081,6 +3107,10 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s
ar(read_used_savestate_versions());
}

ar(u8{1});
ar(rpcs3::get_verbose_version());
ar(fmt::format("Current Time: %s", std::chrono::system_clock::now()));

ar(std::array<u8, 32>{}); // Reserved for future use

if (auto dir = vfs::get("/dev_bdvd/PS3_GAME"); fs::is_dir(dir) && !fs::is_file(fs::get_parent_dir(dir) + "/PS3_DISC.SFB"))
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3_version.h
Expand Up @@ -7,7 +7,7 @@ namespace rpcs3
std::string_view get_branch();
std::string_view get_full_branch();
std::pair<std::string, std::string> get_commit_and_hash();
const utils::version& get_version();
const ::utils::version& get_version();
std::string get_version_and_branch();
std::string get_verbose_version();
bool is_release_build();
Expand Down

0 comments on commit 2062fea

Please sign in to comment.