simulator修正为emulator

This commit is contained in:
Elaina 2024-12-02 23:19:24 +08:00
parent 9668edd7d6
commit 4f38fa732c
8 changed files with 73 additions and 73 deletions

View file

@ -315,13 +315,13 @@ class RIICPart(ConfModel):
"信赖值阈值" "信赖值阈值"
class SimulatorPart(ConfModel): class EmulatorPart(ConfModel):
class SimulatorConf(ConfModel): class EmulatorConf(ConfModel):
name: str = "MuMu12" name: str = "MuMu12"
"名称" "名称"
index: str | int = "0" index: str | int = "0"
"多开编号" "多开编号"
simulator_folder: str = "" emulator_folder: str = ""
"文件夹" "文件夹"
wait_time: int = 30 wait_time: int = 30
"启动时间" "启动时间"
@ -346,7 +346,7 @@ class SimulatorPart(ConfModel):
adb: str = "127.0.0.1:16384" adb: str = "127.0.0.1:16384"
"ADB连接地址" "ADB连接地址"
simulator: SimulatorConf emulator: EmulatorConf
"模拟器" "模拟器"
maa_adb_path: str = "D:\\Program Files\\Netease\\MuMu Player 12\\shell\\adb.exe" maa_adb_path: str = "D:\\Program Files\\Netease\\MuMu Player 12\\shell\\adb.exe"
"ADB路径" "ADB路径"
@ -359,7 +359,7 @@ class SimulatorPart(ConfModel):
tap_to_launch_game: TapToLaunchGameConf tap_to_launch_game: TapToLaunchGameConf
"点击屏幕启动游戏" "点击屏幕启动游戏"
strategy_when_idle: Literal[ 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" ] = "switch_to_home"
fix_mumu12_adb_disconnect: bool = False fix_mumu12_adb_disconnect: bool = False
"关闭MuMu模拟器12时结束adb进程" "关闭MuMu模拟器12时结束adb进程"
@ -402,7 +402,7 @@ class Conf(
RecruitPart, RecruitPart,
RegularTaskPart, RegularTaskPart,
RIICPart, RIICPart,
SimulatorPart, EmulatorPart,
SKLandPart, SKLandPart,
): ):
@property @property

View file

