Direct3D9 EndScene рендеринг - PullRequest
       24

Direct3D9 EndScene рендеринг

2 голосов
/ 05 января 2012

Я подключаю игру Directx9 с помощью хуков vTable.До сих пор я был в состоянии успешно подключить и «Present» и «EndScene» (и, конечно, CreateDevice и Direct3dCreate9), однако - и здесь есть подвох - как только я попытаюсь что-то нарисовать (например, текст)), мой настоящий крючок больше не бьется.(Это может быть встроенная процедура безопасности ... Я не совсем уверен).

Например ... Следующий код работает

HRESULT APIENTRY hook_EndScene(IDirect3DDevice9* pInterface){   
    pInterface->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
    return orig_EndScene(pInterface);
}

В результате экран постоянно отображаетсябелый цвет.Однако при попытке отобразить текст (шрифт, созданный в хуке CreateDevice, используя возвращенный указатель IDirect3DDevice9 - я убедился, что для восстановления регистров используется __asm ​​pushad и popad) или спрайт, в результате хук EndScene больше не попадает вообще,

Мне интересно, есть ли какой-нибудь специальный код, необходимый для обеспечения работы крючка EndScene ... И почему я могу очистить экран, но как только я хочу отобразить на нем дополнительный контент ... ловушкабольше не работает (больше не попадает в точки останова).Текст успешно рендерится ... на долю секунды, прежде чем его заменят видео Bink ... в этом случае крючок больше не работает.

Я совершенно не понимаю ... и был бы признателен за помощьдля некоторых более опытных кодеров DirectX.Спасибо.

РЕДАКТИРОВАТЬ Вот мой хук CreateDevice на всякий случай

HRESULT APIENTRY hook_CreateDevice(IDirect3D9* pInterface, UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface){

HRESULT ret = orig_CreateDevice(pInterface, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
__asm pushad
IDirect3DDevice9* d3ddev = *ppReturnedDeviceInterface;
D3DXCreateFont(d3ddev, 30, 0, FW_NORMAL,1,  false,  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,  DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE, "Arial", &lpfont);   
//We have located the d3ddevice pointer. Now we can hook it!
DWORD* vTable = (DWORD*)*((DWORD*)d3ddev);
HookVTableFunc(vTable, (void*)&hook_EndScene, (void*)&orig_EndScene, 42);
__asm popad
return ret;

}

И хук EndScene, который не работает (полностью ломает хук):

LPD3DXFONT lpfont;
HRESULT APIENTRY hook_EndScene(IDirect3DDevice9* pInterface){


static RECT textbox; SetRect(&textbox, 0, 0, 640, 480); 
lpfont->DrawTextA(NULL, "Testing", 22, &textbox, 0, D3DCOLOR_ARGB(0,255,255,255));
return orig_EndScene(pInterface);

}

1 Ответ

1 голос
/ 15 января 2012

Это работает для меня, я думаю, проблема в том, что вы оставили альфа на 0?

Мой код перехвата генерирует эти переменные

  • fIDirect3DDevice9_EndScene Тип указателя на функцию
  • foIDirect3DDevice9_EndScene Указатель функции на оригинальную функцию
  • fhIDirect3DDevice9_EndScene Функция Указатель на замену Функция
  • vtIDirect3DDevice9_EndScene VTable родственник EndScene

Используя эту схему именования, макросы могут также автоматически генерировать остальные функции.

Фактический образец / крюк (работает для 32 и 64 бит):

LPD3DXFONT g_Font;
D3DXFONT_DESC FontDesc = {24,
                          0,
                          400,
                          0,
                          false,
                          DEFAULT_CHARSET,
                          OUT_TT_PRECIS,
                          CLIP_DEFAULT_PRECIS,
                          DEFAULT_PITCH,
                          "Arial"};

void initHook() {
    IDirect3DDevice9* pD3DDevice = .. you got this one
    hookVT(pD3DDevice, IDirect3DDevice9, EndScene);
    D3DXCreateFontIndirect(pD3DDevice, &FontDesc,&g_Font);
}

#undef METHOD
#undef INTERFACE

#define INTERFACE IDirect3DDevice9
#define METHOD EndScene
GEN_HOOK(INTERFACE FAR* This)
{   
    static RECT textbox;
    SetRect(&textbox, 5, 0, 640, 480); 
    g_Font->DrawTextA(NULL, "Testing sadsadsad asd sadas asd sad sad as das dsadas dsa dsadas dasd ", -1, &textbox, DT_CENTER, 0xffffffff);

    CALL_ORGINAL();

    return hr;
}
#undef METHOD

Я создал несколько вспомогательных функций / макросов для этой работы:

template<typename func, typename vttype> void changeVTEx(void** vt, vttype n, func target)
{
    DWORD OldProtections = 0;
    VirtualProtect(&vt[n], sizeof(LPCVOID), PAGE_EXECUTE_READWRITE, &OldProtections);
    vt[n] = (void*)target;
    VirtualProtect(&vt[n], sizeof(LPCVOID), OldProtections, &OldProtections);
}

// preprocessor tools
#define PPCAT_NX(A, B) A ## B
#define PPCAT(A, B) PPCAT_NX(A, B)

#define getVT(ptr) (*(void***)ptr)
#define changeVT(n, target) changeVTEx(getVT(This), n, target)

#define hookVT(ptr, INTERFACE, METHOD) \
{\
    PPCAT(PPCAT(PPCAT(fo, INTERFACE),_), METHOD) = (PPCAT(PPCAT(PPCAT(f, INTERFACE), _), METHOD))(getVT(ptr)[PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), METHOD)]);\
    changeVTEx(getVT(ptr), PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), METHOD), PPCAT(PPCAT(PPCAT(fh, INTERFACE),_), METHOD));\
}

