diff --git a/Navmesher/esx_reader.cpp b/Navmesher/esx_reader.cpp index 53a59c6..8be5d7f 100644 --- a/Navmesher/esx_reader.cpp +++ b/Navmesher/esx_reader.cpp @@ -1,4 +1,8 @@ #include "esx_reader.hpp" +#include +#include + +using namespace esxr; diff --git a/Navmesher/esx_reader.hpp b/Navmesher/esx_reader.hpp index 6cac197..a99dcf2 100644 --- a/Navmesher/esx_reader.hpp +++ b/Navmesher/esx_reader.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "utility.hpp" @@ -20,6 +21,14 @@ namespace esxr { class GroupNode; class RecordNode; +// +// Constants +// + +static constexpr auto esx_endianness = std::endian::little; +static constexpr std::streamsize header_size = 24; +static constexpr bool same_endianness = std::endian::native == esx_endianness; + // // Enumerations // @@ -135,6 +144,23 @@ struct RecordHeader { uint16_t unknown; }; +// +// Concepts +// + +template +concept packed = sizeof(T) == N; + +template +concept is_header = std::is_same_v || std::is_same_v; + +template +concept packed_header = is_header && packed(header_size)>; + +template +concept directly_readable_header = packed_header && same_endianness; + + // // Classes // @@ -162,6 +188,12 @@ private: [[nodiscard]] std::optional flag_to_description(Flag flag) noexcept; [[nodiscard]] std::optional refr_flag_to_description(RefrFlag refr_flag) noexcept; +void read_header(std::ifstream &in, directly_readable_header auto &out) +{ + auto char_ptr = reinterpret_cast(&out); + in.read(char_ptr, header_size); +} + } #endif diff --git a/Navmesher/main.cpp b/Navmesher/main.cpp index 771345c..ce9cc5f 100644 --- a/Navmesher/main.cpp +++ b/Navmesher/main.cpp @@ -24,10 +24,7 @@ static constexpr auto esm_name = "Skyrim.esm"; int main() { auto esm_fs = open_esm(); - std::array fourcc{}; - esm_fs.read(fourcc.data(), static_cast(fourcc.size())); - for (auto c : fourcc) - std::cout << c; - std::cout << '\n'; - return 0; -} \ No newline at end of file + esxr::RecordHeader header{}; + esxr::read_header(esm_fs, header); + return static_cast(header.type); +}