mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-25 18:05:26 +00:00
Fix: [ALAS] Handle dynamic mumu serial in serial_to_id
This commit is contained in:
parent
bcd6afc94a
commit
f008ecdd00
@ -419,26 +419,28 @@ 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):
|
||||||
|
"""
|
||||||
|
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):
|
Returns:
|
||||||
"""
|
int: instance_id, or None if failed to predict
|
||||||
Predict instance ID from serial
|
"""
|
||||||
E.g.
|
try:
|
||||||
"127.0.0.1:16384" -> 0
|
port = int(serial.split(':')[1])
|
||||||
"127.0.0.1:16416" -> 1
|
except (IndexError, ValueError):
|
||||||
|
return None
|
||||||
Returns:
|
index, offset = divmod(port - 16384 + 16, 32)
|
||||||
int: instance_id, or None if failed to predict
|
offset -= 16
|
||||||
"""
|
if 0 <= index < 32 and offset in [-2, -1, 0, 1, 2]:
|
||||||
try:
|
return index
|
||||||
port = int(serial.split(':')[1])
|
else:
|
||||||
except (IndexError, ValueError):
|
return None
|
||||||
return None
|
|
||||||
index, offset = divmod(port - 16384, 32)
|
|
||||||
if 0 <= index < 32 and offset in [0, 1, 2]:
|
|
||||||
return index
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class NemuIpc(Platform):
|
class NemuIpc(Platform):
|
||||||
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user