Hi everyone,
I am trying to hook EndScene in C# but I am still far away. Project BabBot is using the approach listed at Programming Stuff: Hooking Direct3D9 with C#. and I was trying this too.
BabBot's/my approach is to start WoW as suspended and after that hook Direct3DCreate9. I am able to do this but then after overriding functions from VF table my CreateDevice() is never executed and I have no idea why.
Can anyone help on this (my code snippets from the injected DLL follow)?
Initialize VF table.
Code:
private void InitializeVFTable()
{
// If we don't have a real IDirect3D9 object yet then do nothing.
if (NativeIDirect3D9 == null) return;
// Save off the original VFTable (only if it really is the original).
if (OriginalVFTable == null) OriginalVFTable = NativeIDirect3D9->VFTable;
// IDirect3D9 has 17 members.
UInt32 VFTableLength = 17;
// Allocate space for our new VFTable.
IntPtr* NewVFTable = (IntPtr*)Win32.Kernel32.HeapAlloc(Win32.Kernel32.GetProcessHeap(), 0, (UIntPtr)(VFTableLength * sizeof(IntPtr)));
// Copy all of the original function pointers into our new VFTable.
for (int i = 0; i < VFTableLength; i++)
{
NewVFTable[i] = OriginalVFTable[i];
}
// Set the Real IDirect3D9 implementation's VFTable to point at our custom one.
NativeIDirect3D9->VFTable = NewVFTable;
}
Override functions method. Last log I can see is "Overriding ...".
Code:
private void OverrideFunctions()
{
// this is the last log I can see
HookedDLL.Hook.LoggingInterface.L("Overriding ...");
InitializeVFTable();
// #16: STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) PURE;
DelegateCreateDevice MyCD = new DelegateCreateDevice(CreateDevice);
IntPtr PointerToMyCD = Marshal.GetFunctionPointerForDelegate(MyCD);
NativeIDirect3D9->VFTable[16] = PointerToMyCD;
}
This never is executed. Strangly it works for BabBot creators.
Code:
public delegate uint DelegateCreateDevice(
Win32.D3D9.IDirect3D9* This, uint adapter, uint deviceType, IntPtr focusWindow, uint behaviorFlags,
IntPtr presentationParameters, Win32.D3D9.IDirect3DDevice9* deviceInterface);
public uint CreateDevice(Win32.D3D9.IDirect3D9* This, uint adapter, uint deviceType, IntPtr focusWindow,
uint behaviorFlags, IntPtr presentationParameters,
Win32.D3D9.IDirect3DDevice9* deviceInterface)
{
// never executed
HookedDLL.Hook.LoggingInterface.L("CreateDevice Start ...");
return 1;
}
I hope I described my problem clearly. If not just tell me what you need to know to at least try to help on this.