Decompiled source of InstantChests v1.0.1

InstantChests.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppAssets.Scripts.UI.InGame.Rewards;
using InstantChests;
using MelonLoader;
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: MelonInfo(typeof(Core), "InstantChests", "1.0.0", "Wooshibou", null)]
[assembly: MelonGame("Ved", "Megabonk")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("InstantChests")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InstantChests")]
[assembly: AssemblyTitle("InstantChests")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 InstantChests
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(ChestWindowUi), "Open", new Type[] { typeof(EEncounter) })]
		private static class Patch_ClickOnOpen
		{
			private static void Postfix(ChestWindowUi __instance)
			{
				__instance.OpenButton();
				currentChestWindowUiInstance = __instance;
			}
		}

		[HarmonyPatch(typeof(ChestWindowUi), "ShowOpenButton")]
		private static class Patch_ShowOpenButton
		{
			private static bool Prefix()
			{
				return false;
			}
		}

		[HarmonyPatch(typeof(ChestOpening), "OpenChest", new Type[] { typeof(ItemData) })]
		private static class Patch_OpenChest
		{
			[CompilerGenerated]
			private sealed class <DelayedOpening>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public ChestOpening __instance;

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

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

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

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

				private bool MoveNext()
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = null;
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						if ((Object)(object)currentChestWindowUiInstance == (Object)null)
						{
							Melon<Core>.Logger.Warning("ChestWindowUi is null — skipping first chest.");
							return false;
						}
						if ((Object)(object)__instance.itemData == (Object)null)
						{
							Melon<Core>.Logger.Warning("ItemData is null — skipping OpeningFinished.");
							return false;
						}
						currentChestWindowUiInstance.itemData = __instance.itemData;
						currentChestWindowUiInstance.OpeningFinished(__instance.itemData);
						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 void Postfix(ChestOpening __instance, ItemData itemData)
			{
				__instance.skipped = true;
				__instance.spinning = false;
				__instance.timeBetweenTiers = 0.01f;
				MelonCoroutines.Start(DelayedOpening(__instance));
			}

			[IteratorStateMachine(typeof(<DelayedOpening>d__1))]
			private static IEnumerator DelayedOpening(ChestOpening __instance)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <DelayedOpening>d__1(0)
				{
					__instance = __instance
				};
			}
		}

		private static ChestWindowUi currentChestWindowUiInstance;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}
	}
}