-- Decompiled with the Synapse X Luau decompiler.


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;

