Decompiled source of SteadyRegeneration v1.0.3

SteadyRegen.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SteadyRegen")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/Smoothbrain/SteadyRegeneration")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SteadyRegen")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A3094076-B06A-44AC-BFDD-7FA48D81B35A")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 SteadyRegen
{
	[BepInPlugin("org.bepinex.plugins.steadyregeneration", "Steady Regeneration", "1.0.3")]
	[BepInIncompatibility("org.bepinex.plugins.valheim_plus")]
	public class SteadyRegen : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Player), "UpdateFood")]
		private static class MakeRegenSmooth
		{
			private static readonly MethodInfo Heal = AccessTools.DeclaredMethod(typeof(Character), "Heal", (Type[])null, (Type[])null);

			private static readonly FieldInfo RegenTimer = AccessTools.DeclaredField(typeof(Player), "m_foodRegenTimer");

			[UsedImplicitly]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> instructionList = instructions.ToList();
				int i = 0;
				while (i < instructionList.Count)
				{
					if (instructionList[i].opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(instructionList[i], (object)10f))
					{
						yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.1f);
					}
					else if (instructionList[i].opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(instructionList[i], (object)0f) && instructionList[i + 1].opcode == OpCodes.Stfld && CodeInstructionExtensions.OperandIs(instructionList[i + 1], (MemberInfo)RegenTimer))
					{
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Ldfld, (object)RegenTimer);
						yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.1f);
						yield return new CodeInstruction(OpCodes.Sub, (object)null);
					}
					else if (instructionList[i].opcode == OpCodes.Ldc_I4_1 && instructionList[i + 1].opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(instructionList[i + 1], (MemberInfo)Heal))
					{
						yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.01f);
						yield return new CodeInstruction(OpCodes.Mul, (object)null);
						yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
					}
					else
					{
						yield return instructionList[i];
					}
					int num = i + 1;
					i = num;
				}
			}
		}

		[HarmonyPatch(typeof(GuiBar), "SetValue")]
		private static class DisplaySmoothRegenOnHealthbar
		{
			private static readonly FieldInfo BarValue = AccessTools.DeclaredField(typeof(GuiBar), "m_value");

			private static readonly FieldInfo SmoothFill = AccessTools.DeclaredField(typeof(GuiBar), "m_smoothFill");

			[UsedImplicitly]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Expected O, but got Unknown
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Expected O, but got Unknown
				List<CodeInstruction> list = instructions.ToList();
				for (int i = 0; i < list.Count; i++)
				{
					if (!(list[i].opcode == OpCodes.Ldfld) || !CodeInstructionExtensions.OperandIs(list[i], (MemberInfo)SmoothFill))
					{
						continue;
					}
					while (i > 0)
					{
						if (list[i].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(list[i], (MemberInfo)BarValue))
						{
							list.Insert(i + 1, new CodeInstruction(OpCodes.Add, (object)null));
							list.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_R4, (object)0.5f));
							break;
						}
						i--;
					}
					break;
				}
				return list;
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float),
			typeof(int)
		})]
		private static class ChangeFoodTooltip
		{
			[UsedImplicitly]
			private static void Postfix(ItemData __instance, ref string __result)
			{
				__result = __result.Replace("hp/tick", "hp/10s");
			}
		}

		private const string ModName = "Steady Regeneration";

		private const string ModVersion = "1.0.3";

		private const string ModGUID = "org.bepinex.plugins.steadyregeneration";

		public void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			new Harmony("org.bepinex.plugins.steadyregeneration").PatchAll(executingAssembly);
		}
	}
}