#define GEN_HOOK_(TYPE, ...) \
    PPCAT(PPCAT(PPCAT(f, INTERFACE), _), METHOD) PPCAT(PPCAT(PPCAT(fo, INTERFACE),_), METHOD) = NULL;\
    TYPE STDMETHODCALLTYPE PPCAT(PPCAT(PPCAT(fh, INTERFACE),_), METHOD)(__VA_ARGS__)

#define GEN_HOOK(...) \
    GEN_HOOK_(HRESULT, __VA_ARGS__)

#define UNHOOK \
    changeVT(PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), METHOD), PPCAT(PPCAT(PPCAT(fo, INTERFACE),_), METHOD))

#define REHOOK \
    changeVT(PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), METHOD), PPCAT(PPCAT(PPCAT(fh, INTERFACE),_), METHOD))

#define CALL_ORGINAL_(RET, ...) \
    UNHOOK;\
    RET = PPCAT(This->, METHOD)(__VA_ARGS__);\
    REHOOK;

#define CALL_ORGINAL(...) \
    CALL_ORGINAL_(HRESULT hr, __VA_ARGS__)

// Create function pointer types
#undef INTERFACE
#define INTERFACE IDirect3DDevice9
#undef PURE
#define PURE
#undef THIS_
#define THIS_                   INTERFACE FAR* This,
#undef THIS
#define THIS                    INTERFACE FAR* This
#undef STDMETHOD
#define STDMETHOD(method)       typedef HRESULT (STDMETHODCALLTYPE *PPCAT(PPCAT(PPCAT(f, INTERFACE),_), method))
#undef STDMETHOD_
#define STDMETHOD_(type,method) typedef type (STDMETHODCALLTYPE *PPCAT(PPCAT(PPCAT(f, INTERFACE),_), method))

