Decompiled source of Full Belly v1.0.0

Full Belly.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("Food Saturation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Food Saturation")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("84ff8df7-f5bc-4f4c-8b12-2a6c815ccf0c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FullBellyMod;

[BepInPlugin("tony4twentys.full_belly", "Full Belly", "1.0.0")]
[BepInProcess("PEAK.exe")]
public class FullBellyPlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <ApplyFullness>d__18 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CharacterAfflictions afflictions;

		public FullBellyPlugin <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ApplyFullness>d__18(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>4__this.isFull = true;
				<>4__this.originalHungerPerSecond = afflictions.hungerPerSecond;
				afflictions.hungerPerSecond = 0f;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Full Belly active for {<>4__this.fullnessDuration} seconds. Hunger gain paused.");
				<>2__current = (object)new WaitForSeconds(<>4__this.fullnessDuration);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				afflictions.hungerPerSecond = <>4__this.originalHungerPerSecond;
				<>4__this.isFull = false;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Full Belly expired. Hunger gain restored.");
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <MonitorHungerRoutine>d__17 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public FullBellyPlugin <>4__this;

		private Character <character>5__1;

		private float <currentHunger>5__2;

		private float <hungerChange>5__3;

		private float <intended>5__4;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <MonitorHungerRoutine>d__17(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<character>5__1 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				<>4__this.timeSinceLastRestore += 0.5f;
				<character>5__1 = Character.localCharacter;
				if ((Object)(object)<character>5__1 == (Object)null || <character>5__1.refs == null || (Object)(object)<character>5__1.refs.afflictions == (Object)null)
				{
					break;
				}
				<currentHunger>5__2 = <character>5__1.refs.afflictions.GetCurrentStatus((STATUSTYPE)1);
				<hungerChange>5__3 = <>4__this.lastHunger - <currentHunger>5__2;
				if (<hungerChange>5__3 > 0.001f)
				{
					<>4__this.hungerRestoreAccumulator += <hungerChange>5__3;
					<>4__this.timeSinceLastRestore = 0f;
					<>4__this.hasLoggedReset = false;
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Hunger restored: {<hungerChange>5__3 * 100f:0.00}%, Total accumulated: {<>4__this.hungerRestoreAccumulator * 100f:0.00}%");
				}
				while (<>4__this.restoreIntents.Count > 0)
				{
					<intended>5__4 = <>4__this.restoreIntents.Dequeue();
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Intended hunger restoration detected: {<intended>5__4 * 100f:0.00}%");
					if (<intended>5__4 >= <>4__this.fullnessThreshold)
					{
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Intended fullness reached. Applying Full Belly.");
						if (<>4__this.fullnessCoroutine != null)
						{
							((MonoBehaviour)<>4__this).StopCoroutine(<>4__this.fullnessCoroutine);
							((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Existing Full Belly timer reset.");
						}
						<>4__this.fullnessCoroutine = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.ApplyFullness(<character>5__1.refs.afflictions));
						<>4__this.hungerRestoreAccumulator = 0f;
						<>4__this.timeSinceLastRestore = 0f;
						<>4__this.hasLoggedReset = false;
					}
					else
					{
						<>4__this.hungerRestoreAccumulator += <intended>5__4;
						<>4__this.timeSinceLastRestore = 0f;
						<>4__this.hasLoggedReset = false;
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Accumulated {<intended>5__4 * 100f:0.00}%. New total: {<>4__this.hungerRestoreAccumulator * 100f:0.00}%");
					}
				}
				if (<>4__this.hungerRestoreAccumulator >= <>4__this.fullnessThreshold)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Fullness threshold reached by accumulation. Applying Full Belly.");
					if (<>4__this.fullnessCoroutine != null)
					{
						((MonoBehaviour)<>4__this).StopCoroutine(<>4__this.fullnessCoroutine);
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Existing Full Belly timer reset.");
					}
					<>4__this.fullnessCoroutine = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.ApplyFullness(<character>5__1.refs.afflictions));
					<>4__this.hungerRestoreAccumulator = 0f;
					<>4__this.timeSinceLastRestore = 0f;
					<>4__this.hasLoggedReset = false;
				}
				if (<>4__this.timeSinceLastRestore >= <>4__this.accumulationWindow && !<>4__this.hasLoggedReset)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Accumulation window expired. Resetting accumulator.");
					<>4__this.hungerRestoreAccumulator = 0f;
					<>4__this.hasLoggedReset = true;
				}
				<>4__this.lastHunger = <currentHunger>5__2;
				<character>5__1 = null;
				break;
			}
			<>2__current = (object)new WaitForSeconds(0.5f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private float lastHunger;

	private float hungerRestoreAccumulator = 0f;

	private float timeSinceLastRestore = 0f;

	private float accumulationWindow;

	private float fullnessThreshold;

	private float fullnessDuration;

	private bool isFull = false;

	private float originalHungerPerSecond = 0.0005f;

	private Coroutine fullnessCoroutine;

	private bool hasLoggedReset = false;

	private Queue<float> restoreIntents = new Queue<float>();

	private ConfigEntry<float> cfgFullnessDuration;

	private ConfigEntry<float> cfgAccumulationWindow;

	private ConfigEntry<float> cfgFullnessThreshold;

	private void Awake()
	{
		cfgFullnessDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Full Belly", "FullnessDuration", 300f, "Duration in seconds that hunger is paused after reaching fullness.");
		cfgAccumulationWindow = ((BaseUnityPlugin)this).Config.Bind<float>("Full Belly", "AccumulationWindow", 120f, "Time window in seconds to accumulate small hunger restorations.");
		cfgFullnessThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Full Belly", "FullnessThreshold", 0.25f, "Total hunger restoration percentage needed to trigger fullness.");
		fullnessDuration = cfgFullnessDuration.Value;
		accumulationWindow = cfgAccumulationWindow.Value;
		fullnessThreshold = cfgFullnessThreshold.Value;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Full Belly mod started.");
		((MonoBehaviour)this).StartCoroutine(MonitorHungerRoutine());
	}

	private void Update()
	{
		Item[] array = Object.FindObjectsOfType<Item>();
		foreach (Item val in array)
		{
			if ((Object)(object)((Component)val).gameObject.GetComponent<FoodLoggerComponent>() == (Object)null)
			{
				((Component)val).gameObject.AddComponent<FoodLoggerComponent>().Initialize(((BaseUnityPlugin)this).Logger, EnqueueIntendedRestore);
			}
		}
	}

	private void EnqueueIntendedRestore(float intendedRestore)
	{
		restoreIntents.Enqueue(intendedRestore);
	}

	[IteratorStateMachine(typeof(<MonitorHungerRoutine>d__17))]
	private IEnumerator MonitorHungerRoutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <MonitorHungerRoutine>d__17(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<ApplyFullness>d__18))]
	private IEnumerator ApplyFullness(CharacterAfflictions afflictions)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ApplyFullness>d__18(0)
		{
			<>4__this = this,
			afflictions = afflictions
		};
	}
}
public class FoodLoggerComponent : MonoBehaviour
{
	private ManualLogSource logger;

	private bool hooked = false;

	private Action<float> onIntendedRestore;

	public void Initialize(ManualLogSource log, Action<float> onRestore)
	{
		logger = log;
		onIntendedRestore = onRestore;
	}

	private void Start()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Invalid comparison between Unknown and I4
		if (hooked)
		{
			return;
		}
		hooked = true;
		Item item = ((Component)this).GetComponent<Item>();
		if ((Object)(object)item == (Object)null)
		{
			return;
		}
		ItemAction[] components = ((Component)this).GetComponents<ItemAction>();
		ItemAction[] array = components;
		foreach (ItemAction val in array)
		{
			Action_ModifyStatus val2 = (Action_ModifyStatus)(object)((val is Action_ModifyStatus) ? val : null);
			if (val2 != null && (int)val2.statusType == 1)
			{
				float intended2 = Mathf.Abs(val2.changeAmount);
				Item obj = item;
				obj.OnPrimaryFinishedCast = (Action)Delegate.Combine(obj.OnPrimaryFinishedCast, (Action)delegate
				{
					logger.LogInfo((object)$"Consumed item: {((Object)item).name}, restores hunger: {intended2 * 100f:0.00}% (ModifyStatus)");
					onIntendedRestore?.Invoke(intended2);
				});
				continue;
			}
			Action_RestoreHunger val3 = (Action_RestoreHunger)(object)((val is Action_RestoreHunger) ? val : null);
			if (val3 != null)
			{
				float intended = Mathf.Abs(val3.restorationAmount);
				Item obj2 = item;
				obj2.OnPrimaryFinishedCast = (Action)Delegate.Combine(obj2.OnPrimaryFinishedCast, (Action)delegate
				{
					logger.LogInfo((object)$"Consumed item: {((Object)item).name}, restores hunger: {intended * 100f:0.00}% (RestoreHunger)");
					onIntendedRestore?.Invoke(intended);
				});
			}
		}
	}
}