/*
D3D8 Base by uNrEaL.
2006-2007 uNrEaL
*/
#include < windows.h >
#include < detours.h >
#include < d3d8.h >
#include < d3dx8.h >
#include "base.h"
#pragma comment(lib, "d3dx8.lib")
static DWORD dwBeginScene = 0x6D9D9250;
static DWORD dwEndScene = 0x6D9D93A0;
static DWORD dwDrawIndexedPrimitive = 0x6D9D73A0;
static DWORD dwSetStreamSource = 0x6D9D6760;
static DWORD dwPresent = 0x6D9ECC50;
static DWORD dwReset = 0x6D9EE3B0;
/*
In BeginScene you would usually generate textures,
stuff like that.
*/
HRESULT WINAPI myBeginScene(LPDIRECT3DDEVICE8 pDevice)
{
_asm pushad;
// code goes here
_asm popad;
return pBeginScene(pDevice);
}
/*
In EndScene you could draw text on your screen.
You could also do this in Present.
*/
HRESULT WINAPI myEndScene(LPDIRECT3DDEVICE8 pDevice)
{
_asm pushad;
// code goes here
_asm popad;
return pEndScene(pDevice);
}
/*
In DrawIndexedPrimitive you would do your chams,
wallhack, wireframe, maphacks, stuff like that.
*/
HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE8 pDevice, D3DPRIMITIVETYPE pType, UINT nMinIndex, UINT nNumVertices, UINT nStartIndex, UINT nPrimitiveCount)
{
_asm pushad;
// code goes here
_asm popad;
return pDrawIndexedPrimitive(pDevice, pType, nMinIndex, nNumVertices, nStartIndex, nPrimitiveCount);
}
/*
In SetStreamSource you would setup your stride logging.
This would be used later in DrawIndexedPrimitive
to only cham/wallhack/wireframe/maphack certain strides.
*/
HRESULT WINAPI mySetStreamSource(LPDIRECT3DDEVICE8 pDevice, UINT nStreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT nStride)
{
_asm pushad;
// code goes here
_asm popad;
return pSetStreamSource(pDevice, nStreamNumber, pStreamData, nStride);
}
/*
In Present you can draw text, as mentioned above.
This function is called most often, so any
key events should be in this function.
*/
HRESULT WINAPI myPresent ( LPDIRECT3DDEVICE8 pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion )
{
_asm pushad;
// code goes here
_asm popad;
return pPresent( pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
}
/*
When you start drawing text on your screen,
you will need to reset the text device and such.
This is the function you would do this in.
This function MUST be hooked, otherwise if you
ALT+TAB out of game, or minimize it, or whatnot,
the device will fail, and your game will crash.
This function resets the device, so that you can continue
with no problems.
*/
HRESULT WINAPI myReset ( LPDIRECT3DDEVICE8 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
_asm pushad;
// code goes here
_asm popad;
return pReset(pDevice, pPresentationParameters);
}
BOOL WINAPI DllMain ( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
DisableThreadLibraryCalls(hDll);
if ( dwReason == DLL_PROCESS_ATTACH )
{
pBeginScene = (oBeginScene)DetourFunction((PBYTE)dwBeginScene, (PBYTE)myBeginScene);
pEndScene = (oEndScene)DetourFunction((PBYTE)dwEndScene, (PBYTE)myEndScene);
pDrawIndexedPrimitive = (oDrawIndexedPrimitive)DetourFunction((PBYTE)dwDrawIndexedPrimitive, (PBYTE)myDrawIndexedPrimitive);
pSetStreamSource = (oSetStreamSource)DetourFunction((PBYTE)dwSetStreamSource, (PBYTE)mySetStreamSource);
pPresent = (oPresent)DetourFunction((PBYTE)dwPresent, (PBYTE)myPresent);
pReset = (oReset)DetourFunction((PBYTE)dwReset, (PBYTE)myReset);
}
return TRUE;
}