#include "remorse/glob_archive.h" #include "remorse/flex_archive.h" namespace remorse { namespace { constexpr u32 globCountSize = 2; constexpr u32 globEntrySize = 6; u16 readU16Le(const std::vector& bytes, u32 offset) { return static_cast(bytes[offset] | (static_cast(bytes[offset + 1]) << 8)); } } // namespace std::optional> loadGlobObjects(const std::filesystem::path& path) { const auto archive = loadFlexArchive(path); if (!archive) { return std::nullopt; } std::vector objects; for (const FlexEntry& flexEntry : archive->populatedEntries) { const auto bytes = readFlexEntry(*archive, flexEntry.index); if (!bytes || bytes->size() < globCountSize) { return std::nullopt; } const u16 entryCount = readU16Le(*bytes, 0); const u32 expectedSize = globCountSize + static_cast(entryCount) * globEntrySize; if (expectedSize > bytes->size()) { return std::nullopt; } GlobObject object; object.index = flexEntry.index; for (u32 index = 0; index < entryCount; ++index) { const u32 offset = globCountSize + index * globEntrySize; GlobObjectEntry entry; entry.x = (*bytes)[offset]; entry.y = (*bytes)[offset + 1]; entry.z = (*bytes)[offset + 2]; entry.shape = readU16Le(*bytes, offset + 3); entry.frame = (*bytes)[offset + 5]; object.entries.push_back(entry); } objects.push_back(object); } return objects; } } // namespace remorse