Font Editing - RTHKKona/MHGU-Modding GitHub Wiki

Credits to zelmon64 on the MHGU Mod Server for writing this tutorial. Handburger - Editor

  1. Extract the Game Font Data file by dumping the romfs. The file is at nativeNX/[LANGUAGE]/GUI/02_common/font/font_festa.gfd where [LANGUAGE] is the three character language code.
  2. Extract the font texture file GUI/02_common/font/font_festa_09_HQ.tex from nativeNX/loc/arc/resident.arc (09 has some blank space) using Kuriimu2 or similar. Export the texture image from the tex file using something such as Kukkii from Kuriimu.
  3. Check available characters in the font. fc-query --format='%{charset}\n' ADYS-Regular-V5-4.ttf
  4. Make images of the desired characters.
  • I wanted to replace everything from " " (\u20) to z (\u7a).
  • I chose a pointsize of 22 because it resulted in a height of 28 pixels which I then trimmed down to 26 (one off the top and bottom). The original height is 24 pixels so this results in some missalignment when multiple lines are rendered (addressed in BONUS). for s in {\ ..z}; do printf "%3i:%s " \"$s\" $s; printf "%s" $s | ImageMagick--clang-x86_64.AppImage convert -background none -fill white -font ADYS-Regular-V5-4.ttf -pointsize 22 label:@-$(printf "%03i" \"$s\").22.adys.png; done
  1. Stick them all in a line to check how many will fit in 1024 pixels. ImageMagick--clang-x86_64.AppImage convert +append *.png all.png
  2. Make rows of the characters which fit within 1024 pixels wide. ImageMagick--clang-x86_64.AppImage convert +append (0|10[0-4])*.png top.png ImageMagick--clang-x86_64.AppImage convert +append 1(0[5-9]|[12])*.png bottom.png
  3. Edit the font texture to include the new characters, import it into the texure (tex) file and import that into the nativeNX/loc/arc/resident.arc file.
  4. Measure the width of each character. for f in (0|10[0-4])*.png; do ImageMagick--clang-x86_64.AppImage identify -ping -format $f',%w\n' $f; done > width.top.csv for f in 1(0[5-9]|[12])*.png; do ImageMagick--clang-x86_64.AppImage identify -ping -format $f',%w\n' $f; done > width.bottom.csv
  5. Write the gfd header to a new file. xxd -c2 font_festa.gfd|head -n51|xxd -r > font_festa.mod.gfd
  6. Write the character data to the file (must be in order of ascending unicode values).
  • The first two bytes are the unicode for the character.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The 5th byte is 09 for the texure page number.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The horizontal position is at byte 6 and the second half of 7.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The vertical position is 3e5 and 3ca for 997 and 970 at bytes 8 and the first half of 7 (I left a pixel of space bellow each line otherwise it would be 998 and 972 for a height of 26 per row starting from the bottom).

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The width for the size and advance is at byte 9 and 13 respectfully.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The height for both the size and advance is set to 1a (26) as "a001" at bytes 10-11 and 14-15.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • The offset and symbol are both set to 00 because that seemed to work.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

  • Then finish the entry with ffff.

2000 0000 0900 503e 07a0 0100 07a0 0114 0000 ffff

`awk -F"[,.]" -v x=0 '{printf "echo -en \"\\x%x\\x00\\x00\\x00\\x09\\x%02x\\x5%01x\\x3e\\x%02x\\xa0\\x01\\x00\\x%02x\\xa0\\x01\\x14\\x00\\x00\\xff\\xff\" >> font_festa.mod.gfd\n", $1, x%256, x/256, $5, $5; x+=$5}' width.top.csv | bash`
`awk -F"[,.]" -v x=0 '{printf "echo -en \"\\x%x\\x00\\x00\\x00\\x09\\x%02x\\xa%01x\\x3c\\x%02x\\xa0\\x01\\x00\\x%02x\\xa0\\x01\\x14\\x00\\x00\\xff\\xff\" >> font_festa.mod.gfd\n", $1, x%256, x/256, $5, $5; x+=$5}' width.bottom.csv | bash`
  1. Write the remaining characters (or edit the character count in the header). xxd -c2 font_festa.gfd|tail -n+962|xxd -r >> font_festa.mod.gfd
  2. Edit the gfd header as desired.
  • Bytes 28-29 are the character count (default e6 53 for 21478). The character count must be less than or equal to the number of characters listed.
  • Change the size (byte 20, default "18" for 24) to scale the size of the resulting font.
  • Bytes 42-43 and 46-47 are the maximum width and hight respecfully. I don't know what the maximum size values do so I just set it to a height of 26 ("e041") and a width of 28 ("d041"). hexedit font_festa.mod.gfd

00000000: 4746 4400 060f 0100 0000 0000 0200 0000 0200 0000 GFD................. 00000014: 1800 0000 0a00 0000 e653 0000 0000 0000 0300 0000 .........S.......... 00000028: 0000 e041 0000 d041 0000 a841 0000 4040 0000 4040 ...A...A...A..@@..@@ 0000003c: 0000 1840 0000 0000 1d00 0000 4755 495c 3032 5f63 [email protected]\02_c 00000050: 6f6d 6d6f 6e5c 666f 6e74 5c66 6f6e 745f 6665 7374 ommon\font\font_fest 00000064: 6100

  1. Use gfd.quiple.dev to check over the gfd file.
  2. Copy the modified gfd file to nativeNX/[LANGUAGE]/GUI/02_common/font/font_festa.gfd where [LANGUAGE] is the three character language code for the language being modified.
  3. BONUS: if the height used is not 24 pixels or the font size in the gfd header is not changed to match the new font some of the horizonal line textures won't match the new text line spacing. These can be found in GUI/99_texture/HD_window_BM_MQ_NOMIP.tex and GUI/99_texture/HD_questCounter_BM_NOMIP.tex in nativeNX/[LANGUAGE]/arc/resident_[LANGUAGE].arc.