Decompiled source of Self to Shelf v1.0.2

tony4twentys-Self To Shelf.dll

Decompiled 3 months 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 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("Self To Shelf")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Self To Shelf")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e8ea1f77-f217-4354-81c5-cbe5a7eb2cdd")]
[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.Self_To_Shelf", "Self to Shelf", "1.0.0")]
public class SelfToShelf : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <CheckForShelfSpawns>d__7 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public SelfToShelf <>4__this;

		private List<Transform> <spawns>5__1;

		private List<Transform>.Enumerator <>s__2;

		private Transform <spawn>5__3;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<spawns>5__1 = null;
			<>s__2 = default(List<Transform>.Enumerator);
			<spawn>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				<spawns>5__1 = null;
				break;
			}
			<spawns>5__1 = (from t in Object.FindObjectsByType<Transform>((FindObjectsSortMode)0)
				where ((Object)t).name.Contains("ShelfShroomSpawn")
				select t).ToList();
			<>s__2 = <spawns>5__1.GetEnumerator();
			try
			{
				while (<>s__2.MoveNext())
				{
					<spawn>5__3 = <>s__2.Current;
					if (!<>4__this.excludedSpawns.Contains(<spawn>5__3) && !<>4__this.permanentlyIgnoredSpawns.Contains(<spawn>5__3))
					{
						<>4__this.excludedSpawns.Add(<spawn>5__3);
						<>4__this.permanentlyIgnoredSpawns.Add(<spawn>5__3);
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"New ShelfShroomSpawn detected, teleporting player to: {<spawn>5__3.position}");
						<>4__this.TeleportAbove(<spawn>5__3.position);
						<>4__this.StopTracking();
						return false;
					}
					<spawn>5__3 = null;
				}
			}
			finally
			{
				((IDisposable)<>s__2).Dispose();
			}
			<>s__2 = default(List<Transform>.Enumerator);
			<>2__current = (object)new WaitForSeconds(1f);
			<>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();
		}
	}

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

		private object <>2__current;

		public SelfToShelf <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				goto IL_0052;
			case 1:
				<>1__state = -1;
				goto IL_0052;
			case 2:
				{
					<>1__state = -1;
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Cooldown over. Stopping coroutines.");
					<>4__this.StopTracking();
					return false;
				}
				IL_0052:
				if ((Object)(object)Character.localCharacter.data.currentItem != (Object)null && ((Object)Character.localCharacter.data.currentItem).name.Contains("ShelfShroom"))
				{
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Item dropped, starting 10-second cooldown.");
				<>2__current = (object)new WaitForSeconds(10f);
				<>1__state = 2;
				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 readonly List<Transform> excludedSpawns = new List<Transform>();

	private readonly List<Transform> permanentlyIgnoredSpawns = new List<Transform>();

	private Coroutine shelfCoroutine;

	private Coroutine dropMonitorCoroutine;

	private bool isWatching;

	private void Update()
	{
		Character localCharacter = Character.localCharacter;
		if (!((Object)(object)localCharacter == (Object)null) && !((Object)(object)localCharacter.data == (Object)null) && localCharacter.IsLocal)
		{
			Item currentItem = localCharacter.data.currentItem;
			if (!((Object)(object)currentItem == (Object)null) && !isWatching && ((Object)currentItem).name.Contains("ShelfShroom"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"ShelfShroom held, starting coroutines.");
				isWatching = true;
				BuildInitialExclusionList();
				shelfCoroutine = ((MonoBehaviour)this).StartCoroutine(CheckForShelfSpawns());
				dropMonitorCoroutine = ((MonoBehaviour)this).StartCoroutine(MonitorItemHeld());
			}
		}
	}

	private void BuildInitialExclusionList()
	{
		excludedSpawns.Clear();
		IEnumerable<Transform> enumerable = from t in Object.FindObjectsByType<Transform>((FindObjectsSortMode)0)
			where ((Object)t).name.Contains("ShelfShroomSpawn")
			select t;
		foreach (Transform item in enumerable)
		{
			excludedSpawns.Add(item);
		}
	}

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

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

	private void StopTracking()
	{
		if (shelfCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(shelfCoroutine);
		}
		if (dropMonitorCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(dropMonitorCoroutine);
		}
		shelfCoroutine = null;
		dropMonitorCoroutine = null;
		isWatching = false;
	}

	private void TeleportAbove(Vector3 position)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(0f, 2f, 0f);
		Character localCharacter = Character.localCharacter;
		if ((Object)(object)localCharacter != (Object)null && localCharacter.refs != null && (Object)(object)localCharacter.refs.view != (Object)null)
		{
			Vector3 val2 = position + val;
			localCharacter.refs.view.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { val2, false });
			Character[] array = Object.FindObjectsByType<Character>((FindObjectsSortMode)0);
			foreach (Character val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3 == (Object)(object)localCharacter) && !((Object)(object)val3.data == (Object)null) && !val3.data.dead)
				{
					float num = Vector3.Distance(((Component)localCharacter).transform.position, ((Component)val3).transform.position);
					if (num <= 6f && val3.refs != null && (Object)(object)val3.refs.view != (Object)null)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)"Pulling nearby ally into ShelfShroom teleport!");
						val3.refs.view.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { val2, false });
					}
				}
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Unable to teleport — character or view is null.");
		}
	}
}