From 8b345a43778ce6dec548d6049191b5f3bc38074f Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 30 Sep 2019 08:45:01 -0400 Subject: [PATCH] fix mono perf issues (hopefully) --- GUI/host/textthread.cpp | 4 ++++ include/const.h | 5 +++-- texthook/engine/engine.cc | 2 +- texthook/engine/match64.cc | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 8aced68..b5bfe1c 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -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 (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()); AddSentence(std::move(buffer)); buffer.clear(); @@ -79,11 +80,14 @@ void TextThread::Flush() std::deque sentences; queuedSentences->swap(sentences); + int totalSize = 0; for (auto& sentence : sentences) { + totalSize += sentence.size(); sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0')); 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); if (buffer.empty()) return; diff --git a/include/const.h b/include/const.h index 40e015a..a685b09 100644 --- a/include/const.h +++ b/include/const.h @@ -27,6 +27,7 @@ enum HookParamType : unsigned FIXING_SPLIT = 0x800, DIRECT_READ = 0x1000, // /R read code instead of classic /H hook code FULL_STRING = 0x2000, - HOOK_ENGINE = 0x4000, - HOOK_ADDITIONAL = 0x8000, + BLOCK_FLOOD = 0x4000, // remove this hook if flooding text causing perf issues + HOOK_ENGINE = 0x8000, + HOOK_ADDITIONAL = 0x10000, }; diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index cb37c55..bdf5895 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -16681,7 +16681,7 @@ void InsertMonoHook(HMODULE h) { HookParam hp = {}; hp.address = addr; - hp.type = USING_UNICODE | FULL_STRING; + hp.type = USING_UNICODE | FULL_STRING | BLOCK_FLOOD; hp.offset = 4; hp.text_fun = [](DWORD esp_base, HookParam*, BYTE, DWORD* data, DWORD* split, DWORD* len) { diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index 371827c..a68ea62 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -95,7 +95,7 @@ namespace Engine { HookParam hp = {}; 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.padding = 20; hp.length_fun = [](uintptr_t, uintptr_t data)