Decompiled source of BombCollar v1.1.2

BepInEx/plugins/BombCollar.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using ModelReplacement;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Audio;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BombCollar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BombCollar")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("90081f1b-71c8-44ba-8056-8e803d1d7702")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.2.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace BombCollar;

public class BombCollarProp : GrabbableObject
{
	public GameObject CollarGameObject;

	public GameObject RemoteGameObject;

	public GameObject CollarVisualPrefab;

	public GameObject CollarVisualRagdollPrefab;

	public Collider CollarCollider;

	public Collider RemoteCollider;

	public AudioSource AudioSource;

	public AudioClip RemoteClickClip;

	public AudioClip CollarAttachClip;

	public AudioClip CollarExplodeClip;

	public AudioClip RemoteDropClip;

	public AudioClip CollarDropClip;

	public AudioClip CollarAutoExplodeBeepClip;

	public Sprite RemoteSprite;

	public Sprite CollarSprite;

	private PlayerControllerB targetPlayer;

	private Material remoteMaterial;

	private GameObject visualCollar;

	private AudioSource visualCollarAudioSource;

	private Material visualCollarMaterial;

	private Transform headToFollow;

	private Vector3 headToFollowOffset;

	private bool useTransformPoint;

	private bool updateHeadToFollow;

	[HideInInspector]
	public bool isRemote;

	private bool hasExploded;

	private bool isExploding;

	private bool willAutoExplode;

	private int autoExplodeCount;

	private Coroutine autoExplodeCoroutine;

	public override void Start()
	{
		((GrabbableObject)this).Start();
		BombCollarBase.FixAudioMixer(AudioSource);
		((Component)this).GetComponentInChildren<ScanNodeProperties>().subText = "Not attached";
		remoteMaterial = ((Renderer)RemoteGameObject.GetComponent<MeshRenderer>()).material;
		BombCollarBase.Instance.AllBombCollars.Add(this);
		((NetworkBehaviour)this).NetworkManager.OnClientConnectedCallback += NetworkManager_OnClientConnectedCallback;
		BombCollarBase instance = BombCollarBase.Instance;
		instance.PlayerKilledEvent = (Action<int>)Delegate.Combine(instance.PlayerKilledEvent, new Action<int>(PlayerKilled));
		BombCollarBase instance2 = BombCollarBase.Instance;
		instance2.PlayerModelChangedEvent = (Action<PlayerControllerB, bool>)Delegate.Combine(instance2.PlayerModelChangedEvent, new Action<PlayerControllerB, bool>(PlayerModelChanged));
	}

	public override void Update()
	{
		((GrabbableObject)this).Update();
		if (!isRemote || hasExploded)
		{
			return;
		}
		float distanceToTarget = GetDistanceToTarget();
		remoteMaterial.SetFloat("_Distance", Mathf.Clamp01(math.remap(0f, SyncedInstance<Config>.Instance.MaxSignalDistance, 1f, 0f, distanceToTarget)));
		if ((Object)(object)visualCollarMaterial != (Object)null && !isExploding)
		{
			visualCollarMaterial.SetInt("_Enabled", (!(distanceToTarget > SyncedInstance<Config>.Instance.MaxSignalDistance)) ? 1 : 0);
			if (((NetworkBehaviour)this).IsOwner && SyncedInstance<Config>.Instance.ExplodeOutOfRange && !willAutoExplode && distanceToTarget > SyncedInstance<Config>.Instance.MaxSignalDistance && CanKillPlayer() && !targetPlayer.isPlayerDead)
			{
				SetAutoExplode(value: true);
			}
			else if (((NetworkBehaviour)this).IsOwner && willAutoExplode && distanceToTarget < SyncedInstance<Config>.Instance.MaxSignalDistance)
			{
				SetAutoExplode(value: false);
			}
		}
		if ((Object)(object)visualCollar != (Object)null && (Object)(object)headToFollow != (Object)null)
		{
			SetCollarPosition(useTransformPoint);
		}
	}

	public override void LateUpdate()
	{
		((GrabbableObject)this).LateUpdate();
		if (updateHeadToFollow)
		{
			UpdateHeadToFollowModelReplacement();
			updateHeadToFollow = false;
		}
	}

	public override void OnDestroy()
	{
		BombCollarBase.Instance.AllBombCollars.Remove(this);
		if ((Object)(object)visualCollar != (Object)null)
		{
			Object.Destroy((Object)(object)visualCollar);
		}
		((NetworkBehaviour)this).NetworkManager.OnClientConnectedCallback -= NetworkManager_OnClientConnectedCallback;
		BombCollarBase instance = BombCollarBase.Instance;
		instance.PlayerKilledEvent = (Action<int>)Delegate.Remove(instance.PlayerKilledEvent, new Action<int>(PlayerKilled));
		((NetworkBehaviour)this).OnDestroy();
	}

	public override void EquipItem()
	{
		((GrabbableObject)this).EquipItem();
		if ((Object)(object)base.playerHeldBy != (Object)null)
		{
			base.playerHeldBy.equippedUsableItemQE = true;
		}
	}

	public override void DiscardItem()
	{
		if ((Object)(object)base.playerHeldBy != (Object)null)
		{
			base.playerHeldBy.equippedUsableItemQE = false;
		}
		((GrabbableObject)this).DiscardItem();
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		if (!isRemote && ((NetworkBehaviour)this).IsOwner)
		{
			TryAttachToPlayer();
		}
		else if (isRemote)
		{
			AudioSource.PlayOneShot(RemoteClickClip);
			WalkieTalkie.TransmitOneShotAudio(AudioSource, RemoteClickClip, 0.7f);
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 8f, 0.4f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			((MonoBehaviour)this).StartCoroutine(BlinkRemoteCoroutine());
			if (((NetworkBehaviour)this).IsOwner && !hasExploded)
			{
				TryExplodeHeadServerRpc();
			}
		}
	}

	public override void ItemInteractLeftRight(bool right)
	{
		((GrabbableObject)this).ItemInteractLeftRight(right);
		if ((Object)(object)base.playerHeldBy != (Object)null && !right && !isRemote)
		{
			AttachToPlayerServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
		}
	}

	public override void SetControlTipsForItem()
	{
		if (isRemote)
		{
			base.itemProperties.itemName = "Bomb collar remote";
		}
		if (!isRemote)
		{
			((GrabbableObject)this).SetControlTipsForItem();
		}
		else if (!hasExploded)
		{
			HUDManager.Instance.ClearControlTips();
			HUDManager.Instance.ChangeControlTipMultiple(new string[2]
			{
				"Controlling " + targetPlayer.playerUsername + "'s collar",
				"Detonate: [RMB]"
			}, true, base.itemProperties);
		}
		else
		{
			HUDManager.Instance.ClearControlTips();
			HUDManager.Instance.ChangeControlTipMultiple(new string[1] { "Signal unavailable..." }, true, base.itemProperties);
		}
		if (isRemote)
		{
			base.itemProperties.itemName = "Bomb collar";
		}
	}

	public override void LoadItemSaveData(int saveData)
	{
		((MonoBehaviour)this).StartCoroutine(NetworkSafeLoadItemSaveData(saveData));
	}

	private IEnumerator NetworkSafeLoadItemSaveData(int saveData)
	{
		yield return (object)new WaitUntil((Func<bool>)(() => ((NetworkBehaviour)this).IsSpawned));
		if (((NetworkBehaviour)this).IsServer)
		{
			<>n__0(saveData);
			if ((saveData & 1) == 1)
			{
				LateJoinerSyncClientRpc();
			}
		}
	}

	public override int GetItemDataToSave()
	{
		int num = 0;
		return num | (hasExploded ? 1 : 0);
	}

	private void NetworkManager_OnClientConnectedCallback(ulong clientId)
	{
		//IL_000a: 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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		if (((NetworkBehaviour)this).IsServer)
		{
			ClientRpcParams val = default(ClientRpcParams);
			val.Send = new ClientRpcSendParams
			{
				TargetClientIds = new ulong[1] { clientId }
			};
			ClientRpcParams clientRpcParams = val;
			if ((Object)(object)targetPlayer != (Object)null && !hasExploded)
			{
				AttachToPlayerClientRpc((int)targetPlayer.playerClientId, sync: true, clientRpcParams);
			}
			else if (hasExploded)
			{
				LateJoinerSyncClientRpc(clientRpcParams);
			}
		}
	}

