Decompiled source of AutoEat v1.1.0

plugins/gaakrin.autoeat/AutoEat.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("AutoEat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoEat")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5a5e412-54df-4af1-aabd-09a17d5cc70d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("gaakrin.autoeat", "AutoEat", "1.1.0")]
public class AutoEat : BaseUnityPlugin
{
	private ConfigEntry<bool> enableAutoEat;

	private float autoEatCountdown = 0f;

	private bool hasShown = false;

	private void Awake()
	{
		enableAutoEat = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAutoEat", true, "Enable/disable AutoEat");
	}

	private void Update()
	{
		if (!enableAutoEat.Value)
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		foreach (Food food in localPlayer.GetFoods())
		{
			if (food.CanEatAgain())
			{
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				ItemData item = inventory.GetItem(food.m_item.m_shared.m_name, -1, false);
				if (item == null)
				{
					break;
				}
				if (!hasShown)
				{
					MessageHud.instance.ShowMessage((MessageType)2, "Auto eating in 5 mins", 0, (Sprite)null, false);
					hasShown = true;
				}
				autoEatCountdown += Time.deltaTime;
				if (autoEatCountdown < 300f)
				{
					break;
				}
				autoEatCountdown = 0f;
				hasShown = false;
				((Humanoid)localPlayer).ConsumeItem(inventory, item, false);
			}
		}
	}
}