This commit is contained in:
恍兮惚兮 2024-11-03 20:31:31 +08:00
parent 22d280fd70
commit 798b483f09
3 changed files with 25 additions and 30 deletions

View File

@ -565,9 +565,7 @@ class hookselect(closeashidewindow):
def _check_tp_using(self, key):
hc, hn, tp = key
_isusing = gobject.baseobject.textsource.checkisusingembed(
tp.addr, tp.ctx, tp.ctx2
)
_isusing = gobject.baseobject.textsource.Luna_checkisusingembed(tp)
if _isusing:
if hn[:8] == "UserHook":
@ -582,9 +580,9 @@ class hookselect(closeashidewindow):
pass
return _isusing
def _embedbtnfn(self, key, _):
def _embedbtnfn(self, key, use):
hc, hn, tp = key
gobject.baseobject.textsource.useembed(tp.addr, tp.ctx, tp.ctx2, _)
gobject.baseobject.textsource.Luna_useembed(tp, use)
_use = self._check_tp_using(key)
if _use:
savehook_new_data[gobject.baseobject.gameuid]["embedablehook"].append(
@ -656,7 +654,7 @@ class hookselect(closeashidewindow):
)
)
self.searchtextlayout.addWidget(__)
self.userhook = QLineEdit()
self.searchtextlayout.addWidget(self.userhook)
self.userhookinsert = LPushButton("插入特殊码")

View File

@ -95,7 +95,7 @@ ThreadEvent_maybe_embed = CFUNCTYPE(None, c_wchar_p, c_char_p, ThreadParam, c_bo
ThreadEvent = CFUNCTYPE(None, c_wchar_p, c_char_p, ThreadParam)
OutputCallback = CFUNCTYPE(c_bool, c_wchar_p, c_char_p, ThreadParam, c_wchar_p)
ConsoleHandler = CFUNCTYPE(None, c_wchar_p)
HookInsertHandler = CFUNCTYPE(None, c_uint64, c_wchar_p)
HookInsertHandler = CFUNCTYPE(None, DWORD, c_uint64, c_wchar_p)
EmbedCallback = CFUNCTYPE(None, c_wchar_p, ThreadParam)
QueryHistoryCallback = CFUNCTYPE(None, c_wchar_p)
@ -175,6 +175,8 @@ class texthook(basetext):
os.path.abspath("files/plugins/LunaHook"),
)
)
self.Luna_SyncThread = LunaHost.Luna_SyncThread
self.Luna_SyncThread.argtypes = ThreadParam, c_bool
self.Luna_Settings = LunaHost.Luna_Settings
self.Luna_Settings.argtypes = c_int, c_bool, c_int, c_int, c_int
self.Luna_Start = LunaHost.Luna_Start
@ -218,10 +220,10 @@ class texthook(basetext):
c_bool,
)
self.Luna_checkisusingembed = LunaHost.Luna_checkisusingembed
self.Luna_checkisusingembed.argtypes = DWORD, c_uint64, c_uint64, c_uint64
self.Luna_checkisusingembed.argtypes = (ThreadParam,)
self.Luna_checkisusingembed.restype = c_bool
self.Luna_useembed = LunaHost.Luna_useembed
self.Luna_useembed.argtypes = DWORD, c_uint64, c_uint64, c_uint64, c_bool
self.Luna_useembed.argtypes = ThreadParam, c_bool
self.Luna_embedcallback = LunaHost.Luna_embedcallback
self.Luna_embedcallback.argtypes = DWORD, LPCWSTR, LPCWSTR
@ -426,12 +428,17 @@ class texthook(basetext):
)
self.flashembedsettings(pid)
def newhookinsert(self, addr, hcode):
def newhookinsert(self, pid, addr, hcode):
for _hc, _addr, _ctx1, _ctx2 in savehook_new_data[self.gameuid][
"embedablehook"
]:
if hcode == _hc:
self.useembed(addr, _ctx1, _ctx2, True)
tp = ThreadParam()
tp.processId = pid
tp.addr = addr
tp.ctx = _ctx1
tp.ctx2 = _ctx2
self.useembed(tp, True)
def safeembedcheck(self, text):
try:
@ -446,9 +453,7 @@ class texthook(basetext):
@threader
def getembedtext(self, text: str, tp):
if not (
self.isautorunning and self.checkisusingembed(tp.addr, tp.ctx, tp.ctx2)
):
if not (self.isautorunning and self.Luna_checkisusingembed(tp)):
return self.embedcallback(text, "")
engine = (
globalconfig["embedded"]["translator_2"]
@ -530,7 +535,7 @@ class texthook(basetext):
if idx == -1:
continue
if autoindex < idx:
insertindex = j
insertindex = j
else:
insertindex = j + 1
self.selectedhook.insert(insertindex, key)
@ -674,12 +679,6 @@ class texthook(basetext):
xx.append(self.serialkey(key))
return xx
def checkisusingembed(self, address, ctx1, ctx2):
for pid in self.pids.copy():
if self.Luna_checkisusingembed(pid, address, ctx1, ctx2):
return True
return False
def useembed(self, address, ctx1, ctx2, use):
for pid in self.pids.copy():
self.Luna_useembed(pid, address, ctx1, ctx2, use)

View File

@ -82,7 +82,7 @@ struct ThreadParam
uint64_t ctx2; // The subcontext of the hook: 0 by default, generated in a method specific to the hook
};
typedef void (*ProcessEvent)(DWORD);
typedef void (*HookInsertHandler)(uint64_t, const wchar_t *);
typedef void (*HookInsertHandler)(DWORD, uint64_t, const wchar_t *);
typedef void (*EmbedCallback)(const wchar_t *, ThreadParam);
nlohmann::json config;
std::map<std::string, std::string> translation;
@ -90,8 +90,8 @@ std::unordered_set<DWORD> connectedpids;
void (*Luna_Start)(ProcessEvent Connect, ProcessEvent Disconnect, void *, void *, void *, void *, HookInsertHandler hookinsert, EmbedCallback embed, void *);
void (*Luna_Inject)(DWORD pid, LPCWSTR basepath);
void (*Luna_EmbedSettings)(DWORD pid, UINT32 waittime, UINT8 fontCharSet, bool fontCharSetEnabled, wchar_t *fontFamily, UINT32 keeprawtext, bool fastskipignore);
void (*Luna_useembed)(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2, bool use);
bool (*Luna_checkisusingembed)(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2);
void (*Luna_useembed)(ThreadParam, bool use);
bool (*Luna_checkisusingembed)(ThreadParam);
void (*Luna_embedcallback)(DWORD pid, LPCWSTR text, LPCWSTR trans);
std::set<std::string> notranslation;
HANDLE hsema;
@ -129,7 +129,7 @@ public:
0,
0,
0,
[](uint64_t addr, const wchar_t *output)
[](DWORD pid, uint64_t addr, const wchar_t *output)
{
std::wstring newhookcode = output;
for (auto hook : config["embedhook"])
@ -140,10 +140,8 @@ public:
uint64_t _ctx2 = hook[3];
if (hookcode == newhookcode)
{
for (auto pid : connectedpids)
{
Luna_useembed(pid, addr, _ctx1, _ctx2, true);
}
ThreadParam tp{pid, addr, _ctx1, _ctx2};
Luna_useembed(tp, true);
}
}
},
@ -152,7 +150,7 @@ public:
std::wstring text = output;
for (auto pid : connectedpids)
{
if ((Luna_checkisusingembed(pid, tp.addr, tp.ctx, tp.ctx2)))
if ((Luna_checkisusingembed(tp)))
{
auto trans = findtranslation(text);
Luna_embedcallback(pid, output, trans.c_str());