diff --git a/espReader/ESPReader.h b/espReader/ESPReader.h index f721509..690ae4b 100644 --- a/espReader/ESPReader.h +++ b/espReader/ESPReader.h @@ -35,12 +35,14 @@ extern "C" { #define RT_SIZE 128 -/* RT hash seed was externally calculated s.t. the fourcc codes perfectly hash into - * indices between 0 and 511. That is, there are no hashing collisions. This allows - * for hard coded lookup tables for the fourcc codes in a relatively small space. +/* RT hash seed was externally calculated s.t. the fourcc codes perfectly hash + * into indices between 0 and 511. That is, there are no hashing collisions. + * This allows for hard coded lookup tables for the fourcc codes in a relatively + * small space. * - * A minimal perfect hash is also possible with an intermediate seed table, though - * I'm not sure which is faster, if it's worth trying to speed this up, etc. + * A minimal perfect hash is also possible with an intermediate seed table, + * though I'm not sure which is faster, if it's worth trying to speed this up, + * etc. */ #define RT_HASH_SIZE 512 #define RT_HASH_BITS 9 @@ -238,8 +240,8 @@ extern "C" { * `cb` is a callback that takes a `Node` to process. `pt` is a pointer to * arbitrary data that is passed on to `cb` whenever it is called. * - * Data is walked sequentially. Nodes passed to `cb` will be strictly increasing - * in terms of memory location within the buffer. + * Data is walked sequentially. Nodes passed to `cb` will be strictly + * increasing in terms of memory location within the buffer. */ void espr_walk(char *data, size_t size, struct walker_callbacks cb); @@ -259,8 +261,8 @@ extern "C" { size_t espr_formid_count(char *data, size_t size); /* Copies the data from `data` to `buf` decompressing compressed fields as - * it does so. buf_size should be the value returned from `espr_decompressed_size`, - * and `buf` should be at least of that size. + * it does so. buf_size should be the value returned from + * `espr_decompressed_size`, and `buf` should be at least of that size. */ void espr_decompress(char *data, size_t size, char *buf, size_t buf_size); diff --git a/espReader/LUT.c b/espReader/LUT.c index 4ed317a..e2b13bf 100644 --- a/espReader/LUT.c +++ b/espReader/LUT.c @@ -274,11 +274,11 @@ rfs_inner armo = { }; #define REFERENCE_RECORD { \ - [7] = "Turn Off Fire", \ - [10] = "Persistent", \ - [11] = "Initially Disabled", \ - [28] = "Reflected by Auto Water", \ - [30] = "No Respawn", \ + [7] = "Turn Off Fire", \ + [10] = "Persistent", \ + [11] = "Initially Disabled", \ + [28] = "Reflected by Auto Water", \ + [30] = "No Respawn", \ } rfs_inner parw = REFERENCE_RECORD; @@ -524,28 +524,28 @@ rfs_inner *const rfs[RT_HASH_SIZE] = { // REFR flags depend on what its NAME field references #define REFR_GROUP1 { \ - [9] = "Hidden From Local Map", \ - [10] = "Persistent", \ - [11] = "Initially Disabled", \ - [13] = "Sky Marker", \ - [15] = "Visible When Distant", \ - [16] = "Is Full LOD", \ - [26] = "Filter (Collision Geometry)", \ - [27] = "Bounding Box (Collision Geometry)", \ - [28] = "Reflected By Auto Water", \ - [29] = "Don't Havok Settle", \ - [30] = "No Respawn", \ - [31] = "Multibound", \ + [9] = "Hidden From Local Map", \ + [10] = "Persistent", \ + [11] = "Initially Disabled", \ + [13] = "Sky Marker", \ + [15] = "Visible When Distant", \ + [16] = "Is Full LOD", \ + [26] = "Filter (Collision Geometry)", \ + [27] = "Bounding Box (Collision Geometry)", \ + [28] = "Reflected By Auto Water", \ + [29] = "Don't Havok Settle", \ + [30] = "No Respawn", \ + [31] = "Multibound", \ } -rfs_inner refr_acti = REFR_GROUP1; -rfs_inner refr_stat = REFR_GROUP1; -rfs_inner refr_tree = REFR_GROUP1; -rfs_inner refr_flor = REFR_GROUP1; +rfs_inner r_acti = REFR_GROUP1; +rfs_inner r_stat = REFR_GROUP1; +rfs_inner r_tree = REFR_GROUP1; +rfs_inner r_flor = REFR_GROUP1; #undef REFR_GROUP1 -rfs_inner refr_cont = { +rfs_inner r_cont = { [10] = "Persistent", [11] = "Initially Disabled", [16] = "Is Full LOD", @@ -558,7 +558,7 @@ rfs_inner refr_cont = { [31] = "Multibound", }; -rfs_inner refr_door = { +rfs_inner r_door = { [6] = "Hidden From Local Map", [8] = "Inaccessible", [10] = "Persistent", @@ -572,7 +572,7 @@ rfs_inner refr_door = { [31] = "Multibound", }; -rfs_inner refr_ligh = { +rfs_inner r_ligh = { [8] = "Doesn't Light Water", [9] = "Casts Shadows", [10] = "Persistent", @@ -586,7 +586,7 @@ rfs_inner refr_ligh = { [31] = "Multibound", }; -rfs_inner refr_mstt = { +rfs_inner r_mstt = { [9] = "Motion Blur", [10] = "Persistent", [11] = "Initially Disabled", @@ -599,7 +599,7 @@ rfs_inner refr_mstt = { [31] = "Multibound", }; -rfs_inner refr_addn = { +rfs_inner r_addn = { [10] = "Persistent", [11] = "Initially Disabled", [16] = "Is Full LOD", @@ -610,69 +610,69 @@ rfs_inner refr_addn = { }; #define REFR_GROUP2 { \ - [10] = "Persistent", \ - [11] = "Initially Disabled", \ - [16] = "Is Full LOD", \ - [25] = "No AI Acquire", \ - [28] = "Reflected By Auto Water", \ - [29] = "Don't Havok Settle", \ - [30] = "No Respawn", \ - [31] = "Multibound", \ + [10] = "Persistent", \ + [11] = "Initially Disabled", \ + [16] = "Is Full LOD", \ + [25] = "No AI Acquire", \ + [28] = "Reflected By Auto Water", \ + [29] = "Don't Havok Settle", \ + [30] = "No Respawn", \ + [31] = "Multibound", \ } -rfs_inner refr_alch = REFR_GROUP2; -rfs_inner refr_scrl = REFR_GROUP2; -rfs_inner refr_ammo = REFR_GROUP2; -rfs_inner refr_armo = REFR_GROUP2; -rfs_inner refr_ingr = REFR_GROUP2; -rfs_inner refr_keym = REFR_GROUP2; -rfs_inner refr_misc = REFR_GROUP2; -rfs_inner refr_slgm = REFR_GROUP2; -rfs_inner refr_weap = REFR_GROUP2; +rfs_inner r_alch = REFR_GROUP2; +rfs_inner r_scrl = REFR_GROUP2; +rfs_inner r_ammo = REFR_GROUP2; +rfs_inner r_armo = REFR_GROUP2; +rfs_inner r_ingr = REFR_GROUP2; +rfs_inner r_keym = REFR_GROUP2; +rfs_inner r_misc = REFR_GROUP2; +rfs_inner r_slgm = REFR_GROUP2; +rfs_inner r_weap = REFR_GROUP2; -rfs_inner *const rfs_refr[RT_HASH_SIZE] = { - [RT_AACT] = CP(NULL ),[RT_ACHR] = CP(NULL ),[RT_ACTI] = CP(refr_acti), - [RT_ADDN] = CP(refr_addn),[RT_ALCH] = CP(refr_alch),[RT_AMMO] = CP(refr_ammo), - [RT_ANIO] = CP(NULL ),[RT_APPA] = CP(NULL ),[RT_ARMA] = CP(NULL ), - [RT_ARMO] = CP(refr_armo),[RT_ARTO] = CP(NULL ),[RT_ASPC] = CP(NULL ), - [RT_ASTP] = CP(NULL ),[RT_AVIF] = CP(NULL ),[RT_BOOK] = CP(NULL ), - [RT_BPTD] = CP(NULL ),[RT_CAMS] = CP(NULL ),[RT_CELL] = CP(NULL ), - [RT_CLAS] = CP(NULL ),[RT_CLDC] = CP(NULL ),[RT_CLFM] = CP(NULL ), - [RT_CLMT] = CP(NULL ),[RT_COBJ] = CP(NULL ),[RT_COLL] = CP(NULL ), - [RT_CONT] = CP(refr_cont),[RT_CPTH] = CP(NULL ),[RT_CSTY] = CP(NULL ), - [RT_DEBR] = CP(NULL ),[RT_DIAL] = CP(NULL ),[RT_DLBR] = CP(NULL ), - [RT_DLVW] = CP(NULL ),[RT_DOBJ] = CP(NULL ),[RT_DOOR] = CP(refr_door), - [RT_DUAL] = CP(NULL ),[RT_ECZN] = CP(NULL ),[RT_EFSH] = CP(NULL ), - [RT_ENCH] = CP(NULL ),[RT_EQUP] = CP(NULL ),[RT_EXPL] = CP(NULL ), - [RT_EYES] = CP(NULL ),[RT_FACT] = CP(NULL ),[RT_FLOR] = CP(refr_flor), - [RT_FLST] = CP(NULL ),[RT_FSTP] = CP(NULL ),[RT_FSTS] = CP(NULL ), - [RT_FURN] = CP(NULL ),[RT_GLOB] = CP(NULL ),[RT_GMST] = CP(NULL ), - [RT_GRAS] = CP(NULL ),[RT_GRUP] = CP(NULL ),[RT_HAIR] = CP(NULL ), - [RT_HAZD] = CP(NULL ),[RT_HDPT] = CP(NULL ),[RT_IDLE] = CP(NULL ), - [RT_IDLM] = CP(NULL ),[RT_IMAD] = CP(NULL ),[RT_IMGS] = CP(NULL ), - [RT_INFO] = CP(NULL ),[RT_INGR] = CP(refr_ingr),[RT_IPCT] = CP(NULL ), - [RT_IPDS] = CP(NULL ),[RT_KEYM] = CP(refr_keym),[RT_KYWD] = CP(NULL ), - [RT_LAND] = CP(NULL ),[RT_LCRT] = CP(NULL ),[RT_LCTN] = CP(NULL ), - [RT_LGTM] = CP(NULL ),[RT_LIGH] = CP(refr_ligh),[RT_LSCR] = CP(NULL ), - [RT_LTEX] = CP(NULL ),[RT_LVLI] = CP(NULL ),[RT_LVLN] = CP(NULL ), - [RT_LVSP] = CP(NULL ),[RT_MATO] = CP(NULL ),[RT_MATT] = CP(NULL ), - [RT_MESG] = CP(NULL ),[RT_MGEF] = CP(NULL ),[RT_MISC] = CP(refr_misc), - [RT_MOVT] = CP(NULL ),[RT_MSTT] = CP(refr_mstt),[RT_MUSC] = CP(NULL ), - [RT_MUST] = CP(NULL ),[RT_NAVI] = CP(NULL ),[RT_NAVM] = CP(NULL ), - [RT_NOTE] = CP(NULL ),[RT_NPC_] = CP(NULL ),[RT_OTFT] = CP(NULL ), - [RT_PACK] = CP(NULL ),[RT_PERK] = CP(NULL ),[RT_PGRE] = CP(NULL ), - [RT_PHZD] = CP(NULL ),[RT_PROJ] = CP(NULL ),[RT_PWAT] = CP(NULL ), - [RT_QUST] = CP(NULL ),[RT_RACE] = CP(NULL ),[RT_REFR] = CP(NULL ), - [RT_REGN] = CP(NULL ),[RT_RELA] = CP(NULL ),[RT_REVB] = CP(NULL ), - [RT_RFCT] = CP(NULL ),[RT_RGDL] = CP(NULL ),[RT_SCEN] = CP(NULL ), - [RT_SCOL] = CP(NULL ),[RT_SCPT] = CP(NULL ),[RT_SCRL] = CP(refr_scrl), - [RT_SHOU] = CP(NULL ),[RT_SLGM] = CP(refr_slgm),[RT_SMBN] = CP(NULL ), - [RT_SMEN] = CP(NULL ),[RT_SMQN] = CP(NULL ),[RT_SNCT] = CP(NULL ), - [RT_SNDR] = CP(NULL ),[RT_SOPM] = CP(NULL ),[RT_SOUN] = CP(NULL ), - [RT_SPEL] = CP(NULL ),[RT_SPGD] = CP(NULL ),[RT_STAT] = CP(refr_stat), - [RT_TACT] = CP(NULL ),[RT_TES4] = CP(NULL ),[RT_TREE] = CP(refr_tree), - [RT_TXST] = CP(NULL ),[RT_VTYP] = CP(NULL ),[RT_WATR] = CP(NULL ), - [RT_WEAP] = CP(refr_weap),[RT_WOOP] = CP(NULL ),[RT_WRLD] = CP(NULL ), - [RT_WTHR] = CP(NULL ), +rfs_inner *const rfs_r[RT_HASH_SIZE] = { + [RT_AACT] = CP(NULL ),[RT_ACHR] = CP(NULL ),[RT_ACTI] = CP(r_acti), + [RT_ADDN] = CP(r_addn),[RT_ALCH] = CP(r_alch),[RT_AMMO] = CP(r_ammo), + [RT_ANIO] = CP(NULL ),[RT_APPA] = CP(NULL ),[RT_ARMA] = CP(NULL ), + [RT_ARMO] = CP(r_armo),[RT_ARTO] = CP(NULL ),[RT_ASPC] = CP(NULL ), + [RT_ASTP] = CP(NULL ),[RT_AVIF] = CP(NULL ),[RT_BOOK] = CP(NULL ), + [RT_BPTD] = CP(NULL ),[RT_CAMS] = CP(NULL ),[RT_CELL] = CP(NULL ), + [RT_CLAS] = CP(NULL ),[RT_CLDC] = CP(NULL ),[RT_CLFM] = CP(NULL ), + [RT_CLMT] = CP(NULL ),[RT_COBJ] = CP(NULL ),[RT_COLL] = CP(NULL ), + [RT_CONT] = CP(r_cont),[RT_CPTH] = CP(NULL ),[RT_CSTY] = CP(NULL ), + [RT_DEBR] = CP(NULL ),[RT_DIAL] = CP(NULL ),[RT_DLBR] = CP(NULL ), + [RT_DLVW] = CP(NULL ),[RT_DOBJ] = CP(NULL ),[RT_DOOR] = CP(r_door), + [RT_DUAL] = CP(NULL ),[RT_ECZN] = CP(NULL ),[RT_EFSH] = CP(NULL ), + [RT_ENCH] = CP(NULL ),[RT_EQUP] = CP(NULL ),[RT_EXPL] = CP(NULL ), + [RT_EYES] = CP(NULL ),[RT_FACT] = CP(NULL ),[RT_FLOR] = CP(r_flor), + [RT_FLST] = CP(NULL ),[RT_FSTP] = CP(NULL ),[RT_FSTS] = CP(NULL ), + [RT_FURN] = CP(NULL ),[RT_GLOB] = CP(NULL ),[RT_GMST] = CP(NULL ), + [RT_GRAS] = CP(NULL ),[RT_GRUP] = CP(NULL ),[RT_HAIR] = CP(NULL ), + [RT_HAZD] = CP(NULL ),[RT_HDPT] = CP(NULL ),[RT_IDLE] = CP(NULL ), + [RT_IDLM] = CP(NULL ),[RT_IMAD] = CP(NULL ),[RT_IMGS] = CP(NULL ), + [RT_INFO] = CP(NULL ),[RT_INGR] = CP(r_ingr),[RT_IPCT] = CP(NULL ), + [RT_IPDS] = CP(NULL ),[RT_KEYM] = CP(r_keym),[RT_KYWD] = CP(NULL ), + [RT_LAND] = CP(NULL ),[RT_LCRT] = CP(NULL ),[RT_LCTN] = CP(NULL ), + [RT_LGTM] = CP(NULL ),[RT_LIGH] = CP(r_ligh),[RT_LSCR] = CP(NULL ), + [RT_LTEX] = CP(NULL ),[RT_LVLI] = CP(NULL ),[RT_LVLN] = CP(NULL ), + [RT_LVSP] = CP(NULL ),[RT_MATO] = CP(NULL ),[RT_MATT] = CP(NULL ), + [RT_MESG] = CP(NULL ),[RT_MGEF] = CP(NULL ),[RT_MISC] = CP(r_misc), + [RT_MOVT] = CP(NULL ),[RT_MSTT] = CP(r_mstt),[RT_MUSC] = CP(NULL ), + [RT_MUST] = CP(NULL ),[RT_NAVI] = CP(NULL ),[RT_NAVM] = CP(NULL ), + [RT_NOTE] = CP(NULL ),[RT_NPC_] = CP(NULL ),[RT_OTFT] = CP(NULL ), + [RT_PACK] = CP(NULL ),[RT_PERK] = CP(NULL ),[RT_PGRE] = CP(NULL ), + [RT_PHZD] = CP(NULL ),[RT_PROJ] = CP(NULL ),[RT_PWAT] = CP(NULL ), + [RT_QUST] = CP(NULL ),[RT_RACE] = CP(NULL ),[RT_REFR] = CP(NULL ), + [RT_REGN] = CP(NULL ),[RT_RELA] = CP(NULL ),[RT_REVB] = CP(NULL ), + [RT_RFCT] = CP(NULL ),[RT_RGDL] = CP(NULL ),[RT_SCEN] = CP(NULL ), + [RT_SCOL] = CP(NULL ),[RT_SCPT] = CP(NULL ),[RT_SCRL] = CP(r_scrl), + [RT_SHOU] = CP(NULL ),[RT_SLGM] = CP(r_slgm),[RT_SMBN] = CP(NULL ), + [RT_SMEN] = CP(NULL ),[RT_SMQN] = CP(NULL ),[RT_SNCT] = CP(NULL ), + [RT_SNDR] = CP(NULL ),[RT_SOPM] = CP(NULL ),[RT_SOUN] = CP(NULL ), + [RT_SPEL] = CP(NULL ),[RT_SPGD] = CP(NULL ),[RT_STAT] = CP(r_stat), + [RT_TACT] = CP(NULL ),[RT_TES4] = CP(NULL ),[RT_TREE] = CP(r_tree), + [RT_TXST] = CP(NULL ),[RT_VTYP] = CP(NULL ),[RT_WATR] = CP(NULL ), + [RT_WEAP] = CP(r_weap),[RT_WOOP] = CP(NULL ),[RT_WRLD] = CP(NULL ), + [RT_WTHR] = CP(NULL ), }; diff --git a/espReader/Reader.c b/espReader/Reader.c index 91713ac..430e1ea 100644 --- a/espReader/Reader.c +++ b/espReader/Reader.c @@ -63,7 +63,7 @@ void asserts(void) { // binary overlay size checks assert(sizeof(Record) == 24); // Record struct incorrect size assert(sizeof(Group) == 24); // Group struct incorrect size - assert(sizeof((Group) { 0 }.label) == 4); // Label union in group struct incorrect size + assert(sizeof((Group) { 0 }.label) == 4); // Label union incorrect size assert(sizeof(Field) == 6); // Field struct incorrect size // zlib compatability @@ -112,7 +112,8 @@ size_t espr_decompressed_size(char *data, size_t size) { return dc_size; } -// Adds the size of every node up, reading decompressed size from compressed records. +// Adds the size of every node up, reading decompressed size from compressed +// records. void dc_size_cb(Node n, void *data, void **carry_out) { (void)carry_out; size_t *dc_size = data; @@ -162,7 +163,8 @@ struct decom { void espr_decompress(char *data, size_t size, char *buf, size_t buf_size) { struct decom s = { .buf = buf, .remaining = buf_size }; - struct walker_callbacks cb = { .pre = decompress_pre, .post = decompress_post, .data = &s }; + struct walker_callbacks cb = + { .pre = decompress_pre, .post = decompress_post, .data = &s }; espr_walk(data, size, cb); } @@ -189,7 +191,12 @@ void decompress_pre(Node n, void *decom_ptr, void **carry_out) { uint32_t to_copy = dc_size; uint32_t cur_size = n.header.record->size - sizeof(uint32_t); char *data_start = n.data + sizeof(uint32_t); - int ret = uncompress((Bytef *)d->buf, (uLongf *)&to_copy, (Bytef *)data_start, (uLong)cur_size); + int ret = uncompress( + (Bytef *)d->buf, + (uLongf *)&to_copy, + (Bytef *)data_start, + (uLong)cur_size + ); assert(ret == Z_OK); assert(to_copy == dc_size); @@ -265,10 +272,11 @@ char *walk_concat(char *data, size_t size, struct walker_callbacks cb) { return data; } -/* Walk a group record. Group records are containers for any other type of record, - * including other group records. +/* Walk a group record. Group records are containers for any other type of + * record, including other group records. * - * This function will also call `cb` with the node constructed from this group record. + * This function will also call `cb` with the node constructed from this group + * record. */ char *walk_group(char *data, struct walker_callbacks cb) { Group *const header = (Group *const)data; @@ -358,7 +366,8 @@ void print_group_label(Group *header) { printf("%d", header->label.number); case GT_EXTERIOR_CELL_BLOCK: case GT_EXTERIOR_CELL_SUBBLOCK: - printf("X: %d, Y: %d", header->label.coord[1], header->label.coord[0]); + printf("X: %d, Y: %d", + header->label.coord[1], header->label.coord[0]); case GT_WORLD_CHILDREN: case GT_CELL_CHILDREN: case GT_TOPIC_CHILDREN: