Skip to content

Instantly share code, notes, and snippets.

@NitroXenon
Created September 22, 2015 10:58
Show Gist options
  • Save NitroXenon/2afcebdaeb04185f3e21 to your computer and use it in GitHub Desktop.
Save NitroXenon/2afcebdaeb04185f3e21 to your computer and use it in GitHub Desktop.
EasyHookD3D.cs
private List<IntPtr> id3dDeviceFunctionOffsets()
{
Device device;
List<IntPtr> id3dDeviceFunctionAddresses = new List<IntPtr>();
using (Direct3D d3d = new Direct3D())
{
PresentParameters pPars = new PresentParameters();
pPars.BackBufferWidth = 1;
pPars.BackBufferHeight = 1;
pPars.Windowed=true;
pPars.SwapEffect=SwapEffect.Discard;
using (device = new Device(d3d, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing,pPars))
{
IntPtr realPointer = device.ComPointer;
IntPtr vTable = Marshal.ReadIntPtr(realPointer);
for (int i = 0; i < 119; i++)
id3dDeviceFunctionAddresses.Add(Marshal.ReadIntPtr(vTable, i * IntPtr.Size));
}
}
return id3dDeviceFunctionAddresses;
}
//I use this as id3dDeviceFunctionOffsets[42] to get the EndScene from vtable
public void Run(RemoteHooking.IContext InContext,String InChannelName)
{
Direct3DDevice_EndSceneHook = LocalHook.Create(id3dDeviceFunctionOffsets()[42], new Direct3D9Device_EndSceneDelegate(EndSceneHook), this);
Direct3DDevice_EndSceneHook.ThreadACL.SetExclusiveACL(new Int32[]{0});
}
///And the EndScene
int EndSceneHook(IntPtr devicePtr)
{
MessageBox.Show("test");
using (Device device = Device.FromPointer(devicePtr))
{
using (SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font(FontFamily.GenericSansSerif, 24)))
{
font.DrawString(null, "aasdasdbc", 20, 60, Color.Maroon);
}
return device.EndScene().Code;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment