-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.cpp
103 lines (76 loc) · 2.97 KB
/
extension.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "extension.h"
#include "shared/forwards.h"
#include "l4d2/forwards.h"
#include "RegNatives.h"
Left4downtown g_Left4downtown;
SMEXT_LINK(&g_Left4downtown);
IGameConfig *g_pGameConf = nullptr;
IBinTools *g_pBinTools = nullptr;
ISDKTools *g_pSDKTools = nullptr;
ICvar *icvar = nullptr;
CGlobalVars *gpGlobals = nullptr;
bool m_bDetoursEnabled;
ConVar left4downtown_version("left4downtown_redux_version", SMEXT_CONF_VERSION, FCVAR_SPONLY|FCVAR_NOTIFY,
"Left 4 Downtown redux version");
ConVar l4d_maxplayers("l4d_maxplayers", "-1", FCVAR_SPONLY|FCVAR_NOTIFY,
"Overrides maxplayers with this value");
class BaseAccessor : public IConCommandBaseAccessor {
public:
bool RegisterConCommandBase(ConCommandBase *pCommandBase) {
return META_REGCVAR(pCommandBase);
}
} s_BaseAccessor;
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int , int);
bool Left4downtown::SDK_OnLoad(char *error, size_t maxlen, bool late) {
plsys->AddPluginsListener(this);
sharesys->RegisterLibrary(myself, "left4downtown");
sharesys->AddDependency(myself, "bintools.ext", true, true);
sharesys->AddDependency(myself, "sdktools.ext", true, true);
sharesys->AddNatives(myself, g_SharedNatives);
#if SOURCE_ENGINE == SE_LEFT4DEAD2
sharesys->AddNatives(myself, g_L4D2Natives);
#endif
if (!gameconfs->LoadGameConfigFile("left4downtown.games", &g_pGameConf, error, maxlen)) {
return false;
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
CCallManager::Init(g_pGameConf);
CreateSharedForwards();
#if SOURCE_ENGINE == SE_LEFT4DEAD2
CreateL4D2Forwards();
#endif
#ifdef _DEBUG
smutils->LogMessage(myself, "Left 4 Downtown Redux v%s loaded", left4downtown_version.GetString());
#endif
return true;
}
void Left4downtown::SDK_OnUnload() {
g_RegNatives.UnregisterAll();
gameconfs->CloseGameConfigFile(g_pGameConf);
ReleaseSharedForwards();
#if SOURCE_ENGINE == SE_LEFT4DEAD2
ReleaseL4D2Forwards();
#endif
}
void Left4downtown::SDK_OnAllLoaded() {
SM_GET_LATE_IFACE(SDKTOOLS, g_pSDKTools);
if (g_pSDKTools == nullptr) {
smutils->LogError(myself, "SDKTools interface not found");
}
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
}
bool Left4downtown::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) {
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
g_pCVar = icvar;
ConVar_Register(0, &s_BaseAccessor);
gpGlobals = ismm->GetCGlobals();
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &Left4downtown::OnServerActivate, true);
return true;
}
bool Left4downtown::SDK_OnMetamodUnload(char *error, size_t maxlen) {
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &Left4downtown::OnServerActivate, true);
return true;
}
void Left4downtown::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax) {
InitializeValveGlobals();
}