Decompiled source of ScrapsAllTheSame v0.0.5

ScrapsAllTheSame.dll

Decompiled 6 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("all the same")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("all the same")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6806ebec-dfe5-4c9c-b7c9-34159c47cd78")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ScrapsAllTheSame
{
	[BepInPlugin("nexor.ScrapsAllTheSame", "ScrapsAllTheSame", "0.0.5")]
	public class ScrapsAllTheSame : BaseUnityPlugin
	{
		private const string modGUID = "nexor.ScrapsAllTheSame";

		private const string modName = "ScrapsAllTheSame";

		private const string modVersion = "0.0.5";

		public ConfigEntry<float> random_scrap_day_chance;

		public ConfigEntry<int> random_scrap_type_num;

		public ConfigEntry<string> item_filter_list;

		private readonly Harmony harmony = new Harmony("nexor.ScrapsAllTheSame");

		public static ScrapsAllTheSame Instance;

		public static ManualLogSource Logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			random_scrap_day_chance = ((BaseUnityPlugin)this).Config.Bind<float>("Scraps All The Same Config", "Same Scraps Day Chance (%)", 100f, "你可以在这里修改'单种垃圾日'出现的概率\nYou can modify the probability of Same Scraps Day here");
			random_scrap_type_num = ((BaseUnityPlugin)this).Config.Bind<int>("Scraps All The Same Config", "Random Scrap Type Number", 1, "你可以在这里修改'单种垃圾日'随机出现多少种垃圾,默认只有一种\nHere you can change how many types of garbage appear randomly in the 'Single Garbage Day', and there is only one type by default");
			item_filter_list = ((BaseUnityPlugin)this).Config.Bind<string>("Scraps All The Same Config", "Item Filter List", "", "你可以在这里更改随机的垃圾会从哪些垃圾里面随机,如果是空的则默认从地图会生成的所有垃圾中随机,如果非空则只会从您填写的垃圾列表中随机,垃圾的名字和名字间用 英文逗号 隔开!\nYou can change which trash the randomized trash will be randomized from here, if it's empty it will be randomized by default from all the trash the map will generate, if it's non-empty it will only be randomized from the list of trash you fill in, with English commas separating the name of the trash from the name of the trash!\n这里附上不完全的物品名称表:[apparatus, airhorn, bell, big bolt, bottles, brush, candy, cash register, chemical jug, clown horn, comedy, cookie mold pan, dust pan, easter egg, egg beater, fancy lamp, flask, gift, gold bar, golden cup, hairdryer, homemade flashbang, jar of pickles, large axle, laser pointer, magic 7 ball, magnifying glass, metal sheet, mug, old phone, painting, perfume bottle, pill bottle, plastic fish, red soda, remote, ring, rubber ducky, steering wheel, stop sign, tea kettle, teeth, toothpaste, toy cube, toy robot, tragedy, v-type engine, whoopie cushion, yield sign]");
			harmony.PatchAll();
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"ScrapsAllTheSame 0.0.5 loaded.");
		}
	}
}
namespace ScrapsAllTheSame.Patches.Items
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		private static List<SpawnableItemWithRarity> previousSpawnableScrap;

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPrefix]
		[HarmonyPriority(int.MinValue)]
		private static void SpawnScrapInLevelPrefixPatch(ref SelectableLevel ___currentLevel)
		{
			if (!(ScrapsAllTheSame.Instance.random_scrap_day_chance.Value > (float)Random.Range(0, 100)))
			{
				return;
			}
			previousSpawnableScrap = ___currentLevel.spawnableScrap;
			List<SpawnableItemWithRarity> list = new List<SpawnableItemWithRarity>();
			string text = ScrapsAllTheSame.Instance.item_filter_list.Value.Trim();
			if (string.IsNullOrWhiteSpace(text))
			{
				list = previousSpawnableScrap;
			}
			else
			{
				string[] array = text.Split(new char[1] { ',' });
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					string value = text2.Trim().ToLower();
					for (int j = 0; j < previousSpawnableScrap.Count; j++)
					{
						SpawnableItemWithRarity val = previousSpawnableScrap[j];
						if (val.spawnableItem.itemName.ToLower().Contains(value))
						{
							list.Add(val);
						}
					}
				}
			}
			List<SpawnableItemWithRarity> list2 = new List<SpawnableItemWithRarity>();
			for (int k = 0; k < ScrapsAllTheSame.Instance.random_scrap_type_num.Value; k++)
			{
				SpawnableItemWithRarity item = list[Random.Range(0, list.Count)];
				list2.Add(item);
			}
			HUDManager.Instance.DisplayTip("Random type scrap day!", "Setting spawnable scraps to be only " + ScrapsAllTheSame.Instance.random_scrap_type_num.Value + " type of scraps randomly.", false, false, "LC_Tip1");
			if (list2.Count > 0)
			{
				___currentLevel.spawnableScrap = list2;
			}
			else
			{
				HUDManager.Instance.DisplayTip("Error", "Wrong Item List, enable original item list", true, false, "LC_Tip1");
			}
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPostfix]
		[HarmonyPriority(int.MaxValue)]
		private static void SpawnScrapInLevelPostfixPatch(ref SelectableLevel ___currentLevel)
		{
			___currentLevel.spawnableScrap = previousSpawnableScrap;
		}
	}
}