From 31c46844a00357d32bbcd196bf0f07133e902bb3 Mon Sep 17 00:00:00 2001 From: PeachyPeachSM64 <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sat, 30 May 2026 20:00:48 +0200 Subject: [PATCH] Handle properly japanese for custom hud font - Fix buffer overflow - Use texture_font_jp as placeholder since there is no jp version of the custom hud fonts --- src/pc/djui/djui_font.c | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/pc/djui/djui_font.c b/src/pc/djui/djui_font.c index 312c999d0..21bd89f5a 100644 --- a/src/pc/djui/djui_font.c +++ b/src/pc/djui/djui_font.c @@ -208,11 +208,18 @@ static void djui_font_custom_hud_render_char(const char* c) { u32 index = djui_unicode_get_sprite_index(c); - u32 tx = index % 16; - u32 ty = index / 16; - - extern ALIGNED8 const Texture texture_font_hud[]; - djui_gfx_render_texture_tile_font(texture_font_hud, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32); + if (index & 0x010000) { + index &= ~0x010000; + u32 tx = index % 64; + u32 ty = index / 64; + extern ALIGNED8 const Texture texture_font_jp[]; + djui_gfx_render_texture_tile_font(texture_font_jp, 512, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16); + } else { + u32 tx = index % 16; + u32 ty = index / 16; + extern ALIGNED8 const Texture texture_font_hud[]; + djui_gfx_render_texture_tile_font(texture_font_hud, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32); + } } static void djui_font_custom_hud_recolor_render_char(const char* c) { @@ -221,19 +228,24 @@ static void djui_font_custom_hud_recolor_render_char(const char* c) { u32 index = djui_unicode_get_sprite_index(c); - u32 tx = index % 16; - u32 ty = index / 16; - - extern ALIGNED8 const Texture texture_font_hud_recolor[]; - djui_gfx_render_texture_tile_font(texture_font_hud_recolor, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32); + if (index & 0x010000) { + index &= ~0x010000; + u32 tx = index % 64; + u32 ty = index / 64; + extern ALIGNED8 const Texture texture_font_jp[]; + djui_gfx_render_texture_tile_font(texture_font_jp, 512, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16); + } else { + u32 tx = index % 16; + u32 ty = index / 16; + extern ALIGNED8 const Texture texture_font_hud_recolor[]; + djui_gfx_render_texture_tile_font(texture_font_hud_recolor, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32); + } } -static f32 djui_font_custom_hud_char_width(const char* text) { - char c = *text; - if (c == ' ') { return 0.3750f; } - c = djui_unicode_get_base_char(text); +static f32 djui_font_custom_hud_char_width(const char* c) { + if (*c == ' ') { return 0.3750f; } extern const f32 font_hud_widths[]; - return font_hud_widths[(u8)c - '!']; + return djui_unicode_get_sprite_width(c, font_hud_widths, 32.0f); } static const struct DjuiFont sDjuiFontCustomHud = {