Decompiled source of StaticNetcodeLib v1.1.1

BepInEx/plugins/StaticNetcodeLib/Xilophor.StaticNetcodeLib.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OdinSerializer;
using StaticNetcodeLib.Enums;
using StaticNetcodeLib.Messaging;
using StaticNetcodeLib.Patches;
using StaticNetcodeLib.Serialization;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RegisterFormatterLocator(typeof(INetworkSerializableFormatterLocator), -100)]
[assembly: RegisterFormatter(typeof(NetworkBehaviourReferenceFormatter), 0)]
[assembly: RegisterFormatter(typeof(NetworkObjectReferenceFormatter), 0)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("xilophor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+c96b5d48308fd38bea459d210122948477bffeb9")]
[assembly: AssemblyProduct("StaticNetcodeLib")]
[assembly: AssemblyTitle("Xilophor.StaticNetcodeLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Xilophor/StaticNetcodeLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StaticNetcodeLib
{
	[AttributeUsage(AttributeTargets.Class)]
	public class StaticNetcodeAttribute : Attribute
	{
	}
	[BepInPlugin("Xilophor.StaticNetcodeLib", "StaticNetcodeLib", "1.1.1")]
	public class StaticNetcodeLib : BaseUnityPlugin
	{
		public const string Guid = "Xilophor.StaticNetcodeLib";

		private static readonly HarmonyMethod ServerRpcPatch = new HarmonyMethod(typeof(RpcPatcher), "PatchServerRpc", (Type[])null);

		private static readonly HarmonyMethod ClientRpcPatch = new HarmonyMethod(typeof(RpcPatcher), "PatchClientRpc", (Type[])null);

		public static StaticNetcodeLib Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; private set; }

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			GameObject gameObject = ((Component)this).gameObject;
			((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x3D);
			Logger.LogInfo((object)"Xilophor.StaticNetcodeLib v1.1.1 has loaded!");
		}

		private static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Xilophor.StaticNetcodeLib");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		private void Start()
		{
			IEnumerable<Type> source = from info in Chainloader.PluginInfos.Values
				where info.Instance != null
				select ((object)info.Instance).GetType() into type
				where ((MemberInfo)type).GetCustomAttributes<BepInDependency>().Any((BepInDependency attr) => attr.DependencyGUID == "Xilophor.StaticNetcodeLib")
				select type;
			Type[] source2 = source.SelectMany((Type plugin) => from type in plugin.Assembly.GetTypes()
				where type.GetCustomAttributes<StaticNetcodeAttribute>().Any()
				select type).ToArray();
			MethodInfo[] source3 = source2.SelectMany((Type type) => type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)).ToArray();
			IEnumerable<MethodInfo> enumerable = source3.Where((MethodInfo method) => ((MemberInfo)method).GetCustomAttributes<ServerRpcAttribute>().Any() && method.IsStatic);
			IEnumerable<MethodInfo> enumerable2 = source3.Where((MethodInfo method) => ((MemberInfo)method).GetCustomAttributes<ClientRpcAttribute>().Any() && method.IsStatic);
			CollectionExtensions.Do<MethodInfo>(enumerable, (Action<MethodInfo>)delegate(MethodInfo method)
			{
				if (!method.Name.EndsWith("ServerRpc"))
				{
					Logger.LogError((object)("Method " + GeneralExtensions.FullDescription((MethodBase)method) + " must end with ServerRpc."));
					return;
				}
				try
				{
					Harmony? harmony2 = Harmony;
					if (harmony2 != null)
					{
						harmony2.Patch((MethodBase)method, ServerRpcPatch, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					RpcPatcher.RpcExecStageLookup[method] = RpcExecStage.None;
				}
				catch
				{
					Logger.LogError((object)("Unable to patch the method " + GeneralExtensions.FullDescription((MethodBase)method) + "!"));
				}
			});
			CollectionExtensions.Do<MethodInfo>(enumerable2, (Action<MethodInfo>)delegate(MethodInfo method)
			{
				if (!method.Name.EndsWith("ClientRpc"))
				{
					Logger.LogError((object)("Method " + GeneralExtensions.FullDescription((MethodBase)method) + " must end with ClientRpc."));
					return;
				}
				try
				{
					Harmony? harmony = Harmony;
					if (harmony != null)
					{
						harmony.Patch((MethodBase)method, ClientRpcPatch, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					RpcPatcher.RpcExecStageLookup[method] = RpcExecStage.None;
				}
				catch
				{
					Logger.LogError((object)("Unable to patch the method " + GeneralExtensions.FullDescription((MethodBase)method) + "!"));
				}
			});
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Xilophor.StaticNetcodeLib";

		public const string PLUGIN_NAME = "StaticNetcodeLib";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace StaticNetcodeLib.Serialization
{
	public class INetworkSerializableFormatter<T> : MinimalBaseFormatter<T> where T : INetworkSerializable
	{
		private readonly Serializer<byte[]> _byteArraySerializer = Serializer.Get<byte[]>();

		protected override void Read(ref T value, IDataReader reader)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = _byteArraySerializer.ReadValue(reader);
			FastBufferReader val = default(FastBufferReader);
			((FastBufferReader)(ref val))..ctor(array, (Allocator)2, -1, 0);
			BufferSerializer<BufferSerializerReader> val2 = default(BufferSerializer<BufferSerializerReader>);
			val2..ctor(new BufferSerializerReader(val));
			((INetworkSerializable)value).NetworkSerialize<BufferSerializerReader>(val2);
		}

		protected override void Write(ref T value, IDataWriter writer)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(1024, (Allocator)2, 65536);
			BufferSerializer<BufferSerializerWriter> val2 = default(BufferSerializer<BufferSerializerWriter>);
			val2..ctor(new BufferSerializerWriter(val));
			((INetworkSerializable)value).NetworkSerialize<BufferSerializerWriter>(val2);
			Serializer<byte[]> byteArraySerializer = _byteArraySerializer;
			FastBufferWriter fastBufferWriter = val2.GetFastBufferWriter();
			byteArraySerializer.WriteValue(((FastBufferWriter)(ref fastBufferWriter)).ToArray(), writer);
		}
	}
	public class INetworkSerializableFormatterLocator : IFormatterLocator
	{
		public bool TryGetFormatter(Type type, FormatterLocationStep step, ISerializationPolicy policy, bool allowWeakFallbackFormatters, out IFormatter formatter)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if ((int)step != 1 || !typeof(INetworkSerializable).IsAssignableFrom(type))
			{
				formatter = null;
				return false;
			}
			try
			{
				formatter = (IFormatter)Activator.CreateInstance(typeof(INetworkSerializableFormatter<>).MakeGenericType(type));
			}
			catch (Exception ex)
			{
				if (!allowWeakFallbackFormatters || (!(ex is ExecutionEngineException) && !(ex.GetBaseException() is ExecutionEngineException)))
				{
					throw;
				}
				formatter = (IFormatter)new WeakSerializableFormatter(type);
			}
			return true;
		}
	}
	public class NetworkBehaviourReferenceFormatter : MinimalBaseFormatter<NetworkBehaviourReference>
	{
		private static readonly Serializer<ushort> UInt16Serializer = Serializer.Get<ushort>();

		private static readonly Serializer<NetworkObjectReference> NetworkObjectReferenceSerializer = Serializer.Get<NetworkObjectReference>();

		protected override void Read(ref NetworkBehaviourReference value, IDataReader reader)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			value.m_NetworkObjectReference = NetworkObjectReferenceSerializer.ReadValue(reader);
			value.m_NetworkBehaviourId = UInt16Serializer.ReadValue(reader);
		}

		protected override void Write(ref NetworkBehaviourReference value, IDataWriter writer)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			NetworkObjectReferenceSerializer.WriteValue(value.m_NetworkObjectReference, writer);
			UInt16Serializer.WriteValue(value.m_NetworkBehaviourId, writer);
		}
	}
	internal class NetworkObjectReferenceFormatter : MinimalBaseFormatter<NetworkObjectReference>
	{
		private static readonly Serializer<ulong> UInt64Serializer = Serializer.Get<ulong>();

		protected override void Read(ref NetworkObjectReference value, IDataReader reader)
		{
			((NetworkObjectReference)(ref value)).NetworkObjectId = UInt64Serializer.ReadValue(reader);
		}

		protected override void Write(ref NetworkObjectReference value, IDataWriter writer)
		{
			UInt64Serializer.WriteValue(((NetworkObjectReference)(ref value)).NetworkObjectId, writer);
		}
	}
}
namespace StaticNetcodeLib.Patches
{
	[HarmonyPatch(typeof(NetworkManager))]
	[HarmonyPriority(500)]
	[HarmonyWrapSafe]
	internal static class NetworkManagerPatch
	{
		[HarmonyPatch("Initialize")]
		[HarmonyPostfix]
		public static void InitializePatch()
		{
			new UnnamedMessageHandler();
		}

		[HarmonyPatch("Shutdown")]
		[HarmonyPrefix]
		public static void ShutdownPatch()
		{
			UnnamedMessageHandler.Instance?.Dispose();
		}
	}
	internal class RpcPatcher
	{
		internal static Dictionary<MethodBase, RpcExecStage> RpcExecStageLookup { get; } = new Dictionary<MethodBase, RpcExecStage>();


		public static bool PatchServerRpc(MethodBase __originalMethod, object[] __args)
		{
			if (!IsListening(out NetworkManager networkManager))
			{
				return false;
			}
			RpcExecStage rpcExecStage = RpcExecStageLookup[__originalMethod];
			if (rpcExecStage == RpcExecStage.Server)
			{
				return true;
			}
			if (!networkManager.IsClient && !networkManager.IsHost)
			{
				return false;
			}
			SendServerRpc(__originalMethod, ref __args);
			return false;
		}

		public static bool PatchClientRpc(MethodBase __originalMethod, object[]? __args)
		{
			if (!IsListening(out NetworkManager networkManager))
			{
				return false;
			}
			RpcExecStage rpcExecStage = RpcExecStageLookup[__originalMethod];
			if (rpcExecStage == RpcExecStage.Client)
			{
				return true;
			}
			if (!networkManager.IsHost && !networkManager.IsServer)
			{
				return false;
			}
			SendClientRpc(__originalMethod, __args);
			return false;
		}

		private static bool IsListening(out NetworkManager? networkManager)
		{
			networkManager = NetworkManager.Singleton;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				return UnnamedMessageHandler.Instance != null;
			}
			return false;
		}

		private static void SendServerRpc(MethodBase __originalMethod, ref object[] __args)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!IsListening(out NetworkManager networkManager))
			{
				return;
			}
			MessageData messageData = new MessageData(MessageType.ServerRpc, __originalMethod, __args);
			for (int num = __args.Length - 1; num >= 0; num--)
			{
				if (__args[num] is ServerRpcParams val)
				{
					val.Receive.SenderClientId = networkManager.LocalClientId;
					__args[num] = val;
					break;
				}
			}
			UnnamedMessageHandler.Instance.SendMessageToServer(messageData);
		}

		private static void SendClientRpc(MethodBase __originalMethod, object[]? __args)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (!IsListening(out NetworkManager _))
			{
				return;
			}
			MessageData messageData = new MessageData(MessageType.ClientRpc, __originalMethod, __args);
			if (__args == null || __args.Length == 0 || !__args.Any((object arg) => arg is ClientRpcParams))
			{
				UnnamedMessageHandler.Instance.SendMessageToClient(messageData);
				return;
			}
			ClientRpcParams clientRpcParams = (ClientRpcParams)__args.FirstOrDefault((object arg) => arg is ClientRpcParams);
			UnnamedMessageHandler.Instance.SendMessageToClient(messageData, clientRpcParams);
		}
	}
}
namespace StaticNetcodeLib.Messaging
{
	public record MessageData([property: OdinSerialize] MessageType MessageType, [property: OdinSerialize] MethodBase MethodBase, [property: OdinSerialize] object? Data)
	{
		public (MessageType, MethodBase, object?) AsValueTuple()
		{
			return (MessageType, MethodBase, Data);
		}
	}
	internal class UnnamedMessageHandler : IDisposable
	{
		private const string LibIdentifier = "StaticNetcodeLib";

