升级版跳一跳外挂

时间:2021-07-30 23:25:31

参考园子里 https://www.cnblogs.com/lggggg/p/8176033.html 这个文章里跳一跳思路,

把代码下载下来试了需要点击起点终点,很麻烦,而且终点鼠标点击不是很精准,连续

跳到正中心是要累加分的。所以也准备自己升级一下这个外挂。

 

最终效果图:

升级版跳一跳外挂

 

主要思路:

1、找小黑人中心点

2、鼠标点击一下终点,找到终点的正中心位置

3、根据起点终止坐标计算出应该按几秒再跳

这样保证90%以上都能跳到终点正中心,连续累加分。

 

关键代码:

1、执行adb方法

        private string cmdAdb(string arguments)
        {
            string ret = string.Empty;
            using (Process p = new Process())
            {
                p.StartInfo.FileName = this.textBox1.Text;
                p.StartInfo.Arguments = arguments;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;   //重定向标准输入   
                p.StartInfo.RedirectStandardOutput = true;  //重定向标准输出   
                p.StartInfo.RedirectStandardError = true;   //重定向错误输出   
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                ret = p.StandardOutput.ReadToEnd();
                p.Close();
            }
            return ret;
        }

2、获取图片和小黑人坐标

  private void GetImage()
        {
            var tempFileName = "1.png";
            cmdAdb("shell screencap -p /sdcard/" + tempFileName);
            cmdAdb("pull /sdcard/" + tempFileName);
            using (var temp = Image.FromFile(tempFileName))
            {
                pictureBox1.Invoke(new Action(() =>
                {
                    Bitmap bitmap = new Bitmap(temp);
                    //获取小黑人坐标
                    int Height = bitmap.Height;
                    int Width = bitmap.Width;
                    Color pixel;
                    var hei = Color.FromArgb(54, 60, 102);
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            pixel = bitmap.GetPixel(x, y);
                            if (pixel.R == hei.R && pixel.G == hei.G && pixel.B == hei.B)
                            {
                                if (Start.X == 0 || x > Start.X)
                                {
                                    Start = new Point(x, y);
                                }
                            }
                        }
                    }
                    if (Start.X > 0)
                    {
                        for (int i = -100; i < 100; i++)
                        {
                            bitmap.SetPixel(Start.X + i, Start.Y, Color.Blue);
                        }
                        for (int i = -100; i < 100; i++)
                        {
                            bitmap.SetPixel(Start.X, Start.Y + i, Color.Blue);
                        }
                        End = new Point(0, 0);
                    }
                    pictureBox1.Image = bitmap;
                }));
            }
            GC.Collect();
        }


3、鼠标点击终点时,获取终点中心坐标

   private void pictureBox1_Click(object sender, EventArgs e)
        {
            var me = ((System.Windows.Forms.MouseEventArgs)(e));

            End = ((System.Windows.Forms.MouseEventArgs)(e)).Location;
            GetEndPonit();
            if (Start.X > 0 && End.X > 0)
            {
                this.backgroundWorker1.RunWorkerAsync();
            }
}

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)        

{         

         //计算两点直接的距离            

         double value = Math.Sqrt(Math.Abs(Start.X - End.X) * Math.Abs(Start.X - End.X) + Math.Abs(Start.Y - End.Y) * Math.Abs(Start.Y - End.Y));       

         this.Text = value.ToString();

         cmdAdb(string.Format("shell input swipe 500 500 510 510 {0}", (value * Convert.ToDouble(this.numericUpDown1.Value)).ToString("0")));               End = Start = new Point(0, 0);      

         Thread.Sleep(800);           

        GetImage();        

}

 
 //获取终点中心坐标
        private void GetEndPonit()
        {
            int originalWidth = this.pictureBox1.Image.Width;
            int originalHeight = this.pictureBox1.Image.Height;

            PropertyInfo rectangleProperty = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
            Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox1, null);

            int currentWidth = rectangle.Width;
            int currentHeight = rectangle.Height;

            double rate = (double)currentHeight / (double)originalHeight;

            int black_left_width = (currentWidth == this.pictureBox1.Width) ? 0 : (this.pictureBox1.Width - currentWidth) / 2;
            int black_top_height = (currentHeight == this.pictureBox1.Height) ? 0 : (this.pictureBox1.Height - currentHeight) / 2;

            int zoom_x = End.X - black_left_width;
            int zoom_y = End.Y - black_top_height;
            Color pixel;
            var p = bitmap.GetPixel(End.X, End.Y);
            int left = Width;
            int right = 0;
            int top = Height;
            int bottom = 0;

            bool isFind = false;
            for (int y = End.Y; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    pixel = bitmap.GetPixel(x, y);
                    if (Math.Abs(pixel.R - p.R) < 5 && Math.Abs(pixel.G - p.G) < 5 && Math.Abs(pixel.B - p.B) < 5)
                    {                        isFind = true;
                        if (y > bottom)
                        {
                            bottom = y;
                        }
                        if (x > right)
                        {
                            right = x;
                        }
                        if (x < left)
                        {
                            left = x;
                        }
                        if (y < top)
                        {
                            top = y;
                        }
                    }
                }
                if (!isFind)
                {
                    break;
                }
                isFind = false;
            }
            for (int y = End.Y; y > 0; y--)
            {
                for (int x = 0; x < Width; x++)
                {
                    pixel = bitmap.GetPixel(x, y);
                    if (Math.Abs(pixel.R - p.R) < 5 && Math.Abs(pixel.G - p.G) < 5 && Math.Abs(pixel.B - p.B) < 5)
                    {
                        isFind = true;
                        if (y > bottom)
                        {
                            bottom = y;
                        }
                        if (x > right)
                        {
                            right = x;
                        }
                        if (x < left)
                        {
                            left = x;
                        }
                        if (y < top)
                        {
                            top = y;
                        }
                    }
                }
                if (!isFind)
                {
                    break;
                }
                isFind = false;
            }
            if (right > 0 && top > 0)
            {
                //画目标十字架
                for (int i = left; i < right; i++)
                {
                    bitmap.SetPixel(i, top + (bottom - top) / 2, Color.Blue);
                }
                for (int i = top; i < bottom; i++)
                {
                    bitmap.SetPixel(left + (right - left) / 2, i, Color.Blue);
                }
                End = new Point(left + (right - left) / 2, top + (bottom - top) / 2);
            }

else { End = new Point(0, 0); } pictureBox1.Image = bitmap; }