Decompiled source of BazaarIsMyHaven v5.1.0

BazaarIsMyHaven.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.CaptainSupplyDrop;
using EntityStates.Missions.RepurposedCrater;
using EntityStates.NewtMonster;
using EntityStates.Wisp1Monster;
using HG.Reflection;
using InLobbyConfig;
using InLobbyConfig.Fields;
using ItemStringParser;
using Microsoft.CodeAnalysis;
using On.EntityStates.CaptainSupplyDrop;
using On.EntityStates.Missions.RepurposedCrater;
using On.EntityStates.NewtMonster;
using On.RoR2;
using On.RoR2.Projectile;
using R2API.Utils;
using RoR2;
using RoR2.Artifacts;
using RoR2.CharacterAI;
using RoR2.Hologram;
using RoR2.Navigation;
using RoR2.Networking;
using RoR2.Projectile;
using RoR2.Scripts.GameBehaviors;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BazaarIsMyHaven")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b97861694253c4f1b3080898672b7303f5941aae")]
[assembly: AssemblyProduct("BazaarIsMyHaven")]
[assembly: AssemblyTitle("BazaarIsMyHaven")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BazaarIsMyHaven
{
	public abstract class BazaarBase
	{
		protected Random RNG = new Random();

		public abstract void Preload();

		public abstract void SetupBazaar();

		public virtual void Hook()
		{
		}

		public virtual void RunStart()
		{
		}

		public virtual void RunEnd()
		{
		}

		public virtual void AddDirectorCards(List<DirectorCard> cards)
		{
		}

		public virtual int CheckAfterSetup()
		{
			return 0;
		}

		public virtual void SpawnLatePicks()
		{
		}

		protected static GameObject SpawnAt(GameObject prefab, SpawnCardStruct slot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(prefab, slot.Position, Quaternion.Euler(slot.Rotation));
			NetworkServer.Spawn(obj);
			return obj;
		}

		protected static List<GameObject> SpawnInSlots(Dictionary<int, SpawnCardStruct> slots, GameObject prefab, int start, int count)
		{
			List<GameObject> list = new List<GameObject>();
			for (int i = start; i < start + count; i++)
			{
				list.Add(SpawnAt(prefab, slots[i]));
			}
			return list;
		}

		public static void SpawnEffect(AsyncOperationHandle<GameObject> effect, Vector3 position, Color32 color, float scale = 1f)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			EffectManager.SpawnEffect(effect.WaitForCompletion(), new EffectData
			{
				origin = position,
				rotation = Quaternion.identity,
				scale = scale,
				color = color
			}, true);
		}

		protected bool IsCurrentMapInBazaar()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name == "bazaar";
		}

		protected bool IsMultiplayer()
		{
			return PlayerCharacterMasterController.instances.Count > 1;
		}

		protected T GetRandom<T>(List<T> list, T defaultValue)
		{
			if (list == null || list.Count == 0)
			{
				return defaultValue;
			}
			return list[RNG.Next(list.Count)];
		}

		protected List<t> DisorderList<t>(List<t> TList)
		{
			List<t> list = new List<t>();
			foreach (t T in TList)
			{
				list.Insert(RNG.Next(list.Count()), T);
			}
			return list;
		}
	}
	public class BazaarCauldron : BazaarBase
	{
		private AsyncOperationHandle<GameObject> lunarCauldronWhiteToGreen;

		private AsyncOperationHandle<GameObject> lunarCauldronGreenToRed;

		private AsyncOperationHandle<GameObject> lunarCauldronRedToWhite;

		private AsyncOperationHandle<GameObject> transcendentCauldron;

		private AsyncOperationHandle<GameObject>[] LunarCauldronsCode;

		private Dictionary<int, SpawnCardStruct> DicCauldrons = new Dictionary<int, SpawnCardStruct>();

		private DirectorCard card;

		private int spawned;

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			lunarCauldronWhiteToGreen = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCauldrons/LunarCauldron, WhiteToGreen.prefab");
			lunarCauldronGreenToRed = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCauldrons/LunarCauldron, GreenToRed Variant.prefab");
			lunarCauldronRedToWhite = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCauldrons/LunarCauldron, RedToWhite Variant.prefab");
			transcendentCauldron = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC4/BetterCauldron.prefab");
			LunarCauldronsCode = new AsyncOperationHandle<GameObject>[4] { lunarCauldronWhiteToGreen, lunarCauldronGreenToRed, lunarCauldronRedToWhite, transcendentCauldron };
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			PurchaseInteraction.Awake += new hook_Awake(PurchaseInteraction_Awake);
			PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(PurchaseInteraction_OnInteractionBegin);
			ShopTerminalBehavior.SetPickup += new hook_SetPickup(ShopTerminalBehavior_SetPickup);
		}

		public override void RunStart()
		{
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			card = null;
			if (!ModConfig.CauldronSectionEnabled.Value)
			{
				return;
			}
			if (!GetRandomLunarCauldron().IsValid())
			{
				Log.LogWarning("No cauldron types with a valid weight; skipping cauldrons.");
				return;
			}
			card = new DirectorCard("Lunar Cauldron", ModConfig.CauldronDirectorCost, ModConfig.CauldronDirectorWeight, () => ModConfig.CauldronMaxAmount.Value);
			cards.Add(card);
		}

		public override void SetupBazaar()
		{
			if (card != null)
			{
				DicCauldrons.Clear();
				SetCauldron();
				spawned = 0;
				SpawnLatePicks();
			}
		}

		public override void SpawnLatePicks()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (card != null)
			{
				while (spawned < card.Count)
				{
					BazaarBase.SpawnAt(GetRandomLunarCauldron().WaitForCompletion(), DicCauldrons[spawned]);
					spawned++;
				}
			}
		}

		public void PurchaseInteraction_Awake(orig_Awake orig, PurchaseInteraction self)
		{
			orig.Invoke(self);
			if (ModConfig.EnableMod.Value && ModConfig.CauldronSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active)
			{
				if (((Object)self).name.StartsWith("LunarCauldron, WhiteToGreen"))
				{
					self.cost = ModConfig.CauldronWhiteToGreenCost.Value;
					self.Networkcost = ModConfig.CauldronWhiteToGreenCost.Value;
				}
				if (((Object)self).name.StartsWith("LunarCauldron, GreenToRed"))
				{
					self.cost = ModConfig.CauldronGreenToRedCost.Value;
					self.Networkcost = ModConfig.CauldronGreenToRedCost.Value;
				}
				if (((Object)self).name.StartsWith("LunarCauldron, RedToWhite"))
				{
					self.cost = ModConfig.CauldronRedToWhiteCost.Value;
					self.Networkcost = ModConfig.CauldronRedToWhiteCost.Value;
				}
				if (((Object)self).name.StartsWith("BetterCauldron"))
				{
					self.cost = ModConfig.CauldronTranscendentCost.Value;
					self.Networkcost = ModConfig.CauldronTranscendentCost.Value;
				}
			}
		}

		public void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_00bb: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Invalid comparison between Unknown and I4
			if (ModConfig.EnableMod.Value && ModConfig.CauldronSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active && ((Object)self).name.StartsWith("LunarCauldron, RedToWhite Variant") && IsMultiplayer() && ModCompatibilityShareSuite.enabled && ModCompatibilityShareSuite.IsShareSuite_PrinterCauldronFixEnabled())
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
				Inventory inventory = (Object.op_Implicit((Object)(object)val) ? val.inventory : null);
				ShopTerminalBehavior component = ((Component)self).GetComponent<ShopTerminalBehavior>();
				PickupDef pickupDef = (Object.op_Implicit((Object)(object)component) ? PickupCatalog.GetPickupDef(component.CurrentPickup().pickupIndex) : null);
				if (Object.op_Implicit((Object)(object)inventory) && pickupDef != null && (int)pickupDef.itemIndex != -1)
				{
					bool compensated = false;
					UnityAction<PayCostContext, PayCostResults> val2 = delegate(PayCostContext context, PayCostResults results)
					{
						//IL_003b: Unknown result type (might be due to invalid IL or missing references)
						if (!compensated && (Object)(object)context.activator == (Object)(object)activator && Object.op_Implicit((Object)(object)inventory))
						{
							compensated = true;
							inventory.GiveItemPermanent(pickupDef.itemIndex, 2);
						}
					};
					((UnityEvent<PayCostContext, PayCostResults>)(object)self.onDetailedPurchaseServer).AddListener(val2);
					try
					{
						orig.Invoke(self, activator);
						return;
					}
					finally
					{
						((UnityEvent<PayCostContext, PayCostResults>)(object)self.onDetailedPurchaseServer).RemoveListener(val2);
					}
				}
			}
			orig.Invoke(self, activator);
		}

		public void ShopTerminalBehavior_SetPickup(orig_SetPickup orig, ShopTerminalBehavior self, UniquePickup newPickup, bool newHidden)
		{
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.EnableMod.Value && ModConfig.CauldronSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active)
			{
				if (((Object)self).name.StartsWith("LunarCauldronGreen"))
				{
					CauldronHacked_SetPickupIndex(self, out var listLunarItem);
					if (listLunarItem.Count > 0)
					{
						newPickup.pickupIndex = listLunarItem[RNG.Next(0, listLunarItem.Count)];
					}
				}
				if (((Object)self).name.StartsWith("LunarCauldronRed"))
				{
					CauldronHacked_SetPickupIndex(self, out var listLunarItem2);
					if (listLunarItem2.Count > 0)
					{
						newPickup.pickupIndex = listLunarItem2[RNG.Next(0, listLunarItem2.Count)];
					}
				}
				if (((Object)self).name.StartsWith("LunarCauldronWhite"))
				{
					CauldronHacked_SetPickupIndex(self, out var listLunarItem3);
					if (listLunarItem3.Count > 0)
					{
						newPickup.pickupIndex = listLunarItem3[RNG.Next(0, listLunarItem3.Count)];
					}
				}
			}
			orig.Invoke(self, newPickup, newHidden);
		}

		private void SetCauldron()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = new List<int> { 0, 1, 2, 3, 4, 5, 6 };
			List<int> list2 = new List<int>();
			while (list.Count > 0)
			{
				int index = RNG.Next(list.Count);
				list2.Add(list[index]);
				list.RemoveAt(index);
			}
			DicCauldrons.Add(list2[0], new SpawnCardStruct(new Vector3(-115.9816f, -24.1175f, -6.2091f), new Vector3(0f, 120f, 0f)));
			DicCauldrons.Add(list2[1], new SpawnCardStruct(new Vector3(-119.928f, -24.1238f, -7.0865f), new Vector3(0f, 140f, 0f)));
			DicCauldrons.Add(list2[2], new SpawnCardStruct(new Vector3(-123.4725f, -23.7951f, -5.469f), new Vector3(0f, 160f, 0f)));
			DicCauldrons.Add(list2[3], new SpawnCardStruct(new Vector3(-107.8159f, -23.8448f, -4.517f), new Vector3(0f, 130f, 0f)));
			DicCauldrons.Add(list2[4], new SpawnCardStruct(new Vector3(-101.2425f, -24.8612f, -9.1464f), new Vector3(0f, 160f, 0f)));
			DicCauldrons.Add(list2[5], new SpawnCardStruct(new Vector3(-98.5219f, -25.6548f, -12.3659f), new Vector3(0f, 155f, 0f)));
			DicCauldrons.Add(list2[6], new SpawnCardStruct(new Vector3(-94.6071f, -25.8717f, -13.6159f), new Vector3(0f, 135f, 0f)));
		}

		private void CauldronHacked_SetPickupIndex(ShopTerminalBehavior self, out List<PickupIndex> listLunarItem)
		{
			listLunarItem = new List<PickupIndex>();
			if (((Object)self).name.EndsWith("Yellow"))
			{
				listLunarItem.AddRange(Run.instance.availableBossDropList);
			}
			if (((Object)self).name.EndsWith("Blue"))
			{
				listLunarItem.AddRange(Run.instance.availableLunarItemDropList);
			}
			if (((Object)self).name.EndsWith("Purple"))
			{
				listLunarItem.AddRange(Run.instance.availableVoidTier1DropList);
				listLunarItem.AddRange(Run.instance.availableVoidTier2DropList);
				listLunarItem.AddRange(Run.instance.availableVoidTier3DropList);
				listLunarItem.AddRange(Run.instance.availableVoidBossDropList);
			}
		}

		private AsyncOperationHandle<GameObject> GetRandomLunarCauldron()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			float num = ModConfig.CauldronWhiteToGreenWeight.Value;
			float num2 = ModConfig.CauldronGreenToRedWeight.Value;
			float num3 = ModConfig.CauldronRedToWhiteWeight.Value;
			float num4 = ((Object.op_Implicit((Object)(object)DLC4Content.DLC4) && Run.instance.IsExpansionEnabled(DLC4Content.DLC4)) ? ModConfig.CauldronTranscendentWeight.Value : 0f);
			if (num < 0f)
			{
				num = 0f;
			}
			if (num2 < 0f)
			{
				num2 = 0f;
			}
			if (num3 < 0f)
			{
				num3 = 0f;
			}
			if (num4 < 0f)
			{
				num4 = 0f;
			}
			float num5 = num + num2 + num3 + num4;
			if (num5 == 0f)
			{
				return default(AsyncOperationHandle<GameObject>);
			}
			double num6 = RNG.NextDouble() * (double)num5;
			if (num6 < (double)num)
			{
				return LunarCauldronsCode[0];
			}
			if (num6 < (double)(num + num2))
			{
				return LunarCauldronsCode[1];
			}
			if (num6 < (double)(num + num2 + num3))
			{
				return LunarCauldronsCode[2];
			}
			return LunarCauldronsCode[3];
		}
	}
	public class BazaarCleansingPool : BazaarBase
	{
		private AsyncOperationHandle<InteractableSpawnCard> iscShrineCleanse;

		private AsyncOperationHandle<GameObject> lunarShopTerminal;

		private Dictionary<int, SpawnCardStruct> DicLunarPools = new Dictionary<int, SpawnCardStruct>();

		private DirectorCard card;

		private bool spawned;

		private GameObject pool;

		private GameObject hoveringCoin;

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			iscShrineCleanse = Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"RoR2/Base/ShrineCleanse/iscShrineCleanse.asset");
			lunarShopTerminal = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarShopTerminal/LunarShopTerminal.prefab");
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			ShopTerminalBehavior.SetPickup += new hook_SetPickup(ShopTerminalBehavior_SetPickup);
		}

		public override void RunStart()
		{
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			card = null;
			if (ModConfig.CleansingPoolSectionEnabled.Value)
			{
				card = new DirectorCard("Cleansing Pool", ModConfig.CleansingPoolDirectorCost, ModConfig.CleansingPoolDirectorWeight, () => 1);
				cards.Add(card);
			}
		}

		public override void SetupBazaar()
		{
			spawned = false;
			pool = null;
			hoveringCoin = null;
			SpawnLatePicks();
		}

		public override void SpawnLatePicks()
		{
			if (card != null && card.Count != 0 && !spawned)
			{
				SpawnShrineCleanse();
				spawned = true;
			}
		}

		private void ShopTerminalBehavior_SetPickup(orig_SetPickup orig, ShopTerminalBehavior self, UniquePickup newPickup, bool newHidden)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.CleansingPoolRewardsLunarCoins.Value && NetworkServer.active && Object.op_Implicit((Object)(object)self))
			{
				if (Object.op_Implicit((Object)(object)pool) && (Object)(object)((Component)self).gameObject == (Object)(object)pool)
				{
					newPickup.pickupIndex = PickupCatalog.FindPickupIndex(MiscPickups.LunarCoin.miscPickupIndex);
				}
				if (Object.op_Implicit((Object)(object)hoveringCoin) && (Object)(object)((Component)self).gameObject == (Object)(object)hoveringCoin)
				{
					newPickup.pickupIndex = PickupCatalog.FindPickupIndex(MiscPickups.LunarCoin.miscPickupIndex);
					((Component)self).gameObject.GetComponent<PurchaseInteraction>().SetAvailable(false);
				}
			}
			orig.Invoke(self, newPickup, newHidden);
		}

		private void SpawnShrineCleanse()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			DicLunarPools.Clear();
			SetLunarPool();
			pool = BazaarBase.SpawnAt(((SpawnCard)iscShrineCleanse.WaitForCompletion()).prefab, DicLunarPools[0]);
			if (ModConfig.CleansingPoolRewardsLunarCoins.Value)
			{
				GameObject val = Object.Instantiate<GameObject>(lunarShopTerminal.WaitForCompletion(), DicLunarPools[0].Position, Quaternion.identity);
				val.transform.localPosition = new Vector3(DicLunarPools[0].Position.x, DicLunarPools[0].Position.y + 0.5f, DicLunarPools[0].Position.z);
				val.transform.eulerAngles = DicLunarPools[0].Rotation;
				((Object)val).name = "HoveringLunarCoin";
				hoveringCoin = val;
				NetworkServer.Spawn(val);
			}
		}

		private void SetLunarPool()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			DicLunarPools.Add(0, new SpawnCardStruct(new Vector3(-71.5092f, -25.5622f, -44.2288f), new Vector3(6.4123f, 0f, 356.459f)));
		}
	}
	public class BazaarCommandPedestal : BazaarBase
	{
		private class Essence
		{
			public CharacterMaster owner;

			public Vector3 vaultPosition;
		}

		private class CommandPedestalCard : DirectorCard
		{
			public ModConfig.CommandPedestalTier tier;

			public override float Weight
			{
				get
				{
					if (GetTiers().Count <= 0)
					{
						return 0f;
					}
					return base.Weight;
				}
			}

			public CommandPedestalCard()
				: base("Command Pedestal", null, ModConfig.CommandPedestalDirectorWeight, () => 1)
			{
			}

			private static List<ModConfig.CommandPedestalTier> GetTiers()
			{
				return ModConfig.CommandPedestalTiers.Where((ModConfig.CommandPedestalTier tier) => tier.weight.Value > 0f && tier.dropList(Run.instance).Count > 0).ToList();
			}

			protected override int CheapestCost()
			{
				List<ModConfig.CommandPedestalTier> tiers = GetTiers();
				if (tiers.Count != 0)
				{
					return tiers.Min((ModConfig.CommandPedestalTier tier) => Math.Max(0, tier.directorCost.Value));
				}
				return int.MaxValue;
			}

			protected override int PickCost(int credits)
			{
				WeightedSelection<ModConfig.CommandPedestalTier> val = new WeightedSelection<ModConfig.CommandPedestalTier>(8);
				foreach (ModConfig.CommandPedestalTier tier in GetTiers())
				{
					if (Math.Max(0, tier.directorCost.Value) <= credits)
					{
						val.AddChoice(tier, tier.weight.Value);
					}
				}
				this.tier = val.Evaluate(Random.value);
				return Math.Max(0, this.tier.directorCost.Value);
			}
		}

		private const float SignHeight = 4.5f;

		private const float HiddenEssenceDepth = 5f;

		private const float DisplayDropHeight = 5f;

		private AsyncOperationHandle<GameObject> vaultPrefab;

		private AsyncOperationHandle<GameObject> shrineUseEffect;

		private CommandPedestalCard card;

		private bool spawned;

		private GameObject pedestal;

		private Xoroshiro128Plus rng;

		private bool sold;

		private UniquePickup offer;

		private bool hasOffer;

		private GameObject displayEssence;

		private readonly HashSet<PlayerCharacterMasterController> buyers = new HashSet<PlayerCharacterMasterController>();

		private readonly Dictionary<PickupPickerController, Essence> essences = new Dictionary<PickupPickerController, Essence>();

		private readonly Dictionary<PlayerCharacterMasterController, EquipmentIndex> storedEquipment = new Dictionary<PlayerCharacterMasterController, EquipmentIndex>();

		public static BazaarCommandPedestal instance;

		public BazaarCommandPedestal()
		{
			instance = this;
		}

		public IEnumerable<PickupIndex> GetChoicesFor(PlayerCharacterMasterController player)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)pedestal) || !hasOffer || sold || (ModConfig.CommandPedestalInstancedPurchases.Value && buyers.Contains(player)))
			{
				return Enumerable.Empty<PickupIndex>();
			}
			IEnumerable<PickupIndex> availableGroupFromPickupIndex = PickupTransmutationManager.GetAvailableGroupFromPickupIndex(offer.pickupIndex);
			return availableGroupFromPickupIndex ?? Enumerable.Empty<PickupIndex>();
		}

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			vaultPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/PowerOrbPedestal/PowerOrbVault.prefab");
			shrineUseEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/ShrineUseEffect.prefab");
			PriceSigns.Preload();
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			PowerOrbPedestalManager.DoOnInteract += new hook_DoOnInteract(PowerOrbPedestalManager_DoOnInteract);
			GenericInteraction.RoR2_IInteractable_GetInteractability += new hook_RoR2_IInteractable_GetInteractability(GenericInteraction_GetInteractability);
			PickupPickerController.GetInteractability += new hook_GetInteractability(PickupPickerController_GetInteractability);
			PickupPickerController.CreatePickup_UniquePickup += new hook_CreatePickup_UniquePickup(PickupPickerController_CreatePickup);
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			card = null;
			if (ModConfig.CommandPedestalSectionEnabled.Value)
			{
				card = new CommandPedestalCard();
				cards.Add(card);
			}
		}

		public override void SetupBazaar()
		{
			spawned = false;
			pedestal = null;
			displayEssence = null;
			hasOffer = false;
			sold = false;
			buyers.Clear();
			essences.Clear();
			storedEquipment.Clear();
			SpawnLatePicks();
		}

		public override void SpawnLatePicks()
		{
			if (card != null && card.Count != 0 && !spawned)
			{
				SpawnCommandPedestal();
				spawned = true;
			}
		}

		private bool IsBazaarChest(Component component)
		{
			if (Object.op_Implicit((Object)(object)pedestal) && Object.op_Implicit((Object)(object)component) && (Object)(object)component.gameObject == (Object)(object)pedestal)
			{
				return NetworkServer.active;
			}
			return false;
		}

		private static PlayerCharacterMasterController GetPlayer(GameObject bodyObject)
		{
			CharacterBody val = (Object.op_Implicit((Object)(object)bodyObject) ? bodyObject.GetComponent<CharacterBody>() : null);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.master))
			{
				return null;
			}
			return val.master.playerCharacterMasterController;
		}

		private void PowerOrbPedestalManager_DoOnInteract(orig_DoOnInteract orig, PowerOrbPedestalManager self, GameObject interactorObject)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (!IsBazaarChest((Component)(object)self))
			{
				orig.Invoke(self, interactorObject);
				return;
			}
			Interactor val = (Object.op_Implicit((Object)(object)interactorObject) ? interactorObject.GetComponent<Interactor>() : null);
			CharacterBody val2 = (Object.op_Implicit((Object)(object)interactorObject) ? interactorObject.GetComponent<CharacterBody>() : null);
			PlayerCharacterMasterController player = GetPlayer(interactorObject);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)player))
			{
				return;
			}
			if (storedEquipment.ContainsKey(player))
			{
				SwapStoredEquipment(self, player, val2);
			}
			else
			{
				if (sold || (ModConfig.CommandPedestalInstancedPurchases.Value && buyers.Contains(player)))
				{
					return;
				}
				CostTypeIndex value = ModConfig.CommandPedestalCostType.Value;
				int price = GetPrice();
				if (!Helper.CanAfford(value, price, val, val2))
				{
					Refuse(self);
				}
				else if (ModConfig.CommandPedestalBuyToInventory.Value)
				{
					if (TryGetWaitingEssence(val2.master, out var picker))
					{
						picker.OnInteractionBegin(val);
					}
					else if (hasOffer)
					{
						SpawnHiddenEssence(self, offer, val);
					}
					else
					{
						Refuse(self);
					}
				}
				else if (!hasOffer)
				{
					Refuse(self);
				}
				else
				{
					Helper.PayCost(value, price, val, val2, pedestal, rng);
					CompletePurchase(self, player);
					DropEssence(self, offer);
				}
			}
		}

		private static void Refuse(PowerOrbPedestalManager vault)
		{
			vault.DoInteractResult(false);
			vault.CallRpcInteractResult(false);
		}

		private void CompletePurchase(PowerOrbPedestalManager vault, PlayerCharacterMasterController player)
		{
			if (ModConfig.CommandPedestalInstancedPurchases.Value)
			{
				buyers.Add(player);
				UpdateSwapAvailability(player);
				HideDisplayFor(player);
				PriceSigns.HideFor(pedestal, player);
				PlayBuyEffect(vault);
				return;
			}
			sold = true;
			if (Object.op_Implicit((Object)(object)displayEssence))
			{
				NetworkServer.Destroy(displayEssence);
			}
			vault.DoInteractResult(true);
			vault.CallRpcInteractResult(true);
			if (storedEquipment.ContainsKey(player))
			{
				((MonoBehaviour)Main.instance).StartCoroutine(UpdateSwapAvailabilityLater(player));
			}
			foreach (PickupPickerController key in essences.Keys)
			{
				if (Object.op_Implicit((Object)(object)key))
				{
					NetworkServer.Destroy(((Component)key).gameObject);
				}
			}
			essences.Clear();
		}

		private void PlayBuyEffect(PowerOrbPedestalManager vault)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Object.op_Implicit((Object)(object)vault.activationEffectAttach) ? vault.activationEffectAttach.position : ((Component)vault).transform.position);
			if (Object.op_Implicit((Object)(object)vault.activationEffectPrefab))
			{
				EffectManager.SpawnEffect(vault.activationEffectPrefab, new EffectData
				{
					origin = val
				}, true);
			}
			PickupDef pickupDef = PickupCatalog.GetPickupDef(offer.pickupIndex);
			BazaarBase.SpawnEffect(shrineUseEffect, val, Color32.op_Implicit(pickupDef?.baseColor ?? Color.white));
		}

		private bool TryGetWaitingEssence(CharacterMaster master, out PickupPickerController picker)
		{
			foreach (KeyValuePair<PickupPickerController, Essence> essence in essences)
			{
				if (Object.op_Implicit((Object)(object)essence.Key) && (Object)(object)essence.Value.owner == (Object)(object)master)
				{
					picker = essence.Key;
					return true;
				}
			}
			picker = null;
			return false;
		}

		private Interactability GenericInteraction_GetInteractability(orig_RoR2_IInteractable_GetInteractability orig, GenericInteraction self, Interactor activator)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (IsBazaarChest((Component)(object)self) && Object.op_Implicit((Object)(object)activator))
			{
				CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.master) && TryGetWaitingEssence(component.master, out var _))
				{
					return (Interactability)2;
				}
				PlayerCharacterMasterController player = GetPlayer(((Component)activator).gameObject);
				if (Object.op_Implicit((Object)(object)player) && storedEquipment.ContainsKey(player))
				{
					return (Interactability)2;
				}
				if (buyers.Contains(player))
				{
					return (Interactability)0;
				}
			}
			return orig.Invoke(self, activator);
		}

		private void SetInteractabilityForClient(PlayerCharacterMasterController player, Interactability interactability)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			NetworkConnection val = (Object.op_Implicit((Object)(object)player.networkUser) ? ((NetworkBehaviour)player.networkUser).connectionToClient : null);
			NetworkIdentity component = pedestal.GetComponent<NetworkIdentity>();
			GenericInteraction component2 = pedestal.GetComponent<GenericInteraction>();
			if (val == null || !val.isReady || Util.ConnectionIsLocal(val) || !Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2))
			{
				return;
			}
			int networkChannel = ((NetworkBehaviour)component2).GetNetworkChannel();
			NetworkWriter val2 = new NetworkWriter();
			val2.StartMessage((short)8);
			val2.Write(component.netId);
			Interactability interactability2 = component2.interactability;
			try
			{
				component2.interactability = interactability;
				NetworkBehaviour[] behavioursOfSameChannel = component.GetBehavioursOfSameChannel(networkChannel, false);
				foreach (NetworkBehaviour val3 in behavioursOfSameChannel)
				{
					uint syncVarDirtyBits = val3.m_SyncVarDirtyBits;
					try
					{
						val3.m_SyncVarDirtyBits = (((Object)(object)val3 == (Object)(object)component2) ? 1u : 0u);
						val3.OnSerialize(val2, false);
					}
					finally
					{
						val3.m_SyncVarDirtyBits = syncVarDirtyBits;
					}
				}
			}
			finally
			{
				component2.interactability = interactability2;
			}
			val2.FinishMessage();
			if (!val.SendWriter(val2, networkChannel))
			{
				Log.LogWarning("Could not update the Command Pedestal for a client.");
			}
		}

		private int GetPrice()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (card == null || card.tier == null)
			{
				return 0;
			}
			return Helper.GetCost(card.tier.cost.Value, ModConfig.CommandPedestalCostType.Value);
		}

		private bool TryRollPickup(out UniquePickup pickup)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			List<PickupIndex> list = ((card != null && card.tier != null) ? card.tier.dropList(Run.instance) : null);
			if (list == null || list.Count == 0)
			{
				pickup = UniquePickup.none;
				return false;
			}
			pickup = new UniquePickup(rng.NextElementUniform<PickupIndex>(list));
			return true;
		}

		private static Vector3 GetEssencePosition(PowerOrbPedestalManager vault)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			return (Object.op_Implicit((Object)(object)vault.activationEffectAttach) ? vault.activationEffectAttach : ((Component)vault).transform).position + Vector3.up;
		}

		private static void DropEssence(PowerOrbPedestalManager vault, UniquePickup pickup)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 essencePosition = GetEssencePosition(vault);
			CreatePickupInfo val = default(CreatePickupInfo);
			((CreatePickupInfo)(ref val)).pickup = pickup;
			val.position = essencePosition;
			val.artifactFlag = (PickupArtifactFlag)1;
			PickupDropletController.CreatePickupDroplet(val, essencePosition, Vector3.up * 20f + ((Component)vault).transform.forward * 2f);
		}

		private void SpawnHiddenEssence(PowerOrbPedestalManager vault, UniquePickup pickup, Interactor activator)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(CommandArtifactManager.commandCubePrefab, ((Component)vault).transform.position + Vector3.down * 5f, Quaternion.identity);
			obj.GetComponent<PickupIndexNetworker>().NetworkpickupState = pickup;
			PickupPickerController component = obj.GetComponent<PickupPickerController>();
			component.SetOptionsFromPickupForCommandArtifact(pickup);
			component.pickupThatGeneratedOptions = pickup;
			Rigidbody val = default(Rigidbody);
			if (obj.TryGetComponent<Rigidbody>(ref val))
			{
				val.isKinematic = true;
			}
			NetworkServer.Spawn(obj);
			CharacterBody component2 = ((Component)activator).GetComponent<CharacterBody>();
			essences[component] = new Essence
			{
				owner = (Object.op_Implicit((Object)(object)component2) ? component2.master : null),
				vaultPosition = GetEssencePosition(vault)
			};
			component.OnInteractionBegin(activator);
		}

		private Interactability PickupPickerController_GetInteractability(orig_GetInteractability orig, PickupPickerController self, Interactor activator)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active && essences.TryGetValue(self, out var value) && Object.op_Implicit((Object)(object)value.owner))
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
				if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val.master != (Object)(object)value.owner)
				{
					return (Interactability)0;
				}
			}
			return orig.Invoke(self, activator);
		}

		private void PickupPickerController_CreatePickup(orig_CreatePickup_UniquePickup orig, PickupPickerController self, UniquePickup pickupState)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || !essences.TryGetValue(self, out var value))
			{
				orig.Invoke(self, pickupState);
				return;
			}
			essences.Remove(self);
			CharacterMaster val = (Object.op_Implicit((Object)(object)self.networkUIPromptController) ? self.networkUIPromptController.currentParticipantMaster : null);
			CharacterBody val2 = (Object.op_Implicit((Object)(object)val) ? val.GetBody() : null);
			Interactor val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<Interactor>() : null);
			PlayerCharacterMasterController val4 = (Object.op_Implicit((Object)(object)val) ? val.playerCharacterMasterController : null);
			PowerOrbPedestalManager val5 = (Object.op_Implicit((Object)(object)pedestal) ? pedestal.GetComponent<PowerOrbPedestalManager>() : null);
			CostTypeIndex value2 = ModConfig.CommandPedestalCostType.Value;
			int price = GetPrice();
			if (!Object.op_Implicit((Object)(object)val5) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.inventory) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4) || sold || (ModConfig.CommandPedestalInstancedPurchases.Value && buyers.Contains(val4)) || !Helper.CanAfford(value2, price, val3, val2))
			{
				if (Object.op_Implicit((Object)(object)val5))
				{
					Refuse(val5);
				}
			}
			else
			{
				Helper.PayCost(value2, price, val3, val2, pedestal, rng);
				GiveAndStore(val2, val4, pickupState.pickupIndex, value.vaultPosition);
				CompletePurchase(val5, val4);
			}
		}

		private void GiveAndStore(CharacterBody body, PlayerCharacterMasterController player, PickupIndex pickupIndex, Vector3 vaultPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			EquipmentIndex val = Helper.GivePickup(body, pickupIndex, vaultPosition, dropReplacedEquipmentAsPickupDroplet: false);
			if ((int)val == -1)
			{
				storedEquipment.Remove(player);
				return;
			}
			storedEquipment[player] = val;
			Helper.CreateItemTakenOrb(body.corePosition, pedestal, PickupCatalog.FindPickupIndex(val));
		}

		private void SwapStoredEquipment(PowerOrbPedestalManager vault, PlayerCharacterMasterController player, CharacterBody body)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			EquipmentIndex val = storedEquipment[player];
			storedEquipment.Remove(player);
			GiveAndStore(body, player, PickupCatalog.FindPickupIndex(val), GetEssencePosition(vault));
			UpdateSwapAvailability(player);
		}

		private void UpdateSwapAvailability(PlayerCharacterMasterController player)
		{
			SetInteractabilityForClient(player, (Interactability)(storedEquipment.ContainsKey(player) ? 2 : 0));
		}

		private IEnumerator UpdateSwapAvailabilityLater(PlayerCharacterMasterController player)
		{
			yield return (object)new WaitForSecondsRealtime(0.5f);
			if (Object.op_Implicit((Object)(object)pedestal) && Object.op_Implicit((Object)(object)player))
			{
				UpdateSwapAvailability(player);
			}
		}

		private void HideDisplayFor(PlayerCharacterMasterController player)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			NetworkIdentity val = (Object.op_Implicit((Object)(object)displayEssence) ? displayEssence.GetComponent<NetworkIdentity>() : null);
			NetworkConnection val2 = (Object.op_Implicit((Object)(object)player.networkUser) ? ((NetworkBehaviour)player.networkUser).connectionToClient : null);
			if (!Object.op_Implicit((Object)(object)val) || val2 == null)
			{
				return;
			}
			if (Util.ConnectionIsLocal(val2))
			{
				Transform val3 = displayEssence.transform.Find("PickupDisplay");
				if (Object.op_Implicit((Object)(object)val3))
				{
					((Component)val3).gameObject.SetActive(false);
				}
				return;
			}
			NetworkWriter val4 = new NetworkWriter();
			val4.StartMessage((short)1);
			val4.Write(val.netId);
			val4.FinishMessage();
			if (!val2.SendWriter(val4, QosChannelIndex.defaultReliable.intVal))
			{
				Log.LogWarning("Could not hide the Command Pedestal's essence for a client.");
			}
		}

		private void SpawnDisplayEssence()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab;
			SphereCollider val = (Object.op_Implicit((Object)(object)commandCubePrefab) ? commandCubePrefab.GetComponent<SphereCollider>() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < 32; i++)
			{
				if (!Physics.GetIgnoreLayerCollision(commandCubePrefab.layer, i))
				{
					num |= 1 << i;
				}
			}
			Vector3 val2 = pedestal.transform.position + Vector3.up * 5f;
			RaycastHit val3 = default(RaycastHit);
			if (!Physics.SphereCast(val2, val.radius, Vector3.down, ref val3, 10f, num, (QueryTriggerInteraction)1))
			{
				Log.LogWarning("Found nothing for the Command Pedestal's essence to rest on.");
				return;
			}
			displayEssence = Object.Instantiate<GameObject>(commandCubePrefab, val2 + Vector3.down * ((RaycastHit)(ref val3)).distance, Quaternion.identity);
			displayEssence.GetComponent<PickupIndexNetworker>().NetworkpickupState = offer;
			displayEssence.GetComponent<PickupPickerController>().SetAvailable(false);
			Rigidbody val4 = default(Rigidbody);
			if (displayEssence.TryGetComponent<Rigidbody>(ref val4))
			{
				val4.isKinematic = true;
			}
			NetworkServer.Spawn(displayEssence);
			Log.LogDebug($"The Command Pedestal's essence rests on {((Object)((RaycastHit)(ref val3)).collider).name}, {displayEssence.transform.position.y - pedestal.transform.position.y:0.00} m above the pedestal.");
		}

		private void SpawnCommandPedestal()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			rng = new Xoroshiro128Plus(Run.instance.treasureRng.nextUlong);
			pedestal = Object.Instantiate<GameObject>(vaultPrefab.WaitForCompletion(), new Vector3(-63.9613f, -26.3518f, -73.8056f), Quaternion.Euler(0f, 300f, 0f));
			NetworkServer.Spawn(pedestal);
			hasOffer = TryRollPickup(out offer);
			if (hasOffer)
			{
				SpawnDisplayEssence();
			}
			Log.LogDebug("The Command Pedestal offers " + card.tier.name + ".");
			PriceSigns.Apply(new List<GameObject> { pedestal }, GetPrice(), ModConfig.CommandPedestalCostType.Value, 4.5f);
		}
	}
	public class BazaarDecorate : BazaarBase
	{
		private AsyncOperationHandle<GameObject> TeleporterBeaconEffect;

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			TeleporterBeaconEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Junk/Teleporter/TeleporterBeaconEffect.prefab");
		}

		public override void Hook()
		{
		}

		public override void RunStart()
		{
		}

		public override void SetupBazaar()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			BazaarBase.SpawnEffect(TeleporterBeaconEffect, new Vector3(-73.5143f, -22.2897f, 9.1621f), Color32.op_Implicit(Color.blue));
			BazaarBase.SpawnEffect(TeleporterBeaconEffect, new Vector3(-57.0645f, -22.2698f, -0.5218f), Color32.op_Implicit(Color.blue));
			BazaarBase.SpawnEffect(TeleporterBeaconEffect, new Vector3(15.7063f, -2.1074f, 2.5406f), Color32.op_Implicit(Color.blue));
			BazaarBase.SpawnEffect(TeleporterBeaconEffect, new Vector3(2.5543f, -2.7093f, -8.7185f), Color32.op_Implicit(Color.blue));
		}
	}
	public class DirectorCard
	{
		public readonly string name;

		public readonly bool allowLatePicks;

		private readonly ConfigEntry<int> cost;

		private readonly ConfigEntry<float> weight;

		private readonly Func<int> maxCount;

		private readonly Func<bool> isAvailable;

		public int Count { get; private set; }

		public int Spent { get; private set; }

		public virtual float Weight => Mathf.Max(0f, weight.Value);

		public DirectorCard(string name, ConfigEntry<int> cost, ConfigEntry<float> weight, Func<int> maxCount, Func<bool> isAvailable = null, bool allowLatePicks = true)
		{
			this.name = name;
			this.cost = cost;
			this.weight = weight;
			this.maxCount = maxCount;
			this.isAvailable = isAvailable;
			this.allowLatePicks = allowLatePicks;
		}

		public bool CanPick(int credits)
		{
			if (Weight > 0f && Count < maxCount() && (isAvailable == null || isAvailable()))
			{
				return CheapestCost() <= credits;
			}
			return false;
		}

		public int Pick(int credits)
		{
			int num = PickCost(credits);
			Count++;
			Spent += num;
			return num;
		}

		protected virtual int CheapestCost()
		{
			return Math.Max(0, cost.Value);
		}

		protected virtual int PickCost(int credits)
		{
			return CheapestCost();
		}
	}
	public class BazaarDirector : MonoBehaviour
	{
		private static readonly Random random = new Random();

		private List<BazaarBase> sections;

		private List<DirectorCard> cards;

		private int credits;

		public static int Credits
		{
			get
			{
				int num = ModConfig.DirectorExtraCredits.Value + ModConfig.DirectorCreditsPerStage.Value * Run.instance.stageClearCount;
				if (ModConfig.DirectorCreditsCap.Value < 0)
				{
					return num;
				}
				return Math.Min(num, ModConfig.DirectorCreditsCap.Value);
			}
		}

		public static int Spend(int credits, IEnumerable<DirectorCard> cards, string round)
		{
			List<DirectorCard> source = cards.ToList();
			Dictionary<DirectorCard, int> dictionary = new Dictionary<DirectorCard, int>();
			int num = credits;
			while (true)
			{
				List<DirectorCard> list = source.Where((DirectorCard card) => card.CanPick(credits)).ToList();
				if (list.Count == 0)
				{
					break;
				}
				double num2 = random.NextDouble() * (double)list.Sum((DirectorCard card) => card.Weight);
				DirectorCard directorCard = list[list.Count - 1];
				foreach (DirectorCard item in list)
				{
					if (num2 < (double)item.Weight)
					{
						directorCard = item;
						break;
					}
					num2 -= (double)item.Weight;
				}
				credits -= directorCard.Pick(credits);
				dictionary[directorCard] = dictionary.GetValueOrDefault(directorCard) + 1;
			}
			string text = ((dictionary.Count == 0) ? "nothing" : string.Join(", ", dictionary.Select((KeyValuePair<DirectorCard, int> pick) => $"{pick.Value}x {pick.Key.name}")));
			Log.LogInfo($"Director ({round}): {num} credits bought {text}; {credits} left.");
			return credits;
		}

		public static void Create(List<BazaarBase> sections, List<DirectorCard> cards, int credits)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			BazaarDirector bazaarDirector = new GameObject("BazaarDirector").AddComponent<BazaarDirector>();
			bazaarDirector.sections = sections;
			bazaarDirector.cards = cards;
			bazaarDirector.credits = credits;
		}

		private IEnumerator Start()
		{
			yield return null;
			if (!NetworkServer.active)
			{
				yield break;
			}
			int num = 0;
			foreach (BazaarBase section in sections)
			{
				try
				{
					num += section.CheckAfterSetup();
				}
				catch (Exception arg)
				{
					Log.LogError($"Could not check {section.GetType().Name} after setup: {arg}");
				}
			}
			if (num > 0)
			{
				Spend(credits + num, cards.Where((DirectorCard card) => card.allowLatePicks), "late");
				foreach (BazaarBase section2 in sections)
				{
					try
					{
						section2.SpawnLatePicks();
					}
					catch (Exception arg2)
					{
						Log.LogError($"Could not spawn the late picks of {section2.GetType().Name}: {arg2}");
					}
				}
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	public class BazaarDonate : BazaarBase
	{
		private AsyncOperationHandle<GameObject> altarPrefab;

		private AsyncOperationHandle<GameObject> LevelUpEffect;

		private AsyncOperationHandle<GameObject> MoneyPackPickupEffect;

		private AsyncOperationHandle<GameObject> TeamWarCryActivation;

		private AsyncOperationHandle<GameObject> ShrineUseEffect;

		private readonly Dictionary<PlayerCharacterMasterController, int> donationsDuringRun = new Dictionary<PlayerCharacterMasterController, int>();

		private DirectorCard card;

		private bool spawned;

		private GameObject altar;

		private static readonly Vector3 AltarSignOffset = new Vector3(1.5534f, 1.1769f, -0.1835f);

		private static readonly Quaternion AltarSignRotation = Quaternion.Euler(0f, 270f, 0f);

		private readonly ManualLogSource rewardLog = new ManualLogSource("BazaarIsMyHaven");

		private readonly HashSet<string> loggedRewardWarnings = new HashSet<string>();

		public BazaarDonate()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			rewardLog.LogEvent += delegate(object sender, LogEventArgs args)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				string text = args.Data?.ToString();
				if (text != null && loggedRewardWarnings.Add(text))
				{
					Log.GetSource().Log(args.Level, (object)text);
				}
			};
		}

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			altarPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/DeepVoidPortalBattery/DeepVoidPortalBattery.prefab");
			LevelUpEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/LevelUpEffect.prefab");
			MoneyPackPickupEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/BonusGoldPackOnKill/MoneyPackPickupEffect.prefab");
			TeamWarCryActivation = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/TeamWarCry/TeamWarCryActivation.prefab");
			ShrineUseEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/ShrineUseEffect.prefab");
			DonationRewardDisplay.Preload();
			PriceSigns.Preload();
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(PurchaseInteraction_OnInteractionBegin);
		}

		public override void RunStart()
		{
			donationsDuringRun.Clear();
			loggedRewardWarnings.Clear();
		}

		public override void RunEnd()
		{
			donationsDuringRun.Clear();
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			card = null;
			if (ModConfig.DonateSectionEnabled.Value)
			{
				card = new DirectorCard("Donation Altar", ModConfig.DonateDirectorCost, ModConfig.DonateDirectorWeight, () => 1);
				cards.Add(card);
			}
		}

		public override void SetupBazaar()
		{
			spawned = false;
			altar = null;
			SpawnLatePicks();
		}

		public override void SpawnLatePicks()
		{
			if (card != null && card.Count != 0 && !spawned)
			{
				SpawnDonateAltar();
				spawned = true;
			}
		}

		private void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.EnableMod.Value && ModConfig.DonateSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active && Object.op_Implicit((Object)(object)altar) && (Object)(object)((Component)self).gameObject == (Object)(object)altar)
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.master) || !Object.op_Implicit((Object)(object)val.inventory))
				{
					return;
				}
				PlayerCharacterMasterController playerCharacterMasterController = val.master.playerCharacterMasterController;
				if (!Object.op_Implicit((Object)(object)playerCharacterMasterController) || !self.available || self.cost < 0 || !self.CanBeAffordedByInteractor(activator))
				{
					return;
				}
				PlayerStruct playerStruct = Main.instance.GetPlayerStruct(playerCharacterMasterController);
				if (CanGetReward(playerCharacterMasterController) && TryGetReward(val.bodyIndex, donationsDuringRun.GetValueOrDefault(playerCharacterMasterController), out var resolvedItems, out var tier))
				{
					Helper.PayCost(self.costType, self.cost, activator, val, ((Component)self).gameObject, self.rng);
					Helper.GivePickups(val, resolvedItems, ((Component)self).transform.position + Vector3.up * 6f, dropReplacedEquipmentsAsPickupDroplets: false);
					playerStruct.RewardCount++;
					donationsDuringRun[playerCharacterMasterController] = donationsDuringRun.GetValueOrDefault(playerCharacterMasterController) + 1;
					ShowRewardEffects(self, val, resolvedItems, tier);
					BazaarBase.SpawnEffect(ShrineUseEffect, ((Component)self).transform.position, new Color32((byte)64, (byte)127, byte.MaxValue, byte.MaxValue), 5f);
					DonationRewardDisplay component = ((Component)self).GetComponent<DonationRewardDisplay>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.ShowNextReward(playerCharacterMasterController);
					}
					if (!CanGetReward(playerCharacterMasterController))
					{
						DisableFor(playerCharacterMasterController);
					}
				}
			}
			else
			{
				orig.Invoke(self, activator);
			}
		}

		private void DisableFor(PlayerCharacterMasterController pc)
		{
			InstancedPurchase instancedPurchase = default(InstancedPurchase);
			if (Object.op_Implicit((Object)(object)altar) && altar.TryGetComponent<InstancedPurchase>(ref instancedPurchase))
			{
				InstancedPurchaseStruct orCreate = instancedPurchase.GetOrCreate(pc);
				if (orCreate.available)
				{
					orCreate.available = false;
					InstancedPurchases.UpdatePlayer(altar, pc);
					PriceSigns.HideFor(altar, pc);
				}
			}
		}

		private bool CanGetReward(PlayerCharacterMasterController pc)
		{
			if (Main.instance.GetPlayerStruct(pc).RewardCount < ModConfig.DonateRewardLimitPerVisit.Value)
			{
				return donationsDuringRun.GetValueOrDefault(pc) < ModConfig.DonateRewardLimitPerRun.Value;
			}
			return false;
		}

		private Dictionary<PickupIndex, int> RollReward(PlayerCharacterMasterController pc)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster master = pc.master;
			if (!Object.op_Implicit((Object)(object)master) || !CanGetReward(pc))
			{
				return null;
			}
			CharacterBody body = master.GetBody();
			BodyIndex bodyIndex = (BodyIndex)((!Object.op_Implicit((Object)(object)body)) ? ((!Object.op_Implicit((Object)(object)master.bodyPrefab)) ? (-1) : ((int)BodyCatalog.FindBodyIndex(master.bodyPrefab))) : ((int)body.bodyIndex));
			if (!TryGetReward(bodyIndex, donationsDuringRun.GetValueOrDefault(pc), out var resolvedItems, out var _))
			{
				return null;
			}
			return resolvedItems;
		}

		private bool TryGetReward(BodyIndex bodyIndex, int donations, out Dictionary<PickupIndex, int> resolvedItems, out int tier)
		{
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			tier = 0;
			resolvedItems = new Dictionary<PickupIndex, int>();
			List<(float, int)> list = new List<(float, int)>
			{
				(ModConfig.DonateRewardList1Weight.Value, 1),
				(ModConfig.DonateRewardList2Weight.Value, 2),
				(ModConfig.DonateRewardList3Weight.Value, 3),
				(ModConfig.DonateRewardListCharacterWeight.Value, 4)
			};
			list.RemoveAll(((float weight, int tier) item) => item.weight <= 0f);
			if (list.Count == 0)
			{
				rewardLog.LogWarning((object)"No donation lists with a valid weight; the Donation Altar gives no rewards.");
				return false;
			}
			if (ModConfig.DonateSequentialRewardLists.Value)
			{
				list.Sort(((float weight, int tier) a, (float weight, int tier) b) => b.weight.CompareTo(a.weight));
				tier = list[donations % list.Count].Item2;
			}
			else
			{
				double num = RNG.NextDouble() * (double)list.Sum<(float, int)>(((float weight, int tier) item) => item.weight);
				tier = list[list.Count - 1].Item2;
				foreach (var item in list)
				{
					if (num < (double)item.Item1)
					{
						tier = item.Item2;
						break;
					}
					num -= (double)item.Item1;
				}
			}
			switch (tier)
			{
			case 1:
				ParseRewards(ModConfig.DonateRewardList1.Value, resolvedItems);
				break;
			case 2:
				ParseRewards(ModConfig.DonateRewardList2.Value, resolvedItems);
				break;
			case 3:
				ParseRewards(ModConfig.DonateRewardList3.Value, resolvedItems);
				break;
			case 4:
			{
				if (!ModConfig.DonateRewardListCharacters.TryGetValue(bodyIndex, out var value) || !ParseRewards(value.Value, resolvedItems))
				{
					ParseRewards(ModConfig.DonateRewardListCharacterDefault.Value, resolvedItems);
				}
				break;
			}
			}
			if (resolvedItems.Count == 0)
			{
				rewardLog.LogWarning((object)"A donation list has no valid rewards; donations that choose it charge no coins.");
				return false;
			}
			return true;
		}

		private bool ParseRewards(string rewardList, Dictionary<PickupIndex, int> resolvedItems)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			resolvedItems.Clear();
			ItemStringParser.ParseItemString(rewardList, resolvedItems, rewardLog, false, -1);
			KeyValuePair<PickupIndex, int>[] array = resolvedItems.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<PickupIndex, int> keyValuePair = array[i];
				PickupDef pickupDef = PickupCatalog.GetPickupDef(keyValuePair.Key);
				if (keyValuePair.Value <= 0 || pickupDef == null || ((int)pickupDef.itemIndex == -1 && (int)pickupDef.equipmentIndex == -1))
				{
					resolvedItems.Remove(keyValuePair.Key);
				}
			}
			return resolvedItems.Count > 0;
		}

		private void ShowRewardEffects(PurchaseInteraction self, CharacterBody characterBody, Dictionary<PickupIndex, int> resolvedItems, int tier)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			ChatHelper.DonationThanks(characterBody, resolvedItems, tier);
			BazaarBase.SpawnEffect(LevelUpEffect, ((Component)self).transform.position, new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), 3f);
			BazaarBase.SpawnEffect(MoneyPackPickupEffect, ((Component)self).transform.position, new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), 3f);
			BazaarBase.SpawnEffect(TeamWarCryActivation, ((Component)self).transform.position, new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), 3f);
		}

		private void SpawnDonateAltar()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			altar = Object.Instantiate<GameObject>(altarPrefab.WaitForCompletion(), new Vector3(-114.4226f, -22.6017f, -49.9827f), Quaternion.Euler(0f, 300f, 0f));
			PurchaseInteraction component = altar.GetComponent<PurchaseInteraction>();
			int cost = (component.Networkcost = (component.cost = Helper.GetCost(ModConfig.DonateCost.Value, ModConfig.DonateCostType.Value)));
			component.NetworkcostType = ModConfig.DonateCostType.Value;
			component.NetworkdisplayNameToken = "NEWT_STATUE_NAME";
			component.NetworkcontextToken = "NEWT_STATUE_CONTEXT";
			DonationRewardDisplay.Apply(altar, RollReward);
			altar.AddComponent<InstancedPurchase>().original.available = true;
			NetworkServer.Spawn(altar);
			VoidSignalBeam.Remove(altar);
			PriceSigns.Apply(altar, altar.transform.TransformPoint(AltarSignOffset), altar.transform.rotation * AltarSignRotation, cost, ModConfig.DonateCostType.Value);
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance) && !CanGetReward(instance))
				{
					DisableFor(instance);
				}
			}
		}
	}
	public class BazaarDrones : BazaarBase
	{
		private class Station
		{
			public DirectorCard card;

			public AsyncOperationHandle<GameObject> prefab;

			public SpawnCardStruct slot;

			public bool spawned;

			public GameObject instance;
		}

		private AsyncOperationHandle<GameObject> DroneCombinerStation;

		private AsyncOperationHandle<GameObject> DroneUpgradeStation;

		private AsyncOperationHandle<GameObject> DroneScrapper;

		private AsyncOperationHandle<GameObject> TripleDroneShop;

		private readonly List<Station> stations = new List<Station>();

		private Station upgradeStation;

		private Station tripleDroneShop;

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			DroneCombinerStation = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/DroneCombinerStation/DroneCombinerStation.prefab");
			DroneUpgradeStation = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/DroneAssemblyStation/DroneAssemblyStation.prefab");
			DroneScrapper = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/DroneScrapper/DroneScrapper.prefab");
			TripleDroneShop = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/TripleDroneShop/TripleDroneShop.prefab");
			PriceSigns.Preload();
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			Stage.RespawnAllNPCs += new hook_RespawnAllNPCs(Stage_RespawnAllNPCs);
			PickupPickerController.GetInteractability += new hook_GetInteractability(PickupPickerController_GetInteractability);
			PurchaseInteraction.GetInteractability += new hook_GetInteractability(PurchaseInteraction_GetInteractability);
			DroneVendorMultiShopController.Start += new hook_Start(DroneVendorMultiShopController_Start);
			DroneVendorMultiShopController.ResetDroneVendor += new hook_ResetDroneVendor(DroneVendorMultiShopController_ResetDroneVendor);
		}

		private static bool IsSectionActive()
		{
			if (ModConfig.DronesSectionEnabled.Value && Object.op_Implicit((Object)(object)DLC3Content.DLC3) && Object.op_Implicit((Object)(object)Run.instance))
			{
				return Run.instance.IsExpansionEnabled(DLC3Content.DLC3);
			}
			return false;
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			//IL_0033: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			stations.Clear();
			upgradeStation = null;
			tripleDroneShop = null;
			if (IsSectionActive())
			{
				AddStation(cards, "Drone Combiner Station", ModConfig.DronesDroneCombinerStationDirectorCost, ModConfig.DronesDroneCombinerStationDirectorWeight, DroneCombinerStation, new SpawnCardStruct(new Vector3(-81.4188f, -23.0829f, -3.7793f), new Vector3(0f, 165f, 350f)));
				upgradeStation = AddStation(cards, "Drone Upgrade Station", ModConfig.DronesDroneUpgradeStationDirectorCost, ModConfig.DronesDroneUpgradeStationDirectorWeight, DroneUpgradeStation, new SpawnCardStruct(new Vector3(-85.1751f, -22.264f, -3.539f), new Vector3(0f, 150f, 270f)));
				AddStation(cards, "Drone Scrapper", ModConfig.DronesDroneScrapperDirectorCost, ModConfig.DronesDroneScrapperDirectorWeight, DroneScrapper, new SpawnCardStruct(new Vector3(-92.3398f, -26.1678f, -51.8777f), new Vector3(0f, 315f, 0f)));
				tripleDroneShop = AddStation(cards, "Triple Drone Shop", ModConfig.DronesTripleDroneShopDirectorCost, ModConfig.DronesTripleDroneShopDirectorWeight, TripleDroneShop, new SpawnCardStruct(new Vector3(-64.3101f, -23.0074f, -19.7406f), new Vector3(0f, 300f, 6f)));
			}
		}

		private Station AddStation(List<DirectorCard> cards, string name, ConfigEntry<int> cost, ConfigEntry<float> weight, AsyncOperationHandle<GameObject> prefab, SpawnCardStruct slot)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			Station station = new Station
			{
				card = new DirectorCard(name, cost, weight, () => 1),
				prefab = prefab,
				slot = slot
			};
			stations.Add(station);
			cards.Add(station.card);
			return station;
		}

		public override void SetupBazaar()
		{
			SpawnLatePicks();
		}

		public override void SpawnLatePicks()
		{
			foreach (Station station in stations)
			{
				if (station.card.Count != 0 && !station.spawned)
				{
					station.instance = BazaarBase.SpawnAt(station.prefab.WaitForCompletion(), station.slot);
					station.spawned = true;
				}
			}
		}

		private void Stage_RespawnAllNPCs(orig_RespawnAllNPCs orig, Stage self)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!ModConfig.EnableMod.Value || !IsCurrentMapInBazaar() || !IsSectionActive() || !Object.op_Implicit((Object)(object)self.sceneDef) || !self.sceneDef.suppressNpcEntry)
			{
				return;
			}
			Transform playerSpawnTransform = self.GetPlayerSpawnTransform();
			ReadOnlyCollection<CharacterMaster> readOnlyInstancesList = CharacterMaster.readOnlyInstancesList;
			for (int i = 0; i < readOnlyInstancesList.Count; i++)
			{
				CharacterMaster val = readOnlyInstancesList[i];
				if (!IsPlayerDrone(val) || Object.op_Implicit((Object)(object)val.GetBodyObject()) || !Util.IsDontDestroyOnLoad(((Component)val).gameObject))
				{
					continue;
				}
				Vector3 val2 = Vector3.zero;
				Quaternion val3 = Quaternion.identity;
				if (Object.op_Implicit((Object)(object)playerSpawnTransform))
				{
					val2 = playerSpawnTransform.position;
					val3 = playerSpawnTransform.rotation;
					BaseAI component = ((Component)val).GetComponent<BaseAI>();
					CharacterBody component2 = val.bodyPrefab.GetComponent<CharacterBody>();
					NodeGraph val4 = ((Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2)) ? component.GetDesiredSpawnNodeGraph() : null);
					if (Object.op_Implicit((Object)(object)val4))
					{
						List<NodeIndex> list = new List<NodeIndex>();
						val4.FindNodesInRange(val2, 10f, 100f, (HullMask)(1 << (int)component2.hullClassification), list);
						if (list.Count > 0)
						{
							val4.GetNodePosition(list[Random.Range(0, list.Count)], ref val2);
						}
					}
				}
				val.Respawn(val2, val3, true);
			}
		}

		private void DroneVendorMultiShopController_Start(orig_Start orig, DroneVendorMultiShopController self)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Invalid comparison between Unknown and I4
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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)
			if (!NetworkServer.active || tripleDroneShop == null || !Object.op_Implicit((Object)(object)tripleDroneShop.instance) || (Object)(object)((Component)self).gameObject != (Object)(object)tripleDroneShop.instance || !Object.op_Implicit((Object)(object)Run.instance))
			{
				orig.Invoke(self);
				return;
			}
			float num = Mathf.Max(0f, ModConfig.DronesTripleDroneShopCommonWeight.Value);
			float num2 = Mathf.Max(0f, ModConfig.DronesTripleDroneShopUncommonWeight.Value);
			if (num + num2 <= 0f)
			{
				num = 1f;
			}
			self.tier1Chance = new RangeFloat
			{
				min = num,
				max = num
			};
			self.tier2Chance = new RangeFloat
			{
				min = num2,
				max = num2
			};
			self.tier3Chance = new RangeFloat
			{
				min = 0f,
				max = 0f
			};
			self.baseCostTier1 = ModConfig.DronesTripleDroneShopCommonCost.Value;
			self.baseCostTier2 = ModConfig.DronesTripleDroneShopUncommonCost.Value;
			CostTypeIndex val = (self.costType = ModConfig.DronesTripleDroneShopCostType.Value);
			Run instance = Run.instance;
			int stageClearCount = instance.stageClearCount;
			instance.stageClearCount = Mathf.Max(stageClearCount, 3);
			try
			{
				orig.Invoke(self);
			}
			finally
			{
				instance.stageClearCount = stageClearCount;
			}
			int num3 = (self.Networkcost = Helper.GetCost(self.baseCost, val));
			DroneVendorTerminalBehavior[] array = (DroneVendorTerminalBehavior[])(((object)self._terminals) ?? ((object)new DroneVendorTerminalBehavior[0]));
			foreach (DroneVendorTerminalBehavior val2 in array)
			{
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.purchaseInteraction))
				{
					val2.purchaseInteraction.Networkcost = num3;
				}
			}
			if ((int)val != 1)
			{
				HologramProjector component = ((Component)self).GetComponent<HologramProjector>();
				Transform val3 = ((Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.hologramPivot)) ? component.hologramPivot : ((Component)self).transform);
				self.Networkavailable = false;
				PriceSigns.Apply(((Component)self).gameObject, val3.position, ((Component)self).transform.rotation * Quaternion.Euler(0f, 180f, 0f), num3, val);
			}
		}

		private void DroneVendorMultiShopController_ResetDroneVendor(orig_ResetDroneVendor orig, DroneVendorMultiShopController self)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			orig.Invoke(self);
			if (NetworkServer.active && tripleDroneShop != null && Object.op_Implicit((Object)(object)tripleDroneShop.instance) && (Object)(object)((Component)self).gameObject == (Object)(object)tripleDroneShop.instance && (int)self.costType != 1)
			{
				self.Networkavailable = false;
			}
		}

		private Interactability PickupPickerController_GetInteractability(orig_GetInteractability orig, PickupPickerController self, Interactor activator)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!RefusesUpgrade(((Component)self).gameObject, activator))
			{
				return orig.Invoke(self, activator);
			}
			return (Interactability)1;
		}

		private Interactability PurchaseInteraction_GetInteractability(orig_GetInteractability orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!RefusesUpgrade(((Component)self).gameObject, activator))
			{
				return orig.Invoke(self, activator);
			}
			return (Interactability)1;
		}

		private bool RefusesUpgrade(GameObject interactable, Interactor activator)
		{
			if (upgradeStation == null || !Object.op_Implicit((Object)(object)upgradeStation.instance) || (Object)(object)interactable != (Object)(object)upgradeStation.instance || !Object.op_Implicit((Object)(object)activator))
			{
				return false;
			}
			CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.master))
			{
				return !HasDrones(component.master);
			}
			return true;
		}

		private static bool HasDrones(CharacterMaster owner)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			MinionGroup val = MinionGroup.FindGroup(((NetworkBehaviour)owner).netId);
			if (val == null)
			{
				return false;
			}
			MinionOwnership[] members = val.members;
			foreach (MinionOwnership val2 in members)
			{
				CharacterMaster val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<CharacterMaster>() : null);
				CharacterBody val4 = (Object.op_Implicit((Object)(object)val3) ? val3.GetBody() : null);
				if (Object.op_Implicit((Object)(object)val4) && (val4.bodyFlags & 0x400000) != 0)
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsPlayerDrone(CharacterMaster master)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			if (!Object.op_Implicit((Object)(object)master) || !Object.op_Implicit((Object)(object)master.bodyPrefab) || !Object.op_Implicit((Object)(object)master.minionOwnership))
			{
				return false;
			}
			CharacterMaster ownerMaster = master.minionOwnership.ownerMaster;
			CharacterBody val = default(CharacterBody);
			if (Object.op_Implicit((Object)(object)ownerMaster) && Object.op_Implicit((Object)(object)ownerMaster.playerCharacterMasterController) && master.bodyPrefab.TryGetComponent<CharacterBody>(ref val))
			{
				return (val.bodyFlags & 0x400000) > 0;
			}
			return false;
		}
	}
	public class BazaarEquipment : BazaarBase
	{
		private AsyncOperationHandle<GameObject> multiShopEquipmentTerminal;

		private Dictionary<int, SpawnCardStruct> DicEquipments = new Dictionary<int, SpawnCardStruct>();

		private DirectorCard card;

		private int spawned;

		private PlayerCharacterMasterController currentActivator;

		public override void Preload()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			multiShopEquipmentTerminal = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/MultiShopEquipmentTerminal/MultiShopEquipmentTerminal.prefab");
			PriceSigns.Preload();
		}

		public override void Hook()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			PurchaseInteraction.Awake += new hook_Awake(PurchaseInteraction_Awake);
			PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(PurchaseInteraction_OnInteractionBegin);
			ShopTerminalBehavior.DropPickup += new hook_DropPickup(ShopTerminalBehavior_DropPickup);
			ShopTerminalBehavior.GenerateNewPickupServer_bool += new hook_GenerateNewPickupServer_bool(ShopTerminalBehavior_GenerateNewPickupServer_bool);
		}

		public override void RunStart()
		{
		}

		public override void AddDirectorCards(List<DirectorCard> cards)
		{
			card = null;
			if (ModConfig.EquipmentSectionEnabled.Value)
			{
				card = new DirectorCard("Equipment Terminal", ModConfig.EquipmentDirectorCost, ModConfig.EquipmentDirectorWeight, GetMaxTerminals);
				cards.Add(card);
			}
		}

		public override void SetupBazaar()
		{
			if (card != null)
			{
				DicEquipments.Clear();
				SetEquipment();
				spawned = 0;
				SpawnLatePicks();
			}
		}

		private static int GetMaxTerminals()
		{
			return Math.Min(ModConfig.EquipmentMaxAmount.Value, ModConfig.EquipmentReplaceLunarSeersWithEquipment.Value ? 5 : 3);
		}

		public void PurchaseInteraction_Awake(orig_Awake orig, PurchaseInteraction self)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (ModConfig.EnableMod.Value && ModConfig.EquipmentSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active && ModConfig.EquipmentMaxAmount.Value > 0 && ((Object)self).name.StartsWith("MultiShopEquipmentTerminal"))
			{
				self.Networkcost = (self.cost = Helper.GetCost(ModConfig.EquipmentCost.Value, ModConfig.EquipmentCostType.Value));
				self.NetworkcostType = ModConfig.EquipmentCostType.Value;
			}
		}

		private void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			if (ModConfig.EnableMod.Value && ModConfig.EquipmentSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active && ((Object)self).name.StartsWith("MultiShopEquipmentTerminal"))
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
				PlayerCharacterMasterController player = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.master)) ? val.master.playerCharacterMasterController : null);
				PlayerCharacterMasterController val2 = currentActivator;
				try
				{
					currentActivator = player;
					if (FreeSwaps.IsFreeFor((Component)(object)self, player))
					{
						FreeSwaps.RunFree(self, delegate
						{
							orig.Invoke(self, activator);
							return true;
						});
					}
					else
					{
						orig.Invoke(self, activator);
					}
					return;
				}
				finally
				{
					currentActivator = val2;
				}
			}
			orig.Invoke(self, activator);
		}

		private void ShopTerminalBehavior_DropPickup(orig_DropPickup orig, ShopTerminalBehavior self)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.EnableMod.Value && ModConfig.EquipmentSectionEnabled.Value && IsCurrentMapInBazaar() && NetworkServer.active && ((Object)self).name.StartsWith("MultiShopEquipmentTerminal"))
			{
				if (ModConfig.EquipmentBuyToInventory.Value)
				{
					CharacterBody val = ((Object.op_Implicit((Object)(object)currentActivator) && Object.op_Implicit((Object)(object)currentActivator.master)) ? currentActivator.master.GetBody() : null);
					if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.inventory))
					{
						orig.Invoke(self);
						return;
					}
					EquipmentIndex val2 = Helper.GivePickup(val, self.CurrentPickup().pickupIndex, ((Component)self).transform.position, dropReplacedEquipmentAsPickupDroplet: false);
					if ((int)val2 != -1)
					{
						Helper.CreateItemTakenOrb(val.corePosition, ((Component)self).gameObject, PickupCatalog.FindPickupIndex(val2));
						self.SetPickup(new UniquePickup(PickupCatalog.FindPickupIndex(val2)), false);
						((Component)self).GetComponent<PurchaseInteraction>().SetAvailable(true);
						bool num = !FreeSwaps.IsFreeFor((Component)(object)self, currentActivator);
						FreeSwaps.BuySlot(((Component)self).gameObject, currentActivator);
						PriceSigns.HideFor(((Component)self).gameObject, currentActivator);
						if (num)
						{
							InstancedPurchases.PlayBuySound(self, currentActivator);
						}
					}
					else
					{
						self.SetHasBeenPurchased(true);
						self.SetNoPickup();
					}
				}
				else
				{
					orig.Invoke(self);
					self.SetNoPickup();
				}
			}
			else
			{
				orig.Invoke(self);
			}
		}

		private void ShopTermi