Decompiled source of Dramamist v1.1.0

Dramamist.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Dramamist")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dramamist")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("07cac1e2-0584-44d6-b196-7cba1e28b628")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 Dramamist
{
	public sealed class FadeOutParticleMist : MonoBehaviour
	{
		private Demister _demister;

		private Collider _collider;

		private void Awake()
		{
			_demister = ((Component)this).GetComponentInChildren<Demister>();
			_collider = ((Collider)(object)((Component)(object)_demister.m_forceField).GetOrAddComponent<SphereCollider>().SetRadius(_demister.m_forceField.endRange)).SetIsTrigger(isTrigger: true);
			ParticleMistManager.UpdateDemisterSettings(_demister);
		}

		private void OnEnable()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_collider.SetEnabled(enabled: true);
			TriggerModule trigger = ParticleMist.m_instance.m_ps.trigger;
			((TriggerModule)(ref trigger)).AddCollider((Component)(object)_collider);
		}

		private void OnDisable()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_collider.SetEnabled(enabled: false);
			TriggerModule trigger = ParticleMist.m_instance.m_ps.trigger;
			((TriggerModule)(ref trigger)).RemoveCollider((Component)(object)_collider);
		}
	}
	public sealed class ParticleMistTriggerCallback : MonoBehaviour
	{
		private ParticleSystem _particleSystem;

		private readonly List<Particle> _insideParticles = new List<Particle>();

		private void OnEnable()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			_particleSystem = ((Component)this).GetComponent<ParticleSystem>();
			MainModule main = _particleSystem.main;
			_insideParticles.Capacity = ((MainModule)(ref main)).maxParticles;
		}

		private void OnParticleTrigger()
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				UpdateParticles((ParticleSystemTriggerEventType)0);
			}
		}

		private void UpdateParticles(ParticleSystemTriggerEventType eventType)
		{
			//IL_0011: 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_002e: 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)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_005e: 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)
			float value = PluginConfig.DemisterTriggerFadeOutMultiplier.Value;
			int triggerParticles = ParticlePhysicsExtensions.GetTriggerParticles(_particleSystem, eventType, _insideParticles);
			for (int i = 0; i < triggerParticles; i++)
			{
				Particle value2 = _insideParticles[i];
				Color val = Color32.op_Implicit(((Particle)(ref value2)).startColor);
				val.a *= value;
				((Particle)(ref value2)).startColor = Color32.op_Implicit(val);
				_insideParticles[i] = value2;
			}
			ParticlePhysicsExtensions.SetTriggerParticles(_particleSystem, eventType, _insideParticles);
		}
	}
	public sealed class ParticleSystemProfile
	{
		public MinMaxGradient StartColor { get; }

		public MinMaxCurve StartRotation { get; }

		public MinMaxCurve VelocityOverLifetimeX { get; }

		public MinMaxCurve VelocityOverLifetimeY { get; }

		public MinMaxCurve VelocityOverLifetimeZ { get; }

		public MinMaxCurve RotationOverLifetimeX { get; }

		public MinMaxCurve RotationOverLifetimeY { get; }

		public MinMaxCurve RotationOverLifetimeZ { get; }

		public ParticleSystemProfile(ParticleSystem particleSystem)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			MainModule main = particleSystem.main;
			StartRotation = ((MainModule)(ref main)).startRotation;
			StartColor = ((MainModule)(ref main)).startColor;
			VelocityOverLifetimeModule velocityOverLifetime = particleSystem.velocityOverLifetime;
			VelocityOverLifetimeX = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x;
			VelocityOverLifetimeY = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y;
			VelocityOverLifetimeZ = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z;
			RotationOverLifetimeModule rotationOverLifetime = particleSystem.rotationOverLifetime;
			RotationOverLifetimeX = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).x;
			RotationOverLifetimeY = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).y;
			RotationOverLifetimeZ = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).z;
		}
	}
	public static class ParticleMistManager
	{
		private static readonly MinMaxCurve _zeroCurve = new MinMaxCurve(0f);

		private static ParticleSystemProfile _particleMistProfile;

		private static MinMaxGradient _flatStartColor;

		public static void UpdateDemisterSettings()
		{
			if (Demister.m_instances.Count <= 0)
			{
				return;
			}
			foreach (Demister instance in Demister.m_instances)
			{
				UpdateDemisterSettings(instance);
			}
		}

		public static void UpdateDemisterSettings(Demister demister)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			demister.m_forceField.gravity = MinMaxCurve.op_Implicit(PluginConfig.IsModEnabled.Value ? PluginConfig.DemisterForceFieldGravity.Value : (-0.08f));
			FadeOutParticleMist fadeOutParticleMist = default(FadeOutParticleMist);
			if (((Component)demister).TryGetComponent<FadeOutParticleMist>(ref fadeOutParticleMist))
			{
				((Behaviour)fadeOutParticleMist).enabled = PluginConfig.IsModEnabled.Value && PluginConfig.DemisterTriggerFadeOutParticleMist.Value;
			}
		}

		public static void UpdateParticleMistSettings()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002a: 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)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ParticleMist.m_instance))
			{
				return;
			}
			ParticleMist instance = ParticleMist.m_instance;
			MainModule main = instance.m_ps.main;
			TriggerModule trigger = instance.m_ps.trigger;
			VelocityOverLifetimeModule velocityOverLifetime = instance.m_ps.velocityOverLifetime;
			RotationOverLifetimeModule rotationOverLifetime = instance.m_ps.rotationOverLifetime;
			if (_particleMistProfile == null)
			{
				if (_particleMistProfile == null)
				{
					_particleMistProfile = new ParticleSystemProfile(instance.m_ps);
				}
				MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
				_flatStartColor = new MinMaxGradient(((MinMaxGradient)(ref startColor)).colorMax);
			}
			if (PluginConfig.IsModEnabled.Value && PluginConfig.ParticleMistReduceMotion.Value)
			{
				((MainModule)(ref main)).startRotation = _zeroCurve;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = _zeroCurve;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = _zeroCurve;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = _zeroCurve;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).x = _zeroCurve;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).y = _zeroCurve;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).z = _zeroCurve;
			}
			else
			{
				((MainModule)(ref main)).startRotation = _particleMistProfile.StartRotation;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = _particleMistProfile.VelocityOverLifetimeX;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = _particleMistProfile.VelocityOverLifetimeY;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = _particleMistProfile.VelocityOverLifetimeZ;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).x = _particleMistProfile.RotationOverLifetimeX;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).y = _particleMistProfile.RotationOverLifetimeY;
				((RotationOverLifetimeModule)(ref rotationOverLifetime)).z = _particleMistProfile.RotationOverLifetimeZ;
			}
			if (PluginConfig.IsModEnabled.Value && PluginConfig.ParticleMistUseFlatMistStartColor.Value)
			{
				((MainModule)(ref main)).startColor = _flatStartColor;
			}
			else
			{
				((MainModule)(ref main)).startColor = _particleMistProfile.StartColor;
			}
			((TriggerModule)(ref trigger)).enabled = PluginConfig.IsModEnabled.Value && PluginConfig.DemisterTriggerFadeOutParticleMist.Value;
			((TriggerModule)(ref trigger)).inside = (ParticleSystemOverlapAction)2;
			((TriggerModule)(ref trigger)).colliderQueryMode = (ParticleSystemColliderQueryMode)0;
		}
	}
	[BepInPlugin("redseiko.valheim.dramamist", "Dramamist", "1.1.0")]
	public sealed class Dramamist : BaseUnityPlugin
	{
		public const string PluginGuid = "redseiko.valheim.dramamist";

		public const string PluginName = "Dramamist";

		public const string PluginVersion = "1.1.0";

		private static ManualLogSource _logger;

		public void Awake()
		{
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.dramamist");
		}

		public static void LogInfo(object obj)
		{
			_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
			Chat.m_instance.AddMessage(obj);
		}

		public static void LogError(object obj)
		{
			_logger.LogError((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
			Chat.m_instance.AddMessage(obj);
		}
	}
	[HarmonyPatch(typeof(Demister))]
	internal static class DemisterPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnEnable")]
		private static void OnEnablePostfix(Demister __instance)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				ParticleMistManager.UpdateDemisterSettings(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(ParticleMist))]
	internal static class ParticleMistPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake(ParticleMist __instance)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				ParticleMistManager.UpdateParticleMistSettings();
			}
			((Component)__instance.m_ps).gameObject.AddComponent<ParticleMistTriggerCallback>();
		}
	}
	[HarmonyPatch(typeof(SE_Demister))]
	internal static class SEDemisterPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdateStatusEffect")]
		private static void UpdateStatusEffectPrefix(SE_Demister __instance, ref bool __state)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				__state = Object.op_Implicit((Object)(object)__instance.m_ballInstance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateStatusEffect")]
		private static void UpdateStatusEffectPostfix(SE_Demister __instance, ref bool __state)
		{
			if (PluginConfig.IsModEnabled.Value && Object.op_Implicit((Object)(object)__instance.m_ballInstance) && !__state && __instance.m_ballInstance.TryGetComponentInChildren<Demister>(out Demister component))
			{
				((Component)(object)component).GetOrAddComponent<FadeOutParticleMist>();
			}
		}
	}
	public static class PluginConfig
	{
		public static ConfigFile Config { get; private set; }

		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<bool> ParticleMistReduceMotion { get; private set; }

		public static ConfigEntry<bool> ParticleMistUseFlatMistStartColor { get; private set; }

		public static ConfigEntry<float> ParticleMistDistantEmissionMaxVelocity { get; private set; }

		public static ConfigEntry<float> DemisterForceFieldGravity { get; private set; }

		public static ConfigEntry<bool> DemisterTriggerFadeOutParticleMist { get; private set; }

		public static ConfigEntry<float> DemisterTriggerFadeOutMultiplier { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod.");
			IsModEnabled.OnSettingChanged<bool>(ParticleMistManager.UpdateParticleMistSettings);
			IsModEnabled.OnSettingChanged<bool>((Action)ParticleMistManager.UpdateDemisterSettings);
			ParticleMistReduceMotion = config.BindInOrder("ParticleMist", "particleMistReduceMotion", defaultValue: true, "ParticleMist: reduces motion of the ParticleMist by setting Velocity/Rotation multipliers to 0.");
			ParticleMistReduceMotion.OnSettingChanged<bool>(ParticleMistManager.UpdateParticleMistSettings);
			ParticleMistUseFlatMistStartColor = config.BindInOrder("ParticleMist", "particleMistUseFlatMistStartColor", defaultValue: false, "ParticleMist: uses only a single color for ParticleMist.m_ps.startColor");
			ParticleMistUseFlatMistStartColor.OnSettingChanged<bool>(ParticleMistManager.UpdateParticleMistSettings);
			ParticleMistDistantEmissionMaxVelocity = config.BindInOrder("ParticleMist", "particleMistDistantEmissionMaxVelocity", 2f, "ParticleMist: override the setting for ParticleMist.m_distantEmissionMaxVel", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f));
			ParticleMistDistantEmissionMaxVelocity.OnSettingChanged<float>(ParticleMistManager.UpdateParticleMistSettings);
			DemisterForceFieldGravity = config.BindInOrder("Demister", "demisterForceFieldGravity", -5f, "Demister.m_forceField.gravity (vanilla: -0.08)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-10f, 0f));
			DemisterForceFieldGravity.OnSettingChanged<float>((Action)ParticleMistManager.UpdateDemisterSettings);
			DemisterTriggerFadeOutParticleMist = config.BindInOrder("Demister", "demisterTriggerFadeOutParticleMist", defaultValue: true, "Demister: add a sphere collider trigger that fades-out ParticleMist inside.");
			DemisterTriggerFadeOutMultiplier = config.BindInOrder("Demister", "demisterTriggerFadeOutMultiplier", 0.85f, "Demister: fade-out multiplier for the above trigger.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f));
			DemisterTriggerFadeOutParticleMist.OnSettingChanged<bool>(ParticleMistManager.UpdateParticleMistSettings);
			DemisterTriggerFadeOutParticleMist.OnSettingChanged<bool>((Action)ParticleMistManager.UpdateDemisterSettings);
		}
	}
}
namespace ComfyLib
{
	public static class ChatExtensions
	{
		public static void AddMessage(this Chat chat, object obj)
		{
			if (Object.op_Implicit((Object)(object)chat))
			{
				((Terminal)chat).AddString(obj.ToString());
				chat.m_hideTimer = 0f;
			}
		}
	}
	public static class ColliderExtensions
	{
		public static Collider SetEnabled(this Collider collider, bool enabled)
		{
			collider.enabled = enabled;
			return collider;
		}

