simulator修正为emulator
This commit is contained in:
parent
9668edd7d6
commit
4f38fa732c
8 changed files with 73 additions and 73 deletions
|
@ -315,13 +315,13 @@ class RIICPart(ConfModel):
|
|||
"信赖值阈值"
|
||||
|
||||
|
||||
class SimulatorPart(ConfModel):
|
||||
class SimulatorConf(ConfModel):
|
||||
class EmulatorPart(ConfModel):
|
||||
class EmulatorConf(ConfModel):
|
||||
name: str = "MuMu12"
|
||||
"名称"
|
||||
index: str | int = "0"
|
||||
"多开编号"
|
||||
simulator_folder: str = ""
|
||||
emulator_folder: str = ""
|
||||
"文件夹"
|
||||
wait_time: int = 30
|
||||
"启动时间"
|
||||
|
@ -346,7 +346,7 @@ class SimulatorPart(ConfModel):
|
|||
|
||||
adb: str = "127.0.0.1:16384"
|
||||
"ADB连接地址"
|
||||
simulator: SimulatorConf
|
||||
emulator: EmulatorConf
|
||||
"模拟器"
|
||||
maa_adb_path: str = "D:\\Program Files\\Netease\\MuMu Player 12\\shell\\adb.exe"
|
||||
"ADB路径"
|
||||
|
@ -359,7 +359,7 @@ class SimulatorPart(ConfModel):
|
|||
tap_to_launch_game: TapToLaunchGameConf
|
||||
"点击屏幕启动游戏"
|
||||
strategy_when_idle: Literal[
|
||||
"do_nothing", "switch_to_home", "exit_game", "close_simulator"
|
||||
"do_nothing", "switch_to_home", "exit_game", "close_emulator"
|
||||
] = "switch_to_home"
|
||||
fix_mumu12_adb_disconnect: bool = False
|
||||
"关闭MuMu模拟器12时结束adb进程"
|
||||
|
@ -402,7 +402,7 @@ class Conf(
|
|||
RecruitPart,
|
||||
RegularTaskPart,
|
||||
RIICPart,
|
||||
SimulatorPart,
|
||||
EmulatorPart,
|
||||
SKLandPart,
|
||||
):
|
||||
@property
|
||||
|
|
|
@ -8,7 +8,7 @@ from mower.utils.csleep import MowerExit, csleep
|
|||
from mower.utils.log import logger
|
||||
|
||||
|
||||
class Simulator_Type(Enum):
|
||||
class Emulator_Type(Enum):
|
||||
Nox = "夜神"
|
||||
MuMu12 = "MuMu12"
|
||||
Leidian9 = "雷电9"
|
||||
|
@ -18,7 +18,7 @@ class Simulator_Type(Enum):
|
|||
Genymotion = "Genymotion"
|
||||
|
||||
|
||||
def restart_simulator(stop: bool = True, start: bool = True) -> bool:
|
||||
def restart_emulator(stop: bool = True, start: bool = True) -> bool:
|
||||
"""重启模拟器
|
||||
|
||||
Args:
|
||||
|
@ -28,42 +28,42 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
|
|||
Returns:
|
||||
是否成功
|
||||
"""
|
||||
data = config.conf.simulator
|
||||
data = config.conf.emulator
|
||||
index = data.index
|
||||
simulator_type = data.name
|
||||
simulator_folder = data.simulator_folder
|
||||
emulator_type = data.name
|
||||
emulator_folder = data.emulator_folder
|
||||
wait_time = data.wait_time
|
||||
hotkey = data.hotkey
|
||||
cmd = ""
|
||||
|
||||
if simulator_type not in Simulator_Type:
|
||||
logger.warning(f"尚未支持{simulator_type}重启/自动启动")
|
||||
if emulator_type not in Emulator_Type:
|
||||
logger.warning(f"尚未支持{emulator_type}重启/自动启动")
|
||||
csleep(10)
|
||||
return False
|
||||
|
||||
if simulator_type == Simulator_Type.Nox.value:
|
||||
if emulator_type == Emulator_Type.Nox.value:
|
||||
cmd = "Nox.exe"
|
||||
if int(index) >= 0:
|
||||
cmd += f" -clone:Nox_{index}"
|
||||
cmd += " -quit"
|
||||
elif simulator_type == Simulator_Type.MuMu12.value:
|
||||
elif emulator_type == Emulator_Type.MuMu12.value:
|
||||
cmd = "MuMuManager.exe api -v "
|
||||
if int(index) >= 0:
|
||||
cmd += f"{index} "
|
||||
cmd += "shutdown_player"
|
||||
elif simulator_type == Simulator_Type.Waydroid.value:
|
||||
elif emulator_type == Emulator_Type.Waydroid.value:
|
||||
cmd = "waydroid session stop"
|
||||
elif simulator_type == Simulator_Type.Leidian9.value:
|
||||
elif emulator_type == Emulator_Type.Leidian9.value:
|
||||
cmd = "ldconsole.exe quit --index "
|
||||
if int(index) >= 0:
|
||||
cmd += f"{index} "
|
||||
else:
|
||||
cmd += "0"
|
||||
elif simulator_type == Simulator_Type.ReDroid.value:
|
||||
elif emulator_type == Emulator_Type.ReDroid.value:
|
||||
cmd = f"docker stop {index} -t 0"
|
||||
elif simulator_type == Simulator_Type.MuMuPro.value:
|
||||
elif emulator_type == Emulator_Type.MuMuPro.value:
|
||||
cmd = f"Contents/MacOS/mumutool close {index}"
|
||||
elif simulator_type == Simulator_Type.Genymotion.value:
|
||||
elif emulator_type == Emulator_Type.Genymotion.value:
|
||||
if __system__ == "windows":
|
||||
cmd = "gmtool.exe"
|
||||
elif __system__ == "darwin":
|
||||
|
@ -73,30 +73,30 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
|
|||
cmd += f' admin stop "{index}"'
|
||||
|
||||
if stop:
|
||||
logger.info(f"关闭{simulator_type}模拟器")
|
||||
exec_cmd(cmd, simulator_folder, 0)
|
||||
if simulator_type == "MuMu12" and config.conf.fix_mumu12_adb_disconnect:
|
||||
logger.info(f"关闭{emulator_type}模拟器")
|
||||
exec_cmd(cmd, emulator_folder, 0)
|
||||
if emulator_type == "MuMu12" and config.conf.fix_mumu12_adb_disconnect:
|
||||
logger.info("结束adb进程")
|
||||
system("taskkill /f /t /im adb.exe")
|
||||
|
||||
if start:
|
||||
csleep(3)
|
||||
if simulator_type == Simulator_Type.Nox.value:
|
||||
if emulator_type == Emulator_Type.Nox.value:
|
||||
cmd = cmd.replace(" -quit", "")
|
||||
elif simulator_type == Simulator_Type.MuMu12.value:
|
||||
elif emulator_type == Emulator_Type.MuMu12.value:
|
||||
cmd = cmd.replace(" shutdown_player", " launch_player")
|
||||
elif simulator_type == Simulator_Type.Waydroid.value:
|
||||
elif emulator_type == Emulator_Type.Waydroid.value:
|
||||
cmd = "waydroid show-full-ui"
|
||||
elif simulator_type == Simulator_Type.Leidian9.value:
|
||||
elif emulator_type == Emulator_Type.Leidian9.value:
|
||||
cmd = cmd.replace("quit", "launch")
|
||||
elif simulator_type == Simulator_Type.ReDroid.value:
|
||||
elif emulator_type == Emulator_Type.ReDroid.value:
|
||||
cmd = f"docker start {index}"
|
||||
elif simulator_type == Simulator_Type.MuMuPro.value:
|
||||
elif emulator_type == Emulator_Type.MuMuPro.value:
|
||||
cmd = cmd.replace("close", "open")
|
||||
elif simulator_type == Simulator_Type.Genymotion.value:
|
||||
elif emulator_type == Emulator_Type.Genymotion.value:
|
||||
cmd = cmd.replace("stop", "start", 1)
|
||||
logger.info(f"启动{simulator_type}模拟器")
|
||||
if exec_cmd(cmd, simulator_folder, wait_time):
|
||||
logger.info(f"启动{emulator_type}模拟器")
|
||||
if exec_cmd(cmd, emulator_folder, wait_time):
|
||||
if hotkey:
|
||||
hotkey = hotkey.split("+")
|
||||
import pyautogui
|
||||
|
@ -104,7 +104,7 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
|
|||
pyautogui.FAILSAFE = False
|
||||
pyautogui.hotkey(*hotkey)
|
||||
return True
|
||||
return restart_simulator()
|
||||
return restart_emulator()
|
||||
return True
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ def exec_cmd(cmd, folder_path, wait_time):
|
|||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True,
|
||||
)
|
||||
if config.conf.simulator.name == Simulator_Type.Genymotion.value:
|
||||
if config.conf.emulator.name == Emulator_Type.Genymotion.value:
|
||||
while wait_time > 0:
|
||||
try:
|
||||
csleep(0)
|
|
@ -1,4 +1,4 @@
|
|||
class SimulatorError(Exception):
|
||||
class EmulatorError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ from adbutils import AdbClient, AdbDevice
|
|||
from mower import __system__
|
||||
from mower.utils import config
|
||||
from mower.utils.csleep import MowerExit, csleep
|
||||
from mower.utils.device.exception import SimulatorError
|
||||
from mower.utils.device.simulator import restart_simulator
|
||||
from mower.utils.device.emulator import restart_emulator
|
||||
from mower.utils.device.exception import EmulatorError
|
||||
from mower.utils.image import bytes2img
|
||||
from mower.utils.log import logger
|
||||
|
||||
|
@ -33,9 +33,9 @@ def retry_adb(func):
|
|||
except ADBServerError as e:
|
||||
logger.exception(e)
|
||||
self.restart_server()
|
||||
except SimulatorError as e:
|
||||
except EmulatorError as e:
|
||||
logger.exception(e)
|
||||
restart_simulator()
|
||||
restart_emulator()
|
||||
self._adb_device = None
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
@ -75,13 +75,13 @@ class ADB:
|
|||
try:
|
||||
adb_client.connect(config.conf.adb, 10)
|
||||
except Exception as e:
|
||||
raise SimulatorError(e)
|
||||
raise EmulatorError(e)
|
||||
elif devices[0].state == "offline":
|
||||
try:
|
||||
adb_client.disconnect(config.conf.adb)
|
||||
adb_client.connect(config.conf.adb, 10)
|
||||
except Exception as e:
|
||||
raise SimulatorError(e)
|
||||
raise EmulatorError(e)
|
||||
|
||||
self._adb_device = AdbDevice(adb_client, config.conf.adb)
|
||||
self.check_device_status()
|
||||
|
@ -172,7 +172,7 @@ class ADB:
|
|||
try:
|
||||
self.adb.shell("echo test")
|
||||
except Exception:
|
||||
raise SimulatorError("设备未连接")
|
||||
raise EmulatorError("设备未连接")
|
||||
|
||||
def process(
|
||||
self, path: str, args: list[str] = [], stderr: int = subprocess.DEVNULL
|
||||
|
|
|
@ -6,8 +6,8 @@ import numpy as np
|
|||
|
||||
from mower.utils import config
|
||||
from mower.utils.csleep import MowerExit
|
||||
from mower.utils.device.exception import GameError, SimulatorError
|
||||
from mower.utils.device.simulator import restart_simulator
|
||||
from mower.utils.device.emulator import restart_emulator
|
||||
from mower.utils.device.exception import EmulatorError, GameError
|
||||
from mower.utils.log import logger
|
||||
|
||||
|
||||
|
@ -30,9 +30,9 @@ def retry_mumuipc(func):
|
|||
except GameError as e:
|
||||
logger.exception(e)
|
||||
config.device.app_control.check_current_focus()
|
||||
except SimulatorError as e:
|
||||
except EmulatorError as e:
|
||||
logger.exception(e)
|
||||
restart_simulator()
|
||||
restart_emulator()
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
|
@ -41,13 +41,13 @@ def retry_mumuipc(func):
|
|||
|
||||
class MuMu12IPC:
|
||||
def __init__(self):
|
||||
self.simulator_folder = config.conf.simulator.simulator_folder
|
||||
self.instanse_index = int(config.conf.simulator.index)
|
||||
self.emulator_folder = config.conf.emulator.emulator_folder
|
||||
self.instanse_index = int(config.conf.emulator.index)
|
||||
self.connection = 0
|
||||
self.display_id = -1
|
||||
# 加载动态链接库
|
||||
dll_path = os.path.join(
|
||||
self.simulator_folder, "sdk", "external_renderer_ipc.dll"
|
||||
self.emulator_folder, "sdk", "external_renderer_ipc.dll"
|
||||
)
|
||||
try:
|
||||
self.external_renderer = ctypes.CDLL(dll_path)
|
||||
|
@ -91,11 +91,11 @@ class MuMu12IPC:
|
|||
def connect(self):
|
||||
"连接到 emulator"
|
||||
self.connection = self.external_renderer.nemu_connect(
|
||||
ctypes.c_wchar_p(os.path.dirname(self.simulator_folder)),
|
||||
ctypes.c_wchar_p(os.path.dirname(self.emulator_folder)),
|
||||
self.instanse_index,
|
||||
)
|
||||
if self.connection == 0:
|
||||
raise SimulatorError("连接模拟器失败,请启动模拟器")
|
||||
raise EmulatorError("连接模拟器失败,请启动模拟器")
|
||||
logger.info("连接模拟器成功")
|
||||
|
||||
def get_display_id(self) -> int:
|
||||
|
|
|
@ -4,7 +4,7 @@ import networkx as nx
|
|||
|
||||
from mower.utils import config
|
||||
from mower.utils.csleep import MowerExit
|
||||
from mower.utils.device.simulator import restart_simulator
|
||||
from mower.utils.device.emulator import restart_emulator
|
||||
from mower.utils.log import logger
|
||||
from mower.utils.scene import Scene, SceneComment
|
||||
from mower.utils.solver import BaseSolver
|
||||
|
@ -77,8 +77,8 @@ class SceneGraphSolver(BaseSolver):
|
|||
self.sleep()
|
||||
|
||||
def idle_solver(self):
|
||||
if config.conf.strategy_when_idle == "close_simulator":
|
||||
restart_simulator(start=False)
|
||||
if config.conf.strategy_when_idle == "close_emulator":
|
||||
restart_emulator(start=False)
|
||||
elif config.conf.strategy_when_idle == "exit_game" and config.device:
|
||||
config.device.exit()
|
||||
elif config.conf.strategy_when_idle == "switch_to_home":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue