1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "ns_plugin.h"
#include "internal/logging.h"
#include "plugin.h"
Plugin* plugin = nullptr;
extern "C" __declspec(dllexport)
void PLUGIN_INIT(PluginInitFuncs* funcs, PluginNorthstarData* data)
{
spdlog::default_logger()->sinks().pop_back();
spdlog::default_logger()->sinks().push_back(std::make_shared<PluginSink>(funcs->logger, data->pluginHandle));
plugin = new Plugin(funcs, data);
}
extern "C" __declspec(dllexport)
void PLUGIN_DEINIT()
{
assert(plugin);
delete plugin;
plugin = nullptr;
}
extern "C" __declspec(dllexport)
void PLUGIN_INFORM_DLL_LOAD(const char* dll, PluginEngineData* data, void* dllPtr) {
assert(plugin);
if (!strcmp(dll, "engine.dll"))
{
plugin->LoadEngineData(data, (HMODULE)dllPtr);
plugin->StartServer();
}
}
extern "C" __declspec(dllexport)
void PLUGIN_INIT_SQVM_CLIENT(SquirrelFunctions* funcs)
{
assert(plugin);
plugin->LoadSQVMFunctions(ScriptContext::CLIENT, funcs);
}
extern "C" __declspec(dllexport)
void PLUGIN_INIT_SQVM_SERVER(SquirrelFunctions* funcs)
{
assert(plugin);
plugin->LoadSQVMFunctions(ScriptContext::SERVER, funcs);
}
extern "C" __declspec(dllexport)
void PLUGIN_INFORM_SQVM_CREATED(ScriptContext context, CSquirrelVM* sqvm)
{
assert(plugin);
plugin->LoadSQVM(context, sqvm);
}
extern "C" __declspec(dllexport)
void PLUGIN_INFORM_SQVM_DESTROYED(ScriptContext context)
{
assert(plugin);
plugin->RemoveSQVM(context);
}
// There is no deinit logic for Plugins
// Recreate it using DllMain
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_DETACH:
PLUGIN_DEINIT();
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
|