Decompiled source of MilkMolars v0.6.2

MilkMolars/Snowlance.MilkMolars.dll

Decompiled 6 hours ago
using System;
using System.Collections;
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 System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InteractiveTerminalAPI.Compat;
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.LGU;
using MilkMolars.UI;
using MilkMolars.Upgrades;
using MoreShipUpgrades.Managers;
using MoreShipUpgrades.UI.TerminalNodes;
using Newtonsoft.Json;
using Snowlance.MilkMolars.NetcodePatcher;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[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("MoreShipUpgrades")]
[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.6.2.0")]
[assembly: AssemblyInformationalVersion("0.6.2+c3507c09efe95242b7af8b86fac5cc737e6ea72d")]
[assembly: AssemblyProduct("MilkMolars")]
[assembly: AssemblyTitle("Snowlance.MilkMolars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.2.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 MegaMilkMolarBehavior : PhysicsProp
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		public AudioSource ItemSFX;

		public ScanNodeProperties scanNode;

		private Plugin.ActivateMethod ActivationMethod;

		public override void Start()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Random.Range(0, 2) == 0)
			{
				((GrabbableObject)this).itemProperties.restingRotation = new Vector3(90f, 0f, 0f);
			}
			((GrabbableObject)this).Start();
			((Behaviour)ItemSFX).enabled = true;
			scanNode.subText = "";
			ActivationMethod = Plugin.configMegaMilkMolarActivateMethod.Value;
			if (ActivationMethod == Plugin.ActivateMethod.Use)
			{
				((GrabbableObject)this).itemProperties.toolTips = new string[1] { "Activate [LMB]" };
			}
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				((GrabbableObject)this).grabbable = false;
				((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()
		{
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				ActivateMolar();
			}
			else
			{
				((GrabbableObject)this).InteractItem();
			}
		}

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

		public void ActivateMolar()
		{
			MilkMolarController.AddMegaMilkMolar();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && !((GrabbableObject)this).isPocketed)
			{
				((GrabbableObject)this).playerHeldBy.DespawnHeldObject();
			}
			else
			{
				DespawnMolarServerRpc();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void DespawnMolarServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3583076799u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3583076799u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
				{
					((NetworkBehaviour)this).NetworkObject.Despawn(true);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_MegaMilkMolarBehavior()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3583076799u, new RpcReceiveHandler(__rpc_handler_3583076799));
		}

		private static void __rpc_handler_3583076799(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;
				((MegaMilkMolarBehavior)(object)target).DespawnMolarServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[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()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Random.Range(0, 2) == 0)
			{
				((GrabbableObject)this).itemProperties.restingRotation = new Vector3(90f, 0f, 0f);
			}
			((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 = new string[1] { "Activate [LMB]" };
			}
			if (ActivationMethod == Plugin.ActivateMethod.Grab)
			{
				((GrabbableObject)this).grabbable = false;
				((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();
			}
		}

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

		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 (ActivationMethod != 0)
			{
				if (Plugin.configUpgradePointsToFinder.Value)
				{
					MilkMolarController.AddMilkMolar(playerFoundBy);
				}
				else
				{
					MilkMolarController.AddMilkMolar(((GrabbableObject)this).playerHeldBy);
				}
			}
			else
			{
				MilkMolarController.AddMilkMolar(Plugin.localPlayer);
			}
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && !((GrabbableObject)this).isPocketed)
			{
				((GrabbableObject)this).playerHeldBy.DespawnHeldObject();
			}
			else
			{
				DespawnMolarServerRpc();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void DespawnMolarServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2437545024u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2437545024u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
				{
					((NetworkBehaviour)this).NetworkObject.Despawn(true);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_MilkMolarBehavior()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2437545024u, new RpcReceiveHandler(__rpc_handler_2437545024));
		}

		private static void __rpc_handler_2437545024(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;
				((MilkMolarBehavior)(object)target).DespawnMolarServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[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;

		public static List<MilkMolarUpgrade> MilkMolarUpgrades;

		public static List<MilkMolarUpgrade> MegaMilkMolarUpgrades;

		public static List<MilkMolarUpgrade> ExtraMilkMolarUpgrades;

		public static List<MilkMolarUpgrade> ExtraMegaMilkMolarUpgrades;

		public static List<MilkMolarUpgrade> AllMilkMolarUpgrades => MilkMolarUpgrades.Concat(MegaMilkMolarUpgrades).ToList();

		public static int GetMolarPrice(int price, bool shared)
		{
			if (shared)
			{
				return (int)Math.Ceiling((float)price / Plugin.configLGUMegaMilkMolarContributeAmount.Value);
			}
			return (int)Math.Ceiling((float)price / Plugin.configLGUMilkMolarContributeAmount.Value);
		}

		public static int GetCurrentMolarCount(bool shared)
		{
			if (shared)
			{
				return NetworkHandler.MegaMilkMolars.Value;
			}
			return MilkMolars;
		}

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

		internal static List<MilkMolarUpgrade> GetMilkMolarUpgrades()
		{
			List<MilkMolarUpgrade> list = new List<MilkMolarUpgrade>();
			list.Add(new DaredevilUpgrade());
			list.Add(new DamageResistanceUpgrade());
			Plugin.LoggerInstance.LogDebug((object)("Got milk molar upgrades: " + list.Count));
			return list;
		}

		internal static List<MilkMolarUpgrade> GetMegaMilkMolarUpgrades()
		{
			List<MilkMolarUpgrade> list = new List<MilkMolarUpgrade>();
			list.Add(new KeepItemsOnShipChanceUpgrade());
			list.Add(new RevivePlayerUpgrade());
			logger.LogDebug((object)("Got mega milk molar upgrades: " + list.Count));
			return list;
		}

		public static MilkMolarUpgrade GetUpgradeByName(string name, bool megaUpgrade = false)
		{
			string name2 = name;
			if (megaUpgrade)
			{
				return 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.actualClientId);
		}

		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.UnlockCost)
				{
					MilkMolars -= upgrade.UnlockCost;
					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.UnlockCost)
				{
					MilkMolars -= upgrade.UnlockCost;
					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)
		{
			logger.LogDebug((object)("Attempting to buy Mega Milk Molar upgrade: " + upgrade.Name));
			int value = NetworkHandler.MegaMilkMolars.Value;
			if (upgrade.Type == MilkMolarUpgrade.UpgradeType.Repeatable)
			{
				logger.LogDebug((object)"Upgrade type is Repeatable. Checking if we have enough Mega Milk Molars");
				if (value >= upgrade.UnlockCost)
				{
					logger.LogDebug((object)"Conditions met. Activating Repeatable upgrade.");
					NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.Name, upgrade.UnlockCost);
					return true;
				}
				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 Mega Milk Molars or RPC is not required.");
				if (!upgrade.FullyUpgraded && value >= upgrade.UnlockCost)
				{
					logger.LogDebug((object)"Conditions met. Activating OneTimeUnlock upgrade.");
					NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.Name, upgrade.UnlockCost);
					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 && value >= upgrade.NextTierCost)
			{
				logger.LogDebug((object)"Conditions met. Going to next tier and activating current tier upgrade.");
				NetworkHandler.Instance.BuyMegaMilkMolarUpgradeServerRpc(upgrade.Name, upgrade.NextTierCost);
				return true;
			}
			return false;
		}

		internal static void SpawnMolarsInLevel()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: 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)
			{
				text = source.Where((string x) => x.Trim().Split(":")[0] == "All").FirstOrDefault();
				if (text == null)
				{
					logger.LogDebug((object)"Couldnt find amount in amount config. Not spawning.");
					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);
			}
		}
	}
	internal class MilkMolarNotificationHandler : MonoBehaviour
	{
		private static MilkMolarNotificationHandler _instance = null;

		private static ManualLogSource logger = Plugin.LoggerInstance;

		private static GameObject MilkMolarNotif = null;

		private static GameObject MegaMilkMolarNotif = null;

		private Coroutine? notificationCoroutine = null;

		public static MilkMolarNotificationHandler Instance
		{
			get
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					_instance = Object.FindObjectOfType<MilkMolarNotificationHandler>();
					if ((Object)(object)_instance == (Object)null)
					{
						GameObject val = new GameObject("MilkMolarNotificationHandler");
						Object.DontDestroyOnLoad((Object)(object)val);
						_instance = val.AddComponent<MilkMolarNotificationHandler>();
					}
				}
				return _instance;
			}
		}

		public static void GetUIIcons()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/OpenEyes");
			if ((Object)(object)MilkMolarNotif == (Object)null)
			{
				MilkMolarNotif = new GameObject("MilkMolarNotif");
				MilkMolarNotif.transform.SetParent(val.transform, false);
				Image val2 = MilkMolarNotif.AddComponent<Image>();
				val2.sprite = NetworkHandler.Instance.MilkMolarUIIcon;
				RectTransform component = MilkMolarNotif.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(Plugin.configNotificationSize.Value, Plugin.configNotificationSize.Value);
				component.anchoredPosition = new Vector2(Plugin.configNotificationPositionX.Value, Plugin.configNotificationPositionY.Value);
				MilkMolarNotif.SetActive(false);
				((Graphic)val2).color = new Color(1f, 1f, 1f, 0f);
			}
			if ((Object)(object)MegaMilkMolarNotif == (Object)null)
			{
				MegaMilkMolarNotif = new GameObject("MegaMilkMolarNotif");
				MegaMilkMolarNotif.transform.SetParent(val.transform, false);
				Image val3 = MegaMilkMolarNotif.AddComponent<Image>();
				val3.sprite = NetworkHandler.Instance.MegaMilkMolarUIIcon;
				RectTransform component2 = MegaMilkMolarNotif.GetComponent<RectTransform>();
				component2.sizeDelta = new Vector2(Plugin.configNotificationSize.Value, Plugin.configNotificationSize.Value);
				component2.anchoredPosition = new Vector2(Plugin.configNotificationPositionX.Value, Plugin.configNotificationPositionY.Value);
				((Graphic)val3).color = new Color(1f, 1f, 1f, 0f);
				MegaMilkMolarNotif.SetActive(false);
			}
		}

		public void ShowNotification(bool mega)
		{
			if (Plugin.configPlaySound.Value)
			{
				Plugin.localPlayer.statusEffectAudio.PlayOneShot(Plugin.ActivateSFX, Plugin.configSoundVolume.Value);
			}
			if (notificationCoroutine == null)
			{
				notificationCoroutine = ((MonoBehaviour)this).StartCoroutine(ShowNotificationCoroutine(mega));
			}
		}

		private IEnumerator ShowNotificationCoroutine(bool mega)
		{
			logger.LogDebug((object)"Starting notification coroutine");
			float elapsedTime2 = 0f;
			float duration = 1f;
			float waitTime = 3f;
			GameObject notif;
			Image image;
			if (mega)
			{
				notif = MegaMilkMolarNotif;
				image = MegaMilkMolarNotif.GetComponent<Image>();
			}
			else
			{
				notif = MilkMolarNotif;
				image = MilkMolarNotif.GetComponent<Image>();
			}
			notif.SetActive(Plugin.configShowNotification.Value);
			Color color = ((Graphic)image).color;
			while (elapsedTime2 < duration)
			{
				elapsedTime2 += Time.deltaTime;
				color.a = Mathf.Lerp(0f, 1f, elapsedTime2 / duration);
				((Graphic)image).color = color;
				yield return null;
			}
			yield return (object)new WaitForSeconds(waitTime);
			elapsedTime2 = 0f;
			while (elapsedTime2 < duration)
			{
				elapsedTime2 += Time.deltaTime;
				color.a = Mathf.Lerp(1f, 0f, elapsedTime2 / duration);
				((Graphic)image).color = color;
				yield return null;
			}
			notif.SetActive(false);
			notificationCoroutine = null;
			logger.LogDebug((object)"Ending notification coroutine");
		}
	}
	public abstract class MilkMolarUpgrade
	{
		public enum UpgradeType
		{
			TierNumber,
			TierPercent,
			OneTimeUnlock,
			Repeatable
		}

		private static ManualLogSource logger = Plugin.LoggerInstance;

		private const string upgradePoint = "⬜";

		private const string filledUpgradePoint = "⬛";

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

		public bool Unlocked;

		public bool FullyUpgraded;

		public string Name { get; set; }

		public string Title { get; set; }

		public string Description { get; set; }

		public UpgradeType Type { get; set; }

		public bool Shared { get; set; }

		public bool Visible { get; set; }

		public int UnlockCost { get; set; }

		public int CurrentTier { get; private set; } = 0;


		public float[] AmountPerTier { get; private set; }

		public int[] CostsPerTier { get; private set; }

		[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 virtual bool CanBuyUpgrade()
		{
			int currentPrice = GetCurrentPrice();
			if (Shared)
			{
				int value = NetworkHandler.MegaMilkMolars.Value;
				return value >= currentPrice && !FullyUpgraded;
			}
			return MilkMolarController.MilkMolars >= currentPrice && !FullyUpgraded;
		}

		public virtual void ActivateRepeatableUpgrade()
		{
			logger.LogDebug((object)("Activating Repeatable Upgrade " + Name));
		}

		public virtual void ActivateOneTimeUpgrade()
		{
			logger.LogDebug((object)("Activating One Time Upgrade for " + Name));
			FullyUpgraded = true;
			Unlocked = true;
		}

		public virtual void ActivateCurrentTierUpgrade()
		{
			logger.LogDebug((object)("Activating Current Tier Upgrade for " + Name));
		}

		public int GetCurrentPrice()
		{
			if (Type == UpgradeType.TierNumber || Type == UpgradeType.TierPercent)
			{
				return NextTierCost;
			}
			return UnlockCost;
		}

		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()
		{
			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}", UnlockCost, "\ud83e\uddb7", Title) : (Title + " (Fully Upgraded)"));
				break;
			case UpgradeType.Repeatable:
				result = string.Format("{0}{1} {2} (Repeatable)", UnlockCost, "\ud83e\uddb7", Title);
				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 Sprite MilkMolarUIIcon = null;

		public Sprite MegaMilkMolarUIIcon = null;

		public static NetworkHandler Instance { get; private set; } = null;


		public static string MilkMolarsPath
		{
			get
			{
				string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
				string path = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
				return Path.Combine(path, $"MilkMolars{GameNetworkManager.Instance.saveFileNum}.json");
			}
		}

		public static string MilkMolarUpgradesPath
		{
			get
			{
				string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
				string path = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
				return Path.Combine(path, $"MilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json");
			}
		}

		public static string MegaMilkMolarsPath
		{
			get
			{
				string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
				string path = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
				return Path.Combine(path, $"MegaMilkMolars{GameNetworkManager.Instance.saveFileNum}.json");
			}
		}

		public static string MegaMilkMolarUpgradesPath
		{
			get
			{
				string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
				string path = Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
				return Path.Combine(path, $"MegaMilkMolarUpgrades{GameNetworkManager.Instance.saveFileNum}.json");
			}
		}

		public static string FolderPath
		{
			get
			{
				string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
				return Path.Combine(folderPath + "Low", "ZeekerssRBLX", "Lethal Company", "MilkMolars");
			}
		}

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

		public override void OnNetworkSpawn()
		{
			if (Plugin.IsServerOrHost && (Object)(object)Instance != (Object)null)
			{
				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 void ResetAllData()
		{
			if (Plugin.IsServerOrHost)
			{
				MegaMilkMolars.Value = 0;
				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))
				{
					DeleteSaveData(GameNetworkManager.Instance.saveFileNum);
					MilkMolarController.MilkMolars = 0;
					MilkMolarController.MilkMolarUpgrades = MilkMolarController.GetMilkMolarUpgrades();
					MilkMolarController.MegaMilkMolarUpgrades = MilkMolarController.GetMegaMilkMolarUpgrades();
				}
			}
		}

		internal 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
			};
			if (!Directory.Exists(FolderPath))
			{
				Directory.CreateDirectory(FolderPath);
			}
			if (Plugin.IsServerOrHost)
			{
				string contents = MegaMilkMolars.Value.ToString();
				File.WriteAllText(MegaMilkMolarsPath, contents);
			}
			string contents2 = JsonConvert.SerializeObject((object)MilkMolarController.MilkMolars, val);
			string contents3 = JsonConvert.SerializeObject((object)MilkMolarController.MilkMolarUpgrades, val);
			string contents4 = JsonConvert.SerializeObject((object)MilkMolarController.MegaMilkMolarUpgrades, val);
			File.WriteAllText(MilkMolarsPath, contents2);
			File.WriteAllText(MilkMolarUpgradesPath, contents3);
			File.WriteAllText(MegaMilkMolarUpgradesPath, contents4);
		}

		internal static void DeleteSaveData(int fileToDelete)
		{
			logger.LogDebug((object)("Deleting Milk Molar files for save: " + fileToDelete));
			if (!Directory.Exists(FolderPath))
			{
				Directory.CreateDirectory(FolderPath);
			}
			if (File.Exists(MilkMolarsPath))
			{
				File.Delete(MilkMolarsPath);
			}
			if (File.Exists(MegaMilkMolarsPath))
			{
				File.Delete(MegaMilkMolarsPath);
			}
			if (File.Exists(MilkMolarUpgradesPath))
			{
				File.Delete(MilkMolarUpgradesPath);
			}
			if (File.Exists(MegaMilkMolarUpgradesPath))
			{
				File.Delete(MegaMilkMolarUpgradesPath);
			}
		}

		internal 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
			};
			if (!Directory.Exists(FolderPath))
			{
				Directory.CreateDirectory(FolderPath);
			}
			if (Plugin.IsServerOrHost && File.Exists(MegaMilkMolarsPath))
			{
				logger.LogDebug((object)"Found save data for Mega Milk Molars");
				string s = File.ReadAllText(MegaMilkMolarsPath);
				MegaMilkMolars.Value = int.Parse(s);
			}
			if (File.Exists(MilkMolarsPath))
			{
				logger.LogDebug((object)"Found save data for Milk Molars");
				string s2 = File.ReadAllText(MilkMolarsPath);
				MilkMolarController.MilkMolars = int.Parse(s2);
			}
			if (File.Exists(MilkMolarUpgradesPath))
			{
				logger.LogDebug((object)"Found save data for Milk Molar Upgrades");
				string text = File.ReadAllText(MilkMolarUpgradesPath);
				MilkMolarController.MilkMolarUpgrades = JsonConvert.DeserializeObject<List<MilkMolarUpgrade>>(text, val);
			}
			if (MilkMolarController.MilkMolarUpgrades == null || MilkMolarController.MilkMolarUpgrades.Count == 0)
			{
				logger.LogDebug((object)"MilkMolarUpgrades is null");
				MilkMolarController.MilkMolarUpgrades = MilkMolarController.GetMilkMolarUpgrades();
				logger.LogDebug((object)"Added data for MilkMolarUpgrades");
			}
			else
			{
				foreach (MilkMolarUpgrade milkMolarUpgrade in MilkMolarController.MilkMolarUpgrades)
				{
					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 (File.Exists(MegaMilkMolarUpgradesPath))
			{
				logger.LogDebug((object)"Found save data for Mega Milk Molar Upgrades");
				string text2 = File.ReadAllText(MegaMilkMolarUpgradesPath);
				MilkMolarController.MegaMilkMolarUpgrades = JsonConvert.DeserializeObject<List<MilkMolarUpgrade>>(text2, val);
			}
			if (MilkMolarController.MegaMilkMolarUpgrades == null || MilkMolarController.MegaMilkMolarUpgrades.Count == 0)
			{
				logger.LogDebug((object)"MegaMilkMolarUpgrades is null");
				MilkMolarController.MegaMilkMolarUpgrades = MilkMolarController.GetMegaMilkMolarUpgrades();
				logger.LogDebug((object)"Added data for MegaMilkMolarUpgrades");
			}
			else
			{
				foreach (MilkMolarUpgrade megaMilkMolarUpgrade in MilkMolarController.MegaMilkMolarUpgrades)
				{
					if (megaMilkMolarUpgrade.Type == MilkMolarUpgrade.UpgradeType.OneTimeUnlock && megaMilkMolarUpgrade.Unlocked)
					{
						megaMilkMolarUpgrade.ActivateOneTimeUpgrade();
					}
					if ((megaMilkMolarUpgrade.Type == MilkMolarUpgrade.UpgradeType.TierNumber || megaMilkMolarUpgrade.Type == MilkMolarUpgrade.UpgradeType.TierPercent) && megaMilkMolarUpgrade.Unlocked)
					{
						megaMilkMolarUpgrade.ActivateCurrentTierUpgrade();
					}
				}
			}
			logger.LogDebug((object)"Finished loading data");
		}

		[ServerRpc(RequireOwnership = false)]
		public void AddMilkMolarServerRpc(ulong clientId)
		{
			//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, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4012127579u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
			{
				if (Plugin.configSharedMilkMolars.Value)
				{
					AddMilkMolarToAllClientsClientRpc();
				}
				else
				{
					AddMilkMolarClientRpc(clientId);
				}
			}
		}

		[ClientRpc]
		private void AddMilkMolarClientRpc(ulong clientId)
		{
			//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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1647575292u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clientId);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1647575292u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.localPlayerId == clientId)
				{
					MilkMolarController.MilkMolars++;
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: false);
				}
			}
		}

		[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)
			{
				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++;
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: false);
				}
			}
		}

		[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)
			{
				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;
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: false);
				}
			}
		}

		[ClientRpc]
		public void AddMultipleMilkMolarsClientRpc(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)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1245523314u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, amount);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1245523314u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					MilkMolarController.MilkMolars += amount;
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: false);
				}
			}
		}

		[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) && Plugin.IsServerOrHost)
				{
					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)
			{
				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");
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: true);
				}
			}
		}

		[ClientRpc]
		public void AddMultipleMegaMilkMolarsClientRpc()
		{
			//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(3424838823u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3424838823u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					MilkMolarNotificationHandler.Instance.ShowNotification(mega: true);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BuyMegaMilkMolarUpgradeServerRpc(string upgradeName, int cost)
		{
			//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 != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1443616570u, 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);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1443616570u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
			{
				NetworkVariable<int> megaMilkMolars = MegaMilkMolars;
				megaMilkMolars.Value -= cost;
				BuyMegaMilkMolarUpgradeClientRpc(upgradeName);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BuyMegaMilkMolarUpgradeServerRpc(int cost)
		{
			//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(3672100771u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, cost);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3672100771u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
				{
					NetworkVariable<int> megaMilkMolars = MegaMilkMolars;
					megaMilkMolars.Value -= cost;
				}
			}
		}

		[ClientRpc]
		private void BuyMegaMilkMolarUpgradeClientRpc(string upgradeName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00ba: 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(3443049741u, val, (RpcDelivery)0);
				bool flag = upgradeName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(upgradeName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3443049741u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			MilkMolarUpgrade upgradeByName = MilkMolarController.GetUpgradeByName(upgradeName, megaUpgrade: true);
			if (upgradeByName != null)
			{
				if (upgradeByName.Type == MilkMolarUpgrade.UpgradeType.Repeatable)
				{
					upgradeByName.ActivateRepeatableUpgrade();
					return;
				}
				if (upgradeByName.Type == MilkMolarUpgrade.UpgradeType.OneTimeUnlock)
				{
					upgradeByName.ActivateOneTimeUpgrade();
					return;
				}
				upgradeByName.GoToNextTier();
				upgradeByName.ActivateCurrentTierUpgrade();
			}
			else
			{
				logger.LogError((object)("Error: Invalid upgrade name: " + upgradeName));
			}
		}

		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
			NetworkManager.__rpc_func_table.Add(18401051u, new RpcReceiveHandler(__rpc_handler_18401051));
			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(1245523314u, new RpcReceiveHandler(__rpc_handler_1245523314));
			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(3424838823u, new RpcReceiveHandler(__rpc_handler_3424838823));
			NetworkManager.__rpc_func_table.Add(1443616570u, new RpcReceiveHandler(__rpc_handler_1443616570));
			NetworkManager.__rpc_func_table.Add(3672100771u, new RpcReceiveHandler(__rpc_handler_3672100771));
			NetworkManager.__rpc_func_table.Add(3443049741u, new RpcReceiveHandler(__rpc_handler_3443049741));
		}

		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_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 clientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).AddMilkMolarServerRpc(clientId);
				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 clientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).AddMilkMolarClientRpc(clientId);
				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_1245523314(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).AddMultipleMilkMolarsClientRpc(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_3424838823(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).AddMultipleMegaMilkMolarsClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1443616570(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);
				}
				int cost = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref cost);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).BuyMegaMilkMolarUpgradeServerRpc(upgradeName, cost);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3672100771(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 cost = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref cost);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).BuyMegaMilkMolarUpgradeServerRpc(cost);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3443049741(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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).BuyMegaMilkMolarUpgradeClientRpc(upgradeName);
				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");
				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.AddMultipleMilkMolarsClientRpc(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();
			}
		}
	}
	[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();
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

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

		[HarmonyPostfix]
		[HarmonyPatch("SpawnScrapInLevel")]
		public static void SpawnScrapInLevelPostfix(RoundManager __instance)
		{
			logger.LogDebug((object)"InSpawnScrapInLevelPostfix");
			MilkMolarController.SpawnMolarsInLevel();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

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

		[HarmonyPrefix]
		[HarmonyPatch("playersFiredGameOver")]
		public static void playersFiredGameOverPrefix(StartOfRound __instance)
		{
			logger.LogDebug((object)"In EndPlayersFiredSequenceClientRpcPostfix");
			NetworkHandler.Instance.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;
				}
			}
		}
	}
	[BepInPlugin("Snowlance.MilkMolars", "MilkMolars", "0.6.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		public enum ActivateMethod
		{
			Grab,
			Use,
			ReturnToShip,
			SellToCompany
		}

		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<float> configSoundVolume;

		public static ConfigEntry<bool> configShowNotification;

		public static ConfigEntry<float> configNotificationSize;

		public static ConfigEntry<float> configNotificationPositionX;

		public static ConfigEntry<float> configNotificationPositionY;

		public static ConfigEntry<string> configDamageResistanceUpgrade;

		public static ConfigEntry<string> configDaredevilUpgrade;

		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;

		public static bool IsServerOrHost => NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost;

		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, 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", "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, 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", "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");
			configSoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Client Settings", "Sound Volume", 1f, "Sound volume when milk molar is activated");
			configShowNotification = ((BaseUnityPlugin)this).Config.Bind<bool>("Client Settings", "Show Notification", true, "Show a notification on the HUD when a Milk Molar is activated");
			configNotificationSize = ((BaseUnityPlugin)this).Config.Bind<float>("Client Settings", "Notification Size", 250f, "Size of the notification");
			configNotificationPositionX = ((BaseUnityPlugin)this).Config.Bind<float>("Client Settings", "Notification Position X", 0f, "X position of the notification, relative to the center of the screen");
			configNotificationPositionY = ((BaseUnityPlugin)this).Config.Bind<float>("Client Settings", "Notification Position Y", 175f, "Y position of the notification, relative to the center of the screen");
			configDamageResistanceUpgrade = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Upgrades", "Damage Resistance Upgrade", "0:0, 3:5, 4:10, 5:15, 6:20, 7:25, 8:30, 9:35, 10:40, 15:45, 20:50", "Percentage damage reduction. Default is 0");
			configDaredevilUpgrade = ((BaseUnityPlugin)this).Config.Bind<string>("Milk Molar Upgrades", "Daredevil 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");
				return;
			}
			LoggerInstance.LogDebug((object)"Got MegaMilkMolar prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Utilities.FixMixerGroups(val2.spawnPrefab);
			Items.RegisterScrap(val2, GetLevelRarities(configMegaMilkMolarLevelRarities.Value), GetCustomLevelRarities(configMegaMilkMolarCustomLevelRarities.Value));
			InteractiveTerminalManager.RegisterApplication<UpgradeTerminalUI>(new string[4] { "mmu", "mm", "milk molar upgrades", "milk molar" }, false);
			if (LGUCompatibility.enabled)
			{
				InteractiveTerminalManager.RegisterApplication<LGUUpgradeTerminalUI>(new string[6] { "mmlgu", "mmulgu", "lgu milk molar upgrades", "milk molar lgu", "mmu lgu", "mm lgu" }, false);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MilkMolars v0.6.2 has loaded!");
		}

		public Dictionary<LevelTypes, int> GetLevelRarities(string levelsString)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
				if (levelsString != null && levelsString != "")
				{
					string[] array = levelsString.Split(',');
					string[] array2 = array;
					foreach (string text in array2)
					{
						string[] array3 = text.Split(':');
						if (array3.Length == 2)
						{
							string text2 = array3[0].Trim();
							string text3 = array3[1].Trim();
							if (Enum.TryParse<LevelTypes>(text2, out LevelTypes result) && int.TryParse(text3, out var result2))
							{
								dictionary.Add(result, result2);
							}
							else
							{
								LoggerInstance.LogError((object)("Error: Invalid level rarity: " + text2 + ":" + text3));
							}
						}
					}
				}
				return dictionary;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Error: {arg}");
				return null;
			}
		}

		public Dictionary<string, int> GetCustomLevelRarities(string levelsString)
		{
			try
			{
				Dictionary<string, int> dictionary = new Dictionary<string, int>();
				if (levelsString != null)
				{
					string[] array = levelsString.Split(',');
					string[] array2 = array;
					foreach (string text in array2)
					{
						string[] array3 = text.Split(':');
						if (array3.Length == 2)
						{
							string text2 = array3[0].Trim();
							string text3 = array3[1].Trim();
							if (int.TryParse(text3, out var result))
							{
								dictionary.Add(text2, result);
							}
							else
							{
								LoggerInstance.LogError((object)("Error: Invalid level rarity: " + text2 + ":" + text3));
							}
						}
					}
				}
				return dictionary;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Error: {arg}");
				return null;
			}
		}

		public static void DespawnItemInSlotOnClient(int itemSlot)
		{
			((Behaviour)HUDManager.Instance.itemSlotIcons[itemSlot]).enabled = false;
			localPlayer.DestroyItemInSlotAndSync(itemSlot);
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] array;
			try
			{
				array = Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				array = ex.Types.Where((Type t) => t != null).ToArray();
			}
			Type[] array2 = array;
			foreach (Type type in array2)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array3 = methods;
				foreach (MethodInfo methodInfo in array3)
				{
					try
					{
						object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
						if (customAttributes.Length != 0)
						{
							methodInfo.Invoke(null, null);
						}
					}
					catch (Exception)
					{
					}
				}
			}
			LoggerInstance.LogDebug((object)"Finished initializing network behaviours");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Snowlance.MilkMolars";

		public const string PLUGIN_NAME = "MilkMolars";

		public const string PLUGIN_VERSION = "0.6.2";
	}
}
namespace MilkMolars.Upgrades
{
	internal class DamageResistanceUpgrade : MilkMolarUpgrade
	{
		public DamageResistanceUpgrade()
		{
			base.Name = "DamageResistance";
			base.Title = "Damage Resistance";
			base.Description = "Reduces damage taken per upgrade";
			base.Type = UpgradeType.TierPercent;
			GetTiersFromString(Plugin.configDamageResistanceUpgrade.Value);
			base.Shared = false;
			base.Visible = true;
		}
	}
	[HarmonyPatch]
	internal class DamageResistanceUpgradePatches
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		public static void DamagePlayerPrefix(PlayerControllerB __instance, ref int damageNumber, bool fallDamage)
		{
			if (Plugin.localPlayer.actualClientId == __instance.actualClientId)
			{
				MilkMolarUpgrade upgradeByName = MilkMolarController.GetUpgradeByName("DamageResistance");
				if (upgradeByName != null && upgradeByName.Unlocked)
				{
					damageNumber -= (int)((float)damageNumber * upgradeByName.CurrentTierPercent);
				}
			}
		}
	}
	internal class DaredevilUpgrade : MilkMolarUpgrade
	{
		public DaredevilUpgrade()
		{
			base.Name = "Daredevil";
			base.Title = "Daredevil";
			base.Description = "Reduces fall damage per upgrade";
			base.Type = UpgradeType.TierPercent;
			GetTiersFromString(Plugin.configDaredevilUpgrade.Value);
			base.Shared = false;
			base.Visible = true;
		}
	}
	[HarmonyPatch]
	internal class DaredevilUpgradePatches
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		public static void DamagePlayerPrefix(PlayerControllerB __instance, ref int damageNumber, bool fallDamage)
		{
			if (Plugin.localPlayer.actualClientId == __instance.actualClientId && fallDamage)
			{
				MilkMolarUpgrade upgradeByName = MilkMolarController.GetUpgradeByName("Daredevil");
				if (upgradeByName != null && upgradeByName.Unlocked)
				{
					damageNumber -= (int)((float)damageNumber * upgradeByName.CurrentTierPercent);
				}
			}
		}
	}
	internal class ItemDropshipLandingSpeedUpgrade : MilkMolarUpgrade
	{
		public ItemDropshipLandingSpeedUpgrade()
		{
			base.Name = "itemDropshipLandingSpeed";
			base.Title =