Decompiled source of R2API Buffs v1.0.0

plugins/R2API.Buffs/R2API.Buffs.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using On.RoR2.UI;
using R2API.AutoVersionGen;
using R2API.Utils;
using RoR2;
using RoR2.UI;
using RoR2BepInExPack.Utilities;
using UnityEngine;
using UnityEngine.UI;

[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("R2API.Buffs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+08d7eb19309a06aa19383edbade1e9494f9ee1c2")]
[assembly: AssemblyProduct("R2API.Buffs")]
[assembly: AssemblyTitle("R2API.Buffs")]
[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.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]
	[Microsoft.CodeAnalysis.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]
	[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 System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace R2API
{
	[AutoVersion]
	public static class BuffsAPI
	{
		public delegate SimpleSpriteAnimation CustomSimpleSpriteAnimation(BuffIcon buffIcon);

		public enum ModdedBuffFlag
		{

		}

		public delegate void CustomStackingDisplayMethod(BuffIcon buffIcon);

		private class SingleSimpleSpriteAnimationDisplayClass
		{
			public SimpleSpriteAnimation simpleSpriteAnimation;

			public SimpleSpriteAnimation SingleCustomSimpleSpriteAnimation(BuffIcon buffIcon)
			{
				return simpleSpriteAnimation;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__BuffIcon_UpdateIcon;

			public static hook_OnEnable <1>__BuffIcon_OnEnable;

			public static hook_SetBuffDefs <2>__BuffCatalog_SetBuffDefs;

			public static Func<BuffIcon, bool> <3>__CheckSimpleSpriteAnimation;

			public static Func<BuffIcon, Sprite> <4>__HandleSimpleSpriteAnimation;

			public static Func<BuffIcon, StackingDisplayMethod, bool> <5>__HandleCustomStackingDisplayMethods;
		}

		public const string PluginGUID = "com.bepis.r2api.buffs";

		public const string PluginName = "R2API.Buffs";

		private static bool _hooksEnabled;

		public static StackingDisplayMethod NoneStackingDisplayMethod;

		private static byte[][] _moddedBuffFlags = Array.Empty<byte[]>();

		private static CustomSimpleSpriteAnimation[] _buffDefSimpleSpriteAnimation = Array.Empty<CustomSimpleSpriteAnimation>();

		private static bool _init;

		public static int VanillaStackingDisplayMethodCount;

		private static readonly List<StackingDisplayMethod> CustomStackingDisplayMethods = new List<StackingDisplayMethod>();

		private static CustomStackingDisplayMethod[] _customStackingDisplayMethod = new CustomStackingDisplayMethod[0];

		private static Dictionary<BuffDef, byte[]> _pendingModdedBuffFlags = new Dictionary<BuffDef, byte[]>();

		private static Dictionary<BuffDef, CustomSimpleSpriteAnimation> _pendingSimpleSpriteAnimation = new Dictionary<BuffDef, CustomSimpleSpriteAnimation>();

		private static FixedConditionalWeakTable<BuffIcon, SimpleSpriteAnimator> _buffIconSimpleSpriteAnimator = new FixedConditionalWeakTable<BuffIcon, SimpleSpriteAnimator>();

		public const string PluginVersion = "1.0.0";

		public static int CustomStackingDisplayMethodCount => CustomStackingDisplayMethods.Count;

		public static int ModdedBuffFlagCount { get; private set; }

		internal static void SetHooks()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0087: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//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)
			if (!_hooksEnabled)
			{
				_hooksEnabled = true;
				VanillaStackingDisplayMethodCount = Enum.GetValues(typeof(StackingDisplayMethod)).Length;
				object obj = <>O.<0>__BuffIcon_UpdateIcon;
				if (obj == null)
				{
					Manipulator val = BuffIcon_UpdateIcon;
					<>O.<0>__BuffIcon_UpdateIcon = val;
					obj = (object)val;
				}
				BuffIcon.UpdateIcon += (Manipulator)obj;
				object obj2 = <>O.<1>__BuffIcon_OnEnable;
				if (obj2 == null)
				{
					hook_OnEnable val2 = BuffIcon_OnEnable;
					<>O.<1>__BuffIcon_OnEnable = val2;
					obj2 = (object)val2;
				}
				BuffIcon.OnEnable += (hook_OnEnable)obj2;
				object obj3 = <>O.<2>__BuffCatalog_SetBuffDefs;
				if (obj3 == null)
				{
					hook_SetBuffDefs val3 = BuffCatalog_SetBuffDefs;
					<>O.<2>__BuffCatalog_SetBuffDefs = val3;
					obj3 = (object)val3;
				}
				BuffCatalog.SetBuffDefs += (hook_SetBuffDefs)obj3;
				if ((int)NoneStackingDisplayMethod == 0)
				{
					NoneStackingDisplayMethod = RegisterStackingDisplayMethod(null);
				}
			}
		}

		internal static void UnsetHooks()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//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_0049: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			if (_hooksEnabled)
			{
				_hooksEnabled = false;
				object obj = <>O.<0>__BuffIcon_UpdateIcon;
				if (obj == null)
				{
					Manipulator val = BuffIcon_UpdateIcon;
					<>O.<0>__BuffIcon_UpdateIcon = val;
					obj = (object)val;
				}
				BuffIcon.UpdateIcon -= (Manipulator)obj;
				object obj2 = <>O.<1>__BuffIcon_OnEnable;
				if (obj2 == null)
				{
					hook_OnEnable val2 = BuffIcon_OnEnable;
					<>O.<1>__BuffIcon_OnEnable = val2;
					obj2 = (object)val2;
				}
				BuffIcon.OnEnable -= (hook_OnEnable)obj2;
				object obj3 = <>O.<2>__BuffCatalog_SetBuffDefs;
				if (obj3 == null)
				{
					hook_SetBuffDefs val3 = BuffCatalog_SetBuffDefs;
					<>O.<2>__BuffCatalog_SetBuffDefs = val3;
					obj3 = (object)val3;
				}
				BuffCatalog.SetBuffDefs -= (hook_SetBuffDefs)obj3;
			}
		}

		private static void BuffIcon_OnEnable(orig_OnEnable orig, BuffIcon self)
		{
			orig.Invoke(self);
			SimpleSpriteAnimator val = default(SimpleSpriteAnimator);
			if (_buffIconSimpleSpriteAnimator.TryGetValue(self, ref val) && ((Behaviour)val).enabled)
			{
				val.Tick();
			}
		}

		private static void BuffCatalog_SetBuffDefs(orig_SetBuffDefs orig, BuffDef[] newBuffDefs)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(newBuffDefs);
			if (_init)
			{
				return;
			}
			_moddedBuffFlags = new byte[BuffCatalog.buffCount][];
			_buffDefSimpleSpriteAnimation = new CustomSimpleSpriteAnimation[BuffCatalog.buffCount];
			foreach (KeyValuePair<BuffDef, byte[]> pendingModdedBuffFlag in _pendingModdedBuffFlags)
			{
				BuffDef key = pendingModdedBuffFlag.Key;
				if (Object.op_Implicit((Object)(object)key))
				{
					byte[] value = pendingModdedBuffFlag.Value;
					if (value != null && value.Length != 0)
					{
						_moddedBuffFlags[key.buffIndex] = value;
					}
				}
			}
			_pendingModdedBuffFlags.Clear();
			_pendingModdedBuffFlags = null;
			foreach (KeyValuePair<BuffDef, CustomSimpleSpriteAnimation> item in _pendingSimpleSpriteAnimation)
			{
				BuffDef key2 = item.Key;
				if (Object.op_Implicit((Object)(object)key2))
				{
					CustomSimpleSpriteAnimation value2 = item.Value;
					if (value2 != null)
					{
						_buffDefSimpleSpriteAnimation[key2.buffIndex] = value2;
					}
				}
			}
			_pendingSimpleSpriteAnimation.Clear();
			_pendingSimpleSpriteAnimation = null;
			_init = true;
		}

		private static void BuffIcon_UpdateIcon(ILContext il)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_00e7: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int num = default(int);
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffIcon>(x, "iconImage"),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, (MethodBase)Reflection.GetPropertySetter(typeof(Image), "sprite"))
			}))
			{
				BuffsPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!"));
			}
			else
			{
				Instruction next = val.Next.Next.Next.Next;
				Instruction next2 = val.Next;
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<BuffIcon, bool>>((Func<BuffIcon, bool>)CheckSimpleSpriteAnimation);
				val.Emit(OpCodes.Brfalse_S, next2);
				val.Emit(OpCodes.Ldarg_0);
				val.Emit(OpCodes.Ldfld, AccessTools.Field(typeof(BuffIcon), "iconImage"));
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<BuffIcon, Sprite>>((Func<BuffIcon, Sprite>)HandleSimpleSpriteAnimation);
				val.Emit(OpCodes.Br_S, next);
			}
			ILLabel iLLabel = null;
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffIcon>(x, "buffDef"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffDef>(x, "canStack"),
				(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel)
			}))
			{
				BuffsPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 2 failed!"));
			}
			else
			{
				val.Emit(OpCodes.Ldarg_0);
				val.Emit(OpCodes.Ldfld, AccessTools.Field(typeof(BuffIcon), "stackCount"));
				val.Emit(OpCodes.Ldfld, AccessTools.Field(typeof(BuffDef), "stackingDisplayMethod"));
				val.Emit(OpCodes.Ldsfld, AccessTools.Field(typeof(BuffsAPI), "NoneStackingDisplayMethod"));
				val.Emit(OpCodes.Beq_S, (object)iLLabel);
			}
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffIcon>(x, "stackCount"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, (MethodBase)Reflection.GetPropertySetter(typeof(Behaviour), "enabled"))
			}))
			{
				BuffsPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 3 failed!"));
				return;
			}
			Instruction next3 = val.Next;
			int stackingDisplayMethodLoc = 0;
			if (!val.TryGotoPrev((MoveType)2, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffIcon>(x, "buffDef"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<BuffDef>(x, "stackingDisplayMethod"),
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref stackingDisplayMethodLoc)
			}))
			{
				BuffsPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 4 failed!"));
				return;
			}
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldloc, stackingDisplayMethodLoc);
			val.EmitDelegate<Func<BuffIcon, StackingDisplayMethod, bool>>((Func<BuffIcon, StackingDisplayMethod, bool>)HandleCustomStackingDisplayMethods);
			val.Emit(OpCodes.Brtrue_S, next3);
		}

		public static StackingDisplayMethod RegisterStackingDisplayMethod(CustomStackingDisplayMethod customStackingDisplayMethod)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			int num = VanillaStackingDisplayMethodCount + CustomStackingDisplayMethodCount;
			int num2 = _customStackingDisplayMethod.Length;
			Array.Resize(ref _customStackingDisplayMethod, _customStackingDisplayMethod.Length + 1);
			_customStackingDisplayMethod[num2] = customStackingDisplayMethod;
			StackingDisplayMethod val = (StackingDisplayMethod)num;
			CustomStackingDisplayMethods.Add(val);
			return val;
		}

		public static void SetSimpleSpriteAnimation(this BuffDef buffDef, SimpleSpriteAnimation simpleSpriteAnimation)
		{
			SetHooks();
			SingleSimpleSpriteAnimationDisplayClass singleSimpleSpriteAnimationDisplayClass = new SingleSimpleSpriteAnimationDisplayClass();
			singleSimpleSpriteAnimationDisplayClass.simpleSpriteAnimation = simpleSpriteAnimation;
			buffDef.SetCustomSimpleSpriteAnimation(singleSimpleSpriteAnimationDisplayClass.SingleCustomSimpleSpriteAnimation);
		}

		public static void SetCustomSimpleSpriteAnimation(this BuffDef buffDef, CustomSimpleSpriteAnimation customSimpleSpriteAnimation)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			if (_init)
			{
				_buffDefSimpleSpriteAnimation[buffDef.buffIndex] = customSimpleSpriteAnimation;
			}
			else if (_pendingSimpleSpriteAnimation.ContainsKey(buffDef))
			{
				_pendingSimpleSpriteAnimation[buffDef] = customSimpleSpriteAnimation;
			}
			else
			{
				_pendingSimpleSpriteAnimation.Add(buffDef, customSimpleSpriteAnimation);
			}
		}

		public static CustomSimpleSpriteAnimation GetCustomSimpleSpriteAnimation(this BuffDef buffDef)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			if (_init)
			{
				return _buffDefSimpleSpriteAnimation[buffDef.buffIndex];
			}
			if (_pendingSimpleSpriteAnimation.TryGetValue(buffDef, out CustomSimpleSpriteAnimation value))
			{
				return value;
			}
			return null;
		}

		public static ModdedBuffFlag ReserveBuffFlag()
		{
			SetHooks();
			if (ModdedBuffFlagCount >= 1152)
			{
				throw new IndexOutOfRangeException($"Reached the limit of {1152} ModdedBuffFlags. Please contact R2API developers to increase the limit");
			}
			ModdedBuffFlagCount++;
			return (ModdedBuffFlag)ModdedBuffFlagCount;
		}

		public static void AddModdedBuffFlag(this BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			AddModdedBuffFlagInternal(buffDef, moddedBuffFlag);
		}

		public static bool RemoveModdedBuffFlag(this BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			return RemoveModdedBuffFlagInternal(buffDef, moddedBuffFlag);
		}

		public static bool HasAnyModdedBodyFlag(this BuffDef buffDef)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			byte[] array;
			if (_init)
			{
				array = _moddedBuffFlags[buffDef.buffIndex];
				if (array != null)
				{
					return array.Length != 0;
				}
				return false;
			}
			if (_pendingModdedBuffFlags.TryGetValue(buffDef, out array))
			{
				if (array != null)
				{
					return array.Length != 0;
				}
				return false;
			}
			return false;
		}

		public static bool HasModdedBuffFlag(this BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			return HasModdedBuffFlagInternal(buffDef, moddedBuffFlag);
		}

		private static void AddModdedBuffFlagInternal(BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			if (!CheckRange(moddedBuffFlag))
			{
				return;
			}
			byte[] array;
			if (_init)
			{
				array = _moddedBuffFlags[buffDef.buffIndex];
				if (array == null)
				{
					array = new byte[0];
				}
				CompressedFlagArrayUtilities.AddImmutable(ref array, (int)(moddedBuffFlag - 1));
				_moddedBuffFlags[buffDef.buffIndex] = array;
			}
			else if (_pendingModdedBuffFlags.TryGetValue(buffDef, out array))
			{
				CompressedFlagArrayUtilities.AddImmutable(ref array, (int)(moddedBuffFlag - 1));
				_pendingModdedBuffFlags[buffDef] = array;
			}
			else
			{
				array = new byte[0];
				CompressedFlagArrayUtilities.AddImmutable(ref array, (int)(moddedBuffFlag - 1));
				_pendingModdedBuffFlags.Add(buffDef, array);
			}
		}

		private static bool RemoveModdedBuffFlagInternal(BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			if (!CheckRange(moddedBuffFlag))
			{
				return false;
			}
			byte[] array;
			if (_init)
			{
				array = _moddedBuffFlags[buffDef.buffIndex];
				if (array == null)
				{
					return false;
				}
				bool result = CompressedFlagArrayUtilities.RemoveImmutable(ref array, (int)(moddedBuffFlag - 1));
				_moddedBuffFlags[buffDef.buffIndex] = array;
				return result;
			}
			if (_pendingModdedBuffFlags.TryGetValue(buffDef, out array))
			{
				bool result2 = CompressedFlagArrayUtilities.RemoveImmutable(ref array, (int)(moddedBuffFlag - 1));
				_pendingModdedBuffFlags[buffDef] = array;
				return result2;
			}
			return false;
		}

		private static bool HasModdedBuffFlagInternal(BuffDef buffDef, ModdedBuffFlag moddedBuffFlag)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			SetHooks();
			if (!CheckRange(moddedBuffFlag))
			{
				return false;
			}
			byte[] array;
			if (_init)
			{
				array = _moddedBuffFlags[buffDef.buffIndex];
				if (array == null)
				{
					return false;
				}
				return CompressedFlagArrayUtilities.Has(array, (int)(moddedBuffFlag - 1));
			}
			if (_pendingModdedBuffFlags.TryGetValue(buffDef, out array))
			{
				return CompressedFlagArrayUtilities.Has(array, (int)(moddedBuffFlag - 1));
			}
			return false;
		}

		private static bool CheckRange(ModdedBuffFlag moddedBuffFlag)
		{
			if ((int)moddedBuffFlag > ModdedBuffFlagCount || moddedBuffFlag < (ModdedBuffFlag)1)
			{
				BuffsPlugin.Logger.LogError((object)string.Format("Parameter '{0}' with value {1} is out of range of registered types (1-{2})\n{3}", "moddedBuffFlag", moddedBuffFlag, ModdedBuffFlagCount, new StackTrace(fNeedFileInfo: true)));
				return false;
			}
			return true;
		}

		private static void DisableSimpleSpriteAnimator(BuffIcon buffIcon)
		{
			SimpleSpriteAnimator val = default(SimpleSpriteAnimator);
			if (_buffIconSimpleSpriteAnimator.TryGetValue(buffIcon, ref val) && ((Behaviour)val).enabled)
			{
				((Behaviour)val).enabled = false;
			}
		}

		private static bool CheckSimpleSpriteAnimation(BuffIcon buffIcon)
		{
			if (Object.op_Implicit((Object)(object)buffIcon.buffDef.GetCustomSimpleSpriteAnimation()?.Invoke(buffIcon)))
			{
				return true;
			}
			DisableSimpleSpriteAnimator(buffIcon);
			return false;
		}

		private static Sprite HandleSimpleSpriteAnimation(BuffIcon buffIcon)
		{
			SimpleSpriteAnimation val = buffIcon.buffDef.GetCustomSimpleSpriteAnimation()?.Invoke(buffIcon);
			if (Object.op_Implicit((Object)(object)val))
			{
				SimpleSpriteAnimator val2 = default(SimpleSpriteAnimator);
				if (!_buffIconSimpleSpriteAnimator.TryGetValue(buffIcon, ref val2))
				{
					val2 = ((Component)buffIcon).gameObject.AddComponent<SimpleSpriteAnimator>();
					val2.target = buffIcon.iconImage;
					val2.animation = val;
					val2.Tick();
					_buffIconSimpleSpriteAnimator.Add(buffIcon, val2);
				}
				else
				{
					if ((Object)(object)val2.animation != (Object)(object)val)
					{
						val2.animation = val;
						val2.Tick();
					}
					if (!((Behaviour)val2).enabled)
					{
						((Behaviour)val2).enabled = true;
					}
				}
			}
			else
			{
				DisableSimpleSpriteAnimator(buffIcon);
			}
			return buffIcon.iconImage.sprite;
		}

		private static bool HandleCustomStackingDisplayMethods(BuffIcon buffIcon, StackingDisplayMethod stackingDisplayMethod)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if ((int)stackingDisplayMethod >= VanillaStackingDisplayMethodCount)
			{
				_customStackingDisplayMethod[stackingDisplayMethod - VanillaStackingDisplayMethodCount]?.Invoke(buffIcon);
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("com.bepis.r2api.buffs", "R2API.Buffs", "1.0.0")]
	public sealed class BuffsPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BuffsAPI.SetHooks();
		}

		private void OnDestroy()
		{
			BuffsAPI.UnsetHooks();
		}
	}
}
namespace R2API.AutoVersionGen
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	internal class AutoVersionAttribute : Attribute
	{
	}
}