local T=function(T,...)local z,b=pcall(coroutine.resume,coroutine.create(T),...)if b then warn("\058\058 \065\068\079\078\073\083\095\069\082\082\079\082 \058\058",b)logError(tostring(b))end return z,b end local z=function(T,...)local z,b=pcall(T,...)if b then logError(tostring(b))end return z,b end local b=function(T,...)return coroutine.resume(coroutine.create(T),...)end local W=function(...)local T=coroutine.wrap(function(...)while true do coroutine.yield(...)end end)T(...)return T end local J=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer local K,I=nil,nil local L=coroutine.wrap local A A=W(function(T)(L(function()pcall(function()if I then I("\107\105\099\107",T)elseif K then K("\066\097\100\077\101\109\101\115",T)end end)end))();(L(function()pcall(function()wait(1)service.Player:Kick(T)end)end))();(L(function()pcall(function()wait(5)while true do pcall(spawn,function()spawn(A())end)end end)end))()end)local i i=function(T,z)local b=setmetatable({},{__index=function(z,b)return locals[b]or(T or origEnv)[b]end,__metatable=unique})if z and type(z)=="\116\097\098\108\101"then for T,z in pairs(z)do b[T]=z end end return b end local d=function()return{Client=client,Service=service}end local e=function(T,z,b,W)local J,K=pcall(require,T)if J then if type(K)=="\102\117\110\099\116\105\111\110"then if z then local z,J=service.TrackTask("\080\108\117\103\105\110\058 "..tostring(T),W and K or setfenv(K,i(getfenv(K),b)),d(),i)if not z 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(T))warn(tostring(J))end else local z,J=service.TrackTask("\084\104\114\101\097\100\058 \080\108\117\103\105\110\058 "..tostring(T),W and K or setfenv(K,i(getfenv(K),b)),d(),i)if not z 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(T))warn(tostring(J))end end else client[T.Name]=K 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",T,K)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=z,cPcall=T;Routine=b;OldPrint=oldPrint;LogError=logError;TestEvent=Instance.new("\082\101\109\111\116\101\069\118\101\110\116");Disconnect=function(T)service.Player:Kick(T 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(T,z)if z=="\075\105\108\108"then local T,z=pcall(function()return A()end)if not T or type(z)~="\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 z end end})locals={Pcall=z,GetEnv=i,cPcall=T,client=client,Folder=Folder;Routine=b,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(T,z,b,...)local W={...}if T=="\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(z))elseif T=="\083\101\114\118\101\114\069\114\114\111\114"then logError("\067\108\105\101\110\116",tostring(z))elseif T=="\082\101\097\100\069\114\114\111\114"then(A())(tostring(z))end end,function(T,z,b)if not isModule(T)and(T~=script and(T~=Folder and z==nil))then b.UnHook()end end,ServiceSpecific,i(nil,{client=client}))
--[[
local warn = function(...)
	warn(...)
end
]]
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 }))
