From 24ecf5d3e60dd3c30912a77c0853486fd939c241 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Wed, 22 Feb 2023 05:32:56 +0100 Subject: [PATCH] Load font replacements from csv --- src/client/component/fastfiles.cpp | 13 ++++++- src/client/component/fonts.cpp | 60 +++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index c0c7882e..7045b502 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -149,6 +149,16 @@ namespace fastfiles } } + void load_pre_gfx_zones(game::XZoneInfo* zoneInfo, + unsigned int zoneCount, game::DBSyncMode syncMode) + { + // code_pre_gfx + + try_load_zone("h2_mod_pre_gfx", true); + + game::DB_LoadXAssets(zoneInfo, zoneCount, syncMode); + } + void load_post_gfx_and_ui_and_common_zones(game::XZoneInfo* zoneInfo, unsigned int zoneCount, game::DBSyncMode syncMode) { @@ -156,7 +166,6 @@ namespace fastfiles // ui_mp // common_mp - try_load_zone("h2_mod_ui", true); try_load_zone("h2_mod_common", true); game::DB_LoadXAssets(zoneInfo, zoneCount, syncMode); @@ -602,6 +611,8 @@ namespace fastfiles // load our custom ui and common zones utils::hook::call(0x14074E22A, load_post_gfx_and_ui_and_common_zones); + utils::hook::call(0x1405A46FD, load_pre_gfx_zones); + utils::hook::call(0x1405A4959, load_pre_gfx_zones); reallocate_asset_pools(); diff --git a/src/client/component/fonts.cpp b/src/client/component/fonts.cpp index 6d18e1d7..05157870 100644 --- a/src/client/component/fonts.cpp +++ b/src/client/component/fonts.cpp @@ -6,6 +6,7 @@ #include "filesystem.hpp" #include "command.hpp" #include "language.hpp" +#include "config.hpp" #include "game/game.hpp" #include "game/dvars.hpp" @@ -46,6 +47,60 @@ namespace fonts std::unordered_map raw_fonts; }; + struct font_replacement + { + game::language_t language; + std::string font; + std::string replacement; + }; + + game::StringTable* get_font_replacements() + { + if (!game::DB_XAssetExists(game::ASSET_TYPE_STRINGTABLE, "font_replacements.csv")) + { + return nullptr; + } + + return game::DB_FindXAssetHeader(game::ASSET_TYPE_STRINGTABLE, "font_replacements.csv", false).stringTable; + } + + std::string get_font_replacement(const std::string& name) + { + const auto table = get_font_replacements(); + if (table == nullptr) + { + return name; + } + + const auto current_language = language::current(); + const std::string language_str = game::languages[current_language].name; + + for (auto row = 0; row < table->rowCount; row++) + { + if (table->columnCount < 3) + { + continue; + } + + const auto row_values = &table->values[(row * table->columnCount)]; + const auto lang = row_values[0].string; + if (lang != language_str) + { + continue; + } + + const auto font = row_values[1].string; + const auto replacement = row_values[2].string; + + if (font == name) + { + return replacement; + } + } + + return name; + } + utils::concurrency::container font_data; game::TTF* create_font(const std::string& name, const std::string& data) @@ -108,10 +163,11 @@ namespace fonts game::TTF* db_find_xasset_header_stub(game::XAssetType type, const char* name, int create_default) { - auto result = try_load_font(name); + const auto name_ = get_font_replacement(name); + auto result = try_load_font(name_); if (result == nullptr) { - result = game::DB_FindXAssetHeader(type, name, create_default).ttf; + result = game::DB_FindXAssetHeader(type, name_.data(), create_default).ttf; } return result; }