local function N(N,p,f)local z z=function(N,p)if p then for N,f in ipairs(N:GetChildren())do local D=f:Clone()if f:IsA("\070\111\108\100\101\114")then local N=p:FindFirstChild(f.Name)if not N then D.Parent=p else z(f,N)end else D.Parent=p end end else warn("\077\105\115\115\105\110\103 \112\097\114\101\110\116 \116\111 \117\110\112\097\099\107 \105\110\116\111 \102\111\114 "..tostring(N))end end z(N,p)end local function p()warn("\066\101\103\105\110\110\105\110\103 \065\100\111\110\105\115 \099\108\101\097\110\117\112 \038 \115\104\117\116\100\111\119\110 \112\114\111\099\101\115\115\046\046\046")server.Model.Name="\065\100\111\110\105\115\095\076\111\097\100\101\114"server.Model.Parent=service.ServerScriptService server.Running=false pcall(service.Threads.StopAll)pcall(function()for N,p in pairs(RbxEvents)do print("\068\105\115\099\111\110\110\101\099\116\105\110\103 \101\118\101\110\116")p:Disconnect()table.remove(RbxEvents,N)end end)if server.Core and server.Core.RemoteEvent then pcall(server.Core.DisconnectEvent)end warn("\085\110\108\111\097\100\105\110\103 \099\111\109\112\108\101\116\101")end server={Running=true;Modules={};Pcall=Pcall;cPcall=cPcall,Routine=Routine;LogError=logError,ErrorLogs=ErrorLogs,ServerStartTime=os.time();CommandCache={}}locals={server=server;CodeName="",Settings=server.Settings,HookedEvents=HookedEvents;ErrorLogs=ErrorLogs;logError=logError,origEnv=origEnv;Routine=Routine;Folder=Folder,GetEnv=GetEnv;cPcall=cPcall;Pcall=Pcall}service=(require(Folder.Shared.Service))(function(N,p,f,...)local z={...}if N=="\077\101\116\104\111\100\069\114\114\111\114"then if server and(server.Logs and server.Logs.AddLog)then server.Logs.AddLog("\083\099\114\105\112\116",{Text="\067\097\099\104\101\100 \109\101\116\104\111\100 \100\111\101\115\110\'\116 \109\097\116\099\104 \102\111\117\110\100 \109\101\116\104\111\100\058 "..tostring(z[1]);Desc="\077\101\116\104\111\100\058 "..tostring(z[1])})end elseif N=="\083\101\114\118\101\114\069\114\114\111\114"then logError("\083\101\114\118\101\114",p)elseif N=="\084\097\115\107\069\114\114\111\114"then logError("\084\097\115\107",p)end end,function(N,p,f)if not isModule(N)and(N~=server.Loader and(N~=server.Dropper and(N~=server.Runner and(N~=server.Model and(N~=script and(N~=Folder and p==nil))))))then f.UnHook()end end,ServiceSpecific,GetEnv(nil,{server=server}))
--// WIP
local function LoadPackage(package, folder, runNow)
	--// runNow - Run immediately after unpacking (default behavior is to just unpack (((only needed if loading after startup))))
	--// runNow currently not used (limitations) so all packages must be present at server startup
	local unpack
	unpack = function(curFolder, unpackInto)
		if unpackInto then
			for i, obj in ipairs(curFolder:GetChildren()) do
				local clone = obj:Clone()
				if obj:IsA("Folder") then
					local realFolder = unpackInto:FindFirstChild(obj.Name)
					if not realFolder then
						clone.Parent = unpackInto
					else
						unpack(obj, realFolder)
					end
				else
					clone.Parent = unpackInto
				end
			end
		else
			warn("Missing parent to unpack into for " .. tostring(curFolder))
		end
	end

	unpack(package, folder)
end

local function CleanUp()
	--local env = getfenv(2)
	--local ran,ret = pcall(function() return env.script:GetFullName() end)
	warn("Beginning Adonis cleanup & shutdown process...")
	--warn("CleanUp called from "..tostring((ran and ret) or "Unknown"))
	--local loader = server.Core.ClientLoader
	server.Model.Name = "Adonis_Loader"
	server.Model.Parent = service.ServerScriptService
	server.Running = false

	pcall(service.Threads.StopAll)
	pcall(function()
		for i, v in pairs(RbxEvents) do
			print("Disconnecting event")
			v:Disconnect()
			table.remove(RbxEvents, i)
		end
	end)
	--loader.Archivable = false
	--loader.Disabled = true
	--loader:Destroy()
	if server.Core and server.Core.RemoteEvent then
		pcall(server.Core.DisconnectEvent)
	end

	--[[delay(0, function()
		for i,v in next,server do
			server[i] = nil; --// Try to break it to prevent any potential hanging issues; Not very graceful...
		end
	--end)--]]

	warn("Unloading complete")
end

server = {
	Running = true,
	Modules = {},
	Pcall = Pcall,
	cPcall = cPcall,
	Routine = Routine,
	LogError = logError,
	ErrorLogs = ErrorLogs,
	ServerStartTime = os.time(),
	CommandCache = {},
}

locals = {
	server = server,
	CodeName = "",
	Settings = server.Settings,
	HookedEvents = HookedEvents,
	ErrorLogs = ErrorLogs,
	logError = logError,
	origEnv = origEnv,
	Routine = Routine,
	Folder = Folder,
	GetEnv = GetEnv,
	cPcall = cPcall,
	Pcall = Pcall,
}

service = require(Folder.Shared.Service)(function(eType, msg, desc, ...)
	local extra = { ... }
	if eType == "MethodError" then
		if server and server.Logs and server.Logs.AddLog then
			server.Logs.AddLog("Script", {
				Text = "Cached method doesn't match found method: " .. tostring(extra[1]),
				Desc = "Method: " .. tostring(extra[1]),
			})
		end
	elseif eType == "ServerError" then
		--print("Server error")
		logError("Server", msg)
	elseif eType == "TaskError" then
		--print("Task error")
		logError("Task", msg)
	end
end, function(c, parent, tab)
	if
		not isModule(c)
		and c ~= server.Loader
		and c ~= server.Dropper
		and c ~= server.Runner
		and c ~= server.Model
		and c ~= script
		and c ~= Folder
		and parent == nil
	then
		tab.UnHook()
	end
end, ServiceSpecific, GetEnv(nil, { server = server }))
