Decompiled source of WarpedEchoBugFixes v1.0.0

WarpedEchoBugFixes.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.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;
using WolfoFixes;

[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: 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 RiskOfResources
{
	[BepInPlugin("com.riskofresources.fix.echo", "WarpedEchoBugFixes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class WarpedEchoBugFixes : BaseUnityPlugin
	{
		public const string version = "1.0.0";

		public const string identifier = "com.riskofresources.fix.echo";

		protected void Awake()
		{
			Compatibility.Check();
			Harmony.CreateAndPatchAll(typeof(WarpedEchoBugFixes), (string)null);
		}

		[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
		[HarmonyILManipulator]
		private static void JustFuckingKillMeAlready(ILContext context)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0642: Unknown result type (might be due to invalid IL or missing references)
			//IL_068b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_074b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_079f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b0: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(context);
			VariableDefinition val2 = new VariableDefinition(context.Import(typeof(bool)));
			context.Method.Body.Variables.Add(val2);
			val.Emit(OpCodes.Ldc_I4_0);
			val.Emit(OpCodes.Stloc, val2);
			ILLabel start = null;
			ILLabel val3 = val.DefineLabel();
			int input = 0;
			int output = 0;
			Type type = typeof(HealthComponent);
			FieldInfo protection = type.GetField("ospTimer", AccessTools.all);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, protection)
			});
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchBleUn(i, ref start)
			});
			type = typeof(DamageInfo);
			FieldInfo rejected = type.GetField("rejected");
			ILLabel val6 = default(ILLabel);
			val.GotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, rejected),
				(Instruction i) => ILPatternMatchingExt.MatchBrfalse(i, ref val6),
				(Instruction i) => i.MatchRet()
			});
			FieldInfo damage2 = type.GetField("damage");
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchStfld(i, damage2)
			});
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, damage2)
			});
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchStloc(i, ref output)
			});
			val.GotoLabel(start, (MoveType)1, false);
			val.Emit(OpCodes.Ldarg_1);
			val.Emit(OpCodes.Ldfld, damage2);
			val.Emit(OpCodes.Stloc, output);
			FieldInfo echo = type.GetField("delayedDamageSecondHalf");
			val.Emit(OpCodes.Ldarg_1);
			val.Emit(OpCodes.Ldfld, echo);
			val.Emit(OpCodes.Brtrue, (object)val3);
			type = typeof(Buffs);
			FieldInfo curse = type.GetField("PermanentCurse");
			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);
			val.GotoPrev(new Func<Instruction, bool>[2]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdloc(i, output),
				(Instruction i) => ILPatternMatchingExt.MatchStloc(i, ref input)
			});
			ILLabel val4 = val.DefineLabel();
			ILLabel skip = null;
			val.MarkLabel(val3);
			int index = val.Index + 1;
			val.Index = index;
			index = val.Index + 1;
			val.Index = index;
			val.Emit(OpCodes.Ldloc, val2);
			val.Emit(OpCodes.Brtrue, (object)val4);
			type = typeof(Buffs);
			FieldInfo buff = type.GetField("DelayedDamageBuff");
			type = typeof(CharacterBody);
			val.GotoPrev((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdsfld(i, buff),
				(Instruction i) => ILPatternMatchingExt.MatchCallvirt(i, type, "HasBuff"),
				(Instruction i) => ILPatternMatchingExt.MatchBrfalse(i, ref skip)
			});
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldarg_1);
			val.Emit(OpCodes.Ldloc, output);
			val.EmitDelegate<Func<HealthComponent, DamageInfo, float, float>>((Func<HealthComponent, DamageInfo, float, float>)deflect);
			val.Emit(OpCodes.Stloc, output);
			val.Emit(OpCodes.Ldc_I4_1);
			val.Emit(OpCodes.Stloc, val2);
			val.Emit(OpCodes.Br, (object)skip);
			val.MarkLabel(val4);
			val.Emit(OpCodes.Ldc_I4_0);
			val.Emit(OpCodes.Stloc, val2);
			FieldInfo field = type.GetField("outOfDangerStopwatch", AccessTools.all);
			type = typeof(HealthComponent);
			FieldInfo field2 = type.GetField("body");
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, field2);
			val.Emit(OpCodes.Ldc_R4, 0f);
			val.Emit(OpCodes.Stfld, field);
			type = typeof(CharacterBody);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCallvirt(i, type, "SecondHalfOfDelayedDamage")
			});
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<HealthComponent, float>>((Func<HealthComponent, float>)delay);
			val.Emit(OpCodes.Add);
			val.GotoLabel(skip, (MoveType)0, false);
			val.Emit(OpCodes.Br, (object)val3);
			MethodInfo limit2 = type.GetProperty("oneShotProtectionFraction").GetMethod;
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCallvirt(i, (MethodBase)limit2)
			});
			int num10 = default(int);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchStloc(i, ref num10)
			});
			val.Emit(OpCodes.Add);
			MethodInfo getMethod = type.GetProperty("cursePenalty").GetMethod;
			type = typeof(HealthComponent);
			FieldInfo barrier = type.GetField("barrier");
			val.GotoPrev(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, barrier)
			});
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchAdd(i)
			});
			val.Emit(OpCodes.Ldc_R4, 0f);
			MethodInfo health = type.GetProperty("fullCombinedHealth").GetMethod;
			val.GotoPrev((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchCall(i, (MethodBase)health)
			});
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, field2);
			val.Emit(OpCodes.Call, (MethodBase)getMethod);
			val.Emit(OpCodes.Mul);
			val.Emit(OpCodes.Ldc_R4, 0.9f);
			val.Emit(OpCodes.Mul);
			FieldInfo previous = type.GetField("serverDamageTakenThisUpdate", AccessTools.all);
			ILLabel val5 = val.DefineLabel();
			val.GotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, previous),
				(Instruction i) => ILPatternMatchingExt.MatchSub(i)
			});
			val.Emit(OpCodes.Ldloc, val2);
			val.Emit(OpCodes.Brfalse, (object)val5);
			val.Emit(OpCodes.Dup);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<float, HealthComponent, float>>((Func<float, HealthComponent, float>)decay);
			val.Emit(OpCodes.Sub);
			val.Emit(OpCodes.Ldc_R4, 0.8f);
			val.Emit(OpCodes.Div);
			val.MarkLabel(val5);
			static float decay(float limit, HealthComponent instance)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Invalid comparison between Unknown and I4
				float barrier2 = instance.barrier;
				float num = 0f;
				CharacterBody body = instance.body;
				if (barrier2 <= 0f)
				{
					return 0f;
				}
				if ((int)Run.instance.selectedDifficulty >= 10)
				{
					num = 1f - Mathf.Pow(1.4f, -1f);
				}
				int num2 = 2 + body.inventory.GetItemCount(Items.DelayedDamage);
				float num3 = 0.75f * body.barrierDecayRate;
				float num4 = num2;
				float num5 = -1f;
				float num6 = (barrier2 - limit) * num3;
				num5 *= limit - num * barrier2 - (float)num2 * num3;
				float num7 = 0f - num5 + Mathf.Sqrt(num5 * num5 - 4f * num4 * num6);
				num7 /= 2f * num4;
				num2 = Mathf.FloorToInt(barrier2 / num7);
				barrier2 -= (float)num2 * num7;
				limit = 1f + Mathf.Max(num * num7 + barrier2 - num7, 0f);
				num *= body.cursePenalty * (float)num2 * num7;
				return ((float)num2 + 0.1f) * num3 + num + limit;
			}
			static float deflect(HealthComponent instance, DamageInfo info, float damage)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				int num8 = instance.body.inventory.GetItemCount(Items.DelayedDamage);
				if (num8 > 0)
				{
					num8++;
				}
				if (((Enum)info.damageType.damageType).HasFlag((Enum)(object)(DamageType)2))
				{
					num8 = 0;
				}
				else if (damage < (float)num8)
				{
					num8 = Mathf.FloorToInt(damage);
				}
				float num9 = instance.itemCounts.armorPlate * 5;
				damage -= (float)num8 * num9;
				return Mathf.Max(damage, (float)num8 / 0.8f);
			}
			static float delay(HealthComponent instance)
			{
				float ospTimer = instance.ospTimer;
				if (!(ospTimer > 0f))
				{
					return 0f;
				}
				return Time.fixedDeltaTime * 2f + ospTimer;
			}
		}
	}
	internal static class Extension
	{
		internal static bool MatchRet(this Instruction i)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (i.OpCode == OpCodes.Br)
			{
				object operand = i.Operand;
				ILLabel val = (ILLabel)((operand is ILLabel) ? operand : null);
				if (val == null)
				{
					Instruction val2 = (Instruction)((operand is Instruction) ? operand : null);
					if (val2 != null)
					{
						i = val2;
					}
				}
				else
				{
					i = val.Target;
				}
			}
			return i.OpCode == OpCodes.Ret;
		}
	}
	internal static class Compatibility
	{
		internal const string identifier = "Early.Wolfo.WolfFixes";

		internal static void Check()
		{
			if (Chainloader.PluginInfos.ContainsKey("Early.Wolfo.WolfFixes"))
			{
				Harmony.CreateAndPatchAll(typeof(Compatibility), (string)null);
			}
		}

		[HarmonyPatch(typeof(ItemFixes), "FixWarpedEchoE8")]
		[HarmonyPatch(typeof(ItemFixes), "FixWarpedEchoNotUsingArmor")]
		[HarmonyPrefix]
		private static bool Apply(ILContext __0)
		{
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}