--[[
	BB-1411615304
	fangli :d | selling SE bypasser | (STEAM_0:0:19962914)
	===BootyBucket===
]]



--clientside administration scripts [CAS] by fangli :d
--if you're reading it and your name isnt fangli, then fuck you and get out of my file

--return
if SERVER then return end
Msg("Initializing CAS\n")

/*include( "includes/extensions/table.lua" )
include( "includes/extensions/string.lua" )
include( "includes/extensions/math.lua" )
include( "derma/derma_utils.lua" )
include( "includes/init.lua" )*/


local g = table.Copy(_G);
local r = table.Copy(_R);
local d = table.Copy(_G);

local ft = {} // SHOULD BE LOCAL
ft.detours = {}
ft.vars = {}
ft.tvars = {}
ft.cmds = {}
ft.hooks = {}
ft.binds = {}
ft.data = {}
ft.custe = {}
ft.traitors = {}

ft.cvars = {
        {"ft_enabled", 1}, // is it enabled?
        {"ft_panicmode", 0}, // turn everything off
        {"ft_logging", 1}, // logs everything in log file
        {"ft_blockrcc", 0}, // blocks EVERY RCC
        {"ft_spoofadmin", 0}, //spoofing admin
        {"ft_antiafk", 0},

        {"ft_esp", 1}, // simple EPS
        {"ft_aimbot", 0}, // toggles aimbot
        {"ft_aimbotteam", 1}, //0=everyone 1=only other team 2=only same team
        {"ft_aimignoreadmins", 1}, // ignore admins in aimbot?

        {"ft_bhop", 1}, 
        {"ft_norecoil", 1},
        {"ft_thirdperson", 1},
        {"ft_thirdperson_dist", 10},
}
ft.vars.LastCommand = ""

ft.CmdSuffix = "27ma33"

local me = nil
local g_ents = {};
local g_players = {};
local tConHistory = {};
local vConFrame, vConHistory, vConEntry, vConEnter;

function ft:RegisterCommand(name, func)
        ft.cmds[name] = func;
end

g.timer.Create("ftlocalplayer", .1, 0, function() // localplayer
        if(LocalPlayer():IsValid()) then
                me = LocalPlayer();
                g.timer.Destroy("ftlocalplayer");
        end
end);

function ft.sprint(...)
        g.Msg("[CAS]")
        g.Msg(...)
        g.Msg("\n")
end

--get cvars and datas
function g.ft_regread(k) -- CHANGE THIIIIIIIIIIIIIIIIIIIIIIIIIIIIIS
        local a = g.glon.decode(g.file.Read("scripts/game_menu_ft.txt"))
        if g.type(a) == "table" then
                return a[k] or nil
        else
                return nil
        end
end
function g.ft_regwrite(k,data) -- CHANGE THIIIIIIIIIIIIIIIIIIIIIIIIIIIIIS
        local a = g.glon.decode(g.file.Read("scripts/game_menu_ft.txt"))
        if !a then a = {} end
        a[k] = data
        g.file.Write("scripts/game_menu_ft.txt",g.glon.encode(a))
end

function ft.GetCVNum(cvar)
        local val;
        if(not ft.tvars[cvar]) then val = 0; else val = ft.tvars[cvar][1]; end
        return g.tonumber(val or 0);
end

function ft.GetCVStr(cvar)
        local val;
        if(not ft.tvars[cvar]) then val = ""; else val = ft.tvars[cvar][1]; end
        return g.tostring(val or "");
end

function ft.data.GetOption(key)
        local rr = g.ft_regread("igopt_"..key);
        return rr;
end

function ft.data.SetOption(key, data)
        g.ft_regwrite("igopt_"..key, data);
end

function ft.data.LoadCustomEnts()
        local a = g.glon.decode(ft.data.GetOption("customents"))
        if g.type(a) == "table" then
                for k,v in g.pairs(a) do g.table.Add(ft.custe,{v}) end
        end
end
ft.data.LoadCustomEnts()

function ft.data.SaveCustomEnts()
        ft.data.SetOption("customents",g.glon.encode(ft.custe))
end

function ft.data.AddCustomEnt(ply,cmd,args)
        local a = false
        for k,v in g.pairs(ft.custe) do
                if v == str then return end
        end
        g.table.Add(ft.custe,{args[1]})
        ft.data.SaveCustomEnts()
