Decompiled source of BellMonster v1.0.6

Drak.BellMonster.dll

Decompiled 5 months ago
#define DEBUG
using System;
using System.Collections;
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 BellMonster.Configuration;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Drak.BellMonster.NetcodePatcher;
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("Drak.BellMonster")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+c0b952c1e13a5b8690fe6c600e8e73ce8fb5fdb4")]
[assembly: AssemblyProduct("BellMonster")]
[assembly: AssemblyTitle("Drak.BellMonster")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
}
namespace BellMonster
{
	internal class BellMonsterAI : EnemyAI
	{
		private enum State
		{
			SearchingForPlayer,
			ChasingPlayer
		}

		private Random? bellPitchRandom;

		[Conditional("DEBUG")]
		private void LogIfDebugBuild(string text)
		{
			Plugin.Logger.LogInfo((object)text);
		}

		public override void Start()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			LogIfDebugBuild("Bell Monster Spawned");
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			bellPitchRandom = new Random((int)(((Component)this).transform.position.x + ((Component)this).transform.position.z));
			((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			((MonoBehaviour)this).StartCoroutine(PlayStep());
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			if (!base.isEnemyDead)
			{
			}
		}

		public override void DoAIInterval()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = 1f;
				if (FoundClosestPlayerInRange(15f, 10f))
				{
					LogIfDebugBuild("Start Target Player");
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			case 1:
				base.agent.speed = 3f;
				if (!TargetClosestPlayerInAnyCase() || (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > 20f && !((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null)))
				{
					LogIfDebugBuild("Stop Target Player");
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				else
				{
					((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
					base.targetPlayer.JumpToFearLevel(0.5f, true);
				}
				break;
			default:
				LogIfDebugBuild("This Behavior State doesn't exist!");
				break;
			}
		}

		public IEnumerator PlayStep()
		{
			while (!base.isEnemyDead)
			{
				if (base.currentBehaviourStateIndex == 0)
				{
					LogIfDebugBuild("Playing bellStep sound (Searching)");
					base.creatureSFX.pitch = 1f;
					switch (bellPitchRandom?.Next(0, 7))
					{
					case 1:
					{
						AudioSource creatureSFX6 = base.creatureSFX;
						creatureSFX6.pitch *= Mathf.Pow(1.05946f, 3f);
						break;
					}
					case 2:
					{
						AudioSource creatureSFX5 = base.creatureSFX;
						creatureSFX5.pitch *= Mathf.Pow(1.05946f, 5f);
						break;
					}
					case 3:
					{
						AudioSource creatureSFX4 = base.creatureSFX;
						creatureSFX4.pitch /= Mathf.Pow(1.05946f, 3f);
						break;
					}
					case 4:
					{
						AudioSource creatureSFX3 = base.creatureSFX;
						creatureSFX3.pitch /= Mathf.Pow(1.05946f, 5f);
						break;
					}
					case 5:
					{
						AudioSource creatureSFX2 = base.creatureSFX;
						creatureSFX2.pitch /= Mathf.Pow(1.05946f, 7f);
						break;
					}
					case 6:
					{
						AudioSource creatureSFX = base.creatureSFX;
						creatureSFX.pitch /= Mathf.Pow(1.05946f, 10f);
						break;
					}
					}
					base.creatureSFX.PlayOneShot(Plugin.bellStep);
					WalkieTalkie.TransmitOneShotAudio(base.creatureSFX, Plugin.bellStep, 1f);
					yield return (object)new WaitForSeconds(Random.Range(3f, 6f));
					yield return null;
				}
				if (base.currentBehaviourStateIndex == 1)
				{
					LogIfDebugBuild("Playing bellStep sound (Chasing)");
					base.creatureSFX.pitch = Random.Range(0.2f, 0.4f);
					base.creatureSFX.PlayOneShot(Plugin.bellStep);
					WalkieTalkie.TransmitOneShotAudio(base.creatureSFX, Plugin.bellStep, 1f);
					yield return (object)new WaitForSeconds(Random.Range(0.4f, 0.8f));
					yield return null;
				}
			}
		}

		private bool FoundClosestPlayerInRange(float range, float senseRange)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).TargetClosestPlayer(1.5f, true, 70f);
			if ((Object)(object)base.targetPlayer == (Object)null)
			{
				((EnemyAI)this).TargetClosestPlayer(1.5f, false, 70f);
				range = senseRange;
			}
			return (Object)(object)base.targetPlayer != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < range;
		}

		private bool TargetClosestPlayerInAnyCase()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			base.mostOptimalDistance = 2000f;
			base.targetPlayer = null;
			for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++)
			{
				base.tempDist = Vector3.Distance(((Component)this).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position);
				if (base.tempDist < base.mostOptimalDistance)
				{
					base.mostOptimalDistance = base.tempDist;
					base.targetPlayer = StartOfRound.Instance.allPlayerScripts[i];
				}
			}
			if ((Object)(object)base.targetPlayer == (Object)null)
			{
				return false;
			}
			return true;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val != (Object)null)
			{
				val.DamagePlayer(90, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
				val.JumpToFearLevel(1f, true);
			}
		}

		protected override void __initializeVariables()
		{
			((EnemyAI)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "BellMonsterAI";
		}
	}
	[BepInPlugin("Drak.BellMonster", "BellMonster", "1.0.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		public static AudioClip? bellStep;

		internal static PluginConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "bellmonsterassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load Bell Monster assets.");
				return;
			}
			Logger.LogInfo((object)"Successfully loaded Bell Monster assets.");
			EnemyType val = ModAssets.LoadAsset<EnemyType>("BellMonsterObj");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("BellMonsterTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("BellMonsterTK");
			bellStep = ModAssets.LoadAsset<AudioClip>("BellStep.ogg");
			if ((Object)(object)bellStep == (Object)null)
			{
				Logger.LogError((object)"Failed to load BellStep.ogg asset.");
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), val2, val3);
			Logger.LogInfo((object)"Plugin Drak.BellMonster is loaded!");
		}

		private static void InitializeNetworkBehaviours()
		{
			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);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Drak.BellMonster";

		public const string PLUGIN_NAME = "BellMonster";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}
namespace BellMonster.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> SpawnWeight;

		public PluginConfig(ConfigFile cfg)
		{
			SpawnWeight = cfg.Bind<int>("General", "Spawn weight", 20, "The spawn chance weight for BellMonster, relative to other existing enemies.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			ClearUnusedEntries(cfg);
		}

		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
}
namespace Drak.BellMonster.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}