--[[
	autorun/client/oubhack_derma.lua
	(that crazy lumbee) Skezixx | (STEAM_0:0:35313849)
	===DStream===
]]

/******************************************************************************
 .d88888b.  888     888 888888b.   888    888        d8888  .d8888b.  888    d8P  
d88P" "Y88b 888     888 888  "88b  888    888       d88888 d88P  Y88b 888   d8P   
888     888 888     888 888  .88P  888    888      d88P888 888    888 888  d8P    
888     888 888     888 8888888K.  8888888888     d88P 888 888        888d88K     
888     888 888     888 888  "Y88b 888    888    d88P  888 888        8888888b    
888     888 888     888 888    888 888    888   d88P   888 888    888 888  Y88b   
Y88b. .d88P Y88b. .d88P 888   d88P 888    888  d8888888888 Y88b  d88P 888   Y88b  
 "Y88888P"   "Y88888P"  8888888P"  888    888 d88P     888  "Y8888P"  888    Y88b 
 By Oubliete and UnknownAlias
*******************************************************************************/

if !ConVarExists("aimbot_speed") then CreateClientConVar("aimbot_speed",360,true,false) end -- #4 arg, yeeaah like I'm that stupid.
if !ConVarExists("oh_aimbot_enabled") then CreateClientConVar("oh_aimbot_enabled","false",true,false) end

oubhack.cp_offset = 0;

-------------------------------------------------------------------------------------------------|


-------------------------------------------------------------------------------------------------|


-------------------------------------------------------------------------------------------------|

function oubhack:AimbotPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSkin("oubhack")
		p:SetSize(w,h)
		
		function p:update()
			self:Clear(true)
			
			self.NumSlider = vgui.Create( "DNumSlider", self )
				self.NumSlider:SetPos( 5,10 )
				self.NumSlider:SetWide( 150 )
				self.NumSlider:SetText( "Aimbot Speed" )
				self.NumSlider:SetMin( 1 ) 
				self.NumSlider:SetMax( 360 )
				self.NumSlider:SetDecimals( 0 ) 
				self.NumSlider:SetConVar( "aimbot_speed" ) 
			
			self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
			self.AimbotToggle = vgui.Create("oh_DToggle",self)
				self.AimbotToggle:SetPos(10,50)
				self.AimbotToggle:SetSize(140,25)
				self.AimbotToggle:SetEnabled(oubhack.aimbot_on)
				self.AimbotToggle:SetTitle("Aimbot")
				self.AimbotToggle.DoClick = function()
					if oubhack.aimbot_on then
						oubhack.aimbot_on = false;
					else
						oubhack.aimbot_on = true;
					end
				end
			self.TargetNPCToggle = vgui.Create("oh_DToggle",self)
				self.TargetNPCToggle:SetPos(10,80)
				self.TargetNPCToggle:SetSize(140,25)
				self.TargetNPCToggle:SetEnabled(oubhack.target_npcs)
				self.TargetNPCToggle:SetTitle("Target NPCs")
				self.TargetNPCToggle.DoClick = function()
					if oubhack.target_npcs then
						oubhack.target_npcs = false;
					else
						oubhack.target_npcs = true;
					end
				end
			self.TargetBotToggle = vgui.Create("oh_DToggle",self)
				self.TargetBotToggle:SetPos(10,110)
				self.TargetBotToggle:SetSize(140,25)
				self.TargetBotToggle:SetEnabled(oubhack.target_bots)
				self.TargetBotToggle:SetTitle("Target Bots")
				self.TargetBotToggle.DoClick = function()
					if oubhack.target_bots then
						oubhack.target_bots = false;
					else
						oubhack.target_bots = true;
					end
				end
			self.ToggleAdminIngore = vgui.Create("oh_DToggle",self)
				self.ToggleAdminIngore:SetPos(10,140)
				self.ToggleAdminIngore:SetSize(140,25)
				self.ToggleAdminIngore:SetEnabled(oubhack.ingore_admins)
				self.ToggleAdminIngore:SetTitle("Ingore Admins")
				self.ToggleAdminIngore.DoClick = function()
					if oubhack.ingore_admins then
						oubhack.ingore_admins = false;
					else
						oubhack.ingore_admins = true;
					end
				end
			self.ToggleSuperAdminIngore = vgui.Create("oh_DToggle",self)
				self.ToggleSuperAdminIngore:SetPos(10,170)
				self.ToggleSuperAdminIngore:SetSize(140,25)
				self.ToggleSuperAdminIngore:SetEnabled(oubhack.ingore_super_admins)
				self.ToggleSuperAdminIngore:SetTitle("Ingore Super-Admins")
				self.ToggleSuperAdminIngore.DoClick = function()
					if oubhack.ingore_super_admins then
						oubhack.ingore_super_admins = false;
					else
						oubhack.ingore_super_admins = true;
					end
				end
		
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:ESPPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSkin("oubhack")
		p:SetSize(w,h)
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
				
		end
		
	p:update();
	return p; 
end

-------------------------------------------------------------------------------------------------|

function oubhack:XRayPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:FriendsPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
			
			-------------------------------------------------------------------------------------------------------------------------------------------|
			----------------------------------------------------------------- Targets -----------------------------------------------------------------|
			-------------------------------------------------------------------------------------------------------------------------------------------|
			
			self.TargetList = vgui.Create("DListView",self)
				self.TargetList:SetPos(20,10)
				self.TargetList:SetSize(300,275)
				self.TargetList:SetMultiSelect(false)
				self.TargetList:AddColumn("Name")
				self.TargetList:AddColumn("Is Steam Friend")
				self.TargetList:AddColumn("User Group")
				self.TargetList.OnRowSelected = function(panel,line)
					if !panel or !line then return false end;
					self.Selected = panel:GetLine(line):GetValue(1);
					self.SelectedLine = line;
				end
				for k,v in pairs(oubhack:GetTargets()) do
					self.TargetList:AddLine(v:Nick(),string.BoolToYN(oubhack:IsSteamFriend(v)),oubhack:GetUserGroup(v))
				end
				
			self.AddFriend = vgui.Create("DButton",self)
				self.AddFriend:SetPos(20,self.TargetList:GetTall()+10)
				self.AddFriend:SetSize(self.TargetList:GetWide(),50)
				self.AddFriend:SetText("Add Friend")
				self.AddFriend.DoClick = function()
					if !self.Selected or !self.SelectedLine then return false end;
					oubhack:AddFriend(player.FindByName(self.Selected))
					self.TargetList:RemoveLine(self.SelectedLine)
					self.FriendsList:AddLine(self.Selected,string.BoolToYN(oubhack:IsSteamFriend(player.FindByName(self.Selected))),oubhack:GetUserGroup(player.FindByName(self.Selected)))
					self.Selected = nil;
					self.SelectedLine = nil;
				end
				self.TargetList.DoDoubleClick = self.AddFriend.DoClick
			-------------------------------------------------------------------------------------------------------------------------------------------|
			----------------------------------------------------------------- Friends -----------------------------------------------------------------|
			-------------------------------------------------------------------------------------------------------------------------------------------|
			
			self.FriendsList = vgui.Create("DListView",self)
				self.FriendsList:SetPos(80+self.TargetList:GetWide(),10)
				self.FriendsList:SetSize(300,275)
				self.FriendsList:SetMultiSelect(false)
				self.FriendsList:AddColumn("Name")
				self.FriendsList:AddColumn("Is Steam Friend")
				self.FriendsList:AddColumn("User group")
				self.FriendsList.OnRowSelected = function(panel,line)
					self.RSelected = panel:GetLine(line):GetValue(1);
					self.RSelectedLine = line;
				end
				for k,v in pairs(oubhack.friends) do
					self.FriendsList:AddLine(v:Nick(),string.BoolToYN(oubhack:IsSteamFriend(v)),oubhack:GetUserGroup(v))
				end
			self.RemoveFriend = vgui.Create("DButton",self)
				self.RemoveFriend:SetPos(80+self.FriendsList:GetWide(),self.TargetList:GetTall()+10)
				self.RemoveFriend:SetSize(self.TargetList:GetWide(),50)
				self.RemoveFriend:SetText("Remove Friend")
				self.RemoveFriend.DoClick = function()
					if !self.RSelected or !self.RSelectedLine then return false end;
					oubhack:RemoveFriend(player.FindByName(self.RSelected))
					self.FriendsList:RemoveLine(self.RSelectedLine)
					self.TargetList:AddLine(self.RSelected,string.BoolToYN(oubhack:IsSteamFriend(player.FindByName(self.RSelected))),oubhack:GetUserGroup(player.FindByName(self.RSelected)))
					self.RSelected = nil;
					self.RSelectedLine = nil;
				end
				self.FriendsList.DoDoubleClick = self.RemoveFriend.DoClick
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:HUDPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
					self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:GroupsPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
			
			self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
				
			self.TargList = vgui.Create("DListView",self)
				self.TargList:SetSize(((ScrW()/2)/2),(ScrH()/2)-20)
				self.TargList:SetPos(ScrW()/2-self.TargList:GetWide(),20)
				self.TargList:SetMultiSelect(false)
				self.TargList:AddColumn("Name")
				self.TargList:AddColumn("OubHack freind")
				self.TargList:AddColumn("Steam freind")
				self.TargList:AddColumn("Team")
				for k,v in pairs(oubhack:GetPossibleTargets()) do
					self.TargList:AddLine(v:Nick(),string.BoolToYN(oubhack:IsFriend(v)),string.BoolToYN(oubhack:IsSteamFriend(v)),v.team or "None")
				end
					
			--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--
			
			-- self.CreateGroupName = vgui.Create("DTextEntry",self)
				-- self.CreateGroupName:SetPos()
				

		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:MovementPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|


function oubhack:SetupPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
					self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:MiscPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:BindPanel(w,h)
	local p = vgui.Create("DPanel")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		
		function p:update()
			self:Clear(true)
						self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
		end
		
	p:update();
	return p;
end

-------------------------------------------------------------------------------------------------|

function oubhack:Console(w,h)
	local p = vgui.Create("DFrame")
		p:SetSize(w,h)
		p:SetSkin("oubhack")
		p:SetTitle("OubHack Console")
		p:MouseCapture()
		p:MakePopup()
		p:SetVisible(false)
		function p:update()
			self:Clear(true)
			
					self.Minimize = vgui.Create("DButton",self)
				self.Minimize:SetSize(20,20)
				self.Minimize:SetPos((ScrW()/2)-self.Minimize:GetWide(),0)
				self.Minimize:SetText("-")
				self.Minimize.DoClick = function()
					oubhack.Frame:ClosePanel(self)
				end
				
					self.ConsoleScreen = vgui.Create("RichText",self)
				self.ConsoleScreen:SetPos(20,20)
				self.ConsoleScreen:SetSize(ScrW()/2-42,ScrH()/2-60)
				self.ConsoleScreen:SetVerticalScrollbarEnabled(true)
				
					self.InputBox = vgui.Create("DTextEntry",self)
				self.InputBox:SetPos(20,22+self.ConsoleScreen:GetTall())
				self.InputBox:SetSize(self.ConsoleScreen:GetWide()-40,20)
				self.InputBox:SetEditable(true)
				self.InputBox:SetEnterAllowed(true)
				self.InputBox.OnEnter = function()
					local str = self.InputBox:GetValue().. " " 
					local cmd = string.sub(str,1, string.find(str," ",1)-1 )
					local args = string.sub(str,string.len(cmd) + 2 ,string.len(str))
					if cmd == "" then self.ConsoleScreen:AppendText("]\n") return end
					if !table.HasValue( concommand.GetTable() /* replace this with a table of concommand names*/,cmd) then
						self.ConsoleScreen:AppendText("'"..cmd.."' is not a command.\n")
					else
						self.ConsoleScreen:AppendText("]"..cmd.."\n")
						RunConsoleCommand(cmd,args) -- Replace this with whatever you use to run it.
					end
					self.InputBox:SetValue("")
				end
				self.Submit = vgui.Create("DButton",self)
					self.Submit:SetPos(22+self.InputBox:GetWide(),22+self.ConsoleScreen:GetTall())
					self.Submit:SetSize(self.ConsoleScreen:GetWide()-self.InputBox:GetWide()-2,self.InputBox:GetTall())
					self.Submit.DoClick = self.InputBox.OnEnter
					self.Submit:SetText("Submit")

		
		end
		
	p:update();
	return p;
end

function oubhack:Open()
	self.Frame = vgui.Create("oh_settings_tab")
		self.Frame:SetPos(0,0)
		self.Frame:SetSize(ScrW(),100)
		
	self.Frame:AddSheet("Aimbot", self:AimbotPanel(w,h), "gui/silkicons/bomb", "Configure aimbot settings");
	self.Frame:AddSheet("ESP", self:ESPPanel(w,h), "gui/silkicons/bomb", "Add and remove entities from\nthe ESP sensor");
	self.Frame:AddSheet("X-Ray", self:XRayPanel(w,h), "gui/silkicons/bomb", "Change what you can see\nthrough walls");
	self.Frame:AddSheet("HUD", self:HUDPanel(w,h), "gui/silkicons/bomb", "Change Heads Up Display\nsettings");
	self.Frame:AddSheet("Friends", self:FriendsPanel(w,h), "gui/silkicons/bomb", "Add and remove\nOubHack freinds");
	self.Frame:AddSheet("Groups", self:GroupsPanel(w,h), "gui/silkicons/bomb", "Set up player groups");
	self.Frame:AddSheet("Movement", self:MovementPanel(w,h), "gui/silkicons/bomb", "Change movement settings");
	self.Frame:AddSheet("Setups", self:SetupPanel(w,h), "gui/silkicons/bomb", "Load or Save OubHack\nconfigurations");
	self.Frame:AddSheet("Misc", self:MiscPanel(w,h), "gui/silkicons/bomb", "Miscellaneous settings");
	self.Frame:AddSheet("Binds", self:BindPanel(w,h), "gui/silkicons/bomb", "Bind keys to\nOubHack actions");
	self.Frame:AddSheet("Console", self:Console(w,h), "gui/silkicons/bomb", "The oubhack console");
	self.Frame:Update()
		

end

function oubhack:Close()
	if self.Frame then self.Frame:Remove() end
end

function oubhack:ToggleMenu()
	if self.Frame then
		self.Frame:Remove()
		self.Frame = nil;
		gui.EnableScreenClicker(false)
	else
		self:Open()
		gui.EnableScreenClicker(true)
	end
end

concommand.Add("oh_toggle_menu",function() oubhack:ToggleMenu() end)

-------------------------------------------------------------------------------------------------|

