0 then local okJson, data = pcall(function() return HttpService:JSONDecode(res.Body) end) if okJson then decoded = data end end return decoded or {}, nil end ---------------------------------------------------------------------------------------------------- -- Journal ---------------------------------------------------------------------------------------------------- local function addLog(kind, path, className) table.insert(logEntries, { kind = kind, path = path, className = className, time = os.date("%H:%M:%S") }) if #logEntries > MAX_LOG then table.remove(logEntries, 1) end refreshUi(true) end local function emit(kind, inst, logIt) local entry = { kind = kind, id = idOf(inst), name = inst.Name, className = inst.ClassName, path = pathOf(inst), } if inst.Parent and inst.Parent ~= game then entry.parentId = idOf(inst.Parent) end table.insert(pending, entry) if logIt then addLog(kind, entry.path, entry.className) end end ---------------------------------------------------------------------------------------------------- -- Surveillance du jeu ---------------------------------------------------------------------------------------------------- local function disconnectAll() for _, c in ipairs(connections) do c:Disconnect() end connections = {} for inst, c in pairs(sourceTimers) do sourceTimers[inst] = nil end end local function watch(inst) if inst:IsA("LuaSourceContainer") then table.insert(connections, inst:GetPropertyChangedSignal("Source"):Connect(function() -- Un script en cours de frappe change souvent : on attend la fin avant d'avertir l'application. local stamp = os.clock() sourceTimers[inst] = stamp task.delay(1.2, function() if sourceTimers[inst] == stamp and connected then sourceTimers[inst] = nil emit("changed", inst, true) end end) end)) end if not inst:IsA("BasePart") then table.insert(connections, inst:GetPropertyChangedSignal("Name"):Connect(function() if connected then emit("renamed", inst, true) end end)) end end local function startWatching() for _, root in ipairs(roots()) do for _, d in ipairs(root:GetDescendants()) do if d:IsA("LuaSourceContainer") then watch(d) end end table.insert(connections, root.DescendantAdded:Connect(function(d) if not connected then return end watch(d) -- Les enfants d'un objet ajoute en meme temps ne sont pas listes un par un dans le journal. local parent = d.Parent local noisy = parent ~= nil and addedThisTick[parent] == true addedThisTick[d] = true task.delay(0.3, function() addedThisTick[d] = nil end) emit("added", d, not noisy) end)) table.insert(connections, root.DescendantRemoving:Connect(function(d) if not connected then return end local parent = d.Parent local noisy = parent ~= nil and removedThisTick[parent] == true removedThisTick[d] = true task.delay(0.3, function() removedThisTick[d] = nil end) emit("removed", d, not noisy) end)) end end ---------------------------------------------------------------------------------------------------- -- Commandes recues de l'application ---------------------------------------------------------------------------------------------------- local handlers = {} local function need(ref, label) local inst = resolve(ref) if not inst then error((label or "Objet") .. " introuvable : " .. tostring(ref)) end return inst end local function mutate(label, fn) local recording = ChangeHistoryService:TryBeginRecording("Wezky : " .. label) local ok, res = pcall(fn) if recording then ChangeHistoryService:FinishRecording(recording, ok and Enum.FinishRecordingOperation.Commit or Enum.FinishRecordingOperation.Cancel) end if not ok then error(res, 0) end return res end local function setSource(inst, source) local ok = pcall(function() ScriptEditorService:UpdateSourceAsync(inst, function() return source end) end) if not ok then inst.Source = source end end local function convert(current, value) local kind = typeof(current) if kind == "Vector3" and type(value) == "table" then return Vector3.new(value.x or value[1] or 0, value.y or value[2] or 0, value.z or value[3] or 0) elseif kind == "Vector2" and type(value) == "table" then return Vector2.new(value.x or value[1] or 0, value.y or value[2] or 0) elseif kind == "Color3" then if type(value) == "string" then return Color3.fromHex(value) elseif type(value) == "table" then return Color3.fromRGB(value.r or value[1] or 0, value.g or value[2] or 0, value.b or value[3] or 0) end elseif kind == "UDim2" and type(value) == "table" then return UDim2.new(value[1] or 0, value[2] or 0, value[3] or 0, value[4] or 0) elseif kind == "UDim" and type(value) == "table" then return UDim.new(value[1] or 0, value[2] or 0) elseif kind == "EnumItem" and type(value) == "string" then return current.EnumType[value] elseif kind == "BrickColor" and type(value) == "string" then return BrickColor.new(value) end return value end local function describeValue(v) local kind = typeof(v) if kind == "string" or kind == "number" or kind == "boolean" then return v end return tostring(v) end handlers.roots = function() local nodes = {} for _, root in ipairs(roots()) do table.insert(nodes, nodeOf(root)) end return { nodes = nodes, place = game.Name } end handlers.children = function(a) local inst = need(a.path or a.id, "Parent") local nodes = {} local all = inst:GetChildren() for i, child in ipairs(all) do if i > MAX_CHILDREN then break end table.insert(nodes, nodeOf(child)) end return { node = nodeOf(inst), children = nodes, truncated = #all > MAX_CHILDREN, total = #all } end handlers.read = function(a) local inst = need(a.path or a.id, "Script") if not inst:IsA("LuaSourceContainer") then error(pathOf(inst) .. " n'est pas un script (" .. inst.ClassName .. ")") end return { node = nodeOf(inst), source = inst.Source } end handlers.write = function(a) local source = tostring(a.source or "") return mutate("écrire " .. tostring(a.path or a.id), function() local existing = resolve(a.path or a.id) if existing then if not existing:IsA("LuaSourceContainer") then error(pathOf(existing) .. " n'est pas un script (" .. existing.ClassName .. ")") end setSource(existing, source) return { node = nodeOf(existing), created = false } end local parentPath, name = string.match(tostring(a.path or ""), "^(.*)/([^/]+)$") if not parentPath then error("Chemin invalide : indique le dossier parent, par exemple ServerScriptService/MonScript") end local parent = need(parentPath, "Dossier parent") local className = a.className or "Script" if className ~= "Script" and className ~= "LocalScript" and className ~= "ModuleScript" then error("Classe de script inconnue : " .. tostring(className)) end local inst = Instance.new(className) inst.Name = name setSource(inst, source) inst.Parent = parent return { node = nodeOf(inst), created = true } end) end handlers.create = function(a) return mutate("créer " .. tostring(a.className), function() local parent = need(a.parentPath or a.parentId, "Parent") local okNew, inst = pcall(function() return Instance.new(a.className) end) if not okNew then error("Classe inconnue : " .. tostring(a.className)) end if a.name then inst.Name = a.name end for prop, value in pairs(a.properties or {}) do local okProp, current = pcall(function() return inst[prop] end) if okProp then inst[prop] = convert(current, value) end end inst.Parent = parent return { node = nodeOf(inst) } end) end handlers.delete = function(a) return mutate("supprimer " .. tostring(a.path or a.id), function() local inst = need(a.path or a.id) local node = nodeOf(inst) inst:Destroy() return { deleted = node.path } end) end handlers.rename = function(a) return mutate("renommer " .. tostring(a.path or a.id), function() local inst = need(a.path or a.id) inst.Name = tostring(a.name) return { node = nodeOf(inst) } end) end handlers.move = function(a) return mutate("déplacer " .. tostring(a.path or a.id), function() local inst = need(a.path or a.id) inst.Parent = need(a.parentPath or a.parentId, "Nouveau parent") return { node = nodeOf(inst) } end) end handlers.find = function(a) local query = string.lower(tostring(a.query or "")) local limit = math.min(tonumber(a.limit) or 50, 200) local results = {} for _, root in ipairs(roots()) do for _, d in ipairs(root:GetDescendants()) do if #results >= limit then break end local matchesName = query == "" or string.find(string.lower(d.Name), query, 1, true) ~= nil local matchesClass = (not a.className) or d:IsA(a.className) if matchesName and matchesClass then table.insert(results, nodeOf(d)) end end end return { results = results } end handlers.getprops = function(a) local inst = need(a.path or a.id) local out = {} for _, name in ipairs(a.names or { "Name", "ClassName", "Parent" }) do local ok, value = pcall(function() return inst[name] end) out[name] = ok and describeValue(value) or "(inconnu)" end return { node = nodeOf(inst), properties = out } end handlers.setprops = function(a) return mutate("propriétés " .. tostring(a.path or a.id), function() local inst = need(a.path or a.id) local failed = {} for prop, value in pairs(a.properties or {}) do local okRead, current = pcall(function() return inst[prop] end) if okRead then local okWrite = pcall(function() inst[prop] = convert(current, value) end) if not okWrite then table.insert(failed, prop) end else table.insert(failed, prop) end end return { node = nodeOf(inst), failed = failed } end) end handlers.insert = function(a) local assetId = tonumber(a.assetId) if not assetId then error("Identifiant d'asset invalide : " .. tostring(a.assetId)) end return mutate("asset " .. tostring(assetId), function() local parent = need(a.parentPath or "Workspace", "Parent") local okLoad, container = pcall(function() return game:GetService("InsertService"):LoadAsset(assetId) end) if not okLoad then error("Impossible de charger l'asset " .. tostring(assetId) .. " : " .. tostring(container)) end local nodes = {} for _, child in ipairs(container:GetChildren()) do if a.name and #container:GetChildren() == 1 then child.Name = tostring(a.name) end child.Parent = parent table.insert(nodes, nodeOf(child)) end container:Destroy() return { nodes = nodes } end) end local function handle(cmd) local fn = handlers[cmd.type] local payload if not fn then payload = { id = cmd.id, ok = false, error = "Commande inconnue : " .. tostring(cmd.type) } else local ok, res = pcall(fn, cmd.args or {}) if ok then payload = { id = cmd.id, ok = true, data = res } else payload = { id = cmd.id, ok = false, error = tostring(res) } end end if connected and session then request("POST", "/result?session=" .. session, payload) end end ---------------------------------------------------------------------------------------------------- -- Connexion ---------------------------------------------------------------------------------------------------- local function setDisconnected(reason) connected = false session = nil disconnectAll() pending = {} statusText = reason or "Déconnecté" refreshUi(false) end local function pollLoop(mine) local failures = 0 while connected and session == mine do local res, err = request("GET", "/poll?session=" .. mine) if not connected or session ~= mine then break end if res then failures = 0 for _, cmd in ipairs(res.commands or {}) do task.spawn(handle, cmd) end task.wait(0.05) elseif err == 410 then setDisconnected("Session terminée, reconnecte-toi") break else failures = failures + 1 if failures >= 3 then setDisconnected("Application Wezky fermée") break end task.wait(1) end end end local function flushLoop(mine) while connected and session == mine do task.wait(0.5) if connected and session == mine and #pending > 0 then local batch = pending pending = {} local ok = request("POST", "/events?session=" .. mine, { events = batch }) if not ok then for _, e in ipairs(batch) do table.insert(pending, e) end end end end end local function connect() statusText = "Connexion…" refreshUi(false) local found = false for _, port in ipairs(PORTS) do base = "http://127.0.0.1:" .. port local res = request("POST", "/hello", { version = VERSION, place = game.Name, placeId = game.PlaceId }) if res and res.ok and res.session then session = res.session found = true break end end if not found then base = nil statusText = "Application Wezky introuvable" refreshUi(false) return false end connected = true statusText = "Connecté" startWatching() refreshUi(false) local mine = session task.spawn(pollLoop, mine) task.spawn(flushLoop, mine) return true end local function disconnect() if connected and base and session then pcall(request, "POST", "/bye?session=" .. session, {}) end setDisconnected("Déconnecté") end ---------------------------------------------------------------------------------------------------- -- Interface : noir et blanc ---------------------------------------------------------------------------------------------------- local BLACK = Color3.fromRGB(0, 0, 0) local PANEL = Color3.fromRGB(14, 14, 14) local LINE = Color3.fromRGB(52, 52, 52) local WHITE = Color3.fromRGB(255, 255, 255) local GRAY = Color3.fromRGB(150, 150, 150) local RED = Color3.fromRGB(240, 64, 64) local GREEN = Color3.fromRGB(52, 211, 105) local widget = plugin:CreateDockWidgetPluginGui( "WezkyStudio", DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Right, false, false, 280, 360, 240, 220) ) widget.Title = "Wezky" widget.Name = "WezkyStudio" local root = Instance.new("Frame") root.Size = UDim2.fromScale(1, 1) root.BackgroundColor3 = BLACK root.BorderSizePixel = 0 root.Parent = widget local pad = Instance.new("UIPadding") pad.PaddingLeft, pad.PaddingRight, pad.PaddingTop, pad.PaddingBottom = UDim.new(0, 14), UDim.new(0, 14), UDim.new(0, 14), UDim.new(0, 14) pad.Parent = root local function label(text, size, color, bold) local l = Instance.new("TextLabel") l.BackgroundTransparency = 1 l.Text = text l.TextSize = size l.TextColor3 = color l.Font = bold and Enum.Font.GothamBold or Enum.Font.Gotham l.TextXAlignment = Enum.TextXAlignment.Left l.TextTruncate = Enum.TextTruncate.AtEnd return l end local function button(text) local b = Instance.new("TextButton") b.AutoButtonColor = true b.Text = text b.TextSize = 14 b.Font = Enum.Font.GothamMedium b.BackgroundColor3 = PANEL b.TextColor3 = WHITE b.BorderSizePixel = 0 local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 8) corner.Parent = b local stroke = Instance.new("UIStroke") stroke.Color = LINE stroke.Thickness = 1 stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border stroke.Parent = b return b end local title = label("WEZKY", 16, WHITE, true) title.Size = UDim2.new(1, 0, 0, 22) title.Parent = root local connectButton = button("Connexion") connectButton.Position = UDim2.new(0, 0, 0, 36) connectButton.Size = UDim2.new(1, 0, 0, 38) connectButton.Parent = root local statusRow = Instance.new("Frame") statusRow.BackgroundTransparency = 1 statusRow.Position = UDim2.new(0, 0, 0, 86) statusRow.Size = UDim2.new(1, 0, 0, 24) statusRow.Parent = root local statusLabel = label("Statut", 14, GRAY, false) statusLabel.Size = UDim2.new(0, 56, 1, 0) statusLabel.Parent = statusRow local dot = Instance.new("Frame") dot.Size = UDim2.fromOffset(12, 12) dot.Position = UDim2.new(0, 62, 0.5, -6) dot.BackgroundColor3 = RED dot.BorderSizePixel = 0 local dotCorner = Instance.new("UICorner") dotCorner.CornerRadius = UDim.new(1, 0) dotCorner.Parent = dot dot.Parent = statusRow local statusDetail = label("Déconnecté", 13, WHITE, false) statusDetail.Position = UDim2.new(0, 82, 0, 0) statusDetail.Size = UDim2.new(1, -82, 1, 0) statusDetail.Parent = statusRow local logButton = button("Log") logButton.Position = UDim2.new(0, 0, 0, 122) logButton.Size = UDim2.new(1, 0, 0, 34) logButton.Parent = root local logFrame = Instance.new("ScrollingFrame") logFrame.Position = UDim2.new(0, 0, 0, 168) logFrame.Size = UDim2.new(1, 0, 1, -168) logFrame.BackgroundColor3 = PANEL logFrame.BorderSizePixel = 0 logFrame.ScrollBarThickness = 5 logFrame.ScrollBarImageColor3 = GRAY logFrame.CanvasSize = UDim2.new() logFrame.AutomaticCanvasSize = Enum.AutomaticSize.Y logFrame.Visible = false logFrame.Parent = root local logCorner = Instance.new("UICorner") logCorner.CornerRadius = UDim.new(0, 8) logCorner.Parent = logFrame local logLayout = Instance.new("UIListLayout") logLayout.SortOrder = Enum.SortOrder.LayoutOrder logLayout.Parent = logFrame local logPad = Instance.new("UIPadding") logPad.PaddingLeft, logPad.PaddingRight, logPad.PaddingTop, logPad.PaddingBottom = UDim.new(0, 8), UDim.new(0, 8), UDim.new(0, 6), UDim.new(0, 6) logPad.Parent = logFrame local logOpen = false local SYMBOL = { added = "+", removed = "-", changed = "~", renamed = "~" } local function renderLog() for _, child in ipairs(logFrame:GetChildren()) do if child:IsA("TextLabel") then child:Destroy() end end if #logEntries == 0 then local empty = label("Aucun changement pour l'instant.", 13, GRAY, false) empty.Size = UDim2.new(1, 0, 0, 22) empty.Parent = logFrame return end for i = #logEntries, 1, -1 do local e = logEntries[i] local row = label(string.format("%s %s %s", e.time, SYMBOL[e.kind] or "~", e.path), 12, WHITE, false) row.Size = UDim2.new(1, 0, 0, 20) row.LayoutOrder = #logEntries - i row.TextTruncate = Enum.TextTruncate.AtEnd row.Parent = logFrame end end refreshUi = function(logOnly) if logOnly then if logOpen then renderLog() end return end connectButton.Text = connected and "Déconnexion" or "Connexion" dot.BackgroundColor3 = connected and GREEN or RED statusDetail.Text = statusText logButton.Text = logOpen and "Fermer le log" or "Log" end connectButton.MouseButton1Click:Connect(function() if connected then plugin:SetSetting("wezkyAutoConnect", false) disconnect() else plugin:SetSetting("wezkyAutoConnect", true) task.spawn(connect) end end) logButton.MouseButton1Click:Connect(function() logOpen = not logOpen logFrame.Visible = logOpen if logOpen then renderLog() end refreshUi(false) end) local toolbar = plugin:CreateToolbar("Wezky") local toggle = toolbar:CreateButton("WezkyToggle", "Ouvrir le panneau Wezky", "", "Wezky") toggle.ClickableWhenViewportHidden = true toggle.Click:Connect(function() widget.Enabled = not widget.Enabled end) widget:GetPropertyChangedSignal("Enabled"):Connect(function() toggle:SetActive(widget.Enabled) end) plugin.Unloading:Connect(function() if connected then disconnect() end end) refreshUi(false) -- Reconnexion automatique si l'utilisateur etait connecte a la derniere ouverture de Studio. if plugin:GetSetting("wezkyAutoConnect") then task.spawn(function() task.wait(1) connect() end) end PRNT END