@@ -460,15 +460,15 @@ void gr_font_set_default(int font_id)
460
460
g_default_font_id = font_id;
461
461
}
462
462
463
- FunHook<int (const char *, int )> gr_load_font_hook {
463
+ FunHook<int (const char *, int )> gr_init_font_hook {
464
464
0x0051F6E0 ,
465
465
[](const char *name, int reserved) {
466
- if (string_ends_with (name, " .vf" )) {
467
- return gr_load_font_hook.call_target (name, reserved);
468
- }
469
466
if (rf::is_dedicated_server) {
470
467
return -1 ;
471
468
}
469
+ if (string_ends_with (name, " .vf" )) {
470
+ return gr_init_font_hook.call_target (name, reserved);
471
+ }
472
472
for (unsigned i = 0 ; i < g_fonts.size (); ++i) {
473
473
auto & font = g_fonts[i];
474
474
if (font.get_name () == name) {
@@ -552,6 +552,13 @@ FunHook<void(int*, int*, const char*, int, int)> gr_get_string_size_hook{
552
552
},
553
553
};
554
554
555
+ CodeInjection gr_create_font_increment_number_injection{
556
+ 0x0051F800 ,
557
+ []() {
558
+ rf::gr::num_fonts++;
559
+ },
560
+ };
561
+
555
562
void gr_font_apply_patch ()
556
563
{
557
564
// Fix font texture leak
@@ -561,10 +568,15 @@ void gr_font_apply_patch()
561
568
gr_load_font_internal_fix_texture_ref.install ();
562
569
563
570
// Support TrueType fonts
564
- gr_load_font_hook .install ();
571
+ gr_init_font_hook .install ();
565
572
gr_set_default_font_hook.install ();
566
573
gr_get_font_height_hook.install ();
567
574
gr_string_hook.install ();
568
575
gr_get_string_size_hook.install ();
569
576
init_freetype_lib ();
577
+
578
+ // Do not increament number of loaded fonts before a successful load
579
+ // Fixes slots being exhausted if font cannot be loaded
580
+ gr_create_font_increment_number_injection.install ();
581
+ AsmWriter{0x0051F7D8 , 0x0051F7E3 }.nop ();
570
582
}
0 commit comments