Solved How do you get the dimensions for your window?

Hexui Undetected CSGO Cheats PUBG Accounts

SuperNewbie

i wanna be your friend
Fleep Tier Donator
Dank Tier Donator
Nobleman
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:

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, &current_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);
}
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.
 
Last edited:

obdr

Meme Tier VIP
Sep 22, 2019
179
5,478
18
You have a hooked wglSwapBuffers, so you can get the window handle through the 'hdc' parameter:
Get Window From HDC:
HWND hWnd = WindowFromDC(hdc);
WindowFromDC: WindowFromDC function (winuser.h) - Win32 apps

Now that you have the handle, you want to use GetClientRect rather than GetWindowRect. The window rect includes the title bar, while the client rect is just the game window:
C++:
//Get Window Rect
RECT window_rect = {};
GetClientRect(hWnd, &window_rect);

//window width and height
LONG window_w = window_rect.right - window_rect.left;
LONG window_h = window_rect.bottom - window_rect.top;
I've gone back to Assault Cube yesterday, I think I might have some goods to share soon, stay alert.
 

SuperNewbie

i wanna be your friend
Fleep Tier Donator
Dank Tier Donator
Nobleman
May 5, 2020
55
838
0
You have a hooked wglSwapBuffers, so you can get the window handle through the 'hdc' parameter:
Get Window From HDC:
HWND hWnd = WindowFromDC(hdc);
WindowFromDC: WindowFromDC function (winuser.h) - Win32 apps

Now that you have the handle, you want to use GetClientRect rather than GetWindowRect. The window rect includes the title bar, while the client rect is just the game window:
C++:
//Get Window Rect
RECT window_rect = {};
GetClientRect(hWnd, &window_rect);

//window width and height
LONG window_w = window_rect.right - window_rect.left;
LONG window_h = window_rect.bottom - window_rect.top;
I've gone back to Assault Cube yesterday, I think I might have some goods to share soon, stay alert.
Wow, this works beautifully. Thanks bunches.
 
  • Like
Reactions: obdr

Rake

I'm not your friend
Administrator
Jan 21, 2014
13,058
79,068
2,472
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).
my openGL ESP video teaches you how to do this, not sure if you saw it yet

But the other method is even better, taught in esp1z1's d3d video series, where you WorldToScreen the foot and the head
 
  • Like
Reactions: SuperNewbie

Similar threads

Community Mods