Decompiled source of SLRUpgradePack v0.0.22

plugins/SLRUpgradePack.dll

Decompiled a week 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.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Photon.Pun;
using REPOLib.Modules;
using SLRUpgradePack.UpgradeManagers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("SolarAaron")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SLRUpgradePack")]
[assembly: AssemblyTitle("SLRUpgradePack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.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 SLRUpgradePack
{
	[BepInPlugin("SolarAaron.SLRUpgradePack", "SLRUpgradePack", "0.0.22")]
	public class SLRUpgradePack : BaseUnityPlugin
	{
		internal static SLRUpgradePack Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		public static OverchargeUpgrade OverchargeUpgradeInstance { get; private set; }

		public static ArmorUpgrade ArmorUpgradeInstance { get; private set; }

		public static ObjectValueUpgrade ObjectValueUpgradeInstance { get; private set; }

		public static ObjectDurabilityUpgrade ObjectDurabilityUpgradeInstance { get; private set; }

		public static ValuableDensityUpgrade ValuableDensityUpgradeInstance { get; private set; }

		public static HeartOfGoldUpgrade HeartOfGoldUpgradeInstance { get; private set; }

		public static RegenerationUpgrade RegenerationUpgradeInstance { get; private set; }

		public static ExtraLifeUpgrade ExtraLifeUpgradeInstance { get; private set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			_logger.LogInfo((object)"Configuring upgrade pack...");
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "SLR_assets.bundle");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			string[] allAssetNames = val.GetAllAssetNames();
			foreach (string text2 in allAssetNames)
			{
				_logger.LogInfo((object)("Found asset: " + text2));
			}
			if (PhysGrabberPatch.Prepare())
			{
				OverchargeUpgradeInstance = new OverchargeUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 0.75f);
			}
			ArmorUpgradeInstance = new ArmorUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 1f);
			ObjectValueUpgradeInstance = new ObjectValueUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 1.5f);
			ObjectDurabilityUpgradeInstance = new ObjectDurabilityUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 1.5f);
			ValuableDensityUpgradeInstance = new ValuableDensityUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 1.5f);
			HeartOfGoldUpgradeInstance = new HeartOfGoldUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 10f, 2.5f);
			RegenerationUpgradeInstance = new RegenerationUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 0.1f, 1.5f);
			ExtraLifeUpgradeInstance = new ExtraLifeUpgrade(enabled: true, 0.1f, exponential: false, 1.1f, ((BaseUnityPlugin)this).Config, val, 5, 5f);
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace SLRUpgradePack.UpgradeManagers
{
	public class ArmorUpgrade : UpgradeBase<float>
	{
		public ArmorUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier)
			: base("Armor", "assets/repo/mods/resources/items/items/item upgrade armor.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatReduce(this, "Armor", value, player, level);
		}
	}
	[HarmonyPatch(typeof(PlayerHealth), "Hurt")]
	public class PlayerHealthArmorPatch
	{
		private static void Prefix(PlayerHealth __instance, ref int damage, PlayerAvatar ___playerAvatar)
		{
			ArmorUpgrade armorUpgradeInstance = SLRUpgradePack.ArmorUpgradeInstance;
			if (armorUpgradeInstance.UpgradeEnabled.Value)
			{
				SLRUpgradePack.Logger.LogDebug((object)$"Original damage amount: {damage}");
				damage = (int)Math.Ceiling(armorUpgradeInstance.Calculate(damage, ___playerAvatar, armorUpgradeInstance.UpgradeLevel));
				SLRUpgradePack.Logger.LogDebug((object)string.Format("After calculation with level {0}: {1}", Upgrades.GetUpgrade("Armor").GetLevel(___playerAvatar), damage));
			}
		}
	}
	public class ExtraLifeUpgrade : UpgradeBase<float>
	{
		public ConfigEntry<int> RevivePercent { get; protected set; }

		public ExtraLifeUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, int revivePercent, float priceMultiplier)
			: base("Extra Life", "assets/repo/mods/resources/items/items/item upgrade extra life.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: false)
		{
			RevivePercent = config.Bind<int>("Extra Life Upgrade", "revivePercent", revivePercent, "Percentage of health to recover when revived");
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "ExtraLife", value, player, level);
		}
	}
	public class ExtraLife : MonoBehaviour
	{
		private bool _isMoving;

		private Coroutine? reviving;

		public PlayerDeathHead PlayerDeathHead { get; set; }

		public PlayerAvatar PlayerAvatar { get; set; }

		private void Update()
		{
			if (SemiFunc.PlayerGetSteamID(PlayerAvatar) != SemiFunc.PlayerGetSteamID(SemiFunc.PlayerAvatarLocal()))
			{
				return;
			}
			FieldRef<PlayerHealth, int> val = AccessTools.FieldRefAccess<PlayerHealth, int>("health");
			if (Object.op_Implicit((Object)(object)PlayerAvatar.playerHealth))
			{
				ExtraLifeUpgrade extraLifeUpgradeInstance = SLRUpgradePack.ExtraLifeUpgradeInstance;
				if (val.Invoke(PlayerAvatar.playerHealth) == 0 && extraLifeUpgradeInstance.UpgradeLevel > 0 && !_isMoving && reviving == null)
				{
					reviving = ((MonoBehaviour)this).StartCoroutine(BeginReviving());
				}
			}
			else
			{
				SLRUpgradePack.Logger.LogInfo((object)"why are we here?");
			}
		}

		private IEnumerator BeginReviving()
		{
			yield return (object)new WaitForSeconds(1f);
			SLRUpgradePack.Logger.LogInfo((object)("Reviving " + SemiFunc.PlayerGetSteamID(PlayerAvatar)));
			ExtraLifeUpgrade extraLifeUpgrade = SLRUpgradePack.ExtraLifeUpgradeInstance;
			FieldRef<PlayerHealth, int> maxHealthRef = AccessTools.FieldRefAccess<PlayerHealth, int>("maxHealth");
			PlayerAvatar.Revive(false);
			PlayerAvatar.playerHealth.HealOther(Mathf.FloorToInt((float)(maxHealthRef.Invoke(PlayerAvatar.playerHealth) * extraLifeUpgrade.RevivePercent.Value) / 100f), true);
			extraLifeUpgrade.UpgradeRegister.RemoveLevel(PlayerAvatar, 1);
			reviving = null;
		}

		private void Start()
		{
			SLRUpgradePack.Logger.LogInfo((object)(SemiFunc.PlayerGetSteamID(PlayerAvatar) + " has obtained extra lives"));
			((MonoBehaviour)this).StartCoroutine(MovementCheck());
		}

		private IEnumerator MovementCheck()
		{
			Vector3 currentPosition = ((Component)PlayerDeathHead).transform.position;
			while (true)
			{
				yield return (object)new WaitForSeconds(0.1f);
				Vector3 nextPosition = ((Component)PlayerDeathHead).transform.position;
				_isMoving = Vector3.Distance(currentPosition, nextPosition) >= 0.01f;
				SLRUpgradePack.Logger.LogDebug((object)$"{SemiFunc.PlayerGetSteamID(PlayerAvatar)} is moving: {_isMoving}");
				currentPosition = nextPosition;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerDeathHead), "Update")]
	public class PlayerDeathHeadExtraLifePatch
	{
		[HarmonyWrapSafe]
		private static void Postfix(PlayerDeathHead __instance)
		{
			if (!(SemiFunc.PlayerGetSteamID(__instance.playerAvatar) != SemiFunc.PlayerGetSteamID(SemiFunc.PlayerAvatarLocal())))
			{
				ExtraLifeUpgrade extraLifeUpgradeInstance = SLRUpgradePack.ExtraLifeUpgradeInstance;
				ExtraLife extraLife = default(ExtraLife);
				if (extraLifeUpgradeInstance.UpgradeLevel != 0 && !((Component)__instance).TryGetComponent<ExtraLife>(ref extraLife))
				{
					extraLife = ((Component)__instance).gameObject.AddComponent<ExtraLife>();
					extraLife.PlayerAvatar = __instance.playerAvatar;
					extraLife.PlayerDeathHead = __instance;
				}
			}
		}
	}
	public class HeartOfGoldUpgrade : UpgradeBase<float>
	{
		public ConfigEntry<float> BaseHeartValue { get; protected set; }

		public int LastHealth { get; set; }

		public int LastLevel { get; set; }

		public bool Pause { get; set; }

		public HeartOfGoldUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float baseValue, float priceMultiplier)
			: base("Heart Of Gold", "assets/repo/mods/resources/items/items/item upgrade heart of gold.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
			BaseHeartValue = config.Bind<float>("Heart Of Gold Upgrade", "Base Value", baseValue, "Base value to scale by player health");
			LastHealth = -1;
			LastLevel = -1;
			Pause = false;
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "HeartOfGold", value, player, level);
		}

		protected override void InitUpgrade(PlayerAvatar player, int level)
		{
			base.InitUpgrade(player, level);
			int lastHealth = (LastLevel = -1);
			LastHealth = lastHealth;
			Pause = false;
		}
	}
	[HarmonyPatch(typeof(PlayerHealth), "Update")]
	[HarmonyWrapSafe]
	public class PlayerHealthAddValuePatch
	{
		private static void Postfix(PlayerHealth __instance, PlayerAvatar ___playerAvatar)
		{
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !Traverse.Create((object)RoundDirector.instance).Field("extractionPointsFetched").GetValue<bool>())
			{
				return;
			}
			FieldRef<PlayerHealth, int> val = AccessTools.FieldRefAccess<PlayerHealth, int>("health");
			HeartOfGoldUpgrade heartOfGoldUpgradeInstance = SLRUpgradePack.HeartOfGoldUpgradeInstance;
			if (heartOfGoldUpgradeInstance.UpgradeEnabled.Value && !heartOfGoldUpgradeInstance.Pause && heartOfGoldUpgradeInstance.UpgradeLevel != 0 && val.Invoke(__instance) != 0 && (heartOfGoldUpgradeInstance.LastLevel != heartOfGoldUpgradeInstance.UpgradeLevel || heartOfGoldUpgradeInstance.LastHealth != val.Invoke(__instance)))
			{
				heartOfGoldUpgradeInstance.LastLevel = heartOfGoldUpgradeInstance.UpgradeLevel;
				heartOfGoldUpgradeInstance.LastHealth = val.Invoke(__instance);
				ValuableObject val2 = default(ValuableObject);
				if (!((Component)___playerAvatar.healthGrab).TryGetComponent<ValuableObject>(ref val2) || !Object.op_Implicit((Object)(object)val2) || val.Invoke(__instance) <= 0)
				{
					SLRUpgradePack.Logger.LogInfo((object)("Adding valuable component to player " + SemiFunc.PlayerGetSteamID(___playerAvatar)));
					val2 = ((Component)___playerAvatar.healthGrab).gameObject.AddComponent<ValuableObject>();
					SLRUpgradePack.Logger.LogInfo((object)("Valuable component " + SemiFunc.PlayerGetSteamID(___playerAvatar) + " instantiated at " + JsonConvert.SerializeObject((object)((Component)val2).transform)));
					val2.valuePreset = ScriptableObject.CreateInstance<Value>();
					val2.valuePreset.valueMin = (val2.valuePreset.valueMax = heartOfGoldUpgradeInstance.Calculate((float)val.Invoke(__instance) * heartOfGoldUpgradeInstance.BaseHeartValue.Value, ___playerAvatar, heartOfGoldUpgradeInstance.UpgradeLevel));
					val2.durabilityPreset = ScriptableObject.CreateInstance<Durability>();
					val2.durabilityPreset.durability = 999f;
					val2.durabilityPreset.fragility = 0f;
					val2.physAttributePreset = ScriptableObject.CreateInstance<PhysAttribute>();
					((Component)val2).transform.localScale = Vector3.zero;
					((Component)val2).transform.SetParent(((Component)___playerAvatar).transform, false);
					((Component)val2).gameObject.AddComponent<Rigidbody>();
					PhotonTransformView item = ((Component)val2).gameObject.AddComponent<PhotonTransformView>();
					PhysGrabObject val3 = ((Component)val2).gameObject.AddComponent<PhysGrabObject>();
					PhysGrabObjectImpactDetector val4 = ((Component)val2).gameObject.AddComponent<PhysGrabObjectImpactDetector>();
					PhotonView val5 = ((Component)val2).gameObject.AddComponent<PhotonView>();
					val5.ObservedComponents = new List<Component>(3)
					{
						(Component)(object)val3,
						(Component)(object)val4,
						(Component)(object)item
					};
					((Behaviour)val4).enabled = false;
					((Behaviour)val3).enabled = false;
					((Component)val3).transform.localScale = Vector3.zero;
					((Component)val3).transform.SetParent(((Component)val2).transform, false);
					((Component)val4).transform.localScale = Vector3.zero;
					((Component)val4).transform.SetParent(((Component)val2).transform, false);
					RoomVolumeCheck val6 = ((Component)val2).gameObject.AddComponent<RoomVolumeCheck>();
					val6.CurrentRooms = new List<RoomVolume>();
					ValuableObject obj = val2;
					Gradient val7 = new Gradient();
					val7.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[1]
					{
						new GradientAlphaKey(1f, 0f)
					};
					val7.colorKeys = (GradientColorKey[])(object)new GradientColorKey[1]
					{
						new GradientColorKey(Color.yellow, 0f)
					};
					obj.particleColors = val7;
					FieldRef<ValuableObject, PhysAttribute> val8 = AccessTools.FieldRefAccess<ValuableObject, PhysAttribute>("physAttributePreset");
					val8.Invoke(val2) = ScriptableObject.CreateInstance<PhysAttribute>();
					GoldenHeart goldenHeart = ((Component)___playerAvatar.healthGrab).gameObject.AddComponent<GoldenHeart>();
					goldenHeart.ValuableObject = val2;
					((Component)goldenHeart).gameObject.AddComponent<PhotonView>();
					int lastHealth = (heartOfGoldUpgradeInstance.LastLevel = -1);
					heartOfGoldUpgradeInstance.LastHealth = lastHealth;
				}
				if (!AccessTools.FieldRefAccess<ValuableObject, bool>("discovered").Invoke(val2))
				{
					val2.Discover((State)0);
				}
				FieldRef<ValuableObject, float> val9 = AccessTools.FieldRefAccess<ValuableObject, float>("dollarValueCurrent");
				val9.Invoke(val2) = heartOfGoldUpgradeInstance.Calculate((float)val.Invoke(__instance) * heartOfGoldUpgradeInstance.BaseHeartValue.Value, ___playerAvatar, heartOfGoldUpgradeInstance.UpgradeLevel);
				ValuableObjectValuePatch.Action(val2);
			}
		}
	}
	public class GoldenHeart : MonoBehaviour
	{
		private PhotonView photonView;

		public ValuableObject ValuableObject { get; set; }

		private void Start()
		{
			photonView = ((Component)this).gameObject.GetComponent<PhotonView>();
		}

		public void DestroyOnlyMe()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				DestroyOnlyMeRPC();
			}
			else
			{
				photonView.RPC("DestroyOnlyMeRPC", (RpcTarget)0, Array.Empty<object>());
			}
		}

		[PunRPC]
		private void DestroyOnlyMeRPC()
		{
			Object.Destroy((Object)(object)ValuableObject);
			Object.Destroy((Object)(object)this);
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint))]
	public class ExrtractionPointdestoryPatch
	{
		[HarmonyPatch("DestroyAllPhysObjectsInHaulList")]
		[HarmonyPrefix]
		private static bool DestroyAllPrefix()
		{
			HeartOfGoldUpgrade heartOfGoldUpgradeInstance = SLRUpgradePack.HeartOfGoldUpgradeInstance;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !heartOfGoldUpgradeInstance.UpgradeEnabled.Value)
			{
				return true;
			}
			FieldRef<RoundDirector, int> val = AccessTools.FieldRefAccess<RoundDirector, int>("totalHaul");
			GoldenHeart goldenHeart = default(GoldenHeart);
			foreach (GameObject dollarHaul in RoundDirector.instance.dollarHaulList)
			{
				if (Object.op_Implicit((Object)(object)dollarHaul) && Object.op_Implicit((Object)(object)dollarHaul.GetComponent<PhysGrabObject>()))
				{
					val.Invoke(RoundDirector.instance) += (int)Traverse.Create((object)dollarHaul.GetComponent<ValuableObject>()).Field("dollarValueCurrent").GetValue<float>();
					if (((Object)dollarHaul.GetComponent<ValuableObject>()).name.Equals("Health Grab") && dollarHaul.TryGetComponent<GoldenHeart>(ref goldenHeart))
					{
						SLRUpgradePack.Logger.LogInfo((object)"Player in extraction zone counts as valuable");
						goldenHeart.DestroyOnlyMe();
					}
					else
					{
						dollarHaul.GetComponent<PhysGrabObject>().DestroyPhysGrabObject();
					}
				}
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				player.playerDeathHead.Revive();
			}
			heartOfGoldUpgradeInstance.Pause = false;
			int lastHealth = (heartOfGoldUpgradeInstance.LastLevel = -1);
			heartOfGoldUpgradeInstance.LastHealth = lastHealth;
			return false;
		}

		[HarmonyPatch("DestroyTheFirstPhysObjectsInHaulList")]
		[HarmonyPrefix]
		private static bool DestroyFirstPrefix()
		{
			HeartOfGoldUpgrade heartOfGoldUpgradeInstance = SLRUpgradePack.HeartOfGoldUpgradeInstance;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || RoundDirector.instance.dollarHaulList.Count == 0 || !Object.op_Implicit((Object)(object)RoundDirector.instance.dollarHaulList[0]) || !Object.op_Implicit((Object)(object)RoundDirector.instance.dollarHaulList[0].GetComponent<PhysGrabObject>()) || !heartOfGoldUpgradeInstance.UpgradeEnabled.Value)
			{
				return true;
			}
			heartOfGoldUpgradeInstance.Pause = true;
			AccessTools.FieldRefAccess<RoundDirector, int>("totalHaul").Invoke(RoundDirector.instance) += (int)Traverse.Create((object)RoundDirector.instance.dollarHaulList[0].GetComponent<ValuableObject>()).Field("dollarValueCurrent").GetValue<float>();
			GoldenHeart goldenHeart = default(GoldenHeart);
			if (((Object)RoundDirector.instance.dollarHaulList[0].GetComponent<ValuableObject>()).name.Equals("Health Grab") && RoundDirector.instance.dollarHaulList[0].TryGetComponent<GoldenHeart>(ref goldenHeart))
			{
				SLRUpgradePack.Logger.LogInfo((object)"Player in extraction zone counts as valuable");
				goldenHeart.DestroyOnlyMe();
			}
			else
			{
				RoundDirector.instance.dollarHaulList[0].GetComponent<PhysGrabObject>().DestroyPhysGrabObject();
			}
			RoundDirector.instance.dollarHaulList.RemoveAt(0);
			return false;
		}
	}
	public class ObjectDurabilityUpgrade : UpgradeBase<float>
	{
		public ObjectDurabilityUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier)
			: base("Object Durability", "assets/repo/mods/resources/items/items/item upgrade durability.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "ObjectDurability", value, player, level);
		}
	}
	[HarmonyPatch(typeof(ValuableObject), "Start")]
	public class ValuableObjectDurabilityPatch
	{
		[HarmonyPriority(0)]
		internal static void Prefix(ValuableObject __instance)
		{
			ObjectDurabilityUpgrade objectDurabilityUpgradeInstance = SLRUpgradePack.ObjectDurabilityUpgradeInstance;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !objectDurabilityUpgradeInstance.UpgradeEnabled.Value)
			{
				return;
			}
			SLRUpgradePack.Logger.LogDebug((object)$"Original durability: {__instance.durabilityPreset.durability}");
			Durability val = Object.Instantiate<Durability>(__instance.durabilityPreset);
			foreach (KeyValuePair<string, int> item in objectDurabilityUpgradeInstance.UpgradeRegister.PlayerDictionary)
			{
				val.durability = objectDurabilityUpgradeInstance.Calculate(__instance.durabilityPreset.durability, SemiFunc.PlayerGetFromSteamID(item.Key), item.Value);
				val.fragility = UpgradeBase<float>.DefaultCalculateFloatReduce(objectDurabilityUpgradeInstance, "ObjectDurability", __instance.durabilityPreset.fragility, SemiFunc.PlayerGetFromSteamID(item.Key), item.Value);
			}
			__instance.durabilityPreset = val;
			SLRUpgradePack.Logger.LogDebug((object)string.Format("After calculation with levels {0}: {1}", string.Join(",", Upgrades.GetUpgrade("ObjectDurability").PlayerDictionary), __instance.durabilityPreset.durability));
		}
	}
	public class SpawnedValuableDurabilityPatch<TSVT> where TSVT : MonoBehaviour
	{
		protected static void DoValuableStuff(TSVT spawnedValuable)
		{
			ValuableObject val = default(ValuableObject);
			if (((Component)(object)spawnedValuable).TryGetComponent<ValuableObject>(ref val))
			{
				SLRUpgradePack.Logger.LogDebug((object)$"Valuable spawned with: {val.durabilityPreset.durability} / {val.durabilityPreset.fragility}");
				ValuableObjectDurabilityPatch.Prefix(val);
			}
		}
	}
	[HarmonyPatch(typeof(SurplusValuable), "Start")]
	public class SurplusValuableDurabilityValuePatch : SpawnedValuableDurabilityPatch<SurplusValuable>
	{
		internal static void Prefix(SurplusValuable __instance)
		{
			SpawnedValuableDurabilityPatch<SurplusValuable>.DoValuableStuff(__instance);
		}
	}
	[HarmonyPatch(typeof(EnemyValuable), "Start")]
	public class EnemyValuableDurabilityValuePatch : SpawnedValuableDurabilityPatch<EnemyValuable>
	{
		internal static void Prefix(EnemyValuable __instance)
		{
			SpawnedValuableDurabilityPatch<EnemyValuable>.DoValuableStuff(__instance);
		}
	}
	public class ObjectValueUpgrade : UpgradeBase<float>
	{
		public ConfigEntry<bool> UpgradeScalesSurplus { get; protected set; }

		public ObjectValueUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier)
			: base("Object Value", "assets/repo/mods/resources/items/items/item upgrade value.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
			UpgradeScalesSurplus = config.Bind<bool>("Object Value Upgrade", "Scale Surplus Bag", false, "Should the Object Value Upgrade scale the extraction surplus bag?");
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "ObjectValue", value, player, level);
		}
	}
	[HarmonyPatch(typeof(ValuableObject), "DollarValueSetLogic")]
	public class ValuableObjectValuePatch
	{
		internal static readonly FieldRef<ValuableObject, int> FixedValueRef = AccessTools.FieldRefAccess<ValuableObject, int>("dollarValueOverride");

		internal static readonly FieldRef<ValuableObject, float> DollarValueCurrentRef = AccessTools.FieldRefAccess<ValuableObject, float>("dollarValueCurrent");

		internal static readonly Queue<ValuableObject> DollarValueQueue = new Queue<ValuableObject>();

		[HarmonyPriority(0)]
		internal static void Postfix(ValuableObject __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance) && SLRUpgradePack.ObjectValueUpgradeInstance.UpgradeEnabled.Value)
			{
				ValueHelper valueHelper = ((Component)__instance).gameObject.AddComponent<ValueHelper>();
				((Component)valueHelper).gameObject.AddComponent<PhotonView>();
				valueHelper.Valuable = __instance;
				DollarValueQueue.Enqueue(__instance);
			}
		}

		internal static void Action(ValuableObject instance)
		{
			ObjectValueUpgrade objectValueUpgradeInstance = SLRUpgradePack.ObjectValueUpgradeInstance;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !objectValueUpgradeInstance.UpgradeEnabled.Value)
			{
				return;
			}
			SLRUpgradePack.Logger.LogDebug((object)$"{((Object)instance).name} Original value: {instance.valuePreset.valueMin} - {instance.valuePreset.valueMax} ({DollarValueCurrentRef.Invoke(instance)} / {FixedValueRef.Invoke(instance)})");
			Value val = Object.Instantiate<Value>(instance.valuePreset);
			float num = DollarValueCurrentRef.Invoke(instance);
			foreach (KeyValuePair<string, int> item in objectValueUpgradeInstance.UpgradeRegister.PlayerDictionary)
			{
				val.valueMin = objectValueUpgradeInstance.Calculate(instance.valuePreset.valueMin, SemiFunc.PlayerGetFromSteamID(item.Key), item.Value);
				val.valueMax = objectValueUpgradeInstance.Calculate(instance.valuePreset.valueMax, SemiFunc.PlayerGetFromSteamID(item.Key), item.Value);
				if (FixedValueRef.Invoke(instance) != 0)
				{
					FixedValueRef.Invoke(instance) = (int)Math.Ceiling(objectValueUpgradeInstance.Calculate(FixedValueRef.Invoke(instance), SemiFunc.PlayerGetFromSteamID(item.Key), item.Value));
				}
				num = objectValueUpgradeInstance.Calculate(num, SemiFunc.PlayerGetFromSteamID(item.Key), item.Value);
			}
			instance.valuePreset = val;
			ValueHelper valueHelper = default(ValueHelper);
			if (((Component)instance).TryGetComponent<ValueHelper>(ref valueHelper))
			{
				valueHelper.SetValuableValue(num);
			}
			SLRUpgradePack.Logger.LogDebug((object)string.Format("After calculation with levels {0}: {1} - {2} ({3})", string.Join(",", Upgrades.GetUpgrade("ObjectValue").PlayerDictionary), instance.valuePreset.valueMin, instance.valuePreset.valueMax, FixedValueRef.Invoke(instance)));
		}
	}
	internal class ValueHelper : MonoBehaviour
	{
		private PhotonView photonView;

		internal static readonly FieldRef<ValuableObject, float> DollarValueCurrentRef = AccessTools.FieldRefAccess<ValuableObject, float>("dollarValueCurrent");

		public ValuableObject Valuable { get; set; }

		private void Start()
		{
			photonView = ((Component)this).GetComponent<PhotonView>();
		}

		public void SetValuableValue(float value)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				SetValuableValueRPC(value);
				return;
			}
			photonView.RPC("SetValuableValueRPC", (RpcTarget)0, new object[1] { value });
		}

		[PunRPC]
		private void SetValuableValueRPC(float value)
		{
			DollarValueCurrentRef.Invoke(Valuable) = value;
		}
	}
	[HarmonyPatch(typeof(ValuableDirector), "Start")]
	public class ValuableDirectorHostSetupPatch
	{
		internal static void Postfix(ValuableDirector __instance)
		{
			((MonoBehaviour)__instance).StartCoroutine(AdjustValuables());
		}

		private static IEnumerator AdjustValuables()
		{
			while (!ValuableDirector.instance.setupComplete)
			{
				yield return (object)new WaitForSeconds(0.1f);
			}
			while (ValuableObjectValuePatch.DollarValueQueue.Count > 0)
			{
				ValuableObject valuable = ValuableObjectValuePatch.DollarValueQueue.Dequeue();
				if (Object.op_Implicit((Object)(object)valuable))
				{
					ValuableObjectValuePatch.Action(valuable);
				}
			}
		}
	}
	public class SpawnedValuableValuePatch<TSVT> where TSVT : MonoBehaviour
	{
		protected static void DoValuableStuff(TSVT spawnedValuable)
		{
			ValuableObject val = default(ValuableObject);
			if (((Component)(object)spawnedValuable).TryGetComponent<ValuableObject>(ref val) && SLRUpgradePack.ObjectValueUpgradeInstance.UpgradeEnabled.Value)
			{
				SLRUpgradePack.Logger.LogDebug((object)$"Valuable spawned with: {val.valuePreset.valueMin} {val.valuePreset.valueMax} {ValuableObjectValuePatch.FixedValueRef.Invoke(val)}");
				ValueHelper valueHelper = ((Component)val).gameObject.AddComponent<ValueHelper>();
				((Component)valueHelper).gameObject.AddComponent<PhotonView>();
				valueHelper.Valuable = val;
				ValuableObjectValuePatch.Action(val);
			}
		}
	}
	[HarmonyPatch(typeof(SurplusValuable), "Start")]
	public class SurplusValuableValuePatch : SpawnedValuableValuePatch<SurplusValuable>
	{
		internal static void Prefix(SurplusValuable __instance)
		{
			if (SLRUpgradePack.ObjectValueUpgradeInstance.UpgradeScalesSurplus.Value && SLRUpgradePack.ObjectValueUpgradeInstance.UpgradeEnabled.Value)
			{
				SpawnedValuableValuePatch<SurplusValuable>.DoValuableStuff(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(EnemyValuable), "Start")]
	public class EnemyValuableValuePatch : SpawnedValuableValuePatch<EnemyValuable>
	{
		internal static void Prefix(EnemyValuable __instance)
		{
			SpawnedValuableValuePatch<EnemyValuable>.DoValuableStuff(__instance);
		}
	}
	public class OverchargeUpgrade : UpgradeBase<float>
	{
		public OverchargeUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier)
			: base("Overcharge", "assets/repo/mods/resources/items/items/item upgrade overcharge.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatReduce(this, "Overcharge", value, player, level);
		}
	}
	[HarmonyPatch(typeof(PhysGrabber))]
	public class PhysGrabberPatch
	{
		public static bool Prepare()
		{
			return typeof(PhysGrabber).GetMethods().Any((MethodInfo method) => method.Name.Equals("PhysGrabOverCharge"));
		}

		[HarmonyPatch("PhysGrabOverCharge")]
		private static void Prefix(PhysGrabber __instance, ref float _amount)
		{
			OverchargeUpgrade overchargeUpgradeInstance = SLRUpgradePack.OverchargeUpgradeInstance;
			if (overchargeUpgradeInstance.UpgradeEnabled.Value)
			{
				SLRUpgradePack.Logger.LogDebug((object)$"Original overcharge amount: {_amount}");
				_amount = overchargeUpgradeInstance.Calculate(_amount, __instance.playerAvatar, overchargeUpgradeInstance.UpgradeLevel);
				SLRUpgradePack.Logger.LogDebug((object)string.Format("After calculation with level {0}: {1}", Upgrades.GetUpgrade("Overcharge").GetLevel(__instance.playerAvatar), _amount));
			}
		}
	}
	public class RegenerationUpgrade : UpgradeBase<float>
	{
		internal float PendingHealing = 0f;

		public ConfigEntry<float> BaseHealing { get; protected set; }

		public RegenerationUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float baseHealing, float priceMultiplier)
			: base("Regeneration", "assets/repo/mods/resources/items/items/item upgrade regeneration.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			BaseHealing = config.Bind<float>("Regeneration Upgrade", "Base Healing", baseHealing, new ConfigDescription("Base Healing Amount", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "Regeneration", value, player, level);
		}

		protected override void InitUpgrade(PlayerAvatar player, int level)
		{
			base.InitUpgrade(player, level);
			PendingHealing = 0f;
		}
	}
	[HarmonyPatch(typeof(PlayerHealth), "Update")]
	[HarmonyWrapSafe]
	public class PlayerHealthRecoveryPatch
	{
		private static void Postfix(PlayerHealth __instance, PlayerAvatar ___playerAvatar)
		{
			if (SemiFunc.PlayerGetSteamID(___playerAvatar) != SemiFunc.PlayerGetSteamID(SemiFunc.PlayerAvatarLocal()))
			{
				return;
			}
			FieldRef<PlayerHealth, int> val = AccessTools.FieldRefAccess<PlayerHealth, int>("health");
			RegenerationUpgrade regenerationUpgradeInstance = SLRUpgradePack.RegenerationUpgradeInstance;
			if (ValuableDirector.instance.setupComplete && regenerationUpgradeInstance.UpgradeEnabled.Value && regenerationUpgradeInstance.UpgradeLevel != 0 && val.Invoke(__instance) != 0)
			{
				regenerationUpgradeInstance.PendingHealing += regenerationUpgradeInstance.Calculate(regenerationUpgradeInstance.BaseHealing.Value * Time.deltaTime, ___playerAvatar, regenerationUpgradeInstance.UpgradeLevel);
				if (regenerationUpgradeInstance.PendingHealing >= 1f)
				{
					__instance.HealOther((int)Math.Floor(regenerationUpgradeInstance.PendingHealing), false);
					regenerationUpgradeInstance.PendingHealing -= Mathf.Floor(regenerationUpgradeInstance.PendingHealing);
				}
			}
		}
	}
	public abstract class UpgradeBase<T>
	{
		public ConfigEntry<bool> UpgradeEnabled { get; protected set; }

		public ConfigEntry<T> UpgradeAmount { get; protected set; }

		public ConfigEntry<bool> UpgradeExponential { get; protected set; }

		public ConfigEntry<T> UpgradeExpAmount { get; protected set; }

		public ConfigEntry<float> PriceMultiplier { get; protected set; }

		public int UpgradeLevel { get; protected set; }

		public PlayerUpgrade UpgradeRegister { get; protected set; }

		protected UpgradeBase(string name, string assetName, bool enabled, T upgradeAmount, bool exponential, T exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier, bool configureAmount)
		{
			UpgradeEnabled = config.Bind<bool>(name + " Upgrade", "Enabled", enabled, "Should the " + name + " Upgrade be enabled?");
			PriceMultiplier = config.Bind<float>(name + " Upgrade", "Price multiplier", priceMultiplier, "Multiplier of upgrade base price");
			if (configureAmount)
			{
				UpgradeAmount = config.Bind<T>(name + " Upgrade", name + " Upgrade Power", upgradeAmount, "How much the " + name + " Upgrade increments");
			}
			if (configureAmount)
			{
				UpgradeExponential = config.Bind<bool>(name + " Upgrade", "Exponential upgrade", exponential, "Should the " + name + " Upgrade stack exponentially?");
			}
			if (configureAmount)
			{
				UpgradeExpAmount = config.Bind<T>(name + " Upgrade", name + " Upgrade Exponential Power", exponentialAmount, "How much the Exponential " + name + " upgrade increments");
			}
			if (UpgradeEnabled.Value)
			{
				Item val = assetBundle.LoadAsset<Item>(assetName);
				SLRUpgradePack.Logger.LogInfo((object)$"Upgrade price range (default) {val.value.valueMin} - {val.value.valueMax}");
				Value val2 = ScriptableObject.CreateInstance<Value>();
				val2.valueMin = val.value.valueMin * PriceMultiplier.Value;
				val2.valueMax = val.value.valueMax * PriceMultiplier.Value;
				val.value = val2;
				Items.RegisterItem(val);
				UpgradeRegister = Upgrades.RegisterUpgrade(name.Replace(" ", "") ?? "", val, (Action<PlayerAvatar, int>)InitUpgrade, (Action<PlayerAvatar, int>)UseUpgrade);
			}
		}

		protected virtual void InitUpgrade(PlayerAvatar player, int level)
		{
			if (Traverse.Create((object)player).Field<bool>("isLocal").Value)
			{
				UpgradeLevel = level;
				SLRUpgradePack.Logger.LogInfo((object)("Init: " + string.Join(",", UpgradeRegister.PlayerDictionary)));
			}
		}

		protected void UseUpgrade(PlayerAvatar player, int level)
		{
			if (Traverse.Create((object)player).Field<bool>("isLocal").Value)
			{
				UpgradeLevel = level;
				SLRUpgradePack.Logger.LogInfo((object)("Used: " + string.Join(",", UpgradeRegister.PlayerDictionary)));
			}
		}

		public abstract T Calculate(T value, PlayerAvatar player, int level);

		public static float DefaultCalculateFloatReduce(UpgradeBase<float> instance, string name, float value, PlayerAvatar player, int level)
		{
			if (level > 0)
			{
				if (instance.UpgradeExponential.Value)
				{
					return (float)((double)value / Math.Pow(instance.UpgradeExpAmount.Value, level));
				}
				return value / (1f + instance.UpgradeAmount.Value * (float)level);
			}
			return value;
		}

		public static float DefaultCalculateFloatIncrease(UpgradeBase<float> instance, string name, float value, PlayerAvatar player, int level)
		{
			if (level > 0)
			{
				if (instance.UpgradeExponential.Value)
				{
					return (float)((double)value * Math.Pow(instance.UpgradeExpAmount.Value, level));
				}
				return value * (1f + instance.UpgradeAmount.Value * (float)level);
			}
			return value;
		}
	}
	public class EnumeratorWrapper : IEnumerable
	{
		public IEnumerator enumerator;

		public Action? prefixAction;

		public Action? postfixAction;

		public Action<object>? preItemAction;

		public Action<object>? postItemAction;

		public Func<object, object>? itemAction;

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public IEnumerator GetEnumerator()
		{
			prefixAction?.Invoke();
			while (enumerator.MoveNext())
			{
				object item = enumerator.Current;
				preItemAction?.Invoke(item);
				if (itemAction != null)
				{
					yield return itemAction(item);
				}
				else
				{
					yield return item;
				}
				postItemAction?.Invoke(item);
			}
			postfixAction?.Invoke();
		}
	}
	[HarmonyPatch(typeof(StatsManager), "FetchPlayerUpgrades")]
	public class StatsManagerPatch
	{
		private static bool Prefix(StatsManager __instance, ref string _steamID, ref Dictionary<string, int> __result)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Regex regex = new Regex("(?<!^)(?=[A-Z])");
			foreach (KeyValuePair<string, Dictionary<string, int>> dictionaryOfDictionary in __instance.dictionaryOfDictionaries)
			{
				if (!dictionaryOfDictionary.Key.StartsWith("playerUpgrade") || !dictionaryOfDictionary.Value.ContainsKey(_steamID))
				{
					continue;
				}
				string text = "";
				string[] array = regex.Split(dictionaryOfDictionary.Key);
				bool flag = false;
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					if (flag)
					{
						text = text + text2 + " ";
					}
					if (text2 == "Upgrade")
					{
						flag = true;
					}
				}
				text = text.Replace("Modded", "").Trim();
				if (text.Length != 0)
				{
					int num = dictionaryOfDictionary.Value[_steamID];
					if (dictionary.TryGetValue(text, out var value))
					{
						SLRUpgradePack.Logger.LogWarning((object)$"Duplicate upgrade found [{text}: {value} => {num}]");
					}
					dictionary[text] = num;
				}
			}
			__result = dictionary;
			return false;
		}
	}
	public class ValuableDensityUpgrade : UpgradeBase<float>
	{
		public List<AnimationCurve> TotalMaxAmountCurves { get; set; }

		public List<AnimationCurve> TotalMaxValueCurves { get; set; }

		public List<AnimationCurve> TinyCurves { get; set; }

		public List<AnimationCurve> SmallCurves { get; set; }

		public List<AnimationCurve> MediumCurves { get; set; }

		public List<AnimationCurve> BigCurves { get; set; }

		public List<AnimationCurve> WideCurves { get; set; }

		public List<AnimationCurve> TallCurves { get; set; }

		public List<AnimationCurve> VeryTallCurves { get; set; }

		public ValuableDensityUpgrade(bool enabled, float upgradeAmount, bool exponential, float exponentialAmount, ConfigFile config, AssetBundle assetBundle, float priceMultiplier)
			: base("Valuable Density", "assets/repo/mods/resources/items/items/item upgrade valuable density.asset", enabled, upgradeAmount, exponential, exponentialAmount, config, assetBundle, priceMultiplier, configureAmount: true)
		{
		}

		public override float Calculate(float value, PlayerAvatar player, int level)
		{
			return UpgradeBase<float>.DefaultCalculateFloatIncrease(this, "ValuableDensity", value, player, level);
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "Start")]
	public class LevelGeneratorPatch
	{
		private delegate float difficultyDelegate();

		private static bool initialized;

		private static void Prefix(LevelGenerator __instance)
		{
			ValuableDensityUpgrade valuableDensityUpgrade = SLRUpgradePack.ValuableDensityUpgradeInstance;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !valuableDensityUpgrade.UpgradeEnabled.Value)
			{
				return;
			}
			SLRUpgradePack.Logger.LogInfo((object)"Valuable Density Upgrade runs HERE");
			if (!initialized)
			{
				valuableDensityUpgrade.TinyCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "tinyMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.SmallCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "smallMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.MediumCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "mediumMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.BigCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "bigMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.WideCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "wideMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.TallCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "tallMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.VeryTallCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "veryTallMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.TotalMaxAmountCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "totalMaxAmountCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				valuableDensityUpgrade.TotalMaxValueCurves = (from re in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "totalMaxValueCurve", 10)
					select re.Invoke(ValuableDirector.instance)).ToList();
				initialized = true;
			}
			List<difficultyDelegate> staticNumberedMethodDelegates = GetStaticNumberedMethodDelegates<difficultyDelegate>(typeof(SemiFunc), "RunGetDifficultyMultiplier", Array.Empty<Type>(), 10);
			foreach (string item in valuableDensityUpgrade.TotalMaxAmountCurves.Zip(staticNumberedMethodDelegates, (AnimationCurve curve, difficultyDelegate difficulty) => $"Probably applying valuable density upgrade to {curve.Evaluate(difficulty())}"))
			{
				SLRUpgradePack.Logger.LogInfo((object)item);
			}
			Traverse val = Traverse.Create((object)ValuableDirector.instance).Field("totalMaxAmount");
			if (valuableDensityUpgrade.UpgradeRegister != null && valuableDensityUpgrade.UpgradeRegister.PlayerDictionary != null)
			{
				foreach (KeyValuePair<string, int> pair in valuableDensityUpgrade.UpgradeRegister.PlayerDictionary)
				{
					if (valuableDensityUpgrade.TotalMaxAmountCurves.Count != 0)
					{
						SLRUpgradePack.Logger.LogInfo((object)"Replacing Max Amount curve");
						foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item2 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "totalMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
							where value.Item1.Item1 != null && value.Item1.Item2 != null
							select value)
						{
							item2.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.TotalMaxAmountCurves[item2.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
						}
					}
					else
					{
						SLRUpgradePack.Logger.LogInfo((object)"Setting Max Amount");
						val.SetValue((object)(int)Math.Ceiling(valuableDensityUpgrade.Calculate(val.GetValue<int>(), SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value)));
					}
					if (valuableDensityUpgrade.TotalMaxValueCurves.Count != 0)
					{
						SLRUpgradePack.Logger.LogInfo((object)"Replacing Max Value curve");
						foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item3 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "totalMaxValueCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
							where value.Item1.Item1 != null && value.Item1.Item2 != null
							select value)
						{
							item3.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.TotalMaxValueCurves[item3.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
						}
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Tiny Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item4 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "tinyMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item4.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.TinyCurves[item4.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Small Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item5 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "smallMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item5.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.SmallCurves[item5.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Medium Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item6 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "mediumMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item6.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.MediumCurves[item6.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Big Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item7 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "bigMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item7.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.BigCurves[item7.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Wide Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item8 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "wideMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item8.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.WideCurves[item8.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Tall Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item9 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "tallMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item9.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.TallCurves[item9.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
					SLRUpgradePack.Logger.LogInfo((object)"Replacing Very Tall Max Amount curve");
					foreach (Tuple<Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>, int> item10 in from value in GetNumberedFieldRefs<ValuableDirector, AnimationCurve>(ValuableDirector.instance, "veryTallMaxAmountCurve", 10).Zip(staticNumberedMethodDelegates, Tuple.Create<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate>).Select((Tuple<FieldRef<ValuableDirector, AnimationCurve>, difficultyDelegate> value, int index) => Tuple.Create(value, index))
						where value.Item1.Item1 != null && value.Item1.Item2 != null
						select value)
					{
						item10.Item1.Item1.Invoke(ValuableDirector.instance) = ReplaceCurve(valuableDensityUpgrade.VeryTallCurves[item10.Item2], (float value) => valuableDensityUpgrade.Calculate(value, SemiFunc.PlayerGetFromSteamID(pair.Key), pair.Value));
					}
				}
			}
			SLRUpgradePack.Logger.LogDebug((object)$"Total max items: {val.GetValue<int>()}");
		}

		private static AnimationCurve ReplaceCurve(AnimationCurve target, Func<float, float> calculate)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			AnimationCurve val = new AnimationCurve();
			val.CopyFrom(target);
			val.ClearKeys();
			Keyframe[] keys = target.GetKeys();
			for (int i = 0; i < keys.Length; i++)
			{
				Keyframe val2 = keys[i];
				Keyframe val3 = val2;
				((Keyframe)(ref val3)).value = calculate(((Keyframe)(ref val2)).value);
				Keyframe val4 = val3;
				SLRUpgradePack.Logger.LogDebug((object)$"Increased step at {((Keyframe)(ref val4)).time} from {((Keyframe)(ref val2)).value} to {((Keyframe)(ref val4)).value}");
				val.AddKey(val4);
			}
			return val;
		}

		private static List<FieldRef<S, T>> GetNumberedFieldRefs<S, T>(S source, string expectedBaseName, int checkMax, int checkMin = 0)
		{
			List<FieldRef<S, T>> list = new List<FieldRef<S, T>>();
			if (Traverse.Create((object)source).Field(expectedBaseName).FieldExists())
			{
				list.Add(AccessTools.FieldRefAccess<S, T>(expectedBaseName));
			}
			for (int i = checkMin; i < checkMax; i++)
			{
				if (Traverse.Create((object)source).Field(expectedBaseName + i).FieldExists())
				{
					list.Add(AccessTools.FieldRefAccess<S, T>(expectedBaseName + i));
				}
			}
			return list;
		}

		private static List<T> GetNumberedMethodDelegates<S, T>(S source, string expectedBaseName, Type[] parameters, int checkMax, int checkMin = 0) where T : Delegate
		{
			List<T> list = new List<T>();
			if (Traverse.Create((object)source).Method(expectedBaseName, parameters, (object[])null).MethodExists())
			{
				list.Add(AccessTools.MethodDelegate<T>(AccessTools.Method(typeof(S), expectedBaseName, parameters, (Type[])null), (object)source, true));
			}
			for (int i = checkMin; i < checkMax; i++)
			{
				if (Traverse.Create((object)source).Method(expectedBaseName + i, parameters, (object[])null).MethodExists())
				{
					list.Add(AccessTools.MethodDelegate<T>(AccessTools.Method(typeof(S), expectedBaseName + i, parameters, (Type[])null), (object)source, true));
				}
			}
			return list;
		}

		private static List<T> GetStaticNumberedMethodDelegates<T>(Type source, string expectedBaseName, Type[] parameters, int checkMax, int checkMin = 0) where T : Delegate
		{
			List<T> list = new List<T>();
			if (Traverse.Create(source).Method(expectedBaseName, parameters, (object[])null).MethodExists())
			{
				list.Add(AccessTools.MethodDelegate<T>(AccessTools.Method(source, expectedBaseName, parameters, (Type[])null), (object)source, true));
			}
			for (int i = checkMin; i < checkMax; i++)
			{
				if (Traverse.Create(source).Method(expectedBaseName + i, parameters, (object[])null).MethodExists())
				{
					list.Add(AccessTools.MethodDelegate<T>(AccessTools.Method(source, expectedBaseName + i, parameters, (Type[])null), (object)source, true));
				}
			}
			return list;
		}
	}
}