mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
api
This commit is contained in:
parent
22d280fd70
commit
798b483f09
@ -565,9 +565,7 @@ class hookselect(closeashidewindow):
|
|||||||
|
|
||||||
def _check_tp_using(self, key):
|
def _check_tp_using(self, key):
|
||||||
hc, hn, tp = key
|
hc, hn, tp = key
|
||||||
_isusing = gobject.baseobject.textsource.checkisusingembed(
|
_isusing = gobject.baseobject.textsource.Luna_checkisusingembed(tp)
|
||||||
tp.addr, tp.ctx, tp.ctx2
|
|
||||||
)
|
|
||||||
if _isusing:
|
if _isusing:
|
||||||
|
|
||||||
if hn[:8] == "UserHook":
|
if hn[:8] == "UserHook":
|
||||||
@ -582,9 +580,9 @@ class hookselect(closeashidewindow):
|
|||||||
pass
|
pass
|
||||||
return _isusing
|
return _isusing
|
||||||
|
|
||||||
def _embedbtnfn(self, key, _):
|
def _embedbtnfn(self, key, use):
|
||||||
hc, hn, tp = key
|
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)
|
_use = self._check_tp_using(key)
|
||||||
if _use:
|
if _use:
|
||||||
savehook_new_data[gobject.baseobject.gameuid]["embedablehook"].append(
|
savehook_new_data[gobject.baseobject.gameuid]["embedablehook"].append(
|
||||||
@ -656,7 +654,7 @@ class hookselect(closeashidewindow):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.searchtextlayout.addWidget(__)
|
self.searchtextlayout.addWidget(__)
|
||||||
|
|
||||||
self.userhook = QLineEdit()
|
self.userhook = QLineEdit()
|
||||||
self.searchtextlayout.addWidget(self.userhook)
|
self.searchtextlayout.addWidget(self.userhook)
|
||||||
self.userhookinsert = LPushButton("插入特殊码")
|
self.userhookinsert = LPushButton("插入特殊码")
|
||||||
|
@ -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)
|
ThreadEvent = CFUNCTYPE(None, c_wchar_p, c_char_p, ThreadParam)
|
||||||
OutputCallback = CFUNCTYPE(c_bool, c_wchar_p, c_char_p, ThreadParam, c_wchar_p)
|
OutputCallback = CFUNCTYPE(c_bool, c_wchar_p, c_char_p, ThreadParam, c_wchar_p)
|
||||||
ConsoleHandler = CFUNCTYPE(None, 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)
|
EmbedCallback = CFUNCTYPE(None, c_wchar_p, ThreadParam)
|
||||||
QueryHistoryCallback = CFUNCTYPE(None, c_wchar_p)
|
QueryHistoryCallback = CFUNCTYPE(None, c_wchar_p)
|
||||||
|
|
||||||
@ -175,6 +175,8 @@ class texthook(basetext):
|
|||||||
os.path.abspath("files/plugins/LunaHook"),
|
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 = LunaHost.Luna_Settings
|
||||||
self.Luna_Settings.argtypes = c_int, c_bool, c_int, c_int, c_int
|
self.Luna_Settings.argtypes = c_int, c_bool, c_int, c_int, c_int
|
||||||
self.Luna_Start = LunaHost.Luna_Start
|
self.Luna_Start = LunaHost.Luna_Start
|
||||||
@ -218,10 +220,10 @@ class texthook(basetext):
|
|||||||
c_bool,
|
c_bool,
|
||||||
)
|
)
|
||||||
self.Luna_checkisusingembed = LunaHost.Luna_checkisusingembed
|
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_checkisusingembed.restype = c_bool
|
||||||
self.Luna_useembed = LunaHost.Luna_useembed
|
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 = LunaHost.Luna_embedcallback
|
||||||
self.Luna_embedcallback.argtypes = DWORD, LPCWSTR, LPCWSTR
|
self.Luna_embedcallback.argtypes = DWORD, LPCWSTR, LPCWSTR
|
||||||
|
|
||||||
@ -426,12 +428,17 @@ class texthook(basetext):
|
|||||||
)
|
)
|
||||||
self.flashembedsettings(pid)
|
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][
|
for _hc, _addr, _ctx1, _ctx2 in savehook_new_data[self.gameuid][
|
||||||
"embedablehook"
|
"embedablehook"
|
||||||
]:
|
]:
|
||||||
if hcode == _hc:
|
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):
|
def safeembedcheck(self, text):
|
||||||
try:
|
try:
|
||||||
@ -446,9 +453,7 @@ class texthook(basetext):
|
|||||||
|
|
||||||
@threader
|
@threader
|
||||||
def getembedtext(self, text: str, tp):
|
def getembedtext(self, text: str, tp):
|
||||||
if not (
|
if not (self.isautorunning and self.Luna_checkisusingembed(tp)):
|
||||||
self.isautorunning and self.checkisusingembed(tp.addr, tp.ctx, tp.ctx2)
|
|
||||||
):
|
|
||||||
return self.embedcallback(text, "")
|
return self.embedcallback(text, "")
|
||||||
engine = (
|
engine = (
|
||||||
globalconfig["embedded"]["translator_2"]
|
globalconfig["embedded"]["translator_2"]
|
||||||
@ -530,7 +535,7 @@ class texthook(basetext):
|
|||||||
if idx == -1:
|
if idx == -1:
|
||||||
continue
|
continue
|
||||||
if autoindex < idx:
|
if autoindex < idx:
|
||||||
insertindex = j
|
insertindex = j
|
||||||
else:
|
else:
|
||||||
insertindex = j + 1
|
insertindex = j + 1
|
||||||
self.selectedhook.insert(insertindex, key)
|
self.selectedhook.insert(insertindex, key)
|
||||||
@ -674,12 +679,6 @@ class texthook(basetext):
|
|||||||
xx.append(self.serialkey(key))
|
xx.append(self.serialkey(key))
|
||||||
return xx
|
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):
|
def useembed(self, address, ctx1, ctx2, use):
|
||||||
for pid in self.pids.copy():
|
for pid in self.pids.copy():
|
||||||
self.Luna_useembed(pid, address, ctx1, ctx2, use)
|
self.Luna_useembed(pid, address, ctx1, ctx2, use)
|
||||||
|
@ -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
|
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 (*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);
|
typedef void (*EmbedCallback)(const wchar_t *, ThreadParam);
|
||||||
nlohmann::json config;
|
nlohmann::json config;
|
||||||
std::map<std::string, std::string> translation;
|
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_Start)(ProcessEvent Connect, ProcessEvent Disconnect, void *, void *, void *, void *, HookInsertHandler hookinsert, EmbedCallback embed, void *);
|
||||||
void (*Luna_Inject)(DWORD pid, LPCWSTR basepath);
|
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_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);
|
void (*Luna_useembed)(ThreadParam, bool use);
|
||||||
bool (*Luna_checkisusingembed)(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2);
|
bool (*Luna_checkisusingembed)(ThreadParam);
|
||||||
void (*Luna_embedcallback)(DWORD pid, LPCWSTR text, LPCWSTR trans);
|
void (*Luna_embedcallback)(DWORD pid, LPCWSTR text, LPCWSTR trans);
|
||||||
std::set<std::string> notranslation;
|
std::set<std::string> notranslation;
|
||||||
HANDLE hsema;
|
HANDLE hsema;
|
||||||
@ -129,7 +129,7 @@ public:
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
[](uint64_t addr, const wchar_t *output)
|
[](DWORD pid, uint64_t addr, const wchar_t *output)
|
||||||
{
|
{
|
||||||
std::wstring newhookcode = output;
|
std::wstring newhookcode = output;
|
||||||
for (auto hook : config["embedhook"])
|
for (auto hook : config["embedhook"])
|
||||||
@ -140,10 +140,8 @@ public:
|
|||||||
uint64_t _ctx2 = hook[3];
|
uint64_t _ctx2 = hook[3];
|
||||||
if (hookcode == newhookcode)
|
if (hookcode == newhookcode)
|
||||||
{
|
{
|
||||||
for (auto pid : connectedpids)
|
ThreadParam tp{pid, addr, _ctx1, _ctx2};
|
||||||
{
|
Luna_useembed(tp, true);
|
||||||
Luna_useembed(pid, addr, _ctx1, _ctx2, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -152,7 +150,7 @@ public:
|
|||||||
std::wstring text = output;
|
std::wstring text = output;
|
||||||
for (auto pid : connectedpids)
|
for (auto pid : connectedpids)
|
||||||
{
|
{
|
||||||
if ((Luna_checkisusingembed(pid, tp.addr, tp.ctx, tp.ctx2)))
|
if ((Luna_checkisusingembed(tp)))
|
||||||
{
|
{
|
||||||
auto trans = findtranslation(text);
|
auto trans = findtranslation(text);
|
||||||
Luna_embedcallback(pid, output, trans.c_str());
|
Luna_embedcallback(pid, output, trans.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user