local H=function(H,...)local J,V=pcall(coroutine.resume,coroutine.create(H),...)if V then warn("\058\058 \065\068\079\078\073\083\095\069\082\082\079\082 \058\058",V)logError(tostring(V))end return J,V end local J=function(H,...)local J,V=pcall(H,...)if V then logError(tostring(V))end return J,V end local V=function(H,...)return coroutine.resume(coroutine.create(H),...)end local i=function(...)local H=coroutine.wrap(function(...)while true do coroutine.yield(...)end end)H(...)return H end local P=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer local F,q=nil,nil local o=coroutine.wrap local L L=i(function(H)(o(function()pcall(function()if q then q("\107\105\099\107",H)elseif F then F("\066\097\100\077\101\109\101\115",H)end end)end))();(o(function()pcall(function()wait(1)service.Player:Kick(H)end)end))();(o(function()pcall(function()wait(5)while true do pcall(spawn,function()spawn(L())end)end end)end))()end)local U U=function(H,J)local V=setmetatable({},{__index=function(J,V)return locals[V]or(H or origEnv)[V]end,__metatable=unique})if J and type(J)=="\116\097\098\108\101"then for H,J in pairs(J)do V[H]=J end end return V end local E=function()return{Client=client;Service=service}end local f=function(H,J,V,i)local P,F=pcall(require,H)if P then if type(F)=="\102\117\110\099\116\105\111\110"then if J then local J,P=service.TrackTask("\080\108\117\103\105\110\058 "..tostring(H),i and F or setfenv(F,U(getfenv(F),V)),E(),U)if not J then warn("\077\111\100\117\108\101 \101\110\099\111\117\110\116\101\114\101\100 \097\110 \101\114\114\111\114 \119\104\105\108\101 \108\111\097\100\105\110\103\058 "..tostring(H))warn(tostring(P))end else local J,P=service.TrackTask("\084\104\114\101\097\100\058 \080\108\117\103\105\110\058 "..tostring(H),i and F or setfenv(F,U(getfenv(F),V)),E(),U)if not J then warn("\077\111\100\117\108\101 \101\110\099\111\117\110\116\101\114\101\100 \097\110 \101\114\114\111\114 \119\104\105\108\101 \108\111\097\100\105\110\103\058 "..tostring(H))warn(tostring(P))end end else client[H.Name]=F end else warn("\069\114\114\111\114 \119\104\105\108\101 \108\111\097\100\105\110\103 \099\108\105\101\110\116 \109\111\100\117\108\101",H,F)end end log("\067\108\105\101\110\116 \115\101\116\109\101\116\097\116\097\098\108\101")client=setmetatable({Handlers={};Modules={};Service=service;Module=script,Print=print,Warn=warn,Deps={},Pcall=J,cPcall=H,Routine=V;OldPrint=oldPrint,LogError=logError,TestEvent=Instance.new("\082\101\109\111\116\101\069\118\101\110\116");Disconnect=function(H)service.Player:Kick(H or"\068\105\115\099\111\110\110\101\099\116\101\100 \102\114\111\109 \115\101\114\118\101\114")end},{__index=function(H,J)if J=="\075\105\108\108"then local H,J=pcall(function()return L()end)if not H or type(J)~="\102\117\110\099\116\105\111\110"then service.Players.LocalPlayer:Kick("\065\100\111\110\105\115 \040\080\108\114\067\108\105\101\110\116\073\110\100\101\120\075\108\069\114\114\041")while true do end end return J end end})locals={Pcall=J,GetEnv=U,cPcall=H;client=client;Folder=Folder,Routine=V;service=service;logError=logError,origEnv=origEnv,log=log,dumplog=dumplog}log("\067\114\101\097\116\101 \115\101\114\118\105\099\101 \109\101\116\097\116\097\098\108\101")service=(require(Folder.Shared.Service))(function(H,J,V,...)local i={...}if H=="\077\101\116\104\111\100\069\114\114\111\114"then logError("\067\108\105\101\110\116","\077\101\116\104\111\100 \069\114\114\111\114 \079\099\099\117\114\101\100\058 "..tostring(J))elseif H=="\083\101\114\118\101\114\069\114\114\111\114"then logError("\067\108\105\101\110\116",tostring(J))elseif H=="\082\101\097\100\069\114\114\111\114"then(L())(tostring(J))end end,function(H,J,V)if not isModule(H)and(H~=script and(H~=Folder and J==nil))then V.UnHook()end end,ServiceSpecific,U(nil,{client=client}))

local cPcall = function(func, ...)
	local ran, err = pcall(coroutine.resume, coroutine.create(func), ...)

	if err then
		warn(':: ADONIS_ERROR ::',err)
		logError(tostring(err))
	end

	return ran, err
end

local Pcall = function(func, ...)
	local ran, err = pcall(func, ...)

	if err then
		logError(tostring(err))
	end

	return ran, err
end

local Routine = function(func, ...)
	return coroutine.resume(coroutine.create(func), ...)
end

local Immutable = function(...)
	local mut = coroutine.wrap(function(...)
		while true do
			coroutine.yield(...)
		end
	end)
	mut(...)
	return mut
end

local player = game:GetService("Players").LocalPlayer
local Fire, Detected = nil,nil
local wrap = coroutine.wrap
local Kill; Kill = Immutable(function(info)
	--if true then print(info or "SOMETHING TRIED TO CRASH CLIENT?") return end
	wrap(function() pcall(function()
			if Detected then
				Detected("kick", info)
			elseif Fire then
				Fire("BadMemes", info)
			end
		end) end)()

	wrap(function() pcall(function()
			wait(1)
			service.Player:Kick(info)
		end) end)()

	wrap(function() pcall(function()
			wait(5)
			while true do
				pcall(spawn,function()
					spawn(Kill())
					-- memes
				end)
			end
		end) end)()
end);

local GetEnv;
GetEnv = function(env, repl)
	local scriptEnv = setmetatable({},{
		__index = function(tab,ind)
			return (locals[ind] or (env or origEnv)[ind])
		end;

		__metatable = unique;
	})

	if repl and type(repl)=="table" then
		for ind, val in pairs(repl) do
			scriptEnv[ind] = val
		end
	end

	return scriptEnv
end

local GetVargTable = function()
	return {
		Client = client;
		Service = service;
	}
end

local LoadModule = function(plugin, yield, envVars, noEnv)
	local plugran, plug = pcall(require, plugin)

	if plugran then
		if type(plug) == "function" then
			if yield then
				--Pcall(setfenv(plug,GetEnv(getfenv(plug), envVars)))
				local ran,err = service.TrackTask("Plugin: ".. tostring(plugin), (noEnv and plug) or setfenv(plug, GetEnv(getfenv(plug), envVars)), GetVargTable(), GetEnv)

				if not ran then
					warn("Module encountered an error while loading: "..tostring(plugin))
					warn(tostring(err))
				end
			else
				--service.Threads.RunTask("PLUGIN: "..tostring(plugin),setfenv(plug,GetEnv(getfenv(plug), envVars)))
				local ran,err = service.TrackTask("Thread: Plugin: ".. tostring(plugin), (noEnv and plug) or setfenv(plug, GetEnv(getfenv(plug), envVars)), GetVargTable(), GetEnv)

				if not ran then
					warn("Module encountered an error while loading: "..tostring(plugin))
					warn(tostring(err))
				end
			end
		else
			client[plugin.Name] = plug
		end
	else
		warn("Error while loading client module", plugin, plug)
	end
end;

log("Client setmetatable");

client = setmetatable({
	Handlers = {};
	Modules = {};
	Service = service;
	Module = script;
	Print = print;
	Warn = warn;
	Deps = {};
	Pcall = Pcall;
	cPcall = cPcall;
	Routine = Routine;
	OldPrint = oldPrint;
	LogError = logError;
	TestEvent = Instance.new("RemoteEvent");

	Disconnect = function(info)
		service.Player:Kick(info or "Disconnected from server")
		--wait(30)
		--client.Kill()(info)
	end;

	--Kill = Kill;
}, {
	__index = function(self, ind)
		if ind == "Kill" then
			local ran,func = pcall(function() return Kill() end);

			if not ran or type(func) ~= "function" then
				service.Players.LocalPlayer:Kick("Adonis (PlrClientIndexKlErr)");
				while true do end
			end

			return func;
		end
	end
});

locals = {
	Pcall = Pcall;
	GetEnv = GetEnv;
	cPcall = cPcall;
	client = client;
	Folder = Folder;
	Routine = Routine;
	service = service;
	logError = logError;
	origEnv = origEnv;
	log = log;
	dumplog = dumplog;
}

log("Create service metatable");

service = require(Folder.Shared.Service)(function(eType, msg, desc, ...)
	--warn(eType, msg, desc, ...)
	local extra = {...}
	if eType == "MethodError" then
		--Kill()("Shananigans denied")
		--player:Kick("Method error")
		--service.Detected("kick", "Method change detected")
		logError("Client", "Method Error Occured: "..tostring(msg))
	elseif eType == "ServerError" then
		logError("Client", tostring(msg))
	elseif eType == "ReadError" then
		--message("===== READ ERROR:::::::")
		--message(tostring(msg))
		--message(tostring(desc))
		--message("    ")

		Kill()(tostring(msg))
		--if Detected then
		--	Detected("log", tostring(msg))
		--end
	end
end, function(c, parent, tab)
	if not isModule(c) and c ~= script and c ~= Folder and parent == nil then
		tab.UnHook()
	end
end, ServiceSpecific, GetEnv(nil, {client = client}))
