Decompiled source of ItemMultiplierBis v0.1.0

plugins/com.github.Wesmania.ItemMultiplierBis.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
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;
using pworld.Scripts.Extensions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Wesmania.ItemMultiplierBis")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+f6df70d5aa73ebb78c6e816d3a9dae0c58637080")]
[assembly: AssemblyProduct("com.github.Wesmania.ItemMultiplierBis")]
[assembly: AssemblyTitle("ItemMultiplierBis")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ItemMultiplierBis
{
	[BepInPlugin("com.github.Wesmania.ItemMultiplierBis", "ItemMultiplierBis", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(BerryBush))]
		public class BerryBushPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPrefix(BerryBush __instance, ref List<Transform> spawnSpots, out Vector2 __state)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				__state = __instance.possibleBerries;
				if (BerryBushes.Value)
				{
					multiplySpawnRange(ref __instance.possibleBerries, ref spawnSpots, out __state);
					Vector2 possibleBerries = __instance.possibleBerries;
					Log.LogInfo((object)$"Berry bush would spawn {__state.x}-{__state.y} berries, multiplied to {possibleBerries.x}-{possibleBerries.y}.");
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPostfix(BerryBush __instance, List<Transform> spawnSpots, Vector2 __state)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (BerryBushes.Value)
				{
					__instance.possibleBerries = __state;
				}
			}
		}

		[HarmonyPatch(typeof(BerryVine))]
		public class BerryVinePatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPrefix(BerryVine __instance, ref List<Transform> spawnSpots, out Vector2 __state)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				__state = __instance.possibleBerries;
				if (BerryVines.Value)
				{
					multiplySpawnRange(ref __instance.possibleBerries, ref spawnSpots, out __state);
					Vector2 possibleBerries = __instance.possibleBerries;
					Log.LogInfo((object)$"Berry vine would spawn {__state.x}-{__state.y} berries, multiplied to {possibleBerries.x}-{possibleBerries.y}.");
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPostfix(BerryVine __instance, List<Transform> spawnSpots, Vector2 __state)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (BerryVines.Value)
				{
					__instance.possibleBerries = __state;
				}
			}
		}

		[HarmonyPatch(typeof(GroundPlaceSpawner))]
		public class GroundPlaceSpawnerPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPrefix(GroundPlaceSpawner __instance, ref List<Transform> spawnSpots, out Vector2 __state)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				__state = __instance.possibleItems;
				if (GroundSpawns.Value)
				{
					__instance.possibleItems *= ItemMultiplier.Value;
					Vector2 possibleItems = __instance.possibleItems;
					float num = possibleItems.x - Mathf.Floor(possibleItems.x);
					float num2 = possibleItems.y - Mathf.Floor(possibleItems.y);
					possibleItems.x = ((Random.value < num) ? Mathf.Ceil(possibleItems.x) : Mathf.Floor(possibleItems.x));
					possibleItems.y = ((Random.value < num2) ? Mathf.Ceil(possibleItems.y) : Mathf.Floor(possibleItems.y));
					__instance.possibleItems = possibleItems;
					float num3 = Math.Max(possibleItems.x, possibleItems.y);
					if (num3 > (float)spawnSpots.Count)
					{
						List<Transform> collection = AddMoreSlotsUntil(spawnSpots, Mathf.CeilToInt(num3));
						spawnSpots.Clear();
						spawnSpots.AddRange(collection);
					}
					Vector2 possibleItems2 = __instance.possibleItems;
					Log.LogInfo((object)$"Ground spawner would spawn {__state.x}-{__state.y} berries, multiplied to {possibleItems2.x}-{possibleItems2.y}.");
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SpawnItemsPostfix(GroundPlaceSpawner __instance, List<Transform> spawnSpots, Vector2 __state)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (GroundSpawns.Value)
				{
					__instance.possibleItems = __state;
				}
			}
		}

		[HarmonyPatch(typeof(Spawner))]
		public class LuggagePatch
		{
			public static bool IsLuggage(Spawner spawner)
			{
				Luggage val = (Luggage)(object)((spawner is Luggage) ? spawner : null);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				return luggageSet.Contains(val.displayName);
			}

			[HarmonyPrefix]
			[HarmonyPatch("SpawnItems", new Type[] { typeof(List<Transform>) })]
			public static void SetStatusPrefix(Spawner __instance, ref List<Transform> spawnSpots)
			{
				if (IsLuggage(__instance))
				{
					List<Transform> collection = AddMoreSlots(spawnSpots, ItemMultiplier.Value);
					spawnSpots.Clear();
					spawnSpots.AddRange(collection);
					Log.LogInfo((object)$"We should spawn {spawnSpots.Count} items.");
				}
			}
		}

		private static string defaultLuggages = "Luggage,Big Luggage,Explorer's Luggage";

		private static HashSet<string> luggageSet = new HashSet<string>();

		public const string Id = "com.github.Wesmania.ItemMultiplierBis";

		internal static ManualLogSource Log { get; private set; } = null;


		internal static ConfigEntry<float> ItemMultiplier { get; private set; } = null;


		internal static ConfigEntry<string> Luggages { get; private set; } = null;


		internal static ConfigEntry<bool> GroundSpawns { get; private set; } = null;


		internal static ConfigEntry<bool> BerryBushes { get; private set; } = null;


		internal static ConfigEntry<bool> BerryVines { get; private set; } = null;


		public static string Name => "ItemMultiplierBis";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			ItemMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Config", "ItemMultiplier", 1f, "Item multiplier. Defaults to 1.0");
			Luggages = ((BaseUnityPlugin)this).Config.Bind<string>("Config", "Luggages", defaultLuggages, "Luggages to apply multiplier to, comma separated. Hint: \"Ancient Luggage\" and \"Ancient Statue\" are luggages too!");
			GroundSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "GroundSpawns", false, "Whether the multipler applies to items spawned on the ground.");
			BerryBushes = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "BerryBushes", false, "Whether the multipler applies to berry bushes.");
			BerryVines = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "BerryVines", false, "Whether the multipler applies to berry vines.");
			HashSet<string> hashSet = new HashSet<string>();
			string[] array = Luggages.Value.Split(',');
			foreach (string item in array)
			{
				hashSet.Add(item);
			}
			luggageSet = hashSet;
			Harmony val = new Harmony("com.github.Wesmania.ItemMultiplierBis");
			try
			{
				val.PatchAll();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to patch classes: {arg}");
			}
		}

		public static List<Transform> AddMoreSlotsUntil(List<Transform> spawnSpots, int target, bool addRandom = false)
		{
			List<Transform> list = new List<Transform>();
			while (target >= spawnSpots.Count)
			{
				list.AddRange(spawnSpots);
				target -= spawnSpots.Count;
			}
			if (target > 0)
			{
				ExtCollections.Shuffle<Transform>((IList<Transform>)spawnSpots);
				list.AddRange(spawnSpots.GetRange(0, target));
			}
			if (addRandom)
			{
				list.Add(spawnSpots[target]);
			}
			return list;
		}

		public static List<Transform> AddMoreSlots(List<Transform> spawnSpots, float m)
		{
			float num = (float)spawnSpots.Count * m;
			int num2 = Mathf.FloorToInt(num);
			float num3 = num - (float)num2;
			bool addRandom = Random.value < num3;
			return AddMoreSlotsUntil(spawnSpots, num2, addRandom);
		}

		public static void multiplySpawnRange(ref Vector2 range, ref List<Transform> spawnSpots, out Vector2 original)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			original = range;
			range *= ItemMultiplier.Value;
			float num = Math.Max(range.x, range.y);
			if (num > (float)spawnSpots.Count)
			{
				List<Transform> collection = AddMoreSlotsUntil(spawnSpots, Mathf.CeilToInt(num));
				spawnSpots.Clear();
				spawnSpots.AddRange(collection);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}