Decompiled source of LinearDamage v1.0.1

LinearDamage.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 BepInEx;
using BepInEx.Configuration;
using IL.RoR2;
using LinearDamage.Tweaks;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API;
using R2API.Utils;
using RoR2;
using SneedHooks;
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("LinearDamage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LinearDamage")]
[assembly: AssemblyTitle("LinearDamage")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace LinearDamage
{
	[BepInPlugin("com.RiskyLives.LinearDamage", "LinearDamage", "1.0.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class LinearDamagePlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			AddToAssembly();
		}

		private void AddToAssembly()
		{
			IEnumerable<Type> enumerable = from type in Assembly.GetExecutingAssembly().GetTypes()
				where !type.IsAbstract && type.IsSubclassOf(typeof(TweakBase))
				select type;
			foreach (Type item in enumerable)
			{
				TweakBase tweakBase = (TweakBase)Activator.CreateInstance(item);
				tweakBase.Init(((BaseUnityPlugin)this).Config);
			}
		}
	}
}
namespace LinearDamage.Tweaks
{
	public abstract class TweakBase<T> : TweakBase where T : TweakBase<T>
	{
		public static T Instance { get; private set; }

		public TweakBase()
		{
			if (Instance != null)
			{
				throw new InvalidOperationException("Singleton class \"" + typeof(T).Name + "\" inheriting TweakBase was instantiated twice");
			}
			Instance = this as T;
		}
	}
	public abstract class TweakBase
	{
		public abstract string ConfigCategoryString { get; }

		public abstract string ConfigOptionName { get; }

		public abstract string ConfigDescriptionString { get; }

		public ConfigEntry<bool> Enabled { get; private set; }

		protected virtual void ReadConfig(ConfigFile config)
		{
			Enabled = config.Bind<bool>(ConfigCategoryString, ConfigOptionName, true, ConfigDescriptionString);
		}

		internal void Init(ConfigFile config)
		{
			ReadConfig(config);
			if (Enabled.Value)
			{
				ApplyChanges();
			}
		}

		public virtual void ApplyChanges()
		{
		}

		public virtual void RemoveChanges()
		{
		}
	}
}
namespace LinearDamage.Tweaks.Items
{
	public class APRounds : TweakBase<APRounds>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "AP Rounds";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess += new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Combine((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess -= new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Remove((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		private void ModifyFinalDamage(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody, CharacterBody attackerBody)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			if (!victimBody.isBoss || !Object.op_Implicit((Object)(object)attackerBody.inventory) || (Object)(object)attackerBody == (Object)(object)victimBody)
			{
				return;
			}
			int itemCount = attackerBody.inventory.GetItemCount(Items.BossDamageBonus);
			if (itemCount > 0)
			{
				damageModifierArgs.damageMultAdd += 0.2f * (float)itemCount;
				if ((int)damageInfo.damageColorIndex == 0)
				{
					damageInfo.damageColorIndex = (DamageColorIndex)5;
				}
				EffectManager.SimpleImpactEffect(AssetReferences.bossDamageBonusImpactEffectPrefab, damageInfo.position, damageInfo.force, true);
			}
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "BossDamageBonus"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Inventory>(x, "GetItemCount")
			}))
			{
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int i) => 0));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: APRounds RemoveVanilla IL hook failed.");
			}
		}
	}
	public class ChronicExpansion : TweakBase<ChronicExpansion>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "Chronic Expansion";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CharacterBody.RecalculateStats += new Manipulator(RemoveVanilla);
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
		}

		private void RecalculateStatsAPI_GetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			int buffCount = sender.GetBuffCount(Buffs.IncreaseDamageBuff);
			if (buffCount > 0)
			{
				int num = 0;
				if (Object.op_Implicit((Object)(object)sender.inventory))
				{
					num = sender.inventory.GetItemCount(Items.IncreaseDamageOnMultiKill);
				}
				float num2 = ((num > 1) ? (0.01f * (float)(num - 1)) : 0f);
				args.damageMultAdd += (float)buffCount * (0.035f + num2);
			}
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CharacterBody.RecalculateStats -= new Manipulator(RemoveVanilla);
			RecalculateStatsAPI.GetStatCoefficients -= new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "IncreaseDamageBuff"),
				(Instruction x) => ILPatternMatchingExt.MatchCall<CharacterBody>(x, "GetBuffCount")
			}))
			{
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int i) => 0));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: ChronicExpansion RemoveVanilla IL hook failed.");
			}
		}
	}
	public class DeathMark : TweakBase<DeathMark>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "Death Mark";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess += new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageActions = (ModifyFinalDamageDelegate)Delegate.Combine((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageActions, (Delegate?)new ModifyFinalDamageDelegate(ModifyFinalDamage));
		}

		private void ModifyFinalDamage(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (victimBody.HasBuff(Buffs.DeathMark))
			{
				damageModifierArgs.damageMultAdd += 0.5f;
				damageInfo.damageColorIndex = (DamageColorIndex)7;
			}
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess -= new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageActions = (ModifyFinalDamageDelegate)Delegate.Remove((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageActions, (Delegate?)new ModifyFinalDamageDelegate(ModifyFinalDamage));
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "DeathMark"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "HasBuff")
			}))
			{
				val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool i) => false));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: DeathMark  RemoveVanilla IL hook failed.");
			}
		}
	}
	public class DelicateWatch : TweakBase<DelicateWatch>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "Delicate Watch";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess += new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Combine((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess -= new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Remove((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		private void ModifyFinalDamage(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody, CharacterBody attackerBody)
		{
			if (Object.op_Implicit((Object)(object)attackerBody.inventory))
			{
				int itemCount = attackerBody.inventory.GetItemCount(Items.FragileDamageBonus);
				if (itemCount > 0)
				{
					damageModifierArgs.damageMultAdd += 0.2f * (float)itemCount;
				}
			}
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "FragileDamageBonus"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Inventory>(x, "GetItemCount")
			}))
			{
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int i) => 0));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: DelicateWatch RemoveVanilla IL hook failed.");
			}
		}
	}
	public class FocusCrystal : TweakBase<FocusCrystal>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "Focus Crystal";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess += new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Combine((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess -= new Manipulator(RemoveVanilla);
			ModifyFinalDamage.ModifyFinalDamageAttackerActions = (ModifyFinalDamageAttackerDelegate)Delegate.Remove((Delegate?)(object)ModifyFinalDamage.ModifyFinalDamageAttackerActions, (Delegate?)new ModifyFinalDamageAttackerDelegate(ModifyFinalDamage));
		}

		private void ModifyFinalDamage(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody, CharacterBody attackerBody)
		{
			//IL_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)attackerBody.inventory) && !((Object)(object)attackerBody == (Object)(object)victimBody))
			{
				int itemCount = attackerBody.inventory.GetItemCount(Items.NearbyDamageBonus);
				Vector3 val = attackerBody.corePosition - damageInfo.position;
				if (itemCount > 0 && ((Vector3)(ref val)).sqrMagnitude < 169f)
				{
					damageModifierArgs.damageMultAdd += 0.2f * (float)itemCount;
					damageInfo.damageColorIndex = (DamageColorIndex)10;
					EffectManager.SimpleImpactEffect(AssetReferences.diamondDamageBonusImpactEffectPrefab, damageInfo.position, val, true);
				}
			}
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "NearbyDamageBonus"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Inventory>(x, "GetItemCount")
			}))
			{
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int i) => 0));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: FocusCrystal RemoveVanilla IL hook failed.");
			}
		}
	}
	public class Rachis : TweakBase<Rachis>
	{
		public override string ConfigCategoryString => "Items";

		public override string ConfigOptionName => "Mercurial Rachis";

		public override string ConfigDescriptionString => "Enable Changes";

		public override void ApplyChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CharacterBody.RecalculateStats += new Manipulator(RemoveVanilla);
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
		}

		private void RecalculateStatsAPI_GetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			if (sender.HasBuff(Buffs.PowerBuff))
			{
				args.damageMultAdd += 0.5f;
			}
		}

		public override void RemoveChanges()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			CharacterBody.RecalculateStats -= new Manipulator(RemoveVanilla);
			RecalculateStatsAPI.GetStatCoefficients -= new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
		}

		private void RemoveVanilla(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((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "PowerBuff"),
				(Instruction x) => ILPatternMatchingExt.MatchCall<CharacterBody>(x, "HasBuff")
			}))
			{
				val.EmitDelegate<Func<int, int>>((Func<int, int>)((int i) => 0));
			}
			else
			{
				Debug.LogError((object)"LinearDamage: Rachis RemoveVanilla IL hook failed.");
			}
		}
	}
}