예제 #1
0
        static async Task <bool> Run()
        {
            // init
            RegisterHotKeys();
            var config = GetConfig();

            if (config is null)
            {
                throw new ConfigException("Unable to read config.js");
            }
            Logger.Info("config.js is valid.");
            var feedEngine = new DataFeedEngine(config.Pairs, config.Timeframe, config.LeaderboardWatch);

            feedEngine.ApplyAppConfig(config);
            Logger.Info($"Pairs added to data feed: {string.Join(", ", config.Pairs)}");
            await feedEngine.Start().ConfigureAwait(false);

            Logger.Info("Start successfully.");
            // start overlay
            using (var overlay = new OverlayEngine())
            {
                overlay.ApplyAppConfig(config);
                overlay.CustomMessages.Add($"RSI: {config.RsiPeriod} - Timeframe: {config.Timeframe}");
                overlay.Run();
            }
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Our present hook that will grab a copy of the backbuffer when requested. Note: this supports multi-sampling (anti-aliasing)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="syncInterval"></param>
        /// <param name="flags"></param>
        /// <returns>The HRESULT of the original method</returns>
        int PresentHook(IntPtr swapChainPtr, int syncInterval, SharpDX.DXGI.PresentFlags flags)
        {
            this.Frame();
            SwapChain swapChain = (SharpDX.DXGI.SwapChain)swapChainPtr;

            try
            {
                #region Draw overlay (after screenshot so we don't capture overlay as well)
                // Initialise Overlay Engine
                if (_swapChainPointer != swapChain.NativePointer || OverlayEngine == null)
                {
                    if (OverlayEngine != null)
                    {
                        OverlayEngine.Dispose();
                    }

                    OverlayEngine = new DX11.DXOverlayEngine();
                    OverlayEngine.Overlays.Add(new DirectXHook.Hook.Common.Overlay
                    {
                        Elements =
                        {
                            new Common.ImageElement(new Bitmap(1920,                  1080))
                            {
                                Location = new System.Drawing.Point(0,                                                          0)
                            },
                            //new Common.TextElement(new System.Drawing.Font("Times New Roman", 22)) { Text = "Test", Location = new System.Drawing.Point(200, 200), Color = System.Drawing.Color.Yellow, AntiAliased = false},
                            new Common.FramesPerSecond(new System.Drawing.Font("Arial",                  16))
                            {
                                Location = new System.Drawing.Point(5, 5), Color = System.Drawing.Color.Red, AntiAliased = true
                            },
                        }
                    });
                    OverlayEngine.Initialise(swapChain);

                    _swapChainPointer = swapChain.NativePointer;
                }

                // Draw Overlay(s)
                else if (OverlayEngine != null)
                {
                    foreach (var overlay in OverlayEngine.Overlays)
                    {
                        overlay.Frame();
                    }
                    OverlayEngine.Draw();
                }
                #endregion
            }
            catch (Exception e)
            {
                // If there is an error we do not want to crash the hooked application, so swallow the exception
                this.DebugMessage("PresentHook: Exeception: " + e.GetType().FullName + ": " + e.ToString());
                //return unchecked((int)0x8000FFFF); //E_UNEXPECTED
            }

            // As always we need to call the original method, note that EasyHook will automatically skip the hook and call the original method
            // i.e. calling it here will not cause a stack overflow into this function
            return(DXGISwapChain_PresentHook.Original(swapChainPtr, syncInterval, flags));
        }
예제 #3
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref ModeDescription newTargetParameters)
        {
            // Dispose of overlay engine (so it will be recreated with correct renderTarget view size)
            if (OverlayEngine != null)
            {
                OverlayEngine.Dispose();
                OverlayEngine = null;
            }

            return(DXGISwapChain_ResizeTargetHook.Original(swapChainPtr, ref newTargetParameters));
        }
예제 #4
0
 public override void Cleanup()
 {
     try
     {
         if (OverlayEngine != null)
         {
             OverlayEngine.Dispose();
             OverlayEngine = null;
         }
     }
     catch
     {
     }
 }
