local K={}local D=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer:GetMouse()local C=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local s=workspace.CurrentCamera local N=workspace local w=Ray.new function K.GetPosition(K)return C:GetMouseLocation()end function K.GetDelta(K)return C:GetMouseDelta()end function K.Lock(K)C.MouseBehavior=Enum.MouseBehavior.LockCurrentPosition end function K.LockCenter(K)C.MouseBehavior=Enum.MouseBehavior.LockCenter end function K.Unlock(K)C.MouseBehavior=Enum.MouseBehavior.Default end function K.SetMouseIcon(C,K)D.Icon=K and"\114\098\120\097\115\115\101\116\105\100\058\047\047"..K or""end function K.SetMouseIconEnabled(D,K)C.MouseIconEnabled=K end function K.IsMouseIconEnabled(K)return C.MouseIconEnabled end function K.GetRay(K)local D=C:GetMouseLocation()local N=s:ViewportPointToRay(D.X,D.Y)return w(N.Origin,N.Direction*999)end function K.Cast(s,K,D,C)return N:FindPartOnRay(s:GetRay(),K,D,C)end function K.CastWithIgnoreList(s,K,D,C)return N:FindPartOnRayWithIgnoreList(s:GetRay(),K,D,C)end function K.CastWithWhitelist(C,K,D)return N:FindPartOnRayWithWhitelist(C:GetRay(),K,D)end function K.Start(K) end function K.Init(K)K.LeftDown=K.Shared.Event.new()K.LeftUp=K.Shared.Event.new()K.RightDown=K.Shared.Event.new()K.RightUp=K.Shared.Event.new()K.MiddleDown=K.Shared.Event.new()K.MiddleUp=K.Shared.Event.new()K.Moved=K.Shared.Event.new()K.Scrolled=K.Shared.Event.new()C.InputBegan:Connect(function(D,C)if C then return end if D.UserInputType==Enum.UserInputType.MouseButton1 then K.LeftDown:Fire()elseif D.UserInputType==Enum.UserInputType.MouseButton2 then K.RightDown:Fire()elseif D.UserInputType==Enum.UserInputType.MouseButton3 then K.MiddleDown:Fire()end end)C.InputEnded:Connect(function(D,C)if D.UserInputType==Enum.UserInputType.MouseButton1 then K.LeftUp:Fire()elseif D.UserInputType==Enum.UserInputType.MouseButton2 then K.RightUp:Fire()elseif D.UserInputType==Enum.UserInputType.MouseButton3 then K.MiddleUp:Fire()end end)C.InputChanged:Connect(function(D,C)if D.UserInputType==Enum.UserInputType.MouseMovement then K.Moved:Fire()elseif D.UserInputType==Enum.UserInputType.MouseWheel then if not C then K.Scrolled:Fire(D.Position.Z)end end end)end return K
--[[
	
	Vector2   Mouse:GetPosition()
	Vector2   Mouse:GetDelta()
	Void      Mouse:Lock()
	Void      Mouse:LockCenter()
	Void      Mouse:Unlock()
	Void      Mouse:SetMouseIcon(iconId)
	Void      Mouse:SetMouseIconEnabled(isEnabled)
	Boolean   Mouse:IsMouseIconEnabled()
	Many      Mouse:Cast(ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	Many      Mouse:CastWithIgnoreList(ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	Many      Mouse:CastWithWhitelist(whitelistDescendantsTable, ignoreWater)
	
	Mouse.LeftDown()
	Mouse.LeftUp()
	Mouse.RightDown()
	Mouse.RightUp()
	Mouse.MiddleDown()
	Mouse.MiddleUp()
	Mouse.Moved()
	Mouse.Scrolled(amount)
	
--]]

local Mouse = {}

local playerMouse = game:GetService("Players").LocalPlayer:GetMouse()
local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera

local workspace = workspace
local RAY = Ray.new

function Mouse:GetPosition()
	return userInput:GetMouseLocation()
end

function Mouse:GetDelta()
	return userInput:GetMouseDelta()
end

function Mouse:Lock()
	userInput.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end

function Mouse:LockCenter()
	userInput.MouseBehavior = Enum.MouseBehavior.LockCenter
end

function Mouse:Unlock()
	userInput.MouseBehavior = Enum.MouseBehavior.Default
end

function Mouse:SetMouseIcon(iconId)
	playerMouse.Icon = (iconId and ("rbxassetid://" .. iconId) or "")
end

function Mouse:SetMouseIconEnabled(enabled)
	userInput.MouseIconEnabled = enabled
end

function Mouse:IsMouseIconEnabled()
	return userInput.MouseIconEnabled
end

function Mouse:GetRay()
	local mousePos = userInput:GetMouseLocation()
	local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	return RAY(viewportMouseRay.Origin, viewportMouseRay.Direction * 999)
end

function Mouse:Cast(ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRay(self:GetRay(), ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
end

function Mouse:CastWithIgnoreList(ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRayWithIgnoreList(
		self:GetRay(),
		ignoreDescendantsTable,
		terrainCellsAreCubes,
		ignoreWater
	)
end

function Mouse:CastWithWhitelist(whitelistDescendantsTable, ignoreWater)
	return workspace:FindPartOnRayWithWhitelist(self:GetRay(), whitelistDescendantsTable, ignoreWater)
end

function Mouse:Start() end

function Mouse:Init()
	self.LeftDown = self.Shared.Event.new()
	self.LeftUp = self.Shared.Event.new()
	self.RightDown = self.Shared.Event.new()
	self.RightUp = self.Shared.Event.new()
	self.MiddleDown = self.Shared.Event.new()
	self.MiddleUp = self.Shared.Event.new()
	self.Moved = self.Shared.Event.new()
	self.Scrolled = self.Shared.Event.new()

	userInput.InputBegan:Connect(function(input, processed)
		if processed then
			return
		end
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			self.LeftDown:Fire()
		elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
			self.RightDown:Fire()
		elseif input.UserInputType == Enum.UserInputType.MouseButton3 then
			self.MiddleDown:Fire()
		end
	end)

	userInput.InputEnded:Connect(function(input, processed)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			self.LeftUp:Fire()
		elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
			self.RightUp:Fire()
		elseif input.UserInputType == Enum.UserInputType.MouseButton3 then
			self.MiddleUp:Fire()
		end
	end)

	userInput.InputChanged:Connect(function(input, processed)
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			self.Moved:Fire()
		elseif input.UserInputType == Enum.UserInputType.MouseWheel then
			if not processed then
				self.Scrolled:Fire(input.Position.Z)
			end
		end
	end)
end

return Mouse
