local H=shared.import("\114\101\113\117\105\114\101")local g=(UserSettings()):GetService("\085\115\101\114\071\097\109\101\083\101\116\116\105\110\103\115")local K=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local d=game:GetService("\082\117\110\083\101\114\118\105\099\101")local J=game:GetService("\071\117\105\083\101\114\118\105\099\101")local x=H("\073\110\112\117\116\066\105\110\100\115")local f=(game:FindService("\080\108\097\121\101\114\115")).LocalPlayer.PlayerGui:WaitForChild("\077\111\098\105\108\101\085\073")local S=K.TouchEnabled and(not K.KeyboardEnabled and(not K.MouseEnabled and(not K.GamepadEnabled and not J:IsTenFootInterface())))local V=Vector2.new()local r=Vector2.new()local Y=Vector3.new()local I={Functions={}}local function i(H,g,K)for d,J in pairs(x)do for J,x in pairs(J)do if g.UserInputType==x[1]and g.KeyCode==x[2]then if I.Functions[d]then I.Functions[d](H,K)else warn("\070\076\085\088 \073\078\080\085\084\058 \078\111 \102\117\110\099\116\105\111\110 \105\115 \098\111\117\110\100 \116\111 \'"..(d.."\'"))end end end end if not K then if g.KeyCode==Enum.KeyCode.W then V=Vector2.new(V.X,H and-1 or V.Y<0 and 0 or V.Y)elseif g.KeyCode==Enum.KeyCode.S then V=Vector2.new(V.X,H and 1 or V.Y>0 and 0 or V.Y)elseif g.KeyCode==Enum.KeyCode.A then V=Vector2.new(H and-1 or V.X<0 and 0 or V.X,V.Y)elseif g.KeyCode==Enum.KeyCode.D then V=Vector2.new(H and 1 or V.X>0 and 0 or V.X,V.Y)end end end local function N(...)i(true,...)end local function l(...)i(false,...)end local function B(H,g)if H.UserInputType==Enum.UserInputType.MouseMovement then Y=Vector3.new(H.Delta.X,H.Delta.Y,Y.Z)elseif H.UserInputType==Enum.UserInputType.MouseWheel then Y=Vector3.new(Y.X,Y.Y,H.Position.Z)elseif H.UserInputType==Enum.UserInputType.Gamepad1 then if H.KeyCode==Enum.KeyCode.Thumbstick1 then V=Vector2.new(H.Position.X,-H.Position.Y)elseif H.KeyCode==Enum.KeyCode.Thumbstick2 then r=Vector2.new(H.Delta.X,H.Delta.Y)end end end function I.BindAction(d,H,g,K)if not S then H.Visible=false return end if K then do local K=false H.MouseButton1Click:Connect(function()K=not K d.Functions[g](K,false)end)end else H.MouseButton1Down:Connect(function()d.Functions[g](true,false)end)H.MouseButton1Up:Connect(function()d.Functions[g](false,false)end)end end function I.GetInputMovement(H)return V end function I.GetMouseMovement(H)local g=Y Y=Vector3.new(Y.X,Y.Y,0)return g end function I.GetThumbMovement(H)return r end function I.GetCameraMovement(H)local K=(Vector2.new(Y.X,Y.Y)/100)*g.MouseSensitivity+(r/100)*g.GamepadCameraSensitivity Y=Vector3.new()r=Vector2.new()return K end I:BindAction(f.MobileButtons.FireButton,"\065\099\116\105\118\097\116\101",false)I:BindAction(f.MobileButtons.ReloadButton,"\082\101\108\111\097\100",false)I:BindAction(f.MobileButtons.LowerButton,"\072\111\108\115\116\101\114",false)I:BindAction(f.MobileButtons.Flashlight,"\070\108\097\115\104\108\105\103\104\116",false)K.InputBegan:Connect(N)K.InputEnded:Connect(l)K.InputChanged:Connect(B)return I
--[[
	Name: InputHandler.Luau
	Author(s): @Unknown
	Date: Unknown
	RunTimeContext: Shared
	Information: Input handler able to bind functions to input.
]]

--!nocheck
--!native

