mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-23 13:55:36 +08:00
cache
This commit is contained in:
parent
ca1c76d100
commit
52dec9a66a
@ -179,7 +179,7 @@ inline UINT64 djb2_n2(const unsigned char * str, size_t len, UINT64 hash = 5381
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
std::unordered_map<std::wstring,std::wstring>translatecache;
|
||||
std::unordered_map<UINT64,std::wstring>translatecache;
|
||||
bool check_is_thread_selected(const ThreadParam& tp){
|
||||
for(int i=0;i<10;i++)
|
||||
if(embedsharedmem->use[i])
|
||||
@ -220,22 +220,36 @@ void TextHook::parsenewlineseperator(void*data ,size_t*len)
|
||||
StringReplacer((char*)data,len,newlineseperatorA.c_str(),newlineseperatorA.size(),"\n",1);
|
||||
}
|
||||
}
|
||||
|
||||
UINT64 texthash(void*data,size_t len)
|
||||
{
|
||||
UINT64 sum=0;
|
||||
auto u8data=(UINT8*)data;
|
||||
for(int i=0;i< len;i++){
|
||||
sum+=u8data[i];
|
||||
sum=sum<<1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
bool checktranslatedok(void*data ,size_t len)
|
||||
{
|
||||
if(len>1000)return true;
|
||||
return(translatecache.find(texthash(data,len))!=translatecache.end());
|
||||
}
|
||||
bool TextHook::waitfornotify(TextOutput_T* buffer,void*data ,size_t*len,ThreadParam tp){
|
||||
std::wstring origin;
|
||||
if (auto t=commonparsestring(data,*len,&hp,embedsharedmem->codepage)) origin=t.value();
|
||||
else return false;
|
||||
if(origin.size()>1000)return false;
|
||||
|
||||
std::wstring translate;
|
||||
if(translatecache.find(origin)!=translatecache.end()){
|
||||
translate=translatecache.at(origin);
|
||||
auto hash=texthash(data,*len);
|
||||
if(translatecache.find(hash)!=translatecache.end()){
|
||||
translate=translatecache.at(hash);
|
||||
}
|
||||
else{
|
||||
if(waitforevent(embedsharedmem->waittime,tp,origin)==false)return false;
|
||||
translate=embedsharedmem->text;
|
||||
if((translate.size()==0)||(translate==origin))return false;
|
||||
translatecache.insert(std::make_pair(origin,translate));
|
||||
translatecache.insert(std::make_pair(hash,translate));
|
||||
}
|
||||
if(hp.newlineseperator)strReplace(translate,L"\n",hp.newlineseperator);
|
||||
translate=adjustSpacesSTD(translate,hp);
|
||||
|
@ -24,4 +24,5 @@ namespace Engine{
|
||||
inline std::atomic<void(*)()> patch_fun = nullptr;
|
||||
void ReplaceFunction(PVOID* oldf,PVOID newf);
|
||||
bool check_embed_able(const ThreadParam& tp);
|
||||
bool checktranslatedok(void*data ,size_t len);
|
||||
#endif
|
@ -195,6 +195,9 @@ void TextHook::Send(uintptr_t lpDataBase)
|
||||
ThreadParam tp{ GetCurrentProcessId(), address, lpRetn, lpSplit };
|
||||
|
||||
parsenewlineseperator(pbData, &lpCount);
|
||||
|
||||
if((hp.type&EMBED_ABLE)&&(checktranslatedok(pbData,lpCount)))
|
||||
buffer->type=buffer->type&(~EMBED_ABLE);
|
||||
|
||||
TextOutput(tp, buffer, lpCount);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user