-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.cpp
383 lines (302 loc) · 11.9 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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include "extension.h"
#include "CAI_NetworkManager.h"
#include "GameSystem.h"
#include "tier3.h"
#include "datacache/imdlcache.h"
#include "scenefilecache/ISceneFileCache.h"
Monster g_Monster;
bool g_bUseNetworkVars = false;
SMEXT_LINK(&g_Monster);
CGlobalVars *gpGlobals = NULL;
INetworkStringTableContainer *netstringtables = NULL;
INetworkStringTable *g_pStringTableParticleEffectNames = NULL;
IEngineSound *engsound = NULL;
IEngineTrace *enginetrace = NULL;
IServerGameClients *gameclients = NULL;
ICvar *icvar = NULL;
IUniformRandomStream *enginerandom = NULL;
IStaticPropMgrServer *staticpropmgr = NULL;
IVModelInfo *modelinfo = NULL;
IPhysicsObjectPairHash *my_g_EntityCollisionHash = NULL;
ISpatialPartition *partition = NULL;
IPhysicsSurfaceProps *physprops = NULL;
IPhysicsCollision *physcollision = NULL;
IPhysicsEnvironment *physenv;
IPhysics *iphysics = NULL;
ISoundEmitterSystemBase *soundemitterbase = NULL;
IFileSystem *filesystem = NULL;
IEffects *g_pEffects = NULL;
IDecalEmitterSystem *decalsystem = NULL;
IEngineSound *enginesound = NULL;
ITempEntsSystem *te = NULL;
CSharedEdictChangeInfo *g_pSharedChangeInfo = NULL;
IGameMovement *g_pGameMovement = NULL;
IGameConfig *g_pGameConf = NULL;
IServerTools *servertools = NULL;
ISceneFileCache *scenefilecache = NULL;
CBaseEntityList *g_pEntityList = NULL;
CEntity *my_g_WorldEntity = NULL;
CBaseEntity *my_g_WorldEntity_cbase = NULL;
int gCmdIndex;
int gMaxClients;
unsigned long serverdll_addr;
int g_sModelIndexSmoke;
short g_sModelIndexBubbles;
bool CommandInitialize();
//extern sp_nativeinfo_t g_MonsterNatives[];
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, 0, int);
#define TEST_SIGNATURE 1
#if TEST_SIGNATURE
size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char *hexstr)
{
size_t written = 0;
size_t length = strlen(hexstr);
for (size_t i = 0; i < length; i++)
{
if (written >= maxlength)
break;
buffer[written++] = hexstr[i];
if (hexstr[i] == '\\' && hexstr[i + 1] == 'x')
{
if (i + 3 >= length)
continue;
/* Get the hex part. */
char s_byte[3];
int r_byte;
s_byte[0] = hexstr[i + 2];
s_byte[1] = hexstr[i + 3];
s_byte[2] = '\0';
/* Read it as an integer */
sscanf(s_byte, "%x", &r_byte);
/* Save the value */
buffer[written - 1] = r_byte;
/* Adjust index */
i += 3;
}
}
return written;
}
class Test_Signature : public ITextListener_SMC
{
virtual void ReadSMC_ParseStart()
{
has_error = false;
addrInBase = (void *)g_SMAPI->GetServerFactory(false);
ignore = true;
}
virtual SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
{
if(strcmp(name,"Signatures") == 0)
{
ignore = false;
}
strncpy(current_name,name, strlen(name));
current_name[strlen(name)] = '\0';
return SMCResult_Continue;
}
virtual SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
if(!ignore && strcmp(key,"windows") == 0)
{
unsigned char real_sig[511];
size_t real_bytes;
size_t length;
real_bytes = 0;
length = strlen(value);
real_bytes = UTIL_DecodeHexString(real_sig, sizeof(real_sig), value);
if (real_bytes >= 1)
{
void *addr = memutils->FindPattern(addrInBase,(char *)real_sig,real_bytes);
if(addr == NULL)
{
has_error = true;
META_CONPRINTF("[%s DEBUG] %s - FAIL\n",g_Monster.GetLogTag(), current_name);
}
}
}
return SMCResult_Continue;
}
public:
bool HasError() { return has_error; }
private:
bool ignore;
void *addrInBase;
char current_name[128];
bool has_error;
} g_Test_Signature;
#endif
bool Monster::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
void *__laddr = reinterpret_cast<void *>(g_SMAPI->GetServerFactory(false));
MEMORY_BASIC_INFORMATION mem;
if(!VirtualQuery(__laddr, &mem, sizeof(MEMORY_BASIC_INFORMATION))) {
return false;
}
if(mem.AllocationBase == NULL) {
return false;
}
HMODULE dll = (HMODULE)mem.AllocationBase;
serverdll_addr = (unsigned long)dll;
//0EB829DE
//META_CONPRINTF("%p\n",reinterpret_cast<void *>(0x000AAD60 +serverdll_addr));
//META_CONPRINTF("%p\n",reinterpret_cast<void *>(0x000D5090 +serverdll_addr));
const char *game_foler = g_pSM->GetGameFolderName();
/*if(stricmp(game_foler,"hl2mp") == 0 ||
stricmp(game_foler,"garrysmod") == 0 ||
stricmp(game_foler,"obsidian") == 0
)*/
if(stricmp(game_foler,"cstrike") != 0)
{
g_pSM->Format(error, maxlength, "NOT allow load this extension: %s", game_foler);
return false;
}
char conf_error[255] = "";
char config_path[255];
snprintf(config_path, sizeof(config_path),"monster/monster.%s.games",game_foler);
if (!gameconfs->LoadGameConfigFile(config_path, &g_pGameConf, conf_error, sizeof(conf_error)))
{
if (conf_error[0])
{
g_pSM->Format(error, maxlength, "Could not read monster.%s.games: %s", game_foler, conf_error);
}
return false;
}
#if TEST_SIGNATURE
char path[512];
g_pSM->BuildPath(Path_SM,path, sizeof(path),"gamedata/monster/monster.%s.games.txt",game_foler);
SMCStates state = {0, 0};
textparsers->ParseFile_SMC(path, &g_Test_Signature, &state);
if(g_Test_Signature.HasError())
{
g_pSM->LogError(myself, "Some Signature counld not found.");
return false;
}
#endif
if (!GetEntityManager()->Init(g_pGameConf))
{
g_pSM->LogError(myself, "CEntity failed to Initialize.");
return false;
}
g_pSharedChangeInfo = engine->GetSharedEdictChangeInfo();
g_pEntityList = (CBaseEntityList *)gamehelpers->GetGlobalEntityList();
if(!CommandInitialize())
{
g_pSM->LogError(myself, "Command failed to Initialize. Server may Crash!");
return false;
}
if(!g_helpfunc.Initialize())
{
g_pSM->LogError(myself, "Helper failed to Initialize. Server may Crash!");
return false;
}
//sharesys->AddNatives(myself, g_MonsterNatives);
return true;
}
void Monster::SDK_OnUnload()
{
if(g_pGameConf != NULL)
{
gameconfs->CloseGameConfigFile(g_pGameConf);
g_pGameConf = NULL;
}
}
void Monster::SDK_OnAllLoaded()
{
}
bool Monster::QueryRunning(char *error, size_t maxlength)
{
return true;
}
bool Monster::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
CreateInterfaceFn appSystemFactory = ismm->GetEngineFactory();
ConnectTier1Libraries(&appSystemFactory, 1);
ConnectTier3Libraries(&appSystemFactory, 1);
MathLib_Init(2.2f, 2.2f, 0.0f, 2);
gpGlobals = ismm->GetCGlobals();
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, netstringtables, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
GET_V_IFACE_CURRENT(GetEngineFactory, engsound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
GET_V_IFACE_CURRENT(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
GET_V_IFACE_CURRENT(GetEngineFactory, enginerandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, staticpropmgr, IStaticPropMgrServer, INTERFACEVERSION_STATICPROPMGR_SERVER);
GET_V_IFACE_CURRENT(GetEngineFactory, modelinfo, IVModelInfo, VMODELINFO_SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, partition, ISpatialPartition, INTERFACEVERSION_SPATIALPARTITION);
GET_V_IFACE_CURRENT(GetPhysicsFactory, physprops, IPhysicsSurfaceProps, VPHYSICS_SURFACEPROPS_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, soundemitterbase, ISoundEmitterSystemBase, SOUNDEMITTERSYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetPhysicsFactory, physcollision, IPhysicsCollision, VPHYSICS_COLLISION_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetServerFactory, g_pEffects, IEffects, IEFFECTS_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetPhysicsFactory, iphysics, IPhysics, VPHYSICS_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, mdlcache, IMDLCache, MDLCACHE_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetServerFactory, g_pGameMovement, IGameMovement, INTERFACENAME_GAMEMOVEMENT);
GET_V_IFACE_ANY(GetServerFactory, servertools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, scenefilecache, ISceneFileCache, SCENE_FILE_CACHE_INTERFACE_VERSION);
g_pCVar = icvar;
ConVar_Register(0, this);
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &Monster::ServerActivate, true);
SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverclients, this, &Monster::SetCommandClient, true);
IGameSystem::InitAllSystems();
return true;
}
bool Monster::RegisterConCommandBase(ConCommandBase *pCommand)
{
META_REGCVAR(pCommand);
return true;
}
bool Monster::SDK_OnMetamodUnload(char *error, size_t maxlength)
{
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &Monster::ServerActivate, true);
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverclients, this, &Monster::SetCommandClient, true);
IGameSystem::SDKShutdownAllSystems();
GetEntityManager()->Shutdown();
DisconnectTier1Libraries();
DisconnectTier3Libraries();
return true;
}
void Monster::Precache()
{
g_sModelIndexSmoke = engine->PrecacheModel("sprites/steam1.vmt",true);
g_sModelIndexBubbles = engine->PrecacheModel("sprites/bubble.vmt",true);
soundemitterbase->AddSoundOverrides("scripts/sm_monster/game_sounds_BaseNpc.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_headcrab.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_fastheadcrab.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_blackheadcrab.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_zombie.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_fastzombie.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_poisonzombie.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_manhack.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_antlionguard.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_antlionguard_episodic2.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_antlionguard_episodic.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_stalker.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_antlion.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/game_sounds_weapons.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/game_sounds_items.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_vortigaunt.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_rollermine.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_antlion_episodic.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_combine_cannon.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_env_headcrabcanister.txt");
soundemitterbase->AddSoundOverrides("scripts/sm_monster/npc_sounds_turret.txt");
}
void Monster::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
gMaxClients = clientMax;
RETURN_META(MRES_IGNORED);
}
void Monster::SetCommandClient( int cmd )
{
gCmdIndex = cmd + 1;
}
int Monster::GetCommandClient()
{
return gCmdIndex;
}
int Monster::GetMaxClients()
{
return gMaxClients;
}