background

Js + Android devices accessible without Root

Implementation function: [the 10th anniversary of the Killing of The Three Kingdoms] Guild automatic drumming, temporarily only implemented this. You can update the other task logic later

Idea overview: With the help of OCR function, the page control disassembly, and page status analysis (task completion), and then click the button through auto-.js to complete the corresponding task.

Project directory

.├ ── ├─ package.json ├─ project.json ├── download.js // │ ├ ─ ─ demo / / OCR test using │ │ └ ─ ─ index. The js │ ├ ─ ─ img │ │ ├ ─ ─ WechatIMG604. Jpeg │ │ └ ─ ─ WechatIMG605. Jpeg │ └ ─ ─ page / / The page configuration information is analyzed and generated through OCR, mainly in JSON format. Record control information │ ├ ─ ─ the README. Md │ ├ ─ ─ gonghui / / guild page │ │ ├ ─ ─ gonghui. Js │ │ └ ─ ─ huodong. Js │ ├ ─ ─ shouye, js / / homepage │ └ ─ ─ wujiang / / ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├─ ├.js // ├.js // ├.js // ├─ ├─ ├.js // ├── ├─ ├─ ├.js // The following are all other tasks, not completedCopy the code

Logic implementation

Guild quest Logic

var utilJS = require(".. /lib/utilTool"); var utilTool = utilJS.utilTool; var shouye = require(".. /asset/page/shouye"); var gonghui = require(".. /asset/page/gonghui/gonghui"); var huodong = require(".. /asset/page/gonghui/huodong"); / / guild task function GonghuiTask () {} GonghuiTask. The prototype. The init = function () {utilTool. ClickButton (shouye, "guild"); // Internal method, click on a control utitool. clickButton(gonghui, "active "); while (! Utiol.findtext (" utiol.findText ") {// If there is utiol.findText (" utiol.findText ") {// If there is utiol.findText (huodong, "utiol.findText "); } utilTool.clickBack(); }; module.exports = { gonghuiTask: new GonghuiTask(), };Copy the code

The function is relatively simple, that is, after entering the home page, click the buttons such as guild and activity, and successfully enter the drum task page.

Then check the current task status, whether you can beat the drum.

This is the line utitool.findText (” consume $20″)

UtilTool.prototype.findText = function (text) { var page = this.captureWithOcr("basic"); // Get the screenshot of the current page and enable OCR analysis. Var result = page.find(function (item) {if (item.words == text) {return true; }}); return result; };Copy the code

The difficulties in analysis

In the mobile game version of SGS, control analysis cannot be carried out through auto-.js built-in tools, nor can click a button control through click(” activity “) frame method.

The entire game page is wrapped and all the attributes are not exposed, so it is not possible to locate the individual controls through text(“xx copy “) or other methods. Therefore, this script is to take baidu OCR network picture function for analysis

Baidu OCR has several different scenes, after debugging, network picture OCR is the most accurate in this scene, basically can accurately translate 90% of the text contentCopy the code

After the OCR call, the returned data content is stored in the /asset/ Page/folder (OCR is expensive and takes too long to return, so the data is cached beforehand instead of being called every time the script runs). The data format is as follows

Module. Exports = [{words: "exports ", location: {top: 0, left: 0, width: 0, height: 0}, chars: [],}, {words: 0, 0, 0} }, {words: "world ", location: {top: 29, left: 2136, width: 65, height: 32}, chars: [],}, {words:" world ", location: {top: }, chars: [],}, {words: "trace ", location: {top: 1007, left: 271, width: 100, height: 100}, chars: [],}, {words:" trace ", location: {top: 1007, left: 271, width: 182, height: 26}, chars: [],}, {words: "more ", location: {top: 1031, left: 1021, width: 54, height: 30}, chars: [],}, {words: "wrap ", location: {top: 1031, left: 1142, width: 55, height: 29}, chars: [],}, {words:" wrap ", location: {top: 1031, left: 1142, width: 55, height: 29}, chars: [],}, {words: {top: 1032, left: 1264, width: 57, height: 28}, chars: [],},... ;Copy the code

Data content mainly covers the corresponding text content, as well as text position, size and so on. With this data, we can achieve the desired effect. With auto-.js, we can make the script click on a certain area as we want. The specific method is as follows

/ / traversal location, click on the button UtilTool prototype. ClickButton = function (arrays, name) {var flag = false; for (var i = 0; i < arrays.length; i++) { var item = arrays[i]; If (item.words.includes(name)) {// If (item.location.left + item.location.width / 2, item.location.top + item.location.height / 2 ); Toast (" click button: "+ name); flag = true; sleep(1000); break; } } if (! Flag) {toast(" no traversal button "); }};Copy the code

At this point, the main logic of the script is described

conclusion

This code only to test OCR + Auto. Js, can achieve what script function. Now it seems that the effect should be good, other APP applications, can also refer to this logic, rapid script development.

In addition, such a simple task, can also use XX recording wizard and other tools to achieve, but in contrast, through the way of script development, will be more flexible. For example, when we want to judge the current task status, or page logic, we can use the function of script +OCR to quickly analyze, so as to implement the logic we want.

Code repository: github.com/qiangzi7723… This repository should not be updated later, only for validation use.

Note: After the warehouse is pulled to the local, it cannot run normally and lacks relevant Baidu Token