Solved DIRECT3D hook vs OPENGL hook

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

blergmasta

Newbie
Full Member
Feb 28, 2016
6
52
0
Hey guys ive been browsing this forum for a while now and I have learned a large amount.
Today I made my first working d3d9 endscene hook for windows 10 and using the guide that Broihon sent me https://www.directxtutorial.com/default.aspx and a combination of Fleep's d3d menu tutorial I was able to render a filled rectangle.

https://i.imgur.com/NEi70tg.png

I would like to know how much now does hooking opengl differ? I have looked up ways they do it on google but it seems quite different someone said something about opengl not using scene functions the way d3d uses it ?
I am not asking to be spoonfed but what I am asking how they differ and examples of ways you might of done it with different opengl games you have hacked. Thanks as always.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,119
78,998
2,392
Hey guys ive been browsing this forum for a while now and I have learned a large amount.
Today I made my first working d3d9 endscene hook for windows 10 and using the guide that Broihon sent me https://www.directxtutorial.com/default.aspx and a combination of Fleep's d3d menu tutorial I was able to render a filled rectangle.

https://i.imgur.com/NEi70tg.png

I would like to know how much now does hooking opengl differ? I have looked up ways they do it on google but it seems quite different someone said something about opengl not using scene functions the way d3d uses it ?
I am not asking to be spoonfed but what I am asking how they differ and examples of ways you might of done it with different opengl games you have hacked. Thanks as always.
The openGL equivalents of EndScene are glFinish() or glFlush() and glSwapBuffers(). I have only been using glSwapBuffers, and in fact I do all my hack stuff in this hook when possible.
OpenGL has several major versions from 1.0 up to 4.5. Differences being that in 1.0 immediate mode was the method of drawing while anything past 1.0 I believe has immediate mode deprecated but still usable. What you will be hooking and how it works will rely on the implementation that the game was developed with. I was just helping out FloppyWhale with this today actually

This is 100% copy and pastable stuff from my hack, I am using MS Detours 3.0 cuz I'm a boss like that. And credits to GrandMaster Spock for passing down the knowledge

T = Template Function, O = Original Function, H = Hooked Function

C++:
//Typedef the function prototype straight from MSDN
typedef BOOL(__stdcall * twglSwapBuffers) (_In_ HDC hDc);

//Create instance of function
twglSwapBuffers owglSwapBuffers;
 
//Execution will get detoured to this:
BOOL __stdcall hwglSwapBuffers(_In_ HDC hDc)
{
 
//Put your hack stuff in here
//example from assault cube:
DWORD* localPlayerAddress = (DWORD*)(0x509B74);
int * health = (int*)(*localPlayerAddress + 0xf8);
*health = 1337;



    //return execution to original function
    return owglSwapBuffers(hDc);
}
 
//Detours the OpenGL SwapBuffers function
void HookSwapBuffers()
{
    HMODULE hMod = GetModuleHandle(L"opengl32.dll");
    if (hMod)
    {
        //USe GetProcAddress to find address of wglSwapBuffers in opengl32.dll
        //wglSwapBuffers is the Windows Extention for OpenGL
        //https://msdn.microsoft.com/en-us/library/vs/alm/dd369060(v=vs.85).aspx
        owglSwapBuffers = (twglSwapBuffers)(DWORD)GetProcAddress(hMod, "wglSwapBuffers");
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID &)owglSwapBuffers, hwglSwapBuffers);
        DetourTransactionCommit();
    }
}
So after injection just call HookSwapBuffers() and it's all set. You can do your drawing in the SwapBuffers hook also if you want. You will benefit from learning openGL from the ground up by following tutorials to create your own openGL applications.
 
  • Like
Reactions: koobo22

blergmasta

Newbie
Full Member
Feb 28, 2016
6
52
0
Thank you for the well thought out explanation.
I have never seen or heard of this ms 3.0 detour thing, I hooked my d3d9 manually but I will check it out.
Could I just load up opengl.dll and look for the glSwapBuffers in the vtable and detour it from there? or do you recommend this ms detour?
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,119
78,998
2,392
Thank you for the well thought out explanation.
I have never seen or heard of this ms 3.0 detour thing, I hooked my d3d9 manually but I will check it out.
Could I just load up opengl.dll and look for the glSwapBuffers in the vtable and detour it from there? or do you recommend this ms detour?
Nah just hook it like you hook anything else, I've just never taken the time to write a hooking function :foreveralone:
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods