Decompiled source of HappyBall v3.2.1

juregs.HappyBall.dll

Decompiled a week ago
#define DEBUG
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 HappyBall.Configuration;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using juregs.HappyBall.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("juregs.HappyBall")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyInformationalVersion("3.2.1+0864a05544691c96bb0f101813317f1ce77b7629")]
[assembly: AssemblyProduct("HappyBall")]
[assembly: AssemblyTitle("juregs.HappyBall")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.2.1.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;
		}
	}
}
[RequireComponent(typeof(AudioSource))]
public class BallBounceToVoice : MonoBehaviour
{
	public AudioSource creatureVoice;

	public Transform happyBall;

	public float bounceStrength = 0.5f;

	public float bounceSpeed = 20f;

	private float[] audioSamples = new float[256];

	private void Update()
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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)
		if (!((Object)(object)creatureVoice == (Object)null) && !((Object)(object)happyBall == (Object)null) && creatureVoice.isPlaying)
		{
			creatureVoice.GetOutputData(audioSamples, 0);
			float num = 0f;
			float[] array = audioSamples;
			foreach (float num2 in array)
			{
				num += Mathf.Abs(num2);
			}
			float num3 = num / (float)audioSamples.Length;
			float y = Mathf.Sin(Time.time * bounceSpeed) * num3 * bounceStrength;
			Vector3 localPosition = happyBall.localPosition;
			localPosition.y = y;
			happyBall.localPosition = localPosition;
		}
	}
}
[RequireComponent(typeof(AudioSource))]
public class BallShake : MonoBehaviour
{
	[Header("Referência ao AudioSource (música)")]
	[Tooltip("Arraste aqui o AudioSource que toca sua playlist")]
	public AudioSource audioSource;

	[Header("Configurações de Shake")]
	[Tooltip("Quanto maior, mais intenso será o tremor")]
	public float shakeIntensity = 2f;

	[Tooltip("Velocidade de oscilação vertical")]
	public float shakeSpeed = 8f;

	[Tooltip("Limiar mínimo para considerar que há batida/bass")]
	public float threshold = 0.01f;

	private Vector3 originalPos;

	private float[] spectrum = new float[512];

	private void Awake()
	{
		if ((Object)(object)audioSource == (Object)null)
		{
			audioSource = ((Component)this).GetComponent<AudioSource>();
			Debug.LogWarning((object)"[BallShake] AudioSource não estava atribuído; pegando do próprio GameObject.");
		}
		if ((Object)(object)audioSource == (Object)null)
		{
			Debug.LogError((object)"[BallShake] AudioSource ausente! Arraste manualmente no Inspector.");
		}
	}

	private void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		originalPos = ((Component)this).transform.localPosition;
		Vector3 val = originalPos;
		Debug.Log((object)("[BallShake] Posição original: " + ((object)(Vector3)(ref val)).ToString()));
	}

	private void Update()
	{
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//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_00f8: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)audioSource == (Object)null))
		{
			if (!audioSource.isPlaying)
			{
				Debug.Log((object)"[BallShake] AudioSource não está tocando.");
			}
			audioSource.GetSpectrumData(spectrum, 0, (FFTWindow)5);
			float num = 0f;
			for (int i = 0; i < 8; i++)
			{
				num += spectrum[i];
			}
			float num2 = num / 8f * shakeIntensity;
			Debug.Log((object)$"[BallShake] Bass magnitude: {num2:F4}");
			if (num2 > threshold)
			{
				float num3 = Mathf.Abs(Mathf.Sin(Time.time * shakeSpeed)) * num2;
				Vector3 val = originalPos + Vector3.up * num3;
				((Component)this).transform.localPosition = Vector3.Lerp(((Component)this).transform.localPosition, val, Time.deltaTime * shakeSpeed);
			}
			else
			{
				((Component)this).transform.localPosition = Vector3.Lerp(((Component)this).transform.localPosition, originalPos, Time.deltaTime * shakeSpeed);
			}
		}
	}
}
public class EyeTracking : MonoBehaviour
{
	[Header("Referências")]
	public Transform target;

