Decompiled source of PotionFix v1.0.0

PotionFix.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PotionFix;

[BepInPlugin("dukr.potionfix", "PotionFix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	private ConfigEntry<string> remove;

	private void Awake()
	{
		remove = ((BaseUnityPlugin)this).Config.Bind<string>("General", "RemoveFromHerbalistCooldownList", "MeadHealthMinor,MeadHealthMedium,MeadHealthMajor,MeadStaminaMinor,MeadStaminaMedium,MeadEitrMinor", "Comma separated item prefab names that Herbalist must NOT shorten.");
	}

	private void Start()
	{
		try
		{
			Type type = AccessTools.TypeByName("Herbalist.Plugin");
			if (type == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Herbalist not found, nothing to fix");
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(type, "_ToReduceCooldown");
			if (fieldInfo == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Herbalist field _ToReduceCooldown not found (different version?)");
				return;
			}
			object value = fieldInfo.GetValue(null);
			if (value == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Herbalist list is null");
				return;
			}
			int num = 0;
			string[] array = remove.Value.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length == 0)
				{
					continue;
				}
				MethodInfo method = value.GetType().GetMethod("Remove", new Type[1] { typeof(string) });
				if (method != null)
				{
					object obj = method.Invoke(value, new object[1] { text });
					if (obj is bool && (bool)obj)
					{
						num++;
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("PotionFix 1.0.0: removed " + num + " entries from Herbalist cooldown list"));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("PotionFix failed: " + ex.Message));
		}
	}
}