-
Notifications
You must be signed in to change notification settings - Fork 32
/
l4dtoolz_mm.cpp
332 lines (288 loc) · 8.67 KB
/
l4dtoolz_mm.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
#include "l4dtoolz_mm.h"
#include "signature.h"
#include "game_signature.h"
l4dtoolz g_l4dtoolz;
IVEngineServer* engine = NULL;
IServerPluginCallbacks* vsp_callbacks = NULL;
ICvar* icvar = NULL;
#ifdef L4D1
void* l4dtoolz::max_players_friend_lobby = NULL;
void* l4dtoolz::chuman_limit = NULL;
#endif
void* l4dtoolz::max_players_connect = NULL;
void* l4dtoolz::max_players_server_browser = NULL;
void* l4dtoolz::lobby_sux_ptr = NULL;
void* l4dtoolz::tmp_player = NULL;
void* l4dtoolz::tmp_player2 = NULL;
void* l4dtoolz::unreserved_ptr = NULL;
void* l4dtoolz::lobby_match_ptr = NULL;
ConVar sv_maxplayers("sv_maxplayers", "-1", 0, "Max Human Players", true, -1, true, 32, l4dtoolz::OnChangeMaxplayers);
#ifdef L4D1
ConVar sv_removehumanlimit("sv_removehumanlimit", "0", 0, "Remove Human limit reached kick", true, 0, true, 1, l4dtoolz::OnChangeRemovehumanlimit);
#endif
ConVar L4DToolZ("L4DToolZ", "",0,"L4DToolZ Author",l4dtoolz::OnChangeIvailosp);
ConVar sv_force_unreserved("sv_force_unreserved", "0", 0, "Disallow lobby reservation cookie", true, 0, true, 1, l4dtoolz::OnChangeUnreserved);
void l4dtoolz::OnChangeMaxplayers ( IConVar *var, const char *pOldValue, float flOldValue )
{
int new_value = ((ConVar*)var)->GetInt();
int old_value = atoi(pOldValue);
#ifdef L4D1
if (max_players_friend_lobby == NULL || max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
#else
if (max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
#endif
Msg("sv_maxplayers init error\n");
return;
}
if(new_value != old_value) {
if(new_value >= 0) {
#ifdef L4D1
max_players_new[4] = friends_lobby_new[3] = server_bplayers_new[3] = new_value;
#else
max_players_new[4] = server_bplayers_new[3] = (unsigned char)new_value;
#endif
if(lobby_match_ptr) {
lobby_match_new[2] = (unsigned char)new_value;
write_signature(lobby_match_ptr, lobby_match_new);
} else {
Msg("sv_maxplayers MS init error\n");
}
#ifdef L4D1
write_signature(max_players_friend_lobby, friends_lobby_new);
#endif
write_signature(max_players_connect, max_players_new);
write_signature(lobby_sux_ptr, lobby_sux_new);
write_signature(max_players_server_browser, server_bplayers_new);
} else {
#ifdef L4D1
write_signature(max_players_friend_lobby, friends_lobby_org);
#endif
write_signature(max_players_connect, max_players_org);
write_signature(lobby_sux_ptr, lobby_sux_org);
write_signature(max_players_server_browser, server_bplayers_org);
if(lobby_match_ptr)
write_signature(lobby_match_ptr, lobby_match_org);
}
}
}
#ifdef L4D1
void l4dtoolz::OnChangeRemovehumanlimit ( IConVar *var, const char *pOldValue, float flOldValue )
{
int new_value = ((ConVar*)var)->GetInt();
int old_value = atoi(pOldValue);
if(chuman_limit == NULL) {
Msg( "sv_removehumanlimit init error\n");
return;
}
if(new_value != old_value) {
if(new_value == 1) {
write_signature(chuman_limit, human_limit_new);
}else{
write_signature(chuman_limit, human_limit_org);
}
}
}
#endif
void l4dtoolz::OnChangeIvailosp ( IConVar *var, const char *pOldValue, float flOldValue )
{
if(tmp_player == NULL || tmp_player2 == NULL) {
return;
}
write_signature(tmp_player, players_org);
free(players_org);
players_org = NULL;
write_signature(tmp_player2, players_org2);
free(players_org2);
players_org2 = NULL;
}
void l4dtoolz::OnChangeUnreserved ( IConVar *var, const char *pOldValue, float flOldValue )
{
int new_value = ((ConVar*)var)->GetInt();
int old_value = atoi(pOldValue);
if(unreserved_ptr == NULL ) {
Msg("unreserved_ptr init error\n");
return;
}
if(new_value != old_value) {
if(new_value == 1) {
write_signature(unreserved_ptr, unreserved_new);
engine->ServerCommand("sv_allow_lobby_connect_only 0\n");
} else {
write_signature(unreserved_ptr, unreserved_org);
}
}
}
class BaseAccessor : public IConCommandBaseAccessor
{
public:
bool RegisterConCommandBase(ConCommandBase *pCommandBase)
{
return META_REGCVAR(pCommandBase);
}
} s_BaseAccessor;
PLUGIN_EXPOSE(l4dtoolz, g_l4dtoolz);
bool l4dtoolz::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
#if defined METAMOD_PLAPI_VERSION
if ((vsp_callbacks = ismm->GetVSPInfo(NULL)) == NULL)
#endif
{
ismm->AddListener(this, this);
ismm->EnableVSPListener();
}
#if !defined METAMOD_PLAPI_VERSION
m_EngineCC = SH_GET_CALLCLASS(engine);
#endif
#if SOURCE_ENGINE >= SE_ORANGEBOX
g_pCVar = icvar;
ConVar_Register(0, &s_BaseAccessor);
#else
ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
#endif
struct base_addr_t base_addr;
base_addr.addr = NULL;
base_addr.len = 0;
find_base_from_list(matchmaking_dll, &base_addr);
if(!lobby_match_ptr) {
lobby_match_ptr = find_signature(lobby_match, &base_addr, 1);
get_original_signature(lobby_match_ptr, lobby_match_new, lobby_match_org);
}
find_base_from_list(engine_dll, &base_addr);
#ifdef L4D1
if(!max_players_friend_lobby) {
max_players_friend_lobby = find_signature(friends_lobby, &base_addr, 0);
get_original_signature(max_players_friend_lobby, friends_lobby_new, friends_lobby_org);
}
#endif
if(!max_players_connect) {
max_players_connect = find_signature(max_players, &base_addr, 0);
get_original_signature(max_players_connect, max_players_new, max_players_org);
}
if(!lobby_sux_ptr) {
#ifdef WIN32
lobby_sux_ptr = max_players_connect;
#else
lobby_sux_ptr = find_signature(lobby_sux, &base_addr, 0);
#endif
get_original_signature(lobby_sux_ptr, lobby_sux_new, lobby_sux_org);
}
#ifdef L4D1
#ifdef WIN32
if(!max_players_server_browser) {
max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
}
#endif
#endif
if(!tmp_player) {
tmp_player = find_signature(players, &base_addr, 0);
if(tmp_player) {
tmp_player2 = find_signature(players2, &base_addr, 0);
if(tmp_player2) {
get_original_signature(tmp_player, players_new, players_org);
write_signature(tmp_player, players_new);
get_original_signature(tmp_player2, players_new2, players_org2);
write_signature(tmp_player2, players_new2);
engine->ServerCommand("maxplayers 32\n");
engine->ServerCommand("L4DToolZ [email protected]\n");
}
}
}
if(!unreserved_ptr) {
unreserved_ptr = find_signature(unreserved, &base_addr, 0);
get_original_signature(unreserved_ptr, unreserved_new, unreserved_org);
}
find_base_from_list(server_dll, &base_addr);
#ifdef L4D1
if(!chuman_limit) {
chuman_limit = find_signature(human_limit, &base_addr, 0);
get_original_signature(chuman_limit, human_limit_new, human_limit_org);
}
#ifndef WIN32
if(!max_players_server_browser) {
max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
}
#endif
#else
if(!max_players_server_browser) {
max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
}
#endif
return true;
}
bool l4dtoolz::Unload(char *error, size_t maxlen)
{
#if !defined METAMOD_PLAPI_VERSION
SH_RELEASE_CALLCLASS(m_EngineCC);
#endif
#ifdef L4D1
write_signature(max_players_friend_lobby, friends_lobby_org);
write_signature(chuman_limit, human_limit_org);
free(friends_lobby_org);
free(human_limit_org);
#endif
write_signature(max_players_connect, max_players_org);
write_signature(lobby_sux_ptr, lobby_sux_org);
write_signature(max_players_server_browser, server_bplayers_org);
write_signature(unreserved_ptr, unreserved_org);
write_signature(lobby_match_ptr, lobby_match_org);
free(max_players_org);
free(lobby_sux_org);
free(server_bplayers_org);
free(unreserved_org);
free(lobby_match_org);
return true;
}
void l4dtoolz::OnVSPListening(IServerPluginCallbacks *iface)
{
vsp_callbacks = iface;
}
bool l4dtoolz::Pause(char *error, size_t maxlen)
{
return true;
}
bool l4dtoolz::Unpause(char *error, size_t maxlen)
{
return true;
}
const char *l4dtoolz::GetLicense()
{
return "";
}
const char *l4dtoolz::GetVersion()
{
#ifdef __GIT_VERSION
return __GIT_VERSION;
#else
return "1.0.0.9r1";
#endif
}
const char *l4dtoolz::GetDate()
{
return __DATE__;
}
const char *l4dtoolz::GetLogTag()
{
return "L4DToolZ";
}
const char *l4dtoolz::GetAuthor()
{
return "Ivailosp";
}
const char *l4dtoolz::GetDescription()
{
return "Ivailosp plugin";
}
const char *l4dtoolz::GetName()
{
return "L4DToolZ";
}
const char *l4dtoolz::GetURL()
{
return "n/a";
}