From b0613481c71caddde387d690f00f8b87614431ba Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 9 Nov 2024 03:00:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9B=B7=E7=94=B5?= =?UTF-8?q?=E9=9D=9E0=E5=AE=9E=E4=BE=8B=E6=88=AA=E5=9B=BE=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdbDevice/AdbDeviceWin32Finder.cpp | 20 ++++++++++++++++++- .../AdbDevice/AdbDeviceWin32Finder.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.cpp b/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.cpp index 3500e29ce..eed97ac2c 100644 --- a/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.cpp +++ b/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.cpp @@ -84,7 +84,7 @@ json::object AdbDeviceWin32Finder::get_adb_config(const Emulator& emulator, cons ld_cfg["enable"] = true; ld_cfg["path"] = path_to_utf8_string(dir); - ld_cfg["index"] = 0; + ld_cfg["index"] = get_ld_index(adb_serial); ld_cfg["pid"] = emulator.process.pid; LogInfo << "LDPlayer cfg" << VAR(adb_serial) << cfg; @@ -112,6 +112,24 @@ int AdbDeviceWin32Finder::get_mumu_index(const std::string& adb_serial) return index; } +int AdbDeviceWin32Finder::get_ld_index(const std::string& adb_serial) +{ + auto sp = string_split(adb_serial, '-'); + if (sp.size() != 2) { + return 0; + } + + auto& str_port = sp.at(1); + if (str_port.empty() || !std::ranges::all_of(str_port, [](auto c) { return std::isdigit(c); })) { + return 0; + } + + int port = std::stoi(str_port); + int index = (port - 5554) / 2; + + return index; +} + MAA_TOOLKIT_NS_END #endif diff --git a/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.h b/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.h index e10a38233..b8e373cb1 100644 --- a/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.h +++ b/source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.h @@ -27,6 +27,7 @@ class AdbDeviceWin32Finder AdbDeviceWin32Finder(); static int get_mumu_index(const std::string& adb_serial); + static int get_ld_index(const std::string& adb_serial); }; MAA_TOOLKIT_NS_END