diff --git a/resource/config.json b/resource/config.json index f81df16fa7..851bc24759 100644 --- a/resource/config.json +++ b/resource/config.json @@ -58,7 +58,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "BlueStacks": { "devices": "[Adb] devices", @@ -79,7 +79,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "MuMuEmulator": { "devices": "[Adb] devices", @@ -100,7 +100,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "LDPlayer": { "devices": "[Adb] devices", @@ -121,7 +121,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "Nox": { "devices": "[Adb] devices", @@ -142,7 +142,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "XYAZ": { "devices": "[Adb] devices", @@ -163,7 +163,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "WSA": { "devices": "[Adb] devices", @@ -185,7 +185,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" }, "Compatible": { "devices": "[Adb] devices", @@ -206,7 +206,7 @@ "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i > /dev/null 2&>1" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" } } } diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index 9c43965bec..c78f3d8c74 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -447,6 +447,7 @@ void asst::Controller::callback(AsstMsg msg, const json::value& details) bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) { LogTraceFunction; + Log.info(cmd); m_minitouch_avaiable = false; @@ -457,10 +458,9 @@ bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) .lpSecurityDescriptor = nullptr, .bInheritHandle = TRUE, }; - HANDLE minitouch_in_read = nullptr; - if (!asst::win32::CreateOverlappablePipe(&minitouch_in_read, &m_minitouch_in_write, &sa_attr, nullptr, 4096UL, - false, true)) { + if (!asst::win32::CreateOverlappablePipe(&m_minitouch_in_read, &m_minitouch_in_write, &sa_attr, nullptr, 4096UL, + false, false)) { DWORD err = GetLastError(); Log.error("Failed to create pipe for minitouch, err", err); return false; @@ -470,20 +470,20 @@ bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) si.cb = sizeof(STARTUPINFOW); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; - si.hStdInput = m_minitouch_in_write; + si.hStdInput = m_minitouch_in_read; + si.hStdOutput = m_minitouch_in_write; + si.hStdOutput = m_minitouch_in_write; auto cmd_osstr = utils::to_osstring(cmd); if (!CreateProcessW(NULL, cmd_osstr.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &m_minitouch_process_info)) { DWORD err = GetLastError(); Log.error("Failed to create process for minitouch, err", err); - CloseHandle(minitouch_in_read); + CloseHandle(m_minitouch_in_read); CloseHandle(m_minitouch_in_write); return false; } - CloseHandle(minitouch_in_read); - m_minitouch_avaiable = true; return true; @@ -495,13 +495,20 @@ bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) bool asst::Controller::input_to_minitouch(const std::string& cmd) { - LogTraceFunction; + Log.info("Input to minitouch", Logger::separator::newline, cmd); +#ifdef _WIN32 DWORD written = 0; - BOOL wr_ret = WriteFile(m_minitouch_in_write, cmd.c_str(), static_cast(cmd.size()), &written, NULL); + if (!WriteFile(m_minitouch_in_write, cmd.c_str(), static_cast(cmd.size() * sizeof(std::string::value_type)), + &written, NULL)) { + auto err = GetLastError(); + Log.error("Failed to write to minitouch, err", err); + } - Log.info(std::format("input to minitouch: \"{}\", write_ret: {}, written_size: {}", cmd, wr_ret, written)); - return wr_ret && cmd.size() == written; + return cmd.size() == written; +#else + return false; +#endif } void asst::Controller::release_minitouch() @@ -517,6 +524,7 @@ void asst::Controller::release_minitouch() CloseHandle(m_minitouch_process_info.hProcess); CloseHandle(m_minitouch_process_info.hThread); + CloseHandle(m_minitouch_in_read); CloseHandle(m_minitouch_in_write); #endif // _WIN32 diff --git a/src/MeoAssistant/Controller.h b/src/MeoAssistant/Controller.h index 3e36d3ab13..bb44f34f00 100644 --- a/src/MeoAssistant/Controller.h +++ b/src/MeoAssistant/Controller.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "Utils/NoWarningCVMat.h" @@ -162,6 +163,7 @@ namespace asst bool m_minitouch_avaiable = false; // 状态 #ifdef _WIN32 + HANDLE m_minitouch_in_read = nullptr; HANDLE m_minitouch_in_write = nullptr; ASST_AUTO_DEDUCED_ZERO_INIT_START PROCESS_INFORMATION m_minitouch_process_info = { nullptr }; @@ -192,12 +194,12 @@ namespace asst struct MinitouchCmd { inline static constexpr int DefaultInterval = 50; - inline static std::string reset() { return "r\\n"; } - inline static std::string commit() { return "c\\n"; } + inline static std::string reset() { return "r\n"; } + inline static std::string commit() { return "c\n"; } inline static std::string down(int x, int y, bool with_commit = true, bool with_wait = true, int contact = 0, int pressure = 50) { - std::string str = std::format("d {} {} {} {}\\n", contact, x, y, pressure); + std::string str = std::format("d {} {} {} {}\n", contact, x, y, pressure); if (with_commit) str += commit(); if (with_wait) str += wait(); return str; @@ -205,20 +207,20 @@ namespace asst inline static std::string move(int x, int y, bool with_commit = true, bool with_wait = true, int contact = 0, int pressure = 50) { - std::string str = std::format("m {} {} {} {}\\n", contact, x, y, pressure); + std::string str = std::format("m {} {} {} {}\n", contact, x, y, pressure); if (with_commit) str += commit(); if (with_wait) str += wait(); return str; } inline static std::string up(bool with_commit = true, int contact = 0) { - std::string str = std::format("u {}\\n", contact); + std::string str = std::format("u {}\n", contact); if (with_commit) str += commit(); return str; } inline static std::string wait(int ms = DefaultInterval) { - std::string str = std::format("w {}\\n", ms); + std::string str = std::format("w {}\n", ms); return str; } };