Decompiled source of RelevantCookingSkill v1.0.0

plugins/RelevantCookingSkill.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;

[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("RelevantCookingSkill")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RelevantCookingSkill")]
[assembly: AssemblyTitle("RelevantCookingSkill")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RelevantCookingSkill;

[BepInPlugin("com.relevantcookingskill.RelevantCookingSkill", "RelevantCookingSkill", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "com.relevantcookingskill.RelevantCookingSkill";

	private const int CookingSkillId = 105;

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<bool> ScaleHealth;

	internal static ConfigEntry<bool> ScaleStamina;

	internal static ConfigEntry<bool> ScaleEitr;

	internal static ConfigEntry<bool> PastLevel100;

	internal static ConfigEntry<float> BonusAtLevel100;

	internal static ConfigEntry<float> BonusAtLevel0;

	private static MethodInfo _getSkillFactor;

	private static object _cookingSkill;

	private void Awake()
	{
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Expected O, but got Unknown
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn the cooking skill food multiplier on or off.");
		BonusAtLevel0 = ((BaseUnityPlugin)this).Config.Bind<float>("Multiplier", "BonusAtLevel0", 0f, "Extra food strength at Cooking 0, as a fraction. 0 = vanilla values, 0.1 = +10%, -0.2 = 20% weaker.");
		BonusAtLevel100 = ((BaseUnityPlugin)this).Config.Bind<float>("Multiplier", "BonusAtLevel100", 0.5f, "Extra food strength at Cooking 100, as a fraction. 0.5 = +50%. The bonus rises in a straight line between the level 0 and level 100 values.");
		PastLevel100 = ((BaseUnityPlugin)this).Config.Bind<bool>("Multiplier", "AllowPastLevel100", false, "If another mod lets Cooking go past 100, keep growing the bonus past it. Off: the bonus stops at level 100.");
		ScaleHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("Applies To", "Health", true, "Scale the health food gives.");
		ScaleStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("Applies To", "Stamina", true, "Scale the stamina food gives.");
		ScaleEitr = ((BaseUnityPlugin)this).Config.Bind<bool>("Applies To", "Eitr", true, "Scale the eitr food gives.");
		Type type = AccessTools.TypeByName("Player");
		Type type2 = AccessTools.TypeByName("Character");
		MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetTotalFoodValue", (Type[])null, (Type[])null));
		_getSkillFactor = ((type2 == null) ? null : AccessTools.Method(type2, "GetSkillFactor", (Type[])null, (Type[])null));
		if (methodInfo == null || _getSkillFactor == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Could not find Player.GetTotalFoodValue / Character.GetSkillFactor; the game may have changed. Mod inactive.");
			return;
		}
		_cookingSkill = Enum.ToObject(_getSkillFactor.GetParameters()[0].ParameterType, 105);
		new Harmony("com.relevantcookingskill.RelevantCookingSkill").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "FoodTotalsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"RelevantCookingSkill loaded.");
	}

	public static void FoodTotalsPostfix(object __instance, ref float __0, ref float __1, ref float __2)
	{
		if (!Enabled.Value)
		{
			return;
		}
		float num = Multiplier(__instance);
		if (num != 1f)
		{
			if (ScaleHealth.Value)
			{
				__0 *= num;
			}
			if (ScaleStamina.Value)
			{
				__1 *= num;
			}
			if (ScaleEitr.Value)
			{
				__2 *= num;
			}
		}
	}

	private static float Multiplier(object player)
	{
		float val = (float)_getSkillFactor.Invoke(player, new object[1] { _cookingSkill });
		val = (PastLevel100.Value ? Math.Max(0f, val) : Math.Min(1f, Math.Max(0f, val)));
		float num = BonusAtLevel0.Value + (BonusAtLevel100.Value - BonusAtLevel0.Value) * val;
		return Math.Max(0f, 1f + num);
	}
}