From c3b06eb3a93dfbb4db0628f751580e031fab79a0 Mon Sep 17 00:00:00 2001 From: HIllya51 <1173718158@qq.com> Date: Wed, 22 Jan 2025 19:00:31 +0800 Subject: [PATCH] . --- cpp/LunaHook/LunaHost/LunaHostDll.cpp | 8 +++++--- cpp/LunaHook/LunaHost/textthread.cpp | 3 +++ cpp/LunaHook/LunaHost/textthread.h | 1 + cpp/version.cmake | 2 +- py/LunaTranslator/gui/selecthook.py | 12 +++++++++--- py/LunaTranslator/textsource/texthook.py | 23 ++++++++++++----------- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/cpp/LunaHook/LunaHost/LunaHostDll.cpp b/cpp/LunaHook/LunaHost/LunaHostDll.cpp index 80fed082976..bdad808d07e 100644 --- a/cpp/LunaHook/LunaHost/LunaHostDll.cpp +++ b/cpp/LunaHook/LunaHost/LunaHostDll.cpp @@ -88,10 +88,12 @@ C_LUNA_API bool Luna_InsertHookCode(DWORD pid, LPCWSTR hookcode) Host::InsertHook(pid, hp.value()); return hp.has_value(); } -C_LUNA_API void Luna_QueryThreadHistory(ThreadParam tp, void (*callback)(const wchar_t *)) +C_LUNA_API void Luna_QueryThreadHistory(ThreadParam tp, bool latest, void (*callback)(const wchar_t *)) { - auto s = Host::GetThread(tp).storage.Acquire(); - callback(s->c_str()); + if (latest) + callback(Host::GetThread(tp).latest->c_str()); + else + callback(Host::GetThread(tp).storage->c_str()); } C_LUNA_API void Luna_RemoveHook(DWORD pid, uint64_t addr) { diff --git a/cpp/LunaHook/LunaHost/textthread.cpp b/cpp/LunaHook/LunaHost/textthread.cpp index d77c3b464c6..a1d828bd26a 100644 --- a/cpp/LunaHook/LunaHost/textthread.cpp +++ b/cpp/LunaHook/LunaHost/textthread.cpp @@ -125,7 +125,10 @@ void TextThread::Flush() { sentence.erase(std::remove(sentence.begin(), sentence.end(), 0), sentence.end()); if (Output(*this, sentence)) + { storage->append(sentence + L"\n"); + latest->assign(sentence.c_str()); + } } std::scoped_lock lock(bufferMutex); diff --git a/cpp/LunaHook/LunaHost/textthread.h b/cpp/LunaHook/LunaHost/textthread.h index a7ba5d637a4..a76716f9153 100644 --- a/cpp/LunaHook/LunaHost/textthread.h +++ b/cpp/LunaHook/LunaHost/textthread.h @@ -21,6 +21,7 @@ class TextThread void Push(const wchar_t *data); Synchronized storage; + Synchronized latest; const int64_t handle; const std::wstring name; const ThreadParam tp; diff --git a/cpp/version.cmake b/cpp/version.cmake index ddf6c4d7a54..f70966d4343 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 7) set(VERSION_MINOR 2) -set(VERSION_PATCH 1) +set(VERSION_PATCH 2) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/py/LunaTranslator/gui/selecthook.py b/py/LunaTranslator/gui/selecthook.py index fc9b02b7f7b..836c535d2c3 100644 --- a/py/LunaTranslator/gui/selecthook.py +++ b/py/LunaTranslator/gui/selecthook.py @@ -601,9 +601,7 @@ def setupUi(self): self.vboxlayout.addLayout(self.searchtextlayout) __ = LPushButton("游戏适配") __.clicked.connect( - lambda: os.startfile( - dynamiclink("{main_server}/Resource/game_support") - ) + lambda: os.startfile(dynamiclink("{main_server}/Resource/game_support")) ) self.searchtextlayout.addWidget(__) @@ -836,6 +834,14 @@ def accept(self, key, select): savehook_new_data[gobject.baseobject.gameuid].update( {"hook": gobject.baseobject.textsource.serialselectedhook()} ) + + directshowcollect = [] + for key in gobject.baseobject.textsource.selectedhook: + hc, hn, tp = key + directshowcollect.append( + (key, gobject.baseobject.textsource.QueryThreadHistory(tp, True)) + ) + gobject.baseobject.textsource.dispatchtextlines(directshowcollect) except: print_exc() diff --git a/py/LunaTranslator/textsource/texthook.py b/py/LunaTranslator/textsource/texthook.py index 63351497a1f..01976b69277 100644 --- a/py/LunaTranslator/textsource/texthook.py +++ b/py/LunaTranslator/textsource/texthook.py @@ -270,7 +270,7 @@ def initdll(self): self.Luna_embedcallback.argtypes = ThreadParam, LPCWSTR, LPCWSTR self.Luna_QueryThreadHistory = LunaHost.Luna_QueryThreadHistory - self.Luna_QueryThreadHistory.argtypes = (ThreadParam, c_void_p) + self.Luna_QueryThreadHistory.argtypes = (ThreadParam, c_bool, c_void_p) procs = [ ProcessEvent(self.onprocconnect), ProcessEvent(self.removeproc), @@ -403,9 +403,9 @@ def start(self, hwnd, pids, gamepath, gameuid, autostart=False): gobject.baseobject.hookselectdialog.realshowhide.emit(True) self.injectproc(injecttimeout, pids) - def QueryThreadHistory(self, tp): + def QueryThreadHistory(self, tp, _latest=False): ret = [] - self.Luna_QueryThreadHistory(tp, QueryHistoryCallback(ret.append)) + self.Luna_QueryThreadHistory(tp, _latest, QueryHistoryCallback(ret.append)) return ret[0] def removeproc(self, pid): @@ -680,16 +680,17 @@ def delaycollectallselectedoutput(self): if len(self.multiselectedcollector) == 0: continue with self.multiselectedcollectorlock: - try: - self.multiselectedcollector.sort( - key=lambda xx: self.selectedhook.index(xx[0]) - ) - except: - pass - _collector = "\n".join([_[1] for _ in self.multiselectedcollector]) - self.dispatchtext(_collector) + self.dispatchtextlines(self.multiselectedcollector) self.multiselectedcollector.clear() + def dispatchtextlines(self, keyandtexts): + try: + keyandtexts.sort(key=lambda xx: self.selectedhook.index(xx[0])) + except: + pass + _collector = "\n".join([_[1] for _ in keyandtexts]) + self.dispatchtext(_collector) + def dispatchtext_multiline_delayed(self, key, text): with self.multiselectedcollectorlock: self.lastflushtime = time.time()