Skip to content

Commit c4fe139

Browse files
committed
Fix font limit being reached when switching levels in dedicated server
This is a recent regression after making dedicated server load less vpps
1 parent 5d4e9d3 commit c4fe139

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

game_patch/graphics/gr_font.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,15 @@ void gr_font_set_default(int font_id)
460460
g_default_font_id = font_id;
461461
}
462462

463-
FunHook<int(const char*, int)> gr_load_font_hook{
463+
FunHook<int(const char*, int)> gr_init_font_hook{
464464
0x0051F6E0,
465465
[](const char *name, int reserved) {
466-
if (string_ends_with(name, ".vf")) {
467-
return gr_load_font_hook.call_target(name, reserved);
468-
}
469466
if (rf::is_dedicated_server) {
470467
return -1;
471468
}
469+
if (string_ends_with(name, ".vf")) {
470+
return gr_init_font_hook.call_target(name, reserved);
471+
}
472472
for (unsigned i = 0; i < g_fonts.size(); ++i) {
473473
auto& font = g_fonts[i];
474474
if (font.get_name() == name) {
@@ -552,6 +552,13 @@ FunHook<void(int*, int*, const char*, int, int)> gr_get_string_size_hook{
552552
},
553553
};
554554

555+
CodeInjection gr_create_font_increment_number_injection{
556+
0x0051F800,
557+
[]() {
558+
rf::gr::num_fonts++;
559+
},
560+
};
561+
555562
void gr_font_apply_patch()
556563
{
557564
// Fix font texture leak
@@ -561,10 +568,15 @@ void gr_font_apply_patch()
561568
gr_load_font_internal_fix_texture_ref.install();
562569

563570
// Support TrueType fonts
564-
gr_load_font_hook.install();
571+
gr_init_font_hook.install();
565572
gr_set_default_font_hook.install();
566573
gr_get_font_height_hook.install();
567574
gr_string_hook.install();
568575
gr_get_string_size_hook.install();
569576
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();
570582
}

0 commit comments

Comments
 (0)