Fix: [ALAS] Handle dynamic mumu serial in serial_to_id

This commit is contained in:
LmeSzinc 2024-07-24 22:34:22 +08:00
parent bcd6afc94a
commit f008ecdd00

View File

@ -419,13 +419,14 @@ class NemuIpcImpl:
if ret > 0: if ret > 0:
raise NemuIpcError('nemu_input_event_touch_up failed') raise NemuIpcError('nemu_input_event_touch_up failed')
@staticmethod
def serial_to_id(serial: str): def serial_to_id(serial: str):
""" """
Predict instance ID from serial Predict instance ID from serial
E.g. E.g.
"127.0.0.1:16384" -> 0 "127.0.0.1:16384" -> 0
"127.0.0.1:16416" -> 1 "127.0.0.1:16416" -> 1
Port from 16414 to 16418 -> 1
Returns: Returns:
int: instance_id, or None if failed to predict int: instance_id, or None if failed to predict
@ -434,8 +435,9 @@ def serial_to_id(serial: str):
port = int(serial.split(':')[1]) port = int(serial.split(':')[1])
except (IndexError, ValueError): except (IndexError, ValueError):
return None return None
index, offset = divmod(port - 16384, 32) index, offset = divmod(port - 16384 + 16, 32)
if 0 <= index < 32 and offset in [0, 1, 2]: offset -= 16
if 0 <= index < 32 and offset in [-2, -1, 0, 1, 2]:
return index return index
else: else:
return None return None
@ -452,7 +454,7 @@ class NemuIpc(Platform):
# Try existing settings first # Try existing settings first
if self.config.EmulatorInfo_path: if self.config.EmulatorInfo_path:
folder = os.path.abspath(os.path.join(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: if index is not None:
try: try:
return NemuIpcImpl( return NemuIpcImpl(