// 1:1 copy from d3d9.h:
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    STDMETHOD(TestCooperativeLevel)(THIS) PURE;
    STDMETHOD_(UINT, GetAvailableTextureMem)(THIS) PURE;
    STDMETHOD(EvictManagedResources)(THIS) PURE;
    STDMETHOD(GetDirect3D)(THIS_ IDirect3D9** ppD3D9) PURE;
    STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS9* pCaps) PURE;
    STDMETHOD(GetDisplayMode)(THIS_ UINT iSwapChain,D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(GetCreationParameters)(THIS_ D3DDEVICE_CREATION_PARAMETERS *pParameters) PURE;
    STDMETHOD(SetCursorProperties)(THIS_ UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap) PURE;
    STDMETHOD_(void, SetCursorPosition)(THIS_ int X,int Y,DWORD Flags) PURE;
    STDMETHOD_(BOOL, ShowCursor)(THIS_ BOOL bShow) PURE;
    STDMETHOD(CreateAdditionalSwapChain)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** pSwapChain) PURE;
    STDMETHOD(GetSwapChain)(THIS_ UINT iSwapChain,IDirect3DSwapChain9** pSwapChain) PURE;
    STDMETHOD_(UINT, GetNumberOfSwapChains)(THIS) PURE;
    STDMETHOD(Reset)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters) PURE;
    STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) PURE;
    STDMETHOD(GetBackBuffer)(THIS_ UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer) PURE;
    STDMETHOD(GetRasterStatus)(THIS_ UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus) PURE;
    STDMETHOD(SetDialogBoxMode)(THIS_ BOOL bEnableDialogs) PURE;
    STDMETHOD_(void, SetGammaRamp)(THIS_ UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp) PURE;
    STDMETHOD_(void, GetGammaRamp)(THIS_ UINT iSwapChain,D3DGAMMARAMP* pRamp) PURE;
    STDMETHOD(CreateTexture)(THIS_ UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateVolumeTexture)(THIS_ UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateRenderTarget)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) PURE;
    STDMETHOD(CreateDepthStencilSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) PURE;
    STDMETHOD(UpdateSurface)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) PURE;
    STDMETHOD(UpdateTexture)(THIS_ IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture) PURE;
    STDMETHOD(GetRenderTargetData)(THIS_ IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface) PURE;
    STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain,IDirect3DSurface9* pDestSurface) PURE;
    STDMETHOD(StretchRect)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter) PURE;
    STDMETHOD(ColorFill)(THIS_ IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color) PURE;
    STDMETHOD(CreateOffscreenPlainSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) PURE;
    STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget) PURE;
    STDMETHOD(GetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget) PURE;
    STDMETHOD(SetDepthStencilSurface)(THIS_ IDirect3DSurface9* pNewZStencil) PURE;
    STDMETHOD(GetDepthStencilSurface)(THIS_ IDirect3DSurface9** ppZStencilSurface) PURE;
    STDMETHOD(BeginScene)(THIS) PURE;
    STDMETHOD(EndScene)(THIS) PURE;
    STDMETHOD(Clear)(THIS_ DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil) PURE;
    STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) PURE;
    STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) PURE;
    STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE,CONST D3DMATRIX*) PURE;
    STDMETHOD(SetViewport)(THIS_ CONST D3DVIEWPORT9* pViewport) PURE;
    STDMETHOD(GetViewport)(THIS_ D3DVIEWPORT9* pViewport) PURE;
    STDMETHOD(SetMaterial)(THIS_ CONST D3DMATERIAL9* pMaterial) PURE;
    STDMETHOD(GetMaterial)(THIS_ D3DMATERIAL9* pMaterial) PURE;
    STDMETHOD(SetLight)(THIS_ DWORD Index,CONST D3DLIGHT9*) PURE;
    STDMETHOD(GetLight)(THIS_ DWORD Index,D3DLIGHT9*) PURE;
    STDMETHOD(LightEnable)(THIS_ DWORD Index,BOOL Enable) PURE;
    STDMETHOD(GetLightEnable)(THIS_ DWORD Index,BOOL* pEnable) PURE;
    STDMETHOD(SetClipPlane)(THIS_ DWORD Index,CONST float* pPlane) PURE;
    STDMETHOD(GetClipPlane)(THIS_ DWORD Index,float* pPlane) PURE;
    STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD Value) PURE;
    STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD* pValue) PURE;
    STDMETHOD(CreateStateBlock)(THIS_ D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB) PURE;
    STDMETHOD(BeginStateBlock)(THIS) PURE;
    STDMETHOD(EndStateBlock)(THIS_ IDirect3DStateBlock9** ppSB) PURE;
    STDMETHOD(SetClipStatus)(THIS_ CONST D3DCLIPSTATUS9* pClipStatus) PURE;
    STDMETHOD(GetClipStatus)(THIS_ D3DCLIPSTATUS9* pClipStatus) PURE;
    STDMETHOD(GetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9** ppTexture) PURE;
    STDMETHOD(SetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9* pTexture) PURE;
    STDMETHOD(GetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) PURE;
    STDMETHOD(SetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value) PURE;
    STDMETHOD(GetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue) PURE;
    STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value) PURE;
    STDMETHOD(ValidateDevice)(THIS_ DWORD* pNumPasses) PURE;
    STDMETHOD(SetPaletteEntries)(THIS_ UINT PaletteNumber,CONST PALETTEENTRY* pEntries) PURE;
    STDMETHOD(GetPaletteEntries)(THIS_ UINT PaletteNumber,PALETTEENTRY* pEntries) PURE;
    STDMETHOD(SetCurrentTexturePalette)(THIS_ UINT PaletteNumber) PURE;
    STDMETHOD(GetCurrentTexturePalette)(THIS_ UINT *PaletteNumber) PURE;
    STDMETHOD(SetScissorRect)(THIS_ CONST RECT* pRect) PURE;
    STDMETHOD(GetScissorRect)(THIS_ RECT* pRect) PURE;
    STDMETHOD(SetSoftwareVertexProcessing)(THIS_ BOOL bSoftware) PURE;
    STDMETHOD_(BOOL, GetSoftwareVertexProcessing)(THIS) PURE;
    STDMETHOD(SetNPatchMode)(THIS_ float nSegments) PURE;
    STDMETHOD_(float, GetNPatchMode)(THIS) PURE;
    STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount) PURE;
    STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) PURE;
    STDMETHOD(DrawPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) PURE;
    STDMETHOD(DrawIndexedPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) PURE;
    STDMETHOD(ProcessVertices)(THIS_ UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags) PURE;
    STDMETHOD(CreateVertexDeclaration)(THIS_ CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl) PURE;
    STDMETHOD(SetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9* pDecl) PURE;
    STDMETHOD(GetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9** ppDecl) PURE;
    STDMETHOD(SetFVF)(THIS_ DWORD FVF) PURE;
    STDMETHOD(GetFVF)(THIS_ DWORD* pFVF) PURE;
    STDMETHOD(CreateVertexShader)(THIS_ CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader) PURE;
    STDMETHOD(SetVertexShader)(THIS_ IDirect3DVertexShader9* pShader) PURE;
    STDMETHOD(GetVertexShader)(THIS_ IDirect3DVertexShader9** ppShader) PURE;
    STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) PURE;
    STDMETHOD(GetVertexShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount) PURE;
    STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount) PURE;
    STDMETHOD(GetVertexShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount) PURE;
    STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT  BoolCount) PURE;
    STDMETHOD(GetVertexShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount) PURE;
    STDMETHOD(SetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride) PURE;
    STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* pOffsetInBytes,UINT* pStride) PURE;
    STDMETHOD(SetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT Setting) PURE;
    STDMETHOD(GetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT* pSetting) PURE;
    STDMETHOD(SetIndices)(THIS_ IDirect3DIndexBuffer9* pIndexData) PURE;
    STDMETHOD(GetIndices)(THIS_ IDirect3DIndexBuffer9** ppIndexData) PURE;
    STDMETHOD(CreatePixelShader)(THIS_ CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader) PURE;
    STDMETHOD(SetPixelShader)(THIS_ IDirect3DPixelShader9* pShader) PURE;
    STDMETHOD(GetPixelShader)(THIS_ IDirect3DPixelShader9** ppShader) PURE;
    STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) PURE;
    STDMETHOD(GetPixelShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount) PURE;
    STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount) PURE;
    STDMETHOD(GetPixelShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount) PURE;
    STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT  BoolCount) PURE;
    STDMETHOD(GetPixelShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount) PURE;
    STDMETHOD(DrawRectPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) PURE;
    STDMETHOD(DrawTriPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) PURE;
    STDMETHOD(DeletePatch)(THIS_ UINT Handle) PURE;
    STDMETHOD(CreateQuery)(THIS_ D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery) PURE;

