Decompiled source of FoodBuffConfig v1.0.3

files\plugins\FoodBuffConfig\FoodBuffConfig.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterFeasts")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterFeasts")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f9372c59-ed1e-4431-91db-c76e3869522e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FoodBuffConfigMod;

[BepInPlugin("0zzerod.FoodBuffConfig", "FoodBuffConfig", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FoodBuffConfigPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "EatFood")]
	public static class Patch_Player_EatFood
	{
		private static readonly Dictionary<string, float> _originalBurnTimes = new Dictionary<string, float>();

		private static void Prefix(ItemData item)
		{
			if (item?.m_shared == null)
			{
				return;
			}
			GameObject dropPrefab = item.m_dropPrefab;
			string text = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
			if (text != null && Instance.FoodNames.Contains(text))
			{
				if (!_originalBurnTimes.TryGetValue(text, out var value))
				{
					value = item.m_shared.m_foodBurnTime;
					_originalBurnTimes[text] = value;
				}
				float num = value * Instance.DurationMultiplier.Value;
				float value2 = Instance.MaxFoodBurnTime.Value;
				float num2 = Mathf.Ceil(num / value2) * value2;
				item.m_shared.m_foodBurnTime = num2;
				Log.LogInfo((object)$"Scaled duration for '{item.m_shared.m_name}': *={Instance.DurationMultiplier.Value:F1} → {num2:F1}s");
			}
		}

		private static void Postfix(ItemData item)
		{
			if (item?.m_shared != null)
			{
				GameObject dropPrefab = item.m_dropPrefab;
				string text = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
				if (text != null && _originalBurnTimes.TryGetValue(text, out var value))
				{
					item.m_shared.m_foodBurnTime = value;
				}
			}
		}
	}

	public static ManualLogSource Log;

	private ConfigEntry<string> FoodNamesRaw;

	private ConfigEntry<float> HealthBonusMultiplier;

	private ConfigEntry<float> StaminaBonusMultiplier;

	private ConfigEntry<float> EitrBonusMultiplier;

	private ConfigEntry<float> DurationMultiplier;

	private ConfigEntry<float> MaxFoodHealth;

	private ConfigEntry<float> MaxFoodStamina;

	private ConfigEntry<float> MaxFoodEitr;

	private ConfigEntry<float> MaxFoodBurnTime;

	private List<string> FoodNames = new List<string>();

	private static FoodBuffConfigPlugin _instance;

	public static FoodBuffConfigPlugin Instance => _instance;

	private void Awake()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		_instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		BindConfig();
		FoodNames = (from s in FoodNamesRaw.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
			select s.Trim() into s
			where s.Length > 0
			select s).ToList();
		Log.LogInfo((object)string.Format("[BuffConfig] Loaded {0} food names: {1}", FoodNames.Count, string.Join(", ", FoodNames)));
		PrefabManager.OnPrefabsRegistered += OnPrefabsReady;
		Harmony val = new Harmony("0zzerod.FoodBuffConfig");
		val.PatchAll();
		Log.LogInfo((object)"[FoodBuffConfig] Harmony patches applied");
	}

	private void BindConfig()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Expected O, but got Unknown
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Expected O, but got Unknown
		string text = "FoodBuffConfig";
		ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		};
		FoodNamesRaw = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Food Names", "FeastMeadows, FeastBlackforest, FeastSwamps, FeastOceans, FeastMountains, FeastPlains, FeastMistlands, FeastAshlands", new ConfigDescription("Comma-separated internal item names to boost when eaten.", (AcceptableValueBase)null, Array.Empty<object>()));
		HealthBonusMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Health Bonus Multiplier", 1.2f, new ConfigDescription("Multiplier for max health and regen bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		StaminaBonusMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Stamina Bonus Multiplier", 1.1f, new ConfigDescription("Multiplier for stamina bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		EitrBonusMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Eitr Bonus Multiplier", 1.5f, new ConfigDescription("Multiplier for Eitr bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		DurationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Duration Multiplier", 4f, new ConfigDescription("Multiplier for duration of food effects when eaten.", (AcceptableValueBase)null, new object[1] { val }));
		MaxFoodHealth = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Health Rounding", 5f, new ConfigDescription("Rounding unit for health bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		MaxFoodStamina = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Stamina Rounding", 1f, new ConfigDescription("Rounding unit for stamina bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		MaxFoodEitr = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Eitr Rounding", 1f, new ConfigDescription("Rounding unit for Eitr bonus from food.", (AcceptableValueBase)null, new object[1] { val }));
		MaxFoodBurnTime = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Time Rounding", 60f, new ConfigDescription("Rounding unit in seconds for duration of food effect.", (AcceptableValueBase)null, new object[1] { val }));
	}

	private void OnPrefabsReady()
	{
		PrefabManager.OnPrefabsRegistered -= OnPrefabsReady;
		foreach (string foodName in FoodNames)
		{
			GameObject val = PrefabManager.Instance.GetPrefab(foodName) ?? PrefabManager.Instance.GetPrefab(foodName.ToLowerInvariant());
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)("[FoodBuffConfig] Could not find prefab for '" + foodName + "'"));
				continue;
			}
			ItemDrop component = val.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				Log.LogWarning((object)("[FoodBuffConfig] Prefab '" + foodName + "' missing ItemDrop"));
				continue;
			}
			SharedData shared = component.m_itemData.m_shared;
			shared.m_food *= HealthBonusMultiplier.Value;
			shared.m_foodRegen *= HealthBonusMultiplier.Value;
			shared.m_foodStamina *= StaminaBonusMultiplier.Value;
			shared.m_foodEitr *= EitrBonusMultiplier.Value;
			float num = Mathf.Ceil(shared.m_food);
			float value = MaxFoodHealth.Value;
			shared.m_food = Mathf.Ceil(num / value) * value;
			float num2 = Mathf.Ceil(shared.m_foodStamina);
			float value2 = MaxFoodStamina.Value;
			shared.m_foodStamina = Mathf.Ceil(num2 / value2) * value2;
			float num3 = Mathf.Ceil(shared.m_foodEitr);
			float value3 = MaxFoodEitr.Value;
			shared.m_foodEitr = Mathf.Ceil(num3 / value3) * value3;
			Log.LogInfo((object)$"[FoodBuffConfig] Scaled stats for '{foodName}': health×{HealthBonusMultiplier.Value:F2}, regen×{HealthBonusMultiplier.Value:F2}, stam×{StaminaBonusMultiplier.Value:F2}, eitr×{EitrBonusMultiplier.Value:F2}");
		}
	}
}