- May 5, 2020
- 55
- 838
- 0
- Game Name
- Assault Cube
- Anticheat
- N/A
- Tutorial Link
- https://guidedhacking.com/threads/opengl-hooking-drawing-text-rendering-tutorial.14460/
- How long you been coding/hacking?
- ~3 months hacking / 2 years programming
- Coding Language
- C++
I'm surprised this question hasn't been asked already here, and if it has, I haven't been able to find it.
For Assault Cube, there've been a couple ways I've thought of to get window dimensions:
Use cheat engine find static address of window resolution (pretty easy):
ac_client.exe + 0x110C94 (width)
ac_client.exe + 0x110C98 (height)
Since you can't resize the AC window by dragging it, the only way I'd imagine to change the window size/resolution is whatever function is called when you apply a change to your video settings.
The reason I want this is because I want to be able to change my screen size and for the ESP/Drawn shit to scale accordingly when using glOrtho (however infrequently that might happen).
Since Assault Cube uses SDL, I tried figuring out a way to get a handle to the current window (probably SDL_GetWindowFromID, but no idea where to get that ID from. Has anyone done this?)
After I couldn't figure that out, I decided to go with WINAPI.
The way I unsuccessfully decided to go about it is with EnumWindows + this EnumWindows callback function, which EnumWindows takes as a parameter:
However, all of the RECT's member variables are 0 for some reason, which I know because I'm printing out the values from current_screen.
I found some posts that use EnumWindows, namely this one: Video Tutorial - CSGO Direct3D9 EndScene Hook & D3D9 ESP Tutorial Series
They seem to be using it to get the process ID though.
Actually I'm dumb and I left the window_handle assignment outside of the AssaultCube name check. However, a new problem has cropped up:
My GetWindowRect function is throwing a error 1400 which is an Invalid Handle Error.
I wanted to attach a copy of my project but somehow it's 102MB.
For Assault Cube, there've been a couple ways I've thought of to get window dimensions:
Use cheat engine find static address of window resolution (pretty easy):
ac_client.exe + 0x110C94 (width)
ac_client.exe + 0x110C98 (height)
Since you can't resize the AC window by dragging it, the only way I'd imagine to change the window size/resolution is whatever function is called when you apply a change to your video settings.
The reason I want this is because I want to be able to change my screen size and for the ESP/Drawn shit to scale accordingly when using glOrtho (however infrequently that might happen).
Since Assault Cube uses SDL, I tried figuring out a way to get a handle to the current window (probably SDL_GetWindowFromID, but no idea where to get that ID from. Has anyone done this?)
After I couldn't figure that out, I decided to go with WINAPI.
The way I unsuccessfully decided to go about it is with EnumWindows + this EnumWindows callback function, which EnumWindows takes as a parameter:
C++:
// this is called in the hack thread
EnumWindows(enumWindowCallback, NULL); // gets AC window handle
// this code shamelessly copied and modified from StackOverflow
// https://stackoverflow.com/a/51731567
static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM lparam) {
int length = GetWindowTextLength(hWnd);
wchar_t* buffer = new wchar_t[length + 1];
GetWindowText(hWnd, (LPWSTR)buffer, length + 1);
wchar_t* windowTitle = buffer;
if (windowTitle == L"AssaultCube"){
std::cout << "AC Found!" << std::endl;
}
window_handle = hWnd; // static HWND
delete[] buffer;
return TRUE;
}
// After I got the handle to the window, I called GetWindowRect in my hook:
BOOL __stdcall hkwglSwapBuffers(HDC hDc){
// save old context
game_context = wglGetCurrentContext();
if (contextCreated == false){
my_context = wglCreateContext(hDc);
wglMakeCurrent(hDc, my_context);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1920, 1080, 0.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0, 0, 0, 1.0);
contextCreated = true;
}
wglMakeCurrent(hDc, my_context);
RECT current_screen;
// GetWindowRect returns non-zero if successful
if (GetWindowRect(window_handle, ¤t_screen)){
std::cout << "GetWindowRect succeeded!" << std::endl;
std::cout << "Window Coordinates:\nTop: " << current_screen.top << "\nLeft: " << current_screen.left << std::endl;
std::cout << "Bottom: " << current_screen.bottom << "\nRight: " << current_screen.right << std::endl;
}
else{
std::cout << "GetWindowRect failed. Error Code: " << GetLastError() << std::endl;
}
Draw();
wglMakeCurrent(hDc, game_context);
return wglSwapBuffersGateway(hDc);
}
I found some posts that use EnumWindows, namely this one: Video Tutorial - CSGO Direct3D9 EndScene Hook & D3D9 ESP Tutorial Series
They seem to be using it to get the process ID though.
Actually I'm dumb and I left the window_handle assignment outside of the AssaultCube name check. However, a new problem has cropped up:
My GetWindowRect function is throwing a error 1400 which is an Invalid Handle Error.
I wanted to attach a copy of my project but somehow it's 102MB.
Last edited: