-- Ropes
-- List possibilities for server wreackage
-- Anti Blacklist
Data.Frame:Remove()
if not Data then
	Data = {}
	Data.Ply = LocalPlayer()
	Data.Enabled = {}
	
	local MOTD = function() ulx.showMotdMenu() end
	ulx.showMotdMenu = function() MOTD, Data.Enabled["motdspam"]=false end
end

local ChamsMat = CreateMaterial("Wallhack Material", "VertexLitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$model"] = 1, ["$ignorez"] = 1 })
local WallhackExtra = {"player","prop_physics","prop_vehicle_jeep","adv_moneyprinter"," prop_door_rotating","spawned_weapon","spawned_shipment"}
local AimIgnore = {
"gmod_tool", "gmod_camera", "weapon_physgun", "weapon_physcannon","lockpick","fas2_ifak",
"pocket","keys","arrest_stick","unarrest_stick","itemstore_pickup","stunstick","weaponchecker"}

timer.Stop("AntiMaterials")
timer.Stop("FlashlightSpam")


concommand.Add("cheats", function(_, _, args)
	local text = string.lower(args[1])
	if text=="close" then
		if IsValid(Data["Frame"]) then
			Data["Frame"]:Remove()
		end
	elseif text=="help" then
		table.foreach(Data.Buttons, function(index, value) print("cheats "..index) end)
		Data.Enabled = {}
	elseif text=="disable" then
		table.foreach(Data.Enabled, function(index, value) if value then print("cheats "..index..": off") end end)
		Data.Enabled = {}
	else
		Data.Buttons[text].DoClick()
	end
end)

function AimEnt(ply)
	if not ply then ply = LocalPlayer()
		return ply:GetEyeTrace().Entity
	end
end
function ply(name)
	name = string.lower(name)
	for i, ply in pairs(player.GetAll()) do
		if string.find(string.lower(ply:Nick()),name) then
			return ply
		end
	end
end
local function DrawPlayerInfo(ply)
	local pos = ply:EyePos()
	
	pos.z = pos.z + 0
	pos = pos:ToScreen()
	local yOffset = -60
	
	if not (ply:GetNWString("usergroup")=="user") then
		draw.DrawText(ply:GetNWString("usergroup"), "TargetID", pos.x + 1, pos.y - 15 + yOffset, Color(0, 0, 0, 255), 1)
		if ply:IsSuperAdmin() then
			draw.DrawText(ply:GetNWString("usergroup"), "TargetID", pos.x, pos.y - 16 + yOffset, Color(255,0,0,200), 1)
		elseif ply:IsAdmin() then
			draw.DrawText(ply:GetNWString("usergroup"), "TargetID", pos.x, pos.y - 16 + yOffset, Color(0,0,255,200), 1)
		else
			draw.DrawText(ply:GetNWString("usergroup"), "TargetID", pos.x, pos.y - 16 + yOffset, Color(0,255,0,200), 1)
		end
	end
	
	draw.DrawText(ply:Nick(), "TargetID", pos.x + 1, pos.y + 1 + yOffset, Color(0, 0, 0, 255), 1)
	draw.DrawText(ply:Nick(), "TargetID", pos.x, pos.y + yOffset, team.GetColor(ply:Team()), 1)

	draw.DrawText("Health: "..ply:Health(), "TargetID", pos.x + 1, pos.y + 16 + yOffset, Color(0, 0, 0, 255), 1)
	draw.DrawText("Health: "..ply:Health(), "TargetID", pos.x, pos.y + 15 + yOffset, Color(255,255,255,200), 1)

	draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x + 1, pos.y + 31 + yOffset, Color(0, 0, 0, 255), 1)
	draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x, pos.y + 30 + yOffset, Color(255, 255, 255, 200), 1)

	if IsValid(ply:GetActiveWeapon()) then
		draw.DrawText(ply:GetActiveWeapon():GetClass() or "", "TargetID", pos.x + 1, pos.y + 46 + yOffset, Color(0, 0, 0, 255), 1)
		draw.DrawText(ply:GetActiveWeapon():GetClass() or "", "TargetID", pos.x, pos.y + 45 + yOffset, Color(255, 255, 255, 200), 1)
	end
end
local function angDif(pos)
	local myAngs = Data.Ply:GetAngles()
	local needed = (pos - LocalPlayer():GetShootPos()):Angle()
	
	myAngs.p = math.NormalizeAngle(myAngs.p)
	needed.p = math.NormalizeAngle(needed.p)
	
	myAngs.y = math.NormalizeAngle(myAngs.y)
	needed.y = math.NormalizeAngle(needed.y)
	
	local p = math.NormalizeAngle(needed.p - myAngs.p)
	local y = math.NormalizeAngle(needed.y - myAngs.y)
	
	return math.abs(p) + math.abs(y), {p = p, y = y}
end
local function Distance(pos)
	local myPos = Data.Ply:GetPos()	
	return math.sqrt((pos.x-myPos.x)^2+(pos.y-myPos.y)^2+(pos.z-myPos.z)^2)
end

local function Radar(show)
	if show then
		local RadarPos=Vector((ScrW()/10)*8,(ScrH()/10)*8)
		local RadarSize=Vector(ScrW()/3,ScrH()/3)
		--print(RadarPos,RadarSize)
		local Radar = vgui.Create( "DFrame" )
		Data.Radar = Radar
		Radar:SetPos( Vector(1536,864) )
		Radar:SetSize( Vector(640,360) )
		Radar:SetTitle( "Radar" )
		Radar:SetVisible( true )
		Radar:MakePopup()
		Radar.Paint = function()
			--Rdar.Paint()
			draw.RoundedBox( 8, 0, 0, Radar:GetWide(), Radar:GetTall(), Color( 0, 0, 0, 150 ) )
		end
	else
		Data.Radar:Remove()
	end
end


