Decompiled source of DrunkerCompany v1.0.2

DrunkerCompany.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DrunkerCompany.Buffs;
using DrunkerCompany.Decor;
using DrunkerCompany.Enemies;
using DrunkerCompany.Items;
using DrunkerCompany.Network;
using DrunkerCompany.Revive;
using DrunkerCompany.State;
using DrunkerCompany.Suits;
using DrunkerCompany.UI;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("DrunkerCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Team-vs-team drinking-game competition mod for Lethal Company.")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("DrunkerCompany")]
[assembly: AssemblyTitle("DrunkerCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 DrunkerCompany
{
	public static class Config
	{
		public static ConfigEntry<int> MaskedCount;

		public static ConfigEntry<bool> PosterEnabled;

		public static ConfigEntry<int> WalkieCount;

		public static ConfigEntry<bool> SpeedBoostEnabled;

		public static ConfigEntry<int> SpeedBoostCost;

		public static ConfigEntry<float> SpeedBoostMultiplier;

		public static ConfigEntry<float> SpeedBoostDuration;

		public static ConfigEntry<bool> GroupReviveEnabled;

		public static ConfigEntry<int> GroupReviveCost;

		public static void Init(ConfigFile cfg)
		{
			MaskedCount = cfg.Bind<int>("General", "MaskedEnemyCount", 1, "How many Masked enemies spawn on the surface when the Captain dies.");
			PosterEnabled = cfg.Bind<bool>("General", "ShipPoster", true, "Show the custom drinking-rules poster on the ship wall.");
			WalkieCount = cfg.Bind<int>("General", "WalkieCount", 2, "How many walkie-talkies are dropped by the terminal at the start of each round.");
			SpeedBoostEnabled = cfg.Bind<bool>("CaptainBuffs", "SpeedBoostEnabled", true, "Allow the Captain to buy a crew-wide speed boost with the terminal 'boost' command.");
			SpeedBoostCost = cfg.Bind<int>("CaptainBuffs", "SpeedBoostCost", 15, "Credit cost of the speed boost.");
			SpeedBoostMultiplier = cfg.Bind<float>("CaptainBuffs", "SpeedBoostMultiplier", 1.5f, "Movement-speed multiplier applied to every player during the boost.");
			SpeedBoostDuration = cfg.Bind<float>("CaptainBuffs", "SpeedBoostDuration", 30f, "How long the speed boost lasts, in seconds.");
			GroupReviveEnabled = cfg.Bind<bool>("CaptainBuffs", "GroupReviveEnabled", true, "Allow the Captain to buy a one-time group revive with the terminal 'revive' command.");
			GroupReviveCost = cfg.Bind<int>("CaptainBuffs", "GroupReviveCost", 35, "Credit cost of the one-time group revive.");
		}
	}
	[BepInPlugin("DrunkerCompany", "DrunkerCompany", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Config.Init(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("DrunkerCompany");
			int num = 0;
			Type[] types = typeof(Plugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				try
				{
					val.CreateClassProcessor(type).Patch();
				}
				catch (Exception arg)
				{
					num++;
					Logger.LogError((object)$"Failed to apply patch class {type.FullName}: {arg}");
				}
			}
			if (num > 0)
			{
				Logger.LogWarning((object)string.Format("Plugin {0} loaded with {1} failed patch class(es) — see errors above.", "DrunkerCompany", num));
			}
			else
			{
				Logger.LogInfo((object)"Plugin DrunkerCompany loaded!");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DrunkerCompany";

		public const string PLUGIN_NAME = "DrunkerCompany";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace DrunkerCompany.UI
{
	public static class ScoreBoard
	{
		public static string Build()
		{
			if (RoundState.PlayerTeams.Count == 0)
			{
				return "DRUNKER COMPANY\n\nNo round data yet. Teams appear once a round has begun.\n";
			}
			Dictionary<ulong, string> dictionary = new Dictionary<ulong, string>();
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if ((Object)(object)val != (Object)null && val.isPlayerControlled)
					{
						dictionary[val.playerClientId] = (string.IsNullOrEmpty(val.playerUsername) ? $"Player {val.playerClientId}" : val.playerUsername);
					}
				}
			}
			Dictionary<int, List<ulong>> dictionary2 = new Dictionary<int, List<ulong>>();
			int num = 0;
			foreach (KeyValuePair<ulong, int> playerTeam in RoundState.PlayerTeams)
			{
				if (!dictionary2.TryGetValue(playerTeam.Value, out var value))
				{
					value = new List<ulong>();
					dictionary2[playerTeam.Value] = value;
				}
				value.Add(playerTeam.Key);
				if (playerTeam.Value > num)
				{
					num = playerTeam.Value;
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("DRUNKER COMPANY - TEAMS");
			stringBuilder.AppendLine();
			for (int j = 0; j <= num; j++)
			{
				if (!dictionary2.TryGetValue(j, out var value2))
				{
					continue;
				}
				string arg = RoundState.TeamName(j);
				int num2 = ((j < RoundState.TeamScrapScores.Length) ? RoundState.TeamScrapScores[j] : 0);
				stringBuilder.AppendLine($"{arg}  -  ${num2} collected");
				foreach (ulong item in value2)
				{
					string value3;
					string text = (dictionary.TryGetValue(item, out value3) ? value3 : $"Player {item}");
					stringBuilder.AppendLine("   " + text);
				}
				stringBuilder.AppendLine();
			}
			return stringBuilder.ToString();
		}
	}
	public class TeamHUD : MonoBehaviour
	{
		private static TeamHUD? _instance;

		private TextMeshProUGUI? _label;

		public static void Refresh()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				Create();
			}
			ulong key = (ulong)(((long?)GameNetworkManager.Instance?.localPlayerController?.playerClientId) ?? (-1L));
			if (!RoundState.PlayerTeams.TryGetValue(key, out var value))
			{
				return;
			}
			string text = RoundState.TeamName(value);
			Color color = RoundState.TeamColor(value);
			if ((Object)(object)_instance._label != (Object)null)
			{
				if ((Object)(object)((TMP_Text)_instance._label).font == (Object)null)
				{
					TryBorrowFont(_instance._label);
				}
				((TMP_Text)_instance._label).text = "[ " + text + " ]";
				((Graphic)_instance._label).color = color;
			}
			((Component)_instance).gameObject.SetActive(true);
		}

		public static void Hide()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				((Component)_instance).gameObject.SetActive(false);
			}
		}

		private static void Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DrunkerTeamHUD");
			Object.DontDestroyOnLoad((Object)(object)val);
			_instance = val.AddComponent<TeamHUD>();
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 50;
			CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			val.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("Label");
			val2.transform.SetParent(val.transform, false);
			_instance._label = val2.AddComponent<TextMeshProUGUI>();
			TryBorrowFont(_instance._label);
			((TMP_Text)_instance._label).fontSize = 22f;
			((TMP_Text)_instance._label).fontStyle = (FontStyles)1;
			((TMP_Text)_instance._label).alignment = (TextAlignmentOptions)1025;
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.zero;
			component.pivot = Vector2.zero;
			component.anchoredPosition = new Vector2(20f, 20f);
			component.sizeDelta = new Vector2(320f, 44f);
			val.SetActive(false);
		}

		private static void TryBorrowFont(TextMeshProUGUI label)
		{
			TextMeshProUGUI val = Object.FindObjectOfType<TextMeshProUGUI>();
			if ((Object)(object)val != (Object)null && (Object)(object)((TMP_Text)val).font != (Object)null)
			{
				((TMP_Text)label).font = ((TMP_Text)val).font;
			}
		}
	}
}
namespace DrunkerCompany.Suits
{
	public static class SuitManager
	{
		internal static bool ModApplyingNow = false;

		private static readonly string[][] ColorKeywords = new string[8][]
		{
			new string[1] { "red" },
			new string[1] { "blue" },
			new string[1] { "dandelion" },
			new string[1] { "neon green" },
			new string[1] { "purple" },
			new string[1] { "white" },
			new string[1] { "pink" },
			new string[1] { "orange" }
		};

		private static int[] _suitIds = Array.Empty<int>();

		private static bool _suitsScanned;

		public static void FindSuits()
		{
			if (_suitsScanned)
			{
				return;
			}
			List<UnlockableItem> list = StartOfRound.Instance?.unlockablesList?.unlockables;
			if (list == null || list.Count == 0)
			{
				_suitIds = Array.Empty<int>();
				return;
			}
			_suitIds = new int[ColorKeywords.Length];
			for (int i = 0; i < _suitIds.Length; i++)
			{
				_suitIds[i] = -1;
			}
			for (int j = 0; j < list.Count; j++)
			{
				UnlockableItem val = list[j];
				if (val.unlockableType != 0 && (Object)(object)val.suitMaterial == (Object)null)
				{
					continue;
				}
				string text = val.unlockableName.ToLower().Trim();
				for (int k = 0; k < ColorKeywords.Length; k++)
				{
					if (_suitIds[k] >= 0)
					{
						continue;
					}
					string[] array = ColorKeywords[k];
					foreach (string value in array)
					{
						if (text.Contains(value))
						{
							_suitIds[k] = j;
							break;
						}
					}
				}
			}
			_suitsScanned = true;
			for (int m = 0; m < ColorKeywords.Length; m++)
			{
				Plugin.Logger.LogInfo((object)$"[SuitManager] Team {m} → suit index {_suitIds[m]} (keyword '{ColorKeywords[m][0]}')");
			}
		}

		public static void ApplyAll(Dictionary<ulong, int> playerTeams)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			FindSuits();
			ModApplyingNow = true;
			try
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if (!((Object)(object)val == (Object)null) && val.isPlayerControlled && playerTeams.TryGetValue(val.playerClientId, out var value))
					{
						int num = ((value < _suitIds.Length) ? _suitIds[value] : (-1));
						if (num >= 0)
						{
							Plugin.Logger.LogDebug((object)$"[SuitManager] {val.playerUsername} (team {value}) → suit[{num}]");
							UnlockableSuit.SwitchSuitForPlayer(val, num, false);
						}
						else
						{
							Plugin.Logger.LogWarning((object)($"[SuitManager] No suit found for team {value} ('{ColorKeywords[value][0]}'); " + val.playerUsername + " keeps their current suit. Install a MoreSuits pack with this colour."));
						}
					}
				}
			}
			finally
			{
				ModApplyingNow = false;
			}
		}
	}
}
namespace DrunkerCompany.State
{
	public static class RoundState
	{
		public static ulong CaptainClientId = ulong.MaxValue;

