Decompiled source of IntuitiveKeys BepInEx v1.0.0

IntuitiveKeys-BepinEx.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Actors.Player;
using Assets.Scripts.Inventory__Items__Pickups;
using Assets.Scripts.Inventory__Items__Pickups.Items;
using Assets.Scripts.Inventory__Items__Pickups.Items.ItemImplementations;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("IntuitiveKeys-BepinEx")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Intuitive Keys BepinEx")]
[assembly: AssemblyTitle("IntuitiveKeys-BepinEx")]
[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 BepinKeys
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "IntuitiveKeys-BepinEx";

		public const string PLUGIN_NAME = "Intuitive Keys BepinEx";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace IntuitiveKeys
{
	[BepInPlugin("com.twinzet.intuitivekeys", "IntuitiveKeys", "1.0.0")]
	public class Core : BasePlugin
	{
		[HarmonyPatch(typeof(ItemKey), "OnInitOrAmountChanged")]
		public static class KeyPatch
		{
			private static ItemData storedKeyItem;

			[HarmonyPostfix]
			public static void Postfix(ItemKey __instance)
			{
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				if (__instance == null)
				{
					return;
				}
				try
				{
					MyPlayer instance = MyPlayer.Instance;
					object obj;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						PlayerInventory inventory = instance.inventory;
						obj = ((inventory != null) ? inventory.itemInventory : null);
					}
					ItemInventory val = (ItemInventory)obj;
					if (val == null)
					{
						return;
					}
					int amount = val.GetAmount((EItem)0);
					List<ItemData> val2 = default(List<ItemData>);
					if (!RunUnlockables.availableItems.TryGetValue((EItemRarity)0, ref val2) || val2 == null)
					{
						return;
					}
					if ((Object)(object)storedKeyItem == (Object)null)
					{
						for (int i = 0; i < val2.Count; i++)
						{
							if ((int)val2[i].eItem == 0)
							{
								storedKeyItem = val2[i];
								break;
							}
						}
					}
					if (amount >= 10)
					{
						if ((Object)(object)storedKeyItem != (Object)null && val2.Contains(storedKeyItem))
						{
							val2.Remove(storedKeyItem);
							((BasePlugin)Instance).Log.LogInfo((object)"10 keys reached! Keys removed from loot pool.");
						}
						__instance.currentChance = 1f;
					}
					else
					{
						__instance.currentChance = (float)amount * 0.1f;
						if ((Object)(object)storedKeyItem != (Object)null && !val2.Contains(storedKeyItem))
						{
							val2.Add(storedKeyItem);
							((BasePlugin)Instance).Log.LogInfo((object)"Keys added back to loot pool.");
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = ((BasePlugin)Instance).Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(30, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to apply chance logic: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
					}
					log.LogError(val3);
				}
			}
		}

		public static Core Instance;

		private Harmony _harmony;

		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Instance = this;
			_harmony = new Harmony("com.twinzet.intuitivekeys");
			_harmony.PatchAll();
			((BasePlugin)this).Log.LogInfo((object)"IntuitiveKeys Initialized.");
		}
	}
}