-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.cpp
More file actions
351 lines (281 loc) · 11.4 KB
/
extension.cpp
File metadata and controls
351 lines (281 loc) · 11.4 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Sample Extension
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include "extension.h"
#include <icvar.h>
#ifdef ENGINE_CSS34
#define CVAR_INTERFACE_VERSION VENGINE_CVAR_INTERFACE_VERSION
#endif
CProtectCMDS g_ProtectCMDS; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_ProtectCMDS);
#ifdef ENGINE_CSS34
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CProtectCMDS, IProtectCMDS, INTERFACE_PROTECTCMDS, g_ProtectCMDS);
#endif
char g_cPrefix[] = "[ProtectCMDS]";
#include <tier1/interface.h>
#ifdef ENGINE_CSS34
#include <dlls/iplayerinfo.h>
#elif ENGINE_CSS
#include <edict.h>
#include <game/server/iplayerinfo.h>
#endif
IPlayerInfoManager* g_pPlayerInfoManager = nullptr;
CGlobalVars* g_pGlobals = nullptr;
#include "helpers/symbolmanager.h"
#include "helpers/inireader.h"
#include "CDetour/detours.h"
#include "helpers/util.h"
#define ENGINE_MAX 4
const char sEngineName[ENGINE_MAX][19] = {
"bin/engine_i686.so", "bin/engine_i486.so", "bin/engine_amd.so", "bin/engine_srv.so"
};
bool CProtectCMDS::GetEngineNameLoaded(char *pEngine, int iMaxLength) {
for (int i = 0; i < ENGINE_MAX; i++) {
void *pHandle = (void *)dlopen(sEngineName[i], RTLD_NOW | RTLD_NOLOAD);
if (!pHandle) continue;
Q_strncpy(pEngine, sEngineName[i], iMaxLength);
dlclose(pHandle);
return true;
}
return false;
}
bool CProtectCMDS::LoadLibraries() {
g_pSymbolManager = new CSymbolManager();
char sEngine[20];
if (!GetEngineNameLoaded(sEngine, sizeof(sEngine))) {
g_pSM->LogError(myself, "Сould not find engine file loaded");
return false;
}
if (!g_pSymbolManager->AddModule(ESymbolModule::ENGINE, sEngine)) return false;
char szServerBin[MAX_PATH];
#ifdef ENGINE_CSS34
g_pSM->BuildPath(Path_Game, szServerBin, sizeof(szServerBin), "bin/server_i486.so");
if (!g_pSymbolManager->AddModule(ESymbolModule::VALVE_API, "bin/valve_api.so")) return false;
cvar = GetCVarIF();
#else
g_pSM->BuildPath(Path_Game, szServerBin, sizeof(szServerBin), "bin/server_srv.so");
CreateInterfaceFn vstdlibFactory = Sys_GetFactory("libvstdlib_srv.so");
cvar = static_cast<ICvar*>(vstdlibFactory(CVAR_INTERFACE_VERSION, nullptr));
#endif
if(!cvar)
{
g_pSM->LogError(myself, "Failed to get ICvar interface");
return false;
}
if (!g_pSymbolManager->AddModule(ESymbolModule::SERVER, szServerBin)) return false;
CreateInterfaceFn gameServerFactory = Sys_GetFactory(szServerBin);
g_pPlayerInfoManager = static_cast<IPlayerInfoManager*>(gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, nullptr));
if (!g_pPlayerInfoManager) {
g_pSM->LogError(myself, "Сould not find interface: %s", INTERFACEVERSION_PLAYERINFOMANAGER);
return false;
}
g_pGlobals = g_pPlayerInfoManager->GetGlobalVars();
return true;
}
bool CProtectCMDS::LoadSettings() {
if (g_pSettings) delete g_pSettings;
char szPathSettings[256];
g_pSM->BuildPath(Path_SM, szPathSettings, sizeof szPathSettings, "data/protectcmds/protectcmds.ini");
g_pSettings = new INIReader(szPathSettings);
if (g_pSettings->ParseError() < 0) {
g_pSM->LogError(myself, "Can't load '%s'", szPathSettings);
return false;
}
if (!g_pSettings->GetInteger("ProtectCMDS", "protectcmds_enable", 0)) {
g_pSM->LogMessage(myself, "Disabled!\n");
return false;
}
return true;
}
void CProtectCMDS::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) {
if (m_pBlockCmds) m_pBlockCmds->OnMapStart();
if (m_pVoiceFix) m_pVoiceFix->OnMapStart();
}
sp_nativeinfo_t protectcmds_natives[] = {
{"ProtectCMDS_GetAbsoluteFrameTime", GetAbsoluteFrameTime},
{nullptr, nullptr}
};
cell_t GetAbsoluteFrameTime(IPluginContext *pContext, const cell_t *params) {
return sp_ftoc(g_pGlobals->absoluteframetime);
}
bool CProtectCMDS::SDK_OnLoad(char* error, size_t maxlength, bool late) {
if (!LoadLibraries())
{
Q_snprintf(error, maxlength, "Failed to load libraries");
return false;
}
if (!LoadSettings())
{
Q_snprintf(error, maxlength, "Failed to load settings");
return false;
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), nullptr);
IExtension *pExtensionManager = nullptr;
SM_GET_IFACE(EXTENSIONMANAGER, pExtensionManager);
if (!pExtensionManager)
{
Q_snprintf(error, maxlength, "Failed to get IExtensionManager");
return false;
}
if (g_pSettings->GetInteger("Updater", "protectcmds_updater_enable", 1)) {
m_pUpdater = new CPCMDSUpdater;
if (m_pUpdater) {
m_pUpdater->SetUrl(g_pSettings->GetString("Updater", "protectcmds_updater_url", "http://protectcmds.gm-world.ru"));
m_pUpdater->SetExperimental(g_pSettings->GetInteger("Updater", "protectcmds_updater_experimental", 0));
m_pUpdater->Load((void *)pExtensionManager);
}
else g_pSM->LogError(myself, "Updater failed to load!");
}
if (g_pSettings->GetInteger("FilterPacket", "filterpacket_enable", 1)) {
m_pFilterPacket = new CFilterPacket;
if (m_pFilterPacket) m_pFilterPacket->Load();
else g_pSM->LogError(myself, "Filter Packet failed to load!");
}
sharesys->AddNatives(myself, protectcmds_natives);
sharesys->RegisterLibrary(myself, "ProtectCMDS");
return true;
}
void CProtectCMDS::SDK_OnAllLoaded() {
if (g_pSettings->GetInteger("BlockCmds", "blockcmds_enable", 1)) {
m_pBlockCmds = new CBlockCmds;
if (m_pBlockCmds) {
m_pBlockCmds->Load();
m_pBlockCmds->SetMaxUserCmds(g_pSettings->GetInteger("blockCmds", "blockcmds_maxcommands", 30));
}
else g_pSM->LogError(myself, "BlockCmds failed to load!");
}
if (g_pSettings->GetInteger("SteamIDHashing", "steamidhashing_enable", 1)) {
m_pHashingSteamID = new CHashingSteamID;
if (m_pHashingSteamID) m_pHashingSteamID->Load();
else g_pSM->LogError(myself, "SteamID Hashing failed to load!");
}
#ifdef ENGINE_CSS34
if (g_pSettings->GetInteger("GamePacketFix", "gamepacketfix_enable", 1)) {
m_pGamePacketFix = new CGamePacketFix;
if (m_pGamePacketFix) m_pGamePacketFix->Load();
else g_pSM->LogError(myself, "GamePacketFix failed to load!");
}
m_pPreConnectHook = new CPreConnectHook;
if (m_pPreConnectHook) m_pPreConnectHook->Load();
else g_pSM->LogError(myself, "PreConnectHook failed to load!");
#endif
m_pVoiceFix = new CVoiceFix;
if (m_pVoiceFix) m_pVoiceFix->Load();
else g_pSM->LogError(myself, "VoiceFix failed to load!");
#ifdef ENGINE_CSS34
m_pBlockLoadPluginFix = new CBlockLoadPluginFix;
if (m_pBlockLoadPluginFix) m_pBlockLoadPluginFix->Load();
else g_pSM->LogError(myself, "Block bad load plugin failed to load!");
m_pBoneIndexByNameFix = new CBoneIndexByNameFix;
if (m_pBoneIndexByNameFix) m_pBoneIndexByNameFix->Load();
else g_pSM->LogError(myself, "BoneIndexByNameFix failed to load!");
if (g_pSettings->GetInteger("GameStats", "gamestats_enable", 1)) {
m_pGameStatsFix = new CGameStatsFix;
if (m_pGameStatsFix) m_pGameStatsFix->Load();
else g_pSM->LogError(myself, "GameStatsFix failed to load!");
}
m_pGameUIFix = new CGameUIFix;
if (m_pGameUIFix) m_pGameUIFix->Load();
m_pObServerLoopFix = new CObServerLoopFix;
if (m_pObServerLoopFix) m_pObServerLoopFix->Load();
else g_pSM->LogError(myself, "ObServerLiipFix failed to load!");
if (g_pSettings->GetInteger("OSFix", "osfix_enable", 1)) {
m_pOSFix = new COSFix;
if (m_pOSFix) m_pOSFix->Load();
else g_pSM->LogError(myself, "OSFix failed to load!");
}
m_pSourceTVFix = new CSourceTVFix;
if (m_pSourceTVFix) m_pSourceTVFix->Load();
else g_pSM->LogError(myself, "SourceTVFix failed to load!");
m_pTakeDamageFix = new CTakeDamageFix;
if (m_pTakeDamageFix) m_pTakeDamageFix->Load();
else g_pSM->LogError(myself, "TakeDamageFix failed to load!");
m_pFireGameEventFix = new CFireGameEventFix;
if (m_pFireGameEventFix) m_pFireGameEventFix->Load();
else g_pSM->LogError(myself, "FireGameEventFix failed to load!");
m_pNameFix = new CNameFix;
if (m_pNameFix) m_pNameFix->Load();
else g_pSM->LogError(myself, "NameFix failed to load!");
m_pVoxelHashFix = new CVoxelHashFix;
if (m_pVoxelHashFix) m_pVoxelHashFix->Load();
else g_pSM->LogError(myself, "VoxelHashFix failed to load!");
m_pSpecGotoFix = new CSpecGotoFix;
if (m_pSpecGotoFix) m_pSpecGotoFix->Load();
else g_pSM->LogError(myself, "SpecGotoFix failed to load!");
if (g_pSettings->GetInteger("VACPatch", "vacpatch_enable", 1)) {
m_pVACPatch = new CVACPatch;
if (m_pVACPatch) m_pVACPatch->Load();
else g_pSM->LogError(myself, "VACPatch failed to load!");
}
/*if (g_pSettings->GetInteger("RCONAccess", "rconaccess_enable", 1)) {
ConMsg(0, "rcon access load\n");
m_pRCONAccess = new CRCONAccess;
if (m_pRCONAccess) m_pRCONAccess->Load();
else g_pSM->LogError(myself, "RCON Access failed to load!");
}*/
#endif
}
void CProtectCMDS::SDK_OnUnload() {
if (m_pFilterPacket) m_pFilterPacket->Unload();
if (m_pBlockLoadPluginFix) m_pBlockLoadPluginFix->Unload();
if (m_pBlockCmds) m_pBlockCmds->Unload();
if (m_pBoneIndexByNameFix) m_pBoneIndexByNameFix->Unload();
if (m_pGameStatsFix) m_pGameStatsFix->Unload();
if (m_pGameUIFix) m_pGameUIFix->Unload();
if (m_pHashingSteamID) m_pHashingSteamID->Unload();
if (m_pObServerLoopFix) m_pObServerLoopFix->Unload();
if (m_pOSFix) m_pOSFix->Unload();
#ifdef ENGINE_CSS34
if (m_pGamePacketFix) m_pGamePacketFix->Unload();
if (m_pPreConnectHook) m_pPreConnectHook->Unload();
#endif
if (m_pSourceTVFix) m_pSourceTVFix->Unload();
if (m_pTakeDamageFix) m_pTakeDamageFix->Unload();
if (m_pVoiceFix) m_pVoiceFix->Unload();
if (m_pFireGameEventFix) m_pFireGameEventFix->Unload();
if (m_pNameFix) m_pNameFix->Unload();
if (m_pUpdater) {
m_pUpdater->Unload();
delete m_pUpdater;
m_pUpdater = nullptr;
}
if (g_pSymbolManager) {
delete g_pSymbolManager;
g_pSymbolManager = nullptr;
}
if (g_pSettings) {
delete g_pSettings;
g_pSettings = nullptr;
}
g_pSM->LogMessage(myself, "Unloaded");
}
void *CProtectCMDS::GetExtensionPtr() {
return myself;
}