@ -8,7 +8,7 @@ from mower.utils.csleep import MowerExit, csleep
from mower.utils.log import logger from mower.utils.log import logger
class Simulator_Type(Enum): class Emulator_Type(Enum):
Nox = "夜神" Nox = "夜神"
MuMu12 = "MuMu12" MuMu12 = "MuMu12"
Leidian9 = "雷电9" Leidian9 = "雷电9"
@ -18,7 +18,7 @@ class Simulator_Type(Enum):
Genymotion = "Genymotion" Genymotion = "Genymotion"
def restart_simulator(stop: bool = True, start: bool = True) -> bool: def restart_emulator(stop: bool = True, start: bool = True) -> bool:
"""重启模拟器 """重启模拟器
Args: Args:
@ -28,42 +28,42 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
Returns: Returns:
是否成功 是否成功
""" """
data = config.conf.simulator data = config.conf.emulator
index = data.index index = data.index
simulator_type = data.name emulator_type = data.name
simulator_folder = data.simulator_folder emulator_folder = data.emulator_folder
wait_time = data.wait_time wait_time = data.wait_time
hotkey = data.hotkey hotkey = data.hotkey
cmd = "" cmd = ""
if simulator_type not in Simulator_Type: if emulator_type not in Emulator_Type:
logger.warning(f"尚未支持{simulator_type}重启/自动启动") logger.warning(f"尚未支持{emulator_type}重启/自动启动")
csleep(10) csleep(10)
return False return False
if simulator_type == Simulator_Type.Nox.value: if emulator_type == Emulator_Type.Nox.value:
cmd = "Nox.exe" cmd = "Nox.exe"
if int(index) >= 0: if int(index) >= 0:
cmd += f" -clone:Nox_{index}" cmd += f" -clone:Nox_{index}"
cmd += " -quit" cmd += " -quit"
elif simulator_type == Simulator_Type.MuMu12.value: elif emulator_type == Emulator_Type.MuMu12.value:
cmd = "MuMuManager.exe api -v " cmd = "MuMuManager.exe api -v "
if int(index) >= 0: if int(index) >= 0:
cmd += f"{index} " cmd += f"{index} "
cmd += "shutdown_player" cmd += "shutdown_player"
elif simulator_type == Simulator_Type.Waydroid.value: elif emulator_type == Emulator_Type.Waydroid.value:
cmd = "waydroid session stop" cmd = "waydroid session stop"
elif simulator_type == Simulator_Type.Leidian9.value: elif emulator_type == Emulator_Type.Leidian9.value:
cmd = "ldconsole.exe quit --index " cmd = "ldconsole.exe quit --index "
if int(index) >= 0: if int(index) >= 0:
cmd += f"{index} " cmd += f"{index} "
else: else:
cmd += "0" cmd += "0"
elif simulator_type == Simulator_Type.ReDroid.value: elif emulator_type == Emulator_Type.ReDroid.value:
cmd = f"docker stop {index} -t 0" 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}" cmd = f"Contents/MacOS/mumutool close {index}"
elif simulator_type == Simulator_Type.Genymotion.value: elif emulator_type == Emulator_Type.Genymotion.value:
if __system__ == "windows": if __system__ == "windows":
cmd = "gmtool.exe" cmd = "gmtool.exe"
elif __system__ == "darwin": elif __system__ == "darwin":
@ -73,30 +73,30 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
cmd += f' admin stop "{index}"' cmd += f' admin stop "{index}"'
if stop: if stop:
logger.info(f"关闭{simulator_type}模拟器") logger.info(f"关闭{emulator_type}模拟器")
exec_cmd(cmd, simulator_folder, 0) exec_cmd(cmd, emulator_folder, 0)
if simulator_type == "MuMu12" and config.conf.fix_mumu12_adb_disconnect: if emulator_type == "MuMu12" and config.conf.fix_mumu12_adb_disconnect:
logger.info("结束adb进程") logger.info("结束adb进程")
system("taskkill /f /t /im adb.exe") system("taskkill /f /t /im adb.exe")
if start: if start:
csleep(3) csleep(3)
if simulator_type == Simulator_Type.Nox.value: if emulator_type == Emulator_Type.Nox.value:
cmd = cmd.replace(" -quit", "") 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") 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" cmd = "waydroid show-full-ui"
elif simulator_type == Simulator_Type.Leidian9.value: elif emulator_type == Emulator_Type.Leidian9.value:
cmd = cmd.replace("quit", "launch") cmd = cmd.replace("quit", "launch")
elif simulator_type == Simulator_Type.ReDroid.value: elif emulator_type == Emulator_Type.ReDroid.value:
cmd = f"docker start {index}" cmd = f"docker start {index}"
elif simulator_type == Simulator_Type.MuMuPro.value: elif emulator_type == Emulator_Type.MuMuPro.value:
cmd = cmd.replace("close", "open") 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) cmd = cmd.replace("stop", "start", 1)
logger.info(f"启动{simulator_type}模拟器") logger.info(f"启动{emulator_type}模拟器")
if exec_cmd(cmd, simulator_folder, wait_time): if exec_cmd(cmd, emulator_folder, wait_time):
if hotkey: if hotkey:
hotkey = hotkey.split("+") hotkey = hotkey.split("+")
import pyautogui import pyautogui
@ -104,7 +104,7 @@ def restart_simulator(stop: bool = True, start: bool = True) -> bool:
pyautogui.FAILSAFE = False pyautogui.FAILSAFE = False
pyautogui.hotkey(*hotkey) pyautogui.hotkey(*hotkey)
return True return True
return restart_simulator() return restart_emulator()
return True return True
@ -119,7 +119,7 @@ def exec_cmd(cmd, folder_path, wait_time):
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, 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: while wait_time > 0:
try: try:
csleep(0) csleep(0)

View file

@ -1,4 +1,4 @@
class SimulatorError(Exception): class EmulatorError(Exception):
pass pass

View file

