do local Q=setmetatable({},{__index=function(Q,B)Q[B]={}return Q[B]end;__mode="\107"})local B=setmetatable({},{__index=function(Q,B)Q[B]={}return Q[B]end,__mode="\107"})local Z=64 local X=32 local n={"\110\117\109\098\101\114";"\115\116\114\105\110\103";"\098\111\111\108\101\097\110";"\110\105\108","\086\101\099\116\111\114\050";"\086\101\099\116\111\114\051";"\067\070\114\097\109\101","\067\111\108\111\114\051","\066\114\105\099\107\067\111\108\111\114","\085\068\105\109\050","\085\068\105\109"}for Q,B in ipairs(n)do n[B]=true end local function y(B,y)local j=typeof(B)if not n[j]then error(string.format("\073\110\118\097\108\105\100 \118\097\108\117\101 \112\097\115\115\101\100 \116\111 \078\101\116\119\111\114\107\058\080\097\099\107 \040\118\097\108\117\101\115 \111\102 \116\121\112\101 \037\115 \097\114\101 \110\111\116 \115\117\112\112\111\114\116\101\100\041",j))end if j=="\098\111\111\108\101\097\110"or j=="\110\105\108"or B==""then return B elseif j=="\115\116\114\105\110\103"and#B>Z then return"\000"..B end local l=Q[y]local v=l[B]if not v then if#l<X then local Q=#l+1 v={char=string.char(Q);value=B,last=0}l[Q]=v l[B]=v else for Q,B in ipairs(l)do if not v or B.last<v.last then v=B end end l[v.value]=nil l[B]=v v.value=B end if IsServer then Network:FireClient(y,"\083\101\116\080\097\099\107\101\100\086\097\108\117\101",v.char,v.value)else Network:FireServer("\083\101\116\080\097\099\107\101\100\086\097\108\117\101",v.char,v.value)end end v.last=os.clock()return v.char end local function j(Q,Z)local X=typeof(Q)if X~="\115\116\114\105\110\103"or Q==""then return Q end local n=string.byte(Q,1)if n==0 then return string.sub(Q,2)end return B[Z][n]end if IsServer then function Network.Pack(Z,Q,B)assert(typeof(B)=="\073\110\115\116\097\110\099\101"and B:IsA("\080\108\097\121\101\114"),"\099\108\105\101\110\116 \105\115 \110\111\116 \097 \112\108\097\121\101\114")return y(Q,B)end function Network.Unpack(Z,Q,B)assert(typeof(B)=="\073\110\115\116\097\110\099\101"and B:IsA("\080\108\097\121\101\114"),"\099\108\105\101\110\116 \105\115 \110\111\116 \097 \112\108\097\121\101\114")return j(Q,B)end Network:BindEvents({SetPackedValue=function(Q,y,j)if typeof(y)~="\115\116\114\105\110\103"or#y~=1 then return Q:Kick()end local l=string.byte(y)if l<1 or l>X then return Q:Kick()end local v=typeof(j)if not n[v]or v=="\115\116\114\105\110\103"and#j>Z then return Q:Kick()end B[Q][l]=j end})else function Network.Pack(B,Q)return y(Q,"\083\101\114\118\101\114")end function Network.Unpack(B,Q)return j(Q,"\083\101\114\118\101\114")end Network:BindEvents({SetPackedValue=function(Q,Z)B.Server[string.byte(Q)]=Z end})end end
--[[ Value packing extension ]]
--

do
	local SendingCache = setmetatable({}, {
		__index = function(t, i)
			t[i] = {}
			return t[i]
		end,
		__mode = "k",
	})
	local ReceivingCache = setmetatable({}, {
		__index = function(t, i)
			t[i] = {}
			return t[i]
		end,
		__mode = "k",
	})
	local MaxStringLength = 64
	local CacheSize = 32 -- must be under 256, keeping it low because adding a new entry goes through the entire cache

	local ValidTypes = {
		"number",
		"string",
		"boolean",
		"nil",
		"Vector2",
		"Vector3",
		"CFrame",
		"Color3",
		"BrickColor",
		"UDim2",
		"UDim",
	}

	for i, v in ipairs(ValidTypes) do
		ValidTypes[v] = true
	end

	local function addEntry(value, client)
		local valueType = typeof(value)

		if not ValidTypes[valueType] then
			error(
				string.format("Invalid value passed to Network:Pack (values of type %s are not supported)", valueType)
			)
		end

		if valueType == "boolean" or valueType == "nil" or value == "" then
			return value -- already one-byte
		elseif valueType == "string" and #value > MaxStringLength then
			return "\0" .. value
		end

		local cache = SendingCache[client]
		local info = cache[value]

		if not info then
			if #cache < CacheSize then
				local index = #cache + 1
				info = { char = string.char(index), value = value, last = 0 }

				cache[index] = info
				cache[value] = info
			else
				for i, other in ipairs(cache) do
					if not info or other.last < info.last then
						info = other
					end
				end

				cache[info.value] = nil
				cache[value] = info

				info.value = value
			end

			if IsServer then
				Network:FireClient(client, "SetPackedValue", info.char, info.value)
			else
				Network:FireServer("SetPackedValue", info.char, info.value)
			end
		end

		info.last = os.clock()

		return info.char
	end

	local function getEntry(value, client)
		local valueType = typeof(value)
		if valueType ~= "string" or value == "" then
			return value
		end

		local index = string.byte(value, 1)
		if index == 0 then
			return string.sub(value, 2)
		end

		return ReceivingCache[client][index]
	end

	if IsServer then
		function Network:Pack(value, client)
			assert(typeof(client) == "Instance" and client:IsA("Player"), "client is not a player")
			return addEntry(value, client)
		end

		function Network:Unpack(value, client)
			assert(typeof(client) == "Instance" and client:IsA("Player"), "client is not a player")
			return getEntry(value, client)
		end

		Network:BindEvents({
			SetPackedValue = function(client, char, value)
				if typeof(char) ~= "string" or #char ~= 1 then
					return client:Kick()
				end

				local index = string.byte(char)
				if index < 1 or index > CacheSize then
					return client:Kick()
				end

				local valueType = typeof(value)
				if not ValidTypes[valueType] or valueType == "string" and #value > MaxStringLength then
					return client:Kick()
				end

				ReceivingCache[client][index] = value
			end,
		})
	else
		function Network:Pack(value)
			return addEntry(value, "Server")
		end

		function Network:Unpack(value)
			return getEntry(value, "Server")
		end

		Network:BindEvents({
			SetPackedValue = function(char, value)
				ReceivingCache.Server[string.byte(char)] = value
			end,
		})
	end
end
