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 _renderForm = ToDispose(new SharpDX.Windows.RenderForm()); this.DebugMessage("Hook: Before device creation"); SharpDX.Direct3D11.Device.CreateWithSwapChain( DriverType.Hardware, DeviceCreationFlags.BgraSupport, DXGI.CreateSwapChainDescription(_renderForm.Handle), out _device, out _swapChain); ToDispose(_device); ToDispose(_swapChain); if (_device != null && _swapChain != null) { this.DebugMessage("Hook: Device created"); _d3d11VTblAddresses.AddRange(GetVTblAddresses(_device.NativePointer, D3D11_DEVICE_METHOD_COUNT)); _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(_swapChain.NativePointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT)); } else { this.DebugMessage("Hook: Device creation failed"); } #endregion } // We will capture the backbuffer here DXGISwapChain_PresentHook = new Hook <DXGISwapChain_PresentDelegate>( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present], new DXGISwapChain_PresentDelegate(PresentHook), this); // We will capture target/window resizes here DXGISwapChain_ResizeTargetHook = new Hook <DXGISwapChain_ResizeTargetDelegate>( _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.Activate(); DXGISwapChain_ResizeTargetHook.Activate(); Hooks.Add(DXGISwapChain_PresentHook); Hooks.Add(DXGISwapChain_ResizeTargetHook); }
public override void Hook() { this.DebugMessage("Hook: Begin"); // First we need to determine the function address for IDirect3DDevice9 Device device; id3dSwapChainFunctionAddresses = new List <IntPtr>(); id3dSurfaceFunctionAddresses = new List <IntPtr>(); this.DebugMessage("Hook: Before device creation"); using (Direct3D d3d = new Direct3D()) { using (var renderForm = new System.Windows.Forms.Form()) { using (device = new Device(d3d, 0, SharpDX.Direct3D9.DeviceType.Hardware, renderForm.Handle, CreateFlags.HardwareVertexProcessing, new SharpDX.Direct3D9.PresentParameters(1, 1))) { this.DebugMessage("Hook: Device created"); using (Surface surface = Surface.CreateOffscreenPlain(device, 1, 1, Format.A8R8G8B8, Pool.SystemMemory)) { this.DebugMessage("Hook: Surface created"); id3dSurfaceFunctionAddresses.AddRange(GetVTblAddresses(surface.NativePointer, D3D9_SURFACE_METHOD_COUNT)); } using (SwapChain swapChain = device.GetSwapChain(0)) { this.DebugMessage("Hook: SwapChain created"); id3dSwapChainFunctionAddresses.AddRange(GetVTblAddresses(swapChain.NativePointer, D3D9_SWAP_CHAIN_METHOD_COUNT)); } } } } Direct3D9Surface_FreePrivateDataHook = new Hook <Direct3D9Surface_FreePrivateDataDelegate>( id3dSurfaceFunctionAddresses[(int)Direct3DSurface9FunctionOrdinals.FreePrivateData], new Direct3D9Surface_FreePrivateDataDelegate(SurfaceFreePrivateDataHook), this); Direct3D9SwapChain_PresentHook = new Hook <Direct3D9SwapChain_PresentDelegate>( id3dSwapChainFunctionAddresses[(int)DirectXSwapChainFunctionOrdinals.Present], new Direct3D9SwapChain_PresentDelegate(SwapChainPresentHook), 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. */ Direct3D9Surface_FreePrivateDataHook.Activate(); Hooks.Add(Direct3D9Surface_FreePrivateDataHook); Direct3D9SwapChain_PresentHook.Activate(); Hooks.Add(Direct3D9SwapChain_PresentHook); this.DebugMessage("Hook: End"); }
public override void Hook() { this.DebugMessage("Hook: Begin"); // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain if (_d3d10VTblAddresses == null) { _d3d10VTblAddresses = new List <IntPtr>(); _dxgiSwapChainVTblAddresses = new List <IntPtr>(); this.DebugMessage("Hook: Before device creation"); using (var factory = new Factory1()) { using (var device = new Device(factory.GetAdapter(0), DeviceCreationFlags.None)) { this.DebugMessage("Hook: Device created"); _d3d10VTblAddresses.AddRange(GetVTblAddresses(device.NativePointer, D3D10_DEVICE_METHOD_COUNT)); using (var renderForm = new System.Windows.Forms.Form()) { using (SharpDX.DXGI.SwapChain sc = new SharpDX.DXGI.SwapChain(factory, device, DXGI.CreateSwapChainDescription(renderForm.Handle))) { _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.NativePointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT)); } } } } } // We will capture the backbuffer here DXGISwapChain_PresentHook = new Hook <DXGISwapChain_PresentDelegate>( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present], new DXGISwapChain_PresentDelegate(PresentHook), this); // We will capture target/window resizes here DXGISwapChain_ResizeTargetHook = new Hook <DXGISwapChain_ResizeTargetDelegate>( _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.Activate(); DXGISwapChain_ResizeTargetHook.Activate(); Hooks.Add(DXGISwapChain_PresentHook); Hooks.Add(DXGISwapChain_ResizeTargetHook); }
public override void Hook() { DebugMessage("Hook: Begin"); // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain if (d3d101VTblAddresses == null) { d3d101VTblAddresses = new List <IntPtr>(); dxgiSwapChainVTblAddresses = new List <IntPtr>(); DebugMessage("Hook: Before device creation"); using var factory = new Factory1(); using var device = new Device1(factory.GetAdapter(0), DeviceCreationFlags.None, FeatureLevel.Level_10_1); DebugMessage("Hook: Device created"); d3d101VTblAddresses.AddRange(GetVTblAddresses(device.NativePointer, D_3D10_1_DEVICE_METHOD_COUNT)); using var renderForm = new RenderForm(); using var sc = new SwapChain(factory, device, Dxgi.CreateSwapChainDescription(renderForm.Handle)); dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.NativePointer, Dxgi.DXGI_SWAPCHAIN_METHOD_COUNT)); } // We will capture the backbuffer here dxgiSwapChainPresentHook = new Hook <DxgiSwapChainPresentDelegate>( dxgiSwapChainVTblAddresses[(int)Dxgi.DxgiSwapChainVTbl.Present], new DxgiSwapChainPresentDelegate(PresentHook), this); // We will capture target/window resizes here dxgiSwapChainResizeTargetHook = new Hook <DxgiSwapChainResizeTargetDelegate>( dxgiSwapChainVTblAddresses[(int)Dxgi.DxgiSwapChainVTbl.ResizeTarget], new DxgiSwapChainResizeTargetDelegate(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. */ dxgiSwapChainPresentHook.Activate(); dxgiSwapChainResizeTargetHook.Activate(); Hooks.Add(dxgiSwapChainPresentHook); Hooks.Add(dxgiSwapChainResizeTargetHook); }
public override void Hook() { this.DebugMessage("Hook: Begin"); // First we need to determine the function address for IDirect3DDevice9 Device device; id3dDeviceFunctionAddresses = new List <IntPtr>(); //id3dDeviceExFunctionAddresses = new List<IntPtr>(); this.DebugMessage("Hook: Before device creation"); using (Direct3D d3d = new Direct3D()) { using (var renderForm = new System.Windows.Forms.Form()) { using (device = new Device(d3d, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = renderForm.Handle })) { this.DebugMessage("Hook: Device created"); id3dDeviceFunctionAddresses.AddRange(GetVTblAddresses(device.NativePointer, D3D9_DEVICE_METHOD_COUNT)); } } } try { using (Direct3DEx d3dEx = new Direct3DEx()) { this.DebugMessage("Hook: Direct3DEx..."); using (var renderForm = new System.Windows.Forms.Form()) { using (var deviceEx = new DeviceEx(d3dEx, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = renderForm.Handle }, new DisplayModeEx() { Width = 800, Height = 600 })) { this.DebugMessage("Hook: DeviceEx created - PresentEx supported"); id3dDeviceFunctionAddresses.AddRange(GetVTblAddresses(deviceEx.NativePointer, D3D9_DEVICE_METHOD_COUNT, D3D9Ex_DEVICE_METHOD_COUNT)); _supportsDirect3D9Ex = true; } } } } catch (Exception) { _supportsDirect3D9Ex = false; } // We want to hook each method of the IDirect3DDevice9 interface that we are interested in // 42 - EndScene (we will retrieve the back buffer here) Direct3DDevice_EndSceneHook = new Hook <Direct3D9Device_EndSceneDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.EndScene], // On Windows 7 64-bit w/ 32-bit app and d3d9 dll version 6.1.7600.16385, the address is equiv to: // (IntPtr)(GetModuleHandle("d3d9").ToInt32() + 0x1ce09), // A 64-bit app would use 0xff18 // Note: GetD3D9DeviceFunctionAddress will output these addresses to a log file new Direct3D9Device_EndSceneDelegate(EndSceneHook), this); unsafe { // If Direct3D9Ex is available - hook the PresentEx if (_supportsDirect3D9Ex) { Direct3DDeviceEx_PresentExHook = new Hook <Direct3D9DeviceEx_PresentExDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9ExFunctionOrdinals.PresentEx], new Direct3D9DeviceEx_PresentExDelegate(PresentExHook), this); } // Always hook Present also (device will only call Present or PresentEx not both) Direct3DDevice_PresentHook = new Hook <Direct3D9Device_PresentDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Present], new Direct3D9Device_PresentDelegate(PresentHook), this); } // 16 - Reset (called on resolution change or windowed/fullscreen change - we will reset some things as well) Direct3DDevice_ResetHook = new Hook <Direct3D9Device_ResetDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Reset], // On Windows 7 64-bit w/ 32-bit app and d3d9 dll version 6.1.7600.16385, the address is equiv to: //(IntPtr)(GetModuleHandle("d3d9").ToInt32() + 0x58dda), // A 64-bit app would use 0x3b3a0 // Note: GetD3D9DeviceFunctionAddress will output these addresses to a log file new Direct3D9Device_ResetDelegate(ResetHook), 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. */ Direct3DDevice_EndSceneHook.Activate(); Hooks.Add(Direct3DDevice_EndSceneHook); Direct3DDevice_PresentHook.Activate(); Hooks.Add(Direct3DDevice_PresentHook); if (_supportsDirect3D9Ex) { Direct3DDeviceEx_PresentExHook.Activate(); Hooks.Add(Direct3DDeviceEx_PresentExHook); } Direct3DDevice_ResetHook.Activate(); Hooks.Add(Direct3DDevice_ResetHook); this.DebugMessage("Hook: End"); }
public override void Hook() { CurrentProcess = Process.GetProcessById(ProcessId); TraceListener listen = new DebugListener(Interface); Trace.Listeners.Add(listen); Services.Tracker.Configure(Services.CompassSettings).Apply(); DebugMessage("Settings loaded"); DebugMessage("Hook: Begin"); // First we need to determine the function address for IDirect3DDevice9 id3dDeviceFunctionAddresses = new List <IntPtr>(); using (var d3d = new Direct3D()) { using (var renderForm = new Form()) { Device device; using (device = new Device(d3d, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = renderForm.Handle })) { id3dDeviceFunctionAddresses.AddRange(GetVTblAddresses(device.NativePointer, D3D9_DEVICE_METHOD_COUNT)); } } } try { using (var d3dEx = new Direct3DEx()) { using (var renderForm = new Form()) { using (var deviceEx = new DeviceEx(d3dEx, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = renderForm.Handle }, new DisplayModeEx { Width = 800, Height = 600 })) { id3dDeviceFunctionAddresses.AddRange(GetVTblAddresses(deviceEx.NativePointer, D3D9_DEVICE_METHOD_COUNT, D3D9Ex_DEVICE_METHOD_COUNT)); _supportsDirect3D9Ex = true; } } } } catch (Exception) { _supportsDirect3D9Ex = false; } // We want to hook each method of the IDirect3DDevice9 interface that we are interested in // 42 - EndScene (we will retrieve the back buffer here) Direct3DDevice_EndSceneHook = new Hook <Direct3D9Device_EndSceneDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.EndScene], new Direct3D9Device_EndSceneDelegate(EndSceneHook), this); unsafe { // If Direct3D9Ex is available - hook the PresentEx if (_supportsDirect3D9Ex) { Direct3DDeviceEx_PresentExHook = new Hook <Direct3D9DeviceEx_PresentExDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9ExFunctionOrdinals.PresentEx], new Direct3D9DeviceEx_PresentExDelegate(PresentExHook), this); } // Always hook Present also (device will only call Present or PresentEx not both) Direct3DDevice_PresentHook = new Hook <Direct3D9Device_PresentDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Present], new Direct3D9Device_PresentDelegate(PresentHook), this); } // 16 - Reset (called on resolution change or windowed/fullscreen change - we will reset some things as well) Direct3DDevice_ResetHook = new Hook <Direct3D9Device_ResetDelegate>( id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Reset], new Direct3D9Device_ResetDelegate(ResetHook), 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. */ Direct3DDevice_EndSceneHook.Activate(); Hooks.Add(Direct3DDevice_EndSceneHook); Direct3DDevice_PresentHook.Activate(); Hooks.Add(Direct3DDevice_PresentHook); if (_supportsDirect3D9Ex) { Direct3DDeviceEx_PresentExHook.Activate(); Hooks.Add(Direct3DDeviceEx_PresentExHook); } Direct3DDevice_ResetHook.Activate(); Hooks.Add(Direct3DDevice_ResetHook); DebugMessage("Hook: End"); }