	[ClientRpc]
	private void LateJoinerSyncClientRpc(ClientRpcParams clientRpcParams = default(ClientRpcParams))
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3559542246u, clientRpcParams, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3559542246u, clientRpcParams, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				hasExploded = true;
				isRemote = true;
				remoteMaterial.SetFloat("_Distance", 0f);
				remoteMaterial.SetInt("_Enabled", 0);
				CollarGameObject.SetActive(false);
				CollarCollider.enabled = false;
				RemoteGameObject.SetActive(true);
				RemoteCollider.enabled = true;
				((Component)this).GetComponentInChildren<ScanNodeProperties>().headerText = "Bomb collar remote";
				((Component)this).GetComponentInChildren<ScanNodeProperties>().subText = "Signal unavailable...";
			}
		}
	}

	private float GetDistanceToTarget()
	{
		//IL_0014: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)targetPlayer != (Object)null)
		{
			return Vector3.Distance(((Component)this).transform.position, ((Component)targetPlayer).transform.position + Vector3.up * 0.5f);
		}
		return float.MaxValue;
	}

	private IEnumerator BlinkRemoteCoroutine()
	{
		remoteMaterial.SetInt("_StatusLED", 0);
		yield return (object)new WaitForSeconds(0.075f);
		remoteMaterial.SetInt("_StatusLED", 1);
	}

	public void TryAttachToPlayer()
	{
		//IL_0010: 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)
		//IL_002f: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit[] array = Physics.SphereCastAll(((Component)base.playerHeldBy.gameplayCamera).transform.position + ((Component)base.playerHeldBy.gameplayCamera).transform.forward * -0.35f, 0.8f, ((Component)base.playerHeldBy.gameplayCamera).transform.forward, 1.5f, 8, (QueryTriggerInteraction)2);
		RaycastHit[] array2 = array;
		PlayerControllerB val2 = default(PlayerControllerB);
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val = array2[i];
			if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<PlayerControllerB>(ref val2) && (Object)(object)val2 != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				AttachToPlayerServerRpc((int)val2.playerClientId);
				break;
			}
		}
	}

	private void SetAutoExplode(bool value)
	{
		willAutoExplode = value;
		if (willAutoExplode && autoExplodeCoroutine == null)
		{
			autoExplodeCoroutine = ((MonoBehaviour)this).StartCoroutine(AutoExplodeCoroutine());
			return;
		}
		if (autoExplodeCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(autoExplodeCoroutine);
		}
		autoExplodeCoroutine = null;
		autoExplodeCount = 0;
	}

	private IEnumerator AutoExplodeCoroutine()
	{
		if (!willAutoExplode || hasExploded || ((Object)(object)targetPlayer != (Object)null && targetPlayer.isPlayerDead))
		{
			SetAutoExplode(value: false);
		}
		else if (autoExplodeCount >= SyncedInstance<Config>.Instance.ExplodeOutOfRangeTime)
		{
			SetAutoExplode(value: false);
			if (!((Object)(object)targetPlayer == (Object)null) && CanKillPlayer() && !isExploding)
			{
				ExplodeHeadServerRpc();
			}
		}
		else
		{
			CollarBeepServerRpc();
			autoExplodeCount++;
			yield return (object)new WaitForSeconds(1f);
			autoExplodeCoroutine = ((MonoBehaviour)this).StartCoroutine(AutoExplodeCoroutine());
		}
	}

	[ServerRpc(RequireOwnership = true)]
	public void CollarBeepServerRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Invalid comparison between Unknown and I4
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Invalid comparison between Unknown and I4
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
				return;
			}
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3988253427u, val, (RpcDelivery)0);
			((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3988253427u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
		{
			CollarBeepClientRpc();
		}
	}

	[ServerRpc(RequireOwnership = true)]
	public void ExplodeHeadServerRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Invalid comparison between Unknown and I4
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Invalid comparison between Unknown and I4
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
				return;
			}
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2621359198u, val, (RpcDelivery)0);
			((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2621359198u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
		{
			ExplodeHeadClientRpc();
		}
	}

	[ClientRpc]
	public void CollarBeepClientRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1870152612u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1870152612u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && (Object)(object)visualCollarAudioSource != (Object)null)
			{
				visualCollarAudioSource.PlayOneShot(CollarAutoExplodeBeepClip);
				WalkieTalkie.TransmitOneShotAudio(visualCollarAudioSource, CollarAutoExplodeBeepClip, 0.7f);
				RoundManager.Instance.PlayAudibleNoise(((Component)targetPlayer).transform.position, 25f, 0.5f, 0, targetPlayer.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
		}
	}

	[ServerRpc(RequireOwnership = false)]
	public void AttachToPlayerServerRpc(int playerId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3913542059u, val, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val2, playerId);
			((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3913542059u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
		{
			return;
		}
		if (SyncedInstance<Config>.Instance.OneCollarPerPerson)
		{
			foreach (BombCollarProp allBombCollar in BombCollarBase.Instance.AllBombCollars)
			{
				if ((Object)(object)allBombCollar.targetPlayer != (Object)null && !allBombCollar.hasExploded && (int)allBombCollar.targetPlayer.playerClientId == playerId)
				{
					return;
				}
			}
		}
		AttachToPlayerClientRpc(playerId);
	}

	[ClientRpc]
	public void AttachToPlayerClientRpc(int playerId, bool sync = false, ClientRpcParams clientRpcParams = default(ClientRpcParams))
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1417853357u, clientRpcParams, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val, playerId);
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref sync, default(ForPrimitives));
			((NetworkBehaviour)this).__endSendClientRpc(ref val, 1417853357u, clientRpcParams, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (sync)
			{
				((MonoBehaviour)this).StartCoroutine(AttachToPlayerSync(playerId));
			}
			else
			{
				AttachToPlayer(playerId);
			}
		}
	}

	private IEnumerator AttachToPlayerSync(int playerId)
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null));
		AttachToPlayer(playerId);
	}

	private void AttachToPlayer(int playerId)
	{
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		isExploding = true;
		isRemote = true;
		CollarGameObject.SetActive(false);
		CollarCollider.enabled = false;
		RemoteGameObject.SetActive(true);
		RemoteCollider.enabled = true;
		targetPlayer = StartOfRound.Instance.allPlayerScripts[playerId];
		((Component)this).GetComponentInChildren<ScanNodeProperties>().headerText = "Bomb collar remote";
		((Component)this).GetComponentInChildren<ScanNodeProperties>().subText = targetPlayer.playerUsername + "'s collar";
		if (((NetworkBehaviour)this).IsOwner && base.isHeld)
		{
			HUDManager.Instance.itemSlotIcons[GameNetworkManager.Instance.localPlayerController.currentItemSlot].sprite = RemoteSprite;
			((GrabbableObject)this).SetControlTipsForItem();
		}
		Transform val = ((Component)targetPlayer.playerBodyAnimator).transform.Find("spine").Find("spine.001").Find("spine.002")
			.Find("spine.003");
		visualCollar = Object.Instantiate<GameObject>(CollarVisualPrefab, val);
		visualCollarMaterial = ((Renderer)visualCollar.GetComponentInChildren<MeshRenderer>()).material;
		visualCollarAudioSource = visualCollar.GetComponentInChildren<AudioSource>();
		BombCollarBase.FixAudioMixer(visualCollarAudioSource);
		visualCollarAudioSource.PlayOneShot(CollarAttachClip);
		WalkieTalkie.TransmitOneShotAudio(visualCollarAudioSource, CollarAttachClip, 0.7f);
		RoundManager.Instance.PlayAudibleNoise(((Component)targetPlayer).transform.position, 8f, 0.4f, 0, targetPlayer.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
		if (playerId == (int)GameNetworkManager.Instance.localPlayerController.playerClientId)
		{
			((Component)visualCollar.transform.Find("Model")).transform.SetLocalPositionAndRotation(new Vector3(0f, 0.2109995f, 0.01899986f), Quaternion.Euler(11.547f, 0f, 0f));
			ConstraintSource val2 = default(ConstraintSource);
			((ConstraintSource)(ref val2)).sourceTransform = ((Component)targetPlayer.playerBodyAnimator).transform;
			((ConstraintSource)(ref val2)).weight = 1f;
			ParentConstraint component = visualCollar.GetComponent<ParentConstraint>();
			component.SetSource(0, val2);
			component.constraintActive = true;
			if (!SyncedInstance<Config>.Instance.CanGrabOwnRemote)
			{
				base.grabbable = false;
				if (((NetworkBehaviour)this).IsOwner)
				{
					base.playerHeldBy.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				}
			}
		}
		else
		{
			headToFollow = ((Component)targetPlayer.playerBodyAnimator).transform.Find("spine").Find("spine.001").Find("spine.002")
				.Find("spine.003");
			headToFollowOffset = new Vector3(0f, 0.2109995f, 0.01899986f);
			useTransformPoint = true;
			if (BombCollarBase.Instance.HasModelReplacementAPI)
			{
				Transform modelReplacementTransform = GetModelReplacementTransform(targetPlayer, "spine.004");
				if ((Object)(object)modelReplacementTransform != (Object)null)
				{
					headToFollow = modelReplacementTransform;
					headToFollowOffset = -(Vector3.up * 0.025f);
					useTransformPoint = false;
				}
			}
		}
		((MonoBehaviour)this).StartCoroutine(AttachToPlayerDelayed());
	}

	private IEnumerator AttachToPlayerDelayed()
	{
		yield return (object)new WaitForSeconds(2f);
		isExploding = false;
		remoteMaterial.SetInt("_Enabled", 1);
		visualCollarMaterial.SetInt("_Enabled", 1);
	}

	private void SetCollarPosition(bool useTransformPoint = false)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		visualCollar.transform.SetPositionAndRotation(useTransformPoint ? ((Component)headToFollow).transform.TransformPoint(headToFollowOffset) : (((Component)headToFollow).transform.position + headToFollowOffset), ((Component)headToFollow).transform.rotation * Quaternion.Euler(11.547f, 0f, 0f));
	}

	private void UpdateHeadToFollowModelReplacement()
	{
		headToFollow = GetModelReplacementTransform(targetPlayer, "spine.004");
	}

	private void PlayerModelChanged(PlayerControllerB b, bool isModelReplacement)
	{
		//IL_00bb: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)targetPlayer != (Object)null && targetPlayer.playerClientId == b.playerClientId && b.playerClientId != GameNetworkManager.Instance.localPlayerController.playerClientId)
		{
			if (isModelReplacement)
			{
				updateHeadToFollow = true;
				headToFollowOffset = -(Vector3.up * 0.025f);
				useTransformPoint = false;
			}
			else
			{
				headToFollow = ((Component)targetPlayer.playerBodyAnimator).transform.Find("spine").Find("spine.001").Find("spine.002")
					.Find("spine.003");
				headToFollowOffset = new Vector3(0f, 0.2109995f, 0.01899986f);
				useTransformPoint = true;
			}
		}
	}

	private Transform GetModelReplacementTransform(PlayerControllerB player, string boneName, bool ragdoll = false)
	{
		BodyReplacementBase val = default(BodyReplacementBase);
		ModelReplacementAPI.GetPlayerModelReplacement(player, ref val);
		if ((Object)(object)val != (Object)null)
		{
			if (ragdoll)
			{
				return val.ragdollAvatar.GetAvatarTransformFromBoneName(boneName);
			}
			return val.cosmeticAvatar.GetAvatarTransformFromBoneName(boneName);
		}
		return null;
	}

	private bool CanKillPlayer()
	{
		if ((Object)(object)targetPlayer != (Object)null)
		{
			if (StartOfRound.Instance.inShipPhase || StartOfRound.Instance.timeSinceRoundStarted < 2f || !StartOfRound.Instance.shipDoorsEnabled)
			{
				return false;
			}
			return true;
		}
		return false;
	}

	[ServerRpc(RequireOwnership = false)]
	public void TryExplodeHeadServerRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1847491476u, val, (RpcDelivery)0);
			((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1847491476u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || (Object)(object)targetPlayer == (Object)null || !CanKillPlayer() || isExploding)
		{
			return;
		}
		float distanceToTarget = GetDistanceToTarget();
		if (distanceToTarget < SyncedInstance<Config>.Instance.MaxSignalDistance)
		{
			float num = SyncedInstance<Config>.Instance.RemoteDudChance;
			if (SyncedInstance<Config>.Instance.DistanceAffectsDudChance)
			{
				float num2 = Mathf.Clamp01(math.remap(0f, SyncedInstance<Config>.Instance.MaxSignalDistance, 0f, 1f, distanceToTarget));
				num = Mathf.Lerp(0f, SyncedInstance<Config>.Instance.RemoteDudChance, num2);
			}
			if (Random.Range(0f, 100f) > num)
			{
				ExplodeHeadClientRpc();
				SetAutoExplode(value: false);
			}
		}
	}

	[ClientRpc]
	public void ExplodeHeadClientRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(59171623u, val, (RpcDelivery)0);
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 59171623u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
		{
			isExploding = true;
			if (!SyncedInstance<Config>.Instance.PermanentCollar)
			{
				hasExploded = true;
			}
			visualCollarAudioSource.PlayOneShot(CollarExplodeClip);
			WalkieTalkie.TransmitOneShotAudio(visualCollarAudioSource, CollarExplodeClip, 0.7f);
			((MonoBehaviour)this).StartCoroutine(ExplodeHeadDelayed());
		}
	}

	private IEnumerator ExplodeHeadDelayed()
	{
		yield return (object)new WaitForSeconds(0.5f);
		isExploding = false;
		targetPlayer.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 1, default(Vector3));
		remoteMaterial.SetFloat("_Distance", 0f);
		if (Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)targetPlayer).transform.position) < 5f)
		{
			HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
		}
		if (((NetworkBehaviour)this).IsOwner && base.isHeld)
		{
			((GrabbableObject)this).SetControlTipsForItem();
		}
		if (SyncedInstance<Config>.Instance.CreateExplosion)
		{
			bool flag = SyncedInstance<Config>.Instance.ExplosionRadius > 3.5f;
			Landmine.SpawnExplosion(((Component)targetPlayer).transform.position + Vector3.up * 0.15f, flag, Mathf.Clamp(SyncedInstance<Config>.Instance.ExplosionRadius, 0f, 5f), SyncedInstance<Config>.Instance.ExplosionRadius * 1.5f, 50, 0f, (GameObject)null, false);
		}
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)targetPlayer.deadBody != (Object)null));
		Transform val = ((Component)targetPlayer.deadBody).transform.Find("spine.001").Find("spine.002").Find("spine.003");
		GameObject visualCollarRagdoll = Object.Instantiate<GameObject>(CollarVisualRagdollPrefab, val);
		AudioSource componentInChildren = visualCollarRagdoll.GetComponentInChildren<AudioSource>();
		BombCollarBase.FixAudioMixer(componentInChildren);
		WalkieTalkie.TransmitOneShotAudio(componentInChildren, componentInChildren.clip, 0.7f);
		RoundManager.Instance.PlayAudibleNoise(((Component)targetPlayer).transform.position, 40f, 1f, 0, targetPlayer.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
		if ((Object)(object)targetPlayer.deadBody.detachedHeadObject != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)targetPlayer.deadBody.detachedHeadObject).gameObject);
		}
		visualCollarRagdoll.transform.SetLocalPositionAndRotation(new Vector3(0f, 0.2109995f, 0.01899986f), Quaternion.Euler(11.547f, 0f, 0f));
		if (BombCollarBase.Instance.HasModelReplacementAPI)
		{
			yield return (object)new WaitForEndOfFrame();
			Transform modelReplacementTransform = GetModelReplacementTransform(targetPlayer, "spine.004", ragdoll: true);
			if ((Object)(object)modelReplacementTransform != (Object)null)
			{
				visualCollarRagdoll.transform.SetPositionAndRotation(((Component)modelReplacementTransform).transform.position - Vector3.up * 0.025f, ((Component)modelReplacementTransform).transform.rotation * Quaternion.Euler(11.547f, 0f, 0f));
				visualCollarRagdoll.transform.SetParent(modelReplacementTransform.parent, true);
				((Component)modelReplacementTransform).transform.localScale = Vector3.zero;
			}
		}
	}

	private void PlayerKilled(int playerId)
	{
		if (isRemote && playerId == (int)targetPlayer.playerClientId && !SyncedInstance<Config>.Instance.PermanentCollar)
		{
			hasExploded = true;
			remoteMaterial.SetInt("_Enabled", 0);
			if ((Object)(object)visualCollar != (Object)null)
			{
				Object.Destroy((Object)(object)visualCollar);
			}
			((Component)this).GetComponentInChildren<ScanNodeProperties>().headerText = "Bomb collar remote";
			((Component)this).GetComponentInChildren<ScanNodeProperties>().subText = "Signal unavailable...";
		}
	}

	[CompilerGenerated]
	[DebuggerHidden]
	private void <>n__0(int saveData)
	{
		((GrabbableObject)this).LoadItemSaveData(saveData);
	}

	protected override void __initializeVariables()
	{
		((GrabbableObject)this).__initializeVariables();
	}

	[RuntimeInitializeOnLoadMethod]
	internal static void InitializeRPCS_BombCollarProp()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		NetworkManager.__rpc_func_table.Add(3559542246u, new RpcReceiveHandler(__rpc_handler_3559542246));
		NetworkManager.__rpc_func_table.Add(3988253427u, new RpcReceiveHandler(__rpc_handler_3988253427));
		NetworkManager.__rpc_func_table.Add(2621359198u, new RpcReceiveHandler(__rpc_handler_2621359198));
		NetworkManager.__rpc_func_table.Add(1870152612u, new RpcReceiveHandler(__rpc_handler_1870152612));
		NetworkManager.__rpc_func_table.Add(3913542059u, new RpcReceiveHandler(__rpc_handler_3913542059));
		NetworkManager.__rpc_func_table.Add(1417853357u, new RpcReceiveHandler(__rpc_handler_1417853357));
		NetworkManager.__rpc_func_table.Add(1847491476u, new RpcReceiveHandler(__rpc_handler_1847491476));
		NetworkManager.__rpc_func_table.Add(59171623u, new RpcReceiveHandler(__rpc_handler_59171623));
	}

	private static void __rpc_handler_3559542246(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			ClientRpcParams client = rpcParams.Client;
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((BombCollarProp)(object)target).LateJoinerSyncClientRpc(client);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3988253427(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
		{
			if ((int)networkManager.LogLevel <= 1)
			{
				Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
			}
		}
		else
		{
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((BombCollarProp)(object)target).CollarBeepServerRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_2621359198(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
		{
			if ((int)networkManager.LogLevel <= 1)
			{
				Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
			}
		}
		else
		{
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((BombCollarProp)(object)target).ExplodeHeadServerRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_1870152612(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((BombCollarProp)(object)target).CollarBeepClientRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3913542059(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int playerId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((BombCollarProp)(object)target).AttachToPlayerServerRpc(playerId);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_1417853357(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int playerId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
			bool sync = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref sync, default(ForPrimitives));
			ClientRpcParams client = rpcParams.Client;
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((BombCollarProp)(object)target).AttachToPlayerClientRpc(playerId, sync, client);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_1847491476(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((BombCollarProp)(object)target).TryExplodeHeadServerRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_59171623(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((BombCollarProp)(object)target).ExplodeHeadClientRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	protected internal override string __getTypeName()
	{
		return "BombCollarProp";
	}
}
[DataContract]
public class Config : SyncedInstance<Config>
{
	[DataMember]
	public float MaxSignalDistance { get; private set; }

	[DataMember]
	public float RemoteDudChance { get; private set; }

	[DataMember]
	public bool DistanceAffectsDudChance { get; private set; }

	[DataMember]
	public bool PermanentCollar { get; private set; }

	[DataMember]
	public bool OneCollarPerPerson { get; private set; }

	[DataMember]
	public bool CanGrabOwnRemote { get; private set; }

	[DataMember]
	public int Price { get; private set; }

	[DataMember]
	public int SpawnRate { get; private set; }

	[DataMember]
	public bool CreateExplosion { get; private set; }

	[DataMember]
	public float ExplosionRadius { get; private set; }

	[DataMember]
	public bool ExplodeOutOfRange { get; private set; }

	[DataMember]
	public int ExplodeOutOfRangeTime { get; private set; }

	public Config(ConfigFile cfg)
	{
		InitInstance(this);
		MaxSignalDistance = cfg.Bind<float>("Server only", "Maximum signal distance", 20f, "Maximum distance in meters before a bomb collar's remote loses connection.").Value;
		RemoteDudChance = cfg.Bind<float>("Server only", "Remote dud chance", 33.33f, "Chance in % that using the remote will not trigger the bomb collar's explosion.").Value;
		DistanceAffectsDudChance = cfg.Bind<bool>("Server only", "Distance affects remote dud chance", false, "Whether the signal distance should weigh in on the remote dud chance, if true then the remote dud chance will gradually reach its configured value as it gets closer to the maximum signal distance.").Value;
		PermanentCollar = cfg.Bind<bool>("Server only", "Permanent collar", false, "Whether attaching a bomb collar is permanent and infinite uses even through deaths, so long as the remote exists.").Value;
		OneCollarPerPerson = cfg.Bind<bool>("Server only", "Only one collar per player", true, "Whether it is possible to attach more than one collar on a player.").Value;
		CanGrabOwnRemote = cfg.Bind<bool>("Server only", "Can grab own remote", true, "Whether it is possible for a collar wearer to grab a remote connected to their collar. If this is false and they put the collar on themselves, they will drop the remote instantly.").Value;
		Price = cfg.Bind<int>("Server only", "Price", 100, "Price of the bomb collar in the store. (Maximum discount is fixed at 80%).").Value;
		SpawnRate = cfg.Bind<int>("Server only", "Spawn rate", 40, "Set the bomb collar's spawn rate (This affects all moons, even modded ones). As it can also be purchased in the store, it'll have no value.").Value;
		CreateExplosion = cfg.Bind<bool>("Server only", "Create explosion", true, "Whether the bomb collar going off should create a small explosion (around 2.5m radius by default) that can kill other players.").Value;
		ExplosionRadius = cfg.Bind<float>("Server only", "Explosion radius", 2.5f, "The radius of the bomb collar's explosion (if it is enabled) up to 5m.").Value;
		ExplodeOutOfRange = cfg.Bind<bool>("Server only", "Collar explodes when out of range", false, "Whether the bomb collar should go off on its own if the remote is out of range.").Value;
		ExplodeOutOfRangeTime = cfg.Bind<int>("Server only", "Time (in seconds) before the collar explodes when out of range", 5, "How long does the wearer have to get back in range before the collar explodes (if 'Collar explodes when out of range' is true).").Value;
	}

	public static void RequestSync()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (!SyncedInstance<Config>.IsClient)
		{
			return;
		}
		FastBufferWriter stream = default(FastBufferWriter);
		((FastBufferWriter)(ref stream))..ctor(SyncedInstance<Config>.INT_SIZE, (Allocator)2, -1);
		try
		{
			SyncedInstance<Config>.SendMessage("BombCollar_OnRequestConfigSync", 0uL, stream);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref stream)).Dispose();
		}
	}

	public static void OnRequestSync(ulong clientId, FastBufferReader _)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		if (!SyncedInstance<Config>.IsHost)
		{
			return;
		}
		BombCollarBase.Logger.LogInfo((object)$"Config sync request received from client: {clientId}");
		byte[] array = SyncedInstance<Config>.SerializeToBytes(SyncedInstance<Config>.Instance);
		int num = array.Length;
		FastBufferWriter stream = default(FastBufferWriter);
		((FastBufferWriter)(ref stream))..ctor(num + SyncedInstance<Config>.INT_SIZE, (Allocator)2, -1);
		try
		{
			((FastBufferWriter)(ref stream)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref stream)).WriteBytesSafe(array, -1, 0);
			SyncedInstance<Config>.SendMessage("BombCollar_OnReceiveConfigSync", clientId, stream);
		}
		catch (Exception arg)
		{
			BombCollarBase.Logger.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref stream)).Dispose();
		}
	}

	public static void OnReceiveSync(ulong _, FastBufferReader reader)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<Config>.INT_SIZE))
		{
			BombCollarBase.Logger.LogError((object)"Config sync error: Could not begin reading buffer.");
			return;
		}
		int num = default(int);
		((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
		if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
		{
			BombCollarBase.Logger.LogError((object)"Config sync error: Host could not sync.");
			return;
		}
		byte[] data = new byte[num];
		((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
		SyncedInstance<Config>.SyncInstance(data);
		BombCollarBase.Logger.LogInfo((object)"Successfully synced config with host.");
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	public static void InitializeLocalPlayer()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		if (SyncedInstance<Config>.IsHost)
		{
			SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("BombCollar_OnRequestConfigSync", new HandleNamedMessageDelegate(OnRequestSync));
			SyncedInstance<Config>.Synced = true;
		}
		else
		{
			SyncedInstance<Config>.Synced = false;
			SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("BombCollar_OnReceiveConfigSync", new HandleNamedMessageDelegate(OnReceiveSync));
			RequestSync();
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
	public static void PlayerLeave()
	{
		SyncedInstance<Config>.RevertSync();
	}
}
internal class PatchModelReplacementAPI
{
	[HarmonyPatch(typeof(ModelReplacementAPI), "SetPlayerModelReplacement")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> SetModelTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected O, but got Unknown
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(BodyReplacementBase), "set_suitName", new Type[1] { typeof(string) }, (Type[])null), (string)null)
		};
		Label label = il.DefineLabel();
		CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[9]
		{
			new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(BombCollarBase), "Instance")),
			new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(BombCollarBase), "PlayerModelChangedEvent")),
			new CodeInstruction(OpCodes.Dup, (object)null),
			new CodeInstruction(OpCodes.Brtrue_S, (object)label),
			new CodeInstruction(OpCodes.Pop, (object)null),
			new CodeInstruction(OpCodes.Ret, (object)null),
			new CodeInstruction(OpCodes.Ldarg_0, (object)null),
			new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
			new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(Action<PlayerControllerB, bool>), "Invoke", (Type[])null, (Type[])null))
		};
		array2[6].labels.Add(label);
		CodeMatcher val = new CodeMatcher(instructions, il);
		val.MatchForward(false, array).Advance(1).InsertAndAdvance(array2);
		return val.InstructionEnumeration();
	}
}
[BepInPlugin("Jordo.BombCollar", "BombCollar", "1.1.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BombCollarBase : BaseUnityPlugin
{
	public static class Assets
	{
		public static string mainAssetBundleName = "bombcollar";

		public static AssetBundle MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
				foreach (string text in manifestResourceNames)
				{
					Logger.LogInfo((object)text);
				}
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}

	private const string modGUID = "Jordo.BombCollar";

	private const string modName = "BombCollar";

	private const string modVersion = "1.1.2";

	private readonly Harmony harmony = new Harmony("Jordo.BombCollar");

	public static BombCollarBase Instance;

	internal static ManualLogSource Logger;

	public List<BombCollarProp> AllBombCollars = new List<BombCollarProp>();

	public Action<int> PlayerKilledEvent;

	public bool HasModelReplacementAPI;

	public Action<PlayerControllerB, bool> PlayerModelChangedEvent;

	public static Config Config { get; internal set; }

	private void Awake()
	{
		PatchNetcode();
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		Logger = Logger.CreateLogSource("Jordo.BombCollar");
		Assets.PopulateAssets();
		Config = new Config(((BaseUnityPlugin)this).Config);
		harmony.PatchAll(typeof(Config));
		harmony.PatchAll(typeof(BombCollarBase));
		SyncedInstance<Config>.OnSync = (Action)Delegate.Combine(SyncedInstance<Config>.OnSync, new Action(OnConfigSync));
		SyncedInstance<Config>.OnRevert = (Action)Delegate.Combine(SyncedInstance<Config>.OnRevert, new Action(OnConfigRevert));
		HasModelReplacementAPI = Chainloader.PluginInfos.ContainsKey("meow.ModelReplacementAPI");
		if (HasModelReplacementAPI)
		{
			harmony.PatchAll(typeof(PatchModelReplacementAPI));
		}
		Logger.LogInfo((object)"Initialized BombCollar");
	}

	private void OnConfigSync()
	{
		UpdateBombCollarPrice();
	}

	private void OnConfigRevert()
	{
		UpdateBombCollarPrice();
	}

	public static void FixAudioMixer(AudioSource audioSource, string group = "SFX")
	{
		AudioMixer diageticMixer = SoundManager.Instance.diageticMixer;
		audioSource.outputAudioMixerGroup = diageticMixer.FindMatchingGroups(group)[0];
	}

	[HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")]
	[HarmonyPrefix]
	private static void SwitchToItemSlotPrefix(int slot, GrabbableObject fillSlotWithItem = null)
	{
		if ((Object)(object)fillSlotWithItem != (Object)null && fillSlotWithItem is BombCollarProp bombCollarProp && bombCollarProp.isRemote)
		{
			((GrabbableObject)bombCollarProp).itemProperties.itemIcon = bombCollarProp.RemoteSprite;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")]
	[HarmonyPostfix]
	private static void SwitchToItemSlotPostfix(int slot, GrabbableObject fillSlotWithItem = null)
	{
		if ((Object)(object)fillSlotWithItem != (Object)null && fillSlotWithItem is BombCollarProp bombCollarProp && bombCollarProp.isRemote)
		{
			((GrabbableObject)bombCollarProp).itemProperties.itemIcon = bombCollarProp.CollarSprite;
		}
	}

	[HarmonyPatch(typeof(GrabbableObject), "PlayDropSFX")]
	[HarmonyPrefix]
	private static void PlayDropSFXPrefix(GrabbableObject __instance)
	{
		if (__instance is BombCollarProp bombCollarProp && bombCollarProp.isRemote)
		{
			((GrabbableObject)bombCollarProp).itemProperties.dropSFX = bombCollarProp.RemoteDropClip;
		}
	}

	[HarmonyPatch(typeof(GrabbableObject), "PlayDropSFX")]
	[HarmonyPostfix]
	private static void PlayDropSFXPostfix(GrabbableObject __instance)
	{
		if (__instance is BombCollarProp bombCollarProp)
		{
			((GrabbableObject)bombCollarProp).itemProperties.dropSFX = bombCollarProp.CollarDropClip;
		}
	}

	[HarmonyPatch(typeof(GameNetworkManager), "Start")]
	[HarmonyPostfix]
	private static void AddBombCollarToNetworkManager(GameNetworkManager __instance)
	{
		List<GameObject> list = new List<GameObject>();
		list.Add(Assets.MainAssetBundle.LoadAsset<GameObject>("BombCollar.prefab"));
		foreach (GameObject item in list)
		{
			((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(item);
		}
		Logger.LogInfo((object)"Added BombCollar to Network Manager.");
	}

	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	[HarmonyPostfix]
	private static void AddBombCollarToItems(StartOfRound __instance)
	{
		List<Item> list = new List<Item>();
		list.Add(Assets.MainAssetBundle.LoadAsset<Item>("BombCollarItem"));
		foreach (Item item in list)
		{
			if (!__instance.allItemsList.itemsList.Contains(item))
			{
				__instance.allItemsList.itemsList.Add(item);
			}
		}
		Logger.LogInfo((object)"Added BombCollar to item list.");
	}

	[HarmonyPatch(typeof(Terminal), "Awake")]
	[HarmonyPrefix]
	private static void AddBombCollarToTerminal(Terminal __instance)
	{
		TerminalKeyword buyKeyword = __instance.terminalNodes.allKeywords.First((TerminalKeyword x) => x.word == "buy");
		AddItemToTerminal("BombCollarItem", "BombCollarKeyword", "BuyBombCollarNode", "ConfirmBombCollarNode");
		UpdateBombCollarPrice();
		void AddItemToTerminal(string itemName, string keywordName, string buyNodeName, string confirmNodeName)
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			Item item = Assets.MainAssetBundle.LoadAsset<Item>(itemName);
			TerminalKeyword keyword = Assets.MainAssetBundle.LoadAsset<TerminalKeyword>(keywordName);
			keyword.defaultVerb = buyKeyword;
			TerminalNode val = Assets.MainAssetBundle.LoadAsset<TerminalNode>(buyNodeName);
			TerminalNode val2 = Assets.MainAssetBundle.LoadAsset<TerminalNode>(confirmNodeName);
			List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
			if (!list.Contains(keyword))
			{
				list.Add(keyword);
			}
			__instance.terminalNodes.allKeywords = list.ToArray();
			List<CompatibleNoun> list2 = buyKeyword.compatibleNouns.ToList();
			if (((IEnumerable<CompatibleNoun>)list2).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun x) => (Object)(object)x.noun == (Object)(object)keyword)) == null)
			{
				list2.Add(new CompatibleNoun
				{
					noun = keyword,
					result = val
				});
			}
			buyKeyword.compatibleNouns = list2.ToArray();
			List<Item> list3 = __instance.buyableItemsList.ToList();
			if (!list3.Contains(item))
			{
				list3.Add(item);
			}
			__instance.buyableItemsList = list3.ToArray();
			val.buyItemIndex = (val2.buyItemIndex = __instance.buyableItemsList.Length - 1);
		}
	}

	private static void UpdateBombCollarPrice()
	{
		TerminalKeyword keyword = Assets.MainAssetBundle.LoadAsset<TerminalKeyword>("BombCollarKeyword");
		Terminal val = Object.FindObjectOfType<Terminal>();
		Item val2 = val.buyableItemsList.First((Item x) => x.itemName == "Bomb collar");
		val2.creditsWorth = SyncedInstance<Config>.Instance.Price;
		TerminalKeyword val3 = val.terminalNodes.allKeywords.First((TerminalKeyword x) => x.word == "buy");
		CompatibleNoun val4 = val3.compatibleNouns.First((CompatibleNoun x) => (Object)(object)x.noun == (Object)(object)keyword);
		val4.result.itemCost = SyncedInstance<Config>.Instance.Price;
		val4.result.terminalOptions[0].result.itemCost = SyncedInstance<Config>.Instance.Price;
	}

	[HarmonyPatch(typeof(RoundManager), "Start")]
	[HarmonyPostfix]
	private static void AddBombCollarToAllLevels(RoundManager __instance)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		if (SyncedInstance<Config>.Instance.SpawnRate == 0)
		{
			return;
		}
		Item item = Assets.MainAssetBundle.LoadAsset<Item>("BombCollarItem");
		SpawnableItemWithRarity val = new SpawnableItemWithRarity();
		val.rarity = Config.SpawnRate;
		val.spawnableItem = item;
		SelectableLevel[] levels = StartOfRound.Instance.levels;
		foreach (SelectableLevel val2 in levels)
		{
			if (!val2.spawnableScrap.Any((SpawnableItemWithRarity x) => (Object)(object)x.spawnableItem == (Object)(object)item))
			{
				val2.spawnableScrap.Add(val);
			}
		}
		Logger.LogInfo((object)"Added BombCollar to all levels.");
	}

	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerClientRpc")]
	[HarmonyPostfix]
	private static void AddPlayerKilledEvent(int playerId)
	{
		Instance.PlayerKilledEvent?.Invoke(playerId);
	}

	[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitForPlayer")]
	[HarmonyPostfix]
	private static void PlayerModelChanged(PlayerControllerB player)
	{
		Instance.PlayerModelChangedEvent?.Invoke(player, arg2: false);
	}

	private void PatchNetcode()
	{
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		Type[] array = types;
		foreach (Type type in array)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
			MethodInfo[] array2 = methods;
			foreach (MethodInfo methodInfo in array2)
			{
				object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
				if (customAttributes.Length != 0)
				{
					methodInfo.Invoke(null, null);
				}
			}
		}
	}
}
[Serializable]
public class SyncedInstance<T>
{
	[NonSerialized]
	private static readonly DataContractSerializer Serializer = new DataContractSerializer(typeof(T));

	[NonSerialized]
	protected static int INT_SIZE = 4;

	[NonSerialized]
	private static int MAX_BUFFER_SIZE;

	internal static bool Synced;

	public static Action OnSync;

	public static Action OnRevert;

	internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

	internal static bool IsClient => NetworkManager.Singleton.IsClient;

	internal static bool IsHost => NetworkManager.Singleton.IsHost;

	public static T Default { get; private set; }

	public static T Instance { get; private set; }

	protected void InitInstance(T instance, int maxSize = 1300)
	{
		Default = instance;
		Instance = instance;
		INT_SIZE = 4;
		if (maxSize < 1300)
		{
			MAX_BUFFER_SIZE = maxSize;
		}
	}

	internal static void SyncInstance(byte[] data)
	{
		Instance = DeserializeFromBytes(data);
		Synced = true;
		OnSync?.Invoke();
	}

	internal static void RevertSync()
	{
		Instance = Default;
		Synced = false;
		OnRevert?.Invoke();
	}

	public static byte[] SerializeToBytes(T val)
	{
		using MemoryStream memoryStream = new MemoryStream();
		try
		{
			((XmlObjectSerializer)Serializer).WriteObject((Stream)memoryStream, (object)val);
			return memoryStream.ToArray();
		}
		catch (Exception arg)
		{
			BombCollarBase.Logger.LogError((object)$"Error serializing instance: {arg}");
			return null;
		}
	}

	public static T DeserializeFromBytes(byte[] data)
	{
		using MemoryStream memoryStream = new MemoryStream(data);
		try
		{
			return (T)((XmlObjectSerializer)Serializer).ReadObject((Stream)memoryStream);
		}
		catch (Exception arg)
		{
			BombCollarBase.Logger.LogError((object)$"Error deserializing instance: {arg}");
			return default(T);
		}
	}

	internal static void SendMessage(string label, ulong clientId, FastBufferWriter stream)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		bool flag = ((FastBufferWriter)(ref stream)).Capacity > MAX_BUFFER_SIZE;
		if (flag)
		{
			BombCollarBase.Logger.LogDebug((object)($"Size of stream ({((FastBufferWriter)(ref stream)).Capacity}) was past the max buffer size.\n" + "Config instance will be sent in fragments to avoid overflowing the buffer."));
		}
		NetworkDelivery val = (NetworkDelivery)(flag ? 4 : 2);
		MessageManager.SendNamedMessage(label, clientId, stream, val);
	}
}