Decompiled source of NoHidden v1.0.0

NoHidden.dll

Decompiled 2 months 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 BepInEx;
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("NoHidden")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoHidden")]
[assembly: AssemblyTitle("NoHidden")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace NoHidden
{
	[HarmonyPatch(typeof(EnemyDirector))]
	internal static class EnemyDirectorPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			EnemyHelper.RemoveHiddenEnemyFromList(ref EnemyDirector.instance.enemiesDifficulty1);
			EnemyHelper.RemoveHiddenEnemyFromList(ref EnemyDirector.instance.enemiesDifficulty2);
			EnemyHelper.RemoveHiddenEnemyFromList(ref EnemyDirector.instance.enemiesDifficulty3);
		}
	}
	internal static class EnemyHelper
	{
		public static bool IsHiddenEnemy(EnemySetup enemySetup)
		{
			if ((Object)(object)enemySetup == (Object)null)
			{
				return false;
			}
			if (((Object)enemySetup).name.Contains("Hidden", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (TryGetEnemyName(enemySetup, out string enemyName) && enemyName.Equals("Hidden", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}

		public static bool TryGetEnemyName(EnemySetup enemySetup, out string enemyName)
		{
			enemyName = string.Empty;
			if ((Object)(object)enemySetup == (Object)null || enemySetup.spawnObjects == null)
			{
				return false;
			}
			foreach (GameObject spawnObject in enemySetup.spawnObjects)
			{
				if (TryGetEnemyName(spawnObject, out enemyName))
				{
					return true;
				}
			}
			return false;
		}

		public static bool TryGetEnemyName(GameObject gameObject, out string enemyName)
		{
			enemyName = string.Empty;
			if ((Object)(object)gameObject == (Object)null)
			{
				return false;
			}
			EnemyParent val = null;
			if (gameObject.TryGetComponent<EnemyParent>(ref val))
			{
				enemyName = val.enemyName;
				return true;
			}
			return false;
		}

		public static void RemoveHiddenEnemyFromList(ref List<EnemySetup> list)
		{
			list = list.Where((EnemySetup enemySetup) => !IsHiddenEnemy(enemySetup)).ToList();
		}
	}
	[HarmonyPatch(typeof(LevelGenerator))]
	internal static class LevelGeneratorPatch
	{
		[HarmonyPatch("EnemySpawn")]
		[HarmonyPrefix]
		private static bool EnemySpawnPatch(ref EnemySetup enemySetup)
		{
			if (EnemyHelper.IsHiddenEnemy(enemySetup))
			{
				Plugin.LoggerInstance.LogInfo((object)"Prevented Hidden enemy from spawning.");
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("Snowlance.NoHidden", "NoHidden", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "Snowlance.NoHidden";

		public const string modName = "NoHidden";

		public const string modVersion = "1.0.0";

		public static Plugin PluginInstance;

		public static ManualLogSource LoggerInstance;

		private readonly Harmony harmony = new Harmony("Snowlance.NoHidden");

		public void Awake()
		{
			if ((Object)(object)PluginInstance == (Object)null)
			{
				PluginInstance = this;
			}
			LoggerInstance = ((BaseUnityPlugin)PluginInstance).Logger;
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Snowlance.NoHidden v1.0.0 has loaded!");
		}
	}
}