Суть проблемы такова->инжект проходит а отрисовки вх нету,посмотрите где ошибка в коде.
Сам код
Скрытый текст
#include "Headers.h"
#include "Hook.h"
#include "Menu.h"
#include "Texture.h"
CHAR *OnOff [] = { "[Off]", "[On]" };
CHAR *Folder[] = { "[+]", "[-]" };
//Menu
CHAR MenuTitle [ MAX_PATH ] = { "Menu" };
CHAR Timestruct[ MAX_PATH ] = { "hh':'mm':'ss tt" };
CHAR TimeString[ MAX_PATH ];
BOOL BFont = FALSE;
INT Variable[ MAX_PATH ];
INT VFolder[ MAX_PATH ];
//Примитивы
typedef HRESULT(WINAPI* oDrawIndexedPrimitive) (LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT PrimitiveCount);
oDrawIndexedPrimitive pDrawIndexedPrimitive;
HRESULT WINAPI Reset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS *pPresentationParameters )
{
PFont->OnLostDevice();
HRESULT hTorna = OReset( pDevice, pPresentationParameters );
if( SUCCEEDED( hTorna ) )
PFont->OnResetDevice();
return hTorna;
}
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;
}
// Замена текстур
void SetModelColor(LPDIRECT3DDEVICE9 pDevice, float r, float g, float b, float a, float glowr, float glowg, float glowb, float glowa)
{
float lightValues[4] = { r, g, b, a };
float glowValues[4] = { glowr, glowg, glowb, glowa };
pDevice->SetPixelShaderConstantF(1, lightValues, 1);
pDevice->SetPixelShaderConstantF(3, glowValues, 1);
}
UINT Stride;
LPDIRECT3DVERTEXBUFFER9 StreamData;
UINT OffsetInBytes;
LPDIRECT3DTEXTURE9 chams_bcolor;
bool GenOne = 0;
HRESULT WINAPI Present( LPDIRECT3DDEVICE9 pDevice, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion )
{
if (GenOne == 0)
{
//Цвета
GenerateTexture(pDevice, &chams_bcolor, D3DCOLOR_ARGB(255, 255, 0, 0)); //red
GenOne = 1;
}
if( PFont )
{
PFont->Release();
PFont = NULL;
BFont = FALSE;
}
if( !BFont )
{
D3DXCreateFont( pDevice, 14, 0, 400, 1, 0, 1, 0, 4, 0 | (0<<4), "Arial", &PFont );
BFont = TRUE;
}
if( GetAsyncKeyState( VK_INSERT ) &1 )
menu.ShowMenu =! menu.ShowMenu;
if( menu.ShowMenu && PFont )
{
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
GetTimeFormat( 0, 0, 0, 0, Timestruct, 15 );
DrawBox( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ] - 22, 162, 20, TBlack, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ] - 22, 162, 20, 1, Green, pDevice );
WriteText( menu.matrixPos[ 0 ] , menu.matrixPos[ 1 ] - 20, Yellow, MenuTitle );
sprintf_s( TimeString, "%s", Timestruct );
WriteText( menu.matrixPos[ 0 ] + 100, menu.matrixPos[ 1 ] - 20, Yellow, TimeString );
DrawBox( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ], 162, ( ( menu.Current * 15 ) - 5 ), TBlack, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ], 162, ( ( menu.Current * 15 ) - 5 ), 1, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, ( ( menu.matrixPos[ 2 ] + 2 ) + ( menu.MenuSelection * 15 ) ), 162, 13, 1, Cyan, pDevice );
menu.Current = 1;
if( GetAsyncKeyState( VK_UP ) &1 )
menu.MenuSelection--;
if(GetAsyncKeyState( VK_DOWN ) &1 )
menu.MenuSelection++;
Additem( "[Folder 1]", 1, VFolder[ 0 ], 1, Folder );
if( VFolder[ 0 ] )
{
Additem( "Item 0", 1, Variable[ 0 ], 0, OnOff );
Additem( "Item 1", 1, Variable[ 1 ], 0, OnOff );
Additem( "Item 2", 1, Variable[ 2 ], 0, OnOff );
Additem( "Item 3", 1, Variable[ 3 ], 0, OnOff );
}
if( menu.MenuSelection >= menu.Current )
menu.MenuSelection = 1;
else if( menu.MenuSelection <= 0 )
menu.MenuSelection = ( menu.Current - 1 );
}
if( Variable[ 0 ] )
CrossHair( pDevice, Red );
if( Variable[ 1 ] )
{
POINT vec2Cursor;
GetCursorPos( &vec2Cursor );
menu.matrixPos[ 0 ] = vec2Cursor.x;
menu.matrixPos[ 1 ] = vec2Cursor.y;
menu.matrixPos[ 2 ] = ( vec2Cursor.y - 10 );
}
return OPresent( pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
}
HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT PrimitiveCount)
{
if (pDevice->GetStreamSource(0, &StreamData, &OffsetInBytes, &Stride) == D3D_OK)
{
StreamData->Release();
}
if (Variable[0] == 1)
if
//Stride 8 numvert 8 prim 10
((NumVertices == 8 && PrimitiveCount == 10 && Stride == 8))
/*((NumVertices == 763 && PrimitiveCount == 1020 && Stride == 64))*/
{
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_NEVER);
pDevice->SetTexture(0, chams_bcolor);
SetModelColor(pDevice, 200.0f, 165.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
pDevice->SetTexture(0, chams_bcolor);
SetModelColor(pDevice, 255.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
}
return pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, PrimitiveCount);
}
DWORD WINAPI Hook( LPVOID lpArgs )
{
HMODULE D3D9 = 0;
while( !D3D9 )
{
Sleep( 100 );
D3D9 = GetModuleHandle( "d3d9.dll" );
}
DWORD VTable[ 5 ] = { 0 };
CreateDevice( VTable );
pDrawIndexedPrimitive = (oDrawIndexedPrimitive)DetourFunction((PBYTE)VTable[0], (PBYTE)myDrawIndexedPrimitive);
OReset = (TReset)DetourFunction( (PBYTE)VTable[ 0 ], (PBYTE)&Reset );
OPresent = (TPresent)DetourFunction( (PBYTE)VTable[1], (PBYTE)&Present );
return FALSE;
}
BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
UNREFERENCED_PARAMETER( hModule );
if( dwReason == DLL_PROCESS_ATTACH )
{
DisableThreadLibraryCalls( hModule );
CreateThread( 0, 0, &Hook, 0, 0, 0 );
}
return TRUE;
}
#include "Hook.h"
#include "Menu.h"
#include "Texture.h"
CHAR *OnOff [] = { "[Off]", "[On]" };
CHAR *Folder[] = { "[+]", "[-]" };
//Menu
CHAR MenuTitle [ MAX_PATH ] = { "Menu" };
CHAR Timestruct[ MAX_PATH ] = { "hh':'mm':'ss tt" };
CHAR TimeString[ MAX_PATH ];
BOOL BFont = FALSE;
INT Variable[ MAX_PATH ];
INT VFolder[ MAX_PATH ];
//Примитивы
typedef HRESULT(WINAPI* oDrawIndexedPrimitive) (LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT PrimitiveCount);
oDrawIndexedPrimitive pDrawIndexedPrimitive;
HRESULT WINAPI Reset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS *pPresentationParameters )
{
PFont->OnLostDevice();
HRESULT hTorna = OReset( pDevice, pPresentationParameters );
if( SUCCEEDED( hTorna ) )
PFont->OnResetDevice();
return hTorna;
}
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;
}
// Замена текстур
void SetModelColor(LPDIRECT3DDEVICE9 pDevice, float r, float g, float b, float a, float glowr, float glowg, float glowb, float glowa)
{
float lightValues[4] = { r, g, b, a };
float glowValues[4] = { glowr, glowg, glowb, glowa };
pDevice->SetPixelShaderConstantF(1, lightValues, 1);
pDevice->SetPixelShaderConstantF(3, glowValues, 1);
}
UINT Stride;
LPDIRECT3DVERTEXBUFFER9 StreamData;
UINT OffsetInBytes;
LPDIRECT3DTEXTURE9 chams_bcolor;
bool GenOne = 0;
HRESULT WINAPI Present( LPDIRECT3DDEVICE9 pDevice, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion )
{
if (GenOne == 0)
{
//Цвета
GenerateTexture(pDevice, &chams_bcolor, D3DCOLOR_ARGB(255, 255, 0, 0)); //red
GenOne = 1;
}
if( PFont )
{
PFont->Release();
PFont = NULL;
BFont = FALSE;
}
if( !BFont )
{
D3DXCreateFont( pDevice, 14, 0, 400, 1, 0, 1, 0, 4, 0 | (0<<4), "Arial", &PFont );
BFont = TRUE;
}
if( GetAsyncKeyState( VK_INSERT ) &1 )
menu.ShowMenu =! menu.ShowMenu;
if( menu.ShowMenu && PFont )
{
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
GetTimeFormat( 0, 0, 0, 0, Timestruct, 15 );
DrawBox( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ] - 22, 162, 20, TBlack, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ] - 22, 162, 20, 1, Green, pDevice );
WriteText( menu.matrixPos[ 0 ] , menu.matrixPos[ 1 ] - 20, Yellow, MenuTitle );
sprintf_s( TimeString, "%s", Timestruct );
WriteText( menu.matrixPos[ 0 ] + 100, menu.matrixPos[ 1 ] - 20, Yellow, TimeString );
DrawBox( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ], 162, ( ( menu.Current * 15 ) - 5 ), TBlack, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, menu.matrixPos[ 1 ], 162, ( ( menu.Current * 15 ) - 5 ), 1, Green, pDevice );
DrawBorder( menu.matrixPos[ 0 ] - 10, ( ( menu.matrixPos[ 2 ] + 2 ) + ( menu.MenuSelection * 15 ) ), 162, 13, 1, Cyan, pDevice );
menu.Current = 1;
if( GetAsyncKeyState( VK_UP ) &1 )
menu.MenuSelection--;
if(GetAsyncKeyState( VK_DOWN ) &1 )
menu.MenuSelection++;
Additem( "[Folder 1]", 1, VFolder[ 0 ], 1, Folder );
if( VFolder[ 0 ] )
{
Additem( "Item 0", 1, Variable[ 0 ], 0, OnOff );
Additem( "Item 1", 1, Variable[ 1 ], 0, OnOff );
Additem( "Item 2", 1, Variable[ 2 ], 0, OnOff );
Additem( "Item 3", 1, Variable[ 3 ], 0, OnOff );
}
if( menu.MenuSelection >= menu.Current )
menu.MenuSelection = 1;
else if( menu.MenuSelection <= 0 )
menu.MenuSelection = ( menu.Current - 1 );
}
if( Variable[ 0 ] )
CrossHair( pDevice, Red );
if( Variable[ 1 ] )
{
POINT vec2Cursor;
GetCursorPos( &vec2Cursor );
menu.matrixPos[ 0 ] = vec2Cursor.x;
menu.matrixPos[ 1 ] = vec2Cursor.y;
menu.matrixPos[ 2 ] = ( vec2Cursor.y - 10 );
}
return OPresent( pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
}
HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT PrimitiveCount)
{
if (pDevice->GetStreamSource(0, &StreamData, &OffsetInBytes, &Stride) == D3D_OK)
{
StreamData->Release();
}
if (Variable[0] == 1)
if
//Stride 8 numvert 8 prim 10
((NumVertices == 8 && PrimitiveCount == 10 && Stride == 8))
/*((NumVertices == 763 && PrimitiveCount == 1020 && Stride == 64))*/
{
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_NEVER);
pDevice->SetTexture(0, chams_bcolor);
SetModelColor(pDevice, 200.0f, 165.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
pDevice->SetTexture(0, chams_bcolor);
SetModelColor(pDevice, 255.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
}
return pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, PrimitiveCount);
}
DWORD WINAPI Hook( LPVOID lpArgs )
{
HMODULE D3D9 = 0;
while( !D3D9 )
{
Sleep( 100 );
D3D9 = GetModuleHandle( "d3d9.dll" );
}
DWORD VTable[ 5 ] = { 0 };
CreateDevice( VTable );
pDrawIndexedPrimitive = (oDrawIndexedPrimitive)DetourFunction((PBYTE)VTable[0], (PBYTE)myDrawIndexedPrimitive);
OReset = (TReset)DetourFunction( (PBYTE)VTable[ 0 ], (PBYTE)&Reset );
OPresent = (TPresent)DetourFunction( (PBYTE)VTable[1], (PBYTE)&Present );
return FALSE;
}
BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
UNREFERENCED_PARAMETER( hModule );
if( dwReason == DLL_PROCESS_ATTACH )
{
DisableThreadLibraryCalls( hModule );
CreateThread( 0, 0, &Hook, 0, 0, 0 );
}
return TRUE;
}