Remove unused font code

This commit is contained in:
fed 2023-03-03 19:18:23 +01:00
parent be64210566
commit 945e502d82
3 changed files with 0 additions and 107 deletions

View File

@ -42,85 +42,6 @@ namespace fonts
"bankshadowmore",
};
struct font_data_t
{
std::unordered_map<std::string, game::TTF*> fonts;
std::unordered_map<std::string, std::string> raw_fonts;
};
utils::memory::allocator font_allocator;
utils::concurrency::container<font_data_t> font_data;
game::TTF* create_font(const std::string& name, const std::string& data)
{
const auto font = utils::memory::get_allocator()->allocate<game::TTF>();
font->name = utils::memory::get_allocator()->duplicate_string(name);
font->buffer = utils::memory::get_allocator()->duplicate_string(data);
font->len = static_cast<int>(data.size());
font->fontFace = 0;
return font;
}
void free_font(game::TTF* font)
{
font_allocator.free(font->buffer);
font_allocator.free(font->name);
font_allocator.free(font);
}
game::TTF* load_font(const std::string& name)
{
return font_data.access<game::TTF*>([&](font_data_t& data_) -> game::TTF*
{
if (const auto i = data_.fonts.find(name); i != data_.fonts.end())
{
return i->second;
}
std::string data{};
if (const auto i = data_.raw_fonts.find(name); i != data_.raw_fonts.end())
{
data = i->second;
}
if (data.empty() && !filesystem::read_file(name, &data))
{
return nullptr;
}
const auto material = create_font(name, data);
data_.fonts[name] = material;
return material;
});
}
game::TTF* try_load_font(const std::string& name)
{
try
{
return load_font(name);
}
catch (const std::exception& e)
{
console::error("Failed to load font %s: %s\n", name.data(), e.what());
}
return nullptr;
}
game::TTF* db_find_xasset_header_stub(game::XAssetType type, const char* name, int create_default)
{
auto result = try_load_font(name);
if (result == nullptr)
{
result = game::DB_FindXAssetHeader(type, name, create_default).ttf;
}
return result;
}
game::Font_s* bank_font = nullptr;
utils::hook::detour ui_get_font_handle_hook;
@ -240,29 +161,6 @@ namespace fonts
}
}
void add(const std::string& name, const std::string& data)
{
font_data.access([&](font_data_t& data_)
{
data_.raw_fonts[name] = data;
});
}
void clear()
{
font_data.access([&](font_data_t& data_)
{
for (auto& font : data_.fonts)
{
free_font(font.second);
}
font_allocator.clear();
data_.fonts.clear();
*reinterpret_cast<int*>(0x14EE3ACB8) = 0; // reset registered font count
});
}
void load_font_zones()
{
const auto disabled = config::get<bool>("disable_custom_fonts");
@ -309,8 +207,6 @@ namespace fonts
public:
void post_unpack() override
{
utils::hook::call(0x140747096, db_find_xasset_header_stub);
// add custom fonts to hud elem fonts
ui_asset_cache_hook.create(0x140606090, ui_asset_cache_stub);
ui_get_font_handle_hook.create(0x1406058F0, ui_get_font_handle_stub);

View File

@ -5,7 +5,5 @@
namespace fonts
{
void add(const std::string& name, const std::string& data);
void clear();
void load_font_zones();
}

View File

@ -58,7 +58,6 @@ namespace mods
{
if (release_assets)
{
fonts::clear();
loadscreen::clear();
}