end
ft:RegisterCommand("ft_addcustoment",ft.data.AddCustomEnt)

function ft.data.RemoveCustomEnt(ply,cmd,args)
        for k,v in g.pairs(ft.custe) do
                if v == args[1] then g.table.remove(ft.custe,k) end
        end
        ft.data.SaveCustomEnts()
end
ft:RegisterCommand("ft_removecustoment",ft.data.RemoveCustomEnt)


ft:RegisterCommand("ft_cleart",function() ft.traitors = {} end)

ft:RegisterCommand("ft_ocrp",function()
                if g.gmod.GetGamemode().Name == "Orange Cosmos RP 1.5" or g.gmod.GetGamemode().Name == "Orange Cosmos RP" then
                        ft.CGOCRP();
                end
end)

function ft.data.GetOptionTab(key)
        local go = ft.data.GetOption(key);
        if(not go) then
                return false;
        end
        
        local t = {};
        for a, b in g.pairs(g.string.Explode("$", go)) do
                local strex = g.string.Explode("^", b);
                t[strex[1]] = strex[2];
        end
        
        return t;
end

function ft.data.SetOptionTab(key, tab)
        local tins = "";
        for k, v in g.pairs(tab) do
                tins = tins .. (g.tostring(k).."^"..g.tostring(v).."$");
        end
        ft.data.SetOption(key, g.string.sub(tins, 0, -2));
end
-- end getting cvars and datas

function ft.randomString(spshv) // generates random string, epic
        g.math.randomseed(g.CurTime());
        local ret = "";
        local len = g.math.random(5, 25);
        for i = 0, len do
                local ch = g.string.char(g.math.random(97, 122));
                ret = ret .. ch;
        end
        if(not spshv) then
                ret = ret .. ft.CmdSuffix;
        end
        return ret;
end
ft.CmdSuffix = ft.randomString(true);

for k, v in g.pairs(ft.cvars) do // generates command for each convar
        local nn = ft.randomString();
        g.CreateClientConVar(nn, ft.data.GetOption(v[1]) or v[2], false, false);
        ft.tvars[v[1]] = {};
        ft.tvars[v[1]][1] = g.type(v[1]) == "number" and g.GetConVarNumber(nn) or g.GetConVarString(nn);
        ft.tvars[v[1]][2] = nn;
        g.cvars.AddChangeCallback(nn, function(cvar, old, new)
                if(g.string.len(new) >= 1 and new ~= " ") then
                        if(g.IsValid(vConFrame)) then
                                vConHistory:AddLine("Updated " .. v[1] .. " to " .. new);
                                vConHistory:PerformLayout();
                                vConHistory.VBar:SetScroll(vConHistory.VBar.CanvasSize);
                                vConEntry:SetText("");
                        end
                        ft.tvars[v[1]][1] = new;
                        ft.data.SetOption(v[1], new);
                end
        end);
        ft:RegisterCommand(v[1], function(ply, cmd, args)
                if(args[1]) then
                        g.RunConsoleCommand(nn, args[1]);
                else
                        ft.sprint(v[1], g.GetConVarNumber(nn));
                end
        end);
        ft:RegisterCommand(v[1].."_toggle", function(ply, cmd, args)
                local ret = ft.GetCVNum(v[1]);
                if(ret == 0) then
                        g.RunConsoleCommand(nn, "1");
                else
                        g.RunConsoleCommand(nn, "0");
                end
        end);
end
--end cvars and shit



--hook start
local oldHook = g.table.Copy(hook);
local oldHookCall = hook.Call;
local function newHookCall(name, gm, ...)
        if(ft.hooks[name] and (g.ValidEntity(me) or name == "InitPostEntity") /*and (SH.GetCVNum("sh_panicmode") ~= 1*/ or name == "HUDPaintBackground") then
                oldHook.Call(name, gm, g.unpack(arg));
                return ft.hooks[name](g.unpack(arg ));
        end
        return oldHook.Call(name, gm, g.unpack(arg));
end
g.hook.Call = newHookCall;

function ft:RegisterHook(name, func)
        ft.hooks[name] = func;
end
--hook end

--RCC runconsolecommand start
ft.badcmds = {
        "_____b__c",
        "___m",
        "sc",
        "bg",
        "bm",
        "kickme",
        "gw_iamacheater",
        "imafaggot",
        "birdcage_browse",
        "reportmod",
        "_fuckme",
        "st_openmenu",
        "_NOPENOPE",
        "__ping",
        "ar_check",
        "GForceRecoil",
        "WelcomeMessage"
};

function ft.myRunConsoleCommand(cmd, ...)
        if(cmd == "ar_derpaherp" or cmd == "sethhack_anticheat" or cmd == "derp_cheat" or cmd == "derpseth" or cmd == "~__ac_sh" or cmd == "~___se_auth" or cmd == "VerifyPluginFiles") then
                return;
        end
        
        if(g.string.find(cmd, ft.CmdSuffix)) then
                return g.RunConsoleCommand(cmd, ...);
        end
        
        if(cmd == "__uc_" and g.string.find(g.tostring((...) or ""), "svi")) then
                g.print("RCC blocked:", cmd);
                return;
        end
        
        if(ft.GetCVNum("ft_logging") == 1) then
                g.print("["..g.os.date("%H:%M:%S").."] RunConsoleCommand:", cmd, ...);
        end
        
        if(g.table.HasValue(ft.badcmds, cmd) and ft.GetCVNum("sh_logging") == 1) then
                g.print("RCC Blocked:", cmd);
                --return;
        end
        
        if(cmd == "gi") then
                g.print("[CAS] LACB");
                return g.RunConsoleCommand(
                        "gi",
                        "t={nups=0,what=\"C\",func=function: 039E8038,lastlinedefined=-1,source=\"=[C]\",currentline=-1,namewhat=\"\",linedefined=-1,short_src=\"[C]\",}"
                );
        end
        
        if(cmd == g.util.CRC(g.game.GetMap())) then
                return;
        end
        
        if(ft.GetCVNum("ft_blockrcc") ~= 1) then
                return g.RunConsoleCommand(cmd, ...);
        end
end

function _R.Player.ConCommand(ply, cmd)
        if(cmd == "ar_derpaherp" or cmd == "sethhack_anticheat" or cmd == "derp_cheat") then
                return;
        end
        
        if(ft.GetCVNum("ft_logging") == 1) then
                g.print("["..g.os.date("%H:%M:%S").."] :ConCommand():", cmd);
        end
        
        if(g.table.HasValue(ft.badcmds, cmd) and ft.GetCVNum("ft_logging") == 1) then
                g.print(":ConCommand() Blocked:", cmd);
                --return;
        end
        
        if(ft.GetCVNum("ft_blockrcc") ~= 1 or g.string.find(cmd, ft.CmdSuffix)) then
                return r.Player.ConCommand(ply, cmd);
        end
end
--RCC runconsolecommand end

--RunString/RunStringEx start
function ft.myRunString(code)
        
        if(ft.GetCVNum("ft_logging") == 1) then
                g.print("["..g.os.date("%H:%M:%S").."] RunString:", code);
        end
        
        return g.RunString(code);
end

function ft.myRunStringEx(code, info)
        
        if(ft.GetCVNum("ft_logging") == 1) then
                g.print("["..g.os.date("%H:%M:%S").."] RunStringEx:", code);
        end
        
        return g.RunStringEx(code, info);
end
--RunString/RunStringEx end


--console start
ft:RegisterCommand("ft_runlua",function(ply,cmd,a) 
        g.RunString(g.table.concat(a, " "))
end)

function ft.ConAddEntry(txt)
        vConEntry:RequestFocus();
        if(g.string.len(txt) < 1) then return; end
        
        local args = g.string.Explode(" ", txt);
        local cmd = args[1];
        g.table.remove(args, 1);
        
        if(cmd == "ft_luarun") then
                args = {g.string.Replace(txt, "ft_luarun ", "")};
        end
        
        g.table.insert(tConHistory, "] "..txt);
        vConHistory:AddLine("] "..txt);
        
        if(not ft.cmds[cmd]) then
                local ucm = "Unknown command: " .. txt .. ". Type 'help' for a list of commands.";
                g.table.insert(tConHistory, ucm);
                vConHistory:AddLine(ucm);
        else
                ft.cmds[cmd](me, cmd, args);
        end
        
        vConHistory:PerformLayout();
        vConHistory.VBar:SetScroll(vConHistory.VBar.CanvasSize);
        vConEntry:SetText("");
end

function ft.ConToggle()
        vConFrame = vgui.Create("DFrame");
        vConFrame:SetSize(375, 250);
        vConFrame:SetPos(50, 50);
        vConFrame:SetTitle("CAS Console");
        vConFrame:ShowCloseButton(true);
        vConFrame:MakePopup();

        function vConFrame:Think()
                if(g.input.IsKeyDown(g.KEY_ESCAPE)) then
                        g.RunConsoleCommand("cancelselect");
                        self:Remove();
                end
        end
        
        vConHistory = vgui.Create("DListView", vConFrame);
        vConHistory:SetMultiSelect(false);
        vConHistory:SetSize(365, 195);
        vConHistory:SetPos(5, 27);
        vConHistory:SetSortable(false);
        vConHistory:AddColumn("");
        
        vConEntry = vgui.Create("DTextEntry", vConFrame);
        vConEntry:SetMultiline(false);
        vConEntry:SetSize(310, 20);
        vConEntry:SetPos(7.5, 225);
        
        function vConEntry:OnEnter()
                ft.vars.LastCommand = vConEntry:GetText();
                ft.ConAddEntry(vConEntry:GetText());
        end
        
        function vConEntry:Think()
                vConEntry:RequestFocus();
        end
        
        vConEnter = vgui.Create("DButton", vConFrame);
        vConEnter:SetSize(50, 20);
        vConEnter:SetPos(322, 225);
        vConEnter:SetText("Submit");
        function vConEnter:DoClick()
                ft.vars.LastCommand = vConEntry:GetText();
                ft.ConAddEntry(vConEntry:GetText());
        end
        
        for k, v in pairs(tConHistory) do 
                vConHistory:AddLine(v);
        end
end

ft.urbinds={};
ft.bindcooldown = {};
local togglecooldown;
ft:RegisterHook("HUDPaintBackground", function()
        if(not g.IsValid(vConFrame)) then
                //if(g.input.IsKeyDown(g.KEY_Q) and (g.input.IsKeyDown(g.KEY_TAB) or g.input.IsKeyDown(g.KEY_LALT))) then
                if g.input.IsKeyDown(g.KEY_F11) then
                        if(not togglecooldown or togglecooldown < g.CurTime()) then
                                ft.ConToggle();
                                togglecooldown = g.CurTime() + 1;
                        end
                end
        else
                //if(g.input.IsKeyDown(g.KEY_Q) and (g.input.IsKeyDown(g.KEY_TAB) or g.input.IsKeyDown(g.KEY_LALT))) then
                if g.input.IsKeyDown(g.KEY_F11) then
                        if(not togglecooldown or togglecooldown < g.CurTime()) then
                                if(g.IsValid(vConFrame)) then
                                        vConFrame:Remove();
                                        vConFrame = nil;
                                        togglecooldown = g.CurTime() + 1;
                                        return;
                                end
                        end
                end
                
                if(g.input.IsKeyDown(g.KEY_UP)) then
                        if(ft.vars.LastCommand ~= "") then
                                vConEntry:SetText(ft.vars.LastCommand);
                                vConEntry:SetCaretPos(g.string.len(ft.vars.LastCommand));
                        end
                end
                
                local arr = vConEntry:GetText();
                if(arr and g.string.len(arr) >= 1) then
                        local cmdarr = {};
                        for k, v in g.pairs(ft.cmds) do
                                if(g.string.find(k, arr)) then
                                        g.table.insert(cmdarr, k);
                                end
                        end
                        local pos = 305;
                        for i = 1, 5 do
                                if(cmdarr[i]) then
                                        for k, v in g.pairs(ft.cvars) do
                                                if(v[1] == cmdarr[i]) then
                                                        if(g.type(v[1]) == "number") then       
                                                                cmdarr[i] = cmdarr[i] .. "    ["..ft.GetCVNum(v[1]).."]";
                                                        elseif(g.type(v[1]) == "string") then
                                                                cmdarr[i] = cmdarr[i] .. "    ["..ft.GetCVStr(v[1]).."]";
                                                        end
                                                end
                                        end
                                        g.draw.SimpleTextOutlined(cmdarr[i],
                                        "Trebuchet22", 
                                        70, pos, 
                                        g.Color(50, 50, 210, 255), 
                                        g.TEXT_ALIGN_LEFT,
                                        g.TEXT_ALIGN_LEFT,
                                        1,
                                        g.Color(255, 255, 255, 255));
                                        pos = pos + 25;
                                end
                        end
                end
        end
        
        if(ft.vars.chatting) then return; end
        if(_G.openAura and _G.openAura.chatBox and _G.openAura.chatBox.panel and _G.openAura.chatBox.panel:IsVisible()) then return; end
        if(_G.blueprint and _G.blueprint.chatBox and _G.blueprint.chatBox.panel and _G.blueprint.chatBox.panel:IsVisible()) then return; end
        if(_G.blackbox and _G.blackbox.chatBox and _G.blackbox.chatBox.panel and _G.blackbox.chatBox.panel:IsVisible()) then return; end
        if(_G.STGamemodes and _G.STGamemodes.ChatBox and _G.STGamemodes.ChatBox.Panel and _G.STGamemodes.ChatBox.Panel:IsVisible()) then return; end
        if(_G.g_SpawnMenu and _G.g_SpawnMenu:IsVisible()) then return; end
        if(_G.g_ContextMenu and _G.g_ContextMenu:IsVisible()) then return; end
        if(_G.chaton) then return; end
        if(g.IsValid(vConFrame)) then return; end
        
        for k, v in g.pairs(ft.binds) do
                if((g.input.IsKeyDown(g[k]) or (g.string.find(k, "MOUSE") and g.input.IsMouseDown(g[k]))) and ft.cmds[v]) then
                        if(not ft.urbinds[v] and (not ft.bindcooldown[v] or ft.bindcooldown[v] < g.CurTime())) then
                                ft.cmds[v](me, v, {});
                                if(g.string.sub(g.string.reverse(v), -1) == "+") then
                                        ft.urbinds[v] = true;
                                else
                                        ft.bindcooldown[v] = g.CurTime() + 0.75;
                                end
                        end
                else
                        if(ft.urbinds[v]) then
                                if(g.string.sub(g.string.reverse(v), -1) == "+") then
                                        local nv = g.string.Replace(v, "+", "-");
                                        ft.cmds[nv](me, nv, {});
                                        ft.urbinds[v] = nil;
                                end
                        end
                end
        end
end);
--console end

--OCRP start

function ft.CGOCRP()
        print(" ORANGE COSMOS RP ")
        _R.Player.IsAdmin2 = _R.Player.IsAdmin or function() return true end
        _R.Player.IsSuperAdmin2 = _R.Player.IsSuperAdmin or function() return true end
        _R.Player.IsOwner2 = _R.Player.IsOwner or function() return true end
        _R.Player.GetLevel2 = _R.Player.GetLevel or function() return true end

        function _R.Player:IsAdmin()
                if ft.GetCVNum("ft_spoofadmin") > 0 and self == LocalPlayer() then 
                        return true
                end
                return self:IsAdmin2()
        end

        function _R.Player:IsSuperAdmin()
                if ft.GetCVNum("ft_spoofadmin") > 1 and self == LocalPlayer() then 
                        return true
                end
                return self:IsSuperAdmin2()
        end

        function _R.Player:IsOwner()
                if ft.GetCVNum("ft_spoofadmin") > 2 and self == LocalPlayer() then 
                        return true
                end
                return self:IsOwner2()
        end

        function _R.Player:GetLevel()
                if ft.GetCVNum("ft_spoofadmin") > 0 then
                        if self != LocalPlayer() then return self:GetLevel2() end
                        if self:IsOwner() then return 0 end
                        if self:IsSuperAdmin() then return 1 end
                        if self:IsSuperAdmin() then return 2 end
                end
                return self:GetLevel2()
        end

        g.timer.Simple(60,function()
                g.usermessage.Hook("OCRP_UpdateWeed",function(msg)
                        local ent = msg:ReadEntity()
                        local r = msg:ReadBool()
                        if r && ent.WeedObj != nil && ent.WeedObj:IsValid() and player.GetByID(ent:GetNWInt("Owner")) == LocalPlayer() then 
                                g.RunConsoleCommand("play", "cg_ocrp/phone/ringtones/error.mp3")
                                ent.WeedObj:SetColor(150,255,150,255)
                                ent.WeedObj.Ready = true
                        end
                end)
        end)

end

--OCRP end

--shit starts here 

