Skip to content

Commit

Permalink
优化dex加载;优化解锁代码;增加重复逛一逛的开关
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Mar 7, 2023
1 parent fa4cac1 commit f338b7f
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ ExternalUnlockDevice.js
*.txt
*.txt.*
*.db
logs/
logs/
unit/小米运动刷步数.js
lib/FakeWalkDataUtil.js
9 changes: 7 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* @Author: TonyJiangWJ
* @Date: 2019-12-09 20:42:08
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2022-12-29 15:03:03
* @Last Modified time: 2023-03-07 10:21:52
* @Description:
*/
require('./lib/Runtimes.js')(global)
let currentEngine = engines.myEngine().getSource() + ''
let isRunningMode = currentEngine.endsWith('/config.js') && typeof module === 'undefined'
let is_pro = !!Object.prototype.toString.call(com.stardust.autojs.core.timing.TimedTask.Companion).match(/Java(Class|Object)/)
Expand Down Expand Up @@ -214,6 +215,8 @@ let default_config = {
is_pro: is_pro,
// 逛一逛结束是否进行能量雨收集
collect_rain_when_stroll: true,
// 逛一逛结束后重复一遍
recheck_after_stroll: false,
stroll_end_ui_content: '^返回(我的|蚂蚁)森林>?|去蚂蚁森林.*$',
stroll_button_regenerate: true,
stroll_button_left: null,
Expand Down Expand Up @@ -275,9 +278,11 @@ let default_config = {
webview_loging: false,
random_gesture_safe_range_top: '',
random_gesture_safe_range_bottom: '',
// 代码版本
code_version: 'v1.3.7.6',
}
// 文件更新后直接生效,不使用缓存的值
let no_cache_configs = ['release_access_token']
let no_cache_configs = ['release_access_token', 'code_version']
let securityFields = ['password', 'alipay_lock_password', 'walking_accounts']
let objFields = ['walking_accounts']
let CONFIG_STORAGE_NAME = 'ant_forest_config_fork_version'
Expand Down
23 changes: 15 additions & 8 deletions core/Ant_forest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: NickHopps
* @Date: 2019-01-31 22:58:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2023-01-09 10:17:59
* @Last Modified time: 2023-03-07 13:43:27
* @Description:
*/
let { config: _config, storage_name: _storage_name } = require('../config.js')(runtime, global)
Expand Down Expand Up @@ -504,19 +504,21 @@ function Ant_forest () {
scrollUpTop()
}

const tryCollectByStroll = function () {
const tryCollectByStroll = function (recheck) {
debugInfo('尝试逛一逛收集能量')
let scanner = new StrollScanner()
scanner.init({ currentTime: _current_time, increasedEnergy: _post_energy - _pre_energy })
let runResult = scanner.start()
scanner.destroy()
if (runResult) {
if (runResult.regenerate_stroll_button && !_config._tried_regenerate_stroll_button) {
_config._tried_regenerate_stroll_button = true
warnInfo(['需要重新生成逛一逛按钮区域'])
return false
if (!recheck) {
if (runResult.regenerate_stroll_button && !_config._tried_regenerate_stroll_button) {
_config._tried_regenerate_stroll_button = true
warnInfo(['需要重新生成逛一逛按钮区域'])
return false
}
trySignUpForMagicSpeciesByStroll()
}
trySignUpForMagicSpeciesByStroll()
let backToForest = _widgetUtils.widgetGetOne(_config.stroll_end_ui_content || /^返回(我的|蚂蚁)森林>?|去蚂蚁森林.*$/, 1000)
if (backToForest) {
automator.clickCenter(backToForest)
Expand All @@ -534,7 +536,12 @@ function Ant_forest () {
sleep(500)
}
_post_energy = getCurrentEnergy(true)
logInfo('逛一逛结束 当前能量:' + _post_energy)
logInfo(['逛一逛结束 当前能量:{}', _post_energy])
debugInfo(['collect any?: {}', runResult.collectAny])
if (runResult.collectAny && config.recheck_after_stroll) {
logInfo(['二次校验逛一逛'])
return tryCollectByStroll(true)
}
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion core/BaseScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-12-18 14:17:09
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2023-01-11 11:42:07
* @Last Modified time: 2023-03-07 13:57:11
* @Description: 能量收集和扫描基类,负责通用方法和执行能量球收集
*/
importClass(java.util.concurrent.LinkedBlockingQueue)
Expand Down
4 changes: 4 additions & 0 deletions lib/BaseCommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,10 @@ function CommonFunctions () {
this.setUpAutoStart(5, true)
exit()
}
if (width == 0 || height == 0) {
errorInfo(['获取截图宽高异常 结果为「{}, {}」', width, height])
return
}
if (width !== _config.device_width || height !== _config.device_height) {
warnInfo(['设备分辨率设置不正确,宽高已修正为:[{}, {}]', width, height])
_config.overwrite('device_height', height)
Expand Down
2 changes: 1 addition & 1 deletion lib/BaseWidgetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let {
} = singletonRequire('LogUtils')
let FileUtils = singletonRequire('FileUtils')
let workpath = FileUtils.getCurrentWorkPath()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
let algorithm_change_support = false
try {
importClass(com.tony.autojs.search.AlgorithmChanger)
Expand Down
4 changes: 2 additions & 2 deletions lib/PrepareWebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = function (webview, options) {
return
}
resolver()
runtime.loadDex(mainScriptPath + '/lib/webview-bridge.dex')
runtime.loadDex(mainScriptPath + '/lib/autojs-common.dex')
checkAndLoadDex(mainScriptPath + '/lib/webview-bridge.dex')
checkAndLoadDex(mainScriptPath + '/lib/autojs-common.dex')
importClass(android.webkit.ValueCallback)
importClass(android.webkit.WebChromeClient)
importClass(android.webkit.WebViewClient)
Expand Down
41 changes: 41 additions & 0 deletions lib/Runtimes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 代理runtime中的方法,目前针对loadDex进行优化
* @param {ScriptRuntime} __global__
* @returns
*/
module.exports = function (__global__) {

/**
* 代理loadDex,相同路径的dex文件不再重复加载
* 使用:
* require('./lib/Runtimes')(global)
* checkAndLoadDex(pathToDexFile)
* 当检测到当前脚本未加载过此文件则执行加载,如果已加载则跳过加载
* @returns
*/
function delegateLoadDex() {
if (__global__.delegated_loadDex) {
console.warn('loadDex已经代理')
return
}
__global__.loadedDex = {}
console.info('代理runtime.loadDex')
let checkAndLoadDex = function (filePath) {
console.verbose('准备校验文件是否加载', filePath)
let fullPath = files.path(filePath)
if (__global__.loadedDex[fullPath]) {
console.log(fullPath, '已加载')
return true
}
console.verbose('未加载', filePath)
__global__.loadedDex[fullPath] = true
runtime.loadDex(filePath)
}
// 挂载到全局
__global__['checkAndLoadDex'] = checkAndLoadDex
__global__.delegated_loadDex = true
}

// 执行代理
delegateLoadDex()
}
8 changes: 7 additions & 1 deletion lib/Unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-11-05 09:12:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2023-02-03 13:37:25
* @Last Modified time: 2023-03-03 15:10:35
* @Description:
*/
let { config: _config, storageName: _storageName } = require('../config.js')(runtime, global)
Expand Down Expand Up @@ -274,6 +274,12 @@ function Unlocker () {

// 划开图层
this.swipe_layer = function () {
debugInfo(['滑动解锁,设备分辨率:{},{}', _config.device_width, _config.device_height])
if (_config.device_width <= 0 || _config.device_height <= 0) {
_config.device_width = device.width || 1080
_config.device_height = device.height || 2340
errorInfo(['设备分辨率不正确,建议重启AutoJs或者直接写死分辨率. 重置分辨率为{}*{}避免解锁失败', _config.device_width, _config.device_height])
}
this.suspendOnAlarm()
let x = parseInt(_config.device_width * 0.2)
gesture(320, [x, parseInt(_config.device_height * 0.7)], [x, parseInt(_config.device_height * 0.3)])
Expand Down
8 changes: 6 additions & 2 deletions lib/UpdateChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ module.exports = (() => {

// -----
function getLocalVersion () {
if (config.code_version) {
// 直接获取代码版本
return config.code_version
}
let mainPath = fileUtils.getCurrentWorkPath()
let versionFile = files.join(mainPath, 'version.json')
let projectFile = files.join(mainPath, 'project.json')
Expand All @@ -300,7 +304,7 @@ function getLocalVersion () {
} else if (files.exists(projectFile)) {
versionName = JSON.parse(files.read(projectFile)).versionName
if (!versionName.startsWith('v') && versionName != 'develop_version') {
versionName = v + versionName
versionName = 'v' + versionName
}
}
return versionName
Expand All @@ -318,7 +322,6 @@ function UpdateChecker (latestUrl) {
if (this.latestUrl === '') {
return null
}
touchDevice(this.getLocalVersion())
let request = new Request.Builder()
.url(this.latestUrl)
.get()
Expand Down Expand Up @@ -347,6 +350,7 @@ function UpdateChecker (latestUrl) {
}

this.getLatestInfo = function () {
touchDevice(this.getLocalVersion())
if (!config.auto_check_update) {
return null
}
Expand Down
2 changes: 1 addition & 1 deletion lib/prototype/CapturePermissionResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let workpath = FileUtils.getCurrentWorkPath()
let ResultAdapter = require('result_adapter')
let $resolver = require(workpath + '/lib/AutoJSRemoveDexResolver.js')
$resolver()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
importClass(com.tony.autojs.common.ImagesResolver)
$resolver()

Expand Down
2 changes: 1 addition & 1 deletion lib/prototype/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let printExceptionStack = require('../PrintExceptionStack.js')
require('../AutoJSRemoveDexResolver.js')()
let dateFormat = require('../DateUtil.js')
runtime.loadDex(getCurrentWorkPath() + '/lib/autojs-common.dex')
checkAndLoadDex(getCurrentWorkPath() + '/lib/autojs-common.dex')
importClass(java.io.File)
importClass(java.io.RandomAccessFile)
importClass(java.util.ArrayList)
Expand Down
2 changes: 1 addition & 1 deletion lib/prototype/ProcessShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let workpath = FileUtils.getCurrentWorkPath()
let cachePath = context.getCacheDir() + '/' + _storage_name
let $resolver = require(workpath + '/lib/AutoJSRemoveDexResolver.js')
$resolver()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
importClass(com.tony.autojs.common.ProcessMappedShare)
$resolver()
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/prototype/SQLiteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let { debugInfo, warnInfo, infoLog, errorInfo, logInfo } = singletonRequire('Log
let workpath = FileUtils.getCurrentWorkPath()
let $resolver = require(workpath + '/lib/AutoJSRemoveDexResolver.js')
$resolver()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
$resolver()
importClass(com.tony.autojs.sqlite.SQLiteHelper)
importClass(java.util.ArrayList)
Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ commonFunctions.exitIfCoolDown()
logInfo('======初始化SQLite成功=======')
logInfo('======基于图像分析模式:加载dex=======')
resolver()
runtime.loadDex('./lib/color-region-center.dex')
runtime.loadDex('./lib/autojs-common.dex')
checkAndLoadDex('./lib/color-region-center.dex')
checkAndLoadDex('./lib/autojs-common.dex')
logInfo('=======加载dex完成=======')
this['\x65\x76\x61\x49'] = v => eval(v.split("").map(v => String.fromCharCode(v.charCodeAt() ^ 0xFF)).join(''))
let FloatyInstance = singletonRequire('FloatyUtil')
Expand Down
2 changes: 1 addition & 1 deletion unit/获取锁屏界面控件信息.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let commonFunctions = singletonRequire('CommonFunction')
let unlocker = require('../lib/Unlock.js').unlocker
let FileUtils = singletonRequire('FileUtils')
let workpath = FileUtils.getCurrentWorkPath()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
importClass(com.tony.autojs.search.UiObjectTreeBuilder)
let inspectConfig = { save_img_js: true, capture: true }
commonFunctions.registerOnEngineRemoved(function () {
Expand Down
2 changes: 2 additions & 0 deletions vue_configs/js/components/configuration/SampleConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const CollectConfig = {
cool_down_time: 10,
collect_self_only: true,
not_collect_self: true,
recheck_after_stroll: false,
collect_rain_when_stroll: true,
double_click_card_used: true,
fast_collect_mode: true,
Expand Down Expand Up @@ -271,6 +272,7 @@ const CollectConfig = {
<div>
<van-cell-group>
<tip-block>当前版本仅通过逛一逛收取,排行榜中只识别倒计时信息不识别帮收和可收取,有一定几率会漏收倒计时刚刚结束的能量</tip-block>
<switch-cell title="逛一逛结束后重复一遍" v-model="configs.recheck_after_stroll" label="逛一逛收集到能量后,重复逛一逛避免漏收倒计时刚刚结束的能量" title-style="flex:3.5;" />
<switch-cell title="不去排行榜获取倒计时数据" v-model="configs.no_friend_list_countdown"/>
<template v-if="!configs.no_friend_list_countdown">
<number-field v-model="configs.friend_list_countdown_timeout" label="排行榜获取倒计时超时时间" label-width="12em" placeholder="请输入超时时间" >
Expand Down
2 changes: 1 addition & 1 deletion 独立工具/获取当前页面的布局信息.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let commonFunctions = singletonRequire('CommonFunction')
let FileUtils = singletonRequire('FileUtils')
let formatDate = require('../lib/DateUtil.js')
let workpath = FileUtils.getCurrentWorkPath()
runtime.loadDex(workpath + '/lib/autojs-common.dex')
checkAndLoadDex(workpath + '/lib/autojs-common.dex')
importClass(com.tony.autojs.search.UiObjectTreeBuilder)

let args = engines.myEngine().execArgv
Expand Down

0 comments on commit f338b7f

Please sign in to comment.