	public Transform leftEye;

	public Transform rightEye;

	[Header("Configurações")]
	public float eyeRadius = 0.1f;

	private void Update()
	{
		TrackEye(leftEye);
		TrackEye(rightEye);
	}

	private void TrackEye(Transform eye)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0021: 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)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_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_0049: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = target.position - eye.position;
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		Vector3 val2 = eye.InverseTransformDirection(normalized) * eyeRadius;
		val2 = Vector3.ClampMagnitude(val2, eyeRadius);
		Transform child = eye.GetChild(0);
		child.localPosition = val2;
	}
}
public class MusicPlayer : MonoBehaviour
{
	[Tooltip("Arraste aqui todas as músicas que desejar no seu playlist")]
	public List<AudioClip> playlist = new List<AudioClip>();

	[Tooltip("Reproduzir faixas em ordem aleatória")]
	public bool shuffle = false;

	[Tooltip("Reproduzir em loop toda a playlist")]
	public bool loopPlaylist = true;

	private AudioSource audioSource;

	private int currentIndex = 0;

	private void Awake()
	{
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		audioSource.playOnAwake = false;
		audioSource.loop = false;
	}

	private void Start()
	{
		if (playlist.Count == 0)
		{
			Debug.LogWarning((object)"Playlist vazia! Adicione áudios na lista.");
		}
		else
		{
			PlayCurrentTrack();
		}
	}

	private void Update()
	{
		if (!audioSource.isPlaying && playlist.Count > 0)
		{
			PlayNext();
		}
	}

	public void PlayCurrentTrack()
	{
		audioSource.clip = playlist[currentIndex];
		audioSource.Play();
	}

	public void PlayNext()
	{
		if (shuffle)
		{
			currentIndex = Random.Range(0, playlist.Count);
		}
		else
		{
			currentIndex = (currentIndex + 1) % playlist.Count;
		}
		PlayCurrentTrack();
	}

	public void PlayPrevious()
	{
		if (shuffle)
		{
			currentIndex = Random.Range(0, playlist.Count);
		}
		else
		{
			currentIndex = (currentIndex - 1 + playlist.Count) % playlist.Count;
		}
		PlayCurrentTrack();
	}

	public void PlayTrackAt(int index)
	{
		if (index >= 0 && index < playlist.Count)
		{
			currentIndex = index;
			PlayCurrentTrack();
		}
	}

	public void TogglePlayPause()
	{
		if (audioSource.isPlaying)
		{
			audioSource.Pause();
		}
		else
		{
			audioSource.Play();
		}
	}
}
[RequireComponent(typeof(Light))]
public class PointRGBController : MonoBehaviour
{
	[Tooltip("Velocidade do ciclo de cores (hue por segundo)")]
	[Range(0.1f, 5f)]
	public float cycleSpeed = 1f;

	[Tooltip("Saturação da cor (0–1)")]
	[Range(0f, 1f)]
	public float saturation = 1f;

	[Tooltip("Brilho da cor (0–1)")]
	[Range(0f, 1f)]
	public float brightness = 1f;

	private Light pointLight;

	private void Awake()
	{
		pointLight = ((Component)this).GetComponent<Light>();
		pointLight.type = (LightType)2;
	}

	private void Update()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Repeat(Time.time * cycleSpeed, 1f);
		Color color = Color.HSVToRGB(num, saturation, brightness);
		pointLight.color = color;
	}
}
[RequireComponent(typeof(AudioSource))]
public class RandomMusicPlayer : MonoBehaviour
{
	public AudioClip[] musicTracks;

	private AudioSource _audioSource;

	private void Awake()
	{
		_audioSource = ((Component)this).GetComponent<AudioSource>();
		_audioSource.playOnAwake = false;
	}

	private void Start()
	{
		PlayRandomTrack();
	}

