A little more formatting.

This commit is contained in:
2022-09-08 12:30:59 +10:00
parent ff95aeafbf
commit 2d5c85f0e8
3 changed files with 751 additions and 741 deletions

View File

@@ -78,8 +78,8 @@ extern "C" {
// === SIMPLE TYPES === // === SIMPLE TYPES ===
// //
// 3 byte ID, upper byte is determined at run time and is used to reference // 3 byte ID, upper byte is determined at run time and is used to
// across esp/esm files // reference across esp/esm files
typedef uint32_t formid; typedef uint32_t formid;
// char[4] with uint32_t access, used to access fourcc values // char[4] with uint32_t access, used to access fourcc values
@@ -190,17 +190,24 @@ extern "C" {
/* Given to espr_walk. /* Given to espr_walk.
* *
* pre is called before the children of the current node have been walked * pre is called before the children of the current node have been
* post is called after the children of the current node have been walked * walked post is called after the children of the current node have
* been walked
* *
* carry_out and carry_in is a pointer to a void * on the stack that can be * carry_out and carry_in is a pointer to a void * on the stack that can
* used for passing data between pre and post for a node. * be used for passing data between pre and post for a node.
* *
* data is a pointer that the user can supply when calling espr_walk that * data is a pointer that the user can supply when calling espr_walk
* will be passed to pre and post when they are called. * that will be passed to pre and post when they are called.
*/ */
struct walker_callbacks { struct walker_callbacks {
void (*pre)(Node n, void *data, void **carry_out, void *from_parent, void **to_children); void (*pre)(
Node n,
void *data,
void **carry_out,
void *from_parent,
void **to_children
);
void (*post)(Node n, void *data, void *carry_in); void (*post)(Node n, void *data, void *carry_in);
void *data; void *data;
}; };
@@ -208,25 +215,27 @@ extern "C" {
/* Meta Nodes are used for constructing a more flexible tree structure /* Meta Nodes are used for constructing a more flexible tree structure
* on top of the natural structure of ESP/ESM files. * on top of the natural structure of ESP/ESM files.
* *
* Meta Nodes do not create a pure tree structure, rather they have pointers to * Meta Nodes do not create a pure tree structure, rather they have
* their parent and first child, and children have pointers backwards and * pointers to their parent and first child, and children have pointers
* forward through a linked list of all of the children of the parent node. * backwards and forward through a linked list of all of the children of
* the parent node.
* *
* There is no root node as such, rather there is a root linked list for which * There is no root node as such, rather there is a root linked list for
* all of the Meta Nodes have no parents. * which all of the Meta Nodes have no parents.
* *
* While the ESP/ESM buffer can be modified in-place, any modification that * While the ESP/ESM buffer can be modified in-place, any modification
* changes the size of the stored data cannot be directly written to the buffer * that changes the size of the stored data cannot be directly written
* without first shifting all of the data after the point of modification. * to the buffer without first shifting all of the data after the point
* of modification.
* *
* Modifications that change data size are: * Modifications that change data size are:
* - Adding or deleting a group or record * - Adding or deleting a group or record
* - Adding or deleting a field in a record * - Adding or deleting a field in a record
* - Changing a variable length field with data of different length * - Changing a variable length field with data of different length
* *
* With a Meta Node you can instead allocate new, arbitrarily sized memory for * With a Meta Node you can instead allocate new, arbitrarily sized
* the node data. The Meta Node tree can then be walked to reconstruct a * memory for the node data. The Meta Node tree can then be walked to
* contiguous view of discontiguous memory. * reconstruct a contiguous view of discontiguous memory.
*/ */
struct meta_node { struct meta_node {
Node n; Node n;
@@ -248,7 +257,7 @@ extern "C" {
Type4 grup; // always RT_GRUP Type4 grup; // always RT_GRUP
uint32_t size; // uncludes the 24 byte group header uint32_t size; // uncludes the 24 byte group header
union { union {
Type4 type; // this may be mangled and should not be relied on Type4 type; // this may be mangled, do not rely on
formid formid; formid formid;
int32_t number; int32_t number;
int16_t coord[2]; int16_t coord[2];
@@ -311,11 +320,11 @@ extern "C" {
return rth2rt[uint32_t_msh(type, RT_HASH_BITS, RT_HASH_SEED)]; return rth2rt[uint32_t_msh(type, RT_HASH_BITS, RT_HASH_SEED)];
} }
/* `espr_walk` walks through the tree structure of the esp/esm binary data /* `espr_walk` walks through the tree structure of the esp/esm binary
* starting at `data` of `size` bytes. * data starting at `data` of `size` bytes.
* *
* `cb` is a callback that takes a `Node` to process. `pt` is a pointer to * `cb` is a callback that takes a `Node` to process. `pt` is a pointer
* arbitrary data that is passed on to `cb` whenever it is called. * to arbitrary data that is passed on to `cb` whenever it is called.
* *
* Data is walked sequentially. Nodes passed to `cb` will be strictly * Data is walked sequentially. Nodes passed to `cb` will be strictly
* increasing in terms of memory location within the buffer. * increasing in terms of memory location within the buffer.
@@ -327,8 +336,9 @@ extern "C" {
*/ */
void espr_print(char *data, size_t size); void espr_print(char *data, size_t size);
/* Calculates the number of groups and records in the esp/esm file and the /* Calculates the number of groups and records in the esp/esm file and
* size of the esp/esm if all of the compressed records were decompressed. * the size of the esp/esm if all of the compressed records were
* decompressed.
*/ */
struct esp_stats espr_stats(char *data, size_t size); struct esp_stats espr_stats(char *data, size_t size);
@@ -342,14 +352,14 @@ extern "C" {
return stats.record_count + stats.group_count; return stats.record_count + stats.group_count;
} }
// Calculates the size of a MetaNode tree constructed over the esp/esm for // Calculates the size of a MetaNode tree constructed over the esp/esm
// which the stats were generated. // for which the stats were generated.
inline size_t espr_tree_size(struct esp_stats stats) { inline size_t espr_tree_size(struct esp_stats stats) {
return sizeof(MetaNode) * espr_node_count(stats); return sizeof(MetaNode) * espr_node_count(stats);
} }
/* Copies the data from `data` to `buf` decompressing compressed fields as /* Copies the data from `data` to `buf` decompressing compressed fields
* it does so. buf_size should be the value returned from * as it does so. buf_size should be the value returned from
* `espr_decompressed_size`, and `buf` should be at least of that size. * `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); void espr_decompress(char *data, size_t size, char *buf, size_t buf_size);