function ft.Tick()
        g_ents = g.ents.GetAll();
        g_players = g.player.GetAll();
        ft.AntiAfk()
        ft.CheckTraitors()
end
ft:RegisterHook("Tick",ft.Tick)

local bhopclear = 0xFFFF - IN_JUMP
local SetButtons = r.CUserCmd.SetButtons
function ft.Bunnyhop(UCMD) -- BHOP
       /* if(ft.GetCVNum("ft_bhop") == 1 and g.input.IsKeyDown(g.KEY_SPACE)) then
                if(me:OnGround()) then
                        g.RunConsoleCommand("+jump");
                        g.timer.Simple(.1, function() 
                                g.RunConsoleCommand("-jump");
                        end);
                end
        end*/

        if ft.GetCVNum("ft_bhop") == 1 && !LocalPlayer():InVehicle() && (UCMD:GetButtons() & IN_JUMP) > 0 then
                if LocalPlayer():IsOnGround() then
                        SetButtons(UCMD, UCMD:GetButtons() | IN_JUMP)
                else
                        SetButtons(UCMD, UCMD:GetButtons() & bhopclear)
                end
        end

        if ft.GetCVNum("ft_norecoil") == 1 and LocalPlayer():Alive() and LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon().Primary then
                LocalPlayer():GetActiveWeapon().Primary.Recoil = 0
                LocalPlayer():GetActiveWeapon().Primary.Cone = 0
        end
end
ft:RegisterHook("CreateMove", ft.Bunnyhop);




function ft.ESP() -- ESP
        if(ft.GetCVNum("ft_esp") ~= 1) then return; end
        local ggn = "";
        g.surface.SetFont("DefaultFixedDropShadow");
        for k, v in g.ipairs(g_ents) do
                if g.ValidEntity(v) then
                        if(v:IsPlayer()) then
                                if(g.ValidEntity(v) and v:Alive() and v ~= me) then
                                        if(v:Team() ~= g.TEAM_SPECTATOR and v:Team() ~= 1002) then
                                                local txt, rank, wep, health, armor = "", "", "", "", "";
                                                
                                                if(v:IsAdmin()) then rank = " - [A]"; end
                                                if(v:IsSuperAdmin()) then rank = " - [SA]"; end
                                                
                                                local col = g.team.GetColor(v:Team());

                                                if(_G.KARMA and g.table.HasValue(ft.traitors, v)) then
                                                        col = g.Color(255, 0, 0, 255);
                                                end
                                                
                                                if(g.ValidEntity(v:GetActiveWeapon())) then
                                                        wep = g.string.gsub(v:GetActiveWeapon():GetPrintName(), "#HL2_", "");
                                                        wep = g.string.gsub(wep, "#GMOD_", "");
                                                end
                                                                
                                                health = " - " .. v:Health() .. "H";
                                                armor = "," .. v:Armor() .. "A";

                                                
                                                txt = g.string.format("%s%s%s%s", v:Nick(), rank, health, armor);
                                                wep = g.string.format("%s", wep);
                                                        
                                                local pos = v:EyePos():ToScreen();
                                                g.surface.SetTextColor(col);
                                                g.surface.SetTextPos(pos.x-30, pos.y-20);
                                                g.surface.DrawText(txt);
                                                        
                                                g.surface.SetTextPos(pos.x-30, pos.y-8);
                                                g.surface.DrawText(wep);
                                        end
                                end
                        end
                        for k, t in g.pairs(ft.custe) do
                                if(g.ValidEntity(v) and v:GetClass() == t) then
                                        local pos = (v:GetPos() + g.Vector(0, 0, 50)):ToScreen();
                                        g.surface.SetTextColor(g.Color(255,0,0,255));
                                        g.surface.SetTextPos(pos.x-30, pos.y-8);
                                        g.surface.DrawText(t);          
                                end
                        end
                end
        end
        
        /*if(ft.vars.aim) then
                g.surface.SetFont("Trebuchet22");
                
                g.surface.SetTextColor(not ft.vars.aimtarg and g.Color(255, 15, 15, 255) or g.Color(25, 255, 25, 255));
                
                local w,h = g.ScrW(), g.ScrH();
                g.surface.SetTextPos(w/2-28, h/2+15);
                
                g.surface.DrawText(not ft.vars.aimtarg and "Scanning..." or "Locked!");
        end*/
end
ft:RegisterHook("HUDPaint", ft.ESP);