예제 #5
0
 public override void Cleanup()
 {
     try
     {
         if (OverlayEngine != null)
         {
             OverlayEngine.Dispose();
             OverlayEngine = null;
             DebugMessage("Cleanup");
         }
     }
     catch
     {
     }
 }
예제 #6
0
        public void ManualPresentHook(IntPtr swapChainPtr)
        {
            DebugMessage("ManualPresentHook Method start");
            SwapChain swapChain = (SharpDX.DXGI.SwapChain)swapChainPtr;

            if (swapChainPtr != IntPtr.Zero)
            {
                try
                {
                    DebugMessage("ManualPresentHook:1");
                    #region Draw overlay (after screenshot so we don't capture overlay as well)

                    #region Initialise Overlay Engine
                    if (_swapChainPointer != swapChain.NativePointer || OverlayEngine == null)
                    {
                        DebugMessage("ManualPresentHook:2");
                        NewSwapchain = true;
                        List <IOverlayElement> oldOverlays = null;

                        if (OverlayEngine != null)
                        {
                            DebugMessage("ManualPresentHook:3");
                            if (OverlayEngine.Overlays.Count > 0 && OverlayEngine.Overlays[0].Elements != null)
                            {
                                DebugMessage("ManualPresentHook:4");
                                oldOverlays = new List <IOverlayElement>(OverlayEngine.Overlays[0].Elements);

                                foreach (var element in oldOverlays)
                                {
                                    if (element is ImageElement)
                                    {
                                        DebugMessage("ManualPresentHook:5");
                                        ((ImageElement)element).Image?.Dispose();
                                        ((ImageElement)element).Image = null;
                                    }
                                }
                            }
                            OverlayEngine.Dispose();
                        }

                        DebugMessage("ManualPresentHook:6");
                        OverlayEngine          = new DX11.DXOverlayEngine(this);
                        OverlayEngine.Overlays = new List <IOverlay>();
                        OverlayEngine.Overlays.Add(new Overlay());
                        OverlayEngine.Overlays.Add(new Overlay());
                        DebugMessage("ManualPresentHook:7");
                        if (oldOverlays != null)
                        {
                            DebugMessage("ManualPresentHook:8");
                            OverlayEngine.Overlays[0].Elements = oldOverlays;
                        }
                        DebugMessage("ManualPresentHook:9");
                        if (ObligatoryElement != null)
                        {
                            DebugMessage("ManualPresentHook:10");
                            OverlayEngine.Overlays[0].Elements.Add(ObligatoryElement);
                        }
                        DebugMessage("ManualPresentHook:11");
                        OverlayEngine.Initialise(swapChain);
                        DebugMessage("ManualPresentHook:12");
                        _swapChainPointer = swapChain.NativePointer;
                    }
                    #endregion

                    // ---LOOP---
                    // Draw Overlay(s)
                    if (OverlayEngine != null)
                    {
                        DebugMessage("ManualPresentHook:13");
                        foreach (var overlay in OverlayEngine.Overlays)
                        {
                            overlay.Frame();
                        }
                        OverlayEngine.Draw();
                        DebugMessage("ManualPresentHook:14");
                    }
                    // ---LOOP---

                    #endregion
                }
                catch (Exception e)
                {
                    // If there is an error we do not want to crash the hooked application, so swallow the exception
                    LogManager.DebugLog("PresentHook: Exeception: " + e.GetType().FullName + ": " + e.ToString());
                    LogManager.LogException(e, "PresentHook");
                    //return unchecked((int)0x8000FFFF); //E_UNEXPECTED
                }
            }
        }
예제 #7
0
 public static void ApplyAppConfig(this OverlayEngine engine, AppConfig config)
 {
     engine.OverBoughtRsi = config.OverBoughtRsi;
     engine.OverSoldRsi   = config.OverSoldRsi;
     //engine.ShowUsedWeight = config.ShowUsedWeight;
 }