Decompiled source of NegativeRegenFix v1.0.0

NegativeRegenFix.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("NegativeRegenFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NegativeRegenFix")]
[assembly: AssemblyTitle("NegativeRegenFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NegativeRegenFix;

[BepInPlugin("com.HouseOfFruits.NegativeRegenFix", "NegativeRegenFix", "1.0.0")]
public class NegativeRegenFix : BaseUnityPlugin
{
	public const string guid = "com.HouseOfFruits.NegativeRegenFix";

	public const string teamName = "HouseOfFruits";

	public const string modName = "NegativeRegenFix";

	public const string version = "1.0.0";

	public static PluginInfo PInfo { get; private set; }

	public void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		CharacterBody.RecalculateStats += new Manipulator(RegenMultiplierFix);
	}

	private static void RegenMultiplierFix(ILContext il)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[4]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
			(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "baseRegen"),
			(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
			(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "levelRegen")
		});
		int regenMultLocation = 72;
		int endRegenLocation = 73;
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[2]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 1f),
			(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref regenMultLocation)
		});
		endRegenLocation = regenMultLocation + 1;
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchStloc(x, endRegenLocation)
		});
		val.Emit(OpCodes.Ldloc, endRegenLocation);
		val.Emit(OpCodes.Ldloc, regenMultLocation);
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<float, float, CharacterBody, float>>((Func<float, float, CharacterBody, float>)delegate(float currentRegen, float regenMult, CharacterBody body)
		{
			if (body.HasBuff(Buffs.AffixEcho) || body.HasBuff(Buffs.EliteEarth))
			{
				return 0f;
			}
			float num = body.baseRegen + body.levelRegen * (body.level - 1f);
			float num2 = currentRegen / regenMult - num;
			float num3 = num + Mathf.Abs(num) * (regenMult - 1f) + num2 * regenMult;
			if (body.HasBuff(Buffs.TonicBuff) && num3 < 0f)
			{
				num3 += Mathf.Abs(num3) * 3f;
				num3 /= 4f;
			}
			return num3;
		});
		val.Emit(OpCodes.Stloc, endRegenLocation);
	}
}