Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
- Fix packet profiler errors if opened after game start
- Cleanup remnant connections when packet profiler is closed
  • Loading branch information
Pyseph committed Feb 6, 2024
1 parent 70802fd commit b636e65
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
36 changes: 20 additions & 16 deletions src/Components/PacketFrames.luau
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function PacketFrame:render()
end

function PacketFrames:init()
self.Cleanup = {}

self.ProfilerBackgroundRef = Roact.createRef()
self.Enabled = not IsEditMode

Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand All @@ -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 = {}
Expand Down
19 changes: 13 additions & 6 deletions src/Components/PacketProfiler.luau
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,37 @@ 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)
end
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()
return Roact.createElement(Roact.Portal, {
target = TargetGui,
}, {
PacketProfiler = Roact.createElement("ScreenGui", {
Enabled = self.state.Enabled,
Enabled = self.props.Enabled,
DisplayOrder = 10,
IgnoreGuiInset = true,
ResetOnSpawn = false,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit b636e65

Please sign in to comment.