Python WeChat jump game auxiliary code parsing, python code

Source: Internet
Author: User

Python assisted code parsing and python code

This Code enables you to manually click the start and end points, and the program automatically determines the distance and touch-screen time to complete the jump.

Principles (from the project description page ):

1. Click the cell phone to the "hop-on" applet interface;

2. Use the Adb tool to get the current mobile phone and use adb to bring pull up:

Adb shell screencap-p/sdcard/1.png

Adb pull/sdcard/1.png.

3. Display with matplot;

4. Click the start point and target location with the mouse to calculate the pixel distance;

5. Calculate the compression time based on the pixel distance;

6. Use the Adb tool to click on the screen and jump:

Adb shell input swipe x y time

Environment preparation (window7 ):

1. Download and install python3

2. pip Installation

In the cmd window, enter the script folder under the python3 root directory,

Execute Command

In this case, the scriptsfolder contains a series of pipdoc files, including pip.exe.

Add the pip.exe PATH to the environment variable PATH.

Enter "pip" in cmd. If the "pip" command can be identified, it indicates that pip has been installed successfully.

3. adb Driver Installation

Adb drive: https://adb.clockworkmod.com/

After the download, add the adb command to the system environment variable.

Open the CMD console and enter adb. The following page is displayed, indicating that the configuration is successful.

4. Download source code

In this step, we need to download the source code to the local computer.

Github address: https://github.com/wangshub/wechat_jump_game

5. Install the dependency package

Running,
Therefore, execute the command pip install-r requirements.txt to download these required modules, including matplotlib and numpy.

, We use the CD command to switch to the download directory of the source code,

Run pip install-r requirements.txt.

6. Set mobile phone Permissions

Connect your Android phone to your computer by using USB, enable developer mode on your Android phone, and enable USB debugging mode. The method for enabling each Android phone is different. Take Xiaomi Mix2 as an example, find the mobile phone version number in settings, click 5 times in a row to enable the developer mode, then enter the developer option to Enable usb debugging, usb debugging (security settings ),

If there are no errors in the preceding operations, execute the command adb devices on the CMD console to display the port number connected to the current mobile phone.

7. Run

In the absence of any errors in the above steps, open, start the hop-on game, go to the game homepage, then open the CMD console, and use the CD command to switch the directory, switch to the source code directory of the next hop and run wechat_jump_auto.py.

For parameter adjustment, open the config folder under the source code Directory, which contains folders for various screens and models. Click to enter the corresponding folder based on your own resolution or model, and open the config. json file. Modify the parameters. We recommend that you back up one copy before modification.

Import numpy as npimport matplotlib. pyplot as pltimport matplotlib. animation as animationfrom PIL import Imageimport mathimport timeimport osdef pull_screenshot (): defines the screenshot of the phone screen and sends it to the computer function OS. system ('adb shell screencap-p/sdcard/autojump.png ') sends the screenshot command to the mobile OS. system ('adb pull/sdcard/autojump.png. ') Send and pull the image to the computer command def jump (distance): defines the hop function parameter as the distance from press_time = distance * 1.35, and calculates by screen time press_time = int (press_time) cmd = 'adb shell input swipe 320 410 320 410 '+ str (press_time) press the screen command print (cmd) OS. system (cmd) send by screen command fig = plt. figure () creates an Image object (window) index = 0cor = [0, 0] pull_screenshot () execute the screenshot function img = np.array(Image.open('autojump.png ') Image. open reads the image to the Image array named img update = True click_count = 0cor = [] def update_data (): defines the function for updating data to update the image return np.array(Image.open('autojump.png ') im = plt. imshow (img, animated = True) im = draw an image (array name, animation = open) def updatefig (* args): define the animation function global update if update: time. sleep (1.5) pull_screenshot () im. set_array (update_data () update = False return im, def onClick (event): defines the mouse click processing function global update global ix, iy global click_count global cor # next screenshot ix, iy = event. xdata, event. ydata coords = [] coords. append (ix, iy) [(x1, y1) | (x2, y2)] print ('now = ', coords) cor. append (coords) [[(x1, y1)], [(x2, y2)] click_count + = 1 if click_count> 1: click_count = 0 cor1 = cor. pop () [(x2, y2)] cor2 = cor. pop () [(x1, y1)] distance = (cor1 [0] [0]-cor2 [0] [0]) ** 2 + (cor1 [0] [1]-cor2 [0] [1]) ** 2
X2-x1 y2-y1 distance = distance ** 0.5 print ('distance = ', distance) jump (distance) update = Truefig. canvas. mpl_connect ('button _ press_event ', onClick) Click the processing function onClick ani = animation. funcAnimation (fig, updatefig, interval = 50, bval = True)
Image function animation function update frequency 50 ms update all points plt. show () display image

Running result:

Python wechat_jump_py3.py

 

Send the first line

2. Click the mouse for the first time to generate coordinates.

3. The second mouse clicks to generate coordinates

4. computing distance

5. The four parameters following the "send and click" screen command "swipe are (sliding start point x y sliding end point x y sliding time)

First click

Second click

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.