This commit is contained in:
恍兮惚兮 2024-07-01 18:15:00 +08:00
parent 4bf962f8a1
commit a9dc4b4e7d
3 changed files with 26 additions and 1 deletions

View File

@ -153,6 +153,28 @@ std::wstring adjustSpacesSTD(const std::wstring& text,HookParam hp)
default:return text;
}
}
std::wstring limitTextWidth(const std::wstring& text, int size)
{
auto lines=strSplit(text,L"\n");
std::for_each(lines.begin(),lines.end(),[=](auto &line){
if(line.size()<=size)
return;
std::wstring ret;
for(int i=0;i<line.size();i++){
ret+=line[i];
if((i<line.size()-1) &&( ((1+i)%size)==0)){
ret+=L'\n';
}
}
line=ret;
});
std::wstring ret;
for(int i=0;i<lines.size();i++){
ret+=lines[i];
if(i<lines.size()-1)ret+=L'\n';
}
return ret;
}
bool isPauseKeyPressed()
{
return WinKey::isKeyControlPressed()
@ -239,6 +261,7 @@ bool TextHook::waitfornotify(TextOutput_T* buffer,void*data ,size_t*len,ThreadPa
if((translate.size()==0))return false;
translatecache.insert(std::make_pair(hash,translate));
}
if(embedsharedmem->line_text_length_limit)translate=limitTextWidth(translate,embedsharedmem->line_text_length_limit);
if(hp.newlineseperator)strReplace(translate,L"\n",hp.newlineseperator);
translate=adjustSpacesSTD(translate,hp);
if(embedsharedmem->keeprawtext)translate=origin+L" "+translate;

View File

@ -115,7 +115,7 @@ C_LUNA_API void Luna_FindHooks(DWORD pid, SearchParam sp, findhookcallback_t fin
wcscpy_s(hookcode,HOOKCODE_LEN, hp.hookcode);
findhookcallback(hookcode,text.c_str()); });
}
C_LUNA_API void Luna_EmbedSettings(DWORD pid, UINT32 waittime, UINT8 fontCharSet, bool fontCharSetEnabled, wchar_t *fontFamily, UINT32 spaceadjustpolicy, UINT32 keeprawtext, bool fastskipignore)
C_LUNA_API void Luna_EmbedSettings(DWORD pid, UINT32 waittime, UINT8 fontCharSet, bool fontCharSetEnabled, wchar_t *fontFamily, UINT32 spaceadjustpolicy, UINT32 keeprawtext, bool fastskipignore, UINT32 line_text_length_limit)
{
auto sm = Host::GetEmbedSharedMem(pid);
if (!sm)
@ -127,6 +127,7 @@ C_LUNA_API void Luna_EmbedSettings(DWORD pid, UINT32 waittime, UINT8 fontCharSet
sm->spaceadjustpolicy = spaceadjustpolicy;
sm->keeprawtext = keeprawtext;
sm->fastskipignore = fastskipignore;
sm->line_text_length_limit=line_text_length_limit;
}
C_LUNA_API bool Luna_checkisusingembed(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2)
{

View File

@ -27,6 +27,7 @@ struct EmbedSharedMem{
wchar_t fontFamily[100];
UINT codepage;
bool fastskipignore;
UINT32 line_text_length_limit;
};
class TextHook
{