UE4SS-RE / RE-UE4SS

Injectable LUA scripting system, SDK generator, live property editor and other dumping utilities for UE4/5 games
http://docs.ue4ss.com/
MIT License
1.27k stars 166 forks source link

[BUG - Release] Can't Add Font in Imgui #641

Open 3DMXM opened 1 month ago

3DMXM commented 1 month ago

Branch or Release WukongUE4SS 1.2

Game and Engine Version Game: Black Myth: Wukong Engine Version: 5.0

Describe the bug

a97aac023559b75183f219551214f1cf

Code

class Wukong : public CppUserModBase
{
private:
    int m_private_number{33};
    std::shared_ptr<GUI::GUITab> m_less_safe_tab{};
    bool show_demo_window = false;

public:
    Wukong() : CppUserModBase()
    {
        ModName = STR("Wukong");
        ModVersion = STR("1.0");
        ModDescription = STR("Gloss Trainer");
        ModAuthors = STR("小莫");

        register_tab(STR("Gloss Trainer"), [](CppUserModBase *instance)
                     {
            // In this callback, you can start rendering the contents of your tab with ImGui. 
            ImGui::Text("中文测试");

            // You can access members of your mod class with the 'instance' param.
            auto mod = dynamic_cast<Wukong*>(instance);
            if (!mod)
            {
                return;
            }

            if (mod->show_demo_window)
                ImGui::ShowDemoWindow(&mod->show_demo_window);

            ImGui::Checkbox("Demo Window", &mod->show_demo_window); // Edit bools storing our window open/close state

            // You can access both public and private members.
            mod->render_some_stuff(mod->m_private_number); });
    }

    ~Wukong() override {}

    auto on_update() -> void override
    {
    }

    auto on_unreal_init() -> void override
    {
    }

    auto on_ui_init() -> void override
    {
        // It's critical that you enable ImGui if you intend to use ImGui within the context of UE4SS.
        // If you don't do this, a crash will occur as soon as ImGui tries to render anything, for example in your tab.
        UE4SS_ENABLE_IMGUI();

        ImGuiIO &io = ImGui::GetIO();
        io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
        io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;  // Enable Gamepad Controls

        io.Fonts->AddFontDefault();
        io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\msyh.ttc", 14.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull());
    }
    auto render_some_stuff(int Number) -> void
    {
        auto calculated_value = Number + 1;
        ImGui::Text(std::format("calculated_value: {}", calculated_value).c_str());
    }
};

Mod file Wukong.zip

inkydragon commented 2 weeks ago

I think maybe you need to modify UE4SS: https://github.com/UE4SS-RE/RE-UE4SS/blob/d1a54788faf2e0a79cc599089b5b660d2fbbd694/UE4SS/src/GUI/GUI.cpp#L485-L487

like https://github.com/game-a11y/RE-UE4SS/commit/836fc3f77927005b25be665dfe8bae3c8942925a

Maybe we should add a config item that allows users to specify fonts in absolute paths?