Radfordhound / HedgeLib

A C++ library and collection of tools that aims to make modding games in the Sonic the Hedgehog franchise easier.
MIT License
88 stars 24 forks source link

Writing #39

Closed Radfordhound closed 5 years ago

Radfordhound commented 5 years ago

Yeah lol, just writing in general.

This is gonna be tricky. We can't just call fwrite; we're going to be writing files of dynamic sizes, aka files which contain arrays and/or pointers.

To accomplish this, we need to come up with a way to do the following:

The first and last ones can be accomplished fairly easily by using a variadic macro + variadic template like we did with endian swapping. The main one that trips me up here is that second one; accomplishing this would require looping through arrays to write each value in the array, fix its offsets, and write its children objects (if any) as well as its arrays (if any).

I suppose we could accomplish this by making arrays structs of their own which contain both the value and the count?

Radfordhound commented 5 years ago

a9160a33af276fd7bc7792aeb9fdd7b7a2b1804f implements some of this

Radfordhound commented 5 years ago

6d3d63f157297f58ea7d88eac5300b1f7d3f07c5 Implemented array writing, now just onto strings (I forgot they had to be treated differently tbh lol)

Radfordhound commented 5 years ago

Ack, I have to re-think some of this tbh. The best way I can really think of to write BINA strings is to call a Write function with a pointer to a vector containing "BINAStringTableEntry"s like this:

struct BINAStringTableEntry
{
    long StringOffsetPos;
    char* StringData;
};

But obviously this means having a different write function for BINA files vs. non-BINA files, as you don't want this requirement present to write non-BINA files which don't even have string tables.

Plus some files just require more than this automatic writing stuff easily allows for due to weird padding or whatever.

Radfordhound commented 5 years ago

b5c71e2dfbe052c3487b3398ac73daead6795ed2 Implemented string writing and made writing as a whole more flexible.