Exemplo n.º 1
0
        internal static void ShowPlayerInfo(Models.Player player)
        {
            if (frmMain.Instance.InvokeRequired)
            {
                frmMain.Instance.BeginInvoke(new Action <Models.Player>(ShowPlayerInfo), player);
            }
            else
            {
                if (PlayerInfoForm != null)
                {
                    PlayerInfoForm.Dispose();
                }

                PlayerInfoForm = new frmPlayerInfo(player);
                PlayerInfoForm.Show();
            }
        }
Exemplo n.º 2
0
        public frmPlayerInfo(Models.Player player)
        {
            if (Instance != null)
            {
                Instance.Close();
                Instance = null;
            }

            Instance = this;

            int baseWidth  = 154;
            int baseHeight = 113;
            int baseX      = 252;
            int baseY      = 594;

            double xPercentage      = (double)baseX / 1280 * 100;
            double yPercentage      = (double)baseY / 720 * 100;
            double widthPercentage  = (double)baseWidth / 1280 * 100;
            double heightPercentage = (double)baseHeight / 720 * 100;

            double yScale = Program.SC2WindowRect.Height / 720;
            double xScale = Program.SC2WindowRect.Width / 1280;


            InitializeComponent();



            Animator = new FormAnimator(this, FormAnimator.AnimationMethod.Slide, FormAnimator.AnimationDirection.Right, 1000);

            this.Left   = (int)(Program.SC2WindowRect.Left + ((double)Program.SC2WindowRect.Width / 100 * xPercentage));
            this.Top    = (int)(Program.SC2WindowRect.Top + ((double)Program.SC2WindowRect.Height / 100 * yPercentage));
            this.Height = (int)((double)Program.SC2WindowRect.Height / 100 * heightPercentage);
            this.Width  = (int)((double)Program.SC2WindowRect.Width / 100 * widthPercentage);

            _player = player;

            if (Configuration.Instance.OpponentInfoOverlayTimeout > 0)
            {
                tmrClose.Interval = Configuration.Instance.OpponentInfoOverlayTimeout * 1000;
                tmrClose.Start();
            }
        }
