Decompiled source of nobugs v1.0.0

nobugs.dll

Decompiled 6 hours 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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("nobugs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("移除 PEAK 中的所有昆虫(蜘蛛、蝎子、甲虫、蜂群、蚁狮)")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e46beb3014ed010b00e682f16050a28f87d88b67")]
[assembly: AssemblyProduct("PEAK NoBugs")]
[assembly: AssemblyTitle("PEAK NoBugs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 nobugs
{
	[BepInPlugin("nobugs", "PEAK NoBugs", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> RemoveSpiders;

		internal static ConfigEntry<bool> RemoveScorpions;

		internal static ConfigEntry<bool> RemoveBeetles;

		internal static ConfigEntry<bool> RemoveBees;

		internal static ConfigEntry<bool> RemoveAntlions;

		internal static ConfigEntry<bool> RemoveFrogTongues;

		internal static ConfigEntry<bool> DestroyObjects;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			RemoveSpiders = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveSpiders", true, "移除蜘蛛(Spider):不再从天花板垂降抓人。");
			RemoveScorpions = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveScorpions", true, "移除蝎子(Scorpion):不再造成中毒和击退。");
			RemoveBeetles = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveBeetles", true, "移除甲虫(Beetle):不再顶飞玩家。");
			RemoveBees = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveBees", true, "移除蜂群(BeeSwarm):蜂巢不再孵化蜂群。");
			RemoveAntlions = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveAntlions", true, "移除蚁狮(Antlion):沙坑不再吞噬玩家。");
			RemoveFrogTongues = ((BaseUnityPlugin)this).Config.Bind<bool>("Bugs", "RemoveFrogTongues", false, "移除青蛙舌(FrogTongue)。青蛙不算昆虫,默认关闭。");
			DestroyObjects = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DestroyObjects", true, "true = 直接销毁虫子对象(更彻底);false = 仅隐藏并禁用其行为(联机更安全)。");
			_harmony = new Harmony("nobugs");
			_harmony.PatchAll(typeof(BugPatches));
			Logger.LogInfo((object)"PEAK NoBugs v1.0.0 已加载,昆虫清理已启用。");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static void Remove(Behaviour target, string label)
		{
			if (!((Object)(object)target == (Object)null))
			{
				GameObject gameObject = ((Component)target).gameObject;
				if (DestroyObjects.Value)
				{
					Logger.LogInfo((object)("[NoBugs] 销毁 " + label + ": " + ((Object)gameObject).name));
					Object.Destroy((Object)(object)gameObject);
				}
				else
				{
					Logger.LogInfo((object)("[NoBugs] 禁用 " + label + ": " + ((Object)gameObject).name));
					target.enabled = false;
					gameObject.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class BugPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Spider), "Start")]
		private static bool Spider_Start_Prefix(Spider __instance)
		{
			if (!Plugin.RemoveSpiders.Value)
			{
				return true;
			}
			Plugin.Remove((Behaviour)(object)__instance, "Spider");
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Spider), "Scan")]
		private static bool Spider_Scan_Prefix()
		{
			return !Plugin.RemoveSpiders.Value;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SpiderTrigger), "OnTriggerEnter")]
		private static bool SpiderTrigger_OnTriggerEnter_Prefix()
		{
			return !Plugin.RemoveSpiders.Value;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Mob), "Start")]
		private static void Mob_Start_Postfix(Mob __instance)
		{
			if (__instance is Scorpion && Plugin.RemoveScorpions.Value)
			{
				Plugin.Remove((Behaviour)(object)__instance, "Scorpion");
			}
			else if (__instance is Beetle && Plugin.RemoveBeetles.Value)
			{
				Plugin.Remove((Behaviour)(object)__instance, "Beetle");
			}
			else if (__instance is FrogTongue && Plugin.RemoveFrogTongues.Value)
			{
				Plugin.Remove((Behaviour)(object)__instance, "FrogTongue");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Scorpion), "InflictAttack")]
		private static bool Scorpion_InflictAttack_Prefix()
		{
			return !Plugin.RemoveScorpions.Value;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Beetle), "InflictAttack")]
		private static bool Beetle_InflictAttack_Prefix()
		{
			return !Plugin.RemoveBeetles.Value;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Beehive), "Init")]
		private static void Beehive_Init_Prefix(Beehive __instance)
		{
			if (Plugin.RemoveBees.Value)
			{
				__instance.spawnBees = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BeeSwarm), "Start")]
		private static bool BeeSwarm_Start_Prefix(BeeSwarm __instance)
		{
			if (!Plugin.RemoveBees.Value)
			{
				return true;
			}
			Plugin.Remove((Behaviour)(object)__instance, "BeeSwarm");
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Antlion), "Start")]
		private static bool Antlion_Start_Prefix(Antlion __instance)
		{
			if (!Plugin.RemoveAntlions.Value)
			{
				return true;
			}
			Plugin.Remove((Behaviour)(object)__instance, "Antlion");
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "nobugs";

		public const string PLUGIN_NAME = "PEAK NoBugs";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}