Decompiled source of SpawnItemInLevel v1.0.1

SpawnItemInLevel.dll

Decompiled 19 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 REPOLib.Modules;
using SpawnItemInLevel;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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;
		}
	}
}
internal class ConfigManager
{
	public static Dictionary<string, ConfigEntry<bool>> ShopItemConfigs = new Dictionary<string, ConfigEntry<bool>>();

	public static Dictionary<string, ConfigEntry<bool>> ValueItemConfigs = new Dictionary<string, ConfigEntry<bool>>();

	public static ConfigEntry<Key>? BindKeyValueItem { get; private set; }

	public static ConfigEntry<Key>? BindKeyShopItem { get; private set; }

	public static ConfigEntry<int>? ValueTop { get; private set; }

	public static ConfigEntry<int>? ValueDown { get; private set; }

	public static ConfigEntry<bool>? isDebug { get; private set; }

	public static void Initialize(ConfigFile configFile)
	{
		//IL_0606: Unknown result type (might be due to invalid IL or missing references)
		//IL_0610: Expected O, but got Unknown
		//IL_0638: Unknown result type (might be due to invalid IL or missing references)
		//IL_0642: Expected O, but got Unknown
		List<ConfigEntry<bool>> list = new List<ConfigEntry<bool>>();
		List<CEVT> list2 = new List<CEVT>(7)
		{
			new CEVT("Tiny", "微小的", v3: true),
			new CEVT("Small", "小的", v3: true),
			new CEVT("Medium", "中的", v3: true),
			new CEVT("Big", "大的", v3: true),
			new CEVT("Wide", "宽的", v3: true),
			new CEVT("Tall", "高的", v3: true),
			new CEVT("VeryTall", "很高的", v3: true)
		};
		List<CESI> list3 = new List<CESI>(56)
		{
			new CESI("Tumble Launch Upgrade", "翻滚速度升级", v3: true),
			new CESI("Tumble Wings Upgrade", "翻滚翅膀升级", v3: true),
			new CESI("Crouch Rest Upgrade", "下蹲恢复升级", v3: true),
			new CESI("Sprint Speed Upgrade", "冲刺速度升级", v3: true),
			new CESI("Extra Jump Upgrade", "额外跳跃升级", v3: true),
			new CESI("Health Upgrade", "生命升级", v3: true),
			new CESI("Stamina Upgrade", "体力升级", v3: true),
			new CESI("Strength Upgrade", "力量升级", v3: true),
			new CESI("Range Upgrade", "抓取范围升级", v3: true),
			new CESI("Death Head Battery Upgrade", "头部电池升级", v3: true),
			new CESI("Map Player Count Upgrade", "地图玩家数量升级", v3: true),
			new CESI("Tumble Climb Upgrade", "翻滚抓取升级", v3: true),
			new CESI("Extra Life Upgrade", "额外生命升级", v3: true),
			new CESI("Item Resist Upgrade", "物品抗性升级", v3: true),
			new CESI("Item Value Upgrade", "物品价值升级", v3: true),
			new CESI("Autoscan Upgrade", "自动扫描升级", v3: true),
			new CESI("Valuable Count Upgrade", "贵重物品数量升级", v3: true),
			new CESI("Map Zoom Upgrade", "地图缩放升级", v3: true),
			new CESI("Sprint Usage Upgrade", "冲刺消耗升级", v3: true),
			new CESI("Recharge Drone", "充电无人机", v3: true),
			new CESI("Indestructible Drone", "无敌无人机", v3: true),
			new CESI("Zero Gravity Drone", "零重力无人机", v3: true),
			new CESI("Roll Drone", "滚动无人机", v3: true),
			new CESI("Feather Drone", "羽毛无人机", v3: true),
			new CESI("Large Health Pack (100)", "健康包(100)", v3: true),
			new CESI("Medium Health Pack (50)", "健康包(50)", v3: true),
			new CESI("Small Health Pack (25)", "健康包(25)", v3: true),
			new CESI("Sword", "剑", v3: true),
			new CESI("Sledge Hammer", "大锤", v3: true),
			new CESI("Inflatable Hammer", "充气锤", v3: true),
			new CESI("Frying Pan", "铁锅", v3: true),
			new CESI("Prodzap", "电击棒", v3: true),
			new CESI("Baseball Bat", "棒球棒", v3: true),
			new CESI("Grenade", "手榴弹", v3: true),
			new CESI("Shockwave Grenade", "冲击波手榴弹", v3: true),
			new CESI("Human Grenade", "人类手榴弹", v3: true),
			new CESI("Duct Taped Grenades", "胶带手榴弹", v3: true),
			new CESI("Stun Grenade", "眩晕手雷", v3: true),
			new CESI("Tranq Gun", "麻醉枪", v3: true),
			new CESI("Gun", "枪", v3: true),
			new CESI("Shotgun", "霰弹枪", v3: true),
			new CESI("Photon Blaster", "光子轰击器", v3: true),
			new CESI("Boltzap", "电击弩", v3: true),
			new CESI("Explosive Mine", "爆炸地雷", v3: true),
			new CESI("Shockwave Mine", "冲击波地雷", v3: true),
			new CESI("Trapzap", "电击陷阱", v3: true),
			new CESI("Phase Bridge", "相位桥", v3: true),
			new CESI("C.A.R.T.", "C.A.R.T.手推车", v3: true),
			new CESI("POCKET C.A.R.T.", "迷你C.A.R.T.手推车", v3: true),
			new CESI("C.A.R.T. Laser", "C.A.R.T.激光炮", v3: true),
			new CESI("Zero Gravity Orb", "零重力球体", v3: true),
			new CESI("Duck Bucket", "鸭子桶", v3: true),
			new CESI("Valuable Tracker", "物品追踪器", v3: true),
			new CESI("Rubber Duck", "橡胶鸭", v3: true),
			new CESI("Extraction Tracker", "提取点追踪器", v3: true),
			new CESI("Energy Crystal", "能量晶体", v3: true)
		};
		List<CEVI> list4 = new List<CEVI>();
		isDebug = configFile.Bind<bool>("Controls", "isDebug", true, "调试模式");
		ValueTop = configFile.Bind<int>("Values", "随机物品价值上限", 10000, new ConfigDescription("随机物品价值上限", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50000), Array.Empty<object>()));
		ValueDown = configFile.Bind<int>("Values", "随机物品价值下限", 100, new ConfigDescription("随机物品价值下限", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50000), Array.Empty<object>()));
		BindKeyValueItem = configFile.Bind<Key>("Controls", "高价值物品生成按键绑定", (Key)34, "高价值物品生成按键绑定");
		BindKeyShopItem = configFile.Bind<Key>("Controls", "商店物品生成按键绑定", (Key)21, "商店物品生成按键绑定");
		foreach (CEVT item in list2)
		{
			list.Add(RegisterValueItemConfig(configFile, item.key, item.value, item.desc));
		}
		foreach (CESI item2 in list3)
		{
			list.Add(RegisterShopItemConfig(configFile, item2.key, item2.value, item2.desc));
		}
		foreach (CEVI item3 in list4)
		{
			list.Add(RegisterShopItemConfig(configFile, item3.key, item3.value, item3.desc));
		}
	}

	private static ConfigEntry<bool> RegisterShopItemConfig(ConfigFile file, string key, bool defaultValue, string description)
	{
		ConfigEntry<bool> val = file.Bind<bool>("Controls", key, defaultValue, description);
		ShopItemConfigs[key] = val;
		return val;
	}

	public static List<string> GetShopItemAllowed()
	{
		List<string> list = new List<string>();
		foreach (KeyValuePair<string, ConfigEntry<bool>> shopItemConfig in ShopItemConfigs)
		{
			if (shopItemConfig.Value.Value)
			{
				list.Add(shopItemConfig.Key);
			}
		}
		return list;
	}

	private static ConfigEntry<bool> RegisterValueItemConfig(ConfigFile file, string key, bool defaultValue, string description)
	{
		ConfigEntry<bool> val = file.Bind<bool>("Controls", key, defaultValue, description);
		ValueItemConfigs[key] = val;
		return val;
	}

	public static List<Type> GetValueItemAllowedType()
	{
		List<Type> list = new List<Type>();
		foreach (KeyValuePair<string, ConfigEntry<bool>> valueItemConfig in ValueItemConfigs)
		{
			switch (valueItemConfig.Key)
			{
			case "Tiny":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)0);
				}
				break;
			case "Small":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)1);
				}
				break;
			case "Medium":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)2);
				}
				break;
			case "Big":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)3);
				}
				break;
			case "Wide":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)4);
				}
				break;
			case "Tall":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)5);
				}
				break;
			case "VeryTall":
				if (valueItemConfig.Value.Value)
				{
					list.Add((Type)6);
				}
				break;
			}
		}
		return list;
	}
}
namespace SpawnItemInLevel
{
	internal class CESI
	{
		public string key;

		public string desc;

		public bool value;

		public CESI(string v1, string v2, bool v3)
		{
			key = v1;
			desc = v2;
			value = v3;
		}
	}
	internal class CEVI
	{
		public string key;

		public string desc;

		public bool value;

		public CEVI(string v1, string v2, bool v3)
		{
			key = v1;
			desc = v2;
			value = v3;
		}
	}
	internal class CEVT
	{
		public string key;

		public string desc;

		public bool value;

		public CEVT(string v1, string v2, bool v3)
		{
			key = v1;
			desc = v2;
			value = v3;
		}
	}
	[BepInPlugin("Gs.SpawnItemInLevel", "Spawn Item In Level", "1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SpawnItemInLevel : BaseUnityPlugin
	{
		internal static SpawnItemInLevel Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)"Spawn Item In Level Has Loaded!");
		}

		internal void Patch()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			if (Harmony == null)
			{
				Harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(ShopManager))]
	internal static class SpawnManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void KeyboardListener(ShopManager __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<SpawnShopItemManager>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<SpawnShopItemManager>();
			}
			if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<SpawnValueItemManager>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<SpawnValueItemManager>();
			}
		}
	}
	internal class SpawnShopItemManager : MonoBehaviour
	{
		private static readonly ManualLogSource Logger = Logger.CreateLogSource("SpawnShopItem");

		private static readonly Random random = new Random();

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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)
			Key value = ConfigManager.BindKeyShopItem.Value;
			if (((ButtonControl)Keyboard.current[value]).wasPressedThisFrame)
			{
				GenerateAndSpawnStoreItem();
			}
		}

		public void GenerateAndSpawnStoreItem()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0053: 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_0059: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			if (TryGetRandomItem(new List<itemType>(), out Item item))
			{
				Vector3 position = ((Component)PlayerAvatar.instance).transform.position + Vector3.up * 1f + ((Component)PlayerAvatar.instance).transform.forward * 1.5f;
				Quaternion identity = Quaternion.identity;
				SpawnItem(item, position, identity);
			}
			else
			{
				Logger.LogError((object)"无法获取有效的物品来生成。");
			}
		}

		private static bool TryGetRandomItem(List<itemType>? filterTypes, out Item item)
		{
			List<itemType> filterTypes2 = filterTypes;
			item = null;
			if (StatsManager.instance?.itemDictionary == null)
			{
				Logger.LogError((object)"StatsManager 或 itemDictionary 未初始化");
				return false;
			}
			List<Item> list = ((!filterTypes2.Any()) ? StatsManager.instance.itemDictionary.Values.Select((Item i) => i).ToList() : StatsManager.instance.itemDictionary.Values.Where((Item i) => filterTypes2.Contains(i.itemType)).ToList());
			if (ConfigManager.isDebug.Value)
			{
				Logger.LogInfo((object)("\n-------所有商店物品:\n" + string.Join("\n", list.Select((Item i) => i.itemName)) + "\n-------"));
			}
			List<string> allowedSI = ConfigManager.GetShopItemAllowed();
			if (ConfigManager.isDebug.Value)
			{
				Logger.LogInfo((object)("\n------设置的商店物品:\n" + string.Join("\n", allowedSI) + "\n-------"));
			}
			List<Item> list2 = (from i in list
				where (Object)(object)i != (Object)null && i.prefab != null
				where allowedSI.Contains(i.itemName)
				select i).ToList();
			if (allowedSI.Count == 0)
			{
				Logger.LogWarning((object)"筛选后没有符合条件的物品。从默认的物品集中随机获取。");
				int index = random.Next(list.Count);
				item = list[index];
			}
			else
			{
				int index2 = random.Next(list2.Count);
				item = list2[index2];
			}
			Logger.LogInfo((object)("当前随机选中的商店物品: " + item.itemName));
			return true;
		}

		private static GameObject SpawnItem(Item item, Vector3 position, Quaternion rotation)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = "Items/" + ((Object)item).name;
				return (!SemiFunc.IsMultiplayer()) ? Object.Instantiate<GameObject>(item.prefab.Prefab, position, rotation) : PhotonNetwork.Instantiate(text, position, rotation, (byte)0, (object[])null);
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("生成物品 " + item.itemName + " 时发生错误: " + ex.Message));
				return null;
			}
		}
	}
	internal class SpawnValueItemManager : MonoBehaviour
	{
		private readonly Random random = new Random();

		private static readonly ManualLogSource Logger = Logger.CreateLogSource("SpawnValueItem");

		private void Update()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.RunIsLevel())
			{
				return;
			}
			Key value = ConfigManager.BindKeyValueItem.Value;
			if (((ButtonControl)Keyboard.current[value]).wasPressedThisFrame)
			{
				PrefabRef prefab = GetRandomValuablePrefab() ?? ((IEnumerable<PrefabRef>)Valuables.AllValuables).FirstOrDefault((Func<PrefabRef, bool>)((PrefabRef x) => ((Object)x.Prefab).name.Contains("money", StringComparison.OrdinalIgnoreCase)));
				SpawnItem(prefab);
			}
		}

		private void SpawnItem(PrefabRef prefab)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			ValuableObject val = ((prefab != null) ? prefab.Prefab.GetComponent<ValuableObject>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 val2 = ((Component)PlayerAvatar.instance).transform.position + new Vector3(0f, 1f, 0f) + ((Component)PlayerAvatar.instance).transform.forward * 2f;
				if (ConfigManager.ValueTop.Value < ConfigManager.ValueDown.Value)
				{
					val.valuePreset.valueMax = ConfigManager.ValueDown.Value;
					val.valuePreset.valueMin = ConfigManager.ValueTop.Value;
				}
				else
				{
					val.valuePreset.valueMax = ConfigManager.ValueTop.Value;
					val.valuePreset.valueMin = ConfigManager.ValueDown.Value;
				}
				if (ConfigManager.isDebug.Value)
				{
					Logger.LogInfo((object)$"当前随机的高价值物品:{((Object)val).name}、价值:{val.valuePreset}、物品类型:{val.volumeType}");
				}
				Valuables.SpawnValuable(prefab, val2, Quaternion.identity);
			}
		}

		private PrefabRef? GetRandomValuablePrefab()
		{
			if (Valuables.AllValuables == null || !Valuables.AllValuables.Any())
			{
				return null;
			}
			List<PrefabRef> source = Valuables.AllValuables.ToList();
			List<Type> list = ConfigManager.GetValueItemAllowedType();
			if (!list.Any())
			{
				Logger.LogInfo((object)"\n-------未开启高价值物品分类设置!将随机选择任意高价值物品\n-------");
				PrefabRef val = source.ElementAt(random.Next(source.Count()));
				ValuableObject component = val.Prefab.GetComponent<ValuableObject>();
				Logger.LogInfo((object)("\n-------选中的高价值物品:\n" + ((Object)component).name + "\n-------"));
				return val;
			}
			List<PrefabRef> source2 = (from v in source.Select(delegate(PrefabRef value)
				{
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					ValuableObject val4 = ((value != null) ? value.Prefab.GetComponent<ValuableObject>() : null);
					return list.Contains(val4.volumeType) ? value : null;
				})
				where v != null
				select v).ToList();
			if (ConfigManager.isDebug.Value)
			{
				int i = 1;
				List<string> values = source2.Select(delegate(PrefabRef v)
				{
					//IL_002a: Unknown result type (might be due to invalid IL or missing references)
					ValuableObject val3 = ((v != null) ? v.Prefab.GetComponent<ValuableObject>() : null);
					return $"[{i}]{((Object)val3).name}({val3.volumeType})";
				}).ToList();
				Logger.LogInfo((object)("\n-------所有的高价值物品:\n" + string.Join("\n", values) + "\n-------"));
			}
			PrefabRef val2 = source2.ElementAt(random.Next(source2.Count()));
			ValuableObject component2 = val2.Prefab.GetComponent<ValuableObject>();
			Logger.LogInfo((object)("\n-------选中的高价值物品:\n" + ((Object)component2).name + "\n-------"));
			return val2;
		}
	}
}