-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_rehlds_api.cpp
82 lines (67 loc) · 2.69 KB
/
ex_rehlds_api.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
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
82
#include "precompiled.h"
#include <extdll.h>
#include <meta_api.h>
#include "ex_rehlds_api.h"
IRehldsApi* g_RehldsApi;
const RehldsFuncs_t* g_RehldsFuncs;
IRehldsServerData* g_RehldsData;
IRehldsHookchains* g_RehldsHookchains;
IRehldsServerStatic* g_RehldsSvs;
bool RehldsApi_Init()
{
#ifdef WIN32
// Find the most appropriate module handle from a list of DLL candidates
// Notes:
// - "swds.dll" is the library Dedicated Server
//
// Let's also attempt to locate the ReHLDS API in the client's library
// - "sw.dll" is the client library for Software render, with a built-in listenserver
// - "hw.dll" is the client library for Hardware render, with a built-in listenserver
const char *dllNames[] = { "swds.dll", "sw.dll", "hw.dll" }; // List of DLL candidates to lookup for the ReHLDS API
CSysModule *engineModule = NULL; // The module handle of the selected DLL
for (const char *dllName : dllNames)
{
if (engineModule = Sys_GetModuleHandle(dllName))
break; // gotcha
}
#else
CSysModule *engineModule = Sys_GetModuleHandle("engine_i486.so");
#endif
if (!engineModule)
return false;
CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule);
if (!ifaceFactory)
return false;
int retCode = 0;
g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode);
if (!g_RehldsApi)
return false;
int majorVersion = g_RehldsApi->GetMajorVersion();
int minorVersion = g_RehldsApi->GetMinorVersion();
if (majorVersion != REHLDS_API_VERSION_MAJOR)
{
UTIL_ServerPrint("[%s]: ReHLDS API major version mismatch; expected %d, real %d\n", Plugin_info.logtag, REHLDS_API_VERSION_MAJOR, majorVersion);
// need to notify that it is necessary to update the ReHLDS.
if (majorVersion < REHLDS_API_VERSION_MAJOR)
{
UTIL_ServerPrint("[%s]: Please update the ReHLDS up to a major version API >= %d\n", Plugin_info.logtag, REHLDS_API_VERSION_MAJOR);
}
// need to notify that it is necessary to update the module.
else if (majorVersion > REHLDS_API_VERSION_MAJOR)
{
UTIL_ServerPrint("[%s]: Please update the %s up to a major version API >= %d\n", Plugin_info.logtag, Plugin_info.logtag, majorVersion);
}
return false;
}
if (minorVersion < REHLDS_API_VERSION_MINOR)
{
UTIL_ServerPrint("[%s]: ReHLDS API minor version mismatch; expected at least %d, real %d\n", Plugin_info.logtag, REHLDS_API_VERSION_MINOR, minorVersion);
UTIL_ServerPrint("[%s]: Please update the ReHLDS up to a minor version API >= %d\n", Plugin_info.logtag, REHLDS_API_VERSION_MINOR);
return false;
}
g_RehldsFuncs = g_RehldsApi->GetFuncs();
g_RehldsData = g_RehldsApi->GetServerData();
g_RehldsHookchains = g_RehldsApi->GetHookchains();
g_RehldsSvs = g_RehldsApi->GetServerStatic();
return true;
}