function ft.CalcView(ply, pos, angles, fov)
        if(ft.GetCVNum("ft_thirdperson") == 1) then
                return({origin = pos - (angles:Forward() * (100))});
        end
        return GAMEMODE:CalcView(ply, pos, angles, fov);
end
ft:RegisterHook("CalcView",ft.CalcView)

ft:RegisterHook("ShouldDrawLocalPlayer",function() return (ft.GetCVNum("ft_thirdperson") == 1) end)


local lastftAntiAFK = 0
function ft.AntiAfk()
        if (ft.GetCVNum("ft_antiafk") != 1) then return end
        if g.CurTime() - lastftAntiAFK < 180 then return end
        lastftAntiAFK = g.CurTime()


        for k,v in g.pairs(g.ents.FindInSphere(LocalPlayer():GetPos(),1000)) do
                if v:IsValid() and v:IsPlayer() and v:IsAdmin() then
                        return 
                end
        end
        local a = g.math.random(1,799)
        local b = g.math.random(1,799)

        if a < 200 then
                g.RunConsoleCommand("+moveleft")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-moveleft") end)
        elseif a < 400 then
                g.RunConsoleCommand("+moveright")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-moveright") end)
        elseif a < 600 then
                g.RunConsoleCommand("+back")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-back") end)
        elseif a < 800 then 
                g.RunConsoleCommand("+forward")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-forward") end)
        end

        if b < 200 then
                g.RunConsoleCommand("+left")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-left") end)
        elseif b < 400 then
                g.RunConsoleCommand("+right")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-right") end)
        elseif b < 600 then
                g.RunConsoleCommand("+lookup")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-lookup") end)
        elseif b < 800 then
                g.RunConsoleCommand("+lookdown")
                g.timer.Simple(.01,function() g.RunConsoleCommand("-lookdown") end)
        end
end

function ft.CheckTraitors()
        if(_G.KARMA) then
                for k, v in g.ipairs(g_players) do
                        if(v:Alive() and not g.table.HasValue(ft.traitors, v)) then
                                for x, y in g.pairs(r.Player.GetWeapons(v)) do
                                        if(g.ValidEntity(y)) then
                                                if(y.CanBuy and g.table.HasValue(y.CanBuy, ROLE_TRAITOR)) then
                                                        g.table.insert(ft.traitors, v);
                                                        g.chat.AddText(g.Color(100, 100, 100), 
                                                                "[CAS] ", g.Color(255, 10, 10), v:Nick() .. " has traitor weapon " .. y:GetClass() .. "!"
                                                        );
                                                end
                                        end
                                end
                        end
                end
        end
end



local olddebuguv = g.debug.getupvalue
local blockgetupvalues = {
        "ft",
        "g",
        "oldHookCall",
        "olddebug"
}
function debug.getupvalue(func,upvalue)
        local a,b = olddebuguv(func,upvalue)
        if g.table.HasValue(blockgetupvalues,a) then g.print("debug.getupvalue BLOCKED!!!") return end

        return olddebuguv(func,upvalue)
end


local olddebuggi = g.debug.getinfo
function debug.getinfo(func)
        local asd = ""

        if func == debug.getinfo then
                g.print("debug.getinfo on debug.getinfo BLOCKED!!!")
                local t = {}
                        t["nups"] = 0
                        t["what"] = "C"
                        t["func"] = "function: 02E66618"
                        t["lastlinedefined"] = -1
                        t["source"] = "[C]"
                        t["currentline"] = -1
                        t["namewhat"] = ""
                        t["linedefined"] = -1
                        t["short_src"] = "[C]"
                return t
        end

        -- massive shit coming
        if func == ft.myRunConsoleCommand then asd = "RunConsoleCommand" elseif func == ft.myRunString then asd = "RunString" elseif func == ft.myRunStringEx then asd = "RunStringEx"
        elseif func == file.Read then asd = "file.Read" elseif func == file.Size then asd = "file.Size" elseif func == file.Delete then asd = "file.Delete" elseif func == file.FindInLua then 
        asd = "file.FindInLua" elseif func == file.TFind then asd = "file.TFind" end
                



        if asd != "" then
                g.print("debug.getinfo on ".. asd .." BLOCKED!!!")
                local t = {} 
                        t["nups"] = 0
                        t["what"] = "C"
                        t["func"] = "function: 02EA6F08"
                        t["lastlinedefined"] = -1
                        t["source"] = "[C]"
                        t["currentline"] = -1
                        t["namewhat"] = ""
                        t["linedefined"] = ""
                        t["short_src"] = "[C]"
                return t

        elseif func == hook.Call then
                g.print("debug.getinfo on hook.Call BLOCKED!!!")
                local t = {}        
                        t["nups"] = 8
                        t["what"] = "Lua"
                        t["func"] = "function: 03DD7048"
                        t["lastlinedefined"] = 124
                        t["source"] = [[@lua\includes\modules\hook.lua]]
                        t["currentline"] = -1
                        t["namewhat"] = ""
                        t["linedefined"] = "66"
                        t["short_src"] = [[lua\includes\modules\hook.lua]]
                return t
        end
        return olddebuggi(func)
