2018-10-11 14:29:11 -04:00
|
|
|
#include "extension.h"
|
2018-09-01 04:24:22 -04:00
|
|
|
#include <set>
|
|
|
|
#include <mutex>
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-09-01 04:24:22 -04:00
|
|
|
bool RemoveRepeatedChars(std::wstring& sentence)
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-22 15:45:54 -04:00
|
|
|
int repeatNumber = 0;
|
2018-09-01 04:24:22 -04:00
|
|
|
wchar_t prevChar = sentence[0];
|
2018-10-30 21:21:21 -04:00
|
|
|
for (auto c : sentence)
|
|
|
|
if (c == prevChar) repeatNumber++;
|
2018-09-01 04:24:22 -04:00
|
|
|
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;
|
|
|
|
|
2018-09-13 02:50:03 -04:00
|
|
|
std::wstring newSentence = L"";
|
|
|
|
for (int i = 0; i < sentence.size(); ++i) if (i % repeatNumber == 0) newSentence.push_back(sentence[i]);
|
|
|
|
sentence = newSentence;
|
2018-09-01 04:24:22 -04:00
|
|
|
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-10-11 14:29:11 -04:00
|
|
|
if (sentence == L"") Skip();
|
2018-09-22 15:45:54 -04:00
|
|
|
int junkLength = 0;
|
2018-09-13 02:50:03 -04:00
|
|
|
wchar_t junk[2000] = {};
|
|
|
|
while (wcsstr(sentence.c_str() + junkLength, junk))
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-13 02:50:03 -04:00
|
|
|
junk[junkLength] = sentence[junkLength];
|
|
|
|
if (++junkLength >= 2000) return false;
|
2018-09-01 04:24:22 -04:00
|
|
|
}
|
2018-09-13 02:50:03 -04:00
|
|
|
if (--junkLength >= 5) // If the first 5 characters appear later on, there's probably a repetition issue.
|
2018-09-01 04:24:22 -04:00
|
|
|
{
|
2018-09-13 02:50:03 -04:00
|
|
|
sentence = std::wstring(sentence.c_str() + junkLength);
|
2018-09-01 04:24:22 -04:00
|
|
|
RemoveCyclicRepeats(sentence);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-09-22 15:45:54 -04:00
|
|
|
bool RemoveRepeatedSentences(std::wstring& sentence, int64_t handle)
|
2018-09-01 04:24:22 -04:00
|
|
|
{
|
2018-09-22 15:45:54 -04:00
|
|
|
static std::set<std::pair<int64_t, std::wstring>> seenSentences;
|
2018-09-01 04:24:22 -04:00
|
|
|
static std::mutex m;
|
|
|
|
std::lock_guard<std::mutex> l(m);
|
2018-10-11 14:29:11 -04:00
|
|
|
if (seenSentences.count({ handle, sentence }) != 0) Skip();
|
2018-09-13 02:50:03 -04:00
|
|
|
seenSentences.insert({ handle, sentence });
|
2018-09-01 04:24:22 -04:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-09-22 15:08:31 -04:00
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
2018-09-01 04:24:22 -04:00
|
|
|
{
|
2018-09-22 15:08:31 -04:00
|
|
|
if (sentenceInfo["hook address"] == -1) return false;
|
2018-09-13 02:50:03 -04:00
|
|
|
bool ret = false;
|
|
|
|
ret |= RemoveRepeatedChars(sentence);
|
|
|
|
ret |= RemoveCyclicRepeats(sentence);
|
2018-09-22 15:08:31 -04:00
|
|
|
ret |= RemoveRepeatedSentences(sentence, sentenceInfo["text handle"]);
|
2018-09-13 02:50:03 -04:00
|
|
|
return ret;
|
2018-08-19 00:13:19 -04:00
|
|
|
}
|