diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index da515999..f7ba0ad6 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -394,7 +394,7 @@ class searchhookparam(QDialog): class hookselect(closeashidewindow): - addnewhooksignal = pyqtSignal(tuple, bool, list) + addnewhooksignal = pyqtSignal(tuple, bool) getnewsentencesignal = pyqtSignal(str) sysmessagesignal = pyqtSignal(str) changeprocessclearsignal = pyqtSignal() @@ -441,8 +441,8 @@ class hookselect(closeashidewindow): self.allres = OrderedDict() self.hidesearchhookbuttons() - def addnewhook(self, ss, select, textthread): - hc, hn, tp = textthread + def addnewhook(self, key, select): + hc, hn, tp = key if len(self.save) == 0: if gobject.baseobject.textsource.allow_set_text_name: self.ttCombomodelmodel.setHorizontalHeaderLabels( @@ -478,21 +478,21 @@ class hookselect(closeashidewindow): 0, QHeaderView.ResizeToContents ) - if ss[-1][0] == "E": + if hc[0] == "E": self.selectionbutton.insert( 0, getsimpleswitch( - {1: False}, 1, callback=functools.partial(self.accept, ss) + {1: False}, 1, callback=functools.partial(self.accept, key) ), ) - self.save.insert(0, ss) + self.save.insert(0, key) rown = 0 else: - self.save.append(ss) + self.save.append(key) rown = self.ttCombomodelmodel.rowCount() self.selectionbutton.append( getsimpleswitch( - {1: False}, 1, callback=functools.partial(self.accept, ss) + {1: False}, 1, callback=functools.partial(self.accept, key) ) ) if gobject.baseobject.textsource.allow_set_text_name: @@ -507,20 +507,20 @@ class hookselect(closeashidewindow): ): continue if gobject.baseobject.textsource.match_compatibility( - json.loads(jskey), ss + json.loads(jskey), key ): - gobject.baseobject.textsource.hooktypecollecter[ss] = 1 + gobject.baseobject.textsource.hooktypecollecter[key] = 1 self.typecombo.insert( rown, getsimplecombobox( _TRL(["文本", "人名"]), gobject.baseobject.textsource.hooktypecollecter, - ss, + key, callback=functools.partial( savehook_new_data[gobject.baseobject.textsource.pname][ "hooktypeasname" ].__setitem__, - json.dumps(ss), + json.dumps(key), ), ), ) @@ -529,7 +529,7 @@ class hookselect(closeashidewindow): [ QStandardItem(), QStandardItem(), - QStandardItem("%s %s %x:%x" % (ss[-2], ss[-1], ss[-3], ss[-4])), + QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)), QStandardItem(), ], ) @@ -541,7 +541,7 @@ class hookselect(closeashidewindow): rown, [ QStandardItem(), - QStandardItem("%s %s %x:%x" % (ss[-2], ss[-1], ss[-3], ss[-4])), + QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)), QStandardItem(), ], ) @@ -551,7 +551,7 @@ class hookselect(closeashidewindow): self.tttable.setIndexWidget( self.ttCombomodelmodel.index(rown, 0), self.selectionbutton[rown] ) - if ss[-1][0] == "E": + if hc[0] == "E": embedw, hlay = getformlayoutw(cls=QHBoxLayout) label = QLabel() hlay.addWidget(label) @@ -566,11 +566,11 @@ class hookselect(closeashidewindow): if _isusing: _text = "取消内嵌翻译" - if ss[-2][:8] == "UserHook": + if hn[:8] == "UserHook": needinserthookcode = savehook_new_data[ gobject.baseobject.textsource.pname ]["needinserthookcode"] - needinserthookcode = list(set(needinserthookcode + [ss[-1]])) + needinserthookcode = list(set(needinserthookcode + [hc])) savehook_new_data[gobject.baseobject.textsource.pname].update( {"needinserthookcode": needinserthookcode} ) @@ -739,14 +739,14 @@ class hookselect(closeashidewindow): r = self.tttable.currentIndex().row() if r < 0: return - hook = self.save[r] + hc, hn, tp = self.save[r] if action == remove: - pid = hook[0] - addr = hook[1] + pid = tp.processId + addr = tp.addr gobject.baseobject.textsource.removehook(pid, addr) elif action == copy: - copyhook = hook[-1] + copyhook = hc if copyhook[0] == "E": copyhook = copyhook[copyhook.find("H") :] winsharedutils.clipboard_set(copyhook) @@ -924,7 +924,7 @@ class hookselect(closeashidewindow): pass savehook_new_data[gobject.baseobject.textsource.pname].update( - {"hook": gobject.baseobject.textsource.selectedhook} + {"hook": gobject.baseobject.textsource.serialselectedhook()} ) except: print_exc() @@ -972,10 +972,10 @@ class hookselect(closeashidewindow): try: # print(gobject.baseobject.textsource) gobject.baseobject.textsource.selectinghook = self.save[index.row()] - pid, addr, ctx1, ctx2, _, _ = self.save[index.row()] + hc, hn, tp = self.save[index.row()] self.textOutput.setPlainText( - gobject.baseobject.textsource.QueryThreadHistory(pid, addr, ctx1, ctx2) + gobject.baseobject.textsource.QueryThreadHistory(tp) ) self.textOutput.moveCursor(QTextCursor.End) diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index d3ac0eef..e86f8e0e 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -193,12 +193,7 @@ class texthook(basetext): self.Luna_QueryThreadHistory.argtypes = (ThreadParam,) self.Luna_QueryThreadHistory.restype = c_void_p - def QueryThreadHistory(self, pid, addr, ctx1, ctx2): - tp = ThreadParam() - tp.addr = addr - tp.processId = pid - tp.ctx = ctx1 - tp.ctx2 = ctx2 + def QueryThreadHistory(self, tp): ws = self.Luna_QueryThreadHistory(tp) string = cast(ws, c_wchar_p).value self.Luna_FreePtr(ws) @@ -209,7 +204,7 @@ class texthook(basetext): ProcessEvent(self.onprocconnect), ProcessEvent(self.connectedpids.remove), ThreadEvent(self.onnewhook), - ThreadEvent(lambda _1, _2, tp: self.onremovehook(tp)), + ThreadEvent(self.onremovehook), OutputCallback(self.handle_output), ConsoleHandler(gobject.baseobject.hookselectdialog.sysmessagesignal.emit), HookInsertHandler(self.newhookinsert), @@ -309,43 +304,32 @@ class texthook(basetext): True, ) - def onremovehook(self, tp): - toremove = [] - - for key in self.hookdatacollecter: - if key[1] == tp.addr: - toremove.append(key) - for key in toremove: - gobject.baseobject.hookselectdialog.removehooksignal.emit(key) - self.hookdatacollecter.pop(key) + def onremovehook(self, hc, hn, tp): + key = (hc, hn.decode('utf8'), tp) + self.hookdatacollecter.pop(key) + gobject.baseobject.hookselectdialog.removehooksignal.emit(key) - def parsetextthread(self, hc, hn, tp): - key = (tp.processId, tp.addr, tp.ctx, tp.ctx2, hn.decode("ascii"), hc) - return key - - def match_compatibility(self, key, autostarthookcode): - base = (key[2] & 0xFFFF, key[3] & 0xFFFF, key[5]) == ( + def match_compatibility(self, tp, hc, autostarthookcode): + base = (tp.ctx & 0xFFFF, tp.ctx2 & 0xFFFF, hc) == ( autostarthookcode[2] & 0xFFFF, autostarthookcode[3] & 0xFFFF, autostarthookcode[5], ) - name = ( - key[-1][:8] == "UserHook" and autostarthookcode[-1][:8] == "UserHook" - ) or (key[-1] == autostarthookcode[-1]) + name = (hc[:8] == "UserHook" and autostarthookcode[-1][:8] == "UserHook") or ( + hc == autostarthookcode[-1] + ) return base and name def onnewhook(self, hc, hn, tp): - - key = self.parsetextthread(hc, hn, tp) + key = (hc, hn.decode("utf8"), tp) if self.isremoveuseless: - if key[1] not in [_[1] for _ in self.autostarthookcode]: - self.Luna_RemoveHook(key[0], key[1]) + if tp.addr not in [_[1] for _ in self.autostarthookcode]: + self.Luna_RemoveHook(tp.processId, tp.addr) return False - select = False for _i, autostarthookcode in enumerate(self.autostarthookcode): - if self.match_compatibility(key, autostarthookcode): + if self.match_compatibility(tp, hc, autostarthookcode): self.selectedhook += [key] self.selectinghook = key select = True @@ -353,9 +337,7 @@ class texthook(basetext): self.hookdatacollecter[key] = [] self.hooktypecollecter[key] = 0 - gobject.baseobject.hookselectdialog.addnewhooksignal.emit( - key, select, [hc, hn, tp] - ) + gobject.baseobject.hookselectdialog.addnewhooksignal.emit(key, select) return True def setsettings(self): @@ -451,15 +433,11 @@ class texthook(basetext): collector = [] def handle_output(self, hc, hn, tp, output): - key = self.parsetextthread(hc, hn, tp) if globalconfig["filter_chaos_code"] and checkchaos(output): return False + key = (hc, hn.decode("utf8"), tp) - if key not in self.hookdatacollecter: - if self.onnewhook(hc, hn, tp) == False: - return False - if self.hooktypecollecter[key] == 1: self.currentname = output if len(self.selectedhook) == 1: @@ -478,6 +456,12 @@ class texthook(basetext): return True + def serialselectedhook(self): + xx = [] + for hc, hn, tp in self.selectedhook: + xx.append((tp.processId, tp.addr, tp.ctx, tp.ctx2, hn, hc)) + return xx + def checkisusingembed(self, address, ctx1, ctx2): for pid in self.connectedpids: if self.Luna_checkisusingembed(pid, address, ctx1, ctx2): diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 60f40f7e..f6a77484 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 2) set(VERSION_MINOR 50) -set(VERSION_PATCH 1) +set(VERSION_PATCH 2) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)