Implement imgui with plugin-sdk

Maicol Castro

New member
Joined
Jun 8, 2021
Messages
1
Reaction score
0
Location
Uruguay, Rivera
Hi, I'm trying to implement imgui with plugin-sdk but I can't get it to work and I can't find any errors in my code
C++:
bool showWindow = false;

void GameProcess() {
    static int lastKeyPressTime = 0;

    if(plugin::KeyPressed('G') &&  CTimer::m_snTimeInMilliseconds - lastKeyPressTime >= 500) {
        lastKeyPressTime = CTimer::m_snTimeInMilliseconds;

        showWindow = !showWindow;

        if(showWindow)
            CMessages::AddMessageJumpQ("showWindow = true", 1000, 0, false);
        else
            CMessages::AddMessageJumpQ("showWindow = false", 1000, 0, false);
    }
}

void Init() {
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGui::StyleColorsDark();
    ImGui_ImplWin32_Init((HWND *)0xC97C1C);
    ImGui_ImplDX9_Init((IDirect3DDevice9 *)RwD3D9GetCurrentD3DDevice());
}

void Draw() {
    if(showWindow) {
        ImGui_ImplDX9_NewFrame();
        ImGui_ImplWin32_NewFrame();
        ImGui::NewFrame();
    
        ImGui::Begin("Test", &showWindow);
        ImGui::Text("Hello World");
        ImGui::End();
        
        ImGui::EndFrame();
        ImGui::Render();
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
    }
}

void Free() {
    ImGui_ImplDX9_Shutdown();
    ImGui_ImplWin32_Shutdown();
    ImGui::DestroyContext();
}

__attribute__((constructor)) void Constructor() {
    plugin::Events::initRwEvent += Init;
    plugin::Events::drawingEvent += Draw;
    plugin::Events::shutdownRwEvent += Free;
    plugin::Events::d3dLostEvent += Free;
    plugin::Events::d3dResetEvent += Init;
    plugin::Events::gameProcessEvent += GameProcess;
}
 
Top