function DynamicThumbstick.GetIsJumping(S)local z=S.isJumping S.isJumping=false return z end function DynamicThumbstick.EnableAutoJump(z,S)if FFlagUserDTDoesNotForceAutoJump then return end local m=LocalPlayer.Character and LocalPlayer.Character:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if m then if S then z.shouldRevertAutoJumpOnDisable=m.AutoJumpEnabled==false and LocalPlayer.DevTouchMovementMode==Enum.DevTouchMovementMode.UserChoice m.AutoJumpEnabled=true elseif z.shouldRevertAutoJumpOnDisable then m.AutoJumpEnabled=false end end end function DynamicThumbstick.Enable(m,S,z)if S==nil then return false end S=S and true or false if m.enabled==S then return true end if S then if not m.thumbstickFrame then m:Create(z)end m:BindContextActions()if not FFlagUserDTDoesNotTrackTools then if LocalPlayer.Character then m:OnCharacterAdded(LocalPlayer.Character)else LocalPlayer.CharacterAdded:Connect(function(S)m:OnCharacterAdded(S)end)end end else ContextActionService:UnbindAction(DYNAMIC_THUMBSTICK_ACTION_NAME)m:OnInputEnded()end m.enabled=S m.thumbstickFrame.Visible=S end function DynamicThumbstick.OnCharacterAdded(z,S)assert(not FFlagUserDTDoesNotTrackTools)for S,m in ipairs(S:GetChildren())do if m:IsA("\084\111\111\108")then z.toolEquipped=m end end S.ChildAdded:Connect(function(S)if S:IsA("\084\111\111\108")then z.toolEquipped=S elseif S:IsA("\072\117\109\097\110\111\105\100")then z:EnableAutoJump(true)end end)S.ChildRemoved:Connect(function(S)if S==z.toolEquipped then z.toolEquipped=nil end end)z.humanoid=S:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if z.humanoid then z:EnableAutoJump(true)end end
-- Note: Overrides base class GetIsJumping with get-and-clear behavior to do a single jump
-- rather than sustained jumping. This is only to preserve the current behavior through the refactor.
function DynamicThumbstick:GetIsJumping()
	local wasJumping = self.isJumping
	self.isJumping = false
	return wasJumping
end

function DynamicThumbstick:EnableAutoJump(enable) -- Remove on FFlagUserDTDoesNotForceAutoJump
	if FFlagUserDTDoesNotForceAutoJump then
		return
	end
	local humanoid = LocalPlayer.Character and LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		if enable then
			self.shouldRevertAutoJumpOnDisable = (humanoid.AutoJumpEnabled == false)
				and (LocalPlayer.DevTouchMovementMode == Enum.DevTouchMovementMode.UserChoice)
			humanoid.AutoJumpEnabled = true
		elseif self.shouldRevertAutoJumpOnDisable then
			humanoid.AutoJumpEnabled = false
		end
	end
end

function DynamicThumbstick:Enable(enable, uiParentFrame)
	if enable == nil then
		return false
	end -- If nil, return false (invalid argument)
	enable = enable and true or false -- Force anything non-nil to boolean before comparison
	if self.enabled == enable then
		return true
	end -- If no state change, return true indicating already in requested state

	if enable then
		-- Enable
		if not self.thumbstickFrame then
			self:Create(uiParentFrame)
		end

		self:BindContextActions()

		if not FFlagUserDTDoesNotTrackTools then
			if LocalPlayer.Character then
				self:OnCharacterAdded(LocalPlayer.Character)
			else
				LocalPlayer.CharacterAdded:Connect(function(char)
					self:OnCharacterAdded(char)
				end)
			end
		end
	else
		ContextActionService:UnbindAction(DYNAMIC_THUMBSTICK_ACTION_NAME)
		-- Disable
		self:OnInputEnded() -- Cleanup
	end

	self.enabled = enable
	self.thumbstickFrame.Visible = enable
end

function DynamicThumbstick:OnCharacterAdded(char) -- Remove on FFlagUserDTDoesNotTrackTools
	assert(not FFlagUserDTDoesNotTrackTools)

	for _, child in ipairs(char:GetChildren()) do
		if child:IsA("Tool") then
			self.toolEquipped = child
		end
	end

	char.ChildAdded:Connect(function(child)
		if child:IsA("Tool") then
			self.toolEquipped = child
		elseif child:IsA("Humanoid") then
			self:EnableAutoJump(true) -- Remove on FFlagUserDTDoesNotForceAutoJump
		end
	end)
	char.ChildRemoved:Connect(function(child)
		if child == self.toolEquipped then
			self.toolEquipped = nil
		end
	end)

	self.humanoid = char:FindFirstChildOfClass("Humanoid")
	if self.humanoid then
		self:EnableAutoJump(true) -- Remove on FFlagUserDTDoesNotForceAutoJump
	end
end
