SAutoScript 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sautoscript-0.1.0/LICENSE +21 -0
- sautoscript-0.1.0/PKG-INFO +193 -0
- sautoscript-0.1.0/README.md +144 -0
- sautoscript-0.1.0/SAutoScript.egg-info/PKG-INFO +193 -0
- sautoscript-0.1.0/SAutoScript.egg-info/SOURCES.txt +31 -0
- sautoscript-0.1.0/SAutoScript.egg-info/dependency_links.txt +1 -0
- sautoscript-0.1.0/SAutoScript.egg-info/requires.txt +9 -0
- sautoscript-0.1.0/SAutoScript.egg-info/top_level.txt +1 -0
- sautoscript-0.1.0/pyproject.toml +37 -0
- sautoscript-0.1.0/sautoscript/__init__.py +28 -0
- sautoscript-0.1.0/sautoscript/core/__init__.py +23 -0
- sautoscript-0.1.0/sautoscript/core/base_game_script.py +346 -0
- sautoscript-0.1.0/sautoscript/core/error_logger.py +114 -0
- sautoscript-0.1.0/sautoscript/core/game_operations.py +267 -0
- sautoscript-0.1.0/sautoscript/core/image_recognition.py +291 -0
- sautoscript-0.1.0/sautoscript/core/input_controller.py +347 -0
- sautoscript-0.1.0/sautoscript/core/screen_capture.py +175 -0
- sautoscript-0.1.0/sautoscript/core/window_locator.py +181 -0
- sautoscript-0.1.0/setup.cfg +22 -0
- sautoscript-0.1.0/setup.py +7 -0
- sautoscript-0.1.0/test/test_capture_methods.py +65 -0
- sautoscript-0.1.0/test/test_memory_optimization.py +153 -0
- sautoscript-0.1.0/test/test_object_pool.py +224 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SAutoScript
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SAutoScript
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 基于图像识别技术的自动脚本系统
|
|
5
|
+
Author-email: SAutoScript Team <shiwangwei771@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 SAutoScript
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/Sthons/SAutoScript
|
|
29
|
+
Project-URL: Repository, https://github.com/Sthons/SAutoScript
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: Topic :: Games/Entertainment
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: System :: Monitoring
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Requires-Dist: opencv-python
|
|
40
|
+
Requires-Dist: pyautogui
|
|
41
|
+
Requires-Dist: pywin32
|
|
42
|
+
Requires-Dist: pydirectinput
|
|
43
|
+
Requires-Dist: Pillow
|
|
44
|
+
Requires-Dist: loguru
|
|
45
|
+
Requires-Dist: pyyaml
|
|
46
|
+
Requires-Dist: psutil
|
|
47
|
+
Requires-Dist: mss
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# SAutoScript - 游戏自动脚本系统
|
|
51
|
+
|
|
52
|
+
基于图像识别技术的动作游戏自动脚本系统(支持使用DirectX的游戏),支持Windows平台的鼠标键盘仿真输入。
|
|
53
|
+
|
|
54
|
+
## 功能特点
|
|
55
|
+
|
|
56
|
+
- 基于OpenCV的图像识别和模板匹配
|
|
57
|
+
- 直接调用Windows API的鼠标键盘控制
|
|
58
|
+
- 可配置的脚本系统
|
|
59
|
+
- 实时屏幕捕获和分析
|
|
60
|
+
- 多线程处理,提高响应速度
|
|
61
|
+
- 智能内存优化和垃圾回收
|
|
62
|
+
- 随机事件支持
|
|
63
|
+
- 完善的错误日志记录
|
|
64
|
+
|
|
65
|
+
## 安装
|
|
66
|
+
|
|
67
|
+
### 从 PyPI 安装
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install SAutoScript
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 从源码安装
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 克隆仓库
|
|
77
|
+
git clone https://github.com/yourusername/SAutoScript.git
|
|
78
|
+
cd SAutoScript
|
|
79
|
+
|
|
80
|
+
# 安装依赖
|
|
81
|
+
pip install -r requirements.txt
|
|
82
|
+
|
|
83
|
+
# 安装包
|
|
84
|
+
pip install -e .
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 项目结构
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
SAutoScript/
|
|
91
|
+
├── sautoscript/ # 主要包目录
|
|
92
|
+
│ ├── __init__.py # 包初始化文件
|
|
93
|
+
│ └── core/ # 核心模块
|
|
94
|
+
│ ├── __init__.py
|
|
95
|
+
│ ├── base_game_script.py # 基础游戏脚本类
|
|
96
|
+
│ ├── error_logger.py # 错误日志记录模块
|
|
97
|
+
│ ├── game_operations.py # 游戏操作模块
|
|
98
|
+
│ ├── image_recognition.py # 图像识别模块
|
|
99
|
+
│ ├── input_controller.py # 输入控制模块
|
|
100
|
+
│ ├── screen_capture.py # 屏幕捕获模块
|
|
101
|
+
│ └── window_locator.py # 窗口定位模块
|
|
102
|
+
├── examples/ # 示例脚本
|
|
103
|
+
│ └── example.py # 使用示例
|
|
104
|
+
├── assets/ # 资源目录
|
|
105
|
+
│ └── templates/ # 图像模板
|
|
106
|
+
├── config/ # 配置文件目录
|
|
107
|
+
│ └── settings.yaml # 全局配置
|
|
108
|
+
├── docs/ # 文档目录
|
|
109
|
+
├── logs/ # 日志目录
|
|
110
|
+
├── pyproject.toml # 项目配置
|
|
111
|
+
├── setup.cfg # 安装配置
|
|
112
|
+
├── setup.py # 安装脚本
|
|
113
|
+
├── README.md # 项目说明
|
|
114
|
+
├── LICENSE # 许可证
|
|
115
|
+
└── requirements.txt # 依赖包列表
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 快速开始
|
|
119
|
+
|
|
120
|
+
### 基本使用
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from sautoscript import BaseGameScript
|
|
124
|
+
|
|
125
|
+
class MyGameScript(BaseGameScript):
|
|
126
|
+
def game_logic(self):
|
|
127
|
+
# 捕获屏幕
|
|
128
|
+
screenshot = self.screen_capture.capture()
|
|
129
|
+
|
|
130
|
+
if screenshot is None:
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
# 查找并点击特定图像
|
|
134
|
+
if self.game_ops.appear_then_click(
|
|
135
|
+
"target_button", # 模板名称
|
|
136
|
+
timeout=3, # 超时时间(秒)
|
|
137
|
+
threshold=0.8, # 匹配阈值
|
|
138
|
+
click_delay=0.5 # 点击后延迟
|
|
139
|
+
):
|
|
140
|
+
self.success_num += 1
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
script = MyGameScript()
|
|
144
|
+
script.start()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 运行示例
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python examples/example.py
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 核心模块说明
|
|
154
|
+
|
|
155
|
+
### 核心功能模块
|
|
156
|
+
|
|
157
|
+
- **base_game_script.py**: 游戏脚本基类,所有游戏脚本都应继承此类,实现通用的初始化、配置加载和主循环功能
|
|
158
|
+
- **error_logger.py**: 错误日志记录器,用于保存完整的错误信息到日志文件
|
|
159
|
+
- **game_operations.py**: 游戏操作模块,实现基于图像识别的循环模式
|
|
160
|
+
- **image_recognition.py**: 图像识别模块,包含NumpyArrayPool类提高性能
|
|
161
|
+
- **input_controller.py**: 输入控制模块,处理鼠标和键盘的仿真输入
|
|
162
|
+
- **screen_capture.py**: 屏幕捕获模块,支持多种捕获方法和质量设置
|
|
163
|
+
- **window_locator.py**: 窗口定位模块,用于获取窗口位置和大小
|
|
164
|
+
|
|
165
|
+
### 依赖库
|
|
166
|
+
|
|
167
|
+
- **OpenCV**: 用于图像识别和模板匹配
|
|
168
|
+
- **pyautogui**: 提供跨平台的鼠标键盘控制
|
|
169
|
+
- **pywin32**: 直接调用Windows API,提供更底层的控制
|
|
170
|
+
- **pydirectinput**: 基于**pywin32**,针对使用**DirectX**的游戏特化
|
|
171
|
+
- **mss**: 高性能屏幕捕获
|
|
172
|
+
- **PIL (Pillow)**: 图像处理和屏幕捕获
|
|
173
|
+
- **loguru**: 高级日志记录
|
|
174
|
+
- **pyyaml**: 配置文件解析
|
|
175
|
+
- **psutil**: 系统资源监控(用于内存监控)
|
|
176
|
+
|
|
177
|
+
## 文档
|
|
178
|
+
|
|
179
|
+
项目提供了详细的使用文档,帮助您快速上手:
|
|
180
|
+
|
|
181
|
+
- **BaseGameScript 使用指南** (`docs/BaseGameScript_Guide.md`): 详细介绍如何使用 BaseGameScript 基类创建游戏自动化脚本,包括核心功能、使用方法和最佳实践。
|
|
182
|
+
- **错误日志记录指南** (`docs/Error_Logging_Guide.md`): 介绍项目的错误日志记录功能,包括如何查看和分析错误日志,以及如何在自定义脚本中集成错误记录。
|
|
183
|
+
|
|
184
|
+
## 注意事项
|
|
185
|
+
|
|
186
|
+
- 运行脚本时请确保游戏窗口处于活动状态
|
|
187
|
+
- 某些游戏可能有反作弊机制,使用自动脚本需谨慎
|
|
188
|
+
- 建议在测试环境中先验证脚本功能
|
|
189
|
+
- 在Windows上,建议以管理员权限运行脚本,以确保输入控制功能正常工作
|
|
190
|
+
|
|
191
|
+
## 许可证
|
|
192
|
+
|
|
193
|
+
MIT License - 详见 LICENSE 文件
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# SAutoScript - 游戏自动脚本系统
|
|
2
|
+
|
|
3
|
+
基于图像识别技术的动作游戏自动脚本系统(支持使用DirectX的游戏),支持Windows平台的鼠标键盘仿真输入。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- 基于OpenCV的图像识别和模板匹配
|
|
8
|
+
- 直接调用Windows API的鼠标键盘控制
|
|
9
|
+
- 可配置的脚本系统
|
|
10
|
+
- 实时屏幕捕获和分析
|
|
11
|
+
- 多线程处理,提高响应速度
|
|
12
|
+
- 智能内存优化和垃圾回收
|
|
13
|
+
- 随机事件支持
|
|
14
|
+
- 完善的错误日志记录
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
### 从 PyPI 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install SAutoScript
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 从源码安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 克隆仓库
|
|
28
|
+
git clone https://github.com/yourusername/SAutoScript.git
|
|
29
|
+
cd SAutoScript
|
|
30
|
+
|
|
31
|
+
# 安装依赖
|
|
32
|
+
pip install -r requirements.txt
|
|
33
|
+
|
|
34
|
+
# 安装包
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 项目结构
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
SAutoScript/
|
|
42
|
+
├── sautoscript/ # 主要包目录
|
|
43
|
+
│ ├── __init__.py # 包初始化文件
|
|
44
|
+
│ └── core/ # 核心模块
|
|
45
|
+
│ ├── __init__.py
|
|
46
|
+
│ ├── base_game_script.py # 基础游戏脚本类
|
|
47
|
+
│ ├── error_logger.py # 错误日志记录模块
|
|
48
|
+
│ ├── game_operations.py # 游戏操作模块
|
|
49
|
+
│ ├── image_recognition.py # 图像识别模块
|
|
50
|
+
│ ├── input_controller.py # 输入控制模块
|
|
51
|
+
│ ├── screen_capture.py # 屏幕捕获模块
|
|
52
|
+
│ └── window_locator.py # 窗口定位模块
|
|
53
|
+
├── examples/ # 示例脚本
|
|
54
|
+
│ └── example.py # 使用示例
|
|
55
|
+
├── assets/ # 资源目录
|
|
56
|
+
│ └── templates/ # 图像模板
|
|
57
|
+
├── config/ # 配置文件目录
|
|
58
|
+
│ └── settings.yaml # 全局配置
|
|
59
|
+
├── docs/ # 文档目录
|
|
60
|
+
├── logs/ # 日志目录
|
|
61
|
+
├── pyproject.toml # 项目配置
|
|
62
|
+
├── setup.cfg # 安装配置
|
|
63
|
+
├── setup.py # 安装脚本
|
|
64
|
+
├── README.md # 项目说明
|
|
65
|
+
├── LICENSE # 许可证
|
|
66
|
+
└── requirements.txt # 依赖包列表
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 快速开始
|
|
70
|
+
|
|
71
|
+
### 基本使用
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from sautoscript import BaseGameScript
|
|
75
|
+
|
|
76
|
+
class MyGameScript(BaseGameScript):
|
|
77
|
+
def game_logic(self):
|
|
78
|
+
# 捕获屏幕
|
|
79
|
+
screenshot = self.screen_capture.capture()
|
|
80
|
+
|
|
81
|
+
if screenshot is None:
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
# 查找并点击特定图像
|
|
85
|
+
if self.game_ops.appear_then_click(
|
|
86
|
+
"target_button", # 模板名称
|
|
87
|
+
timeout=3, # 超时时间(秒)
|
|
88
|
+
threshold=0.8, # 匹配阈值
|
|
89
|
+
click_delay=0.5 # 点击后延迟
|
|
90
|
+
):
|
|
91
|
+
self.success_num += 1
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
script = MyGameScript()
|
|
95
|
+
script.start()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 运行示例
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
python examples/example.py
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 核心模块说明
|
|
105
|
+
|
|
106
|
+
### 核心功能模块
|
|
107
|
+
|
|
108
|
+
- **base_game_script.py**: 游戏脚本基类,所有游戏脚本都应继承此类,实现通用的初始化、配置加载和主循环功能
|
|
109
|
+
- **error_logger.py**: 错误日志记录器,用于保存完整的错误信息到日志文件
|
|
110
|
+
- **game_operations.py**: 游戏操作模块,实现基于图像识别的循环模式
|
|
111
|
+
- **image_recognition.py**: 图像识别模块,包含NumpyArrayPool类提高性能
|
|
112
|
+
- **input_controller.py**: 输入控制模块,处理鼠标和键盘的仿真输入
|
|
113
|
+
- **screen_capture.py**: 屏幕捕获模块,支持多种捕获方法和质量设置
|
|
114
|
+
- **window_locator.py**: 窗口定位模块,用于获取窗口位置和大小
|
|
115
|
+
|
|
116
|
+
### 依赖库
|
|
117
|
+
|
|
118
|
+
- **OpenCV**: 用于图像识别和模板匹配
|
|
119
|
+
- **pyautogui**: 提供跨平台的鼠标键盘控制
|
|
120
|
+
- **pywin32**: 直接调用Windows API,提供更底层的控制
|
|
121
|
+
- **pydirectinput**: 基于**pywin32**,针对使用**DirectX**的游戏特化
|
|
122
|
+
- **mss**: 高性能屏幕捕获
|
|
123
|
+
- **PIL (Pillow)**: 图像处理和屏幕捕获
|
|
124
|
+
- **loguru**: 高级日志记录
|
|
125
|
+
- **pyyaml**: 配置文件解析
|
|
126
|
+
- **psutil**: 系统资源监控(用于内存监控)
|
|
127
|
+
|
|
128
|
+
## 文档
|
|
129
|
+
|
|
130
|
+
项目提供了详细的使用文档,帮助您快速上手:
|
|
131
|
+
|
|
132
|
+
- **BaseGameScript 使用指南** (`docs/BaseGameScript_Guide.md`): 详细介绍如何使用 BaseGameScript 基类创建游戏自动化脚本,包括核心功能、使用方法和最佳实践。
|
|
133
|
+
- **错误日志记录指南** (`docs/Error_Logging_Guide.md`): 介绍项目的错误日志记录功能,包括如何查看和分析错误日志,以及如何在自定义脚本中集成错误记录。
|
|
134
|
+
|
|
135
|
+
## 注意事项
|
|
136
|
+
|
|
137
|
+
- 运行脚本时请确保游戏窗口处于活动状态
|
|
138
|
+
- 某些游戏可能有反作弊机制,使用自动脚本需谨慎
|
|
139
|
+
- 建议在测试环境中先验证脚本功能
|
|
140
|
+
- 在Windows上,建议以管理员权限运行脚本,以确保输入控制功能正常工作
|
|
141
|
+
|
|
142
|
+
## 许可证
|
|
143
|
+
|
|
144
|
+
MIT License - 详见 LICENSE 文件
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SAutoScript
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 基于图像识别技术的自动脚本系统
|
|
5
|
+
Author-email: SAutoScript Team <shiwangwei771@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 SAutoScript
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/Sthons/SAutoScript
|
|
29
|
+
Project-URL: Repository, https://github.com/Sthons/SAutoScript
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: Topic :: Games/Entertainment
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: System :: Monitoring
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Requires-Dist: opencv-python
|
|
40
|
+
Requires-Dist: pyautogui
|
|
41
|
+
Requires-Dist: pywin32
|
|
42
|
+
Requires-Dist: pydirectinput
|
|
43
|
+
Requires-Dist: Pillow
|
|
44
|
+
Requires-Dist: loguru
|
|
45
|
+
Requires-Dist: pyyaml
|
|
46
|
+
Requires-Dist: psutil
|
|
47
|
+
Requires-Dist: mss
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# SAutoScript - 游戏自动脚本系统
|
|
51
|
+
|
|
52
|
+
基于图像识别技术的动作游戏自动脚本系统(支持使用DirectX的游戏),支持Windows平台的鼠标键盘仿真输入。
|
|
53
|
+
|
|
54
|
+
## 功能特点
|
|
55
|
+
|
|
56
|
+
- 基于OpenCV的图像识别和模板匹配
|
|
57
|
+
- 直接调用Windows API的鼠标键盘控制
|
|
58
|
+
- 可配置的脚本系统
|
|
59
|
+
- 实时屏幕捕获和分析
|
|
60
|
+
- 多线程处理,提高响应速度
|
|
61
|
+
- 智能内存优化和垃圾回收
|
|
62
|
+
- 随机事件支持
|
|
63
|
+
- 完善的错误日志记录
|
|
64
|
+
|
|
65
|
+
## 安装
|
|
66
|
+
|
|
67
|
+
### 从 PyPI 安装
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install SAutoScript
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 从源码安装
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 克隆仓库
|
|
77
|
+
git clone https://github.com/yourusername/SAutoScript.git
|
|
78
|
+
cd SAutoScript
|
|
79
|
+
|
|
80
|
+
# 安装依赖
|
|
81
|
+
pip install -r requirements.txt
|
|
82
|
+
|
|
83
|
+
# 安装包
|
|
84
|
+
pip install -e .
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 项目结构
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
SAutoScript/
|
|
91
|
+
├── sautoscript/ # 主要包目录
|
|
92
|
+
│ ├── __init__.py # 包初始化文件
|
|
93
|
+
│ └── core/ # 核心模块
|
|
94
|
+
│ ├── __init__.py
|
|
95
|
+
│ ├── base_game_script.py # 基础游戏脚本类
|
|
96
|
+
│ ├── error_logger.py # 错误日志记录模块
|
|
97
|
+
│ ├── game_operations.py # 游戏操作模块
|
|
98
|
+
│ ├── image_recognition.py # 图像识别模块
|
|
99
|
+
│ ├── input_controller.py # 输入控制模块
|
|
100
|
+
│ ├── screen_capture.py # 屏幕捕获模块
|
|
101
|
+
│ └── window_locator.py # 窗口定位模块
|
|
102
|
+
├── examples/ # 示例脚本
|
|
103
|
+
│ └── example.py # 使用示例
|
|
104
|
+
├── assets/ # 资源目录
|
|
105
|
+
│ └── templates/ # 图像模板
|
|
106
|
+
├── config/ # 配置文件目录
|
|
107
|
+
│ └── settings.yaml # 全局配置
|
|
108
|
+
├── docs/ # 文档目录
|
|
109
|
+
├── logs/ # 日志目录
|
|
110
|
+
├── pyproject.toml # 项目配置
|
|
111
|
+
├── setup.cfg # 安装配置
|
|
112
|
+
├── setup.py # 安装脚本
|
|
113
|
+
├── README.md # 项目说明
|
|
114
|
+
├── LICENSE # 许可证
|
|
115
|
+
└── requirements.txt # 依赖包列表
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 快速开始
|
|
119
|
+
|
|
120
|
+
### 基本使用
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from sautoscript import BaseGameScript
|
|
124
|
+
|
|
125
|
+
class MyGameScript(BaseGameScript):
|
|
126
|
+
def game_logic(self):
|
|
127
|
+
# 捕获屏幕
|
|
128
|
+
screenshot = self.screen_capture.capture()
|
|
129
|
+
|
|
130
|
+
if screenshot is None:
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
# 查找并点击特定图像
|
|
134
|
+
if self.game_ops.appear_then_click(
|
|
135
|
+
"target_button", # 模板名称
|
|
136
|
+
timeout=3, # 超时时间(秒)
|
|
137
|
+
threshold=0.8, # 匹配阈值
|
|
138
|
+
click_delay=0.5 # 点击后延迟
|
|
139
|
+
):
|
|
140
|
+
self.success_num += 1
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
script = MyGameScript()
|
|
144
|
+
script.start()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 运行示例
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python examples/example.py
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 核心模块说明
|
|
154
|
+
|
|
155
|
+
### 核心功能模块
|
|
156
|
+
|
|
157
|
+
- **base_game_script.py**: 游戏脚本基类,所有游戏脚本都应继承此类,实现通用的初始化、配置加载和主循环功能
|
|
158
|
+
- **error_logger.py**: 错误日志记录器,用于保存完整的错误信息到日志文件
|
|
159
|
+
- **game_operations.py**: 游戏操作模块,实现基于图像识别的循环模式
|
|
160
|
+
- **image_recognition.py**: 图像识别模块,包含NumpyArrayPool类提高性能
|
|
161
|
+
- **input_controller.py**: 输入控制模块,处理鼠标和键盘的仿真输入
|
|
162
|
+
- **screen_capture.py**: 屏幕捕获模块,支持多种捕获方法和质量设置
|
|
163
|
+
- **window_locator.py**: 窗口定位模块,用于获取窗口位置和大小
|
|
164
|
+
|
|
165
|
+
### 依赖库
|
|
166
|
+
|
|
167
|
+
- **OpenCV**: 用于图像识别和模板匹配
|
|
168
|
+
- **pyautogui**: 提供跨平台的鼠标键盘控制
|
|
169
|
+
- **pywin32**: 直接调用Windows API,提供更底层的控制
|
|
170
|
+
- **pydirectinput**: 基于**pywin32**,针对使用**DirectX**的游戏特化
|
|
171
|
+
- **mss**: 高性能屏幕捕获
|
|
172
|
+
- **PIL (Pillow)**: 图像处理和屏幕捕获
|
|
173
|
+
- **loguru**: 高级日志记录
|
|
174
|
+
- **pyyaml**: 配置文件解析
|
|
175
|
+
- **psutil**: 系统资源监控(用于内存监控)
|
|
176
|
+
|
|
177
|
+
## 文档
|
|
178
|
+
|
|
179
|
+
项目提供了详细的使用文档,帮助您快速上手:
|
|
180
|
+
|
|
181
|
+
- **BaseGameScript 使用指南** (`docs/BaseGameScript_Guide.md`): 详细介绍如何使用 BaseGameScript 基类创建游戏自动化脚本,包括核心功能、使用方法和最佳实践。
|
|
182
|
+
- **错误日志记录指南** (`docs/Error_Logging_Guide.md`): 介绍项目的错误日志记录功能,包括如何查看和分析错误日志,以及如何在自定义脚本中集成错误记录。
|
|
183
|
+
|
|
184
|
+
## 注意事项
|
|
185
|
+
|
|
186
|
+
- 运行脚本时请确保游戏窗口处于活动状态
|
|
187
|
+
- 某些游戏可能有反作弊机制,使用自动脚本需谨慎
|
|
188
|
+
- 建议在测试环境中先验证脚本功能
|
|
189
|
+
- 在Windows上,建议以管理员权限运行脚本,以确保输入控制功能正常工作
|
|
190
|
+
|
|
191
|
+
## 许可证
|
|
192
|
+
|
|
193
|
+
MIT License - 详见 LICENSE 文件
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
./sautoscript/__init__.py
|
|
7
|
+
./sautoscript/core/__init__.py
|
|
8
|
+
./sautoscript/core/base_game_script.py
|
|
9
|
+
./sautoscript/core/error_logger.py
|
|
10
|
+
./sautoscript/core/game_operations.py
|
|
11
|
+
./sautoscript/core/image_recognition.py
|
|
12
|
+
./sautoscript/core/input_controller.py
|
|
13
|
+
./sautoscript/core/screen_capture.py
|
|
14
|
+
./sautoscript/core/window_locator.py
|
|
15
|
+
SAutoScript.egg-info/PKG-INFO
|
|
16
|
+
SAutoScript.egg-info/SOURCES.txt
|
|
17
|
+
SAutoScript.egg-info/dependency_links.txt
|
|
18
|
+
SAutoScript.egg-info/requires.txt
|
|
19
|
+
SAutoScript.egg-info/top_level.txt
|
|
20
|
+
sautoscript/__init__.py
|
|
21
|
+
sautoscript/core/__init__.py
|
|
22
|
+
sautoscript/core/base_game_script.py
|
|
23
|
+
sautoscript/core/error_logger.py
|
|
24
|
+
sautoscript/core/game_operations.py
|
|
25
|
+
sautoscript/core/image_recognition.py
|
|
26
|
+
sautoscript/core/input_controller.py
|
|
27
|
+
sautoscript/core/screen_capture.py
|
|
28
|
+
sautoscript/core/window_locator.py
|
|
29
|
+
test/test_capture_methods.py
|
|
30
|
+
test/test_memory_optimization.py
|
|
31
|
+
test/test_object_pool.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sautoscript
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "SAutoScript"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "基于图像识别技术的自动脚本系统"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "SAutoScript Team", email = "shiwangwei771@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
license = { file = "LICENSE" }
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Games/Entertainment",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
"Topic :: System :: Monitoring",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"opencv-python",
|
|
25
|
+
"pyautogui",
|
|
26
|
+
"pywin32",
|
|
27
|
+
"pydirectinput",
|
|
28
|
+
"Pillow",
|
|
29
|
+
"loguru",
|
|
30
|
+
"pyyaml",
|
|
31
|
+
"psutil",
|
|
32
|
+
"mss"
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
"Homepage" = "https://github.com/Sthons/SAutoScript"
|
|
37
|
+
"Repository" = "https://github.com/Sthons/SAutoScript"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
SAutoScript - 游戏自动脚本系统
|
|
5
|
+
基于图像识别技术的动作游戏自动脚本系统,支持Windows平台的鼠标键盘仿真输入。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
__author__ = "SAutoScript Team"
|
|
10
|
+
__license__ = "MIT"
|
|
11
|
+
|
|
12
|
+
from sautoscript.core.base_game_script import BaseGameScript
|
|
13
|
+
from sautoscript.core.input_controller import InputController
|
|
14
|
+
from sautoscript.core.screen_capture import ScreenCapture
|
|
15
|
+
from sautoscript.core.image_recognition import ImageRecognition
|
|
16
|
+
from sautoscript.core.game_operations import GameOperations
|
|
17
|
+
from sautoscript.core.window_locator import WindowLocator
|
|
18
|
+
from sautoscript.core.error_logger import log_exception
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"BaseGameScript",
|
|
22
|
+
"InputController",
|
|
23
|
+
"ScreenCapture",
|
|
24
|
+
"ImageRecognition",
|
|
25
|
+
"GameOperations",
|
|
26
|
+
"WindowLocator",
|
|
27
|
+
"log_exception"
|
|
28
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
SAutoScript 核心模块
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from sautoscript.core.base_game_script import BaseGameScript
|
|
8
|
+
from sautoscript.core.input_controller import InputController
|
|
9
|
+
from sautoscript.core.screen_capture import ScreenCapture
|
|
10
|
+
from sautoscript.core.image_recognition import ImageRecognition
|
|
11
|
+
from sautoscript.core.game_operations import GameOperations
|
|
12
|
+
from sautoscript.core.window_locator import WindowLocator
|
|
13
|
+
from sautoscript.core.error_logger import log_exception
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"BaseGameScript",
|
|
17
|
+
"InputController",
|
|
18
|
+
"ScreenCapture",
|
|
19
|
+
"ImageRecognition",
|
|
20
|
+
"GameOperations",
|
|
21
|
+
"WindowLocator",
|
|
22
|
+
"log_exception"
|
|
23
|
+
]
|