diff --git a/include/europa/structs/Yatf.hpp b/include/europa/structs/Yatf.hpp index a6beaae..0e3266b 100644 --- a/include/europa/structs/Yatf.hpp +++ b/include/europa/structs/Yatf.hpp @@ -11,7 +11,6 @@ #include #include -#include namespace europa::structs { @@ -33,13 +32,20 @@ namespace europa::structs { kTextureFormatV2_4Bpp = 5 }; - // For some reason Jedi Starfighter YATFs use a different fourcc. ??? - constexpr static auto ValidMagicSF = util::FourCC<"YATF", std::endian::big>(); - constexpr static auto ValidMagicJSF = util::FourCC<"YATF", std::endian::little>(); + enum class Version : u16 { + Invalid = 0xffff, + Version1 = 1, + Version2 = 2, + }; + + // For some reason Jedi Starfighter (V2) YATFs use a different fourcc endianness than V1. + // When writing we should use the appropiate one. + constexpr static auto ValidMagic_V1 = util::FourCC<"YATF", std::endian::big>(); + constexpr static auto ValidMagic_V2 = util::FourCC<"YATF", std::endian::little>(); u32 magic; - u16 version; // 0x1 for starfighter, 0x2 for new jsf files + Version version; TextureFormat format; @@ -52,7 +58,11 @@ namespace europa::structs { u32 width; [[nodiscard]] constexpr bool IsValid() const { - return magic == ValidMagicSF || magic == ValidMagicJSF; + if(auto magicValid = magic == ValidMagic_V1 || magic == ValidMagic_V2; !magicValid) + return false; + + // Make sure version is sensical + return version == Version::Version1 || version == Version::Version2; } }; diff --git a/src/libeuropa/io/yatf/Reader.cpp b/src/libeuropa/io/yatf/Reader.cpp index ff7f9e8..26ef2b4 100644 --- a/src/libeuropa/io/yatf/Reader.cpp +++ b/src/libeuropa/io/yatf/Reader.cpp @@ -122,11 +122,11 @@ namespace europa::io::yatf { }; switch(header.version) { - case 1: + case structs::YatfHeader::Version::Version1: v1(); break; - case 2: + case structs::YatfHeader::Version::Version2: v2(); break;