lundi 17 mars 2014

[Help] DirectX drawing problem... topic




Hey guys, I am actually trying to write an ESP for CS:GO.
The problem about it is that, when I use my DirectX code with a window which is NOT extended into client area with margins = {-1, -1, -1, -1}, it works, I can draw lines and shit like that.
When I use DwmExtendFrameIntoClientArea( ) & move the window over the CS:GO window and try to draw a simple line from 0/0 to 600/600 for example, the whole screen turns into the color designated for the line.

CBaseEntity returns correct values and all functions are working correctly (WorldToScreen etc). Well, except for the DirectX code...

here's the source:

Main.cpp

Code:


#include <Windows.h>
#include <dwmapi.h>
#include <math.h>
#include <algorithm>
#pragma comment( lib, "dwmapi.lib" )

#include "CProcess.h"
CProcess gProcess;
RECT m_Rect;

#include "Vector.h"
#include "CBaseEntity.h"

#include "CEsp.h"
CEsp pEsp;

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

int APIENTRY WinMain( HINSTANCE hThis, HINSTANCE hPrev, LPSTR lpCmdLine, int iCmdShow )
{
        gProcess.Init( "Counter-Strike: Global Offensive" );
        WNDCLASSEX wc = { sizeof( WNDCLASSEX ), 0, WndProc, 0, 0, hThis,
                LoadIcon( 0, IDI_APPLICATION ), LoadCursor( 0, IDC_ARROW ), 0, 0, "ZClass001", LoadIcon( 0, IDI_APPLICATION ) };
        if( !RegisterClassEx( &wc ) )
                MessageBox( 0, "Error reg Class", "", MB_OK );

        MARGINS margins = { -1, -1, -1, -1 };
        HWND hWnd = CreateWindowEx( WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT, "ZClass001", "DirectX",
                WS_POPUP, 0, 0, 1, 1, 0, 0, hThis, 0 );
        SetLayeredWindowAttributes( hWnd, RGB( 0, 0, 0 ), 255, LWA_COLORKEY );
        DwmExtendFrameIntoClientArea( hWnd, &margins );
        ShowWindow( hWnd, iCmdShow );
        GetWindowRect( FindWindow( 0, "Counter-Strike: Global Offensive" ), &m_Rect );

        pEsp.Init( hWnd );
       
        HWND hCSGO;
        RECT rc;

        MSG msg;
        while( 1 )
        {
                if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
                {
                        if( msg.message == WM_QUIT )
                                break;

                        TranslateMessage( &msg );
                        DispatchMessage( &msg );
                }

                hCSGO = FindWindow( 0, "Counter-Strike: Global Offensive" );
                if( !hCSGO )
                        break;
                GetWindowRect( hCSGO, &rc );
                MoveWindow( hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE );

                pEsp.DrawEsp( );

                Sleep( 10 );
        }
        pEsp.Cleanup( );

        return 0;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
        switch( uMsg )
        {
        case WM_DESTROY:
                {
                        PostQuitMessage( 0 );
                        return 0;
                } break;
        case WM_PAINT:
                {
                        PAINTSTRUCT ps;
                        HDC hDC = BeginPaint( hWnd, &ps );
                        EndPaint( hWnd, &ps );
                } break;
        }
        return DefWindowProc( hWnd, uMsg, wParam, lParam );
}


CEsp.h

Code:


#pragma once
#pragma warning( disable: 4244 )
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment( lib, "d3d9.lib" )
#pragma comment( lib, "d3dx9.lib" )

class CEsp
{
public:
        VOID DrawEsp( )
        {
                dx_Device->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 );
                dx_Device->BeginScene( );

                pMe.ReadInformation( );
                for( int i = 0; i < 32; i++ )
                {
                        pEntityList[i].ReadInformation( i );

                        if( pEntityList[i].m_iHealth < 2 )
                                continue;

                        D3DCOLOR dColor = D3DCOLOR_XRGB( 0, 255, 0 );
                       
                        Vector vScreen;
                        if( WorldToScreen( pEntityList[i].m_vecOrigin, vScreen ) )
                        {
                                DrawSnapline( vScreen.X, vScreen.Y, dColor );
                        }
                }

                dx_Device->EndScene( );
                dx_Device->PresentEx( 0, 0, 0, 0, 0 );
        }

        VOID Init( HWND hWnd )
        {
                if(FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &dx_Object)))
                        MessageBox( 0, "Unable to create dxObject", "", MB_OK );

                dx_Params.BackBufferFormat    = D3DFMT_A8R8G8B8;
                dx_Params.hDeviceWindow        = hWnd;
                dx_Params.MultiSampleQuality  = D3DMULTISAMPLE_NONE;
                dx_Params.SwapEffect          = D3DSWAPEFFECT_DISCARD;
                dx_Params.Windowed            = true;

                if(FAILED(dx_Object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_Params, NULL, &dx_Device)))
                        MessageBox( 0, "Unable to create dxDevice", "", MB_OK );

                D3DXCreateLine( dx_Device, &dx_Line );
                dx_Line->SetAntialias( false );
                dx_Line->SetPattern( 0xffffffff );

                D3DXCreateFont( dx_Device, 12, 0, 0, 0, 0, 0, 0, 0, 0, "Arial", &dx_Font );

                m_hWnd = hWnd;
        }
        VOID Cleanup( )
        {
                dx_Line->Release( );
                dx_Font->Release( );
                dx_Device->Release( );
                dx_Object->Release( );
        }
private:
        IDirect3D9Ex* dx_Object;
        IDirect3DDevice9Ex* dx_Device;
        D3DPRESENT_PARAMETERS dx_Params;
        ID3DXLine* dx_Line;
        ID3DXFont* dx_Font;
        HWND m_hWnd;

        VOID DrawBox( float fX0, float fY0, float fX1, float fY1, D3DCOLOR dColor, float fThickness = 1.0f )
        {
                POINT p1 = { fX0, fY0 };
                POINT p2 = { fX1, fY0 };
                POINT p3 = { fX0, fY1 };
                POINT p4 = { fX1, fY1 };

                DrawLine( p1.x, p1.y, p3.x, p3.y, dColor, fThickness );
                DrawLine( p3.x, p3.y, p4.x, p4.y, dColor, fThickness );
                DrawLine( p4.x, p4.y, p2.x, p2.y, dColor, fThickness );
                DrawLine( p2.x, p2.y, p1.x, p1.y, dColor, fThickness );
        }
        VOID DrawLine( float fX0, float fY0, float fX1, float fY1, D3DCOLOR dColor, float fThickness = 1.0f )
        {
                dx_Line->SetWidth( fThickness );
                D3DXVECTOR2 pVec[2];
                pVec[0].x = fX0;
                pVec[0].y = fY0;
                pVec[1].x = fX1;
                pVec[1].y = fY1;

                dx_Line->Draw( pVec, 2, dColor );
        }
        VOID DrawSnapline( float fX, float fY, D3DCOLOR dColor, float fThickness = 1.0f )
        {
                RECT rc;
                GetClientRect( m_hWnd, &rc );

                DrawLine( (float)(rc.right / 2), (float)rc.bottom, fX, fY, dColor, fThickness );
        }
        VOID DrawString( float fX, float fY, char* pszString, D3DCOLOR dColor )
        {
                RECT rc = { fX, fY, fX+120.0f, fY + 13.0f };
                dx_Font->DrawTextA( 0, pszString, -1, &rc, DT_NOCLIP, dColor );
        }
};
extern CEsp pEsp;







Aucun commentaire:

Enregistrer un commentaire