Decompiled source of SkullEnemyUpdated v1.0.0

SkullEnemyUpdated.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using LethalLib.Modules;
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("Mikusch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a new custom enemy, the floating skull.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("SkullEnemy")]
[assembly: AssemblyTitle("SkullEnemy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SkullEnemy
{
	[BepInPlugin("SkullEnemy", "SkullEnemy", "1.2.0")]
	public class SkullEnemyPlugin : BaseUnityPlugin
	{
		private static readonly Dictionary<LevelTypes, int> DefaultLevelRarities = new Dictionary<LevelTypes, int>
		{
			[(LevelTypes)128] = 66,
			[(LevelTypes)512] = 66,
			[(LevelTypes)256] = 66,
			[(LevelTypes)1024] = 66
		};

		public static SkullEnemyPlugin Instance;

		public ConfigEntry<float> ConfigMovementSpeed;

		public ConfigEntry<float> ConfigRotationSpeed;

		public ConfigEntry<bool> ConfigCanOnlyCollideWithTargetPlayer;

		private void Awake()
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Invalid comparison between Unknown and I4
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Invalid comparison between Unknown and I4
			Instance = this;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (Utility.IsNullOrWhiteSpace(directoryName))
			{
				return;
			}
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "skullassets"));
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load custom assets");
				return;
			}
			ConfigMovementSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MovementSpeed", 2f, "The speed at which the enemy moves towards its target.");
			ConfigRotationSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RotationSpeed", 2f, "The speed at which the enemy rotates towards its target.");
			ConfigCanOnlyCollideWithTargetPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CanOnlyCollideWithTargetPlayer", true, "If enabled, the enemy will only be able to collide with its target player.");
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
			foreach (LevelTypes value in Enum.GetValues(typeof(LevelTypes)))
			{
				if ((int)value != 1 && (int)value != -1 && (!((Enum)(LevelTypes)1020).HasFlag((Enum)(object)value) || (int)value != 1020))
				{
					ConfigEntry<int> val3 = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", $"{(object)value}Rarity", DefaultLevelRarities.GetValueOrDefault(value, 0), $"The spawn rarity on {(object)value}.");
					dictionary.Add(value, val3.Value);
				}
			}
			EnemyType val4 = val.LoadAsset<EnemyType>("SkullEnemy");
			TerminalNode val5 = val.LoadAsset<TerminalNode>("SkullTerminalNode");
			TerminalKeyword val6 = val.LoadAsset<TerminalKeyword>("SkullTerminalKeyword");
			NetworkPrefabs.RegisterNetworkPrefab(val4.enemyPrefab);
			Enemies.RegisterEnemy(val4, dictionary, (Dictionary<string, int>)null, val5, val6);
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SkullEnemy is loaded!");
		}
	}
	public class SkullEnemyAI : EnemyAI
	{
		public float laughTimer;

		private float _movementSpeed;

		private float _rotationSpeed;

		private bool _canOnlyCollideWithTargetPlayer;

		public override void Start()
		{
			((EnemyAI)this).Start();
			_movementSpeed = SkullEnemyPlugin.Instance.ConfigMovementSpeed.Value;
			_rotationSpeed = SkullEnemyPlugin.Instance.ConfigRotationSpeed.Value;
			_canOnlyCollideWithTargetPlayer = SkullEnemyPlugin.Instance.ConfigCanOnlyCollideWithTargetPlayer.Value;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0053: 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)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (!base.isEnemyDead)
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if (!((Object)(object)val == (Object)null) && (!_canOnlyCollideWithTargetPlayer || !((Object)(object)val != (Object)(object)base.targetPlayer)))
				{
					val.DamagePlayer(100, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
		}

		public override void Update()
		{
			//IL_0117: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			laughTimer -= Time.deltaTime;
			if ((double)laughTimer <= 0.0)
			{
				laughTimer = Random.Range(6f, 7f);
				if (base.enemyType.audioClips.Length != 0)
				{
					base.creatureVoice.PlayOneShot(base.enemyType.audioClips[Random.Range(0, base.enemyType.audioClips.Length)]);
				}
			}
			if (!HasValidTarget())
			{
				base.targetPlayer = ((EnemyAI)this).GetClosestPlayer(false, false, false);
				if (base.debugEnemyAI && (Object)(object)base.targetPlayer != (Object)null)
				{
					Debug.Log((object)("Found new target: " + base.targetPlayer.playerUsername));
				}
			}
			if (!HasValidTarget())
			{
				if (base.debugEnemyAI)
				{
					Debug.Log((object)"Failed to find new target");
				}
				return;
			}
			Vector3 val = base.targetPlayer.playerGlobalHead.position - ((Component)this).transform.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Quaternion val2 = Quaternion.LookRotation(normalized);
			((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, Time.deltaTime * _rotationSpeed);
			Transform transform = ((Component)this).transform;
			transform.position += normalized * (Time.deltaTime * _movementSpeed);
		}

		private bool HasValidTarget()
		{
			return (Object)(object)base.targetPlayer != (Object)null && base.targetPlayer.isInsideFactory && !base.targetPlayer.isPlayerDead;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SkullEnemy";

		public const string PLUGIN_NAME = "SkullEnemy";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}