Decompiled source of SmallfryEnemy v1.0.2

SmallfryEnemy.dll

Decompiled 2 hours 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 BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using SmallfryEnemy.Configuration;
using Unity.Netcode.Components;
using UnityEngine;
using com.riskivr.SmallfryEnemy.NetcodePatcher;

[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("com.riskivr.SmallfryEnemy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a572bf473d62974fca65352ee701f286f5e94e13")]
[assembly: AssemblyProduct("SmallfryEnemy")]
[assembly: AssemblyTitle("com.riskivr.SmallfryEnemy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 SmallfryEnemy
{
	[BepInPlugin("com.riskivr.SmallfryEnemy", "SmallfryEnemy", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		internal static PluginConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "smallfryassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			EnemyType val = ModAssets.LoadAsset<EnemyType>("Smallfry");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("SmallfryEnemyTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("SmallfryEnemyTK");
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), val2, val3);
			Logger.LogInfo((object)"Plugin com.riskivr.SmallfryEnemy is awake :3");
		}

		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 class SmallfryEnemy : EnemyAI
	{
		private enum States
		{
			Idle,
			Active
		}

		[SerializeField]
		private AudioClip[] vo;

		[SerializeField]
		private NetworkAnimator networkAnimator;

		private float attackCooldown;

		public override void Start()
		{
			((EnemyAI)this).Start();
			base.agent.speed = 0f;
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			if ((Object)(object)base.targetPlayer != (Object)null && base.targetPlayer.isPlayerDead)
			{
				base.targetPlayer = null;
			}
			if (attackCooldown > 0f)
			{
				attackCooldown -= Time.deltaTime;
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				Idle();
				break;
			case 1:
				Active();
				break;
			}
		}

		public void Idle()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 50f, LayerMask.GetMask(new string[1] { "Player" }), (QueryTriggerInteraction)2);
			Collider[] array2 = array;
			PlayerControllerB val2 = default(PlayerControllerB);
			foreach (Collider val in array2)
			{
				if (((Component)val).gameObject.TryGetComponent<PlayerControllerB>(ref val2) && val2.isPlayerControlled && !val2.isPlayerDead)
				{
					base.targetPlayer = val2;
					base.agent.speed = 7f;
					base.creatureVoice.PlayOneShot(vo[Random.Range(0, vo.Length)]);
					base.creatureSFX.volume = 1f;
					base.creatureAnimator.SetBool("Walk", true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
			}
		}

		public void Active()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.targetPlayer == (Object)null)
			{
				base.creatureAnimator.SetBool("Walk", false);
				base.creatureSFX.volume = 0f;
				base.agent.speed = 0f;
				((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			}
			else
			{
				((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (!(attackCooldown > 0f) && !base.isEnemyDead)
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)base.targetPlayer))
				{
					Vector3 val2 = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
					Vector3 val3 = ((Vector3)(ref val2)).normalized * 5f;
					val.DamagePlayer(10, true, true, (CauseOfDeath)0, 0, false, val3);
					base.creatureVoice.PlayOneShot(vo[Random.Range(0, vo.Length)]);
					base.creatureAnimator.SetInteger("AttackInt", Random.Range(0, 2));
					networkAnimator.SetTrigger("Attack");
					attackCooldown = 0.75f;
				}
			}
		}

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

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "SmallfryEnemy";
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.riskivr.SmallfryEnemy";

		public const string PLUGIN_NAME = "SmallfryEnemy";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SmallfryEnemy.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 SmallfryEnemy, 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 com.riskivr.SmallfryEnemy.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}