-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta_api.cpp
458 lines (384 loc) · 11.5 KB
/
meta_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
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// CSX Module
//
#include "amxxmodule.h"
#include "rank.h"
funEventCall modMsgsEnd[MAX_REG_MSGS];
funEventCall modMsgs[MAX_REG_MSGS];
void (*function)(void*);
void (*endfunction)(void*);
CPlayer players[33];
CPlayer* mPlayer;
int mPlayerIndex;
int mState;
RankSystem g_rank;
Stats null;
Grenades g_grenades;
int iFGrenade;
int iFDeath;
int iFDamage;
int iFBPlanted;
int iFBDefused;
int iFBPlanting;
int iFBDefusing;
int iFBExplode;
int g_bombAnnounce;
int g_Planter;
int g_Defuser;
bool rankBots;
int gmsgCurWeapon;
int gmsgDeathMsg;
int gmsgDamage;
int gmsgDamageEnd;
int gmsgWeaponList;
int gmsgResetHUD;
int gmsgAmmoX;
int gmsgScoreInfo;
int gmsgAmmoPickup;
int gmsgSendAudio;
int gmsgTextMsg;
int gmsgBarTime;
int g_CurrentMsg;
cvar_t init_csstats_maxsize ={"csstats_maxsize","9000", 0 , 9000.0 };
cvar_t init_csstats_reset ={"csstats_reset","0"};
cvar_t init_csstats_rank ={"csstats_rank","1"};
cvar_t *csstats_maxsize;
cvar_t *csstats_reset;
cvar_t *csstats_rank;
cvar_t* csstats_rankbots;
cvar_t* csstats_pause;
cvar_t init_csstats_rankbots ={"csstats_rankbots","0"};
cvar_t init_csstats_pause = {"csstats_pause","0"};
struct sUserMsg
{
const char* name;
int* id;
funEventCall func;
bool endmsg;
} g_user_msg[] = {
{"CurWeapon", &gmsgCurWeapon, Client_CurWeapon, false},
{"Damage", &gmsgDamage, Client_Damage, false},
{"Damage", &gmsgDamageEnd, Client_Damage_End, true},
{"WeaponList", &gmsgWeaponList, Client_WeaponList, false},
{"ResetHUD", &gmsgResetHUD, Client_ResetHUD, true},
{"AmmoX", &gmsgAmmoX, Client_AmmoX, false},
{"ScoreInfo", &gmsgScoreInfo, Client_ScoreInfo, false},
{"AmmoPickup", &gmsgAmmoPickup, Client_AmmoPickup, false},
{"SendAudio", &gmsgSendAudio, Client_SendAudio, false},
{"TextMsg", &gmsgTextMsg, Client_TextMsg, false},
{"BarTime", &gmsgBarTime, Client_BarTime, false},
{"DeathMsg", &gmsgDeathMsg, Client_DeathMsg, false},
{0, 0, 0, false}
};
int RegUserMsg_Post(const char *pszName, int iSize)
{
for (int i = 0; g_user_msg[ i ].name; ++i )
{
if ( !*g_user_msg[i].id && strcmp( g_user_msg[ i ].name , pszName ) == 0 )
{
int id = META_RESULT_ORIG_RET( int );
*g_user_msg[ i ].id = id;
if ( g_user_msg[ i ].endmsg )
modMsgsEnd[ id ] = g_user_msg[ i ].func;
else
modMsgs[ id ] = g_user_msg[ i ].func;
//break;
}
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
const char* get_localinfo( const char* name , const char* def )
{
const char* b = LOCALINFO( (char*)name );
if (((b==0)||(*b==0)) && def )
SET_LOCALINFO((char*)name,(char*)(b = def) );
return b;
}
static bool ClientKill_wasAlive;
void ClientKill(edict_t *pEntity)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
ClientKill_wasAlive = pPlayer->IsAlive();
RETURN_META(MRES_IGNORED);
}
void ClientKill_Post(edict_t *pEntity)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
if (ClientKill_wasAlive && !pPlayer->IsAlive())
{
MF_ExecuteForward(iFDamage, static_cast<cell>(pPlayer->index), static_cast<cell>(pPlayer->index),
static_cast<cell>(0), static_cast<cell>(0), static_cast<cell>(0), static_cast<cell>(0)); // he would
pPlayer->saveKill(pPlayer, 0, 0, 0);
MF_ExecuteForward(iFDeath, static_cast<cell>(pPlayer->index), static_cast<cell>(pPlayer->index),
static_cast<cell>(0), static_cast<cell>(0), static_cast<cell>(0));
}
RETURN_META(MRES_IGNORED);
}
void ServerActivate_Post( edict_t *pEdictList, int edictCount, int clientMax ){
rankBots = (int)csstats_rankbots->value ? true:false;
for( int i = 1; i <= gpGlobals->maxClients; ++i)
GET_PLAYER_POINTER_I(i)->Init( i , pEdictList + i );
RETURN_META(MRES_IGNORED);
}
void PlayerPreThink_Post( edict_t *pEntity ) {
if ( !isModuleActive() )
{
RETURN_META(MRES_IGNORED);
}
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
if (pPlayer->clearStats && pPlayer->clearStats < gpGlobals->time ){
if ( !ignoreBots(pEntity) ){
pPlayer->clearStats = 0.0f;
if (pPlayer->rank)
pPlayer->rank->updatePosition( &pPlayer->life );
pPlayer->restartStats(false);
}
}
RETURN_META(MRES_IGNORED);
}
void ServerDeactivate()
{
int i;
for( i = 1; i <= gpGlobals->maxClients; ++i)
{
GET_PLAYER_POINTER_I(i)->Disconnect();
}
if (static_cast<int>(csstats_maxsize->value) <= 0 || g_rank.getRankNum() >= static_cast<int>(csstats_maxsize->value) || static_cast<int>(csstats_reset->value) != 0)
{
CVAR_SET_FLOAT("csstats_reset", 0.0f);
g_rank.clear(); // clear before save to file
}
g_rank.saveRank( MF_BuildPathname("%s",get_localinfo("csstats")) );
// clear custom weapons info
for ( i=MAX_WEAPONS;i<MAX_WEAPONS+MAX_CWEAPONS;i++)
weaponData[i].used = false;
RETURN_META(MRES_IGNORED);
}
BOOL ClientConnect_Post( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
pPlayer->Connect(pszAddress);
RETURN_META_VALUE(MRES_IGNORED, TRUE);
}
void ClientDisconnect( edict_t *pEntity )
{
GET_PLAYER_POINTER(pEntity)->Disconnect();
RETURN_META(MRES_IGNORED);
}
void ClientPutInServer_Post( edict_t *pEntity )
{
GET_PLAYER_POINTER(pEntity)->PutInServer();
RETURN_META(MRES_IGNORED);
}
void ClientUserInfoChanged_Post( edict_t *pEntity, char *infobuffer ) {
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
if (pPlayer->pEdict == NULL)
{
pPlayer->Init(ENTINDEX(pEntity), pEntity);
}
const char* name = INFOKEY_VALUE(infobuffer,"name");
const char* oldname = STRING(pEntity->v.netname);
if ( pPlayer->rank ){
if ( strcmp(oldname,name) != 0 ) {
if ((int)csstats_rank->value == 0)
{
pPlayer->rank = g_rank.findEntryInRank( name, name );
if ( !pPlayer->rank )
{
pPlayer->rank = g_rank.newEntryInRank( name, name );
if (pPlayer->rank)
pPlayer->rank->updatePosition(&null);
}
}
else
pPlayer->rank->setName( name );
}
}
else if ( pPlayer->IsBot() ) {
pPlayer->Connect( "127.0.0.1" );
pPlayer->PutInServer();
}
RETURN_META(MRES_IGNORED);
}
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) {
if (ed){
mPlayerIndex = ENTINDEX(ed);
mPlayer = GET_PLAYER_POINTER_I(mPlayerIndex);
} else {
mPlayerIndex = 0;
mPlayer = 0;
}
mState = 0;
g_CurrentMsg = msg_type;
if ( g_CurrentMsg < 0 || g_CurrentMsg >= MAX_REG_MSGS )
g_CurrentMsg = 0;
function=modMsgs[g_CurrentMsg];
endfunction=modMsgsEnd[g_CurrentMsg];
RETURN_META(MRES_IGNORED);
}
void MessageEnd_Post(void) {
if (endfunction) (*endfunction)(NULL);
RETURN_META(MRES_IGNORED);
}
void WriteByte_Post(int iValue) {
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
void WriteChar_Post(int iValue) {
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
void WriteShort_Post(int iValue) {
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
void WriteLong_Post(int iValue) {
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
void WriteAngle_Post(float flValue) {
if (function) (*function)((void *)&flValue);
RETURN_META(MRES_IGNORED);
}
void WriteCoord_Post(float flValue) {
if (function) (*function)((void *)&flValue);
RETURN_META(MRES_IGNORED);
}
void WriteString_Post(const char *sz) {
if (function) (*function)((void *)sz);
RETURN_META(MRES_IGNORED);
}
void WriteEntity_Post(int iValue) {
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
void StartFrame_Post(){
if (g_bombAnnounce){
switch (g_bombAnnounce){
case BOMB_PLANTING:
MF_ExecuteForward( iFBPlanting, static_cast<cell>(g_Planter) );
break;
case BOMB_PLANTED:
MF_ExecuteForward( iFBPlanted, static_cast<cell>(g_Planter) );
break;
case BOMB_EXPLODE:
MF_ExecuteForward( iFBExplode, static_cast<cell>(g_Planter), static_cast<cell>(g_Defuser) );
break;
case BOMB_DEFUSING:
MF_ExecuteForward( iFBDefusing, static_cast<cell>(g_Defuser) );
break;
case BOMB_DEFUSED:
MF_ExecuteForward( iFBDefused, static_cast<cell>(g_Defuser) );
break;
}
g_bombAnnounce = 0;
}
RETURN_META(MRES_IGNORED);
}
void SetModel_Post(edict_t *e, const char *m){
if ( !isModuleActive() )
{
RETURN_META(MRES_IGNORED);
}
if ( e->v.owner && m[7]=='w' && m[8]=='_' ){
int w_id = 0;
CPlayer *pPlayer = GET_PLAYER_POINTER(e->v.owner);
switch(m[9]){
case 'h':
w_id = CSW_HEGRENADE;
g_grenades.put(e, 2.0, 4, pPlayer);
pPlayer->saveShot(CSW_HEGRENADE);
break;
case 'f':
if (m[10]=='l') w_id = CSW_FLASHBANG;
break;
case 's':
if (m[10]=='m') w_id = CSW_SMOKEGRENADE;
break;
}
if ( w_id )
MF_ExecuteForward( iFGrenade, static_cast<cell>(pPlayer->index),
static_cast<cell>(ENTINDEX(e)), static_cast<cell>(w_id));
}
RETURN_META(MRES_IGNORED);
}
void EmitSound_Post(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch) {
if (sample[0]=='w'&&sample[1]=='e'&&sample[8]=='k'&&sample[9]=='n'&&sample[14]!='d'){
CPlayer*pPlayer = GET_PLAYER_POINTER(entity);
pPlayer->saveShot(pPlayer->current);
}
RETURN_META(MRES_IGNORED);
}
void TraceLine_Post(const float *v1, const float *v2, int fNoMonsters, edict_t *e, TraceResult *ptr)
{
if (ptr->pHit && (ptr->pHit->v.flags & (FL_CLIENT|FL_FAKECLIENT))
&& e
&& (e->v.flags & (FL_CLIENT|FL_FAKECLIENT))
&& ptr->iHitgroup)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(e);
if (pPlayer->current != CSW_KNIFE)
{
pPlayer->aiming = ptr->iHitgroup;
}
}
RETURN_META(MRES_IGNORED);
}
void OnMetaAttach() {
CVAR_REGISTER (&init_csstats_maxsize);
CVAR_REGISTER (&init_csstats_reset);
CVAR_REGISTER (&init_csstats_rank);
csstats_maxsize=CVAR_GET_POINTER(init_csstats_maxsize.name);
csstats_reset=CVAR_GET_POINTER(init_csstats_reset.name);
csstats_rank=CVAR_GET_POINTER(init_csstats_rank.name);
CVAR_REGISTER (&init_csstats_rankbots);
CVAR_REGISTER (&init_csstats_pause);
csstats_rankbots = CVAR_GET_POINTER(init_csstats_rankbots.name);
csstats_pause = CVAR_GET_POINTER(init_csstats_pause.name);
}
int AmxxCheckGame(const char *game)
{
if (strcasecmp(game, "cstrike") == 0 ||
strcasecmp(game, "czero") == 0)
{
return AMXX_GAME_OK;
}
return AMXX_GAME_BAD;
}
void OnAmxxAttach(){
MF_AddNatives(stats_Natives);
const char* path = get_localinfo("csstats_score");
if ( path && *path )
{
char error[128];
g_rank.loadCalc( MF_BuildPathname("%s",path) , error, sizeof(error));
}
if ( !g_rank.begin() )
{
g_rank.loadRank( MF_BuildPathname("%s",
get_localinfo("csstats") ) );
}
}
void OnAmxxDetach() {
g_grenades.clear();
g_rank.clear();
g_rank.unloadCalc();
}
void OnPluginsLoaded(){
iFDeath = MF_RegisterForward("client_death",ET_IGNORE,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_DONE);
iFDamage = MF_RegisterForward("client_damage",ET_IGNORE,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_DONE);
iFBPlanted = MF_RegisterForward("bomb_planted",ET_IGNORE,FP_CELL,FP_DONE);
iFBDefused = MF_RegisterForward("bomb_defused",ET_IGNORE,FP_CELL,FP_DONE);
iFBPlanting = MF_RegisterForward("bomb_planting",ET_IGNORE,FP_CELL,FP_DONE);
iFBDefusing = MF_RegisterForward("bomb_defusing",ET_IGNORE,FP_CELL,FP_DONE);
iFBExplode = MF_RegisterForward("bomb_explode",ET_IGNORE,FP_CELL,FP_CELL,FP_DONE);
iFGrenade = MF_RegisterForward("grenade_throw",ET_IGNORE,FP_CELL,FP_CELL,FP_CELL,FP_DONE);
}