local C=game:GetService("\082\117\110\083\101\114\118\105\099\101")local O=game:GetService("\083\116\097\114\116\101\114\071\117\105")local V=game:GetService("\080\108\097\121\101\114\115")local L=V.LocalPlayer local j=script:WaitForChild("\083\104\097\114\101\100")local W=require(j:WaitForChild("\085\116\105\108"))if C:IsClient()==false then error("\083\101\114\118\101\114 \115\099\114\105\112\116\115 \099\097\110\110\111\116 \114\101\113\117\105\114\101 \116\104\101 \099\108\105\101\110\116 \108\105\098\114\097\114\121\046 \080\108\101\097\115\101 \114\101\113\117\105\114\101 \116\104\101 \115\101\114\118\101\114 \108\105\098\114\097\114\121 \116\111 \117\115\101 \067\109\100\114 \105\110 \121\111\117\114 \111\119\110 \099\111\100\101\046")end local y do y=setmetatable({ReplicatedRoot=script;RemoteFunction=script:WaitForChild("\067\109\100\114\070\117\110\099\116\105\111\110");RemoteEvent=script:WaitForChild("\067\109\100\114\069\118\101\110\116");ActivationKeys={[Enum.KeyCode.F2]=true};Enabled=true,MashToEnable=false,ActivationUnlocksMouse=false,HideOnLostFocus=true,PlaceName="\067\109\100\114",Util=W,Events={}},{__index=function(C,O)local V=C.Dispatcher[O]if V and type(V)=="\102\117\110\099\116\105\111\110"then return function(O,...)return V(C.Dispatcher,...)end end end})y.Registry=(require(j.Registry))(y)y.Dispatcher=(require(j.Dispatcher))(y)end if O:WaitForChild("\067\109\100\114")and(wait()and(L:WaitForChild("\080\108\097\121\101\114\071\117\105")):FindFirstChild("\067\109\100\114")==nil)then(O.Cmdr:Clone()).Parent=L.PlayerGui end local I=(require(script.CmdrInterface))(y)function y.SetActivationKeys(O,C)O.ActivationKeys=W.MakeDictionary(C)end function y.SetPlaceName(O,C)O.PlaceName=C I.Window:UpdateLabel()end function y.SetEnabled(O,C)O.Enabled=C end function y.SetActivationUnlocksMouse(O,C)O.ActivationUnlocksMouse=C end function y.Show(C)if not C.Enabled then return end I.Window:Show()end function y.Hide(C)I.Window:Hide()end function y.Toggle(C)if not C.Enabled then return C:Hide()end I.Window:SetVisible(not I.Window:IsVisible())end function y.SetMashToEnable(O,C)O.MashToEnable=C if C then O:SetEnabled(false)end end function y.SetHideOnLostFocus(O,C)O.HideOnLostFocus=C end function y.HandleEvent(V,C,O)V.Events[C]=O end if C:IsServer()==false then y.Registry:RegisterTypesIn(script:WaitForChild("\084\121\112\101\115"))y.Registry:RegisterCommandsIn(script:WaitForChild("\067\111\109\109\097\110\100\115"))end y.RemoteEvent.OnClientEvent:Connect(function(C,...)if y.Events[C]then y.Events[C](...)end end);(require(script.DefaultEventHandlers))(y)return y
local RunService = game:GetService("RunService")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Shared = script:WaitForChild("Shared")
local Util = require(Shared:WaitForChild("Util"))

if RunService:IsClient() == false then
	error("Server scripts cannot require the client library. Please require the server library to use Cmdr in your own code.")
end

local Cmdr do
	Cmdr = setmetatable({
		ReplicatedRoot = script;
		RemoteFunction = script:WaitForChild("CmdrFunction");
		RemoteEvent = script:WaitForChild("CmdrEvent");
		ActivationKeys = {[Enum.KeyCode.F2] = true};
		Enabled = true;
		MashToEnable = false;
		ActivationUnlocksMouse = false;
		HideOnLostFocus = true;
		PlaceName = "Cmdr";
		Util = Util;
		Events = {};
	}, {
		-- This sucks, and may be redone or removed
		-- Proxies dispatch methods on to main Cmdr object
		__index = function (self, k)
			local r = self.Dispatcher[k]
			if r and type(r) == "function" then
				return function (_, ...)
					return r(self.Dispatcher, ...)
				end
			end
		end
	})

	Cmdr.Registry = require(Shared.Registry)(Cmdr)
	Cmdr.Dispatcher = require(Shared.Dispatcher)(Cmdr)
end

if StarterGui:WaitForChild("Cmdr") and wait() and Player:WaitForChild("PlayerGui"):FindFirstChild("Cmdr") == nil then
	StarterGui.Cmdr:Clone().Parent = Player.PlayerGui
end

local Interface = require(script.CmdrInterface)(Cmdr)

--// Sets a list of keyboard keys (Enum.KeyCode) that can be used to open the commands menu
function Cmdr:SetActivationKeys (keysArray)
	self.ActivationKeys = Util.MakeDictionary(keysArray)
end

--// Sets the place name label on the interface
function Cmdr:SetPlaceName (name)
	self.PlaceName = name
	Interface.Window:UpdateLabel()
end

--// Sets whether or not the console is enabled
function Cmdr:SetEnabled (enabled)
	self.Enabled = enabled
end

--// Sets if activation will free the mouse.
function Cmdr:SetActivationUnlocksMouse (enabled)
	self.ActivationUnlocksMouse = enabled
end

--// Shows Cmdr window
function Cmdr:Show ()
	if not self.Enabled then
		return
	end

	Interface.Window:Show()
end

--// Hides Cmdr window
function Cmdr:Hide ()
	Interface.Window:Hide()
end

--// Toggles Cmdr window
function Cmdr:Toggle ()
	if not self.Enabled then
		return self:Hide()
	end

	Interface.Window:SetVisible(not Interface.Window:IsVisible())
end

--// Enables the "Mash to open" feature
function Cmdr:SetMashToEnable(isEnabled)
	self.MashToEnable = isEnabled

	if isEnabled then
		self:SetEnabled(false)
	end
end

--// Sets the hide on 'lost focus' feature.
function Cmdr:SetHideOnLostFocus(enabled)
	self.HideOnLostFocus = enabled
end

--// Sets the handler for a certain event type
function Cmdr:HandleEvent(name, callback)
	self.Events[name] = callback
end

-- Only register when we aren't in studio because don't want to overwrite what the server portion did
if RunService:IsServer() == false then
	Cmdr.Registry:RegisterTypesIn(script:WaitForChild("Types"))
	Cmdr.Registry:RegisterCommandsIn(script:WaitForChild("Commands"))
end

-- Hook up event listener
Cmdr.RemoteEvent.OnClientEvent:Connect(function(name, ...)
	if Cmdr.Events[name] then
		Cmdr.Events[name](...)
	end
end)

require(script.DefaultEventHandlers)(Cmdr)

return Cmdr
