-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gamemode.cpp
49 lines (41 loc) · 1003 Bytes
/
Gamemode.cpp
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
#include <sstream>
#include "Gamemode.hpp"
void Gamemode::load(const std::string& name)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
handle = LoadLibrary(("gamemodes/" + name + ".dll").c_str());
if (handle == NULL)
{
DWORD error = GetLastError();
std::stringstream errMsg;
errMsg << "error code " << error;
throw std::runtime_error(errMsg.str());
}
#else
handle = dlopen(("gamemodes/" + name + ".so").c_str(), RTLD_GLOBAL | RTLD_NOW);
if (handle == NULL)
{
const char* errMsg = dlerror();
if (errMsg != NULL)
{
throw std::runtime_error(std::string(errMsg));
}
}
#endif
}
void Gamemode::unload()
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
FreeLibrary((HMODULE)handle);
#else
dlclose(handle);
#endif
}
void* Gamemode::findCallback(const std::string& name)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
return (void*)GetProcAddress((HMODULE)handle, name.c_str());
#else
return dlsym(handle, name.c_str());
#endif
}