-
Notifications
You must be signed in to change notification settings - Fork 2
/
client-side-cheats.sp
148 lines (124 loc) · 3.08 KB
/
client-side-cheats.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
#include <sourcemod>
#include <cstrike>
#include <clientprefs>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required
ConVar sv_cheats;
bool gB_Cheats[MAXPLAYERS + 1];
Handle gH_CheatsCookie;
public Plugin myinfo =
{
name = "Client-side Cheats",
author = "Juked",
description = "Enables client-side cheats.",
version = "1.0",
url = ""
};
public void OnPluginStart()
{
RegConsoleCmd("sm_cheats", Command_Cheats, "Enables client side cheats.");
sv_cheats = FindConVar("sv_cheats");
gH_CheatsCookie = RegClientCookie("cheats_enabled", "", CookieAccess_Protected);
}
public void OnClientCookiesCached(int client)
{
if (IsFakeClient(client))
{
return;
}
if (!GetClientCookieBool(client, gH_CheatsCookie, gB_Cheats[client]))
{
gB_Cheats[client] = false;
SetClientCookieBool(client, gH_CheatsCookie, false);
}
if (gB_Cheats[client])
{
sv_cheats.ReplicateToClient(client, "1");
}
else
{
sv_cheats.ReplicateToClient(client, "0");
}
}
public Action Command_Cheats(int client, int args)
{
if (!IsValidClient(client))
{
return Plugin_Handled;
}
ShowMenu(client);
return Plugin_Handled;
}
void ShowMenu(int client)
{
Menu menu = CreateMenu(Menu_Callback);
menu.SetTitle("Client-side Cheats\n \n");
char buffer[256];
Format(buffer, sizeof(buffer), "Cheats: %s", gB_Cheats[client] ? "[ON]" : "[OFF]");
menu.AddItem("cheats", buffer);
menu.AddItem("vcollide", "Model Collision");
menu.AddItem("water", "Water");
menu.Display(client, MENU_TIME_FOREVER);
}
public int Menu_Callback(Menu menu, MenuAction action, int client, int param2)
{
switch(action)
{
case MenuAction_Select:
{
char item[32];
menu.GetItem(param2, item, sizeof(item));
if (StrEqual(item, "vcollide"))
{
PrintToChat(client, "[SM] Usage: 'vcollide_wireframe 1'");
ShowMenu(client);
}
else if (StrEqual(item, "water"))
{
PrintToChat(client, "[SM] Usage: 'mat_drawwater 0'");
ShowMenu(client);
}
else if (StrEqual(item, "cheats"))
{
gB_Cheats[client] = !gB_Cheats[client];
SetClientCookieBool(client, gH_CheatsCookie, gB_Cheats[client]);
if (gB_Cheats[client])
{
sv_cheats.ReplicateToClient(client, "1");
PrintToChat(client, "[SM] Enabled client-side cheats.");
ShowMenu(client);
}
else
{
sv_cheats.ReplicateToClient(client, "0");
PrintToChat(client, "[SM] Disabled client-side cheats.");
ShowMenu(client);
}
}
}
case MenuAction_End:
{
delete menu;
}
}
}
stock bool IsValidClient(int client)
{
return (0 < client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));
}
stock void SetClientCookieBool(int client, Handle cookie, bool value)
{
SetClientCookie(client, cookie, value ? "1" : "0");
}
stock bool GetClientCookieBool(int client, Handle cookie, bool& value)
{
char buffer[8];
GetClientCookie(client, cookie, buffer, sizeof(buffer));
if (buffer[0] == '\0')
{
return false;
}
value = StringToInt(buffer) != 0;
return true;
}