Exemplo n.º 3
0
        internal static void SC2InteractionThreadWorker()
        {
            try
            {
                var processNames = new string[] { "SC2_X64", "SC2" };

                while (true)
                {
                    Process sc2Process = null;

                    while (sc2Process == null)
                    {
                        if (!Configuration.Instance.UseAdvancedOptions)
                        {
                            throw new Exception();
                        }
                        System.Threading.Thread.Sleep(100);

                        foreach (var name in processNames)
                        {
                            Process[] processes = Process.GetProcessesByName(name);

                            foreach (Process p in processes)
                            {
                                if (!p.HasExited)
                                {
                                    if (p.MainWindowTitle == "StarCraft II")
                                    {
                                        sc2Process = p;
                                    }
                                }
                            }

                            if (sc2Process != null)
                            {
                                break;
                            }
                        }
                    }



                    byte[] buffer = new byte[256];
                    int    read;

                    bool   inGame           = false;
                    bool   tabbed           = false;
                    string game_player_1    = null;
                    string game_player_1_id = null;
                    string game_player_2    = null;
                    string game_player_2_id = null;


                    while (!sc2Process.HasExited)
                    {
                        if (!Configuration.Instance.UseAdvancedOptions)
                        {
                            throw new Exception();
                        }
                        if (Program.ActivePatch != null)
                        {
                            if (sc2Process.MainWindowHandle == IntPtr.Zero || !Win32.IsWindow(sc2Process.MainWindowHandle))
                            {
                                inGame = false;
                                Debug.WriteLine("SC2 main window gone.");
                                HidePlayerInfo();
                                HideBuildSelection();
                                HideOverlay();
                            }

                            Win32.RECT rct;
                            Win32.GetWindowRect(sc2Process.MainWindowHandle, out rct);

                            SC2WindowRect.X      = rct.Left;
                            SC2WindowRect.Y      = rct.Top;
                            SC2WindowRect.Width  = rct.Right - rct.Left;
                            SC2WindowRect.Height = rct.Bottom - rct.Top;

                            yScale = (double)Program.SC2WindowRect.Height / (double)720;
                            xScale = (double)Program.SC2WindowRect.Width / (double)1280;
                            //Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                            if (!inGame)
                            {
                                bool result = Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1, buffer, 256, out read);

                                if (result)
                                {
                                    if (buffer[0] != 0)
                                    {
                                        game_player_1 = ReadBufferToNull(buffer, 0, read);

                                        Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1 + Program.ActivePatch.Ptr1Size, buffer, 256, out read);
                                        game_player_2 = ReadBufferToNull(buffer, 0, read);

                                        Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr2, buffer, 256, out read);
                                        game_player_1_id = ReadBufferToNull(buffer, 0, read);

                                        Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr2 + Program.ActivePatch.Ptr2Size, buffer, 256, out read);
                                        game_player_2_id = ReadBufferToNull(buffer, 0, read);

                                        if (string.IsNullOrEmpty(game_player_1_id) && (string.IsNullOrEmpty(game_player_2_id)))
                                        {
                                            Debug.WriteLine("AI Showmatch?");
                                        }
                                        else if (!string.IsNullOrEmpty(game_player_1_id) && (string.IsNullOrEmpty(game_player_2_id)))
                                        {
                                            Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_1, game_player_1_id, GetProfileFromID(game_player_1, game_player_1_id)));
                                            Debug.WriteLine("Now in game: AI?");

                                            if (Configuration.Instance.BuildSelectionOverlay)
                                            {
                                                ShowBuildSelection();
                                            }
                                        }
                                        else
                                        {
                                            Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_1, game_player_1_id, GetProfileFromID(game_player_1, game_player_1_id)));
                                            Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_2, game_player_2_id, GetProfileFromID(game_player_2, game_player_2_id)));

                                            if (Configuration.Instance.OpponentInfoOverlay)
                                            {
                                                Models.Player player = null;
                                                if (game_player_1.ToLower() == Configuration.Instance.MySC2Character.ToLower())
                                                {
                                                    player = GetPlayer(game_player_2, game_player_2_id);
                                                }
                                                else
                                                {
                                                    player = GetPlayer(game_player_1, game_player_1_id);
                                                }

                                                ShowPlayerInfo(player);
                                            }

                                            if (Configuration.Instance.BuildSelectionOverlay)
                                            {
                                                ShowBuildSelection();
                                            }
                                        }

                                        inGame = true;
                                    }
                                }
                            }
                            else
                            {
                                bool result = Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1, buffer, 256, out read);
                                if (!result)
                                {
                                    inGame = false;
                                }
                                else
                                {
                                    if (buffer[0] == 0)
                                    {
                                        inGame = false;
                                        Debug.WriteLine("Now out of game.");
                                        HidePlayerInfo();
                                        HideBuildSelection();
                                        HideOverlay();
                                    }
                                    else
                                    {
                                        IntPtr fgw = Win32.GetForegroundWindow();

                                        if (tabbed)
                                        {
                                            if (fgw == sc2Process.MainWindowHandle)
                                            {
                                                tabbed = false;
                                                Debug.WriteLine("Tabbed in");

                                                if (frmPlayerInfo.Instance != null)
                                                {
                                                    frmPlayerInfo.Instance.ShowNoActivate();
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (fgw != sc2Process.MainWindowHandle)
                                            {
                                                tabbed = true;
                                                Debug.WriteLine("Tabbed out");
                                                if (frmPlayerInfo.Instance != null)
                                                {
                                                    frmPlayerInfo.Instance.HideWindow();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        System.Threading.Thread.Sleep(500);
                    }

                    inGame = false;
                    Debug.WriteLine("Process exited");
                    HidePlayerInfo();
                    HideBuildSelection();
                    HideOverlay();
                }
            }
            catch
            {
                HidePlayerInfo();
                HideBuildSelection();
                _sc2InteractionThread = null;
            }
        }