Decompiled source of MacronEnemy v1.0.1

BepInEx\plugins\MacronEnemy\MacronMod.dll

Decompiled a day ago
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 BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using MacronMod;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MacronMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MacronMod")]
[assembly: AssemblyTitle("MacronMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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;
		}
	}
}
public class MacronAI : EnemyAI
{
	private enum State
	{
		Wandering,
		Chasing,
		Attacking,
		Passive
	}

	[CompilerGenerated]
	private sealed class <DespawnBody>d__31 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public MacronAI <>4__this;

		private Renderer[] <renderers>5__2;

		private Color[] <origColors>5__3;

		private float <fadeDuration>5__4;

		private float <elapsed>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <DespawnBody>d__31(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<renderers>5__2 = null;
			<origColors>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			MacronAI macronAI = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
			{
				<>1__state = -1;
				<renderers>5__2 = ((Component)macronAI).GetComponentsInChildren<Renderer>(true);
				<origColors>5__3 = (Color[])(object)new Color[<renderers>5__2.Length];
				for (int i = 0; i < <renderers>5__2.Length; i++)
				{
					if ((Object)(object)<renderers>5__2[i].material != (Object)null)
					{
						<origColors>5__3[i] = <renderers>5__2[i].material.GetColor("_BaseColor");
					}
				}
				<>2__current = (object)new WaitForSeconds(7f);
				<>1__state = 1;
				return true;
			}
			case 1:
				<>1__state = -1;
				<fadeDuration>5__4 = 3f;
				<elapsed>5__5 = 0f;
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if (<elapsed>5__5 < <fadeDuration>5__4)
			{
				<elapsed>5__5 += Time.deltaTime;
				float a = 1f - <elapsed>5__5 / <fadeDuration>5__4;
				for (int j = 0; j < <renderers>5__2.Length; j++)
				{
					if ((Object)(object)<renderers>5__2[j] != (Object)null && (Object)(object)<renderers>5__2[j].material != (Object)null)
					{
						Color val = <origColors>5__3[j];
						val.a = a;
						<renderers>5__2[j].material.SetColor("_BaseColor", val);
					}
				}
				<>2__current = null;
				<>1__state = 2;
				return true;
			}
			((EnemyAI)macronAI).EnableEnemyMesh(false, false);
			if (((NetworkBehaviour)macronAI).IsServer)
			{
				NetworkObject component = ((Component)macronAI).GetComponent<NetworkObject>();
				if ((Object)(object)component != (Object)null && component.IsSpawned)
				{
					component.Despawn(true);
				}
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <DoAttack>d__28 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public MacronAI <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <DoAttack>d__28(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			MacronAI macronAI = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				macronAI._isAttacking = true;
				macronAI._attackTimer = macronAI.attackCooldown;
				if ((Object)(object)macronAI.attackSound != (Object)null && (Object)(object)((EnemyAI)macronAI).creatureSFX != (Object)null)
				{
					((EnemyAI)macronAI).creatureSFX.PlayOneShot(macronAI.attackSound);
				}
				if ((Object)(object)((EnemyAI)macronAI).creatureAnimator != (Object)null)
				{
					((EnemyAI)macronAI).creatureAnimator.SetTrigger("Attack");
				}
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)((EnemyAI)macronAI).targetPlayer != (Object)null && !((EnemyAI)macronAI).targetPlayer.isPlayerDead && Vector3.Distance(((Component)macronAI).transform.position, ((Component)((EnemyAI)macronAI).targetPlayer).transform.position) <= macronAI.attackRange)
				{
					((EnemyAI)macronAI).targetPlayer.DamagePlayer((int)macronAI.damage, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
				}
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				macronAI._isAttacking = false;
				if (((EnemyAI)macronAI).currentBehaviourStateIndex == 2)
				{
					((EnemyAI)macronAI).SwitchToBehaviourState(1);
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <SelfActivate>d__16 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public MacronAI <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <SelfActivate>d__16(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			int num = <>1__state;
			MacronAI macronAI = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(2f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if (!macronAI._ready)
				{
					macronAI._ready = true;
					if ((Object)(object)((EnemyAI)macronAI).agent != (Object)null)
					{
						((Behaviour)((EnemyAI)macronAI).agent).enabled = true;
					}
					((EnemyAI)macronAI).EnableEnemyMesh(true, false);
					macronAI.PlayMusic(macronAI.walkMusic);
					if (((NetworkBehaviour)macronAI).IsOwner)
					{
						((MonoBehaviour)macronAI).StartCoroutine(macronAI.WanderCoroutine());
					}
					Debug.Log((object)"[Macron] Auto-activation (vent spawn)");
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <WanderCoroutine>d__27 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public MacronAI <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WanderCoroutine>d__27(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			MacronAI macronAI = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (!((EnemyAI)macronAI).isEnemyDead)
			{
				if (((EnemyAI)macronAI).currentBehaviourStateIndex == 0 && (Object)(object)((EnemyAI)macronAI).agent != (Object)null && ((EnemyAI)macronAI).agent.isOnNavMesh)
				{
					Vector3 randomNavMeshPositionInRadius = RoundManager.Instance.GetRandomNavMeshPositionInRadius(((Component)macronAI).transform.position, 15f, default(NavMeshHit));
					((EnemyAI)macronAI).SetDestinationToPosition(randomNavMeshPositionInRadius, false);
				}
				<>2__current = (object)new WaitForSeconds(5f);
				<>1__state = 1;
				return true;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[Header("Stats Macron")]
	public float attackRange = 2f;

	public float attackCooldown = 2f;

	public float detectionRange = 20f;

	public float damage = 25f;

	[Header("Audio Macron")]
	public AudioClip walkMusic;

	public AudioClip chaseMusic;

	public AudioClip attackSound;

	private AudioSource _musicSource;

	private bool _isAttacking;

	private float _attackTimer;

	private bool _ready;

	private bool _isDancing;

	private float _losTimer;

	private Vector3 _lastPos;

	public override void Start()
	{
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)base.agent == (Object)null)
		{
			base.agent = ((Component)this).GetComponent<NavMeshAgent>();
		}
		AudioSource[] components = ((Component)this).GetComponents<AudioSource>();
		if ((Object)(object)base.creatureSFX == (Object)null && components.Length != 0)
		{
			base.creatureSFX = components[0];
		}
		if ((Object)(object)base.creatureVoice == (Object)null && components.Length > 1)
		{
			base.creatureVoice = components[1];
		}
		if ((Object)(object)base.creatureAnimator == (Object)null)
		{
			base.creatureAnimator = ((Component)this).GetComponentInChildren<Animator>();
		}
		((EnemyAI)this).Start();
		if ((Object)(object)base.agent != (Object)null)
		{
			((Behaviour)base.agent).enabled = false;
		}
		_musicSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		_musicSource.spatialBlend = 1f;
		_musicSource.rolloffMode = (AudioRolloffMode)1;
		_musicSource.maxDistance = 30f;
		_musicSource.loop = true;
		_musicSource.volume = 0.8f;
		_lastPos = ((Component)this).transform.position;
		((EnemyAI)this).SwitchToBehaviourState(0);
		((MonoBehaviour)this).StartCoroutine(SelfActivate());
	}

	[IteratorStateMachine(typeof(<SelfActivate>d__16))]
	private IEnumerator SelfActivate()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <SelfActivate>d__16(0)
		{
			<>4__this = this
		};
	}

	public override void EnableEnemyMesh(bool enable, bool overrideDoNotSet = false)
	{
		((EnemyAI)this).EnableEnemyMesh(enable, overrideDoNotSet);
		if (enable && !_ready)
		{
			_ready = true;
			if ((Object)(object)base.agent != (Object)null)
			{
				((Behaviour)base.agent).enabled = true;
			}
			PlayMusic(walkMusic);
			if (((NetworkBehaviour)this).IsOwner)
			{
				((MonoBehaviour)this).StartCoroutine(WanderCoroutine());
			}
		}
	}

	public override void Update()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		((EnemyAI)this).Update();
		if (base.isEnemyDead)
		{
			return;
		}
		_attackTimer -= Time.deltaTime;
		if (_isDancing || !((Object)(object)base.creatureAnimator != (Object)null))
		{
			return;
		}
		Vector3 val = ((Component)this).transform.position - _lastPos;
		float magnitude = ((Vector3)(ref val)).magnitude;
		_lastPos = ((Component)this).transform.position;
		bool flag = magnitude > 0.001f && !_isAttacking;
		base.creatureAnimator.SetBool("Walk", flag);
		if (flag)
		{
			AnimatorStateInfo currentAnimatorStateInfo = base.creatureAnimator.GetCurrentAnimatorStateInfo(0);
			if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime >= 0.99f)
			{
				base.creatureAnimator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, 0, 0f);
			}
		}
	}

	public override void DoAIInterval()
	{
		((EnemyAI)this).DoAIInterval();
		if (!_ready || base.isEnemyDead || StartOfRound.Instance.allPlayersDead || (Object)(object)base.agent == (Object)null || !base.agent.isOnNavMesh)
		{
			return;
		}
		if (!_isDancing && base.currentBehaviourStateIndex != 3)
		{
			PlayerControllerB dancingPlayer = GetDancingPlayer();
			if ((Object)(object)dancingPlayer != (Object)null)
			{
				base.targetPlayer = dancingPlayer;
				((EnemyAI)this).SwitchToBehaviourState(3);
				StartDancing();
			}
		}
		switch (base.currentBehaviourStateIndex)
		{
		case 0:
			DoWandering();
			break;
		case 1:
			DoChasing();
			break;
		case 3:
			DoPassive();
			break;
		case 2:
			break;
		}
	}

	private bool HasLineOfSight(PlayerControllerB player)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)this).transform.position + Vector3.up * 1.5f;
		Vector3 val2 = ((Component)player).transform.position + Vector3.up * 1f - val;
		return !Physics.Raycast(val, ((Vector3)(ref val2)).normalized, ((Vector3)(ref val2)).magnitude, StartOfRound.Instance.collidersAndRoomMask);
	}

	private PlayerControllerB GetDancingPlayer()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (!val.isPlayerDead && val.isPlayerControlled && val.performingEmote)
			{
				int num = (((Object)(object)val.playerBodyAnimator != (Object)null) ? val.playerBodyAnimator.GetInteger("emoteNumber") : (-1));
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
				Debug.Log((object)$"[Macron] Joueur emote detecte: performingEmote=true, emoteNumber={num}, dist={num2:F1}");
				if (num >= 1 && num2 <= detectionRange)
				{
					return val;
				}
			}
		}
		return null;
	}

	private void StartDancing()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		_isDancing = true;
		Debug.Log((object)"[Macron] StartDancing() appele !");
		if ((Object)(object)base.creatureAnimator != (Object)null)
		{
			base.creatureAnimator.SetBool("Walk", false);
			base.creatureAnimator.SetBool("Dance", true);
			Debug.Log((object)"[Macron] Animator Dance=true set");
		}
		if ((Object)(object)base.agent != (Object)null && base.agent.isOnNavMesh)
		{
			base.agent.isStopped = true;
			base.agent.velocity = Vector3.zero;
		}
		List<AudioClip> list = new List<AudioClip>();
		if ((Object)(object)MacronPlugin.DanceMusic1 != (Object)null)
		{
			list.Add(MacronPlugin.DanceMusic1);
		}
		if ((Object)(object)MacronPlugin.DanceMusic2 != (Object)null)
		{
			list.Add(MacronPlugin.DanceMusic2);
		}
		if ((Object)(object)MacronPlugin.DanceMusic3 != (Object)null)
		{
			list.Add(MacronPlugin.DanceMusic3);
		}
		if (list.Count > 0)
		{
			AudioClip clip = list[Random.Range(0, list.Count)];
			_musicSource.loop = true;
			PlayMusic(clip);
		}
	}

	private void StopDancing()
	{
		_isDancing = false;
		if ((Object)(object)base.creatureAnimator != (Object)null)
		{
			base.creatureAnimator.SetBool("Dance", false);
		}
		if ((Object)(object)base.agent != (Object)null && base.agent.isOnNavMesh)
		{
			base.agent.isStopped = false;
		}
	}

	private void DoPassive()
	{
		if ((Object)(object)base.targetPlayer == (Object)null || base.targetPlayer.isPlayerDead || !base.targetPlayer.performingEmote)
		{
			Debug.Log((object)"[Macron] Joueur a arrete de danser, retour Wandering");
			StopDancing();
			((EnemyAI)this).SwitchToBehaviourState(0);
			PlayMusic(walkMusic);
		}
	}

	private void DoWandering()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB closestPlayer = GetClosestPlayer();
		if (!((Object)(object)closestPlayer == (Object)null) && Vector3.Distance(((Component)this).transform.position, ((Component)closestPlayer).transform.position) <= detectionRange && HasLineOfSight(closestPlayer))
		{
			base.targetPlayer = closestPlayer;
			((EnemyAI)this).SwitchToBehaviourState(1);
			PlayMusic(chaseMusic);
		}
	}

	private void DoChasing()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)base.targetPlayer == (Object)null || base.targetPlayer.isPlayerDead)
		{
			((EnemyAI)this).SwitchToBehaviourState(0);
			PlayMusic(walkMusic);
			return;
		}
		float num = Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position);
		if (num > attackRange && !HasLineOfSight(base.targetPlayer))
		{
			_losTimer += base.AIIntervalTime;
			if (_losTimer >= 5f)
			{
				_losTimer = 0f;
				((EnemyAI)this).SwitchToBehaviourState(0);
				PlayMusic(walkMusic);
				return;
			}
		}
		else
		{
			_losTimer = 0f;
		}
		if (num > detectionRange * 2f)
		{
			_losTimer = 0f;
			((EnemyAI)this).SwitchToBehaviourState(0);
			PlayMusic(walkMusic);
		}
		else if (num <= attackRange && _attackTimer <= 0f && !_isAttacking)
		{
			((EnemyAI)this).SwitchToBehaviourState(2);
			((MonoBehaviour)this).StartCoroutine(DoAttack());
		}
		else if ((Object)(object)base.agent != (Object)null && base.agent.isOnNavMesh)
		{
			((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
		}
	}

	[IteratorStateMachine(typeof(<WanderCoroutine>d__27))]
	private IEnumerator WanderCoroutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WanderCoroutine>d__27(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<DoAttack>d__28))]
	private IEnumerator DoAttack()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DoAttack>d__28(0)
		{
			<>4__this = this
		};
	}

	public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
	{
		((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
		if (!base.isEnemyDead)
		{
			base.enemyHP -= force;
			Debug.Log((object)$"[Macron] HitEnemy! force={force}, enemyHP restant={base.enemyHP}");
			if (base.enemyHP <= 0)
			{
				((EnemyAI)this).KillEnemyOnOwnerClient(false);
			}
		}
	}

	public override void KillEnemy(bool destroy = false)
	{
		((EnemyAI)this).KillEnemy(destroy);
		StopMusic();
		if ((Object)(object)base.creatureAnimator != (Object)null)
		{
			base.creatureAnimator.SetBool("Death", true);
		}
		if ((Object)(object)_musicSource != (Object)null)
		{
			AudioClip deathSound = MacronPlugin.DeathSound;
			AudioClip deathSound2 = MacronPlugin.DeathSound2;
			AudioClip val = null;
			val = ((!((Object)(object)deathSound != (Object)null) || !((Object)(object)deathSound2 != (Object)null)) ? (deathSound ?? deathSound2) : ((Random.value < 0.5f) ? deathSound : deathSound2));
			if ((Object)(object)val != (Object)null)
			{
				_musicSource.loop = false;
				_musicSource.clip = val;
				_musicSource.Play();
			}
		}
		if (((NetworkBehaviour)this).IsServer)
		{
			SpawnLoot();
		}
		((MonoBehaviour)this).StartCoroutine(DespawnBody());
	}

	[IteratorStateMachine(typeof(<DespawnBody>d__31))]
	private IEnumerator DespawnBody()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DespawnBody>d__31(0)
		{
			<>4__this = this
		};
	}

	private void SpawnLoot()
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		List<SpawnableItemWithRarity> spawnableScrap = RoundManager.Instance.currentLevel.spawnableScrap;
		if (spawnableScrap == null || spawnableScrap.Count == 0)
		{
			Debug.Log((object)"[Macron] Aucun scrap dans le niveau pour le loot !");
			return;
		}
		int num = Random.Range(6, 16);
		Debug.Log((object)$"[Macron] Drop de {num} items...");
		Transform spawnedScrapContainer = RoundManager.Instance.spawnedScrapContainer;
		for (int i = 0; i < num; i++)
		{
			Item spawnableItem = spawnableScrap[Random.Range(0, spawnableScrap.Count)].spawnableItem;
			if ((Object)(object)spawnableItem.spawnPrefab == (Object)null)
			{
				continue;
			}
			Vector3 val = ((Component)this).transform.position + new Vector3(Random.Range(-2f, 2f), 0.5f, Random.Range(-2f, 2f));
			GameObject val2 = Object.Instantiate<GameObject>(spawnableItem.spawnPrefab, val, Quaternion.identity, ((Object)(object)spawnedScrapContainer != (Object)null) ? spawnedScrapContainer : ((Component)this).transform.parent);
			GrabbableObject component = val2.GetComponent<GrabbableObject>();
			if ((Object)(object)component != (Object)null)
			{
				((Component)component).transform.rotation = Quaternion.Euler(spawnableItem.restingRotation);
				component.fallTime = 0f;
				int num2 = (int)((float)Random.Range(spawnableItem.minValue, spawnableItem.maxValue + 1) * RoundManager.Instance.scrapValueMultiplier);
				if (num2 < 1)
				{
					num2 = Random.Range(15, 80);
				}
				component.scrapValue = num2;
				ScanNodeProperties componentInChildren = val2.GetComponentInChildren<ScanNodeProperties>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.scrapValue = num2;
					componentInChildren.subText = $"Value: ${num2}";
				}
			}
			NetworkObject component2 = val2.GetComponent<NetworkObject>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Spawn(false);
			}
		}
	}

	private void PlayMusic(AudioClip clip)
	{
		if (!((Object)(object)_musicSource == (Object)null) && !((Object)(object)clip == (Object)null) && (!((Object)(object)_musicSource.clip == (Object)(object)clip) || !_musicSource.isPlaying))
		{
			_musicSource.clip = clip;
			_musicSource.Play();
		}
	}

	private void StopMusic()
	{
		if ((Object)(object)_musicSource != (Object)null)
		{
			_musicSource.Stop();
		}
	}

	private PlayerControllerB GetClosestPlayer()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB result = null;
		float num = float.MaxValue;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (!val.isPlayerDead && val.isPlayerControlled)
			{
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}
}
namespace MacronMod
{
	[BepInPlugin("jamesmod.macron", "Macron Enemy", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MacronPlugin : BaseUnityPlugin
	{
		public const string GUID = "jamesmod.macron";

		public const string NAME = "Macron Enemy";

		public const string VERSION = "1.0.0";

		internal static ManualLogSource Log;

		internal static MacronPlugin Instance;

		public static EnemyType MacronEnemyType;

		public static AudioClip WalkingMusic;

		public static AudioClip ChaseMusic;

		public static AudioClip DeathSound;

		public static AudioClip DeathSound2;

		public static AudioClip DanceMusic1;

		public static AudioClip DanceMusic2;

		public static AudioClip DanceMusic3;

		private static bool _helperCreated;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Chargement du mod Macron...");
			LoadAssets();
			RegisterEnemy();
			new Harmony("jamesmod.macron").PatchAll(Assembly.GetExecutingAssembly());
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogInfo((object)"Macron pret !");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (!_helperCreated)
			{
				_helperCreated = true;
				GameObject val = new GameObject("MacronSoundLoader");
				Object.DontDestroyOnLoad((Object)val);
				val.AddComponent<MacronSoundLoader>();
			}
		}

		private void LoadAssets()
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Expected O, but got Unknown
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Expected O, but got Unknown
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Expected O, but got Unknown
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Expected O, but got Unknown
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "macronassets"));
			if ((Object)(object)val == (Object)null)
			{
				Log.LogError((object)"Impossible de charger macronassets !");
				return;
			}
			GameObject val2 = val.LoadAsset<GameObject>("MacronEnnemy");
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = val.LoadAsset<GameObject>("macronennemy");
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Log.LogError((object)"Prefab non trouve !");
				return;
			}
			val2.layer = 19;
			Shader val3 = Shader.Find("HDRP/Lit");
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren)
			{
				((Component)val4).gameObject.SetActive(true);
				((Component)val4).gameObject.layer = 19;
				if ((Object)(object)val3 != (Object)null && (Object)(object)val4.sharedMaterial != (Object)null)
				{
					Texture mainTexture = val4.sharedMaterial.mainTexture;
					Color color = val4.sharedMaterial.color;
					Material val5 = new Material(val3);
					if ((Object)(object)mainTexture != (Object)null)
					{
						val5.SetTexture("_BaseColorMap", mainTexture);
					}
					val5.SetColor("_BaseColor", color);
					val4.sharedMaterial = val5;
				}
				SkinnedMeshRenderer val6 = (SkinnedMeshRenderer)(object)((val4 is SkinnedMeshRenderer) ? val4 : null);
				if (val6 != null)
				{
					val6.updateWhenOffscreen = true;
				}
			}
			if ((Object)(object)val3 != (Object)null)
			{
				Log.LogInfo((object)"Matériaux convertis vers HDRP/Lit");
			}
			else
			{
				Log.LogWarning((object)"Shader HDRP/Lit introuvable au chargement — sera corrigé au runtime");
			}
			val2.transform.localScale = Vector3.one * 1.7f;
			if ((Object)(object)val2.GetComponent<NetworkObject>() == (Object)null)
			{
				val2.AddComponent<NetworkObject>();
			}
			if ((Object)(object)val2.GetComponent<NavMeshAgent>() == (Object)null)
			{
				val2.AddComponent<NavMeshAgent>();
			}
			AudioSource[] components = val2.GetComponents<AudioSource>();
			AudioSource creatureSFX = ((components.Length != 0) ? components[0] : val2.AddComponent<AudioSource>());
			AudioSource creatureVoice = ((components.Length > 1) ? components[1] : val2.AddComponent<AudioSource>());
			MacronAI macronAI = val2.GetComponent<MacronAI>();
			if ((Object)(object)macronAI == (Object)null)
			{
				macronAI = val2.AddComponent<MacronAI>();
			}
			((EnemyAI)macronAI).enemyHP = 3;
			((EnemyAI)macronAI).creatureSFX = creatureSFX;
			((EnemyAI)macronAI).creatureVoice = creatureVoice;
			((EnemyAI)macronAI).creatureAnimator = val2.GetComponentInChildren<Animator>();
			((EnemyAI)macronAI).agent = val2.GetComponent<NavMeshAgent>();
			((EnemyAI)macronAI).agent.speed = 3.5f;
			((EnemyAI)macronAI).agent.angularSpeed = 120f;
			((EnemyAI)macronAI).agent.acceleration = 8f;
			BoxCollider val7 = val2.GetComponent<BoxCollider>();
			if ((Object)(object)val7 == (Object)null)
			{
				val7 = val2.AddComponent<BoxCollider>();
			}
			val7.center = new Vector3(0f, 0.9f, 0f);
			val7.size = new Vector3(0.6f, 1.8f, 0.6f);
			EnemyAICollisionDetect val8 = val2.GetComponent<EnemyAICollisionDetect>();
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = val2.AddComponent<EnemyAICollisionDetect>();
			}
			val8.mainScript = (EnemyAI)(object)macronAI;
			Log.LogInfo((object)"MacronAI configure avec tous les composants EnemyAI !");
			MacronEnemyType = ScriptableObject.CreateInstance<EnemyType>();
			MacronEnemyType.enemyName = "Macron";
			MacronEnemyType.enemyPrefab = val2;
			MacronEnemyType.isOutsideEnemy = false;
			MacronEnemyType.isDaytimeEnemy = false;
			MacronEnemyType.probabilityCurve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
			MacronEnemyType.PowerLevel = 2f;
			MacronEnemyType.MaxCount = 2;
			WalkingMusic = val.LoadAsset<AudioClip>("Macron walking music");
			ChaseMusic = val.LoadAsset<AudioClip>("Macron Chase music");
			macronAI.walkMusic = WalkingMusic;
			macronAI.chaseMusic = ChaseMusic;
			((EnemyAI)macronAI).enemyType = MacronEnemyType;
			((EnemyAI)macronAI).enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[4]
			{
				new EnemyBehaviourState
				{
					name = "Wandering"
				},
				new EnemyBehaviourState
				{
					name = "Chasing"
				},
				new EnemyBehaviourState
				{
					name = "Attacking"
				},
				new EnemyBehaviourState
				{
					name = "Passive"
				}
			};
			Log.LogInfo((object)"Assets charges !");
		}

		private void RegisterEnemy()
		{
			if ((Object)(object)MacronEnemyType == (Object)null)
			{
				Log.LogError((object)"EnemyType null, impossible d'enregistrer Macron !");
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(MacronEnemyType.enemyPrefab);
			Enemies.RegisterEnemy(MacronEnemyType, 100, (LevelTypes)(-1), (SpawnType)0, (TerminalNode)null, (TerminalKeyword)null);
			Log.LogInfo((object)"Macron enregistre comme ennemi interieur (rarity: 100) !");
		}
	}
	internal class MacronSoundLoader : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <LoadAllSounds>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MacronSoundLoader <>4__this;

			private string <pluginDir>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadAllSounds>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<pluginDir>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				MacronSoundLoader macronSoundLoader = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<pluginDir>5__2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
					<>2__current = macronSoundLoader.LoadMp3(Path.Combine(<pluginDir>5__2, "macron_death.mp3"), delegate(AudioClip clip)
					{
						MacronPlugin.DeathSound = clip;
					});
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = macronSoundLoader.LoadMp3(Path.Combine(<pluginDir>5__2, "macron_death2.mp3"), delegate(AudioClip clip)
					{
						MacronPlugin.DeathSound2 = clip;
					});
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = macronSoundLoader.LoadMp3(Path.Combine(<pluginDir>5__2, "macron_dance1.mp3"), delegate(AudioClip clip)
					{
						MacronPlugin.DanceMusic1 = clip;
					});
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<>2__current = macronSoundLoader.LoadMp3(Path.Combine(<pluginDir>5__2, "macron_dance2.mp3"), delegate(AudioClip clip)
					{
						MacronPlugin.DanceMusic2 = clip;
					});
					<>1__state = 4;
					return true;
				case 4:
					<>1__state = -1;
					<>2__current = macronSoundLoader.LoadMp3(Path.Combine(<pluginDir>5__2, "macron_dance3.mp3"), delegate(AudioClip clip)
					{
						MacronPlugin.DanceMusic3 = clip;
					});
					<>1__state = 5;
					return true;
				case 5:
					<>1__state = -1;
					MacronPlugin.Log.LogInfo((object)"Sons charges (death + dance) !");
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <LoadMp3>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string path;

			public Action<AudioClip> onLoaded;

			private UnityWebRequest <request>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadMp3>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<request>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Invalid comparison between Unknown and I4
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						if (!File.Exists(path))
						{
							MacronPlugin.Log.LogWarning((object)("Fichier non trouve: " + Path.GetFileName(path)));
							return false;
						}
						string text = "file:///" + path.Replace("\\", "/");
						<request>5__2 = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)13);
						<>1__state = -3;
						<>2__current = <request>5__2.SendWebRequest();
						<>1__state = 1;
						return true;
					}
					case 1:
						<>1__state = -3;
						if ((int)<request>5__2.result == 1)
						{
							onLoaded(DownloadHandlerAudioClip.GetContent(<request>5__2));
						}
						else
						{
							MacronPlugin.Log.LogError((object)("Erreur chargement: " + <request>5__2.error));
						}
						<>m__Finally1();
						<request>5__2 = null;
						return false;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<request>5__2 != null)
				{
					((IDisposable)<request>5__2).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(LoadAllSounds());
		}

		[IteratorStateMachine(typeof(<LoadAllSounds>d__1))]
		private IEnumerator LoadAllSounds()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAllSounds>d__1(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<LoadMp3>d__2))]
		private IEnumerator LoadMp3(string path, Action<AudioClip> onLoaded)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadMp3>d__2(0)
			{
				path = path,
				onLoaded = onLoaded
			};
		}
	}
}