# ScriptLib **Repository Path**: javadevelopuser_admin/ScriptLib ## Basic Information - **Project Name**: ScriptLib - **Description**: 适用于 16+:9 比例分辨率的手游脚本多分辨率适配插件 for AutoJs - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 27 - **Created**: 2024-03-09 - **Last Updated**: 2024-03-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ScriptLib # 注意: 项目已停止维护! **适用于 16+:9 比例分辨率的手游脚本多分辨率适配插件 for AutoJs** 建议在720x1280p分辨率配合图色助手取色 图色助手: https://gitee.com/yiszza/ScriptGraphicHelper/releases 不保证适用于所有游戏, 使用前请测试 取点时先观察控件的布局, 可能是居中, 或者是靠左或者是靠右, 然后进行取色
# **多分辨率适配原理简单解析** 明日方舟720x1280与720x1560分辨率下的对比 ![截图](screenshot/screen_1.png)
# **请我喝杯咖啡?**
# **初始化** ``` const none = -1; //定义常量 const left = 0; const center = 1; const right = 2; //申请截图 if (!requestScreenCapture(true)) { alert("请求截图权限失败"); exit(); } //加载dex runtime.unloadDex(".//scriptlib.dex") runtime.loadDex(".//scriptlib.dex") //导入类 importClass(com.scriptlib.AnchorGraphicHelper); ```
# **API** ## **AnchorGraphicHelper class** | 返回值 | 方法 | 描述 | | :------------------------- | ---------------------------------------------------- | :----------------------------- | | static AnchorGraphicHelper | [Create](#创建实例) | 创建实例 | | static String | [Version](#获取版本号) | 获取版本号 | | void | [ReInitialize](#重新初始化环境) | 重新初始化环境 | | boolean | [KeepScreen](#获取截图数据到数组) | 获取截图数据到数组 | | void | [GetRedList](#获取所有r值对应的坐标) | 获取所有r值对应的坐标 | | byte[] | [GetScreenData](#获取图像数据) | 获取图像数据 | | Bitmap | [GetBitmap](#获取bitmap) | 获取bitmap | | int[] | [GetPixel](#获取指定像素数据) | 获取指定像素数据 | | String | [GetPixelStr](#获取指定像素数据<`String`>) |获取指定像素数据<`String`>| | int | [GetPixelHex](#获取指定像素数据<`int`>) |获取指定像素数据<`int`>| | int[] | [GetRange](#获取与运行分辨率相关的范围) | 获取与运行分辨率相关的范围 | | Point | [GetPoint](#获取与运行分辨率相关的坐标) | 获取与运行分辨率相关的坐标 | | `int[][]` | [GetFindColorArray](#获取与运行分辨率相关的找色色组) | 获取与运行分辨率相关的找色色组 | | Point | [FindMultiColor](#多点找色) | 多点找色 | | `List` | [FindMultiColorEx](#多点找色返回所有坐标) | 多点找色返回所有坐标 | | Point | [FindMultiColorLoop](#条件循环多点找色) | 条件循环多点找色 | | `int[][]` | [GetCmpColorArray](#获取与运行分辨率相关的比色色组) | 获取与运行分辨率相关的比色色组 | | boolean | [CompareColor](#单点比色) | 单点比色 | | boolean | [CompareColorEx](#多点比色) | 多点比色 | | boolean | [CompareColorExLoop](#条件循环多点比色) | 条件循环多点比色 |
### 创建实例 static AnchorGraphicHelper Create(Object obj, int devWidth, int devHeight, int left, int top, int right, int bottom); 静态构造函数, 当初始化失败时返回null | 参数 | 描述 | | --------- | --------------------- | | obj | autojs.runtime | | devWidth | 开发分辨率 宽 | | devHeight | 开发分辨率 高 | | left | 运行分辨率布局 startX | | top | 运行分辨率布局 startY | | right | 运行分辨率布局 endX | | bottom | 运行分辨率布局 endY | 例子: ``` let helper = AnchorGraphicHelper.Create(runtime, 1280, 720, 0, 0, width - 1, height - 1); if(helper == null){ alert("插件初始化失败!"); return; } ```
### 获取版本号 static String Version(); 例子: ``` print(AnchorGraphicHelper.Version()); ```
### 重新初始化环境 void ReInitialize(); 使用KeepScreen(bitmap, bool)方法后, 如果需要调用KeepScreen(bool), 请先调用ReInitialize()方法 例子: ``` helper.ReInitialize(); ```
### 获取截图数据到数组 boolean KeepScreen(boolean sign); 从屏幕获取截图数据到数组 | 参数 | 描述 | | ---- | -------------------- | | sign | 是否需要调用多点找色 | boolean KeepScreen(Bitmap bitmap, boolean sign); 从图片获取数据到数组, 只推荐用于测试 | 参数 | 描述 | | ------ | -------------------------------------------------------- | | bitmap | android.Graphic.Bitmap对象, 这个对象需要你使用后自行释放 | 例子: ``` helper.KeepScreen(true); let fis = new FileInputStream(file_name); let bitmap = BitmapFactory.decodeStream(fis); helper.KeepScreen(bitmap, true); fis.close(); bitmap.recycle(); ```
### 获取所有r值对应的坐标 void GetRedList(); 例子: ``` helper.GetRedList(); ```
### 获取图像数据 byte[] GetScreenData(); 返回当前图像数据 例子: ``` let bytes = helper.GetScreenData(); ```
### 获取bitmap Bitmap GetBitmap(); Bitmap GetBitmap(int sx, int sy, int ex, int ey); | 参数 | 描述 | | ---- | ------------------ | | sx | 当前分辨率的startX | | sy | 当前分辨率的startY | | ex | 当前分辨率的endX | | ey | 当前分辨率的endY | 返回当前Bitmap, 这个对象需要你使用后自行释放 例子: ``` let bitmap1 = helper.GetBitmap(); let bitmap2 = helper.GetBitmap(0,0,200,200); //some codes bitmap1.recycle(); bitmap2.recycle(); ```
### 获取指定像素数据 int[] GetPixel(int x, int y, int mode); | 参数 | 描述 | | ---- | ------------- | | x | 开发分辨率的x | | y | 开发分辨率的y | | mode | 坐标对齐方式 | 例子: ``` let pixel = helper.GetPixel(50,50,left); ```
### 获取指定像素数据<`String`> String GetPixelStr(int x, int y, int mode); 例子: ``` let pixel = helper.GetPixelStr(50,50,center); ```
### 获取指定像素数据<`int`> int GetPixelHex(int x, int y, int mode); 例子: ``` let pixel = helper.GetPixelHex(50,50,right); ```
### 获取与运行分辨率相关的范围 int[] GetRange(int sx, int sy, int ex, int ey, int mode) | 参数 | 描述 | | ---- | ------------------ | | sx | 开发分辨率的startX | | sy | 开发分辨率的startY | | ex | 开发分辨率的endX | | ey | 开发分辨率的endY | | mode | 坐标对齐方式 | int[] GetRange(int sx, int sy, int smode, int ex, int ey, int emode); | 参数 | 描述 | | ----- | -------------------- | | smode | sx和sy的坐标对齐方式 | | emode | sx和sy的坐标对齐方式 | 例子: ``` let range1 = helper.GetRange(100, 100, 500, 500, center); let range2 = helper.GetRange(100, 100, left, 500, 500, right); ```
### 获取与运行分辨率相关的坐标 Point GetPoint(int x, int y, int mode); | 参数 | 描述 | | ---- | ------------- | | x | 开发分辨率的x | | y | 开发分辨率的y | | mode | 坐标对齐方式 | 例子: ``` let point = helper.GetRange(100, 100, center); ```
### 获取与运行分辨率相关的找色色组 `int[][]` GetFindColorArray(String description); | 参数 | 描述 | | ----------- | -------------- | | description | 锚点色组字符串 | 例子: ``` let desc = "1080,1920,left|113|301|0x37474f,center|697|320|0x37474f,center|565|617|0xfafafa,left|238|384|0x37474f"; let findColorArray = helper.GetFindColorArray(desc); ``` `int[][]` GetFindColorArray(int devWidth, int devHeight, `int[][]` description); | 参数 | 描述 | | ----------- | ------------- | | devWidth | 开发分辨率 宽 | | devHeight | 开发分辨率 高 | | description | 锚点色组 | 例子: ``` let desc = [1280, 720, [ [center, 106, 72, 0xb1833a], [center, 161, 68, 0xc49143], [center, 568, 92, 0xd6b89c], [center, 697, 84, 0xdcc4aa], [center, 1033, 643, 0x41343c] ] ]; let findColorArray = helper.GetFindColorArray(desc[0],desc[1],desc[2]); ```
### 多点找色 Point FindMultiColor(int[] range, `int[][]` description, int sim, boolean offset); Point FindMultiColor(int sx, int sy, int ex, int ey, `int[][]` description, int sim, boolean offset); | 参数 | 描述 | | ----------- | ------------------ | | sx | 运行分辨率的startX | | sy | 运行分辨率的startY | | ex | 运行分辨率的endX | | ey | 运行分辨率的endY | | description | 色组描述 | | sim | 相似度 | | offset | 是否偏移查找 | 例子: ``` let result = helper.FindMultiColor(0, 0, 1000, 500, findColorArray, 95, 0); ```
### 多点找色返回所有坐标 `List` FindMultiColorEx(int[] range, `int[][]` description, int sim); `List` FindMultiColorEx(int[] range, `int[][]` description, int sim, int filterNum); `List` FindMultiColorEx(int sx, int sy, int ex, int ey, `int[][]` description, int sim); `List` FindMultiColorEx(int sx, int sy, int ex, int ey, `int[][]` description, int sim, int filterNum); `List` FindMultiColorEx(int[] range, `int[][]` description, int sim, int filterNum, boolean offset); `List` FindMultiColorEx(int sx, int sy, int ex, int ey, `int[][]` description, int sim, boolean offset); `List` FindMultiColorEx(int sx, int sy, int ex, int ey, `int[][]` description, int sim, int filterNum, boolean offset); | 参数 | 描述 | | ----------- | ------------------------------ | | sx | 运行分辨率的startX | | sy | 运行分辨率的startY | | ex | 运行分辨率的endX | | ey | 运行分辨率的endY | | description | 色组描述 | | sim | 相似度 | | filterNum | 过滤半径, 默认-1, 去除重叠区域 | | filterNum | 是否偏移查找 | 例子: ``` let result = helper.FindMultiColorEx(0, 0, 1000, 500, findColorArray, 95); ```
### 条件循环多点找色 Point FindMultiColorLoop(int[] range, int[][] description, int sim, boolean offset, long timeout, long timelag, int sign); Point FindMultiColorLoop(int sx, int sy, int ex, int ey, int[][] description, int sim, boolean offset, long timeout, long timelag, int sign); | 参数 | 描述 | | ----------- | -------------------------------------------- | | sx | 运行分辨率的startX | | sy | 运行分辨率的startY | | ex | 运行分辨率的endX | | ey | 运行分辨率的endY | | description | 色组描述 | | sim | 相似度 | | offset | 是否偏移查找 | | timeout | 超时时间 | | timelag | timelag | | sign | 跳出条件,0为找色成功时返回,1为找色失败时返回 | 例子: ``` let result = helper.FindMultiColorLoop(0, 0, 1000, 500, findColorArray, 95, 0, 60000, 1000, 0); if(result.x != -1){ print("循环多点找色条件达成"); } ```
### 获取与运行分辨率相关的比色色组 `int[][]` GetCmpColorArray(String description); | 参数 | 描述 | | ----------- | -------------- | | description | 锚点色组字符串 | 例子: ``` let desc = "1080,1920,left|113|301|0x37474f,center|697|320|0x37474f,center|565|617|0xfafafa,left|238|384|0x37474f"; let CmpColorArray = helper.GetCmpColorArray(desc); ``` `int[][]` GetCmpColorArray(int devWidth, int devHeight, `int[][]` description); | 参数 | 描述 | | ----------- | ------------- | | devWidth | 开发分辨率 宽 | | devHeight | 开发分辨率 高 | | description | 锚点色组 | 例子: ``` let desc = [1280, 720, [ [center, 106, 72, 0xb1833a], [center, 161, 68, 0xc49143], [center, 568, 92, 0xd6b89c], [center, 697, 84, 0xdcc4aa], [center, 1033, 643, 0x41343c] ] ]; let CmpColorArray = helper.GetCmpColorArray(desc[0],desc[1],desc[2]); ```
### 单点比色 boolean CompareColor(int[] description, int sim, boolean offset); | 参数 | 描述 | | ----------- | ------------ | | description | 色组描述 | | sim | 相似度 | | offset | 是否偏移查找 | 例子: ``` print(helper.CompareColor([50,50,0xff,0xff,0xff,0,0,0,0], 95, false); ```
### 多点比色 boolean CompareColorEx(`int[][]` description, int sim, boolean offset); | 参数 | 描述 | | ----------- | ------------ | | description | 色组描述 | | sim | 相似度 | | offset | 是否偏移查找 | 例子: ``` print(helper.CompareColor(CmpColorArray, 95, false); ```
### 条件循环多点比色 boolean CompareColorExLoop(`int[][]` description, int sim, boolean offset, long timeout, long timelag, int sign); | 参数 | 描述 | | ----------- | -------------------------------------------- | | description | 色组描述 | | sim | 相似度 | | offset | 是否偏移查找 | | timeout | 超时时间 | | timelag | timelag | | sign | 跳出条件,0为找色成功时返回,1为找色失败时返回 | 例子: ``` let result = helper.CompareColorExLoop(0, 0, 1000, 500, findColorArray, 95, false, 60000, 1000, 0); if(result){ print("循环多点比色条件达成"); } ```

