local k={}local u=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer:GetMouse()local B=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local R=workspace.CurrentCamera local H=workspace local O=Ray.new function k.GetPosition(k)return B:GetMouseLocation()end function k.GetDelta(k)return B:GetMouseDelta()end function k.Lock(k)B.MouseBehavior=Enum.MouseBehavior.LockCurrentPosition end function k.LockCenter(k)B.MouseBehavior=Enum.MouseBehavior.LockCenter end function k.Unlock(k)B.MouseBehavior=Enum.MouseBehavior.Default end function k.SetMouseIcon(B,k)u.Icon=k and"\114\098\120\097\115\115\101\116\105\100\058\047\047"..k or""end function k.SetMouseIconEnabled(u,k)B.MouseIconEnabled=k end function k.IsMouseIconEnabled(k)return B.MouseIconEnabled end function k.GetRay(k)local u=B:GetMouseLocation()local H=R:ViewportPointToRay(u.X,u.Y)return O(H.Origin,H.Direction*999)end function k.Cast(R,k,u,B)return H:FindPartOnRay(R:GetRay(),k,u,B)end function k.CastWithIgnoreList(R,k,u,B)return H:FindPartOnRayWithIgnoreList(R:GetRay(),k,u,B)end function k.CastWithWhitelist(B,k,u)return H:FindPartOnRayWithWhitelist(B:GetRay(),k,u)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()B.InputBegan:Connect(function(u,B)if B then return end if u.UserInputType==Enum.UserInputType.MouseButton1 then k.LeftDown:Fire()elseif u.UserInputType==Enum.UserInputType.MouseButton2 then k.RightDown:Fire()elseif u.UserInputType==Enum.UserInputType.MouseButton3 then k.MiddleDown:Fire()end end)B.InputEnded:Connect(function(u,B)if u.UserInputType==Enum.UserInputType.MouseButton1 then k.LeftUp:Fire()elseif u.UserInputType==Enum.UserInputType.MouseButton2 then k.RightUp:Fire()elseif u.UserInputType==Enum.UserInputType.MouseButton3 then k.MiddleUp:Fire()end end)B.InputChanged:Connect(function(u,B)if u.UserInputType==Enum.UserInputType.MouseMovement then k.Moved:Fire()elseif u.UserInputType==Enum.UserInputType.MouseWheel then if not B then k.Scrolled:Fire(u.Position.Z)end end end)end return k




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
