Decompiled source of BetterBlight v1.0.5

BetterBlight.dll

Decompiled 3 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]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 BetterBlight
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.tetrapink.BetterBlight", "BetterBlight", "1.0.5")]
	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 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>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1048576)
				}))
				{
				}
			}

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

		public const string PluginGUID = "com.tetrapink.BetterBlight";

		public const string PluginAuthor = "tetrapink";

		public const string PluginName = "BetterBlight";

		public const string PluginVersion = "1.0.5";

		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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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);
			LanguageAPI.Add("CROCO_PASSIVE_ALT_DESCRIPTION", CreateBlightDescription());
			DotController.AddDot_GameObject_float_DotIndex_float_Nullable1_Nullable1_Nullable1 += new hook_AddDot_GameObject_float_DotIndex_float_Nullable1_Nullable1_Nullable1(RefreshBlightDurationOnStack);
			DotController.AddDot_GameObject_float_HurtBox_DotIndex_float_Nullable1_Nullable1_Nullable1 += new hook_AddDot_GameObject_float_HurtBox_DotIndex_float_Nullable1_Nullable1_Nullable1(DotController_AddDot_GameObject_float_HurtBox_DotIndex_float_Nullable1_Nullable1_Nullable1);
			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 val3 = new ILCursor(il);
					if (val3.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)
					}))
					{
						val3.Index += 2;
						val3.Next.Operand = 1f / BlightTicksPerSecond.Value;
						val3.Index += 3;
						val3.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>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1048576)
					}))
					{
					}
				};
				<>c.<>9__44_1 = val2;
				obj2 = (object)val2;
			}
			GlobalEventManager.ProcessHitEnemy += (Manipulator)obj2;
		}

		private void DotController_AddDot_GameObject_float_HurtBox_DotIndex_float_Nullable1_Nullable1_Nullable1(orig_AddDot_GameObject_float_HurtBox_DotIndex_float_Nullable1_Nullable1_Nullable1 orig, DotController self, GameObject attackerObject, float duration, HurtBox hitHurtBox, DotIndex dotIndex, float damageMultiplier, uint? maxStacksFromAttacker, float? totalDamage, DotIndex? preUpgradeDotIndex)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			float num = duration;
			if (!ResetDurationOnStack.Value && (int)dotIndex == 5)
			{
				num *= BlightDuration.Value / 5f;
			}
			orig.Invoke(self, attackerObject, num, hitHurtBox, dotIndex, damageMultiplier, maxStacksFromAttacker, totalDamage, preUpgradeDotIndex);
			if (!ResetDurationOnStack.Value || (int)dotIndex != 5)
			{
				return;
			}
			foreach (DotStack dotStack in self.dotStackList)
			{
				if (dotStack.dotIndex == dotIndex)
				{
					dotStack.timer = BlightDuration.Value;
				}
			}
		}

		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_GameObject_float_DotIndex_float_Nullable1_Nullable1_Nullable1 orig, DotController self, GameObject attackerObject, float duration, DotIndex dotIndex, float damageMultiplier, uint? maxStacksFromAttacker, float? totalDamage, DotIndex? preUpgradeDotIndex)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//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)
			float num = duration;
			if (!ResetDurationOnStack.Value && (int)dotIndex == 5)
			{
				num *= BlightDuration.Value / 5f;
			}
			orig.Invoke(self, attackerObject, num, dotIndex, damageMultiplier, maxStacksFromAttacker, totalDamage, preUpgradeDotIndex);
			if (!ResetDurationOnStack.Value || (int)dotIndex != 5)
			{
				return;
			}
			foreach (DotStack dotStack in self.dotStackList)
			{
				if (dotStack.dotIndex == dotIndex)
				{
					dotStack.timer = BlightDuration.Value;
				}
			}
		}

		public static string CreateBlightDescription()
		{
			string text = "";
			string text2 = "";
			string format = "Attacks that apply <style=cIsHealing>Poison</style> apply stacking <style=cIsDamage>Blight</style> instead{0}. ";
			string text3 = $", dealing <style=cIsDamage>{Mathf.Round(BlightDamagePerTick.Value * BlightTicksPerSecond.Value)}% damage per second</style>";
			string arg = ". Does nothing";
			string text4 = "Enemies afflicted with <style=cIsDamage>Blight</style> have their ";
			string text5 = $"armor reduced by <style=cIsUtility>{ArmorReduction.Value}</style>";
			string text6 = $"speed reduced by <style=cIsUtility>{SpeedReduction.Value}%</style>";
			string text7 = $"damage reduced by <style=cIsDamage>{DmgReduction.Value}%</style>";
			bool flag = BlightDamagePerTick.Value != 0f && BlightTicksPerSecond.Value != 0f;
			bool flag2 = ArmorReduction.Value != 0;
			bool flag3 = SpeedReduction.Value != 0f;
			bool flag4 = DmgReduction.Value != 0f;
			bool flag5 = flag2 || flag3 || flag4;
			if (BlightDuration.Value == 0f || (!flag && !flag5))
			{
				return string.Format(format, arg);
			}
			text += string.Format(format, flag ? text3 : "");
			if (flag5)
			{
				text2 = text4;
				if (flag2)
				{
					text2 = text2 + text5 + (((flag3 && !flag4) || (!flag3 && flag4)) ? ", and " : ((flag3 && flag4) ? ", " : "."));
				}
				if (flag3)
				{
					text2 = text2 + text6 + (flag4 ? ", and " : ".");
				}
				if (flag4)
				{
					text2 = text2 + text7 + ".";
				}
			}
			return text + text2;
		}
	}
	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);
		}
	}
}