Decompiled source of Networking Tools v0.1.0

Packer.NetworkingTools.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using FistVR;
using H3MP.Scripts;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("Packer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("H3MP networking tools for easy syncing mods")]
[assembly: AssemblyFileVersion("0.9.0.0")]
[assembly: AssemblyInformationalVersion("0.9.0+4451aca4407294906a656f22f8ac49eee81db56c")]
[assembly: AssemblyProduct("Packer.NetworkingTools")]
[assembly: AssemblyTitle("Networking Tools")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.9.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace H3MP.Networking
{
	[BepInPlugin("Packer.NetworkingTools", "Networking Tools", "0.9.0")]
	[BepInProcess("h3vr.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NetworkingToolsPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
		}
	}
	public class CustomConnection
	{
		public delegate void UpdateHandlerDelegate(int clientID, PacketData packet);

		private bool Ready = false;

		public string Name;

		private string ToClientName = "ToClient";

		private int toClient_ID;

		private string ToServerName = "ToServer";

		private int toServer_ID;

		public int ToClientID => toClient_ID;

		public int ToServerID => toServer_ID;

		public event UpdateHandlerDelegate ServerHandlerEvent;

		public event UpdateHandlerDelegate ClientHandlerEvent;

		public CustomConnection(string connectionName)
		{
			ToClientName = connectionName + "ToClient";
			ToServerName = connectionName + "ToServer";
			Name = connectionName;
		}

		public void Setup()
		{
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			if (Ready)
			{
				return;
			}
			Ready = true;
			NetworkingToolsPlugin.Logger.LogMessage((object)(Name + " Setup"));
			if (Tools.IsHost())
			{
				if (Mod.registeredCustomPacketIDs.ContainsKey(ToClientName))
				{
					toClient_ID = Mod.registeredCustomPacketIDs[ToClientName];
				}
				else
				{
					toClient_ID = Server.RegisterCustomPacketType(ToClientName, 0);
				}
				Mod.customPacketHandlers[toClient_ID] = new CustomPacketHandler(ClientReceiver_Handler);
				if (Mod.registeredCustomPacketIDs.ContainsKey(ToServerName))
				{
					toServer_ID = Mod.registeredCustomPacketIDs[ToServerName];
				}
				else
				{
					toServer_ID = Server.RegisterCustomPacketType(ToServerName, 0);
				}
				Mod.customPacketHandlers[toServer_ID] = new CustomPacketHandler(ServerReceiver_Handler);
				return;
			}
			if (Mod.registeredCustomPacketIDs.ContainsKey(ToClientName))
			{
				toClient_ID = Mod.registeredCustomPacketIDs[ToClientName];
				Mod.customPacketHandlers[toClient_ID] = new CustomPacketHandler(ClientReceiver_Handler);
			}
			else
			{
				ClientSend.RegisterCustomPacketType(ToClientName);
				Mod.CustomPacketHandlerReceived += new CustomPacketHandlerReceivedDelegate(ClientIdentifier_Received);
			}
			if (Mod.registeredCustomPacketIDs.ContainsKey(ToServerName))
			{
				toServer_ID = Mod.registeredCustomPacketIDs[ToServerName];
				Mod.customPacketHandlers[toServer_ID] = new CustomPacketHandler(ServerReceiver_Handler);
			}
			else
			{
				ClientSend.RegisterCustomPacketType(ToServerName);
				Mod.CustomPacketHandlerReceived += new CustomPacketHandlerReceivedDelegate(ServerIdentifier_Received);
			}
		}

		public void ServerToClients(PacketData packet)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Packet val = new Packet(packet.ToArray());
			ServerSend.SendTCPDataToAll(val, true);
			NetworkingToolsPlugin.Logger.LogDebug((object)"Server To Clients");
		}

		public void ServerToSelectClients(PacketData packet, List<int> clientIDs)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Packet val = new Packet(packet.ToArray());
			ServerSend.SendTCPDataToClients(val, clientIDs, -1, true);
			NetworkingToolsPlugin.Logger.LogDebug((object)"Server To Select Clients");
		}

		public void ServerToClient(int clientID, PacketData packet)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Packet val = new Packet(packet.ToArray());
			ServerSend.SendTCPData(clientID, val, true);
			NetworkingToolsPlugin.Logger.LogDebug((object)"Server To Client");
		}

		public void ClientToServer(PacketData packet)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Packet val = new Packet(packet.ToArray());
			ClientSend.SendTCPData(val, true);
			NetworkingToolsPlugin.Logger.LogDebug((object)"Client To Server - Send Data");
		}

		private void ClientReceiver_Handler(int clientID, Packet packet)
		{
			if (this.ClientHandlerEvent != null)
			{
				PacketData packetData = new PacketData(packet.ToArray());
				packetData.readPos = packet.readPos;
				this.ClientHandlerEvent(clientID, packetData);
			}
			NetworkingToolsPlugin.Logger.LogMessage((object)"Client - Client Receiver");
		}

		private void ServerReceiver_Handler(int clientID, Packet packet)
		{
			if (this.ServerHandlerEvent != null)
			{
				PacketData packetData = new PacketData(packet.ToArray());
				packetData.readPos = packet.readPos;
				this.ServerHandlerEvent(clientID, packetData);
			}
			NetworkingToolsPlugin.Logger.LogMessage((object)"Server - Server Receiver");
		}

		private void ClientIdentifier_Received(string identifier, int index)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			if (identifier == ToClientName)
			{
				NetworkingToolsPlugin.Logger.LogMessage((object)"Client Handshake");
				toClient_ID = index;
				Mod.customPacketHandlers[index] = new CustomPacketHandler(ClientReceiver_Handler);
				Mod.CustomPacketHandlerReceived -= new CustomPacketHandlerReceivedDelegate(ClientIdentifier_Received);
			}
		}

		private void ServerIdentifier_Received(string identifier, int index)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			if (identifier == ToServerName)
			{
				NetworkingToolsPlugin.Logger.LogMessage((object)"Server Handshake");
				toServer_ID = index;
				Mod.customPacketHandlers[index] = new CustomPacketHandler(ServerReceiver_Handler);
				Mod.CustomPacketHandlerReceived -= new CustomPacketHandlerReceivedDelegate(ServerIdentifier_Received);
			}
		}
	}
	public class PacketData : IDisposable
	{
		public List<byte> buffer;

		public byte[] readableBuffer;

		public int readPos;

		private bool disposed = false;

		public PacketData()
		{
			buffer = new List<byte>();
			readPos = 0;
		}

		public PacketData(int _id)
		{
			buffer = new List<byte>();
			readPos = 0;
			Write(_id);
		}

		public PacketData(byte[] _data)
		{
			buffer = new List<byte>();
			readPos = 0;
			SetBytes(_data);
		}

		public void SetBytes(byte[] _data)
		{
			Write(_data);
			readableBuffer = buffer.ToArray();
		}

		public void WriteLength()
		{
			buffer.InsertRange(0, BitConverter.GetBytes(buffer.Count));
		}

		public void InsertInt(int _value)
		{
			buffer.InsertRange(0, BitConverter.GetBytes(_value));
		}

		public byte[] ToArray()
		{
			readableBuffer = buffer.ToArray();
			return readableBuffer;
		}

		public int Length()
		{
			return buffer.Count;
		}

		public int UnreadLength()
		{
			return Length() - readPos;
		}

		public void Reset(bool _shouldReset = true)
		{
			if (_shouldReset)
			{
				buffer.Clear();
				readableBuffer = null;
				readPos = 0;
			}
			else
			{
				readPos -= 4;
			}
		}

		public void Write(byte _value)
		{
			buffer.Add(_value);
		}

		public void Write(byte[] _value)
		{
			buffer.AddRange(_value);
		}

		public void Write(short _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(ushort _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(int _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(uint _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(long _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(float _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(double _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(bool _value)
		{
			buffer.AddRange(BitConverter.GetBytes(_value));
		}

		public void Write(string _value)
		{
			Write(_value.Length);
			buffer.AddRange(Encoding.ASCII.GetBytes(_value));
		}

		public void Write(Vector3 _value)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			Write(_value.x);
			Write(_value.y);
			Write(_value.z);
		}

		public void Write(Vector2 _value)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Write(_value.x);
			Write(_value.y);
		}

		public void Write(Quaternion _value)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			Write(_value.x);
			Write(_value.y);
			Write(_value.z);
			Write(_value.w);
		}

		public void Write(Damage damage)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			Write(damage.point);
			Write(damage.Source_IFF);
			Write(damage.Source_Point);
			Write(damage.Dam_Blunt);
			Write(damage.Dam_Piercing);
			Write(damage.Dam_Cutting);
			Write(damage.Dam_TotalKinetic);
			Write(damage.Dam_Thermal);
			Write(damage.Dam_Chilling);
			Write(damage.Dam_EMP);
			Write(damage.Dam_TotalEnergetic);
			Write(damage.Dam_Stunning);
			Write(damage.Dam_Blinding);
			Write(damage.hitNormal);
			Write(damage.strikeDir);
			Write(damage.edgeNormal);
			Write(damage.damageSize);
			Write((byte)damage.Class);
		}

		public void Write(SosigConfigTemplate config)
		{
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			Write(config.AppliesDamageResistToIntegrityLoss);
			Write(config.DoesDropWeaponsOnBallistic);
			Write(config.TotalMustard);
			Write(config.BleedDamageMult);
			Write(config.BleedRateMultiplier);
			Write(config.BleedVFXIntensity);
			Write(config.SearchExtentsModifier);
			Write(config.ShudderThreshold);
			Write(config.ConfusionThreshold);
			Write(config.ConfusionMultiplier);
			Write(config.ConfusionTimeMax);
			Write(config.StunThreshold);
			Write(config.StunMultiplier);
			Write(config.StunTimeMax);
			Write(config.HasABrain);
			Write(config.HasNightVision);
			Write(config.RegistersPassiveThreats);
			Write(config.CanBeKnockedOut);
			Write(config.MaxUnconsciousTime);
			Write(config.IgnoresNeedForWeapons);
			Write(config.AssaultPointOverridesSkirmishPointWhenFurtherThan);
			Write(config.ViewDistance);
			Write(config.HearingDistance);
			Write(config.MaxFOV);
			Write(config.StateSightRangeMults);
			Write(config.StateHearingRangeMults);
			Write(config.StateFOVMults);
			Write(config.CanPickup_Ranged);
			Write(config.CanPickup_Melee);
			Write(config.CanPickup_Other);
			Write(config.MaxThreatingIFFReactionRange_Visual);
			Write(config.MaxThreatingIFFReactionRange_Sonic);
			Write(config.AggroSensitivityMultiplier);
			Write(config.EntityRecognitionSpeedMultiplier);
			Write(config.CombatTargetIdentificationSpeedMultiplier);
			Write(config.DoesJointBreakKill_Head);
			Write(config.DoesJointBreakKill_Upper);
			Write(config.DoesJointBreakKill_Lower);
			Write(config.DoesSeverKill_Head);
			Write(config.DoesSeverKill_Upper);
			Write(config.DoesSeverKill_Lower);
			Write(config.DoesExplodeKill_Head);
			Write(config.DoesExplodeKill_Upper);
			Write(config.DoesExplodeKill_Lower);
			Write(config.CrawlSpeed);
			Write(config.SneakSpeed);
			Write(config.WalkSpeed);
			Write(config.RunSpeed);
			Write(config.TurnSpeed);
			Write(config.MovementRotMagnitude);
			Write(config.DamMult_Projectile);
			Write(config.DamMult_Explosive);
			Write(config.DamMult_Melee);
			Write(config.DamMult_Piercing);
			Write(config.DamMult_Blunt);
			Write(config.DamMult_Cutting);
			Write(config.DamMult_Thermal);
			Write(config.DamMult_Chilling);
			Write(config.DamMult_EMP);
			Write(config.CanBeSurpressed);
			Write(config.SuppressionMult);
			Write(config.CanBeGrabbed);
			Write(config.CanBeSevered);
			Write(config.CanBeStabbed);
			Write(config.MaxJointLimit);
			if (config.LinkDamageMultipliers == null || config.LinkDamageMultipliers.Count == 0)
			{
				Write((byte)0);
			}
			else
			{
				Write((byte)config.LinkDamageMultipliers.Count);
				foreach (float linkDamageMultiplier in config.LinkDamageMultipliers)
				{
					Write(linkDamageMultiplier);
				}
			}
			if (config.LinkStaggerMultipliers == null || config.LinkStaggerMultipliers.Count == 0)
			{
				Write((byte)0);
			}
			else
			{
				Write((byte)config.LinkStaggerMultipliers.Count);
				foreach (float linkStaggerMultiplier in config.LinkStaggerMultipliers)
				{
					Write(linkStaggerMultiplier);
				}
			}
			if (config.StartingLinkIntegrity == null || config.StartingLinkIntegrity.Count == 0)
			{
				Write((byte)0);
			}
			else
			{
				Write((byte)config.StartingLinkIntegrity.Count);
				foreach (Vector2 item in config.StartingLinkIntegrity)
				{
					Write(item);
				}
			}
			if (config.StartingChanceBrokenJoint == null || config.StartingChanceBrokenJoint.Count == 0)
			{
				Write((byte)0);
			}
			else
			{
				Write((byte)config.StartingChanceBrokenJoint.Count);
				foreach (float item2 in config.StartingChanceBrokenJoint)
				{
					Write(item2);
				}
			}
			if (config.LinkSpawnChance == null || config.LinkSpawnChance.Count == 0)
			{
				Write((byte)0);
			}
			else
			{
				Write((byte)config.LinkSpawnChance.Count);
				foreach (float item3 in config.LinkSpawnChance)
				{
					Write(item3);
				}
			}
			Write(config.TargetCapacity);
			Write(config.TargetTrackingTime);
			Write(config.NoFreshTargetTime);
			Write(config.DoesAggroOnFriendlyFire);
			Write(config.UsesLinkSpawns);
			Write(config.TimeInSkirmishToAlert);
		}

		public byte ReadByte(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				byte result = readableBuffer[readPos];
				if (_moveReadPos)
				{
					readPos++;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'byte'!");
		}

		public byte[] ReadBytes(int _length, bool _moveReadPos = true)
		{
			if (_length == 0)
			{
				return null;
			}
			if (buffer.Count > readPos)
			{
				byte[] result = buffer.GetRange(readPos, _length).ToArray();
				if (_moveReadPos)
				{
					readPos += _length;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'byte[]'!");
		}

		public short ReadShort(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				short result = BitConverter.ToInt16(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 2;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'short'!");
		}

		public ushort ReadUShort(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				ushort result = BitConverter.ToUInt16(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 2;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'ushort'!");
		}

		public int ReadInt(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				int result = BitConverter.ToInt32(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 4;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'int'!");
		}

		public uint ReadUInt(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				uint result = BitConverter.ToUInt32(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 4;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'uint'!");
		}

		public long ReadLong(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				long result = BitConverter.ToInt64(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 8;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'long'!");
		}

		public float ReadFloat(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				float result = BitConverter.ToSingle(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 4;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'float'!");
		}

		public double ReadDouble(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				double result = BitConverter.ToDouble(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos += 8;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'double'!");
		}

		public bool ReadBool(bool _moveReadPos = true)
		{
			if (buffer.Count > readPos)
			{
				bool result = BitConverter.ToBoolean(readableBuffer, readPos);
				if (_moveReadPos)
				{
					readPos++;
				}
				return result;
			}
			throw new Exception("Could not read value of type 'bool'!");
		}

		public string ReadString(bool _moveReadPos = true)
		{
			try
			{
				int num = ReadInt();
				string @string = Encoding.ASCII.GetString(readableBuffer, readPos, num);
				if (_moveReadPos && @string.Length > 0)
				{
					readPos += num;
				}
				return @string;
			}
			catch
			{
				throw new Exception("Could not read value of type 'string'!");
			}
		}

		public Vector3 ReadVector3(bool _moveReadPos = true)
		{
			//IL_0016: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(ReadFloat(_moveReadPos), ReadFloat(_moveReadPos), ReadFloat(_moveReadPos));
		}

		public Vector2 ReadVector2(bool _moveReadPos = true)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(ReadFloat(_moveReadPos), ReadFloat(_moveReadPos));
		}

		public Quaternion ReadQuaternion(bool _moveReadPos = true)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(ReadFloat(_moveReadPos), ReadFloat(_moveReadPos), ReadFloat(_moveReadPos), ReadFloat(_moveReadPos));
		}

		public SosigConfigTemplate ReadSosigConfig(bool full = false, bool _moveReadPos = true)
		{
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			SosigConfigTemplate val = ScriptableObject.CreateInstance<SosigConfigTemplate>();
			val.AppliesDamageResistToIntegrityLoss = ReadBool();
			val.DoesDropWeaponsOnBallistic = ReadBool();
			val.TotalMustard = ReadFloat();
			val.BleedDamageMult = ReadFloat();
			val.BleedRateMultiplier = ReadFloat();
			val.BleedVFXIntensity = ReadFloat();
			val.SearchExtentsModifier = ReadFloat();
			val.ShudderThreshold = ReadFloat();
			val.ConfusionThreshold = ReadFloat();
			val.ConfusionMultiplier = ReadFloat();
			val.ConfusionTimeMax = ReadFloat();
			val.StunThreshold = ReadFloat();
			val.StunMultiplier = ReadFloat();
			val.StunTimeMax = ReadFloat();
			val.HasABrain = ReadBool();
			val.HasNightVision = ReadBool();
			val.RegistersPassiveThreats = ReadBool();
			val.CanBeKnockedOut = ReadBool();
			val.MaxUnconsciousTime = ReadFloat();
			val.IgnoresNeedForWeapons = ReadBool();
			val.AssaultPointOverridesSkirmishPointWhenFurtherThan = ReadFloat();
			val.ViewDistance = ReadFloat();
			val.HearingDistance = ReadFloat();
			val.MaxFOV = ReadFloat();
			val.StateSightRangeMults = ReadVector3();
			val.StateHearingRangeMults = ReadVector3();
			val.StateFOVMults = ReadVector3();
			val.CanPickup_Ranged = ReadBool();
			val.CanPickup_Melee = ReadBool();
			val.CanPickup_Other = ReadBool();
			val.MaxThreatingIFFReactionRange_Visual = ReadFloat();
			val.MaxThreatingIFFReactionRange_Sonic = ReadFloat();
			val.AggroSensitivityMultiplier = ReadFloat();
			val.EntityRecognitionSpeedMultiplier = ReadFloat();
			val.CombatTargetIdentificationSpeedMultiplier = ReadFloat();
			val.DoesJointBreakKill_Head = ReadBool();
			val.DoesJointBreakKill_Upper = ReadBool();
			val.DoesJointBreakKill_Lower = ReadBool();
			val.DoesSeverKill_Head = ReadBool();
			val.DoesSeverKill_Upper = ReadBool();
			val.DoesSeverKill_Lower = ReadBool();
			val.DoesExplodeKill_Head = ReadBool();
			val.DoesExplodeKill_Upper = ReadBool();
			val.DoesExplodeKill_Lower = ReadBool();
			val.CrawlSpeed = ReadFloat();
			val.SneakSpeed = ReadFloat();
			val.WalkSpeed = ReadFloat();
			val.RunSpeed = ReadFloat();
			val.TurnSpeed = ReadFloat();
			val.MovementRotMagnitude = ReadFloat();
			val.DamMult_Projectile = ReadFloat();
			val.DamMult_Explosive = ReadFloat();
			val.DamMult_Melee = ReadFloat();
			val.DamMult_Piercing = ReadFloat();
			val.DamMult_Blunt = ReadFloat();
			val.DamMult_Cutting = ReadFloat();
			val.DamMult_Thermal = ReadFloat();
			val.DamMult_Chilling = ReadFloat();
			val.DamMult_EMP = ReadFloat();
			val.CanBeSurpressed = ReadBool();
			val.SuppressionMult = ReadFloat();
			val.CanBeGrabbed = ReadBool();
			val.CanBeSevered = ReadBool();
			val.CanBeStabbed = ReadBool();
			val.MaxJointLimit = ReadFloat();
			byte b = ReadByte();
			if (b > 0)
			{
				val.LinkDamageMultipliers = new List<float>();
				for (int i = 0; i < b; i++)
				{
					val.LinkDamageMultipliers.Add(ReadFloat());
				}
			}
			byte b2 = ReadByte();
			if (b2 > 0)
			{
				val.LinkStaggerMultipliers = new List<float>();
				for (int j = 0; j < b2; j++)
				{
					val.LinkStaggerMultipliers.Add(ReadFloat());
				}
			}
			byte b3 = ReadByte();
			if (b3 > 0)
			{
				val.StartingLinkIntegrity = new List<Vector2>();
				for (int k = 0; k < b3; k++)
				{
					val.StartingLinkIntegrity.Add(ReadVector2());
				}
			}
			byte b4 = ReadByte();
			if (b4 > 0)
			{
				val.StartingChanceBrokenJoint = new List<float>();
				for (int l = 0; l < b4; l++)
				{
					val.StartingChanceBrokenJoint.Add(ReadFloat());
				}
			}
			byte b5 = ReadByte();
			if (b5 > 0)
			{
				val.LinkSpawnChance = new List<float>();
				for (int m = 0; m < b5; m++)
				{
					val.LinkSpawnChance.Add(ReadFloat());
				}
			}
			val.TargetCapacity = ReadInt();
			val.TargetTrackingTime = ReadFloat();
			val.NoFreshTargetTime = ReadFloat();
			val.DoesAggroOnFriendlyFire = ReadBool();
			val.UsesLinkSpawns = ReadBool();
			val.TimeInSkirmishToAlert = ReadFloat();
			return val;
		}

		public Damage ReadDamage(bool _moveReadPos = true)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Damage val = new Damage();
			val.point = ReadVector3();
			val.Source_IFF = ReadInt();
			val.Source_Point = ReadVector3();
			val.Dam_Blunt = ReadFloat();
			val.Dam_Piercing = ReadFloat();
			val.Dam_Cutting = ReadFloat();
			val.Dam_TotalKinetic = ReadFloat();
			val.Dam_Thermal = ReadFloat();
			val.Dam_Chilling = ReadFloat();
			val.Dam_EMP = ReadFloat();
			val.Dam_TotalEnergetic = ReadFloat();
			val.Dam_Stunning = ReadFloat();
			val.Dam_Blinding = ReadFloat();
			val.hitNormal = ReadVector3();
			val.strikeDir = ReadVector3();
			val.edgeNormal = ReadVector3();
			val.damageSize = ReadFloat();
			val.Class = (DamageClass)ReadByte();
			return val;
		}

		protected virtual void Dispose(bool _disposing)
		{
			if (!disposed)
			{
				if (_disposing)
				{
					buffer = null;
					readableBuffer = null;
					readPos = 0;
				}
				disposed = true;
			}
		}

		public void Dispose()
		{
			Dispose(_disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	public class Tools
	{
		private static int enabled = 2;

		public static List<CustomConnection> connections = new List<CustomConnection>();

		public static bool H3MPEnabled
		{
			get
			{
				if (enabled == 2)
				{
					enabled = (byte)(Chainloader.PluginInfos.ContainsKey("VIP.TommySoucy.H3MP") ? 1 : 0);
				}
				return enabled == 1;
			}
		}

		private static bool isServerRunning
		{
			get
			{
				if ((Object)(object)Mod.managerObject == (Object)null)
				{
					return false;
				}
				return true;
			}
		}

		private static bool isHosting
		{
			get
			{
				if ((Object)(object)Mod.managerObject == (Object)null)
				{
					return false;
				}
				if (ThreadManager.host)
				{
					return true;
				}
				return false;
			}
		}

		private static int[] playerIds
		{
			get
			{
				int[] array = new int[GameManager.players.Count];
				int num = 0;
				foreach (KeyValuePair<int, PlayerManager> player in GameManager.players)
				{
					array[num] = player.Key;
					num++;
				}
				return array;
			}
		}

		private static int getLocalPlayerID => GameManager.ID;

		public static bool ServerRunning()
		{
			if (H3MPEnabled)
			{
				return isServerRunning;
			}
			return false;
		}

		public static bool IsClient()
		{
			if (ServerRunning())
			{
				return isClient();
			}
			return false;
		}

		private static bool isClient()
		{
			if ((Object)(object)Mod.managerObject == (Object)null)
			{
				return false;
			}
			if (!ThreadManager.host)
			{
				return true;
			}
			return false;
		}

		public static bool IsHost()
		{
			if (ServerRunning())
			{
				return isHosting;
			}
			return false;
		}

		public static void SetLocalPlayerIFF(int iff)
		{
			GM.CurrentPlayerBody.SetPlayerIFF(iff);
			if (ServerRunning())
			{
				setLocalPlayerIFF(iff);
			}
		}

		private static void setLocalPlayerIFF(int iff)
		{
			if (ThreadManager.host)
			{
				ServerSend.PlayerIFF(0, GM.CurrentPlayerBody.GetPlayerIFF());
			}
			else
			{
				ClientSend.PlayerIFF(GM.CurrentPlayerBody.GetPlayerIFF());
			}
		}

		public static int GetPlayerCount()
		{
			if (H3MPEnabled)
			{
				return GetNetworkPlayerCount();
			}
			return 1;
		}

		private static int GetNetworkPlayerCount()
		{
			return GameManager.players.Count;
		}

		public static int[] GetPlayerIDs()
		{
			if (!H3MPEnabled)
			{
				return null;
			}
			return playerIds;
		}

		public static int GetLocalPlayerID()
		{
			if (!H3MPEnabled)
			{
				return -1;
			}
			return getLocalPlayerID;
		}

		public static PlayerData GetPlayerData(int clientID)
		{
			if (!H3MPEnabled)
			{
				return GetLocalPlayerData();
			}
			return getPlayerData(clientID);
		}

		private static PlayerData getPlayerData(int clientID)
		{
			if (clientID == GameManager.ID)
			{
				PlayerData localPlayerData = GetLocalPlayerData();
				localPlayerData.username = ((object)Mod.config["Username"]).ToString();
				return localPlayerData;
			}
			PlayerData playerData = new PlayerData();
			playerData.head = GameManager.players[clientID].head;
			playerData.username = GameManager.players[clientID].username;
			playerData.handLeft = GameManager.players[clientID].leftHand;
			playerData.handRight = GameManager.players[clientID].rightHand;
			playerData.iff = GameManager.players[clientID].IFF;
			playerData.health = GameManager.players[clientID].health;
			playerData.ID = clientID;
			return playerData;
		}

		private static PlayerData GetLocalPlayerData()
		{
			PlayerData playerData = new PlayerData();
			playerData.username = "Player";
			playerData.head = GM.CurrentPlayerBody.Head;
			playerData.handLeft = GM.CurrentPlayerBody.LeftHand;
			playerData.handRight = GM.CurrentPlayerBody.RightHand;
			playerData.iff = GM.CurrentPlayerBody.GetPlayerIFF();
			playerData.health = GM.CurrentPlayerBody.Health;
			return playerData;
		}

		public static CustomConnection CreateCustomConnection(string connectionName)
		{
			CustomConnection customConnection = connections.FirstOrDefault((CustomConnection obj) => obj.Name == connectionName);
			CustomConnection customConnection2;
			if (customConnection != null)
			{
				customConnection2 = customConnection;
				NetworkingToolsPlugin.Logger.LogMessage((object)("Found Existing connection " + connectionName));
			}
			else
			{
				customConnection2 = new CustomConnection(connectionName);
				connections.Add(customConnection2);
				NetworkingToolsPlugin.Logger.LogMessage((object)("Created new connection " + connectionName));
			}
			customConnection2.Setup();
			return customConnection2;
		}
	}
	[Serializable]
	public class PlayerData
	{
		public Transform head;

		public string username;

		public Transform handLeft;

		public Transform handRight;

		public int ID;

		public float health;

		public int iff;

		public static PlayerData GetPlayer(int clientID)
		{
			return new PlayerData
			{
				head = GameManager.players[clientID].head,
				username = GameManager.players[clientID].username,
				handLeft = GameManager.players[clientID].leftHand,
				handRight = GameManager.players[clientID].rightHand,
				ID = clientID,
				health = GameManager.players[clientID].health,
				iff = GameManager.players[clientID].IFF
			};
		}
	}
	internal static class PluginInfo
	{
		internal const string NAME = "Networking Tools";

		internal const string GUID = "Packer.NetworkingTools";

		internal const string VERSION = "0.9.0";
	}
}