Decompiled source of CursedEcho v0.3.1

CursedEcho.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.1.0")]
[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 Prototype
{
	[BepInPlugin("prototype.cursed.echo", "CursedEcho", "0.3.1")]
	[BepInIncompatibility("Early.Wolfo.WolfFixes")]
	internal class CursedEcho : BaseUnityPlugin
	{
		public const string version = "0.3.1";

		public const string identifier = "prototype.cursed.echo";

		public void Awake()
		{
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
		}

		[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
		[HarmonyILManipulator]
		public static void Manipulate(ILContext context)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			MethodInfo delay = typeof(CharacterBody).GetMethod("SecondHalfOfDelayedDamage");
			FieldInfo damage = typeof(DamageInfo).GetField("damage");
			FieldInfo curse = typeof(Buffs).GetField("PermanentCurse");
			FieldInfo echo = typeof(DamageInfo).GetField("delayedDamageSecondHalf");
			ILCursor val = new ILCursor(context);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCallvirt(i, (MethodBase)delay)
			});
			val.GotoPrev(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchStfld(i, damage)
			});
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldarg_1);
			val.Emit(OpCodes.Call, (MethodBase)typeof(CursedEcho).GetMethod("Hook"));
			val.Index = 0;
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdsfld(i, curse)
			});
			val.GotoPrev((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, echo)
			});
			val.Emit(OpCodes.Pop);
			val.Emit(OpCodes.Ldc_I4_0);
		}

		public static float Hook(float damage, HealthComponent component, DamageInfo info)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody body = component.body;
			body.outOfDangerStopwatch = 0f;
			if (!((Enum)info.damageType.damageType).HasFlag((Enum)(object)(DamageType)2))
			{
				float armor = body.armor;
				damage *= 1f - armor / (100f + Mathf.Abs(armor));
			}
			if (!((Enum)info.damageType.damageType).HasFlag((Enum)(object)(DamageType)262144) && body.hasOneShotProtection)
			{
				int num = 2 + body.inventory.GetItemCount(Items.DelayedDamage);
				float fullCombinedHealth = component.fullCombinedHealth;
				float barrier = component.barrier;
				float num2 = 0.9f;
				fullCombinedHealth *= body.cursePenalty;
				if (barrier > 0f)
				{
					fullCombinedHealth += barrier;
					barrier /= fullCombinedHealth * num2;
					fullCombinedHealth -= Mathf.Floor(barrier * (float)num) * 0.75f * body.barrierDecayRate;
				}
				num2 *= fullCombinedHealth / (float)num;
				damage = Mathf.Min(num2, damage);
			}
			return Mathf.Max(damage, 1f);
		}
	}
}