[AutoSilencer] Fix array out of bounds.

This commit is contained in:
zaCade 2023-01-24 13:44:45 +01:00
parent 00e00d7680
commit 856b97d65a

View File

@ -6,8 +6,8 @@
Cookie g_CookieUsp = null; Cookie g_CookieUsp = null;
Cookie g_CookieM4a1 = null; Cookie g_CookieM4a1 = null;
bool g_bLateLoad = false; bool g_bLateLoad = false;
bool g_bM4A1Silenced[MAXPLAYERS] = true; bool g_bM4A1Silenced[MAXPLAYERS+1] = true;
bool g_bUSPSilenced[MAXPLAYERS] = false; bool g_bUSPSilenced[MAXPLAYERS+1] = false;
public Plugin myinfo = public Plugin myinfo =
{ {
@ -25,17 +25,17 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
} }
public void OnPluginStart() public void OnPluginStart()
{ {
g_CookieUsp = new Cookie("usp_silence", "uh...", CookieAccess_Private); g_CookieUsp = new Cookie("usp_silence", "uh...", CookieAccess_Private);
g_CookieM4a1 = new Cookie("m4a1_silence", "eh...", CookieAccess_Private); g_CookieM4a1 = new Cookie("m4a1_silence", "eh...", CookieAccess_Private);
RegConsoleCmd("sm_sm4", Command_SM4, "Toggle M4 Silencer"); RegConsoleCmd("sm_sm4", Command_SM4, "Toggle M4 Silencer");
RegConsoleCmd("sm_susp", Command_SUSP, "Toggle USPS Silencer"); RegConsoleCmd("sm_susp", Command_SUSP, "Toggle USPS Silencer");
if (g_bLateLoad) if (g_bLateLoad)
{ {
for (int i = 1; i <= MaxClients; i++) for (int i = 1; i <= MaxClients; i++)
{ {
if (IsClientConnected(i) && IsClientInGame(i)) if (IsClientConnected(i) && IsClientInGame(i))
{ {
OnClientPutInServer(i); OnClientPutInServer(i);
} }
@ -48,27 +48,27 @@ public void OnClientPutInServer(int client)
SDKHook(client, SDKHook_WeaponEquip, Hook_OnWeaponEquip); SDKHook(client, SDKHook_WeaponEquip, Hook_OnWeaponEquip);
} }
public Action Command_SM4(int client, int args) public Action Command_SM4(int client, int args)
{ {
g_bM4A1Silenced[client] = !g_bM4A1Silenced[client]; g_bM4A1Silenced[client] = !g_bM4A1Silenced[client];
char buffer[2]; char buffer[2];
Format(buffer, sizeof(buffer), "%s", g_bM4A1Silenced[client] ? "1":"0"); Format(buffer, sizeof(buffer), "%s", g_bM4A1Silenced[client] ? "1":"0");
g_CookieM4a1.Set(client, buffer); g_CookieM4a1.Set(client, buffer);
PrintToChat(client, "Toggled Silencer for M4A1 to %s", g_bM4A1Silenced[client] ? "On":"Off") PrintToChat(client, "Toggled Silencer for M4A1 to %s", g_bM4A1Silenced[client] ? "On":"Off")
return Plugin_Handled; return Plugin_Handled;
} }
public Action Command_SUSP(int client, int args) public Action Command_SUSP(int client, int args)
{ {
g_bUSPSilenced[client] = !g_bUSPSilenced[client]; g_bUSPSilenced[client] = !g_bUSPSilenced[client];
char buffer[2]; char buffer[2];
Format(buffer, sizeof(buffer), "%s", g_bUSPSilenced[client] ? "1":"0"); Format(buffer, sizeof(buffer), "%s", g_bUSPSilenced[client] ? "1":"0");
g_CookieUsp.Set(client, buffer); g_CookieUsp.Set(client, buffer);
PrintToChat(client, "Toggled Silencer for USP to %s", g_bUSPSilenced[client] ? "On":"Off") PrintToChat(client, "Toggled Silencer for USP to %s", g_bUSPSilenced[client] ? "On":"Off")
return Plugin_Handled; return Plugin_Handled;
} }
@ -90,7 +90,7 @@ public Action Hook_OnWeaponEquip(int client, int weapon)
SetEntProp(weapon, Prop_Send, "m_weaponMode", 0); SetEntProp(weapon, Prop_Send, "m_weaponMode", 0);
} }
} }
if(StrEqual(item, "weapon_usp")) if(StrEqual(item, "weapon_usp"))
{ {
if(g_bUSPSilenced[client]) if(g_bUSPSilenced[client])
@ -112,19 +112,19 @@ public void OnClientCookiesCached(int client)
char strUSP[2], strM4A1[2]; char strUSP[2], strM4A1[2];
g_CookieUsp.Get(client, strUSP, sizeof(strUSP)); g_CookieUsp.Get(client, strUSP, sizeof(strUSP));
g_CookieM4a1.Get(client, strM4A1, sizeof(strM4A1)); g_CookieM4a1.Get(client, strM4A1, sizeof(strM4A1));
if (StrEqual(strUSP, "")) //Means the cookie has never been set. Default is Off for USP, On for M4A1. if (StrEqual(strUSP, "")) //Means the cookie has never been set. Default is Off for USP, On for M4A1.
{ {
g_bM4A1Silenced[client] = true; g_bM4A1Silenced[client] = true;
g_CookieM4a1.Set(client, "1"); g_CookieM4a1.Set(client, "1");
g_bUSPSilenced[client] = false; g_bUSPSilenced[client] = false;
g_CookieUsp.Set(client, "0"); g_CookieUsp.Set(client, "0");
return; return;
} }
g_bM4A1Silenced[client] = StrEqual(strM4A1, "1"); g_bM4A1Silenced[client] = StrEqual(strM4A1, "1");
g_bUSPSilenced[client] = StrEqual(strUSP, "1"); g_bUSPSilenced[client] = StrEqual(strUSP, "1");
} }