微信跳一跳(adb+py)

25
Jan

微信跳一跳(adb+py)

事情是这样的:
zzq发了一张图片给我

然后我就...
是键盘先动的手!!!


环境

win10+夜神模拟器+三星S8+wechat_jump.py


win10安装adb

折腾了很久,其实直接下载下来解压就行了
adbshell手册http://adbshell.com/
我直接放在桌面了 因为不常用adb(/Desktop/adb)
这里有个坑 需要先看一下adb的版本号adb version 必须要和模拟器nox_adb版本号相同,不然执行会要报错(后面要讲QAQ)


夜神模拟器

必须开启开发者模式
设置-关于平板电脑-多次点击版本号
退回到设置目录-开发者选项-USB调试模式
然后在win10本机命令行执行adb devices
发现adb连不上模拟器
报错信息:

C:\Users\A1in\Desktop>adb devices
List of devices attached
adb server version (31) doesn't match this client (36); killing...
* daemon started successfully *

解决方案:

  1. 关掉adb和夜神模拟器,在任务管理器下,结束adb.exe和nox_adb.exe这两个进程
  2. 找到adb的目录和夜神模拟器的目录,将夜神模拟器的adb.exe复制到adb的目录下
  3. 这样就adb目录下的adb.exe和模拟器下的adb.exe文件就完全同步了,版本号也一致了

再次执行adb devices
发现虽然不报错了 但是还是显示无配置连接
突然想到翻夜神文件夹时,在\Nox\bin文件夹自带了nox_adb.exe
尝试直接用nox_adb.exe 连接夜神 直接成功了
orz 我绕了地球一圈后来发现要找的东西就在脚下...
nox_adb连接模拟器成功,模拟器微信也安装了
然后打开微信-进入跳一跳 发现闪退 闪退 闪退???:alien:
网上的方法都尝试过了(关闭root/调试显卡渲染模式/性能设置/机型设置)
后来知道好像是夜神模拟器中微信跳一跳已封禁...


adb+S8=起飞

然后我妥协了...
向凌同学借了他的S8...
adb devices秒连

adb shell 秒root

(当然S8也是要开启开发者模式-USB调试模式的)


wechat_jump.py

# coding: utf-8
import math
import os
import tempfile
import time
from functools import reduce
from PIL import Image

BACKGROUND_POS = (40, 500)
DISTANCE_TO_TIME_RATIO = 1.35
SCREENSHOT_PATH = tempfile.gettempdir() + "/screenshot.png"

def calculate_jump_distance():
    im = Image.open(SCREENSHOT_PATH)
    background_rgb = im.getpixel(BACKGROUND_POS)
    role_pos_list = None
    vertex1_pos = None
    block_background_rgb = None
    vertex2_pos = None
    role_line_flag = True
    for y in range(BACKGROUND_POS[1], im.height):
        if role_pos_list and role_line_flag:
            break

        role_line_flag = True
        vertex2_line_flag = True
        for x in range(BACKGROUND_POS[0], im.width):
            current_rgb = im.getpixel((x, y))
            next_rgb = im.getpixel((x + 1, y)) if x + 1 < im.width else (0, 0, 0)

            # 识别顶点1
            if x > BACKGROUND_POS[0] and y > BACKGROUND_POS[1] and not vertex1_pos and not is_similar(background_rgb, current_rgb) and is_similar(current_rgb, next_rgb):
                vertex1_pos = (x, y)
                block_background_rgb = current_rgb

            # 识别顶点2
            if block_background_rgb and vertex2_line_flag and is_similar(current_rgb, block_background_rgb, 5):
                vertex2_line_flag = False
                if vertex2_pos:
                    if x < vertex2_pos[0] and vertex2_pos[0] - x < 20 and y - vertex2_pos[1] < 20:
                        vertex2_pos = (x, y)
                else:
                    vertex2_pos = (x, y)

            # 识别小人
            if is_part_of_role(current_rgb):
                if role_line_flag:
                    role_pos_list = []
                    role_line_flag = False
                role_pos_list.append((x, y))

    if len(role_pos_list) == 0:
        raise Exception('无法识别小人位置!!!')
    pos_sum = reduce((lambda o1, o2: (o1[0] + o2[0], o1[1] + o2[1])), role_pos_list)
    role_pos = (int(pos_sum[0] / len(role_pos_list)), int(pos_sum[1] / len(role_pos_list)))
    destination_pos = (vertex1_pos[0], vertex2_pos[1])
    return int(linear_distance(role_pos, destination_pos))

def is_part_of_role(rgb):
    return 53 < rgb[0] < 59 and 57 < rgb[1] < 61 and 95 < rgb[2] < 103
def linear_distance(xy1, xy2):
    return math.sqrt(pow(xy1[0] - xy2[0], 2) + pow(xy1[1] - xy2[1], 2))
def is_similar(rgb1, rgb2, degree=10):
    return abs(rgb1[0] - rgb2[0]) <= degree and abs(rgb1[1] - rgb2[1]) <= degree and abs(rgb1[2] - rgb2[2]) <= degree
def screenshot():
    os.system("adb shell screencap -p /mnt/sdcard/screencap.png")
    os.system("adb pull /mnt/sdcard/screencap.png {} >> {}/jump.out".format(SCREENSHOT_PATH, tempfile.gettempdir()))
def jump(touch_time):
    os.system("adb shell input swipe 0 0 0 0 {}".format(touch_time))
def distance2time(distance):
    return int(distance * DISTANCE_TO_TIME_RATIO)

if __name__ == '__main__':
    count = 1
    while True:
        screenshot()
        distance = calculate_jump_distance()
        touch_time = distance2time(distance)
        jump(touch_time)
        print("#{}: distance={}, time={}".format(count, distance, touch_time))
        count += 1
        time.sleep(1)

运行需要安装PIL(pip install Pillow)


你想要多少分呀

已有 2 条评论

  1. 你的爸爸Lion Ei'Jonson

    牛逼,学习了,我也想变强

    时间: 2018-01-26 at 17:02 回复
  2. 你的爷爷Sariel.D
    你的爷爷Sariel.D

    牛逼,学习了,我也想变强

    时间: 2018-03-20 at 14:39 回复

添加新评论