Exemple #1
0
        /// <summary>
        /// Instantiates the DirectX overlay, by first finding the applicable
        /// version of DirectX for the application and then finding the individual
        /// details. For more details, see <see cref="DX9Overlay"/>
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="renderDelegate">
        ///     A delegate type to use for DirectX rendering. The delegate type should
        ///     contain an appropriate DirectX <see cref="Direct3D9Device_EndSceneDelegate"/>
        ///     object for drawing overlays.
        /// </param>
        /// <param name="resetDelegate">
        ///     A delegate or function of type of <see cref="Direct3D9Device_ResetDelegate"/> to call when D3D9 fires its Reset function,
        ///     called on resolution change or windowed/fullscreen change - we can reset some things as well.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        public static async Task <DX9Overlay> CreateDirectXOverlay(Direct3D9Device_EndSceneDelegate renderDelegate, Direct3D9Device_ResetDelegate resetDelegate, int hookDelay)
        {
            // Wait the hook delay.
            await Task.Delay(hookDelay);

            // Create a new self-object.
            DX9Overlay dx9Overlay = new DX9Overlay();

            // Wait for DirectX
            Direct3DVersion direct3DVersion = await DXHookCommon.DetermineDirectXVersion();

            // Return nothing if not D3D9
            if (direct3DVersion != Direct3DVersion.Direct3D9)
            {
                Bindings.PrintError(
                    "libReloaded Hooking: DirectX 9 module not found, the application is either not" +
                    "a DirectX 9 application or uses an unsupported version of DirectX.");

                return(null);
            }

            // Instantiate DX9 hook
            dx9Overlay.DirectX9Hook = new DX9Hook();

            // Obtain Virtual Function Table Entries
            VirtualFunctionTable.TableEntry endSceneTableEntry = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.EndScene];
            VirtualFunctionTable.TableEntry resetTableEntry    = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.Reset];

            // Hook relevant DirectX functions.
            dx9Overlay.EndSceneHook = new FunctionHook <Direct3D9Device_EndSceneDelegate>((long)endSceneTableEntry.FunctionPointer, renderDelegate);
            dx9Overlay.ResetHook    = new FunctionHook <Direct3D9Device_ResetDelegate>((long)resetTableEntry.FunctionPointer, resetDelegate);

            // Return our DX9Overlay
            return(dx9Overlay);
        }
Exemple #2
0
        /// <summary>
        /// Instantiates the DirectX overlay, by first finding the applicable
        /// version of DirectX for the application and then finding the individual
        /// details. For more details, see <see cref="DX11Overlay"/>
        ///
        /// Note: The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/>
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="DXGIPresentDelegate">
        ///     A delegate type to use for DirectX rendering. The delegate type should
        ///     contain an appropriate DirectX <see cref="DXGISwapChain_PresentDelegate"/>
        ///     object for drawing overlays.
        /// </param>
        /// <param name="DXGIResizeTargetDelegate">
        ///     A delegate or function of type of <see cref="DXGISwapChain_ResizeTargetDelegate"/> to call when DXGI Buffer
        ///     commits a resolution change or windowed/fullscreen change.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        /// <remarks>The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/></remarks>
        public static async Task <DX11Overlay> CreateDirectXOverlay(DXGISwapChain_PresentDelegate DXGIPresentDelegate, DXGISwapChain_ResizeTargetDelegate DXGIResizeTargetDelegate, int hookDelay)
        {
            // Wait the hook delay.
            await Task.Delay(hookDelay);

            // Create a new self-object.
            DX11Overlay dx11Overlay = new DX11Overlay();

            // Wait for DirectX
            Direct3DVersion direct3DVersion = await DXHookCommon.GetDirectXVersion();

            // Return nothing if not D3D9
            if (direct3DVersion != Direct3DVersion.Direct3D11 && direct3DVersion != Direct3DVersion.Direct3D11_1 &&
                direct3DVersion != Direct3DVersion.Direct3D11_3 && direct3DVersion != Direct3DVersion.Direct3D11_4)
            {
                Bindings.PrintError(
                    "libReloaded Hooking: DirectX 11 module not found, the application is either not " +
                    "a DirectX 11 application or uses an unsupported version of DirectX.");

                return(null);
            }

            // Instantiate DX9 hook
            dx11Overlay.DirectX11Hook = new DX11Hook();;

            // Obtain Virtual Function Table Entries
            VirtualFunctionTable.TableEntry presentTableEntry = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.Present];
            VirtualFunctionTable.TableEntry resizeTableEntry  = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.ResizeTarget];

            // Hook relevant DirectX functions.
            if (IntPtr.Size == 4)
            {
                // X86
                dx11Overlay.PresentHook = FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate);

                dx11Overlay.ResizeTargetHook = FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate);
            }
            else if (IntPtr.Size == 8)
            {
                // X64
                dx11Overlay.PresentHook64 = X64FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate);

                dx11Overlay.ResizeTargetHook64 = X64FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate);
            }

            // Return our DX9Overlay
            return(dx11Overlay);
        }