fix mono perf issues (hopefully)

This commit is contained in:
Akash Mozumdar 2019-09-30 08:45:01 -04:00
parent 17aa20109f
commit 8b345a4377
4 changed files with 9 additions and 4 deletions

View File

@ -57,6 +57,7 @@ void TextThread::Push(BYTE* data, int length)
if (std::all_of(buffer.begin(), buffer.end(), [&](auto ch) { return repeatingChars.find(ch) != repeatingChars.end(); })) buffer.clear(); if (std::all_of(buffer.begin(), buffer.end(), [&](auto ch) { return repeatingChars.find(ch) != repeatingChars.end(); })) buffer.clear();
if (RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received if (RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received
{ {
if (hp.type & BLOCK_FLOOD) Host::RemoveHook(tp.processId, tp.addr);
repeatingChars = std::unordered_set(buffer.begin(), buffer.end()); repeatingChars = std::unordered_set(buffer.begin(), buffer.end());
AddSentence(std::move(buffer)); AddSentence(std::move(buffer));
buffer.clear(); buffer.clear();
@ -79,11 +80,14 @@ void TextThread::Flush()
std::deque<std::wstring> sentences; std::deque<std::wstring> sentences;
queuedSentences->swap(sentences); queuedSentences->swap(sentences);
int totalSize = 0;
for (auto& sentence : sentences) for (auto& sentence : sentences)
{ {
totalSize += sentence.size();
sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0')); sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0'));
if (Output(*this, sentence)) storage->append(sentence); if (Output(*this, sentence)) storage->append(sentence);
} }
if (hp.type & BLOCK_FLOOD && totalSize > PIPE_BUFFER_SIZE) Host::RemoveHook(tp.processId, tp.addr);
std::scoped_lock lock(bufferMutex); std::scoped_lock lock(bufferMutex);
if (buffer.empty()) return; if (buffer.empty()) return;

View File

@ -27,6 +27,7 @@ enum HookParamType : unsigned
FIXING_SPLIT = 0x800, FIXING_SPLIT = 0x800,
DIRECT_READ = 0x1000, // /R read code instead of classic /H hook code DIRECT_READ = 0x1000, // /R read code instead of classic /H hook code
FULL_STRING = 0x2000, FULL_STRING = 0x2000,
HOOK_ENGINE = 0x4000, BLOCK_FLOOD = 0x4000, // remove this hook if flooding text causing perf issues
HOOK_ADDITIONAL = 0x8000, HOOK_ENGINE = 0x8000,
HOOK_ADDITIONAL = 0x10000,
}; };

View File

@ -16681,7 +16681,7 @@ void InsertMonoHook(HMODULE h)
{ {
HookParam hp = {}; HookParam hp = {};
hp.address = addr; hp.address = addr;
hp.type = USING_UNICODE | FULL_STRING; hp.type = USING_UNICODE | FULL_STRING | BLOCK_FLOOD;
hp.offset = 4; hp.offset = 4;
hp.text_fun = [](DWORD esp_base, HookParam*, BYTE, DWORD* data, DWORD* split, DWORD* len) hp.text_fun = [](DWORD esp_base, HookParam*, BYTE, DWORD* data, DWORD* split, DWORD* len)
{ {

View File

@ -95,7 +95,7 @@ namespace Engine
{ {
HookParam hp = {}; HookParam hp = {};
hp.address = addr; hp.address = addr;
hp.type = USING_STRING | USING_UNICODE | FULL_STRING; hp.type = USING_STRING | USING_UNICODE | BLOCK_FLOOD | FULL_STRING;
hp.offset = -0x20; // rcx hp.offset = -0x20; // rcx
hp.padding = 20; hp.padding = 20;
hp.length_fun = [](uintptr_t, uintptr_t data) hp.length_fun = [](uintptr_t, uintptr_t data)