Пример #1
0
        private void SetupData(Device device)
        {
            this.DebugMessage("SetupData called");

            using (SwapChain swapChain = device.GetSwapChain(0))
            {
                PresentParameters pp = swapChain.PresentParameters;
                this.width = pp.BackBufferWidth;
                this.height = pp.BackBufferHeight;
                this.format = pp.BackBufferFormat;

                this.DebugMessage(string.Format("D3D9 Setup: w: {0} h: {1} f: {2}", this.width, this.height, this.format));
            }

            this.hooksStarted = true;
        }
Пример #2
0
        /// <summary>
        /// Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx)
        /// </summary>
        /// <param name="device"></param>
        void DoCaptureRenderTarget(Device device, string hook)
        {
            this.Frame();

            try
            {
                    #region Screenshot Request
                // Single frame capture request
                if (this.Request != null)
                {
                    DateTime start = DateTime.Now;
                    try
                    {

                        using (Surface renderTargetTemp = device.GetRenderTarget(0))
                        {
                            int width, height;

                            // TODO: If resizing the captured image is required it can be adjusted here
                            //if (renderTargetTemp.Description.Width > 1280)
                            //{
                            //    width = 1280;
                            //    height = (int)Math.Round((renderTargetTemp.Description.Height * (1280.0 / renderTargetTemp.Description.Width)));
                            //}
                            //else
                            {
                                width = renderTargetTemp.Description.Width;
                                height = renderTargetTemp.Description.Height;
                            }

                            // First ensure we have a Surface to the render target data into
                            if (_renderTarget == null)
                            {
                                // Create offscreen surface to use as copy of render target data
                                using (SwapChain sc = device.GetSwapChain(0))
                                {
                                    _renderTarget = Surface.CreateOffscreenPlain(device, width, height, sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                }
                            }

                            // Create our resolved surface (resizing if necessary and to resolve any multi-sampling)
                            using (Surface resolvedSurface = Surface.CreateRenderTarget(device, width, height, renderTargetTemp.Description.Format, MultisampleType.None, 0, false))
                            {
                                // Resize from Render Surface to resolvedSurface
                                device.StretchRectangle(renderTargetTemp, resolvedSurface, TextureFilter.None);

                                // Get Render Data
                                device.GetRenderTargetData(resolvedSurface, _renderTarget);
                            }
                        }

                        if (Request != null)
                            ProcessRequest();
                    }
                    finally
                    {
                        // We have completed the request - mark it as null so we do not continue to try to capture the same request
                        // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                        //         and send back to the host application as needed. The IPC overhead significantly slows down 
                        //         the whole process if sending frame by frame.
                        Request = null;
                    }
                    DateTime end = DateTime.Now;
                    this.DebugMessage(hook + ": Capture time: " + (end - start).ToString());
                }

                #endregion

                if (this.Config.ShowOverlay)
                {
                    #region Draw frame rate

                    // TODO: font needs to be created and then reused, not created each frame!
                    using (SharpDX.Direct3D9.Font font = new SharpDX.Direct3D9.Font(device, new FontDescription()
                                    {
                                        Height = 16,
                                        FaceName = "Arial",
                                        Italic = false,
                                        Width = 0,
                                        MipLevels = 1,
                                        CharacterSet = FontCharacterSet.Default,
                                        OutputPrecision = FontPrecision.Default,
                                        Quality = FontQuality.Antialiased,
                                        PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare,
                                        Weight = FontWeight.Bold
                                    }))
                    {

                        if (this.FPS.GetFPS() >= 1)
                        {
                            font.DrawText(null, String.Format("{0:N0} fps", this.FPS.GetFPS()), 5, 5, SharpDX.Color.Red);
                        }

                        if (this.TextDisplay != null && this.TextDisplay.Display)
                        {
                            font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                        }
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                DebugMessage(e.ToString());
            }
        }
        private void SetupData(Device device)
        {
            DebugMessage("SetupData called");

            using (var swapChain = device.GetSwapChain(0))
            {
                var pp = swapChain.PresentParameters;
                _copyData.width = pp.BackBufferWidth;
                _copyData.height = pp.BackBufferHeight;
                _copyData.format = (int)pp.BackBufferFormat;

                DebugMessage(string.Format("D3D9 Setup: w: {0} h: {1} f: {2}", _copyData.width, _copyData.height, pp.BackBufferFormat));
            }

            _hooksStarted = true;
        }
Пример #4
0
        /// <summary>
        /// Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx)
        /// </summary>
        /// <param name="device"></param>
        void DoCaptureRenderTarget(Device device, string hook)
        {
            try
            {
                #region Screenshot Request

                // Single frame capture request
                if (this.Request != null)
                {
                    DateTime start = DateTime.Now;
                    try
                    {
                        using (Surface renderTargetTemp = device.GetRenderTarget(0))
                        {
                            int width, height;

                            // TODO: If resizing the captured image is required it can be adjusted here
                            //if (renderTargetTemp.Description.Width > 1280)
                            //{
                            //    width = 1280;
                            //    height = (int)Math.Round((renderTargetTemp.Description.Height * (1280.0 / renderTargetTemp.Description.Width)));
                            //}
                            //else
                            {
                                width  = renderTargetTemp.Description.Width;
                                height = renderTargetTemp.Description.Height;
                            }

                            // First ensure we have a Surface to the render target data into
                            if (_renderTarget == null)
                            {
                                // Create offscreen surface to use as copy of render target data
                                using (SwapChain sc = device.GetSwapChain(0))
                                {
                                    _renderTarget = Surface.CreateOffscreenPlain(device, width, height,
                                                                                 sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                }
                            }

                            // Create our resolved surface (resizing if necessary and to resolve any multi-sampling)
                            using (
                                Surface resolvedSurface = Surface.CreateRenderTarget(device, width, height,
                                                                                     renderTargetTemp.Description.Format, MultisampleType.None, 0, false))
                            {
                                // Resize from Render Surface to resolvedSurface
                                device.StretchRectangle(renderTargetTemp, resolvedSurface, TextureFilter.None);

                                // Get Render Data
                                device.GetRenderTargetData(resolvedSurface, _renderTarget);
                            }
                        }

                        if (Request != null)
                        {
                            ProcessRequest();
                        }
                    }
                    finally
                    {
                        // We have completed the request - mark it as null so we do not continue to try to capture the same request
                        // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                        //         and send back to the host application as needed. The IPC overhead significantly slows down
                        //         the whole process if sending frame by frame.
                        Request = null;
                    }
                    DateTime end = DateTime.Now;
                    this.DebugMessage(hook + ": Capture time: " + (end - start).ToString());
                }

                #endregion

                if (this.Config.ShowOverlay)
                {
                    // SHIT
                    this.Frame();

                    #region Draw frame rate

                    // TODO: font needs to be created and then reused, not created each frame!

                    using (var font = new SharpDX.Direct3D9.Font(device, new FontDescription()
                    {
                        Height = 26,
                        FaceName = "Quartz MS",
                        Italic = false,
                        Width = 0,
                        MipLevels = 1,
                        CharacterSet = FontCharacterSet.Default,
                        OutputPrecision = FontPrecision.Default,
                        Quality = FontQuality.Antialiased,
                        PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare,
                        Weight = FontWeight.Normal
                    }))
                    {
                        // Make a Texture from a file...
                        using (FileStream myFileStream = new FileStream(@"baronbutton.png", System.IO.FileMode.Open))
                        { mytexStream = SharpDX.Direct3D9.Texture.FromStream(device, myFileStream); }

                        Sprite spritezor = new SharpDX.Direct3D9.Sprite(device);
                        spritezor.Begin(SharpDX.Direct3D9.SpriteFlags.None);
                        var baronPos = new Vector3(1476, 812, 0);
                        spritezor.Draw(mytexStream, new ColorBGRA(0xffffffff), null, null, baronPos);

                        // Display always...
                        if (this.Config.TestThisShit != 0)
                        {
                            // Draw sprite...
                            spritezor.End();
                            spritezor.Dispose();

                            // Oritinal Text before sprites worked...
                            //font.DrawText(null, "Timer 1", 5, 10, SharpDX.Color.Lime);
                        }

                        // Display on Timer...
                        if (this.TextDisplay != null && this.TextDisplay.Display)
                        {
                            font.DrawText(null, this.TextDisplay.Text, 1477, 870, new SharpDX.ColorBGRA(255, 0, 0, 255));
                            // Alternate font for timers pulsed with alpha fading between ticks...
                            // font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                        }

                        /* DXHookD3D9 Original statements to draw the FPS...
                         * if (this.FPS.GetFPS() >= 1)
                         * {
                         * font.DrawText(null, String.Format("{0:N0} fps", this.FPS.GetFPS()), 5, 5, SharpDX.Color.Red);
                         * }
                         * if (this.TextDisplay != null && this.TextDisplay.Display)
                         * {
                         * font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                         * }
                         */
                    }

                    #endregion
                }
            }

            catch (Exception e)
            {
                DebugMessage(e.ToString());
            }
        }
Пример #5
0
        /// <summary>
        /// Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx)
        /// </summary>
        /// <param name="device"></param>
        void DoCaptureRenderTarget(Device device, string hook)
        {
            try
            {
                #region Screenshot Request

                // Single frame capture request
                if (this.Request != null)
                {
                    DateTime start = DateTime.Now;
                    try
                    {

                        using (Surface renderTargetTemp = device.GetRenderTarget(0))
                        {
                            int width, height;

                            // TODO: If resizing the captured image is required it can be adjusted here
                            //if (renderTargetTemp.Description.Width > 1280)
                            //{
                            //    width = 1280;
                            //    height = (int)Math.Round((renderTargetTemp.Description.Height * (1280.0 / renderTargetTemp.Description.Width)));
                            //}
                            //else
                            {
                                width = renderTargetTemp.Description.Width;
                                height = renderTargetTemp.Description.Height;
                            }

                            // First ensure we have a Surface to the render target data into
                            if (_renderTarget == null)
                            {
                                // Create offscreen surface to use as copy of render target data
                                using (SwapChain sc = device.GetSwapChain(0))
                                {
                                    _renderTarget = Surface.CreateOffscreenPlain(device, width, height,
                                        sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                }
                            }

                            // Create our resolved surface (resizing if necessary and to resolve any multi-sampling)
                            using (
                                Surface resolvedSurface = Surface.CreateRenderTarget(device, width, height,
                                    renderTargetTemp.Description.Format, MultisampleType.None, 0, false))
                            {
                                // Resize from Render Surface to resolvedSurface
                                device.StretchRectangle(renderTargetTemp, resolvedSurface, TextureFilter.None);

                                // Get Render Data
                                device.GetRenderTargetData(resolvedSurface, _renderTarget);
                            }
                        }

                        if (Request != null)
                            ProcessRequest();
                    }
                    finally
                    {
                        // We have completed the request - mark it as null so we do not continue to try to capture the same request
                        // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                        //         and send back to the host application as needed. The IPC overhead significantly slows down
                        //         the whole process if sending frame by frame.
                        Request = null;
                    }
                    DateTime end = DateTime.Now;
                    this.DebugMessage(hook + ": Capture time: " + (end - start).ToString());
                }

                #endregion

                if (this.Config.ShowOverlay)
                {

                    // SHIT
                    this.Frame();

                    #region Draw frame rate

                    // TODO: font needs to be created and then reused, not created each frame!

                    using (var font = new SharpDX.Direct3D9.Font(device, new FontDescription()
                    {
                        Height = 26,
                        FaceName = "Quartz MS",
                        Italic = false,
                        Width = 0,
                        MipLevels = 1,
                        CharacterSet = FontCharacterSet.Default,
                        OutputPrecision = FontPrecision.Default,
                        Quality = FontQuality.Antialiased,
                        PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare,
                        Weight = FontWeight.Normal
                    }))
                    {

                    // Make a Texture from a file...
                    using (FileStream myFileStream = new FileStream(@"baronbutton.png", System.IO.FileMode.Open))
                    { mytexStream = SharpDX.Direct3D9.Texture.FromStream(device, myFileStream); }

                        Sprite spritezor = new SharpDX.Direct3D9.Sprite(device);
                        spritezor.Begin(SharpDX.Direct3D9.SpriteFlags.None);
                        var baronPos = new Vector3(1476, 812, 0);
                        spritezor.Draw(mytexStream, new ColorBGRA(0xffffffff), null, null, baronPos);

                        // Display always...
                        if (this.Config.TestThisShit != 0)
                        {
                            // Draw sprite...
                            spritezor.End();
                            spritezor.Dispose();

                            // Oritinal Text before sprites worked...
                            //font.DrawText(null, "Timer 1", 5, 10, SharpDX.Color.Lime);
                        }

                        // Display on Timer...
                        if (this.TextDisplay != null && this.TextDisplay.Display)
                        {
                            font.DrawText(null, this.TextDisplay.Text, 1477, 870, new SharpDX.ColorBGRA(255, 0, 0, 255));
                            // Alternate font for timers pulsed with alpha fading between ticks...
                            // font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                        }

                        /* DXHookD3D9 Original statements to draw the FPS...
                        if (this.FPS.GetFPS() >= 1)
                        {
                           font.DrawText(null, String.Format("{0:N0} fps", this.FPS.GetFPS()), 5, 5, SharpDX.Color.Red);
                        }
                        if (this.TextDisplay != null && this.TextDisplay.Display)
                        {
                           font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                        }
                        */
                    }

                    #endregion
                }
            }

            catch (Exception e)
            {
                DebugMessage(e.ToString());
            }
        }
Пример #6
0
        private void SetupD3D9(Device device)
        {
            try
            {
                DebugMessage("Setting up Direct3D...");
                using (SwapChain swapChain = device.GetSwapChain(0))
                {
                    PresentParameters pp = swapChain.PresentParameters;
                    this.copyData.width = pp.BackBufferWidth;
                    this.copyData.height = pp.BackBufferHeight;
                    this.copyData.format = (int)pp.BackBufferFormat;

                    DebugMessage(string.Format("D3D9 Setup: w: {0} h: {1} f: {2}", copyData.width, copyData.height, copyData.format));
                    isCapturing = true;
                    lastTime = 0;
                }
            }
            catch (Exception ex)
            {
                DebugMessage(ex.ToString());
            }
        }