Decompiled source of MasterCooking v1.0.2

MasterCooking.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MasterCooking")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that applies Smoothbrain's Cooking skill bonuses to Ashlands Feast items")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MasterCooking")]
[assembly: AssemblyTitle("MasterCooking")]
[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 MasterCooking
{
	[BepInPlugin("com.ruijven.mastercooking", "MasterCooking", "1.0.2")]
	internal class MasterCookingPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.ruijven.mastercooking";

		public const string PluginName = "MasterCooking";

		public const string PluginVersion = "1.0.2";

		internal static ManualLogSource Logger;

		public static ConfigEntry<float> HealthFactor;

		public static ConfigEntry<float> StaminaFactor;

		public static ConfigEntry<float> RegenFactor;

		public static ConfigEntry<float> EitrFactor;

		public static ConfigEntry<float> DurationFactor;

		public static ConfigEntry<float> ExperienceGainFactor;

		public static ConfigEntry<bool> LogDebugInfo;

		public static ConfigEntry<bool> DisableStatDecay;

		internal static MasterCookingPlugin Instance { get; private set; }

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			InitializeConfig();
			Harmony val = new Harmony("com.ruijven.mastercooking");
			val.PatchAll(Assembly.GetExecutingAssembly());
			Logger.LogInfo((object)"MasterCooking v1.0.2 loaded successfully!");
			Logger.LogInfo((object)"This mod applies Cooking skill bonuses to ALL food consumption.");
		}

		private void InitializeConfig()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			HealthFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Stat Multipliers", "HealthFactor", 1.3f, new ConfigDescription("Health multiplier at Cooking skill level 100 (e.g., 1.3 = 30% increase)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			StaminaFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Stat Multipliers", "StaminaFactor", 1.3f, new ConfigDescription("Stamina multiplier at Cooking skill level 100 (e.g., 1.3 = 30% increase)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			RegenFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Stat Multipliers", "RegenFactor", 1.3f, new ConfigDescription("Health regeneration multiplier at Cooking skill level 100 (e.g., 1.3 = 30% increase)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			EitrFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Stat Multipliers", "EitrFactor", 1.3f, new ConfigDescription("Eitr multiplier at Cooking skill level 100 (e.g., 1.3 = 30% increase)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			DurationFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Stat Multipliers", "DurationFactor", 1f, new ConfigDescription("Duration multiplier at Cooking skill level 100 (e.g., 1.5 = 50% longer duration)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), Array.Empty<object>()));
			ExperienceGainFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Skill Progression", "ExperienceGainFactor", 50f, new ConfigDescription("Multiplier for Cooking skill experience gained (e.g., 50.0 = 50x XP)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100f), Array.Empty<object>()));
			LogDebugInfo = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LogDebugInfo", false, new ConfigDescription("Enable detailed debug logging in the console.", (AcceptableValueBase)null, Array.Empty<object>()));
			DisableStatDecay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableStatDecay", false, new ConfigDescription("Disable food stat decay over time. When enabled, food stats remain at full strength regardless of remaining duration.", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
	[HarmonyPatch]
	internal class Patch_FeastFix
	{
		[HarmonyPatch(typeof(Player), "EatFood")]
		[HarmonyPrefix]
		private static void EatFoodPrefix(Player __instance, ItemData item)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || item == null || item.m_shared == null)
			{
				return;
			}
			float cookingSkillLevel = GetCookingSkillLevel(__instance);
			float num = Mathf.Min(cookingSkillLevel / 100f, 1f);
			if (!(num <= 0f))
			{
				float num2 = 1f + num * (MasterCookingPlugin.HealthFactor.Value - 1f);
				float num3 = 1f + num * (MasterCookingPlugin.StaminaFactor.Value - 1f);
				float num4 = 1f + num * (MasterCookingPlugin.RegenFactor.Value - 1f);
				float num5 = 1f + num * (MasterCookingPlugin.EitrFactor.Value - 1f);
				if (item.m_shared.m_food > 0f)
				{
					SharedData shared = item.m_shared;
					shared.m_food *= num2;
				}
				if (item.m_shared.m_foodStamina > 0f)
				{
					SharedData shared2 = item.m_shared;
					shared2.m_foodStamina *= num3;
				}
				if (item.m_shared.m_foodRegen > 0f)
				{
					SharedData shared3 = item.m_shared;
					shared3.m_foodRegen *= num4;
				}
				if (item.m_shared.m_foodEitr > 0f)
				{
					SharedData shared4 = item.m_shared;
					shared4.m_foodEitr *= num5;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "EatFood")]
		[HarmonyPostfix]
		private static void EatFoodPostfix(Player __instance, ItemData item, ref bool __result)
		{
			if (!__result || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || item == null || item.m_shared == null)
			{
				return;
			}
			float cookingSkillLevel = GetCookingSkillLevel(__instance);
			float num = Mathf.Min(cookingSkillLevel / 100f, 1f);
			if (!(num <= 0f))
			{
				float num2 = 1f + num * (MasterCookingPlugin.HealthFactor.Value - 1f);
				float num3 = 1f + num * (MasterCookingPlugin.StaminaFactor.Value - 1f);
				float num4 = 1f + num * (MasterCookingPlugin.RegenFactor.Value - 1f);
				float num5 = 1f + num * (MasterCookingPlugin.EitrFactor.Value - 1f);
				if (item.m_shared.m_food > 0f)
				{
					SharedData shared = item.m_shared;
					shared.m_food /= num2;
				}
				if (item.m_shared.m_foodStamina > 0f)
				{
					SharedData shared2 = item.m_shared;
					shared2.m_foodStamina /= num3;
				}
				if (item.m_shared.m_foodRegen > 0f)
				{
					SharedData shared3 = item.m_shared;
					shared3.m_foodRegen /= num4;
				}
				if (item.m_shared.m_foodEitr > 0f)
				{
					SharedData shared4 = item.m_shared;
					shared4.m_foodEitr /= num5;
				}
				float num6 = 1f + num * (MasterCookingPlugin.DurationFactor.Value - 1f);
				List<Food> foods = __instance.GetFoods();
				Food val = ((IEnumerable<Food>)foods).FirstOrDefault((Func<Food, bool>)((Food f) => f.m_item.m_shared.m_name == item.m_shared.m_name));
				if (val != null && val.m_time > 0f)
				{
					val.m_time *= num6;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateFood")]
		[HarmonyPrefix]
		private static void UpdateFoodPrefix(Player __instance, float dt, bool forceUpdate)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			float cookingSkillLevel = GetCookingSkillLevel(__instance);
			float num = Mathf.Min(cookingSkillLevel / 100f, 1f);
			if (num <= 0f)
			{
				return;
			}
			float num2 = 1f + num * (MasterCookingPlugin.HealthFactor.Value - 1f);
			float num3 = 1f + num * (MasterCookingPlugin.StaminaFactor.Value - 1f);
			float num4 = 1f + num * (MasterCookingPlugin.EitrFactor.Value - 1f);
			List<Food> foods = __instance.GetFoods();
			foreach (Food item in foods)
			{
				if (item.m_item.m_shared.m_food > 0f)
				{
					SharedData shared = item.m_item.m_shared;
					shared.m_food *= num2;
				}
				if (item.m_item.m_shared.m_foodStamina > 0f)
				{
					SharedData shared2 = item.m_item.m_shared;
					shared2.m_foodStamina *= num3;
				}
				if (item.m_item.m_shared.m_foodEitr > 0f)
				{
					SharedData shared3 = item.m_item.m_shared;
					shared3.m_foodEitr *= num4;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateFood")]
		[HarmonyPostfix]
		private static void UpdateFoodPostfix(Player __instance, float dt, bool forceUpdate)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			float cookingSkillLevel = GetCookingSkillLevel(__instance);
			float num = Mathf.Min(cookingSkillLevel / 100f, 1f);
			if (num <= 0f)
			{
				return;
			}
			float num2 = 1f + num * (MasterCookingPlugin.HealthFactor.Value - 1f);
			float num3 = 1f + num * (MasterCookingPlugin.StaminaFactor.Value - 1f);
			float num4 = 1f + num * (MasterCookingPlugin.EitrFactor.Value - 1f);
			List<Food> foods = __instance.GetFoods();
			foreach (Food item in foods)
			{
				if (item.m_item.m_shared.m_food > 0f)
				{
					SharedData shared = item.m_item.m_shared;
					shared.m_food /= num2;
				}
				if (item.m_item.m_shared.m_foodStamina > 0f)
				{
					SharedData shared2 = item.m_item.m_shared;
					shared2.m_foodStamina /= num3;
				}
				if (item.m_item.m_shared.m_foodEitr > 0f)
				{
					SharedData shared3 = item.m_item.m_shared;
					shared3.m_foodEitr /= num4;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "RaiseSkill")]
		[HarmonyPrefix]
		private static void RaiseSkillPrefix(Player __instance, SkillType skill, ref float value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			if ((int)skill == 105)
			{
				value *= MasterCookingPlugin.ExperienceGainFactor.Value;
			}
		}

		private static float GetCookingSkillLevel(Player player)
		{
			try
			{
				return ((Character)player).GetSkillLevel((SkillType)105);
			}
			catch (Exception ex)
			{
				MasterCookingPlugin.Logger.LogError((object)("Error getting Cooking skill level: " + ex.Message));
				return 0f;
			}
		}

		[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
		[HarmonyPostfix]
		private static void GetTotalFoodValue_Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !MasterCookingPlugin.DisableStatDecay.Value)
			{
				return;
			}
			try
			{
				List<Food> foods = __instance.GetFoods();
				if (foods == null || foods.Count == 0)
				{
					return;
				}
				float cookingSkillLevel = GetCookingSkillLevel(__instance);
				float num = Mathf.Min(cookingSkillLevel / 100f, 1f);
				if (num <= 0f)
				{
					return;
				}
				float num2 = 1f + num * (MasterCookingPlugin.HealthFactor.Value - 1f);
				float num3 = 1f + num * (MasterCookingPlugin.StaminaFactor.Value - 1f);
				float num4 = 1f + num * (MasterCookingPlugin.EitrFactor.Value - 1f);
				float num5 = 0f;
				float num6 = 0f;
				float num7 = 0f;
				foreach (Food item in foods)
				{
					if (item != null && item.m_item != null && item.m_item.m_shared != null)
					{
						if (item.m_item.m_shared.m_food > 0f)
						{
							num5 += item.m_item.m_shared.m_food * num2;
						}
						if (item.m_item.m_shared.m_foodStamina > 0f)
						{
							num6 += item.m_item.m_shared.m_foodStamina * num3;
						}
						if (item.m_item.m_shared.m_foodEitr > 0f)
						{
							num7 += item.m_item.m_shared.m_foodEitr * num4;
						}
					}
				}
				hp = num5;
				stamina = num6;
				eitr = num7;
			}
			catch (Exception ex)
			{
				MasterCookingPlugin.Logger.LogError((object)("Error in GetTotalFoodValue_Postfix: " + ex.Message));
			}
		}
	}
}