D-side / ftl_font

Font dissection tools for FTL Faster Than Light version 1.6
MIT License
10 stars 0 forks source link

Some info on the font file format #2

Open Nasa62 opened 2 years ago

Nasa62 commented 2 years ago

image

Just in case it's still helpful

Also it looks like you're off by 8 bits in the character itself, "spacing before" is 8 bits later and there's "pad" there. image

Texture section appears to have 2 versions supported by FTL. Texture header is: MAGIC always 4 characters TEX\n I think (0xa584554)... appears big-endian maybe?

Tex V2's format is:

char[4] magic
uint8_t version
uint8_t format
uint8_t mipmaps
unit8_t opaque_bitmap
int16_t width
int16_t height
int32_t field_7 // I think this is some sort of scale or font size field
int32_t pixels_offset
int32_t pixels_size
int32_t bitmap_offset
int32_t bitmap_size

Tex V1's format is:

char[4] magic
uint8_t version
uint8_t[3] // 3 bytes unused, probably padding in the original struct
int16_t width
int16_t height
uint8_t field_7  // I think this is some sort of scale or font size field
uint8_t format
uint8_t mipmaps
uint8_t opaque_bitmap
int32_t pixels_offset
int32_t pixels_size
int32_t bitmap_offset
int32_t bitmap_size

There's some weird flipping of values in the assembly code so it looks like any 2 or 4 bytes value is actually stored big-endian (this is true for both the TEX & FONT headers).

This appears to be the different texture format values supported, again v1 does something weird with remapping some of these but I think these values are valid for v2 image

This all came from decompiling FTL in Ghidra.

D-side commented 2 years ago

This is certainly interesting input, thanks for posting!

I don't think v2 existed when I was building this, and v1 I was tearing down basically blind (using just the font files themselves, no code analysis) — but working alongside @bamalf, who at the time was adapting the old Russian translation and Arsenal+ to the new version of the game, battle-testing the solution as I went. It took a few tries, but it worked. At the time that is, which was back in December, 2017.

Yeah, what I see in the screenshots seems to match your reporting, meaning this tool would not work on the current version. Which is less than ideal, yes.


However, I punched a few identifiers from your last list into the search engine and I think I found the source: it would seem that the code where this stuff is implemented is open, GPLv3, and can be found over there: http://achurch.org/SIL/ — no decompilation necessary.

Now, which version of the library a given version of the game uses has to be guessed I suppose, as the current one (if that's the code involved) looks different to me. But generally this library is likely a better backbone for modding tooling than my half-baked scripting.

Which I think would render my project at least deprecated and possibly obsolete 🤷 …when someone makes a usable tool out of that library, that is.

Nasa62 commented 2 years ago

Yes FTL uses SIL and it's a fairly recent version but not sure if it's the latest.

Granted yeah SIL exists but I was digging through and reversing things for other reasons (trying to figure out how some of the language stuff works) and spent a while looking at FTL's font stuff and figured I'd paste this here because someone else linked me the project.

As you said SIL is GPLv3 but when it was used in FTL it wasn't.

I guess yeah it would be nice to write a tool to unpack them directly with SIL instead so we can repack the files for other languages.