From 205d9671874bceef3596547bd87da9fbbadd876b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:46:50 +0800 Subject: [PATCH] fix --- .../LunaTranslator/LunaTranslator.py | 24 +++++++--------- .../LunaTranslator/gui/attachprocessdialog.py | 20 ++++++------- LunaTranslator/LunaTranslator/myutils/hwnd.py | 28 +++++++++---------- .../LunaTranslator/textsource/texthook.py | 8 ++++-- .../LunaTranslator/winsharedutils.py | 4 ++- plugins/CMakeLists.txt | 2 +- plugins/winsharedutils/hwnd.cpp | 4 +-- 7 files changed, 44 insertions(+), 46 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index eb536e37..17f7bf42 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -807,20 +807,16 @@ class MAINUI: uid = findgameuidofpath(name_, savehook_new_list) if not uid: return - lps = ListProcess(False) - for pids, _exe in lps: - if _exe != name_: - continue - - if self.textsource is not None: - return - if not globalconfig["sourcestatus2"]["texthook"]["use"]: - return - if globalconfig["startgamenototop"] == False: - idx = savehook_new_list.index(uid) - savehook_new_list.insert(0, savehook_new_list.pop(idx)) - self.textsource = texthook(pids, hwnd, name_, uid, autostart=True) - self.textsource.start() + pids = ListProcess(name_) + if self.textsource is not None: + return + if not globalconfig["sourcestatus2"]["texthook"]["use"]: + return + if globalconfig["startgamenototop"] == False: + idx = savehook_new_list.index(uid) + savehook_new_list.insert(0, savehook_new_list.pop(idx)) + self.textsource = texthook(pids, hwnd, name_, uid, autostart=True) + self.textsource.start() else: pids = self.textsource.pids diff --git a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py index 6da6aba2..8fd401d2 100644 --- a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py +++ b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py @@ -23,14 +23,7 @@ class AttachProcessDialog(saveposwindow): if pid == os.getpid(): return name = getpidexe(pid) - lps = ListProcess(False) - _pids = None - for pids, _exe in lps: - if _exe == name: - _pids = pids - break - if _pids is None: - _pids = [pid] + _pids = ListProcess(name) self.processEdit.setText(name) self.processIdEdit.setText(",".join([str(pid) for pid in _pids])) self.windowtext.setText(windows.GetWindowText(hwnd)) @@ -129,7 +122,7 @@ class AttachProcessDialog(saveposwindow): self.model = QStandardItemModel(self.processList) self.processlist = ListProcess() self.processList.setModel(self.model) - for pid, pexe in self.processlist: + for pexe in self.processlist: if pexe in self.iconcache: icon = self.iconcache[pexe] else: @@ -152,14 +145,19 @@ class AttachProcessDialog(saveposwindow): def editpid(self, process): pids = self.safesplit(process) + if len(pids) == 0: + self.windowtext.clear() + self.processEdit.clear() + return self.selectedp = (pids, getpidexe(pids[0]), self.guesshwnd(pids)) self.windowtext.setText(windows.GetWindowText(self.selectedp[-1])) self.processEdit.setText(self.selectedp[1]) self.windowtext.setCursorPosition(0) self.processEdit.setCursorPosition(0) - def selectedfunc(self, index): - pids, pexe = self.processlist[index.row()] + def selectedfunc(self, index: QModelIndex): + pexe = self.model.itemFromIndex(index).text() + pids = self.processlist.get(pexe, []) self.processEdit.setText(pexe) self.processIdEdit.setText(",".join([str(pid) for pid in pids])) self.selectedp = pids, pexe, self.guesshwnd(pids) diff --git a/LunaTranslator/LunaTranslator/myutils/hwnd.py b/LunaTranslator/LunaTranslator/myutils/hwnd.py index 36381f9e..d7c984ec 100644 --- a/LunaTranslator/LunaTranslator/myutils/hwnd.py +++ b/LunaTranslator/LunaTranslator/myutils/hwnd.py @@ -118,36 +118,34 @@ def test_injectable(pids): return True -def ListProcess(filt=True): - ret = [] - for pid in winsharedutils.Getprcesses(): +def ListProcess(exe=None): + ret = {} + for pid, exebase in winsharedutils.Getprcesses(): if os.getpid() == pid: continue try: + if exe is not None: + if exebase.lower() != os.path.basename(exe).lower(): + continue name_ = getpidexe(pid) if name_ is None: continue name = name_.lower() - if filt: + if exe is None: if ( ":\\windows\\" in name or "\\microsoft\\" in name or "\\windowsapps\\" in name ): continue - ret.append([pid, name_]) + if name_ not in ret: + ret[name_] = [] + ret[name_].append(pid) except: pass - kv = {} - for pid, exe in ret: - if exe not in kv: - kv[exe] = [] - - kv[exe].append(pid) - xxx = [] - for exe in kv: - xxx.append([kv[exe], exe]) - return xxx + if exe is None: + return ret + return ret.get(exe, []) def getExeIcon(name, icon=True, cache=False): diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index 53e5d2c8..6127f355 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -8,7 +8,7 @@ from winsharedutils import Is64bit from myutils.config import globalconfig, savehook_new_data, static_data from textsource.textsourcebase import basetext from myutils.utils import checkchaos -from myutils.hwnd import injectdll, test_injectable +from myutils.hwnd import injectdll, test_injectable, ListProcess from myutils.wrapper import threader from myutils.utils import getfilemd5 from traceback import print_exc @@ -264,8 +264,12 @@ class texthook(basetext): @threader def start(self): + if self.injecttimeout: + time.sleep(self.injecttimeout) + if set(self.pids) != set(ListProcess(self.gamepath)): + # 部分cef/v8引擎的游戏,会在一段启动时间后,启动子进程用于渲染 + return self.start() - time.sleep(self.injecttimeout) if self.ending: return try: diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index 147c7ff5..4bc95519 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -256,7 +256,9 @@ getprocesses.argtypes = (c_void_p,) def Getprcesses(): ret = [] - getprocesses(CFUNCTYPE(None, DWORD)(ret.append)) + getprocesses( + CFUNCTYPE(None, DWORD, c_wchar_p)(lambda pid, exe: ret.append((pid, exe))) + ) return ret diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index a5997971..ba57e135 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,7 +28,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) include(generate_product_version) set(VERSION_MAJOR 5) -set(VERSION_MINOR 19) +set(VERSION_MINOR 20) set(VERSION_PATCH 0) add_library(pch pch.cpp) diff --git a/plugins/winsharedutils/hwnd.cpp b/plugins/winsharedutils/hwnd.cpp index bb913017..eecb2253 100644 --- a/plugins/winsharedutils/hwnd.cpp +++ b/plugins/winsharedutils/hwnd.cpp @@ -110,7 +110,7 @@ DECLARE bool Is64bit(DWORD pid) return false; } -DECLARE void getprocesses(void (*cb)(DWORD)) +DECLARE void getprocesses(void (*cb)(DWORD, const wchar_t *)) { std::unordered_map> exe_pid; AutoHandle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); @@ -124,7 +124,7 @@ DECLARE void getprocesses(void (*cb)(DWORD)) { do { - cb(pe32.th32ProcessID); + cb(pe32.th32ProcessID, pe32.szExeFile); } while (Process32Next(hSnapshot, &pe32)); } } \ No newline at end of file