-- NewsSlide seguro para o cliente MuDevs S21.1-2. -- Mantem o recurso original sem codigo codificado/dinamico e usa o handle de fonte do cliente. local CONFIG_PATH = "Data\\Custom\\LuaScript\\NewsSlide\\NewsSlide_Config.lua" local configLoaded, Config = pcall(dofile, CONFIG_PATH) if not configLoaded or type(Config) ~= "table" then print("[NewsSlide] Falha ao carregar NewsSlide_Config.lua") return end local function Clamp(value, minimum, maximum) local number = tonumber(value) or minimum if number < minimum then return minimum end if number > maximum then return maximum end return number end local WAIT_FRAMES = math.floor(Clamp(Config.WAIT_TIME, 0, 60) * 60) local SLIDER_POS_Y = math.floor(Clamp(Config.SLIDER_POS_Y, 0, 2000)) local SPEED_NORMAL = Clamp(Config.SPEED_NORMAL, 0.05, 10) local SPEED_HOVER = Clamp(Config.SPEED_HOVER, 0.05, 10) local TEXT_WIDTH = math.floor(Clamp(Config.TEXT_WIDTH, 32, 2000)) local TEXT_HEIGHT = math.floor(Clamp(Config.TEXT_HEIGHT, 12, 200)) local messageQueue = {} local currentMessageData = nil local currentIndex = 1 local messageX = 800 local initialized = false local disabled = false local waitTimer = 0 local function ColorComponent(value, fallback) return math.floor(Clamp(tonumber(value) or fallback, 0, 255)) end local function RemoveUnsupportedUtf8(text) -- O renderizador antigo nao processa caracteres UTF-8 de quatro bytes com seguranca. -- Remove somente esses caracteres (por exemplo, emojis) e preserva textos/acentos comuns. local cleaned = text:gsub("[\240-\244][\128-\191][\128-\191][\128-\191]", "") return cleaned:gsub("%s+", " ") end local function GetClientLanguage() local paths = { "LauncherOption.if", "../LauncherOption.if", "../../LauncherOption.if", "../../../LauncherOption.if", } for _, path in ipairs(paths) do local file = io.open(path, "r") if file then for line in file:lines() do local match = line:match("^%s*Language%s*:%s*(%d+)") if match then file:close() return tonumber(match) or 0 end end file:close() end end return 0 end local function BuildMessageQueue() local language = GetClientLanguage() local source = type(Config.messages) == "table" and Config.messages[language] or nil if type(source) ~= "table" and type(Config.messages) == "table" then source = Config.messages[0] end if type(source) ~= "table" then return {} end local queue = {} for _, entry in ipairs(source) do if type(entry) == "table" and type(entry[1]) == "string" then local text = RemoveUnsupportedUtf8(entry[1]) local color = type(entry[2]) == "table" and entry[2] or {} if text ~= "" then queue[#queue + 1] = { text, { ColorComponent(color[1], 255), ColorComponent(color[2], 255), ColorComponent(color[3], 255), }, } end end end return queue end local function LoadNextMessage() if #messageQueue == 0 then return end currentMessageData = messageQueue[currentIndex] currentIndex = (currentIndex % #messageQueue) + 1 messageX = 800 end local function Initialize() if initialized or disabled then return end messageQueue = BuildMessageQueue() if #messageQueue == 0 then disabled = true print("[NewsSlide] Nenhuma mensagem valida configurada") return end initialized = true LoadNextMessage() end local function NewsSlide_Render() if disabled or Hero == nil then return end if not initialized then Initialize() if not initialized then return end end if currentMessageData == nil then return end local mouseOver = CheckMouseIn(messageX, SLIDER_POS_Y, TEXT_WIDTH, TEXT_HEIGHT) local currentSpeed = mouseOver and SPEED_HOVER or SPEED_NORMAL if waitTimer > 0 then waitTimer = waitTimer - 1 return end messageX = messageX - currentSpeed if messageX + TEXT_WIDTH < 0 then waitTimer = WAIT_FRAMES LoadNextMessage() return end local text = currentMessageData[1] local color = currentMessageData[2] if mouseOver and type(Config.COLOR_HOVER) == "table" then UIRenderText_SetTextColor( ColorComponent(Config.COLOR_HOVER.r, 255), ColorComponent(Config.COLOR_HOVER.g, 255), ColorComponent(Config.COLOR_HOVER.b, 255), 255 ) else UIRenderText_SetTextColor(color[1], color[2], color[3], 255) end -- Nesta versao o primeiro argumento e um handle de fonte, nao um ID/tamanho. if g_hFont == nil or g_hFont == 0 then return end UIRenderText_SetFont(g_hFont) UIRenderText_SetBgColor(0, 0, 0, 0) UIRenderText_RenderText(math.floor(messageX), SLIDER_POS_Y, text, TEXT_WIDTH, TEXT_HEIGHT, 1) end BridgeFunctionAttach("OnInterfaceRender", NewsSlide_Render)