Decompiled source of DefibroForEverybot v1.1.0

plugins/DefibroForEverybot/DefibroForEverybot.dll

Decompiled an hour 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 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("DefibroForEverybot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("DefibroForEverybot")]
[assembly: AssemblyTitle("DefibroForEverybot")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 DefibroForEverybot
{
	[BepInPlugin("PrincessUsa.DefibroForEverybot", "Defibro for Everybot", "1.1.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ShopManager), "ShopInitialize")]
		private static class ShopInitializePatch
		{
			private static void Prefix()
			{
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					ApplyDefibroLimits();
					if (TryGetDefibro(out var defibro))
					{
						Log.LogInfo((object)("Defibro shop settings applied: " + $"maxAmountInShop={defibro.maxAmountInShop}, " + $"maxAmount={defibro.maxAmount}, " + $"maxPurchase={defibro.maxPurchase}. " + "Vanilla shop randomization remains enabled."));
					}
				}
			}
		}

		[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
		private static class LevelGeneratorPatch
		{
			private static void Prefix()
			{
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					ApplyDefibroLimits();
				}
			}
		}

		public const string PluginGuid = "PrincessUsa.DefibroForEveryone";

		public const string PluginName = "Defibro For Everyone";

		public const string PluginVersion = "1.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> MaxDefibrosInShop;

		internal static ConfigEntry<int> MaxDefibrosInTruck;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			MaxDefibrosInShop = ((BaseUnityPlugin)this).Config.Bind<int>("Defibro", "MaxDefibrosInShop", 8, new ConfigDescription("Maximum number of Defibros that vanilla shop generation is allowed to roll in one shop. The shop remains random; this does NOT force this many to spawn.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 32), Array.Empty<object>()));
			MaxDefibrosInTruck = ((BaseUnityPlugin)this).Config.Bind<int>("Defibro", "MaxDefibrosInTruck", 32, new ConfigDescription("Maximum number of purchased Defibros allowed to carry forward into the truck.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 128), Array.Empty<object>()));
			Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "PrincessUsa.DefibroForEveryone");
			Log.LogInfo((object)"Defibro For Everyone v1.1.0 loaded.");
		}

		internal static bool TryGetDefibro(out Item defibro)
		{
			defibro = null;
			if ((Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null)
			{
				return false;
			}
			return StatsManager.instance.itemDictionary.TryGetValue("Item ReviveItem", out defibro);
		}

		internal static void ApplyDefibroLimits()
		{
			if (TryGetDefibro(out var defibro))
			{
				defibro.maxAmountInShop = MaxDefibrosInShop.Value;
				defibro.maxPurchase = false;
				defibro.maxPurchaseAmount = MaxDefibrosInShop.Value;
				defibro.maxAmount = MaxDefibrosInTruck.Value;
			}
		}
	}
}