Decompiled source of BepInExUtilities v0.1.1

BepInExUtilities.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
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 HutongGames.PlayMaker;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BepInExUtilities")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+8d395d8c97a242221214b966c2c7e5a4fc0ae3b1")]
[assembly: AssemblyProduct("BepInExUtilities")]
[assembly: AssemblyTitle("BepInExUtilities")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/al3ks1s/Silksong.BepInExUtilities")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInExUtilities
{
	[BepInPlugin("io.github.al3ks1s.bepinexutilities", "BepInExUtilities", "0.1.1")]
	public class BepInExUtilitiesPlugin : BaseUnityPlugin
	{
		public const string Id = "io.github.al3ks1s.bepinexutilities";

		public static string Name => "BepInExUtilities";

		public static string Version => "0.1.1";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.al3ks1s.bepinexutilities) has loaded!"));
		}
	}
}
namespace BepInExUtilities.Behaviours
{
	[Serializable]
	[Tooltip("Extends the Scene Additional Load script to support bepinEx configs")]
	public class SceneAdditiveLoadConditionalBepinEx : SceneAdditiveLoadConditional
	{
		[SerializeField]
		public BepinExTest bepinTests;

		private void Awake()
		{
		}

		private void OnEnable()
		{
			if (SceneAdditiveLoadConditional.LoadInSequence && !base.sceneLoaded && TryTestLoad())
			{
				SceneAdditiveLoadConditional._additiveSceneLoads.Add((SceneAdditiveLoadConditional)(object)this);
			}
		}

		private void Start()
		{
			//IL_002e: 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)
			if (SceneAdditiveLoadConditional.LoadInSequence || base.sceneLoaded || !TryTestLoad())
			{
				return;
			}
			SceneAdditiveLoadConditional._additiveSceneLoads.Add((SceneAdditiveLoadConditional)(object)this);
			((SceneAdditiveLoadConditional)this).ApplySettings();
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				if (((Scene)(ref sceneAt)).name == ((SceneAdditiveLoadConditional)this).SceneNameToLoad)
				{
					base.sceneLoaded = true;
					return;
				}
			}
			((MonoBehaviour)this).StartCoroutine(((SceneAdditiveLoadConditional)this).LoadRoutine(true, (SceneAdditiveLoadConditional)(object)this));
		}

