MaaFw 3.0.4__py3-none-macosx_13_0_x86_64.whl → 4.0.0a1__py3-none-macosx_13_0_x86_64.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 CHANGED
@@ -9,4 +9,4 @@ if env_path:
9
9
  else:
10
10
  __PATH = Path(Path(__file__).parent, "bin")
11
11
 
12
- Library.open(__PATH)
12
+ Library.open(__PATH, agent_server=False)
maa/agent/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ import os
2
+ from pathlib import Path
3
+
4
+ from ..library import Library
5
+
6
+ env_path = os.environ.get("MAAFW_BINARY_PATH")
7
+ if env_path:
8
+ __PATH = Path(env_path)
9
+ else:
10
+ __PATH = Path(Path(__file__).parent.parent, "bin")
11
+
12
+ Library.open(__PATH, agent_server=True)
@@ -0,0 +1,132 @@
1
+ import ctypes
2
+ import sys
3
+
4
+ from ..define import *
5
+ from ..library import Library
6
+ from ..buffer import StringBuffer
7
+
8
+
9
+ class AgentServer:
10
+
11
+ @staticmethod
12
+ def custom_recognition(name: str):
13
+
14
+ def wrapper_recognition(recognition):
15
+ AgentServer.register_custom_recognition(
16
+ name=name, recognition=recognition()
17
+ )
18
+ return recognition
19
+
20
+ return wrapper_recognition
21
+
22
+ _custom_recognition_holder = {}
23
+
24
+ @staticmethod
25
+ def register_custom_recognition(
26
+ name: str, recognition: "CustomRecognition" # type: ignore
27
+ ) -> bool:
28
+
29
+ AgentServer._set_api_properties()
30
+
31
+ # avoid gc
32
+ AgentServer._custom_recognition_holder[name] = recognition
33
+
34
+ return bool(
35
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition(
36
+ name.encode(),
37
+ recognition.c_handle,
38
+ recognition.c_arg,
39
+ )
40
+ )
41
+
42
+ @staticmethod
43
+ def custom_action(name: str):
44
+
45
+ def wrapper_action(action):
46
+ AgentServer.register_custom_action(name=name, action=action())
47
+ return action
48
+
49
+ return wrapper_action
50
+
51
+ _custom_action_holder = {}
52
+
53
+ @staticmethod
54
+ def register_custom_action(name: str, action: "CustomAction") -> bool: # type: ignore
55
+
56
+ AgentServer._set_api_properties()
57
+
58
+ # avoid gc
59
+ AgentServer._custom_action_holder[name] = action
60
+
61
+ return bool(
62
+ Library.agent_server().MaaAgentServerRegisterCustomAction(
63
+ name.encode(),
64
+ action.c_handle,
65
+ action.c_arg,
66
+ )
67
+ )
68
+
69
+ @staticmethod
70
+ def start_up(identifier: str) -> bool:
71
+
72
+ AgentServer._set_api_properties()
73
+
74
+ return bool(Library.agent_server().MaaAgentServerStartUp(identifier.encode()))
75
+
76
+ @staticmethod
77
+ def shut_down() -> None:
78
+
79
+ AgentServer._set_api_properties()
80
+
81
+ Library.agent_server().MaaAgentServerShutDown()
82
+
83
+ @staticmethod
84
+ def join() -> None:
85
+
86
+ AgentServer._set_api_properties()
87
+
88
+ Library.agent_server().MaaAgentServerJoin()
89
+
90
+ @staticmethod
91
+ def detach(self) -> None:
92
+
93
+ AgentServer._set_api_properties()
94
+
95
+ Library.agent_server().MaaAgentServerDetach()
96
+
97
+ _api_properties_initialized: bool = False
98
+
99
+ @staticmethod
100
+ def _set_api_properties():
101
+ if AgentServer._api_properties_initialized:
102
+ return
103
+
104
+ AgentServer._api_properties_initialized = True
105
+
106
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition.restype = MaaBool
107
+ Library.agent_server().MaaAgentServerRegisterCustomRecognition.argtypes = [
108
+ ctypes.c_char_p,
109
+ MaaCustomRecognitionCallback,
110
+ ctypes.c_void_p,
111
+ ]
112
+
113
+ Library.agent_server().MaaAgentServerRegisterCustomAction.restype = MaaBool
114
+ Library.agent_server().MaaAgentServerRegisterCustomAction.argtypes = [
115
+ ctypes.c_char_p,
116
+ MaaCustomActionCallback,
117
+ ctypes.c_void_p,
118
+ ]
119
+
120
+ Library.agent_server().MaaAgentServerStartUp.restype = MaaBool
121
+ Library.agent_server().MaaAgentServerStartUp.argtypes = [
122
+ ctypes.c_char_p,
123
+ ]
124
+
125
+ Library.agent_server().MaaAgentServerShutDown.restype = None
126
+ Library.agent_server().MaaAgentServerShutDown.argtypes = []
127
+
128
+ Library.agent_server().MaaAgentServerJoin.restype = None
129
+ Library.agent_server().MaaAgentServerJoin.argtypes = []
130
+
131
+ Library.agent_server().MaaAgentServerDetach.restype = None
132
+ Library.agent_server().MaaAgentServerDetach.argtypes = []
maa/agent_client.py ADDED
@@ -0,0 +1,83 @@
1
+ import ctypes
2
+
3
+ from .define import *
4
+ from .library import Library
5
+ from .resource import Resource
6
+ from .buffer import StringBuffer
7
+
8
+
9
+ class AgentClient:
10
+ _handle: MaaAgentClientHandle
11
+
12
+ def __init__(self):
13
+ self._set_api_properties()
14
+
15
+ self._handle = Library.agent_client().MaaAgentClientCreate()
16
+ if not self._handle:
17
+ raise RuntimeError("Failed to create agent client.")
18
+
19
+ def __del__(self):
20
+ if self._handle:
21
+ Library.agent_client().MaaAgentClientDestroy(self._handle)
22
+
23
+ def bind(self, resource: Resource) -> bool:
24
+ # avoid gc
25
+ self._resource = resource
26
+
27
+ return bool(
28
+ Library.agent_client().MaaAgentClientBindResource(
29
+ self._handle, resource._handle
30
+ )
31
+ )
32
+
33
+ def create_socket(self, identifier: str = "") -> Optional[str]:
34
+ id_buffer = StringBuffer()
35
+ id_buffer.set(identifier)
36
+
37
+ ret = bool(
38
+ Library.agent_client().MaaAgentClientCreateSocket(
39
+ self._handle, id_buffer._handle
40
+ )
41
+ )
42
+ if not ret:
43
+ return None
44
+
45
+ return id_buffer.get()
46
+
47
+ def connect(self) -> bool:
48
+ return bool(Library.agent_client().MaaAgentClientConnect(self._handle))
49
+
50
+ _api_properties_initialized: bool = False
51
+
52
+ @staticmethod
53
+ def _set_api_properties():
54
+ if AgentClient._api_properties_initialized:
55
+ return
56
+
57
+ if Library.is_agent_server():
58
+ raise RuntimeError("AgentClient is not available in AgentServer.")
59
+
60
+ AgentClient._api_properties_initialized = True
61
+
62
+ Library.agent_client().MaaAgentClientCreate.restype = MaaAgentClientHandle
63
+ Library.agent_client().MaaAgentClientCreate.argtypes = []
64
+
65
+ Library.agent_client().MaaAgentClientDestroy.restype = None
66
+ Library.agent_client().MaaAgentClientDestroy.argtypes = [MaaAgentClientHandle]
67
+
68
+ Library.agent_client().MaaAgentClientBindResource.restype = MaaBool
69
+ Library.agent_client().MaaAgentClientBindResource.argtypes = [
70
+ MaaAgentClientHandle,
71
+ MaaResourceHandle,
72
+ ]
73
+
74
+ Library.agent_client().MaaAgentClientCreateSocket.restype = MaaBool
75
+ Library.agent_client().MaaAgentClientCreateSocket.argtypes = [
76
+ MaaAgentClientHandle,
77
+ MaaStringBufferHandle,
78
+ ]
79
+
80
+ Library.agent_client().MaaAgentClientConnect.restype = MaaBool
81
+ Library.agent_client().MaaAgentClientConnect.argtypes = [
82
+ MaaAgentClientHandle,
83
+ ]
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
maa/bin/libMaaUtils.dylib CHANGED
Binary file
maa/bin/libc++.1.dylib CHANGED
Binary file
maa/bin/libc++abi.1.dylib CHANGED
Binary file
Binary file
Binary file
Binary file