Savestates: Fixup

This commit is contained in:
Eladash 2024-04-13 19:03:39 +03:00 committed by Elad Ashkenazi
parent 1111c1952b
commit fba1db29b3
2 changed files with 21 additions and 2 deletions

View file

@ -77,6 +77,11 @@ struct avc2_settings
u8 video_stream_sharing = 0; u8 video_stream_sharing = 0;
u32 total_video_bitrate = 0; u32 total_video_bitrate = 0;
static bool saveable(bool is_writing) noexcept
{
return GET_SERIALIZATION_VERSION(cellSysutil) != 0;
}
avc2_settings(utils::serial& ar) noexcept avc2_settings(utils::serial& ar) noexcept
{ {
[[maybe_unused]] const s32 version = GET_SERIALIZATION_VERSION(cellSysutil); [[maybe_unused]] const s32 version = GET_SERIALIZATION_VERSION(cellSysutil);

View file

@ -73,6 +73,7 @@ namespace stx
bool(*create)(uchar* ptr, manual_typemap&, utils::serial*, std::string_view) noexcept = nullptr; bool(*create)(uchar* ptr, manual_typemap&, utils::serial*, std::string_view) noexcept = nullptr;
void(*thread_op)(void* ptr, thread_state) noexcept = nullptr; void(*thread_op)(void* ptr, thread_state) noexcept = nullptr;
void(*save)(void* ptr, utils::serial&) noexcept = nullptr; void(*save)(void* ptr, utils::serial&) noexcept = nullptr;
bool(*saveable)(bool) noexcept = nullptr;
void(*destroy)(void* ptr) noexcept = nullptr; void(*destroy)(void* ptr) noexcept = nullptr;
bool is_trivial_and_nonsavable = false; bool is_trivial_and_nonsavable = false;
std::string_view name; std::string_view name;
@ -148,6 +149,12 @@ namespace stx
std::launder(static_cast<T*>(ptr))->save(stx::exact_t<utils::serial&>(ar)); std::launder(static_cast<T*>(ptr))->save(stx::exact_t<utils::serial&>(ar));
} }
template <typename T> requires requires (const T&) { T::saveable(true); }
static bool call_saveable(bool is_writing) noexcept
{
return T::saveable(is_writing);
}
template <typename T> template <typename T>
static typeinfo make_typeinfo() static typeinfo make_typeinfo()
{ {
@ -167,6 +174,11 @@ namespace stx
r.save = &call_save<T>; r.save = &call_save<T>;
} }
if constexpr (!!(requires (const T&) { T::saveable(true); }))
{
r.saveable = &call_saveable<T>;
}
r.is_trivial_and_nonsavable = std::is_trivially_default_constructible_v<T> && !r.save; r.is_trivial_and_nonsavable = std::is_trivially_default_constructible_v<T> && !r.save;
#ifdef _MSC_VER #ifdef _MSC_VER
@ -284,13 +296,15 @@ namespace stx
continue; continue;
} }
if (type.create(data, *this, ar, type.name)) const bool saveable = !type.saveable || type.saveable(false);
if (type.create(data, *this, saveable ? ar : nullptr, type.name))
{ {
*m_order++ = data; *m_order++ = data;
*m_info++ = &type; *m_info++ = &type;
m_init[id] = true; m_init[id] = true;
if (ar && type.save) if (ar && saveable && type.save)
{ {
serial_breathe_and_tag(*ar, type.name, false); serial_breathe_and_tag(*ar, type.name, false);
} }