return function(d)local l=d.Server local R=d.Service local z,Q,e,o,Z,B,O,G,v,K local function a()z=l.Functions Q=l.Admin e=l.Anti o=l.Core Z=l.HTTP B=l.Logs O=l.Remote G=l.Process v=l.Variables K=l.Settings B:AddLog("\083\099\114\105\112\116","\065\110\116\105\069\120\112\108\111\105\116 \077\111\100\117\108\101 \073\110\105\116\105\097\108\105\122\101\100")end l.Anti={Init=a,SpoofCheckCache={},RemovePlayer=function(d,l)l=l or"\078\111 \082\101\097\115\111\110 \071\105\118\101\110"pcall(function()(R.UnWrap(d)):Kick(tostring(l))end)wait(1)pcall(d.Destroy,d)pcall(R.Delete,d)B.AddLog("\083\099\114\105\112\116",{Text="\083\101\114\118\101\114 \114\101\109\111\118\101\100 "..tostring(d);Desc=tostring(l)})end;UserSpoofCheck=function(d)if not R.RunService:IsStudio()then local l=R.UserService local z,Q=pcall(function()local R=e.SpoofCheckCache[d.UserId]or l:GetUserInfosByUserIdsAsync({d.UserId})local z=R and R[1]e.SpoofCheckCache[d.UserId]=R if z and z.Id==d.UserId then if d.Name~=z.Username or d.DisplayName~=z.DisplayName then return true end else for l,R in next,R do if R.Id==d.UserId then if d.Name~=R.Username or d.DisplayName~=R.DisplayName then return true end end end end end)if not z then warn("\070\097\105\108\101\100 \116\111 \099\104\101\099\107 \118\097\108\105\100\105\116\121 \111\102 \112\108\097\121\101\114\'\115 \110\097\109\101\044 \114\101\097\115\111\110\058 "..tostring(Q))end end end,Sanitize=function(d,l)if e.RLocked(d)then pcall(R.Delete,d)else for d,Q in next,d:GetChildren()do if e.RLocked(Q)or z.IsClass(Q,l)then pcall(R.Delete,Q)else pcall(e.Sanitize,Q,l)end end end end,isFake=function(d)if e.ObjRLocked(d)or not d:IsA("\080\108\097\121\101\114")then return true,1 else local l=R.Players:GetChildren()local z=0 if R.NetworkServer then local l=false for R,z in pairs(R.NetworkServer:GetChildren())do if z:IsA("\078\101\116\119\111\114\107\082\101\112\108\105\099\097\116\111\114")and z:GetPlayer()==d then l=true end end if not l then return true,1 end end for l,R in pairs(l)do if tostring(R)==tostring(d)then z=z+1 end end if z>1 then return true,z else return false end end end,RemoveIfFake=function(d)local l local R,z=pcall(function()l=e.isFake(d)end)if l or not R then e.RemovePlayer(d)end end,FindFakePlayers=function()for d,l in pairs(R.Players:GetChildren())do if e.isFake(l)then e.RemovePlayer(l,"\070\097\107\101")end end end,GetClassName=function(d)local l=tostring(math.random()..math.random())local R,z=pcall(function()local R=d[l]end)if z then local d=z:match(l.." \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \040\046\042\041")if d then return d end end end,RLocked=function(d)return not pcall(function()return d.GetFullName(d)end)end;ObjRLocked=function(d)return not pcall(function()return d.GetFullName(d)end)end,AssignName=function()local d=math.random(100000,999999)return d end;Detected=function(d,l,z)local Q=string.gsub(tostring(z),"\n","")if o.DebugMode or R.RunService:IsStudio()then warn("\065\078\084\073-\069\088\080\076\079\073\084\058 "..(d.Name..(" "..(l..(" "..Q)))))elseif R.NetworkServer then if d then if l:lower()=="\108\111\103"then elseif l:lower()=="\107\105\099\107"then e.RemovePlayer(d,Q)elseif l:lower()=="\107\105\108\108"then d.Character:BreakJoints()elseif l:lower()=="\099\114\097\115\104"then O.Send(d,"\070\117\110\099\116\105\111\110","\075\105\108\108")wait(5)pcall(function()local l=o.NewScript("\076\111\099\097\108\083\099\114\105\112\116","\119\104\105\108\101 \116\114\117\101 \100\111 \101\110\100")l.Parent=d.Backpack l.Disabled=false end)e.RemovePlayer(d,Q)else e.Detected(d,"\075\105\099\107","\083\112\111\111\102\101\100 \108\111\103")return end end end B.AddLog(B.Script,{Text="\065\069 \068\101\116\101\099\116\101\100 "..tostring(d),Desc="\084\104\101 \065\110\116\105-\069\120\112\108\111\105\116 \115\121\115\116\101\109 \100\101\116\101\099\116\101\100 \115\116\114\097\110\103\101 \097\099\116\105\118\105\116\121 \102\114\111\109 "..tostring(d);Player=d})B.AddLog(B.Exploit,{Text="\091\065\099\116\105\111\110\058 "..(tostring(l)..(" \085\115\101\114\058 \040"..(tostring(d)..("\041\093 "..(tostring(Q:sub(1,50)).." \040\077\111\117\115\101 \111\118\101\114 \102\117\108\108 \105\110\102\111\041"))))),Desc=tostring(Q);Player=d})end;CheckNameID=function(d)if d.userId>0 and(d.userId~=game.CreatorId and d.Character)then local l=R.Players:GetUserIdFromNameAsync(d.Name)or d.userId local z=R.Players:GetNameFromUserIdAsync(d.userId)or d.Name if z and l then if tonumber(l)and l~=d.userId or tostring(z)~="\110\105\108"and z~=d.Name then e.Detected(d,"\108\111\103","\078\097\109\101\047\085\115\101\114\073\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")end O.Send(d,"\076\097\117\110\099\104\065\110\116\105","\078\097\109\101\073\100",{RealID=l;RealName=z})end end end}end

return function(Vargs)
	local server = Vargs.Server;
	local service = Vargs.Service;

	local Functions, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Settings
	local function Init()
		Functions = server.Functions;
		Admin = server.Admin;
		Anti = server.Anti;
		Core = server.Core;
		HTTP = server.HTTP;
		Logs = server.Logs;
		Remote = server.Remote;
		Process = server.Process;
		Variables = server.Variables;
		Settings = server.Settings;

		Logs:AddLog("Script", "AntiExploit Module Initialized")
	end;

	server.Anti = {
		Init = Init;
		SpoofCheckCache = {};
		RemovePlayer = function(p, info)
			info = info or "No Reason Given"
			pcall(function() service.UnWrap(p):Kick(tostring(info)) end)
			--pcall(function() Remote.Send(p,"Function","Kill") end)
			wait(1)
			pcall(p.Destroy, p)
			pcall(service.Delete, p)
			Logs.AddLog("Script",{
				Text = "Server removed "..tostring(p);
				Desc = tostring(info);
			})
		end;

		UserSpoofCheck = function(p)
			--// Supplied by BetterAccount
			if not service.RunService:IsStudio() then
				local userService = service.UserService;
				local success,err = pcall(function()
					local userInfo = Anti.SpoofCheckCache[p.UserId] or userService:GetUserInfosByUserIdsAsync({p.UserId})
					local data = userInfo and userInfo[1];

					Anti.SpoofCheckCache[p.UserId] = userInfo;

					if data and data.Id == p.UserId then
						if p.Name ~= data.Username or p.DisplayName ~= data.DisplayName then
							return true
						end
					else
						for i,user in next,userInfo do
							if user.Id == p.UserId then
								if p.Name ~= user.Username or p.DisplayName ~= user.DisplayName then
									return true
								end
							end
						end
					end
				end)

				if not success then
					warn("Failed to check validity of player's name, reason: ".. tostring(err))
				end
			end
		end;

		Sanitize = function(obj, classList)
			if Anti.RLocked(obj) then
				pcall(service.Delete, obj)
			else
				for i,child in next,obj:GetChildren() do
					if Anti.RLocked(child) or Functions.IsClass(child, classList) then
						pcall(service.Delete, child)
					else
						pcall(Anti.Sanitize, child, classList)
					end
				end
			end
		end;

		isFake = function(p)
			if Anti.ObjRLocked(p) or not p:IsA("Player") then
				return true,1
			else
				local players = service.Players:GetChildren()
				local found = 0

				if service.NetworkServer then
					local net = false
					for i,v in pairs(service.NetworkServer:GetChildren()) do
						if v:IsA("NetworkReplicator") and v:GetPlayer() == p then
							net = true
						end 
					end
					if not net then
						return true,1
					end
				end

				for i,v in pairs(players) do
					if tostring(v) == tostring(p) then
						found = found+1
					end
				end

				if found>1 then
					return true,found
				else
					return false
				end
			end
		end;

		RemoveIfFake = function(p)
			local isFake
			local ran,err = pcall(function() isFake = Anti.isFake(p) end)
			if isFake or not ran then
				Anti.RemovePlayer(p)
			end
		end;

		FindFakePlayers = function()
			for i,v in pairs(service.Players:GetChildren()) do
				if Anti.isFake(v) then
					Anti.RemovePlayer(v, "Fake")
				end
			end
		end;

		GetClassName = function(obj)
			local testName = tostring(math.random()..math.random())
			local ran,err = pcall(function()
				local test = obj[testName]
			end)
			if err then
				local class = err:match(testName.." is not a valid member of (.*)")
				if class then
					return class
				end
			end
		end;

		RLocked = function(obj)
			return not pcall(function() return obj.GetFullName(obj) end)
			--[[local ran,err = pcall(function() service.New("StringValue", obj):Destroy() end)
			if ran then
				return false
			else
				return true
			end--]]
		end;

		ObjRLocked = function(obj)
			return not pcall(function() return obj.GetFullName(obj) end)
			--[[local ran,err = pcall(function() obj.Parent = obj.Parent end)
			if ran then
				return false
			else
				return true
			end--]]
		end;

		AssignName = function()
			local name = math.random(100000,999999)
			return name
		end;

		Detected = function(player,action,info)
			local info = string.gsub(tostring(info), "\n", "")

			if Core.DebugMode or service.RunService:IsStudio() then 
				warn("ANTI-EXPLOIT: "..player.Name.." "..action.." "..info)
			elseif service.NetworkServer then
				if player then
					if action:lower() == 'log' then
						-- yay?
					elseif action:lower() == 'kick' then
						Anti.RemovePlayer(player, info)
						--player:Kick("Adonis; Disconnected by server; \n"..tostring(info))
					elseif action:lower() == 'kill' then
						player.Character:BreakJoints()
					elseif action:lower() == 'crash' then
						Remote.Send(player,'Function','Kill')
						wait(5)
						pcall(function()
							local scr = Core.NewScript("LocalScript",[[while true do end]])
							scr.Parent = player.Backpack
							scr.Disabled = false
						end)

						Anti.RemovePlayer(player, info)
					else
						-- fake log (thonk?)
						Anti.Detected(player, "Kick", "Spoofed log")
						return;
					end
				end
			end

			Logs.AddLog(Logs.Script,{
				Text = "AE Detected "..tostring(player);
				Desc = "The Anti-Exploit system detected strange activity from "..tostring(player);
				Player = player;
			})

			Logs.AddLog(Logs.Exploit,{
				Text = "[Action: "..tostring(action).." User: (".. tostring(player) ..")] ".. tostring(info:sub(1, 50)) .. " (Mouse over full info)";
				Desc = tostring(info);
				Player = player;
			})
		end;

		CheckNameID = function(p)
			if p.userId > 0 and p.userId ~= game.CreatorId and p.Character then 
				local realId = service.Players:GetUserIdFromNameAsync(p.Name) or p.userId
				local realName = service.Players:GetNameFromUserIdAsync(p.userId) or p.Name

				if realName and realId then
					if (tonumber(realId) and realId~=p.userId) or (tostring(realName)~="nil" and realName~=p.Name) then 
						Anti.Detected(p,'log','Name/UserId does not match') 
					end 

					Remote.Send(p,"LaunchAnti","NameId",{RealID = realId; RealName = realName})
				end
			end 
		end;
	};
end
