This commit is contained in:
恍兮惚兮 2024-03-08 22:22:26 +08:00
parent ca1c76d100
commit 52dec9a66a
3 changed files with 24 additions and 6 deletions

View File

@ -179,7 +179,7 @@ inline UINT64 djb2_n2(const unsigned char * str, size_t len, UINT64 hash = 5381
} }
return hash; 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){ bool check_is_thread_selected(const ThreadParam& tp){
for(int i=0;i<10;i++) for(int i=0;i<10;i++)
if(embedsharedmem->use[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); 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){ bool TextHook::waitfornotify(TextOutput_T* buffer,void*data ,size_t*len,ThreadParam tp){
std::wstring origin; std::wstring origin;
if (auto t=commonparsestring(data,*len,&hp,embedsharedmem->codepage)) origin=t.value(); if (auto t=commonparsestring(data,*len,&hp,embedsharedmem->codepage)) origin=t.value();
else return false; else return false;
if(origin.size()>1000)return false;
std::wstring translate; std::wstring translate;
if(translatecache.find(origin)!=translatecache.end()){ auto hash=texthash(data,*len);
translate=translatecache.at(origin); if(translatecache.find(hash)!=translatecache.end()){
translate=translatecache.at(hash);
} }
else{ else{
if(waitforevent(embedsharedmem->waittime,tp,origin)==false)return false; if(waitforevent(embedsharedmem->waittime,tp,origin)==false)return false;
translate=embedsharedmem->text; translate=embedsharedmem->text;
if((translate.size()==0)||(translate==origin))return false; 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); if(hp.newlineseperator)strReplace(translate,L"\n",hp.newlineseperator);
translate=adjustSpacesSTD(translate,hp); translate=adjustSpacesSTD(translate,hp);

View File

@ -24,4 +24,5 @@ namespace Engine{
inline std::atomic<void(*)()> patch_fun = nullptr; inline std::atomic<void(*)()> patch_fun = nullptr;
void ReplaceFunction(PVOID* oldf,PVOID newf); void ReplaceFunction(PVOID* oldf,PVOID newf);
bool check_embed_able(const ThreadParam& tp); bool check_embed_able(const ThreadParam& tp);
bool checktranslatedok(void*data ,size_t len);
#endif #endif

View File

@ -196,6 +196,9 @@ void TextHook::Send(uintptr_t lpDataBase)
parsenewlineseperator(pbData, &lpCount); parsenewlineseperator(pbData, &lpCount);
if((hp.type&EMBED_ABLE)&&(checktranslatedok(pbData,lpCount)))
buffer->type=buffer->type&(~EMBED_ABLE);
TextOutput(tp, buffer, lpCount); TextOutput(tp, buffer, lpCount);
if((hp.type&EMBED_ABLE)&&(check_embed_able(tp))) if((hp.type&EMBED_ABLE)&&(check_embed_able(tp)))