Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 22, 2025
1 parent d31f7c6 commit c3b06eb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
8 changes: 5 additions & 3 deletions cpp/LunaHook/LunaHost/LunaHostDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions cpp/LunaHook/LunaHost/textthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cpp/LunaHook/LunaHost/textthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TextThread
void Push(const wchar_t *data);

Synchronized<std::wstring> storage;
Synchronized<std::wstring> latest;
const int64_t handle;
const std::wstring name;
const ThreadParam tp;
Expand Down
2 changes: 1 addition & 1 deletion cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 9 additions & 3 deletions py/LunaTranslator/gui/selecthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(__)

Expand Down Expand Up @@ -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()

Expand Down
23 changes: 12 additions & 11 deletions py/LunaTranslator/textsource/texthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c3b06eb

Please sign in to comment.