Decompiled source of AAV Reborn v1.0.0

AAV Reborn.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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: AssemblyTitle("AAV_Reborn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AAV_Reborn")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("61BCEF99-55A8-478A-99C5-209DE6956A1D")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 AAV_Reborn
{
	[BepInPlugin("Eardwulf.valheim.aavreborn", "AAV_Reborn", "1.0.0")]
	public sealed class AAV_Reborn : BaseUnityPlugin
	{
		public const string PluginGuid = "Eardwulf.valheim.aavreborn";

		public const string PluginName = "AAV_Reborn";

		public const string PluginVersion = "1.0.0";

		private static ManualLogSource _logger;

		private void Awake()
		{
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Eardwulf.valheim.aavreborn");
		}

		public static void LogInfo(object obj)
		{
			_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
		}
	}
	public static class PluginConfig
	{
		public static ConfigEntry<string> ErrorMessage { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			ErrorMessage = config.Bind<string>("ErrorMessage", "Custom Error Message", "You've had enough", "Message to show when you don't need to drink any mead.");
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal class PlayerPatches
	{
		[HarmonyPatch("CanConsumeItem")]
		[HarmonyPostfix]
		public static void SaveTheMeads(Player __instance, ref bool __result, ItemData item)
		{
			float healthPercentage = ((Character)__instance).GetHealthPercentage();
			float healthPercentage2 = ((Character)__instance).GetHealthPercentage();
			float eitrPercentage = ((Character)__instance).GetEitrPercentage();
			string name = item.m_shared.m_name;
			switch (name)
			{
			case "$item_mead_hp_major":
			case "$item_mead_hp_medium":
			case "$item_mead_hp_minor":
				if (healthPercentage >= 0.9f)
				{
					AAV_Reborn.LogInfo($"Health Percentage is {healthPercentage * 100f} so {name} should not be consumed");
					((Character)__instance).Message((MessageType)2, PluginConfig.ErrorMessage.Value, 0, (Sprite)null, false);
					__result = false;
				}
				break;
			}
			if ((name == "$item_mead_stamina_medium" || name == "$item_mead_stamina_minor") && healthPercentage2 >= 0.9f)
			{
				AAV_Reborn.LogInfo($"Stamina Percentage is {healthPercentage2 * 100f} so {name} should not be consumed");
				((Character)__instance).Message((MessageType)2, PluginConfig.ErrorMessage.Value, 0, (Sprite)null, false);
				__result = false;
			}
			if (name == "$item_mead_eitr_minor" && eitrPercentage >= 0.9f)
			{
				AAV_Reborn.LogInfo($"Eitr Percentage is {eitrPercentage * 100f} so {name} should not be consumed");
				((Character)__instance).Message((MessageType)2, PluginConfig.ErrorMessage.Value, 0, (Sprite)null, false);
				__result = false;
			}
		}
	}
}