Decompiled source of Shop Items Spawn in Level v1.1.2

REPO_Shop_Items_in_Level.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("REPO_Shop_Items_in_Level")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+b60390afb9e4de4c6d2b4f5068a51ffdbaaf6441")]
[assembly: AssemblyProduct("Shop Items spawn in Level")]
[assembly: AssemblyTitle("REPO_Shop_Items_in_Level")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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 REPO_Shop_Items_in_Level
{
	[BepInPlugin("REPO_Shop_Items_in_Level", "Shop Items spawn in Level", "1.1.2")]
	[BepInProcess("REPO.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> SpawnUpgradeItems;

		internal static ConfigEntry<float> UpgradeItemSpawnChance;

		private Harmony harmony;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin REPO_Shop_Items_in_Level is loaded!");
			harmony = new Harmony("REPO_Shop_Items_in_Level");
			harmony.PatchAll(typeof(Plugin));
			Logger.LogInfo((object)"Harmony patches applied!");
			SpawnUpgradeItems = ((BaseUnityPlugin)this).Config.Bind<bool>("UpgradeItems", "SpawnUpgradeItems", true, "Whether upgrade items can spawn in levels");
			UpgradeItemSpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("UpgradeItems", "UpgradeItemSpawnChance", 5f, "Percentage chance (0-100) for an upgrade item to spawn. Default is 5%.");
		}

		private static bool GetRandomItemOfType(itemType itemType, out Item item)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			List<Item> list = StatsManager.instance.itemDictionary.Values.Where((Item item) => item.itemType == itemType).ToList();
			if (list.Count == 0)
			{
				Logger.LogWarning((object)$"Failed to get random item of type {(object)(itemType)3}");
				item = null;
				return false;
			}
			item = list[Random.Range(0, list.Count)];
			return true;
		}

		private static bool ShouldReplaceValuable(ValuableVolume volume, out itemType? itemType)
		{
			//IL_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			itemType = null;
			Type volumeType = volume.VolumeType;
			Type val = volumeType;
			if ((int)val == 0)
			{
				if (!SpawnUpgradeItems.Value)
				{
					return false;
				}
				itemType = (itemType)3;
				return Random.Range(0f, 100f) < UpgradeItemSpawnChance.Value;
			}
			return false;
		}

		[HarmonyPatch(typeof(ValuableDirector), "Spawn")]
		[HarmonyPrefix]
		public static bool ValuableDirector_Spawn_Prefix(ref GameObject _valuable, ValuableVolume _volume, string _path)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (!ShouldReplaceValuable(_volume, out var itemType))
			{
				return true;
			}
			if (!itemType.HasValue)
			{
				return true;
			}
			if (!GetRandomItemOfType(itemType.Value, out var item))
			{
				return true;
			}
			_valuable = item.prefab;
			if (GameManager.instance.gameMode != 0)
			{
				PhotonNetwork.Instantiate("Items/" + ((Object)_valuable).name, ((Component)_volume).transform.position, ((Component)_volume).transform.rotation, (byte)0, (object[])null);
				Logger.LogInfo((object)$"Highjacking Spawn for: {((Object)_valuable).name} with volume {_volume} at path {_path}");
				return false;
			}
			Logger.LogInfo((object)$"ValuableDirector spawning: {((Object)_valuable).name} with volume {_volume} at path {_path}");
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "REPO_Shop_Items_in_Level";

		public const string PLUGIN_NAME = "Shop Items spawn in Level";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}