function MouseLockController.OnMouseLockToggled(y)y.isMouseLocked=not y.isMouseLocked if y.isMouseLocked then local J=script:FindFirstChild("\067\117\114\115\111\114\073\109\097\103\101")if J and(J:IsA("\083\116\114\105\110\103\086\097\108\117\101")and J.Value)then y.savedMouseCursor=Mouse.Icon else if J then J:Destroy()end J=Instance.new("\083\116\114\105\110\103\086\097\108\117\101")J.Name="\067\117\114\115\111\114\073\109\097\103\101"J.Value=DEFAULT_MOUSE_LOCK_CURSOR J.Parent=script y.savedMouseCursor=Mouse.Icon end else if y.savedMouseCursor then y.savedMouseCursor=nil end end y.mouseLockToggledEvent:Fire()end function MouseLockController.DoMouseLockSwitch(l,y,J,K)if J==Enum.UserInputState.Begin then l:OnMouseLockToggled()return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function MouseLockController.BindContextActions(y)ContextActionService:BindActionAtPriority(CONTEXT_ACTION_NAME,function(J,K,l)return y:DoMouseLockSwitch(J,K,l)end,false,MOUSELOCK_ACTION_PRIORITY,unpack(y.boundKeys))end function MouseLockController.UnbindContextActions(y)ContextActionService:UnbindAction(CONTEXT_ACTION_NAME)end function MouseLockController.IsMouseLocked(y)return y.enabled and y.isMouseLocked end function MouseLockController.EnableMouseLock(J,y)if y~=J.enabled then J.enabled=y if J.enabled then J:BindContextActions()else if Mouse.Icon~=""then Mouse.Icon=""end J:UnbindContextActions()if J.isMouseLocked then J.mouseLockToggledEvent:Fire()end J.isMouseLocked=false end end end return MouseLockController
--[[ Local Functions ]]
--
function MouseLockController:OnMouseLockToggled()
	self.isMouseLocked = not self.isMouseLocked

	if self.isMouseLocked then
		local cursorImageValueObj = script:FindFirstChild("CursorImage")
		if cursorImageValueObj and cursorImageValueObj:IsA("StringValue") and cursorImageValueObj.Value then
			self.savedMouseCursor = Mouse.Icon
			--Mouse.Icon = cursorImageValueObj.Value
		else
			if cursorImageValueObj then
				cursorImageValueObj:Destroy()
			end
			cursorImageValueObj = Instance.new("StringValue")
			cursorImageValueObj.Name = "CursorImage"
			cursorImageValueObj.Value = DEFAULT_MOUSE_LOCK_CURSOR
			cursorImageValueObj.Parent = script
			self.savedMouseCursor = Mouse.Icon
			--Mouse.Icon = DEFAULT_MOUSE_LOCK_CURSOR
		end
	else
		if self.savedMouseCursor then
			--Mouse.Icon = self.savedMouseCursor
			self.savedMouseCursor = nil
		end
	end

	self.mouseLockToggledEvent:Fire()
end

function MouseLockController:DoMouseLockSwitch(name, state, input)
	if state == Enum.UserInputState.Begin then
		self:OnMouseLockToggled()
		return Enum.ContextActionResult.Sink
	end
	return Enum.ContextActionResult.Pass
end

function MouseLockController:BindContextActions()
	ContextActionService:BindActionAtPriority(CONTEXT_ACTION_NAME, function(name, state, input)
		return self:DoMouseLockSwitch(name, state, input)
	end, false, MOUSELOCK_ACTION_PRIORITY, unpack(self.boundKeys))
end

function MouseLockController:UnbindContextActions()
	ContextActionService:UnbindAction(CONTEXT_ACTION_NAME)
end

function MouseLockController:IsMouseLocked()
	return self.enabled and self.isMouseLocked
end

function MouseLockController:EnableMouseLock(enable)
	if enable ~= self.enabled then
		self.enabled = enable

		if self.enabled then
			-- Enabling the mode
			self:BindContextActions()
		else
			-- Disabling
			-- Restore mouse cursor
			if Mouse.Icon ~= "" then
				Mouse.Icon = ""
			end

			self:UnbindContextActions()

			-- If the mode is disabled while being used, fire the event to toggle it off
			if self.isMouseLocked then
				self.mouseLockToggledEvent:Fire()
			end

			self.isMouseLocked = false
		end
	end
end

return MouseLockController
