local p=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local N=game:GetService("\080\108\097\121\101\114\115")local q=game:GetService("\083\116\097\114\116\101\114\071\117\105")local k=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local a=p("\067\104\097\114\097\099\116\101\114\085\116\105\108")local Y={}Y.__index=Y Y.ClassName="\067\111\114\101\071\117\105\069\110\097\098\108\101\114"function Y.new()local p=setmetatable({},Y)p._states={}p:AddState(Enum.CoreGuiType.Backpack,function(p)q:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,p)a.UnequipTools(N.LocalPlayer)end)for N,k in pairs(Enum.CoreGuiType:GetEnumItems())do if not p._states[k]then p:AddState(k,function(p)q:SetCoreGuiEnabled(k,p)end)end end p.TopbarEnabledState=Instance.new("\066\111\111\108\086\097\108\117\101")p.TopbarEnabledState.Value=false p:AddState("\084\111\112\098\097\114\069\110\097\098\108\101\100",function(N)p.TopbarEnabledState.Value=N local k,a=pcall(function()q:SetCore("\084\111\112\098\097\114\069\110\097\098\108\101\100",N)end)if not k then warn("\070\097\105\108\101\100 \116\111 \115\101\116 \116\111\112\098\097\114",a)end end)p:AddState("\077\111\100\097\108\069\110\097\098\108\101\100",function(p)k.ModalEnabled=not p end)p:AddState("\077\111\117\115\101\073\099\111\110\069\110\097\098\108\101\100",function(p)k.MouseIconEnabled=p end)return p end function Y.AddState(q,p,N)assert(type(N)=="\102\117\110\099\116\105\111\110","\109\117\115\116 \104\097\118\101 \099\111\114\101\071\117\105\083\116\097\116\101\067\104\097\110\103\101\070\117\110\099 \097\115 \102\117\110\099\116\105\111\110")assert(q._states[p]==nil,"\115\116\097\116\101 \097\108\114\101\097\100\121 \101\120\105\115\116\115")local k={}local a=true local function Y()for p,N in pairs(k)do return false end return true end q._states[p]=setmetatable({},{__newindex=function(p,q,E)rawset(k,q,E)local J=Y()if a~=J then a=J N(J)end end})end function Y.Disable(q,p,N)if not q._states[N]then error(("\091\067\111\114\101\071\117\105\069\110\097\098\108\101\114\093 - \083\116\097\116\101 \'\037\115\' \100\111\101\115 \110\111\116 \101\120\105\115\116\046"):format(tostring(N)))end q._states[N][p]=true return function()q:Enable(p,N)end end function Y.Enable(q,p,N)if not q._states[N]then error(("\091\067\111\114\101\071\117\105\069\110\097\098\108\101\114\093 - \083\116\097\116\101 \'\037\115\' \100\111\101\115 \110\111\116 \101\120\105\115\116\046"):format(tostring(N)))end q._states[N][p]=nil end return Y.new()
--- Key based CoreGuiEnabler, singleton
-- Use this class to load/unload CoreGuis / other GUIs, by disabling based upon keys
-- Keys are additive, so if you have more than 1 disabled, it's ok.
-- @module CoreGuiEnabler

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")

local CharacterUtil = require("CharacterUtil")

local CoreGuiEnabler = {}
CoreGuiEnabler.__index = CoreGuiEnabler
CoreGuiEnabler.ClassName = "CoreGuiEnabler"

function CoreGuiEnabler.new()
	local self = setmetatable({}, CoreGuiEnabler)

	self._states = {}

	self:AddState(Enum.CoreGuiType.Backpack, function(isEnabled)
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, isEnabled)
		CharacterUtil.UnequipTools(Players.LocalPlayer)
	end)

	for _, coreGuiType in pairs(Enum.CoreGuiType:GetEnumItems()) do
		if not self._states[coreGuiType] then
			self:AddState(coreGuiType, function(isEnabled)
				StarterGui:SetCoreGuiEnabled(coreGuiType, isEnabled)
			end)
		end
	end

	self.TopbarEnabledState = Instance.new("BoolValue")
	self.TopbarEnabledState.Value = false

	self:AddState("TopbarEnabled", function(isEnabled)
		self.TopbarEnabledState.Value = isEnabled
		local success, err = pcall(function()
			StarterGui:SetCore("TopbarEnabled", isEnabled)
		end)
		if not success then
			warn("Failed to set topbar", err)
		end
	end)

	self:AddState("ModalEnabled", function(isEnabled)
		UserInputService.ModalEnabled = not isEnabled
	end)

	self:AddState("MouseIconEnabled", function(isEnabled)
		UserInputService.MouseIconEnabled = isEnabled
	end)

	return self
end

function CoreGuiEnabler:AddState(key, coreGuiStateChangeFunc)
	assert(type(coreGuiStateChangeFunc) == "function", "must have coreGuiStateChangeFunc as function")
	assert(self._states[key] == nil, "state already exists")

	local realState = {}
	local lastState = true

	local function isEnabled()
		for _, _ in pairs(realState) do
			return false
		end
		return true
	end

	self._states[key] = setmetatable({}, {
		__newindex = function(_, index, value)
			rawset(realState, index, value)

			local newState = isEnabled()
			if lastState ~= newState then
				lastState = newState
				coreGuiStateChangeFunc(newState)
			end
		end;
	})
end

function CoreGuiEnabler:Disable(key, coreGuiState)
	if not self._states[coreGuiState] then
		error(("[CoreGuiEnabler] - State '%s' does not exist."):format(tostring(coreGuiState)))
	end

	self._states[coreGuiState][key] = true

	return function()
		self:Enable(key, coreGuiState)
	end
end

function CoreGuiEnabler:Enable(key, coreGuiState)
	if not self._states[coreGuiState] then
		error(("[CoreGuiEnabler] - State '%s' does not exist."):format(tostring(coreGuiState)))
	end

	self._states[coreGuiState][key] = nil
end

return CoreGuiEnabler.new()