首页
社区
课程
招聘
[讨论]大神进来看看,关于微信跳一跳的
发表于: 2017-12-31 19:57 5495

[讨论]大神进来看看,关于微信跳一跳的

2017-12-31 19:57
5495
尝试刷一下微信跳一跳的分数,做了如下尝试:

1、监控request

猜测如下的request(sessionid是发帖时删的)是设置分数的,我按照如下格式设置分数发request,返回无异常,但是分数没有修改成功。求指导思路。
POST https://mp.weixin.qq.com/wxagame/wxagame_bottlereport HTTP/1.1
charset: utf-8
Accept-Encoding: gzip
referer: https://servicewechat.com/wx7c8d593b2c3a7703/3/page-frame.html
content-type: application/json
User-Agent: MicroMessenger/6.6.1.1220(0x26060133) NetType/WIFI Language/zh_CN
Content-Length: 400
Host: mp.weixin.qq.com
Connection: Keep-Alive
{
	"base_req": {
		"session_id": "XXX",
		"fast": 1,
		"client_info": {
			"platform": "android",
			"brand": "Xiaomi",
			"model": "MI 5s",
			"system": "Android 7.0"
		}
	},
	"report_list": [{
		"ts": 1514644685,
		"type": 1,
		"score": 1122,
		"best_score": 119,
		"break_record": 1,
		"duration": 87,
		"times": 366
	}]
}

2、通过adb模拟点击屏幕进行游戏。

通过颜色区分物体、识别目标,计算距离,模拟触摸。有时候目标很小时识别不了 ,差不多到八九百分就挂了 ,下面上图。求指导有没有什么好的图像识别算法可以适用本例。
如下是代码,求别喷,写的时候没想给别人看。
package Main;

import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class Main {

	private double v = 0.7075;

	public static void main(String[] args) throws Exception {
		File d = new File("./");
		File[] ds = d.listFiles();
		for (File tmp : ds) {
			if (tmp.getName().endsWith("png")) {
				tmp.delete();
			}
		}
		Main m = new Main();
		while (true) {
			try {
				m.getImage();
				m.load();
				Thread.sleep(100);
			} catch (Exception e) {
				e.printStackTrace();
				m.push(10.0);
			}
		}
	}

	private void getImage() throws Exception {
		Thread.sleep(1200);
		Process p = Runtime.getRuntime().exec("adb shell screencap -p /sdcard/1.png");
		p.waitFor();
		p = Runtime.getRuntime().exec("adb pull /sdcard/1.png .");
		p.waitFor();
	}

	private void push(double time) throws Exception {
		String exe = "adb shell input swipe 410 1720 410 1720 " + (int) time;
		Runtime.getRuntime().exec(exe);
		System.out.println(exe);
		Thread.sleep((long) (time + 720));
	}

	private int index = 0;
	private Color b = null;

	private String genFileName() {
		return "P_" + (index++) + ".png";
	}

	void mark(Point p, BufferedImage buff) {
		for (int y = -10; y < 10; y++) {
			for (int x = -10; x < 10; x++) {
				buff.setRGB((int) (x + p.getX()), (int) (y + p.getY()), Color.RED.getRGB());
			}
		}
	}

	void setBackground(BufferedImage buff) {
		b = new Color(buff.getRGB(500, 500));
		System.out.println("background RGB:" + b);
	}

	private void load() throws Exception {
		BufferedImage buff = ImageIO.read(new File("./1.png"));
		setBackground(buff);
		Point t = findTarget(buff), me = findMe(buff);
		System.out.println("target:" + t + " me:" + me);
		mark(t, buff);
		mark(me, buff);

		ImageIO.write(buff, "png", new File(genFileName()));

		double dis = Math.sqrt(
				(me.getX() - t.getX()) * (me.getX() - t.getX()) + (me.getY() - t.getY()) * (me.getY() - t.getY()));

		double time = dis / v;
		if (dis < 300) {
			System.out.println(String.format("distance plus from [%f] to [%f]-------------------", time, time + 100));
			time += 50;
		}
		push(time);
	}

	private boolean colorSame(int left, int mid, int right) {
		return colorSame(left, right) && colorSame(left, mid) && colorSame(mid, right);
	}

	private boolean colorSame(int left, int right) {
		Color l = new Color(left);
		Color r = new Color(right);
		return Math.abs(l.getRed() - r.getRed()) < 10 && Math.abs(l.getGreen() - r.getGreen()) < 10
				&& Math.abs(l.getBlue() - r.getBlue()) < 10;
	}

	public Point findTarget(BufferedImage buff) {
		int width = buff.getWidth();
		int step = 75;
		for (int y = 500; y < 1743; y++) {
			for (int x = 10; x < width - step - 1; x++) {
				int left = buff.getRGB(x, y);
				int right = buff.getRGB(x + step, y);
				int mid = buff.getRGB(x + step / 2, y);
				if (colorSame(left, mid, right) && !isBackGround(left) && !isBackGround(right) && !isBackGround(mid)) {
					// isBackGround(left);
					// isBackGround(left);
					return new Point(x + step / 2, y /*+ step * 1 / 2*/);
				}
			}
		}
		return null;
	}

	private boolean isBackGround(int rgb) {
		if (b == null) {
			int gray = this.gray(rgb);
			return gray < 235 && gray > 225;
		} else {
			Color t = new Color(rgb);
			return Math.abs(t.getRed() - b.getRed()) < 20 && Math.abs(t.getGreen() - b.getGreen()) < 20
					&& Math.abs(t.getBlue() - b.getBlue()) < 20;
		}
	}

	int gray(int rgb) {
		Color c = new Color(rgb);
		return (c.getRed() + c.getGreen() + c.getBlue()) / 3;
	}

	private Point findMe(BufferedImage buff) {
		int width = buff.getWidth(), height = buff.getHeight();
		for (int y = 700; y < 1743; y++) {
			for (int x = 10; x < width - 70 - 1; x++) {
				int left = buff.getRGB(x, y);
				int right = buff.getRGB(x + 70, y);
				if (isMe(left) && isMe(right) && !isBackGround(left) && !isBackGround(right)) {
					return new Point(x + 35, y);
				}
			}
		}
		return new Point(width, height);
	}

	private boolean isMe(int rgb) {
		Color a = new Color(rgb);
		return a.getRed() > 39 && a.getRed() < 60 && a.getGreen() > 39 && a.getGreen() < 60 && a.getBlue() > 70
				&& a.getBlue() < 98;
	}
}

下图是正常识别,打红点是mark函数做的


下面就识别不了,因为目标面太小。

物块颜色不完全一致。是否有颜色域过滤的算法、或者形状识别的算法呢?


[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 1
支持
分享
最新回复 (4)
雪    币: 201
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不知道微信小程序  的JavaScript是什么时候加载的,如果能看到js源码,事情就好说了。但我在监控网络的过程中没有看到类似浏览器Get  JavaScript代码的请求。有熟悉微信小程序的讲讲吗    或者给个链接?
2017-12-31 20:02
0
雪    币: 22
活跃值: (423)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
楼主加油~    期待你的大作~
2018-1-1 09:52
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
4
https://zhuanlan.zhihu.com/p/32473340
2018-1-1 15:03
0
雪    币: 70
活跃值: (71)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
我不懂js,感觉代码被混淆过了,你可以参考一下.

上传的附件:
2018-1-2 14:09
0
游客
登录 | 注册 方可回帖
返回
//