Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to draw pixels on a hooked game

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
marco0999
Cheater
Reputation: 0

Joined: 28 Jun 2020
Posts: 29
Location: Italy

PostPosted: Wed Jun 08, 2022 6:19 am    Post subject: How to draw pixels on a hooked game Reply with quote

Hi,

I have succefully hooked a game and I need to do read and write with GetPixel and SetPixel to the game window.

To do a test I have created this code:

Here my hooked function:

Code:
My_hooked_function(int a3)
{

    HWND hWnd = GetForegroundWindow();

    if (hWnd == NULL)
         hWnd = GetDesktopWindow();

    if (a3==49)
    {

        string buf;
        LF::Log_Update("Button Pressed");
       
        SetWindowLongA(hWnd, GWL_WNDPROC, (LONG_PTR)&WndProc);
        // SetWindowSubclass(hWnd, &WndProc, 1, 0);
        //DefSubclassProc
        // DrawPixels(hWnd);
    }
}



here my test function to draw something in the game (that is a old 32 bit that required directx 11):

Code:
void DrawPixels(HWND hwnd) {

    PAINTSTRUCT ps;
    RECT r;

    LF::Log_Update("DrawPixels Entrato");

    GetClientRect(hwnd, &r);

    if (r.bottom == 0) {

        return;
    }

    HDC hdc = BeginPaint(hwnd, &ps);

    for (int i = 0; i < 1000; i++) {

        int x = rand() % r.right;
        int y = rand() % r.bottom;
        SetPixel(hdc, x, y, RGB(0, 0, 0));

        for (int i = 1; i <= 4; i++)
        {
            SetPixel(hdc, x - i, y, RGB(0, 0, 0));
            SetPixel(hdc, x + -i, y, RGB(0, 0, 0));

            SetPixel(hdc, x, y + i, RGB(0, 0, 0));
            SetPixel(hdc, x, y - i, RGB(0, 0, 0));
        }

    }

    EndPaint(hwnd, &ps);

}



and here the window procedure callback:

Code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
    WPARAM wParam, LPARAM lParam) {

    LF::Log_Update("Enter here");

    DrawPixels(hwnd);

    switch (msg) {

    case WM_PAINT:

        LF::Log_Update("For some reason not enter here");

        DrawPixels(hwnd);

        break;

    case WM_DESTROY:

        PostQuitMessage(0);
        return 0;
    }


return DefWindowProcW(hwnd, msg, wParam, lParam);
}


In my code I have 2 problems:

1) I need to attach and not replace the window procedure (SetWindowLongA is not right in this case) because the game must continue to work. I need only to paint some line to the game existing window.

2) I have tested the function "DrawPixels" to an empty c++ windows project and If I put it in the "WM_PAINT" message of the WndProc work perfectly but not in the game.

I searching for a way to draw some pixel on a external DirectX 11 game.

Can you help me please ?

Thanks !
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Wed Jun 08, 2022 7:34 pm    Post subject: Reply with quote

You shouldn't really be using GDI/GDI+ to try and draw on the window like that, if the goal is to render things over the game, you'd be better off doing an overlay if you want to go the GDI route.

If you need to render into the game (ie. into the 3D space and such), then you should instead hook the actual engine or the rendering system being used (Direct3D, OpenGL, etc.) and use the appropriate calls from within that context to draw your stuff.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
marco0999
Cheater
Reputation: 0

Joined: 28 Jun 2020
Posts: 29
Location: Italy

PostPosted: Thu Jun 09, 2022 12:01 am    Post subject: Reply with quote

atom0s wrote:
You shouldn't really be using GDI/GDI+ to try and draw on the window like that, if the goal is to render things over the game, you'd be better off doing an overlay if you want to go the GDI route.

If you need to render into the game (ie. into the 3D space and such), then you should instead hook the actual engine or the rendering system being used (Direct3D, OpenGL, etc.) and use the appropriate calls from within that context to draw your stuff.


Thank you atom0s for your reponse:

I like to create a highlight menu selected item:

http://www.pro-software.it/bzbackground2.png

this because actually the menu is accessible directly only with numeric keys (without any highlight ) but I like to access with arrow keys and for this reason I need to create a sort of "selected menu".

I have not decided yet how do it, I can change the inside background color and / or change the text color.

For do this what is the best way to start ?

Many Thanks !!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites