--[[
	menu_plugins/OubHack/oubhack.lua
	Oubliette | (STEAM_0:1:34029133)
	===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
*******************************************************************************/
-- Main

local concommand = concommand
local draw = draw
local render = render
local concommand = concommand
local cvars = cvars
local debug = debug
local ents = ents
local file = file
local hook = hook
local math = math
local spawnmenu = spawnmenu
local string = string
local surface = surface
local table = table
local timer = timer
local util = util
local vgui = vgui

local Angle = Angle
local CreateClientConVar = CreateClientConVar
local CurTime = CurTime
local ErrorNoHalt = ErrorNoHalt
local FrameTime = FrameTime
local GetConVarString = GetConVarString
local GetViewEntity = GetViewEntity
local include = include
local ipairs = ipairs
local LocalPlayer = LocalPlayer
local pairs = pairs
local pcall = pcall
local print = print
local RunConsoleCommand = RunConsoleCommand
local ScrH = ScrH
local ScrW = ScrW
local tonumber = tonumber
local type = type
local unpack = unpack
local ValidEntity = ValidEntity
local Vector = Vector
local _G = _G

local PMD = _R.Player
local VMD = _R.Vector
local EMD = _R.Entity
local CUserCmdMD = _R.CUserCmd
local AMD = _R.Angle

oubhack = {} --------- FUCCCCCCCCCCCKKKKKKKKK YYYYYYYEEEEEEAAAAAAHHHHH, THE START OF THE BEASTLY AWESOMENESS.

include("oubhack_lib.lua") -- Include relevante libraries.
include("oubhack_derma.lua")
include("oubhack_skin.lua")
include("vgui/oh_settings_tab_button.lua")
include("vgui/oh_DOption.lua")
include("vgui/oh_settings_tab.lua")
include("vgui/oh_DToggle.lua")
include("oubhack_anti_cheat_bp.lua")
include("vgui/oh_DPowerToggle.lua")
include("vgui/oh_DSettingsSwitch.lua")
include("oubhack_esp.lua")
include("oubhack_ttt.lua")
include("vgui/oh_DPanelList.lua")
include("vgui/oubhack_aimbot_panel.lua")
include("vgui/oh_DSwitchPanel.lua")
include("vgui/oh_DRadar.lua")
include("vgui/oh_DSwitch.lua")
-- Operations 
oubhack.aimbot_on = false;
oubhack.xray_on = false;
oubhack.triggerbot_on = false
oubhack.wallhack_on = false;
oubhack.hidemode = false;
oubhack.spam_on = false;

-- Groups & friends
oubhack.friends = {}; -- player objests
oubhack.friend_ids = {} -- friends steam ID's
oubhack.groups = {}
oubhack.groups[1] = {Name="None",Mbrs={}}


-- Aimbot 
oubhack.target_npcs = true;
oubhack.target_bots = true;
oubhack.ingore_admins = false;
oubhack.ingore_super_admins = true;
oubhack.attacking = false;
oubhack.notraceweapons = {"weapon_phygsun","gmod_tool","weapon_physcannon"}
oubhack.AimbotTrackKey = IN_ATTACK

oubhack.antisnap = false;
oubhack.antisnap_cllb = false;
oubhack.antisnap_clhb = false;
oubhack.antisnap_hb = 3.6;
oubhack.antisnap_lb = 0;
oubhack.antisnap_speed = 360;

oubhack.group_targeting = false

-- aimbot Priorities 
oubhack.distance_p = 2
oubhack.health_p = 1
oubhack.wepdamage_p = 2
oubhack.rclip_p = 1
oubhack.admin_p = 2
oubhack.superadmin_p = 4
oubhack.player_p = 3
-- Console

oubhack.ConsoleScreenItems = {};

-- GUI

oubhack.Grad_UP = surface.GetTextureID( "gui/gradient_up" )
oubhack.Grad_DOWN = surface.GetTextureID( "gui/gradient_down" )
oubhack.TexGrad_UP = Material("gui/gradient_up")
oubhack.TexGrad_DOWN = Material("gui/gradient_down")
oubhack.bg_main = Color(0,255,0,255)
oubhack.VguiElements = {}

-- Xray & ESP

oubhack.esp_classes = {}

-- Gangsta mode

oubhack.gangsta_angle = Angle(0,5,-90)
oubhack.gangsta_vector = Vector(0,0,7)
oubhack.gangsta_mode = false;

--[[
The scoring system: when deciding if 
we should switch from one player to another
we ask, if it is further away, if it has
more health, etc... It adds a certain amount^^
for each thing it checks for. fr example, 
when deciding if we should shoot the guy
on your right, or the guy on your left, 
it will first check distance, the closer one
get's oubhack.distance_p added to it's "score"
then it runs another check, such as health,
if the one on the left has less health then
the one on the right, it adds oubhack.health_p
to the left's score.

== This information is relevant to my co-coders ==
== If you're reading this because it was leaked, fuck you. ==
--]]

--[[
	You'll see a lot of big ass text. the first one is for fanciness
	the rest seprate certain sections of the code.
]]




/********************************************************************************
888    d8P  8888888888 Y88b   d88P      888888b.  8888888 888b    888 8888888b.       
888   d8P   888         Y88b d88P       888  "88b   888   8888b   888 888  "Y88b      
888  d8P    888          Y88o88P        888  .88P   888   88888b  888 888    888      
888d88K     8888888       Y888P         8888888K.   888   888Y88b 888 888    888      
8888888b    888            888          888  "Y88b  888   888 Y88b888 888    888      
888  Y88b   888            888          888    888  888   888  Y88888 888    888      
888   Y88b  888            888          888   d88P  888   888   Y8888 888  .d88P      
888    Y88b 8888888888     888          8888888P" 8888888 888    Y888 8888888P"       
********************************************************************************/     
oubhack.Binds = {}                                                                                          
-- Letters
oubhack.KeyToEnum = {}
oubhack.KeyToEnum["A"] = KEY_A
oubhack.KeyToEnum["B"] = KEY_B
oubhack.KeyToEnum["C"] = KEY_C
oubhack.KeyToEnum["D"] = KEY_D
oubhack.KeyToEnum["E"] = KEY_E
oubhack.KeyToEnum["F"] = KEY_F
oubhack.KeyToEnum["G"] = KEY_G
oubhack.KeyToEnum["H"] = KEY_H
oubhack.KeyToEnum["I"] = KEY_I
oubhack.KeyToEnum["J"] = KEY_J
oubhack.KeyToEnum["K"] = KEY_K
oubhack.KeyToEnum["L"] = KEY_L
oubhack.KeyToEnum["M"] = KEY_M
oubhack.KeyToEnum["N"] = KEY_N
oubhack.KeyToEnum["O"] = KEY_O
oubhack.KeyToEnum["P"] = KEY_P
oubhack.KeyToEnum["Q"] = KEY_Q
oubhack.KeyToEnum["R"] = KEY_R
oubhack.KeyToEnum["S"] = KEY_S
oubhack.KeyToEnum["T"] = KEY_T
oubhack.KeyToEnum["U"] = KEY_U
oubhack.KeyToEnum["V"] = KEY_V
oubhack.KeyToEnum["W"] = KEY_W
oubhack.KeyToEnum["X"] = KEY_X
oubhack.KeyToEnum["Y"] = KEY_Y
oubhack.KeyToEnum["Z"] = KEY_Z
-- Numbers
oubhack.KeyToEnum["1"] = KEY_1
oubhack.KeyToEnum["2"] = KEY_2
oubhack.KeyToEnum["3"] = KEY_3
oubhack.KeyToEnum["4"] = KEY_4
oubhack.KeyToEnum["5"] = KEY_5
oubhack.KeyToEnum["6"] = KEY_6
oubhack.KeyToEnum["7"] = KEY_7
oubhack.KeyToEnum["8"] = KEY_8
oubhack.KeyToEnum["9"] = KEY_9
oubhack.KeyToEnum["0"] = KEY_0
-- Puncatition
oubhack.KeyToEnum[","] = KEY_COMMA
oubhack.KeyToEnum["."] = KEY_PERIOD
oubhack.KeyToEnum["/"] = KEY_SLASH
oubhack.KeyToEnum[";"] = KEY_SEMICOLON
oubhack.KeyToEnum["'"] = KEY_APOSTROPHE
oubhack.KeyToEnum[ [[\]] ]  = KEY_BACKSLASH
oubhack.KeyToEnum["["] = KEY_LBRACKET
oubhack.KeyToEnum["]"] = KEY_RBRACKET
-- Controls
oubhack.KeyToEnum["RIGHT_CLICK"] = IN_ATTACK2
oubhack.KeyToEnum["LEFT_CLICK"] = IN_ATTACK
oubhack.KeyToEnum["RIGHT_CTRL"] = KEY_RCONTROL
oubhack.KeyToEnum["LEFT_CTRL"] = KEY_LCONTROL
oubhack.KeyToEnum["RIGHT_ALT"] = KEY_RALT
oubhack.KeyToEnum["LEFT_ALT"] = KEY_LALT
oubhack.KeyToEnum["RIGHT_SHIFT"] = KEY_RSHIFT
oubhack.KeyToEnum["LEFT_SHIFT"] = KEY_LSHIFT
oubhack.KeyToEnum["ENTER"] = KEY_ENTER
oubhack.KeyToEnum["UP"] = KEY_UP
oubhack.KeyToEnum["DOWN"] = KEY_DOWN
oubhack.KeyToEnum["LEFT"] = KEY_LEFT
oubhack.KeyToEnum["RIGHT"] = KEY_RIGHT
oubhack.KeyToEnum["TAB"] = KEY_TAB
oubhack.KeyToEnum["BACKSPACE"] = KEY_BACKSPACE
oubhack.KeyToEnum["="] = KEY_EQUAL
oubhack.KeyToEnum["-"] = KEY_MINUS
-- F keys
oubhack.KeyToEnum["F1"] = KEY_F1
oubhack.KeyToEnum["F2"] = KEY_F2
oubhack.KeyToEnum["F3"] = KEY_F3
oubhack.KeyToEnum["F4"] = KEY_F4
oubhack.KeyToEnum["F5"] = KEY_F5
oubhack.KeyToEnum["F6"] = KEY_F6
oubhack.KeyToEnum["F7"] = KEY_F7
oubhack.KeyToEnum["F8"] = KEY_F8
oubhack.KeyToEnum["F9"] = KEY_F9
oubhack.KeyToEnum["F10"] = KEY_F10
oubhack.KeyToEnum["F11"] = KEY_F11
oubhack.KeyToEnum["F12"] = KEY_F12
-- Other
oubhack.KeyToEnum["SCROLL_LOCK"] = KEY_SCROLLLOCK
oubhack.KeyToEnum["SPACE"] = KEY_SPACE
oubhack.KeyToEnum["INS"] = KEY_INSERT
oubhack.KeyToEnum["DEL"] = KEY_DELETE


function oubhack:KeyBindHandler() -- Handles all key binds.
	for k,v in pairs(self.Binds) do
		if input.IsKeyDown(v.BindKey) or LocalPlayer():KeyDown(v.BindKey) then
			if v.DownThinkFunc then v.DownThinkFunc() end
			if !v.CalledKDF then 
				if v.KeyDownFunc then v.KeyDownFunc() end 
				v.CalledKDF = true; 
				v.CalledKRF = false;
			end
		else 
			if v.UpThinkFunc then v.UpThinkFunc() end
			if !v.CalledKRF then 
				if v.KeyUpFunc then v.KeyUpFunc() end 
				v.CalledKDF = false; 
				v.CalledKRF = true;
			end
		end
	end
end

function oubhack:StringToEnum(str)
	if type(str) == "string" then
		for k,v in pairs(self.KeyToEnum) do
			if string.upper(str) == k then
				return v;
			end
		end
	else
		return str;
	end
end

function oubhack:EnumToString(enum)
	if enum == 1 then return "Left Click" end
	for k,v in pairs(self.KeyToEnum) do
		if enum == v then
			print("found, returning  : "..k)
			return k;
		end
	end
	return enum;
end


function oubhack:AddKeyBind(key,downfunc,upfunc,downfuncthink,upfuncthink,name)
	key = self:StringToEnum(key)
	key = tonumber(key) or 0 -- The rest is fail proofed in the handler.
	print(name.." is binding key " .. key)
	self.Binds[name or #self.Binds+1] = {BindKey=key,KeyDownFunc=downfunc,KeyUpFunc=upfunc,DownThinkFunc=downfuncthink,UpThinkFunc=upfuncthink};
end

function oubhack:EditKeyBind(name,newkey)
	newkey = self:StringToEnum(newkey)
	newkey = tonumber(newkey) or 0; 
	for k,v in pairs(self.Binds) do
		if k == name then
			v.BindKey = newkey
		end
	end
end

function oubhack:RemoveKeyBind(name)
	for k,v in pairs(self.Binds) do
		if k == name then
			table.remove(self.Binds,k)
		end
	end
end

hook.Add("CreateMove","KeyBindHandler",function() oubhack:KeyBindHandler() end) -- Called just before information is sent to the server, perfect for key binds.


/******************************************************************
       d8888 8888888 888b     d888 888888b.    .d88888b. 88888888888 
      d88888   888   8888b   d8888 888  "88b  d88P" "Y88b    888     
     d88P888   888   88888b.d88888 888  .88P  888     888    888     
    d88P 888   888   888Y88888P888 8888888K.  888     888    888     
   d88P  888   888   888 Y888P 888 888  "Y88b 888     888    888     
  d88P   888   888   888  Y8P  888 888    888 888     888    888     
 d8888888888   888   888   "   888 888   d88P Y88b. .d88P    888     
d88P     888 8888888 888       888 8888888P"   "Y88888P"     888     
*****************************************************************/


function oubhack:CanTrace() -- This checks for reasons the aimbot SHOULDN'T calculate positions, angles etc..
	if !LocalPlayer():Alive() or !LocalPlayer():GetActiveWeapon():IsValid() then return false end;
	return !table.HasValue(self.notraceweapons,LocalPlayer():GetActiveWeapon():GetClass()) and !(LocalPlayer():GetActiveWeapon():Clip1()<=0) 
end

function oubhack:AimbotCaclualteAngles(cmd) -- Main aimbot function
	local targ = self:GetBestTarget()
	local ply = LocalPlayer()
	
	if ply == targ then
		self.targ_pos = false
		self.targ_ang = Angle(0,0,0)
		return false
	elseif targ:IsValid() and self:CanTrace() then
		-- Group Stuff
		if self.group_targeting then
			print(self:GetGroup(v).target)
			if !self:GetGroup(v).target then return false end
		end
		--Aiming
		local t_pos = targ:GetPos() + targ:OBBCenter()
		local m_pos = ply:EyePos()

		local targ_ang = (t_pos-m_pos):Angle()
		local ang = targ_ang;

		if self.antisnap then
			ang = EMD["EyeAngles"](LocalPlayer());
			local speedp = (10.5/self.antisnap_speed*(math.abs(math.AngleDifference(ang.p,targ_ang.p))));
			local speedy = (10.5/self.antisnap_speed*(math.abs(math.AngleDifference(ang.y,targ_ang.y))));
			if self.antisnap_clhb then
				speedp = math.Clamp(speedp , 0 , tonumber(self.antisnap_hb));
				speedy = math.Clamp(speedy , 0 , tonumber(self.antisnap_hb));
			end
			if self.antisnap_cllb then	
				speedp = math.Clamp(speedp , tonumber(self.antisnap_lb) , speedp);
				speedy = math.Clamp(speedy , tonumber(self.antisnap_lb) , speedy);
			end
			ang.r = 0;
			ang.p = math.ApproachAngle(ang.p,targ_ang.p,speedp);
			ang.y = math.ApproachAngle(ang.y,targ_ang.y,speedy);
		end
		if self.AimbotTrackKey == IN_ATTACK then
			if cmd:KeyDown(IN_ATTACK) then 
				CUserCmdMD["SetViewAngles"](cmd,ang)
			else
			--	self.lastaim = 
			end
		else
			if input.IsKeyDown(self.AimbotTrackKey) then
				CUserCmdMD["SetViewAngles"](cmd,ang)
			else
				-- something else
			end
		end
	else
		-- ooohhh damn
	end

end
hook.Add("CreateMove","AimbotSelectTarget",function(cmd) if !oubhack.hidemode then oubhack:AimbotCaclualteAngles(cmd) end end,-10)



local redlaser = Material("cable/redlaser")
local small_laser = Material("cable/crystal_beam1")

-- function oubhack:NPCXrayPaint()
	-- local ply = LocalPlayer()
	-- for k,v in pairs(self:GetNPCS()) do
		-- cam.Start3D( EyePos(), EyeAngles()); 
				-- if ((v:IsPlayer() and v:Alive()) or v:IsWeapon() or v:IsNPC() or v:IsVehicle() or v:GetClass() == "prop_physics") then
					-- cam.IgnoreZ( true );
						
						-- render.ResetModelLighting( 1, 1, 1 );
						
						
						-- render.SetMaterial(small_laser)
						
						-- local trace = util.GetPlayerTrace(ply)
						-- local trres = util.TraceLine(trace)
						
						-- if self.targ_pos and self.aimbot_on then
							-- render.SetMaterial(redlaser)
							-- render.DrawBeam(ply:GetViewModel():GetAttachment("1").Pos,self.targ_pos,1,1,1,Color(255,0,0,255))
						-- else
							-- render.DrawBeam(ply:GetViewModel():GetAttachment("1").Pos,trres.HitPos,1,1,1,Color(128,0,128,255))
						-- end
						

						-- if v:IsPlayer() then
							-- local trace = util.GetPlayerTrace(v)
							-- local trres = util.TraceLine(trace)
							-- if v:GetActiveWeapon():IsValid() and v:GetActiveWeapon():GetAttachment("2").Pos then 
								-- render.DrawBeam(v:GetActiveWeapon():GetAttachment("2").Pos,trres.HitPos,2,1,1,Color(255,255,255,255))
							-- end
						-- end
						-- if v:IsWeapon() then
						-- render.SetColorModulation( 1, 255, 1 );
						-- v:DrawModel()
						-- end
						-- if v:IsPlayer() then
						-- render.SetColorModulation( 255, 1, 1 );						
						-- v:DrawModel();
						-- end
						
						-- render.SuppressEngineLighting( false );
					-- cam.IgnoreZ( false );
				-- end
			-- end
		-- cam.End3D(); 
	-- end
-- end
-- hook.Add("HUDPaint","AimbotX-RayPaint",function() if oubhack.xray_on and !oubhack.hidemode then oubhack:NPCXrayPaint() end end)
	
function oubhack:CreateMove(cmd,x,y,angles) -- Handles snapping of aim-angles, and triggerbot	
	local ply = LocalPlayer()
	if !self:CanTrace() then return false end
	if (self.triggerbot_on and !oubhack.hidemode and self.vis_targs and #self.vis_targs > 0) then
		-- Activate the triggerbot, how we do this is decided in here
		if !ply:GetActiveWeapon().Primary then -- We can't tell if it's automatic or not, so were just gonna speed tap it
			if self.attacking then 
				RunConsoleCommand("-attack")
				self.attacking = false;
			else
				RunConsoleCommand("+attack")
				self.attacking = true;
			end
		else -- We can tell if it's automatic, so we will hold it down, if it is, and tap it, if it's not.
			-- For future. I'm leaving this here
			if self.attacking then 
				RunConsoleCommand("-attack")
				self.attacking = false;
			else
				RunConsoleCommand("+attack")
				self.attacking = true;
			end
		end
		
	else
		if self.attacking then
			RunConsoleCommand("-attack")
			self.attacking = false;
		end
	end
end
hook.Add("CreateMove","OH_CM",function(cmd,x,y,angles) oubhack:CreateMove(cmd,x,y,angles) end)

function oubhack:CompareTargetPriority(targ,targ2)
	if not targ:IsValid() then return false end;
	if not targ2:IsValid() then return true end;
	-- Setup a "score"
	local score1 = 0;
	local score2 = 0;
	-- Add some data to compare
	local dist = targ:GetPos():Distance(LocalPlayer():GetPos());
	local dist2 = targ2:GetPos():Distance(LocalPlayer():GetPos());
	
	local h1 = targ:Health();
	local h2 = targ2:Health();
	
	if dist > dist2 then score2 = score2 + self.distance_p else score = score + self.distance_p end 
	if h1 < h2 then score = score + self.health_p else score2 = score2 + self.health_p end 
	if targ:IsPlayer() and targ2:IsPlayer() and targ:GetActiveWeapon().Primary and targ2:GetActiveWeapon().Primary then -- only run these checks if they're active weapon is valid.
		if targ:GetActiveWeapon().Primary.Damage > targ2:GetActiveWeapon().Primary.Damage then score = score + self.wepdamage_p else score2 = score2 + self.wepdamage_p end 
		if targ:GetActiveWeapon():Clip1() > targ2:GetActiveWeapon():Clip1() then score = score + self.rclip_p else score2 = score2 + self.rclip_p end 
	end
	if targ:IsPlayer() and !targ2:IsPlayer() then score = score + self.player_p elseif targ2:IsPlayer() and !targ:IsPlayer() then score2 = score2 + self.player_p end
	
	if targ:IsAdmin() and !targ:IsSuperAdmin() then score2 = score2 + self.admin_p elseif targ:IsSuperAdmin() then score2 = score2 + self.superadmin_p end
	if targ2:IsAdmin() and !targ2:IsSuperAdmin() then score = score + self.admin_p elseif targ2:IsSuperAdmin() then score = score + self.superadmin_p end
	return score > score2;
end

function oubhack:CalculateVisibleTargets() 
	
	local targ = LocalPlayer();
	local bone = "ValveBiped.Bip01_Head1"
	self.vis_targs = {};
	for k,v in pairs(self:GetTargets()) do
		local trace = {};
		local boneid = v:LookupBone(bone);
		local vehicle = LocalPlayer():GetVehicle() or LocalPlayer();
		trace.start = EyePos();
		trace.endpos = v:GetBonePosition(boneid);
		trace.filter = {LocalPlayer(),vehicle};
		trace.mask = MASK_SHOT;
		
		local traceline = util.TraceLine(trace);
		local ent = traceline.Entity
		
		if table.HasValue(self:GetTargets(),ent) then
			self.vis_targs[#self.vis_targs+1] = ent;
		end
	end
end
hook.Add("Think","OH-Calculate-VisTargs",function() if (oubhack.triggerbot_on or oubhack.wallhack_on or oubhack.xray_on) and !oubhack.hidemode then oubhack:CalculateVisibleTargets() end end)

function oubhack:GetBestTarget() 
	local targ = LocalPlayer();
	local ply = LocalPlayer();
	local bone = "ValveBiped.Bip01_Head1"
	for k,v in pairs(self:GetTargets()) do
		if targ == ply or self:CompareTargetPriority(v,targ) then
			local trace = {};
			local boneid = v:LookupBone(bone);
			local vehicle = LocalPlayer():GetVehicle() or LocalPlayer();
			trace.start = EyePos();
			trace.endpos = v:GetBonePosition(boneid);
			trace.filter = {LocalPlayer(),vehicle};
			trace.mask = MASK_SHOT;
			
			local traceline = util.TraceLine(trace);
			local ent = traceline.Entity
			if ent:IsValid() and ent == v then return v end;
		end
	end
	return targ;
end

function oubhack:Visible(ent)
	if not self.vis_targs then return false end;
	return !table.HasValue(self.vis_targs,ent)
end

/********************************************************************************************************************************************
 .d8888b.         d8888 888b    888  .d8888b.   .d8888b. 88888888888     d8888      888b     d888  .d88888b.  8888888b.  8888888888 
d88P  Y88b       d88888 8888b   888 d88P  Y88b d88P  Y88b    888        d88888      8888b   d8888 d88P" "Y88b 888  "Y88b 888        
888    888      d88P888 88888b  888 888    888 Y88b.         888       d88P888      88888b.d88888 888     888 888    888 888        
888            d88P 888 888Y88b 888 888         "Y888b.      888      d88P 888      888Y88888P888 888     888 888    888 8888888    
888  88888    d88P  888 888 Y88b888 888  88888     "Y88b.    888     d88P  888      888 Y888P 888 888     888 888    888 888        
888    888   d88P   888 888  Y88888 888    888       "888    888    d88P   888      888  Y8P  888 888     888 888    888 888        
Y88b  d88P  d8888888888 888   Y8888 Y88b  d88P Y88b  d88P    888   d8888888888      888   "   888 Y88b. .d88P 888  .d88P 888        
 "Y8888P88 d88P     888 888    Y888  "Y8888P88  "Y8888P"     888  d88P     888      888       888  "Y88888P"  8888888P"  8888888888, bitches
*********************************************************************************************************************************************/                                                                                            
                                                                                                                                    
                                                                                                                                    
                                                                    
                                                                                                                                                                                                                     
                                                                                                                                                       

function oubhack:PreApplyGangstaSettings( ent )
	ent:SetAngles(ent:GetAngles()+self.gangsta_angle)
	ent:SetPos(ent:GetPos()-self.gangsta_vector)
end


function oubhack:PostApplyGangstaSettings( ent )
	ent:SetAngles(ent:GetAngles()+self.gangsta_angle)
	ent:SetPos(ent:GetPos()-self.gangsta_vector)
end
	
hook.Add("PreDrawViewModel","oh_gangsta_apply_settings_pre",function(ent) if oubhack.gangsta_mode then oubhack:PreApplyGangstaSettings(ent) end end)
hook.Add("PostDrawViewModel","oh_gangsta_apply_settings_post",function(ent) if oubhack.gangsta_mode then oubhack:PostApplyGangstaSettings(ent) end end)

local SetButtons = _R.CUserCmd.SetButtons
function oubhack:ClientSideNoClipAVH(cmd)
	if self.CSNC_on then
	    local offset = Vector( 0, 0, 0 )
	    local ang = LocalPlayer():EyeAngles()
		    if cmd:KeyDown(IN_FORWARD) then offset = offset + ang:Forward() end
		    if cmd:KeyDown(IN_BACK) then offset = offset - ang:Forward() end
		    if cmd:KeyDown(IN_MOVERIGHT) then offset = offset + ang:Right() end
		    if cmd:KeyDown(IN_MOVELEFT) then offset = offset - ang:Right() end
		    if cmd:KeyDown(IN_JUMP) then offset = offset + ang:Up() end
		    if cmd:KeyDown(IN_DUCK) then offset = offset - ang:Up() end
	    offset = offset:GetNormal() * FrameTime() * 500
	    if ( cmd:KeyDown( IN_SPEED ) ) then offset = offset * 2 end
	    self.CSNCVector = (self.CSNCVector or LocalPlayer():GetPos()) + offset;
	    cmd:SetForwardMove( 0 )
	    cmd:SetSideMove( 0 )
	    cmd:SetUpMove( 0 )
	    SetButtons( cmd, 0 )
    end
end
hook.Add("CreateMove","oh-csnc_avh",function(cmd) oubhack:ClientSideNoClipAVH(cmd) end)

local function ClientSideNoClipCV(ply,pos,angles,fov)
	local view = {}
	if oubhack.CSNC_on then
		view.angles = angles
		view.origin = oubhack.CSNCVector or pos
		view.fov = oubhack.CSNCFOV or fov
	end

	return view
end
hook.Add("CalcView","oh-csnc_cv",ClientSideNoClipCV)


/********************************************************************************************************************************************
 .d8888b.  8888888888 88888888888 88888888888 8888888 888b    888  .d8888b.   .d8888b.       888b     d888 8888888888 888b    888 888     888 
d88P  Y88b 888            888         888       888   8888b   888 d88P  Y88b d88P  Y88b      8888b   d8888 888        8888b   888 888     888 
Y88b.      888            888         888       888   88888b  888 888    888 Y88b.           88888b.d88888 888        88888b  888 888     888 
 "Y888b.   8888888        888         888       888   888Y88b 888 888         "Y888b.        888Y88888P888 8888888    888Y88b 888 888     888 
    "Y88b. 888            888         888       888   888 Y88b888 888  88888     "Y88b.      888 Y888P 888 888        888 Y88b888 888     888 
      "888 888            888         888       888   888  Y88888 888    888       "888      888  Y8P  888 888        888  Y88888 888     888 
Y88b  d88P 888            888         888       888   888   Y8888 Y88b  d88P Y88b  d88P      888   "   888 888        888   Y8888 Y88b. .d88P 
 "Y8888P"  8888888888     888         888     8888888 888    Y888  "Y8888P88  "Y8888P"       888       888 8888888888 888    Y888  "Y88888P"  
********************************************************************************************************************************************                                                                                                                                              
-- This part took me a long time, if ANYONE takes this code, I will find you, and rip your balls off, comprede?                                                                                                                                        