	private void Update()
	{
		if (!_audioSource.isPlaying)
		{
			PlayRandomTrack();
		}
	}

	private void PlayRandomTrack()
	{
		if (musicTracks != null && musicTracks.Length != 0)
		{
			int num = Random.Range(0, musicTracks.Length);
			_audioSource.clip = musicTracks[num];
			_audioSource.Play();
		}
	}
}
[RequireComponent(typeof(Light))]
public class RandomSpotLightRotator : MonoBehaviour
{
	[Header("Velocidade de rotação (graus por segundo)")]
	public float rotationSpeed = 60f;

	[Header("Mudar direção a cada X segundos (se <= 0, muda todo frame)")]
	public float changeInterval = 2f;

	private Vector3 currentAxis;

	private float timer;

	private void Start()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Light component = ((Component)this).GetComponent<Light>();
		if ((int)component.type > 0)
		{
			LightType type = component.type;
			Debug.LogWarning((object)("Esse script foi desenhado pra Spot Light, mas o componente é " + ((object)(LightType)(ref type)).ToString()));
		}
		PickNewAxis();
	}

	private void Update()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		timer += Time.deltaTime;
		if (timer >= changeInterval)
		{
			PickNewAxis();
			timer = 0f;
		}
		((Component)this).transform.Rotate(currentAxis, rotationSpeed * Time.deltaTime, (Space)1);
	}

	private void PickNewAxis()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		currentAxis = Random.onUnitSphere;
	}
}
public class RGBLightCycle : MonoBehaviour
{
	public Light targetLight;

	public float cycleSpeed = 1f;

	private void Start()
	{
		if ((Object)(object)targetLight == (Object)null)
		{
			targetLight = ((Component)this).GetComponent<Light>();
		}
	}

	private void Update()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.PingPong(Time.time * cycleSpeed, 1f);
		Color val = Color.Lerp(Color.red, Color.green, num);
		val = Color.Lerp(val, Color.blue, num);
		targetLight.color = val;
	}
}
namespace HappyBall
{
	[RequireComponent(typeof(AudioListener))]
	public class AudioBouncer : MonoBehaviour
	{
		[Tooltip("Intervalo, em segundos, entre cada captura de amostras de áudio.")]
		public float sampleInterval = 0.1f;

		[Tooltip("Quantidade de amostras que serão lidas por captura.")]
		public int sampleCount = 256;

		private float timer;

		private float[] samples;

		public event Action<float> OnAmplitudeUpdated;

		private void Awake()
		{
			samples = new float[sampleCount];
		}

		private void Update()
		{
			timer += Time.deltaTime;
			if (!(timer < sampleInterval))
			{
				timer = 0f;
				AudioListener.GetOutputData(samples, 0);
				float num = 0f;
				for (int i = 0; i < samples.Length; i++)
				{
					num += Mathf.Abs(samples[i]);
				}
				float obj = num / (float)samples.Length;
				this.OnAmplitudeUpdated?.Invoke(obj);
			}
		}
	}
	public class MusicPulseBall : MonoBehaviour
	{
		public float minScale = 1f;

		public float maxScale = 2f;

		public float sensitivity = 50f;

		public float smoothSpeed = 10f;

		private float[] samples = new float[512];

		private float currentLevel;

