mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
feat.初步完成跨平台移植的初始化部分
This commit is contained in:
@@ -2,6 +2,8 @@ import ctypes
|
||||
import os
|
||||
import json
|
||||
import pathlib
|
||||
import platform
|
||||
|
||||
from message import Message
|
||||
|
||||
|
||||
@@ -24,16 +26,20 @@ class Asst:
|
||||
``callback``: 回调函数
|
||||
``arg``: 自定义参数
|
||||
"""
|
||||
self.__dllpath = pathlib.Path(dirname) / 'MeoAssistant.dll'
|
||||
self.__dll = ctypes.WinDLL(str(self.__dllpath))
|
||||
if platform.system().lower() == 'windows':
|
||||
self.__libpath = pathlib.Path(dirname) / 'MeoAssistant.dll'
|
||||
self.__lib = ctypes.WinDLL(str(self.__libpath))
|
||||
else:
|
||||
self.__libpath = pathlib.Path(dirname) / 'libMeoAssistant.so'
|
||||
self.__lib = ctypes.CDLL(str(self.__libpath))
|
||||
|
||||
self.__dll.AsstCreateEx.restype = ctypes.c_void_p
|
||||
self.__dll.AsstCreateEx.argtypes = (ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p,)
|
||||
self.__ptr = self.__dll.AsstCreateEx(dirname.encode('utf-8'), callback, arg)
|
||||
self.__lib.AsstCreateEx.restype = ctypes.c_void_p
|
||||
self.__lib.AsstCreateEx.argtypes = (ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p,)
|
||||
self.__ptr = self.__lib.AsstCreateEx(dirname.encode('utf-8'), callback, arg)
|
||||
|
||||
def __del__(self):
|
||||
self.__dll.AsstDestroy.argtypes = (ctypes.c_void_p,)
|
||||
self.__dll.AsstDestroy(self.__ptr)
|
||||
self.__lib.AsstDestroy.argtypes = (ctypes.c_void_p,)
|
||||
self.__lib.AsstDestroy(self.__ptr)
|
||||
|
||||
def catch_default(self) -> bool:
|
||||
"""
|
||||
@@ -41,8 +47,8 @@ class Asst:
|
||||
|
||||
:return: 是否连接成功
|
||||
"""
|
||||
self.__dll.AsstCatchDefault.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstCatchDefault(self.__ptr)
|
||||
self.__lib.AsstCatchDefault.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstCatchDefault(self.__ptr)
|
||||
|
||||
def catch_emulator(self) -> bool:
|
||||
"""
|
||||
@@ -50,8 +56,8 @@ class Asst:
|
||||
|
||||
:return: 是否连接成功
|
||||
"""
|
||||
self.__dll.AsstCatchEmulator.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstCatchEmulator(self.__ptr)
|
||||
self.__lib.AsstCatchEmulator.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstCatchEmulator(self.__ptr)
|
||||
|
||||
def catch_custom(self, address: str) -> bool:
|
||||
"""
|
||||
@@ -59,9 +65,9 @@ class Asst:
|
||||
|
||||
:return: 是否连接成功
|
||||
"""
|
||||
self.__dll.AsstCatchCustom.argtypes = (
|
||||
self.__lib.AsstCatchCustom.argtypes = (
|
||||
ctypes.c_void_p, ctypes.c_char_p,)
|
||||
return self.__dll.AsstCatchCustom(self.__ptr, address.encode('utf-8'))
|
||||
return self.__lib.AsstCatchCustom(self.__ptr, address.encode('utf-8'))
|
||||
|
||||
def append_fight(self, stage: str, max_medicine: int, max_stone: int, max_times: int) -> bool:
|
||||
"""
|
||||
@@ -74,23 +80,23 @@ class Asst:
|
||||
``max_stone``: 最多吃多少源石
|
||||
``max_times``: 最多刷多少
|
||||
"""
|
||||
self.__dll.AsstAppendFight.argtypes = (
|
||||
self.__lib.AsstAppendFight.argtypes = (
|
||||
ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,)
|
||||
return self.__dll.AsstAppendFight(self.__ptr, stage.encode('utf-8'), max_medicine, max_stone, max_times)
|
||||
return self.__lib.AsstAppendFight(self.__ptr, stage.encode('utf-8'), max_medicine, max_stone, max_times)
|
||||
|
||||
def append_award(self) -> bool:
|
||||
"""
|
||||
添加领取每日奖励任务
|
||||
"""
|
||||
self.__dll.AsstAppendAward.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstAppendAward(self.__ptr)
|
||||
self.__lib.AsstAppendAward.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstAppendAward(self.__ptr)
|
||||
|
||||
def append_visit(self) -> bool:
|
||||
"""
|
||||
添加访问好友任务
|
||||
"""
|
||||
self.__dll.AsstAppendVisit.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstAppendVisit(self.__ptr)
|
||||
self.__lib.AsstAppendVisit.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstAppendVisit(self.__ptr)
|
||||
|
||||
def append_mall(self, with_shopping: bool) -> bool:
|
||||
"""
|
||||
@@ -99,8 +105,8 @@ class Asst:
|
||||
:params:
|
||||
``with_shopping``: 是否信用商店购物
|
||||
"""
|
||||
self.__dll.AsstAppendMall.argtypes = (ctypes.c_void_p, ctypes.c_bool)
|
||||
return self.__dll.AsstAppendMall(self.__ptr, with_shopping)
|
||||
self.__lib.AsstAppendMall.argtypes = (ctypes.c_void_p, ctypes.c_bool)
|
||||
return self.__lib.AsstAppendMall(self.__ptr, with_shopping)
|
||||
|
||||
def append_infrast(self, work_mode: int, order_list: list, uses_of_drones: str, dorm_threshold: float) -> bool:
|
||||
"""
|
||||
@@ -121,11 +127,11 @@ class Asst:
|
||||
order_arr = (ctypes.c_char_p * order_len)()
|
||||
order_arr[:] = order_byte_list
|
||||
|
||||
self.__dll.AsstAppendInfrast.argtypes = (
|
||||
self.__lib.AsstAppendInfrast.argtypes = (
|
||||
ctypes.c_void_p, ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_char_p), ctypes.c_int,
|
||||
ctypes.c_char_p, ctypes.c_double,)
|
||||
return self.__dll.AsstAppendInfrast(self.__ptr, work_mode,
|
||||
return self.__lib.AsstAppendInfrast(self.__ptr, work_mode,
|
||||
order_arr, order_len,
|
||||
uses_of_drones.encode('utf-8'), dorm_threshold)
|
||||
|
||||
@@ -147,11 +153,11 @@ class Asst:
|
||||
confirm_arr = (ctypes.c_int * confirm_len)()
|
||||
confirm_arr[:] = confirm_level
|
||||
|
||||
self.__dll.AsstAppendRecruit.argtypes = (
|
||||
self.__lib.AsstAppendRecruit.argtypes = (
|
||||
ctypes.c_void_p, ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int), ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_bool,)
|
||||
return self.__dll.AsstAppendRecruit(self.__ptr, max_times,
|
||||
return self.__lib.AsstAppendRecruit(self.__ptr, max_times,
|
||||
select_arr, select_len,
|
||||
confirm_arr, confirm_len, need_refresh)
|
||||
|
||||
@@ -159,8 +165,8 @@ class Asst:
|
||||
"""
|
||||
开始任务
|
||||
"""
|
||||
self.__dll.AsstStart.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstStart(self.__ptr)
|
||||
self.__lib.AsstStart.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstStart(self.__ptr)
|
||||
|
||||
def start_recurit_calc(self, select_level: list, set_time: bool) -> bool:
|
||||
"""
|
||||
@@ -174,16 +180,16 @@ class Asst:
|
||||
select_arr = (ctypes.c_int * select_len)()
|
||||
select_arr[:] = select_level
|
||||
|
||||
self.__dll.AsstStartRecruitCalc.argtypes = (
|
||||
self.__lib.AsstStartRecruitCalc.argtypes = (
|
||||
ctypes.c_void_p, ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_bool,)
|
||||
return self.__dll.AsstStartRecruitCalc(self.__ptr, select_arr, select_len, set_time)
|
||||
return self.__lib.AsstStartRecruitCalc(self.__ptr, select_arr, select_len, set_time)
|
||||
|
||||
def stop(self) -> bool:
|
||||
"""
|
||||
停止并清空所有任务
|
||||
"""
|
||||
self.__dll.AsstStop.argtypes = (ctypes.c_void_p,)
|
||||
return self.__dll.AsstStop(self.__ptr)
|
||||
self.__lib.AsstStop.argtypes = (ctypes.c_void_p,)
|
||||
return self.__lib.AsstStop(self.__ptr)
|
||||
|
||||
def set_penguin_id(self, id: str) -> bool:
|
||||
"""
|
||||
@@ -192,9 +198,9 @@ class Asst:
|
||||
:params:
|
||||
``id``: 企鹅物流ID,仅数字部分
|
||||
"""
|
||||
self.__dll.AsstSetPenguinId.argtypes = (
|
||||
self.__lib.AsstSetPenguinId.argtypes = (
|
||||
ctypes.c_void_p, ctypes.c_char_p)
|
||||
return self.__dll.AsstSetPenguinId(self.__ptr, id.encode('utf-8'))
|
||||
return self.__lib.AsstSetPenguinId(self.__ptr, id.encode('utf-8'))
|
||||
|
||||
def get_version(self) -> str:
|
||||
"""
|
||||
@@ -202,8 +208,8 @@ class Asst:
|
||||
|
||||
:return: 版本号
|
||||
"""
|
||||
self.__dll.AsstGetVersion.restype = ctypes.c_char_p
|
||||
return self.__dll.AsstGetVersion().decode('utf-8')
|
||||
self.__lib.AsstGetVersion.restype = ctypes.c_char_p
|
||||
return self.__lib.AsstGetVersion().decode('utf-8')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -213,16 +219,20 @@ if __name__ == "__main__":
|
||||
d = json.loads(details.decode('gbk'))
|
||||
print(Message(msg), d, arg)
|
||||
|
||||
dirname: str = (pathlib.Path.cwd().parent.parent / 'x64' / 'Release').__str__()
|
||||
if platform.system().lower() == 'windows':
|
||||
dirname: str = (pathlib.Path.cwd().parent.parent / 'x64' / 'Release').__str__()
|
||||
else:
|
||||
dirname: str = (pathlib.Path.cwd().parent.parent / 'build').__str__()
|
||||
|
||||
asst = Asst(dirname=dirname, callback=my_callback)
|
||||
|
||||
print('version', asst.get_version())
|
||||
|
||||
if asst.catch_default():
|
||||
if asst.catch_custom('127.0.0.1:5555'):
|
||||
print('连接成功')
|
||||
else:
|
||||
print('连接失败')
|
||||
os.system.exit()
|
||||
exit()
|
||||
|
||||
asst.append_fight("CE-5", 0, 0, 1)
|
||||
# asst.append_infrast(1, [ "Mfg", "Trade", "Control", "Power", "Reception", "Office", "Dorm"], "Money", 0.3)
|
||||
|
||||
Reference in New Issue
Block a user