local require = shared.import("require")

local UserSetting = UserSettings():GetService("UserGameSettings")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local GuiService = game:GetService("GuiService")

local InputBinds = require("InputBinds")

local MobileUI = game:FindService("Players").LocalPlayer.PlayerGui:WaitForChild("MobileUI")
local isMobileDevice = UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface()
local inputMovement = Vector2.new()
local thumbMovement = Vector2.new()
local mouseMovement = Vector3.new()

local self = {
	Functions = {}
}

local function inputHandle(down, input, gameProcessed)
	for name, binds in pairs(InputBinds) do
		for _, bind in pairs(binds) do
			if input.UserInputType == bind[1] and input.KeyCode == bind[2] then
				if self.Functions[name] then
					self.Functions[name](down, gameProcessed)
				else
					warn("FLUX INPUT: No function is bound to '" .. name .. "'")
				end
			end
		end
	end
	if not gameProcessed then
		if input.KeyCode == Enum.KeyCode.W then
			inputMovement = Vector2.new(inputMovement.X, down and -1 or inputMovement.Y < 0 and 0 or inputMovement.Y)
		elseif input.KeyCode == Enum.KeyCode.S then
			inputMovement = Vector2.new(inputMovement.X, down and 1 or inputMovement.Y > 0 and 0 or inputMovement.Y)
		elseif input.KeyCode == Enum.KeyCode.A then
			inputMovement = Vector2.new(down and -1 or inputMovement.X < 0 and 0 or inputMovement.X, inputMovement.Y)
		elseif input.KeyCode == Enum.KeyCode.D then
			inputMovement = Vector2.new(down and 1 or inputMovement.X > 0 and 0 or inputMovement.X, inputMovement.Y)
		end
	end
end

local function inputBegan(...)
	inputHandle(true, ...)
end

local function inputEnded(...)
	inputHandle(false, ...)
end

local function inputChanged(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		mouseMovement = Vector3.new(input.Delta.X, input.Delta.Y, mouseMovement.Z)
	elseif input.UserInputType == Enum.UserInputType.MouseWheel then
		mouseMovement = Vector3.new(mouseMovement.X, mouseMovement.Y, input.Position.Z)
	elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.Thumbstick1 then
			inputMovement = Vector2.new(input.Position.X, -input.Position.Y)
		elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
			thumbMovement = Vector2.new(input.Delta.X, input.Delta.Y)
		end
	end
end

function self:BindAction(guiObject, action, toggle)
	if not isMobileDevice then
		guiObject.Visible = false
		return
	end
	if toggle then
		do
			local active = false
			guiObject.MouseButton1Click:Connect(function()
				active = not active
				self.Functions[action](active, false)
			end)
		end
	else
		guiObject.MouseButton1Down:Connect(function()
			self.Functions[action](true, false)
		end)
		guiObject.MouseButton1Up:Connect(function()
			self.Functions[action](false, false)
		end)
	end
end

function self:GetInputMovement()
	return inputMovement
end

function self:GetMouseMovement()
	local currentMouse = mouseMovement
	mouseMovement = Vector3.new(mouseMovement.X, mouseMovement.Y, 0)
	return currentMouse
end

function self:GetThumbMovement()
	return thumbMovement
end

function self:GetCameraMovement()
	local cameraMovement = Vector2.new(mouseMovement.X, mouseMovement.Y) / 100 * UserSetting.MouseSensitivity + thumbMovement / 100 * UserSetting.GamepadCameraSensitivity
	mouseMovement = Vector3.new()
	thumbMovement = Vector2.new()
	return cameraMovement
end

self:BindAction(MobileUI.MobileButtons.FireButton, "Activate", false)
self:BindAction(MobileUI.MobileButtons.ReloadButton, "Reload", false)
self:BindAction(MobileUI.MobileButtons.LowerButton, "Holster", false)
self:BindAction(MobileUI.MobileButtons.Flashlight, "Flashlight", false)

UserInputService.InputBegan:Connect(inputBegan)
UserInputService.InputEnded:Connect(inputEnded)
UserInputService.InputChanged:Connect(inputChanged)

return self
