From ba2f0545d16e78fcc144657e67d3c911e4659c32 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: Wed, 28 Aug 2024 02:02:41 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/textsource/texthook.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index 4ef2a5b1..cf017040 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -200,6 +200,8 @@ class texthook(basetext): self.runonce_line = "" gobject.baseobject.autoswitchgameuid = False self.delaycollectallselectedoutput() + self.singlethread = True + self.singlethreadlock = threading.Lock() self.autohookmonitorthread() self.initdllonce = True self.initdlllock = threading.Lock() @@ -357,6 +359,10 @@ class texthook(basetext): @threader def autohookmonitorthread(self): + with self.singlethreadlock: + if not self.singlethread: + return + self.singlethread = False while (not self.ending) and (len(self.pids) == 0): try: hwnd = windows.GetForegroundWindow() @@ -365,9 +371,14 @@ class texthook(basetext): except: print_exc() time.sleep(0.1) + with self.singlethreadlock: + self.singlethread = True def start(self, hwnd, pids, gamepath, gameuid, autostart=False): self.delayinit() + for pid in pids: + # 如果有进程一闪而逝,没来的及注入,导致无法自动重连 + self.waitend(pid) gobject.baseobject.hwnd = hwnd gobject.baseobject.gameuid = gameuid self.gameuid = gameuid @@ -463,7 +474,6 @@ class texthook(basetext): def onprocconnect(self, pid): self.pids.append(pid) - self.waitend(pid) for hookcode in self.needinserthookcode: self.Luna_InsertHookCode(pid, hookcode) gobject.baseobject.displayinfomessage(