## **RecordHelper class** 主要应用于部分客户手机录屏工具和脚本录屏冲突的问题 | 返回值 | 方法 | 描述 | | :----------- | ------------------ | :------- | | RecordHelper | [.ctor](#构造函数) | 构造函数 | | boolean | [Start](#开始录屏) | 开始录屏 | | void | [Stop](#结束录屏) | 结束录屏 |
### 构造函数 RecordHelper(Object obj, int width, int height, int dpi, String path); | 参数 | 描述 | | ------ | -------------- | | obj | autojs runtime | | width | 宽 | | height | 高 | | dpi | dpi | | path | 录屏保存路径 | 例子: ``` importClass(com.scriptlib.RecordHelper); let recordHelper = new RecordHelper(runtime, 1920, 1080, 480, "/sdcard/record.mp4"); ```
### 开始录屏 boolean Start(); 例子: ``` threads.start(function () { recordHelper.Start(); }); ```
### 结束录屏 void Stop(); 例子: ``` recordHelper.Stop(); ```

# **锚点格式** ## 默认格式 ``` [center, 158, 203, 0xe027cc] ``` ## 添加偏色 ``` [center, 158, 203, 0xe027cc, 0x101010] ``` ## 添加反转条件 ``` [center, 158, 203, 0xe027cc, 1] //默认比色成功时返回true, 当添加反转条件时, 比色失败时返回true ``` ## 添加偏色及反转条件 ``` [center, 158, 203, 0xe027cc, 0x101010, 1] ```