Tutorial How to use ImGui in your mods

NotALegitGuy

Solid & Active Platinian
Original poster
Sep 24, 2018
69
67
18
Costa Rica
Hey people, nop here, i can't tell for sure if this will work in all games but in the ones I've tried it has.
I don't have a PC as of the time I'm writing this so i won't be able to provide much images but hopefully a good explanation can still be done.

To use ImGui in your mods you must first make your UI, unlike with Java Menus you must make your own OpenGL3 ( or OpenGL2 if that's the case ) Environment, you can just use the example from github for this, this is needed to design your UI and test it to see how it looks.

I recommend putting the code you need such as initialization and UI Design close to each other and organized to easily copy it into your hook.

Next up we need to make a hook to SwapBuffers ( Sometimes it's AppDraw, depends ), to do this we do what we would go about in normal hooking, the old function, then the new function and finally Hook, except instead of hooking to an address, we hook to a Symbol, this is because AppDraw and SwapBuffers are symbols.

Here's an example of a simple ImGui hook i just wrote.

C++:
static bool init{ false }; // initiliazation checker

void (*old_swapbuffersHook)();
void swapbuffersHook()
{
  if (!init)
  {
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();

    io.IniFilename = NULL; //recommended
    ImGui::GetStyle().WindowRounding = 12.0f; // Makes the UI Rounded
  
    ImGui_ImplAndroid_Init(NULL);
    ImGui_ImplOpenGL3_Init("#version 100"); // Initiates backends

    ImFontConfig font_cfg;
    font_cfg.SizePixels = 22.0f;
    io.Fonts->AddFontDefault(&font_cfg); // loads default font, if you wanna add one, look at the documentation of ImGui

    init = true;
  }

  // After initialization is done, we begin drawing

  ImGuiIO& io = ImGui::GetIO();
  ImGui_ImplOpenGL3_NewFrame();
  ImGui_ImplAndroid_NewFrame(getSSX(), getSSY()); // the parameters are functions for getting screen size
  ImGui::NewFrame(); // makes new frames to draw on

  ImGui::Begin("PlatinMods Tuto"); // No flags cuz im not gonna make something complicated

  ImGui::Text("PMT is epicly epic"); // Makes a new TextLabel

  ImGui::End(); // ends drawing
  ImGui::Render(); // renders the imgui
  glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);

  ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

  old_swapbuffershook();
}
Finally, we hook the symbol and use our functions we wrote such as the ones in the above example.

To hook a Symbol you either make your own hooking tool or use the one provided by LGL Mod Menu in the Macros.h file, called HOOKSYM.

C++:
HOOKSYM_LIB("libroblox.so", "__imp_eglSwapBuffers", (void *) swapbuffersHook, (void **)&old_swapbuffersHook);
 
Last edited:

AndnixSH

PMT Elite Modder
Staff member
Modding-Team
Jun 27, 2017
4,539
302,674
1,213
Modding World
Nice tut.
A disadventage, you need to hook the game for display. Need some kind of 'universal'
 

NotALegitGuy

Solid & Active Platinian
Original poster
Sep 24, 2018
69
67
18
Costa Rica
Nice tut.
A disadventage, you need to hook the game for display. Need some kind of 'universal'
Yeah, this is mainly for opengl games so you have to open them in IDA Pro or Binja and search for a symbol such as appdraw or swapbuffers, they are easy to find luckily, just let IDA Pro analyze then search in the functions for AppDraw or swapbuffers or search them in Exports.
 

AndnixSH

PMT Elite Modder
Staff member
Modding-Team
Jun 27, 2017
4,539
302,674
1,213
Modding World
Yeah, this is mainly for opengl games so you have to open them in IDA Pro or Binja and search for a symbol such as appdraw or swapbuffers, they are easy to find luckily, just let IDA Pro analyze then search in the functions for AppDraw or swapbuffers or search them in Exports.
I hate IDA Pro 😂
Well easier way will come in the future
 
  • Like
Reactions: zlh123

NotALegitGuy

Solid & Active Platinian
Original poster
Sep 24, 2018
69
67
18
Costa Rica
I hate IDA Pro 😂
Well easier way will come in the future
Try using Binary Ninja then, it has a nice UI, nice plugins, and more and even has some stuff to find functions i saw iivilian ( Roblox ScriptWare Dev ) mentioning.

I have it cracked but it's a somewhat old version sadly, if you have money then you can probably afford it
 

AndnixSH

PMT Elite Modder
Staff member
Modding-Team
Jun 27, 2017
4,539
302,674
1,213
Modding World
Try using Binary Ninja then, it has a nice UI, nice plugins, and more and even has some stuff to find functions i saw iivilian ( Roblox ScriptWare Dev ) mentioning.

I have it cracked but it's a somewhat old version sadly, if you have money then you can probably afford it
My point is not to use disassembler. I want to use universally and auto updateable without worrying about hooking gl, just like LGL menu

Do you know how to make floating icon in imgui like geokar2006 did?
 
Last edited:
  • Like
Reactions: Neko Mage

NotALegitGuy

Solid & Active Platinian
Original poster
Sep 24, 2018
69
67
18
Costa Rica
My point is not to use disassembler. I want to use universally and auto updateable without worrying about hooking gl, just like LGL menu

Do you know how to make floating icon in imgui like geokar2006 did?
ImGui is already auto update able since SwapBuffers or AppDraw don't change when the game updates unless the graphics engine is changed which never happens.

For floating icon i guess make a filled circle and put some image inside it then if it gets tapped, initiate a new window with the UI and make the circle invisible, I'm not really that much of an expert at making UIs with ImGui.

For not using Disassembler, if the reason is because of mobile users, then i have a possible Solution, on the playstore there's 2 apps for disassembly, one is called Disassembler - Viewer, Dumper This one supports viewing symbols, so people could just search the SwapBuffers symbol or AppDraw symbol and easily hook.

Hooking is easy too, just put the symbol of SwapBuffers or AppDraw in the symbol Hook, then as pointer use the function you used which displays our UI, just like in this tutorial.
 
  • Like
Reactions: AndnixSH

busmanl30

Solid & Active Platinian
Mar 17, 2019
84
3,573
193
20
United States
Nice tut.
A disadventage, you need to hook the game for display. Need some kind of 'universal'
This is just incorrect, Open GL is native to android so all you need is to use symbols to resolve the function, i think this is a really good way for drawing stuff as swap buffers is the best way to hook onto gl graphics. It runs the drawing on the gpu instead of the cpu like some mod menus.
 
  • Like
Reactions: AFRIZAL GAMING