Decompiled source of CompetitiveCompany v0.3.1

CompetitiveCompany.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Lib;
using CSync.Util;
using CompetitiveCompany;
using CompetitiveCompany.patches;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements.Collections;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CompetitiveCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Your Mod Description Goes Here")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8b26f609e928f638868b8916e7cd58fa7c6ac023")]
[assembly: AssemblyProduct("CompetitiveCompany")]
[assembly: AssemblyTitle("CompetitiveCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[DataContract]
public class Config : SyncedConfig<Config>
{
	[DataMember]
	internal SyncedEntry<int> team1Suit { get; private set; }

	[DataMember]
	internal SyncedEntry<int> team2Suit { get; private set; }

	[DataMember]
	internal SyncedEntry<string> team1Name { get; private set; }

	[DataMember]
	internal SyncedEntry<string> team2Name { get; private set; }

	[DataMember]
	internal SyncedEntry<string> team1ColorCode { get; private set; }

	[DataMember]
	internal SyncedEntry<string> team2ColorCode { get; private set; }

	[DataMember]
	internal SyncedEntry<int> graceTime { get; private set; }

	[DataMember]
	internal SyncedEntry<int> fineAmount { get; private set; }

	public Config(ConfigFile cfg)
		: base("CompetitiveCompany")
	{
		ConfigManager.Register<Config>(this);
		team1Suit = Extensions.BindSyncedEntry<int>(cfg, "Suits", "Team 1 Suits", 0, "Originally the orange suit.\nIf you want to set a custom suit with AdditionalSuits, their suits\nGet logged when the game starts. Simply read the logs\nAnd use their SuitIDs!");
		team2Suit = Extensions.BindSyncedEntry<int>(cfg, "Suits", "Team 2 Suits", 3, "Originally the Pajama Suit");
		team1Name = Extensions.BindSyncedEntry<string>(cfg, "Names", "Team 1 Name", "Orange", "Set the name for team 1.");
		team2Name = Extensions.BindSyncedEntry<string>(cfg, "Names", "Team 2 Name", "Blue", "Set the name for team 2.");
		team1ColorCode = Extensions.BindSyncedEntry<string>(cfg, "Colors", "Team 1 Color", "orange", "Set the color code for team 1. Hex codes can be used.");
		team2ColorCode = Extensions.BindSyncedEntry<string>(cfg, "Colors", "Team 2 Color", "blue", "Set the color code for team 2. Hex codes can be used.");
		graceTime = Extensions.BindSyncedEntry<int>(cfg, "Grace Time", "Grace Time", 14, "How long grace lasts for. 12+ = PM");
		fineAmount = Extensions.BindSyncedEntry<int>(cfg, "Grace Time", "Fine Amount", 200, "How much should you be fined for leaving early");
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	public static void InitializeLocalPlayer()
	{
		Plugin.Instance.mls.LogError((object)"10088 - Start");
		if (SyncedInstance<Config>.IsHost)
		{
			SyncedInstance<Config>.Synced = true;
		}
		else
		{
			SyncedInstance<Config>.Synced = false;
		}
	}
}
public class Randomizer
{
	public static void Randomize<T>(T[] items)
	{
		Random random = new Random();
		for (int i = 0; i < items.Length - 1; i++)
		{
			int num = random.Next(i, items.Length);
			T val = items[i];
			items[i] = items[num];
			items[num] = val;
		}
	}
}
namespace CompetitiveCompany
{
	[BepInPlugin("org.agmas.CompetitiveCompany", "Competitive Company", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "org.agmas.CompetitiveCompany";

		private const string modName = "Competitive Company";

		private const string modVersion = "0.3.0";

		private readonly Harmony harmony = new Harmony("org.agmas.CompetitiveCompany");

		public static Plugin Instance;

		public static int blueScore = 0;

		public static bool startLogic = false;

		public static bool warnship = true;

		public static bool finedForShip = false;

		public static int redScore = 0;

		public static int curHour = 0;

		public static int nextHour = 0;

		public static Dictionary<PlayerControllerB, int> teams = new Dictionary<PlayerControllerB, int>();

		public static Dictionary<PlayerControllerB, bool> initiated = new Dictionary<PlayerControllerB, bool>();

		public ManualLogSource mls;

		public static Config MyConfig { get; internal set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			MyConfig = new Config(((BaseUnityPlugin)this).Config);
			mls = Logger.CreateLogSource("org.agmas.CompetitiveCompany");
			mls.LogInfo((object)"We're up and running!");
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(HudManagerPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(GrabbableObjectPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(Config));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CompetitiveCompany";

		public const string PLUGIN_NAME = "CompetitiveCompany";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CompetitiveCompany.patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class HudManagerPatch
	{
		public static TextMeshProUGUI _blueTeam;

		public static TextMeshProUGUI _seperator;

		public static TextMeshProUGUI _redTeam;

		[HarmonyPatch(typeof(HUDManager), "Start")]
		[HarmonyPrefix]
		public static void fix(HUDManager __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0147: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("BlueHUD");
			val.AddComponent<RectTransform>();
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
			((Transform)rectTransform).SetParent(((Component)__instance.PTTIcon).transform, false);
			rectTransform.anchoredPosition = new Vector2(0f, 2f);
			((TMP_Text)val2).font = ((TMP_Text)__instance.controlTipLines[0]).font;
			((TMP_Text)val2).fontSize = 16f;
			((TMP_Text)val2).text = "1000";
			((Graphic)val2).color = Color.red;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((Behaviour)val2).enabled = true;
			_redTeam = val2;
			GameObject val3 = new GameObject("SepHUD");
			val3.AddComponent<RectTransform>();
			TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
			RectTransform rectTransform2 = ((TMP_Text)val4).rectTransform;
			((Transform)rectTransform2).SetParent(((Component)__instance.PTTIcon).transform, false);
			rectTransform2.anchoredPosition = new Vector2(0f, 2f);
			((TMP_Text)val4).font = ((TMP_Text)__instance.controlTipLines[0]).font;
			((TMP_Text)val4).fontSize = 16f;
			((TMP_Text)val4).text = "vs";
			((Graphic)val4).color = Color.gray;
			((TMP_Text)val4).overflowMode = (TextOverflowModes)0;
			((Behaviour)val4).enabled = true;
			_seperator = val4;
			GameObject val5 = new GameObject("RedHUD");
			val5.AddComponent<RectTransform>();
			TextMeshProUGUI val6 = val5.AddComponent<TextMeshProUGUI>();
			RectTransform rectTransform3 = ((TMP_Text)val6).rectTransform;
			((Transform)rectTransform3).SetParent(((Component)__instance.PTTIcon).transform, false);
			rectTransform3.anchoredPosition = new Vector2(0f, 2f);
			((TMP_Text)val6).font = ((TMP_Text)__instance.controlTipLines[0]).font;
			((TMP_Text)val6).fontSize = 16f;
			((TMP_Text)val6).text = "1000";
			((Graphic)val6).color = Color.blue;
			((TMP_Text)val6).overflowMode = (TextOverflowModes)0;
			((Behaviour)val6).enabled = true;
			_blueTeam = val6;
		}

		[HarmonyPatch(typeof(HUDManager), "DisplayDaysLeft")]
		[HarmonyPrefix]
		private static bool teams2()
		{
			if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer)
			{
				TimeOfDay.Instance.timeUntilDeadline = 2000f;
			}
			if (Plugin.blueScore > Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText).text = SyncedInstance<Config>.Instance.team2Name.Value + " Wins!";
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText2).text = SyncedInstance<Config>.Instance.team2Name.Value + " Wins!";
			}
			if (Plugin.blueScore < Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText).text = SyncedInstance<Config>.Instance.team1Name.Value + " Wins!";
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText2).text = SyncedInstance<Config>.Instance.team1Name.Value + " Wins!";
			}
			if (Plugin.blueScore == Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText).text = "Tie!";
				((TMP_Text)HUDManager.Instance.profitQuotaDaysLeftText2).text = "Tie!";
			}
			if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer)
			{
				RoundManager.Instance.DespawnPropsAtEndOfRound(true);
			}
			HUDManager.Instance.reachedProfitQuotaAnimator.SetTrigger("displayDaysLeftCalm");
			HUDManager.Instance.UIAudio.PlayOneShot(HUDManager.Instance.profitQuotaDaysLeftCalmSFX);
			return false;
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPostfix]
		private static void teams()
		{
			if (Plugin.blueScore > Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.statsUIElements.gradeLetter).text = SyncedInstance<Config>.Instance.team2Name.Value.Substring(0, 2);
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team2Name.Value + " won the game!!", -1);
				}
			}
			if (Plugin.blueScore < Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.statsUIElements.gradeLetter).text = SyncedInstance<Config>.Instance.team1Name.Value.Substring(0, 2);
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team1Name.Value + " won the game!!", -1);
				}
			}
			if (Plugin.blueScore == Plugin.redScore)
			{
				((TMP_Text)HUDManager.Instance.statsUIElements.gradeLetter).text = "T";
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=white>Tied.", -1);
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "AddChatMessage")]
		[HarmonyPrefix]
		public static bool Prefix(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped = "")
		{
			if (string.IsNullOrEmpty(nameOfUserWhoTyped))
			{
				if (chatMessage.StartsWith("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">") && chatMessage.EndsWith(" was put on " + SyncedInstance<Config>.Instance.team1Name.Value + "!"))
				{
					string text = (string)chatMessage.Clone();
					text = text.Remove(0, 8 + SyncedInstance<Config>.Instance.team1ColorCode.Value.Length);
					string[] array = text.Split(" was");
					Plugin.Instance.mls.LogInfo((object)("Detected Player " + array[0]));
					PlayerControllerB[] allPlayerScripts = RoundManager.Instance.playersManager.allPlayerScripts;
					foreach (PlayerControllerB val in allPlayerScripts)
					{
						if (array[0].Equals(val.playerUsername) && !Plugin.teams.ContainsKey(val))
						{
							Plugin.teams.Add(val, 0);
						}
					}
				}
				if (chatMessage.Equals("<color=green>Use the suit rack to switch team or\nPut on the Yellow suit to be randomly selected!"))
				{
					HUDManager.Instance.DisplayTip("Competitive Company", "Use the suit rack to switch team or\nPut on the Yellow suit to be randomly selected!", false, false, "LC_Tip1");
					return false;
				}
				if (chatMessage.StartsWith("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">") && chatMessage.EndsWith(" was put on " + SyncedInstance<Config>.Instance.team2Name.Value + "!"))
				{
					string text2 = (string)chatMessage.Clone();
					text2 = text2.Remove(0, 8 + SyncedInstance<Config>.Instance.team2ColorCode.Value.Length);
					string[] array2 = text2.Split(" was");
					Plugin.Instance.mls.LogInfo((object)("Detected Player " + array2[0]));
					PlayerControllerB[] allPlayerScripts2 = RoundManager.Instance.playersManager.allPlayerScripts;
					foreach (PlayerControllerB val2 in allPlayerScripts2)
					{
						if (array2[0].Equals(val2.playerUsername) && !Plugin.teams.ContainsKey(val2))
						{
							Plugin.teams.Add(val2, 1);
						}
					}
				}
				if (chatMessage.StartsWith("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + GameNetworkManager.Instance.localPlayerController.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team1Name.Value + "!"))
				{
					__instance.DisplayTip("Competitive Company", "You're on " + SyncedInstance<Config>.Instance.team1Name.Value + "!", false, false, "LC_Tip1");
				}
				if (chatMessage.StartsWith("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + GameNetworkManager.Instance.localPlayerController.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team2Name.Value + "!"))
				{
					__instance.DisplayTip("Competitive Company", "You're on " + SyncedInstance<Config>.Instance.team2Name.Value + "!", false, false, "LC_Tip1");
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch(typeof(PlayerControllerB), "SetItemInElevator")]
		[HarmonyPrefix]
		private static void gammaPatch2(PlayerControllerB __instance, ref GrabbableObject gObject, ref bool droppedInShipRoom)
		{
			if (!((gObject.itemProperties.isScrap && !gObject.scrapPersistedThroughRounds) & droppedInShipRoom) || RoundManager.Instance.scrapCollectedThisRound.Contains(gObject) || !Plugin.teams.ContainsKey(__instance))
			{
				return;
			}
			if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, __instance, 0) == 0)
			{
				Plugin.redScore += gObject.scrapValue;
				if (GameNetworkManager.Instance.isHostingGame)
				{
					Terminal val = Object.FindObjectOfType<Terminal>();
					val.groupCredits += gObject.scrapValue;
					val.SyncGroupCreditsServerRpc(val.groupCredits, val.numberOfItemsInDropship);
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">+" + gObject.scrapValue + "\n<color=white>(<color=red>" + Plugin.redScore + "<color=white> - <color=blue>" + Plugin.blueScore + "<color=white>)", -1);
				}
			}
			if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, __instance, 0) == 1)
			{
				Plugin.blueScore += gObject.scrapValue;
				if (GameNetworkManager.Instance.isHostingGame)
				{
					Terminal val2 = Object.FindObjectOfType<Terminal>();
					val2.groupCredits += gObject.scrapValue;
					val2.SyncGroupCreditsServerRpc(val2.groupCredits, val2.numberOfItemsInDropship);
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">+" + gObject.scrapValue + "\n<color=white>(<color=red>" + Plugin.redScore + "<color=white> - <color=blue>" + Plugin.blueScore + "<color=white>)", -1);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayerFromOtherClientServerRpc")]
		[HarmonyPrefix]
		private static void ff(PlayerControllerB __instance, ref int damageAmount, ref int playerWhoHit)
		{
			int num = (int)(TimeOfDay.Instance.normalizedTimeOfDay * (60f * (float)TimeOfDay.Instance.numberOfHours)) + 360;
			int num2 = (int)Mathf.Floor((float)(num / 60));
			if (RoundManager.Instance.playersManager.allPlayerScripts[playerWhoHit].currentSuitID == __instance.currentSuitID)
			{
				HUDManager.Instance.DisplayTip("Competitive Company", "Friendly fire is not allowed!", true, false, "LC_Tip1");
				damageAmount = 0;
			}
			if (num2 >= SyncedInstance<Config>.Instance.graceTime.Value)
			{
				return;
			}
			damageAmount = 0;
			if (((object)RoundManager.Instance.playersManager.allPlayerScripts[playerWhoHit]).Equals((object?)GameNetworkManager.Instance.localPlayerController))
			{
				int num3 = 0;
				string text = "am";
				num3 += SyncedInstance<Config>.Instance.graceTime.Value;
				if (num3 > 12)
				{
					num3 -= 12;
					text = "pm";
				}
				HUDManager.Instance.DisplayTip("Competitive Company", "You can only attack others in the factory or after " + num3 + text + "!", true, false, "LC_Tip1");
			}
		}

		private static IEnumerator SuitSetter(PlayerControllerB b)
		{
			yield return (object)new WaitForSeconds(2f);
			UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>(true);
			UnlockableSuit[] array2 = array;
			foreach (UnlockableSuit us in array2)
			{
				if (us.suitID == 2)
				{
					us.SwitchSuitToThis(b);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void gammaPatch(PlayerControllerB __instance)
		{
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)null))
			{
				return;
			}
			if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
			{
				if (!Plugin.initiated.ContainsKey(__instance))
				{
					Plugin.initiated.Add(__instance, value: true);
					HUDManager.Instance.AddTextToChatOnServer("<color=green>Use the suit rack to switch team or\nPut on the Yellow suit to be randomly selected!", -1);
					((MonoBehaviour)__instance).StartCoroutine(SuitSetter(__instance));
				}
				if (Plugin.teams.ContainsKey(__instance) && Plugin.startLogic && RoundManager.Instance.dungeonFinishedGeneratingForAllPlayers)
				{
					if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, __instance, 0) == 0 && __instance.currentSuitID != SyncedInstance<Config>.Instance.team1Suit.Value)
					{
						UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>(true);
						UnlockableSuit[] array2 = array;
						foreach (UnlockableSuit val in array2)
						{
							if (val.suitID == SyncedInstance<Config>.Instance.team1Suit.Value)
							{
								val.SwitchSuitToThis(__instance);
							}
						}
					}
					if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, __instance, 0) == 1 && __instance.currentSuitID != SyncedInstance<Config>.Instance.team2Suit.Value)
					{
						UnlockableSuit[] array3 = Object.FindObjectsOfType<UnlockableSuit>(true);
						UnlockableSuit[] array4 = array3;
						foreach (UnlockableSuit val2 in array4)
						{
							if (val2.suitID == SyncedInstance<Config>.Instance.team2Suit.Value)
							{
								val2.SwitchSuitToThis(__instance);
							}
						}
					}
				}
			}
			if (__instance.currentSuitID == 0)
			{
				((Graphic)__instance.usernameBillboardText).color = Color.red;
			}
			if (__instance.currentSuitID == 3)
			{
				((Graphic)__instance.usernameBillboardText).color = Color.blue;
			}
			if (__instance.currentSuitID == 2)
			{
				((Graphic)__instance.usernameBillboardText).color = Color.yellow;
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch(typeof(RoundManager), "OnDestroy")]
		[HarmonyPostfix]
		private static void undo(RoundManager __instance)
		{
			Plugin.startLogic = false;
			Plugin.teams.Clear();
			Plugin.initiated.Clear();
		}

		[HarmonyPatch(typeof(RoundManager), "Update")]
		[HarmonyPostfix]
		private static void checkIfDead(RoundManager __instance)
		{
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			if (!StartOfRound.Instance.unlockablesList.unlockables[2].alreadyUnlocked && (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost))
			{
				if (SyncedInstance<Config>.Instance.team2Suit.Value == 0 || SyncedInstance<Config>.Instance.team1Suit.Value == 1 || SyncedInstance<Config>.Instance.team1Suit.Value == 24 || SyncedInstance<Config>.Instance.team1Suit.Value == 3)
				{
					UnlockShipItem(StartOfRound.Instance, SyncedInstance<Config>.Instance.team1Suit.Value, "Pajama Suit");
				}
				if (SyncedInstance<Config>.Instance.team2Suit.Value == 0 || SyncedInstance<Config>.Instance.team2Suit.Value == 1 || SyncedInstance<Config>.Instance.team2Suit.Value == 24 || SyncedInstance<Config>.Instance.team2Suit.Value == 3)
				{
					UnlockShipItem(StartOfRound.Instance, SyncedInstance<Config>.Instance.team2Suit.Value, "Pajama Suit");
				}
				UnlockShipItem(StartOfRound.Instance, 2, "Hazard Suit");
			}
			if (Plugin.startLogic)
			{
				if (StartOfRound.Instance.shipHasLanded)
				{
					if (Plugin.curHour >= Plugin.nextHour)
					{
					}
					int num = 0;
					int num2 = 0;
					PlayerControllerB[] allPlayerScripts = RoundManager.Instance.playersManager.allPlayerScripts;
					foreach (PlayerControllerB val in allPlayerScripts)
					{
						if (Plugin.teams.ContainsKey(val) && !val.isPlayerDead && val.isPlayerControlled)
						{
							if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, val, 0) == 0)
							{
								num++;
							}
							if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, val, 0) == 1)
							{
								num2++;
							}
						}
					}
					if (num == 0)
					{
						Plugin.startLogic = false;
						Plugin.redScore = -400;
						if (GameNetworkManager.Instance.isHostingGame)
						{
							HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team1Name.Value + " was team-wiped...", -1);
							StartOfRound.Instance.EndGameServerRpc(-1);
						}
					}
					if (num2 == 0)
					{
						Plugin.startLogic = false;
						Plugin.blueScore = -400;
						if (GameNetworkManager.Instance.isHostingGame)
						{
							HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team2Name.Value + " was team-wiped...", -1);
							StartOfRound.Instance.EndGameServerRpc(-1);
						}
					}
				}
				((TMP_Text)HudManagerPatch._blueTeam).text = Plugin.blueScore.ToString();
				((TMP_Text)HudManagerPatch._seperator).text = "vs";
				((TMP_Text)HudManagerPatch._redTeam).text = Plugin.redScore.ToString();
				((TMP_Text)HudManagerPatch._seperator).rectTransform.anchoredPosition = new Vector2((float)((((TMP_Text)HudManagerPatch._redTeam).text.Length + 1) * 8), 2f);
				((TMP_Text)HudManagerPatch._blueTeam).rectTransform.anchoredPosition = new Vector2((float)((((TMP_Text)HudManagerPatch._redTeam).text.Length + 1 + ((TMP_Text)HudManagerPatch._seperator).text.Length + 1) * 8), 2f);
			}
			else
			{
				((TMP_Text)HudManagerPatch._redTeam).text = "";
				((TMP_Text)HudManagerPatch._blueTeam).text = "";
				((TMP_Text)HudManagerPatch._seperator).text = "";
			}
		}

		[HarmonyPatch(typeof(TimeOfDay), "UpdateProfitQuotaCurrentTime")]
		[HarmonyPostfix]
		public static void noDeadline(RoundManager __instance)
		{
			TimeOfDay.Instance.timeUntilDeadline = (int)(TimeOfDay.Instance.totalTime * (float)TimeOfDay.Instance.quotaVariables.deadlineDaysAmount);
			((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "Competitive\nCompany";
		}

		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void gammaPatch(RoundManager __instance)
		{
			Plugin.warnship = true;
			Plugin.blueScore = 0;
			Plugin.startLogic = true;
			Plugin.redScore = 0;
		}

		[HarmonyPatch(typeof(StartMatchLever), "LeverAnimation")]
		[HarmonyPrefix]
		private static bool noLeave(StartMatchLever __instance)
		{
			int num = (int)(TimeOfDay.Instance.normalizedTimeOfDay * (60f * (float)TimeOfDay.Instance.numberOfHours)) + 360;
			int num2 = (int)Mathf.Floor((float)(num / 60));
			if (num2 < SyncedInstance<Config>.Instance.graceTime.Value && Plugin.warnship && RoundManager.Instance.playersManager.shipHasLanded)
			{
				HUDManager.Instance.DisplayTip("Competitive Company", "You can't leave this early!\nIf you want to leave anyways, You will be fined " + SyncedInstance<Config>.Instance.fineAmount.Value + "$ and the ship will leave.", true, false, "LC_Tip1");
				Plugin.warnship = false;
				return false;
			}
			return true;
		}

		private static void UnlockShipItem(StartOfRound instance, int unlockableID, string name)
		{
			try
			{
				MethodInfo method = ((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic);
				method.Invoke(instance, new object[1] { unlockableID });
			}
			catch (NullReferenceException arg)
			{
				Plugin.Instance.mls.LogError((object)$"Could not invoke UnlockShipObject method: {arg}");
			}
		}

		public static Vector3 GetPlayerSpawnPosition(int playerNum, bool simpleTeleport = false)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			Transform[] playerSpawnPositions = StartOfRound.Instance.playerSpawnPositions;
			if (simpleTeleport)
			{
				return playerSpawnPositions[0].position;
			}
			Debug.DrawRay(playerSpawnPositions[playerNum].position, Vector3.up, Color.red, 15f);
			if (!Physics.CheckSphere(playerSpawnPositions[playerNum].position, 0.2f, 67108864, (QueryTriggerInteraction)1))
			{
				return playerSpawnPositions[playerNum].position;
			}
			if (!Physics.CheckSphere(playerSpawnPositions[playerNum].position + Vector3.up, 0.2f, 67108864, (QueryTriggerInteraction)1))
			{
				return playerSpawnPositions[playerNum].position + Vector3.up * 0.5f;
			}
			for (int i = 0; i < playerSpawnPositions.Length; i++)
			{
				if (i != playerNum)
				{
					Debug.DrawRay(playerSpawnPositions[i].position, Vector3.up, Color.green, 15f);
					if (!Physics.CheckSphere(playerSpawnPositions[i].position, 0.12f, -67108865, (QueryTriggerInteraction)1))
					{
						return playerSpawnPositions[i].position;
					}
					if (!Physics.CheckSphere(playerSpawnPositions[i].position + Vector3.up, 0.12f, 67108864, (QueryTriggerInteraction)1))
					{
						return playerSpawnPositions[i].position + Vector3.up * 0.5f;
					}
				}
			}
			Random random = new Random(65);
			float y = playerSpawnPositions[0].position.y;
			Vector3 val = default(Vector3);
			for (int j = 0; j < 15; j++)
			{
				Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				int minValue = (int)((Bounds)(ref bounds)).min.x;
				bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				float num = random.Next(minValue, (int)((Bounds)(ref bounds)).max.x);
				bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				int minValue2 = (int)((Bounds)(ref bounds)).min.z;
				bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				((Vector3)(ref val))..ctor(num, y, (float)random.Next(minValue2, (int)((Bounds)(ref bounds)).max.z));
				val = ((Component)StartOfRound.Instance.shipInnerRoomBounds).transform.InverseTransformPoint(val);
				Debug.DrawRay(val, Vector3.up, Color.yellow, 15f);
				if (!Physics.CheckSphere(val, 0.12f, 67108864, (QueryTriggerInteraction)1))
				{
					return playerSpawnPositions[j].position;
				}
			}
			return playerSpawnPositions[0].position + Vector3.up * 0.5f;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
		[HarmonyPostfix]
		private static void undo(StartOfRound __instance)
		{
			Plugin.startLogic = false;
			Plugin.teams.Clear();
			if (!((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer && !((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>(true);
				UnlockableSuit[] array2 = array;
				foreach (UnlockableSuit val2 in array2)
				{
					if (val2.suitID == 2)
					{
						val2.SwitchSuitToThis(val);
					}
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
		[HarmonyPrefix]
		private static void teams()
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((!val.disconnectedMidGame && !val.isPlayerDead && !val.isPlayerControlled) || !Plugin.teams.ContainsKey(val))
				{
					continue;
				}
				if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, val, 0) == 0)
				{
					StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add(SyncedInstance<Config>.Instance.team1Name.Value + " Team");
					if (Plugin.redScore >= Plugin.blueScore)
					{
						StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add("Won the game!");
					}
					else
					{
						StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add("Lost the game..");
					}
				}
				if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, val, 0) == 1)
				{
					StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add(SyncedInstance<Config>.Instance.team2Name.Value + " Team");
					if (Plugin.blueScore >= Plugin.redScore)
					{
						StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add("Won the game!");
					}
					else
					{
						StartOfRound.Instance.gameStats.allPlayerStats[val.playerClientId].playerNotes.Add("Lost the game..");
					}
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "StartGame")]
		[HarmonyPostfix]
		private static void gammaPatch(StartOfRound __instance)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			if (!((NetworkBehaviour)__instance).IsServer && !((NetworkBehaviour)__instance).IsHost)
			{
				return;
			}
			PlayerControllerB[] array = (PlayerControllerB[])RoundManager.Instance.playersManager.allPlayerScripts.Clone();
			Randomizer.Randomize(array);
			PlayerControllerB[] array2 = array;
			foreach (PlayerControllerB val in array2)
			{
				if (val.currentSuitID == SyncedInstance<Config>.Instance.team1Suit.Value)
				{
					num2++;
				}
				if (val.currentSuitID == SyncedInstance<Config>.Instance.team2Suit.Value)
				{
					num++;
				}
			}
			PlayerControllerB[] array3 = array;
			foreach (PlayerControllerB val2 in array3)
			{
				if (!val2.isPlayerControlled)
				{
					continue;
				}
				if (val2.currentSuitID != SyncedInstance<Config>.Instance.team1Suit.Value && val2.currentSuitID != SyncedInstance<Config>.Instance.team2Suit.Value)
				{
					if (num2 <= num)
					{
						HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + val2.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team1Name.Value + "!", -1);
						num3 = 0;
						num2++;
					}
					else
					{
						HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + val2.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team2Name.Value + "!", -1);
						num++;
						num3 = 1;
					}
					if (Plugin.teams.ContainsKey(val2))
					{
						Plugin.teams.Remove(val2);
					}
					Plugin.teams.Add(val2, num3);
				}
				if (val2.currentSuitID == SyncedInstance<Config>.Instance.team1Suit.Value)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + val2.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team1Name.Value + "!", -1);
					if (Plugin.teams.ContainsKey(val2))
					{
						Plugin.teams.Remove(val2);
					}
					Plugin.teams.Add(val2, 0);
				}
				if (val2.currentSuitID == SyncedInstance<Config>.Instance.team2Suit.Value)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + val2.playerUsername + " was put on " + SyncedInstance<Config>.Instance.team2Name.Value + "!", -1);
					if (Plugin.teams.ContainsKey(val2))
					{
						Plugin.teams.Remove(val2);
					}
					Plugin.teams.Add(val2, 1);
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "EndGameClientRpc")]
		[HarmonyPostfix]
		private static void fine(StartOfRound __instance, ref int playerClientId)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (playerClientId == -1)
			{
				return;
			}
			StartOfRound.Instance.localPlayerController.isInElevator = true;
			StartOfRound.Instance.localPlayerController.isInHangarShipRoom = true;
			StartOfRound.Instance.localPlayerController.isInsideFactory = false;
			StartOfRound.Instance.localPlayerController.TeleportPlayer(RoundManagerPatch.GetPlayerSpawnPosition((int)StartOfRound.Instance.localPlayerController.playerClientId, simpleTeleport: true), false, 0f, false, true);
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerClientId];
			if (Plugin.finedForShip)
			{
				return;
			}
			Plugin.finedForShip = true;
			int num = (int)(TimeOfDay.Instance.normalizedTimeOfDay * (60f * (float)TimeOfDay.Instance.numberOfHours)) + 360;
			int num2 = (int)Mathf.Floor((float)(num / 60));
			if (!Plugin.teams.ContainsKey(val) || num2 >= SyncedInstance<Config>.Instance.graceTime.Value)
			{
				return;
			}
			if (DictionaryExtensions.Get<PlayerControllerB, int>((IDictionary<PlayerControllerB, int>)Plugin.teams, val, 0) == 0)
			{
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team1ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team1Name.Value + " <color=red>was fined for leaving the ship early...", -1);
					HUDManager.Instance.DisplayTip("Fined!", SyncedInstance<Config>.Instance.team1Name.Value + " was fined for leaving!", true, false, "LC_Tip1");
				}
				Plugin.redScore -= SyncedInstance<Config>.Instance.fineAmount.Value;
			}
			else
			{
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer || ((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
				{
					HUDManager.Instance.AddTextToChatOnServer("<color=" + SyncedInstance<Config>.Instance.team2ColorCode.Value + ">" + SyncedInstance<Config>.Instance.team2Name.Value + " <color=red>was fined for leaving the ship early...", -1);
					HUDManager.Instance.DisplayTip("Fined!", SyncedInstance<Config>.Instance.team1Name.Value + " was fined for leaving!", true, false, "LC_Tip1");
				}
				Plugin.blueScore -= SyncedInstance<Config>.Instance.fineAmount.Value;
			}
		}
	}
}