local U=require(script.Parent:WaitForChild("\066\097\115\101\067\104\097\114\097\099\116\101\114\067\111\110\116\114\111\108\108\101\114"))local I=setmetatable({},U)I.__index=I local s=Enum.UserInputType.None function I.new()local Q=setmetatable(U.new(),I)Q.forwardValue=0 Q.backwardValue=0 Q.leftValue=0 Q.rightValue=0 Q.activeGamepad=s Q.gamepadConnectedConn=nil Q.gamepadDisconnectedConn=nil return Q end local Q=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local C=Vector3.new(0,0,0)function I.Enable(U,I)if not Q.GamepadEnabled then return false end if I==U.enabled then return true end U.forwardValue=0 U.backwardValue=0 U.leftValue=0 U.rightValue=0 U.moveVector=C U.isJumping=false if I then U.activeGamepad=U:GetHighestPriorityGamepad()if U.activeGamepad==s then return false end U:BindContextActions()U:ConnectGamepadConnectionListeners()else U:UnbindContextActions()U:DisconnectGamepadConnectionListeners()U.activeGamepad=s end U.enabled=I return true end function I.GetHighestPriorityGamepad(U)local I=s for U,s in pairs(Q:GetConnectedGamepads())do if s.Value<I.Value then I=s end end return I end local n=game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")function I.BindContextActions(U)if U.activeGamepad==s then return false end n:BindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)n:BindAction("\106\117\109\112\065\099\116\105\111\110",function(I,s,Q)U.isJumping=s==Enum.UserInputState.Begin end,false,Enum.KeyCode.ButtonA)n:BindAction("\109\111\118\101\084\104\117\109\098\115\116\105\099\107",function(I,s,Q)if U.activeGamepad~=Q.UserInputType then return end if Q.KeyCode~=Enum.KeyCode.Thumbstick1 then return end if s==Enum.UserInputState.Cancel then U.moveVector=C return end if not(Q.Position.magnitude>.2)then U.moveVector=C return end U.moveVector=Vector3.new(Q.Position.X,0,-Q.Position.Y)end,false,Enum.KeyCode.Thumbstick1)return true end function I.UnbindContextActions(U)if U.activeGamepad~=s then n:UnbindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)end n:UnbindAction("\109\111\118\101\084\104\117\109\098\115\116\105\099\107")n:UnbindAction("\106\117\109\112\065\099\116\105\111\110")end function I.OnNewGamepadConnected(U)local I=U:GetHighestPriorityGamepad()if I==U.activeGamepad then return end if I==s then warn("\071\097\109\101\112\097\100\058\079\110\078\101\119\071\097\109\101\112\097\100\067\111\110\110\101\099\116\101\100 \102\111\117\110\100 \110\111 \099\111\110\110\101\099\116\101\100 \103\097\109\101\112\097\100\115")U:UnbindContextActions()return end if U.activeGamepad~=s then n:UnbindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)end U.activeGamepad=I n:BindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)end function I.OnCurrentGamepadDisconnected(U)if U.activeGamepad~=s then n:UnbindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)end local I=U:GetHighestPriorityGamepad()if U.activeGamepad~=s and I==U.activeGamepad then warn("\071\097\109\101\112\097\100\058\079\110\067\117\114\114\101\110\116\071\097\109\101\112\097\100\068\105\115\099\111\110\110\101\099\116\101\100 \102\111\117\110\100 \116\104\101 \115\117\112\112\111\115\101\100\108\121 \100\105\115\099\111\110\110\101\099\116\101\100 \103\097\109\101\112\097\100 \105\110 \099\111\110\110\101\099\116\101\100\071\097\109\101\112\097\100\115\046")U:UnbindContextActions()U.activeGamepad=s return end if I==s then U:UnbindContextActions()U.activeGamepad=s return end U.activeGamepad=I n:BindActivate(U.activeGamepad,Enum.KeyCode.ButtonR2)end function I.ConnectGamepadConnectionListeners(U)U.gamepadConnectedConn=Q.GamepadConnected:Connect(function(I)U:OnNewGamepadConnected()end)U.gamepadDisconnectedConn=Q.GamepadDisconnected:Connect(function(I)if U.activeGamepad==I then U:OnCurrentGamepadDisconnected()end end)end function I.DisconnectGamepadConnectionListeners(U)if U.gamepadConnectedConn then U.gamepadConnectedConn:Disconnect()U.gamepadConnectedConn=nil end if U.gamepadDisconnectedConn then U.gamepadDisconnectedConn:Disconnect()U.gamepadDisconnectedConn=nil end end return I


local v1 = require(script.Parent:WaitForChild("BaseCharacterController"));
local v2 = setmetatable({}, v1);
v2.__index = v2;
local l__Enum_UserInputType_None__1 = Enum.UserInputType.None;
function v2.new()
	local v3 = setmetatable(v1.new(), v2);
	v3.forwardValue = 0;
	v3.backwardValue = 0;
	v3.leftValue = 0;
	v3.rightValue = 0;
	v3.activeGamepad = l__Enum_UserInputType_None__1;
	v3.gamepadConnectedConn = nil;
	v3.gamepadDisconnectedConn = nil;
	return v3;
