Decompiled source of McNoHungryPets v1.0.0

McNoHungryPets.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("McNoHungryPets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Tamed creatures never get hungry.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("McNoHungryPets")]
[assembly: AssemblyTitle("McNoHungryPets")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace McNoHungryPets
{
	[BepInPlugin("joaorodrigues.valheim.mcnohungrypets", "McNoHungryPets", "1.0.0")]
	[BepInProcess("valheim.exe")]
	[BepInProcess("valheim_server.exe")]
	public class McNoHungryPetsPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "joaorodrigues.valheim.mcnohungrypets";

		public const string PluginName = "McNoHungryPets";

		public const string PluginVersion = "1.0.0";

		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<bool> TamedOnly;

		internal static ConfigEntry<bool> OverrideFedDuration;

		internal static ConfigEntry<float> FedDurationSeconds;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Enables the mod. Set to false to restore vanilla behaviour.");
			TamedOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "TamedOnly", true, "true: only already tamed creatures stop getting hungry. Taming still requires feeding, like vanilla. false: no tameable creature gets hungry, and taming also progresses without feeding.");
			OverrideFedDuration = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Duration", "OverrideFedDuration", false, "Conservative alternative: instead of removing hunger, only stretch how long a creature stays fed after eating. Works together with Enabled and TamedOnly.");
			FedDurationSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Duration", "FedDurationSeconds", 86400f, new ConfigDescription("Seconds a creature stays fed when OverrideFedDuration is true. Vanilla varies per creature (usually between 30 and 600). 86400 = one real day.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 31536000f), Array.Empty<object>()));
			_harmony = new Harmony("joaorodrigues.valheim.mcnohungrypets");
			_harmony.PatchAll();
			Log.LogInfo((object)("McNoHungryPets 1.0.0 loaded. TamedOnly=" + TamedOnly.Value + " OverrideFedDuration=" + OverrideFedDuration.Value));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static bool AppliesTo(Tameable tameable)
		{
			if (!ModEnabled.Value)
			{
				return false;
			}
			if ((Object)(object)tameable == (Object)null)
			{
				return false;
			}
			if (TamedOnly.Value && !tameable.IsTamed())
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Tameable), "IsHungry")]
	internal static class Patch_Tameable_IsHungry
	{
		private static void Postfix(Tameable __instance, ref bool __result)
		{
			if (__result && !McNoHungryPetsPlugin.OverrideFedDuration.Value && McNoHungryPetsPlugin.AppliesTo(__instance))
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Tameable), "Awake")]
	internal static class Patch_Tameable_Awake
	{
		private static void Postfix(Tameable __instance)
		{
			if (McNoHungryPetsPlugin.ModEnabled.Value && McNoHungryPetsPlugin.OverrideFedDuration.Value)
			{
				__instance.m_fedDuration = McNoHungryPetsPlugin.FedDurationSeconds.Value;
			}
		}
	}
}