Decompiled source of SandStar v1.0.2

SandStar.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[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 = "")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("SandStar")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SandStar")]
[assembly: AssemblyTitle("SandStar")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace SandStarEnemy
{
	internal class GroundSensor : MonoBehaviour
	{
		public SandStarAI star;

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).gameObject.layer == LayerMask.NameToLayer("Room"))
			{
				star.StopAttacking();
			}
		}
	}
	public class SandStarAI : EnemyAI
	{
		public enum SandStarState
		{
			Moving,
			PRE_JUMP_DELAY,
			Jumping,
			Aiming,
			Attacking,
			Post_Attacking,
			AIMING_FALLING,
			FALLING,
			FOLLOW_PLAYER,
			DEAD
		}

		private SandStarState state;

		private SkinnedMeshRenderer skinnedMeshRenderer;

		private float startTime = 0f;

		private Vector3 targetAttack = Vector3.zero;

		private PlayerControllerB targetPlayer = null;

		private const float Speed = 25f;

		private const float AttackSpeed = 18f;

		private const float JumpingTime = 1f;

		private float timeSinceHittingPlayer = 0f;

		private static List<SandStarAI> stars = new List<SandStarAI>();

		private Transform starObject;

		private ParticleSystem diggingParticles;

		private GameObject radarCircle;

		private float lastChangedDirection = 0f;

		private AudioSource FlySound;

		private AudioSource HitGroundSound;

		private AudioSource JumpSound;

		private AudioSource TransformSound;

		private bool spawnChild = true;

		private List<SandStarAI> childStars = null;

		private static AISearchRoutine roamPlanet = new AISearchRoutine();

		private static GameObject prevNode = null;

		private static int motherStarIndex = 0;

		private static bool updateMother = false;

		private Coroutine preJumping = null;

		private float targetHeight = 0f;

		private float startHeight = 0f;

		private float[] shapeTimes = new float[3] { 0.25f, 0.25f, 0.25f };

		private int shapeKeyIndex = 0;

		private Quaternion attackRotation;

		private Vector3 direction = Vector3.zero;

		private float attackingStartTime = 0f;

		private Coroutine attackforTimeCoroutine;

		private Quaternion startRot;

		private Quaternion endRot = Quaternion.EulerRotation(180f, 0f, 0f);

		private float startAiming;

		private const float AimingTime = 1f;

		public Vector3 velocity { get; private set; } = Vector3.zero;


		public override void Start()
		{
			//IL_00c8: 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_0063: 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)
			if (spawnChild && ((NetworkBehaviour)this).IsServer)
			{
				childStars = new List<SandStarAI>();
				NavMeshHit val = default(NavMeshHit);
				if (!NavMesh.SamplePosition(((Component)this).transform.position, ref val, 100f, -1))
				{
					Debug.LogError((object)"Sandstar couldn't find a place for children :/");
				}
				for (int i = 0; i < 2; i++)
				{
					GameObject val2 = Object.Instantiate<GameObject>(base.enemyType.enemyPrefab, ((NavMeshHit)(ref val)).position, Quaternion.Euler(Vector3.zero));
					val2.gameObject.GetComponentInChildren<NetworkObject>().Spawn(true);
					SandStarAI component = val2.GetComponent<SandStarAI>();
					component.spawnChild = false;
					childStars.Add(component);
				}
			}
			((EnemyAI)this).Start();
			((Component)this).transform.localEulerAngles = Vector3.zero;
			skinnedMeshRenderer = ((Component)((Component)this).transform.Find("SandStar")).GetComponent<SkinnedMeshRenderer>();
			diggingParticles = ((Component)((Component)this).transform.Find("SandStar").Find("Particles").Find("Digging")).GetComponent<ParticleSystem>();
			starObject = ((Component)this).transform.Find("SandStar");
			base.ventAnimationFinished = true;
			base.stunNormalizedTimer = -1f;
			base.enemyHP = 2;
			stars.Add(this);
			radarCircle = ((Component)((Component)this).transform.Find("Circle")).gameObject;
			radarCircle.layer = 14;
			FlySound = ((Component)((Component)this).transform.Find("Sounds").Find("Fly")).GetComponent<AudioSource>();
			HitGroundSound = ((Component)((Component)this).transform.Find("Sounds").Find("HitGround")).GetComponent<AudioSource>();
			JumpSound = ((Component)((Component)this).transform.Find("Sounds").Find("Jump")).GetComponent<AudioSource>();
			TransformSound = ((Component)((Component)this).transform.Find("Sounds").Find("Transform")).GetComponent<AudioSource>();
			SetStateServerRPC(SandStarState.Moving);
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			CheckState();
			timeSinceHittingPlayer -= Time.deltaTime;
			lastChangedDirection -= Time.deltaTime;
			if ((Object)(object)radarCircle == (Object)null)
			{
				radarCircle = ((Component)((Component)this).transform.Find("Circle")).gameObject;
			}
			if (radarCircle.layer != 14)
			{
				radarCircle.layer = 14;
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (state == SandStarState.Moving || state == SandStarState.FOLLOW_PLAYER)
			{
				CheckForPlayer();
			}
		}

		private void CheckState()
		{
			switch (state)
			{
			case SandStarState.Moving:
				Moving();
				break;
			case SandStarState.Jumping:
				Jumping();
				break;
			case SandStarState.Aiming:
				Aiming();
				break;
			case SandStarState.Attacking:
				Attacking();
				break;
			case SandStarState.Post_Attacking:
				Attacking();
				break;
			case SandStarState.AIMING_FALLING:
				AimingFalling();
				break;
			case SandStarState.FALLING:
				Falling();
				break;
			case SandStarState.FOLLOW_PLAYER:
				FollowPlayer();
				break;
			case SandStarState.DEAD:
				Falling();
				break;
			case SandStarState.PRE_JUMP_DELAY:
				break;
			}
		}

		private void CheckForPlayer()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - startTime > 5f)
			{
				PlayerControllerB closestPlayer = ((EnemyAI)this).GetClosestPlayer(false, true, true);
				if ((Object)(object)closestPlayer != (Object)null && Vector3.Distance(((Component)closestPlayer).transform.position, ((Component)this).transform.position) < 15f)
				{
					Debug.Log((object)"sand star FOUND TARGET");
					SetTargetPlayerServerRCP(closestPlayer.playerClientId);
				}
			}
		}

		[ServerRpc]
		private void SetTargetPlayerServerRCP(ulong playerID)
		{
			SetTargetPlayerClientRCP(playerID);
		}

		[ClientRpc]
		private void SetTargetPlayerClientRCP(ulong playerID)
		{
			targetPlayer = StartOfRound.Instance.allPlayerScripts[playerID];
			if (state == SandStarState.Moving || state == SandStarState.FOLLOW_PLAYER)
			{
				SetStateClientRPC(SandStarState.PRE_JUMP_DELAY);
			}
		}

		private void Moving()
		{
			//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)
			//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)
			if (base.destination != Vector3.zero)
			{
				if (Vector3.Distance(base.destination, ((Component)this).transform.position) < 15f)
				{
					SetNewTargetDestinationServerRpc();
				}
			}
			else
			{
				GetTargetDestinationServerRpc();
			}
		}

		private static GameObject GetClosestNodeFromPosition(Vector3 pos)
		{
			//IL_0025: 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)
			GameObject result = null;
			float num = float.MaxValue;
			foreach (GameObject unsearchedNode in roamPlanet.unsearchedNodes)
			{
				float num2 = Vector3.Distance(pos, unsearchedNode.transform.position);
				if (num2 < num)
				{
					num = num2;
					result = unsearchedNode;
				}
			}
			return result;
		}

		[ServerRpc(RequireOwnership = false)]
		private static void SetNewMother(ulong starID)
		{
			for (int i = 0; i < stars.Count; i++)
			{
				SandStarAI sandStarAI = stars[i];
				if (((NetworkBehaviour)sandStarAI).NetworkObjectId == starID)
				{
					motherStarIndex = i;
					updateMother = true;
					break;
				}
			}
		}

		private static void SetNewMother()
		{
			for (int i = 0; i < stars.Count; i++)
			{
				SandStarAI sandStarAI = stars[i];
				if (sandStarAI.state != SandStarState.DEAD)
				{
					motherStarIndex = i;
					updateMother = true;
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private static void SetNewTargetDestinationServerRpc()
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			if (stars[motherStarIndex].state == SandStarState.DEAD)
			{
				SetNewMother();
			}
			if (updateMother)
			{
				roamPlanet.currentTargetNode = null;
				roamPlanet.unsearchedNodes = null;
				prevNode = null;
				updateMother = false;
			}
			if ((Object)(object)roamPlanet.currentTargetNode != (Object)null)
			{
				if (roamPlanet.unsearchedNodes == null)
				{
					Debug.LogError((object)"Sandstar: roamPlanet.unsearchedNodes is null");
				}
				else
				{
					roamPlanet.unsearchedNodes.Remove(roamPlanet.currentTargetNode);
				}
				prevNode = roamPlanet.currentTargetNode;
			}
			if (roamPlanet.unsearchedNodes == null || roamPlanet.unsearchedNodes.Count <= 0)
			{
				roamPlanet.unsearchedNodes = ((EnemyAI)stars[motherStarIndex]).allAINodes.ToList();
			}
			if ((Object)(object)prevNode == (Object)null)
			{
				roamPlanet.currentTargetNode = GetClosestNodeFromPosition(((Component)stars[motherStarIndex]).transform.position);
			}
			else
			{
				roamPlanet.currentTargetNode = GetClosestNodeFromPosition(prevNode.transform.position);
			}
			Vector3 position = roamPlanet.currentTargetNode.transform.position;
			Debug.Log((object)("Sandstar: New target position: " + ((object)(Vector3)(ref position)).ToString()));
			foreach (SandStarAI star in stars)
			{
				star.SetNewTargetDestinationClientRpc(roamPlanet.currentTargetNode.transform.position);
			}
		}

		[ClientRpc]
		private void SetNewTargetDestinationClientRpc(Vector3 targetPos)
		{
			//IL_0002: 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)
			base.destination = targetPos;
		}

		[ServerRpc(RequireOwnership = false)]
		private static void GetTargetDestinationServerRpc()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)roamPlanet.currentTargetNode == (Object)null)
			{
				SetNewTargetDestinationServerRpc();
				return;
			}
			foreach (SandStarAI star in stars)
			{
				star.SetNewTargetDestinationClientRpc(roamPlanet.currentTargetNode.transform.position);
			}
		}

		private void AlertOtherStars()
		{
			//IL_003a: 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)
			if (targetPlayer.isInHangarShipRoom)
			{
				return;
			}
			foreach (SandStarAI star in stars)
			{
				if ((Object)(object)star != (Object)(object)this && Vector3.Distance(((Component)star).transform.position, ((Component)this).transform.position) < 20f)
				{
					star.SetTargetPlayerServerRCP(targetPlayer.playerClientId);
				}
			}
		}

		private IEnumerator PreJumping()
		{
			float randomTimeOffset = Random.value;
			yield return (object)new WaitForSeconds(randomTimeOffset);
			SetStateServerRPC(SandStarState.Jumping);
		}

		private void Jumping()
		{
			//IL_000d: 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_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			targetAttack = ((Component)targetPlayer).transform.position + new Vector3(0f, 1f, 0f);
			float num = (Time.time - startTime) / 1f;
			if (num > 1f)
			{
				SetStateServerRPC(SandStarState.Aiming);
				AlertOtherStars();
			}
			else
			{
				float y = Mathf.Lerp(startHeight, targetHeight, Mathf.Sqrt(num));
				Vector3 position = ((Component)this).transform.position;
				position.y = y;
				((Component)this).transform.position = position;
				((Component)starObject).transform.localPosition = Vector3.Lerp(new Vector3(0f, -3f, 0f), Vector3.zero, Mathf.Sqrt(num));
			}
			((Component)this).transform.LookAt(targetAttack);
		}

		private void Aiming()
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			float num = (Time.time - startTime) / shapeTimes[shapeKeyIndex];
			if (num > 1f)
			{
				if (shapeKeyIndex > 0)
				{
					skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyIndex - 1, 0f);
					skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyIndex, 100f);
				}
				else
				{
					skinnedMeshRenderer.SetBlendShapeWeight(0, 100f);
				}
				shapeKeyIndex++;
				startTime = Time.time;
				if (shapeKeyIndex >= 3)
				{
					((Component)this).transform.LookAt(targetAttack);
					Transform transform = ((Component)this).transform;
					transform.localRotation *= Quaternion.Euler(90f, 0f, 0f);
					attackRotation = ((Component)this).transform.rotation;
					SetStateServerRPC(SandStarState.Attacking);
				}
			}
			else if (shapeKeyIndex > 0)
			{
				skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyIndex, num * 100f);
				skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyIndex - 1, 100f - num * 100f);
			}
			else
			{
				skinnedMeshRenderer.SetBlendShapeWeight(0, num * 100f);
			}
			((Component)this).transform.LookAt(targetAttack);
			Transform transform2 = ((Component)this).transform;
			transform2.localRotation *= Quaternion.Euler(90f, 0f, 0f);
		}

		private void Attacking()
		{
			//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)
			//IL_001e: 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_002e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (direction == Vector3.zero)
			{
			}
			Transform transform = ((Component)this).transform;
			transform.position += direction * Time.deltaTime * 18f;
			((Component)this).transform.rotation = attackRotation;
			Transform transform2 = ((Component)this).transform;
			transform2.localRotation *= Quaternion.Euler(0f, 180f * (Time.time - attackingStartTime), 0f);
			if (Time.time - attackingStartTime > 3f)
			{
				SetStateServerRPC(SandStarState.AIMING_FALLING);
			}
		}

		public void StopAttacking()
		{
			if (state == SandStarState.Attacking || state == SandStarState.FALLING)
			{
				SetStateServerRPC(SandStarState.Post_Attacking);
				attackforTimeCoroutine = ((MonoBehaviour)this).StartCoroutine(AttackForTime(0.25f));
				HitGroundSound.Play();
			}
		}

		private void AimingFalling()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localRotation = Quaternion.Lerp(startRot, endRot, (Time.time - startAiming) / 1f);
			if (Time.time - startAiming > 1f)
			{
				((Component)this).transform.localRotation = endRot;
				SetStateServerRPC(SandStarState.FALLING);
			}
		}

		private void Falling()
		{
			//IL_0008: 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_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)
			Transform transform = ((Component)this).transform;
			transform.position -= new Vector3(0f, 3f, 0f) * Time.deltaTime;
		}

		protected IEnumerator AttackForTime(float duration)
		{
			float startTime = Time.time;
			while (Time.time < startTime + duration)
			{
				yield return null;
			}
			SetStateServerRPC(SandStarState.FOLLOW_PLAYER);
		}

		private void FollowPlayer()
		{
			if (Time.time > startTime + 10f)
			{
				SetStateServerRPC(SandStarState.Moving);
			}
		}

		[ServerRpc]
		private void SetStateServerRPC(SandStarState state)
		{
			SetStateClientRPC(state);
		}

		[ClientRpc]
		private void SetStateClientRPC(SandStarState newState)
		{
			//IL_0055: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			state = newState;
			startTime = Time.time;
			switch (state)
			{
			case SandStarState.Moving:
				((Component)this).transform.localEulerAngles = Vector3.zero;
				velocity = Vector3.zero;
				diggingParticles.Play();
				base.agent.Warp(((Component)this).transform.position);
				base.agent.updatePosition = true;
				base.agent.updateRotation = true;
				skinnedMeshRenderer.SetBlendShapeWeight(2, 0f);
				((Component)starObject).transform.localPosition = new Vector3(0f, -3f, 0f);
				base.moveTowardsDestination = true;
				base.movingTowardsTargetPlayer = false;
				break;
			case SandStarState.PRE_JUMP_DELAY:
				preJumping = ((MonoBehaviour)this).StartCoroutine(PreJumping());
				break;
			case SandStarState.Jumping:
				base.moveTowardsDestination = false;
				diggingParticles.Stop();
				base.agent.updatePosition = false;
				base.agent.updateRotation = false;
				startHeight = ((Component)this).transform.position.y;
				targetHeight = startHeight + 4f;
				JumpSound.Play(0.10000000149011612);
				((MonoBehaviour)this).StopCoroutine(preJumping);
				break;
			case SandStarState.Aiming:
			{
				shapeKeyIndex = 0;
				Vector3 val = targetAttack - ((Component)this).transform.position;
				direction = ((Vector3)(ref val)).normalized;
				SetNewMother(((NetworkBehaviour)this).NetworkObjectId);
				TransformSound.Play();
				break;
			}
			case SandStarState.Attacking:
				attackingStartTime = Time.time;
				FlySound.Play();
				break;
			case SandStarState.FOLLOW_PLAYER:
				((Component)this).transform.localEulerAngles = Vector3.zero;
				velocity = Vector3.zero;
				diggingParticles.Play();
				base.agent.Warp(((Component)this).transform.position);
				base.agent.updatePosition = true;
				base.agent.updateRotation = true;
				skinnedMeshRenderer.SetBlendShapeWeight(2, 0f);
				((Component)starObject).transform.localPosition = new Vector3(0f, -3f, 0f);
				base.moveTowardsDestination = true;
				base.movingTowardsTargetPlayer = false;
				((MonoBehaviour)this).StopCoroutine(attackforTimeCoroutine);
				((EnemyAI)this).SetMovingTowardsTargetPlayer(targetPlayer);
				break;
			case SandStarState.DEAD:
				skinnedMeshRenderer.SetBlendShapeWeight(2, 0f);
				base.agent.Warp(((Component)this).transform.position);
				base.agent.updatePosition = false;
				base.agent.updateRotation = false;
				break;
			case SandStarState.Post_Attacking:
			case SandStarState.AIMING_FALLING:
			case SandStarState.FALLING:
				break;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			Debug.Log((object)"Star Collided with player!");
			if ((Object)(object)val != (Object)null && timeSinceHittingPlayer <= 0f)
			{
				timeSinceHittingPlayer = 0.5f;
				val.DamagePlayer(20, true, true, (CauseOfDeath)14, 2, false, default(Vector3));
			}
		}

		public override void OnDestroy()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			((EnemyAI)this).OnDestroy();
			stars.Remove(this);
			foreach (SandStarAI childStar in childStars)
			{
				Object.Destroy((Object)(object)childStar);
			}
			if (stars.Count == 0)
			{
				roamPlanet = new AISearchRoutine();
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			base.enemyHP -= force;
			if (base.enemyHP <= 0)
			{
				SetStateServerRPC(SandStarState.DEAD);
			}
		}
	}
	[BepInPlugin("SandStarEnemy", "SandStarEnemy", "1.0.0")]
	public class SandStarEnemyPlugin : BaseUnityPlugin
	{
		public static EnemyType EnemyType;

		internal static ManualLogSource Log;

		private const string EnemyTypePath = "Assets/SandStar/SandStarType.asset";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Sand Star enemy PROPERLY LOADED!");
		}

		private void LoadAssets()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			Assets.PopulateAssets();
			LoadNetWeaver();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			if (Assets.MainAssetBundle.Contains("Assets/SandStar/SandStarType.asset"))
			{
				EnemyType = Assets.MainAssetBundle.LoadAsset<EnemyType>("Assets/SandStar/SandStarType.asset");
				if ((Object)(object)EnemyType == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SandStar ENEMYTYPE IS NULL!");
					return;
				}
				if ((Object)(object)EnemyType.enemyPrefab == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SandStar SandStar ENEMY PREFAB MISSING!");
					return;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SandStar SandStar ENEMY TYPE LOADED CORRECTLY!");
				AddScripts(EnemyType);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registering Sand Star as Enemy");
				LevelTypes val = (LevelTypes)(-1);
				SpawnType val2 = (SpawnType)2;
				TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
				val3.displayText = "Sand Star \n\nDanger level: 15%\n\nIt buries itself in the ground, and will try to keep in touch with its peers. Whenever threatened, it will jump out of the ground and fly towards player to pierce him through. It's not dangerous on its own, but a bigger group can be deadly!\n\n";
				val3.clearPreviousText = true;
				val3.maxCharactersToType = 2000;
				val3.creatureName = "SandStar";
				val3.creatureFileID = 963287;
				TerminalKeyword val4 = TerminalUtils.CreateTerminalKeyword("sandstar", false, (CompatibleNoun[])null, val3, (TerminalKeyword)null, false);
				NetworkPrefabs.RegisterNetworkPrefab(EnemyType.enemyPrefab);
				Enemies.RegisterEnemy(EnemyType, 30, val, val2, val3, val4);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SandStar INVALID PATH!");
			}
		}

		private void AddScripts(EnemyType startType)
		{
			GameObject enemyPrefab = startType.enemyPrefab;
			enemyPrefab.AddComponent<SandStarAI>();
			((EnemyAI)enemyPrefab.GetComponent<SandStarAI>()).enemyType = startType;
			enemyPrefab.GetComponent<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)enemyPrefab.GetComponent<SandStarAI>();
			if ((Object)(object)enemyPrefab.transform.Find("SandStar") == (Object)null)
			{
				Debug.Log((object)"Sand star null");
			}
			else if ((Object)(object)enemyPrefab.transform.Find("SandStar").Find("GroundSensor") == (Object)null)
			{
				Debug.Log((object)"GroundSensor null");
			}
			((Component)enemyPrefab.transform.Find("SandStar").Find("GroundSensor")).gameObject.AddComponent<GroundSensor>();
			((Component)enemyPrefab.transform.Find("SandStar").Find("GroundSensor")).gameObject.GetComponent<GroundSensor>().star = enemyPrefab.GetComponent<SandStarAI>();
		}

		private void LoadNetWeaver()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin SandStar ASSEMBLY TYPE: " + type.Name));
				try
				{
					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);
						}
					}
				}
				catch
				{
				}
			}
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "sandstarbundle";

		public static AssetBundle MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name;
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}