		private void Update()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			AudioListener.GetOutputData(samples, 0);
			float num = 0f;
			float[] array = samples;
			foreach (float num2 in array)
			{
				num += Mathf.Abs(num2);
			}
			currentLevel = Mathf.Clamp01(num / (float)samples.Length * sensitivity);
			float num3 = Mathf.Lerp(minScale, maxScale, currentLevel);
			float num4 = Mathf.Lerp(((Component)this).transform.localScale.x, num3, Time.deltaTime * smoothSpeed);
			((Component)this).transform.localScale = Vector3.one * num4;
		}
	}
	internal class HappyBallAI : EnemyAI
	{
		private enum State
		{
			SearchingForPlayer,
			ChasingPlayer,
			Investigating,
			ZappingArea
		}

		[Header("Distância da bola acima do chão ao spawn (metros)")]
		public float spawnHeightOffset = 1.2f;

		[Header("Configurações de bounce por áudio")]
		public float bounceStrength = 0.5f;

		public float bounceSpeed = 20f;

		private float currentAmplitude = 0f;

		private NavMeshAgent navAgent;

		private Vector3 lastDestination;

		private float destThresholdSqr = 0.25f;

		private static readonly RaycastHit[] raycastHits = (RaycastHit[])(object)new RaycastHit[1];

		private float lostSightTimer = 0f;

		private const float maxLostSightTime = 2f;

		private Vector3 lastKnownPos;

		private float investigateTimer = 0f;

		private const float investigateTime = 6f;

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

		public override void Start()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0024: 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)
			((EnemyAI)this).Start();
			Transform transform = ((Component)this).transform;
			transform.position += Vector3.up * spawnHeightOffset;
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.useGravity = false;
				component.isKinematic = true;
			}
			navAgent = ((Component)this).GetComponent<NavMeshAgent>();
			if ((Object)(object)navAgent != (Object)null)
			{
				navAgent.baseOffset = spawnHeightOffset;
				navAgent.updatePosition = false;
				navAgent.updateRotation = true;
			}
			AudioBouncer audioBouncer = Object.FindObjectOfType<AudioBouncer>();
			if ((Object)(object)audioBouncer != (Object)null)
			{
				audioBouncer.OnAmplitudeUpdated += delegate(float amp)
				{
					currentAmplitude = amp;
				};
			}
			LogIfDebugBuild("HappyBall Spawned");
			DoAnimationClientRpc("startWalk");
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
		}

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

		public override void DoAIInterval()
		{
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_012e: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			switch ((State)base.currentBehaviourStateIndex)
			{
			case State.SearchingForPlayer:
				base.agent.speed = 4f;
				if (FoundClosestPlayerInRange(30f))
				{
					LogIfDebugBuild("Start Target Player");
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				else if (TargetClosestPlayerInAnyCase())
				{
					LogIfDebugBuild("Fallback target sem LOS");
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			case State.ChasingPlayer:
				base.agent.speed = 4.5f;
				if (TargetClosestPlayerInAnyCase() && (Object)(object)base.targetPlayer != (Object)null)
				{
					Vector3 position = ((Component)this).transform.position;
					Vector3 position2 = ((Component)base.targetPlayer).transform.position;
					Vector3 val = position2 - position;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Vector3 targetPos = position2 - normalized * 0.4f;
					val = position - position2;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					bool flag = CheckLineOfSightForPosition(position2);
					if (sqrMagnitude <= 16f)
					{
						lostSightTimer = 0f;
					}
					else if (flag)
					{
						lostSightTimer = 0f;
					}
					else
					{
						lostSightTimer += Time.deltaTime;
					}
					if (sqrMagnitude > 900f || lostSightTimer > 2f)
					{
						lastKnownPos = position2;
						investigateTimer = 0f;
						((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					}
					else
					{
						TrySetDestination(targetPos);
					}
				}
				else
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			case State.Investigating:
				base.agent.speed = 2f;
				TrySetDestination(lastKnownPos);
				investigateTimer += Time.deltaTime;
				if (investigateTimer > 6f)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			case State.ZappingArea:
				base.agent.speed = 0f;
				break;
			default:
				LogIfDebugBuild("Estado desconhecido!");
				break;
			}
		}

		public void ZapArea()
		{
		}

		public void DamagePlayerPerSecond()
		{
			//IL_001c: 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)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				Vector3 val2 = ((Component)this).transform.position - ((Component)val).transform.position;
				if (((Vector3)(ref val2)).sqrMagnitude < 100f)
				{
					val2 = default(Vector3);
					val.DamagePlayer(5, true, true, (CauseOfDeath)0, 0, false, val2);
				}
			}
		}

		private bool FoundClosestPlayerInRange(float range)
		{
			//IL_0016: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			if (TargetClosestPlayerInAnyCase())
			{
				float num = range * range;
				Vector3 val = ((Component)this).transform.position - ((Component)base.targetPlayer).transform.position;
				return ((Vector3)(ref val)).sqrMagnitude < num;
			}
			return false;
		}

		private bool TargetClosestPlayerInAnyCase()
		{
			//IL_0045: 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)
			//IL_0055: 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)
			float num = float.MaxValue;
			base.targetPlayer = null;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isPlayerControlled && ((Behaviour)val).isActiveAndEnabled)
				{
					Vector3 val2 = ((Component)this).transform.position - ((Component)val).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						base.targetPlayer = val;
					}
				}
			}
			return (Object)(object)base.targetPlayer != (Object)null;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val != (Object)null)
			{
				LogIfDebugBuild("Collision with Player!");
				((EnemyAI)this).SwitchToBehaviourClientRpc(3);
				DoAnimationClientRpc("startZap");
			}
		}

		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;
				if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0 && !base.isEnemyDead)
				{
					((MonoBehaviour)this).StopCoroutine(base.searchCoroutine);
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
			}
		}

		[ClientRpc]
		public void DoAnimationClientRpc(string animationName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: 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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1429322745u, val, (RpcDelivery)0);
				bool flag = animationName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1429322745u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				LogIfDebugBuild("Animation: " + animationName);
				base.creatureAnimator.SetTrigger(animationName);
			}
		}

		private void LateUpdate()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)navAgent != (Object)null)
			{
				Vector3 nextPosition = navAgent.nextPosition;
				float num = Mathf.Sin(Time.time * bounceSpeed) * currentAmplitude * bounceStrength;
				nextPosition.y += spawnHeightOffset + num;
				((Component)this).transform.position = nextPosition;
			}
			else
			{
				Vector3 localPosition = ((Component)this).transform.localPosition;
				localPosition.y = Mathf.Sin(Time.time * bounceSpeed) * currentAmplitude * bounceStrength;
				((Component)this).transform.localPosition = localPosition;
			}
		}

		private void TrySetDestination(Vector3 targetPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = targetPos - lastDestination;
			if (((Vector3)(ref val)).sqrMagnitude > destThresholdSqr)
			{
				navAgent.SetDestination(targetPos);
				lastDestination = targetPos;
			}
		}

		private bool CheckLineOfSightForPosition(Vector3 pos)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position + Vector3.up * spawnHeightOffset;
			Vector3 val2 = pos + Vector3.up * 1.5f;
			Vector3 val3 = val2 - val;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			int num = Physics.RaycastNonAlloc(val, normalized, raycastHits, 35f);
			if (num > 0 && (Object)(object)((RaycastHit)(ref raycastHits[0])).collider != (Object)null)
			{
				return (Object)(object)((Component)((RaycastHit)(ref raycastHits[0])).collider).GetComponent<PlayerControllerB>() != (Object)null;
			}
			return false;
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_HappyBallAI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1429322745u, new RpcReceiveHandler(__rpc_handler_1429322745));
		}

		private static void __rpc_handler_1429322745(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_0061: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string animationName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref animationName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((HappyBallAI)(object)target).DoAnimationClientRpc(animationName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "HappyBallAI";
		}
	}
	[BepInPlugin("juregs.HappyBall", "HappyBall", "3.2.1")]
	[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 = "happyballassets";
			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>("HappyBallObj");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("HappyBallTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("HappyBallTK");
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), val2, val3);
			Logger.LogInfo((object)"Plugin juregs.HappyBall 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 = "juregs.HappyBall";

		public const string PLUGIN_NAME = "HappyBall";

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

		public PluginConfig(ConfigFile cfg)
		{
			SpawnWeight = cfg.Bind<int>("General", "Spawn weight", 999, "The spawn chance weight for HappyBall, 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 juregs.HappyBall.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}