-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine_fix.sp
540 lines (484 loc) · 15.2 KB
/
engine_fix.sp
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define DEBUG 0
#define PLUGIN_VERSION "1.3"
#define FIRST_RESTORE_TIME 0.3
#define RESTORE_TIME 2.0
#define MAX_HEALTH_PER_RESTORE 10
#define MAX_HEALTH 100
#define CONSTANT_HEALTH 1
#define MAX_TEMP_HEALTH MAX_HEALTH - CONSTANT_HEALTH
bool g_bCvarWarnEnabled,
g_bTempWarnLock[MAXPLAYERS+1];
Handle g_hFixGlitchTimer[MAXPLAYERS+1],
g_hRestoreTimer[MAXPLAYERS+1];
int g_iCvarEngineFlags,
g_iHealthToRestore[MAXPLAYERS+1],
g_iLastKnownHealth[MAXPLAYERS+1];
float g_fCvarDecayRate;
ConVar hCvarDecayRate,
hCvarWarnEnabled,
hCvarEngineFlags;
enum
{
LadderSpeedGlitch = 1,
NoFallDamageBug,
HealthBoostGlitch
};
public Plugin myinfo =
{
name = "[L4D & L4D2] Engine Fix",
author = "raziEiL [disawar1]",
description = "Blocking ladder speed glitch, no fall damage bug, health boost glitch.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?p=1682064"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if (test != Engine_Left4Dead && test != Engine_Left4Dead2)
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
CreateConVar("engine_fix_version", PLUGIN_VERSION, "Engine Fix plugin version", FCVAR_NOTIFY | FCVAR_DONTRECORD);
hCvarWarnEnabled = CreateConVar("engine_warning", "0", "Display a warning message saying that player using expolit: 1=enable, 0=disable.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
hCvarEngineFlags = CreateConVar("engine_fix_flags", "14", "Enables what kind of exploit should be fixed/blocked. Flags (add together): 0=disable, 2=ladder speed glitch, 4=no fall damage bug, 8=health boost glitch.", FCVAR_NOTIFY, true, 0.0, true, 14.0);
hCvarDecayRate = FindConVar("pain_pills_decay_rate");
hCvarDecayRate.AddChangeHook(OnConvarChange);
GetCvars();
hCvarWarnEnabled.AddChangeHook(OnConvarChange);
hCvarEngineFlags.AddChangeHook(OnConvarChange);
AutoExecConfig(true, "engine_fix");
if (g_iCvarEngineFlags & (1 << HealthBoostGlitch))
EF_ToogleEvents(true);
#if DEBUG
RegConsoleCmd("DEBUG", CmdDebug);
#endif
}
void OnConvarChange(ConVar convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_fCvarDecayRate = hCvarDecayRate.FloatValue;
g_bCvarWarnEnabled = hCvarWarnEnabled.BoolValue;
g_iCvarEngineFlags = hCvarEngineFlags.IntValue;
EF_ToogleEvents(!!(g_iCvarEngineFlags & (1 << HealthBoostGlitch)));
}
void EF_ToogleEvents(bool bHook)
{
static bool bIsHooked;
if (!bIsHooked && bHook)
{
for (int i = 1; i <= MAXPLAYERS; i++)
EF_ClearAllVars(i);
HookEvent("round_start", EF_ev_RoundStart, EventHookMode_PostNoCopy);
HookEvent("pills_used", EF_ev_PillsUsed);
HookEvent("player_hurt", EF_ev_PlayerHurt);
HookEvent("heal_success", EF_ev_HealSuccess);
HookEvent("revive_success", EF_ev_HealSuccess);
HookEvent("player_incapacitated", EF_ev_HealSuccess);
bIsHooked = true;
}
else if (bIsHooked && !bHook)
{
UnhookEvent("round_start", EF_ev_RoundStart, EventHookMode_PostNoCopy);
UnhookEvent("pills_used", EF_ev_PillsUsed);
UnhookEvent("player_hurt", EF_ev_PlayerHurt);
UnhookEvent("heal_success", EF_ev_HealSuccess);
UnhookEvent("revive_success", EF_ev_HealSuccess);
UnhookEvent("player_incapacitated", EF_ev_HealSuccess);
bIsHooked = false;
}
}
/* +==========================================+
| LADDER GLITCH |
| NO FALL DMG GLITCH |
+==========================================+
*/
public Action OnPlayerRunCmd(int client, int &buttons)
{
if (g_iCvarEngineFlags && IsPlayerAlive(client) && !IsFakeClient(client))
{
if (g_iCvarEngineFlags & (1 << LadderSpeedGlitch) && GetEntityMoveType(client) == MOVETYPE_LADDER)
{
static int iUsingBug[MAXPLAYERS+1];
if (buttons & 8 || buttons & 16)
{
if (buttons & 512)
{
iUsingBug[client]++;
buttons &= ~IN_MOVELEFT;
}
if (buttons & 1024)
{
iUsingBug[client]++;
buttons &= ~IN_MOVERIGHT;
}
if (g_bCvarWarnEnabled && iUsingBug[client] > 48)
{
WarningsMsg(client, 1);
iUsingBug[client] = 0;
}
}
else
iUsingBug[client] = 0;
}
if (g_iCvarEngineFlags & (1 << NoFallDamageBug) && GetClientTeam(client) == 2 && IsFallDamage(client) && buttons & IN_USE){
buttons &= ~IN_USE;
if (g_bCvarWarnEnabled && !g_bTempWarnLock[client])
{
g_bTempWarnLock[client] = true;
WarningsMsg(client, 2);
CreateTimer(5.0, EF_t_UnlockWarnMsg, client);
}
}
}
return Plugin_Continue;
}
Action EF_t_UnlockWarnMsg(Handle timer, any client)
{
g_bTempWarnLock[client] = false;
return Plugin_Stop;
}
bool IsFallDamage(int client)
{
return GetEntPropFloat(client, Prop_Send, "m_flFallVelocity") > 440;
}
/* +==========================================+
| DROWN GLITCH |
+==========================================+
*/
public void OnClientDisconnect(int client)
{
if (client && g_iCvarEngineFlags & (1 << HealthBoostGlitch))
EF_ClearAllVars(client);
}
void EF_ev_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
EF_ClearAllVars(i);
if (IsClientInGame(i) && IsDrownPropNotEqual(i))
ForceEqualDrownProp(i);
}
}
void EF_ev_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
if (event.GetInt("type") & DMG_DROWN)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (IsIncapacitated(client))
return;
if (event.GetInt("health") == CONSTANT_HEALTH)
{
int damage = event.GetInt("dmg_health");
if (g_iLastKnownHealth[client] && damage >= g_iLastKnownHealth[client])
{
damage -= g_iLastKnownHealth[client];
g_iLastKnownHealth[client] -= CONSTANT_HEALTH;
}
if (g_iHealthToRestore[client] < 0)
g_iHealthToRestore[client] = 0;
if (!g_iHealthToRestore[client])
{
EF_KillRestoreTimer(client);
CreateTimer(FIRST_RESTORE_TIME, EF_t_CheckRestoring, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
g_iHealthToRestore[client] += damage;
#if DEBUG
PrintToChatAll("m_idrowndmg = %d, dmg = %d, temp hp to restote = %d", GetEntProp(client, Prop_Data, "m_idrowndmg"), damage, g_iHealthToRestore[client]);
#endif
DataPack hdataPack;
CreateDataTimer(0.1, EF_t_SetDrownDmg, hdataPack, TIMER_FLAG_NO_MAPCHANGE);
hdataPack.WriteCell(client);
hdataPack.WriteCell(GetEntProp(client, Prop_Data, "m_idrowndmg") + g_iLastKnownHealth[client]);
g_iLastKnownHealth[client] = 0;
}
else
g_iLastKnownHealth[client] = event.GetInt("health");
}
}
Action EF_t_SetDrownDmg(Handle timer, DataPack datapack)
{
datapack.Reset();
int client = datapack.ReadCell();
if (!IsSurvivor(client))
return Plugin_Stop;
int drowndmg = datapack.ReadCell();
SetEntProp(client, Prop_Data, "m_idrowndmg", drowndmg);
return Plugin_Stop;
}
Action EF_t_CheckRestoring(Handle timer, int client)
{
if (g_iHealthToRestore[client] <= 0 || !IsSurvivor(client))
{
g_iHealthToRestore[client] = 0;
return Plugin_Stop;
}
if (IsUnderWater(client))
return Plugin_Continue;
float fHealthToRestore = float(GetEntProp(client, Prop_Data, "m_idrowndmg") - GetEntProp(client, Prop_Data, "m_idrownrestored"));
if (fHealthToRestore <= 0)
{
#if DEBUG
PrintToChatAll("restoring started (player using glitch while have 1-10hp");
#endif
g_hRestoreTimer[client] = CreateTimer(RESTORE_TIME, EF_t_RestoreTempHealth, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
int iRestoreCount = RoundToCeil(fHealthToRestore / MAX_HEALTH_PER_RESTORE);
float fRestoreTimeEnd = RESTORE_TIME * float(iRestoreCount);
#if DEBUG
PrintToChatAll("restore count = %d (beginning in %.0f sec.)", iRestoreCount, fRestoreTimeEnd);
#endif
CreateTimer(fRestoreTimeEnd, EF_t_StartRestoreTempHealth, client, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
Action EF_t_StartRestoreTempHealth(Handle timer, int client)
{
if (g_iHealthToRestore[client] <= 0 || !IsSurvivor(client))
return Plugin_Stop;
#if DEBUG
PrintToChatAll("restoring started");
#endif
g_hRestoreTimer[client] = CreateTimer(RESTORE_TIME, EF_t_RestoreTempHealth, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
Action EF_t_RestoreTempHealth(Handle timer, int client)
{
if (g_iHealthToRestore[client] <= 0 || !IsSurvivor(client))
{
EF_ClearVars(client);
return Plugin_Stop;
}
if (!IsUnderWater(client) && !IsDrownPropNotEqual(client))
{
float fTemp = GetTempHealth(client);
int iLimit = MAX_TEMP_HEALTH - (GetClientHealth(client) + RoundToFloor(fTemp));
int iTempToRestore = g_iHealthToRestore[client] >= MAX_HEALTH_PER_RESTORE ? MAX_HEALTH_PER_RESTORE : g_iHealthToRestore[client];
if (iTempToRestore > iLimit)
{
#if DEBUG
PrintToChatAll("temp health limit is exceeded");
#endif
iTempToRestore = iLimit;
g_iHealthToRestore[client] = 0;
if (iTempToRestore <= 0)
return Plugin_Continue;
}
SetTempHealth(client, fTemp + iTempToRestore);
g_iHealthToRestore[client] -= MAX_HEALTH_PER_RESTORE;
EF_GlitchWarnFunc(client);
}
return Plugin_Continue;
}
void EF_ev_HealSuccess(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, StrEqual(name, "player_incapacitated") ? "userid" : "subject"));
if (IsDrownPropNotEqual(client))
{
#if DEBUG
PrintToChatAll("reset drownrestored prop %N", client);
#endif
EF_ClearVars(client);
ForceEqualDrownProp(client);
}
}
void EF_ev_PillsUsed(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (IsDrownPropNotEqual(client))
{
EF_KillFixGlitchTimer(client);
g_hFixGlitchTimer[client] = CreateTimer(0.0, EF_t_FixTempHpGlitch, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
}
Action EF_t_FixTempHpGlitch(Handle timer, int client)
{
if (IsSurvivor(client) && !IsIncapacitated(client))
{
float fTemp = GetTempHealth(client);
if (fTemp)
{
int iHealth = GetClientHealth(client);
if ((iHealth + RoundToFloor(fTemp)) > MAX_TEMP_HEALTH)
{
SetTempHealth(client, float(MAX_HEALTH - iHealth));
EF_GlitchWarnFunc(client);
#if DEBUG
PrintToChatAll("temp glitch fixed");
#endif
}
}
if (IsDrownPropNotEqual(client))
return Plugin_Continue;
}
#if DEBUG
PrintToChatAll("stopped temp glich fix timer");
#endif
g_hFixGlitchTimer[client] = null;
return Plugin_Stop;
}
void EF_GlitchWarnFunc(int client)
{
if (g_bCvarWarnEnabled && !g_bTempWarnLock[client])
{
g_bTempWarnLock[client] = true;
WarningsMsg(client, 3);
CreateTimer(15.0, EF_t_UnlockWarnMsg, client);
}
}
void EF_KillRestoreTimer(int client)
{
if (g_hRestoreTimer[client] != null)
{
#if DEBUG
PrintToChatAll("restoring stopped");
#endif
delete g_hRestoreTimer[client];
g_hRestoreTimer[client] = null;
}
}
void EF_KillFixGlitchTimer(int client)
{
if (g_hFixGlitchTimer[client] != null)
{
delete g_hFixGlitchTimer[client];
g_hFixGlitchTimer[client] = null;
}
}
void EF_ClearVars(int client)
{
EF_KillRestoreTimer(client);
g_iHealthToRestore[client] = 0;
g_iLastKnownHealth[client] = 0;
}
void EF_ClearAllVars(int client)
{
EF_ClearVars(client);
EF_KillFixGlitchTimer(client);
}
bool IsSurvivor(int client)
{
return IsClientInGame(client) && GetClientTeam(client) == 2 && IsPlayerAlive(client);
}
bool IsUnderWater(int client)
{
return GetEntProp(client, Prop_Send, "m_nWaterLevel") == 3;
}
bool IsIncapacitated(int client)
{
return GetEntProp(client, Prop_Send, "m_isIncapacitated") != 0;
}
bool IsDrownPropNotEqual(int client)
{
return GetEntProp(client, Prop_Data, "m_idrowndmg") != GetEntProp(client, Prop_Data, "m_idrownrestored");
}
void ForceEqualDrownProp(int client)
{
SetEntProp(client, Prop_Data, "m_idrownrestored", GetEntProp(client, Prop_Data, "m_idrowndmg"));
}
void SetTempHealth(int client, float health)
{
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", GetGameTime());
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", health);
}
// Code by SilverShot aka Silvers (Healing Gnome plugin https://forums.alliedmods.net/showthread.php?p=1658852)
float GetTempHealth(int client)
{
float fTempHealth = GetEntPropFloat(client, Prop_Send, "m_healthBuffer");
fTempHealth -= (GetGameTime() - GetEntPropFloat(client, Prop_Send, "m_healthBufferTime")) * g_fCvarDecayRate;
return fTempHealth < 0.0 ? 0.0 : fTempHealth;
}
void WarningsMsg(int client, int msg)
{
char STEAM_ID[32];
GetClientAuthId(client, AuthId_Steam2, STEAM_ID, sizeof(STEAM_ID));
switch (msg)
{
case 1:
PrintToChatAll("%N (%s) attempted to use a ladder speed glitch.", client, STEAM_ID);
case 2:
PrintToChatAll("%N (%s) is suspected of using a no fall damage bug.", client, STEAM_ID);
case 3:
PrintToChatAll("%N (%s) attempted to use a health boost glitch.", client, STEAM_ID);
case 4:
PrintToChatAll("%N (%s) attempted to use a ladder reload glitch.", client, STEAM_ID);
}
}
/* +==========================================+
| Debug Stuff |
+==========================================+
*/
#if DEBUG
bool g_bDebugEnabled[MAXPLAYERS+1];
Handle g_hDebugTimer[MAXPLAYERS+1];
Action CmdDebug(int client, int agrs)
{
g_bDebugEnabled[client] = !g_bDebugEnabled[client];
if (g_bDebugEnabled[client])
{
PrintHintText(client, "LOADING...");
CreateTimer(1.0, EF_t_LoadDebug, client);
}
else
{
DisableDebug(client);
PrintHintText(client, "Developers Stuff by raziEiL", client);
}
return Plugin_Handled;
}
Action EF_t_LoadDebug(Handle timer, int client)
{
g_hDebugTimer[client] = CreateTimer(0.1, EF_t_DebugMe, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
Action EF_t_DebugMe(Handle timer, int client)
{
if (IsClientInGame(client))
{
float speed = GetEntPropFloat(client, Prop_Data, "m_flGroundSpeed");
float fall = GetEntPropFloat(client, Prop_Send, "m_flFallVelocity");
PrintCenterText(client, "%d/%d", GetEntProp(client, Prop_Data, "m_idrownrestored"), GetEntProp(client, Prop_Data, "m_idrowndmg"));
if (GetEntityMoveType(client) == MOVETYPE_LADDER)
{
if (speed > 130)
PrintHintText(client, "Ground Speed %f WARNING!!!!", speed);
else
PrintHintText(client, "Ground Speed %f", speed);
}
else
{
if (fall != 0)
{
PrintHintText(client, "Move type %d | Flags %d\n Fall Speed: %f\n Health %d(%f)", GetEntityMoveType(client), GetEntityFlags(client), fall, GetClientHealth(client), GetTempHealth(client));
if (fall > 500)
PrintCenterText(client, "FALL DMG!");
}
else
PrintHintText(client, "Move type %d | Flags %d\n Ground Speed %f\n Health %d(%f)", GetEntityMoveType(client), GetEntityFlags(client), speed, GetClientHealth(client), GetTempHealth(client));
}
}
else
DisableDebug(client);
return Plugin_Stop;
}
void DisableDebug(int client)
{
if (g_hDebugTimer[client] != null)
{
delete g_hDebugTimer[client];
g_hDebugTimer[client] = null;
}
}
#endif