Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3DMXM opened this issue Aug 29, 2024 · 1 comment
Open

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

3DMXM opened this issue Aug 29, 2024 · 1 comment

Comments

@3DMXM
Copy link

3DMXM commented Aug 29, 2024

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
Copy link

I think maybe you need to modify UE4SS:

ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false; // if true it will try to free memory and fail
io.Fonts->AddFontFromMemoryTTF(Roboto, sizeof(Roboto), base_font_size, &font_cfg);

like game-a11y@836fc3f

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants