Decompiled source of Safe Beehive Looting v2.0.0

tony4twentys-Safe Beehive Looting.dll

Decompiled 2 days ago
using System;
using System.Collections;
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 Photon.Pun;
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("Safe Beehive Looting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Safe Beehive Looting")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("825daf2a-23c0-489c-b237-ebbe84d04038")]
[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")]
[BepInPlugin("tony4twentys.Safe_Beehive_looting", "Safe Beehive Looting", "2.0.0")]
public class SafeBeehiveLooting : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Item), "FinishCastPrimary")]
	private class FlareUsePatch
	{
		[HarmonyPostfix]
		private static void Postfix(Item __instance)
		{
			if (((Object)__instance).name.ToLower().Contains("flare"))
			{
				ManualLogSource logger = ((BaseUnityPlugin)instance).Logger;
				Character trueHolderCharacter = __instance.trueHolderCharacter;
				logger.LogInfo((object)("[SafeBeehiveLooting] Flare lit by: " + ((trueHolderCharacter != null) ? ((Object)trueHolderCharacter).name : null)));
				StartFlareCycle(((Component)__instance).gameObject);
			}
		}
	}

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

		private object <>2__current;

		public GameObject flare;

		public SafeBeehiveLooting <>4__this;

		private float <timer>5__1;

		private HashSet<Transform> <preSmokes>5__2;

		private IEnumerable<Transform> <newSmokes>5__3;

		private IEnumerator<Transform> <>s__4;

		private Transform <smoke>5__5;

		private Item <item>5__6;

		private bool <held>5__7;

		private IEnumerable<Transform> <rescanSmokes>5__8;

		private IEnumerator<Transform> <>s__9;

		private Transform <smoke>5__10;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<preSmokes>5__2 = null;
			<newSmokes>5__3 = null;
			<>s__4 = null;
			<smoke>5__5 = null;
			<item>5__6 = null;
			<rescanSmokes>5__8 = null;
			<>s__9 = null;
			<smoke>5__10 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<timer>5__1 = 0f;
				<>4__this.flareHeldLastFrame = false;
				<preSmokes>5__2 = new HashSet<Transform>(from t in Object.FindObjectsByType<Transform>((FindObjectsSortMode)0)
					where ((Object)t).name.Contains("VFX_FlareSmoke")
					select t);
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<newSmokes>5__3 = from t in Object.FindObjectsByType<Transform>((FindObjectsSortMode)0)
					where ((Object)t).name.Contains("VFX_FlareSmoke")
					select t;
				<>s__4 = <newSmokes>5__3.GetEnumerator();
				try
				{
					while (<>s__4.MoveNext())
					{
						<smoke>5__5 = <>s__4.Current;
						if (!<preSmokes>5__2.Contains(<smoke>5__5))
						{
							<>4__this.trackedSmokeTransform = <smoke>5__5;
							break;
						}
						<smoke>5__5 = null;
					}
				}
				finally
				{
					if (<>s__4 != null)
					{
						<>s__4.Dispose();
					}
				}
				<>s__4 = null;
				break;
			case 2:
				<>1__state = -1;
				<item>5__6 = null;
				break;
			}
			if (<timer>5__1 < 60f)
			{
				<item>5__6 = flare.GetComponent<Item>();
				if ((Object)(object)<item>5__6 != (Object)null)
				{
					<held>5__7 = (Object)(object)<item>5__6.trueHolderCharacter != (Object)null;
					if (<held>5__7 != <>4__this.flareHeldLastFrame)
					{
						<>4__this.flareHeldLastFrame = <held>5__7;
						if (!<held>5__7 && !<>4__this.hasRescannedForSmoke)
						{
							<>4__this.hasRescannedForSmoke = true;
							<rescanSmokes>5__8 = from t in Object.FindObjectsByType<Transform>((FindObjectsSortMode)0)
								where ((Object)t).name.Contains("VFX_FlareSmoke")
								select t;
							<>s__9 = <rescanSmokes>5__8.GetEnumerator();
							try
							{
								while (<>s__9.MoveNext())
								{
									<smoke>5__10 = <>s__9.Current;
									if (!<preSmokes>5__2.Contains(<smoke>5__10))
									{
										<>4__this.trackedSmokeTransform = <smoke>5__10;
										break;
									}
									<smoke>5__10 = null;
								}
							}
							finally
							{
								if (<>s__9 != null)
								{
									<>s__9.Dispose();
								}
							}
							<>s__9 = null;
							<rescanSmokes>5__8 = null;
						}
					}
				}
				<timer>5__1 += 1f;
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 2;
				return true;
			}
			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 <CheckNearbyBees>d__13 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public SafeBeehiveLooting <>4__this;

		private float <timer>5__1;

		private float <timeInRange>5__2;

		private Vector3 <smokePosition>5__3;

		private bool <swarmInRange>5__4;

		private BeeSwarm[] <>s__5;

		private int <>s__6;

		private BeeSwarm <swarm>5__7;

		private float <dist>5__8;

		private BeeSwarm[] <>s__9;

		private int <>s__10;

		private BeeSwarm <swarm>5__11;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>s__5 = null;
			<swarm>5__7 = null;
			<>s__9 = null;
			<swarm>5__11 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<timer>5__1 = 0f;
				<timeInRange>5__2 = 0f;
				break;
			case 1:
				<>1__state = -1;
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if (<timer>5__1 < 60f)
			{
				if ((Object)(object)<>4__this.trackedSmokeTransform == (Object)null)
				{
					<timer>5__1 += 1f;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				<smokePosition>5__3 = <>4__this.trackedSmokeTransform.position;
				<swarmInRange>5__4 = false;
				<>s__5 = Object.FindObjectsByType<BeeSwarm>((FindObjectsSortMode)0);
				for (<>s__6 = 0; <>s__6 < <>s__5.Length; <>s__6++)
				{
					<swarm>5__7 = <>s__5[<>s__6];
					<dist>5__8 = Vector3.Distance(((Component)<swarm>5__7).transform.position, <smokePosition>5__3);
					if (<dist>5__8 < instance.beeCheckRadiusConfig.Value)
					{
						<swarmInRange>5__4 = true;
						break;
					}
					<swarm>5__7 = null;
				}
				<>s__5 = null;
				if (<swarmInRange>5__4)
				{
					<timeInRange>5__2 += 1f;
					if (<timeInRange>5__2 >= instance.smokeProximityTimeConfig.Value)
					{
						((BaseUnityPlugin)instance).Logger.LogInfo((object)"[SafeBeehiveLooting] Dispersing bees!");
						<>s__9 = Object.FindObjectsByType<BeeSwarm>((FindObjectsSortMode)0);
						for (<>s__10 = 0; <>s__10 < <>s__9.Length; <>s__10++)
						{
							<swarm>5__11 = <>s__9[<>s__10];
							if (Vector3.Distance(((Component)<swarm>5__11).transform.position, <smokePosition>5__3) < instance.beeCheckRadiusConfig.Value)
							{
								((MonoBehaviourPun)<swarm>5__11).photonView.RPC("DisperseRPC", (RpcTarget)0, Array.Empty<object>());
							}
							<swarm>5__11 = null;
						}
						<>s__9 = null;
						StopRunningCoroutines();
						return false;
					}
				}
				else
				{
					<timeInRange>5__2 = 0f;
				}
				<timer>5__1 += 1f;
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 2;
				return true;
			}
			((BaseUnityPlugin)instance).Logger.LogInfo((object)"[SafeBeehiveLooting] Bee check coroutine completed");
			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();
		}
	}

	private static SafeBeehiveLooting instance;

	private Harmony harmony;

	private Coroutine flareCheckCoroutine;

	private Coroutine beeCheckCoroutine;

	private GameObject activeFlare;

	private Transform trackedSmokeTransform;

	private bool flareHeldLastFrame = false;

	private bool hasRescannedForSmoke = false;

	private ConfigEntry<float> beeCheckRadiusConfig;

	private ConfigEntry<float> smokeProximityTimeConfig;

	public void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		instance = this;
		harmony = new Harmony("tony4twentys.safe_beehive_looting");
		harmony.PatchAll();
		((BaseUnityPlugin)instance).Logger.LogInfo((object)"[SafeBeehiveLooting] Loaded");
		beeCheckRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BeeCheckRadius", 12f, "Distance from smoke to bees required to trigger dispersal.");
		smokeProximityTimeConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SmokeProximityTime", 3f, "Seconds smoke must remain near bees before dispersal.");
	}

	public static void StartFlareCycle(GameObject flare)
	{
		((BaseUnityPlugin)instance).Logger.LogInfo((object)"[SafeBeehiveLooting] Starting flare cycle");
		StopRunningCoroutines();
		instance.activeFlare = flare;
		instance.hasRescannedForSmoke = false;
		instance.flareCheckCoroutine = ((MonoBehaviour)instance).StartCoroutine(instance.CheckFlareHeldState(flare));
		instance.beeCheckCoroutine = ((MonoBehaviour)instance).StartCoroutine(instance.CheckNearbyBees());
	}

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

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

	private static void StopRunningCoroutines()
	{
		((BaseUnityPlugin)instance).Logger.LogInfo((object)"[SafeBeehiveLooting] Stopping all coroutines");
		if (instance.flareCheckCoroutine != null)
		{
			((MonoBehaviour)instance).StopCoroutine(instance.flareCheckCoroutine);
		}
		if (instance.beeCheckCoroutine != null)
		{
			((MonoBehaviour)instance).StopCoroutine(instance.beeCheckCoroutine);
		}
		instance.flareCheckCoroutine = null;
		instance.beeCheckCoroutine = null;
		instance.activeFlare = null;
		instance.trackedSmokeTransform = null;
		instance.hasRescannedForSmoke = false;
	}
}