2018-07-26 22:42:21 -07:00
|
|
|
#include "extensions.h"
|
2018-08-21 22:43:30 -04:00
|
|
|
#include <shared_mutex>
|
2018-07-28 12:41:21 -07:00
|
|
|
#include <QDir>
|
2018-07-26 22:42:21 -07:00
|
|
|
|
2018-08-21 22:43:30 -04:00
|
|
|
std::shared_mutex extenMutex;
|
2018-07-26 22:42:21 -07:00
|
|
|
std::map<int, ExtensionFunction> extensions;
|
|
|
|
|
2018-07-28 12:41:21 -07:00
|
|
|
std::map<int, QString> LoadExtensions()
|
2018-07-26 22:42:21 -07:00
|
|
|
{
|
2018-07-29 18:24:46 -07:00
|
|
|
std::map<int, ExtensionFunction> newExtensions;
|
2018-07-28 12:41:21 -07:00
|
|
|
std::map<int, QString> extensionNames;
|
2018-08-19 17:55:50 -04:00
|
|
|
QStringList files = QDir().entryList();
|
|
|
|
for (auto file : files)
|
|
|
|
if (file.endsWith("_nexthooker_extension.dll"))
|
|
|
|
if (GetProcAddress(GetModuleHandleW(file.toStdWString().c_str()), "OnNewSentence") ||
|
|
|
|
GetProcAddress(LoadLibraryW(file.toStdWString().c_str()), "OnNewSentence"))
|
|
|
|
{
|
|
|
|
QString extensionNumber = file.split("_")[0];
|
|
|
|
newExtensions[extensionNumber.toInt()] = (ExtensionFunction)GetProcAddress(GetModuleHandleW(file.toStdWString().c_str()), "OnNewSentence");
|
|
|
|
file.chop(sizeof("_nexthooker_extension.dll") - 1);
|
|
|
|
file.remove(0, extensionNumber.length() + 1);
|
|
|
|
extensionNames[extensionNumber.toInt()] = file;
|
|
|
|
}
|
2018-08-21 22:43:30 -04:00
|
|
|
extenMutex.lock();
|
2018-07-29 18:24:46 -07:00
|
|
|
extensions = newExtensions;
|
2018-08-21 22:43:30 -04:00
|
|
|
extenMutex.unlock();
|
2018-07-26 22:42:21 -07:00
|
|
|
return extensionNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map<std::string, int> miscInfo)
|
|
|
|
{
|
2018-08-21 22:43:30 -04:00
|
|
|
wchar_t* sentenceBuffer = (wchar_t*)malloc((sentence.size() + 1) * sizeof(wchar_t));
|
|
|
|
wcscpy(sentenceBuffer, sentence.c_str());
|
2018-07-29 14:36:45 -07:00
|
|
|
InfoForExtension* miscInfoLinkedList = new InfoForExtension;
|
|
|
|
InfoForExtension* miscInfoTraverser = miscInfoLinkedList;
|
2018-08-21 22:43:30 -04:00
|
|
|
for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->nextProperty = new InfoForExtension{ i.first.c_str(), i.second, new InfoForExtension };
|
|
|
|
extenMutex.lock_shared();
|
2018-07-29 14:36:45 -07:00
|
|
|
for (auto i : extensions)
|
2018-07-30 00:47:09 -07:00
|
|
|
{
|
2018-08-21 22:43:30 -04:00
|
|
|
wchar_t* prev = sentenceBuffer;
|
2018-07-29 14:36:45 -07:00
|
|
|
sentenceBuffer = i.second(sentenceBuffer, miscInfoLinkedList);
|
2018-07-30 11:29:36 -07:00
|
|
|
if (sentenceBuffer != prev) free((void*)prev);
|
2018-07-30 00:47:09 -07:00
|
|
|
}
|
2018-08-21 22:43:30 -04:00
|
|
|
extenMutex.unlock_shared();
|
|
|
|
delete miscInfoLinkedList;
|
2018-07-29 14:36:45 -07:00
|
|
|
std::wstring newSentence = std::wstring(sentenceBuffer);
|
2018-07-30 11:29:36 -07:00
|
|
|
free((void*)sentenceBuffer);
|
2018-07-29 14:36:45 -07:00
|
|
|
return newSentence;
|
2018-07-26 22:42:21 -07:00
|
|
|
}
|