return function(e)local C=service.PlayerGui local N=service.Players.LocalPlayer local L=script.Parent.Parent local H=L.Frame local r=H.termCont local g=H.serverCont local K=H.localCont local A=H.logsCont local S=H.scriptCont local q=H.errorCont local a=H.localTab local I=H.scriptTab local d=H.logsTab local v=H.termTab local f=H.serverTab local z=H.errorTab local h=L.Frame.Close local V=L.Frame.Command local s=L.Frame.Nameb local E=L.Frame.Dragger local m=L.Entry local W={}local j={}local o={}local Q={}local O={}local R={}local function X()K.Visible=true S.Visible=false A.Visible=false r.Visible=false g.Visible=false q.Visible=false a.BackgroundTransparency=0 I.BackgroundTransparency=.5 d.BackgroundTransparency=.5 v.BackgroundTransparency=.5 f.BackgroundTransparency=.5 z.BackgroundTransparency=.5 end local function J()K.Visible=false S.Visible=true A.Visible=false r.Visible=false g.Visible=false q.Visible=false a.BackgroundTransparency=.5 I.BackgroundTransparency=0 d.BackgroundTransparency=.5 v.BackgroundTransparency=.5 f.BackgroundTransparency=.5 z.BackgroundTransparency=.5 end local function x()K.Visible=false S.Visible=false A.Visible=true r.Visible=false g.Visible=false q.Visible=false a.BackgroundTransparency=.5 I.BackgroundTransparency=.5 d.BackgroundTransparency=0 v.BackgroundTransparency=.5 f.BackgroundTransparency=.5 z.BackgroundTransparency=.5 end local function F()K.Visible=false S.Visible=false A.Visible=false r.Visible=true g.Visible=false q.Visible=false a.BackgroundTransparency=.5 I.BackgroundTransparency=.5 d.BackgroundTransparency=.5 v.BackgroundTransparency=0 f.BackgroundTransparency=.5 z.BackgroundTransparency=.5 end local function P()K.Visible=false S.Visible=false A.Visible=false r.Visible=false g.Visible=true q.Visible=false a.BackgroundTransparency=.5 I.BackgroundTransparency=.5 d.BackgroundTransparency=.5 v.BackgroundTransparency=.5 f.BackgroundTransparency=0 z.BackgroundTransparency=.5 end local function l()K.Visible=false S.Visible=false A.Visible=false r.Visible=false g.Visible=false q.Visible=true a.BackgroundTransparency=.5 I.BackgroundTransparency=.5 d.BackgroundTransparency=.5 v.BackgroundTransparency=.5 f.BackgroundTransparency=.5 z.BackgroundTransparency=0 end local function p(e,C)e:ClearAllChildren()local N=0 for C,L in next,C do local H,r,g=m:Clone()if type(L)=="\116\097\098\108\101"then r=L.Text g=L.Color else r=tostring(L)end H.Visible=true H.Text=tostring(r)H.Position=UDim2.new(0,0,0,N*20)H.Parent=e H.TextColor3=g or H.TextColor3 N=N+1 end e.CanvasSize=UDim2.new(0,0,0,N*20)local L=N*20-e.AbsoluteWindowSize.Y if L<0 then L=0 end e.CanvasPosition=Vector2.new(0,L)end local function M()p(S,O)p(A,Q)p(g,o)p(r,W)p(K,j)p(q,R)end local function n(e,C)table.insert(C,e)if#C>500 then table.remove(C,1)end end local function Y(e)local C={}for e,N in next,e do if type(N)=="\116\097\098\108\101"then local e,L=N.messageType if e=="\069\114\114\111\114"then L=Color3.new(1,0,0)elseif e=="\073\110\102\111"then L=Color3.new(0,0,1)elseif e=="\087\097\114\110\105\110\103"then L=Color3.new(0,1,1)end table.insert(C,{Text=N.message;Color=L})else table.insert(C,tostring(N))end end return C end local function y(e)local C={}for e,N in next,e do if type(N)=="\116\097\098\108\101"then table.insert(C,{Text=tostring(N.Text)..("\058 "..tostring(N.Desc))})else table.insert(C,tostring(N))end end return C end service.Events.TerminalLive:connect(function(e)local C=e.Data local N=e.Type n(C,W)p(r,W)end)local U=service.StartLoop("\084\101\114\109\105\110\097\108\076\111\111\112",1,function()service.Debounce("\095\084\069\082\077\073\078\065\076\095\085\080\068\065\084\073\078\071",function()local e=client.Remote.Get("\084\101\114\109\105\110\097\108\068\097\116\097")o=Y(e.ServerLogs or{})Q=y(e.AdminLogs or{})O=y(e.ScriptLogs or{})R=y(e.ErrorLogs or{})j=Y(service.LogService:GetLogHistory()or{})p(S,O)p(A,Q)p(q,R)p(g,o)p(K,j)end)end,true)V.FocusLost:connect(function(e)service.Debounce("\095\084\069\082\077\073\078\065\076\095\066\079\088\095\070\079\067\085\083\076\079\083\084",function()wait(.1)if e and V.Text~=""then local e=V.Text V.Text=""n("\062"..e,W)p(r,W)local C=client.Remote.Get("\084\101\114\109\105\110\097\108",e,{Time=tick()})if C and type(C)=="\116\097\098\108\101"then for e,C in next,C do n(C,W)end p(r,W)end V:CaptureFocus()V.Text=""end end)end)h.MouseButton1Click:connect(function()U:Kill()client.Remote.Send("\083\101\115\115\105\111\110","\084\101\114\109\105\110\097\108",false)n("\068\105\115\099\111\110\110\101\099\116\105\110\103 \115\101\115\115\105\111\110\046\046\046",W)p(r,W)wait(.5)L:Destroy()end)a.MouseButton1Down:connect(X)I.MouseButton1Down:connect(J)d.MouseButton1Down:connect(x)v.MouseButton1Down:connect(F)f.MouseButton1Down:connect(P)z.MouseButton1Down:connect(l)local t=service.Players.LocalPlayer:GetMouse()local w,i=H.AbsoluteSize.X,H.AbsoluteSize.Y local Z=false local G,u=w,i t.Move:connect(function(e,C)if Z then w=G+(E.Position.X.Offset+20)i=u+(E.Position.Y.Offset+20)if w<300 then w=300 end if i<200 then i=200 end H.Size=UDim2.new(0,w,0,i)end end)E.DragBegin:connect(function(e)Z=true H.Active=false end)E.DragStopped:connect(function(e,C)H.Active=true Z=false G=w u=i E.Position=UDim2.new(1,-20,1,-20)M()end)M()gTable:Ready()end
--// All global vars will be wiped/replaced except script

return function(data)
	local playergui = service.PlayerGui
	local localplayer = service.Players.LocalPlayer
	local gui = script.Parent.Parent
	local frame = gui.Frame
	--local cont = gui.Frame.Container

	local termCont = frame.termCont
	local serverCont = frame.serverCont
	local localCont = frame.localCont
	local logsCont = frame.logsCont
	local scriptCont = frame.scriptCont
	local errorCont = frame.errorCont

	local localTab = frame.localTab
	local scriptTab = frame.scriptTab
	local logsTab = frame.logsTab
	local termTab = frame.termTab
	local serverTab = frame.serverTab
	local errorTab = frame.errorTab

	local close = gui.Frame.Close
	local box = gui.Frame.Command
	local name = gui.Frame.Nameb
	local dragger = gui.Frame.Dragger
	local entry = gui.Entry

	local termLines = {}
	local localLines = {}
	local serverLines = {}
	local logsLines = {}
	local scriptLines = {}
	local errorLines = {}

	local function openLocal()
		localCont.Visible = true
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false

		localTab.BackgroundTransparency = 0
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end

	local function openScript()
		localCont.Visible = false
		scriptCont.Visible = true
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false

		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end

	local function openLogs()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = true
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false

		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end

	local function openTerm()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = true
		serverCont.Visible = false
		errorCont.Visible = false

		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end

	local function openServer()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = true
		errorCont.Visible = false

		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0
		errorTab.BackgroundTransparency = 0.5
	end

	local function openErrors()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = true

		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0
	end

	local function populate(cont, lines)
		cont:ClearAllChildren()

		local num = 0
		for i, v in next, lines do
			local new, text, color = entry:Clone()

			if type(v) == "table" then
				text = v.Text
				color = v.Color
			else
				text = tostring(v)
			end

			new.Visible = true
			new.Text = tostring(text)
			new.Position = UDim2.new(0, 0, 0, num * 20)
			new.Parent = cont
			new.TextColor3 = color or new.TextColor3
			num = num + 1
		end

		cont.CanvasSize = UDim2.new(0, 0, 0, (num * 20))
		local glob = ((num * 20) - cont.AbsoluteWindowSize.Y)
		if glob < 0 then
			glob = 0
		end
		cont.CanvasPosition = Vector2.new(0, glob)
	end

	local function populateAll()
		populate(scriptCont, scriptLines)
		populate(logsCont, logsLines)
		populate(serverCont, serverLines)
		populate(termCont, termLines)
		populate(localCont, localLines)
		populate(errorCont, errorLines)
	end

	--name.Text = localplayer.userId.."@"..game.PlaceId.." ;/>"

	local function out(put, lines)
		table.insert(lines, put)
		if #lines > 500 then
			table.remove(lines, 1)
		end
	end

	local function formatOutput(tab)
		local new = {}
		for i, v in next, tab do
			if type(v) == "table" then
				local typ, color = v.messageType
				if typ == "Error" then
					color = Color3.new(1, 0, 0)
				elseif typ == "Info" then
					color = Color3.new(0, 0, 1)
				elseif typ == "Warning" then
					color = Color3.new(0, 1, 1)
				end

				table.insert(new, {
					Text = v.message,
					Color = color,
				})
			else
				table.insert(new, tostring(v))
			end
		end
		return new
	end

	local function formatLogs(tab)
		local new = {}
		for i, v in next, tab do
			if type(v) == "table" then
				table.insert(new, {
					Text = tostring(v.Text) .. ": " .. tostring(v.Desc),
				})
			else
				table.insert(new, tostring(v))
			end
		end
		return new
	end

	service.Events.TerminalLive:connect(function(rData)
		local data = rData.Data
		local rType = rData.Type

		out(data, termLines)
		populate(termCont, termLines)
	end)

	local updater = service.StartLoop("TerminalLoop", 1, function()
		service.Debounce("_TERMINAL_UPDATING", function()
			local data = client.Remote.Get("TerminalData")

			--termLines = data.Output
			serverLines = formatOutput(data.ServerLogs or {})
			logsLines = formatLogs(data.AdminLogs or {})
			scriptLines = formatLogs(data.ScriptLogs or {})
			errorLines = formatLogs(data.ErrorLogs or {})
			localLines = formatOutput(service.LogService:GetLogHistory() or {})

			--populate(termCont,termLines)
			populate(scriptCont, scriptLines)
			populate(logsCont, logsLines)
			populate(errorCont, errorLines)
			populate(serverCont, serverLines)
			populate(localCont, localLines)
		end)
	end, true)

	box.FocusLost:connect(function(enterPressed)
		service.Debounce("_TERMINAL_BOX_FOCUSLOST", function()
			wait(0.1)
			if enterPressed and box.Text ~= "" then
				local com = box.Text
				box.Text = ""
				out(">" .. com, termLines)
				populate(termCont, termLines)
				local ret = client.Remote.Get("Terminal", com, {
					Time = tick(),
				})
				if ret and type(ret) == "table" then
					for i, ent in next, ret do
						out(ent, termLines)
					end
					populate(termCont, termLines)
				end
				box:CaptureFocus()
				box.Text = ""
			end
		end)
	end)

	close.MouseButton1Click:connect(function()
		updater:Kill()
		client.Remote.Send("Session", "Terminal", false)
		out("Disconnecting session...", termLines)
		populate(termCont, termLines)
		wait(0.5)
		gui:Destroy()
	end)

	localTab.MouseButton1Down:connect(openLocal)
	scriptTab.MouseButton1Down:connect(openScript)
	logsTab.MouseButton1Down:connect(openLogs)
	termTab.MouseButton1Down:connect(openTerm)
	serverTab.MouseButton1Down:connect(openServer)
	errorTab.MouseButton1Down:connect(openErrors)

	local mouse = service.Players.LocalPlayer:GetMouse()
	local nx, ny = frame.AbsoluteSize.X, frame.AbsoluteSize.Y --500,300
	local dragging = false
	local defx, defy = nx, ny
	mouse.Move:connect(function(x, y)
		if dragging then
			nx = defx + (dragger.Position.X.Offset + 20)
			ny = defy + (dragger.Position.Y.Offset + 20)
			if nx < 300 then
				nx = 300
			end
			if ny < 200 then
				ny = 200
			end
			frame.Size = UDim2.new(0, nx, 0, ny)
		end
	end)
	dragger.DragBegin:connect(function(init)
		dragging = true
		frame.Active = false
	end)
	dragger.DragStopped:connect(function(x, y)
		frame.Active = true
		dragging = false
		defx = nx
		defy = ny
		dragger.Position = UDim2.new(1, -20, 1, -20)
		populateAll()
	end)

	populateAll()
	gTable:Ready()
end
