- #include <windows.h>
- #include <stdio.h>
- #include <fstream>
- #include "cDetours.h"
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- /******************************************************************************/
- #define HOOK(func,addy) o##func = (t##func)CreateDetour((DWORD)hk##func,(DWORD)addy,Detour_Type_0xB8,7)//Quick Hook using CreateDetour *********
- #define UNHOOK(func,addy) o##func = (t##func)CreateDetour((DWORD)o##func,(DWORD)addy,Detour_Type_0xB8,7)//Quick Unook using CreateDetour *********
- /********************************************************************************/
- typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
- tEndScene oEndScene = NULL;
- typedef HRESULT (WINAPI* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
- tDrawIndexedPrimitive oDrawIndexedPrimitive = NULL;
- typedef HRESULT(WINAPI* tReset)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
- tReset oReset = NULL;
- /********************************************************************************/
- LPDIRECT3DDEVICE9 npDevice;
- LPD3DXLINE g_pLine = NULL;
- D3DVIEWPORT9 g_ViewPort;
- LPDIRECT3DVERTEXBUFFER9 Stream_Data;
- UINT Offset = 0;
- UINT Stride = 0;
- bool WallHack = true;
- bool chams = true;
- int m_stride;
- LPDIRECT3DDEVICE9 g_pDevice = 0;
- int b = 0;
- LPDIRECT3DTEXTURE9 g_Blue = NULL;
- const BYTE Blue [60] =
- {
- 0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
- };
- LPDIRECT3DTEXTURE9 g_Oren = NULL;
- const BYTE oren[ 58 ] = {
- 0x42, 0x4D, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0xFF, 0x00
- };
- LPDIRECT3DTEXTURE9 g_Muda = NULL;
- const BYTE muda[60] =
- {
- 0x42, 0x4D, 0x3C, 0x00,0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x36, 0x00,
- 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x01,0x00,
- 0x00, 0x00, 0x01, 0x00, 0x20, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00,
- 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00
- };
- void ReFont(LPDIRECT3DDEVICE9 pDevice)
- {
- if (g_pDevice != pDevice)
- {
- g_pDevice = pDevice;
- }
- }
- PBYTE HookVTableFunction( PDWORD* dwVTable, PBYTE dwHook, INT Index )
- {
- DWORD dwOld = 0;
- PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
- (*dwVTable)[Index] = (DWORD)dwHook;
- return pOrig;
- }
- HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
- {
- while(!npDevice) {
- npDevice = pDevice;
- }
- if(g_Oren == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&oren, sizeof(oren), &g_Oren);
- if(g_Blue == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&Blue, sizeof(Blue), &g_Blue);
- if(g_Muda == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&muda, sizeof(muda), &g_Muda);
- if(g_pLine == NULL) D3DXCreateLine(pDevice, &g_pLine);
- pDevice->GetViewport(&g_ViewPort);
- if(g_Blue == NULL) D3DXCrea[Maaf Saya Kasar]xtureFromFileInMemory(pDevice, (LPCVOID)&Blue, sizeof(Blue), &g_Blue);
- if(g_pLine != NULL){
- }
- return oEndScene(pDevice);
- }
- HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
- {
- if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
- Stream_Data->Release();
- if(WallHack)
- {
- if(m_stride==52)
- {
- DWORD dwOldZEnable;
- pDevice-> GetRenderState (D3DRS_ZENABLE, & dwOldZEnable);
- pDevice-> SetRenderState (D3DRS_ZENABLE, D3DZB_FALSE);
- oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
- }
- }
- if(chams)
- {
- if(m_stride==44)
- {
- DWORD dwOldZEnable;
- pDevice-> GetRenderState (D3DRS_ZENABLE, & dwOldZEnable);
- pDevice-> SetRenderState (D3DRS_ZENABLE, D3DZB_FALSE);
- pDevice->SetRenderState( D3DRS_FILLMODE,D3DFILL_SOLID );
- pDevice->SetTexture( 0, g_Oren);
- oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
- pDevice-> SetRenderState (D3DRS_ZENABLE, dwOldZEnable);
- }
- }
- return oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
- }
- HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
- {
- if( g_pLine )
- g_pLine->OnLostDevice();
- HRESULT iReturnValue = oReset(pDevice, pPresentationParameters);
- if(iReturnValue == D3D_OK) {
- if( g_pLine )
- g_pLine->OnResetDevice();
- }
- HRESULT hRet = oReset(pDevice, pPresentationParameters);
- return iReturnValue;
- }
- /********************************************************************************/
- DWORD CreateDetour(DWORD dwThread,DWORD dwAdress,DWORD dwType,DWORD dwSize)
- {
- DWORD dwDetour,dwProtect,i;
- if (dwAdress&&dwThread&&dwSize>= dwSize)
- {
- dwDetour = (DWORD)VirtualAlloc(0,dwSize+dwSize,0x1000,0x40);
- if (dwDetour&&VirtualProtect((VOID*)dwAdress,dwSize,0x40,&dwProtect))
- {
- for (i=0;i<dwSize;i++)
- {
- *(BYTE*)(dwDetour+i)=*(BYTE*)(dwAdress+i);
- }
- switch (dwType)
- {
- case Detour_Type_0xE9:
- {
- *(BYTE*)(dwDetour+dwSize+0)=0xE9;
- *(DWORD*)(dwDetour+dwSize+1)=(dwAdress-dwDetour-dwSize);
- *(BYTE*)(dwAdress+0)=0xE9;
- *(DWORD*)(dwAdress+1)=(dwThread-dwAdress-dwSize);
- }
- break;
- case Detour_Type_0xB8:
- {
- *(BYTE*)(dwDetour+dwSize+0)=0xB8;
- *(DWORD*)(dwDetour+dwSize+1)=(dwAdress+dwSize);
- *(WORD*)(dwDetour+dwSize+5)=0xE0FF;
- *(BYTE*)(dwAdress+0)=0xB8;
- *(DWORD*)(dwAdress+1)=(dwThread);
- *(WORD*)(dwAdress+5)=0xE0FF;
- }
- break;
- case Detour_Type_0x68:
- {
- *(BYTE*)(dwDetour+dwSize+0)=0x68;
- *(DWORD*)(dwDetour+dwSize+1)=(dwAdress+dwSize);
- *(WORD*)(dwDetour+dwSize+5)=0xC3;
- *(BYTE*)(dwAdress+0)=0x68;
- *(DWORD*)(dwAdress+1)=(dwThread);
- *(WORD*)(dwAdress+5)=0xC3;
- }
- break;
- }
- VirtualProtect((VOID*)dwAdress,dwSize,dwProtect,&dwProtect);
- VirtualProtect((VOID*)dwDetour,dwSize+dwSize,0x20,&dwProtect);
- return dwDetour;
- }
- }
- Sleep(15);
- return (0);
- }
- //------------------------- [ Hook in Here ]-------------------------//
- BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
- {
- if(dwReason == DLL_PROCESS_ATTACH){
- Beep(100,1000);
- CreateThread(0, 0, LoopFunction, 0, 0, 0);
- }
- return TRUE;
- }