1 #pragma once 2 3 // Simple RIFF file format reader. 4 // Unrelated to the ChunkFile.h used in Dolphin and PPSSPP. 5 6 // TO REMEMBER WHEN USING: 7 8 // EITHER a chunk contains ONLY data 9 // OR it contains ONLY other chunks 10 // otherwise the scheme breaks. 11 12 #include <string> 13 #include <cstdint> 14 15 class RIFFReader { 16 public: 17 RIFFReader(const uint8_t *data, int dataSize); 18 ~RIFFReader(); 19 20 bool Descend(uint32_t id); 21 void Ascend(); 22 23 int ReadInt(); 24 void ReadData(void *data, int count); 25 26 int GetCurrentChunkSize(); 27 28 private: 29 struct ChunkInfo { 30 int startLocation; 31 int parentStartLocation; 32 int parentEOF; 33 uint32_t ID; 34 int length; 35 }; 36 ChunkInfo stack[32]; 37 uint8_t *data_; 38 int pos_ = 0; 39 int eof_ = 0; // really end of current block 40 int depth_ = 0; 41 int fileSize_ = 0; 42 }; 43