Decompiled source of UnchainedIndestructibles v0.1.0

UnchainedIndestructibles.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UnchainedIndestructibles")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+7fea4ac47027cf96089307b0e903d454c14f4530")]
[assembly: AssemblyProduct("UnchainedIndestructibles")]
[assembly: AssemblyTitle("UnchainedIndestructibles")]
[assembly: AssemblyVersion("0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 UnchainedIndestructibles
{
	internal static class Config
	{
		internal static ConfigEntry<int> MaxAmount;

		internal static ConfigEntry<int> MaxAmountInShop;

		internal static void Bind(ConfigFile config)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			AcceptableValueRange<int> val = new AcceptableValueRange<int>(1, 99);
			MaxAmount = config.Bind<int>("IndestructibleDrone", "MaxAmount", 10, new ConfigDescription("Maximum number of Indestructible Drones the host can carry into a run from purchased inventory. Vanilla is 1.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			MaxAmountInShop = config.Bind<int>("IndestructibleDrone", "MaxAmountInShop", 3, new ConfigDescription("Maximum number of Indestructible Drones the host's shop can spawn per refresh. Vanilla is 1.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
		}
	}
	internal static class DroneItem
	{
		private static Item? _cached;

		private static StatsManager? _cachedStats;

		private static bool _missingWarned;

		internal static Item? Resolve()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			StatsManager instance = StatsManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			if (instance != _cachedStats)
			{
				_cached = null;
				_cachedStats = instance;
				_missingWarned = false;
			}
			if ((Object)(object)_cached != (Object)null)
			{
				return _cached;
			}
			foreach (Item value in instance.itemDictionary.Values)
			{
				if ((Object)(object)value != (Object)null && (int)value.emojiIcon == 2)
				{
					_cached = value;
					break;
				}
			}
			if ((Object)(object)_cached == (Object)null && !_missingWarned)
			{
				Plugin.Log.LogWarning((object)"Indestructible Drone item not found in StatsManager.itemDictionary — mod is inert.");
				_missingWarned = true;
			}
			return _cached;
		}
	}
	[BepInPlugin("darkharasho.UnchainedIndestructibles", "UnchainedIndestructibles", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Config.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("darkharasho.UnchainedIndestructibles").PatchAll();
			Log.LogInfo((object)"UnchainedIndestructibles v0.1.0 loaded.");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "darkharasho.UnchainedIndestructibles";

		public const string PLUGIN_NAME = "UnchainedIndestructibles";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace UnchainedIndestructibles.Patches
{
	[HarmonyPatch(typeof(ItemManager), "GetPurchasedItems")]
	internal static class ItemManager_GetPurchasedItems_Patch
	{
		private static Item? _drone;

		private static int _originalMaxAmount;

		private static bool _restorePending;

		public static void Prefix()
		{
			_restorePending = false;
			_drone = DroneItem.Resolve();
			if (!((Object)(object)_drone == (Object)null))
			{
				_originalMaxAmount = _drone.maxAmount;
				_drone.maxAmount = Config.MaxAmount.Value;
				_restorePending = true;
			}
		}

		public static void Finalizer()
		{
			if (_restorePending && !((Object)(object)_drone == (Object)null))
			{
				_drone.maxAmount = _originalMaxAmount;
				_restorePending = false;
				_drone = null;
			}
		}
	}
	[HarmonyPatch(typeof(ShopManager), "GetAllItemsFromStatsManager")]
	internal static class ShopManager_GetAllItemsFromStatsManager_Patch
	{
		private static Item? _drone;

		private static int _originalMaxAmountInShop;

		private static bool _restorePending;

		public static void Prefix()
		{
			_restorePending = false;
			_drone = DroneItem.Resolve();
			if (!((Object)(object)_drone == (Object)null))
			{
				_originalMaxAmountInShop = _drone.maxAmountInShop;
				_drone.maxAmountInShop = Config.MaxAmountInShop.Value;
				_restorePending = true;
			}
		}

		public static void Finalizer()
		{
			if (_restorePending && !((Object)(object)_drone == (Object)null))
			{
				_drone.maxAmountInShop = _originalMaxAmountInShop;
				_restorePending = false;
				_drone = null;
			}
		}
	}
}