Decompiled source of PocketHammer v1.1.0

BepInEx/plugins/PocketHammer/PocketHammer.dll

Decompiled 14 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("PocketHammer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PocketHammer")]
[assembly: AssemblyTitle("PocketHammer")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PocketHammer
{
	[BepInPlugin("BetaTester704-PocketHammer", "PocketHammer", "1.1.0")]
	public class PocketHammerPlugin : BaseUnityPlugin
	{
		public enum PocketSide
		{
			Left,
			Right
		}

		public const string PluginGuid = "BetaTester704-PocketHammer";

		public const string PluginName = "PocketHammer";

		public const string PluginVersion = "1.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<PocketSide> DesiredPocket;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			DesiredPocket = ((BaseUnityPlugin)this).Config.Bind<PocketSide>("PocketHammer", "DesiredPocket", PocketSide.Left, "Which Pocket the Hammer Spawns in at the Start of your run");
			harmony = new Harmony("BetaTester704-PocketHammer");
			harmony.Patch((MethodBase)AccessTools.Method(typeof(CL_GameManager), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(PocketHammerPlugin), "CL_GameManager_Start_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)"PocketHammer loaded");
		}

		private static void CL_GameManager_Start_Postfix()
		{
			PocketHammerUTIL.RequestPocketHammer();
		}
	}
	public class PocketHammerUTIL : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <TryPocketHammerForTwoSeconds>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PocketHammerUTIL <>4__this;

			private int <i>5__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				int num = <>1__state;
				PocketHammerUTIL pocketHammerUTIL = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<i>5__2 = 0;
					break;
				case 1:
					<>1__state = -1;
					<i>5__2++;
					break;
				}
				if (<i>5__2 < 8 && !pocketHammerUTIL.TryPocketHammer())
				{
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 1;
					return true;
				}
				pocketHammerUTIL.retryCoroutine = null;
				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 PocketHammerUTIL instance;

		private Inventory lastInventory;

		private bool movedThisLoad;

		private Coroutine retryCoroutine;

		public static void RequestPocketHammer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if ((Object)(object)instance == (Object)null)
			{
				GameObject val = new GameObject("PocketHammerUTIL")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)val);
				instance = val.AddComponent<PocketHammerUTIL>();
			}
			instance.StartPocketHammerAttempt();
		}

		private void StartPocketHammerAttempt()
		{
			if (retryCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(retryCoroutine);
			}
			retryCoroutine = ((MonoBehaviour)this).StartCoroutine(TryPocketHammerForTwoSeconds());
		}

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

		private bool TryPocketHammer()
		{
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			Inventory val = (((Object)(object)Inventory.instance != (Object)null) ? Inventory.instance : ENT_Player.GetInventory());
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (val != lastInventory)
			{
				lastInventory = val;
				movedThisLoad = false;
			}
			if (movedThisLoad)
			{
				return true;
			}
			val.RescanInventory();
			Item val2 = null;
			int num = 0;
			while (val.bagItems != null && num < val.bagItems.Count)
			{
				Item val3 = val.bagItems[num];
				if (val3 != null && val3.itemTags != null)
				{
					for (int i = 0; i < val3.itemTags.Count; i++)
					{
						if (string.Equals(val3.itemTags[i], "hammer", StringComparison.OrdinalIgnoreCase))
						{
							val2 = val3;
							break;
						}
					}
					if (val2 != null)
					{
						break;
					}
				}
				num++;
			}
			if (val2 == null || !val2.pocketable)
			{
				return false;
			}
			int num2 = ((PocketHammerPlugin.DesiredPocket.Value != PocketHammerPlugin.PocketSide.Left) ? 1 : 0);
			Pocket val4 = null;
			for (int j = 0; j < val.pockets.Count; j++)
			{
				if (val.pockets[j] != null && val.pockets[j].targetHandID == num2)
				{
					val4 = val.pockets[j];
					break;
				}
			}
			if (val4 == null || (Object)(object)val4.item != (Object)null)
			{
				return false;
			}
			Item_Object dropObject = val2.GetDropObject(true);
			if ((Object)(object)dropObject == (Object)null)
			{
				return false;
			}
			Transform transform = ((Component)dropObject).transform;
			Vector3 localPosition = val4.transform.localPosition;
			transform.localPosition = ((Vector3)(ref localPosition)).normalized * 1.6f;
			((Component)dropObject).transform.localScale = Vector3.one * val2.inventoryScale * 0.8f;
			val2.bagPosition = ((Component)dropObject).transform.localPosition;
			val2.bagRotation = ((Component)dropObject).transform.localRotation;
			val4.item = dropObject;
			val.CalculateEncumberance();
			movedThisLoad = true;
			PocketHammerPlugin.Log.LogInfo((object)("Hammer moved to " + PocketHammerPlugin.DesiredPocket.Value.ToString() + " pocket"));
			return true;
		}
	}
}