|
1 |
| -#include <set> |
2 |
| -#include <fstream> |
3 |
| -#include <tchar.h> |
4 |
| -#include <list> |
5 |
| -#include <vector> |
6 |
| - |
7 | 1 | #include "pch.h"
|
8 |
| -#include "INIReader.h" // https://github.com/jtilly/inih |
9 |
| - |
10 |
| -#include "HookLib.h" |
11 | 2 | #include "PluginLoadHook.h"
|
12 |
| -#pragma comment(lib, "Zydis.lib") |
13 |
| -#pragma comment(lib, "HookLib.lib") |
14 | 3 |
|
15 | 4 | std::wstring pluginsPath;
|
16 | 5 | static std::wstring iniPath;
|
@@ -39,6 +28,16 @@ VOID WINAPI ExitProcessHook(ULONG ExitCode)
|
39 | 28 | #pragma endregion
|
40 | 29 |
|
41 | 30 | #pragma region Plugin Loading
|
| 31 | + |
| 32 | +void PluginLoadFunction(std::wstring dll, long delay) { |
| 33 | + std::this_thread::sleep_for(std::chrono::seconds(delay)); |
| 34 | + HMODULE hMod = LoadLibrary(dll.c_str()); |
| 35 | + if (hMod) |
| 36 | + loadedModules.push_back(hMod); |
| 37 | + else |
| 38 | + std::wcout << "Unable to load plugin: " << dll << ": " << GetLastErrorAsString() << std::endl; |
| 39 | +} |
| 40 | + |
42 | 41 | void LoadPlugins() {
|
43 | 42 | std::wcout << "Loading Plugins..." << std::endl;
|
44 | 43 |
|
@@ -67,31 +66,37 @@ void LoadPlugins() {
|
67 | 66 | return; // Just return now, no need to bother to execute the rest of the code
|
68 | 67 | }
|
69 | 68 |
|
| 69 | + std::vector<std::thread> threads; |
| 70 | + |
70 | 71 | do {
|
71 | 72 | if ((!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))) {
|
72 | 73 | std::wstring pluginName = (std::wstring)fd.cFileName;
|
73 | 74 | std::string s(pluginName.begin(), pluginName.end());
|
74 | 75 |
|
| 76 | + std::wstring filePath = pluginsPath + (pluginName); // Generate our file path + the name of our plugin to load |
| 77 | + |
75 | 78 | if (reader.Sections().count(s)) {
|
76 | 79 | float delayTime = reader.GetFloat(s, "delaySeconds", 0);
|
77 |
| - std::wcout << "Waiting " << delayTime << " seconds to load " << WidenString(s) << std::endl; |
78 |
| - Sleep(delayTime * 1000); |
| 80 | + std::wcout << "Waiting " << delayTime << " seconds to load " << pluginName << "\n"; |
| 81 | + threads.push_back(std::thread(PluginLoadFunction, filePath, (long)delayTime)); |
79 | 82 | }
|
80 |
| - |
81 |
| - |
82 |
| - std::wstring filePath = pluginsPath + (pluginName); // Generate our file path + the name of our plugin to load |
83 |
| - HMODULE hMod = LoadLibrary(filePath.c_str()); |
84 |
| - if (hMod) { |
85 |
| - loadedModules.push_back(hMod); |
86 |
| - dllCount++; |
| 83 | + else { |
| 84 | + HMODULE hMod = LoadLibrary(filePath.c_str()); |
| 85 | + if (hMod) loadedModules.push_back(hMod); |
| 86 | + else std::wcout << "Unable to load plugin: " << filePath << ": " << GetLastErrorAsString() << std::endl; |
87 | 87 | }
|
88 |
| - else |
89 |
| - std::wcout << "Unable to load plugin: " << filePath << ": " << GetLastErrorAsString() << std::endl; |
90 | 88 | }
|
91 | 89 |
|
92 | 90 | } while (FindNextFile(dllFile, &fd));
|
93 |
| - |
94 | 91 | FindClose(dllFile);
|
| 92 | + |
| 93 | + for (auto& t : threads) { |
| 94 | + if (t.joinable()) |
| 95 | + t.join(); |
| 96 | + } |
| 97 | + |
| 98 | + // Add an extra new line just in case it all gets messed up with the whole multithreading |
| 99 | + std::wcout << std::endl; |
95 | 100 | }
|
96 | 101 |
|
97 | 102 | using _LoadLibrary = HMODULE(WINAPI*)(LPCWSTR lpLibFileName);
|
|
0 commit comments