Decompiled source of DestroyItemInSlotFix v1.0.0

BepInEx/plugins/DestroyItemInSlotFix.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DestroyItemInSlotFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DestroyItemInSlotFix")]
[assembly: AssemblyTitle("DestroyItemInSlotFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 DestroyItemInSlotFix
{
	[BepInPlugin("JacobG5.DestroyItemInSlotFix", "DestroyItemInSlotFix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <FindObjectTranspiler>d__6 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private MethodBase original;

			public MethodBase <>3__original;

			private MethodInfo <getHudManager>5__1;

			private FieldInfo <itemSlotIcons>5__2;

			private MethodInfo <setBehaviorEnabled>5__3;

			private MethodInfo <replacement>5__4;

			private int <found>5__5;

			private List<CodeInstruction> <matches>5__6;

			private int <maxMatch>5__7;

			private IEnumerator<CodeInstruction> <>s__8;

			private CodeInstruction <instruction>5__9;

			private int <>s__10;

			private CodeInstruction <first>5__11;

			private List<CodeInstruction>.Enumerator <>s__12;

			private CodeInstruction <match>5__13;

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

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

			[DebuggerHidden]
			public <FindObjectTranspiler>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if ((uint)(num - -4) <= 1u || (uint)(num - 1) <= 3u)
				{
					try
					{
						if (num == -4 || num == 3)
						{
							try
							{
							}
							finally
							{
								<>m__Finally2();
							}
						}
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<getHudManager>5__1 = null;
				<itemSlotIcons>5__2 = null;
				<setBehaviorEnabled>5__3 = null;
				<replacement>5__4 = null;
				<matches>5__6 = null;
				<>s__8 = null;
				<instruction>5__9 = null;
				<first>5__11 = null;
				<>s__12 = default(List<CodeInstruction>.Enumerator);
				<match>5__13 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ee: Expected O, but got Unknown
				//IL_028a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<getHudManager>5__1 = AccessTools.Method(typeof(HUDManager), "get_Instance", (Type[])null, (Type[])null);
						<itemSlotIcons>5__2 = AccessTools.Field(typeof(HUDManager), "itemSlotIcons");
						<setBehaviorEnabled>5__3 = AccessTools.Method(typeof(Behaviour), "set_enabled", (Type[])null, (Type[])null);
						<replacement>5__4 = AccessTools.Method(typeof(Plugin), "UpdateSlotIcons", (Type[])null, (Type[])null);
						<found>5__5 = 0;
						<matches>5__6 = new List<CodeInstruction>();
						<maxMatch>5__7 = 0;
						<>s__8 = instructions.GetEnumerator();
						<>1__state = -3;
						goto IL_03e2;
					case 1:
						<>1__state = -3;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)<replacement>5__4);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -3;
						<matches>5__6.Clear();
						<first>5__11 = null;
						goto IL_03da;
					case 3:
						<>1__state = -4;
						<match>5__13 = null;
						goto IL_038d;
					case 4:
						{
							<>1__state = -3;
							goto IL_03da;
						}
						IL_03e2:
						if (<>s__8.MoveNext())
						{
							<instruction>5__9 = <>s__8.Current;
							<>s__10 = <matches>5__6.Count;
							if (1 == 0)
							{
							}
							bool flag = <>s__10 switch
							{
								0 => <instruction>5__9.opcode == OpCodes.Call && CodeInstructionExtensions.Calls(<instruction>5__9, <getHudManager>5__1), 
								1 => <instruction>5__9.opcode == OpCodes.Ldfld && CodeInstructionExtensions.LoadsField(<instruction>5__9, <itemSlotIcons>5__2, false), 
								2 => <instruction>5__9.opcode == OpCodes.Ldarg_1, 
								3 => <instruction>5__9.opcode == OpCodes.Ldelem_Ref, 
								4 => <instruction>5__9.opcode == OpCodes.Ldc_I4_0, 
								5 => <instruction>5__9.opcode == OpCodes.Callvirt && CodeInstructionExtensions.Calls(<instruction>5__9, <setBehaviorEnabled>5__3), 
								_ => false, 
							};
							if (1 == 0)
							{
							}
							if (flag)
							{
								<matches>5__6.Add(<instruction>5__9);
								<maxMatch>5__7 = Mathf.Max(<matches>5__6.Count, <maxMatch>5__7);
								if (<matches>5__6.Count >= 6)
								{
									<found>5__5++;
									<first>5__11 = new CodeInstruction(OpCodes.Ldarg_1, (object)null);
									<first>5__11.labels.AddRange(<matches>5__6[0].labels);
									<>2__current = <first>5__11;
									<>1__state = 1;
									return true;
								}
								goto IL_03da;
							}
							if (<matches>5__6.Count > 0)
							{
								<>s__12 = <matches>5__6.GetEnumerator();
								<>1__state = -4;
								goto IL_038d;
							}
							goto IL_03ba;
						}
						<>m__Finally1();
						<>s__8 = null;
						mls.LogInfo((object)$"found {<found>5__5} in {original.DeclaringType.FullName} | {<maxMatch>5__7}");
						return false;
						IL_038d:
						if (<>s__12.MoveNext())
						{
							<match>5__13 = <>s__12.Current;
							<>2__current = <match>5__13;
							<>1__state = 3;
							return true;
						}
						<>m__Finally2();
						<>s__12 = default(List<CodeInstruction>.Enumerator);
						<matches>5__6.Clear();
						goto IL_03ba;
						IL_03ba:
						<>2__current = <instruction>5__9;
						<>1__state = 4;
						return true;
						IL_03da:
						<instruction>5__9 = null;
						goto IL_03e2;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__8 != null)
				{
					<>s__8.Dispose();
				}
			}

			private void <>m__Finally2()
			{
				<>1__state = -3;
				((IDisposable)<>s__12).Dispose();
			}

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

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<FindObjectTranspiler>d__6 <FindObjectTranspiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<FindObjectTranspiler>d__ = this;
				}
				else
				{
					<FindObjectTranspiler>d__ = new <FindObjectTranspiler>d__6(0);
				}
				<FindObjectTranspiler>d__.instructions = <>3__instructions;
				<FindObjectTranspiler>d__.original = <>3__original;
				return <FindObjectTranspiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		private const string modGUID = "JacobG5.DestroyItemInSlotFix";

		private const string modName = "DestroyItemInSlotFix";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("JacobG5.DestroyItemInSlotFix");

		private static ManualLogSource mls;

		public void Awake()
		{
			mls = Logger.CreateLogSource("JacobG5.DestroyItemInSlotFix");
			harmony.PatchAll(typeof(Plugin));
		}

		[IteratorStateMachine(typeof(<FindObjectTranspiler>d__6))]
		[HarmonyPatch(typeof(PlayerControllerB), "DestroyItemInSlot")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> FindObjectTranspiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FindObjectTranspiler>d__6(-2)
			{
				<>3__instructions = instructions,
				<>3__original = original
			};
		}

		public static void UpdateSlotIcons(int itemSlot)
		{
			if (itemSlot == 50)
			{
				((Behaviour)HUDManager.Instance.itemOnlySlotIcon).enabled = false;
			}
			else
			{
				((Behaviour)HUDManager.Instance.itemSlotIcons[itemSlot]).enabled = false;
			}
		}
	}
}