From 19157a4266fe94285e1f5c8770a80db659789416 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Wed, 24 Jul 2024 01:25:12 +0800 Subject: [PATCH 1/5] Fix: Exit to COMBAT_AGAIN if fuel exhausted --- tasks/combat/fuel.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/combat/fuel.py b/tasks/combat/fuel.py index ce4a287dc..06fc08df0 100644 --- a/tasks/combat/fuel.py +++ b/tasks/combat/fuel.py @@ -147,6 +147,10 @@ class Fuel(UI): Returns: bool: If used + + Pages: + in: COMBAT_AGAIN + out: COMBAT_AGAIN """ limit = self.config.stored.TrailblazePower.FIXED_TOTAL use = (limit - current) // self.fuel_trailblaze_power @@ -173,6 +177,7 @@ class Fuel(UI): has_fuel = True if not has_fuel and timeout.reached(): logger.info("No fuel found") + self._fuel_cancel() return False if self.appear_then_click(FUEL): has_fuel = True From 5ad44863c7ac4a9b081b40d277cac42d2eeafa24 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:51:22 +0800 Subject: [PATCH 2/5] Fix: [ALAS] use ldconsole.exe --- module/device/platform/emulator_windows.py | 24 ++++++++++++++++++++++ module/device/platform/platform_windows.py | 18 +++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/module/device/platform/emulator_windows.py b/module/device/platform/emulator_windows.py index d4d5477fb..021203ae7 100644 --- a/module/device/platform/emulator_windows.py +++ b/module/device/platform/emulator_windows.py @@ -155,6 +155,30 @@ class Emulator(EmulatorBase): else: yield exe + @staticmethod + def single_to_console(exe: str): + """ + Convert a string that might be a single instance executable to its console. + + Args: + exe (str): Path to emulator executable + + Returns: + str: Path to emulator console + """ + if 'MuMuPlayer.exe' in exe: + return exe.replace('MuMuPlayer.exe', 'MuMuManager.exe') + elif 'LDPlayer.exe' in exe: + return exe.replace('LDPlayer.exe', 'ldconsole.exe') + elif 'dnplayer.exe' in exe: + return exe.replace('dnplayer.exe', 'ldconsole.exe') + elif 'Bluestacks.exe' in exe: + return exe.replace('Bluestacks.exe', 'bsconsole.exe') + elif 'MEmu.exe' in exe: + return exe.replace('MEmu.exe', 'memuc.exe') + else: + return exe + @staticmethod def vbox_file_to_serial(file: str) -> str: """ diff --git a/module/device/platform/platform_windows.py b/module/device/platform/platform_windows.py index 5fd4a5a7f..a2eebd149 100644 --- a/module/device/platform/platform_windows.py +++ b/module/device/platform/platform_windows.py @@ -94,6 +94,9 @@ class PlatformWindows(PlatformBase, EmulatorManager): if instance.MuMuPlayer12_id is None: logger.warning(f'Cannot get MuMu instance index from name {instance.name}') self.execute(f'"{exe}" -v {instance.MuMuPlayer12_id}') + elif instance == Emulator.LDPlayerFamily: + # ldconsole.exe launch --index 0 + self.execute(f'"{Emulator.single_to_console(exe)}" launch --index {instance.LDPlayer_id}') elif instance == Emulator.NoxPlayerFamily: # Nox.exe -clone:Nox_1 self.execute(f'"{exe}" -clone:{instance.name}') @@ -141,11 +144,20 @@ class PlatformWindows(PlatformBase, EmulatorManager): rf')' ) elif instance == Emulator.MuMuPlayer12: - # MuMu 12 has 2 processes: - # E:\ProgramFiles\Netease\MuMuPlayer-12.0\shell\MuMuPlayer.exe -v 0 - # "C:\Program Files\MuMuVMMVbox\Hypervisor\MuMuVMMHeadless.exe" --comment MuMuPlayer-12.0-0 --startvm xxx + # MuMuManager.exe api -v 1 shutdown_player if instance.MuMuPlayer12_id is None: logger.warning(f'Cannot get MuMu instance index from name {instance.name}') + self.execute(f'"{Emulator.single_to_console(exe)}" api -v {instance.MuMuPlayer12_id} shutdown_player') + elif instance == Emulator.LDPlayerFamily: + # ldconsole.exe quit --index 0 + self.execute(f'"{Emulator.single_to_console(exe)}" quit --index {instance.LDPlayer_id}') + elif instance == Emulator.NoxPlayerFamily: + # Nox.exe -clone:Nox_1 -quit + self.execute(f'"{exe}" -clone:{instance.name} -quit') + elif instance == Emulator.BlueStacks5: + # BlueStack has 2 processes + # C:\Program Files\BlueStacks_nxt_cn\HD-Player.exe --instance Pie64 + # C:\Program Files\BlueStacks_nxt_cn\BstkSVC.exe -Embedding self.kill_process_by_regex( rf'(' rf'MuMuVMMHeadless.exe.*--comment {instance.name}' From bcd6afc94aa8bb3e0acc22596ef200416abdb510 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:17:37 +0800 Subject: [PATCH 3/5] Opt: [ALAS] Skip nemud_app_keep_alive check on non-mumu --- module/device/connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/device/connection.py b/module/device/connection.py index e8757106f..5779e9760 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -338,6 +338,8 @@ class Connection(ConnectionAttr): which has nemud.app_keep_alive and always be a vertical device MuMu PRO on mac has the same feature """ + if not self.is_mumu_family: + return False if self.nemud_app_keep_alive != '': return True if IS_MACINTOSH: From f008ecdd00cb3dd260e8b10d22e589326f1ed37d Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:34:22 +0800 Subject: [PATCH 4/5] Fix: [ALAS] Handle dynamic mumu serial in serial_to_id --- module/device/method/nemu_ipc.py | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/module/device/method/nemu_ipc.py b/module/device/method/nemu_ipc.py index b69cf9dd5..315c1897e 100644 --- a/module/device/method/nemu_ipc.py +++ b/module/device/method/nemu_ipc.py @@ -419,26 +419,28 @@ class NemuIpcImpl: if ret > 0: raise NemuIpcError('nemu_input_event_touch_up failed') + @staticmethod + def serial_to_id(serial: str): + """ + Predict instance ID from serial + E.g. + "127.0.0.1:16384" -> 0 + "127.0.0.1:16416" -> 1 + Port from 16414 to 16418 -> 1 -def serial_to_id(serial: str): - """ - Predict instance ID from serial - E.g. - "127.0.0.1:16384" -> 0 - "127.0.0.1:16416" -> 1 - - Returns: - int: instance_id, or None if failed to predict - """ - try: - port = int(serial.split(':')[1]) - except (IndexError, ValueError): - return None - index, offset = divmod(port - 16384, 32) - if 0 <= index < 32 and offset in [0, 1, 2]: - return index - else: - return None + Returns: + int: instance_id, or None if failed to predict + """ + try: + port = int(serial.split(':')[1]) + except (IndexError, ValueError): + return None + index, offset = divmod(port - 16384 + 16, 32) + offset -= 16 + if 0 <= index < 32 and offset in [-2, -1, 0, 1, 2]: + return index + else: + return None class NemuIpc(Platform): @@ -452,7 +454,7 @@ class NemuIpc(Platform): # Try existing settings first if self.config.EmulatorInfo_path: folder = os.path.abspath(os.path.join(self.config.EmulatorInfo_path, '../../')) - index = serial_to_id(self.serial) + index = NemuIpcImpl.serial_to_id(self.serial) if index is not None: try: return NemuIpcImpl( From 19eeb54a0f2635be4e3017ac82ca4c6fb7411caf Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Thu, 25 Jul 2024 01:27:55 +0800 Subject: [PATCH 5/5] Upd: Emulator launch arguments --- module/device/platform/emulator_base.py | 17 +++++++++ module/device/platform/platform_windows.py | 41 +++++++++++++++------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/module/device/platform/emulator_base.py b/module/device/platform/emulator_base.py index 394becc24..51925e9a6 100644 --- a/module/device/platform/emulator_base.py +++ b/module/device/platform/emulator_base.py @@ -114,6 +114,23 @@ class EmulatorInstanceBase: return None + @cached_property + def LDPlayer_id(self): + """ + Convert LDPlayer instance name to instance id. + Example names: + leidian0 + leidian1 + + Returns: + int: Instance ID, or None if this is not a LDPlayer instance + """ + res = re.search(r'leidian(\d+)', self.name) + if res: + return int(res.group(1)) + + return None + class EmulatorBase: # Values here must match those in argument.yaml EmulatorInfo.Emulator.option diff --git a/module/device/platform/platform_windows.py b/module/device/platform/platform_windows.py index a2eebd149..4b384eecf 100644 --- a/module/device/platform/platform_windows.py +++ b/module/device/platform/platform_windows.py @@ -82,7 +82,7 @@ class PlatformWindows(PlatformBase, EmulatorManager): """ Start a emulator without error handling """ - exe = instance.emulator.path + exe: str = instance.emulator.path if instance == Emulator.MuMuPlayer: # NemuPlayer.exe self.execute(exe) @@ -104,8 +104,11 @@ class PlatformWindows(PlatformBase, EmulatorManager): # HD-Player.exe --instance Pie64 self.execute(f'"{exe}" --instance {instance.name}') elif instance == Emulator.BlueStacks4: - # BlueStacks\Client\Bluestacks.exe -vmname Android_1 + # Bluestacks.exe -vmname Android_1 self.execute(f'"{exe}" -vmname {instance.name}') + elif instance == Emulator.MEmuPlayer: + # MEmu.exe MEmu_0 + self.execute(f'"{exe}" {instance.name}') else: raise EmulatorUnknown(f'Cannot start an unknown emulator instance: {instance}') @@ -113,8 +116,7 @@ class PlatformWindows(PlatformBase, EmulatorManager): """ Stop a emulator without error handling """ - logger.hr('Emulator stop', level=2) - exe = instance.emulator.path + exe: str = instance.emulator.path if instance == Emulator.MuMuPlayer: # MuMu6 does not have multi instance, kill one means kill all # Has 4 processes @@ -160,19 +162,19 @@ class PlatformWindows(PlatformBase, EmulatorManager): # C:\Program Files\BlueStacks_nxt_cn\BstkSVC.exe -Embedding self.kill_process_by_regex( rf'(' - rf'MuMuVMMHeadless.exe.*--comment {instance.name}' - rf'|MuMuPlayer.exe.*-v {instance.MuMuPlayer12_id}' + rf'HD-Player.exe.*"--instance" "{instance.name}"' rf')' ) - # There is also a shared service, no need to kill it - # "C:\Program Files\MuMuVMMVbox\Hypervisor\MuMuVMMSVC.exe" --Embedding - elif instance == Emulator.NoxPlayerFamily: - # Nox.exe -clone:Nox_1 -quit - self.execute(f'"{exe}" -clone:{instance.name} -quit') + elif instance == Emulator.BlueStacks4: + # E:\Program Files (x86)\BluestacksCN\bsconsole.exe quit --name Android + self.execute(f'"{Emulator.single_to_console(exe)}" quit --name {instance.name}') + elif instance == Emulator.MEmuPlayer: + # F:\Program Files\Microvirt\MEmu\memuc.exe stop -n MEmu_0 + self.execute(f'"{Emulator.single_to_console(exe)}" stop -n {instance.name}') else: raise EmulatorUnknown(f'Cannot stop an unknown emulator instance: {instance}') - def _emulator_function_wrapper(self, func): + def _emulator_function_wrapper(self, func: callable): """ Args: func (callable): _emulator_start or _emulator_stop @@ -324,7 +326,20 @@ class PlatformWindows(PlatformBase, EmulatorManager): def emulator_stop(self): logger.hr('Emulator stop', level=1) - return self._emulator_function_wrapper(self._emulator_stop) + for _ in range(3): + # Stop + if self._emulator_function_wrapper(self._emulator_stop): + # Success + return True + else: + # Failed to stop, start and stop again + if self._emulator_function_wrapper(self._emulator_start): + continue + else: + return False + + logger.error('Failed to stop emulator 3 times, stopped') + return False if __name__ == '__main__':