Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


class AppConfig(GlobalConfig):
VERSION = "v5.2.0-beta.2"
VERSION = "v5.2.0"

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -761,29 +761,29 @@ async def upload_script_to_web(
logger.error(f"无法上传配置到 AUTO-MAS 服务器: {e}")
raise ConnectionError(f"无法上传配置到 AUTO-MAS 服务器: {e}")

async def remove_privacy_info(self, confg: dict, name: str) -> dict:
async def remove_privacy_info(self, config: dict, name: str) -> dict:
"""移除配置中可能存在的隐私信息"""

confg["Info"]["Name"] = name
config["Info"]["Name"] = name
for path in ["ScriptPath", "ConfigPath", "LogPath", "TrackProcessExe"]:
if Path(confg["Script"][path]).is_relative_to(
Path(confg["Info"]["RootPath"])
if Path(config["Script"][path]).is_relative_to(
Path(config["Info"]["RootPath"])
):
confg["Script"][path] = str(
config["Script"][path] = str(
Path(r"C:/脚本根目录")
/ Path(confg["Script"][path]).relative_to(
Path(confg["Info"]["RootPath"])
/ Path(config["Script"][path]).relative_to(
Path(config["Info"]["RootPath"])
)
)
if sys.platform == "win32" and Path(confg["Script"][path]).is_relative_to(
if sys.platform == "win32" and Path(config["Script"][path]).is_relative_to(
Path(os.environ["APPDATA"])
):
confg["Script"][
config["Script"][
path
] = f"%APPDATA%/{Path(confg["Script"][path]).relative_to(Path(os.environ["APPDATA"]))}"
confg["Info"]["RootPath"] = str(Path(r"C:/脚本根目录"))
] = f"%APPDATA%/{Path(config['Script'][path]).relative_to(Path(os.environ['APPDATA']))}"
config["Info"]["RootPath"] = str(Path(r"C:/脚本根目录"))

return confg
return config

async def get_user(
self, script_id: str, user_id: Optional[str]
Expand Down
40 changes: 18 additions & 22 deletions app/task/MaaEnd/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from app.utils import get_logger, LogMonitor, ProcessManager
from app.tools import skland_sign_in
from app.utils.constants import UTC4, UTC8, MAAEND_KILLPROC_TASK
from .tools import login, push_notification, wait_and_focus_window
from .tools import login, push_notification

logger = get_logger("MaaEnd 自动代理")

Expand Down Expand Up @@ -113,17 +113,6 @@ async def prepare(self):

self.run_book = False

def _has_stop_sequence_completed(self, log: str) -> bool:
return any(
marker in log
for marker in (
"任务完成: 停止任务",
"任务完成: ⛔ 结束进程",
"任务完成: __MXU_KILLPROC__",
"任务完成: StopTask",
)
)

async def main_task(self):
"""自动代理模式主逻辑"""

Expand Down Expand Up @@ -243,11 +232,6 @@ async def main_task(self):
self.script_info.log = (
"正在启动游戏...\n游戏启动成功\n正在登录「明日方舟:终末地」..."
)
if self.emulator_manager is None and not await wait_and_focus_window(
"Endfield"
):
await self.handle_pre_maaend_error("未检测到 Endfield 窗口")
continue

if self.cur_user_config.get("Info", "Id") == "" or await login(
self.cur_user_config.get("Info", "Id"),
Expand All @@ -269,14 +253,18 @@ async def main_task(self):
await self.maaend_process_manager.open_process(
self.maaend_exe_path, stdout=asyncio.subprocess.PIPE
)

# 静默模式隐藏 MaaEnd 窗口
if Config.get("Function", "IfSilence"):
while datetime.now() - t < timedelta(minutes=1):
if await self.maaend_process_manager.is_visible():
await self.maaend_process_manager.hide_window()
break
await asyncio.sleep(0.1)
if self.script_config.get("Game", "ControllerType") == "Win32-Front":
if await self.game_process_manager.activate_window():
logger.success("前置 Endfield 窗口成功")
else:
logger.error("前置 Endfield 窗口失败")

await asyncio.sleep(1)
if isinstance(
Expand Down Expand Up @@ -401,6 +389,9 @@ async def set_maaend(self, device_info: DeviceInfo | None) -> None:
# 建立全局设置引用
settings = maaend_set["settings"]

# 移除冗余任务项信息
maaend_set["recentlyClosed"] = []

# 直接运行任务
settings["autoStartInstanceId"] = "automas"
settings["autoRunOnLaunch"] = True
Expand Down Expand Up @@ -509,10 +500,15 @@ async def check_log(self, log_content: list[str], latest_time: datetime) -> None
self.script_info.log = log
if "资源加载失败" in log:
self.cur_user_log.status = "MaaEnd 资源加载失败"
elif (not await self.maaend_process_manager.is_running()) or self._has_stop_sequence_completed(log):
# MaaEnd may close stdout before asyncio refreshes returncode.
# The explicit stop-task markers avoid missing the final completion pass.

elif "快捷键开始任务:失败" in log:
self.cur_user_log.status = "MaaEnd 任务启动失败"
elif (
"任务完成: 停止任务" in log
or "任务完成: ⛔ 结束进程" in log
or "任务完成: __MXU_KILLPROC__" in log
or "任务完成: StopTask" in log
or not await self.maaend_process_manager.is_running()
):
if self.task_dict is None:
self.cur_user_log.status = "MaaEnd 未加载任何任务"
else:
Expand Down
3 changes: 3 additions & 0 deletions app/task/MaaEnd/ScriptConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ async def set_maaend(self):
maaend_set["instances"] = [selected_instance]
maaend_set["lastActiveInstanceId"] = "automas"

# 移除冗余任务项信息
maaend_set["recentlyClosed"] = []

# 不直接运行任务
maaend_set["settings"]["autoStartInstanceId"] = "automas"
maaend_set["settings"]["autoRunOnLaunch"] = False
Expand Down
4 changes: 2 additions & 2 deletions app/task/MaaEnd/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

from .login import login
from .notify import push_notification
from .window import wait_and_focus_window

__all__ = ["login", "push_notification", "wait_and_focus_window"]

__all__ = ["login", "push_notification"]
47 changes: 16 additions & 31 deletions app/task/MaaEnd/tools/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,37 @@ async def login(
pipeline_override = {
"输入账号[EndFieldPC]": {"action": {"param": {"input_text": account}}},
"输入密码[EndFieldPC]": {"action": {"param": {"input_text": password}}},
"检查账号[EndFieldPC]": {
"recognition": {
"param": {
"expected": [f"{account[:3]}[a-zA-Z0-9 *]*{account[-2:]}"]
}
}
},
"选中账号[EndFieldPC]": {
"recognition": {
"param": {
"expected": [f"{account[:3]}[a-zA-Z0-9 *]*{account[-2:]}"]
}
}
},
}

try:
hwnd = win32gui.FindWindow(None, "Endfield")
tasker = await MaaFWManager.get_win32_tasker(
hwnd=hwnd,
screencap_method=MaaWin32ScreencapMethodEnum.PrintWindow,
screencap_method=MaaWin32ScreencapMethodEnum.FramePool,
mouse_method=MaaWin32InputMethodEnum.PostMessageWithCursorPos,
keyboard_method=MaaWin32InputMethodEnum.PostMessageWithCursorPos,
)
except Exception as e:
logger.error(f"获取终末地的 win32 控制器时出现异常: {e}")
return False

if win32gui.FindWindow(None, "Form") == 0:
try:
await MaaFWManager.do_job(
tasker.post_task(
"切换账号-调出登录框[EndFieldPC]", pipeline_override
)
)
except Exception as e:
logger.error(f"终末地调出登录框时出现异常: {e}")
return False
except asyncio.CancelledError:
with suppress(Exception):
await MaaFWManager.do_job(tasker.post_stop())
raise

try:
# 稍等登录表单弹出,避免窗口尚未创建时直接卡死。
await asyncio.sleep(3)
hwnd = win32gui.FindWindow(None, "Form")
tasker = await MaaFWManager.get_win32_tasker(
hwnd=hwnd,
screencap_method=MaaWin32ScreencapMethodEnum.PrintWindow,
mouse_method=MaaWin32InputMethodEnum.PostMessageWithCursorPos,
keyboard_method=MaaWin32InputMethodEnum.PostMessageWithCursorPos,
)
except Exception as e:
logger.error(f"获取终末地登录表单的 win32 控制器时出现异常: {e}")
return False

try:
await MaaFWManager.do_job(
tasker.post_task("切换账号-账号登录[EndFieldPC]", pipeline_override)
tasker.post_task("切换账号[EndFieldPC]", pipeline_override)
)
logger.success("终末地登录成功")
await asyncio.sleep(10) # 等待资源释放
Expand Down
41 changes: 0 additions & 41 deletions app/task/MaaEnd/tools/window.py

This file was deleted.

40 changes: 28 additions & 12 deletions app/task/SRC/tools/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ async def login(
if (package_name == "com.miHoYo.hkrpg" and "*" in id) or password == "":
logger.info("账号密码不完整,禁用通过输入账号密码登录")
pipeline_override = {
"切换账号[StarRailEmulator]": {"action": {"param": {"package": package_name}}},
"启动游戏[StarRailEmulator]": {"action": {"param": {"package": package_name}}},
"Bilibili隐私政策[StarRailEmulator]": {"enabled": Config.get("Function", "IfAgreeBilibili")},
"切换账号[StarRailEmulator]": {
"action": {"param": {"package": package_name}}
},
"启动游戏[StarRailEmulator]": {
"action": {"param": {"package": package_name}}
},
"Bilibili隐私政策[StarRailEmulator]": {
"enabled": Config.get("Function", "IfAgreeBilibili")
},
"下滑账号列表[StarRailEmulator]": {"on_error": []},
"下滑账号列表-B服[StarRailEmulator]": {"on_error": []},
"识别登录下拉框禁用[StarRailEmulator]": {"on_error": []},
"选中账号[StarRailEmulator]": {
"recognition": {
"param": {"expected": [f"^{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}$"]}
"param": {"expected": [f"{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}"]}
}
},
"验证当前账号[StarRailEmulator]": {
"recognition": {
"param": {"expected": [f"^{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}$"]}
"param": {"expected": [f"{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}"]}
}
},
"选中账号-B服[StarRailEmulator]": {
Expand All @@ -82,17 +88,23 @@ async def login(
}
else:
pipeline_override = {
"切换账号[StarRailEmulator]": {"action": {"param": {"package": package_name}}},
"启动游戏[StarRailEmulator]": {"action": {"param": {"package": package_name}}},
"Bilibili隐私政策[StarRailEmulator]": {"enabled": Config.get("Function", "IfAgreeBilibili")},
"切换账号[StarRailEmulator]": {
"action": {"param": {"package": package_name}}
},
"启动游戏[StarRailEmulator]": {
"action": {"param": {"package": package_name}}
},
"Bilibili隐私政策[StarRailEmulator]": {
"enabled": Config.get("Function", "IfAgreeBilibili")
},
"选中账号[StarRailEmulator]": {
"recognition": {
"param": {"expected": [f"^{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}$"]}
"param": {"expected": [f"{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}"]}
}
},
"验证当前账号[StarRailEmulator]": {
"recognition": {
"param": {"expected": [f"^{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}$"]}
"param": {"expected": [f"{id[:3]}[a-zA-Z0-9 *]*{id[-2:]}"]}
}
},
"选中账号-B服[StarRailEmulator]": {
Expand All @@ -104,15 +116,19 @@ async def login(
}
},
"输入账号[StarRailEmulator]": {"action": {"param": {"input_text": id}}},
"输入密码[StarRailEmulator]": {"action": {"param": {"input_text": password}}},
"输入密码[StarRailEmulator]": {
"action": {"param": {"input_text": password}}
},
"输入账号-B服[StarRailEmulator]": {
"action": {
"param": {
"input_text": id.split("|")[1].strip() if "|" in id else id
}
}
},
"输入密码-B服[StarRailEmulator]": {"action": {"param": {"input_text": password}}},
"输入密码-B服[StarRailEmulator]": {
"action": {"param": {"input_text": password}}
},
}

try:
Expand Down
13 changes: 7 additions & 6 deletions app/utils/LogMonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,15 @@ async def monitor_process(

line = ANSI_ESCAPE_RE.sub("", decode_bytes(bline))

if not line.strip():
continue

self.log_contents.append(line)
await self.update_latest_timestamp(line)

if datetime.now() - self.last_callback_time > timedelta(seconds=0.1):
if process_stream.at_eof():
logger.info("监控的流已结束")
await self.do_callback()
break

if datetime.now() - self.last_callback_time > timedelta(seconds=1):
await self.do_callback()

async def do_callback(self):
Expand All @@ -242,7 +244,7 @@ async def update_latest_timestamp(self, log: str, if_init: bool = False) -> None
self.latest_time = datetime.now()
return

if any(_ in log for _ in self.except_logs):
if log == "" or any(_ in log for _ in self.except_logs):
return

with suppress(IndexError, ValueError):
Expand All @@ -253,7 +255,6 @@ async def update_latest_timestamp(self, log: str, if_init: bool = False) -> None
self.time_format,
self.last_callback_time,
)
logger.debug(f"日志时间戳更新: {self.latest_time}")
self.last_log = log_text

async def start_monitor_file(
Expand Down
Loading
Loading