diff --git a/src/client/component/fonts.cpp b/src/client/component/fonts.cpp index c89fe3f7..09a655cb 100644 --- a/src/client/component/fonts.cpp +++ b/src/client/component/fonts.cpp @@ -23,7 +23,7 @@ namespace fonts { namespace { - const char* hudelem_fonts[] = + std::array hudelem_fonts { "", "bigfixed", @@ -45,26 +45,45 @@ namespace fonts game::Font_s* bank_font = nullptr; utils::hook::detour ui_get_font_handle_hook; + utils::hook::detour ui_get_font_handle2_hook; utils::hook::detour ui_asset_cache_hook; - game::Font_s* ui_get_font_handle_stub(void* a1, int font_index) + game::Font_s* get_font_handle_at_index(int font_index) { - if (font_index < 12 || bank_font == nullptr) - { - return ui_get_font_handle_hook.invoke(a1, font_index); - } - switch (font_index) { - case 12: - case 13: - case 14: + case game::HE_FONT_BANK: + case game::HE_FONT_BANKSHADOW: + case game::HE_FONT_BANKSHADOWMORE: return bank_font; } + return nullptr; + } + + game::Font_s* ui_get_font_handle_stub(void* a1, int font_index) + { + const auto res = get_font_handle_at_index(font_index); + if (res) + { + return res; + } + return ui_get_font_handle_hook.invoke(a1, font_index); } + game::Font_s* ui_get_font_handle2_stub(void* a1, size_t a2) + { + const auto font_index = *reinterpret_cast(a2 + 208); + const auto res = get_font_handle_at_index(font_index); + if (res) + { + return res; + } + + return ui_get_font_handle2_hook.invoke(a1, a2); + } + game::Font_s* get_bank_font() { if (language::is_asian()) @@ -87,9 +106,9 @@ namespace fonts { switch (hudelem_font_index) { - case 12: - case 13: - case 14: + case game::HE_FONT_BANK: + case game::HE_FONT_BANKSHADOW: + case game::HE_FONT_BANKSHADOWMORE: return hudelem_font_index; } @@ -117,11 +136,11 @@ namespace fonts { switch (font_index) { - case 12: + case game::HE_FONT_BANK: return 0; // none - case 13: + case game::HE_FONT_BANKSHADOW: return 2; // shadowed - case 14: + case game::HE_FONT_BANKSHADOWMORE: return 4; // shadowed more } @@ -212,10 +231,11 @@ namespace fonts // 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); + ui_get_font_handle2_hook.create(0x1405F9820, ui_get_font_handle2_stub); // change hudelem font array - utils::hook::inject(0x1404C17A6, hudelem_fonts); - utils::hook::set(0x1404C17B7, static_cast(ARRAYSIZE(hudelem_fonts))); + utils::hook::inject(0x1404C17A6, hudelem_fonts.data()); + utils::hook::set(0x1404C17B7, static_cast(hudelem_fonts.size())); // handle custom fonts utils::hook::jump(0x14037B390, utils::hook::assemble(get_hud_elem_info_stub), true); diff --git a/src/client/component/menus.cpp b/src/client/component/menus.cpp new file mode 100644 index 00000000..4e9b5181 --- /dev/null +++ b/src/client/component/menus.cpp @@ -0,0 +1,61 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" + +#include "console.hpp" + +#include + +namespace menus +{ + namespace + { + constexpr auto patch_menu_list_name = "ui/patch_code.txt"; + + void ui_add_menu_list_stub(void* context, void* menu_list, int a3) + { + game::UI_AddMenuList(context, menu_list, a3); + + if (game::DB_XAssetExists(game::ASSET_TYPE_MENUFILE, patch_menu_list_name) && + !game::DB_IsXAssetDefault(game::ASSET_TYPE_MENUFILE, patch_menu_list_name)) + { + const auto patch_code_list = game::UI_LoadMenus(patch_menu_list_name); + game::UI_AddMenuList(context, patch_code_list, a3); + } + } + + int menus_open_by_name_stub(void* context, const char* name) + { + const std::string override_name = "override/"s + name; + const auto override_menu = game::Menus_FindByName(context, override_name.data()); + + if (override_menu) + { + game::Menus_Open(context, override_menu, 0); + return 1; + } + + const auto menu = game::Menus_FindByName(context, name); + if (menu) + { + game::Menus_Open(context, menu, 0); + return 1; + } + + return 0; + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + utils::hook::call(0x1405F0A45, ui_add_menu_list_stub); + utils::hook::jump(game::Menus_OpenByName, menus_open_by_name_stub); + } + }; +} + +REGISTER_COMPONENT(menus::component) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index fab98422..ad746aca 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -2949,6 +2949,26 @@ namespace game GamerProfileDataUnion u; }; + enum HeFont + { + HE_FONT_DEFAULT = 0x0, + HE_FONT_BIGFIXED = 0x1, + HE_FONT_SMALLFIXED = 0x2, + HE_FONT_OBJECTIVE = 0x3, + HE_FONT_BIG = 0x4, + HE_FONT_SMALL = 0x5, + HE_FONT_HUDBIG = 0x6, + HE_FONT_HUDSMALL = 0x7, + HE_FONT_BUTTONPROMPT = 0x8, + HE_FONT_SUBTITLE = 0x9, + HE_FONT_TIMER = 0xA, + HE_FONT_NAMEPLATE = 0xB, + HE_FONT_BANK = 0xC, + HE_FONT_BANKSHADOW = 0xD, + HE_FONT_BANKSHADOWMORE = 0xE, + HE_FONT_COUNT, + }; + namespace hks { struct lua_State; diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index efd254f3..c2f574c8 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -120,7 +120,11 @@ namespace game WEAK symbol LUI_EndEvent{0x140316890}; WEAK symbol LUI_EnterCriticalSection{0x140316980}; WEAK symbol LUI_LeaveCriticalSection{0x14031BC20}; + WEAK symbol Menu_IsMenuOpenAndVisible{0x1405EE1A0}; + WEAK symbol Menus_FindByName{0x140603080}; + WEAK symbol Menus_OpenByName{0x140603770}; + WEAK symbol Menus_Open{0x1406034E0}; WEAK symbol Material_RegisterHandle{0x140759BA0}; @@ -211,6 +215,9 @@ namespace game WEAK symbol UI_DrawWrappedText{0x1406055E0}; + WEAK symbol UI_LoadMenus{0x1406072B0}; + WEAK symbol UI_AddMenuList{0x140604FE0}; + WEAK symbol PM_playerTrace{0x14068F0A0}; WEAK symbol