DirectX11 Hook and Render menu

User Tag List

Results 1 to 11 of 11
  1. #1
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DirectX11 Hook and Render

    Hi Everyone,

    I'm busy converting one of my projects which currently uses DX9 to draw; which is fine but it forces me to use DX9 in wow and since I have nice hardware I would much prefer to use it to its potential and use DX11.

    The problem is I have never used DX11 and I can't find much good information about it; at least none about rendering on someone else's device.

    My hook is like this:

    Code:
            private int Callback(IntPtr swapChainPtr, int syncInterval, PresentFlags flags)
            {
                this.Pointer = swapChainPtr;
                RaiseEvent(); //This just calls my onFrame functions
                return (int)_presentHook.CallOriginal(swapChainPtr, syncInterval, flags);
            }
    This works fine I do get a valid swapChainPtr! However, I'm stuck on how to get the device for this swapchain. I should point out I'm using SlimDx(purely because my dx9 code already works with it and since I have a friend who uses this project as well I need to keep dx9 support as well)

    I have looked at the SlimDx documentation but it's not great and I can't find how to get a SlimDX.Direct3D11.Device from wows swapchain.

    I have tried the following:

    Code:
    //This works but is not the device I am looking for
         SwapChain swapChain = SwapChain.FromPointer(swapChainPtr);
         SlimDX.DXGI.Device ddd = swapChain.Device;

    Code:
    //This gives an error about being unable to create the device from the user provided pointer
    _DeviceDX11 = SlimDX.Direct3D11.Device.FromPointer(swapChain);
    For DirectX9 it was very easy:
    Code:
    _DeviceDX9 = SlimDX.Direct3D9.Device.FromPointer(Hook.DevicePointer);
    Can anyone help?

    Thanks
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

    DirectX11 Hook and Render
  2. #2
    lolp1's Avatar Site Donator CoreCoins Purchaser
    Reputation
    190
    Join Date
    Feb 2013
    Posts
    210
    Thanks G/R
    43/77
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not use SlimDX, but you want something like this. Just send me a PM if you want the full set of classes for my generic hook x32/64 d3d9/11 hook that checks which one to detour at runtime.

    Code:
            [DllImport("d3d11.dll")]
            public static extern unsafe int D3D11CreateDeviceAndSwapChain(void* pAdapter, int driverType, void* Software,
                int flags, void* pFeatureLevels,
                int FeatureLevels, int SDKVersion,
                void* pSwapChainDesc, void* ppSwapChain,
                void* ppDevice, void* pFeatureLevel,
                void* ppImmediateContext);
    Then you grab the device pointer

    Code:
          protected override void InitD3D(out IntPtr d3DDevicePtr)
            {
                LoadDxgiDll();
                var scd = new SwapChainDescription
                {
                    BufferCount = 1,
                    ModeDescription = new ModeDescription {Format = DXGI_FORMAT_R8G8B8A8_UNORM},
                    Usage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
                    OutputHandle = Form.Handle,
                    SampleDescription = new SampleDescription {Count = 1},
                    IsWindowed = true
                };
    
                unsafe
                {
                    var pSwapChain = IntPtr.Zero;
                    var pDevice = IntPtr.Zero;
                    var pImmediateContext = IntPtr.Zero;
    
                    var ret = D3D11CreateDeviceAndSwapChain((void*) IntPtr.Zero, D3D_DRIVER_TYPE_HARDWARE,
                        (void*) IntPtr.Zero, 0, (void*) IntPtr.Zero, 0, D3D11_SDK_VERSION, &scd, &pSwapChain, &pDevice,
                        (void*) IntPtr.Zero, &pImmediateContext);
    
                    _swapChain = pSwapChain;
                    _device = pDevice;
                    d3DDevicePtr = pImmediateContext;
    
                    if (ret >= 0)
                    {
                        var vTableFuncAddress = GetVTableFuncAddress(_swapChain, VTableIndexes.DXGISwapChainRelease);
                        _swapchainRelease = Marshal.GetDelegateForFunctionPointer<VTableFuncDelegate>(vTableFuncAddress);
    
                        var deviceptr = GetVTableFuncAddress(_device, VTableIndexes.D3D11DeviceRelease);
                        _deviceRelease = Marshal.GetDelegateForFunctionPointer<VTableFuncDelegate>(deviceptr);
    
                        var contex = GetVTableFuncAddress(d3DDevicePtr, VTableIndexes.D3D11DeviceContextRelease);
                        _deviceContextRelease = Marshal.GetDelegateForFunctionPointer<VTableFuncDelegate>(contex);
                    }
                }
            }
    i personally use a generic hook that determines the d3d device when loaded, and applies the correct detour. Make sure to use IntPtr.Size for your vtables as to ensure x32/62 compatibly.

    I think yours would look something like this

    Code:
        public class D3D11Hook : D3DHook
        {
            private DxgiSwapChainPresentDelegate _presentCallBack;
            private Detour _presentDetour;
    
            protected override void OnInitialize()
            {
                _presentCallBack = Dirext3D.HookAddress.ToDelegate<DxgiSwapChainPresentDelegate>();
    
                _presentDetour = Detour("Present", _presentCallBack,
                    new DxgiSwapChainPresentDelegate(OnPresent), false);
    
                base.OnInitialize();
            }
    
            private int OnPresent(IntPtr device, int syncInterval, int flags)
            {
                UpdateFrame();
                return (int) _presentDetour.CallOriginal(device, syncInterval, flags);
            }
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainPresentDelegate(IntPtr swapChainPtr, int syncInterval, int flags);
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainResizeTargetDelegate(
                IntPtr swapChainPtr, ref D3D11Device.ModeDescription newTargetParameters);
        }

  3. #3
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi lolp1, Thanks for the input... however as explained in my original post, I already have the hook which in your example is called OnPresent in mine its Callback

    What you call '
    device' in this function I believe to be the swapChainPointer, I need to be able to draw with this and therefore need the real device pointer used for the game (not the one I created) to get the address to hook.

    I have no other use for the hook, I don't need it as a 'pulse' it is purely for rendering my own graphics.

    If you have an example of drawing even if just a 2d line across the screen with the wow d3d11 device id be interested to see this.
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

  4. #4
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1584
    Join Date
    May 2010
    Posts
    1,829
    Thanks G/R
    188/531
    Trade Feedback
    16 (100%)
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    I use,

    Code:
    HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&pDevice);
    but that's in C++ and not using SlimDX

  5. #5
    lolp1's Avatar Site Donator CoreCoins Purchaser
    Reputation
    190
    Join Date
    Feb 2013
    Posts
    210
    Thanks G/R
    43/77
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by -Ryuk- View Post
    Hi lolp1, Thanks for the input... however as explained in my original post, I already have the hook which in your example is called OnPresent in mine its Callback

    What you call '
    device' in this function I believe to be the swapChainPointer, I need to be able to draw with this and therefore need the real device pointer used for the game (not the one I created) to get the address to hook.

    I have no other use for the hook, I don't need it as a 'pulse' it is purely for rendering my own graphics.

    If you have an example of drawing even if just a 2d line across the screen with the wow d3d11 device id be interested to see this.
    I do too, sorry if it was confusing. I'll send you an example in PM tomorrow of how I render my radar.

  6. #6
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lolp1 View Post
    I do too, sorry if it was confusing. I'll send you an example in PM tomorrow of how I render my radar.
    Great. Thanks
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

  7. #7
    zdohdds's Avatar Active Member
    Reputation
    16
    Join Date
    Feb 2013
    Posts
    46
    Thanks G/R
    19/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all. Trying to write DXGI::Present_hook for x64, it works, but crashes after 10 - 180 seconds.

    PHP Code:
        public interface IPulsable
        
    {
            
    void DXGI_Present();
        } 
    PHP Code:
        public static class DirectX
        
    {
            private const 
    int VMT_PRESENT 8;

            private static List<
    IPulsable_pulsables = new List<IPulsable>();

            private static 
    DxgiSwapChainPresentDelegate _present null;
            private static 
    Detour _presentHook null;

            public static 
    void Initialize()
            {
                
    IntPtr pPresent IntPtr.Zero;

                
    using (var renderForm = new SlimDX.Windows.RenderForm())
                {
                    var 
    description = new SlimDX.DXGI.SwapChainDescription()
                    {
                        
    BufferCount 1,
                        
    Flags SlimDX.DXGI.SwapChainFlags.None,
                        
    IsWindowed true,
                        
    ModeDescription = new SlimDX.DXGI.ModeDescription(100100, new SlimDX.Rational(601), SlimDX.DXGI.Format.R8G8B8A8_UNorm),
                        
    OutputHandle renderForm.Handle,
                        
    SampleDescription = new SlimDX.DXGI.SampleDescription(10),
                        
    SwapEffect SlimDX.DXGI.SwapEffect.Discard,
                        
    Usage SlimDX.DXGI.Usage.RenderTargetOutput
                    
    };
                    
    SlimDX.Direct3D11.Device device;
                    
    SlimDX.DXGI.SwapChain swapChain;
                    var 
    result SlimDX.Direct3D11.Device.CreateWithSwapChain(
                        
    SlimDX.Direct3D11.DriverType.Hardware,
                        
    SlimDX.Direct3D11.DeviceCreationFlags.None,
                        
    description,
                        
    out device,
                        
    out swapChain);
                    if (
    result.IsSuccessusing (deviceusing (swapChain)
                    {
                        
    // 8 * 4 = 0x20 for x86
                        // 8 * 8 = 0x40 for x64
                        
    IntPtr pointer = new IntPtrMemory.Read<long>(swapChain.ComPointer) + VtableFunc(VMT_PRESENT) );
                        
    pPresent = new IntPtr(Memory.Read<long>(pointer));
                    }
                }

                
    _present Memory.RegisterDelegat<DxgiSwapChainPresentDelegate>(pPresent);
                
    _presentHook Detour.CreateAndApply(_present, new DxgiSwapChainPresentDelegate(DXGI_Present));
            }

            private static 
    int VtableFunc(int index)
            {
                return 
    IntPtr.Size index;
            }

            private static 
    int DXGI_Present(IntPtr swapChainPtrint syncIntervalint flags)
            {
                
    //foreach (var pulsable in _pulsables)
                   // pulsable.DXGI_Present();
                //Log.WriteLine("In DXGI_Present");
                
    return (int)_presentHook.CallOriginal(swapChainPtrsyncIntervalflags);
            }

            public static 
    void RegisterCallBack(IPulsable pulsable)
            {
                
    _pulsables.Add(pulsable);
            }

            [
    UnmanagedFunctionPointer(CallingConvention.StdCallCharSet CharSet.UnicodeSetLastError true)]
            
    delegate int DxgiSwapChainPresentDelegate(IntPtr swapChainPtrint syncIntervalint flags);
            
            
    //public static IntPtr D3D11Present { get { return IntPtr.Add(Memory.ModuleBaseAddress("dxgi.dll"), 0x11A0); } }
            //public static Delegate Present { get { return Memory.RegisterDelegat<DxgiSwapChainPresentDelegate>(D3D11Present); } }
        

    PHP Code:
        public class Detour
        
    {
            private 
    IntPtr _original;
            private 
    IntPtr _hook;
            private 
    byte[] _originalBytes;
            private 
    byte[] _hookBytes;

            private 
    Delegate _func_original;
            
            public 
    Detour(Delegate func_originalDelegate func_hook)
            {
                
    this._hook Marshal.GetFunctionPointerForDelegate(func_hook);
                List<
    bytehookOpCode = new List<byte>();
                
    hookOpCode.AddRange(new byte[] { 0x480xb8 }); // movabs rax
                
    hookOpCode.AddRange(BitConverter.GetBytes(this._hook.ToInt64())); // address
                
    hookOpCode.AddRange(new byte[] { 0xff0xe0 }); // jmp rax
                
    this._hookBytes hookOpCode.ToArray();

                
    this._original Marshal.GetFunctionPointerForDelegate(func_original);
                
    this._originalBytes Memory.ReadBytes(this._originalhookOpCode.Count);
                
    this._func_original func_original;
            }

            public static 
    Detour CreateAndApply(Delegate func_originalDelegate func_hook)
            {
                
    Detour ret = new Detour(func_originalfunc_hook);
                if (
    ret != null)
                {
                    
    ret.Apply();
                }
                return 
    ret;
            }

            public 
    void Apply()
            {
                
    Memory.WriteBytes(this._originalthis._hookBytes);
                
            }

            public 
    void Remove()
            {
                
    Memory.WriteBytes(this._originalthis._originalBytes);
            }

            public 
    object CallOriginal(params object[] args)
            {
                
    Remove();
                
    object ret _func_original.DynamicInvoke(args);
                
    Apply();
                return 
    ret;
            }
        } 
    With exception:
    Code:
    Exception handler died
    Original exception:
    0xE0434352 (unknown exception) at 00007ffd49701f28
    What could it be?

  8. #8
    lolp1's Avatar Site Donator CoreCoins Purchaser
    Reputation
    190
    Join Date
    Feb 2013
    Posts
    210
    Thanks G/R
    43/77
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure the code you are calling in the detour is safe? What if you just do a frame count?

    Try something like this.

    Code:
        public class D3D11Hook : D3DHook
        {
            DxgiSwapChainPresentDelegate _presentCallBack;
            Detour _presentDetour;
    
            protected override void OnInitialize()
            {
                _presentCallBack = Dirext3D.HookAddress.ToDelegate<DxgiSwapChainPresentDelegate>();
    
                _presentDetour = Detour("Present", _presentCallBack,
                    new DxgiSwapChainPresentDelegate(OnPresent), false);
    
                base.OnInitialize();
            }
    
            int OnPresent(IntPtr device, int syncInterval, int flags)
            {
                UpdateFrame();
                return (int) _presentDetour.CallOriginal(device, syncInterval, flags);
            }
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainPresentDelegate(IntPtr swapChainPtr, int syncInterval, int flags);
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainResizeTargetDelegate(
                IntPtr swapChainPtr, ref D3D11Device.ModeDescription newTargetParameters);
        }
    
        public static class FrameCounterTest
        {
            static readonly D3D11Hook D3D11Hook = new D3D11Hook();
    
            public static void Test()
            {
                D3D11Hook.Initialize();
                D3D11Hook.Frame += D3D11HookOnFrame;
            }
    
            public static int FrameCount { get; private set; }
    
            static void D3D11HookOnFrame(object sender, DeltaTimeEventArgs deltaTimeEventArgs)
            {
                if (FrameCount != 60)
                {
                    FrameCount++;
                    return;
                }
    
                FrameCount = 0;
                Log.WriteLine(FrameCount + " was reached");
            }
        }

  9. #9
    zdohdds's Avatar Active Member
    Reputation
    16
    Join Date
    Feb 2013
    Posts
    46
    Thanks G/R
    19/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lolp1 View Post
    Are you sure the code you are calling in the detour is safe? What if you just do a frame count?

    Try something like this.

    Code:
        public class D3D11Hook : D3DHook
        {
            DxgiSwapChainPresentDelegate _presentCallBack;
            Detour _presentDetour;
    
            protected override void OnInitialize()
            {
                _presentCallBack = Dirext3D.HookAddress.ToDelegate<DxgiSwapChainPresentDelegate>();
    
                _presentDetour = Detour("Present", _presentCallBack,
                    new DxgiSwapChainPresentDelegate(OnPresent), false);
    
                base.OnInitialize();
            }
    
            int OnPresent(IntPtr device, int syncInterval, int flags)
            {
                UpdateFrame();
                return (int) _presentDetour.CallOriginal(device, syncInterval, flags);
            }
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainPresentDelegate(IntPtr swapChainPtr, int syncInterval, int flags);
    
            [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
            protected delegate int DxgiSwapChainResizeTargetDelegate(
                IntPtr swapChainPtr, ref D3D11Device.ModeDescription newTargetParameters);
        }
    
        public static class FrameCounterTest
        {
            static readonly D3D11Hook D3D11Hook = new D3D11Hook();
    
            public static void Test()
            {
                D3D11Hook.Initialize();
                D3D11Hook.Frame += D3D11HookOnFrame;
            }
    
            public static int FrameCount { get; private set; }
    
            static void D3D11HookOnFrame(object sender, DeltaTimeEventArgs deltaTimeEventArgs)
            {
                if (FrameCount != 60)
                {
                    FrameCount++;
                    return;
                }
    
                FrameCount = 0;
                Log.WriteLine(FrameCount + " was reached");
            }
        }
    Thanks for the quick response. I haven't tried what you suggested, but "ugly code" works on all of 200% and without lunch breaks.

    PHP Code:
            //_present = Memory.RegisterDelegat<DxgiSwapChainPresentDelegate>(pPresent);
            //_presentHook = Detour.CreateAndApply(pPresent, new DXGI_Present_Delegate(DXGI_Present));
            //...

            
    private static void DXGI_Present(IntPtr swapChainPtrint syncIntervalint flags)
            {
                
    _presentHook.Dispose();

                foreach (var 
    pulsable in _pulsables)
                    
    pulsable.DXGI_Present();
                
    Log.WriteLine("{0:X}"swapChainPtr.ToInt64());

                
    _present.DynamicInvoke(swapChainPtrsyncIntervalflags);
                
    _presentHook.Apply();
            }
            
    delegate void DXGI_Present_Delegate(IntPtr swapChainPtrint syncIntervalint flags); 
    PHP Code:
        public class Detour
        
    {
            private 
    IntPtr _originalAddress;
            private 
    IntPtr _hookAddress;
            private 
    byte[] _originalOpCodes;
            private 
    byte[] _hookOpCodes;

            private 
    Delegate _func;

            public 
    Detour(IntPtr addressDelegate func)
            {
                
    this._func func;
                
    this._hookAddress Marshal.GetFunctionPointerForDelegate(func);
                List<
    bytehookOpCode = new List<byte>();
                
    hookOpCode.AddRange(new byte[] { 0x480xb8 }); // movabs rax
                
    hookOpCode.AddRange(BitConverter.GetBytes(this._hookAddress.ToInt64())); // address
                
    hookOpCode.AddRange(new byte[] { 0xff0xe0 }); // jmp rax
                
    this._hookOpCodes hookOpCode.ToArray();

                
    this._originalAddress address;
                
    this._originalOpCodes Memory.ReadBytes(addresshookOpCode.Count);
            }

            public static 
    Detour CreateAndApply(IntPtr addressDelegate func)
            {
                
    Detour ret = new Detour(addressfunc);
                if (
    ret != null)
                {
                    
    ret.Apply();
                }
                return 
    ret;
            }

            public 
    void Apply()
            {
                
    Memory.WriteBytes(this._originalAddressthis._hookOpCodes);

            }

            public 
    void Dispose()
            {
                
    Memory.WriteBytes(this._originalAddressthis._originalOpCodes);
            }

            public 
    object CallOriginal(params object[] args)
            {
                
    Dispose();
                
    object ret _func.DynamicInvoke(args);
                
    Apply();
                return 
    ret;
            }
        } 
    If I try to use CallOriginal (in the previous Detour example, not this) function it crashes.
    Last edited by zdohdds; 12-03-2016 at 01:30 AM.

  10. #10
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1511
    Join Date
    May 2008
    Posts
    2,432
    Thanks G/R
    81/333
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by zdohdds View Post
    Hi all. Trying to write DXGI::Present_hook for x64, it works, but crashes after 10 - 180 seconds.

    ...

    PHP Code:
        public class Detour
        
    {
            private 
    IntPtr _original;
            private 
    IntPtr _hook;
            private 
    byte[] _originalBytes;
            private 
    byte[] _hookBytes;

            private 
    Delegate _func_original;
            
            public 
    Detour(Delegate func_originalDelegate func_hook)
            {
                
    this._hook Marshal.GetFunctionPointerForDelegate(func_hook);
                List<
    bytehookOpCode = new List<byte>();
                
    hookOpCode.AddRange(new byte[] { 0x480xb8 }); // movabs rax
                
    hookOpCode.AddRange(BitConverter.GetBytes(this._hook.ToInt64())); // address
                
    hookOpCode.AddRange(new byte[] { 0xff0xe0 }); // jmp rax
                
    this._hookBytes hookOpCode.ToArray();

                
    this._original Marshal.GetFunctionPointerForDelegate(func_original);
                
    this._originalBytes Memory.ReadBytes(this._originalhookOpCode.Count);
                
    this._func_original func_original;
            }

            ...
        } 
    With exception:
    Code:
    Exception handler died
    Original exception:
    0xE0434352 (unknown exception) at 00007ffd49701f28
    What could it be?
    You need to pin the destination delegate or the GC will eventually dispose of it since it is never explicitly stored or referenced after Marshal.GetFunctionPointerForDelegate. If and when this happens, your jmp will send you to a delegate which no longer exists.

    Add a new field, _destination, and assign func_hook to it when you create the detour. Even though you'll never need to use it again, the GC will not dispose of it or move it's memory location.

  11. Thanks zdohdds (1 members gave Thanks to Jadd for this useful post)
  12. #11
    imzz's Avatar Active Member
    Reputation
    24
    Join Date
    May 2011
    Posts
    36
    Thanks G/R
    37/17
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by zdohdds View Post
    Thanks for the quick response. I haven't tried what you suggested, but "ugly code" works on all of 200% and without lunch breaks.

    PHP Code:
            //_present = Memory.RegisterDelegat<DxgiSwapChainPresentDelegate>(pPresent);
            //_presentHook = Detour.CreateAndApply(pPresent, new DXGI_Present_Delegate(DXGI_Present));
            //...

            
    private static void DXGI_Present(IntPtr swapChainPtrint syncIntervalint flags)
            {
                
    _presentHook.Dispose();

                foreach (var 
    pulsable in _pulsables)
                    
    pulsable.DXGI_Present();
                
    Log.WriteLine("{0:X}"swapChainPtr.ToInt64());

                
    _present.DynamicInvoke(swapChainPtrsyncIntervalflags);
                
    _presentHook.Apply();
            }
            
    delegate void DXGI_Present_Delegate(IntPtr swapChainPtrint syncIntervalint flags); 
    PHP Code:
        public class Detour
        
    {
            private 
    IntPtr _originalAddress;
            private 
    IntPtr _hookAddress;
            private 
    byte[] _originalOpCodes;
            private 
    byte[] _hookOpCodes;

            private 
    Delegate _func;

            public 
    Detour(IntPtr addressDelegate func)
            {
                
    this._func func;
                
    this._hookAddress Marshal.GetFunctionPointerForDelegate(func);
                List<
    bytehookOpCode = new List<byte>();
                
    hookOpCode.AddRange(new byte[] { 0x480xb8 }); // movabs rax
                
    hookOpCode.AddRange(BitConverter.GetBytes(this._hookAddress.ToInt64())); // address
                
    hookOpCode.AddRange(new byte[] { 0xff0xe0 }); // jmp rax
                
    this._hookOpCodes hookOpCode.ToArray();

                
    this._originalAddress address;
                
    this._originalOpCodes Memory.ReadBytes(addresshookOpCode.Count);
            }

            public static 
    Detour CreateAndApply(IntPtr addressDelegate func)
            {
                
    Detour ret = new Detour(addressfunc);
                if (
    ret != null)
                {
                    
    ret.Apply();
                }
                return 
    ret;
            }

            public 
    void Apply()
            {
                
    Memory.WriteBytes(this._originalAddressthis._hookOpCodes);

            }

            public 
    void Dispose()
            {
                
    Memory.WriteBytes(this._originalAddressthis._originalOpCodes);
            }

            public 
    object CallOriginal(params object[] args)
            {
                
    Dispose();
                
    object ret _func.DynamicInvoke(args);
                
    Apply();
                return 
    ret;
            }
        } 
    If I try to use CallOriginal (in the previous Detour example, not this) function it crashes.
    Is your problem solved?

Similar Threads

  1. Replies: 11
    Last Post: 12-23-2010, 09:30 PM
  2. DR Hooks and Detection
    By GliderPro in forum WoW Memory Editing
    Replies: 18
    Last Post: 01-20-2010, 04:37 AM
  3. [Rate] Sig and Render
    By Phoenix WoW in forum Art & Graphic Design
    Replies: 7
    Last Post: 07-08-2008, 05:57 AM
  4. [Showoff] Simple Batman Signature, and render!
    By PrimoPie in forum Art & Graphic Design
    Replies: 0
    Last Post: 06-01-2008, 01:47 AM
  5. Brushes and Renders
    By Xcynic in forum Art & Graphic Design
    Replies: 10
    Last Post: 10-02-2007, 12:47 PM
All times are GMT -5. The time now is 04:26 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search