Decompiled source of BazaarExpansion v1.0.0

BazaarExpansion-Release.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("BazaarExpansion-Release")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3b7603e16e8fe61559c0af926133d9160f7b75c7")]
[assembly: AssemblyProduct("BazaarExpansion-Release")]
[assembly: AssemblyTitle("BazaarExpansion-Release")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BazaarExpand
{
	[BepInPlugin("com.Susciety.BazaarExpand", "BazaarExpand", "1.0.0")]
	public class BazaarExpand : BaseUnityPlugin
	{
		internal class PrinterInfo
		{
			public Vector3 position;

			public Vector3 rotation;
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass15_0
		{
			public List<AsyncOperationHandle> handles;

			internal bool <PreloadAssetsParallel>b__0()
			{
				//IL_000c: 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)
				for (int i = 0; i < handles.Count; i++)
				{
					AsyncOperationHandle val = handles[i];
					if (!((AsyncOperationHandle)(ref val)).IsDone)
					{
						return false;
					}
				}
				return true;
			}
		}

		[CompilerGenerated]
		private sealed class <PreloadAssetsParallel>d__15 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public BazaarExpand <>4__this;

			private <>c__DisplayClass15_0 <>8__1;

			private AsyncOperationHandle<SpawnCard> <hGold>5__2;

			private AsyncOperationHandle<SpawnCard> <hCleanse>5__3;

			private AsyncOperationHandle<SpawnCard> <hScrapper>5__4;

			private AsyncOperationHandle<GameObject> <hCauldron>5__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <PreloadAssetsParallel>d__15(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				//IL_000d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				<>8__1 = null;
				<hGold>5__2 = default(AsyncOperationHandle<SpawnCard>);
				<hCleanse>5__3 = default(AsyncOperationHandle<SpawnCard>);
				<hScrapper>5__4 = default(AsyncOperationHandle<SpawnCard>);
				<hCauldron>5__5 = default(AsyncOperationHandle<GameObject>);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_0099: 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_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_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Invalid comparison between Unknown and I4
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Expected O, but got Unknown
				//IL_0139: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d7: Invalid comparison between Unknown and I4
				//IL_0204: Unknown result type (might be due to invalid IL or missing references)
				//IL_020a: Invalid comparison between Unknown and I4
				//IL_0237: Unknown result type (might be due to invalid IL or missing references)
				//IL_023d: Invalid comparison between Unknown and I4
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass15_0();
					<>8__1.handles = new List<AsyncOperationHandle>();
					<hGold>5__2 = default(AsyncOperationHandle<SpawnCard>);
					<hCleanse>5__3 = default(AsyncOperationHandle<SpawnCard>);
					<hScrapper>5__4 = default(AsyncOperationHandle<SpawnCard>);
					<hCauldron>5__5 = default(AsyncOperationHandle<GameObject>);
					if (cfgChest.Value)
					{
						<hGold>5__2 = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/Base/GoldChest/iscGoldChest.asset");
						<>8__1.handles.Add(AsyncOperationHandle<SpawnCard>.op_Implicit(<hGold>5__2));
					}
					if (cfgPot.Value)
					{
						<hCleanse>5__3 = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/Base/ShrineCleanse/iscShrineCleanse.asset");
						<>8__1.handles.Add(AsyncOperationHandle<SpawnCard>.op_Implicit(<hCleanse>5__3));
					}
					if (cfgScrapper.Value)
					{
						<hScrapper>5__4 = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/Base/Scrapper/iscScrapper.asset");
						<>8__1.handles.Add(AsyncOperationHandle<SpawnCard>.op_Implicit(<hScrapper>5__4));
					}
					if (cfgEnableCadulron.Value)
					{
						<hCauldron>5__5 = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCauldron/LunarCauldron, RedToWhite Variant.prefab");
						<>8__1.handles.Add(AsyncOperationHandle<GameObject>.op_Implicit(<hCauldron>5__5));
					}
					<>2__current = (object)new WaitUntil((Func<bool>)delegate
					{
						//IL_000c: 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)
						for (int i = 0; i < <>8__1.handles.Count; i++)
						{
							AsyncOperationHandle val = <>8__1.handles[i];
							if (!((AsyncOperationHandle)(ref val)).IsDone)
							{
								return false;
							}
						}
						return true;
					});
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (cfgChest.Value && (int)<hGold>5__2.Status == 1)
					{
						goldChestCard = <hGold>5__2.Result;
					}
					if (cfgPot.Value && (int)<hCleanse>5__3.Status == 1)
					{
						shrineCleanseCard = <hCleanse>5__3.Result;
					}
					if (cfgScrapper.Value && (int)<hScrapper>5__4.Status == 1)
					{
						scrapperCard = <hScrapper>5__4.Result;
					}
					if (cfgEnableCadulron.Value && (int)<hCauldron>5__5.Status == 1)
					{
						lunarCauldronPrefab = <hCauldron>5__5.Result;
					}
					assetsLoaded = true;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <SpawnWhenReady>d__16 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public BazaarExpand <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnWhenReady>d__16(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitUntil((Func<bool>)(() => assetsLoaded));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.TrySpawnOnce();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static ConfigEntry<bool> cfgPot;

		public static ConfigEntry<bool> cfgScrapper;

		public static ConfigEntry<bool> cfgChest;

		public static ConfigEntry<bool> cfgEnableCadulron;

		public static ConfigEntry<bool> cfgGtoW;

		public static ConfigEntry<int> cfgAmountTraded;

		private static SpawnCard goldChestCard;

		private static SpawnCard shrineCleanseCard;

		private static SpawnCard scrapperCard;

		private static GameObject lunarCauldronPrefab;

		private static bool assetsLoadingStarted;

		private static bool assetsLoaded;

		private static bool spawnedOnce;

		public void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Paths.ConfigPath + "\\BazaarExpand.cfg", true);
			cfgChest = val.Bind<bool>("General", "Enable Golden Chest", true, "If enabled, spawn a Golden Chest in the bazaar.");
			cfgPot = val.Bind<bool>("General", "Enable CleanPot", true, "If enabled, spawn a Cleansing Pool in the bazaar.");
			cfgScrapper = val.Bind<bool>("General", "Enable Scrapper", true, "If enabled, spawn a Scrapper in the bazaar.");
			cfgEnableCadulron = val.Bind<bool>("Lunar Cauldron", "Enable Reforge Cauldron", true, "If enabled, spawn a Special Cauldron in the bazaar.");
			cfgGtoW = val.Bind<bool>("Lunar Cauldron", "GreenToWhite", true, "If enabled, Green Items reforge into 3 White Items instead of a red item.");
			cfgAmountTraded = val.Bind<int>("Lunar Cauldron", "Items Amount Needed", 2, "Set the number of items needed to reforge.");
			if (!assetsLoadingStarted)
			{
				assetsLoadingStarted = true;
				((MonoBehaviour)this).StartCoroutine(PreloadAssetsParallel());
			}
			BazaarController.Start += new hook_Start(BazaarController_Start);
		}

		private void BazaarController_Start(orig_Start orig, BazaarController self)
		{
			orig.Invoke(self);
			if (assetsLoaded)
			{
				TrySpawnOnce();
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(SpawnWhenReady());
			}
		}

		[IteratorStateMachine(typeof(<PreloadAssetsParallel>d__15))]
		private IEnumerator PreloadAssetsParallel()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PreloadAssetsParallel>d__15(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<SpawnWhenReady>d__16))]
		private IEnumerator SpawnWhenReady()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SpawnWhenReady>d__16(0)
			{
				<>4__this = this
			};
		}

		private void TrySpawnOnce()
		{
			if (!spawnedOnce && !((Object)(object)Run.instance == (Object)null) && NetworkServer.active)
			{
				SpawnExpand();
			}
		}

		private void SpawnExpand()
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00e3: 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)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Expected O, but got Unknown
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Expected O, but got Unknown
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			PrinterInfo printerInfo = new PrinterInfo
			{
				position = new Vector3(-87.1f, -24f, -7.2f),
				rotation = new Vector3(0f, 72.6f, 0f)
			};
			PrinterInfo printerInfo2 = new PrinterInfo
			{
				position = new Vector3(-65.7f, -23.5f, -18.9f),
				rotation = new Vector3(0f, 72.6f, 0f)
			};
			PrinterInfo printerInfo3 = new PrinterInfo
			{
				position = new Vector3(-82.1f, -23.7f, -5.2f),
				rotation = new Vector3(0f, 72.6f, 0f)
			};
			PrinterInfo printerInfo4 = new PrinterInfo
			{
				position = new Vector3(-132f, -25f, -29.7f),
				rotation = new Vector3(0f, 72.6f, 0f)
			};
			ArtifactDef val = ArtifactCatalog.FindArtifactDef("Sacrifice");
			bool flag = false;
			if (Object.op_Implicit((Object)(object)RunArtifactManager.instance) && RunArtifactManager.instance.IsArtifactEnabled(val))
			{
				RunArtifactManager.instance.SetArtifactEnabledServer(val, false);
				flag = true;
			}
			DirectorPlacementRule val2 = new DirectorPlacementRule
			{
				placementMode = (PlacementMode)0
			};
			if (cfgChest.Value && (Object)(object)goldChestCard != (Object)null)
			{
				DirectorSpawnRequest val3 = new DirectorSpawnRequest(goldChestCard, val2, Run.instance.runRNG);
				GameObject spawnedInstance = goldChestCard.DoSpawn(printerInfo.position, Quaternion.identity, val3).spawnedInstance;
				if (Object.op_Implicit((Object)(object)spawnedInstance))
				{
					PurchaseInteraction component = spawnedInstance.GetComponent<PurchaseInteraction>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Networkcost = 1;
						component.costType = (CostTypeIndex)8;
					}
					ChestBehavior component2 = spawnedInstance.GetComponent<ChestBehavior>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						component2.tier1Chance = 0f;
						component2.tier2Chance = 0f;
						component2.tier3Chance = 1f;
						component2.lunarChance = 0f;
					}
					spawnedInstance.transform.eulerAngles = printerInfo.rotation;
					NetworkServer.Spawn(spawnedInstance);
				}
			}
			if (cfgPot.Value && (Object)(object)shrineCleanseCard != (Object)null)
			{
				DirectorSpawnRequest val4 = new DirectorSpawnRequest(shrineCleanseCard, val2, Run.instance.runRNG);
				GameObject spawnedInstance2 = shrineCleanseCard.DoSpawn(printerInfo2.position, Quaternion.identity, val4).spawnedInstance;
				if (Object.op_Implicit((Object)(object)spawnedInstance2))
				{
					spawnedInstance2.transform.eulerAngles = printerInfo2.rotation;
					NetworkServer.Spawn(spawnedInstance2);
				}
			}
			if (cfgScrapper.Value && (Object)(object)scrapperCard != (Object)null)
			{
				DirectorSpawnRequest val5 = new DirectorSpawnRequest(scrapperCard, val2, Run.instance.runRNG);
				GameObject spawnedInstance3 = scrapperCard.DoSpawn(printerInfo3.position, Quaternion.identity, val5).spawnedInstance;
				if (Object.op_Implicit((Object)(object)spawnedInstance3))
				{
					spawnedInstance3.transform.eulerAngles = printerInfo3.rotation;
					NetworkServer.Spawn(spawnedInstance3);
				}
			}
			if (cfgEnableCadulron.Value && (Object)(object)lunarCauldronPrefab != (Object)null)
			{
				GameObject val6 = Object.Instantiate<GameObject>(lunarCauldronPrefab, printerInfo4.position, Quaternion.identity);
				PurchaseInteraction component3 = val6.GetComponent<PurchaseInteraction>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					if (cfgGtoW.Value)
					{
						component3.costType = (CostTypeIndex)5;
					}
					component3.Networkcost = cfgAmountTraded.Value;
				}
				val6.transform.eulerAngles = printerInfo4.rotation;
				NetworkServer.Spawn(val6);
			}
			if (flag && Object.op_Implicit((Object)(object)RunArtifactManager.instance))
			{
				RunArtifactManager.instance.SetArtifactEnabledServer(val, true);
			}
		}
	}
}