		private bool TryTestLoad()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			bool flag = !base.tests.IsFulfilled || !BepinExTests();
			QuestTest[] questTests = base.questTests;
			for (int i = 0; i < questTests.Length; i++)
			{
				QuestTest val = questTests[i];
				if (!((QuestTest)(ref val)).IsFulfilled)
				{
					flag = true;
					break;
				}
			}
			string entryGateName = GameManager.instance.entryGateName;
			if (!flag && base.doorWhiteList.Length != 0)
			{
				bool flag2 = false;
				string[] doorWhiteList = base.doorWhiteList;
				for (int j = 0; j < doorWhiteList.Length; j++)
				{
					if (doorWhiteList[j].Equals(entryGateName))
					{
						flag2 = true;
						break;
					}
				}
				if (!flag2)
				{
					flag = true;
				}
			}
			if (!flag && base.doorBlackList.Length != 0)
			{
				string[] doorBlackList = base.doorBlackList;
				for (int k = 0; k < doorBlackList.Length; k++)
				{
					if (doorBlackList[k].Equals(entryGateName))
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag && base.otherLoaderBlacklist.Length != 0)
			{
				SceneAdditiveLoadConditional[] otherLoaderBlacklist = base.otherLoaderBlacklist;
				for (int l = 0; l < otherLoaderBlacklist.Length; l++)
				{
					if (otherLoaderBlacklist[l].TryTestLoad())
					{
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				base.loadAlt = true;
			}
			return !string.IsNullOrEmpty(((SceneAdditiveLoadConditional)this).SceneNameToLoad);
		}

		private bool BepinExTests()
		{
			if (bepinTests != null)
			{
				return bepinTests.IsFulfilled;
			}
			return true;
		}
	}
	[Serializable]
	[Tooltip("Test group on bepinex configurations")]
	public class BepinExTest
	{
		public enum NumTestType
		{
			Equal,
			NotEqual,
			LessThan,
			MoreThan
		}

		public enum StringTestType
		{
			Equal,
			NotEqual,
			Contains,
			NotContains
		}

		[Serializable]
		public abstract class BepinTest
		{
			public virtual bool IsFulfilled => false;
		}

		[Serializable]
		public class BepinTest<T> : BepinTest
		{
			public string KeyName;

			public string SectionName;

			public string BepinExPluginID;

			public T GetConfigValue()
			{
				ConfigEntry<T> val = default(ConfigEntry<T>);
				if (Chainloader.PluginInfos.TryGetValue(BepinExPluginID, out var value) && value.Instance.Config.TryGetEntry<T>(SectionName, KeyName, ref val))
				{
					return val.Value;
				}
				return default(T);
			}
		}

		[Serializable]
		public class BepinTestBool : BepinTest<bool>
		{
			public bool ExpectedValue;

			public override bool IsFulfilled => GetConfigValue() == ExpectedValue;
		}

		[Serializable]
		public class BepinTestInt : BepinTest<int>
		{
			public int ExpectedValue;

			public NumTestType testType;

			public override bool IsFulfilled
			{
				get
				{
					int configValue = GetConfigValue();
					return testType switch
					{
						NumTestType.Equal => configValue == ExpectedValue, 
						NumTestType.NotEqual => configValue != ExpectedValue, 
						NumTestType.LessThan => configValue < ExpectedValue, 
						NumTestType.MoreThan => configValue > ExpectedValue, 
						_ => false, 
					};
				}
			}
		}

		[Serializable]
		public class BepinTestFloat : BepinTest<float>
		{
			public float ExpectedValue;

			public NumTestType testType;

			public override bool IsFulfilled
			{
				get
				{
					float configValue = GetConfigValue();
					return testType switch
					{
						NumTestType.Equal => configValue == ExpectedValue, 
						NumTestType.NotEqual => configValue != ExpectedValue, 
						NumTestType.LessThan => configValue < ExpectedValue, 
						NumTestType.MoreThan => configValue > ExpectedValue, 
						_ => false, 
					};
				}
			}
		}

		[Serializable]
		public class BepinTestString : BepinTest<string>
		{
			public string ExpectedValue;

			public StringTestType testType;

			public override bool IsFulfilled
			{
				get
				{
					string configValue = GetConfigValue();
					return testType switch
					{
						StringTestType.Equal => configValue.Equals(ExpectedValue), 
						StringTestType.NotEqual => !configValue.Equals(ExpectedValue), 
						StringTestType.Contains => configValue.Contains(ExpectedValue), 
						StringTestType.NotContains => !configValue.Contains(ExpectedValue), 
						_ => false, 
					};
				}
			}
		}

		[Serializable]
		public class BepinTestGroup
		{
			[SerializeReference]
			public List<BepinTest> tests = new List<BepinTest>();

			public bool IsFulfilled
			{
				get
				{
					if (tests == null)
					{
						return true;
					}
					if (tests.Count == 0)
					{
						return true;
					}
					return tests.All((BepinTest t) => t.IsFulfilled);
				}
			}
		}

		[SerializeField]
		public List<BepinTestGroup> tests = new List<BepinTestGroup>();

		public bool IsFulfilled
		{
			get
			{
				if (tests == null)
				{
					return true;
				}
				if (tests.Count == 0)
				{
					return true;
				}
				return tests.Any((BepinTestGroup t) => t.IsFulfilled);
			}
		}
	}
}
namespace BepInExUtilities.Actions
{
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Bool Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigBool : GetBepinExConfigValue<bool>
	{
		public FsmBool storeVariable;

		public override void DoGetValue()
		{
			ConfigEntry<bool> val = default(ConfigEntry<bool>);
			if (config.TryGetEntry<bool>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Float Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigFloat : GetBepinExConfigValue<float>
	{
		public FsmFloat storeVariable;

		public override void DoGetValue()
		{
			ConfigEntry<float> val = default(ConfigEntry<float>);
			if (config.TryGetEntry<float>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Int Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigInt : GetBepinExConfigValue<int>
	{
		public FsmInt storeVariable;

		public override void DoGetValue()
		{
			ConfigEntry<int> val = default(ConfigEntry<int>);
			if (config.TryGetEntry<int>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("String Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigString : GetBepinExConfigValue<string>
	{
		public FsmString storeVariable;

		public override void DoGetValue()
		{
			ConfigEntry<string> val = default(ConfigEntry<string>);
			if (config.TryGetEntry<string>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Generic Bepin Ex configuration retrieval action. This is a stub, use the type specific actions.")]
	public class GetBepinExConfigValue<T> : FsmStateAction
	{
		[RequiredField]
		[Tooltip("The plugin ID as defined in the main class.")]
		public string BepinExPluginID;

		[RequiredField]
		public string BepinExConfigSection;

		[RequiredField]
		public string BepinExConfigKey;

		protected ConfigFile config;

		public override void Awake()
		{
			if (!Chainloader.PluginInfos.TryGetValue(BepinExPluginID, out var value))
			{
				((FsmStateAction)this).Finish();
			}
			else
			{
				config = value.Instance.Config;
			}
		}

		public override void OnEnter()
		{
			DoGetValue();
			((FsmStateAction)this).Finish();
		}

		public virtual void DoGetValue()
		{
			ConfigEntry<T> val = default(ConfigEntry<T>);
			config.TryGetEntry<T>(BepinExConfigSection, BepinExConfigKey, ref val);
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Vector2 Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigVector2 : GetBepinExConfigValue<Vector2>
	{
		public FsmVector2 storeVariable;

		public override void DoGetValue()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<Vector2> val = default(ConfigEntry<Vector2>);
			if (config.TryGetEntry<Vector2>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
	[ActionCategory("BepInEx Utilities")]
	[Tooltip("Vector3 Bepin Ex configuration retrieval action")]
	public class GetBepinExConfigVector3 : GetBepinExConfigValue<Vector3>
	{
		public FsmVector3 storeVariable;

		public override void DoGetValue()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<Vector3> val = default(ConfigEntry<Vector3>);
			if (config.TryGetEntry<Vector3>(BepinExConfigSection, BepinExConfigKey, ref val))
			{
				storeVariable.Value = val.Value;
			}
		}
	}
}