-
Notifications
You must be signed in to change notification settings - Fork 0
/
tickrate_fix.sp
283 lines (246 loc) · 8.03 KB
/
tickrate_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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#define PLUGIN_VERSION "1.4.0"
#define ENTITY_MAX_NAME 64
#define MAX_ENTITIES 2048 //(1 << 11)
enum /*DoorsTypeTracked*/
{
DoorsTypeTracked_None = -1,
DoorsTypeTracked_Prop_Door_Rotating = 0,
DoorTypeTracked_Prop_Door_Rotating_Checkpoint = 1
};
static const char g_szDoors_Type_Tracked[][MAX_NAME_LENGTH] =
{
"prop_door_rotating",
"prop_door_rotating_checkpoint"
};
enum struct DoorsData
{
int DoorsData_Type;
float DoorsData_Speed;
bool DoorsData_ForceClose;
}
DoorsData g_ddDoors[MAX_ENTITIES];
//<<<<<<<<<<<<<<<<<<<<< TICKRATE FIXES >>>>>>>>>>>>>>>>>>
//--------------- Fast Pistols & Slow Doors -------------
//*******************************************************
ConVar g_hCvarPistolDelayDualies;
ConVar g_hCvarPistolDelaySingle;
ConVar g_hCvarPistolDelayIncapped;
ConVar g_hCvarDoorSpeed;
float g_fNextAttack[MAXPLAYERS + 1];
float g_fPistolDelayDualies = 0.1;
float g_fPistolDelaySingle = 0.2;
float g_fPistolDelayIncapped = 0.3;
float g_fDoorSpeed;
bool g_bLateLoad;
public Plugin myinfo =
{
name = "Tickrate Fixes",
author = "Sir, Griffin, Chanz, Dosergen",
description = "Fixes a handful of silly Tickrate bugs",
version = PLUGIN_VERSION,
url = "https://github.com/SirPlease/L4D2-Competitive-Rework/blob/master/addons/sourcemod/scripting/TickrateFixes.sp"
}
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;
}
g_bLateLoad = late;
return APLRes_Success;
}
public void OnPluginStart()
{
CreateConVar("l4d_tickrate_fixes_version", PLUGIN_VERSION, "Tickrate Fixes plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
g_hCvarPistolDelayDualies = CreateConVar("l4d_tickrate_pistol_dualies", "0.15", "Minimum time (in seconds) between dual pistol shots", FCVAR_NOTIFY, true, 0.0, true, 5.0);
g_hCvarPistolDelaySingle = CreateConVar("l4d_tickrate_pistol_single", "0.2", "Minimum time (in seconds) between single pistol shots", FCVAR_NOTIFY, true, 0.0, true, 5.0);
g_hCvarPistolDelayIncapped = CreateConVar("l4d_tickrate_pistol_incapped", "0.3", "Minimum time (in seconds) between pistol shots while incapped", FCVAR_NOTIFY, true, 0.0, true, 5.0);
g_hCvarDoorSpeed = CreateConVar("l4d_tickrate_door_speed", "1.5", "Sets the speed of all prop_door entities on a map. 1.05 means = 105% speed", FCVAR_NOTIFY, true, 0.0, true, 5.0);
GetCvars();
UpdatePistolDelays();
Door_ClearSettingsAll();
Door_GetSettingsAll();
Door_SetSettingsAll();
g_hCvarPistolDelayDualies.AddChangeHook(ConVarChanged_Cvars);
g_hCvarPistolDelaySingle.AddChangeHook(ConVarChanged_Cvars);
g_hCvarPistolDelayIncapped.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDoorSpeed.AddChangeHook(ConVarChanged_Cvars);
HookEvent("weapon_fire", Event_WeaponFire);
if (g_bLateLoad)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
OnClientPutInServer(i);
}
}
AutoExecConfig(true, "tickrate_fix");
}
public void OnPluginEnd()
{
Door_ResetSettingsAll();
}
void ConVarChanged_Cvars(ConVar convar, char[] oldValue, char[] newValue)
{
GetCvars();
UpdatePistolDelays();
Door_SetSettingsAll();
}
void GetCvars()
{
g_fPistolDelayDualies = g_hCvarPistolDelayDualies.FloatValue;
g_fPistolDelaySingle = g_hCvarPistolDelaySingle.FloatValue;
g_fPistolDelayIncapped = g_hCvarPistolDelayIncapped.FloatValue;
g_fDoorSpeed = g_hCvarDoorSpeed.FloatValue;
}
public void OnEntityCreated(int iEntity, const char[] sClassName)
{
if (sClassName[0] != 'p')
return;
for (int i = 0; i < sizeof(g_szDoors_Type_Tracked); i++)
{
if (strcmp(sClassName, g_szDoors_Type_Tracked[i], false) != 0)
continue;
SDKHook(iEntity, SDKHook_SpawnPost, Hook_DoorSpawnPost);
}
}
void Hook_DoorSpawnPost(int iEntity)
{
if (!IsValidEntity(iEntity))
return;
char sClassName[ENTITY_MAX_NAME];
GetEntityClassname(iEntity, sClassName, sizeof(sClassName));
for (int i = 0; i < sizeof(g_szDoors_Type_Tracked); i++)
{
if (strcmp(sClassName, g_szDoors_Type_Tracked[i], false) != 0)
continue;
Door_GetSettings(iEntity, i);
}
Door_SetSettings(iEntity);
}
public void OnClientPutInServer(int iClient)
{
g_fNextAttack[iClient] = 0.0;
SDKHook(iClient, SDKHook_PreThink, Hook_OnPreThink);
}
public void OnClientDisconnect(int iClient)
{
g_fNextAttack[iClient] = 0.0;
SDKUnhook(iClient, SDKHook_PreThink, Hook_OnPreThink);
}
void UpdatePistolDelays()
{
g_fPistolDelayDualies = Clamp(g_fPistolDelayDualies, 0.0, 5.0);
g_fPistolDelaySingle = Clamp(g_fPistolDelaySingle, 0.0, 5.0);
g_fPistolDelayIncapped = Clamp(g_fPistolDelayIncapped, 0.0, 5.0);
}
float Clamp(float value, float min, float max)
{
return value < min ? min : value > max ? max : value;
}
void Hook_OnPreThink(int iClient)
{
if (!IsClientInGame(iClient) || GetClientTeam(iClient) != 2)
return;
int iActiveWeapon = GetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon");
if (!IsValidEntity(iActiveWeapon))
return;
char sWeaponName[ENTITY_MAX_NAME];
GetEdictClassname(iActiveWeapon, sWeaponName, sizeof(sWeaponName));
if (strcmp(sWeaponName, "weapon_pistol") != 0)
return;
float fOldValue = GetEntPropFloat(iActiveWeapon, Prop_Send, "m_flNextPrimaryAttack");
float fNewValue = g_fNextAttack[iClient];
if (fNewValue > fOldValue)
SetEntPropFloat(iActiveWeapon, Prop_Send, "m_flNextPrimaryAttack", fNewValue);
}
void Event_WeaponFire(Event event, const char[] name , bool dontBroadcast)
{
int iClient = GetClientOfUserId(event.GetInt("userid"));
if (!IsClientInGame(iClient) || GetClientTeam(iClient) != 2)
return;
int iActiveWeapon = GetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon");
if (!IsValidEntity(iActiveWeapon))
return;
char sWeaponName[ENTITY_MAX_NAME];
GetEdictClassname(iActiveWeapon, sWeaponName, sizeof(sWeaponName));
if (strcmp(sWeaponName, "weapon_pistol") != 0)
return;
g_fNextAttack[iClient] = GetGameTime() + (GetEntProp(iClient, Prop_Send, "m_isIncapacitated") ?
g_fPistolDelayIncapped : (GetEntProp(iActiveWeapon, Prop_Send, "m_isDualWielding") ?
g_fPistolDelayDualies : g_fPistolDelaySingle));
}
void Door_GetSettingsAll()
{
int iEntity = -1;
for (int i = 0; i < sizeof(g_szDoors_Type_Tracked); i++)
{
while ((iEntity = FindEntityByClassname(iEntity, g_szDoors_Type_Tracked[i])) != INVALID_ENT_REFERENCE)
{
if (IsValidEntity(iEntity))
Door_GetSettings(iEntity, i);
}
iEntity = -1;
}
}
void Door_GetSettings(int iEntity, int iType)
{
g_ddDoors[iEntity].DoorsData_Type = iType;
g_ddDoors[iEntity].DoorsData_Speed = GetEntPropFloat(iEntity, Prop_Data, "m_flSpeed");
g_ddDoors[iEntity].DoorsData_ForceClose = GetEntProp(iEntity, Prop_Data, "m_bForceClosed") != 0;
}
void Door_SetSettings(int iEntity)
{
SetEntPropFloat(iEntity, Prop_Data, "m_flSpeed", g_ddDoors[iEntity].DoorsData_Speed * g_fDoorSpeed);
SetEntProp(iEntity, Prop_Data, "m_bForceClosed", false);
}
void Door_SetSettingsAll()
{
int iEntity = -1;
for (int i = 0; i < sizeof(g_szDoors_Type_Tracked); i++)
{
while ((iEntity = FindEntityByClassname(iEntity, g_szDoors_Type_Tracked[i])) != INVALID_ENT_REFERENCE)
{
if (IsValidEntity(iEntity))
{
Door_SetSettings(iEntity);
SetEntProp(iEntity, Prop_Data, "m_bForceClosed", false);
}
}
iEntity = -1;
}
}
void Door_ResetSettings(int iEntity)
{
SetEntPropFloat(iEntity, Prop_Data, "m_flSpeed", g_ddDoors[iEntity].DoorsData_Speed);
SetEntProp(iEntity, Prop_Data, "m_bForceClosed", g_ddDoors[iEntity].DoorsData_ForceClose);
}
void Door_ResetSettingsAll()
{
int iEntity = -1;
for (int i = 0; i < sizeof(g_szDoors_Type_Tracked); i++)
{
while ((iEntity = FindEntityByClassname(iEntity, g_szDoors_Type_Tracked[i])) != INVALID_ENT_REFERENCE)
{
if (IsValidEntity(iEntity))
Door_ResetSettings(iEntity);
}
iEntity = -1;
}
}
void Door_ClearSettingsAll()
{
for (int i = 0; i < MAX_ENTITIES; i++)
{
g_ddDoors[i].DoorsData_Type = DoorsTypeTracked_None;
g_ddDoors[i].DoorsData_Speed = 0.0;
g_ddDoors[i].DoorsData_ForceClose = false;
}
}