local function CheatMenuLoad()
	if IsValid(Data["Frame"]) then
		Data["Frame"]:SetVisible( true )
		table.foreach(Data.Buttons, function(text, button)
			if Data.Filters[text] and (Data.Filters[text]==false) then 
				Data.Enabled[text] = false
				button:SetColor(Color(150,150,150))
			else
				if Data.Enabled[text] then button:SetColor(Color(255,0,0))
				else button:SetColor(Color(255,255,255)) end
			end
		end)
	else
		local FramePos=Vector(ScrW()*0.66,ScrH()*0.01,0)
		local FrameScale=Vector(ScrW()/3,ScrH()/3,0)
		Data["Frame"] = vgui.Create("DFrame")
		Data["Frame"]:SetSize(FrameScale.x,FrameScale.y)
		Data["Frame"]:SetPos(FramePos.x,FramePos.y)
		Data["Frame"]:SetTitle("Hack")
		Data["Frame"]:SetSkin("DarkRP")
		Data["Frame"]:ShowCloseButton( true )
		Data["Frame"]:MakePopup()
		Data.Buttons = {}
		Data.Filters = {}
		
		local ButtonCreate = function(text, pos, Size, filter, click )
			local button = vgui.Create("DButton",Data["Frame"])
			if not Size then Size = Vector(1,1) end
			button:SetSize(FrameScale.x/6*1.8*Size.x,FrameScale.y/10*1.8*Size.y)
			button:SetPos((FrameScale.x/3)*pos.x+FrameScale.x/48,(FrameScale.y/5)*pos.y+FrameScale.y/10)
			button:SetText(text)
			text = string.lower(text)
			Data.Buttons[text] = button
			if not filter==nil then Data.Filters[text] = filter end
			button.DoClick = function()
				if not (filter==nil) and (filter==false) then 
					Data.Enabled[text] = false
					button:SetColor(Color(150,150,150))
				else
					Data.Enabled[text] = not Data.Enabled[text]
					if Data.Enabled[text] then button:SetColor(Color(255,0,0))
					else button:SetColor(Color(255,255,255)) end
					if not (click == nil) then click(Data.Enabled[text]) end	
				end
			end
		end

		----------------------------------------------------------------------
		--ButtonCreate( Index/name, Pos, size, filter, Optional OnClick function(Enabled))--
		
		ButtonCreate("Wallhack",Vector(0,0), Vector(0.5,1))
		ButtonCreate("Wallhack_props",Vector(0.449,0),Vector(0.5,1))
		ButtonCreate("BHop",Vector(1,0), _, _, function(ena) if not ena then RunConsoleCommand("-jump") end end)
		ButtonCreate("MOTDSpam",Vector(2,0), _, GetConVarString( "ulx_showMotd" )=="0", function(ena) if ena then timer.Create("MOTDSPAM",0.05,0, function() for i=0,10 do LocalPlayer():ConCommand("ulx motd") end end) else timer.Stop("MOTDSPAM") end end)
		ButtonCreate("AimEnhance",Vector(0,1), Vector(0.5,1))
		ButtonCreate("AntiArrest",Vector(1,1))
		ButtonCreate("AutoShoot",Vector(0.449,1),Vector(0.5,1))
		ButtonCreate("FlashlightSpam",Vector(2,1), _, _, function(ena) if ena then timer.Create("FlashlightSpam",0.01,0, function() if Data.Enabled["antimaterials"] then timer.Stop("FlashlightSpam") end LocalPlayer():ConCommand('impulse 100') end) else timer.Stop("FlashlightSpam") end end)
		ButtonCreate("AntiMaterials",Vector(0,2), _, _, function(ena) if ena then timer.Create("AntiMaterials",1, 0, function() table.foreach(ents.FindByClass("prop_physics"), function( _, ENT) if (ENT:GetMaterial() != "") and Data.Enabled["antimaterials"] then ENT:SetMaterial("") end end) end) else timer.Stop("AntiMaterials") end end)
		ButtonCreate("8",Vector(1,2))
		ButtonCreate("9",Vector(2,2))
		ButtonCreate("10",Vector(0,3), _, _, function() LocalPlayer():PrintMessage(HUD_PRINTCENTER,'tits') end)
		ButtonCreate("11",Vector(1,3))
		ButtonCreate("Radar",Vector(2,3), _, _, Radar)
		
	end
end
CheatMenuLoad(); Data["Frame"]:SetVisible( false )

