- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
来到这还没发过贴子~~战地2142 战地2 去烟雾上色透视源码,很简单的东西,不会的看看吧
dll语言 C++,编译环境 vc6.0
注入随便~~
#include <d3d9.h>
#include <d3dx9.h>
#include <cstdio>
#pragma comment (lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
DWORD dwVTable[1] = {0};
IDirect3DPixelShader9 *Front,
*Back;
bool Chams = 0;
bool Call = 1;
BOOL WallHack=0;
HRESULT CreateMyShader(IDirect3DPixelShader9 **pShader, IDirect3DDevice9 *Device, float red, float green, float blue, float alpha )
{
ID3DXBuffer *MyBuffer = NULL;
char MyShader[ 256 ];
sprintf( MyShader, "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", red/255, green/255, blue/255, alpha/255 );
D3DXAssembleShader( MyShader, sizeof( MyShader ), NULL, NULL, 0, &MyBuffer , NULL );
if( FAILED( Device->CreatePixelShader((const DWORD*)MyBuffer ->GetBufferPointer(), pShader)) )return E_FAIL;
return S_OK;
}
void *DetourFunction(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);
}
DWORD WINAPI dwWaitThread( LPVOID lpArgs );
typedef HRESULT(WINAPI* DIP_)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount);
DIP_ pDIP;
HRESULT WINAPI DIP(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex,UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
{
IDirect3DVertexBuffer9* pStreamData = NULL;
UINT iOffsetInBytes,iStride;
pDevice->GetStreamSource(0,&pStreamData,&iOffsetInBytes,&iStride);
pDevice->SetRenderState(D3DRS_LIGHTING, false);
pDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_ARGB(255,255,255,255));
pDevice->SetRenderState(D3DRS_FOGENABLE ,false);
if(Call)
{
CreateMyShader( &Front, pDevice,255,255,0,255);
CreateMyShader( &Back, pDevice,0,255,255,255 );
Call = 0;
}
if (iStride==52&&WallHack==1)
{
DWORD dwOldZEnable;
pDevice->GetRenderState(D3DRS_ZENABLE,&dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_FALSE);
pDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_NEVER);
pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pDIP(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE,dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL);
}
if (iStride==52&&Chams==1)
{
DWORD dwOldZEnable;
pDevice->SetTexture(0,NULL);
pDevice->SetPixelShader( Front );
pDevice->GetRenderState(D3DRS_ZENABLE,&dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_FALSE);
pDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_NEVER);
pDIP(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE,dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL);
pDevice->SetPixelShader( Back );
}
return pDIP(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
void InitDevice( DWORD * dwVTable )
{
LPDIRECT3D9 pD3d9 = NULL;
LPDIRECT3DDEVICE9 pD3DDevice = NULL;
pD3d9 = Direct3DCreate9( D3D_SDK_VERSION );
if ( pD3d9 == NULL )
{
MessageBox( NULL, "[ERROR] Direct3DCreate9 失败", " Error", MB_ICONERROR | MB_ICONSTOP );
return;
}
D3DPRESENT_PARAMETERS pPresentParms;
ZeroMemory( &pPresentParms, sizeof( pPresentParms ));
pPresentParms.Windowed = TRUE;
pPresentParms.BackBufferFormat = D3DFMT_UNKNOWN;
pPresentParms.SwapEffect = D3DSWAPEFFECT_DISCARD;
if ( FAILED ( pD3d9->CreateDevice ( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pPresentParms, &pD3DDevice )))
{
MessageBox( NULL, "[ERROR] CreateDevice Failed", "Fatal Error", MB_ICONERROR | MB_ICONSTOP );
return;
}
DWORD * dwTable = ( DWORD* ) pD3DDevice;
dwTable = ( DWORD* ) dwTable[0];
dwVTable[0] = dwTable[82];
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
if ( dwReason == DLL_PROCESS_ATTACH )
{
CreateThread( NULL, NULL, &dwWaitThread, NULL, NULL, NULL );
}
return TRUE;
}
DWORD WINAPI dwWaitThread( LPVOID lpArgs )
{
DWORD dwD3d9 = NULL;
while ( !dwD3d9 )
{
Sleep( 500 );
dwD3d9 = ( DWORD ) GetModuleHandle( "D3d9.dll" );
}
InitDevice( dwVTable );
pDIP=(DIP_) DetourFunction(( PBYTE ) dwVTable[0], ( PBYTE ) &DIP,5);
for (;;Sleep (500))
{
if (GetAsyncKeyState (VK_NUMPAD1)!=0)
{
WallHack=1;
}
if (GetAsyncKeyState (VK_NUMPAD2)!=0)
{
WallHack=0;
}
if (GetAsyncKeyState (VK_NUMPAD4)!=0)
{
Chams=1;
}
if (GetAsyncKeyState (VK_NUMPAD5)!=0)
{
Chams=0;
}
}
return FALSE;
} |
|