--// Hash: 53ab6b5234323af6aa5c293925b6bd3fa53a7304d8e5f6ed1458452d96a6c330fc93ce57e3f8ea4393a6e5ed4eb1e6ca
-- Decompiled with the Synapse X Luau decompiler.


local v1 = {};
local u1 = {
	Disconnect = function(p1)
		local l___listener__2 = p1._listener;
		if l___listener__2 ~= nil then
			local l___listener_table__3 = p1._listener_table;
			local v4 = table.find(l___listener_table__3, l___listener__2);
			if v4 ~= nil then
				table.remove(l___listener_table__3, v4);
			end;
			p1._listener = nil;
		end;
		if p1._disconnect_listener ~= nil then
			p1._disconnect_listener(p1._disconnect_param);
			p1._disconnect_listener = nil;
		end;
	end
};
function v1.NewArrayScriptConnection(p2, p3, p4, p5)
	return {
		_listener = p3, 
		_listener_table = p2, 
		_disconnect_listener = p4, 
		_disconnect_param = p5, 
		Disconnect = u1.Disconnect
	};
end;
local v5 = {};
local u2 = {
	Disconnect = function(p6)
		local l___listener__6 = p6._listener;
		if l___listener__6 ~= nil then
			local l___script_signal__7 = p6._script_signal;
			local l___fire_pointer_stack__8 = l___script_signal__7._fire_pointer_stack;
			local l___listeners_next__9 = l___script_signal__7._listeners_next;
			local l___listeners_back__10 = l___script_signal__7._listeners_back;
			for v11 = 1, l___script_signal__7._stack_count do
				if l___fire_pointer_stack__8[v11] == l___listener__6 then
					l___fire_pointer_stack__8[v11] = l___listeners_next__9[l___listener__6];
				end;
			end;
			if l___script_signal__7._tail_listener == l___listener__6 then
				local v12 = l___listeners_back__10[l___listener__6];
				if v12 ~= nil then
					l___listeners_next__9[v12] = nil;
					l___listeners_back__10[l___listener__6] = nil;
				else
					l___script_signal__7._head_listener = nil;
				end;
				l___script_signal__7._tail_listener = v12;
			elseif l___script_signal__7._head_listener == l___listener__6 then
				local v13 = l___listeners_next__9[l___listener__6];
				l___listeners_back__10[v13] = nil;
				l___listeners_next__9[l___listener__6] = nil;
				l___script_signal__7._head_listener = v13;
			else
				local v14 = l___listeners_next__9[l___listener__6];
				local v15 = l___listeners_back__10[l___listener__6];
				if v14 ~= nil or v15 ~= nil then
					l___listeners_next__9[v15] = v14;
					l___listeners_back__10[v14] = v15;
					l___listeners_next__9[l___listener__6] = nil;
					l___listeners_back__10[l___listener__6] = nil;
				end;
			end;
			p6._listener = nil;
			l___script_signal__7._listener_count = l___script_signal__7._listener_count - 1;
		end;
		if p6._disconnect_listener ~= nil then
			p6._disconnect_listener(p6._disconnect_param);
			p6._disconnect_listener = nil;
		end;
	end
};
function v5.Connect(p7, p8, p9, p10)
	if type(p8) ~= "function" then
		error("[MadworkScriptSignal]: Only functions can be passed to ScriptSignal:Connect()");
	end;
	local l___tail_listener__16 = p7._tail_listener;
	if l___tail_listener__16 == nil then
		p7._head_listener = p8;
		p7._tail_listener = p8;
		p7._listener_count = p7._listener_count + 1;
	elseif l___tail_listener__16 ~= p8 and p7._listeners_next[p8] == nil then
		p7._listeners_next[l___tail_listener__16] = p8;
		p7._listeners_back[p8] = l___tail_listener__16;
		p7._tail_listener = p8;
		p7._listener_count = p7._listener_count + 1;
	end;
	return {
		_listener = p8, 
		_script_signal = p7, 
		_disconnect_listener = p9, 
		_disconnect_param = p10, 
		Disconnect = u2.Disconnect
	};
end;
function v5.GetListenerCount(p11)
	return p11._listener_count;
end;
function v5.Fire(p12, ...)
	local l___fire_pointer_stack__17 = p12._fire_pointer_stack;
	local v18 = p12._stack_count + 1;
	p12._stack_count = v18;
	local l___listeners_next__19 = p12._listeners_next;
	l___fire_pointer_stack__17[v18] = p12._head_listener;
	while true do
		local v20 = l___fire_pointer_stack__17[v18];
		l___fire_pointer_stack__17[v18] = l___listeners_next__19[v20];
		if v20 == nil then
			break;
		end;
		v20(...);	
	end;
	p12._stack_count = p12._stack_count - 1;
end;
function v1.NewScriptSignal()
	return {
		_fire_pointer_stack = {}, 
		_stack_count = 0, 
		_listener_count = 0, 
		_listeners_next = {}, 
		_listeners_back = {}, 
		_head_listener = nil, 
		_tail_listener = nil, 
		Connect = v5.Connect, 
		GetListenerCount = v5.GetListenerCount, 
		Fire = v5.Fire
	};
end;
return v1;
