/// <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); }
/// <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> public static async Task <DX9Overlay> CreateDirectXOverlay(Direct3D9Device_EndSceneDelegate renderDelegate, Direct3D9Device_ResetDelegate resetDelegate) { return(await CreateDirectXOverlay(renderDelegate, resetDelegate, 0)); }