目前开发的所有代码都已经上传到了GitHub。欢迎大家来Star
https://github.com/GiantLiu/AutoJump
目前程序分为“全自动版本”和“半自动版本”
全自动版本
WeChat.AutoJump.CMDApp
当手机连接好后,打开微信跳一跳
点击"开始游戏"后。运行此程序。就可以实现自动跳了
半自动版本
此版本需要鼠标左键点小黑人的底部,鼠标右键点目标位的中心
然后程序就会自动跳到相应的位置
程序原理
1。将手机点击到《跳一跳》小程序界面;点击“开始游戏”后
2。用Adb工具获取当前手机的截图,半下载到本地
3.1。如果是半自动版本,那么就要用鼠标左右键来点击起始和目标位置
然后程序会自动算出要跳动的距离与要点击屏幕的时间。
3.2。如果是全自动版本,那么程序会自动算出小黑人的位置与目标的中心点,
然后自动算距离与点击屏幕的时间。
4。用Adb工具向手机发送点击屏幕蓄力命令,完成一次跳动
目前程序只能支持Android设备,IOS设备只写了接口,还没有实现
步骤:
- 安卓手机打开USB调试,设置》开发者选项》USB调试
- 电脑与手机USB线连接,确保执行
adb devices可以找到设备id
- 界面转至微信跳一跳游戏,点击开始游戏
运行自动/半自动版本程序,就可以开始游戏之路
代码关键实现
1。通过adb拿到手机的屏幕截图,其实就是向手机发送相关的命令
第一条命令是把屏幕的截图以png格式保存到手机SD卡
第二条命令是把手机SD卡里面的图片下载到本地硬盘对应的目录
第三条命令是把手机里的截图删除
第四条命令是发送屏幕按压命令 从X:100,Y:100这个位置向X200,Y:200这个位置移动,其中时间为500毫秒
adb shell screencap -p /sdcard/1.png adb pull /sdcard/1.png D:/Download/ adb shell rm /sdcard/1.png adb shell input swipe 100 100 200 200 500
这里是.net发送命令相关代码
public string AdbCommand(string arg) { using (Process process = new Process()) { var adbDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AndoridAdb"); var adbPath = Path.Combine(adbDirectoryPath, "adb.exe"); process.StartInfo.FileName = adbPath; process.StartInfo.Arguments = arg; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; //重定向标准输入 process.StartInfo.RedirectStandardOutput = true; //重定向标准输出 process.StartInfo.RedirectStandardError = true; //重定向错误输出 process.StartInfo.CreateNoWindow = true; process.Start(); var result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); process.Close(); return result; } }
2。如果是半自动版本,那么要先鼠标左键点小黑人的底部,然后鼠标右键点目标位置的中间。
点完右键后。程序会自动算出两点之间距离与时间。然后就跳一步了。这个没有什么技术问题
3。如果是全自动版本,那反第一步,你拿到屏幕截图后。要分析出小黑人的位置
我这里的话。就用了EmguCV (OpenCV的.net调用)。
我们可以用到OpenCV的模板匹配。MatchTemplate方法
模板的话。随便找一张屏幕截图,用PS把小黑人扣出来。保存为图片就可以了
MatchTemplate会找出匹配最高的点。然后给出坐标,这样,我们就可以算出小黑人的中心位置了
var tempGrayPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "Current.png"); var tempGrayImg = new Image<Rgb, byte>(tempGrayPath); var match = img.MatchTemplate(tempGrayImg, TemplateMatchingType.CcorrNormed); double min = 0, max = 0; Point maxp = new Point(0, 0);//最好匹配的点 Point minp = new Point(0, 0); CvInvoke.MinMaxLoc(match, ref min, ref max, ref minp, ref maxp); Console.WriteLine(min + " " + max); CvInvoke.Rectangle(img, new Rectangle(maxp, new Size(tempGrayImg.Width, tempGrayImg.Height)), new MCvScalar(0, 0, 255), 3); var startPoint = new Point(); startPoint.X = maxp.X + (int)(tempGrayImg.Width / 2.0); startPoint.Y = maxp.Y + tempGrayImg.Height - 2; CvInvoke.Rectangle(img, new Rectangle(startPoint, new Size(1, 1)), new MCvScalar(0, 0, 0), 3);