Ejemplo n.º 1
0
        /// <summary>
        /// Look for a Window named 'Clicker Heroes' and grab its rectangle.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void detectBtn_Click(object sender, EventArgs e)
        {
            // Find the Window
            var hwnd = Imports.FindWindow(null, "Clicker Heroes");

            // Get the RECT
            var rect = new Imports.RECT();
            var b    = Imports.GetClientRect(hwnd, out rect);

            if (b)
            {
                var point = new Imports.POINT();
                b = Imports.ClientToScreen(hwnd, ref point);
                if (b)
                {
                    // Set the playable area and update labels
                    //x y is supposed to be the top corner
                    Console.WriteLine("point.x: " + point.X); //top left corner x
                    Console.WriteLine("point.y: " + point.Y); //top left corner y
                    GameEngine.SetPlayableArea(new Rectangle(point.X, point.Y, rect.Right - rect.Left, rect.Bottom - rect.Top));

                    Point clickPoint = GameEngine.GetClickArea();
                    clickAreaLbl.Text = string.Format("{0}, {1}", clickPoint.X, clickPoint.Y);

                    if (GameEngine.ValidatePlayableArea())
                    {
                        Properties.Settings.Default.top   = point.Y;
                        Properties.Settings.Default.bot   = rect.Height + point.Y;
                        Properties.Settings.Default.left  = point.X;
                        Properties.Settings.Default.right = rect.Width + point.X;
                        Properties.Settings.Default.Save();
                        Console.WriteLine("We think top is " + Properties.Settings.Default.top + " bottom is " + Properties.Settings.Default.bot + " left is " + Properties.Settings.Default.left + " right is " + Properties.Settings.Default.right);
                        MessageBox.Show("Settings saved!");
                        return;
                    }
                }
            }
            getSettings();
            MessageBox.Show("Can't find game, please try again");
        }
        /// <summary>
        /// Look for a Window named 'Clicker Heroes' and grab its rectangle.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void detectBtn_Click(object sender, EventArgs e)
        {
            // Find the Window
            var hwnd = Imports.FindWindow(null, "Clicker Heroes");

            // Get the RECT
            var rect = new Imports.RECT();
            var b = Imports.GetClientRect(hwnd, out rect);
            if (b)
            {
                var point = new Imports.POINT();
                b = Imports.ClientToScreen(hwnd, ref point);
                if (b)
                {
                    // Set the playable area and update labels
                    //x y is supposed to be the top corner
                    Console.WriteLine("point.x: " + point.X); //top left corner x
                    Console.WriteLine("point.y: " + point.Y); //top left corner y
                    GameEngine.SetPlayableArea(new Rectangle(point.X, point.Y, rect.Right - rect.Left, rect.Bottom - rect.Top));

                    Point clickPoint = GameEngine.GetClickArea();
                    clickAreaLbl.Text = string.Format("{0}, {1}", clickPoint.X, clickPoint.Y);

                    if (GameEngine.ValidatePlayableArea())
                    {

                        Properties.Settings.Default.top = point.Y;
                        Properties.Settings.Default.bot = rect.Height + point.Y;
                        Properties.Settings.Default.left = point.X;
                        Properties.Settings.Default.right = rect.Width + point.X;
                        Properties.Settings.Default.Save();
                        Console.WriteLine("We think top is " + Properties.Settings.Default.top + " bottom is " + Properties.Settings.Default.bot + " left is " + Properties.Settings.Default.left + " right is " + Properties.Settings.Default.right);
                        MessageBox.Show("Settings saved!");
                        return;
                    }
                }
            }
            getSettings();
            MessageBox.Show("Can't find game, please try again");
        }
Ejemplo n.º 3
0
        //From neilmcguire on github; https://github.com/neilmcguire/ClickerHeroes_AutoPlayer/blob/Steam/GameEngine.cs
        //Used with background window support
        public static Bitmap GetImage(Rectangle rect)
        {
            if (Properties.Settings.Default.backgroundWindow && WindowHandle != IntPtr.Zero)
            {
                Imports.RECT rc;
                Imports.GetWindowRect(WindowHandle, out rc);

                Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
                Graphics gfxBmp = Graphics.FromImage(bmp);
                IntPtr hdcBitmap = gfxBmp.GetHdc();
                bool succeeded = Imports.PrintWindow(WindowHandle, hdcBitmap, 0);
                gfxBmp.ReleaseHdc(hdcBitmap);
                if (!succeeded)
                {
                    gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(Point.Empty, bmp.Size));
                }
                IntPtr hRgn = Imports.CreateRectRgn(0, 0, 0, 0);
                Imports.GetWindowRgn(WindowHandle, hRgn);
                Region region = Region.FromHrgn(hRgn);
                if (!region.IsEmpty(gfxBmp))
                {
                    gfxBmp.ExcludeClip(region);
                    gfxBmp.Clear(Color.Transparent);
                }
                gfxBmp.Dispose();

                var point = new Imports.POINT();
                Imports.ScreenToClient(WindowHandle, ref point);

                var windowPos = new Imports.RECT();
                Imports.GetWindowRect(WindowHandle, out windowPos);
                var origin = new Imports.POINT();
                Imports.ClientToScreen(WindowHandle, ref origin);

                rect.Offset(point.X, point.Y);
                rect.Offset(-windowPos.Left, -windowPos.Top);
                rect.Offset(origin.X, origin.Y);

                var img = bmp.Clone(rect, PixelFormat.Format32bppArgb);
                return img;
            }
            else
            {
                var bmp = new Bitmap(rect.Width, rect.Height);
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.CopyFromScreen(new Point(rect.Left, rect.Top), Point.Empty, rect.Size);
                }
                return bmp;
            }
        }
Ejemplo n.º 4
0
 public static void DoClick(Point p)
 {
     if (WindowHandle != IntPtr.Zero)
     {
         var pt = new Imports.POINT() { X = p.X, Y = p.Y };
         Imports.ScreenToClient(WindowHandle, ref pt);
         int coordinates = pt.X | (pt.Y << 16);
         Imports.PostMessage(WindowHandle, Imports.WM_LBUTTONDOWN, (IntPtr)0x1, (IntPtr)coordinates);
         System.Threading.Thread.Sleep(10);
         Imports.PostMessage(WindowHandle, Imports.WM_LBUTTONUP, (IntPtr)0x1, (IntPtr)coordinates);
     }
     else
     {
         Cursor.Position = p;
         Imports.mouse_event(Imports.MOUSEEVENTF_LEFTDOWN | Imports.MOUSEEVENTF_LEFTUP, (uint)p.X, (uint)p.Y, 0, 0);
     }
 }