		public static Collider SetIsTrigger(this Collider collider, bool isTrigger)
		{
			collider.isTrigger = isTrigger;
			return collider;
		}

		public static SphereCollider SetRadius(this SphereCollider collider, float radius)
		{
			collider.radius = radius;
			return collider;
		}
	}
	public static class ComponentExtensions
	{
		public static T GetOrAddComponent<T>(this Component component) where T : Component
		{
			T result = default(T);
			if (!component.TryGetComponent<T>(ref result))
			{
				return component.gameObject.AddComponent<T>();
			}
			return result;
		}

		public static bool TryGetComponentInChildren<T>(this Component component, out T componentOut) where T : Component
		{
			componentOut = component.GetComponentInChildren<T>();
			return Object.op_Implicit((Object)(object)componentOut);
		}

		public static bool TryGetComponentInParent<T>(this Component component, out T componentOut) where T : Component
		{
			componentOut = component.GetComponentInParent<T>();
			return Object.op_Implicit((Object)(object)componentOut);
		}
	}
	public static class GameObjectExtensions
	{
		public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out T component) where T : Component
		{
			component = gameObject.GetComponentInChildren<T>();
			return Object.op_Implicit((Object)(object)component);
		}

		public static bool TryGetComponentInParent<T>(this GameObject gameObject, out T component) where T : Component
		{
			component = gameObject.GetComponentInParent<T>();
			return Object.op_Implicit((Object)(object)component);
		}
	}
	public static class ObjectExtensions
	{
		public static T FirstByNameOrThrow<T>(this T[] unityObjects, string name) where T : Object
		{
			foreach (T val in unityObjects)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}");
		}

		public static T Ref<T>(this T unityObject) where T : Object
		{
			if (!Object.op_Implicit((Object)(object)unityObject))
			{
				return default(T);
			}
			return unityObject;
		}
	}
	public static class ConfigFileExtensions
	{
		internal sealed class ConfigurationManagerAttributes
		{
			public Action<ConfigEntryBase> CustomDrawer;

			public bool? Browsable;

			public bool? HideDefaultButton;

			public bool? HideSettingName;

			public bool? IsAdvanced;

			public int? Order;

			public bool? ReadOnly;
		}

		private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();

		private static int GetSettingOrder(string section)
		{
			if (!_sectionToSettingOrder.TryGetValue(section, out var value))
			{
				value = 0;
			}
			_sectionToSettingOrder[section] = value - 1;
			return value;
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = null,
					HideDefaultButton = hideDefaultButton,
					HideSettingName = hideSettingName,
					IsAdvanced = isAdvanced,
					Order = GetSettingOrder(section),
					ReadOnly = readOnly
				}
			}));
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = customDrawer,
					HideDefaultButton = hideDefaultButton,
					HideSettingName = hideSettingName,
					IsAdvanced = isAdvanced,
					Order = GetSettingOrder(section),
					ReadOnly = readOnly
				}
			}));
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}
	}
}