Decompiled source of GuaranteedScrapper v1.0.0

GuaranteedScrapper.dll

Decompiled a week 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.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("GuaranteedScrapper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GuaranteedScrapper")]
[assembly: AssemblyTitle("GuaranteedScrapper")]
[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 GuaranteedScraper
{
	[BepInPlugin("cavemoss.GuaranteedScraper", "GuaranteedScraper", "1.0.0")]
	public class GuaranteedScrapper : BaseUnityPlugin
	{
		private static readonly string[] AllowedScenes = new string[10] { "artifactworld", "artifactworld01", "artifactworld02", "artifactworld03", "voidraid", "moon2", "meridian", "goldshores", "limbo", "mysteryspace" };

		public static ConfigEntry<int> ScrapperAmount { get; set; }

		public void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			ScrapperAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "Scrapper Amount", 3, new ConfigDescription("Amount of scrappers to be spawned on each allowed stage. (0 for no extra spawns).", (AcceptableValueBase)null, Array.Empty<object>()));
			SceneDirector.PlaceTeleporter += (hook_PlaceTeleporter)delegate(orig_PlaceTeleporter orig, SceneDirector self)
			{
				orig.Invoke(self);
				if (IsAllowedScene())
				{
					int num = Mathf.Max(0, ScrapperAmount.Value);
					for (int i = 0; i < num; i++)
					{
						SpawnScrapper(self);
					}
				}
				TrySpawnCleansingPoolWithChance(self);
			};
		}

		private static bool IsAllowedScene()
		{
			SceneDef val = (Object.op_Implicit((Object)(object)SceneInfo.instance) ? SceneInfo.instance.sceneDef : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			string cachedName = val.cachedName;
			string[] allowedScenes = AllowedScenes;
			foreach (string text in allowedScenes)
			{
				if (cachedName == text)
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsBazaarScene()
		{
			SceneDef val = (Object.op_Implicit((Object)(object)SceneInfo.instance) ? SceneInfo.instance.sceneDef : null);
			return (Object)(object)val != (Object)null && val.cachedName == "bazaar";
		}

		public void SpawnScrapper(SceneDirector self)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			Xoroshiro128Plus fieldValue = Reflection.GetFieldValue<Xoroshiro128Plus>((object)self, "rng");
			Xoroshiro128Plus val = new Xoroshiro128Plus(fieldValue.nextUlong);
			SpawnCard val2 = Resources.Load<SpawnCard>("SpawnCards/InteractableSpawnCard/iscScrapper");
			if ((Object)(object)val2 != (Object)null && (Object)(object)DirectorCore.instance != (Object)null)
			{
				DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(val2, new DirectorPlacementRule
				{
					placementMode = (PlacementMode)4
				}, val));
			}
		}

		private void TrySpawnCleansingPoolWithChance(SceneDirector self)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			float num = (IsAllowedScene() ? 0.08f : (IsBazaarScene() ? 0.04f : 0f));
			if (!(num <= 0f))
			{
				Xoroshiro128Plus fieldValue = Reflection.GetFieldValue<Xoroshiro128Plus>((object)self, "rng");
				Xoroshiro128Plus val = new Xoroshiro128Plus(fieldValue.nextUlong);
				if (val.nextNormalizedFloat < num)
				{
					SpawnCleansingPool(self, val);
				}
			}
		}

		private void SpawnCleansingPool(SceneDirector self, Xoroshiro128Plus rng)
		{
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if ((Object)(object)DirectorCore.instance == (Object)null)
			{
				return;
			}
			InteractableSpawnCard val = Resources.Load<InteractableSpawnCard>("SpawnCards/InteractableSpawnCard/iscShrineCleanse");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[GuaranteedScraper] iscShrineCleanse not found.");
				return;
			}
			DirectorSpawnRequest val2 = new DirectorSpawnRequest((SpawnCard)(object)val, new DirectorPlacementRule
			{
				placementMode = (PlacementMode)4
			}, rng);
			GameObject val3 = DirectorCore.instance.TrySpawnObject(val2);
			if (Object.op_Implicit((Object)(object)val3))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[GuaranteedScraper] Spawned Cleansing Pool (iscShrineCleanse).");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[GuaranteedScraper] Failed to spawn Cleansing Pool.");
			}
		}
	}
}