Ejemplo n.º 1
0
        private void OnAreaSelected(object sender, EventArgs e)
        {
            RECT windowRect = new RECT();

            User32.GetWindowRect(HWnd, ref windowRect);

            int       increasedWidth  = (int)(SnippingTool.Area.Size.Width * 1.1);
            int       increasedHeight = (int)(SnippingTool.Area.Size.Height * 1.35);
            Rectangle increasedRect   = _isFullScreen ? new Rectangle(SnippingTool.Area.Location.X, SnippingTool.Area.Location.Y, increasedWidth, increasedHeight)
                : new Rectangle(SnippingTool.Area.Location.X - windowRect.X, SnippingTool.Area.Location.Y - windowRect.Y, increasedWidth, increasedHeight);

            using (Bitmap bitmap = (Bitmap)ScreenCapture.CapturePartialWindow(HWnd, increasedRect))
            {
                RECT hpRECT = ImageProcessing.GetMatchingImageLocation(bitmap, AttributeType.HP);
                if (hpRECT.Width == 0 || hpRECT.Height == 0)
                {
                    MainForm form = Parent.Parent.Parent.Parent as MainForm;
                    form.StatusLabel.Text = "Status: Error! Cannot find life potion. Please try mystic size.";
                    return;
                }
                RECT absoluteLifeRECT = _isFullScreen ? GetAbsoluteRectBySnippingTool(hpRECT) : GetAbsoluteRectWhenNotFullScreen(hpRECT, HWnd);

                RECT mpRECT = ImageProcessing.GetMatchingImageLocation(bitmap, AttributeType.MP);
                if (mpRECT.Width == 0 || mpRECT.Height == 0)
                {
                    MainForm form = Parent.Parent.Parent.Parent as MainForm;
                    form.StatusLabel.Text = "Status: Error! Cannot find mana potion. Please try mystic size.";
                    return;
                }
                RECT absoluteManaRECT = _isFullScreen ? GetAbsoluteRectBySnippingTool(mpRECT) : GetAbsoluteRectWhenNotFullScreen(mpRECT, HWnd);

                RECT stmRECT = ImageProcessing.GetMatchingImageLocation(bitmap, AttributeType.STM);
                if (stmRECT.Width == 0 || stmRECT.Height == 0)
                {
                    MainForm form = Parent.Parent.Parent.Parent as MainForm;
                    form.StatusLabel.Text = "Status: Error! Cannot find stm potion. Please try mystic size.";
                    return;
                }
                RECT absoluteSTMRECT = _isFullScreen ? GetAbsoluteRectBySnippingTool(stmRECT) : GetAbsoluteRectWhenNotFullScreen(stmRECT, HWnd);

                refillPotData = GetPotRefillData(absoluteLifeRECT, absoluteManaRECT, absoluteSTMRECT);
            }

            User32.SetForegroundWindow(Handle);

            if (chkAutoPot.Checked)
            {
                State.SetRefillPotStrategy(new ActiveRefillPotStrategy(HWnd));
            }
        }