end;
local l__UserInputService__2 = game:GetService("UserInputService");
local u3 = Vector3.new(0, 0, 0);
function v2.Enable(p1, p2)
	if not l__UserInputService__2.GamepadEnabled then
		return false;
	end;
	if p2 == p1.enabled then
		return true;
	end;
	p1.forwardValue = 0;
	p1.backwardValue = 0;
	p1.leftValue = 0;
	p1.rightValue = 0;
	p1.moveVector = u3;
	p1.isJumping = false;
	if p2 then
		p1.activeGamepad = p1:GetHighestPriorityGamepad();
		if p1.activeGamepad == l__Enum_UserInputType_None__1 then
			return false;
		end;
		p1:BindContextActions();
		p1:ConnectGamepadConnectionListeners();
	else
		p1:UnbindContextActions();
		p1:DisconnectGamepadConnectionListeners();
		p1.activeGamepad = l__Enum_UserInputType_None__1;
	end;
	p1.enabled = p2;
	return true;
end;
function v2.GetHighestPriorityGamepad(p3)
	local v4 = l__Enum_UserInputType_None__1;
	for v5, v6 in pairs((l__UserInputService__2:GetConnectedGamepads())) do
		if v6.Value < v4.Value then
			v4 = v6;
		end;
	end;
	return v4;
end;
local l__ContextActionService__4 = game:GetService("ContextActionService");
function v2.BindContextActions(p4)
	if p4.activeGamepad == l__Enum_UserInputType_None__1 then
		return false;
	end;
	l__ContextActionService__4:BindActivate(p4.activeGamepad, Enum.KeyCode.ButtonR2);
	l__ContextActionService__4:BindAction("jumpAction", function(p5, p6, p7)
		p4.isJumping = p6 == Enum.UserInputState.Begin;
	end, false, Enum.KeyCode.ButtonA);
	l__ContextActionService__4:BindAction("moveThumbstick", function(p8, p9, p10)
		if p4.activeGamepad ~= p10.UserInputType then
			return;
		end;
		if p10.KeyCode ~= Enum.KeyCode.Thumbstick1 then
			return;
		end;
		if p9 == Enum.UserInputState.Cancel then
			p4.moveVector = u3;
			return;
		end;
		if not (p10.Position.magnitude > 0.2) then
			p4.moveVector = u3;
			return;
		end;
		p4.moveVector = Vector3.new(p10.Position.X, 0, -p10.Position.Y);
	end, false, Enum.KeyCode.Thumbstick1);
	return true;
end;
function v2.UnbindContextActions(p11)
	if p11.activeGamepad ~= l__Enum_UserInputType_None__1 then
		l__ContextActionService__4:UnbindActivate(p11.activeGamepad, Enum.KeyCode.ButtonR2);
	end;
	l__ContextActionService__4:UnbindAction("moveThumbstick");
	l__ContextActionService__4:UnbindAction("jumpAction");
end;
function v2.OnNewGamepadConnected(p12)
	local v7 = p12:GetHighestPriorityGamepad();
	if v7 == p12.activeGamepad then
		return;
	end;
	if v7 == l__Enum_UserInputType_None__1 then
		warn("Gamepad:OnNewGamepadConnected found no connected gamepads");
		p12:UnbindContextActions();
		return;
	end;
	if p12.activeGamepad ~= l__Enum_UserInputType_None__1 then
		l__ContextActionService__4:UnbindActivate(p12.activeGamepad, Enum.KeyCode.ButtonR2);
	end;
	p12.activeGamepad = v7;
	l__ContextActionService__4:BindActivate(p12.activeGamepad, Enum.KeyCode.ButtonR2);
end;
function v2.OnCurrentGamepadDisconnected(p13)
	if p13.activeGamepad ~= l__Enum_UserInputType_None__1 then
		l__ContextActionService__4:UnbindActivate(p13.activeGamepad, Enum.KeyCode.ButtonR2);
	end;
	local v8 = p13:GetHighestPriorityGamepad();
	if p13.activeGamepad ~= l__Enum_UserInputType_None__1 and v8 == p13.activeGamepad then
		warn("Gamepad:OnCurrentGamepadDisconnected found the supposedly disconnected gamepad in connectedGamepads.");
		p13:UnbindContextActions();
		p13.activeGamepad = l__Enum_UserInputType_None__1;
		return;
	end;
	if v8 == l__Enum_UserInputType_None__1 then
		p13:UnbindContextActions();
		p13.activeGamepad = l__Enum_UserInputType_None__1;
		return;
	end;
	p13.activeGamepad = v8;
	l__ContextActionService__4:BindActivate(p13.activeGamepad, Enum.KeyCode.ButtonR2);
end;
function v2.ConnectGamepadConnectionListeners(p14)
	p14.gamepadConnectedConn = l__UserInputService__2.GamepadConnected:Connect(function(p15)
		p14:OnNewGamepadConnected();
	end);
	p14.gamepadDisconnectedConn = l__UserInputService__2.GamepadDisconnected:Connect(function(p16)
		if p14.activeGamepad == p16 then
			p14:OnCurrentGamepadDisconnected();
		end;
	end);
end;
function v2.DisconnectGamepadConnectionListeners(p17)
	if p17.gamepadConnectedConn then
		p17.gamepadConnectedConn:Disconnect();
		p17.gamepadConnectedConn = nil;
	end;
	if p17.gamepadDisconnectedConn then
		p17.gamepadDisconnectedConn:Disconnect();
		p17.gamepadDisconnectedConn = nil;
	end;
end;
return v2;

