Skip to content

Instantly share code, notes, and snippets.

@roccodev
Last active June 17, 2024 16:28
Show Gist options
  • Save roccodev/024effb9d8c2da7ba7d176fb6f773c73 to your computer and use it in GitHub Desktop.
Save roccodev/024effb9d8c2da7ba7d176fb6f773c73 to your computer and use it in GitHub Desktop.
.wifnt file format
// MiblFooter in xc3_lib
struct TexturePackFooter {
u32 a;
u32 b;
u32 c;
u32 d;
u32 e;
u32 f;
u32 g;
u32 h;
u32 i;
char j[4];
};
struct GlyphFontInfo {
// UTF-16LE
u16 codepoint;
// relative to the glyph area, I think this is used
// for alignment (definitely used for getFontPixelX/Y)
u8 origin_x;
u8 origin_y;
};
struct GlyphMapping {
// Index in the map
u16 glyph_id;
// Map ID for the code point (0=absent, 1, 2, ...)
u16 map;
};
// check layer::LayerFontResObj::getFontUvParms
// (accessible at this+0x58)
struct Struct3 {
// image dimensions
u32 texture_width;
u32 texture_height;
// glyph area dims (width + 1) x (height + 1)
u32 glyph_area_width;
u32 glyph_area_height;
u32 glyphs_per_row;
u32 f;
// Glyph u, v
// ----------
// pos = offset + i (see glyph_font_info docs)
// row = pos / glyphs_per_row
// column = pos % glyphs_per_row
// u = (1 + glyph_area_width * (column + 1)) / texture_width
// v = (1 + glyph_area_height * (row + 1)) / texture_height
};
struct Laft {
char magic[4];
u32 unk; // 0x2711
u32 font_info_ofs @ 0xc;
u32 glyph_offsets_ofs @ 0x10;
u32 glyph_count @ 0x14;
u32 mappings_ofs @ 0x18;
// assert = mask + 1?
u32 mappings_count @ 0x1c;
// Max code point (power of 2 -1, AND mask)
u32 mask @ 0x20;
u32 mibl_offset @ 0x24;
u32 mibl_size @ 0x28;
u32 ofs3 @ 0x2c;
u32 unk_conv_to_float @ 0x30;
// Indexed by code point (modulo mappings count <=> AND mask)
GlyphMapping mappings[mappings_count] @ mappings_ofs;
// Example: (layer::LayerFontResObj::getFontInfo)
//
// u16 codepoint = 0x20 (' ')
// GlyphMapping mapping = mappings[codepoint]
// u16 offset = glyph_offsets[mapping.glyph_id]
//
// binary search for i (starting at mapping.map/2) such that:
//
// GlyphFontInfo info = glyph_font_info[offset + i]
// info.codepoint == codepoint
GlyphFontInfo glyph_font_info[(ofs3-font_info_ofs)/4] @ font_info_ofs;
u16 glyph_offsets[glyph_count] @ glyph_offsets_ofs;
Struct3 s3 @ ofs3;
#define tex_pack_hdr_size 0x28
#define tex_pack_hdr mibl_offset + mibl_size - 0x28
// use xc3_lib (Mibl)
u8 mibl_pak[mibl_size - 0x28] @ mibl_offset;
TexturePackFooter tpf @ tex_pack_hdr;
};
Laft l @ 0x0;
bitfield StyleFlags {
unk1: 1;
// Checked in createFontCode, if set doesn't use glyph-specific data.
// Basically makes fonts monospace
no_glyph_data: 1;
unk: 30;
};
struct Style {
StyleFlags flags;
u32 style_name_ptr;
u32 font_name_ptr;
// UITextObject::getTransformPosOffs
float scale_x;
float scale_y;
// always 100 - no visible changes when altered
float b;
u16 max_width;
u16 max_lines;
// For vertical text (getDispSetting() != 0), these two are reversed
// Added to fontPixelHeight, essentially increases line height/spacing between lines
u16 add_height;
// Added to fontPixelWidth
// Only used by "caption_v" (XC3 style 170), which is used in JP
// for song lyrics displayed vertically. (For vertical text, this adds space between
// characters)
u16 add_width;
padding[4];
// always 4 - no visible changes when altered
u32 unk;
char style_name[] @ style_name_ptr;
char font_name[] @ font_name_ptr;
};
struct Last {
char magic[4];
u32 version;
u32 style_ofs;
u32 style_count;
Style styles[style_count] @ style_ofs;
};
Last l @ 0x0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment