#ifndef HMT_PARSER_H_ #define HMT_PARSER_H_ #include #include #include "options.h" #include "RS_images.h" ///////////////////////////// ///// Define HMT types ////// ///////////////////////////// /** * @brief Material struct inside HMT file type * * Actual RE material struct:\n * 4B material entry count MC\n * 4B offset after material entries / offset to textures\n * MC * material entry (36B)\n * [\n * 2B int material/texture type:\n * 1 - material with texture\n * 2 - material without texture\n * 2B int texture index\n * 4B float (scale factor?)\n * 4B float (always 1.0)\n * 4B int zero\n * 4B int 0x0A\n * 16B name\n * ]\n * * @image html hmt_materialDef.png */ typedef struct HMTMaterial { short type_; /**< Material type:\n 1 = Material with texture\n 2 = Material without texture */ short texture_index; float unknow1,unknow2; int zero; int hex_a; char name[16]; }HMT_MATERIAL; /** * @brief Texture struct inside HMT file type * * Actual RE texture struct:\n * 4B int texcount Tc\n * TC * texture entry 52B\n * [\n * 4B int pixel offset\n * 28B zero\n * 4B int palette offset, 0 = no palette\n * 4B int texname offset\n * 2B int width\n * 2B int height\n * 8B texture format [\n * 1B int : always 1?\n * 1B int : bits per sample?\n * 1B int : subtype:\n * -0 - palette 16x3B RGB, 4bit per pixel\n * -1 - 256x3B palette RGB, 8bit per pixel\n * -3 - RGBA 32bpp\n * -4 - greyscale, 4bpp\n * -5 - grayscale, 8bpp\n * 1B int ? 0, 0x40, 0x80\n * 4B RGBA transparent color?\n * ]\n * ]\n * * @image html hmt_textureDef.png */ typedef struct HMTTexture { int data_offset; int palette_offset; int textureName_offset; unsigned long width, height; char name[16]; RS_IMAGE image; }HMT_TEXTURE; /** * @brief Instance of HMTFile in memory * This structure contain all parsed data for a single HMT file. */ typedef struct HMTFile { int material_count; /**< Number of materials registered inside HMTFile instance. */ int texture_offset; /**< Address from which texture data begins. */ int texture_count; /**< Number of textures registered inside HMTFile instance. */ HMT_MATERIAL *materials_list; /**< Starting pointer of the materials list. Managed like an array and declared as a pointer */ HMT_TEXTURE *textures_list; /**< Starting pointer of the textures list. Managed like an array and declared as a pointer*/ }HMT_FILE; ///////////////////////////// ///// Declare functions ///// ///////////////////////////// HMT_FILE *parseHMTFile(FILE *hmt_src); int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src); int readTexture(HMT_TEXTURE *tex, FILE *hmt_src); HMT_MATERIAL *getMaterialFromIndex(int i); HMT_MATERIAL *getMaterialFromName(char *matName); HMT_TEXTURE *getTextureFromIndex(int i); HMT_TEXTURE *getTextureFromMaterial(HMT_MATERIAL *mat); int getPaletteFromFile(RS_IMAGE *img, FILE *f); int getSamplesFromFile(RS_IMAGE *img, FILE *f); void purgeHMTFromMemory(HMT_FILE *_f); #endif