		private static readonly SerializationContext DefaultSerializationContext = new SerializationContext
		{
			Config = new SerializationConfig
			{
				SerializationPolicy = SerializationPolicies.Everything
			}
		};

		private static readonly DeserializationContext DefaultDeserializationContext = new DeserializationContext
		{
			Config = new SerializationConfig
			{
				SerializationPolicy = SerializationPolicies.Everything
			}
		};

		internal static UnnamedMessageHandler? Instance { get; private set; }

		private NetworkManager NetworkManager { get; }

		private CustomMessagingManager CustomMessagingManager { get; }

		internal UnnamedMessageHandler()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Instance = this;
			NetworkManager = NetworkManager.Singleton;
			CustomMessagingManager = NetworkManager.CustomMessagingManager;
			CustomMessagingManager.OnUnnamedMessage += new UnnamedMessageDelegate(ReceiveMessage);
		}

		internal void SendMessageToClient(MessageData messageData, ClientRpcParams clientRpcParams = default(ClientRpcParams))
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			WriteMessageData(out var writer, messageData);
			IReadOnlyList<ulong> readOnlyList = clientRpcParams.Send.TargetClientIds ?? clientRpcParams.Send.TargetClientIdsNativeArray.GetValueOrDefault().ToArray();
			if (readOnlyList.Any((ulong client) => client == 0))
			{
				readOnlyList = readOnlyList.Where((ulong client) => client != 0) as IReadOnlyList<ulong>;
				FastBufferReader message = default(FastBufferReader);
				((FastBufferReader)(ref message))..ctor(writer, (Allocator)2, -1, 0, (Allocator)2);
				try
				{
					ReceiveMessage(0uL, message);
					if ((readOnlyList == null || readOnlyList.Count == 0) ? true : false)
					{
						((FastBufferWriter)(ref writer)).Dispose();
						return;
					}
				}
				finally
				{
					((IDisposable)(FastBufferReader)(ref message)).Dispose();
				}
			}
			if (readOnlyList.Any())
			{
				CustomMessagingManager.SendUnnamedMessage(readOnlyList, writer, (NetworkDelivery)4);
			}
			else
			{
				CustomMessagingManager.SendUnnamedMessageToAll(writer, (NetworkDelivery)4);
			}
			((FastBufferWriter)(ref writer)).Dispose();
		}

		internal void SendMessageToServer(MessageData messageData)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			WriteMessageData(out var writer, messageData);
			CustomMessagingManager.SendUnnamedMessage(0uL, writer, (NetworkDelivery)4);
			((FastBufferWriter)(ref writer)).Dispose();
		}

		private void ReceiveMessage(ulong clientId, FastBufferReader message)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			string text = default(string);
			((FastBufferReader)(ref message)).ReadValueSafe(ref text, false);
			if (!(text != "StaticNetcodeLib"))
			{
				byte[] serializedData = default(byte[]);
				((FastBufferReader)(ref message)).ReadValueSafe<byte>(ref serializedData, default(ForPrimitives));
				MessageData messageData = DeserializeMessageData(serializedData);
				switch (messageData.MessageType)
				{
				case MessageType.ServerRpc:
				case MessageType.ClientRpc:
					ReceiveRpc(messageData);
					break;
				case MessageType.Variable:
					throw new NotImplementedException();
				default:
					throw new ArgumentOutOfRangeException();
				}
			}
		}

		private void ReceiveRpc(MessageData messageData)
		{
			(MessageType, MethodBase, object?) tuple = messageData.AsValueTuple();
			MethodBase item = tuple.Item2;
			object item2 = tuple.Item3;
			item = item ?? throw new NullReferenceException("MethodBase is null.");
			object[] array = (object[])item2;
			object[] parameters = ((array != null && array.Length == 0) ? null : ((object[])item2));
			RpcExecStage value = ((messageData.MessageType == MessageType.ServerRpc) ? RpcExecStage.Server : RpcExecStage.Client);
			RpcPatcher.RpcExecStageLookup[item] = value;
			item.Invoke(null, parameters);
			RpcPatcher.RpcExecStageLookup[item] = RpcExecStage.None;
		}

		private static byte[] Serialize(object? data)
		{
			return SerializationUtility.SerializeValue<object>(data, (DataFormat)0, DefaultSerializationContext);
		}

		private static byte[] SerializeMessageData(MessageData messageData)
		{
			return SerializationUtility.SerializeValue<MessageData>(messageData with
			{
				Data = Serialize(messageData.Data)
			}, (DataFormat)0, (SerializationContext)null);
		}

		private static T Deserialize<T>(byte[] serializedData)
		{
			return SerializationUtility.DeserializeValue<T>(serializedData, (DataFormat)0, DefaultDeserializationContext);
		}

		private static MessageData DeserializeMessageData(byte[] serializedData)
		{
			MessageData messageData = SerializationUtility.DeserializeValue<MessageData>(serializedData, (DataFormat)0, (DeserializationContext)null);
			return messageData with
			{
				Data = Deserialize<object[]>((byte[])messageData.Data)
			};
		}

		private static void WriteMessageData(out FastBufferWriter writer, MessageData messageData)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			(byte[], int) tuple = SerializeDataAndGetSize(messageData);
			byte[] item = tuple.Item1;
			int item2 = tuple.Item2;
			writer = new FastBufferWriter(item2, (Allocator)2, -1);
			((FastBufferWriter)(ref writer)).WriteValueSafe("StaticNetcodeLib", false);
			((FastBufferWriter)(ref writer)).WriteValueSafe<byte>(item, default(ForPrimitives));
		}

		private static (byte[], int) SerializeDataAndGetSize(MessageData messageData)
		{
			int num = 0;
			byte[] array = SerializeMessageData(messageData);
			num += Encoding.UTF8.GetByteCount("StaticNetcodeLib");
			num += array.Length;
			num += 100;
			return (array, num);
		}

		public void Dispose()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			CustomMessagingManager.OnUnnamedMessage -= new UnnamedMessageDelegate(ReceiveMessage);
		}
	}
}
namespace StaticNetcodeLib.Enums
{
	public enum MessageType
	{
		ServerRpc,
		ClientRpc,
		Variable
	}
	internal enum RpcExecStage
	{
		None,
		Server,
		Client
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
	internal static class IsExternalInit
	{
	}
}