-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
174 lines (153 loc) · 4.98 KB
/
main.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
#include "precompiled.h"
edict_t *g_pEdicts;
playermove_t *g_pMove;
char g_szMapName[32] = "";
void OnAmxxAttach()
{
// initialize API
api_cfg.Init();
g_pEdicts = g_engfuncs.pfnPEntityOfEntIndex(0);
// If AMXX_Attach been called in a first the event Spawn
if (g_pEdicts)
{
// save true mapname
strncpy(g_szMapName, STRING(gpGlobals->mapname), sizeof(g_szMapName) - 1);
g_szMapName[sizeof(g_szMapName) - 1] = '\0';
}
}
bool OnMetaAttach()
{
#ifndef WITHOUT_SQL
g_mysql_mngr.start_main();
#endif
return true;
}
void OnMetaDetach()
{
// clear all hooks?
// g_hookManager.Clear();
if (api_cfg.hasReGameDLL())
{
g_ReGameHookchains->InstallGameRules()->unregisterHook(&InstallGameRules);
}
}
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
{
SERVER_PRINT("[DEBUG] SERVER_ACTIVATED\n");
#ifndef WITHOUT_SQL
g_mysql_mngr.start();
#endif
r_bMapHasBuyZone = g_Tries.entities.find("func_buyzone") != g_Tries.entities.end();
g_RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_RH);
g_RehldsHookchains->CreateFakeClient()->registerHook(CreateFakeClient_RH);
g_RehldsHookchains->ExecuteServerStringCmd()->registerHook(R_ExecuteServerStringCmd);
g_ReGameHookchains->CBasePlayer_Killed()->registerHook(CBasePlayer_Killed_RG);
g_ReGameHookchains->CSGameRules_CheckMapConditions()->registerHook(CSGameRules_CheckMapConditions_RG);
g_ReGameHookchains->CBasePlayer_AddPlayerItem()->registerHook(CBasePlayer_AddPlayerItem_RG);
g_ReGameHookchains->CBasePlayer_RemovePlayerItem()->registerHook(CBasePlayer_RemovePlayerItem_RG);
g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(CBasePlayer_Spawn_RG);
// g_ReGameHookchains->CreateWeaponBox()->registerHook(CreateWeaponBox_RG);
SET_META_RESULT(MRES_IGNORED);
}
void ServerDeactivate_Post()
{
SERVER_PRINT("[DEBUG] SERVER_DEACTIVATED\n");
#ifndef WITHOUT_SQL
g_mysql_mngr.stop();
g_mysql_mngr.close_all();
#endif
g_cvar_mngr.clear();
g_pEdicts = nullptr;
api_cfg.ServerDeactivate();
// g_hookManager.Clear();
g_pFunctionTable->pfnSpawn = DispatchSpawn;
g_pFunctionTable->pfnKeyValue = KeyValue;
g_RehldsHookchains->SV_DropClient()->unregisterHook(SV_DropClient_RH);
g_RehldsHookchains->CreateFakeClient()->unregisterHook(CreateFakeClient_RH);
g_RehldsHookchains->ExecuteServerStringCmd()->unregisterHook(R_ExecuteServerStringCmd);
g_ReGameHookchains->CBasePlayer_Killed()->unregisterHook(CBasePlayer_Killed_RG);
g_ReGameHookchains->CSGameRules_CheckMapConditions()->unregisterHook(CSGameRules_CheckMapConditions_RG);
g_ReGameHookchains->CBasePlayer_AddPlayerItem()->unregisterHook(CBasePlayer_AddPlayerItem_RG);
g_ReGameHookchains->CBasePlayer_RemovePlayerItem()->unregisterHook(CBasePlayer_RemovePlayerItem_RG);
g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(CBasePlayer_Spawn_RG);
// g_ReGameHookchains->CreateWeaponBox()->unregisterHook(CreateWeaponBox_RG);
// CLEAR TRIES
r_bMapHasBuyZone = false;
memset(g_Clients, 0, sizeof(g_Clients));
memset(g_PlayersNum, 0, sizeof(g_PlayersNum));
g_Tries.authids.clear();
g_Tries.classnames.clear();
g_Tries.entities.clear();
g_Tries.names.clear();
g_Tries.wp_entities.clear();
for (int i_i = 0; i_i < MAX_PLAYERS + 1; i_i++)
g_Tries.player_entities[i_i].clear();
SET_META_RESULT(MRES_IGNORED);
}
void KeyValue(edict_t *pentKeyvalue, KeyValueData *pkvd)
{
// Get the first edict worldspawn
if (FClassnameIs(pentKeyvalue, "worldspawn"))
{
// Save true mapname
strncpy(g_szMapName, STRING(gpGlobals->mapname), sizeof(g_szMapName) - 1);
g_szMapName[sizeof(g_szMapName) - 1] = '\0';
g_pEdicts = pentKeyvalue;
g_pFunctionTable->pfnKeyValue = nullptr;
}
SET_META_RESULT(MRES_IGNORED);
}
CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain)
{
auto gamerules = chain->callNext();
// Safe check CGameRules API interface version
if (!g_ReGameApi->BGetIGameRules(GAMERULES_API_INTERFACE_VERSION))
{
api_cfg.FailedReGameDllAPI();
UTIL_ServerPrint("[%s]: Interface CGameRules API version '%s' not found.\n", Plugin_info.logtag, GAMERULES_API_INTERFACE_VERSION);
}
else
g_pGameRules = gamerules;
return gamerules;
}
int DispatchSpawn(edict_t *pEntity)
{
g_pEdicts = g_engfuncs.pfnPEntityOfEntIndex(0);
if (api_cfg.hasReGameDLL())
g_pMove = g_ReGameApi->GetPlayerMove();
RETURN_META_VALUE(MRES_IGNORED, 0);
}
void ResetGlobalState()
{
// restore mapname
if (strcmp(g_RehldsData->GetName(), g_szMapName) != 0)
{
g_RehldsData->SetName(g_szMapName);
g_pFunctionTable->pfnResetGlobalState = nullptr;
}
SET_META_RESULT(MRES_IGNORED);
}
void OnFreeEntPrivateData(edict_t *pEdict)
{
CBaseEntity *pEntity = getPrivate<CBaseEntity>(pEdict);
if (pEntity)
Free_EntPrivateData(pEdict); // RefsAPI
SET_META_RESULT(MRES_IGNORED);
}
CTempStrings::CTempStrings()
{
m_current = 0;
}
char *CTempStrings::push(AMX *amx)
{
if (m_current == STRINGS_MAX)
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "Temp strings limit exceeded, contact reapi authors");
return nullptr;
}
return m_strings[m_current++];
}
void CTempStrings::pop(size_t count)
{
m_current -= count;
}