@ -10,8 +10,8 @@ from adbutils import AdbClient, AdbDevice
from mower import __system__ from mower import __system__
from mower.utils import config from mower.utils import config
from mower.utils.csleep import MowerExit, csleep from mower.utils.csleep import MowerExit, csleep
from mower.utils.device.exception import SimulatorError from mower.utils.device.emulator import restart_emulator
from mower.utils.device.simulator import restart_simulator from mower.utils.device.exception import EmulatorError
from mower.utils.image import bytes2img from mower.utils.image import bytes2img
from mower.utils.log import logger from mower.utils.log import logger
@ -33,9 +33,9 @@ def retry_adb(func):
except ADBServerError as e: except ADBServerError as e:
logger.exception(e) logger.exception(e)
self.restart_server() self.restart_server()
except SimulatorError as e: except EmulatorError as e:
logger.exception(e) logger.exception(e)
restart_simulator() restart_emulator()
self._adb_device = None self._adb_device = None
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
@ -75,13 +75,13 @@ class ADB:
try: try:
adb_client.connect(config.conf.adb, 10) adb_client.connect(config.conf.adb, 10)
except Exception as e: except Exception as e:
raise SimulatorError(e) raise EmulatorError(e)
elif devices[0].state == "offline": elif devices[0].state == "offline":
try: try:
adb_client.disconnect(config.conf.adb) adb_client.disconnect(config.conf.adb)
adb_client.connect(config.conf.adb, 10) adb_client.connect(config.conf.adb, 10)
except Exception as e: except Exception as e:
raise SimulatorError(e) raise EmulatorError(e)
self._adb_device = AdbDevice(adb_client, config.conf.adb) self._adb_device = AdbDevice(adb_client, config.conf.adb)
self.check_device_status() self.check_device_status()
@ -172,7 +172,7 @@ class ADB:
try: try:
self.adb.shell("echo test") self.adb.shell("echo test")
except Exception: except Exception:
raise SimulatorError("设备未连接") raise EmulatorError("设备未连接")
def process( def process(
self, path: str, args: list[str] = [], stderr: int = subprocess.DEVNULL self, path: str, args: list[str] = [], stderr: int = subprocess.DEVNULL

View file

@ -6,8 +6,8 @@ import numpy as np
from mower.utils import config from mower.utils import config
from mower.utils.csleep import MowerExit from mower.utils.csleep import MowerExit
from mower.utils.device.exception import GameError, SimulatorError from mower.utils.device.emulator import restart_emulator
from mower.utils.device.simulator import restart_simulator from mower.utils.device.exception import EmulatorError, GameError
from mower.utils.log import logger from mower.utils.log import logger
@ -30,9 +30,9 @@ def retry_mumuipc(func):
except GameError as e: except GameError as e:
logger.exception(e) logger.exception(e)
config.device.app_control.check_current_focus() config.device.app_control.check_current_focus()
except SimulatorError as e: except EmulatorError as e:
logger.exception(e) logger.exception(e)
restart_simulator() restart_emulator()
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
@ -41,13 +41,13 @@ def retry_mumuipc(func):
class MuMu12IPC: class MuMu12IPC:
def __init__(self): def __init__(self):
self.simulator_folder = config.conf.simulator.simulator_folder self.emulator_folder = config.conf.emulator.emulator_folder
self.instanse_index = int(config.conf.simulator.index) self.instanse_index = int(config.conf.emulator.index)
self.connection = 0 self.connection = 0
self.display_id = -1 self.display_id = -1
# 加载动态链接库 # 加载动态链接库
dll_path = os.path.join( dll_path = os.path.join(
self.simulator_folder, "sdk", "external_renderer_ipc.dll" self.emulator_folder, "sdk", "external_renderer_ipc.dll"
) )
try: try:
self.external_renderer = ctypes.CDLL(dll_path) self.external_renderer = ctypes.CDLL(dll_path)
@ -91,11 +91,11 @@ class MuMu12IPC:
def connect(self): def connect(self):
"连接到 emulator" "连接到 emulator"
self.connection = self.external_renderer.nemu_connect( 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, self.instanse_index,
) )
if self.connection == 0: if self.connection == 0:
raise SimulatorError("连接模拟器失败,请启动模拟器") raise EmulatorError("连接模拟器失败,请启动模拟器")
logger.info("连接模拟器成功") logger.info("连接模拟器成功")
def get_display_id(self) -> int: def get_display_id(self) -> int:

View file

@ -4,7 +4,7 @@ import networkx as nx
from mower.utils import config from mower.utils import config
from mower.utils.csleep import MowerExit 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.log import logger
from mower.utils.scene import Scene, SceneComment from mower.utils.scene import Scene, SceneComment
from mower.utils.solver import BaseSolver from mower.utils.solver import BaseSolver
@ -77,8 +77,8 @@ class SceneGraphSolver(BaseSolver):
self.sleep() self.sleep()
def idle_solver(self): def idle_solver(self):
if config.conf.strategy_when_idle == "close_simulator": if config.conf.strategy_when_idle == "close_emulator":
restart_simulator(start=False) restart_emulator(start=False)
elif config.conf.strategy_when_idle == "exit_game" and config.device: elif config.conf.strategy_when_idle == "exit_game" and config.device:
config.device.exit() config.device.exit()
elif config.conf.strategy_when_idle == "switch_to_home": elif config.conf.strategy_when_idle == "switch_to_home":

File diff suppressed because one or more lines are too long

View file

@ -19,7 +19,7 @@ const facility_with_empty = computed(() => {
return [{ label: '(加速任意贸易站)', value: '' }].concat(left_side_facility) return [{ label: '(加速任意贸易站)', value: '' }].concat(left_side_facility)
}) })
const simulator_types = [ const emulator_types = [
{ label: '夜神', value: '夜神' }, { label: '夜神', value: '夜神' },
{ label: 'MuMu模拟器12', value: 'MuMu12' }, { label: 'MuMu模拟器12', value: 'MuMu12' },
{ label: 'Waydroid', value: 'Waydroid' }, { label: 'Waydroid', value: 'Waydroid' },
@ -39,13 +39,13 @@ const stop_options = [
{ label: '什么都不做', value: 'do_nothing' }, { label: '什么都不做', value: 'do_nothing' },
{ label: '返回桌面', value: 'switch_to_home' }, { label: '返回桌面', value: 'switch_to_home' },
{ label: '退出游戏', value: 'exit_game' }, { label: '退出游戏', value: 'exit_game' },
{ label: '退出模拟器', value: 'close_simulator' } { label: '退出模拟器', value: 'close_emulator' }
] ]
async function select_simulator_folder() { async function select_emulator_folder() {
const folder_path = await folder_dialog() const folder_path = await folder_dialog()
if (folder_path) { if (folder_path) {
conf.value.simulator.simulator_folder = folder_path conf.value.emulator.emulator_folder = folder_path
} }
} }
@ -74,7 +74,7 @@ const screencap_options = computed(() => {
{ label: 'DroidCast(有损压缩,速度较快)', value: 'droidcast' }, { label: 'DroidCast(有损压缩,速度较快)', value: 'droidcast' },
{ label: '自定义(以下命令需要向STDOUT打印截图文件)', value: 'diy' } { label: '自定义(以下命令需要向STDOUT打印截图文件)', value: 'diy' }
] ]
if (conf.value.simulator.name == 'MuMu12') { if (conf.value.emulator.name == 'MuMu12') {
result.push({ label: 'MuMu模拟器12专属截图(无损,速度超快)', value: 'mumuipc' }) result.push({ label: 'MuMu模拟器12专属截图(无损,速度超快)', value: 'mumuipc' })
} }
return result return result
@ -141,9 +141,9 @@ const screenshot_type = computed(() => {
label-align="left" label-align="left"
> >
<n-form-item label="模拟器"> <n-form-item label="模拟器">
<n-select v-model:value="conf.simulator.name" :options="simulator_types" /> <n-select v-model:value="conf.emulator.name" :options="emulator_types" />
</n-form-item> </n-form-item>
<n-form-item v-if="conf.simulator.name"> <n-form-item v-if="conf.emulator.name">
<template #label> <template #label>
<span>模拟器文件夹</span> <span>模拟器文件夹</span>
<help-text> <help-text>
@ -152,27 +152,27 @@ const screenshot_type = computed(() => {
</help-text> </help-text>
</template> </template>
<n-input <n-input
v-model:value="conf.simulator.simulator_folder" v-model:value="conf.emulator.emulator_folder"
type="textarea" type="textarea"
:autosize="true" :autosize="true"
/> />
<n-button @click="select_simulator_folder" class="dialog-btn">...</n-button> <n-button @click="select_emulator_folder" class="dialog-btn">...</n-button>
</n-form-item> </n-form-item>
<n-form-item v-if="conf.simulator.name"> <n-form-item v-if="conf.emulator.name">
<template #label> <template #label>
<span>多开编号</span> <span>多开编号</span>
<help-text> <help-text>
<div>除夜神单开选择-1以外其他的按照改模拟器多开器中的序号</div> <div>除夜神单开选择-1以外其他的按照改模拟器多开器中的序号</div>
</help-text> </help-text>
</template> </template>
<n-input v-model:value="conf.simulator.index" /> <n-input v-model:value="conf.emulator.index" />
</n-form-item> </n-form-item>
<n-form-item label="模拟器启动时间" v-if="conf.simulator.name"> <n-form-item label="模拟器启动时间" v-if="conf.emulator.name">
<n-input-number v-model:value="conf.simulator.wait_time"> <n-input-number v-model:value="conf.emulator.wait_time">
<template #suffix></template> <template #suffix></template>
</n-input-number> </n-input-number>
</n-form-item> </n-form-item>
<n-form-item v-if="conf.simulator.name"> <n-form-item v-if="conf.emulator.name">
<template #label> <template #label>
<span>模拟器老板键</span> <span>模拟器老板键</span>
<help-text> <help-text>
@ -194,7 +194,7 @@ const screenshot_type = computed(() => {
</help-text> </help-text>
</template> </template>
<n-input <n-input
v-model:value="conf.simulator.hotkey" v-model:value="conf.emulator.hotkey"
placeholder="留空停用;组合键用加号分隔" placeholder="留空停用;组合键用加号分隔"
/> />
</n-form-item> </n-form-item>
@ -222,7 +222,7 @@ const screenshot_type = computed(() => {
closable closable
style="margin: 8px 0" style="margin: 8px 0"
type="success" type="success"
v-if="conf.simulator.name == 'MuMu12' && conf.screencap_strategy != 'mumuipc'" v-if="conf.emulator.name == 'MuMu12' && conf.screencap_strategy != 'mumuipc'"
> >
通过共享内存的方式直接获取无损截图避免了编码解码跨进程传输等环节的开销截图速度远高于通用截图方案 通过共享内存的方式直接获取无损截图避免了编码解码跨进程传输等环节的开销截图速度远高于通用截图方案
</n-alert> </n-alert>
@ -231,7 +231,7 @@ const screenshot_type = computed(() => {
closable closable
style="margin: 8px 0" style="margin: 8px 0"
type="warning" type="warning"
v-if="conf.simulator.name == 'MuMu12' && conf.screencap_strategy == 'droidcast'" v-if="conf.emulator.name == 'MuMu12' && conf.screencap_strategy == 'droidcast'"
> >
在MuMu模拟器12上使用DroidCast截图方式需关闭后台保活或换用ADB+Gzip截图方式 在MuMu模拟器12上使用DroidCast截图方式需关闭后台保活或换用ADB+Gzip截图方式
</n-alert> </n-alert>
@ -292,7 +292,7 @@ const screenshot_type = computed(() => {
</n-form-item> </n-form-item>
<n-form-item <n-form-item
:show-label="false" :show-label="false"
v-if="conf.simulator.name == 'MuMu12' && conf.strategy_when_idle == 'close_simulator'" v-if="conf.emulator.name == 'MuMu12' && conf.strategy_when_idle == 'close_emulator'"
> >
<n-checkbox v-model:checked="conf.fix_mumu12_adb_disconnect"> <n-checkbox v-model:checked="conf.fix_mumu12_adb_disconnect">
关闭MuMu模拟器12时结束adb进程 关闭MuMu模拟器12时结束adb进程