Decompiled source of BetterBlight v1.0.2

plugins/BetterBlight.dll

Decompiled 2 weeks 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 IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterBlight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterBlight")]
[assembly: AssemblyTitle("BetterBlight")]
[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 BetterBlight
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("pinky1emonade.BetterBlight", "BetterBlight", "1.0.0")]
	public class BetterBlight : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__44_2;

			public static Func<Instruction, bool> <>9__44_3;

			public static Func<Instruction, bool> <>9__44_4;

			public static Func<Instruction, bool> <>9__44_5;

			public static Func<Instruction, bool> <>9__44_6;

			public static Func<Instruction, bool> <>9__44_7;

			public static Func<Instruction, bool> <>9__44_8;

			public static Func<Instruction, bool> <>9__44_9;

			public static Func<Instruction, bool> <>9__44_10;

			public static Manipulator <>9__44_0;

			public static Func<Instruction, bool> <>9__44_11;

			public static Func<Instruction, bool> <>9__44_12;

			public static Func<Instruction, bool> <>9__44_13;

			public static Func<Instruction, bool> <>9__44_14;

			public static Func<Instruction, bool> <>9__44_15;

			public static Func<Instruction, bool> <>9__44_16;

			public static Func<Instruction, bool> <>9__44_17;

			public static Func<Instruction, bool> <>9__44_18;

			public static Func<Instruction, bool> <>9__44_19;

			public static Manipulator <>9__44_1;

			internal void <Awake>b__44_0(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				if (val.TryGotoNext(new Func<Instruction, bool>[9]
				{
					(Instruction x) => ILPatternMatchingExt.MatchNewobj(x, "RoR2.DotController/DotDef"),
					(Instruction x) => ILPatternMatchingExt.MatchDup(x),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.333f),
					(Instruction x) => ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "interval"),
					(Instruction x) => ILPatternMatchingExt.MatchDup(x),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.2f),
					(Instruction x) => ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "damageCoefficient"),
					(Instruction x) => ILPatternMatchingExt.MatchDup(x),
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 4)
				}))
				{
					val.Index += 2;
					val.Next.Operand = 1f / BlightTicksPerSecond.Value;
					val.Index += 3;
					val.Next.Operand = BlightDamagePerTick.Value / 100f;
				}
				else
				{
					Log.Error(((MemberReference)il.Method).Name + " DotController ilhook failed");
				}
			}

			internal bool <Awake>b__44_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchNewobj(x, "RoR2.DotController/DotDef");
			}

			internal bool <Awake>b__44_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchDup(x);
			}

			internal bool <Awake>b__44_4(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcR4(x, 0.333f);
			}

			internal bool <Awake>b__44_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "interval");
			}

			internal bool <Awake>b__44_6(Instruction x)
			{
				return ILPatternMatchingExt.MatchDup(x);
			}

			internal bool <Awake>b__44_7(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcR4(x, 0.2f);
			}

			internal bool <Awake>b__44_8(Instruction x)
			{
				return ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "damageCoefficient");
			}

			internal bool <Awake>b__44_9(Instruction x)
			{
				return ILPatternMatchingExt.MatchDup(x);
			}

			internal bool <Awake>b__44_10(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcI4(x, 4);
			}

			internal void <Awake>b__44_1(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				ILCursor val = new ILCursor(il);
				if (val.TryGotoNext(new Func<Instruction, bool>[9]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "procChainMask"),
					(Instruction x) => ILPatternMatchingExt.MatchPop(x),
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 2),
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "attacker"),
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 5),
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 5f),
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1)
				}))
				{
					val.Index += 7;
					val.Next.Operand = BlightDuration.Value;
				}
				else
				{
					Log.Error(((MemberReference)il.Method).Name + " ProcessHitEnemy ilhook failed");
				}
			}

			internal bool <Awake>b__44_11(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 1);
			}

			internal bool <Awake>b__44_12(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "procChainMask");
			}

			internal bool <Awake>b__44_13(Instruction x)
			{
				return ILPatternMatchingExt.MatchPop(x);
			}

			internal bool <Awake>b__44_14(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 2);
			}

			internal bool <Awake>b__44_15(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 1);
			}

			internal bool <Awake>b__44_16(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "attacker");
			}

			internal bool <Awake>b__44_17(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcI4(x, 5);
			}

			internal bool <Awake>b__44_18(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdcR4(x, 5f);
			}

			internal bool <Awake>b__44_19(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 1);
			}
		}

		public const string PluginGUID = "pinky1emonade.BetterBlight";

		public const string PluginAuthor = "pinky1emonade";

		public const string PluginName = "BetterBlight";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<float> SpeedReduction { get; set; }

		public static ConfigEntry<float> DmgReduction { get; set; }

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

		public static ConfigEntry<bool> UseSoftScaling { get; set; }

		public static ConfigEntry<float> DmgScalingParam { get; set; }

		public static ConfigEntry<float> SpeedScalingParam { get; set; }

		public static ConfigEntry<float> BlightDuration { get; set; }

		public static ConfigEntry<float> BlightDamagePerTick { get; set; }

		public static ConfigEntry<float> BlightTicksPerSecond { get; set; }

		public static ConfigEntry<bool> ResetDurationOnStack { get; set; }

		public void Awake()
		{
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			SpeedReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Speed Reduction Percent", 10f, "Reduces an enemy's Speed stat by this percent for every stack of Blight they have.");
			DmgReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Damage Reduction Percent", 5f, "Reduces an enemy's Damage stat by this percent for every stack of Blight they have.");
			ArmorReduction = ((BaseUnityPlugin)this).Config.Bind<int>("Stats", "Armor Reduction", 10, "Reduces an enemy's Armor by this value for every stack of Blight they have.");
			UseSoftScaling = ((BaseUnityPlugin)this).Config.Bind<bool>("Stats", "Use Diminishing Returns", true, "Gives diminishing returns to Blight's Speed and Damage reduction. Enabled by default.");
			DmgScalingParam = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Damage - Diminishing Returns", 0.75f, "Raises the number of Blight stacks to this power when calculating damage reduction. Only used when 'Use Diminishing Returns' is enabled.");
			SpeedScalingParam = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Speed - Diminishing Returns", 0.75f, "Raises the number of Blight stacks to this power when calculating speed reduction. Only used when 'Use Diminishing Returns' is enabled.");
			BlightDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Blight Duration", 6f, "How long the Blight stack lasts.");
			BlightDamagePerTick = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Blight Damage Per Tick", 16f, "How much damage each tick of Blight deals, as a percent of Acrid's base damage.");
			BlightTicksPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Blight Ticks Per Second", 3f, "How many times Blight ticks each second.");
			ResetDurationOnStack = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Reset Duration On Stack", true, "Resets Blight duration upon stack. Enabled by default.");
			Log.Init(((BaseUnityPlugin)this).Logger);
			if (ResetDurationOnStack.Value)
			{
				DotController.AddDot += new hook_AddDot(RefreshBlightDurationOnStack);
			}
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(BlightDebuffStatModifier);
			object obj = <>c.<>9__44_0;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val4 = new ILCursor(il);
					if (val4.TryGotoNext(new Func<Instruction, bool>[9]
					{
						(Instruction x) => ILPatternMatchingExt.MatchNewobj(x, "RoR2.DotController/DotDef"),
						(Instruction x) => ILPatternMatchingExt.MatchDup(x),
						(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.333f),
						(Instruction x) => ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "interval"),
						(Instruction x) => ILPatternMatchingExt.MatchDup(x),
						(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.2f),
						(Instruction x) => ILPatternMatchingExt.MatchStfld(x, "RoR2.DotController/DotDef", "damageCoefficient"),
						(Instruction x) => ILPatternMatchingExt.MatchDup(x),
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 4)
					}))
					{
						val4.Index += 2;
						val4.Next.Operand = 1f / BlightTicksPerSecond.Value;
						val4.Index += 3;
						val4.Next.Operand = BlightDamagePerTick.Value / 100f;
					}
					else
					{
						Log.Error(((MemberReference)il.Method).Name + " DotController ilhook failed");
					}
				};
				<>c.<>9__44_0 = val;
				obj = (object)val;
			}
			DotController.InitDotCatalog += (Manipulator)obj;
			object obj2 = <>c.<>9__44_1;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val3 = new ILCursor(il);
					if (val3.TryGotoNext(new Func<Instruction, bool>[9]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
						(Instruction x) => ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "procChainMask"),
						(Instruction x) => ILPatternMatchingExt.MatchPop(x),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 2),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
						(Instruction x) => ILPatternMatchingExt.MatchLdfld<DamageInfo>(x, "attacker"),
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 5),
						(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 5f),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1)
					}))
					{
						val3.Index += 7;
						val3.Next.Operand = BlightDuration.Value;
					}
					else
					{
						Log.Error(((MemberReference)il.Method).Name + " ProcessHitEnemy ilhook failed");
					}
				};
				<>c.<>9__44_1 = val2;
				obj2 = (object)val2;
			}
			GlobalEventManager.ProcessHitEnemy += (Manipulator)obj2;
		}

		private void BlightDebuffStatModifier(CharacterBody victim, StatHookEventArgs stats)
		{
			int buffCount = victim.GetBuffCount(Buffs.Blight);
			if (buffCount > 0)
			{
				stats.armorAdd -= (float)(buffCount * ArmorReduction.Value);
				stats.damageTotalMult *= Mathf.Pow(1f - DmgReduction.Value / 100f, Mathf.Pow((float)buffCount, UseSoftScaling.Value ? DmgScalingParam.Value : 1f));
				stats.moveSpeedTotalMult *= Mathf.Pow(1f - SpeedReduction.Value / 100f, Mathf.Pow((float)buffCount, UseSoftScaling.Value ? SpeedScalingParam.Value : 1f));
			}
		}

		private void RefreshBlightDurationOnStack(orig_AddDot orig, DotController self, GameObject attackerObject, float duration, DotIndex dotIndex, float damageMultiplier, uint? maxStacksFromAttacker, float? totalDamage, DotIndex? preUpgradeDotIndex)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//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)
			orig.Invoke(self, attackerObject, duration, dotIndex, damageMultiplier, maxStacksFromAttacker, totalDamage, preUpgradeDotIndex);
			if ((int)dotIndex != 5)
			{
				return;
			}
			for (int i = 0; i < self.dotStackList.Count; i++)
			{
				if (self.dotStackList[i].dotIndex == dotIndex)
				{
					self.dotStackList[i].timer = BlightDuration.Value;
				}
			}
		}
	}
	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);
		}
	}
}