Decompiled source of MoreShopItems Updated v3.0.0

MoreShopItems.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreShopItems.Compatability;
using MoreShopItems.Config;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreShopItems")]
[assembly: AssemblyDescription("More Shop Items Mod for R.E.P.O.! Originally developed by InfusedGalaxy, updated by Jettcodey.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("InfusedGalaxy, Jettcodey")]
[assembly: AssemblyProduct("MoreShopItems")]
[assembly: AssemblyCopyright("")]
[assembly: ComVisible(false)]
[assembly: Guid("b52829e7-88b6-4158-ba1b-23566c7cf06b")]
[assembly: AssemblyFileVersion("3.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace MoreShopItems
{
	[BepInPlugin("Jettcodey.MoreShopItems", "More Shop Items", "3.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static GameObject? CustomItemShelf;

		private readonly Harmony _harmony = new Harmony("MoreShopItems");

		internal Dictionary<string, ConfigEntry<int>> intConfigEntries = new Dictionary<string, ConfigEntry<int>>();

		internal Dictionary<string, ConfigEntry<bool>> boolConfigEntries = new Dictionary<string, ConfigEntry<bool>>();

		internal static Plugin? Instance { get; private set; }

		internal static ManualLogSource? Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadConfig();
			AssetBundle bundle = LoadAssetBundle("moreshopitems_assets.file");
			CustomItemShelf = LoadAssetFromBundle(bundle, "custom_soda_shelf");
			if ((Object)(object)CustomItemShelf == (Object)null)
			{
				Logger.LogError((object)"Failed to load CustomItemShelf from asset bundle.");
				return;
			}
			_harmony.PatchAll(typeof(ShopManagerPatch));
			_harmony.PatchAll(typeof(PunManagerPatch));
			Logger.LogInfo((object)"Plugin More Shop Items v3.0.0 loaded successfully.");
		}

		private AssetBundle LoadAssetBundle(string filename)
		{
			Plugin? instance = Instance;
			string path = Path.GetDirectoryName((instance != null) ? ((BaseUnityPlugin)instance).Info.Location : null) ?? "";
			string text = Path.Combine(path, filename);
			if (!File.Exists(text))
			{
				Logger.LogError((object)("Asset bundle not found at " + text));
				return null;
			}
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Failed to load asset bundle from " + text));
			}
			return val;
		}

		private GameObject LoadAssetFromBundle(AssetBundle bundle, string assetName)
		{
			if ((Object)(object)bundle == (Object)null)
			{
				return null;
			}
			GameObject val = bundle.LoadAsset<GameObject>(assetName);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Asset '" + assetName + "' not found in bundle."));
			}
			return val;
		}

		private void LoadConfig()
		{
			string[] configDescriptions = ConfigEntries.GetConfigDescriptions();
			intConfigEntries.Add("Max Upgrades In Shop", ConfigHelper.CreateConfig("Upgrades", "Max Upgrades In Shop", 5, configDescriptions[0], -1, 20));
			intConfigEntries.Add("Max Upgrade Purchase Amount", ConfigHelper.CreateConfig("Upgrades", "Max Upgrade Purchase Amount", 0, configDescriptions[1], 0, 1000));
			intConfigEntries.Add("Max Melee Weapons In Shop", ConfigHelper.CreateConfig("Weapons", "Max Melee Weapons In Shop", 5, configDescriptions[2], -1, 20));
			intConfigEntries.Add("Max Melee Weapon Purchase Amount", ConfigHelper.CreateConfig("Weapons", "Max Melee Weapon Purchase Amount", 0, configDescriptions[3], 0, 1000));
			intConfigEntries.Add("Max Guns In Shop", ConfigHelper.CreateConfig("Weapons", "Max Guns In Shop", 5, configDescriptions[4], -1, 20));
			intConfigEntries.Add("Max Gun Purchase Amount", ConfigHelper.CreateConfig("Weapons", "Max Gun Purchase Amount", 0, configDescriptions[5], 0, 1000));
			intConfigEntries.Add("Max Grenades In Shop", ConfigHelper.CreateConfig("Weapons", "Max Grenades In Shop", 5, configDescriptions[6], -1, 20));
			intConfigEntries.Add("Max Grenade Purchase Amount", ConfigHelper.CreateConfig("Weapons", "Max Grenade Purchase Amount", 0, configDescriptions[7], 0, 1000));
			intConfigEntries.Add("Max Mines In Shop", ConfigHelper.CreateConfig("Weapons", "Max Mines In Shop", 5, configDescriptions[8], -1, 20));
			intConfigEntries.Add("Max Mine Purchase Amount", ConfigHelper.CreateConfig("Weapons", "Max Mine Purchase Amount", 0, configDescriptions[9], 0, 1000));
			intConfigEntries.Add("Max Health-Packs In Shop", ConfigHelper.CreateConfig("Health-Packs", "Max Health-Packs In Shop", 15, configDescriptions[10], -1, 20));
			intConfigEntries.Add("Max Health-Pack Purchase Amount", ConfigHelper.CreateConfig("Health-Packs", "Max Health-Pack Purchase Amount", 0, configDescriptions[11], 0, 1000));
			intConfigEntries.Add("Max Drones In Shop", ConfigHelper.CreateConfig("Utilities", "Max Drones In Shop", 5, configDescriptions[12], -1, 20));
			intConfigEntries.Add("Max Drone Purchase Amount", ConfigHelper.CreateConfig("Utilities", "Max Drone Purchase Amount", 0, configDescriptions[13], 0, 1000));
			intConfigEntries.Add("Max Orbs In Shop", ConfigHelper.CreateConfig("Utilities", "Max Orbs In Shop", 5, configDescriptions[14], -1, 20));
			intConfigEntries.Add("Max Orb Purchase Amount", ConfigHelper.CreateConfig("Utilities", "Max Orb Purchase Amount", 0, configDescriptions[15], 0, 1000));
			intConfigEntries.Add("Max Crystals In Shop", ConfigHelper.CreateConfig("Utilities", "Max Crystals In Shop", 10, configDescriptions[16], -1, 20));
			intConfigEntries.Add("Max Crystal Purchase Amount", ConfigHelper.CreateConfig("Utilities", "Max Crystal Purchase Amount", 0, configDescriptions[17], 0, 1000));
			intConfigEntries.Add("Max Trackers In Shop", ConfigHelper.CreateConfig("Utilities", "Max Trackers In Shop", 5, configDescriptions[18], -1, 20));
			intConfigEntries.Add("Max Tracker Purchase Amount", ConfigHelper.CreateConfig("Utilities", "Max Tracker Purchase Amount", 0, configDescriptions[19], 0, 1000));
			intConfigEntries.Add("Max Carts In Shop", ConfigHelper.CreateConfig("Carts", "Max Carts In Shop", 2, configDescriptions[24], -1, 4));
			intConfigEntries.Add("Max Cart Purchase Amount", ConfigHelper.CreateConfig("Carts", "Max Cart Purchase Amount", 0, configDescriptions[25], 0, 100));
			intConfigEntries.Add("Max Pocket Carts In Shop", ConfigHelper.CreateConfig("Carts", "Max Pocket Carts In Shop", 2, configDescriptions[26], -1, 4));
			intConfigEntries.Add("Max Pocket Cart Purchase Amount", ConfigHelper.CreateConfig("Carts", "Max Pocket Cart Purchase Amount", 0, configDescriptions[27], 0, 100));
			intConfigEntries.Add("Max Tools In Shop", ConfigHelper.CreateConfig("Tools", "Max Tools In Shop", 2, configDescriptions[28], -1, 10));
			intConfigEntries.Add("Max Tool Purchase Amount", ConfigHelper.CreateConfig("Tools", "Max Tool Purchase Amount", 0, configDescriptions[29], 0, 100));
			intConfigEntries.Add("Max Additional Shelves In Shop", ConfigHelper.CreateConfig("General", "Max Additional Shelves In Shop", 2, configDescriptions[23], 0, 2));
			boolConfigEntries.Add("Override Modded Items", ConfigHelper.CreateConfig("General", "Override Modded Items", value: true, configDescriptions[20], -1, -1));
			boolConfigEntries.Add("Override Single-Use Upgrades", ConfigHelper.CreateConfig("General", "Override Single-Use Upgrades", value: false, configDescriptions[21], -1, -1));
			boolConfigEntries.Add("Spawn Additional Shelving", ConfigHelper.CreateConfig("General", "Spawn Additional Shelving", value: true, configDescriptions[22], -1, -1));
			boolConfigEntries.Add("Log Potential Items", ConfigHelper.CreateConfig("Dev General", "Log Potential Items", value: false, configDescriptions[30], -1, -1));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Jettcodey.MoreShopItems";

		public const string PLUGIN_NAME = "More Shop Items";

		public const string PLUGIN_VERSION = "3.0.0";
	}
	[HarmonyPatch(typeof(PunManager))]
	internal static class PunManagerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("TruckPopulateItemVolumes")]
		private static void RemoveNullValues()
		{
			if ((Object)(object)ItemManager.instance != (Object)null && (SemiFunc.IsMasterClient() || !SemiFunc.IsMultiplayer()))
			{
				Predicate<ItemVolume> match = (ItemVolume volume) => (Object)(object)volume == (Object)null;
				ItemManager.instance.itemVolumes.RemoveAll(match);
			}
		}
	}
	internal class ShelfEventListener : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		private static bool _created;

		private static readonly HashSet<string> spawnedShelves = new HashSet<string>();

		public static void Ensure()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!_created)
			{
				_created = true;
				GameObject val = new GameObject("MoreShopItems_ShelfEventListener");
				Object.DontDestroyOnLoad((Object)(object)val);
				val.AddComponent<ShelfEventListener>();
				Plugin.Logger.LogInfo((object)"ShelfEventListener created!");
			}
		}

		private void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		public override void OnJoinedRoom()
		{
			lock (spawnedShelves)
			{
				spawnedShelves.Clear();
			}
			Plugin.Logger.LogInfo((object)"[ShelfEventListener] OnJoinedRoom: cleared spawned shelf registry");
		}

		public override void OnLeftRoom()
		{
			lock (spawnedShelves)
			{
				spawnedShelves.Clear();
			}
			Plugin.Logger.LogInfo((object)"[ShelfEventListener] OnLeftRoom: cleared spawned shelf registry");
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_004b: 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)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (photonEvent.Code != 155 || !(photonEvent.CustomData is object[] array) || array.Length < 5)
			{
				return;
			}
			string text = array[0] as string;
			Vector3 val = (Vector3)array[1];
			Quaternion val2 = (Quaternion)array[2];
			string text2 = array[3] as string;
			string text3 = array[4] as string;
			if (!string.IsNullOrEmpty(text) && !spawnedShelves.Contains(text))
			{
				GameObject obj = GameObject.Find(text2);
				Transform val3 = ((obj != null) ? obj.transform : null);
				if ((Object)(object)val3 == (Object)null)
				{
					Plugin.Logger.LogWarning((object)("[ShelfEventListener] Parent " + text2 + " not found for shelf " + text3));
					return;
				}
				Object.Instantiate<GameObject>(Plugin.CustomItemShelf, val, val2, val3);
				spawnedShelves.Add(text);
				Plugin.Logger.LogInfo((object)("[ShelfEventListener] Spawned shelf " + text3 + " for client via event"));
			}
		}
	}
	internal static class ShelfEvents
	{
		public const byte EV_SPAWN_SHELF = 155;

		public static void RaiseSpawnShelf(string shelfID, Vector3 pos, Quaternion rot, string parentName, string placeholder)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom)
			{
				Plugin.Logger.LogWarning((object)("[ShelfEvents] Not in room - cannot raise event for shelf " + placeholder));
				return;
			}
			object[] array = new object[5] { shelfID, pos, rot, parentName, placeholder };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			};
			SendOptions val2 = default(SendOptions);
			((SendOptions)(ref val2)).Reliability = true;
			SendOptions val3 = val2;
			PhotonNetwork.RaiseEvent((byte)155, (object)array, val, val3);
			Plugin.Logger.LogInfo((object)("[ShelfEvents] Master raised EV_SPAWN_SHELF for " + placeholder));
		}
	}
	[HarmonyPatch(typeof(ShopManager))]
	internal static class ShopManagerPatch
	{
		internal static class ShelfSpawner
		{
			public static GameObject? Spawn(Vector3 pos, Quaternion rot, Transform parentTransform, string placeholderName)
			{
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!SemiFunc.IsMultiplayer())
					{
						if ((Object)(object)Plugin.CustomItemShelf == (Object)null)
						{
							Plugin.Logger.LogError((object)"[MoreShopItems] CustomItemShelf is null. Cannot spawn shelf.");
							return null;
						}
						if ((Object)(object)parentTransform != (Object)null)
						{
							return Object.Instantiate<GameObject>(Plugin.CustomItemShelf, pos, rot, parentTransform);
						}
						return Object.Instantiate<GameObject>(Plugin.CustomItemShelf, pos, rot);
					}
					if (SemiFunc.IsMasterClient())
					{
						if ((Object)(object)Plugin.CustomItemShelf == (Object)null)
						{
							Plugin.Logger.LogError((object)"[MoreShopItems] CustomItemShelf is null on host. Cannot spawn shelf.");
							return null;
						}
						string text = Guid.NewGuid().ToString("N");
						GameObject val = Object.Instantiate<GameObject>(Plugin.CustomItemShelf, pos, rot);
						((Object)val).name = "MoreShopShelf_" + text;
						if ((Object)(object)parentTransform != (Object)null)
						{
							val.transform.SetParent(parentTransform, true);
						}
						if (!string.IsNullOrEmpty(placeholderName))
						{
							GameObject val2 = GameObject.Find(placeholderName);
							if ((Object)(object)val2 != (Object)null)
							{
								val2.SetActive(false);
							}
						}
						string parentName = (((Object)(object)parentTransform != (Object)null) ? ((Object)((Component)parentTransform).gameObject).name : string.Empty);
						try
						{
							ShelfEvents.RaiseSpawnShelf(text, pos, rot, parentName, placeholderName ?? string.Empty);
						}
						catch (Exception ex)
						{
							Plugin.Logger.LogError((object)("ShelfSpawner: RaiseSpawnShelf failed: " + ex));
						}
						return val;
					}
					return null;
				}
				catch (Exception ex2)
				{
					Plugin.Logger.LogError((object)("ShelfSpawner.Spawn exception: " + ex2));
					return null;
				}
			}
		}

		private static readonly FieldRef<ShopManager, int> itemSpawnTargetAmount_ref = AccessTools.FieldRefAccess<ShopManager, int>("itemSpawnTargetAmount");

		private static readonly FieldRef<ShopManager, int> itemConsumablesAmount_ref = AccessTools.FieldRefAccess<ShopManager, int>("itemConsumablesAmount");

		private static readonly FieldRef<ShopManager, int> itemUpgradesAmount_ref = AccessTools.FieldRefAccess<ShopManager, int>("itemUpgradesAmount");

		private static readonly FieldRef<ShopManager, int> itemHealthPacksAmount_ref = AccessTools.FieldRefAccess<ShopManager, int>("itemHealthPacksAmount");

		private static GameObject? shelf;

		internal static bool isMoreUpgrades = false;

		[HarmonyPrefix]
		[HarmonyPatch("ShopInitialize")]
		private static void AdjustItems()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected I4, but got Unknown
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Invalid comparison between Unknown and I4
			if (!(RunManager.instance.levelCurrent.ResourcePath == "Shop") || !((Object)(object)StatsManager.instance != (Object)null) || (!SemiFunc.IsMasterClient() && SemiFunc.IsMultiplayer()))
			{
				return;
			}
			Dictionary<string, ConfigEntry<int>> intConfigEntries = Plugin.Instance.intConfigEntries;
			Dictionary<string, ConfigEntry<bool>> boolConfigEntries = Plugin.Instance.boolConfigEntries;
			Plugin.Logger.LogInfo((object)("Override modded items = " + boolConfigEntries["Override Modded Items"].Value));
			foreach (Item value in StatsManager.instance.itemDictionary.Values)
			{
				int num = -2;
				int maxPurchaseAmount = -2;
				itemType itemType = value.itemType;
				itemType val = itemType;
				switch ((int)val)
				{
				case 0:
					if (intConfigEntries["Max Drones In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Drones In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Drone Purchase Amount"].Value;
					}
					break;
				case 1:
					if (intConfigEntries["Max Orbs In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Orbs In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Orb Purchase Amount"].Value;
					}
					break;
				case 3:
					if (intConfigEntries["Max Upgrades In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Upgrades In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Upgrade Purchase Amount"].Value;
					}
					break;
				case 5:
					if (intConfigEntries["Max Crystals In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Crystals In Shop"].Value + 1;
						maxPurchaseAmount = intConfigEntries["Max Crystal Purchase Amount"].Value;
					}
					break;
				case 6:
					if (intConfigEntries["Max Grenades In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Grenades In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Grenade Purchase Amount"].Value;
					}
					break;
				case 7:
					if (intConfigEntries["Max Melee Weapons In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Melee Weapons In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Melee Weapon Purchase Amount"].Value;
					}
					break;
				case 8:
					if (intConfigEntries["Max Health-Packs In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Health-Packs In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Health-Pack Purchase Amount"].Value;
					}
					break;
				case 9:
					if (intConfigEntries["Max Guns In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Guns In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Gun Purchase Amount"].Value;
					}
					break;
				case 10:
					if (intConfigEntries["Max Trackers In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Trackers In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Tracker Purchase Amount"].Value;
					}
					break;
				case 11:
					if (intConfigEntries["Max Mines In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Mines In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Mine Purchase Amount"].Value;
					}
					break;
				case 2:
					if (intConfigEntries["Max Carts In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Carts In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Cart Purchase Amount"].Value;
					}
					break;
				case 12:
					if (intConfigEntries["Max Pocket Carts In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Pocket Carts In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Pocket Cart Purchase Amount"].Value;
					}
					break;
				case 13:
					if (intConfigEntries["Max Tools In Shop"].Value != -1)
					{
						num = intConfigEntries["Max Tools In Shop"].Value;
						maxPurchaseAmount = intConfigEntries["Max Tool Purchase Amount"].Value;
					}
					break;
				default:
					continue;
				}
				bool flag = (int)value.itemType == 3;
				if (num == -2)
				{
					continue;
				}
				if (boolConfigEntries["Override Modded Items"].Value)
				{
					if (boolConfigEntries["Override Single-Use Upgrades"].Value && flag)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
					else if (!value.maxPurchase)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
					else if (!flag)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
				}
				else if (((!MoreUpgradesMOD.isLoaded() && !NikkisUpgradesMOD.isLoaded()) || !((Object)value).name.Contains("Modded")) && !(VanillaUpgradesMOD.isLoaded() && flag))
				{
					if (boolConfigEntries["Override Single-Use Upgrades"].Value && flag)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
					else if (flag && !value.maxPurchase)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
					else if (!flag)
					{
						SetItemValues(value, num, maxPurchaseAmount);
					}
				}
			}
		}

		private static void SetItemValues(Item item, int maxInShop, int maxPurchaseAmount)
		{
			item.maxAmountInShop = (item.maxAmount = maxInShop);
			item.maxPurchase = maxPurchaseAmount > 0;
			item.maxPurchaseAmount = maxPurchaseAmount;
		}

		[PunRPC]
		public static void SetParent(Transform parent, GameObject gameObj)
		{
			gameObj.transform.SetParent(parent);
		}

		[HarmonyPrefix]
		[HarmonyPatch("Awake")]
		private static void SetValues(ShopManager __instance)
		{
			itemConsumablesAmount_ref.Invoke(__instance) = 50;
			itemUpgradesAmount_ref.Invoke(__instance) = 180;
			itemHealthPacksAmount_ref.Invoke(__instance) = 60;
			itemSpawnTargetAmount_ref.Invoke(__instance) = 450;
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetAllItemsFromStatsManager")]
		private static void Postfix(ShopManager __instance)
		{
			__instance.itemConsumablesAmount = 50;
			Plugin.Logger.LogInfo((object)$"Forced itemConsumablesAmount to {__instance.itemConsumablesAmount}");
		}

		[HarmonyPrefix]
		[HarmonyPatch("ShopInitialize")]
		private static void SpawnShelf()
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: 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_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_073a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0822: Unknown result type (might be due to invalid IL or missing references)
			//IL_0824: Unknown result type (might be due to invalid IL or missing references)
			//IL_0860: Unknown result type (might be due to invalid IL or missing references)
			//IL_0862: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0942: Unknown result type (might be due to invalid IL or missing references)
			//IL_0947: Unknown result type (might be due to invalid IL or missing references)
			//IL_0923: Unknown result type (might be due to invalid IL or missing references)
			//IL_0994: Unknown result type (might be due to invalid IL or missing references)
			if (!(RunManager.instance.levelCurrent.ResourcePath == "Shop") || !Plugin.Instance.boolConfigEntries["Spawn Additional Shelving"].Value)
			{
				return;
			}
			ShelfEventListener.Ensure();
			int value = Plugin.Instance.intConfigEntries["Max Additional Shelves In Shop"].Value;
			if (value <= 0)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>();
			int num = 0;
			for (int i = 0; i < value; i++)
			{
				bool flag = false;
				if (!hashSet.Contains("Soda"))
				{
					GameObject val = GameObject.Find("Soda Shelf");
					GameObject val2 = GameObject.Find("Module Switch BOT");
					if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && !val2.GetComponent<ModulePropSwitch>().ConnectedParent.activeSelf)
					{
						Vector3 position = val.transform.position;
						Quaternion rotation = val.transform.rotation;
						Transform transform = val2.transform;
						string placeholderName = "Soda Shelf";
						if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient())
						{
							GameObject val3 = ShelfSpawner.Spawn(position, rotation, transform, placeholderName);
							if ((Object)(object)val3 != (Object)null)
							{
								SetParent(transform, val3);
							}
						}
						else if (!SemiFunc.IsMultiplayer())
						{
							Object.Instantiate<GameObject>(Plugin.CustomItemShelf, position, rotation, transform);
						}
						val.SetActive(false);
						hashSet.Add("Soda");
						num++;
						flag = true;
					}
				}
				if (flag)
				{
					continue;
				}
				if (!hashSet.Contains("Magazine"))
				{
					GameObject val4 = GameObject.Find("Module Switch (1) top");
					GameObject val5 = GameObject.Find("Shop Magazine Stand (1)");
					GameObject val6 = GameObject.Find("Shop Magazine Stand");
					if ((Object)(object)val5 != (Object)null && (Object)(object)val4 != (Object)null && !val4.GetComponent<ModulePropSwitch>().ConnectedParent.activeSelf)
					{
						Vector3 position2 = val5.transform.position;
						Quaternion val7 = val5.transform.rotation * Quaternion.Euler(0f, 90f, 0f);
						Transform parent = val4.transform.parent;
						string placeholderName2 = "Shop Magazine Stand (1)";
						if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient())
						{
							GameObject val8 = ShelfSpawner.Spawn(position2, val7, parent, placeholderName2);
							if ((Object)(object)val8 != (Object)null)
							{
								SetParent(parent, val8);
							}
						}
						else if (!SemiFunc.IsMultiplayer())
						{
							Object.Instantiate<GameObject>(Plugin.CustomItemShelf, position2, val7, parent);
						}
						val5.SetActive(false);
						if ((Object)(object)val6 != (Object)null)
						{
							val6.SetActive(false);
						}
						hashSet.Add("Magazine");
						num++;
						flag = true;
					}
				}
				if (flag)
				{
					continue;
				}
				if (!hashSet.Contains("Candy"))
				{
					GameObject val9 = GameObject.Find("Module Switch (2) left");
					GameObject val10 = GameObject.Find("Candy Shelf");
					if ((Object)(object)val9 != (Object)null && (Object)(object)val10 != (Object)null && !val9.GetComponent<ModulePropSwitch>().ConnectedParent.activeSelf)
					{
						Vector3 val11 = val9.transform.position + val9.transform.right * 0.5f - val9.transform.forward * 0.8f;
						Quaternion val12 = val9.transform.rotation * Quaternion.Euler(0f, 180f, 0f);
						Transform transform2 = val9.transform;
						string placeholderName3 = "Candy Shelf";
						if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient())
						{
							GameObject val13 = ShelfSpawner.Spawn(val11, val12, transform2, placeholderName3);
							if ((Object)(object)val13 != (Object)null)
							{
								SetParent(transform2, val13);
							}
						}
						else if (!SemiFunc.IsMultiplayer())
						{
							Object.Instantiate<GameObject>(Plugin.CustomItemShelf, val11, val12, transform2);
						}
						val10.SetActive(false);
						hashSet.Add("Candy");
						num++;
						flag = true;
					}
				}
				if (flag)
				{
					continue;
				}
				if (!hashSet.Contains("Soda Machine"))
				{
					GameObject val14 = GameObject.Find("Soda Machine (1)");
					GameObject val15 = GameObject.Find("Module Switch (1) top");
					GameObject val16 = GameObject.Find("Shop Owner");
					GameObject val17 = null;
					if ((Object)(object)val15 != (Object)null)
					{
						Transform val18 = val15.transform.Find("Connected");
						if ((Object)(object)val18 != (Object)null)
						{
							Transform obj = val18.Find("Wall 01 - 1x1 - Door (3)");
							val17 = ((obj != null) ? ((Component)obj).gameObject : null);
						}
					}
					bool flag2 = (Object)(object)val17 != (Object)null && !val17.activeSelf && (Object)(object)val16 != (Object)null && val16.activeSelf;
					if ((Object)(object)val14 != (Object)null && (Object)(object)val15 != (Object)null && val14.activeSelf && !flag2)
					{
						Vector3 position3 = val14.transform.position;
						Quaternion val19 = Quaternion.Euler(0f, 90f, 0f);
						Transform transform3 = val15.transform;
						string placeholderName4 = "Soda Machine (1)";
						if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient())
						{
							GameObject val20 = ShelfSpawner.Spawn(position3, val19, transform3, placeholderName4);
							if ((Object)(object)val20 != (Object)null)
							{
								SetParent(transform3, val20);
							}
						}
						else if (!SemiFunc.IsMultiplayer())
						{
							Object.Instantiate<GameObject>(Plugin.CustomItemShelf, position3, val19, transform3);
						}
						val14.SetActive(false);
						hashSet.Add("Soda Machine");
						num++;
						flag = true;
					}
					else if (flag2 && (Object)(object)val14 != (Object)null)
					{
						val14.SetActive(true);
					}
				}
				if (flag)
				{
					continue;
				}
				if (!hashSet.Contains("cashiers shelf"))
				{
					GameObject val21 = GameObject.Find("Module Switch (2) right");
					GameObject val22 = GameObject.Find("cashiers shelf");
					GameObject val23 = GameObject.Find("cashiers desk");
					GameObject val24 = GameObject.Find("Shop Magazine Holder");
					GameObject val25 = GameObject.Find("Shop Cash register");
					GameObject val26 = GameObject.Find("Shop Chair");
					GameObject val27 = GameObject.Find("Shop Owner");
					Transform val28 = ((val21 != null) ? val21.transform.Find("Connected") : null);
					if ((Object)(object)val21 != (Object)null && (Object)(object)val28 != (Object)null && !((Component)val28).gameObject.activeSelf && (Object)(object)val22 != (Object)null)
					{
						Vector3 position4 = val21.transform.position;
						bool flag3 = Vector3.Distance(position4, new Vector3(-7.9544f, 0f, 7.7214f)) < 0.01f;
						bool flag4 = Vector3.Distance(position4, new Vector3(7.9544f, 0f, 7.2786f)) < 0.01f;
						Vector3 position5 = val22.transform.position;
						if (flag3)
						{
							position5.x += 0.4f;
							position5.z += 1f;
						}
						else if (flag4)
						{
							position5.x -= 0.5f;
							position5.z -= 0.9f;
						}
						else
						{
							position5.x += 1f;
							position5.z -= 0.4f;
						}
						Quaternion val29 = val22.transform.rotation * Quaternion.Euler(0f, 180f, 0f);
						Transform transform4 = val21.transform;
						string placeholderName5 = "cashiers shelf";
						if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient())
						{
							GameObject val30 = ShelfSpawner.Spawn(position5, val29, transform4, placeholderName5);
							if ((Object)(object)val30 != (Object)null)
							{
								SetParent(transform4, val30);
							}
						}
						else if (!SemiFunc.IsMultiplayer())
						{
							Object.Instantiate<GameObject>(Plugin.CustomItemShelf, position5, val29, transform4);
						}
						val22.SetActive(false);
						if ((Object)(object)val24 != (Object)null)
						{
							val24.SetActive(false);
						}
						if ((Object)(object)val26 != (Object)null)
						{
							val26.SetActive(false);
						}
						if ((Object)(object)val27 != (Object)null)
						{
							val27.SetActive(false);
						}
						if ((Object)(object)val23 != (Object)null)
						{
							Vector3 position6 = val23.transform.position;
							if (flag3)
							{
								position6.x += 0.9f;
							}
							else if (flag4)
							{
								position6.x -= 0.9f;
							}
							else
							{
								position6.z -= 1f;
							}
							val23.transform.position = position6;
						}
						if ((Object)(object)val25 != (Object)null)
						{
							Vector3 position7 = val25.transform.position;
							if (flag3)
							{
								position7.x += 0.9f;
							}
							else if (flag4)
							{
								position7.x -= 0.9f;
							}
							else
							{
								position7.z -= 1f;
							}
							val25.transform.position = position7;
						}
						hashSet.Add("cashiers shelf");
						num++;
						flag = true;
					}
				}
				if (!flag)
				{
					Plugin.Logger.LogInfo((object)$"No more available locations found. Stopping shelf spawn at {num} shelves.");
					break;
				}
			}
			if (num > 0)
			{
				Plugin.Logger.LogInfo((object)$"Successfully spawned {num} custom shelf/shelves!");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetAllItemVolumesInScene")]
		private static void LogPotentialItems(ShopManager __instance)
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Instance.boolConfigEntries["Log Potential Items"].Value || (Object)(object)__instance == (Object)null)
			{
				return;
			}
			Plugin.Logger.LogInfo((object)"--- Shop Initialization: Starting Item Scan ---");
			Task.Delay(2000).Wait();
			LogItemCollection(__instance.potentialItems, "Standard Items");
			LogItemCollection(__instance.potentialItemUpgrades, "Upgrade Items");
			LogItemCollection(__instance.potentialItemConsumables, "Consumables");
			LogItemCollection(__instance.potentialItemHealthPacks, "Health Packs");
			if (__instance.potentialSecretItems.Count > 0)
			{
				Plugin.Logger.LogInfo((object)$"Found {__instance.potentialSecretItems.Count} potential Secret Items (grouped):");
				foreach (KeyValuePair<itemSecretShopType, List<Item>> potentialSecretItem in __instance.potentialSecretItems)
				{
					Plugin.Logger.LogInfo((object)$"  Category: {potentialSecretItem.Key}");
					LogItemCollection(potentialSecretItem.Value, "", nested: true);
				}
			}
			else
			{
				Plugin.Logger.LogInfo((object)"No potential Secret Items found.");
			}
			Plugin.Logger.LogInfo((object)"--- Shop Initialization: Item Scan Complete ---");
		}

		private static void LogItemCollection(List<Item> items, string collectionName, bool nested = false)
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (items != null && items.Count > 0)
			{
				if (!string.IsNullOrEmpty(collectionName))
				{
					Plugin.Logger.LogInfo((object)$"Found {items.Count} potential {collectionName}:");
				}
				int num = 0;
				foreach (Item item in items)
				{
					if (item.itemName != null && item.itemName.Length > num)
					{
						num = item.itemName.Length;
					}
				}
				num += 3;
				{
					foreach (Item item2 in items)
					{
						string arg = (nested ? "    - " : "  - ");
						Plugin.Logger.LogInfo((object)$"{arg}Name: {item2.itemName.PadRight(num)}Type: {item2.itemType}");
					}
					return;
				}
			}
			if (!string.IsNullOrEmpty(collectionName))
			{
				Plugin.Logger.LogInfo((object)("No potential " + collectionName + " found."));
			}
		}
	}
}
namespace MoreShopItems.Config
{
	public static class ConfigEntries
	{
		private static string[] DESCRIPTIONS = new string[31]
		{
			"How many of each upgrade to spawn in the shop.", "How many upgrades you can purchase total. Set 0 to disable", "How many of each melee weapon to spawn in the shop.", "How many melee weapons you can purchase total. Set 0 to disable", "How many of each gun to spawn in the shop.", "How many guns you can purchase total. Set 0 to disable", "How many of each grenade to spawn in the shop.", "How many grenades you can purchase total. Set 0 to disable", "How many of each mine to spawn in the shop.", "How many mines you can purchase total. Set 0 to disable",
			"How many of each health-pack to spawn in the shop.", "How many health-packs you can purchase total. Set 0 to disable", "How many of each drone to spawn in the shop.", "How many drones you can purchase total. Set 0 to disable", "How many of each orb to spawn in the shop.", "How many orbs you can purchase total. Set 0 to disable", "How many of each crystal to spawn in the shop.", "How many crystals you can purchase total. Set 0 to disable", "How many trackers to spawn in the shop.", "How many trackers you can purchase total. Set 0 to disable",
			"Overrides the values (MaxAmountInShop, MaxPurchaseAmount) set by other item/upgrade mods.", "Overrides the values (MaxAmountInShop, MaxPurchaseAmount) of single-use upgrades.", "Spawns the additional shelving into the shop (set false to disable the shelf spawning).", "How many additional shelving units to spawn in the shop. Set 0 to disable.", "How many Carts to spawn in the shop.", "How many Carts you can purchase total. Set 0 to disable", "How many Pocket Carts to spawn in the shop.", "How many Pocket Carts you can purchase total. Set 0 to disable", "How many Tools to spawn in the shop.", "How many Tools you can purchase total. Set 0 to disable",
			"Enable logging of the potential items Spawning in the shop."
		};

		public static string[] GetConfigDescriptions()
		{
			return DESCRIPTIONS;
		}
	}
	public class ConfigHelper
	{
		public static ConfigEntry<bool> CreateConfig(string section, string name, bool value, string description, int min, int max)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>(section, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}

		public static ConfigEntry<int> CreateConfig(string section, string name, int value, string description, int min, int max)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>(section, name, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(min, max), Array.Empty<object>()));
		}
	}
}
namespace MoreShopItems.Compatability
{
	internal static class MoreUpgradesMOD
	{
		public static bool isLoaded()
		{
			return Chainloader.PluginInfos.ContainsKey("bulletbot.moreupgrades");
		}
	}
	internal static class NikkisUpgradesMOD
	{
		public static bool isLoaded()
		{
			return Chainloader.PluginInfos.ContainsKey("NikkiUpgrades");
		}
	}
	internal static class VanillaUpgradesMOD
	{
		public static bool isLoaded()
		{
			return Chainloader.PluginInfos.ContainsKey("bulletbot.vanillaupgrades");
		}
	}
}