Decompiled source of OopsAllShrines v0.1.0

plugin.dll

Decompiled 3 days 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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
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("ExamplePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+520bdb6a3b54c0d5369dc0992186c0c60bc744ae")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[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 EverythingIsChanceShrines
{
	[BepInPlugin("com.yourname.everythingischance", "Everything Is Chance Shrines", "1.1.0")]
	public class EverythingIsChanceShrinesPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "JTNGRoup.OopsAllShrines";

		public const string PluginAuthor = "JTNGRoup";

		public const string PluginName = "OopsAllShrines";

		public const string PluginVersion = "0.1.0";

		private GameObject shrineChancePrefab;

		private ConfigEntry<float> replacementRate;

		private ConfigEntry<bool> keepPrinters;

		private Xoroshiro128Plus rng;

		public void Awake()
		{
			shrineChancePrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/NetworkedObjects/Shrines/ShrineChance");
			if (!Object.op_Implicit((Object)(object)shrineChancePrefab))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load ShrineChance prefab.");
			}
			replacementRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ReplacementRate", 0.5f, "Chance (0-1) that a non-chance interactable becomes a Chance Shrine. 0.5 = ~50%.");
			keepPrinters = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "KeepPrinters", true, "If true, printers (duplicators) are NOT replaced.");
			Stage.onStageStartGlobal += OnStageStart;
		}

		public void OnDestroy()
		{
			Stage.onStageStartGlobal -= OnStageStart;
		}

		private void OnStageStart(Stage stage)
		{
			//IL_003f: 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_0049: Expected O, but got Unknown
			if (NetworkServer.active)
			{
				rng = (((Object)(object)Run.instance != (Object)null) ? new Xoroshiro128Plus(Run.instance.stageRng.nextUlong) : new Xoroshiro128Plus((ulong)Random.Range(1, int.MaxValue)));
				((MonoBehaviour)this).Invoke("ReplacePass1", 1f);
				((MonoBehaviour)this).Invoke("ReplacePass2", 2.5f);
			}
		}

		private void ReplacePass1()
		{
			ReplaceAllIntoChanceShrines();
		}

		private void ReplacePass2()
		{
			ReplaceAllIntoChanceShrines();
		}

		private void ReplaceAllIntoChanceShrines()
		{
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)shrineChancePrefab))
			{
				return;
			}
			float num = Mathf.Clamp01(replacementRate.Value);
			PurchaseInteraction[] array = Object.FindObjectsOfType<PurchaseInteraction>();
			PurchaseInteraction[] array2 = array;
			foreach (PurchaseInteraction val in array2)
			{
				if (Object.op_Implicit((Object)(object)val) && !Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<TeleporterInteraction>()) && !Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<ShrineChanceBehavior>()) && (!keepPrinters.Value || !IsPrinter(((Component)val).gameObject)) && !(rng.nextNormalizedFloat > num))
				{
					ReplaceGameObjectWithChanceShrine(((Component)val).gameObject);
				}
			}
			BarrelInteraction[] array3 = Object.FindObjectsOfType<BarrelInteraction>();
			BarrelInteraction[] array4 = array3;
			foreach (BarrelInteraction val2 in array4)
			{
				if (Object.op_Implicit((Object)(object)val2) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<TeleporterInteraction>()) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<ShrineChanceBehavior>()) && !(rng.nextNormalizedFloat > num))
				{
					ReplaceGameObjectWithChanceShrine(((Component)val2).gameObject);
				}
			}
		}

		private bool IsPrinter(GameObject obj)
		{
			NetworkIdentity componentInParent = obj.GetComponentInParent<NetworkIdentity>();
			GameObject val = ((componentInParent != null) ? ((Component)componentInParent).gameObject : null) ?? obj;
			string text = ((Object)val).name ?? "";
			if (text.Contains("Duplicator"))
			{
				return true;
			}
			if (Object.op_Implicit((Object)(object)val.GetComponentInParent<ShopTerminalBehavior>()) && text.Contains("Duplicator"))
			{
				return true;
			}
			return false;
		}

		private void ReplaceGameObjectWithChanceShrine(GameObject target)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0073: 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_0082: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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)
			if (!Object.op_Implicit((Object)(object)target))
			{
				return;
			}
			NetworkIdentity componentInParent = target.GetComponentInParent<NetworkIdentity>();
			GameObject val = (Object.op_Implicit((Object)(object)componentInParent) ? ((Component)componentInParent).gameObject : target);
			if (!Object.op_Implicit((Object)(object)val.GetComponentInParent<TeleporterInteraction>()) && !Object.op_Implicit((Object)(object)val.GetComponentInParent<ShrineChanceBehavior>()))
			{
				Vector3 val2 = val.transform.position;
				Quaternion val3 = val.transform.rotation;
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(val2 + Vector3.up * 3f, Vector3.down, ref val4, 20f, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask)))
				{
					val2 = ((RaycastHit)(ref val4)).point;
					val3 = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val4)).normal) * val3;
				}
				NetworkServer.Destroy(val);
				GameObject val5 = Object.Instantiate<GameObject>(shrineChancePrefab, val2, val3);
				NetworkServer.Spawn(val5);
			}
		}
	}
}
namespace OopsAllShrines
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}