MaaFw 3.0.3__py3-none-win_amd64.whl → 4.0.0__py3-none-win_amd64.whl
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.
Potentially problematic release.
This version of MaaFw might be problematic. Click here for more details.
- maa/__init__.py +1 -1
- maa/agent/__init__.py +12 -0
- maa/agent/agent_server.py +132 -0
- maa/agent_client.py +91 -0
- maa/bin/MaaAdbControlUnit.dll +0 -0
- maa/bin/MaaAgentClient.dll +0 -0
- maa/bin/MaaAgentServer.dll +0 -0
- maa/bin/MaaDbgControlUnit.dll +0 -0
- maa/bin/MaaFramework.dll +0 -0
- maa/bin/MaaToolkit.dll +0 -0
- maa/bin/MaaUtils.dll +0 -0
- maa/bin/MaaWin32ControlUnit.dll +0 -0
- maa/bin/fastdeploy_ppocr_maa.dll +0 -0
- maa/bin/onnxruntime_maa.dll +0 -0
- maa/bin/opencv_world4_maa.dll +0 -0
- maa/buffer.py +129 -131
- maa/context.py +24 -24
- maa/controller.py +70 -70
- maa/define.py +15 -12
- maa/library.py +103 -15
- maa/notification_handler.py +3 -3
- maa/resource.py +47 -47
- maa/tasker.py +63 -61
- maa/toolkit.py +82 -78
- {MaaFw-3.0.3.dist-info → maafw-4.0.0.dist-info}/METADATA +23 -8
- maafw-4.0.0.dist-info/RECORD +32 -0
- {MaaFw-3.0.3.dist-info → maafw-4.0.0.dist-info}/WHEEL +1 -1
- MaaFw-3.0.3.dist-info/RECORD +0 -28
- MaaFw-3.0.3.dist-info/top_level.txt +0 -1
- {MaaFw-3.0.3.dist-info → maafw-4.0.0.dist-info/licenses}/LICENSE.md +0 -0
maa/controller.py
CHANGED
|
@@ -22,7 +22,7 @@ __all__ = [
|
|
|
22
22
|
class Controller:
|
|
23
23
|
_notification_handler: Optional[NotificationHandler]
|
|
24
24
|
_handle: MaaControllerHandle
|
|
25
|
-
_own: bool
|
|
25
|
+
_own: bool
|
|
26
26
|
|
|
27
27
|
def __init__(
|
|
28
28
|
self,
|
|
@@ -39,40 +39,40 @@ class Controller:
|
|
|
39
39
|
|
|
40
40
|
def __del__(self):
|
|
41
41
|
if self._handle and self._own:
|
|
42
|
-
Library.framework.MaaControllerDestroy(self._handle)
|
|
42
|
+
Library.framework().MaaControllerDestroy(self._handle)
|
|
43
43
|
|
|
44
44
|
def post_connection(self) -> Job:
|
|
45
|
-
ctrl_id = Library.framework.MaaControllerPostConnection(self._handle)
|
|
45
|
+
ctrl_id = Library.framework().MaaControllerPostConnection(self._handle)
|
|
46
46
|
return self._gen_ctrl_job(ctrl_id)
|
|
47
47
|
|
|
48
48
|
def post_click(self, x: int, y: int) -> Job:
|
|
49
|
-
ctrl_id = Library.framework.MaaControllerPostClick(self._handle, x, y)
|
|
49
|
+
ctrl_id = Library.framework().MaaControllerPostClick(self._handle, x, y)
|
|
50
50
|
return self._gen_ctrl_job(ctrl_id)
|
|
51
51
|
|
|
52
52
|
def post_swipe(self, x1: int, y1: int, x2: int, y2: int, duration: int) -> Job:
|
|
53
|
-
ctrl_id = Library.framework.MaaControllerPostSwipe(
|
|
53
|
+
ctrl_id = Library.framework().MaaControllerPostSwipe(
|
|
54
54
|
self._handle, x1, y1, x2, y2, duration
|
|
55
55
|
)
|
|
56
56
|
return self._gen_ctrl_job(ctrl_id)
|
|
57
57
|
|
|
58
58
|
def post_press_key(self, key: int) -> Job:
|
|
59
|
-
ctrl_id = Library.framework.MaaControllerPostPressKey(self._handle, key)
|
|
59
|
+
ctrl_id = Library.framework().MaaControllerPostPressKey(self._handle, key)
|
|
60
60
|
return self._gen_ctrl_job(ctrl_id)
|
|
61
61
|
|
|
62
62
|
def post_input_text(self, text: str) -> Job:
|
|
63
|
-
ctrl_id = Library.framework.MaaControllerPostInputText(
|
|
63
|
+
ctrl_id = Library.framework().MaaControllerPostInputText(
|
|
64
64
|
self._handle, text.encode()
|
|
65
65
|
)
|
|
66
66
|
return self._gen_ctrl_job(ctrl_id)
|
|
67
67
|
|
|
68
68
|
def post_start_app(self, intent: str) -> Job:
|
|
69
|
-
ctrl_id = Library.framework.MaaControllerPostStartApp(
|
|
69
|
+
ctrl_id = Library.framework().MaaControllerPostStartApp(
|
|
70
70
|
self._handle, intent.encode()
|
|
71
71
|
)
|
|
72
72
|
return self._gen_ctrl_job(ctrl_id)
|
|
73
73
|
|
|
74
74
|
def post_stop_app(self, intent: str) -> Job:
|
|
75
|
-
ctrl_id = Library.framework.MaaControllerPostStopApp(
|
|
75
|
+
ctrl_id = Library.framework().MaaControllerPostStopApp(
|
|
76
76
|
self._handle, intent.encode()
|
|
77
77
|
)
|
|
78
78
|
return self._gen_ctrl_job(ctrl_id)
|
|
@@ -80,7 +80,7 @@ class Controller:
|
|
|
80
80
|
def post_touch_down(
|
|
81
81
|
self, x: int, y: int, contact: int = 0, pressure: int = 1
|
|
82
82
|
) -> Job:
|
|
83
|
-
ctrl_id = Library.framework.MaaControllerPostTouchDown(
|
|
83
|
+
ctrl_id = Library.framework().MaaControllerPostTouchDown(
|
|
84
84
|
self._handle, contact, x, y, pressure
|
|
85
85
|
)
|
|
86
86
|
return self._gen_ctrl_job(ctrl_id)
|
|
@@ -88,17 +88,17 @@ class Controller:
|
|
|
88
88
|
def post_touch_move(
|
|
89
89
|
self, x: int, y: int, contact: int = 0, pressure: int = 1
|
|
90
90
|
) -> Job:
|
|
91
|
-
ctrl_id = Library.framework.MaaControllerPostTouchMove(
|
|
91
|
+
ctrl_id = Library.framework().MaaControllerPostTouchMove(
|
|
92
92
|
self._handle, contact, x, y, pressure
|
|
93
93
|
)
|
|
94
94
|
return self._gen_ctrl_job(ctrl_id)
|
|
95
95
|
|
|
96
96
|
def post_touch_up(self, contact: int = 0) -> Job:
|
|
97
|
-
ctrl_id = Library.framework.MaaControllerPostTouchUp(self._handle, contact)
|
|
97
|
+
ctrl_id = Library.framework().MaaControllerPostTouchUp(self._handle, contact)
|
|
98
98
|
return self._gen_ctrl_job(ctrl_id)
|
|
99
99
|
|
|
100
100
|
def post_screencap(self) -> JobWithResult:
|
|
101
|
-
ctrl_id = Library.framework.MaaControllerPostScreencap(self._handle)
|
|
101
|
+
ctrl_id = Library.framework().MaaControllerPostScreencap(self._handle)
|
|
102
102
|
return JobWithResult(
|
|
103
103
|
ctrl_id,
|
|
104
104
|
self._status,
|
|
@@ -109,7 +109,7 @@ class Controller:
|
|
|
109
109
|
@property
|
|
110
110
|
def cached_image(self) -> numpy.ndarray:
|
|
111
111
|
image_buffer = ImageBuffer()
|
|
112
|
-
if not Library.framework.MaaControllerCachedImage(
|
|
112
|
+
if not Library.framework().MaaControllerCachedImage(
|
|
113
113
|
self._handle, image_buffer._handle
|
|
114
114
|
):
|
|
115
115
|
raise RuntimeError("Failed to get cached image.")
|
|
@@ -117,19 +117,19 @@ class Controller:
|
|
|
117
117
|
|
|
118
118
|
@property
|
|
119
119
|
def connected(self) -> bool:
|
|
120
|
-
return bool(Library.framework.MaaControllerConnected(self._handle))
|
|
120
|
+
return bool(Library.framework().MaaControllerConnected(self._handle))
|
|
121
121
|
|
|
122
122
|
@property
|
|
123
123
|
def uuid(self) -> str:
|
|
124
124
|
buffer = StringBuffer()
|
|
125
|
-
if not Library.framework.MaaControllerGetUuid(self._handle, buffer._handle):
|
|
125
|
+
if not Library.framework().MaaControllerGetUuid(self._handle, buffer._handle):
|
|
126
126
|
raise RuntimeError("Failed to get UUID.")
|
|
127
127
|
return buffer.get()
|
|
128
128
|
|
|
129
129
|
def set_screenshot_target_long_side(self, long_side: int) -> bool:
|
|
130
130
|
cint = ctypes.c_int32(long_side)
|
|
131
131
|
return bool(
|
|
132
|
-
Library.framework.MaaControllerSetOption(
|
|
132
|
+
Library.framework().MaaControllerSetOption(
|
|
133
133
|
self._handle,
|
|
134
134
|
MaaOption(MaaCtrlOptionEnum.ScreenshotTargetLongSide),
|
|
135
135
|
ctypes.pointer(cint),
|
|
@@ -140,7 +140,7 @@ class Controller:
|
|
|
140
140
|
def set_screenshot_target_short_side(self, short_side: int) -> bool:
|
|
141
141
|
cint = ctypes.c_int32(short_side)
|
|
142
142
|
return bool(
|
|
143
|
-
Library.framework.MaaControllerSetOption(
|
|
143
|
+
Library.framework().MaaControllerSetOption(
|
|
144
144
|
self._handle,
|
|
145
145
|
MaaOption(MaaCtrlOptionEnum.ScreenshotTargetShortSide),
|
|
146
146
|
ctypes.pointer(cint),
|
|
@@ -151,7 +151,7 @@ class Controller:
|
|
|
151
151
|
def set_screenshot_use_raw_size(self, enable: bool) -> bool:
|
|
152
152
|
cbool = MaaBool(enable)
|
|
153
153
|
return bool(
|
|
154
|
-
Library.framework.MaaControllerSetOption(
|
|
154
|
+
Library.framework().MaaControllerSetOption(
|
|
155
155
|
self._handle,
|
|
156
156
|
MaaOption(MaaCtrlOptionEnum.ScreenshotUseRawSize),
|
|
157
157
|
ctypes.pointer(cbool),
|
|
@@ -162,10 +162,10 @@ class Controller:
|
|
|
162
162
|
### private ###
|
|
163
163
|
|
|
164
164
|
def _status(self, maaid: int) -> MaaStatus:
|
|
165
|
-
return Library.framework.MaaControllerStatus(self._handle, maaid)
|
|
165
|
+
return Library.framework().MaaControllerStatus(self._handle, maaid)
|
|
166
166
|
|
|
167
167
|
def _wait(self, maaid: int) -> MaaStatus:
|
|
168
|
-
return Library.framework.MaaControllerWait(self._handle, maaid)
|
|
168
|
+
return Library.framework().MaaControllerWait(self._handle, maaid)
|
|
169
169
|
|
|
170
170
|
def _get_screencap(self, _: int) -> numpy.ndarray:
|
|
171
171
|
return self.cached_image
|
|
@@ -185,29 +185,29 @@ class Controller:
|
|
|
185
185
|
return
|
|
186
186
|
Controller._api_properties_initialized = True
|
|
187
187
|
|
|
188
|
-
Library.framework.MaaControllerDestroy.restype = None
|
|
189
|
-
Library.framework.MaaControllerDestroy.argtypes = [MaaControllerHandle]
|
|
188
|
+
Library.framework().MaaControllerDestroy.restype = None
|
|
189
|
+
Library.framework().MaaControllerDestroy.argtypes = [MaaControllerHandle]
|
|
190
190
|
|
|
191
|
-
Library.framework.MaaControllerSetOption.restype = MaaBool
|
|
192
|
-
Library.framework.MaaControllerSetOption.argtypes = [
|
|
191
|
+
Library.framework().MaaControllerSetOption.restype = MaaBool
|
|
192
|
+
Library.framework().MaaControllerSetOption.argtypes = [
|
|
193
193
|
MaaControllerHandle,
|
|
194
194
|
MaaCtrlOption,
|
|
195
195
|
MaaOptionValue,
|
|
196
196
|
MaaOptionValueSize,
|
|
197
197
|
]
|
|
198
198
|
|
|
199
|
-
Library.framework.MaaControllerPostConnection.restype = MaaCtrlId
|
|
200
|
-
Library.framework.MaaControllerPostConnection.argtypes = [MaaControllerHandle]
|
|
199
|
+
Library.framework().MaaControllerPostConnection.restype = MaaCtrlId
|
|
200
|
+
Library.framework().MaaControllerPostConnection.argtypes = [MaaControllerHandle]
|
|
201
201
|
|
|
202
|
-
Library.framework.MaaControllerPostClick.restype = MaaCtrlId
|
|
203
|
-
Library.framework.MaaControllerPostClick.argtypes = [
|
|
202
|
+
Library.framework().MaaControllerPostClick.restype = MaaCtrlId
|
|
203
|
+
Library.framework().MaaControllerPostClick.argtypes = [
|
|
204
204
|
MaaControllerHandle,
|
|
205
205
|
c_int32,
|
|
206
206
|
c_int32,
|
|
207
207
|
]
|
|
208
208
|
|
|
209
|
-
Library.framework.MaaControllerPostSwipe.restype = MaaCtrlId
|
|
210
|
-
Library.framework.MaaControllerPostSwipe.argtypes = [
|
|
209
|
+
Library.framework().MaaControllerPostSwipe.restype = MaaCtrlId
|
|
210
|
+
Library.framework().MaaControllerPostSwipe.argtypes = [
|
|
211
211
|
MaaControllerHandle,
|
|
212
212
|
c_int32,
|
|
213
213
|
c_int32,
|
|
@@ -216,37 +216,37 @@ class Controller:
|
|
|
216
216
|
c_int32,
|
|
217
217
|
]
|
|
218
218
|
|
|
219
|
-
Library.framework.MaaControllerPostPressKey.restype = MaaCtrlId
|
|
220
|
-
Library.framework.MaaControllerPostPressKey.argtypes = [
|
|
219
|
+
Library.framework().MaaControllerPostPressKey.restype = MaaCtrlId
|
|
220
|
+
Library.framework().MaaControllerPostPressKey.argtypes = [
|
|
221
221
|
MaaControllerHandle,
|
|
222
222
|
c_int32,
|
|
223
223
|
]
|
|
224
224
|
|
|
225
|
-
Library.framework.MaaControllerPostInputText.restype = MaaCtrlId
|
|
226
|
-
Library.framework.MaaControllerPostInputText.argtypes = [
|
|
225
|
+
Library.framework().MaaControllerPostInputText.restype = MaaCtrlId
|
|
226
|
+
Library.framework().MaaControllerPostInputText.argtypes = [
|
|
227
227
|
MaaControllerHandle,
|
|
228
228
|
ctypes.c_char_p,
|
|
229
229
|
]
|
|
230
230
|
|
|
231
|
-
Library.framework.MaaControllerPostScreencap.restype = MaaCtrlId
|
|
232
|
-
Library.framework.MaaControllerPostScreencap.argtypes = [
|
|
231
|
+
Library.framework().MaaControllerPostScreencap.restype = MaaCtrlId
|
|
232
|
+
Library.framework().MaaControllerPostScreencap.argtypes = [
|
|
233
233
|
MaaControllerHandle,
|
|
234
234
|
]
|
|
235
235
|
|
|
236
|
-
Library.framework.MaaControllerPostStartApp.restype = MaaCtrlId
|
|
237
|
-
Library.framework.MaaControllerPostStartApp.argtypes = [
|
|
236
|
+
Library.framework().MaaControllerPostStartApp.restype = MaaCtrlId
|
|
237
|
+
Library.framework().MaaControllerPostStartApp.argtypes = [
|
|
238
238
|
MaaControllerHandle,
|
|
239
239
|
ctypes.c_char_p,
|
|
240
240
|
]
|
|
241
241
|
|
|
242
|
-
Library.framework.MaaControllerPostStopApp.restype = MaaCtrlId
|
|
243
|
-
Library.framework.MaaControllerPostStopApp.argtypes = [
|
|
242
|
+
Library.framework().MaaControllerPostStopApp.restype = MaaCtrlId
|
|
243
|
+
Library.framework().MaaControllerPostStopApp.argtypes = [
|
|
244
244
|
MaaControllerHandle,
|
|
245
245
|
ctypes.c_char_p,
|
|
246
246
|
]
|
|
247
247
|
|
|
248
|
-
Library.framework.MaaControllerPostTouchDown.restype = MaaCtrlId
|
|
249
|
-
Library.framework.MaaControllerPostTouchDown.argtypes = [
|
|
248
|
+
Library.framework().MaaControllerPostTouchDown.restype = MaaCtrlId
|
|
249
|
+
Library.framework().MaaControllerPostTouchDown.argtypes = [
|
|
250
250
|
MaaControllerHandle,
|
|
251
251
|
c_int32,
|
|
252
252
|
c_int32,
|
|
@@ -254,8 +254,8 @@ class Controller:
|
|
|
254
254
|
c_int32,
|
|
255
255
|
]
|
|
256
256
|
|
|
257
|
-
Library.framework.MaaControllerPostTouchMove.restype = MaaCtrlId
|
|
258
|
-
Library.framework.MaaControllerPostTouchMove.argtypes = [
|
|
257
|
+
Library.framework().MaaControllerPostTouchMove.restype = MaaCtrlId
|
|
258
|
+
Library.framework().MaaControllerPostTouchMove.argtypes = [
|
|
259
259
|
MaaControllerHandle,
|
|
260
260
|
c_int32,
|
|
261
261
|
c_int32,
|
|
@@ -263,34 +263,34 @@ class Controller:
|
|
|
263
263
|
c_int32,
|
|
264
264
|
]
|
|
265
265
|
|
|
266
|
-
Library.framework.MaaControllerPostTouchUp.restype = MaaCtrlId
|
|
267
|
-
Library.framework.MaaControllerPostTouchUp.argtypes = [
|
|
266
|
+
Library.framework().MaaControllerPostTouchUp.restype = MaaCtrlId
|
|
267
|
+
Library.framework().MaaControllerPostTouchUp.argtypes = [
|
|
268
268
|
MaaControllerHandle,
|
|
269
269
|
c_int32,
|
|
270
270
|
]
|
|
271
|
-
Library.framework.MaaControllerStatus.restype = MaaStatus
|
|
272
|
-
Library.framework.MaaControllerStatus.argtypes = [
|
|
271
|
+
Library.framework().MaaControllerStatus.restype = MaaStatus
|
|
272
|
+
Library.framework().MaaControllerStatus.argtypes = [
|
|
273
273
|
MaaControllerHandle,
|
|
274
274
|
MaaCtrlId,
|
|
275
275
|
]
|
|
276
276
|
|
|
277
|
-
Library.framework.MaaControllerWait.restype = MaaStatus
|
|
278
|
-
Library.framework.MaaControllerWait.argtypes = [
|
|
277
|
+
Library.framework().MaaControllerWait.restype = MaaStatus
|
|
278
|
+
Library.framework().MaaControllerWait.argtypes = [
|
|
279
279
|
MaaControllerHandle,
|
|
280
280
|
MaaCtrlId,
|
|
281
281
|
]
|
|
282
282
|
|
|
283
|
-
Library.framework.MaaControllerConnected.restype = MaaBool
|
|
284
|
-
Library.framework.MaaControllerConnected.argtypes = [MaaControllerHandle]
|
|
283
|
+
Library.framework().MaaControllerConnected.restype = MaaBool
|
|
284
|
+
Library.framework().MaaControllerConnected.argtypes = [MaaControllerHandle]
|
|
285
285
|
|
|
286
|
-
Library.framework.MaaControllerCachedImage.restype = MaaBool
|
|
287
|
-
Library.framework.MaaControllerCachedImage.argtypes = [
|
|
286
|
+
Library.framework().MaaControllerCachedImage.restype = MaaBool
|
|
287
|
+
Library.framework().MaaControllerCachedImage.argtypes = [
|
|
288
288
|
MaaControllerHandle,
|
|
289
289
|
MaaImageBufferHandle,
|
|
290
290
|
]
|
|
291
291
|
|
|
292
|
-
Library.framework.MaaControllerGetUuid.restype = MaaBool
|
|
293
|
-
Library.framework.MaaControllerGetUuid.argtypes = [
|
|
292
|
+
Library.framework().MaaControllerGetUuid.restype = MaaBool
|
|
293
|
+
Library.framework().MaaControllerGetUuid.argtypes = [
|
|
294
294
|
MaaControllerHandle,
|
|
295
295
|
MaaStringBufferHandle,
|
|
296
296
|
]
|
|
@@ -317,7 +317,7 @@ class AdbController(Controller):
|
|
|
317
317
|
|
|
318
318
|
self._notification_handler = notification_handler
|
|
319
319
|
|
|
320
|
-
self._handle = Library.framework.MaaAdbControllerCreate(
|
|
320
|
+
self._handle = Library.framework().MaaAdbControllerCreate(
|
|
321
321
|
str(adb_path).encode(),
|
|
322
322
|
address.encode(),
|
|
323
323
|
MaaAdbScreencapMethod(screencap_methods),
|
|
@@ -332,8 +332,8 @@ class AdbController(Controller):
|
|
|
332
332
|
|
|
333
333
|
def _set_adb_api_properties(self):
|
|
334
334
|
|
|
335
|
-
Library.framework.MaaAdbControllerCreate.restype = MaaControllerHandle
|
|
336
|
-
Library.framework.MaaAdbControllerCreate.argtypes = [
|
|
335
|
+
Library.framework().MaaAdbControllerCreate.restype = MaaControllerHandle
|
|
336
|
+
Library.framework().MaaAdbControllerCreate.argtypes = [
|
|
337
337
|
ctypes.c_char_p,
|
|
338
338
|
ctypes.c_char_p,
|
|
339
339
|
MaaAdbScreencapMethod,
|
|
@@ -349,7 +349,7 @@ class Win32Controller(Controller):
|
|
|
349
349
|
|
|
350
350
|
def __init__(
|
|
351
351
|
self,
|
|
352
|
-
hWnd:
|
|
352
|
+
hWnd: Union[ctypes.c_void_p, int, None],
|
|
353
353
|
screencap_method: int = MaaWin32ScreencapMethodEnum.DXGI_DesktopDup,
|
|
354
354
|
input_method: int = MaaWin32InputMethodEnum.Seize,
|
|
355
355
|
notification_handler: Optional[NotificationHandler] = None,
|
|
@@ -358,7 +358,7 @@ class Win32Controller(Controller):
|
|
|
358
358
|
self._set_win32_api_properties()
|
|
359
359
|
|
|
360
360
|
self._notification_handler = notification_handler
|
|
361
|
-
self._handle = Library.framework.MaaWin32ControllerCreate(
|
|
361
|
+
self._handle = Library.framework().MaaWin32ControllerCreate(
|
|
362
362
|
hWnd,
|
|
363
363
|
MaaWin32ScreencapMethod(screencap_method),
|
|
364
364
|
MaaWin32InputMethod(input_method),
|
|
@@ -369,8 +369,8 @@ class Win32Controller(Controller):
|
|
|
369
369
|
raise RuntimeError("Failed to create Win32 controller.")
|
|
370
370
|
|
|
371
371
|
def _set_win32_api_properties(self):
|
|
372
|
-
Library.framework.MaaWin32ControllerCreate.restype = MaaControllerHandle
|
|
373
|
-
Library.framework.MaaWin32ControllerCreate.argtypes = [
|
|
372
|
+
Library.framework().MaaWin32ControllerCreate.restype = MaaControllerHandle
|
|
373
|
+
Library.framework().MaaWin32ControllerCreate.argtypes = [
|
|
374
374
|
ctypes.c_void_p,
|
|
375
375
|
MaaWin32ScreencapMethod,
|
|
376
376
|
MaaWin32InputMethod,
|
|
@@ -393,7 +393,7 @@ class DbgController(Controller):
|
|
|
393
393
|
self._set_dbg_api_properties()
|
|
394
394
|
|
|
395
395
|
self._notification_handler = notification_handler
|
|
396
|
-
self._handle = Library.framework.MaaDbgControllerCreate(
|
|
396
|
+
self._handle = Library.framework().MaaDbgControllerCreate(
|
|
397
397
|
str(read_path).encode(),
|
|
398
398
|
str(write_path).encode(),
|
|
399
399
|
MaaDbgControllerType(dbg_type),
|
|
@@ -405,8 +405,8 @@ class DbgController(Controller):
|
|
|
405
405
|
raise RuntimeError("Failed to create DBG controller.")
|
|
406
406
|
|
|
407
407
|
def _set_dbg_api_properties(self):
|
|
408
|
-
Library.framework.MaaDbgControllerCreate.restype = MaaControllerHandle
|
|
409
|
-
Library.framework.MaaDbgControllerCreate.argtypes = [
|
|
408
|
+
Library.framework().MaaDbgControllerCreate.restype = MaaControllerHandle
|
|
409
|
+
Library.framework().MaaDbgControllerCreate.argtypes = [
|
|
410
410
|
ctypes.c_char_p,
|
|
411
411
|
ctypes.c_char_p,
|
|
412
412
|
MaaDbgControllerType,
|
|
@@ -444,7 +444,7 @@ class CustomController(Controller):
|
|
|
444
444
|
CustomController._c_input_text_agent,
|
|
445
445
|
)
|
|
446
446
|
|
|
447
|
-
self._handle = Library.framework.MaaCustomControllerCreate(
|
|
447
|
+
self._handle = Library.framework().MaaCustomControllerCreate(
|
|
448
448
|
self.c_handle,
|
|
449
449
|
self.c_arg,
|
|
450
450
|
*NotificationHandler._gen_c_param(self._notification_handler)
|
|
@@ -735,8 +735,8 @@ class CustomController(Controller):
|
|
|
735
735
|
return int(self.input_text(c_text.decode()))
|
|
736
736
|
|
|
737
737
|
def _set_custom_api_properties(self):
|
|
738
|
-
Library.framework.MaaCustomControllerCreate.restype = MaaControllerHandle
|
|
739
|
-
Library.framework.MaaCustomControllerCreate.argtypes = [
|
|
738
|
+
Library.framework().MaaCustomControllerCreate.restype = MaaControllerHandle
|
|
739
|
+
Library.framework().MaaCustomControllerCreate.argtypes = [
|
|
740
740
|
ctypes.POINTER(MaaCustomControllerCallbacks),
|
|
741
741
|
ctypes.c_void_p,
|
|
742
742
|
MaaNotificationCallback,
|
maa/define.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import ctypes
|
|
2
2
|
import platform
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from enum import IntEnum
|
|
4
|
+
from enum import IntEnum
|
|
5
5
|
from typing import List, Tuple, Union, Dict, Optional
|
|
6
6
|
|
|
7
7
|
import numpy
|
|
8
|
+
from strenum import StrEnum # For Python 3.9/3.10
|
|
8
9
|
|
|
9
10
|
MaaBool = ctypes.c_uint8
|
|
10
11
|
MaaSize = ctypes.c_size_t
|
|
@@ -52,7 +53,7 @@ MaaCtrlOption = MaaOption
|
|
|
52
53
|
MaaResOption = MaaOption
|
|
53
54
|
|
|
54
55
|
|
|
55
|
-
class MaaGlobalOptionEnum:
|
|
56
|
+
class MaaGlobalOptionEnum(IntEnum):
|
|
56
57
|
Invalid = 0
|
|
57
58
|
|
|
58
59
|
# Log dir
|
|
@@ -88,7 +89,7 @@ class MaaGlobalOptionEnum:
|
|
|
88
89
|
DebugMode = 6
|
|
89
90
|
|
|
90
91
|
|
|
91
|
-
class MaaCtrlOptionEnum:
|
|
92
|
+
class MaaCtrlOptionEnum(IntEnum):
|
|
92
93
|
Invalid = 0
|
|
93
94
|
|
|
94
95
|
# Only one of long and short side can be set, and the other is automatically scaled according to the aspect ratio.
|
|
@@ -110,13 +111,13 @@ class MaaCtrlOptionEnum:
|
|
|
110
111
|
Recording = 5
|
|
111
112
|
|
|
112
113
|
|
|
113
|
-
class MaaInferenceDeviceEnum:
|
|
114
|
+
class MaaInferenceDeviceEnum(IntEnum):
|
|
114
115
|
CPU = -2
|
|
115
116
|
Auto = -1
|
|
116
117
|
# and more gpu id or flag...
|
|
117
118
|
|
|
118
119
|
|
|
119
|
-
class MaaInferenceExecutionProviderEnum:
|
|
120
|
+
class MaaInferenceExecutionProviderEnum(IntEnum):
|
|
120
121
|
# I don't recommend setting up MaaResOption_InferenceDevice in this case,
|
|
121
122
|
# because you don't know which EP will be used on different user devices.
|
|
122
123
|
Auto = 0
|
|
@@ -139,7 +140,7 @@ class MaaInferenceExecutionProviderEnum:
|
|
|
139
140
|
CUDA = 4
|
|
140
141
|
|
|
141
142
|
|
|
142
|
-
class MaaResOptionEnum:
|
|
143
|
+
class MaaResOptionEnum(IntEnum):
|
|
143
144
|
Invalid = 0
|
|
144
145
|
|
|
145
146
|
# Use the specified inference device.
|
|
@@ -160,7 +161,7 @@ class MaaResOptionEnum:
|
|
|
160
161
|
MaaAdbScreencapMethod = ctypes.c_uint64
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
class MaaAdbScreencapMethodEnum:
|
|
164
|
+
class MaaAdbScreencapMethodEnum(IntEnum):
|
|
164
165
|
"""
|
|
165
166
|
Use bitwise OR to set the method you need
|
|
166
167
|
MaaFramework will test their speed and use the fastest one.
|
|
@@ -183,7 +184,7 @@ class MaaAdbScreencapMethodEnum:
|
|
|
183
184
|
MaaAdbInputMethod = ctypes.c_uint64
|
|
184
185
|
|
|
185
186
|
|
|
186
|
-
class MaaAdbInputMethodEnum:
|
|
187
|
+
class MaaAdbInputMethodEnum(IntEnum):
|
|
187
188
|
"""
|
|
188
189
|
Use bitwise OR to set the method you need
|
|
189
190
|
MaaFramework will select the available ones according to priority.
|
|
@@ -205,7 +206,7 @@ MaaWin32ScreencapMethod = ctypes.c_uint64
|
|
|
205
206
|
|
|
206
207
|
|
|
207
208
|
# No bitwise OR, just set it
|
|
208
|
-
class MaaWin32ScreencapMethodEnum:
|
|
209
|
+
class MaaWin32ScreencapMethodEnum(IntEnum):
|
|
209
210
|
Null = 0
|
|
210
211
|
|
|
211
212
|
GDI = 1
|
|
@@ -217,7 +218,7 @@ MaaWin32InputMethod = ctypes.c_uint64
|
|
|
217
218
|
|
|
218
219
|
|
|
219
220
|
# No bitwise OR, just set it
|
|
220
|
-
class MaaWin32InputMethodEnum:
|
|
221
|
+
class MaaWin32InputMethodEnum(IntEnum):
|
|
221
222
|
Null = 0
|
|
222
223
|
|
|
223
224
|
Seize = 1
|
|
@@ -228,7 +229,7 @@ class MaaWin32InputMethodEnum:
|
|
|
228
229
|
MaaDbgControllerType = ctypes.c_uint64
|
|
229
230
|
|
|
230
231
|
|
|
231
|
-
class MaaDbgControllerTypeEnum:
|
|
232
|
+
class MaaDbgControllerTypeEnum(IntEnum):
|
|
232
233
|
Null = 0
|
|
233
234
|
|
|
234
235
|
CarouselImage = 1
|
|
@@ -273,6 +274,8 @@ MaaToolkitAdbDeviceHandle = ctypes.c_void_p
|
|
|
273
274
|
MaaToolkitDesktopWindowListHandle = ctypes.c_void_p
|
|
274
275
|
MaaToolkitDesktopWindowHandle = ctypes.c_void_p
|
|
275
276
|
|
|
277
|
+
MaaAgentClientHandle = ctypes.c_void_p
|
|
278
|
+
|
|
276
279
|
|
|
277
280
|
class MaaCustomControllerCallbacks(ctypes.Structure):
|
|
278
281
|
ConnectFunc = FUNCTYPE(
|
|
@@ -446,7 +449,7 @@ RectType = Union[
|
|
|
446
449
|
]
|
|
447
450
|
|
|
448
451
|
|
|
449
|
-
class AlgorithmEnum(
|
|
452
|
+
class AlgorithmEnum(StrEnum):
|
|
450
453
|
DirectHit = "DirectHit"
|
|
451
454
|
TemplateMatch = "TemplateMatch"
|
|
452
455
|
FeatureMatch = "FeatureMatch"
|
maa/library.py
CHANGED
|
@@ -7,38 +7,126 @@ from .define import *
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Library:
|
|
10
|
+
_is_agent_server: bool = False
|
|
11
|
+
|
|
12
|
+
_framework: ctypes.CDLL = None
|
|
13
|
+
_toolkit: ctypes.CDLL = None
|
|
14
|
+
_agent_client: ctypes.CDLL = None
|
|
15
|
+
_agent_server: ctypes.CDLL = None
|
|
16
|
+
_lib_type = None
|
|
10
17
|
|
|
11
18
|
@staticmethod
|
|
12
|
-
def open(path: pathlib.Path):
|
|
19
|
+
def open(path: pathlib.Path, agent_server: bool = False):
|
|
20
|
+
if Library._api_properties_initialized:
|
|
21
|
+
return
|
|
22
|
+
|
|
13
23
|
if not path.exists():
|
|
14
24
|
raise FileNotFoundError(f"`{path}` does not exist.")
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
WINDOWS = "windows"
|
|
27
|
+
MACOS = "darwin"
|
|
28
|
+
LINUX = "linux"
|
|
29
|
+
|
|
30
|
+
Library._is_agent_server = agent_server
|
|
31
|
+
|
|
32
|
+
if not Library.is_agent_server():
|
|
33
|
+
framework_library = {
|
|
34
|
+
WINDOWS: "MaaFramework.dll",
|
|
35
|
+
MACOS: "libMaaFramework.dylib",
|
|
36
|
+
LINUX: "libMaaFramework.so",
|
|
37
|
+
}
|
|
38
|
+
agent_client_library = {
|
|
39
|
+
WINDOWS: "MaaAgentClient.dll",
|
|
40
|
+
MACOS: "libMaaAgentClient.dylib",
|
|
41
|
+
LINUX: "libMaaAgentClient.so",
|
|
42
|
+
}
|
|
43
|
+
else:
|
|
44
|
+
agent_server_library = {
|
|
45
|
+
WINDOWS: "MaaAgentServer.dll",
|
|
46
|
+
MACOS: "libMaaAgentServer.dylib",
|
|
47
|
+
LINUX: "libMaaAgentServer.so",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toolkit_library = {
|
|
51
|
+
WINDOWS: "MaaToolkit.dll",
|
|
52
|
+
MACOS: "libMaaToolkit.dylib",
|
|
53
|
+
LINUX: "libMaaToolkit.so",
|
|
20
54
|
}
|
|
21
55
|
|
|
22
56
|
platform_type = platform.system().lower()
|
|
23
57
|
|
|
24
58
|
if platform_type == "windows":
|
|
25
|
-
|
|
59
|
+
Library._lib_type = ctypes.WinDLL
|
|
26
60
|
else:
|
|
27
|
-
|
|
61
|
+
Library._lib_type = ctypes.CDLL
|
|
28
62
|
|
|
29
|
-
Library.
|
|
30
|
-
|
|
63
|
+
if not Library.is_agent_server():
|
|
64
|
+
Library.framework_libpath = path / framework_library[platform_type]
|
|
65
|
+
Library.agent_client_libpath = path / agent_client_library[platform_type]
|
|
66
|
+
else:
|
|
67
|
+
Library.agent_server_libpath = path / agent_server_library[platform_type]
|
|
31
68
|
|
|
32
|
-
Library.toolkit_libpath = path /
|
|
33
|
-
Library.toolkit = lib_import(str(Library.toolkit_libpath))
|
|
69
|
+
Library.toolkit_libpath = path / toolkit_library[platform_type]
|
|
34
70
|
|
|
35
|
-
|
|
71
|
+
@staticmethod
|
|
72
|
+
def framework() -> ctypes.CDLL:
|
|
73
|
+
if not Library.is_agent_server():
|
|
74
|
+
if not Library._framework:
|
|
75
|
+
Library._framework = Library._lib_type(str(Library.framework_libpath))
|
|
76
|
+
|
|
77
|
+
return Library._framework
|
|
78
|
+
else:
|
|
79
|
+
return Library.agent_server()
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def toolkit() -> ctypes.CDLL:
|
|
83
|
+
if not Library._toolkit:
|
|
84
|
+
Library._toolkit = Library._lib_type(str(Library.toolkit_libpath))
|
|
85
|
+
|
|
86
|
+
return Library._toolkit
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def agent_client() -> ctypes.CDLL:
|
|
90
|
+
if Library.is_agent_server():
|
|
91
|
+
raise ValueError("Agent server is not available in the current context.")
|
|
92
|
+
|
|
93
|
+
if not Library._agent_client:
|
|
94
|
+
Library._agent_client = Library._lib_type(
|
|
95
|
+
str(Library.agent_client_libpath)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return Library._agent_client
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def agent_server() -> ctypes.CDLL:
|
|
102
|
+
if not Library.is_agent_server():
|
|
103
|
+
raise ValueError("Agent client is not available in the current context.")
|
|
104
|
+
|
|
105
|
+
if not Library._agent_server:
|
|
106
|
+
Library._agent_server = Library._lib_type(
|
|
107
|
+
str(Library.agent_server_libpath)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
return Library._agent_server
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def is_agent_server() -> bool:
|
|
114
|
+
return Library._is_agent_server
|
|
36
115
|
|
|
37
116
|
@staticmethod
|
|
38
117
|
def version() -> str:
|
|
39
|
-
|
|
118
|
+
Library._set_api_properties()
|
|
119
|
+
|
|
120
|
+
return Library.framework().MaaVersion().decode()
|
|
121
|
+
|
|
122
|
+
_api_properties_initialized: bool = False
|
|
40
123
|
|
|
41
124
|
@staticmethod
|
|
42
125
|
def _set_api_properties():
|
|
43
|
-
Library.
|
|
44
|
-
|
|
126
|
+
if Library._api_properties_initialized:
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
Library._api_properties_initialized = True
|
|
130
|
+
|
|
131
|
+
Library.framework().MaaVersion.restype = ctypes.c_char_p
|
|
132
|
+
Library.framework().MaaVersion.argtypes = []
|
maa/notification_handler.py
CHANGED
|
@@ -2,13 +2,13 @@ import ctypes
|
|
|
2
2
|
import json
|
|
3
3
|
from abc import ABC
|
|
4
4
|
from typing import Optional, Tuple
|
|
5
|
-
from enum import
|
|
5
|
+
from enum import IntEnum
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
|
|
8
8
|
from .define import MaaNotificationCallback
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
# class NotificationEvent(
|
|
11
|
+
# class NotificationEvent(IntEnum):
|
|
12
12
|
# ResourceLoading = 1
|
|
13
13
|
# ControllerAction = 2
|
|
14
14
|
# TaskerTask = 3
|
|
@@ -17,7 +17,7 @@ from .define import MaaNotificationCallback
|
|
|
17
17
|
# TaskAction = 6
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
class NotificationType(
|
|
20
|
+
class NotificationType(IntEnum):
|
|
21
21
|
Unknown = 0
|
|
22
22
|
Starting = 1
|
|
23
23
|
Succeeded = 2
|