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 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

View file

@ -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)

View file

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

View file

@ -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

View file

@ -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:

View file

@ -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":

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)
})
const simulator_types = [
const emulator_types = [
{ label: '夜神', value: '夜神' },
{ label: 'MuMu模拟器12', value: 'MuMu12' },
{ label: 'Waydroid', value: 'Waydroid' },
@ -39,13 +39,13 @@ const stop_options = [
{ label: '什么都不做', value: 'do_nothing' },
{ label: '返回桌面', value: 'switch_to_home' },
{ 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()
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: '自定义(以下命令需要向STDOUT打印截图文件)', value: 'diy' }
]
if (conf.value.simulator.name == 'MuMu12') {
if (conf.value.emulator.name == 'MuMu12') {
result.push({ label: 'MuMu模拟器12专属截图(无损,速度超快)', value: 'mumuipc' })
}
return result
@ -141,9 +141,9 @@ const screenshot_type = computed(() => {
label-align="left"
>
<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 v-if="conf.simulator.name">
<n-form-item v-if="conf.emulator.name">
<template #label>
<span>模拟器文件夹</span>
<help-text>
@ -152,27 +152,27 @@ const screenshot_type = computed(() => {
</help-text>
</template>
<n-input
v-model:value="conf.simulator.simulator_folder"
v-model:value="conf.emulator.emulator_folder"
type="textarea"
: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 v-if="conf.simulator.name">
<n-form-item v-if="conf.emulator.name">
<template #label>
<span>多开编号</span>
<help-text>
<div>除夜神单开选择-1以外其他的按照改模拟器多开器中的序号</div>
</help-text>
</template>
<n-input v-model:value="conf.simulator.index" />
<n-input v-model:value="conf.emulator.index" />
</n-form-item>
<n-form-item label="模拟器启动时间" v-if="conf.simulator.name">
<n-input-number v-model:value="conf.simulator.wait_time">
<n-form-item label="模拟器启动时间" v-if="conf.emulator.name">
<n-input-number v-model:value="conf.emulator.wait_time">
<template #suffix></template>
</n-input-number>
</n-form-item>
<n-form-item v-if="conf.simulator.name">
<n-form-item v-if="conf.emulator.name">
<template #label>
<span>模拟器老板键</span>
<help-text>
@ -194,7 +194,7 @@ const screenshot_type = computed(() => {
</help-text>
</template>
<n-input
v-model:value="conf.simulator.hotkey"
v-model:value="conf.emulator.hotkey"
placeholder="留空停用;组合键用加号分隔"
/>
</n-form-item>
@ -222,7 +222,7 @@ const screenshot_type = computed(() => {
closable
style="margin: 8px 0"
type="success"
v-if="conf.simulator.name == 'MuMu12' && conf.screencap_strategy != 'mumuipc'"
v-if="conf.emulator.name == 'MuMu12' && conf.screencap_strategy != 'mumuipc'"
>
通过共享内存的方式直接获取无损截图避免了编码解码跨进程传输等环节的开销截图速度远高于通用截图方案
</n-alert>
@ -231,7 +231,7 @@ const screenshot_type = computed(() => {
closable
style="margin: 8px 0"
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截图方式
</n-alert>
@ -292,7 +292,7 @@ const screenshot_type = computed(() => {
</n-form-item>
<n-form-item
: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">
关闭MuMu模拟器12时结束adb进程