public override void Hook() { this.DebugMessage("Hook: Begin"); // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain if (_d3d10_1VTblAddresses == null) { _d3d10_1VTblAddresses = new List <IntPtr>(); _dxgiSwapChainVTblAddresses = new List <IntPtr>(); this.DebugMessage("Hook: Before device creation"); using (Factory1 factory = new Factory1()) { using (var device = new SlimDX.Direct3D10_1.Device1(factory.GetAdapter(0), DriverType.Hardware, SlimDX.Direct3D10.DeviceCreationFlags.None, FeatureLevel.Level_10_1)) { this.DebugMessage("Hook: Device created"); _d3d10_1VTblAddresses.AddRange(GetVTblAddresses(device.ComPointer, D3D10_1_DEVICE_METHOD_COUNT)); using (var renderForm = new SlimDX.Windows.RenderForm()) { using (var sc = new SwapChain(factory, device, DXGI.CreateSwapChainDescription(renderForm.Handle))) { _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.ComPointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT)); } } } } } // We will capture the backbuffer here DXGISwapChain_PresentHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present], new DXGISwapChain_PresentDelegate(PresentHook), this); // We will capture target/window resizes here DXGISwapChain_ResizeTargetHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.ResizeTarget], new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook), this); /* * Don't forget that all hooks will start deactivated... * The following ensures that all threads are intercepted: * Note: you must do this for each hook. */ DXGISwapChain_PresentHook.ThreadACL.SetExclusiveACL(new Int32[1]); DXGISwapChain_ResizeTargetHook.ThreadACL.SetExclusiveACL(new Int32[1]); }
public override void Hook() { this.DebugMessage("Hook: Begin"); if (_d3d11VTblAddresses == null) { _d3d11VTblAddresses = new List <IntPtr>(); _dxgiSwapChainVTblAddresses = new List <IntPtr>(); #region Get Device and SwapChain method addresses // Create temporary device + swapchain and determine method addresses SlimDX.Direct3D11.Device device; SwapChain swapChain; using (SlimDX.Windows.RenderForm renderForm = new SlimDX.Windows.RenderForm()) { this.DebugMessage("Hook: Before device creation"); SlimDX.Result result = SlimDX.Direct3D11.Device.CreateWithSwapChain( DriverType.Hardware, DeviceCreationFlags.None, DXGI.CreateSwapChainDescription(renderForm.Handle), out device, out swapChain); if (result.IsSuccess) { this.DebugMessage("Hook: Device created"); using (device) { _d3d11VTblAddresses.AddRange(GetVTblAddresses(device.ComPointer, D3D11_DEVICE_METHOD_COUNT)); using (swapChain) { _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(swapChain.ComPointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT)); } } } else { this.DebugMessage("Hook: Device creation failed"); } } #endregion } // We will capture the backbuffer here DXGISwapChain_PresentHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present], new DXGISwapChain_PresentDelegate(PresentHook), this); // We will capture target/window resizes here DXGISwapChain_ResizeTargetHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.ResizeTarget], new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook), this); /* * Don't forget that all hooks will start deactivated... * The following ensures that all threads are intercepted: * Note: you must do this for each hook. */ DXGISwapChain_PresentHook.ThreadACL.SetExclusiveACL(new Int32[1]); DXGISwapChain_ResizeTargetHook.ThreadACL.SetExclusiveACL(new Int32[1]); }