2018-08-19 00:13:19 -04:00
|
|
|
#include "extensions.h"
|
2018-09-01 04:24:22 -04:00
|
|
|
#include <set>
|
|
|
|
#include <mutex>
|
2018-08-19 00:13:19 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-09-01 04:24:22 -04:00
|
|
|
bool RemoveRepeatedChars(std::wstring& sentence)
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-01 04:24:22 -04:00
|
|
|
unsigned int repeatNumber = 0;
|
|
|
|
wchar_t prevChar = sentence[0];
|
|
|
|
for (auto i : sentence)
|
|
|
|
if (i == prevChar) repeatNumber++;
|
|
|
|
else break;
|
|
|
|
if (repeatNumber == 1) return false;
|
|
|
|
|
|
|
|
for (int i = 0; i < sentence.size(); i += repeatNumber)
|
|
|
|
for (int j = i; j < sentence.size(); ++j)
|
|
|
|
if (sentence[j] != sentence[i])
|
|
|
|
if ((j - i) % repeatNumber != 0) return false;
|
|
|
|
else break;
|
|
|
|
|
|
|
|
// Removes every repeatNumber'th character.
|
|
|
|
sentence.erase(std::remove_if(sentence.begin(), sentence.end(), [&](const wchar_t& c) {return (&c - &*sentence.begin()) % repeatNumber != 0; }), sentence.end());
|
|
|
|
return true;
|
2018-08-19 00:13:19 -04:00
|
|
|
}
|
|
|
|
|
2018-09-01 04:24:22 -04:00
|
|
|
bool RemoveCyclicRepeats(std::wstring& sentence)
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-01 04:24:22 -04:00
|
|
|
unsigned int realLength = 6; // If the first 6 characters appear later on, there's probably a repetition issue.
|
|
|
|
if (sentence.size() < realLength) return false;
|
|
|
|
wchar_t realSentence[2000] = {};
|
|
|
|
memcpy(realSentence, sentence.c_str(), realLength * sizeof(wchar_t));
|
|
|
|
while (wcsstr(sentence.c_str() + realLength, realSentence))
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-01 04:24:22 -04:00
|
|
|
realSentence[realLength] = sentence[realLength];
|
|
|
|
if (++realLength >= 2000) return false;
|
|
|
|
}
|
|
|
|
if (realLength > 7)
|
|
|
|
{
|
|
|
|
sentence = std::wstring(realSentence);
|
2018-09-03 18:37:32 -04:00
|
|
|
sentence.pop_back();
|
2018-09-01 04:24:22 -04:00
|
|
|
RemoveCyclicRepeats(sentence);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-09-01 04:24:22 -04:00
|
|
|
bool RemoveRepeatedSentences(std::wstring& sentence, int threadHandle)
|
|
|
|
{
|
|
|
|
static std::set<std::pair<int, std::wstring>> seenSentences;
|
|
|
|
static std::mutex m;
|
|
|
|
std::lock_guard<std::mutex> l(m);
|
|
|
|
if (seenSentences.count({ threadHandle, sentence }) != 0) throw std::exception();
|
|
|
|
seenSentences.insert({ threadHandle, sentence });
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-09-01 04:24:22 -04:00
|
|
|
bool ProcessSentence(std::wstring& sentence, const InfoForExtension* miscInfo)
|
|
|
|
{
|
|
|
|
if (GetProperty("hook address", miscInfo) == -1) return false;
|
2018-09-02 12:47:48 -04:00
|
|
|
return RemoveRepeatedChars(sentence) | RemoveCyclicRepeats(sentence) | RemoveRepeatedSentences(sentence, GetProperty("text handle", miscInfo));
|
2018-08-19 00:13:19 -04:00
|
|
|
}
|