Skip to content

Commit

Permalink
feat: SerializationInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Oct 15, 2024
1 parent dc4c411 commit fcbf923
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
24 changes: 18 additions & 6 deletions include/SKSE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,36 @@ namespace SKSE
[[nodiscard]] bool OpenRecord(std::uint32_t a_type, std::uint32_t a_version) const;

bool WriteRecordData(const void* a_buf, std::uint32_t a_length) const;
bool WriteRecordDataEx(std::uint32_t& a_diff, const void* a_buf, std::uint32_t a_length) const;

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
bool WriteRecordData(const T& a_buf) const
{
return WriteRecordData(std::addressof(a_buf), sizeof(T));
}

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
bool WriteRecordDataEx(std::uint32_t& a_diff, const T& a_buf) const
{
return WriteRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T));
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
bool WriteRecordData(const T (&a_buf)[N]) const
{
return WriteRecordData(std::addressof(a_buf), sizeof(T) * N);
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
bool WriteRecordDataEx(std::uint32_t& a_diff, const T (&a_buf)[N]) const
{
return WriteRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T) * N);
}

bool GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const;

std::uint32_t ReadRecordData(void* a_buf, std::uint32_t a_length) const;
std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, void* a_buf, std::uint32_t a_length) const;

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
std::uint32_t ReadRecordData(T& a_buf) const
Expand All @@ -139,10 +153,9 @@ namespace SKSE
}

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
std::uint32_t ReadRecordDataEx(std::uint32_t& a_length, T& a_buf) const
std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, T& a_buf) const
{
a_length -= sizeof(T);
return ReadRecordData(std::addressof(a_buf), sizeof(T));
return ReadRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T));
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
Expand All @@ -152,10 +165,9 @@ namespace SKSE
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
std::uint32_t ReadRecordDataEx(std::uint32_t& a_length, T (&a_buf)[N]) const
std::uint32_t ReadRecordDataEx(std::uint32_t& a_diff, T (&a_buf)[N]) const
{
a_length -= sizeof(T);
return ReadRecordData(std::addressof(a_buf), sizeof(T) * N);
return ReadRecordDataEx(a_diff, std::addressof(a_buf), sizeof(T) * N);
}

bool ResolveFormID(RE::FormID a_oldFormID, RE::FormID& a_newFormID) const;
Expand Down
13 changes: 13 additions & 0 deletions src/SKSE/Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ namespace SKSE
return GetProxy()->WriteRecordData(a_buf, a_length);
}

bool SerializationInterface::WriteRecordDataEx(std::uint32_t& a_diff, const void* a_buf, std::uint32_t a_length) const
{
a_diff += a_length;
return GetProxy()->WriteRecordData(a_buf, a_length);
}

bool SerializationInterface::GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const
{
return GetProxy()->GetNextRecordInfo(&a_type, &a_version, &a_length);
Expand All @@ -138,6 +144,13 @@ namespace SKSE
return GetProxy()->ReadRecordData(a_buf, a_length);
}

std::uint32_t SerializationInterface::ReadRecordDataEx(std::uint32_t& a_diff, void* a_buf, std::uint32_t a_length) const
{
const auto result = GetProxy()->ReadRecordData(a_buf, a_length);
a_diff -= result;
return result;
}

bool SerializationInterface::ResolveFormID(RE::FormID a_oldFormID, RE::FormID& a_newFormID) const
{
return GetProxy()->ResolveFormId(a_oldFormID, &a_newFormID);
Expand Down

0 comments on commit fcbf923

Please sign in to comment.