function CheckIfPointIsInSquare(G,l,E)return l.X<=G.X and(G.X<=E.X and(l.Y<=G.Y and G.Y<=E.Y))end local G=false local l=false local E=0 local Y=0 local B=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local p=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local J=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")function DoBackgroundFadeIn(l)Y=tick()G=false B:Fire()ChatWindow:FadeInBackground(l or ChatSettings.ChatDefaultFadeDuration)local E=ChatWindow:GetCurrentChannel()if E then local G=MessageLogDisplay.Scroller G.ScrollingEnabled=true G.ScrollBarThickness=moduleMessageLogDisplay.ScrollBarThickness end end function DoBackgroundFadeOut(l)Y=tick()G=true B:Fire()ChatWindow:FadeOutBackground(l or ChatSettings.ChatDefaultFadeDuration)local E=ChatWindow:GetCurrentChannel()if E then local G=MessageLogDisplay.Scroller G.ScrollingEnabled=false G.ScrollBarThickness=0 end end function DoTextFadeIn(G)E=tick()l=false B:Fire()ChatWindow:FadeInText((G or ChatSettings.ChatDefaultFadeDuration)*0)end function DoTextFadeOut(G)E=tick()l=true B:Fire()ChatWindow:FadeOutText(G or ChatSettings.ChatDefaultFadeDuration)end function DoFadeInFromNewInformation()DoTextFadeIn()if ChatSettings.ChatShouldFadeInFromNewInformation then DoBackgroundFadeIn()end end function InstantFadeIn()DoBackgroundFadeIn(0)DoTextFadeIn(0)end function InstantFadeOut()DoBackgroundFadeOut(0)DoTextFadeOut(0)end local t=nil function UpdateFadingForMouseState(G)t=G p:Fire()if ChatBar:IsFocused()then return end if G then DoBackgroundFadeIn()DoTextFadeIn()else DoBackgroundFadeIn()end end spawn(function()while true do RunService.RenderStepped:wait()while t or ChatBar:IsFocused()do if t then p.Event:wait()end if ChatBar:IsFocused()then J.Event:wait()end end if not G then local G=tick()-Y if G>ChatSettings.ChatWindowBackgroundFadeOutTime then DoBackgroundFadeOut()end elseif not l then local G=tick()-E if G>ChatSettings.ChatWindowTextFadeOutTime then DoTextFadeOut()end else B.Event:wait()end end end)function getClassicChatEnabled()if ChatSettings.ClassicChatEnabled~=nil then return ChatSettings.ClassicChatEnabled end return Players.ClassicChat end function getBubbleChatEnabled()if ChatSettings.BubbleChatEnabled~=nil then return ChatSettings.BubbleChatEnabled end return Players.BubbleChat end function bubbleChatOnly()return not getClassicChatEnabled()and getBubbleChatEnabled()end function UpdateMousePosition(G,l)if not(moduleApiTable.Visible and(moduleApiTable.IsCoreGuiEnabled and(moduleApiTable.TopbarEnabled or ChatSettings.ChatOnWithTopBarOff)))then return end if bubbleChatOnly()then return end local E=ChatWindow.GuiObject.AbsolutePosition local Y=ChatWindow.GuiObject.AbsoluteSize local B=CheckIfPointIsInSquare(G,E,E+Y)if FFlagFixChatWindowHoverOver then if l and B==true then return end end if B~=t then UpdateFadingForMouseState(B)end end UserInputService.InputChanged:connect(function(G,l)if G.UserInputType==Enum.UserInputType.MouseMovement then local E=Vector2.new(G.Position.X,G.Position.Y)UpdateMousePosition(E,l)end end)UserInputService.TouchTap:connect(function(G,l)UpdateMousePosition(G[1],false)end)UserInputService.TouchMoved:connect(function(G,l)local E=Vector2.new(G.Position.X,G.Position.Y)UpdateMousePosition(E,false)end)if not FFlagFixMouseCapture then UserInputService.Changed:connect(function(G)if G=="\077\111\117\115\101\066\101\104\097\118\105\111\114"then if UserInputService.MouseBehavior==Enum.MouseBehavior.LockCenter then local G=ChatWindow.GuiObject.AbsolutePosition local l=ChatWindow.GuiObject.AbsoluteSize local E=GuiParent.AbsoluteSize local Y=CheckIfPointIsInSquare(E/2,G,G+l)if Y then UserInputService.MouseBehavior=Enum.MouseBehavior.Default end end end end)end
--////////////////////////////////////////////////////////////////////////////////////////////
--////////////////////////////////////////////////////////////// Code to do chat window fading
--////////////////////////////////////////////////////////////////////////////////////////////
function CheckIfPointIsInSquare(checkPos, topLeft, bottomRight)
	return (
		topLeft.X <= checkPos.X
		and checkPos.X <= bottomRight.X
		and topLeft.Y <= checkPos.Y
		and checkPos.Y <= bottomRight.Y
	)
end

local backgroundIsFaded = false
local textIsFaded = false
local lastTextFadeTime = 0
local lastBackgroundFadeTime = 0

local fadedChanged = Instance.new("BindableEvent")
local mouseStateChanged = Instance.new("BindableEvent")
local chatBarFocusChanged = Instance.new("BindableEvent")

function DoBackgroundFadeIn(setFadingTime)
	lastBackgroundFadeTime = tick()
	backgroundIsFaded = false
	fadedChanged:Fire()
	ChatWindow:FadeInBackground((setFadingTime or ChatSettings.ChatDefaultFadeDuration))

	local currentChannelObject = ChatWindow:GetCurrentChannel()
	if currentChannelObject then
		local Scroller = MessageLogDisplay.Scroller
		Scroller.ScrollingEnabled = true
		Scroller.ScrollBarThickness = moduleMessageLogDisplay.ScrollBarThickness
	end
