Decompiled source of StartingEitrBonus v1.0.4

StartingEitrBonus.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("StartingEitrBonus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3aaf2c9631da4e433509c83747c9ecc3bda2fea4")]
[assembly: AssemblyProduct("StartingEitrBonus")]
[assembly: AssemblyTitle("StartingEitrBonus")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[CompilerGenerated]
	[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 StartingEitrBonus
{
	[BepInPlugin("badbatch.valheim.startingeitrbonus", "Starting Eitr Bonus", "1.0.4")]
	public sealed class StartingEitrBonusPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "badbatch.valheim.startingeitrbonus";

		public const string PluginName = "Starting Eitr Bonus";

		public const string PluginVersion = "1.0.4";

		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<float> BaseEitrBonus;

		private readonly Harmony _harmony = new Harmony("badbatch.valheim.startingeitrbonus");

		private void Awake()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the starting Eitr bonus.");
			BaseEitrBonus = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BaseEitrBonus", 25f, new ConfigDescription("Amount of base Eitr to add before food bonuses. Set to 0 to keep vanilla behavior.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 250f), Array.Empty<object>()));
			PatchTotalFoodValue();
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded. Base Eitr bonus: {2}", "Starting Eitr Bonus", "1.0.4", BaseEitrBonus.Value));
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}

		private void PatchTotalFoodValue()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			string[] array = new string[7] { "GetTotalFoodValue", "getTotalFoodValue", "GetTotalEitr", "GetTotalEitrValue", "GetTotalFoodEitr", "GetEitrFromFood", "GetTotalEitrFromFood" };
			MethodInfo methodInfo = null;
			string[] array2 = array;
			foreach (string text in array2)
			{
				methodInfo = AccessTools.Method(typeof(Player), text, (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					break;
				}
			}
			if (methodInfo == null)
			{
				MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo[] array3 = methods;
				foreach (MethodInfo methodInfo2 in array3)
				{
					if (methodInfo2.ReturnType == typeof(float) && methodInfo2.GetParameters().Length == 0)
					{
						string text2 = methodInfo2.Name.ToLowerInvariant();
						if (text2.Contains("total") && (text2.Contains("food") || text2.Contains("eitr")))
						{
							methodInfo = methodInfo2;
							break;
						}
					}
				}
			}
			if (methodInfo == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find Player total Eitr/food value method. The Eitr bonus patch was not applied.");
				return;
			}
			HarmonyMethod val = new HarmonyMethod(typeof(PlayerGetTotalFoodValuePatch), "Postfix", (Type[])null);
			_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
	internal static class PlayerGetTotalFoodValuePatch
	{
		internal static void Postfix(ref float eitr)
		{
			if (StartingEitrBonusPlugin.ModEnabled.Value)
			{
				float value = StartingEitrBonusPlugin.BaseEitrBonus.Value;
				if (!(value <= 0f))
				{
					eitr += value;
				}
			}
		}
	}
}