#ifndef WC3RE_TREFILE_HH__ #define WC3RE_TREFILE_HH__ #include #include #include #include #include class TreFile { public: TreFile(char const* base, size_t length); ~TreFile(); std::vector getNames() const; std::vector getCRCs() const; void dumpName(std::string path, std::string const& name) const; void dumpCRC(std::string path, uint32_t crc) const; void dumpAll(std::string path) const; void printStructure(); class Object { public: Object() : base_(nullptr), length_(0) { } Object(Object const& copy) = delete; Object(Object && move) : base_(move.base_), length_(move.length_) { move.base_ = nullptr; move.length_ = 0; } Object& operator=(Object const& copy) = delete; Object& operator=(Object && move) { base_ = move.base_; length_ = move.length_; move.base_ = nullptr; move.length_ = 0; return *this; } char const* data() const { return base_; } size_t size() const { return length_; } operator bool() const { return base_; } private: char const* base_; size_t length_; Object(char const* base, size_t length) : base_(base), length_(length) { } friend class TreFile; }; Object openName(std::string const& name) const; Object openCRC(uint32_t crc) const; struct Stat { uint32_t size; uint8_t flags; }; Stat statName(std::string const& name) const; Stat statCRC(uint32_t crc) const; private: void construct_(); size_t findName_(std::string const& name) const; size_t findCRC_(uint32_t crc) const; void dumpIdx_(std::string const& name, size_t table3Idx) const; Object openIdx_(size_t table3Idx) const; Stat statIdx_(size_t table3Idx) const; std::map table1_; std::map table2_; struct Table3Entry { // little endian unsigned dataPtr:32; unsigned length:24; unsigned flags:8; } __attribute__((__packed__)); Table3Entry const* table3_; size_t table3Size_; char const* base_; size_t length_; }; #endif