Decompiled source of MilkMolars v0.3.0

BepInEx/plugins/MilkMolars/Snowlance.MilkMolars.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InteractiveTerminalAPI.UI;
using InteractiveTerminalAPI.UI.Application;
using InteractiveTerminalAPI.UI.Cursor;
using InteractiveTerminalAPI.UI.Page;
using InteractiveTerminalAPI.UI.Screen;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MilkMolars.Upgrades;
using MoreShipUpgrades.Managers;
using MoreShipUpgrades.Misc.TerminalNodes;
using Newtonsoft.Json;
using Snowlance.MilkMolars.NetcodePatcher;
using TMPro;
using Unity.Netcode;
using UnityEngine;

[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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("Snowlance.MilkMolars")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+804dfef0a9e41c272329a3bb86b77272def895a6")]
[assembly: AssemblyProduct("MilkMolars")]
[assembly: AssemblyTitle("Snowlance.MilkMolars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MilkMolars
{
	internal class LGUCompatibility
	{
		private static readonly ManualLogSource logger = Plugin.LoggerInstance;

		private static bool? _enabled;

		internal static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.malco.lethalcompany.moreshipupgrades") && Plugin.configLGUCompatible.Value;
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static List<MilkMolarUpgrade> GetLGUUpgrades(bool mega = false)
		{
			logger.LogDebug((object)("GetLGUUpgrades: " + enabled));
			List<MilkMolarUpgrade> list = new List<MilkMolarUpgrade>();
			if (!mega)
			{
				CustomTerminalNode[] array = UpgradeBus.Instance.terminalNodes.Where((CustomTerminalNode x) => x.Visible && !x.SharedUpgrade && (x.UnlockPrice > 0 || (x.OriginalName == "NV Headset Batteries" && x.Prices.Length != 0 && x.Prices[0] != 0))).ToArray();
				CustomTerminalNode[] array2 = array;
				foreach (CustomTerminalNode val in array2)
				{
					logger.LogDebug((object)("Adding " + val.OriginalName));
					MilkMolarUpgrade milkMolarUpgrade = new LGUUpgrade();
					milkMolarUpgrade.name = val.OriginalName;
					milkMolarUpgrade.title = val.Name;
					milkMolarUpgrade.LGUUpgrade = true;
					if (val.Prices.Length != 0)
					{
						milkMolarUpgrade.type = MilkMolarUpgrade.UpgradeType.LGUTier;
						List<int> list2 = new List<int>();
						list2.Add(0);
						list2.Add((int)Math.Ceiling((float)val.UnlockPrice / Plugin.configLGUMilkMolarContributeAmount.Value));
						int[] prices = val.Prices;
						foreach (int num in prices)
						{
							list2.Add((int)Math.Ceiling((float)num / Plugin.configLGUMilkMolarContributeAmount.Value));
						}
						if (val.CurrentUpgrade == 0)
						{
							if (val.Unlocked)
							{
								milkMolarUpgrade.currentTier = 1;
							}
							else
							{
								milkMolarUpgrade.currentTier = 0;
							}
						}
						else
						{
							milkMolarUpgrade.currentTier = val.CurrentUpgrade + 1;
						}
						milkMolarUpgrade.costsPerTier = list2.ToArray();
						logger.LogDebug((object)("Upgrade costs: " + string.Join(", ", milkMolarUpgrade.costsPerTier)));
					}
					else
					{
						milkMolarUpgrade.type = MilkMolarUpgrade.UpgradeType.LGUOneTimeUnlock;
						milkMolarUpgrade.cost = (int)Math.Ceiling((float)val.UnlockPrice / Plugin.configLGUMilkMolarContributeAmount.Value);
					}
					list.Add(milkMolarUpgrade);
				}
				Plugin.LoggerInstance.LogDebug((object)list.Count);
			}
			else
			{
				CustomTerminalNode[] array3 = UpgradeBus.Instance.terminalNodes.Where((CustomTerminalNode x) => x.Visible && x.SharedUpgrade && (x.UnlockPrice > 0 || (x.OriginalName == "NV Headset Batteries" && x.Prices.Length != 0 && x.Prices[0] != 0))).ToArray();
				logger.LogDebug((object)("Got " + array3.Length + " nodes"));
				CustomTerminalNode[] array4 = array3;
				foreach (CustomTerminalNode val2 in array4)
				{
					logger.LogDebug((object)("Adding " + val2.OriginalName));
					MilkMolarUpgrade milkMolarUpgrade2 = new LGUUpgrade();
					milkMolarUpgrade2.name = val2.OriginalName;
					milkMolarUpgrade2.title = val2.Name;
					milkMolarUpgrade2.LGUUpgrade = true;
					if (val2.Prices.Length != 0)
					{
						milkMolarUpgrade2.type = MilkMolarUpgrade.UpgradeType.LGUTier;
						List<int> list3 = new List<int>();
						list3.Add(0);
						list3.Add((int)Math.Ceiling((float)val2.UnlockPrice / Plugin.configLGUMegaMilkMolarContributeAmount.Value));
						int[] prices2 = val2.Prices;
						foreach (int num2 in prices2)
						{
							list3.Add((int)Math.Ceiling((float)num2 / Plugin.configLGUMegaMilkMolarContributeAmount.Value));
						}
						if (val2.CurrentUpgrade == 0)
						{
							if (val2.Unlocked)
							{
								milkMolarUpgrade2.currentTier = 1;
							}
							else
							{
								milkMolarUpgrade2.currentTier = 0;
							}
						}
						else
						{
							milkMolarUpgrade2.currentTier = val2.CurrentUpgrade + 1;
						}
						milkMolarUpgrade2.costsPerTier = list3.ToArray();
						logger.LogDebug((object)("Upgrade costs: " + string.Join(", ", milkMolarUpgrade2.costsPerTier)));
					}
					else
					{
						milkMolarUpgrade2.type = MilkMolarUpgrade.UpgradeType.LGUOneTimeUnlock;
						milkMolarUpgrade2.cost = (int)Math.Ceiling((float)val2.UnlockPrice / Plugin.configLGUMegaMilkMolarContributeAmount.Value);
						logger.LogDebug((object)("One time upgrade costs: " + milkMolarUpgrade2.cost));
					}
					list.Add(milkMolarUpgrade2);
				}
			}
			return list;
		}
	}
	internal class LGUUpgrade : MilkMolarUpgrade
	{
		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public override void ActivateCurrentTierUpgrade()
		{
			base.ActivateCurrentTierUpgrade();
			CustomTerminalNode val = UpgradeBus.Instance.terminalNodes.Where((CustomTerminalNode x) => x.OriginalName == name).FirstOrDefault();
			if (val != null)
			{
				if (!val.Unlocked)
				{
					LguStore.Instance.HandleUpgrade(val, false);
				}
				else if (val.Unlocked && val.MaxUpgrade > val.CurrentUpgrade)
				{
					LguStore.Instance.HandleUpgrade(val, true);
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public override void ActivateOneTimeUpgrade()
		{
			base.ActivateOneTimeUpgrade();
			CustomTerminalNode val = UpgradeBus.Instance.terminalNodes.Where((CustomTerminalNode x) => x.OriginalName == name).FirstOrDefault();
			if (val != null)
			{
				LguStore.Instance.HandleUpgrade(val, false);
			}
		}
	}
	internal class MegaMilkMolarBehavior : PhysicsProp
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		public AudioSource ItemSFX;

		public ScanNodeProperties scanNode;

		private Plugin.ActivateMethod ActivationMethod;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			((Behaviour)ItemSFX).enabled = true;
			scanNode.subText = "";
			ActivationMethod = Plugin.configMegaMilkMolarActivateMethod.Value;
			if (ActivationMethod == Plugin.ActivateMethod.Use)
			{
				((GrabbableObject)this).itemProperties.toolTips[0] = "Activate [LMB]";
			}
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				((GrabbableObject)this).customGrabTooltip = "Activate [E]";
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (ActivationMethod == Plugin.ActivateMethod.ReturnToShip && ((GrabbableObject)this).isInShipRoom && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).playerHeldBy.isInHangarShipRoom)
			{
				ActivateMolar();
			}
		}

		public override void InteractItem()
		{
			((GrabbableObject)this).InteractItem();
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				ActivateMolar();
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && ActivationMethod == Plugin.ActivateMethod.Use)
			{
				ActivateMolar();
			}
		}

		public void ActivateMolar()
		{
			if (Plugin.configPlaySound.Value)
			{
				ItemSFX.Play();
			}
			((GrabbableObject)this).playerHeldBy.DespawnHeldObject();
			MilkMolarController.AddMegaMilkMolar();
		}

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

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "MegaMilkMolarBehavior";
		}
	}
	internal class MilkMolarBehavior : PhysicsProp
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		public AudioSource ItemSFX;

		public ScanNodeProperties scanNode;

		private Plugin.ActivateMethod ActivationMethod;

		private bool Shared;

		public PlayerControllerB lastPlayerHeldBy;

		public PlayerControllerB playerFoundBy;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			((Behaviour)ItemSFX).enabled = true;
			scanNode.subText = "";
			ActivationMethod = Plugin.configMilkMolarActivateMethod.Value;
			Shared = Plugin.configSharedMilkMolars.Value;
			if (ActivationMethod == Plugin.ActivateMethod.Use)
			{
				((GrabbableObject)this).itemProperties.toolTips[0] = "Activate [LMB]";
			}
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				((GrabbableObject)this).customGrabTooltip = "Activate [E]";
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				lastPlayerHeldBy = ((GrabbableObject)this).playerHeldBy;
				if ((Object)(object)playerFoundBy == (Object)null)
				{
					playerFoundBy = ((GrabbableObject)this).playerHeldBy;
				}
			}
			if (ActivationMethod == Plugin.ActivateMethod.ReturnToShip && ((GrabbableObject)this).isInShipRoom && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).playerHeldBy.isInHangarShipRoom)
			{
				ActivateMolar();
			}
			if (ActivationMethod == Plugin.ActivateMethod.Grab && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).isHeld && !((GrabbableObject)this).isPocketed)
			{
				ActivateMolar();
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && ActivationMethod == Plugin.ActivateMethod.Use)
			{
				ActivateMolar();
			}
		}

		public void ActivateMolar()
		{
			ItemSFX.Play();
			((GrabbableObject)this).playerHeldBy.DespawnHeldObject();
			if (Plugin.configUpgradePointsToFinder.Value)
			{
				MilkMolarController.AddMilkMolar(playerFoundBy);
			}
			else
			{
				MilkMolarController.AddMilkMolar(((GrabbableObject)this).playerHeldBy);
			}
		}

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

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "MilkMolarBehavior";
		}
	}
	public static class MilkMolarController
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		internal static int MilkMolars = 0;

		internal static bool InUpgradeUI = false;

		internal static bool InMegaUpgradeUI = false;

		internal static List<MilkMolarUpgrade> MilkMolarUpgrades = new List<MilkMolarUpgrade>();

		public static List<MilkMolarUpgrade> ExtraMilkMolarUpgrades = new List<MilkMolarUpgrade>();

		public static List<MilkMolarUpgrade> ExtraMegaMilkMolarUpgrades = new List<MilkMolarUpgrade>();

		internal static void Init()
		{
			Plugin.LoggerInstance.LogDebug((object)"Initing milk molar controller");
			NetworkHandler.LoadDataFromFile();
		}

		internal static void RefreshLGUUpgrades(bool mega)
		{
			if (mega)
			{
				NetworkHandler.MegaMilkMolarUpgrades.RemoveAll((MilkMolarUpgrade x) => x.LGUUpgrade);
				NetworkHandler.MegaMilkMolarUpgrades.AddRange(LGUCompatibility.GetLGUUpgrades(mega));
			}
			else
			{
				MilkMolarUpgrades.RemoveAll((MilkMolarUpgrade x) => x.LGUUpgrade);
				MilkMolarUpgrades.AddRange(LGUCompatibility.GetLGUUpgrades(mega));
			}
		}

		internal static List<MilkMolarUpgrade> GetUpgrades(bool mega = false, bool skipLGU = false)
		{
			List<MilkMolarUpgrade> list = new List<MilkMolarUpgrade>();
			if (!mega)
			{
				if (!LGUCompatibility.enabled)
				{
					list.Add(new MilkMolarUpgrade("FallDamageReduction", "Fall Damage Reduction", MilkMolarUpgrade.UpgradeType.TierPercent, Plugin.configFallDamageReductionUpgrade.Value));
				}
				else
				{
					List<MilkMolarUpgrade> list2 = new List<MilkMolarUpgrade>();
					list2 = LGUCompatibility.GetLGUUpgrades(mega);
					list.AddRange(list2);
				}
				list.Add(new MilkMolarUpgrade("DamageResistance", "Damage Resistance", MilkMolarUpgrade.UpgradeType.TierPercent, Plugin.configDamageResistanceUpgrade.Value));
				if (ExtraMilkMolarUpgrades.Count > 0)
				{
					list.AddRange(ExtraMilkMolarUpgrades);
				}
				Plugin.LoggerInstance.LogDebug((object)list.Count);
			}
			else
			{
				if (LGUCompatibility.enabled)
				{
					logger.LogDebug((object)("Getting lguUpgrades. mega: " + mega));
					List<MilkMolarUpgrade> list3 = new List<MilkMolarUpgrade>();
					list3 = LGUCompatibility.GetLGUUpgrades(mega);
					list.AddRange(list3);
				}
				MilkMolarUpgrade item = new MilkMolarUpgrade("keepItemsOnShipChance", "Keep Items On Ship", MilkMolarUpgrade.UpgradeType.TierPercent, Plugin.configKeepItemsOnShipChanceUpgrade.Value);
				list.Add(item);
				RevivePlayerUpgrade revivePlayerUpgrade = new RevivePlayerUpgrade();
				revivePlayerUpgrade.name = "revivePlayer";
				revivePlayerUpgrade.title = "Revive Player";
				revivePlayerUpgrade.type = MilkMolarUpgrade.UpgradeType.Repeatable;
				revivePlayerUpgrade.cost = Plugin.configRevivePlayerUpgrade.Value;
				list.Add(revivePlayerUpgrade);
				if (ExtraMegaMilkMolarUpgrades.Count > 0)
				{
					list.AddRange(ExtraMegaMilkMolarUpgrades);
				}
			}
			return list;
		}

		public static void RegisterMilkMolarUpgrade(MilkMolarUpgrade upgrade)
		{
			MilkMolarUpgrade upgrade2 = upgrade;
			if (MilkMolarUpgrades.Where((MilkMolarUpgrade x) => x.name == upgrade2.name).FirstOrDefault() == null)
			{
				MilkMolarUpgrades.Add(upgrade2);
			}
			else
			{
				Plugin.LoggerInstance.LogError((object)("Error: Theres already a Milk Molar upgrade with the name: " + upgrade2.name));
			}
		}

		public static void RegisterMegaMilkMolarUpgrade(MilkMolarUpgrade upgrade)
		{
			MilkMolarUpgrade upgrade2 = upgrade;
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				if (NetworkHandler.MegaMilkMolarUpgrades.Where((MilkMolarUpgrade x) => x.name == upgrade2.name).FirstOrDefault() == null)
				{
					NetworkHandler.MegaMilkMolarUpgrades.Add(upgrade2);
				}
				else
				{
					Plugin.LoggerInstance.LogError((object)("Error: Theres already a Mega Milk Molar upgrade with the name: " + upgrade2.name));
				}
			}
		}

		public static MilkMolarUpgrade GetUpgradeByName(string name, bool megaUpgrade = false)
		{
			string name2 = name;
			if (megaUpgrade)
			{
				return NetworkHandler.MegaMilkMolarUpgrades.Find((MilkMolarUpgrade x) => x.name == name2);
			}
			return MilkMolarUpgrades.Find((MilkMolarUpgrade x) => x.name == name2);
		}

		internal static void AddMilkMolar(PlayerControllerB player)
		{
			NetworkHandler.Instance.AddMilkMolarServerRpc(player.playerSteamId);
		}

		internal static void AddMegaMilkMolar()
		{
			NetworkHandler.Instance.AddMegaMilkMolarServerRpc();
		}

		internal static bool BuyMilkMolarUpgrade(MilkMolarUpgrade upgrade)
		{
			logger.LogDebug((object)("Attempting to buy Milk Molar upgrade: " + upgrade.name));
			if (upgrade.type == MilkMolarUpgrade.UpgradeType.Repeatable)
			{
				logger.LogDebug((object)"Upgrade type is Repeatable. Checking if we have enough Milk Molars.");
				if (MilkMolars >= upgrade.cost)
				{
					MilkMolars -= upgrade.cost;
					logger.LogDebug((object)"Conditions met. Activating Repeatable upgrade and updating server.");
					upgrade.ActivateRepeatableUpgrade();
					return true;
				}
				logger.LogDebug((object)"Not enough Milk Molars for Repeatable upgrade.");
				return false;
			}
			if (upgrade.type == MilkMolarUpgrade.UpgradeType.OneTimeUnlock)
			{
				logger.LogDebug((object)"Upgrade type is OneTimeUnlock. Checking if upgrade is not fully upgraded and if we have enough Milk Molars.");
				if (!upgrade.fullyUpgraded && MilkMolars >= upgrade.cost)
				{
					MilkMolars -= upgrade.cost;
					logger.LogDebug((object)"Conditions met. Activating OneTimeUnlock upgrade and updating server.");
					upgrade.ActivateOneTimeUpgrade();
					return true;
				}
				logger.LogDebug((object)"Not enough Milk Molars or upgrade is fully upgraded.");
				return false;
			}
			logger.LogDebug((object)"Checking if upgrade is not fully upgraded and if we have enough Milk Molars for next tier.");
			logger.LogDebug((object)("Current Tier: " + upgrade.currentTier));
			if (!upgrade.fullyUpgraded && MilkMolars >= upgrade.nextTierCost)
			{
				MilkMolars -= upgrade.nextTierCost;
				logger.LogDebug((object)"Conditions met. Going to next tier, activating current tier upgrade, and updating server.");
				upgrade.GoToNextTier();
				upgrade.ActivateCurrentTierUpgrade();
				return true;
			}
			logger.LogDebug((object)"Upgrade purchase failed. Conditions not met.");
			return false;
		}

		internal static bool BuyMegaMilkMolarUpgrade(MilkMolarUpgrade upgrade, bool callRPC = false)
		{
			logger.LogDebug((object)("Attempting to buy Mega Milk Molar upgrade: " + upgrade.name));
			if (upgrade.type == MilkMolarUpgrade.UpgradeType.Repeatable)
			{
				logger.LogDebug((object)"Upgrade type is Repeatable. Checking if we have enough Mega Milk Molars or RPC is not required.");
				if (NetworkHandler.MegaMilkMolars.Value >= upgrade.cost || !callRPC)
				{
					logger.LogDebug((object)"Conditions met. Activating Repeatable upgrade.");
					if (callRPC)
					{
						logger.LogDebug((object)"Calling server RPC to buy upgrade.");
						NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.name, upgrade.cost, Plugin.localPlayerId, upgrade.LGUUpgrade);
					}
					upgrade.ActivateRepeatableUpgrade();
					return true;
				}
				return false;
			}
			if (upgrade.type == MilkMolarUpgrade.UpgradeType.OneTimeUnlock || upgrade.type == MilkMolarUpgrade.UpgradeType.LGUOneTimeUnlock)
			{
				logger.LogDebug((object)"Upgrade type is OneTimeUnlock. Checking if upgrade is not fully upgraded and if we have enough Mega Milk Molars or RPC is not required.");
				if ((!upgrade.fullyUpgraded && NetworkHandler.MegaMilkMolars.Value >= upgrade.cost) || !callRPC)
				{
					logger.LogDebug((object)"Conditions met. Activating OneTimeUnlock upgrade.");
					if (callRPC)
					{
						logger.LogDebug((object)"Calling server RPC to buy upgrade.");
						NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.name, upgrade.cost, Plugin.localPlayerId, upgrade.LGUUpgrade);
					}
					upgrade.ActivateOneTimeUpgrade();
					return true;
				}
				return false;
			}
			logger.LogDebug((object)"Checking if upgrade is not fully upgraded and if we have enough Mega Milk Molars or RPC is not required.");
			logger.LogDebug((object)("Current Tier: " + upgrade.currentTier));
			if ((!upgrade.fullyUpgraded && NetworkHandler.MegaMilkMolars.Value >= upgrade.nextTierCost) || !callRPC)
			{
				logger.LogDebug((object)"Conditions met. Going to next tier and activating current tier upgrade.");
				if (callRPC)
				{
					logger.LogDebug((object)"Calling server RPC to buy upgrade.");
					NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.name, upgrade.nextTierCost, Plugin.localPlayerId, upgrade.LGUUpgrade);
				}
				upgrade.GoToNextTier();
				upgrade.ActivateCurrentTierUpgrade();
				return true;
			}
			logger.LogDebug((object)"Upgrade purchase failed. Conditions not met.");
			return false;
		}

		internal static void SpawnMolarsInLevel()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			List<RandomScrapSpawn> list = (from x in Object.FindObjectsOfType<RandomScrapSpawn>()
				where !x.spawnUsed
				select x).ToList();
			List<string> source = Plugin.configMilkMolarSpawnAmount.Value.Split(",").ToList();
			string text = source.Where((string x) => x.Trim().Split(":")[0] == ((Object)RoundManager.Instance.currentLevel).name).FirstOrDefault();
			if (text == null)
			{
				logger.LogError((object)"Unable to spawn molars, couldnt find level in MilkMolarSpawnAmount config");
				return;
			}
			string[] array = text.Trim().Split(":")[1].Split("-");
			int num = int.Parse(array[0]);
			int num2 = int.Parse(array[1]);
			int num3 = Random.Range(num, num2 + 1);
			for (int i = 0; i < num3; i++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				int index = Random.Range(0, list.Count);
				RandomScrapSpawn val = list[index];
				Vector3 val2 = ((Component)val).transform.position;
				if (val.spawnedItemsCopyPosition)
				{
					list.RemoveAt(index);
				}
				else
				{
					val2 = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(((Component)val).transform.position, val.itemSpawnRange, RoundManager.Instance.navHit);
				}
				Item val3 = Items.LethalLibItemList.Where((Item x) => ((Object)x).name == "MilkMolarItem").FirstOrDefault();
				if ((Object)(object)val3 == (Object)null)
				{
					logger.LogError((object)"Unable to find molar in LethalLibItemList");
					return;
				}
				GameObject val4 = Object.Instantiate<GameObject>(val3.spawnPrefab, val2, Quaternion.identity, StartOfRound.Instance.propsContainer);
				val4.GetComponent<GrabbableObject>().fallTime = 0f;
				val4.GetComponent<NetworkObject>().Spawn(false);
			}
			source = Plugin.configMegaMilkMolarSpawnAmount.Value.Split(",").ToList();
			text = source.Where((string x) => x.Trim().Split(":")[0] == ((Object)RoundManager.Instance.currentLevel).name).FirstOrDefault();
			if (text == null)
			{
				logger.LogError((object)"Unable to spawn molars, couldnt find level in MegaMilkMolarSpawnAmount config");
				return;
			}
			array = text.Trim().Split(":")[1].Split("-");
			num = int.Parse(array[0]);
			num2 = int.Parse(array[1]);
			num3 = Random.Range(num, num2 + 1);
			for (int j = 0; j < num3; j++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				int index2 = Random.Range(0, list.Count);
				RandomScrapSpawn val5 = list[index2];
				Vector3 val6 = ((Component)val5).transform.position;
				if (val5.spawnedItemsCopyPosition)
				{
					list.RemoveAt(index2);
				}
				else
				{
					val6 = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(((Component)val5).transform.position, val5.itemSpawnRange, RoundManager.Instance.navHit);
				}
				Item val7 = Items.LethalLibItemList.Where((Item x) => ((Object)x).name == "MegaMilkMolarItem").FirstOrDefault();
				if ((Object)(object)val7 == (Object)null)
				{
					logger.LogError((object)"Unable to find molar in LethalLibItemList");
					break;
				}
				GameObject val8 = Object.Instantiate<GameObject>(val7.spawnPrefab, val6, Quaternion.identity, StartOfRound.Instance.propsContainer);
				val8.GetComponent<GrabbableObject>().fallTime = 0f;
				val8.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	public class MilkMolarUpgrade
	{
		public enum UpgradeType
		{
			TierNumber,
			TierPercent,
			OneTimeUnlock,
			Repeatable,
			LGUTier,
			LGUOneTimeUnlock
		}

		private static ManualLogSource logger = Plugin.LoggerInstance;

		private const string upgradePoint = "⬜";

		private const string filledUpgradePoint = "⬛";

		private const string tooth = "\ud83e\uddb7";

		public string name;

		public string title;

		public UpgradeType type;

		public int cost;

		public bool unlocked;

		public int currentTier = 0;

		public float[] amountPerTier;

		public int[] costsPerTier;

		public bool fullyUpgraded;

		public bool LGUUpgrade = false;

		[JsonIgnore]
		public int count => costsPerTier.Length;

		[JsonIgnore]
		public int maxTier => count - 1;

		[JsonIgnore]
		public float currentTierPercent => amountPerTier[currentTier] / 100f;

		[JsonIgnore]
		public float currentTierAmount => amountPerTier[currentTier];

		[JsonIgnore]
		public int nextTierCost => costsPerTier[currentTier + 1];

		public MilkMolarUpgrade()
		{
		}

		public MilkMolarUpgrade(string name, string title, UpgradeType type, string tierString = null)
		{
			logger.LogDebug((object)("Adding " + name));
			this.name = name;
			this.title = title;
			this.type = type;
			if (tierString != null)
			{
				GetTiersFromString(tierString);
			}
		}

		public MilkMolarUpgrade(string name, string title, UpgradeType type, int cost)
		{
			logger.LogDebug((object)("Adding " + name));
			this.name = name;
			this.title = title;
			this.type = type;
			this.cost = cost;
		}

		public virtual void ActivateRepeatableUpgrade()
		{
		}

		public virtual void ActivateOneTimeUpgrade()
		{
			fullyUpgraded = true;
			unlocked = true;
		}

		public virtual void ActivateCurrentTierUpgrade()
		{
		}

		public void GetTiersFromString(string configString)
		{
			string[] array = configString.Split(',');
			costsPerTier = new int[array.Length];
			amountPerTier = new float[array.Length];
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(':');
				costsPerTier[i] = int.Parse(array2[0].Trim());
				amountPerTier[i] = float.Parse(array2[1].Trim());
			}
		}

		public void GoToNextTier()
		{
			logger.LogDebug((object)"Going to next tier");
			unlocked = true;
			currentTier++;
			if (currentTier >= maxTier)
			{
				fullyUpgraded = true;
			}
		}

		public string GetUpgradeString()
		{
			logger.LogDebug((object)"Getting upgrade string");
			string result = "";
			switch (type)
			{
			case UpgradeType.TierNumber:
				if (fullyUpgraded)
				{
					result = title + " (Fully Upgraded) " + $"{amountPerTier[maxTier]}";
					result = result + "\n" + GetUpgradeSymbols();
				}
				else
				{
					result = string.Format("{0}{1} ", nextTierCost, "\ud83e\uddb7") + title + ": " + $"{amountPerTier[currentTier]} -> {amountPerTier[currentTier + 1]}";
					result = result + "\n" + GetUpgradeSymbols();
				}
				break;
			case UpgradeType.TierPercent:
				if (fullyUpgraded)
				{
					result = title + " (Fully Upgraded) " + $"{amountPerTier[maxTier]}%";
					result = result + "\n" + GetUpgradeSymbols();
				}
				else
				{
					result = string.Format("{0}{1} ", nextTierCost, "\ud83e\uddb7") + title + ": " + $"{amountPerTier[currentTier]}% -> {amountPerTier[currentTier + 1]}%";
					result = result + "\n" + GetUpgradeSymbols();
				}
				break;
			case UpgradeType.OneTimeUnlock:
				result = ((!fullyUpgraded) ? string.Format("{0}{1} {2}", cost, "\ud83e\uddb7", title) : (title + " (Fully Upgraded)"));
				break;
			case UpgradeType.Repeatable:
				result = string.Format("{0}{1} {2} (Repeatable)", cost, "\ud83e\uddb7", title);
				break;
			case UpgradeType.LGUTier:
				if (fullyUpgraded)
				{
					result = title + " (Fully Upgraded)\n ";
					result = result + "\n" + GetUpgradeSymbols();
				}
				else
				{
					result = string.Format("{0}{1} {2}", nextTierCost, "\ud83e\uddb7", title);
					result = result + "\n" + GetUpgradeSymbols();
				}
				break;
			case UpgradeType.LGUOneTimeUnlock:
				result = ((!fullyUpgraded) ? string.Format("{0}{1} {2}\n ", cost, "\ud83e\uddb7", title) : (title + " (Fully Upgraded)\n "));
				break;
			}
			return result;
		}

		private string GetUpgradeSymbols()
		{
			string text = "";
			for (int i = 0; i < currentTier; i++)
			{
				text += "⬛";
			}
			for (int j = currentTier; j < maxTier; j++)
			{
				text += "⬜";
			}
			return text;
		}
	}
	internal class NetworkHandler : NetworkBehaviour
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		public static NetworkVariable<int> MegaMilkMolars = new NetworkVariable<int>(0, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public static List<MilkMolarUpgrade> MegaMilkMolarUpgrades;

		public static NetworkHandler Instance { get; private set; }

		public static PlayerControllerB PlayerFromId(ulong id)
		{
			return StartOfRound.Instance.allPlayerScripts[StartOfRound.Instance.ClientPlayerList[id]];
		}

		public override void OnNetworkSpawn()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				NetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
				logger.LogDebug((object)"Despawned network object");
			}
			Instance = this;
			logger.LogDebug((object)"set instance to this");
			((NetworkBehaviour)this).OnNetworkSpawn();
			logger.LogDebug((object)"base.OnNetworkSpawn");
		}

		internal static void DeleteSaveData(int fileToDelete)
		{
			logger.LogDebug((object)("Deleting Milk Molar files for save: " + fileToDelete));
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			logger.LogDebug((object)("Got appData path at: " + folderPath));
			string text = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
			logger.LogDebug((object)("Got save path at: " + text));
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string path = Path.Combine(text, $"MilkMolars{fileToDelete}.json");
			string path2 = Path.Combine(text, $"MegaMilkMolars{fileToDelete}.json");
			string path3 = Path.Combine(text, $"MilkMolarUpgrades{fileToDelete}.json");
			string path4 = Path.Combine(text, $"MegaMilkMolarUpgrades{fileToDelete}.json");
			if (File.Exists(path))
			{
				File.Delete(path);
			}
			if (File.Exists(path2))
			{
				File.Delete(path2);
			}
			if (File.Exists(path3))
			{
				File.Delete(path3);
			}
			if (File.Exists(path4))
			{
				File.Delete(path4);
			}
		}

		public static void ResetAllData()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				MegaMilkMolars.Value = 0;
			}
			DeleteSaveData(GameNetworkManager.Instance.saveFileNum);
			Instance.ResetAllDataClientRpc();
		}

		[ClientRpc]
		private void ResetAllDataClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(18401051u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 18401051u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					MilkMolarController.MilkMolars = 0;
					MegaMilkMolarUpgrades = MilkMolarController.GetUpgrades(mega: true);
					MilkMolarController.MilkMolarUpgrades = MilkMolarController.GetUpgrades();
				}
			}
		}

		public static void SaveDataToFile()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings
			{
				TypeNameHandling = (TypeNameHandling)4
			};
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			string text = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				string contents = MegaMilkMolars.Value.ToString();
				string contents2 = JsonConvert.SerializeObject((object)MegaMilkMolarUpgrades.Where((MilkMolarUpgrade x) => !x.LGUUpgrade), val);
				File.WriteAllText(Path.Combine(text, $"MegaMilkMolars{GameNetworkManager.Instance.saveFileNum}.json"), contents);
				File.WriteAllText(Path.Combine(text, $"MegaMilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json"), contents2);
			}
			string contents3 = JsonConvert.SerializeObject((object)MilkMolarController.MilkMolars, val);
			string contents4 = JsonConvert.SerializeObject((object)MilkMolarController.MilkMolarUpgrades.Where((MilkMolarUpgrade x) => !x.LGUUpgrade), val);
			File.WriteAllText(Path.Combine(text, $"MilkMolars{GameNetworkManager.Instance.saveFileNum}.json"), contents3);
			File.WriteAllText(Path.Combine(text, $"MilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json"), contents4);
		}

		public static void LoadDataFromFile()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings
			{
				TypeNameHandling = (TypeNameHandling)4
			};
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			string text = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string path = Path.Combine(text, $"MilkMolars{GameNetworkManager.Instance.saveFileNum}.json");
			string path2 = Path.Combine(text, $"MilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json");
			if (File.Exists(path))
			{
				logger.LogDebug((object)"Found save data for Milk Molars");
				string s = File.ReadAllText(path);
				MilkMolarController.MilkMolars = int.Parse(s);
			}
			if (File.Exists(path2))
			{
				logger.LogDebug((object)"Found save data for Milk Molar Upgrades");
				string text2 = File.ReadAllText(path2);
				MilkMolarController.MilkMolarUpgrades = JsonConvert.DeserializeObject<List<MilkMolarUpgrade>>(text2, val);
			}
			if (MilkMolarController.MilkMolarUpgrades == null || MilkMolarController.MilkMolarUpgrades.Count == 0)
			{
				logger.LogDebug((object)"MilkMolarUpgrades is null");
				MilkMolarController.MilkMolarUpgrades = MilkMolarController.GetUpgrades();
				logger.LogDebug((object)"Added data for MilkMolarUpgrades");
				if (LGUCompatibility.enabled)
				{
					MilkMolarController.MilkMolarUpgrades.AddRange(LGUCompatibility.GetLGUUpgrades());
				}
			}
			else
			{
				foreach (MilkMolarUpgrade milkMolarUpgrade in MilkMolarController.MilkMolarUpgrades)
				{
					if (!milkMolarUpgrade.LGUUpgrade)
					{
						if (milkMolarUpgrade.type == MilkMolarUpgrade.UpgradeType.OneTimeUnlock && milkMolarUpgrade.unlocked)
						{
							milkMolarUpgrade.ActivateOneTimeUpgrade();
						}
						if ((milkMolarUpgrade.type == MilkMolarUpgrade.UpgradeType.TierNumber || milkMolarUpgrade.type == MilkMolarUpgrade.UpgradeType.TierPercent) && milkMolarUpgrade.unlocked)
						{
							milkMolarUpgrade.ActivateCurrentTierUpgrade();
						}
					}
				}
			}
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				string path3 = Path.Combine(text, $"MegaMilkMolars{GameNetworkManager.Instance.saveFileNum}.json");
				string path4 = Path.Combine(text, $"MegaMilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json");
				if (File.Exists(path3))
				{
					logger.LogDebug((object)"Found save data for Mega Milk Molars");
					string s2 = File.ReadAllText(path3);
					MegaMilkMolars.Value = int.Parse(s2);
				}
				if (File.Exists(path4))
				{
					logger.LogDebug((object)"Found save data for Mega Milk Molar Upgrades");
					string text3 = File.ReadAllText(path4);
					MegaMilkMolarUpgrades = JsonConvert.DeserializeObject<List<MilkMolarUpgrade>>(text3, val);
					if (LGUCompatibility.enabled)
					{
						MegaMilkMolarUpgrades.AddRange(LGUCompatibility.GetLGUUpgrades(mega: true));
					}
				}
				if (MegaMilkMolarUpgrades == null || MegaMilkMolarUpgrades.Count == 0)
				{
					logger.LogDebug((object)"MegaMilkMolarUpgrades is null");
					MegaMilkMolarUpgrades = MilkMolarController.GetUpgrades(mega: true);
					logger.LogDebug((object)"Added data for MegaMilkMolarUpgrades");
				}
			}
			else
			{
				Instance.GetDataFromServerServerRpc(Plugin.localPlayerId);
			}
			logger.LogDebug((object)"Finished loading data");
		}

		[ServerRpc(RequireOwnership = false)]
		public void GetDataFromServerServerRpc(ulong steamId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3378123690u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, steamId);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3378123690u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
				{
					SendDataToClient(steamId);
				}
			}
		}

		public static void SendDataToClient(ulong steamId)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				JsonSerializerSettings val = new JsonSerializerSettings
				{
					TypeNameHandling = (TypeNameHandling)4
				};
				string megaUpgrades = JsonConvert.SerializeObject((object)MegaMilkMolarUpgrades, val);
				Instance.SendDataToClientClientRpc(steamId, megaUpgrades);
			}
		}

		[ClientRpc]
		private void SendDataToClientClientRpc(ulong steamId, string megaUpgrades)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2075443844u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, steamId);
				bool flag = megaUpgrades != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(megaUpgrades, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2075443844u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.localPlayerId == steamId)
			{
				JsonSerializerSettings val3 = new JsonSerializerSettings
				{
					TypeNameHandling = (TypeNameHandling)4
				};
				MegaMilkMolarUpgrades = JsonConvert.DeserializeObject<List<MilkMolarUpgrade>>(megaUpgrades, val3);
				if (LGUCompatibility.enabled)
				{
					MegaMilkMolarUpgrades.AddRange(LGUCompatibility.GetLGUUpgrades(mega: true));
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void AddMilkMolarServerRpc(ulong steamId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4012127579u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, steamId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4012127579u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				if (Plugin.configSharedMilkMolars.Value)
				{
					AddMilkMolarToAllClientsClientRpc();
				}
				else
				{
					AddMilkMolarClientRpc(steamId);
				}
			}
		}

		[ClientRpc]
		private void AddMilkMolarClientRpc(ulong steamId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1647575292u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, steamId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1647575292u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.localPlayerId == steamId)
			{
				MilkMolarController.MilkMolars++;
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 1f);
				}
				HUDManager.Instance.AddChatMessage($"Milk Molar activated! You now have {MilkMolarController.MilkMolars} unspent Milk Molars.", "Server");
			}
		}

		[ClientRpc]
		private void AddMilkMolarToAllClientsClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3921717141u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3921717141u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				MilkMolarController.MilkMolars++;
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 1f);
				}
				HUDManager.Instance.AddChatMessage($"Milk Molar activated! You now have {MilkMolarController.MilkMolars} unspent Milk Molars.", "Server");
			}
		}

		[ClientRpc]
		public void AddMultipleMilkMolarsClientRpc(ulong steamId, int amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1488999507u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, steamId);
				BytePacker.WriteValueBitPacked(val2, amount);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1488999507u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.localPlayerId == steamId)
			{
				MilkMolarController.MilkMolars += amount;
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 0.5f);
				}
				HUDManager.Instance.AddChatMessage($"{amount} Milk Molars activated! Your now have {MilkMolarController.MilkMolars} unspent Milk Molars.", "Server");
			}
		}

		[ClientRpc]
		public void AddMultipleMilkMolarsAllClientsClientRpc(int amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2314137320u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, amount);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2314137320u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				MilkMolarController.MilkMolars += amount;
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 0.5f);
				}
				HUDManager.Instance.AddChatMessage($"{MegaMilkMolars.Value} Mega Milk Molars activated! Your crew now has {MegaMilkMolars.Value} unspent Mega Milk Molars.", "Server");
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void AddMegaMilkMolarServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(573478436u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 573478436u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
				{
					NetworkVariable<int> megaMilkMolars = MegaMilkMolars;
					int value = megaMilkMolars.Value;
					megaMilkMolars.Value = value + 1;
					AddMegaMilkMolarClientRpc();
				}
			}
		}

		[ClientRpc]
		private void AddMegaMilkMolarClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(538069040u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 538069040u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				logger.LogDebug((object)"Added mega milk molar");
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 1f);
				}
				HUDManager.Instance.AddChatMessage($"Mega Milk Molar activated! Your group now has {MegaMilkMolars.Value} unspent Mega Milk Molars.", "Server");
			}
		}

		[ClientRpc]
		public void AddMultipleMegaMilkMolarsClientRpc(int amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2807716155u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, amount);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2807716155u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (Plugin.configPlaySound.Value)
				{
					Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, 0.5f);
				}
				HUDManager.Instance.AddChatMessage($"{MegaMilkMolars.Value} Mega Milk Molars activated! Your crew now has {MegaMilkMolars.Value} unspent Mega Milk Molars.", "Server");
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BuyMegaMilkMolarUpgradeServerRpc(string upgradeName, int cost, ulong steamId, bool lguUpgrade)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1402986398u, val, (RpcDelivery)0);
				bool flag = upgradeName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(upgradeName, false);
				}
				BytePacker.WriteValueBitPacked(val2, cost);
				BytePacker.WriteValueBitPacked(val2, steamId);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref lguUpgrade, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1402986398u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				NetworkVariable<int> megaMilkMolars = MegaMilkMolars;
				megaMilkMolars.Value -= cost;
				if (!lguUpgrade)
				{
					BuyMegaMilkMolarUpgradeClientRpc(upgradeName, steamId);
				}
			}
		}

		[ClientRpc]
		public void BuyMegaMilkMolarUpgradeClientRpc(string upgradeName, ulong steamId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1397248893u, val, (RpcDelivery)0);
				bool flag = upgradeName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(upgradeName, false);
				}
				BytePacker.WriteValueBitPacked(val2, steamId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1397248893u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.localPlayerId != steamId)
			{
				logger.LogDebug((object)"Buying mega milk molar upgrade");
				MilkMolarUpgrade upgradeByName = MilkMolarController.GetUpgradeByName(upgradeName);
				MilkMolarController.BuyMegaMilkMolarUpgrade(upgradeByName);
			}
		}

		protected override void __initializeVariables()
		{
			if (MegaMilkMolars == null)
			{
				throw new Exception("NetworkHandler.MegaMilkMolars cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)MegaMilkMolars).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)MegaMilkMolars, "MegaMilkMolars");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)MegaMilkMolars);
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_NetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(18401051u, new RpcReceiveHandler(__rpc_handler_18401051));
			NetworkManager.__rpc_func_table.Add(3378123690u, new RpcReceiveHandler(__rpc_handler_3378123690));
			NetworkManager.__rpc_func_table.Add(2075443844u, new RpcReceiveHandler(__rpc_handler_2075443844));
			NetworkManager.__rpc_func_table.Add(4012127579u, new RpcReceiveHandler(__rpc_handler_4012127579));
			NetworkManager.__rpc_func_table.Add(1647575292u, new RpcReceiveHandler(__rpc_handler_1647575292));
			NetworkManager.__rpc_func_table.Add(3921717141u, new RpcReceiveHandler(__rpc_handler_3921717141));
			NetworkManager.__rpc_func_table.Add(1488999507u, new RpcReceiveHandler(__rpc_handler_1488999507));
			NetworkManager.__rpc_func_table.Add(2314137320u, new RpcReceiveHandler(__rpc_handler_2314137320));
			NetworkManager.__rpc_func_table.Add(573478436u, new RpcReceiveHandler(__rpc_handler_573478436));
			NetworkManager.__rpc_func_table.Add(538069040u, new RpcReceiveHandler(__rpc_handler_538069040));
			NetworkManager.__rpc_func_table.Add(2807716155u, new RpcReceiveHandler(__rpc_handler_2807716155));
			NetworkManager.__rpc_func_table.Add(1402986398u, new RpcReceiveHandler(__rpc_handler_1402986398));
			NetworkManager.__rpc_func_table.Add(1397248893u, new RpcReceiveHandler(__rpc_handler_1397248893));
		}

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

		private static void __rpc_handler_3378123690(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).GetDataFromServerServerRpc(steamId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2075443844(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string megaUpgrades = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref megaUpgrades, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).SendDataToClientClientRpc(steamId, megaUpgrades);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4012127579(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).AddMilkMolarServerRpc(steamId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1647575292(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).AddMilkMolarClientRpc(steamId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

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

		private static void __rpc_handler_1488999507(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				int amount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amount);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).AddMultipleMilkMolarsClientRpc(steamId, amount);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2314137320(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int amount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amount);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).AddMultipleMilkMolarsAllClientsClientRpc(amount);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

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

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

		private static void __rpc_handler_2807716155(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int amount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amount);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).AddMultipleMegaMilkMolarsClientRpc(amount);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1402986398(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_005b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string upgradeName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref upgradeName, false);
				}
				int cost = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref cost);
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				bool lguUpgrade = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref lguUpgrade, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).BuyMegaMilkMolarUpgradeServerRpc(upgradeName, cost, steamId, lguUpgrade);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1397248893(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string upgradeName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref upgradeName, false);
				}
				ulong steamId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).BuyMegaMilkMolarUpgradeClientRpc(upgradeName, steamId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[HarmonyPatch]
	internal class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			logger.LogDebug((object)"Initializing network prefab...");
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)Plugin.ModAssets.LoadAsset("Assets/ModAssets/MilkMolars/NetworkHandlerMilkMolars.prefab");
				logger.LogDebug((object)"Got networkPrefab");
				networkPrefab.AddComponent<NetworkHandler>();
				logger.LogDebug((object)"Added component");
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
				logger.LogDebug((object)"Added networkPrefab");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//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)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				logger.LogDebug((object)"Instantiated networkHandlerHost");
				val.GetComponent<NetworkObject>().Spawn(false);
				logger.LogDebug((object)"Spawned network object");
			}
		}
	}
	[HarmonyPatch(typeof(DeleteFileButton))]
	internal class DeleteFileButtonPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("DeleteFile")]
		public static void DeleteFilePostfix(DeleteFileButton __instance)
		{
			NetworkHandler.DeleteSaveData(__instance.fileToDelete);
		}
	}
	[HarmonyPatch(typeof(DepositItemsDesk))]
	internal class DepositItemsDeskPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("delayedAcceptanceOfItems")]
		public static void delayedAcceptanceOfItemsPostFix(GrabbableObject[] objectsOnDesk)
		{
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				return;
			}
			if (Plugin.configSharedMilkMolars.Value)
			{
				int num = objectsOnDesk.OfType<MilkMolarBehavior>().Count();
				if (num > 0)
				{
					NetworkHandler.Instance.AddMultipleMilkMolarsAllClientsClientRpc(num);
				}
			}
			else
			{
				foreach (PlayerControllerB player in StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB x) => x.isPlayerControlled))
				{
					int num2 = ((!Plugin.configUpgradePointsToFinder.Value) ? (from x in objectsOnDesk.OfType<MilkMolarBehavior>()
						where (Object)(object)x.lastPlayerHeldBy == (Object)(object)player
						select x).Count() : (from x in objectsOnDesk.OfType<MilkMolarBehavior>()
						where (Object)(object)x.playerFoundBy == (Object)(object)player
						select x).Count());
					if (num2 > 0)
					{
						NetworkHandler.Instance.AddMultipleMilkMolarsClientRpc(player.playerSteamId, num2);
					}
				}
			}
			int num3 = objectsOnDesk.OfType<MegaMilkMolarBehavior>().Count();
			if (num3 > 0)
			{
				NetworkVariable<int> megaMilkMolars = NetworkHandler.MegaMilkMolars;
				megaMilkMolars.Value += num3;
				NetworkHandler.Instance.AddMultipleMegaMilkMolarsClientRpc(num3);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("ConnectClientToPlayerObject")]
		public static void ConnectClientToPlayerObjectPostfix(PlayerControllerB __instance)
		{
			logger.LogDebug((object)"In ConnectClientToPlayerObjectPostfix");
			MilkMolarController.Init();
		}

		[HarmonyPrefix]
		[HarmonyPatch("DamagePlayer")]
		public static void DamagePlayerPrefix(PlayerControllerB __instance, ref int damageNumber, bool fallDamage)
		{
			if (Plugin.localPlayer.actualClientId != __instance.actualClientId)
			{
				return;
			}
			MilkMolarUpgrade upgradeByName = MilkMolarController.GetUpgradeByName("DamageResistance");
			if (upgradeByName != null && upgradeByName.unlocked)
			{
				damageNumber -= (int)((float)damageNumber * (upgradeByName.currentTierAmount / 100f));
			}
			if (fallDamage)
			{
				MilkMolarUpgrade upgradeByName2 = MilkMolarController.GetUpgradeByName("FallDamageReduction");
				if (upgradeByName2 != null && upgradeByName2.unlocked)
				{
					damageNumber -= (int)((float)damageNumber * (upgradeByName2.currentTierAmount / 100f));
				}
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		private const string tooth = "\ud83e\uddb7";

		private static bool allPlayersDead = false;

		[HarmonyPostfix]
		[HarmonyPatch("SpawnScrapInLevel")]
		public static void SpawnScrapInLevelPostfix(RoundManager __instance)
		{
			MilkMolarController.SpawnMolarsInLevel();
		}

		[HarmonyPrefix]
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		public static void DespawnPropsAtEndOfRoundPrefix()
		{
			try
			{
				if (NetworkHandler.MegaMilkMolarUpgrades != null)
				{
					MilkMolarUpgrade milkMolarUpgrade = NetworkHandler.MegaMilkMolarUpgrades.FirstOrDefault((MilkMolarUpgrade x) => x.name == "keepItemsOnShipChance");
					if (milkMolarUpgrade != null && milkMolarUpgrade.unlocked)
					{
						int num = Random.Range(0, 101);
						allPlayersDead = milkMolarUpgrade.currentTierAmount >= (float)num;
						StartOfRound.Instance.allPlayersDead = allPlayersDead;
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		public static void DespawnPropsAtEndOfRoundPostfix()
		{
			try
			{
				if (NetworkHandler.MegaMilkMolarUpgrades != null)
				{
					MilkMolarUpgrade milkMolarUpgrade = NetworkHandler.MegaMilkMolarUpgrades.FirstOrDefault((MilkMolarUpgrade x) => x.name == "keepItemsOnShipChance");
					if (milkMolarUpgrade != null && milkMolarUpgrade.unlocked)
					{
						StartOfRound.Instance.allPlayersDead = allPlayersDead;
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("AutoSaveShipData")]
		public static void AutoSaveShipDataPostfix(StartOfRound __instance)
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				logger.LogDebug((object)"AutoSaveShipDataPostfix called");
				NetworkHandler.SaveDataToFile();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("playersFiredGameOver")]
		public static void playersFiredGameOverPrefix(StartOfRound __instance)
		{
			logger.LogDebug((object)"In EndPlayersFiredSequenceClientRpcPostfix");
			NetworkHandler.ResetAllData();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		private const string tooth = "\ud83e\uddb7";

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void AwakePostfix(Terminal __instance)
		{
			if (!((TMP_Text)__instance.inputFieldText).font.fallbackFontAssetTable.Contains(Plugin.NotoEmojiFA))
			{
				((TMP_Text)__instance.inputFieldText).font.fallbackFontAssetTable.Add(Plugin.NotoEmojiFA);
			}
			if (!((TMP_Text)__instance.topRightText).font.fallbackFontAssetTable.Contains(Plugin.NotoEmojiFA))
			{
				((TMP_Text)__instance.topRightText).font.fallbackFontAssetTable.Add(Plugin.NotoEmojiFA);
			}
			if (!__instance.screenText.fontAsset.fallbackFontAssetTable.Contains(Plugin.NotoEmojiFA))
			{
				__instance.screenText.fontAsset.fallbackFontAssetTable.Add(Plugin.NotoEmojiFA);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePostfix(Terminal __instance)
		{
			if ((Object)(object)InteractiveTerminalManager.Instance != (Object)null && ((Behaviour)InteractiveTerminalManager.Instance).isActiveAndEnabled)
			{
				if (MilkMolarController.InUpgradeUI)
				{
					((TMP_Text)__instance.topRightText).text = "\ud83e\uddb7" + MilkMolarController.MilkMolars;
				}
				else if (MilkMolarController.InMegaUpgradeUI)
				{
					((TMP_Text)__instance.topRightText).text = "\ud83e\uddb7" + NetworkHandler.MegaMilkMolars.Value;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("BuyItemsServerRpc")]
		public static void BuyItemsServerRpcPostfix(Terminal __instance)
		{
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				return;
			}
			MilkMolarUpgrade milkMolarUpgrade = NetworkHandler.MegaMilkMolarUpgrades.Where((MilkMolarUpgrade x) => x.name == "itemDropshipLandingSpeed").FirstOrDefault();
			if (milkMolarUpgrade != null && milkMolarUpgrade.unlocked)
			{
				ItemDropship val = Object.FindObjectsOfType<ItemDropship>().FirstOrDefault();
				if ((Object)(object)val != (Object)null && !val.playersFirstOrder)
				{
					val.shipTimer = 39f;
				}
			}
		}
	}
	[BepInPlugin("Snowlance.MilkMolars", "MilkMolars", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		public enum ActivateMethod
		{
			Grab,
			Use,
			ReturnToShip,
			SellToCompany
		}

		public const string modGUID = "Snowlance.MilkMolars";

		public const string modName = "MilkMolars";

		public const string modVersion = "0.3.0";

		public static Plugin PluginInstance;

		public static ManualLogSource LoggerInstance;

		private readonly Harmony harmony = new Harmony("Snowlance.MilkMolars");

		public static AssetBundle? ModAssets;

		public static AudioClip ActivateSFX;

		public static TMP_FontAsset NotoEmojiFA;

		public static ConfigEntry<bool> configLGUCompatible;

		public static ConfigEntry<float> configLGUMilkMolarContributeAmount;

		public static ConfigEntry<float> configLGUMegaMilkMolarContributeAmount;

		public static ConfigEntry<string> configMilkMolarLevelRarities;

		public static ConfigEntry<string> configMilkMolarCustomLevelRarities;

		public static ConfigEntry<string> configMilkMolarSpawnAmount;

		public static ConfigEntry<ActivateMethod> configMilkMolarActivateMethod;

		public static ConfigEntry<bool> configSharedMilkMolars;

		public static ConfigEntry<bool> configUpgradePointsToFinder;

		public static ConfigEntry<string> configMegaMilkMolarLevelRarities;

		public static ConfigEntry<string> configMegaMilkMolarCustomLevelRarities;

		public static ConfigEntry<string> configMegaMilkMolarSpawnAmount;

		public static ConfigEntry<ActivateMethod> configMegaMilkMolarActivateMethod;

		public static ConfigEntry<bool> configPlaySound;

		public static ConfigEntry<string> configDamageResistanceUpgrade;

		public static ConfigEntry<string> configFallDamageReductionUpgrade;

		public static ConfigEntry<string> configKeepItemsOnShipChanceUpgrade;

		public static ConfigEntry<int> configRevivePlayerUpgrade;

		public static PlayerControllerB localPlayer => GameNetworkManager.Instance.localPlayerController;

		public static ulong localPlayerId => GameNetworkManager.Instance.localPlayerController.playerSteamId;

		private void Awake()
		{
			if ((Object)(object)PluginInstance == (Object)null)
			{
				PluginInstance = this;
			}
			LoggerInstance = ((BaseUnityPlugin)PluginInstance).Logger;
			LoggerInstance.LogDebug((object)"Loaded logger for MilkMolarsMod");
			harmony.PatchAll();
			LoggerInstance.LogDebug((object)"Patched MilkMolarsMod");
			InitializeNetworkBehaviours();
			LoggerInstance.LogDebug((object)"Initialized network behaviours");
			configLGUCompatible = ((BaseUnityPlugin)this).Config.Bind<bool>("LGU Compatibility", "LGU Compatible", true, "If true, Milk Molars will be compatible with Lategame Upgrades.");
			configLGUMilkMolarContributeAmount = ((BaseUnityPlugin)this).Config.Bind<float>("LGU Compatibility", "Milk Molar Contribute Amount", 100f, "How much credits Milk Molars will contribute towards LGU Upgrades.");
			configLGUMegaMilkMolarContributeAmount = ((BaseUnityPlugin)this).Config.Bind<float>("LGU Compatibility", "Mega Milk Molar Contribute Amount", 100f, "How much credits Mega Milk Molars will contribute towards LGU Upgrades.");
			configMilkMolarLevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Rarities", "Level Rarities", "ExperimentationLevel:10, AssuranceLevel:10, VowLevel:10, OffenseLevel:30, AdamanceLevel:50, MarchLevel:50, RendLevel:50, DineLevel:50, TitanLevel:80, ArtificeLevel:80, EmbrionLevel:100, All:30, Modded:30", "Rarities for each level. See default for formatting.");
			configMilkMolarCustomLevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Rarities", "Custom Level Rarities", "", "Rarities for modded levels. Same formatting as level rarities.");
			configMilkMolarSpawnAmount = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Rarities", "Spawn Amount Min Max", "ExperimentationLevel:1-2, AssuranceLevel:1-4, VowLevel:1-5, OffenseLevel:3-5, AdamanceLevel:4-8, MarchLevel:2-6, RendLevel:3-10, DineLevel:4-10, TitanLevel:6-15, ArtificeLevel:7-14, EmbrionLevel:10-20, All:1-5, Modded:1-10", "The minimum and maximum amount of Milk Molars to spawn after scrap spawns in round for each moon.");
			configMilkMolarActivateMethod = ((BaseUnityPlugin)this).Config.Bind<ActivateMethod>("Milk Molar", "Activate Method", ActivateMethod.Use, "Activation method for Milk Molars.\nGrab: Grabbing the Milk Molar will activate it.\nUse: Using the Milk Molar while its in your inventory will activate it.\nShip: Milk Molar will activate when brought inside the ship.\nSell: Milk Molar will activate when sold to the company.");
			configSharedMilkMolars = ((BaseUnityPlugin)this).Config.Bind<bool>("Milk Molar", "Shared Milk Molars", true, "By default (true), Milk Molars will give 1 upgrade point to each player when activated. Setting this to false will only give 1 upgrade point to the player who activated it.");
			configUpgradePointsToFinder = ((BaseUnityPlugin)this).Config.Bind<bool>("Milk Molar", "Upgrade Points to Finder", false, "This only works when configMilkMolarActivateMethod is SHIP or SELL and configSharedMilkMolars is false. Setting this to true will only give an upgrade point to the first person who held the Milk Molar when activating it.");
			configMegaMilkMolarLevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("Mega Milk Molar Rarities", "Mega Milk Molar Level Rarities", "ExperimentationLevel:10, AssuranceLevel:10, VowLevel:10, OffenseLevel:30, AdamanceLevel:50, MarchLevel:50, RendLevel:50, DineLevel:50, TitanLevel:80, ArtificeLevel:80, EmbrionLevel:100, All:30, Modded:30", "Rarities for each level. See default for formatting.");
			configMegaMilkMolarCustomLevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("Mega Milk Molar Rarities", "Mega Milk Molar Custom Level Rarities", "", "Rarities for modded levels. Same formatting as level rarities.");
			configMegaMilkMolarSpawnAmount = ((BaseUnityPlugin)this).Config.Bind<string>("Mega Milk Molar Rarities", "Spawn Amount Min Max", "ExperimentationLevel:1-2, AssuranceLevel:1-3, VowLevel:1-3, OffenseLevel:2-3, AdamanceLevel:3-5, MarchLevel:2-3, RendLevel:3-5, DineLevel:3-6, TitanLevel:5-10, ArtificeLevel:5-12, EmbrionLevel:7-15, All:1-3, Modded:1-5", "The minimum and maximum amount of Mega Milk Molars to spawn after scrap spawns in round for each moon.");
			configMegaMilkMolarActivateMethod = ((BaseUnityPlugin)this).Config.Bind<ActivateMethod>("Mega Milk Molar", "Activate Method", ActivateMethod.Use, "Activation method for Mega Milk Molars.\nGrab: Grabbing the Mega Milk Molar will activate it.\nUse: Using the Mega Milk Molar while its in your inventory will activate it.\nShip: Mega Milk Molar will activate when brought inside the ship.\nSell: Mega Milk Molar will activate when sold to the company.");
			configPlaySound = ((BaseUnityPlugin)this).Config.Bind<bool>("Client Settings", "Play Sound", true, "Play sound when milk molar is activated");
			configDamageResistanceUpgrade = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Upgrades", "Damage Resistance Upgrade", "0:0, 1:5, 2:10, 3:15, 4:20, 5:25, 6:30, 7:35, 8:40, 9:45, 10:50", "Percentage damage reduction. Default is 0");
			configFallDamageReductionUpgrade = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Upgrades", "Fall Damage Reduction Upgrade", "0:0, 1:5, 2:10, 4:15, 5:20", "Percent damage reduction from falling. Default is 0");
			configKeepItemsOnShipChanceUpgrade = ((BaseUnityPlugin)this).Config.Bind<string>("Mega Milk Molar Upgrades", "Keep Items On Ship Upgrade", "0:0, 5:25, 10:50, 15:75, 20:100", "Chance of keeping scrap items on ship. Default is 0");
			configRevivePlayerUpgrade = ((BaseUnityPlugin)this).Config.Bind<int>("Mega Milk Molar Upgrades", "Revive Player Upgrade", 5, "Repeatable upgrade. Revives the player selected on the ship monitor.");
			LoggerInstance.LogDebug((object)"Got configs");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "milkmolar_assets"));
			if ((Object)(object)ModAssets == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			LoggerInstance.LogDebug((object)("Got AssetBundle at: " + Path.Combine(directoryName, "milkmolar_assets")));
			NotoEmojiFA = ModAssets.LoadAsset<TMP_FontAsset>("Assets/ModAssets/MilkMolars/NotoEmoji-Regular SDF.asset");
			if ((Object)(object)NotoEmojiFA == (Object)null)
			{
				LoggerInstance.LogError((object)"Error: Couldnt get NotoEmojiFA from assets");
				return;
			}
			LoggerInstance.LogDebug((object)"Got NotoEmojiFA");
			ActivateSFX = ModAssets.LoadAsset<AudioClip>("Assets/ModAssets/MilkMolars/Audio/milkmolaractivate.mp3");
			if ((Object)(object)ActivateSFX == (Object)null)
			{
				LoggerInstance.LogError((object)"Error: Couldnt get ActivateSFX from assets");
				return;
			}
			LoggerInstance.LogDebug((object)"Got ActivateSFX");
			Item val = ModAssets.LoadAsset<Item>("Assets/ModAssets/MilkMolars/MilkMolarItem.asset");
			if ((Object)(object)val == (Object)null)
			{
				LoggerInstance.LogError((object)"Error: Couldnt get MilkMolar from assets");
				return;
			}
			LoggerInstance.LogDebug((object)"Got MilkMolar prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, GetLevelRarities(configMilkMolarLevelRarities.Value), GetCustomLevelRarities(configMilkMolarCustomLevelRarities.Value));
			Item val2 = ModAssets.LoadAsset<Item>("Assets/ModAssets/MilkMolars/MegaMilkMolarItem.asset");
			if ((Object)(object)val2 == (Object)null)
			{
				LoggerInstance.LogError((object)"Error: Couldnt get MegaMilkMolar from assets"