/*
	Disable sv_cheats command, online thidperson/firstperson is enabled
*/
new Handle:CheckTimer;

public EnableAntiCheat()
{
	PrintToServer("[Hiddensm] AntiCheat enabled!");
	CheckTimer = CreateTimer(30.0,TimerCheck,0, TIMER_REPEAT);
	new String:Name[256];
	new bool:isCommand;
	new Flags;
	new Handle:Command;
	
	Command = FindFirstConCommand(Name,gMaxLength,isCommand,Flags);
	do
	{
		if(Flags & FCVAR_CHEAT)
		{
				if(isCommand)
				{
					if(strcmp(Name,"thirdperson") != 0 || strcmp(Name,"firstperson") != 0)
					{
						RegConsoleCmd(Name,Check_Command);
					}
				}
		}			
	}while(FindNextConCommand(Command,Name,gMaxLength,isCommand,Flags));				
}

public DisableAntiCheat()
{
	KillTimer(CheckTimer);
}

public Action:TimerCheck(Handle:timer, any:value)
{
	new client;
	
	for(new i=0;i<MAXPLAYERS;i++)
	{
		client = GetClientOfUserId(i);
		if(client > 0 && IsClientInGame(client))
		{
			if(IsPlayerAlive(client))
			{
				//PrintToChat(client,"[!!]CheatCheck");
				QueryClientConVar(client,"cl_leveloverview",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"cl_particles_show_bbox",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"Mat_fillrate",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"mat_proxy",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"mat_luxels",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"mat_showlowresimage",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"mat_wireframe",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"mem_force_flush",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"r_aspectratio",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"r_drawlights",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"r_drawrenderboxes",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"r_showenvcubemap",ConVarQueryFinished:Check_CVAR0, client);
				QueryClientConVar(client,"r_shadowwireframe",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"r_visualizetraces",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"r_visualizelighttraces",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"r_drawmodelstatsoverlay",ConVarQueryFinished:Check_CVAR0, client);				
				QueryClientConVar(client,"snd_show",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"snd_visualize",ConVarQueryFinished:Check_CVAR0, client);	
				QueryClientConVar(client,"vcollide_wireframe",ConVarQueryFinished:Check_CVAR0, client);									
				//
				QueryClientConVar(client,"r_DrawDisp",ConVarQueryFinished:Check_CVAR1, client);
				QueryClientConVar(client,"r_drawentities",ConVarQueryFinished:Check_CVAR1, client);
				QueryClientConVar(client,"r_drawopaquerenderables",ConVarQueryFinished:Check_CVAR1, client);
				QueryClientConVar(client,"r_drawothermodels",ConVarQueryFinished:Check_CVAR1, client);		
				QueryClientConVar(client,"r_drawparticles",ConVarQueryFinished:Check_CVAR1, client);
				QueryClientConVar(client,"r_drawtranslucentrenderables",ConVarQueryFinished:Check_CVAR1, client);
				QueryClientConVar(client,"r_drawworld",ConVarQueryFinished:Check_CVAR1, client);
			}
		}
	}
}

public Action:Check_Command(client, args)
{
	if(GetConVarInt(CVAR_AntiCheat))
	{
		PrintToConsole(client,"blocked!");
		return Plugin_Handled;
	}
	return Plugin_Continue;
}

public Check_CVAR0(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
	if(StringToInt(cvarValue) > 0)
	{
		Cheatdetect(client,cvarName);
	}
}

public Check_CVAR1(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
	if(StringToInt(cvarValue) != 1)
	{
		Cheatdetect(client,cvarName);
	}
}

public Cheatdetect(client,const String:cvarName[])
{
	if(GetConVarInt(CVAR_AntiCheat))
	{
		new String:ClientName[256];
		GetClientName(client,ClientName,gMaxLength);
		
		PrintToChatAll("Cheat detect! Player: \"%s\" CVAR: \"%s\"",ClientName,cvarName);
		KickClient(client,"Cheat detect! CVAR: \"%s\"",cvarName);
	}
}