Decompiled source of FoodDuration v1.1.0

BepInEx/plugins/FoodDuration/FoodDuration.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FoodDuration")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+83efcbeca5b65142c2d231601ec9ebe7e99e7453")]
[assembly: AssemblyProduct("FoodDuration")]
[assembly: AssemblyTitle("FoodDuration")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace FoodDuration;

[BepInPlugin("local.valheim.foodduration", "Food Duration", "1.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	private static class AwakePatch
	{
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void Postfix(ObjectDB __instance)
		{
			Apply(__instance);
		}
	}

	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	private static class CopyPatch
	{
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void Postfix(ObjectDB __instance)
		{
			Apply(__instance);
		}
	}

	private static ConfigFile settings;

	private static readonly Dictionary<string, float> durations = new Dictionary<string, float>();

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		settings = ((BaseUnityPlugin)this).Config;
		new Harmony("local.valheim.foodduration").PatchAll(typeof(Plugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Per-food durations enabled; defaults extend 20-minute foods to 25 minutes.");
	}

	private static void Apply(ObjectDB db)
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		if ((Object)(object)db == (Object)null || db.m_items == null)
		{
			return;
		}
		foreach (GameObject item in db.m_items)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			SharedData val = item.GetComponent<ItemDrop>()?.m_itemData?.m_shared;
			if (val != null && !(val.m_food <= 0f))
			{
				if (!durations.TryGetValue(((Object)item).name, out var value))
				{
					float foodBurnTime = val.m_foodBurnTime;
					float num = ((foodBurnTime == 1200f) ? 1500f : foodBurnTime);
					float value2 = settings.Bind<float>("FoodDurations", ((Object)item).name, num, new ConfigDescription("Duration in seconds. Default preserves the original duration except 1200 becomes 1500. Restart after editing.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
					value = ((float.IsNaN(value2) || float.IsInfinity(value2) || value2 <= 0f) ? num : value2);
					durations.Add(((Object)item).name, value);
				}
				val.m_foodBurnTime = value;
			}
		}
	}
}