Decompiled source of BazaarLimit v1.1.1

BazaarLimit.dll

Decompiled 3 months ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BazaarLimit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+21b1342309b51cdf560460fd0d11a6ee79ca4a7f")]
[assembly: AssemblyProduct("BazaarLimit")]
[assembly: AssemblyTitle("BazaarLimit")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BazaarLimit
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Moffein.BazaarLimit", "BazaarLimit", "1.1.1")]
	public class BazaarLimitPlugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Start <>9__7_0;

			public static Func<Instruction, bool> <>9__7_5;

			public static Func<float, float> <>9__7_6;

			public static Manipulator <>9__7_1;

			public static Func<Instruction, bool> <>9__7_7;

			public static Func<int, int> <>9__7_8;

			public static Manipulator <>9__7_2;

			public static hook_GrantPortalEntry <>9__7_3;

			public static hook_Begin <>9__7_4;

			internal void <Awake>b__7_0(orig_Start orig, Run self)
			{
				usedNewt = false;
				loopNewtUses = 0;
				loopBazaarCount = 0;
				orig.Invoke(self);
			}

			internal void <Awake>b__7_1(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(TeleporterInteraction), "baseShopSpawnChance")
				});
				val.EmitDelegate<Func<float, float>>((Func<float, float>)((float origChance) => (loopBazaarCount >= maxLoopBazaarCount.Value) ? 0f : origChance));
			}

			internal bool <Awake>b__7_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld(x, typeof(TeleporterInteraction), "baseShopSpawnChance");
			}

			internal float <Awake>b__7_6(float origChance)
			{
				return (loopBazaarCount >= maxLoopBazaarCount.Value) ? 0f : origChance;
			}

			internal void <Awake>b__7_2(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(Run), "shopPortalCount")
				});
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int origCount) => (!fixedRandomPortalChance.Value) ? origCount : 0));
			}

			internal bool <Awake>b__7_7(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld(x, typeof(Run), "shopPortalCount");
			}

			internal int <Awake>b__7_8(int origCount)
			{
				return (!fixedRandomPortalChance.Value) ? origCount : 0;
			}

			internal void <Awake>b__7_3(orig_GrantPortalEntry orig, PortalStatueBehavior self)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Invalid comparison between Unknown and I4
				orig.Invoke(self);
				if (NetworkServer.active && (int)self.portalType == 0)
				{
					usedNewt = true;
				}
			}

			internal void <Awake>b__7_4(orig_Begin orig, SceneExitController self)
			{
				orig.Invoke(self);
				if ((Object)(object)self.destinationScene == (Object)(object)bazaarSceneDef && usedNewt)
				{
					loopNewtUses++;
				}
			}
		}

		private static bool usedNewt = false;

		private static SceneDef bazaarSceneDef = Addressables.LoadAssetAsync<SceneDef>((object)"RoR2/Base/bazaar/bazaar.asset").WaitForCompletion();

		private static int loopBazaarCount = 0;

		public static ConfigEntry<int> maxLoopBazaarCount;

		private static int loopNewtUses = 0;

		public static ConfigEntry<int> maxLoopNewtUses;

		public static ConfigEntry<bool> fixedRandomPortalChance;

		public void Awake()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0135: 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_0140: Expected O, but got Unknown
			maxLoopBazaarCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Bazaar Entries per Loop", -1, "How many times you can visit the Bazaar Between Time each loop. When the limit is reached, random blue portals stop spawning and Newt Altars become unable to be used. -1 disables this check.");
			maxLoopNewtUses = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Newt Altars per Loop", 1, "How many times you can use Newt Altars per loop. When the limit is reached, Newt Altars become unable to be used. -1 disables this check.");
			fixedRandomPortalChance = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Random Bazaar Portal - Fixed Chance", true, "Random blue orbs have a fixed chance, instead of lowering based on bazaar visits.");
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				RiskOfOptionsSupport();
			}
			object obj = <>c.<>9__7_0;
			if (obj == null)
			{
				hook_Start val = delegate(orig_Start orig, Run self)
				{
					usedNewt = false;
					loopNewtUses = 0;
					loopBazaarCount = 0;
					orig.Invoke(self);
				};
				<>c.<>9__7_0 = val;
				obj = (object)val;
			}
			Run.Start += (hook_Start)obj;
			Stage.onStageStartGlobal += Stage_onStageStartGlobal;
			object obj2 = <>c.<>9__7_1;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val7 = new ILCursor(il);
					val7.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(TeleporterInteraction), "baseShopSpawnChance")
					});
					val7.EmitDelegate<Func<float, float>>((Func<float, float>)((float origChance) => (loopBazaarCount >= maxLoopBazaarCount.Value) ? 0f : origChance));
				};
				<>c.<>9__7_1 = val2;
				obj2 = (object)val2;
			}
			TeleporterInteraction.Start += (Manipulator)obj2;
			object obj3 = <>c.<>9__7_2;
			if (obj3 == null)
			{
				Manipulator val3 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val6 = new ILCursor(il);
					val6.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(Run), "shopPortalCount")
					});
					val6.EmitDelegate<Func<int, int>>((Func<int, int>)((int origCount) => (!fixedRandomPortalChance.Value) ? origCount : 0));
				};
				<>c.<>9__7_2 = val3;
				obj3 = (object)val3;
			}
			TeleporterInteraction.Start += (Manipulator)obj3;
			object obj4 = <>c.<>9__7_3;
			if (obj4 == null)
			{
				hook_GrantPortalEntry val4 = delegate(orig_GrantPortalEntry orig, PortalStatueBehavior self)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0017: Invalid comparison between Unknown and I4
					orig.Invoke(self);
					if (NetworkServer.active && (int)self.portalType == 0)
					{
						usedNewt = true;
					}
				};
				<>c.<>9__7_3 = val4;
				obj4 = (object)val4;
			}
			PortalStatueBehavior.GrantPortalEntry += (hook_GrantPortalEntry)obj4;
			object obj5 = <>c.<>9__7_4;
			if (obj5 == null)
			{
				hook_Begin val5 = delegate(orig_Begin orig, SceneExitController self)
				{
					orig.Invoke(self);
					if ((Object)(object)self.destinationScene == (Object)(object)bazaarSceneDef && usedNewt)
					{
						loopNewtUses++;
					}
				};
				<>c.<>9__7_4 = val5;
				obj5 = (object)val5;
			}
			SceneExitController.Begin += (hook_Begin)obj5;
		}

		private void Stage_onStageStartGlobal(Stage obj)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Invalid comparison between Unknown and I4
			usedNewt = false;
			if ((Object)(object)SceneCatalog.GetSceneDefForCurrentScene() == (Object)(object)bazaarSceneDef)
			{
				loopBazaarCount++;
			}
			if (Run.instance.stageClearCount % 5 == 0)
			{
				loopBazaarCount = 0;
				loopNewtUses = 0;
			}
			bool flag = maxLoopBazaarCount.Value >= 0 && loopBazaarCount >= maxLoopBazaarCount.Value;
			bool flag2 = maxLoopNewtUses.Value >= 0 && loopNewtUses >= maxLoopNewtUses.Value;
			if (!NetworkServer.active || !(flag || flag2))
			{
				return;
			}
			PortalStatueBehavior[] array = Object.FindObjectsOfType<PortalStatueBehavior>();
			foreach (PortalStatueBehavior val in array)
			{
				if ((int)val.portalType == 0)
				{
					PurchaseInteraction component = ((Component)val).GetComponent<PurchaseInteraction>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Networkavailable = false;
					}
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private void RiskOfOptionsSupport()
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(maxLoopBazaarCount, new IntSliderConfig
			{
				min = -1,
				max = 5
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(maxLoopNewtUses, new IntSliderConfig
			{
				min = -1,
				max = 5
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(fixedRandomPortalChance));
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}