end

function DoBackgroundFadeOut(setFadingTime)
	lastBackgroundFadeTime = tick()
	backgroundIsFaded = true
	fadedChanged:Fire()
	ChatWindow:FadeOutBackground((setFadingTime or ChatSettings.ChatDefaultFadeDuration))

	local currentChannelObject = ChatWindow:GetCurrentChannel()
	if currentChannelObject then
		local Scroller = MessageLogDisplay.Scroller
		Scroller.ScrollingEnabled = false
		Scroller.ScrollBarThickness = 0
	end
end

function DoTextFadeIn(setFadingTime)
	lastTextFadeTime = tick()
	textIsFaded = false
	fadedChanged:Fire()
	ChatWindow:FadeInText((setFadingTime or ChatSettings.ChatDefaultFadeDuration) * 0)
end

function DoTextFadeOut(setFadingTime)
	lastTextFadeTime = tick()
	textIsFaded = true
	fadedChanged:Fire()
	ChatWindow:FadeOutText((setFadingTime or ChatSettings.ChatDefaultFadeDuration))
end

function DoFadeInFromNewInformation()
	DoTextFadeIn()
	if ChatSettings.ChatShouldFadeInFromNewInformation then
		DoBackgroundFadeIn()
	end
end

function InstantFadeIn()
	DoBackgroundFadeIn(0)
	DoTextFadeIn(0)
end

function InstantFadeOut()
	DoBackgroundFadeOut(0)
	DoTextFadeOut(0)
end

local mouseIsInWindow = nil
function UpdateFadingForMouseState(mouseState)
	mouseIsInWindow = mouseState

	mouseStateChanged:Fire()

	if ChatBar:IsFocused() then
		return
	end

	if mouseState then
		DoBackgroundFadeIn()
		DoTextFadeIn()
	else
		DoBackgroundFadeIn()
	end
end

spawn(function()
	while true do
		RunService.RenderStepped:wait()

		while mouseIsInWindow or ChatBar:IsFocused() do
			if mouseIsInWindow then
				mouseStateChanged.Event:wait()
			end
			if ChatBar:IsFocused() then
				chatBarFocusChanged.Event:wait()
			end
		end

		if not backgroundIsFaded then
			local timeDiff = tick() - lastBackgroundFadeTime
			if timeDiff > ChatSettings.ChatWindowBackgroundFadeOutTime then
				DoBackgroundFadeOut()
			end
		elseif not textIsFaded then
			local timeDiff = tick() - lastTextFadeTime
			if timeDiff > ChatSettings.ChatWindowTextFadeOutTime then
				DoTextFadeOut()
			end
		else
			fadedChanged.Event:wait()
		end
	end
end)

function getClassicChatEnabled()
	if ChatSettings.ClassicChatEnabled ~= nil then
		return ChatSettings.ClassicChatEnabled
	end
	return Players.ClassicChat
end

function getBubbleChatEnabled()
	if ChatSettings.BubbleChatEnabled ~= nil then
		return ChatSettings.BubbleChatEnabled
	end
	return Players.BubbleChat
end

function bubbleChatOnly()
	return not getClassicChatEnabled() and getBubbleChatEnabled()
end

function UpdateMousePosition(mousePos, ignoreForFadeIn)
	if
		not (
			moduleApiTable.Visible
			and moduleApiTable.IsCoreGuiEnabled
			and (moduleApiTable.TopbarEnabled or ChatSettings.ChatOnWithTopBarOff)
		)
	then
		return
	end

	if bubbleChatOnly() then
		return
	end

	local windowPos = ChatWindow.GuiObject.AbsolutePosition
	local windowSize = ChatWindow.GuiObject.AbsoluteSize

	local newMouseState = CheckIfPointIsInSquare(mousePos, windowPos, windowPos + windowSize)

	if FFlagFixChatWindowHoverOver then
		if ignoreForFadeIn and newMouseState == true then
			return
		end
	end

	if newMouseState ~= mouseIsInWindow then
		UpdateFadingForMouseState(newMouseState)
	end
end

UserInputService.InputChanged:connect(function(inputObject, gameProcessedEvent)
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local mousePos = Vector2.new(inputObject.Position.X, inputObject.Position.Y)
		UpdateMousePosition(mousePos, --[[ ignoreForFadeIn = ]] gameProcessedEvent)
	end
end)

UserInputService.TouchTap:connect(function(tapPos, gameProcessedEvent)
	UpdateMousePosition(tapPos[1], --[[ ignoreForFadeIn = ]] false)
end)

UserInputService.TouchMoved:connect(function(inputObject, gameProcessedEvent)
	local tapPos = Vector2.new(inputObject.Position.X, inputObject.Position.Y)
	UpdateMousePosition(tapPos, --[[ ignoreForFadeIn = ]] false)
end)

if not FFlagFixMouseCapture then
	UserInputService.Changed:connect(function(prop)
		if prop == "MouseBehavior" then
			if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
				local windowPos = ChatWindow.GuiObject.AbsolutePosition
				local windowSize = ChatWindow.GuiObject.AbsoluteSize
				local screenSize = GuiParent.AbsoluteSize

				local centerScreenIsInWindow = CheckIfPointIsInSquare(screenSize / 2, windowPos, windowPos + windowSize)
				if centerScreenIsInWindow then
					UserInputService.MouseBehavior = Enum.MouseBehavior.Default
				end
			end
		end
	end)
end
