Decompiled source of DontWastePotions v1.0.0

plugins\DontWastePotions.dll

Decompiled 2 months ago
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Jotunn;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DontWastePotions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DontWastePotions")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[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")]
namespace DontWastePotions
{
	[BepInPlugin("sephalon.DontWastePotions", "DontWastePotions", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[HarmonyPatch]
	internal class DontWastePotions : BaseUnityPlugin
	{
		public const string PluginGUID = "sephalon.DontWastePotions";

		public const string PluginName = "DontWastePotions";

		public const string PluginVersion = "1.0.0";

		public static List<string> m_healPotions = new List<string> { "MeadHealthMinor", "MeadHealthMedium", "MeadHealthMajor" };

		public static List<string> m_staminaPotions = new List<string> { "MeadStaminaMinor", "MeadStaminaMedium" };

		public static List<string> m_eitrPotions = new List<string> { "MeadEitrMinor" };

		public void Awake()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "sephalon.DontWastePotions");
			Logger.LogMessage((object)"DontWastePotions");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "ConsumeItem")]
		public static bool ConsumeItemPrefix(Player __instance, ref bool __result, Inventory inventory, ItemData item, bool checkWorldLevel)
		{
			string name = ((Object)item.m_dropPrefab).name;
			if (m_healPotions.Contains(name) && ((Character)__instance).GetHealth() == ((Character)__instance).GetMaxHealth())
			{
				Logger.LogMessage((object)("DontWastePotions: Potion " + name + " refused because player is at max health"));
				MessagePlayer("Potion not consumed. You are already at maximum Health");
				__result = false;
				return false;
			}
			if (m_staminaPotions.Contains(name) && __instance.GetStamina() == ((Character)__instance).GetMaxStamina())
			{
				Logger.LogMessage((object)("DontWastePotions: Potion " + name + " refused because player is at max stamina"));
				MessagePlayer("Potion not consumed. You are already at maximum Stamina");
				__result = false;
				return false;
			}
			if (m_eitrPotions.Contains(name) && __instance.GetEitr() == ((Character)__instance).GetMaxEitr())
			{
				Logger.LogMessage((object)("DontWastePotions: Potion " + name + " refused because player is at max eitr"));
				MessagePlayer("Potion not consumed. You are already at maximum Eitr");
				__result = false;
				return false;
			}
			return true;
		}

		public static void MessagePlayer(string msg)
		{
			((Character)Player.m_localPlayer).Message((MessageType)2, msg, 0, (Sprite)null);
		}
	}
}
namespace DontWastePotions.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("DontWastePotions.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}