Пример #1
0
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            gen = game.Game as GenericGameInfo;
            if (gen == null)
            {
                // you f****d up
                return(false);
            }

            if (gen.LockMouse)
            {
                _cursorModule = new CursorModule();
            }

            jsData = new Dictionary <string, string>();
            jsData.Add(Folder.Documents.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            jsData.Add(Folder.MainGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));
            jsData.Add(Folder.InstancedGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));

            timerInterval = gen.HandlerInterval;

            Log.RegisterForLogCallback(this);

            return(true);
        }
Пример #2
0
        public bool Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            this.handlerData = handlerData;

            if (this.handlerData.LockMouse)
            {
                _cursorModule = new CursorModule();
            }

            jsData = new Dictionary <string, string>();
            jsData.Add(Folder.Documents.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            jsData.Add(Folder.MainGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));
            jsData.Add(Folder.InstancedGameFolder.ToString(), "");

            timerInterval = this.handlerData.HandlerInterval;

            Log.RegisterForLogCallback(this);

            return(true);
        }
Пример #3
0
        public override void Tick(double delayMs)
        {
            exited = 0;
            timer += delayMs;

            bool updatedHwnd = false;

            if (timer > HWndInterval)
            {
                updatedHwnd = true;
                timer       = 0;
            }

            List <PlayerInfo> players      = profile.PlayerData;
            CursorModule      cursorModule = handler.GetModule <CursorModule>();

            for (int i = 0; i < players.Count; i++)
            {
                PlayerInfo  p    = players[i];
                ProcessInfo data = p.ProcessData;
                if (data == null)
                {
                    continue;
                }

                if (data.Finished)
                {
                    if (data.Process.HasExited)
                    {
                        exited++;
                    }
                    continue;
                }

                if (updatedHwnd)
                {
                    if (data.Setted)
                    {
                        if (data.Process.HasExited)
                        {
                            exited++;
                            continue;
                        }

                        data.HWnd.TopMost = true;

                        if (data.Status == 2)
                        {
                            uint lStyle = User32Interop.GetWindowLong(data.HWnd.NativePtr, User32_WS.GWL_STYLE);
                            lStyle = lStyle & ~User32_WS.WS_CAPTION;
                            lStyle = lStyle & ~User32_WS.WS_THICKFRAME;
                            lStyle = lStyle & ~User32_WS.WS_MINIMIZE;
                            lStyle = lStyle & ~User32_WS.WS_MAXIMIZE;
                            lStyle = lStyle & ~User32_WS.WS_SYSMENU;
                            User32Interop.SetWindowLong(data.HWnd.NativePtr, User32_WS.GWL_STYLE, lStyle);

                            lStyle = User32Interop.GetWindowLong(data.HWnd.NativePtr, User32_WS.GWL_EXSTYLE);
                            lStyle = lStyle & ~User32_WS.WS_EX_DLGMODALFRAME;
                            lStyle = lStyle & ~User32_WS.WS_EX_CLIENTEDGE;
                            lStyle = lStyle & ~User32_WS.WS_EX_STATICEDGE;
                            User32Interop.SetWindowLong(data.HWnd.NativePtr, User32_WS.GWL_EXSTYLE, lStyle);
                            User32Interop.SetWindowPos(data.HWnd.NativePtr, IntPtr.Zero, 0, 0, 0, 0, (uint)(PositioningFlags.SWP_FRAMECHANGED | PositioningFlags.SWP_NOMOVE | PositioningFlags.SWP_NOSIZE | PositioningFlags.SWP_NOZORDER | PositioningFlags.SWP_NOOWNERZORDER));
                            //User32Interop.SetForegroundWindow(data.HWnd.NativePtr);

                            data.Finished = true;
                            Debug.WriteLine("State 2");

                            if (i == players.Count - 1 && handlerData.LockMouse)
                            {
                                //last screen setuped
                                cursorModule?.SetActiveWindow();
                            }
                        }
                        else if (data.Status == 1)
                        {
                            data.HWnd.Location = data.Position;
                            data.Status++;
                            Debug.WriteLine("State 1");

                            if (handlerData.LockMouse)
                            {
                                if (p.IsKeyboardPlayer)
                                {
                                    cursorModule?.Setup(data.Process, p.MonitorBounds);
                                }
                                else
                                {
                                    cursorModule?.AddOtherGameHandle(data.Process.MainWindowHandle);
                                }
                            }
                        }
                        else if (data.Status == 0)
                        {
                            data.HWnd.Size = data.Size;

                            data.Status++;
                            Debug.WriteLine("State 0");
                        }
                    }
                    else
                    {
                        data.Process.Refresh();

                        if (data.Process.HasExited)
                        {
                            if (p.GotLauncher)
                            {
                                if (p.GotGame)
                                {
                                    exited++;
                                }
                                else
                                {
                                    List <int> children = ProcessUtil.GetChildrenProcesses(data.Process);
                                    if (children.Count > 0)
                                    {
                                        for (int j = 0; j < children.Count; j++)
                                        {
                                            int     id  = children[j];
                                            Process pro = Process.GetProcessById(id);

                                            if (!attached.Contains(pro))
                                            {
                                                attached.Add(pro);
                                                data.HWnd = null;
                                                p.GotGame = true;
                                                data.AssignProcess(pro);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // Steam showing a launcher, need to find our game process
                                string launcher = handlerData.LauncherExe;
                                if (!string.IsNullOrEmpty(launcher))
                                {
                                    if (launcher.ToLower().EndsWith(".exe"))
                                    {
                                        launcher = launcher.Remove(launcher.Length - 4, 4);
                                    }

                                    Process[] procs = Process.GetProcessesByName(launcher);
                                    for (int j = 0; j < procs.Length; j++)
                                    {
                                        Process pro = procs[j];
                                        if (!attached.Contains(pro))
                                        {
                                            attached.Add(pro);
                                            data.AssignProcess(pro);
                                            p.GotLauncher = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (data.HWNDRetry || data.HWnd == null || data.HWnd.NativePtr != data.Process.MainWindowHandle)
                            {
                                data.HWnd = new HwndObject(data.Process.MainWindowHandle);
                                Point pos = data.HWnd.Location;

                                if (String.IsNullOrEmpty(data.HWnd.Title) ||
                                    pos.X == -32000 ||
                                    data.HWnd.Title.ToLower() == handlerData.LauncherTitle.ToLower())
                                {
                                    data.HWNDRetry = true;
                                }
                                else if (!string.IsNullOrEmpty(handlerData.Hook.ForceFocusWindowName) &&
                                         // TODO: this Levenshtein distance is being used to help us around Call of Duty Black Ops, as it uses a ® icon in the title bar
                                         //       there must be a better way
                                         StringUtil.ComputeLevenshteinDistance(data.HWnd.Title, handlerData.Hook.ForceFocusWindowName) > 2)
                                {
                                    data.HWNDRetry = true;
                                }
                                else
                                {
                                    Size s = data.Size;
                                    data.Setted = true;
                                }
                            }
                        }
                    }
                }
            }

            if (exited == players.Count)
            {
                handler.End();
            }
        }
Пример #4
0
        }                 //конструктор для intellisense

        public View(ChartWindow Window, ChartShell Shell)
        {
            this.Window = Window;
            this.Shell  = Shell;

            InitializeComponent();
            this.Shell.ToggleClipTime += b => Clipped = b;
            this.PreviewMouseDown     += (s, e) => this.Shell.ChartGotFocus(this);
            this.MouseEnter           += (s, e) => this.Shell.InstrumentsHandler = this;
            this.MouseLeave           += (s, e) =>
            {
                if (this.Shell.InstrumentsHandler == this)
                {
                    this.Shell.InstrumentsHandler = null;
                }
            };
            this.ShowSettings += this.Shell.ShowSettings;

            PriceMarksModule = new PriceMarksModule(this, LevelsLayer, PaintingMarksLayer);

            PriceLineModule = new PriceLineModule(this, GridLayerHorizontal, PricesLayer, PriceMarksModule);
            PriceLineModule.VerticalСhanges   += () => VerticalСhanges.Invoke();
            PriceLineModule.ScaleWidthChanged += (w, fsf) =>
            {
                Dispatcher.Invoke(() =>
                {
                    PriceLineCD.Width  = new GridLength(w);
                    PriceLineCD2.Width = new GridLength(w);
                });

                NewFSF?.Invoke(fsf);
            };

            TimeLineModule = new TimeLineModule(this, GridLayerVertical);
            TimeLineModule.HorizontalСhanges += () => HorizontalСhanges.Invoke();

            CursorModule = new CursorModule(this, CursorLayer, MagnetLayer, CursorTimeMarkLayer, CursorPriceMarkLayer);

            CandlesModule = new CandlesModule(this, CandlesLayer, PriceLineModule, TimeLineModule,
                                              Translate, ScaleX, ScaleY, TimeLine, PriceLine,
                                              new Vector(ScaleX.ScaleX, ScaleY.ScaleY));
            CandlesModule.CandlesChanged     += ac => CandlesChanged?.Invoke(ac);
            CandlesModule.AllHorizontalReset += cc => AllHorizontalReset?.Invoke(cc);
            CandlesModule.NewXScale          += sc => NewXScale?.Invoke(sc);
            CandlesModule.NewXTrans          += tr => NewXTrans?.Invoke(tr);

            BottomIndicatorManger = new BottomIndicatorsManger(this, IndicatorsGrid, IndicatorsRowRD, IndicatorsSplitterRD);
            CenterIndicatorManger = new CenterIndicatorManger(this, BackgroundIndLayer,
                                                              ForegroundIndLayer, PaintingMarksLayer, PaintingTimeLayer);

            PaintingModule = new PaintingModule(this, PrototypeLayer, PrototypePriceLayer,
                                                PrototypeTimeLayer, CenterIndicatorManger.AddElement);
            this.Shell.ClearPrototypes += PaintingModule.ClearPrototype;

            HooksModule = new HooksModule(this, HooksLayer, HookPriceLayer, HookTimeLayer,
                                          () => CursorModule.LinesPen, CenterIndicatorManger,
                                          new List <FrameworkElement>
            {
                SubLayers,
                PaintingMarksLayer,
                BackgroundIndLayer,
                ForegroundIndLayer
            });

            ChartGrid.PreviewMouseRightButtonDown += (s, e) =>
            {
                var items = HooksModule.ShowContextMenu(s, e);
                if (items == null)
                {
                    items = (new List <(string Name, Action Act)>()
                    {
                        ("Test 1", () => { Debug.WriteLine("Test 1"); }),
                        ("+++", null),
                        ("Test 2", () => { Debug.WriteLine("Test 2"); }),
                        ("+++", null),
                        ("Test 3", () => { Debug.WriteLine("Test 3"); })
                    },
                             null, null);
                }
                this.Shell.ShowContextMenu(items.Value);
            };

            CandlesModule.WheelScalled += () => CursorModule.Redraw(CursorPosition.Current);

            var DC = DataContext as ViewModel;

            DC.PropertyChanged += DC_PropertyChanged;
            DC.Inicialize();

            SetsDefinition();
        }