Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions runtime/ui/i18n.mm
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,22 @@ static int ttc_face(const char *path, const char *lang) {
static bool add_single_fallback(ImFontAtlas *atlas, float size, const ImFontConfig *base,
const char *const *fonts, const char *lang,
const ImVector<ImWchar> &ranges, const char *shipped_path = nullptr) {
if (!fonts) return false;
for (int i = -1; i < 0 || fonts[i]; i++) {
const char *path = (i < 0 && shipped_path) ? shipped_path : (i >= 0 ? fonts[i] : nullptr);
if (!path || !*path) continue;
auto try_load = [&](const char *path) -> bool {
if (!path || !*path) return false;
FILE *f = fopen(path, "rb");
if (!f) continue;
if (!f) return false;
fclose(f);
ImFontConfig cfg = base ? *base : ImFontConfig();
cfg.MergeMode = true;
cfg.FontNo = ttc_face(path, lang);
cfg.FontDataOwnedByAtlas = true;
atlas->AddFontFromFileTTF(path, size, &cfg, ranges.Data);
return true;
};
if (shipped_path && try_load(shipped_path)) return true;
if (fonts) {
for (int i = 0; fonts[i]; i++)
if (try_load(fonts[i])) return true;
}
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions runtime/ui_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ bool rt_ui_layout_pane_draw(Cpu *c, void (*native)(Cpu *)) {
#endif
}

uint32_t rt_cjk_font_scale(void) {
const char *env = getenv("SAVAGEWIND_CJK_SCALE");
if (env && *env) {
int v = atoi(env);
if (v >= 1 && v <= 4) return (uint32_t)v;
}
return (g_settings.sharper_text >= 2) ? 2 : 1;
}

uint64_t ui_layout_begin(Cpu *c) {
#ifdef SW_METAL
return 0;
Expand Down
1 change: 1 addition & 0 deletions runtime/ui_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ uint64_t ui_layout_begin(Cpu *c);
void ui_layout_end(Cpu *c, uint64_t commands);
void rt_ui_layout_draw(Cpu *c, void (*native)(Cpu *));
bool rt_ui_layout_pane_draw(Cpu *c, void (*native)(Cpu *));
uint32_t rt_cjk_font_scale(void);
8 changes: 8 additions & 0 deletions tools/game_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
Site('quick_menu_capture_alpha', 'code', 'f9400268/ffc003ff bd405100 1e202008 54000000/ff00001f '
'bd402100 1e2e1001 1e212000 54000001/ff00001f 90000001/9f00001f 91000021/ffc003ff '
'aa1303e0 94000000/fc000000 52801fe8 39016408', 7),
# Scalable font engine (CJK/Chinese TrueType) resolution scaling
Site('cjk_font_size', 'code', '53103d01 2a0103e4 94000000/fc000000 f9400660 52800102 b9403381 94000000/fc000000 aa0003f4', 0),
Site('cjk_font_bin', 'code', '7d406f81 4b080128 f94c826a 79406b8b 9bba296a bd400940 7e21d821 1f012400', 0),
Site('cjk_font_quad', 'code', '2d42212b 79c03aa9 1e220120 1e200960 1e380009 79009389 79c00329 0b090289', 0),
# the wait for the ground (tools/patches.py _tp_gate): is the map around Link not loaded yet? (the world pauses for it)
Site('tp_gate', 'code', 'd10283ff fd002be8 f90037f9 a905fbfd a9075ff8 a90857f6 a9094ff4 910163fd '
'90000016/9f00001f', 0),
Expand Down Expand Up @@ -480,6 +484,7 @@
('surf_contact', 'surf_boost_remove', 'surf_jump_request'),
('stale_actor_helper', 'stale_actor_kind', 'stale_actor_target', 'stale_actor_flag', 'stale_actor_flag2'),
('quick_menu_capture_alpha',),
('cjk_font_size', 'cjk_font_bin', 'cjk_font_quad'),
('kf_angle',),
('demo_move_arrive',),
('rail_point_radius',),
Expand Down Expand Up @@ -516,6 +521,9 @@

KNOWN = {
'1.9.0': {
'cjk_font_size': 0x7000017d40,
'cjk_font_bin': 0x7000017d78,
'cjk_font_quad': 0x7000017f78,
'ui_layout_draw': 0x70013ee084,
'ui_layout_native': 0x7000f6f690,
'ui_layout_pane': 0x7000027d30,
Expand Down
39 changes: 39 additions & 0 deletions tools/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ def _ui_layout_pane(gen, a):
f'if (rt_ui_layout_pane_draw(c, {fn})) return; c->x[8] = LD8(c->x[0] + 0x58); }}')


def _cjk_font_size(gen, a):
assert _word(gen, a) == 0x53103d01, hex(_word(gen, a)) # lsl w1, w8, #0x10
return ('{ extern uint32_t rt_cjk_font_scale(void); '
'uint32_t scale = rt_cjk_font_scale(); '
'uint32_t size = (uint32_t)c->x[8] * scale; '
'c->x[1] = size << 16; }')


def _cjk_font_bin(gen, a):
assert _word(gen, a) == 0x7d406f81, hex(_word(gen, a)) # ldr h1, [x28, #0x36]
return ('{ extern uint32_t rt_cjk_font_scale(void); '
'uint64_t ea = c->x[28] + 0x36ull; '
'uint32_t scale = rt_cjk_font_scale(); '
'c->v[1] = (u128)((uint32_t)LD16(ea) * scale); }')


def _cjk_font_quad(gen, a):
assert _word(gen, a) == 0x2d42212b, hex(_word(gen, a)) # ldp s11, s8, [x9, #0x10]
return ('{ extern uint32_t rt_cjk_font_scale(void); '
'uint64_t ea = c->x[9] + 16; '
'uint32_t u_s11 = LD32(ea); '
'uint32_t u_s8 = LD32(ea + 4); '
'uint32_t scale = rt_cjk_font_scale(); '
'if (scale > 1) { '
'float f_s11, f_s8; '
'memcpy(&f_s11, &u_s11, 4); '
'memcpy(&f_s8, &u_s8, 4); '
'f_s11 /= (float)scale; '
'f_s8 /= (float)scale; '
'memcpy(&u_s11, &f_s11, 4); '
'memcpy(&u_s8, &f_s8, 4); '
'} '
'c->v[11] = (u128)u_s11; '
'c->v[8] = (u128)u_s8; }')


def _quick_sort_enter(gen, a):
# Menu::enter: sample held X before the selector initializes its list.
assert _word(gen, a) == 0xfc1d0fe8, hex(_word(gen, a)) # str d8, [sp, #-0x30]!
Expand Down Expand Up @@ -1312,6 +1348,9 @@ def _tp_gate(gen, a):
'horse_crash': _horse_crash,
'horse_look_ahead': _horse_look_ahead,
'item_tick': _item_tick,
'cjk_font_size': _cjk_font_size,
'cjk_font_bin': _cjk_font_bin,
'cjk_font_quad': _cjk_font_quad,
}


Expand Down