local hwid = [[Host: meepdarknessmeep.com]];
local steamip = [[]];
local isdev = false;
local debugging = false;
if(hwid == "342387F8D6C0201A069D989008002700C49A{846ee340-7039-11de-9d20-806e6f6e6963}") then
	isdev = true;
	print("[**] - Developer mode enabled");
end

local __tc = _tc;
local _p = print;
local function DebugPrint(x)
	if(isdev and debugging) then
		_p(x);
		__tc(x, "Dismay");
	end
end
local dismay = {};
dismay.private = {
	hiddenfiles = {};
	funcs	= {};
	oldfuncs= {};
	metas = {
		real = {};
	};
	waitfor = {};
	gm 		= {};
	fgm 	= {};
	ogm 	= {};
	egm 	= {};
	vars 	= {};
	dhook 	= {};
	realg	= _G;
	esp		= {};
	scrnsht	= {};
	scrnshtd= {};
	oldr	= {};
	mem     = {};
};

setmetatable( dismay.private.mem, {__mode = "kv"})

function dismay.ShouldDrawESP() 
	return dismay.private.ShouldDrawESP;
end
print("***[C] - Loading");

function dismay.HideThisFile(f)
	dismay.private.hiddenfiles[dismay.private.oldfuncs.debug_getinfo(f).short_src] = true;
end

dismay.private.hiddenfiles["\x01"] = true;

local function __indexnew(self, k)
	local mt = dismay.private.oldg.getmetatable(self);
	if(dismay.private.oldg.rawget(mt.spoofed, k) == nil) then
		if(mt.spoofedname == "_G" and k == "dismay") then return dismay; end
		dismay.private.oldg.MsgC(dismay.private.oldg.Color(200, 0, 0, 255), "***WARNING: indexed function "..mt.spoofedname.."."..k.." but didn't exist! Defaulting to real global table (could have anticheat code in it)\n"..dismay.private.oldg.debug.traceback().."\n\n");
	else
		if(mt.spoofedname == "_G.dismay.private" and k == "realg") then
			return dismay.private.oldg.rawget(mt.spoofed, k);
		end
		if(dismay.private.oldg.type(dismay.private.oldg.rawget(mt.spoofed, k)) == "table") then
			local nmt 	= dismay.CopyTable(dismay.private.spf);
			nmt.spoofed = dismay.private.oldg.rawget(mt.spoofed, k);
			nmt.real	= dismay.private.oldg.rawget(mt.real, k);
			nmt.spoofedname = (mt.spoofedname and mt.spoofedname.."." or "")..k; 
			return dismay.private.oldg.setmetatable(mt.spoofed[k], nmt);
		else
			return mt.spoofed[k];
		end
	end
	return mt.real[k];
end

local function __newindexnew(self, k, v)
	dismay.private.oldg.MsgC(dismay.private.oldg.Color(200,0,0,255), "***WARNING: created new global index "..k.." ("..tostring(v).."). If this was intended use dismay.private.realg["..k.."] = "..tostring(v).."\n");
end

dismay.private.spf = {
	__index 	= __indexnew;
	__newindex 	= __newindexnew;
}

function dismay.SetupGlobalTable()
	DebugPrint("START - SetupGlobalTable()");
	local mt 		= dismay.CopyTable(dismay.private.spf);
	mt.spoofedname 	= "_G";
	mt.real 		= dismay.private.realg;
	mt.spoofed 		= dismay.private.newg;
	dismay.private.oldg.setfenv(2, dismay.private.oldg.setmetatable({}, mt));
	DebugPrint("END - SetupGlobalTable()");
end


local function normalang(ang)
	ang.p = (ang.p + 180) % 360 - 180; ang.y = (ang.y + 180) % 360 - 180; ang.r = (ang.r + 180) % 360 - 180;
	
	return ang
end

if (GetPred) then dismay.private.GetPred = GetPred; GetPred = nil; 
	function dismay.GetPred(ply)
		return dismay.private.GetPred(ply, Vector(0,0,0));
	end
end
local predicting = false;
if (PredSpread) then
	dismay.private.PredSpread = PredSpread; PredSpread = nil;
	function dismay.PredSpread(cmd, ang)	
		local l = LocalPlayer();
		local w = l:GetActiveWeapon();
		if(LocalPlayer():GetActiveWeapon().Author == "Spy" and w.CurCone) then -- fas2
			local n = cmd:CommandNumber();
			math.randomseed(n)
			local a = Angle(math.Rand(-w.CurCone, w.CurCone), math.Rand(-w.CurCone, w.CurCone), 0);
			local nang = ang - l:GetPunchAngle() - a * 25
			local b = false; 
			if w.ClumpSpread and w.ClumpSpread > 0 then
				b = Vector(math.Rand(-1, 1), math.Rand(-1, 1), math.Rand(-1, 1)) * w.ClumpSpread
			end
			if(b) then
				nang = (nang:Forward() - b):Angle();
			end
			
			return nang;
		end
		local b, _spread = dismay.private.PredSpread(cmd:CommandNumber(), ang, dismay.GetSpread(LocalPlayer():GetActiveWeapon()));
		local g = {b, _spread};
		local ret = _spread:Angle();
		ret.p = ret.p;
		
		return normalang(ret);
	end
end
dismay.version = 8;
local oG = _G;

local function ReplaceG(index)
	dismay[index] = oG[index];
	oG[index] = nil;
end
local function ReplaceUN(index)
	dismay.private[index] = oG[index];
	oG[index] = nil;
end

ReplaceG	"Repaint";
ReplaceUN	"SendFile";
ReplaceUN	"GetFile";
ReplaceG	"SetCommandNumber";
ReplaceG	"_tc";
ReplaceG	"RunClient";
ReplaceG	"OpenClient";
ReplaceG	"RunMenu";
ReplaceG	"OpenMenu";
ReplaceG	"rversion";
ReplaceG	"IsDormant";
ReplaceG	"GetCmdRepState";
ReplaceG	"SetCmdRepState";
ReplaceG	"GetCmdSendState";
ReplaceG	"SetTickRate";
ReplaceG	"SetCmdSendState";
ReplaceG	"SetSteamName";
ReplaceG	"GetSteamName";
ReplaceG	"SetIGN";
ReplaceG	"LoadWebScript";
ReplaceG	"RequestFile";
ReplaceG	"GetTickCount";
ReplaceG	"SetTickCount";

dismay.SetCmdSendState(true);
dismay.SetCmdRepState(false);
dismay.SetCommandNumber(-1);

function dismay.OverrideHook(name, redir)
	dismay.private.Hooks = dismay.private.Hooks or {};
	dismay.private.Hooks[name] = redir;
end

function dismay.CallHook(name, ...)
	if(not dismay.private.Hooks[name]) then return; end
	for k,v in dismay.private.oldfuncs.pairs(dismay.private.Hooks[name]) do
		v(...);
	end
end

function dismay.SpoofFunction(oldfunction, replacefunction)
	dismay.private.funcs[replacefunction] = oldfunction;
end

function dismay.runwhenindexcreated(k, func)
	if (oG[k]) then func(); return; end
	dismay.private.waitfor[k] = dismay.private.waitfor[k] or {};
	dismay.private.waitfor[k][#dismay.private.waitfor[k] + 1] = func;
end

function dismay.GetHooks(name)
	local _name = name;
	return dismay.private.fgm[name] or {};
end

function dismay.AddHook(_type, name, func)
	DebugPrint("START - AddHook(".._type..", "..name..", func)");
	if(_type == "OnScreenshot") then
		dismay.private.scrnsht[name] = func;
	end
	if(_type == "OnScreenshotDone") then
		dismay.private.scrnshtd[name] = func;
	end
	dismay.private.fgm[_type] = dismay.private.fgm[_type] or {};
	dismay.private.fgm[_type][name] = func;
	DebugPrint("END - AddHook()");
end

function dismay.RemoveHook(_type, name)
	local type = _type;
	local c = dismay.private.fgm[type] or {};
	c[name] = nil;
end

function dismay.CopyTable(t, lookup_table)
	if (t == nil) then return nil end
	local copy = {}
	for i,v in dismay.private.oldfuncs.pairs(t) do
		if ( !istable(v) ) then
			copy[i] = v
		else
			lookup_table = lookup_table or {}
			lookup_table[t] = copy
			if lookup_table[v] then
				copy[i] = lookup_table[v] -- we already copied this table. reuse the copy.
			else
				copy[i] = dismay.CopyTable(v,lookup_table) -- not yet copied. copy it.
			end
		end
	end
	return copy;
end


function dismay.CopyTable_l(t, lookup_table)
	if (t == nil) then return nil end
	local copy = {}
	for i,v in dismay.private.oldfuncs.pairs(t) do
		copy[i] = v;
	end
	
	return copy
end
dismay.private.oldfuncs.jit_util_funcinfo	= jit.util.funcinfo;
dismay.private.oldfuncs.debug_setupvalue	= debug.setupvalue;
dismay.private.oldfuncs.debug_getupvalue	= debug.getupvalue;
dismay.private.oldfuncs.debug_getinfo	= debug.getinfo;
dismay.private.oldfuncs.tostring		= tostring;
dismay.private.oldfuncs.getmetatable	= getmetatable;
dismay.private.oldfuncs.setmetatable	= setmetatable;
dismay.private.oldfuncs.rawget		= rawget;
dismay.private.oldfuncs.rawset		= rawset;
dismay.private.oldfuncs.pairs		= pairs;
dismay.private.oldfuncs.next		= next;

local function Color(r, g, b, a)
	return {r = r; g = g; b = b; a = a;}
end
local function IsValid(x)
	return x and x.IsValid and x:IsValid();
end

dismay.private.oldg = dismay.CopyTable(_G);
dismay.private.newg = dismay.CopyTable(_G);
dismay.private.oldr = dismay.CopyTable(debug.getregistry());

local _R 	= dismay.private.oldr;
local G 	= dismay.private.oldg;
local rG = dismay.private.realg;
function dismay.private.newg.math.Round(x)
	return G.math.floor(x + 0.5);
end
dismay.SetupGlobalTable();


dismay.private.oldg.Color = Color;
dismay.private.oldg.IsValid = IsValid;
dismay.private.newg.Color = Color;
dismay.private.newg.IsValid = IsValid;

dismay.private.metas.real.GAMEMODE = {
	__index = function(self, k)
		DebugPrint("START - __index(GAMEMODE, "..tostring(k)..")");
		return dismay.private.gm[k] or dismay.private.ogm[k] or function(GM, ...)
			if (dismay.private.fgm[k]) then
				for _k, vfunc in dismay.private.oldg.pairs(dismay.private.fgm[k]) do
					local r = vfunc(...);
					if (r ~= nil) then return r; end
				end
			end
		end;
	end;
	__newindex = function(self, k, func)
		DebugPrint("START - __newindex(GAMEMODE, "..tostring(k)..", "..tostring(func)..")");
		dismay.private.gm[k] = func;
		dismay.private.ogm[k] = func;
		dismay.private.oldfuncs.rawset(self, k, nil);
		if (dismay.private.oldg.type(func) == "function") then
			local f = function(GM, ...)
				if (dismay.private.fgm[k]) then
					for _k, vfunc in dismay.private.oldg.pairs(dismay.private.fgm[k]) do
						local r = vfunc(...);
						if (r ~= nil) then return r; end
					end
				end
				return dismay.private.ogm[k](dismay.private.ogm, ...);
			end
			dismay.SpoofFunction(func, f);
			dismay.private.gm[k] = f;
		end
		return;
	end;
	__dtable = true;
};
local troo = false;

dismay.private.metas.real._G = {
	__index = function(self, k)
		--if(troo) then dismay._tc(dismay.private.oldg.tostring(k).."\n"..debug.traceback(), "__index - _G"); end
		if (k == "dismay" and (dismay.private.oldg.debug.getinfo(2).short_src == "" or dismay.private.oldg.debug.getinfo(2).short_src == "\x01")) then
		--if(k == "dismay") then
			return dismay;
		end
		if (dismay.private.metas._G and dismay.private.metas._G.__index) then
			local ret = dismay.private.metas._G.__index(self, k);
			if (dismay.private.oldg.type(ret) ~= "no value") then
				return ret;
			end
		end
	end;
	__newindex = function(self, k, v)
		if (k == "dismay") then 
			return;
		end
		if (dismay.private.metas["_G"] and dismay.private.metas["_G"].__newindex and not dismay.private.check1) then
			dismay.private.check1 = true;			
			local ret = dismay.private.metas["_G"].__newindex(self, k, v);
			dismay.private.check1 = false;
			if (dismay.private.oldg.type(ret) ~= "no value") then
				return ret;
			end
		end
		if (dismay.private.waitfor[k]) then
			local o = dismay.CopyTable_l(dismay.private.waitfor[k]);
			dismay.private.waitfor[k] = nil;
			for i, func in dismay.private.oldg.ipairs(o) do
				func(v);
			end
		end
		return dismay.private.oldfuncs.rawset(self, k, v);
	end;
	__dtable = true;
};

function rG.debug.getupvalue(func, ...)
	--dismay._tc(tostring(func), "debug.getupvalue");
	if(dismay.private.funcs[func]) then
		return dismay.private.oldfuncs.debug_getupvalue(dismay.private.funcs[func], ...);
	end
	return dismay.private.oldfuncs.debug_getupvalue(func, ...);
end

function rG.debug.setupvalue(func, ...)
	--dismay._tc(tostring(func), "debug.setupvalue");
	if(dismay.private.funcs[func]) then
		return dismay.private.oldfuncs.debug_setupvalue(dismay.private.funcs[func], ...);
	end
	return dismay.private.oldfuncs.debug_setupvalue(func, ...);
end

local debug_getinfo;

function debug_getinfo(func, value)
	DebugPrint("SRT - dbginf");
	local ret = nil;
	if (dismay.private.funcs[func]) then
		ret = dismay.private.oldfuncs.debug_getinfo(dismay.private.funcs[func], value or nil);
		if (ret.func) then ret.func = func; end
	else
		ret = dismay.private.oldfuncs.debug_getinfo(func, value or nil);
		if(dismay.private.oldg.type(func) == "number") then
			local need = func;
			local current = 0;
			while(need > 1) do
				--ret and ret.short_src and dismay.private.hiddenfiles[ret.short_src]
				local r = dismay.private.oldfuncs.debug_getinfo(current);
				if(not r or not r.short_src or not dismay.private.hiddenfiles[r.short_src]) then
					need = need - 1;
				end
				current = current + 1;
			end
			DebugPrint("END - dbginf NUM");
			ret = dismay.private.oldfuncs.debug_getinfo(current, value or nil);
		end
	end
	DebugPrint("END - dbginf");
	return ret;
end

rG.debug.getinfo = debug_getinfo;

function rG.jit.util.funcinfo(func, ...)
	local ret = nil;
	if(dismay.private.funcs[func]) then
		ret = dismay.private.oldfuncs.jit_util_funcinfo(dismay.private.funcs[func], ...);
	else
		ret = dismay.private.oldfuncs.jit_util_funcinfo(func, ...);
	end
	return ret;
end

function rG.next(table, t)
	--dismay._tc(tostring(table).." "..tostring(t), "next");
	if (table == dismay.private.oldg.rawget(rG, "GAMEMODE")) then
		return dismay.private.oldfuncs.next, dismay.private.gm, t;
	end
	if (table == rG) then
		local f_G = dismay.CopyTable_l(rG);
		f_G.GAMEMODE = dismay.private.oldg.rawget(rG, "GAMEMODE");
		return dismay.private.oldfuncs.next, f_G, t;
	end
	return dismay.private.oldfuncs.next, table, t;
end

function rG.pairs(table)
	if (table == dismay.private.oldg.rawget(rG, "GAMEMODE")) then
		--dismay._tc(tostring(table), "pairs - gamemode");
		return dismay.private.oldfuncs.next, dismay.private.gm, nil;
	end
	if (table == rG) then
		--dismay._tc(tostring(table).."\n"..debug.traceback(), "pairs - _G");
		
		local f_G = dismay.CopyTable_l(rG);
		f_G.GAMEMODE = dismay.private.oldg.rawget(rG, "GAMEMODE");
		return dismay.private.oldfuncs.next, f_G, nil;
	end
	return dismay.private.oldfuncs.next, table, nil;
end
local rawgetb = true;
function rG.rawget(table, index)
	if (rawgetb and dismay.private.oldfuncs.getmetatable(table) and dismay.private.oldg.type(dismay.private.oldfuncs.getmetatable(table)) == "table" and dismay.private.oldfuncs.getmetatable(table).__dtable) then
		rawgetb = false;
		local ret = dismay.private.oldfuncs.getmetatable(table).__index(table, index);
		rawgetb = true;
		return ret;
	end
	return dismay.private.oldfuncs.rawget(table, index);
end

function rG.rawset(table, index, value)
	if (dismay.private.oldfuncs.getmetatable(table) and dismay.private.oldg.type(dismay.private.oldfuncs.getmetatable(table)) == "table" and dismay.private.oldfuncs.getmetatable(table).__dtable) then
		return dismay.private.oldfuncs.getmetatable(table).__newindex(table, index, value);
	end
	return dismay.private.oldfuncs.rawset(table, index, value);
end

function rG.tostring(value)
	local ots = dismay.private.oldfuncs.tostring;
	if(dismay.private.funcs[value]) then 
		return ots(dismay.private.funcs[value]);
	end
	return ots(value);
end

function rG.getmetatable(tbl)
	troo = true;
	if (tbl == rG) then
		return dismay.private.metas._G or nil;
	end
	if (tbl == dismay.private.oldg.rawget(rG, "GAMEMODE")) then
		return dismay.private.metas.GAMEMODE or nil;
	end
	troo = false;
	return G.getmetatable(tbl);
end

function rG.setmetatable(tbl, mt)
	if (tbl == rG) then
		dismay.private.metas._G = mt;
		return tbl;
	end
	if (tbl == G.rawget(rG, "GAMEMODE")) then
		dismay.private.metas.GAMEMODE = mt;
		return tbl;
	end
	return G.setmetatable(tbl, mt);
end
dismay.SpoofFunction(dismay.private.oldfuncs.jit_util_funcinfo,	rG.jit.util.funcinfo);
dismay.SpoofFunction(dismay.private.oldfuncs.debug_getupvalue,	rG.debug.getupvalue);
dismay.SpoofFunction(dismay.private.oldfuncs.debug_setupvalue,	rG.debug.setupvalue);
dismay.SpoofFunction(dismay.private.oldfuncs.debug_getinfo,	rG.debug.getinfo);
dismay.SpoofFunction(dismay.private.oldfuncs.getmetatable,	rG.getmetatable);
dismay.SpoofFunction(dismay.private.oldfuncs.setmetatable,	rG.setmetatable);
dismay.SpoofFunction(dismay.private.oldfuncs.tostring,		rG.tostring);
dismay.SpoofFunction(dismay.private.oldfuncs.rawget,		rG.rawget);
dismay.SpoofFunction(dismay.private.oldfuncs.rawset,		rG.rawset);
dismay.SpoofFunction(dismay.private.oldfuncs.pairs,		rG.pairs);
dismay.SpoofFunction(dismay.private.oldfuncs.next,		rG.next);
--dismay.SpoofFunction(G.table.insert,				rG.table.insert);

dismay.private.oldfuncs.setmetatable(rG, dismay.private.metas.real._G);

dismay.runwhenindexcreated("GAMEMODE", function(GAMEMODE)
	for k, func in dismay.private.oldfuncs.pairs(dismay.CopyTable_l(GAMEMODE)) do
		dismay.private.gm[k] = func;
		dismay.private.ogm[k] = func;
		dismay.private.oldfuncs.rawset(GAMEMODE, k, nil);
		if (dismay.private.oldg.type(func) == "function") then
			local f = function(self, ...)
				if (dismay.private.fgm[k]) then
					for _k, vfunc in dismay.private.oldg.pairs(dismay.private.fgm[k]) do
						local r = vfunc(...);
						if (r ~= nil) then return r; end
					end
				end
				return dismay.private.ogm[k](dismay.private.ogm, ...);
			end
			dismay.SpoofFunction(func, f);
			dismay.private.gm[k] = f;
		end
	end
	dismay.private.oldfuncs.setmetatable(GAMEMODE, dismay.private.metas.real.GAMEMODE);
end);


local plys = player.GetAll();
local function rem(i) table.remove(plys, i) end
local x = 10;

dismay.AddHook("Think", "InitValid", function()
	x = x - 1;
	if(x ~= 0) then return; end
	plys = player.GetAll();
	for i = #plys, 1, -1 do
		local v = plys[i];
		if(v:Health() <= 0) then rem(i); continue; end
		if(v:Team() == TEAM_SPECTATOR) then rem(i); continue; end
		if(v:GetObserverMode() ~= OBS_MODE_NONE) then rem(i); continue; end
	end
end);

gameevent.Listen("player_spawn");
dismay.AddHook("player_spawn", "AddValid", function(d)
	local ply = Player(d.userid);
	plys[#plys + 1] = ply;
end);
gameevent.Listen("player_hurt");
dismay.AddHook("player_hurt", "RemoveValid", function(d)
	local att = Player(d.userid);
	if(d.health <= 0) then 
		for i = 1, #plys do
			if(plys[i] == att) then rem(i); break; end
		end
	end
end);
gameevent.Listen("player_connect");
dismay.AddHook("player_connect", "ConnectValid", function(d)
	dismay.AddHook("Think", "dontremove"..tostring(d.userid), function()
		plys[#plys + 1] = Player(d.userid);
		dismay.RemoveHook("Think", "dontremove");
	end);
end);
dismay.runwhenindexcreated("GAMEMODE", function(GM)
	local rand;
	for k,v in pairs(GM) do
		rand = v;
		break;
	end
	if(not GM.player_hurt) then 
		function GM:player_hurt() end;
		dismay.SpoofFunction(rand, GM.player_hurt);
	end
	if(not GM.player_spawn) then 
		function GM:player_spawn() end;
		dismay.SpoofFunction(rand, GM.player_spawn);
	end
	if(not GM.player_connect) then 
		function GM:player_connect() end;
		dismay.SpoofFunction(rand, GM.player_connect);
	end
end);

dismay.runwhenindexcreated("vgui", function()
	timer.Simple(1, function() -- lz
		local w = 200;
		local h = 200;
		local texture = surface.GetTextureID("gui/corner8");

		local function DrawCircle(x, y, r, col)
			surface.SetTexture(texture);
			surface.SetDrawColor(col);
			local mx = x + r;
			local my = y + r
			surface.DrawTexturedRectRotated(mx - r / 2, my - r / 2 , r, r, 0);
			surface.DrawTexturedRectRotated(mx - r / 2, my + r / 2 , r, r, 90);
			surface.DrawTexturedRectRotated(mx + r / 2, my + r / 2 , r, r, 180);
			surface.DrawTexturedRectRotated(mx + r / 2, my - r / 2 , r, r, 270);
		end

		dismay.Panels = dismay.Panels or {};

		local sqsize = 4;

		local function DrawPlayers(w, h, pixelsperunit)
			local lp = LocalPlayer();
			local lppos = _R.Entity.GetPos(lp);
			local lpy = _R.Entity.EyeAngles(lp).y;
			lppos.z = 0;
			for i = 1, #plys do
				local v = plys[i];
				if(v == lp) then continue; end
				if(not IsValid(v)) then rem(i); continue; end
				local ppos = _R.Entity.GetPos(v);
				ppos.z = 0;
				local dist = _R.Vector.Distance(ppos, lppos);
				local angy = _R.Vector.Angle(ppos - lppos).y;
				local d = (angy - lpy - 90) / 57;
				local xdif = -math.cos(d) * dist * pixelsperunit;
				local ydif = math.sin(d) * dist * pixelsperunit;
				local x = w / 2 + xdif - sqsize / 2;
				local y = h / 2 + ydif - sqsize / 2;
				if(x > w or y > h) then continue; end
				G.surface.DrawRect(x, y, sqsize, sqsize);
				G.surface.SetFont("BudgetLabel");
				local text = v:Nick().."("..math.Round(dist).."u)";
				local w2, h2 = G.surface.GetTextSize(text);
				G.surface.SetTextPos(x - w2 / 2, y + 2);
				G.surface.DrawText(text);
			end
		end

		local function DrawBG(w, h)
			local r = 4;
			local max = 3; -- max - 1
			local maxfade = 10;
			local bgcol = Color(57,57,57,250);
			local col = Color(255,0,0,0);
			local times = 3;
			surface.SetDrawColor(bgcol);
			surface.DrawRect(0, 0, w, h);
			for i = -((times - 1) / 2), ((times - 1) / 2) do
				local mult = math.abs(i) / (times - 1) / 2;
				bgcol.a = 250 * mult;
				bgcol.r = 57 * mult;
				bgcol.g = 57 * mult;
				bgcol.b = 57 * mult;
				--print(bgcol.a);
				surface.SetDrawColor(bgcol);
				surface.DrawLine(w / 2 + i, 0, w / 2 + i, h);
				surface.DrawLine(0, h / 2 + i, w, h / 2+ i);
			end
			DrawCircle(w / 2 - r, h / 2 - r, r, Color(235,25,0,255));
			surface.SetDrawColor(Color(122,0,0,255));
			surface.SetTextColor(Color(235, 35, 0, 255));
			DrawPlayers(w, h, 0.025);
			for i = 0, max do
				col.a = 255 * (i + 1) / (max + 1);
				surface.SetDrawColor(col);
				surface.DrawOutlinedRect(i, i, w - i * 2, h - i * 2);
			end
			for i = max + 1, maxfade do
				bgcol.a = 255 * (1 - (i+1) / (maxfade + 1));
				surface.SetDrawColor(bgcol);
				surface.DrawOutlinedRect(i, i, w - i * 2, h - i * 2);
			end
			
		end


		dismay.AddHook("HUDPaint", "Radar", function()
			if(not dismay.ShouldDrawESP()) then print("SDE: "..CurTime()); return; end
			DrawBG(w, h);
		end);
	end);
end)

function rG.IsFirstTimePredicted()
	if(predicting) then
		return true;
	end
	return IsFirstTimePredicted();
end

dismay.SpoofFunction(IsFirstTimePredicted, rG.IsFirstTimePredicted);

function dismay.GetStatusString(l)
	local l = l or LocalPlayer();
	local str = tostring(l:Crouching())..tostring(l:IsOnGround())..tostring(l:KeyDown(IN_SPEED))..tostring(l:GetActiveWeapon() and l:GetActiveWeapon().GetIronsights and l:GetActiveWeapon():GetIronsights());
	return str;
end

dismay.runwhenindexcreated("LocalPlayer", function()
	local player_meta = FindMetaTable("Entity");
	local weapon_meta = FindMetaTable("Weapon");
	dismay.Spread = {}
	local Spread = dismay.Spread;
	Spread.weapon_pistol 	= Vector(-0.01000, -0.01000, -0.01000);
	Spread.weapon_smg1		= Vector(-0.04362, -0.04362, -0.04362);
	Spread.weapon_ar2		= Vector(-0.02618, -0.02618, -0.02618);
	Spread.weapon_shotgun	= Vector(-0.08716, -0.08716, -0.08716);

	local old_es = player_meta.EmitSound;
	
	function player:EmitSound(...)
		print(CurTime());
		if(predicting) then return; end
		return old_es(self, ...);
	end
	dismay.SpoofFunction(old_es, player_meta.EmitSound);
	
	local old_animate = weapon_meta.SendWeaponAnim;
	function weapon_meta.SendWeaponAnim(...) 	
		if(predicting) then return; end
		return old_animate(...);
	end
	dismay.SpoofFunction(old_animate, weapon_meta.SendWeaponAnim);
	
	
	local old_fb = player_meta.FireBullets
	function player_meta:FireBullets(tbl)
		if(self == LocalPlayer()) then
			local wep = self:GetActiveWeapon();
			if(IsValid(self) and IsValid(wep) and not dismay.Spread[wep:GetClass()..dismay.GetStatusString(self)]) then
				local c = true;
				if(wep and wep.Base) then
					local b = wep.Base or "";
					if(b == "bobs_gun_base" or b == "bobs_scoped_base" or b == "bobs_shotty_base") then
						if(tbl.Spread == Vector(0,0,0)) then
							c = false;
						end
					end
				end
				if(c) then
					dismay.Spread[wep:GetClass()..dismay.GetStatusString()] = -(tbl.Spread or Vector(0,0,0));
				end
			end
		end
		if(predicting) then return; end
 	    old_fb(self, tbl);
		if(dismay.FireBullets) then dismay.FireBullets(self, tbl); end
	end
	dismay.SpoofFunction(old_fb, player_meta.FireBullets);
end);
do
	function dismay.GetSpread(wep)
		predicting = true;
		local x = wep:GetClass()..dismay.GetStatusString();
		if(not dismay.Spread[x] and IsValid(wep) and wep.CanPrimaryAttack and wep:CanPrimaryAttack() and wep.PrimaryAttack) then
			wep:PrimaryAttack(true);
		end
		predicting = false
		return dismay.Spread[x] or dismay.Spread[wep:GetClass()] or Vector(0, 0, 0);
	end
end

dismay.private.o_RenderCapture = render.Capture;

function rG.render.Capture(...)
	dismay.private.ShouldDrawESP = false;
	dismay.Repaint();
	print("RC:"..CurTime());
	local ret = dismay.private.o_RenderCapture(...);
	dismay.private.ShouldDrawESP = true;
	dismay.Repaint();
	return ret;
end

dismay.CurSpeedNum = 0;
dismay.WasSpeeding = true;
dismay.SpeedKey = false;

local function _tc(a)
	dismay._tc(a, a);
end

dismay.RunMenu([[
	dismay.SKey = dismay.SKey or KEY_G;
	dismay.RunClient("dismay.SKey = "..tostring(dismay.SKey)..";");
	dismay.RunClient("dismay.SpeedNum = "..(dismay.SpeedNum or 0)..";");
	dismay.RunClient("dismay.SpeedKey = "..(dismay.SpeedKey and "true" or "false")..";");
]]);

dismay.AddHook("CreateMove", "Speed", function(cmd)
	dismay.IsSpeeding = dismay.private.oldg.input.IsKeyDown(dismay.SKey or KEY_G) and dismay.SpeedKey;
	if(dismay.IsSpeeding) then
		if(dismay.CurSpeedNum > 0) then
			dismay.SetCmdRepState(true);
			dismay.CurSpeedNum = dismay.CurSpeedNum - 1;
			--_tc(tostring(dismay.CurSpeedNum));
		else
			dismay.SetCmdRepState(false);
			dismay.CurSpeedNum = dismay.SpeedNum;
		end
	elseif(dismay.WasSpeeding) then
		dismay.SetCmdRepState(false);
	end
	dismay.WasSpeeding = dismay.IsSpeeding;
end);


dismay.SpoofFunction(dismay.private.o_RenderCapture, render.Capture);
print("***[C] - Loaded");
dismay.runwhenindexcreated("FindMetaTable", function()
	local o = FindMetaTable("Weapon").SetNextPrimaryFire;
	local w = FindMetaTable("Weapon");
	dismay.NextPrimaryFire = {};
	function w:SetNextPrimaryFire(time, ...)
		dismay.NextPrimaryFire[self] = SysTime() + (time - CurTime()) / 4;
		return o(self, time, ...);
	end
	dismay.SpoofFunction(o, FindMetaTable("Weapon").SetNextPrimaryFire);
	dismay.RemoveHook("Think", "f");
end);

function dismay.GetNextPFire(wep)
	return dismay.NextPrimaryFire[wep] or 0;
end
print("***[C] - LOADING AIMBOAT");
dismay.runwhenindexcreated("GAMEMODE", function()
	local GetPred = dismay.GetPred;
	local IsDormant = dismay.IsDormant;
	local lp = LocalPlayer();

	local _R = debug.getregistry();

	local TraceLine = util.TraceLine;

	local function IsValidTrace(trace, targ)
		return not trace.Hit;
	end

	local hooks = dismay.AddHook;
	local sv_gravity 	= GetConVar"sv_gravity";
	local interp_ratio 	= GetConVar"cl_interp_ratio";
	local updaterate 	= GetConVar"cl_updaterate";
	local interp		= GetConVar"cl_interp";

	local function predict(ply, pos, time)
		if(dismay.CustomPrediction) then return dismay.CustomPrediction(ply, pos, time); end
		if(ply ~= LocalPlayer() or not IsValid(ply)) then return pos; end
		if(not dismay.IsSpeeding) then return pos; end
		local ent = ply;
		local i = math.max(interp:GetFloat(), interp_ratio:GetFloat() / updaterate:GetFloat());
		local vel = ent:GetVelocity();
		if(ent:IsOnGround()) then
			vel.z = vel.z - (sv_gravity:GetFloat() * .5 * FrameTime());
			vel.z = vel.z + (ent:GetVelocity().z * FrameTime());
		end
		return pos + vel * (engine.TickInterval() / (dismay.SpeedNum - dismay.CurSpeedNum + 1)) * i;
	end

	local function GetSpread(cmd, ang)
		return dismay.PredSpread(cmd, ang);
	end

	local function clamp(ang)
		ang.p = (ang.p + 180) % 360 - 180
		ang.y = (ang.y + 180) % 360 - 180
		return ang;
	end
	local ptbl = {
		endpos 	= nil;
		filter 	= {LocalPlayer(), nil};
		mask	= MASK_SHOT;
	};
	local function inbox(pos, mins, maxs)
		return pos.x >= mins.x and pos.y >= mins.y and pos.z >= mins.z and pos.x <= maxs.x and pos.y <= maxs.y and pos.z <= maxs.z;
	end
	local t = {
		filter = Entity(0);
		mask = MASK_SHOT;
	};
	local function GetBoneHitGroup(pos) -- fag die
		t.start = pos;
		t.endpos = pos + Vector(0.1, 0.1, 0.1);
		return TraceLine(t).HitGroup
	end
	local lp = LocalPlayer();
	local function GetPos(ply, my_pos)
		if(not IsValid(lp)) then lp = LocalPlayer(); end
		local bestpos = false
		ptbl.filter[2] = ply;
		ptbl.start = predict(lp, my_pos);
		local p = _R.Entity.GetPos(ply);
		local mins = _R.Entity.OBBMins(ply) + p;
		local maxs = _R.Entity.OBBMaxs(ply) + p;
		local best = 12;
		for i = 0, _R.Entity.GetBoneCount(ply) and _R.Entity.GetBoneCount(ply) - 1 or -1 do
			if(not _R.Entity.BoneHasFlag(ply, i, BONE_USED_BY_HITBOX)) then continue; end
			local pos = _R.Entity.GetBonePosition(ply, i);
			ptbl.endpos = predict(ply, pos);
			local trace_r = TraceLine(ptbl);
			local hg = GetBoneHitGroup(pos);
			if(hg == 0) then hg = 11; end
			if(IsValidTrace(trace_r, ply) and inbox(pos, mins, maxs) and hg < best) then
				bestpos = pos;
				best = hg;
			end
		end
		local peye = _R.Entity.EyeAngles(ply);
		if(peye.p >= 90 or peye.p <= -90) then --player is antiaiming
			bestpos = p + ply:OBBCenter();
		end
		
		if(not bestpos) then
			bestpos = ply:EyePos();
		end
		
		return bestpos;
	end

	local frnds = true;
	function dismay.ToggleFriends(bOn)
		frnds = bOn;
	end

	local l = false;
	function dismay.ToggleAimbot(bOn)
		l = bOn;
	end
	local teams = false;
	function dismay.ToggleTeams(bOn)
		teams = bOn;
	end
	function dismay.ToggleAimbotPred(b)
		pred = b;
	end
	dismay.RunMenu([[
		--if(not dismay.PredAimbot) then
		--	local self;
		--	self = dismay.CreateMenuItem("Toggle Prediction", function(bOn)
		--		dismay.AimbotPred = bOn;
		--		dismay.RunClient("dismay.ToggleAimbotPred("..tostring(bOn)..")");
		--	end);
		--	dismay.PredAimbot = self;
		--end
		
		if(not dismay.Aimbot) then
			local self;
			self = dismay.CreateMenuItem("Toggle aimbot", function(bOn)
				dismay.AimbotToggle = bOn;
				dismay.RunClient("dismay.ToggleAimbot("..tostring(bOn)..")");
			end);
			dismay.Aimbot = self;
		end
		if(not dismay.TeamsAimbot) then
			local self;
			self = dismay.CreateMenuItem("Toggle Teams", function(bOn)
				dismay.AimbotTeams = bOn;
				dismay.RunClient("dismay.ToggleTeams("..tostring(bOn)..")");
			end);
			dismay.TeamsAimbot = self;
		end
		if(not dismay.FriendsAimbot) then
			local self;
			self = dismay.CreateMenuItem("Toggle Friends", function(bOn)
				dismay.AimbotFriends = bOn;
				dismay.RunClient("dismay.ToggleFriends("..tostring(bOn)..")");
			end);
			dismay.FriendsAimbot = self;
		end
		dismay.RunClient("dismay.ToggleTeams("..tostring(dismay.AimbotTeams)..");");
		dismay.RunClient("dismay.ToggleAimbot("..tostring(dismay.AimbotToggle)..");");
	]]);

	dismay.RemoveHook("CreateMove", "Aimbot");

	dismay.SetCmdSendState(true);
	dismay.SetCmdRepState(false);
	
	local time = CurTime;
	local ctime = time();
	local silent = false;
	local function angdif3d(x, y)
		return math.abs((x.p - y.p + 180) % 360 - 180) + math.abs((x.y - y.y + 180) % 360 - 180);
	end
	local tracet = ptbl;
	hooks("InitPostEntity", "Aimbot", function()
		tracet.filter[1] = Entity(0);
	end);
	local function CanSee(pos)
		ptbl.endpos = pos;
		return util.TraceLine(ptbl).Fraction == 1;
	end
	local lastang = Angle(0,0,0);
	local gav = _R.CUserCmd.GetViewAngles;
	local sav = _R.CUserCmd.SetViewAngles;
	local rk = _R.CUserCmd.RemoveKey;
	local sb = _R.CUserCmd.SetButtons;
	local gb = _R.CUserCmd.GetButtons;
	hooks("CreateMove", "Aimbot", function(cmd)
		if(dismay.GetCmdRepState()) then return; end
		if(not l) then return; end
		lastang = gav(cmd) - lastang;
		local plys = player.GetAll();
		if(silent) then 
			if(dismay.IsSpeeding) then
				dismay.SetCmdSendState(dismay.GetCmdRepState());
			else
				dismay.SetCmdSendState(not dismay.GetCmdSendState());
			end
		end
		local ply;
		local troo = false;
		local mp = predict(LocalPlayer(), LocalPlayer():GetShootPos());
		for i = 1, #plys do 
			ply = plys[i];
			if(not IsValid(ply)) then rem(plys, i); end
			if(ply == lp) then continue; end
			if(dismay.IsDormant(ply)) then continue; end
			if(ply:GetColor().a ~= 255) then continue; end
			if(ply:Health() <= 0 or not ply:Alive()) then continue; end
			if(ply:GetObserverMode() ~= OBS_MODE_NONE) then continue; end
			if(ply:Team() == rG.TEAM_SPECTATOR) then continue; end
			local pos = GetPos(ply, mp);
			if(pos and mp and CanSee(pos)) then
				local ang = (pos - mp):Angle();
				sav(cmd, dismay.PredSpread(cmd, ang));
				troo = true;
				break;
			end
		end
		
		if(troo) then
			sb(cmd, bit.bor(gb(cmd), IN_ATTACK));
		else
			rk(cmd, IN_ATTACK);
		end
		
		lastang = gav(cmd);
		dismay.LastAng = lastang;
	end)
	print("***[C] - LOADED AIMBOAT");
	dismay.LocalPlayer = nil;
end);

local function IsValidESP(ply, i)
	if(not IsValid(ply)) then
		rem(i);
		return false;
	end
	return true;
end
local _col 				= Color(255,0,0,255);
local col_black			= Color(0,0,0,255);
local SetFont 			= surface.SetFont;
local pairs 			= pairs;
local lp 				= LocalPlayer;
local r 				= debug.getregistry();
local gp 				= r.Entity.GetPos;
local obbmx 			= r.Entity.OBBMaxs;
local obbms 			= r.Entity.OBBMins;
local toscr 			= r.Vector.ToScreen;
local ScrW 				= ScrW();
local ScrH 				= ScrH();
local ghp 				= r.Entity.Health;
local SetDrawColor 		= surface.SetDrawColor;
local SetTextColor 		= surface.SetTextColor;
local SetTextPos 		= surface.SetTextPos;
local DrawText			= surface.DrawText;
local DrawOutlinedRect 	= surface.DrawOutlinedRect;
local GetTextSize		= surface.GetTextSize;
local DrawRect			= surface.DrawRect;
local min 				= math.min;
local max 				= math.max;
local retcol = Color(0,0,0,255);

local function HealthToColor(hp)
	local retcol = Color( 0, 0, 0, 255 )
	local g = min(max(hp * 2.55, 0), 255);
	local r = 255 - min(max((hp - 12) * 2.55, 0), 255);
	retcol.g = g;
	retcol.r = r;
	return retcol;
end

SetFont("BudgetLabel");
local _, h = GetTextSize("|ABCDEF");

dismay.RunMenu([[
	dismay.RunClient("dismay.NoESP = "..(dismay.NoESP and "true" or "false")..";");
]]);
local hud = true;
local view = {
	x = 0;
	y = 0;
	w = ScrW;
	h = ScrH;
	dopostprocess = true;
	drawhud = false;
	drawviewmodel = true;
};

dismay.private.ShouldDrawESP = true;
local vecs = {
	Vector();
	Vector();
	Vector();
	Vector();
	Vector();
	Vector();
	Vector();
	Vector();
};
dismay.AddHook("HUDPaint", "ESP", function()
	if(not hud) then return; end
	if(not dismay.private.ShouldDrawESP) then 
		view.origin = LocalPlayer():EyePos();
		view.angles = LocalPlayer():EyeAngles();
		hud = false;
		render.RenderView(view);
		render.RenderHUD(0, 0, ScrW, ScrH);
		rG.hook.Call("HUDPaint");
		hud = true;
		return;
	end
	if(dismay.NoESP) then return; end
	SetFont("BudgetLabel");
	local col, p, mn, mx, t, mostx, leastx, mosty, leasty, hp, text;
	t = { nil, nil, nil, nil, nil, nil, nil, nil };
	for k,v in next, plys do
		if(v == lp() or not IsValidESP(v, k)) then continue; end
		p = gp(v);
		mn = obbms(v)
		mx = obbmx(v);
		--[[
		for i = 1, 8 do
			local cvec = 1;
			vecs[i].x = 1;
		end]]
		t[1] = toscr(p + mn);
		t[2] = toscr(p + Vector(mn.x, mx.y, mn.z));
		t[3] = toscr(p + Vector(mx.x, mx.y, mn.z));
		t[4] = toscr(p + Vector(mx.x, mn.y, mn.z));
		t[5] = toscr(p + mx);
		t[6] = toscr(p + Vector(mx.x, mn.y, mx.z));
		t[7] = toscr(p + Vector(mn.x, mn.y, mx.z));
		t[8] = toscr(p + Vector(mn.x, mx.y, mx.z));
		mostx, leastx, mosty, leasty = 0,ScrW,0,ScrH;
		for i, cur in ipairs(t) do
			if(cur.x < leastx) then leastx = cur.x; end
			if(cur.y < leasty) then leasty = cur.y; end
			if(cur.x >  mostx) then  mostx = cur.x; end
			if(cur.y >  mosty) then  mosty = cur.y; end
		end
		hp = ghp(v);
		col = rG.team.GetColor(_R.Player.Team(v));
		SetDrawColor(col);
		SetTextColor(col);
		text = v:Nick();
		local w = GetTextSize(text);
		SetTextPos(mostx + 2, leasty);
		DrawText(text);
		SetTextPos(mostx + 2, leasty + h + 2);
		DrawText("H: "..tostring(hp));
		for i = 1, 2 do
			DrawOutlinedRect(leastx + i, leasty + i, (mostx - i * 2) - leastx, (mosty - i * 2) - leasty);
		end
		SetDrawColor(col_black);
		DrawOutlinedRect(leastx, leasty, mostx - leastx, mosty - leasty);
		DrawOutlinedRect(leastx + 3, leasty + 3, (mostx - 3 * 2) - leastx, (mosty - 3 * 2) - leasty);
		DrawOutlinedRect(leastx - 3, leasty, 4, mosty - leasty);
		
		SetDrawColor(HealthToColor(hp));
		local h = min(100, max(0, hp)) / 100;
		local rh = mosty - leasty - 2;
		DrawRect(leastx - 2, leasty + 1 + rh * (1 - h), 2, rh * h);
	end
end);

dismay.RunMenu([[
	if(not dismay.FullBright) then
		local self;
		self = dismay.CreateMenuItem("Toggle Fullbright", function(bOn)
			dismay.FullBrightOn = bOn;
			dismay.RunClient("dismay.FullBright = "..tostring(bOn)..";");
		end);
		dismay.FullBright = self;
	end
	dismay.RunClient("dismay.FullBright = "..tostring(dismay.FullBrightOn)..";");
]]);
dismay.AddHook("RenderScene", "fullbright", function(origin, angles, fov)
	if(not dismay.FullBright) then return; end
	render.SetLightingMode(2);
	render.RenderView{
		origin 	= origin;
		angles 	= angles;
		fov		= fov;
		x		= 0;
		y		= 0;
		w 		= ScrW;
		h		= ScrH;
		drawhud	= false;
		dopostprocess = true;
		drawmonitors = true; 
		drawviewmodel = true;
	};
	render.SetLightingMode(0);
	render.RenderHUD(0, 0, ScrW, ScrH);
	return true;
end)
local x = {
	__index = function() return function() end; end;
	__newindex = function() end;
};
local old_ed = EffectData;
local old_ue = util.Effect;

function rG.util.Effect(...)
	if(predicting) then return; end
	return old_ue(...);
end

dismay.SpoofFunction(old_ue, rG.util.Effect);

function rG.EffectData(...) 
	if(predicting) then
		return setmetatable({}, x);
	end
	return old_ed(...);
end

dismay.SpoofFunction(old_ed, rG.EffectData);

dismay.HideThisFile(function() end);
dismay.RunClient([[dismay.HideThisFile(function() end)]]);

dismay.AddHook("EntityEmitSound", "StopPrediction", function() if(predicting) then return false; end end);