hook.Add("OnContextMenuOpen","CheatMenuOpen", function() CheatMenuLoad() end)
hook.Add("OnContextMenuClose","CheatMenuClose", function()
	if IsValid(Data["Frame"]) then
		Data["Frame"]:SetVisible( false )
	end
end)
hook.Add("HUDPaint", "CheatHudPaint", function()
	if Data.Enabled["wallhack"] then
		table.foreach(player.GetAll(), function(i, ply)
			if not (ply == Data.Ply) then
				DrawPlayerInfo(ply)
			end
		end)
	end
	
	if Data.Enabled["aimenhance"] then
		local x = ScrW() / 2
		local y = ScrH() / 2
		local gap = 5
		local length = gap + 15	
	
		if IsValid(Data.Ply:GetActiveWeapon()) then
			if input.IsMouseDown(MOUSE_RIGHT) and not table.HasValue(AimIgnore, Data.Ply:GetActiveWeapon():GetClass()) then
				if Data.AimEnhance_Target then
					if Data.AimEnhance_Target==Data.Ply:GetEyeTrace().Entity then
						surface.SetDrawColor( 0, 255, 0, 255 )
					else
						surface.SetDrawColor( 255, 0, 0, 255 )
					end
					if Data.AimEnhance_Target then
						draw.DrawText(Data.AimEnhance_Target:Nick(), "TargetID", x + 1 , y + 41, Color(0, 0, 0, 200), 1)
						draw.DrawText(Data.AimEnhance_Target:Nick(), "TargetID", x , y + 40, team.GetColor(Data.AimEnhance_Target:Team()), 1)
					end
				else
					surface.SetDrawColor( 0, 0, 255, 255 )			
				end

				surface.DrawLine( x - length, y, x - gap, y )
				surface.DrawLine( x + length, y, x + gap, y )
				surface.DrawLine( x, y - length, x, y - gap )
				surface.DrawLine( x, y + length, x, y + gap )
			end
		end
	end
end)
hook.Add("RenderScreenspaceEffects", "chams", function()
	if Data.Enabled["wallhack"] and Data.Enabled["wallhack_props"] then
		cam.Start3D(EyePos(), EyeAngles())
		table.foreach(ents.GetAll(), function(i, ENT)
			render.MaterialOverride(ChamsMat)
			render.SuppressEngineLighting(true)
			if ENT:IsPlayer() then
				if ENT:Alive() then
					local color = team.GetColor(ENT:Team())
					if ENT:GetColor().a == 100 then
						render.SetColorModulation((color.r + 75)/255, (color.g + 75)/255, (color.b + 75)/255, 1)
						render.SetBlend(0.5)
						ENT:DrawModel()
						render.SetBlend(1)
					else
						render.SetColorModulation(color.r/255, color.g/255, color.b/255, 1)
						ENT:DrawModel()
					end
					render.SetColorModulation((color.r + 150)/255, (color.g + 150)/255, (color.b + 150)/255, 1)
					ENT:GetActiveWeapon():DrawModel()
				end
			elseif table.HasValue(WallhackExtra, ENT:GetClass()) then
				render.SetBlend(0.5)
				render.SetColorModulation(1, 0, 0)
				ENT:DrawModel()
				render.SetBlend(1)
			end
			render.MaterialOverride()
			render.SetColorModulation(1, 1, 1)
			ENT:DrawModel()
			render.SuppressEngineLighting(false)
		end)
		cam.End3D()
	elseif Data.Enabled["wallhack"] then
		cam.Start3D(EyePos(), EyeAngles())
		table.foreach(player.GetAll(), function(i, ENT)
			if ENT:Alive() then
				render.MaterialOverride(ChamsMat)
				render.SuppressEngineLighting(true)
				local color = team.GetColor(ENT:Team())
				if ENT:GetColor().a == 100 then
					render.SetColorModulation((color.r + 75)/255, (color.g + 75)/255, (color.b + 75)/255, 1)
					render.SetBlend(0.5)
					ENT:DrawModel()
					render.SetBlend(1)
				else
					render.SetColorModulation(color.r/255, color.g/255, color.b/255, 1)
					ENT:DrawModel()
				end

				if IsValid(ENT:GetActiveWeapon()) and false then
					local color = ENT:GetActiveWeapon():GetColor()
					render.SetColorModulation(color.r/255, color.g/255, color.b/255, 1)
					ENT:GetActiveWeapon():DrawModel()
					render.MaterialOverride()
					render.SetColorModulation(1, 1, 1)
					ENT:GetActiveWeapon():DrawModel()
				end
				render.MaterialOverride()
				render.SetColorModulation(1, 1, 1)
				ENT:DrawModel()
				render.SuppressEngineLighting(false)
			end
		end)
		cam.End3D()
	elseif Data.Enabled["wallhack_props"] then
		cam.Start3D(EyePos(), EyeAngles())
		render.SetBlend(0.5)
		render.MaterialOverride(ChamsMat)
		render.SetColorModulation(1, 0, 0)
		Ents = ents.GetAll()
		for i=1, #Ents do 
			if table.HasValue(WallhackExtra, Ents[ i ]:GetClass()) then
				Ents[ i ]:DrawModel()
			end
		end
		render.SetColorModulation(1, 1, 1)
		render.SetBlend(1)
		cam.End3D()
	end
end)
hook.Add("Think","AimEnhance",function()
	if Data.Enabled["bhop"] then
		 if (input.IsKeyDown( KEY_SPACE ) ) and (LocalPlayer():GetMoveType()!=MOVETYPE_NOCLIP) then
			if LocalPlayer():IsOnGround() then
				RunConsoleCommand("+jump")
				HasJumped = 1
			else
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		elseif HasJumped == 1 then
				RunConsoleCommand("-jump")
				HasJumped = 0
		end
	end
	if Data.Enabled["aimenhance"] then
		if IsValid(Data.Ply:GetActiveWeapon()) then
			if input.IsMouseDown(MOUSE_RIGHT) and not table.HasValue(AimIgnore, Data.Ply:GetActiveWeapon():GetClass()) then
				if not Data.AimEnhance_Target then
					table.foreach(player.GetAll(), function(i, ply)
						if not (ply == Data.Ply) and not Data.AimEnhance_Target then
							if ply:Alive() then
								Data.Dist = Distance(ply:GetPos()+Vector(0,0,50))
								if angDif(ply:GetPos()) < (3600/Data.Dist) then
									Data.AimEnhance_Target = ply
								end
							end
						end
						
					end)
				else
					if Data.Ply:GetActiveWeapon().Primary then
						local pos = Data.AimEnhance_Target:GetBonePosition(Data.AimEnhance_Target:LookupBone("ValveBiped.Bip01_Head1"))+Vector(0,0,2)+
						Data.AimEnhance_Target:GetVelocity() * 0.013-Data.Ply:GetVelocity() * 0.013
						Data.Ply:SetEyeAngles((pos - Data.Ply:GetShootPos()):Angle())
					end
					if not Data.AimEnhance_Target:Alive() then
						Data.AimEnhance_Target = false
					end
				end
			else
				Data.AimEnhance_Target = false
			end
		end
	end

	if Data.Enabled["antiarrest"] then
		table.foreach(player.GetAll(), function(i,ply)
			if IsValid(ply:GetActiveWeapon()) then
				if ply:GetActiveWeapon():GetClass()=="arrest_stick" then
					--if (ply:GetEyeTrace().Entity == LocalPlayer()) then 
						--LocalPlayer():ChatPrint("Line352")
						if (Distance(ply:GetPos())<175) then
							RunConsoleCommand("kill")
							--LocalPlayer():ChatPrint("Suiside!!")
						--end
					end
				end
			end
		end)
	end
	
	
end)
hook.Add("CreateMove", "AutoShoot", function(cmd)
	if Data.Enabled["aimenhance"] and Data.Enabled["autoshoot"] then
		if IsValid(Data.Ply:GetActiveWeapon()) then
			if input.IsKeyDown(KEY_LALT) and input.IsMouseDown(MOUSE_RIGHT) then
				if Data.AimEnhance_Target==Data.Ply:GetEyeTrace().Entity then
					if not Data.AutoShootTimer then
						Data.AutoShootTimer = true
						timer.Create("AutoShoot", 0.05, 1, function() Data.AutoShootDelay = true end)
					end
				else
					timer.Stop("AutoShoot")
					Data.AutoShootDelay = false
					Data.AutoShootTimer = false
				end
				if Data.AutoShootDelay and Data.AutoShootReady then
					Data.AutoShootReady = false
					cmd:SetButtons(cmd:GetButtons() + IN_ATTACK)
					Data.AutoShootDelay = false
					Data.AutoShootTimer = false
				end
			else
				Data.AutoShootReady = true
			end
		end
	end
end)



--https://www.google.dk/search?q=gmod+lua+menubar&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&channel=fflb&gws_rd=cr&ei=fyR8U93IKoWe0QW964GACw
--http://www.yoyogaming.net/gmod/fastdl/lua/autorun/menubar/


























































