Code:
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#define PI 3.14159265//Defining what PI is. PI is a Circle
//int CenterX = GetSystemMetrics( 0 ) / 2-1;//Gets screen X resolution then cutting it in half to get the center.
//int CenterY = GetSystemMetrics( 1 ) / 2-1;//Gets screen Y resolution then cutting it in half to get the center.
LPDIRECT3DDEVICE9 pDevice;
ID3DXLine *pLine;
#define RED D3DCOLOR_ARGB(255, 255, 0, 0)
#define GREEN D3DCOLOR_ARGB(255, 0, 255, 0)
#define BLUE D3DCOLOR_ARGB(255, 0, 0, 255)
#define WHITE D3DCOLOR_ARGB(255, 255, 255, 255)
#define BLACK D3DCOLOR_ARGB(255, 0, 0, 0)
#define YELLOW D3DCOLOR_ARGB(255, 255, 255, 0)
#define TEAL D3DCOLOR_ARGB(255, 0, 255, 255)
#define PINK D3DCOLOR_ARGB(255, 255, 240, 0)
#define ORANGE D3DCOLOR_ARGB(255, 255, 132, 0)
#define LIME D3DCOLOR_ARGB(255, 198, 255, 0)
#define SKYBLUE D3DCOLOR_ARGB(255, 0, 180, 255)
#define MAROON D3DCOLOR_ARGB(255, 142, 30, 0)
#define LGRAY D3DCOLOR_ARGB(255, 174, 174, 174)
#define DGRAY D3DCOLOR_ARGB(255, 71, 65, 64)
#define BROWN D3DCOLOR_ARGB(255, 77, 46, 38)
#define SHIT D3DCOLOR_ARGB(255, 74, 38, 38)
#define PURPLE D3DCOLOR_ARGB(255, 125, 000, 255)
#define mauxam D3DCOLOR_ARGB(255,245,245,220)
typedef HRESULT (WINAPI* pEndScene)(LPDIRECT3DDEVICE9);
pEndScene oEndScene = NULL;
HRESULT WINAPI MyEndScene(LPDIRECT3DDEVICE9);
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
DWORD* Direct3D_VMTable = NULL;
bool ClossHair = true;
HMODULE D3D9;
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pDev;
D3DVIEWPORT9 Viewport;
LRESULT CALLBACK MsgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnd, uMsg, wParam, lParam);}
VOID WINAPI MYHOOK( VOID )
{
WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L, GetModuleHandle(NULL),NULL,NULL,NULL,NULL,"DX",NULL};
RegisterClassEx(&wc);
HWND hWnd = CreateWindow("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL);
while( D3D9 == NULL )
{
D3D9 = GetModuleHandleA( "d3d9.dll" );
Sleep( 100 );
}
D3DPRESENT_PARAMETERS D3D_PP = {0};
IDirect3D9 * (WINAPI *oDirect3DCreate9)(UINT SDKVersion);
*(PDWORD)&oDirect3DCreate9 = (DWORD)GetProcAddress( D3D9, "Direct3DCreate9" );
pD3D = oDirect3DCreate9( D3D_SDK_VERSION );
D3D_PP.Windowed = TRUE;
D3D_PP.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3D_PP.BackBufferFormat = D3DFMT_UNKNOWN;
pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3D_PP, &pDev );
Direct3D_VMTable = *(DWORD**)pDev;
{
oEndScene = (pEndScene) DetourFunc((BYTE*)Direct3D_VMTable[42], (BYTE*) MyEndScene, 5);
}
Sleep( 400 );
pDev->Release( );
pD3D->Release( );
DestroyWindow(hWnd);
}
void FillRGB( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice )
{
D3DRECT rec = { x, y, x + w, y + h };
pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
}
HRESULT WINAPI MyEndScene (LPDIRECT3DDEVICE9 pDev)
{
if(ClossHair)
{
pDev->GetViewport( &Viewport );
DWORD CenterX = (Viewport.Width / 2);
DWORD CenterY = (Viewport.Height / 2);
FillRGB(CenterX-20, CenterY, 40, 1,PURPLE,pDev);//Purple
FillRGB(CenterX, CenterY-20, 1, 40,PURPLE,pDev);
FillRGB(CenterX-17, CenterY, 34, 1,BLUE,pDev);//Blue
FillRGB(CenterX, CenterY-17, 1, 34,BLUE,pDev);
FillRGB(CenterX-14, CenterY, 28, 1,BROWN,pDev);//Cyan
FillRGB(CenterX, CenterY-14, 1, 28,BROWN,pDev);
FillRGB(CenterX-11, CenterY, 22, 1,GREEN,pDev);//Green
FillRGB(CenterX, CenterY-11, 1, 22,GREEN,pDev);
FillRGB(CenterX-9, CenterY, 18, 1,YELLOW,pDev);//Yellow
FillRGB(CenterX, CenterY-9, 1, 18,YELLOW,pDev);
FillRGB(CenterX-6, CenterY, 12, 1,ORANGE,pDev);//Orange
FillRGB(CenterX, CenterY-6, 1, 12,ORANGE,pDev);
FillRGB(CenterX-3, CenterY, 6, 1,RED,pDev);//Red
FillRGB(CenterX, CenterY-3, 1, 6,RED,pDev);
}
return oEndScene(pDev);
}
BOOL WINAPI DllMain( HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved )
{
if( dwReason == DLL_PROCESS_ATTACH )
{
CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)MYHOOK, NULL, NULL, NULL);
MessageBox(NULL,"Succeed!","CrossHair Test",NULL);
}
return TRUE;
}
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}