end

local oldgetmetat = g.getmetatable 
local oldgetmetatd = g.debug.getmetatable
function getmetatable(a)
        if a == _G or a == _R then g.print("getmetatable BLOCKED!!!") return nil end
        return oldgetmetat(a)
end
function debug.getmetatable(a)
        if a == _G or a == _R then g.print("debug.getmetatable BLOCKED!!!") return nil end
        return oldgetmetatd(a)
end

local oldfr = g.file.Read
local oldfs = g.file.Size
local oldfd = g.file.Delete
local oldfl = g.file.FindInLua 
local oldtf = g.file.TFind
function file.Read(file,bool)
        if g.string.find(file,"23fv54.txt") then g.print("file.Read BLOCKED!!!") return "" end
        if g.string.find(file,"gm_mat1") then g.print("file.Read BLOCKED!!!") return "" end

        if bool == true then g.print("file.Read attempted to read: "..file) end
        return oldfr(file,bool)
end
function file.Size(file,bool)
        if g.string.find(file,"23fv54.txt") then g.print("file.Size BLOCKED!!!") return -1 end
        if g.string.find(file,"gm_mat1") then g.print("file.Size BLOCKED!!!") return -1 end

        if bool == true then g.print("file.Size attempted to read: "..file) end
        return oldfs(file,bool)
end
function file.Delete(file)
        --insert some hack here and there
        return oldfd(file)
end
function file.FindInLua(dir)
        local a = oldfl(dir)
        if g.type(a) == "table" then
                for k,v in g.pairs(a) do
                        if g.string.find(v,"gm_mat1") then
                                g.print("file.FindInLua BLOCKED!!!")
                                g.table.remove(a,k)
                        end
                end
        end
        return a
end
function file.TFind(file,func) -- its a fucking mess but i dont give a shit because noone else reads it, right?
        oldtf(file,function(a,b,c)
                local q = 1
                local z = {}
                for k,v in g.pairs(c) do
                        if g.string.find(v,"gm_mat1") then
                                z[q] = k
                                q = q+1
                        end
                end
                if z[1] then g.table.remove(c,z[1]) g.print("file.TFind BLOCKED!!!") end
                if z[2] then g.table.remove(c,z[1]) end
                func(a,b,c)
        end)
end

--metatables
--g.rawset(_G, "__metatable", false);
--g.rawset(hook, "__metatable", false);
--g.rawset(usermessage, "__metatable", false);

--g.rawset(_G, "RunConsoleCommand", ft.myRunConsoleCommand);
--g.rawset(_G, "RunString", ft.myRunString);
--g.rawset(_G, "RunStringEx", ft.myRunStringEx);

hook = g.hook;
RunConsoleCommand = ft.myRunConsoleCommand;
RunString = ft.myRunString;
RunStringEx = ft.myRunStringEx;

/*g.setmetatable(_G, {
        __index = function(t , k)
                if(k == "hook") then
                        return g.hook;
                end
                if(k == "RunConsoleCommand") then
                        return ft.myRunConsoleCommand;
                end
                if(k == "require") then
                        return g.require;
                end
                if(k == "concommand") then
                        return g.concommand;
                end
                if(k == "engineConsoleCommand") then
                        return g.engineConsoleCommand;
                end
                if(k == "RunString") then
                        return ft.myRunString;
                end
                if(k == "RunStringEx") then
                        return ft.myRunStringEx;
                end
        end,
        //__metatable = true,
});*/
--metatables end