PHP Code:
//=====================================================================================
#define _CRT_SECURE_NO_WARNINGS
// Roverturbo | www.uc-forum.com
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
#define D3D_RELEASE(D3D_PTR) if( D3D_PTR ){ D3D_PTR->Release(); D3D_PTR = NULL; }
#define D3DXGetPixel( Pixel, scx, scy, BITSPERPIXEL, pBits, pitch ) \
Pixel = ( PBYTE )( ( DWORD ) pBits + ( ( scy * pitch ) \
+ ( scx * ( BITSPERPIXEL / 8 ) ) ) );
#define GETA(rgb) ((BYTE)((rgb)>>24))
#define GETR(rgb) ((BYTE)((rgb)>>16))
#define GETG(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
#define GETB(rgb) ((BYTE)(rgb))
#define Opfor ((OpforAssualt || OpforGunnermen || OpforSniper || Opfortje))
#define OpforAssualt (Stride == 32 && (NumVertices == 3124 && PrimitiveCount == 4132) || (NumVertices == 1970 && PrimitiveCount == 2186) || (NumVertices == 1252 && PrimitiveCount == 1160) || (NumVertices == 470 && PrimitiveCount == 352))
#define OpforGunnermen (Stride == 32 && (NumVertices == 2715 && PrimitiveCount == 3588) || (NumVertices == 1620 && PrimitiveCount == 1886) || (NumVertices == 943 && PrimitiveCount == 908) || (NumVertices == 441 && PrimitiveCount == 308))
#define OpforSniper (Stride == 32 && (NumVertices == 250 && PrimitiveCount == 304) || (NumVertices == 2818 && PrimitiveCount == 3672) || (NumVertices == 150 && PrimitiveCount == 142) || (NumVertices == 1715 && PrimitiveCount == 1950) || (NumVertices == 1101 && PrimitiveCount == 1066) || (NumVertices == 481 && PrimitiveCount == 350)) || (Stride == 32 && (NumVertices == 2816 && PrimitiveCount == 3642) || (NumVertices == 1773 && PrimitiveCount == 2022) || (NumVertices == 1150 && PrimitiveCount == 1086) || (NumVertices == 435 && PrimitiveCount == 320))
#define Opfortje (Stride == 32 && (NumVertices == 3531 && PrimitiveCount == 4526) || (NumVertices == 2188 && PrimitiveCount == 2386) || (NumVertices == 1325 && PrimitiveCount == 1194) || (NumVertices == 499 && PrimitiveCount == 352))
#define Marines ((MarinesAssault || MarinesGunnremen || MarinesSniper || Marines1 || Marines2))
#define MarinesAssault (Stride == 32 && (NumVertices == 2613 && PrimitiveCount == 3248) || (NumVertices == 1842 && PrimitiveCount == 1978) || (NumVertices == 1144 && PrimitiveCount == 814) || (NumVertices == 1034 && PrimitiveCount == 904) || (NumVertices == 447 && PrimitiveCount == 312))
#define MarinesGunnremen (Stride == 32 && (NumVertices == 3597 && PrimitiveCount == 4280) || (NumVertices == 2301 && PrimitiveCount == 2364) || (NumVertices == 1341 && PrimitiveCount == 1132) || (NumVertices == 580 && PrimitiveCount == 380))
#define MarinesSniper (Stride == 32 && (NumVertices == 2516 && PrimitiveCount == 2940) || (NumVertices == 681 && PrimitiveCount == 588) || (NumVertices == 106 && PrimitiveCount == 114) || (NumVertices == 1726 && PrimitiveCount == 1760) || (NumVertices == 1020 && PrimitiveCount == 872) || (NumVertices == 587 && PrimitiveCount == 370))
#define Marines1 (Stride == 32 && (NumVertices == 689 && PrimitiveCount == 1172) || (NumVertices == 367 && PrimitiveCount == 298) || (NumVertices == 4050 && PrimitiveCount == 4486) || (NumVertices == 308 && PrimitiveCount == 212) || (NumVertices == 2540 && PrimitiveCount == 2444) || (NumVertices == 628 && PrimitiveCount == 670) || (NumVertices == 1488 && PrimitiveCount == 1114) || (NumVertices == 105 && PrimitiveCount == 74) || (NumVertices == 592 && PrimitiveCount == 374))
#define Marines2 (Stride == 32 && (NumVertices == 3790 && PrimitiveCount == 4078) || (NumVertices == 2784 && PrimitiveCount == 2384) || (NumVertices == 1572 && PrimitiveCount == 1166) || (NumVertices == 634 && PrimitiveCount == 372) || (NumVertices == 233 && PrimitiveCount == 330))
#define Spetz ((SpetzAssualt || SpetzGunnermen || SpetzSniper || Spetz1 || Spetz2))
#define SpetzAssualt (Stride == 32 && (NumVertices == 4358 && PrimitiveCount == 4864) || (NumVertices == 3278 && PrimitiveCount == 3188) || (NumVertices == 503 && PrimitiveCount == 704) || (NumVertices == 1633 && PrimitiveCount == 1332) || (NumVertices == 840 && PrimitiveCount == 618) || (NumVertices == 783 && PrimitiveCount == 1168))
#define SpetzGunnermen (Stride == 32 && (NumVertices == 4270 && PrimitiveCount == 4804) || (NumVertices == 2755 && PrimitiveCount == 2494) || (NumVertices == 1317 && PrimitiveCount == 1054) || (NumVertices == 809 && PrimitiveCount == 590))
#define SpetzSniper (Stride == 32 && (NumVertices == 726 && PrimitiveCount == 556) || (NumVertices == 1315 && PrimitiveCount == 1170) || (NumVertices == 2140 && PrimitiveCount == 2310) || (NumVertices == 3326 && PrimitiveCount == 4336) || (NumVertices == 2578 && PrimitiveCount == 2192) || (NumVertices == 482 && PrimitiveCount == 476) || (NumVertices == 3254 && PrimitiveCount == 4122) || (NumVertices == 1730 && PrimitiveCount == 1938) || (NumVertices == 398 && PrimitiveCount == 410) || (NumVertices == 327 && PrimitiveCount == 500) || (NumVertices == 2388 && PrimitiveCount == 2040) || (NumVertices == 222 && PrimitiveCount == 298) || (NumVertices == 1111 && PrimitiveCount == 986) || (NumVertices == 1186 && PrimitiveCount == 1184) || (NumVertices == 339 && PrimitiveCount == 248) || (NumVertices == 994 && PrimitiveCount == 714))
#define Spetz1 (Stride == 32 && (NumVertices == 4242 && PrimitiveCount == 5028) || (NumVertices == 2391 && PrimitiveCount == 2488) || (NumVertices == 1689 && PrimitiveCount == 1422) || (NumVertices == 384 && PrimitiveCount == 250) || (NumVertices == 969 && PrimitiveCount == 708))
#define Spetz2 (Stride == 32 && (NumVertices == 793 && PrimitiveCount == 834) || (NumVertices == 3891 && PrimitiveCount == 4598) || (NumVertices == 592 && PrimitiveCount == 532) || (NumVertices == 2510 && PrimitiveCount == 2470) || (NumVertices == 171 && PrimitiveCount == 114) || (NumVertices == 1398 && PrimitiveCount == 1176) || (NumVertices == 384 && PrimitiveCount == 250) || (NumVertices == 384 && PrimitiveCount == 250) || (NumVertices == 994 && PrimitiveCount == 714) || (NumVertices == 529 && PrimitiveCount == 540) || (NumVertices == 353 && PrimitiveCount == 346))
#define SAS ((SASAssualt || SASGunnermen || SASSniper || SAS1 || SAS2))
#define SASAssualt (Stride == 32 && (NumVertices == 447 && PrimitiveCount == 312) || (NumVertices == 1034 && PrimitiveCount == 904) || (NumVertices == 1842 && PrimitiveCount == 1978) || (NumVertices == 2613 && PrimitiveCount == 3248) || (NumVertices == 1001 && PrimitiveCount == 964) || (NumVertices == 3935 && PrimitiveCount == 5226) || (NumVertices == 960 && PrimitiveCount == 1072) || (NumVertices == 2640 && PrimitiveCount == 3070) || (NumVertices == 212 && PrimitiveCount == 288) || (NumVertices == 214 && PrimitiveCount == 202) || (NumVertices == 1373 && PrimitiveCount == 1256) || (NumVertices == 585 && PrimitiveCount == 440))
#define SASGunnermen (Stride == 32 && (NumVertices == 193 && PrimitiveCount == 140) || (NumVertices == 580 && PrimitiveCount == 380) || (NumVertices == 1341 && PrimitiveCount == 1132) || (NumVertices == 802 && PrimitiveCount == 800) || (NumVertices == 2301 && PrimitiveCount == 2364) || (NumVertices == 275 && PrimitiveCount == 322) || (NumVertices == 3597 && PrimitiveCount == 4280) || (NumVertices == 3716 && PrimitiveCount == 5064) || (NumVertices == 2578 && PrimitiveCount == 2994) || (NumVertices == 1412 && PrimitiveCount == 1330) || (NumVertices == 568 && PrimitiveCount == 470))
#define SASSniper (Stride == 32 && (NumVertices == 1615 && PrimitiveCount == 1706) || (NumVertices == 541 && PrimitiveCount == 366) || (NumVertices == 3667 && PrimitiveCount == 4952) || (NumVertices == 2460 && PrimitiveCount == 2882) || (NumVertices == 1479 && PrimitiveCount == 1402) || (NumVertices == 552 && PrimitiveCount == 452))
#define SAS1 (Stride == 32 && (NumVertices == 634 && PrimitiveCount == 372) || (NumVertices == 1572 && PrimitiveCount == 1166) || (NumVertices == 2784 && PrimitiveCount == 2384) || (NumVertices == 3790 && PrimitiveCount == 4078) || (NumVertices == 3585 && PrimitiveCount == 4858) || (NumVertices == 1498 && PrimitiveCount == 1304) || (NumVertices == 2525 && PrimitiveCount == 3022) || (NumVertices == 695 && PrimitiveCount == 478))
#define SAS2 (Stride == 32 && (NumVertices == 689 && PrimitiveCount == 1172) || (NumVertices == 367 && PrimitiveCount == 298) || (NumVertices == 4050 && PrimitiveCount == 4486) || (NumVertices == 308 && PrimitiveCount == 212) || (NumVertices == 2540 && PrimitiveCount == 2444) || (NumVertices == 628 && PrimitiveCount == 670) || (NumVertices == 1488 && PrimitiveCount == 1114) || (NumVertices == 105 && PrimitiveCount == 74) || (NumVertices == 592 && PrimitiveCount == 374) || (NumVertices == 3562 && PrimitiveCount == 4784) || (NumVertices == 2509 && PrimitiveCount == 2954) || (NumVertices == 1402 && PrimitiveCount == 1164) || (NumVertices == 628 && PrimitiveCount == 450))
#define snow ( Stride == 20 )
#define Smoke ((NumVertices == 16384))
#define sky ((Stride == 44) && (NumVertices == 20 && PrimitiveCount == 10) || (NumVertices == 12 && PrimitiveCount == 12) || (PrimitiveCount >= 20 && PrimitiveCount <= 30 && NumVertices == 50) || (PrimitiveCount >= 20 && PrimitiveCount <= 30 && PrimitiveCount == 37) || (PrimitiveCount >= 20 && PrimitiveCount <= 30 && PrimitiveCount == 32) || (PrimitiveCount >= 20 && PrimitiveCount <= 30 && PrimitiveCount == 41))
//=====================================================================================
typedef HRESULT (WINAPI* CreateDevice_Prototype) (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
typedef HRESULT (WINAPI* Reset_Prototype) (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
typedef HRESULT (WINAPI* EndScene_Prototype) (LPDIRECT3DDEVICE9);
typedef HRESULT (WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
CreateDevice_Prototype CreateDevice_Pointer = NULL;
Reset_Prototype Reset_Pointer = NULL;
EndScene_Prototype EndScene_Pointer = NULL;
DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;
HRESULT WINAPI Direct3DCreate9_VMTable (VOID);
HRESULT WINAPI CreateDevice_Detour (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
HRESULT WINAPI Reset_Detour (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
HRESULT WINAPI EndScene_Detour (LPDIRECT3DDEVICE9);
HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
void WINAPI Aimbot( void );
HRESULT GenerateTexture( IDirect3DDevice9 *pD3Ddev,
IDirect3DTexture9 **ppD3Dtex, DWORD colour32 );
HRESULT CreateMyShader(IDirect3DPixelShader9 **Shader_Name, IDirect3DDevice9 *Device, int red, int green, int blue, int alpha );
VOID WINAPI Scanner( LPBYTE Bits, int pitch, DWORD ScanWidth, DWORD ScanHeight );
DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID);
struct MyColor
{
BYTE A,R,G,B;
};
struct Entities
{
DWORD X;
DWORD Y;
};
PDWORD Direct3D_VMTable = NULL;
LPDIRECT3DDEVICE9 pDevice;
LPDIRECT3DSURFACE9 pRenderSurf = NULL;
LPDIRECT3DSURFACE9 oDStencilSurface = NULL;
LPDIRECT3DSURFACE9 oSurface = NULL;
LPDIRECT3DTEXTURE9 tBlue = NULL;
BOOL bFrameReady = FALSE;
BOOL bDrawn = FALSE;
LPDIRECT3DPIXELSHADER9 Color[MAX_PATH];
LPDIRECT3DPIXELSHADER9 Color2 = NULL;
BOOL InitShaders = FALSE;
int Color_Ctr = 0;
MyColor Colors = {0x0};
Entities Ents[255];
int iNumOfColors = 0;
BYTE Init = 0x0;
DWORD Box_Size = 10;
D3DVIEWPORT9 pView;
//=====================================================================================
BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinstModule);
if(Direct3DCreate9_VMTable() == D3D_OK)
return TRUE;
}
return FALSE;
}
//=====================================================================================
HRESULT WINAPI Direct3DCreate9_VMTable(VOID)
{
LPDIRECT3D9 Direct3D_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(Direct3D_Object == NULL)
return D3DERR_INVALIDCALL;
Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
Direct3D_Object->Release();
DWORD dwProtect;
if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
{
*(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[16];
*(PDWORD)&Direct3D_VMTable[16] = (DWORD)CreateDevice_Detour;
if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
return D3DERR_INVALIDCALL;
}
else
return D3DERR_INVALIDCALL;
return D3D_OK;
}
//=====================================================================================
HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D9 Direct3D_Object, UINT Adapter, D3DDEVTYPE DeviceType, HWND FocusWindow,
DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* PresentationParameters,
LPDIRECT3DDEVICE9* Returned_Device_Interface)
{
HRESULT Returned_Result = CreateDevice_Pointer(Direct3D_Object, Adapter, DeviceType, FocusWindow, BehaviorFlags,
PresentationParameters, Returned_Device_Interface);
DWORD dwProtect;
if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
{
*(PDWORD)&Direct3D_VMTable[16] = *(PDWORD)&CreateDevice_Pointer;
CreateDevice_Pointer = NULL;
if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
return D3DERR_INVALIDCALL;
}
else
return D3DERR_INVALIDCALL;
if(Returned_Result == D3D_OK)
{
Direct3D_VMTable = (PDWORD)*(PDWORD)*Returned_Device_Interface;
*(PDWORD)&Reset_Pointer = (DWORD)Direct3D_VMTable[16];
*(PDWORD)&EndScene_Pointer = (DWORD)Direct3D_VMTable[42];
*(PDWORD)&DrawIndexedPrimitive_Pointer = (DWORD)Direct3D_VMTable[82];
if(CreateThread(NULL, 0, VirtualMethodTableRepatchingLoopToCounterExtensionRepatching, NULL, 0, NULL) == NULL)
return D3DERR_INVALIDCALL;
}
return Returned_Result;
}
//=====================================================================================
HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRESENT_PARAMETERS* PresentationParameters)
{
if( tBlue != NULL )
D3D_RELEASE( tBlue )
if( InitShaders == TRUE )
{
for( int i = 0;i < 255;i++ )
D3D_RELEASE( Color[i] )
InitShaders = FALSE;
}
return Reset_Pointer(Device_Interface, PresentationParameters);
}
//=====================================================================================
HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE9 Device_Interface)
{
Device_Interface->GetViewport( &pView );
if( Init == 0x0 )
{
pDevice = Device_Interface;
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Aimbot, NULL, 0, NULL);
Init = 0x1;
}
if( bDrawn == TRUE )
bFrameReady = TRUE;
if( tBlue == NULL )
GenerateTexture( Device_Interface, &tBlue,
D3DCOLOR_ARGB( 255, 0, 0, 255 ) );
if( InitShaders == FALSE )
{
for( int i = 0;i < 255;i++ )
CreateMyShader( &Color[i], Device_Interface, 20, 20, 255, i + 1 );
InitShaders = TRUE;
}
if( bDrawn == TRUE )
{
for( int i = 0; i < iNumOfColors; i++ )
{
DWORD Exp_x = Ents[i].X;
DWORD Exp_y = Ents[i].Y;
D3DRECT HBOX;
HBOX.x1 = Exp_x - Box_Size;
HBOX.y1 = Exp_y - Box_Size;
HBOX.x2 = Exp_x + Box_Size;
HBOX.y2 = Exp_y - (Box_Size - 1);
Device_Interface->Clear( 1, &HBOX, D3DCLEAR_TARGET,
D3DCOLOR_ARGB( 255, 20, 128, 255 ), 0, 0 );
HBOX.x1 = Exp_x - Box_Size;
HBOX.y1 = Exp_y + (Box_Size - 1);
HBOX.x2 = Exp_x + Box_Size;
HBOX.y2 = Exp_y + Box_Size;
Device_Interface->Clear( 1, &HBOX, D3DCLEAR_TARGET,
D3DCOLOR_ARGB( 255, 20, 128, 255 ), 0, 0 );
HBOX.x1 = Exp_x - Box_Size;
HBOX.y1 = Exp_y - Box_Size;
HBOX.x2 = Exp_x - (Box_Size - 1);
HBOX.y2 = Exp_y + Box_Size;
Device_Interface->Clear( 1, &HBOX, D3DCLEAR_TARGET,
D3DCOLOR_ARGB( 255, 20, 128, 255 ), 0, 0 );
HBOX.x1 = Exp_x + (Box_Size - 1);
HBOX.y1 = Exp_y - Box_Size;
HBOX.x2 = Exp_x + Box_Size;
HBOX.y2 = Exp_y + Box_Size;
Device_Interface->Clear( 1, &HBOX, D3DCLEAR_TARGET,
D3DCOLOR_ARGB( 255, 20, 128, 255 ), 0, 0 );
}
}
return EndScene_Pointer(Device_Interface);
}
//=====================================================================================
HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRIMITIVETYPE Type, INT BaseIndex,
UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
{
LPDIRECT3DVERTEXBUFFER9 Stream_Data;
UINT Offset = 0;
UINT Stride = 0;
LPDIRECT3DPIXELSHADER9 pShade = NULL;
D3DSURFACE_DESC Desc;
DWORD IsInGame;
if(Device_Interface->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
Stream_Data->Release();
IsInGame = *(PDWORD)0x0074E35C;
if( Opfor || Marines || Spetz || SAS )
{
if( bFrameReady == FALSE && IsInGame )
{
Device_Interface->GetPixelShader( &pShade );
Device_Interface->GetRenderTarget( 0, &oSurface );
oSurface->GetDesc( &Desc );
if( Desc.Width == pView.Width && Desc.Height == pView.Height )
{
Device_Interface->SetRenderTarget( 0, pRenderSurf );
Device_Interface->SetPixelShader( Color[Color_Ctr] );
Device_Interface->SetRenderState( D3DRS_ZENABLE, FALSE );
DrawIndexedPrimitive_Pointer( Device_Interface, Type, BaseIndex,
MinIndex, NumVertices, StartIndex, PrimitiveCount );
Device_Interface->SetRenderState( D3DRS_ZENABLE, TRUE );
DrawIndexedPrimitive_Pointer( Device_Interface, Type, BaseIndex,
MinIndex, NumVertices, StartIndex, PrimitiveCount );
Device_Interface->SetRenderTarget( 0, oSurface );
Device_Interface->SetPixelShader( pShade );
bDrawn = TRUE;
if( Color_Ctr < 255 )
Color_Ctr++;
}
D3D_RELEASE( oSurface );
D3D_RELEASE( pShade );
}
Device_Interface->SetRenderState( D3DRS_ZENABLE, FALSE );
Device_Interface->SetTexture( 0, tBlue );
DrawIndexedPrimitive_Pointer(Device_Interface,
Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
Device_Interface->SetRenderState( D3DRS_ZENABLE, TRUE );
return DrawIndexedPrimitive_Pointer(Device_Interface,
Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
return DrawIndexedPrimitive_Pointer(Device_Interface, Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
//=====================================================================================
DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID Param)
{
UNREFERENCED_PARAMETER(Param);
while(1)
{
Sleep(100);
*(PDWORD)&Direct3D_VMTable[16] = (DWORD)Reset_Detour;
*(PDWORD)&Direct3D_VMTable[42] = (DWORD)EndScene_Detour;
*(PDWORD)&Direct3D_VMTable[82] = (DWORD)DrawIndexedPrimitive_Detour;
}
return 1;
}
//=====================================================================================
void WINAPI Aimbot( void )
{
LPDIRECT3DSURFACE9 pSurf = NULL;
D3DLOCKED_RECT lRect;
D3DVIEWPORT9 Viewport;
PBYTE pBits = NULL;
int BITSPERPIXEL = 32;
PBYTE Pixel;
pDevice->GetViewport( &Viewport );
pDevice->CreateOffscreenPlainSurface( UINT(Viewport.Width), UINT(Viewport.Height),
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pSurf, NULL );
pDevice->CreateRenderTarget( UINT(Viewport.Width), UINT(Viewport.Height),
D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &pRenderSurf, NULL );
while( 1 )
{
if( pDevice != NULL && bFrameReady == TRUE )
{
pDevice->GetViewport( &Viewport );
pDevice->GetRenderTargetData( pRenderSurf, pSurf );
if( pSurf->LockRect( &lRect, NULL,
D3DLOCK_NOSYSLOCK | D3DLOCK_DONOTWAIT ) == S_OK )
{
Scanner( ( LPBYTE ) lRect.pBits, lRect.Pitch,
Viewport.Width, Viewport.Height );
pSurf->UnlockRect();
}
if( pRenderSurf->LockRect( &lRect, NULL,
D3DLOCK_NOSYSLOCK | D3DLOCK_DONOTWAIT ) == S_OK )
{
for( DWORD scy = 1L; scy < Viewport.Height; scy++ )
{
for( DWORD scx = 1L; scx < Viewport.Width; scx++ )
{
Pixel = ( PBYTE ) lRect.pBits;
Pixel += ( ( scy * lRect.Pitch )
+ ( scx * ( BITSPERPIXEL / 8 ) ) );
Pixel[3] = 0x00;
Pixel[2] = 0x00;
Pixel[1] = 0x00;
Pixel[0] = 0x00;
}
}
pRenderSurf->UnlockRect();
}
Color_Ctr = 0;
bFrameReady = FALSE;
bDrawn = FALSE;
}
Sleep( 10 );
}
}
//=====================================================================================
HRESULT GenerateTexture( IDirect3DDevice9 *pD3Ddev,
IDirect3DTexture9 **ppD3Dtex, DWORD colour32 )
{
if( FAILED( pD3Ddev->CreateTexture( 8, 8, 1, 0,
D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL ) ) )
return E_FAIL;
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);
D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;
for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;
(*ppD3Dtex)->UnlockRect(0);
return S_OK;
}
HRESULT CreateMyShader(IDirect3DPixelShader9 **Shader_Name, IDirect3DDevice9 *Device, int red, int green, int blue, int alpha )
{
ID3DXBuffer *MyBuffer = NULL;
char MyShader[ 256 ];
sprintf( MyShader, "ps_3_0\ndef c0, %f, %f, %f, %f\nmov oC0, c0", (float)red/(float)255, (float)green/(float)255, (float)blue/(float)255, (float)alpha/(float)255 );
D3DXAssembleShader( MyShader, sizeof( MyShader ), NULL, NULL, 0, &MyBuffer , NULL );
if( FAILED( Device->CreatePixelShader((const DWORD*)MyBuffer ->GetBufferPointer(), Shader_Name)) )return E_FAIL;
return S_OK;
}
VOID WINAPI GetColor( MyColor * pCol )
{
if( pCol->R < 0xFF )
pCol->R++;
if( pCol->R >= 0xFF )
{
pCol->G++;
pCol->R = 0x0;
}
if( pCol->G >= 0xFF )
{
pCol->B++;
pCol->R = 0x0;
pCol->G = 0x0;
}
if( pCol->B >= 0xFF )
{
pCol->B = 0x0;
pCol->R = 0x0;
pCol->G = 0x0;
}
}
VOID WINAPI Scanner( LPBYTE Bits, int pitch, DWORD ScanWidth, DWORD ScanHeight )
{
DWORD BITSPERPIXEL = 32; // ARGB 32Bits/Pixel
PBYTE Pixel;
iNumOfColors = 0;
Colors.R = 0x7F;
Colors.G = 0x00;
Colors.B = 0x00;
int nPosx;
int nPosy;
int lPosx;
int lPosy;
BOOL FirstPixel;
iNumOfColors = Color_Ctr;
for( int i = 0; i < Color_Ctr; i++ )
{
GetColor( &Colors );
nPosx = 0;
nPosy = 0;
FirstPixel = FALSE;
Ents[i].X = 0;
Ents[i].Y = 0;
for( DWORD scy = 1L; scy < ScanHeight; scy++ )
{
for( DWORD scx = 1L; scx < ScanWidth; scx++ )
{
Pixel = ( PBYTE ) Bits;
Pixel += ( ( scy * pitch )
+ ( scx * ( BITSPERPIXEL / 8 ) ) );
if( *(PDWORD)Pixel != NULL )
{
if( Pixel[3] == i + 1 )
{
Pixel[3] = 0xFF;
Pixel[2] = Colors.R;
Pixel[1] = Colors.G;
Pixel[0] = Colors.B;
if( FirstPixel == FALSE )
{
nPosx = scx;
nPosy = scy;
FirstPixel = TRUE;
}
else
{
lPosx = scx;
lPosy = scy;
}
}
}
}
}
Ents[i].X = (nPosx + lPosx) / 2;
Ents[i].Y = (nPosy + lPosy) / 2;
}
}
Bookmarks