From b636e6508232afb2fc7b4e048403c9ffdc1bb3c2 Mon Sep 17 00:00:00 2001 From: PysephRBX Date: Tue, 6 Feb 2024 09:48:47 +0100 Subject: [PATCH] v1.5.0 - Fix packet profiler errors if opened after game start - Cleanup remnant connections when packet profiler is closed --- src/Components/PacketFrames.luau | 36 +++++++++++++++++------------- src/Components/PacketProfiler.luau | 19 +++++++++++----- wally.toml | 2 +- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Components/PacketFrames.luau b/src/Components/PacketFrames.luau index a7b684d..4cb19f6 100644 --- a/src/Components/PacketFrames.luau +++ b/src/Components/PacketFrames.luau @@ -81,6 +81,8 @@ function PacketFrame:render() end function PacketFrames:init() + self.Cleanup = {} + self.ProfilerBackgroundRef = Roact.createRef() self.Enabled = not IsEditMode @@ -198,9 +200,9 @@ end function PacketFrames:didMount() if not IsEditMode then - self.props.OnPacketProfilerPaused:Connect(function(Paused: boolean) + table.insert(self.Cleanup, self.props.OnPacketProfilerPaused:Connect(function(Paused: boolean) self.Enabled = not Paused - end) + end)) self.CurrentFrame = { Time = os.clock(), @@ -209,39 +211,36 @@ function PacketFrames:didMount() } task.spawn(function() - if not self.props.Enabled:getValue() then - self.props.OnPacketProfilerEnabled:Wait() - end - + print("Running") for _, Object in next, game:GetDescendants() do if Object:IsA("RemoteEvent") or Object:IsA("UnreliableRemoteEvent") then - Object[RemoteContext]:Connect(function(...) + table.insert(self.Cleanup, Object[RemoteContext]:Connect(function(...) self.RemoteCallback(Object, ...) - end) + end)) end end - game.DescendantAdded:Connect(function(Object) + table.insert(self.Cleanup, game.DescendantAdded:Connect(function(Object) if Object:IsA("RemoteEvent") or Object:IsA("UnreliableRemoteEvent") then - Object[RemoteContext]:Connect(function(...) + table.insert(self.Cleanup, Object[RemoteContext]:Connect(function(...) self.RemoteCallback(Object, ...) - end) + end)) end - end) + end)) if RemoteFunctionEvent == nil then local Connection; Connection = ReplicatedStorage.DescendantAdded:Connect(function(Object) if Object:IsA("BindableEvent") and Object.Name == REMOTE_FUNCTION_EVENT_NAME then RemoteFunctionEvent = Object - RemoteFunctionEvent.Event:Connect(self.RemoteCallback) + table.insert(self.Cleanup, RemoteFunctionEvent.Event:Connect(self.RemoteCallback)) Connection:Disconnect() end end) else - RemoteFunctionEvent.Event:Connect(self.RemoteCallback) + table.insert(self.Cleanup, RemoteFunctionEvent.Event:Connect(self.RemoteCallback)) end - RunService.RenderStepped:Connect(function() + table.insert(self.Cleanup, RunService.RenderStepped:Connect(function() if not self.Enabled then return end @@ -259,10 +258,15 @@ function PacketFrames:didMount() local MousePosition = self.MousePosition:getValue() self.UpdateMouseData(MousePosition.X, MousePosition.Y, self.SelectedFrameData:getValue().Selected) end - end) + end)) end) end end +function PacketFrames:willUnmount() + for _, Connection in self.Cleanup do + Connection:Disconnect() + end +end function PacketFrames:render() local Frames = {} diff --git a/src/Components/PacketProfiler.luau b/src/Components/PacketProfiler.luau index bf27ab6..273b85d 100644 --- a/src/Components/PacketProfiler.luau +++ b/src/Components/PacketProfiler.luau @@ -136,12 +136,14 @@ function ProfilerComponent:init() MaxFrameSize = 1*1000, }) + self.Cleanup = {} + self.PacketProfilerPaused, self.SetPacketProfilerPaused = Roact.createBinding(false) self.OnPacketProfilerPaused = Signal.new() - self.OnPacketProfilerPaused:Connect(function(IsPaused) + table.insert(self.Cleanup, self.OnPacketProfilerPaused:Connect(function(IsPaused) self.SetPacketProfilerPaused(IsPaused) - end) + end)) function self.Pause(IsPaused) self.OnPacketProfilerPaused:Fire(IsPaused) @@ -149,9 +151,14 @@ function ProfilerComponent:init() end function ProfilerComponent:didMount() - self.props.Signals.ProfilerPaused:Connect(function(IsPaused) + table.insert(self.Cleanup, self.props.Signals.ProfilerPaused:Connect(function(IsPaused) self.Pause(IsPaused) - end) + end)) +end +function ProfilerComponent:willUnmount() + for _, Connection in self.Cleanup do + Connection:Disconnect() + end end function ProfilerComponent:render() @@ -159,7 +166,7 @@ function ProfilerComponent:render() target = TargetGui, }, { PacketProfiler = Roact.createElement("ScreenGui", { - Enabled = self.state.Enabled, + Enabled = self.props.Enabled, DisplayOrder = 10, IgnoreGuiInset = true, ResetOnSpawn = false, @@ -174,7 +181,7 @@ function ProfilerComponent:render() Position = UDim2.fromOffset(0, TOPBAR_HEIGHT), }, { PacketFrames = Roact.createElement(PacketFrames, { - Enabled = self.state.Enabled, + Enabled = self.props.Enabled, MaxFrameSize = self.state.MaxFrameSize, OnPacketProfilerPaused = self.OnPacketProfilerPaused, OnPacketProfilerEnabled = self.props.OnEnabled, diff --git a/wally.toml b/wally.toml index 3dbfae4..24aab35 100644 --- a/wally.toml +++ b/wally.toml @@ -1,6 +1,6 @@ [package] name = "pysephwasntavailable/packetprofiler" -version = "1.4.8" +version = "1.5.0" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" description = "Remote packet profiler"