// Create vtable offsets
#undef STDMETHOD
#define STDMETHOD(method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method),
#undef STDMETHOD_
#define STDMETHOD_(type,method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method),

enum PPCAT(vt, INTERFACE)
{
// 1:1 copy from d3d9.h: replace (THIS* -> ""
    STDMETHOD(QueryInterface)
    STDMETHOD_(ULONG,AddRef)
    STDMETHOD_(ULONG,Release)
    STDMETHOD(TestCooperativeLevel)
    STDMETHOD_(UINT, GetAvailableTextureMem)
    STDMETHOD(EvictManagedResources)
    STDMETHOD(GetDirect3D)
    STDMETHOD(GetDeviceCaps)
    STDMETHOD(GetDisplayMode)
    STDMETHOD(GetCreationParameters)
    STDMETHOD(SetCursorProperties)
    STDMETHOD_(void, SetCursorPosition)
    STDMETHOD_(BOOL, ShowCursor)
    STDMETHOD(CreateAdditionalSwapChain)
    STDMETHOD(GetSwapChain)
    STDMETHOD_(UINT, GetNumberOfSwapChains)
    STDMETHOD(Reset)
    STDMETHOD(Present)
    STDMETHOD(GetBackBuffer)
    STDMETHOD(GetRasterStatus)
    STDMETHOD(SetDialogBoxMode)
    STDMETHOD_(void, SetGammaRamp)
    STDMETHOD_(void, GetGammaRamp)
    STDMETHOD(CreateTexture)
    STDMETHOD(CreateVolumeTexture)
    STDMETHOD(CreateCubeTexture)
    STDMETHOD(CreateVertexBuffer)
    STDMETHOD(CreateIndexBuffer)
    STDMETHOD(CreateRenderTarget)
    STDMETHOD(CreateDepthStencilSurface)
    STDMETHOD(UpdateSurface)
    STDMETHOD(UpdateTexture)
    STDMETHOD(GetRenderTargetData)
    STDMETHOD(GetFrontBufferData)
    STDMETHOD(StretchRect)
    STDMETHOD(ColorFill)
    STDMETHOD(CreateOffscreenPlainSurface)
    STDMETHOD(SetRenderTarget)
    STDMETHOD(GetRenderTarget)
    STDMETHOD(SetDepthStencilSurface)
    STDMETHOD(GetDepthStencilSurface)
    STDMETHOD(BeginScene)
    STDMETHOD(EndScene)
    STDMETHOD(Clear)
    STDMETHOD(SetTransform)
    STDMETHOD(GetTransform)
    STDMETHOD(MultiplyTransform)
    STDMETHOD(SetViewport)
    STDMETHOD(GetViewport)
    STDMETHOD(SetMaterial)
    STDMETHOD(GetMaterial)
    STDMETHOD(SetLight)
    STDMETHOD(GetLight)
    STDMETHOD(LightEnable)
    STDMETHOD(GetLightEnable)
    STDMETHOD(SetClipPlane)
    STDMETHOD(GetClipPlane)
    STDMETHOD(SetRenderState)
    STDMETHOD(GetRenderState)
    STDMETHOD(CreateStateBlock)
    STDMETHOD(BeginStateBlock)
    STDMETHOD(EndStateBlock)
    STDMETHOD(SetClipStatus)
    STDMETHOD(GetClipStatus)
    STDMETHOD(GetTexture)
    STDMETHOD(SetTexture)
    STDMETHOD(GetTextureStageState)
    STDMETHOD(SetTextureStageState)
    STDMETHOD(GetSamplerState)
    STDMETHOD(SetSamplerState)
    STDMETHOD(ValidateDevice)
    STDMETHOD(SetPaletteEntries)
    STDMETHOD(GetPaletteEntries)
    STDMETHOD(SetCurrentTexturePalette)
    STDMETHOD(GetCurrentTexturePalette)
    STDMETHOD(SetScissorRect)
    STDMETHOD(GetScissorRect)
    STDMETHOD(SetSoftwareVertexProcessing)
    STDMETHOD_(BOOL, GetSoftwareVertexProcessing)
    STDMETHOD(SetNPatchMode)
    STDMETHOD_(float, GetNPatchMode)
    STDMETHOD(DrawPrimitive)
    STDMETHOD(DrawIndexedPrimitive)
    STDMETHOD(DrawPrimitiveUP)
    STDMETHOD(DrawIndexedPrimitiveUP)
    STDMETHOD(ProcessVertices)
    STDMETHOD(CreateVertexDeclaration)
    STDMETHOD(SetVertexDeclaration)
    STDMETHOD(GetVertexDeclaration)
    STDMETHOD(SetFVF)
    STDMETHOD(GetFVF)
    STDMETHOD(CreateVertexShader)
    STDMETHOD(SetVertexShader)
    STDMETHOD(GetVertexShader)
    STDMETHOD(SetVertexShaderConstantF)
    STDMETHOD(GetVertexShaderConstantF)
    STDMETHOD(SetVertexShaderConstantI)
    STDMETHOD(GetVertexShaderConstantI)
    STDMETHOD(SetVertexShaderConstantB)
    STDMETHOD(GetVertexShaderConstantB)
    STDMETHOD(SetStreamSource)
    STDMETHOD(GetStreamSource)
    STDMETHOD(SetStreamSourceFreq)
    STDMETHOD(GetStreamSourceFreq)
    STDMETHOD(SetIndices)
    STDMETHOD(GetIndices)
    STDMETHOD(CreatePixelShader)
    STDMETHOD(SetPixelShader)
    STDMETHOD(GetPixelShader)
    STDMETHOD(SetPixelShaderConstantF)
    STDMETHOD(GetPixelShaderConstantF)
    STDMETHOD(SetPixelShaderConstantI)
    STDMETHOD(GetPixelShaderConstantI)
    STDMETHOD(SetPixelShaderConstantB)
    STDMETHOD(GetPixelShaderConstantB)
    STDMETHOD(DrawRectPatch)
    STDMETHOD(DrawTriPatch)
    STDMETHOD(DeletePatch)
    STDMETHOD(CreateQuery)
};
...