		public static Dictionary<ulong, int> PlayerTeams = new Dictionary<ulong, int>();

		public static int[] TeamScrapScores = Array.Empty<int>();

		public static HashSet<ulong> DeadPlayers = new HashSet<ulong>();

		public static HashSet<ulong> CountedScrap = new HashSet<ulong>();

		public static HashSet<ulong> RevivedPlayers = new HashSet<ulong>();

		public static HashSet<ulong> DiedOnShip = new HashSet<ulong>();

		public static HashSet<ulong> OurMaskedNetIds = new HashSet<ulong>();

		public static bool FirstDeathAnnounced;

		public static bool CaptainDead;

		public static bool IsRoundActive;

		public static bool GroupReviveUsed;

		public static readonly Color[] TeamColors = (Color[])(object)new Color[8]
		{
			new Color(0.9f, 0.15f, 0.15f),
			new Color(0.25f, 0.55f, 1f),
			new Color(1f, 0.85f, 0.1f),
			new Color(0.3f, 1f, 0.2f),
			new Color(0.6f, 0.2f, 0.85f),
			Color.white,
			new Color(1f, 0.45f, 0.7f),
			new Color(1f, 0.5f, 0.1f)
		};

		public static readonly string[] TeamNames = new string[8] { "Captain", "Blue Team", "Yellow Team", "Green Team", "Purple Team", "White Team", "Pink Team", "Orange Team" };

		private static readonly string[][] ColorWords = new string[8][]
		{
			new string[2] { "red", "captain" },
			new string[1] { "blue" },
			new string[2] { "yellow", "gold" },
			new string[2] { "green", "olive" },
			new string[2] { "purple", "violet" },
			new string[1] { "white" },
			new string[2] { "pink", "rose" },
			new string[1] { "orange" }
		};

		public static void Reset()
		{
			CaptainClientId = ulong.MaxValue;
			PlayerTeams.Clear();
			TeamScrapScores = Array.Empty<int>();
			DeadPlayers.Clear();
			CountedScrap.Clear();
			RevivedPlayers.Clear();
			DiedOnShip.Clear();
			OurMaskedNetIds.Clear();
			FirstDeathAnnounced = false;
			CaptainDead = false;
			IsRoundActive = false;
			GroupReviveUsed = false;
		}

		public static Color GetTeamColor(ulong clientId)
		{
			//IL_0016: 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)
			if (!PlayerTeams.TryGetValue(clientId, out var value))
			{
				return Color.white;
			}
			return TeamColor(value);
		}

		public static string GetTeamName(ulong clientId)
		{
			if (!PlayerTeams.TryGetValue(clientId, out var value))
			{
				return string.Empty;
			}
			return TeamName(value);
		}

		public static string TeamName(int team)
		{
			if (team < 0 || team >= TeamNames.Length)
			{
				return $"Team {team}";
			}
			return TeamNames[team];
		}

		public static Color TeamColor(int team)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (team < 0 || team >= TeamColors.Length)
			{
				return Color.white;
			}
			return TeamColors[team];
		}

		public static int ParseTeam(string word)
		{
			if (string.IsNullOrEmpty(word))
			{
				return -1;
			}
			word = word.ToLower();
			for (int i = 0; i < ColorWords.Length; i++)
			{
				string[] array = ColorWords[i];
				for (int j = 0; j < array.Length; j++)
				{
					if (array[j] == word)
					{
						return i;
					}
				}
			}
			return -1;
		}

		public static string TeamColorWord(int team)
		{
			if (team < 0 || team >= ColorWords.Length)
			{
				return $"team{team}";
			}
			return ColorWords[team][0];
		}

		public static bool TeamHasPlayers(int team)
		{
			foreach (KeyValuePair<ulong, int> playerTeam in PlayerTeams)
			{
				if (playerTeam.Value == team)
				{
					return true;
				}
			}
			return false;
		}

		public static bool TeamFullyDead(int team)
		{
			int num = 0;
			int num2 = 0;
			foreach (KeyValuePair<ulong, int> playerTeam in PlayerTeams)
			{
				if (playerTeam.Value == team)
				{
					num++;
					if (DeadPlayers.Contains(playerTeam.Key))
					{
						num2++;
					}
				}
			}
			if (num > 0)
			{
				return num2 == num;
			}
			return false;
		}

		public static string ActiveTeamColors()
		{
			SortedSet<int> sortedSet = new SortedSet<int>();
			foreach (KeyValuePair<ulong, int> playerTeam in PlayerTeams)
			{
				sortedSet.Add(playerTeam.Value);
			}
			List<string> list = new List<string>();
			foreach (int item in sortedSet)
			{
				list.Add(TeamColorWord(item));
			}
			return string.Join(", ", list);
		}

		public static void GetBestWorst(out int bestTeam, out int bestScrap, out int worstTeam, out int worstScrap)
		{
			bestTeam = -1;
			bestScrap = 0;
			for (int i = 0; i < TeamScrapScores.Length; i++)
			{
				if (TeamScrapScores[i] > bestScrap)
				{
					bestScrap = TeamScrapScores[i];
					bestTeam = i;
				}
			}
			HashSet<int> hashSet = new HashSet<int>();
			foreach (KeyValuePair<ulong, int> playerTeam in PlayerTeams)
			{
				if (playerTeam.Value != 0)
				{
					hashSet.Add(playerTeam.Value);
				}
			}
			worstTeam = -1;
			int num = int.MaxValue;
			foreach (int item in hashSet)
			{
				int num2 = ((item < TeamScrapScores.Length) ? TeamScrapScores[item] : 0);
				if (num2 < num)
				{
					num = num2;
					worstTeam = item;
				}
			}
			worstScrap = ((worstTeam >= 0) ? num : 0);
		}
	}
}
namespace DrunkerCompany.Revive
{
	public static class ReviveManager
	{
		public static void RevivePlayer(PlayerControllerB player, bool recallBodyToShip = false)
		{
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			bool isPlayerDead = player.isPlayerDead;
			player.isPlayerDead = false;
			player.isPlayerControlled = true;
			player.isInElevator = true;
			player.isInHangarShipRoom = true;
			player.isInsideFactory = false;
			player.parentedToElevatorLastFrame = false;
			player.setPositionOfDeadPlayer = false;
			player.isClimbingLadder = false;
			player.clampLooking = false;
			player.inVehicleAnimation = false;
			player.disableMoveInput = false;
			player.disableLookInput = false;
			player.disableInteract = false;
			player.health = 100;
			player.criticallyInjured = false;
			player.hasBeenCriticallyInjured = false;
			player.bleedingHeavily = false;
			player.activatingItem = false;
			player.twoHanded = false;
			player.isHoldingObject = false;
			player.inShockingMinigame = false;
			player.inSpecialInteractAnimation = false;
			player.freeRotationInInteractAnimation = false;
			player.disableSyncInAnimation = false;
			player.inAnimationWithEnemy = null;
			player.holdingWalkieTalkie = false;
			player.speakingToWalkieTalkie = false;
			player.isSinking = false;
			player.isUnderwater = false;
			player.sinkingValue = 0f;
			player.hinderedMultiplier = 1f;
			player.isMovementHindered = 0;
			player.sourcesCausingSinking = 0;
			player.carryWeight = 1f;
			player.overrideGameOverSpectatePivot = null;
			StartOfRound instance = StartOfRound.Instance;
			HUDManager instance2 = HUDManager.Instance;
			try
			{
				Vector3 val = (((Object)(object)instance != (Object)null) ? instance.GetPlayerSpawnPosition((int)player.playerClientId, false) : ((Component)player).transform.position);
				if (recallBodyToShip && (Object)(object)player.deadBody != (Object)null)
				{
					player.deadBody.SetRagdollPositionSafely(val, true);
				}
				player.TeleportPlayer(val, false, 0f, false, true);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"[Revive] teleport step failed: {arg}");
			}
			try
			{
				player.ResetPlayerBloodObjects(isPlayerDead);
				if ((Object)(object)player.gameplayCamera != (Object)null)
				{
					Vector3 localEulerAngles = ((Component)player.gameplayCamera).transform.localEulerAngles;
					((Component)player.gameplayCamera).transform.localEulerAngles = new Vector3(localEulerAngles.x, 0f, localEulerAngles.z);
				}
				player.ResetZAndXRotation();
				if ((Object)(object)player.thisController != (Object)null)
				{
					((Collider)player.thisController).enabled = true;
				}
				if ((Object)(object)player.nightVisionRadar != (Object)null)
				{
					((Behaviour)player.nightVisionRadar).enabled = false;
				}
				player.DisablePlayerModel(((Component)player).gameObject, true, true);
				if ((Object)(object)player.helmetLight != (Object)null)
				{
					((Behaviour)player.helmetLight).enabled = false;
				}
				player.Crouch(false);
				if ((Object)(object)player.playerBodyAnimator != (Object)null)
				{
					player.playerBodyAnimator.SetBool("Limp", false);
				}
				if ((Object)(object)player.statusEffectAudio != (Object)null)
				{
					player.statusEffectAudio.Stop();
				}
				if ((Object)(object)player.mapRadarDotAnimator != (Object)null)
				{
					player.mapRadarDotAnimator.SetBool("dead", false);
				}
				player.externalForceAutoFade = Vector3.zero;
			}
			catch (Exception arg2)
			{
				Plugin.Logger.LogError((object)$"[Revive] body step failed: {arg2}");
			}
			if (((NetworkBehaviour)player).IsOwner)
			{
				try
				{
					if ((Object)(object)instance2 != (Object)null)
					{
						instance2.SetCracksOnVisor(100f);
						if ((Object)(object)instance2.gasHelmetAnimator != (Object)null)
						{
							instance2.gasHelmetAnimator.SetBool("gasEmitting", false);
						}
						instance2.RemoveSpectateUI();
						if ((Object)(object)instance2.gameOverAnimator != (Object)null)
						{
							instance2.gameOverAnimator.SetTrigger("revive");
						}
						instance2.UpdateHealthUI(100, false);
						if ((Object)(object)instance2.audioListenerLowPass != (Object)null)
						{
							((Behaviour)instance2.audioListenerLowPass).enabled = false;
						}
						instance2.HideHUD(false);
					}
					player.hasBegunSpectating = false;
					player.spectatedPlayerScript = null;
					if (instance != null)
					{
						instance.SetSpectateCameraToGameOverMode(false, player);
					}
				}
				catch (Exception arg3)
				{
					Plugin.Logger.LogError((object)$"[Revive] owner UI step failed: {arg3}");
				}
			}
			try
			{
				if ((Object)(object)player.deadBody != (Object)null)
				{
					if ((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsHost && (Object)(object)player.deadBody.grabBodyObject != (Object)null)
					{
						NetworkObject component = ((Component)player.deadBody.grabBodyObject).GetComponent<NetworkObject>();
						if ((Object)(object)component != (Object)null && component.IsSpawned)
						{
							component.Despawn(true);
						}
					}
					player.deadBody.DeactivateBody(false);
					player.deadBody = null;
				}
			}
			catch (Exception arg4)
			{
				Plugin.Logger.LogError((object)$"[Revive] body despawn failed: {arg4}");
			}
			if ((Object)(object)instance != (Object)null)
			{
				int num = 0;
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if ((Object)(object)val2 != (Object)null && val2.isPlayerControlled && !val2.isPlayerDead)
					{
						num++;
					}
				}
				instance.livingPlayers = num;
				instance.allPlayersDead = false;
			}
			PlayerControllerB val3 = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val3 != (Object)null && val3.isPlayerDead && val3.playerClientId != player.playerClientId)
			{
				try
				{
					if (instance2 != null)
					{
						instance2.RemoveSpectateUI();
					}
				}
				catch (Exception arg5)
				{
					Plugin.Logger.LogError((object)$"[Revive] spectate UI reset failed: {arg5}");
				}
			}
			if (instance2 != null)
			{
				instance2.UpdateBoxesSpectateUI();
			}
		}
	}
}
namespace DrunkerCompany.Patches
{
	[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
	internal static class EndGameStatsPatch
	{
		[HarmonyPostfix]
		private static void Postfix(HUDManager __instance)
		{
			if (RoundState.PlayerTeams.Count == 0)
			{
				return;
			}
			EndOfGameStatUIElements statsUIElements = __instance.statsUIElements;
			if (statsUIElements?.playerNamesText == null)
			{
				return;
			}
			ClearReport(statsUIElements);
			RoundState.GetBestWorst(out var bestTeam, out var bestScrap, out var worstTeam, out var worstScrap);
			if (bestTeam < 0 || bestScrap <= 0)
			{
				SetName(statsUIElements, 0, "No scrap was collected this round.");
				return;
			}
			SetRow(statsUIElements, 0, "MOST SCRAP", bestTeam, bestScrap);
			if (worstTeam >= 0 && worstTeam != bestTeam)
			{
				SetRow(statsUIElements, 1, "LEAST SCRAP", worstTeam, worstScrap);
			}
		}

		private static void SetRow(EndOfGameStatUIElements ui, int row, string label, int team, int scrap)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			SetName(ui, row, label);
			string arg = ColorUtility.ToHtmlStringRGB(RoundState.TeamColor(team));
			if (ui.playerNotesText != null && row < ui.playerNotesText.Length && (Object)(object)ui.playerNotesText[row] != (Object)null)
			{
				TextMeshProUGUI obj = ui.playerNotesText[row];
				((TMP_Text)obj).alignment = (TextAlignmentOptions)257;
				((TMP_Text)obj).enableWordWrapping = false;
				((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
				((TMP_Text)obj).text = $"<color=#{arg}>{RoundState.TeamName(team)}</color>  ${scrap}";
				ApplyOutline(obj);
			}
		}

		private static void SetName(EndOfGameStatUIElements ui, int row, string text)
		{
			if (row < ui.playerNamesText.Length && (Object)(object)ui.playerNamesText[row] != (Object)null)
			{
				((TMP_Text)ui.playerNamesText[row]).text = text;
				ApplyOutline(ui.playerNamesText[row]);
			}
		}

		private static void ApplyOutline(TextMeshProUGUI t)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)t == (Object)null))
			{
				Material fontMaterial = ((TMP_Text)t).fontMaterial;
				fontMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, 0.2f);
				fontMaterial.SetColor(ShaderUtilities.ID_OutlineColor, Color.black);
			}
		}

		private static void ClearReport(EndOfGameStatUIElements ui)
		{
			if (ui.playerNamesText != null)
			{
				TextMeshProUGUI[] playerNamesText = ui.playerNamesText;
				for (int i = 0; i < playerNamesText.Length; i++)
				{
					Blank(playerNamesText[i]);
				}
			}
			if (ui.playerNotesText != null)
			{
				TextMeshProUGUI[] playerNamesText = ui.playerNotesText;
				for (int i = 0; i < playerNamesText.Length; i++)
				{
					Blank(playerNamesText[i]);
				}
			}
			if (ui.playerStates != null)
			{
				Image[] playerStates = ui.playerStates;
				foreach (Image val in playerStates)
				{
					if ((Object)(object)val != (Object)null)
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
			Blank(ui.penaltyAddition);
			Blank(ui.penaltyTotal);
			Blank(ui.challengeCollectedText);
			Blank(ui.challengeRankText);
			if ((Object)(object)ui.allPlayersDeadOverlay != (Object)null)
			{
				((Behaviour)ui.allPlayersDeadOverlay).enabled = false;
			}
		}

		private static void Blank(TextMeshProUGUI t)
		{
			if ((Object)(object)t != (Object)null)
			{
				((TMP_Text)t).text = "";
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager), "ApplyPenalty")]
	internal static class NoCasualtyPenaltyPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return RoundState.PlayerTeams.Count == 0;
		}
	}
	[HarmonyPatch(typeof(Animator), "SetTrigger", new Type[] { typeof(string) })]
	internal static class NoPenaltyBoxPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(Animator __instance, string name)
		{
			if (RoundState.PlayerTeams.Count == 0)
			{
				return true;
			}
			HUDManager instance = HUDManager.Instance;
			if (name == "displayPenalty" && (Object)(object)instance != (Object)null && (Object)(object)__instance == (Object)(object)instance.endgameStatsAnimator)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
	internal static class FreeTravelPatch
	{
		[HarmonyPrefix]
		private static void Prefix(TerminalNode node)
		{
			if ((Object)(object)node != (Object)null && node.buyRerouteToMoon != -1)
			{
				node.itemCost = 0;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Start")]
	internal static class GameNetworkManagerStartPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			DrunkerMessages.Register();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	internal static class StartOfRoundAwakePatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			DrunkerMessages.Reset();
			DrunkerMessages.Register();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal static class StartOfRoundStartPosterPatch
	{
		[HarmonyPostfix]
		private static void Postfix(StartOfRound __instance)
		{
			Plugin.Logger.LogInfo((object)"[Poster] StartOfRound.Start postfix fired — scheduling poster spawn.");
			((MonoBehaviour)__instance).StartCoroutine(PosterSpawner.SpawnSoon());
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "StartGame")]
	internal static class StartOfRoundStartGamePatch
	{
		[HarmonyPostfix]
		private static void Postfix(StartOfRound __instance)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton == null || !singleton.IsHost)
			{
				return;
			}
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val != (Object)null && val.isPlayerControlled)
				{
					list.Add(val);
				}
			}
			if (list.Count != 0)
			{
				for (int num = list.Count - 1; num > 0; num--)
				{
					int num2 = Random.Range(0, num + 1);
					List<PlayerControllerB> list2 = list;
					int i = num;
					int index = num2;
					PlayerControllerB value = list[num2];
					PlayerControllerB value2 = list[num];
					list2[i] = value;
					list[index] = value2;
				}
				ulong[] array = new ulong[list.Count];
				int[] array2 = new int[list.Count];
				array[0] = list[0].playerClientId;
				array2[0] = 0;
				for (int j = 1; j < list.Count; j++)
				{
					array[j] = list[j].playerClientId;
					array2[j] = (j - 1) / 2 + 1;
				}
				int num3 = list.Count - 1;
				if (num3 >= 3 && num3 % 2 == 1)
				{
					array2[list.Count - 1]--;
				}
				DrunkerMessages.BroadcastSyncRound(list[0].playerClientId, array, array2);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
	internal static class StartOfRoundShipLeavePatch
	{
		[HarmonyPostfix]
		private static void Postfix(StartOfRound __instance)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton != null && singleton.IsHost && RoundState.IsRoundActive)
			{
				DrunkerMessages.BroadcastRoundEnd();
			}
		}
	}
	[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
	internal static class MaskedTargetablePatch
	{
		[HarmonyPrefix]
		private static void Prefix(EnemyAI __instance, ref bool overrideInsideFactoryCheck)
		{
			if (!overrideInsideFactoryCheck && __instance is MaskedPlayerEnemy && !((Object)(object)((NetworkBehaviour)__instance).NetworkObject == (Object)null) && RoundState.OurMaskedNetIds.Contains(((NetworkBehaviour)__instance).NetworkObjectId))
			{
				overrideInsideFactoryCheck = true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	internal static class PlayerDeathPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerControllerB __instance)
		{
			if (RoundState.IsRoundActive && !__instance.isPlayerDead)
			{
				DrunkerMessages.ReportDeath(__instance.playerClientId, __instance.playerUsername, __instance.isInHangarShipRoom);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")]
	internal static class ReviveBodyPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerControllerB __instance, out ulong __state)
		{
			__state = ulong.MaxValue;
			if (!RoundState.IsRoundActive)
			{
				return;
			}
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || __instance.playerClientId != val.playerClientId || !__instance.isInHangarShipRoom)
			{
				return;
			}
			GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
			RagdollGrabbableObject val2 = (RagdollGrabbableObject)(object)((currentlyHeldObjectServer is RagdollGrabbableObject) ? currentlyHeldObjectServer : null);
			if (val2 != null)
			{
				PlayerControllerB val3 = val2.ragdoll?.playerScript;
				if (!((Object)(object)val3 == (Object)null) && RoundState.DeadPlayers.Contains(val3.playerClientId))
				{
					__state = val3.playerClientId;
				}
			}
		}

		[HarmonyPostfix]
		private static void Postfix(ulong __state)
		{
			if (__state != ulong.MaxValue)
			{
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if (!((Object)(object)val == (Object)null))
				{
					DrunkerMessages.RequestRevive(__state, val.playerClientId);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")]
	internal static class ShipScrapPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerControllerB __instance)
		{
			if (!RoundState.IsRoundActive)
			{
				return;
			}
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null) && __instance.playerClientId == val.playerClientId && __instance.isInHangarShipRoom)
			{
				GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
				if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && !((Object)(object)currentlyHeldObjectServer.itemProperties == (Object)null) && currentlyHeldObjectServer.itemProperties.isScrap && !((Object)(object)((NetworkBehaviour)currentlyHeldObjectServer).NetworkObject == (Object)null) && ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObject.IsSpawned && RoundState.PlayerTeams.TryGetValue(val.playerClientId, out var value))
				{
					DrunkerMessages.ReportScrapDeposit(value, currentlyHeldObjectServer.scrapValue, ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObjectId);
				}
			}
		}
	}
	[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitToThis")]
	internal static class SuitChangePatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			if (!RoundState.IsRoundActive)
			{
				return true;
			}
			if (SuitManager.ModApplyingNow)
			{
				return true;
			}
			HUDManager.Instance.DisplayTip("Suit Locked", "You cannot change suits while a round is in progress.", true, false, "LC_Tip1");
			return false;
		}
	}
	internal static class ShopRestriction
	{
		public static bool IsCreditPurchase(TerminalNode node)
		{
			if ((Object)(object)node != (Object)null)
			{
				if (node.buyItemIndex == -1 && node.buyVehicleIndex == -1)
				{
					return node.shipUnlockableID != -1;
				}
				return true;
			}
			return false;
		}

		public static bool LocalPlayerIsCaptain()
		{
			ulong key = (ulong)(((long?)GameNetworkManager.Instance?.localPlayerController?.playerClientId) ?? (-1L));
			if (RoundState.PlayerTeams.TryGetValue(key, out var value))
			{
				return value == 0;
			}
			return false;
		}

		public static void WarnRestricted()
		{
			HUDManager instance = HUDManager.Instance;
			if (instance != null)
			{
				instance.DisplayTip("Shop Restricted", "Only the Captain can purchase items this round!", true, false, "LC_Tip1");
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
	internal static class ShopAffordableGatePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(TerminalNode node)
		{
			if (!RoundState.IsRoundActive)
			{
				return true;
			}
			if (!ShopRestriction.IsCreditPurchase(node))
			{
				return true;
			}
			if (ShopRestriction.LocalPlayerIsCaptain())
			{
				return true;
			}
			ShopRestriction.WarnRestricted();
			return false;
		}
	}
	[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
	internal static class ShopCommitGatePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(TerminalNode node)
		{
			if (!RoundState.IsRoundActive)
			{
				return true;
			}
			if ((Object)(object)node == (Object)null)
			{
				return true;
			}
			if (!ShopRestriction.IsCreditPurchase(node))
			{
				return true;
			}
			if (ShopRestriction.LocalPlayerIsCaptain())
			{
				return true;
			}
			ShopRestriction.WarnRestricted();
			return false;
		}
	}
	[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
	internal static class TerminalStoreNoticePatch
	{
		[HarmonyPostfix]
		private static void Postfix(TerminalNode node, ref string __result)
		{
			if (node != null && node.displayText != null && __result != null && node.displayText.Contains("[buyableItemsList]"))
			{
				int i;
				for (i = 0; i < __result.Length && (__result[i] == '\n' || __result[i] == '\r'); i++)
				{
				}
				__result = __result.Substring(0, i) + "Only the [Captain] can purchase items from the shop.\n\n" + __result.Substring(i);
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
	internal static class TerminalScorePatch
	{
		private static TerminalNode? _teamsNode;

		private static TerminalNode? _buffNode;

		private static TerminalNode? _captainNode;

		[HarmonyPostfix]
		private static void Postfix(Terminal __instance, ref TerminalNode __result)
		{
			string typedText = GetTypedText(__instance);
			switch (typedText)
			{
			case "teams":
			case "team":
				if ((Object)(object)_teamsNode == (Object)null)
				{
					_teamsNode = ScriptableObject.CreateInstance<TerminalNode>();
					_teamsNode.clearPreviousText = true;
					_teamsNode.maxCharactersToType = 9999;
				}
				_teamsNode.displayText = ScoreBoard.Build() + "\n";
				__result = _teamsNode;
				return;
			case "captain":
			case "captain commands":
				__result = CaptainMenu();
				return;
			}
			string[] array = typedText.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			string text = ((array.Length != 0) ? array[0] : typedText);
			string arg = ((array.Length > 1) ? typedText.Substring(text.Length).Trim() : "");
			switch (text)
			{
			case "boost":
			case "speed":
				__result = BuffCommand(__instance, speed: true, arg);
				return;
			case "revive":
			case "rescue":
				__result = BuffCommand(__instance, speed: false, arg);
				return;
			}
			if (typedText == "help" || typedText == "other")
			{
				AddTeamsToCommandList(__result);
			}
		}

		private static TerminalNode BuffCommand(Terminal terminal, bool speed, string arg)
		{
			if ((Object)(object)_buffNode == (Object)null)
			{
				_buffNode = ScriptableObject.CreateInstance<TerminalNode>();
				_buffNode.clearPreviousText = true;
				_buffNode.maxCharactersToType = 9999;
			}
			_buffNode.displayText = ResolveBuff(terminal, speed, arg) + "\n";
			return _buffNode;
		}

		private static string ResolveBuff(Terminal terminal, bool speed, string arg)
		{
			bool flag = (speed ? Config.SpeedBoostEnabled.Value : Config.GroupReviveEnabled.Value);
			int num = (speed ? Config.SpeedBoostCost.Value : Config.GroupReviveCost.Value);
			string text = (speed ? "Speed boost" : "Group revive");
			string text2 = (speed ? "boost" : "revive");
			if (!RoundState.IsRoundActive)
			{
				return "There is no active round.";
			}
			if (!flag)
			{
				return text + " is disabled.";
			}
			if (!ShopRestriction.LocalPlayerIsCaptain())
			{
				return "Only the Captain can buy buffs.";
			}
			if (string.IsNullOrEmpty(arg))
			{
				return "Usage: " + text2 + " <team colour>\nColours this round: " + RoundState.ActiveTeamColors();
			}
			int num2 = RoundState.ParseTeam(arg);
			if (num2 < 0 || !RoundState.TeamHasPlayers(num2))
			{
				return "No team with colour '" + arg + "'.\nColours this round: " + RoundState.ActiveTeamColors();
			}
			if (!speed && RoundState.GroupReviveUsed)
			{
				return "Group revive has already been used this round.";
			}
			if (!speed && !RoundState.TeamFullyDead(num2))
			{
				return RoundState.TeamName(num2) + " still has living members — the whole team must be down.";
			}
			if (terminal.groupCredits < num)
			{
				return $"Not enough credits — {text} costs ${num}.";
			}
			if (speed)
			{
				DrunkerMessages.RequestSpeedBoost(num2);
			}
			else
			{
				DrunkerMessages.RequestGroupRevive(num2);
			}
			return $"{text} sent to {RoundState.TeamName(num2)} for ${num}!";
		}

		private static TerminalNode CaptainMenu()
		{
			if ((Object)(object)_captainNode == (Object)null)
			{
				_captainNode = ScriptableObject.CreateInstance<TerminalNode>();
				_captainNode.clearPreviousText = true;
				_captainNode.maxCharactersToType = 9999;
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("CAPTAIN\n");
			stringBuilder.Append("Only the Captain can use these during an active round.\n");
			if (Config.SpeedBoostEnabled.Value)
			{
				stringBuilder.Append($"\n>BOOST [colour]\nSpeed-boost one team. (${Config.SpeedBoostCost.Value})\n");
			}
			if (Config.GroupReviveEnabled.Value)
			{
				stringBuilder.Append($"\n>REVIVE [colour]\nRevive one fully-wiped team, once per round. (${Config.GroupReviveCost.Value})\n");
			}
			_captainNode.displayText = stringBuilder.ToString();
			return _captainNode;
		}

		private static string CommandAdvert()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(">TEAMS\nView this round's teams and their members.");
			if (Config.SpeedBoostEnabled.Value || Config.GroupReviveEnabled.Value)
			{
				stringBuilder.Append("\n\n>CAPTAIN\n[Captain] Give a team speed boost or revive a team.");
			}
			return stringBuilder.ToString();
		}

		private static void AddTeamsToCommandList(TerminalNode? node)
		{
			if ((Object)(object)node == (Object)null || node.displayText == null)
			{
				return;
			}
			string displayText = node.displayText;
			if (displayText.Contains(">TEAMS"))
			{
				return;
			}
			string text = CommandAdvert();
			int num = displayText.IndexOf(">bestiary", StringComparison.OrdinalIgnoreCase);
			if (num < 0)
			{
				node.displayText = displayText.TrimEnd(Array.Empty<char>()) + "\n\n" + text + "\n";
				return;
			}
			int num2 = displayText.IndexOf("\n>", num + 1, StringComparison.Ordinal);
			if (num2 < 0)
			{
				num2 = displayText.Length;
			}
			string value = displayText.Substring(num, num2 - num).TrimEnd(Array.Empty<char>());
			string value2 = displayText.Substring(0, num).TrimEnd(Array.Empty<char>());
			string text2 = displayText.Substring(num2).Trim();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(value2);
			stringBuilder.Append("\n\n").Append(text);
			if (text2.Length > 0)
			{
				stringBuilder.Append("\n\n").Append(text2);
			}
			stringBuilder.Append("\n\n").Append(value);
			stringBuilder.Append('\n');
			node.displayText = stringBuilder.ToString();
		}

		private static string GetTypedText(Terminal terminal)
		{
			if ((Object)(object)terminal.screenText == (Object)null)
			{
				return string.Empty;
			}
			string text = terminal.screenText.text;
			int textAdded = terminal.textAdded;
			if (textAdded <= 0 || textAdded > text.Length)
			{
				return string.Empty;
			}
			return text.Substring(text.Length - textAdded).Trim().ToLower();
		}
	}
}
namespace DrunkerCompany.Network
{
	public static class DrunkerMessages
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnReceiveSyncRound;

			public static HandleNamedMessageDelegate <1>__OnReceiveReveal;

			public static HandleNamedMessageDelegate <2>__OnReceiveDeath;

			public static HandleNamedMessageDelegate <3>__OnReceiveDeathReport;

			public static HandleNamedMessageDelegate <4>__OnReceiveScores;

			public static HandleNamedMessageDelegate <5>__OnReceiveRoundEnd;

			public static HandleNamedMessageDelegate <6>__OnReceiveScrapReport;

			public static HandleNamedMessageDelegate <7>__OnReceiveRevive;

			public static HandleNamedMessageDelegate <8>__OnReceiveReviveReport;

			public static HandleNamedMessageDelegate <9>__OnReceiveMaskedSpawned;

			public static HandleNamedMessageDelegate <10>__OnReceiveBuffReq;

			public static HandleNamedMessageDelegate <11>__OnReceiveSpeedBoost;

			public static HandleNamedMessageDelegate <12>__OnReceiveGroupRevive;

			public static HandleNamedMessageDelegate <13>__OnReceiveResync;

			public static HandleNamedMessageDelegate <14>__OnReceiveAddPlayer;

			public static Action<ulong> <15>__HandleClientConnected;
		}

		private const string kSyncRound = "DrunkerCompany_SyncRound";

		private const string kReveal = "DrunkerCompany_Reveal";

		private const string kDeath = "DrunkerCompany_Death";

		private const string kDeathReport = "DrunkerCompany_DeathReport";

		private const string kScores = "DrunkerCompany_Scores";

		private const string kRoundEnd = "DrunkerCompany_RoundEnd";

		private const string kScrapReport = "DrunkerCompany_ScrapReport";

		private const string kRevive = "DrunkerCompany_Revive";

		private const string kReviveReport = "DrunkerCompany_ReviveReport";

		private const string kMaskedSpawned = "DrunkerCompany_MaskedSpawned";

		private const string kBuffReq = "DrunkerCompany_BuffReq";

		private const string kSpeedBoost = "DrunkerCompany_SpeedBoost";

		private const string kGroupRevive = "DrunkerCompany_GroupRevive";

		private const string kResync = "DrunkerCompany_Resync";

		private const string kAddPlayer = "DrunkerCompany_AddPlayer";

		private const byte BuffSpeed = 0;

		private const byte BuffRevive = 1;

		private static bool _registered;

		private static bool _connectHooked;

		private static bool _walkiesSpawnedThisRound;

		private static bool IsHost
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton != (Object)null)
				{
					return NetworkManager.Singleton.IsHost;
				}
				return false;
			}
		}

		public static void Register()
		{
			//IL_003a: 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)
			//IL_0045: Expected O, but got Unknown
			//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)
			//IL_006b: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Expected O, but got Unknown
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			if (_registered)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			CustomMessagingManager val = ((singleton != null) ? singleton.CustomMessagingManager : null);
			if (val != null)
			{
				_registered = true;
				object obj = <>O.<0>__OnReceiveSyncRound;
				if (obj == null)
				{
					HandleNamedMessageDelegate val2 = OnReceiveSyncRound;
					<>O.<0>__OnReceiveSyncRound = val2;
					obj = (object)val2;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_SyncRound", (HandleNamedMessageDelegate)obj);
				object obj2 = <>O.<1>__OnReceiveReveal;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val3 = OnReceiveReveal;
					<>O.<1>__OnReceiveReveal = val3;
					obj2 = (object)val3;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_Reveal", (HandleNamedMessageDelegate)obj2);
				object obj3 = <>O.<2>__OnReceiveDeath;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val4 = OnReceiveDeath;
					<>O.<2>__OnReceiveDeath = val4;
					obj3 = (object)val4;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_Death", (HandleNamedMessageDelegate)obj3);
				object obj4 = <>O.<3>__OnReceiveDeathReport;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val5 = OnReceiveDeathReport;
					<>O.<3>__OnReceiveDeathReport = val5;
					obj4 = (object)val5;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_DeathReport", (HandleNamedMessageDelegate)obj4);
				object obj5 = <>O.<4>__OnReceiveScores;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val6 = OnReceiveScores;
					<>O.<4>__OnReceiveScores = val6;
					obj5 = (object)val6;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_Scores", (HandleNamedMessageDelegate)obj5);
				object obj6 = <>O.<5>__OnReceiveRoundEnd;
				if (obj6 == null)
				{
					HandleNamedMessageDelegate val7 = OnReceiveRoundEnd;
					<>O.<5>__OnReceiveRoundEnd = val7;
					obj6 = (object)val7;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_RoundEnd", (HandleNamedMessageDelegate)obj6);
				object obj7 = <>O.<6>__OnReceiveScrapReport;
				if (obj7 == null)
				{
					HandleNamedMessageDelegate val8 = OnReceiveScrapReport;
					<>O.<6>__OnReceiveScrapReport = val8;
					obj7 = (object)val8;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_ScrapReport", (HandleNamedMessageDelegate)obj7);
				object obj8 = <>O.<7>__OnReceiveRevive;
				if (obj8 == null)
				{
					HandleNamedMessageDelegate val9 = OnReceiveRevive;
					<>O.<7>__OnReceiveRevive = val9;
					obj8 = (object)val9;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_Revive", (HandleNamedMessageDelegate)obj8);
				object obj9 = <>O.<8>__OnReceiveReviveReport;
				if (obj9 == null)
				{
					HandleNamedMessageDelegate val10 = OnReceiveReviveReport;
					<>O.<8>__OnReceiveReviveReport = val10;
					obj9 = (object)val10;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_ReviveReport", (HandleNamedMessageDelegate)obj9);
				object obj10 = <>O.<9>__OnReceiveMaskedSpawned;
				if (obj10 == null)
				{
					HandleNamedMessageDelegate val11 = OnReceiveMaskedSpawned;
					<>O.<9>__OnReceiveMaskedSpawned = val11;
					obj10 = (object)val11;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_MaskedSpawned", (HandleNamedMessageDelegate)obj10);
				object obj11 = <>O.<10>__OnReceiveBuffReq;
				if (obj11 == null)
				{
					HandleNamedMessageDelegate val12 = OnReceiveBuffReq;
					<>O.<10>__OnReceiveBuffReq = val12;
					obj11 = (object)val12;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_BuffReq", (HandleNamedMessageDelegate)obj11);
				object obj12 = <>O.<11>__OnReceiveSpeedBoost;
				if (obj12 == null)
				{
					HandleNamedMessageDelegate val13 = OnReceiveSpeedBoost;
					<>O.<11>__OnReceiveSpeedBoost = val13;
					obj12 = (object)val13;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_SpeedBoost", (HandleNamedMessageDelegate)obj12);
				object obj13 = <>O.<12>__OnReceiveGroupRevive;
				if (obj13 == null)
				{
					HandleNamedMessageDelegate val14 = OnReceiveGroupRevive;
					<>O.<12>__OnReceiveGroupRevive = val14;
					obj13 = (object)val14;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_GroupRevive", (HandleNamedMessageDelegate)obj13);
				object obj14 = <>O.<13>__OnReceiveResync;
				if (obj14 == null)
				{
					HandleNamedMessageDelegate val15 = OnReceiveResync;
					<>O.<13>__OnReceiveResync = val15;
					obj14 = (object)val15;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_Resync", (HandleNamedMessageDelegate)obj14);
				object obj15 = <>O.<14>__OnReceiveAddPlayer;
				if (obj15 == null)
				{
					HandleNamedMessageDelegate val16 = OnReceiveAddPlayer;
					<>O.<14>__OnReceiveAddPlayer = val16;
					obj15 = (object)val16;
				}
				val.RegisterNamedMessageHandler("DrunkerCompany_AddPlayer", (HandleNamedMessageDelegate)obj15);
				if (IsHost && !_connectHooked)
				{
					NetworkManager.Singleton.OnClientConnectedCallback += HandleClientConnected;
					_connectHooked = true;
				}
				Plugin.Logger.LogInfo((object)"[DrunkerMessages] Handlers registered.");
			}
		}

		public static void Reset()
		{
			_registered = false;
		}

		public static void BroadcastSyncRound(ulong captainId, ulong[] playerIds, int[] teamIndices)
		{
			//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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			int num = 12 + playerIds.Length * 8 + 4 + teamIndices.Length * 4 + 16;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref captainId, default(ForPrimitives));
			int num2 = playerIds.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
			for (num2 = 0; num2 < playerIds.Length; num2++)
			{
				ulong num3 = playerIds[num2];
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref num3, default(ForPrimitives));
			}
			num2 = teamIndices.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
			for (num2 = 0; num2 < teamIndices.Length; num2++)
			{
				int num4 = teamIndices[num2];
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num4, default(ForPrimitives));
			}
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_SyncRound", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			_walkiesSpawnedThisRound = false;
			ApplySyncRound(captainId, playerIds, teamIndices);
		}

		public static void ReportDeath(ulong clientId, string playerName, bool diedInShip)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost)
			{
				HandleDeath(clientId, playerName, diedInShip);
				return;
			}
			byte[] bytes = Encoding.UTF8.GetBytes(playerName);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(13 + bytes.Length, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref clientId, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref diedInShip, default(ForPrimitives));
			int num = bytes.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteBytesSafe(bytes, -1, 0);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DrunkerCompany_DeathReport", 0uL, val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
		}

		private static void HandleDeath(ulong clientId, string playerName, bool diedInShip)
		{
			if (!RoundState.DeadPlayers.Contains(clientId))
			{
				bool flag = !RoundState.FirstDeathAnnounced;
				if (flag)
				{
					RoundState.FirstDeathAnnounced = true;
				}
				if (diedInShip)
				{
					RoundState.DiedOnShip.Add(clientId);
				}
				bool flag2 = clientId == RoundState.CaptainClientId;
				BroadcastDeath(clientId, playerName, flag, flag2);
				if (flag2 && !RoundState.CaptainDead)
				{
					RoundState.CaptainDead = true;
					MaskedSpawner.SpawnOutsideAfterCaptainDeath();
				}
			}
		}

		private static void BroadcastDeath(ulong clientId, string playerName, bool isFirst, bool isCaptain)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			byte[] bytes = Encoding.UTF8.GetBytes(playerName);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(14 + bytes.Length, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref clientId, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref isFirst, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref isCaptain, default(ForPrimitives));
			int num = bytes.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteBytesSafe(bytes, -1, 0);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_Death", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplyDeath(clientId, playerName, isFirst, isCaptain);
		}

		private static void BroadcastScores()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost)
			{
				int[] teamScrapScores = RoundState.TeamScrapScores;
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(4 + teamScrapScores.Length * 4, (Allocator)2, -1);
				int num = teamScrapScores.Length;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				int[] array = teamScrapScores;
				for (num = 0; num < array.Length; num++)
				{
					int num2 = array[num];
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
				}
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_Scores", val, (NetworkDelivery)3);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void BroadcastRoundEnd()
		{
			//IL_0017: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			BroadcastScores();
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			int num = 0;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_RoundEnd", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplyRoundEnd();
		}

		public static void BroadcastMaskedSpawned(ulong netId)
		{
			//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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			RoundState.OurMaskedNetIds.Add(netId);
			if (IsHost)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref netId, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_MaskedSpawned", val, (NetworkDelivery)3);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnReceiveMaskedSpawned(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ulong num = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives));
			RoundState.OurMaskedNetIds.Add(num);
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(MaskedSpawner.MarkOutsideWhenReplicated(num));
			}
		}

		public static void ReportScrapDeposit(int teamIndex, int value, ulong netId)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost)
			{
				AccumulateScrap(teamIndex, value, netId);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(20, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref teamIndex, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref value, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref netId, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DrunkerCompany_ScrapReport", 0uL, val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
		}

		private static void AccumulateScrap(int teamIndex, int value, ulong netId)
		{
			if (teamIndex >= 0 && teamIndex < RoundState.TeamScrapScores.Length && RoundState.CountedScrap.Add(netId))
			{
				RoundState.TeamScrapScores[teamIndex] += value;
				BroadcastScores();
			}
		}

		public static void RequestRevive(ulong deadClientId, ulong reviverClientId)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost)
			{
				HandleRevive(deadClientId, reviverClientId);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref deadClientId, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref reviverClientId, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DrunkerCompany_ReviveReport", 0uL, val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
		}

		private static void HandleRevive(ulong deadClientId, ulong reviverClientId)
		{
			if (deadClientId != reviverClientId && !RoundState.RevivedPlayers.Contains(deadClientId) && RoundState.DeadPlayers.Contains(deadClientId))
			{
				RoundState.RevivedPlayers.Add(deadClientId);
				BroadcastRevive(deadClientId, reviverClientId);
			}
		}

		private static void BroadcastRevive(ulong deadClientId, ulong reviverClientId)
		{
			//IL_0011: 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)
			//IL_0023: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref deadClientId, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref reviverClientId, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_Revive", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplyRevive(deadClientId, reviverClientId);
		}

		private static void ApplyRevive(ulong deadClientId, ulong reviverClientId)
		{
			PlayerControllerB val = null;
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if ((Object)(object)val2 != (Object)null && val2.playerClientId == deadClientId)
					{
						val = val2;
						break;
					}
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				RoundState.DeadPlayers.Remove(deadClientId);
				ReviveManager.RevivePlayer(val);
				AnnounceRevive(deadClientId, reviverClientId, val.playerUsername);
			}
		}

		private static void AnnounceRevive(ulong deadClientId, ulong reviverClientId, string revivedName)
		{
			ulong num = (ulong)(((long?)GameNetworkManager.Instance?.localPlayerController?.playerClientId) ?? (-1L));
			RoundState.PlayerTeams.TryGetValue(deadClientId, out var value);
			int value2;
			bool flag = RoundState.PlayerTeams.TryGetValue(reviverClientId, out value2) && value2 != value;
			string text = ((value2 < RoundState.TeamNames.Length) ? RoundState.TeamNames[value2] : $"Team {value2}");
			int value3;
			bool flag2 = RoundState.PlayerTeams.TryGetValue(num, out value3) && value3 == value;
			if (num == deadClientId)
			{
				string text2 = (flag ? ("You were brought back by " + text + "!") : "You were brought back to life!");
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Revived", text2, false, false, "LC_Tip1");
				}
			}
			else if (flag2)
			{
				string text3 = (flag ? (text + " revived your teammate " + revivedName + "!") : ("Your teammate " + revivedName + " has been brought back to life!"));
				HUDManager instance2 = HUDManager.Instance;
				if (instance2 != null)
				{
					instance2.DisplayTip("Teammate Revived", text3, false, false, "LC_Tip1");
				}
			}
		}

		public static void RequestSpeedBoost(int team)
		{
			RequestBuff(0, team);
		}

		public static void RequestGroupRevive(int team)
		{
			RequestBuff(1, team);
		}

		private static void RequestBuff(byte buffType, int team)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			ulong requesterClientId = (ulong)(((long?)GameNetworkManager.Instance?.localPlayerController?.playerClientId) ?? (-1L));
			if (IsHost)
			{
				HandleBuff(buffType, team, requesterClientId);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(13, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref buffType, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref team, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref requesterClientId, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DrunkerCompany_BuffReq", 0uL, val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
		}

		private static void HandleBuff(byte buffType, int team, ulong requesterClientId)
		{
			if (!IsHost || !RoundState.IsRoundActive || requesterClientId != RoundState.CaptainClientId || !RoundState.TeamHasPlayers(team))
			{
				return;
			}
			Terminal val = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			switch (buffType)
			{
			case 0:
				if (Config.SpeedBoostEnabled.Value && val.groupCredits >= Config.SpeedBoostCost.Value)
				{
					DeductCredits(val, Config.SpeedBoostCost.Value);
					BroadcastSpeedBoost(Config.SpeedBoostMultiplier.Value, Config.SpeedBoostDuration.Value, team);
				}
				break;
			case 1:
				if (Config.GroupReviveEnabled.Value && !RoundState.GroupReviveUsed && RoundState.TeamFullyDead(team) && val.groupCredits >= Config.GroupReviveCost.Value)
				{
					DeductCredits(val, Config.GroupReviveCost.Value);
					RoundState.GroupReviveUsed = true;
					BroadcastGroupRevive(team);
				}
				break;
			}
		}

		private static void DeductCredits(Terminal terminal, int cost)
		{
			terminal.groupCredits = Mathf.Max(0, terminal.groupCredits - cost);
			terminal.SyncGroupCreditsClientRpc(terminal.groupCredits, terminal.numberOfItemsInDropship);
		}

		private static void BroadcastSpeedBoost(float multiplier, float duration, int team)
		{
			//IL_0011: 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)
			//IL_0023: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref multiplier, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref duration, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref team, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_SpeedBoost", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplySpeedBoost(multiplier, duration, team);
		}

		private static void OnReceiveSpeedBoost(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			float multiplier = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref multiplier, default(ForPrimitives));
			float duration = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref duration, default(ForPrimitives));
			int team = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref team, default(ForPrimitives));
			ApplySpeedBoost(multiplier, duration, team);
		}

		private static void ApplySpeedBoost(float multiplier, float duration, int team)
		{
			ulong key = (ulong)(((long?)GameNetworkManager.Instance?.localPlayerController?.playerClientId) ?? (-1L));
			if (RoundState.PlayerTeams.TryGetValue(key, out var value) && value == team)
			{
				BuffManager.ApplySpeedBoost(multiplier, duration);
			}
		}

		private static void BroadcastGroupRevive(int team)
		{
			//IL_0068: 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_0083: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			List<ulong> list = new List<ulong>();
			foreach (ulong deadPlayer in RoundState.DeadPlayers)
			{
				if (RoundState.PlayerTeams.TryGetValue(deadPlayer, out var value) && value == team)
				{
					list.Add(deadPlayer);
				}
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8 + list.Count * 8, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref team, default(ForPrimitives));
			int count = list.Count;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
			foreach (ulong item in list)
			{
				ulong current2 = item;
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current2, default(ForPrimitives));
			}
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_GroupRevive", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplyGroupRevive(team, list.ToArray());
		}

		private static void OnReceiveGroupRevive(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//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)
			int team = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref team, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong[] array = new ulong[num];
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref array[i], default(ForPrimitives));
			}
			ApplyGroupRevive(team, array);
		}

		private static void ApplyGroupRevive(int team, ulong[] ids)
		{
			RoundState.GroupReviveUsed = true;
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			foreach (ulong num in ids)
			{
				RoundState.DeadPlayers.Remove(num);
				RoundState.RevivedPlayers.Add(num);
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if ((Object)(object)val != (Object)null && val.playerClientId == num)
					{
						ReviveManager.RevivePlayer(val, recallBodyToShip: true);
						break;
					}
				}
			}
			HUDManager instance = HUDManager.Instance;
			if (instance != null)
			{
				instance.DisplayTip("Group Revive", "The Captain brought " + RoundState.TeamName(team) + " back to life!", false, false, "LC_Tip1");
			}
		}

		private static void HandleClientConnected(ulong clientId)
		{
			if (IsHost && RoundState.IsRoundActive && clientId != 0L && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(ResyncLateJoiner(clientId));
			}
		}

		private static IEnumerator ResyncLateJoiner(ulong clientId)
		{
			yield return (object)new WaitForSeconds(3f);
			if (!RoundState.IsRoundActive)
			{
				yield break;
			}
			if (!RoundState.PlayerTeams.ContainsKey(clientId))
			{
				Dictionary<int, int> dictionary = new Dictionary<int, int>();
				foreach (KeyValuePair<ulong, int> playerTeam in RoundState.PlayerTeams)
				{
					if (playerTeam.Value != 0)
					{
						dictionary[playerTeam.Value] = ((!dictionary.TryGetValue(playerTeam.Value, out var value)) ? 1 : (value + 1));
					}
				}
				int num = 1;
				int num2 = int.MaxValue;
				foreach (KeyValuePair<int, int> item in dictionary)
				{
					if (item.Value < num2)
					{
						num2 = item.Value;
						num = item.Key;
					}
				}
				RoundState.PlayerTeams[clientId] = num;
				BroadcastAddPlayer(clientId, num);
			}
			SendResyncTo(clientId);
			Plugin.Logger.LogInfo((object)$"[Resync] Late joiner {clientId} folded into team {RoundState.PlayerTeams[clientId]}.");
		}

		private static void BroadcastAddPlayer(ulong clientId, int team)
		{
			//IL_0011: 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)
			//IL_0023: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref clientId, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref team, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_AddPlayer", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			ApplyAddPlayer(clientId, team);
		}

		private static void OnReceiveAddPlayer(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			ulong clientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref clientId, default(ForPrimitives));
			int team = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref team, default(ForPrimitives));
			ApplyAddPlayer(clientId, team);
		}

		private static void ApplyAddPlayer(ulong clientId, int team)
		{
			RoundState.PlayerTeams[clientId] = team;
			SuitManager.ApplyAll(RoundState.PlayerTeams);
			TeamHUD.Refresh();
		}

		private static void SendResyncTo(ulong clientId)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			List<ulong> list = new List<ulong>();
			List<int> list2 = new List<int>();
			foreach (KeyValuePair<ulong, int> playerTeam in RoundState.PlayerTeams)
			{
				list.Add(playerTeam.Key);
				list2.Add(playerTeam.Value);
			}
			int[] teamScrapScores = RoundState.TeamScrapScores;
			List<ulong> list3 = new List<ulong>(RoundState.DeadPlayers);
			int num = 12 + list.Count * 12 + 4 + teamScrapScores.Length * 4 + 4 + list3.Count * 8;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref RoundState.CaptainClientId, default(ForPrimitives));
			int count = list.Count;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
			for (int i = 0; i < list.Count; i++)
			{
				ulong num2 = list[i];
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref num2, default(ForPrimitives));
				count = list2[i];
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
			}
			count = teamScrapScores.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
			int[] array = teamScrapScores;
			for (count = 0; count < array.Length; count++)
			{
				int num3 = array[count];
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num3, default(ForPrimitives));
			}
			count = list3.Count;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
			foreach (ulong item in list3)
			{
				ulong current2 = item;
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current2, default(ForPrimitives));
			}
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DrunkerCompany_Resync", clientId, val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
		}

		private static void OnReceiveResync(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00e6: 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)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			ulong num = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives));
			int num2 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			RoundState.Reset();
			RoundState.CaptainClientId = num;
			RoundState.IsRoundActive = true;
			int num3 = 0;
			ulong key = default(ulong);
			int num4 = default(int);
			for (int i = 0; i < num2; i++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num4, default(ForPrimitives));
				RoundState.PlayerTeams[key] = num4;
				if (num4 > num3)
				{
					num3 = num4;
				}
			}
			int num5 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num5, default(ForPrimitives));
			int[] array = new int[num5];
			for (int j = 0; j < num5; j++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array[j], default(ForPrimitives));
			}
			RoundState.TeamScrapScores = ((array.Length != 0) ? array : new int[num3 + 1]);
			int num6 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num6, default(ForPrimitives));
			ulong item = default(ulong);
			for (int k = 0; k < num6; k++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref item, default(ForPrimitives));
				RoundState.DeadPlayers.Add(item);
			}
			RunApplySyncRoundVisuals(num);
			Plugin.Logger.LogInfo((object)"[Resync] Applied late-join state from host.");
		}

		private static void OnReceiveSyncRound(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			ulong captainId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref captainId, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong[] array = new ulong[num];
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref array[i], default(ForPrimitives));
			}
			int num2 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			int[] array2 = new int[num2];
			for (int j = 0; j < num2; j++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array2[j], default(ForPrimitives));
			}
			ApplySyncRound(captainId, array, array2);
		}

		private static void OnReceiveDeath(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			ulong clientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref clientId, default(ForPrimitives));
			bool isFirst = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref isFirst, default(ForPrimitives));
			bool isCaptain = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref isCaptain, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			byte[] bytes = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref bytes, num, 0);
			ApplyDeath(clientId, Encoding.UTF8.GetString(bytes), isFirst, isCaptain);
		}

		private static void OnReceiveDeathReport(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: 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)
			ulong clientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref clientId, default(ForPrimitives));
			bool diedInShip = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref diedInShip, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			byte[] bytes = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref bytes, num, 0);
			HandleDeath(clientId, Encoding.UTF8.GetString(bytes), diedInShip);
		}

		private static void OnReceiveScores(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int[] array = new int[num];
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array[i], default(ForPrimitives));
			}
			RoundState.TeamScrapScores = array;
		}

		private static void OnReceiveRoundEnd(ulong _, FastBufferReader reader)
		{
			ApplyRoundEnd();
		}

		private static void OnReceiveReviveReport(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			ulong deadClientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref deadClientId, default(ForPrimitives));
			ulong reviverClientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref reviverClientId, default(ForPrimitives));
			HandleRevive(deadClientId, reviverClientId);
		}

		private static void OnReceiveRevive(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			ulong deadClientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref deadClientId, default(ForPrimitives));
			ulong reviverClientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref reviverClientId, default(ForPrimitives));
			ApplyRevive(deadClientId, reviverClientId);
		}

		private static void OnReceiveScrapReport(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			int teamIndex = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref teamIndex, default(ForPrimitives));
			int value = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref value, default(ForPrimitives));
			ulong netId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref netId, default(ForPrimitives));
			AccumulateScrap(teamIndex, value, netId);
		}

		private static void OnReceiveBuffReq(ulong _, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			byte buffType = default(byte);
			((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref buffType, default(ForPrimitives));
			int team = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref team, default(ForPrimitives));
			ulong requesterClientId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref requesterClientId, default(ForPrimitives));
			HandleBuff(buffType, team, requesterClientId);
		}

		private static void ApplySyncRound(ulong captainId, ulong[] playerIds, int[] teamIndices)
		{
			RoundState.Reset();
			BuffManager.ClearSpeedBoost();
			RoundState.CaptainClientId = captainId;
			RoundState.IsRoundActive = true;
			int num = 0;
			for (int i = 0; i < playerIds.Length; i++)
			{
				RoundState.PlayerTeams[playerIds[i]] = teamIndices[i];
				if (teamIndices[i] > num)
				{
					num = teamIndices[i];
				}
			}
			RoundState.TeamScrapScores = new int[num + 1];
			if (IsHost)
			{
				SnapshotExistingShipScrap();
				if ((Object)(object)StartOfRound.Instance != (Object)null)
				{
					((MonoBehaviour)StartOfRound.Instance).StartCoroutine(RevealAfterDelay(captainId));
				}
				else
				{
					BroadcastReveal(captainId);
				}
			}
		}

		private static void SnapshotExistingShipScrap()
		{
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.itemProperties == (Object)null) && val.itemProperties.isScrap && (val.isInShipRoom || val.isInElevator) && !((Object)(object)((NetworkBehaviour)val).NetworkObject == (Object)null) && ((NetworkBehaviour)val).NetworkObject.IsSpawned)
				{
					RoundState.CountedScrap.Add(((NetworkBehaviour)val).NetworkObjectId);
				}
			}
		}

		private static IEnumerator RevealAfterDelay(ulong captainId)
		{
			yield return (object)new WaitForSeconds(5f);
			BroadcastReveal(captainId);
		}

		private static void BroadcastReveal(ulong captainId)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref captainId, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("DrunkerCompany_Reveal", val, (NetworkDelivery)3);
			((FastBufferWriter)(ref val)).Dispose();
			if (IsHost && !_walkiesSpawnedThisRound && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				_walkiesSpawnedThisRound = true;
				((MonoBehaviour)StartOfRound.Instance).Star