Decompiled source of AmbientLife v2.0.3

AmbientLife.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AmbientLife")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+73b30c2ccfc5f560959a1cb2d57bf43a03622b8c")]
[assembly: AssemblyProduct("AmbientLife")]
[assembly: AssemblyTitle("AmbientLife")]
[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;
		}
	}
}
namespace AmbientLife
{
	[BepInPlugin("com.certifired.AmbientLife", "AmbientLife", "2.0.3")]
	public class AmbientLifePlugin : BaseUnityPlugin
	{
		public enum CreatureType
		{
			Butterfly,
			Firefly,
			FlyingBeetle,
			NightmareBeetle,
			BrownSpider,
			GreenSpider,
			BlackSpider,
			Dog,
			Cat,
			Chicken,
			Deer,
			Wolf,
			Penguin
		}

		public const string MyGUID = "com.certifired.AmbientLife";

		public const string PluginName = "AmbientLife";

		public const string VersionString = "2.0.3";

		private static readonly Harmony Harmony = new Harmony("com.certifired.AmbientLife");

		public static ManualLogSource Log;

		public static AmbientLifePlugin Instance;

		public static string PluginPath;

		public static ConfigEntry<bool> EnableAmbientLife;

		public static ConfigEntry<int> MaxCreatures;

		public static ConfigEntry<float> SpawnRadius;

		public static ConfigEntry<float> DespawnRadius;

		public static ConfigEntry<bool> DebugMode;

		public static ConfigEntry<bool> EnableButterflies;

		public static ConfigEntry<bool> EnableFireflies;

		public static ConfigEntry<bool> EnableBeetles;

		public static ConfigEntry<bool> EnableNightmareBeetles;

		public static ConfigEntry<bool> EnableBrownSpiders;

		public static ConfigEntry<bool> EnableGreenSpiders;

		public static ConfigEntry<bool> EnableBlackSpiders;

		public static ConfigEntry<bool> EnableDogs;

		public static ConfigEntry<bool> EnableCats;

		public static ConfigEntry<bool> EnableChickens;

		public static ConfigEntry<bool> EnableDeer;

		public static ConfigEntry<bool> EnableWolves;

		public static ConfigEntry<bool> EnablePenguins;

		public static float DensityFlying = 0.4f;

		public static float DensityCrawling = 0.3f;

		public static float DensityAnimals = 0.3f;

		public static List<SmartAmbientCreature> ActiveCreatures = new List<SmartAmbientCreature>();

		private float spawnTimer = 0f;

		private const float SPAWN_INTERVAL = 1.5f;

		public static readonly Dictionary<CreatureType, CreatureDefinition> CreatureDefinitions = new Dictionary<CreatureType, CreatureDefinition>
		{
			{
				CreatureType.Butterfly,
				new CreatureDefinition("butterfly", SmartCreatureController.MovementMode.Hovering, 1.5f, 0.3f)
			},
			{
				CreatureType.Firefly,
				new CreatureDefinition("firefly", SmartCreatureController.MovementMode.Hovering, 0.8f, 0.1f, hasGlow: true)
			},
			{
				CreatureType.FlyingBeetle,
				new CreatureDefinition("flying beetle", SmartCreatureController.MovementMode.Flying, 3f, 0.5f)
			},
			{
				CreatureType.NightmareBeetle,
				new CreatureDefinition("nightmare beetle", SmartCreatureController.MovementMode.Flying, 4f, 0.8f)
			},
			{
				CreatureType.BrownSpider,
				new CreatureDefinition("brown_spider", SmartCreatureController.MovementMode.WallCrawling, 2f, 0.4f)
			},
			{
				CreatureType.GreenSpider,
				new CreatureDefinition("green_spider", SmartCreatureController.MovementMode.WallCrawling, 1.8f, 0.35f)
			},
			{
				CreatureType.BlackSpider,
				new CreatureDefinition("black_spider", SmartCreatureController.MovementMode.WallCrawling, 2.5f, 0.5f)
			},
			{
				CreatureType.Dog,
				new CreatureDefinition("dog", SmartCreatureController.MovementMode.Crawling, 3f, 1f)
			},
			{
				CreatureType.Cat,
				new CreatureDefinition("kitty", SmartCreatureController.MovementMode.Crawling, 2.5f, 0.8f)
			},
			{
				CreatureType.Chicken,
				new CreatureDefinition("chicken", SmartCreatureController.MovementMode.Crawling, 1.5f, 0.5f)
			},
			{
				CreatureType.Deer,
				new CreatureDefinition("deer", SmartCreatureController.MovementMode.Crawling, 4f, 1.5f)
			},
			{
				CreatureType.Wolf,
				new CreatureDefinition("wolf_lrp", SmartCreatureController.MovementMode.Crawling, 5f, 1.2f)
			},
			{
				CreatureType.Penguin,
				new CreatureDefinition("penguin", SmartCreatureController.MovementMode.Crawling, 1.2f, 0.7f)
			}
		};

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			PluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Log.LogInfo((object)"AmbientLife v2.0.3 loading...");
			InitializeConfig();
			Harmony.PatchAll();
			CreatureAssetLoader.Initialize();
			((Component)this).gameObject.AddComponent<CreatureConfigUI>();
			Log.LogInfo((object)"AmbientLife v2.0.3 loaded!");
			Log.LogInfo((object)$"Loaded {CreatureAssetLoader.LoadedPrefabCount} creature prefabs from {CreatureAssetLoader.LoadedBundleCount} bundles");
		}

		private void InitializeConfig()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			EnableAmbientLife = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Ambient Life", true, "Enable ambient creature spawning");
			MaxCreatures = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Creatures", 40, new ConfigDescription("Maximum ambient creatures at once", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 150), Array.Empty<object>()));
			SpawnRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Spawn Radius", 50f, new ConfigDescription("Distance from player to spawn creatures", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 150f), Array.Empty<object>()));
			DespawnRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Despawn Radius", 80f, new ConfigDescription("Distance from player to despawn creatures", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 200f), Array.Empty<object>()));
			DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug Mode", false, "Enable debug logging");
			EnableButterflies = ((BaseUnityPlugin)this).Config.Bind<bool>("Flying Insects", "Enable Butterflies", true, "Spawn butterflies");
			EnableFireflies = ((BaseUnityPlugin)this).Config.Bind<bool>("Flying Insects", "Enable Fireflies", true, "Spawn fireflies (glow)");
			EnableBeetles = ((BaseUnityPlugin)this).Config.Bind<bool>("Flying Insects", "Enable Flying Beetles", true, "Spawn flying beetles");
			EnableNightmareBeetles = ((BaseUnityPlugin)this).Config.Bind<bool>("Flying Insects", "Enable Nightmare Beetles", false, "Spawn nightmare beetles (larger, intimidating)");
			EnableBrownSpiders = ((BaseUnityPlugin)this).Config.Bind<bool>("Spiders", "Enable Brown Spiders", true, "Spawn brown spiders (wall crawlers)");
			EnableGreenSpiders = ((BaseUnityPlugin)this).Config.Bind<bool>("Spiders", "Enable Green Spiders", true, "Spawn green spiders");
			EnableBlackSpiders = ((BaseUnityPlugin)this).Config.Bind<bool>("Spiders", "Enable Black Spiders", false, "Spawn black spiders (larger)");
			EnableDogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Dogs", true, "Spawn dogs");
			EnableCats = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Cats", true, "Spawn cats");
			EnableChickens = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Chickens", true, "Spawn chickens");
			EnableDeer = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Deer", true, "Spawn deer");
			EnableWolves = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Wolves", false, "Spawn wolves");
			EnablePenguins = ((BaseUnityPlugin)this).Config.Bind<bool>("Ground Animals", "Enable Penguins", false, "Spawn penguins");
		}

		private void Update()
		{
			if (EnableAmbientLife.Value && !((Object)(object)Player.instance == (Object)null))
			{
				spawnTimer += Time.deltaTime;
				if (spawnTimer >= 1.5f)
				{
					spawnTimer = 0f;
					TrySpawnCreature();
				}
				UpdateCreatures();
			}
		}

		private void TrySpawnCreature()
		{
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			if (ActiveCreatures.Count >= MaxCreatures.Value)
			{
				return;
			}
			List<(CreatureType, float)> list = new List<(CreatureType, float)>();
			if (EnableButterflies.Value)
			{
				list.Add((CreatureType.Butterfly, DensityFlying * 0.4f));
			}
			if (EnableFireflies.Value)
			{
				list.Add((CreatureType.Firefly, DensityFlying * 0.3f));
			}
			if (EnableBeetles.Value)
			{
				list.Add((CreatureType.FlyingBeetle, DensityFlying * 0.2f));
			}
			if (EnableNightmareBeetles.Value)
			{
				list.Add((CreatureType.NightmareBeetle, DensityFlying * 0.1f));
			}
			if (EnableBrownSpiders.Value)
			{
				list.Add((CreatureType.BrownSpider, DensityCrawling * 0.4f));
			}
			if (EnableGreenSpiders.Value)
			{
				list.Add((CreatureType.GreenSpider, DensityCrawling * 0.35f));
			}
			if (EnableBlackSpiders.Value)
			{
				list.Add((CreatureType.BlackSpider, DensityCrawling * 0.25f));
			}
			if (EnableDogs.Value)
			{
				list.Add((CreatureType.Dog, DensityAnimals * 0.2f));
			}
			if (EnableCats.Value)
			{
				list.Add((CreatureType.Cat, DensityAnimals * 0.2f));
			}
			if (EnableChickens.Value)
			{
				list.Add((CreatureType.Chicken, DensityAnimals * 0.25f));
			}
			if (EnableDeer.Value)
			{
				list.Add((CreatureType.Deer, DensityAnimals * 0.15f));
			}
			if (EnableWolves.Value)
			{
				list.Add((CreatureType.Wolf, DensityAnimals * 0.1f));
			}
			if (EnablePenguins.Value)
			{
				list.Add((CreatureType.Penguin, DensityAnimals * 0.1f));
			}
			if (list.Count == 0)
			{
				return;
			}
			float num = 0f;
			foreach (var item in list)
			{
				num += item.Item2;
			}
			float num2 = Random.value * num;
			float num3 = 0f;
			CreatureType type = list[0].Item1;
			foreach (var item2 in list)
			{
				num3 += item2.Item2;
				if (num2 <= num3)
				{
					(type, _) = item2;
					break;
				}
			}
			Vector3 spawnPosition = GetSpawnPosition(type);
			if (!(spawnPosition == Vector3.zero))
			{
				SpawnCreature(type, spawnPosition);
			}
		}

		private Vector3 GetSpawnPosition(CreatureType type)
		{
			//IL_0028: 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_0070: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			//IL_00fa: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.instance == (Object)null)
			{
				return Vector3.zero;
			}
			Vector3 position = ((Component)Player.instance).transform.position;
			CreatureDefinition creatureDefinition = CreatureDefinitions[type];
			float num = Random.Range(0f, 360f) * ((float)Math.PI / 180f);
			float num2 = Random.Range(SpawnRadius.Value * 0.4f, SpawnRadius.Value);
			Vector3 val = position + new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
			switch (creatureDefinition.MovementMode)
			{
			case SmartCreatureController.MovementMode.Flying:
				val.y = position.y + Random.Range(5f, 15f);
				break;
			case SmartCreatureController.MovementMode.Hovering:
				val.y = position.y + Random.Range(0.5f, 4f);
				break;
			case SmartCreatureController.MovementMode.Crawling:
			case SmartCreatureController.MovementMode.WallCrawling:
			{
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val + Vector3.up * 50f, Vector3.down, ref val2, 100f))
				{
					val = ((RaycastHit)(ref val2)).point + Vector3.up * 0.1f;
				}
				else
				{
					val.y = position.y;
				}
				break;
			}
			}
			if (Physics.CheckSphere(val, creatureDefinition.Scale * 0.5f))
			{
				for (int i = 0; i < 5; i++)
				{
					Vector3 val3 = val + Random.insideUnitSphere * 3f;
					if (!Physics.CheckSphere(val3, creatureDefinition.Scale * 0.5f))
					{
						return val3;
					}
				}
				return Vector3.zero;
			}
			return val;
		}

		private void SpawnCreature(CreatureType type, Vector3 position)
		{
			//IL_0016: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			CreatureDefinition creatureDefinition = CreatureDefinitions[type];
			GameObject val = null;
			try
			{
				val = CreatureAssetLoader.SpawnCreature(creatureDefinition.PrefabName, position, Quaternion.identity);
				if ((Object)(object)val == (Object)null)
				{
					val = CreateProceduralCreature(type, position);
				}
				if (!((Object)(object)val != (Object)null))
				{
					return;
				}
				val.transform.localScale = Vector3.one * creatureDefinition.Scale;
				SmartCreatureController smartCreatureController = val.AddComponent<SmartCreatureController>();
				if ((Object)(object)smartCreatureController != (Object)null)
				{
					smartCreatureController.Initialize(creatureDefinition.MovementMode, creatureDefinition.Speed, 15f);
				}
				SmartAmbientCreature smartAmbientCreature = val.AddComponent<SmartAmbientCreature>();
				if ((Object)(object)smartAmbientCreature != (Object)null)
				{
					smartAmbientCreature.Initialize(type, creatureDefinition);
					if (creatureDefinition.HasGlow)
					{
						AddGlowEffect(val);
					}
					ActiveCreatures.Add(smartAmbientCreature);
					LogDebug($"Spawned {type} at {position} (prefab: {((Object)val).name})");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)$"Error spawning {type}: {ex.Message}");
				if ((Object)(object)val != (Object)null)
				{
					try
					{
						Object.Destroy((Object)(object)val);
						return;
					}
					catch
					{
						return;
					}
				}
			}
		}

		private GameObject CreateProceduralCreature(CreatureType type, Vector3 position)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject($"Ambient_{type}_Procedural");
			val.transform.position = position;
			CreatureDefinition creatureDefinition = CreatureDefinitions[type];
			switch (creatureDefinition.MovementMode)
			{
			case SmartCreatureController.MovementMode.Flying:
			case SmartCreatureController.MovementMode.Hovering:
				CreateFlyingInsectVisual(val, type);
				break;
			case SmartCreatureController.MovementMode.Crawling:
				CreateGroundAnimalVisual(val, type);
				break;
			case SmartCreatureController.MovementMode.WallCrawling:
				CreateSpiderVisual(val, type);
				break;
			}
			return val;
		}

		private void CreateFlyingInsectVisual(GameObject parent, CreatureType type)
		{
			//IL_0020: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)1);
			val.transform.SetParent(parent.transform);
			val.transform.localPosition = Vector3.zero;
			val.transform.localScale = new Vector3(0.05f, 0.1f, 0.05f);
			val.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			for (int i = -1; i <= 1; i += 2)
			{
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)5);
				val2.transform.SetParent(parent.transform);
				val2.transform.localPosition = new Vector3((float)i * 0.08f, 0f, 0f);
				val2.transform.localScale = new Vector3(0.15f, 0.1f, 1f);
				val2.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
				Object.Destroy((Object)(object)val2.GetComponent<Collider>());
				Renderer component = val2.GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					if (1 == 0)
					{
					}
					Color val3 = (Color)(type switch
					{
						CreatureType.Butterfly => new Color(Random.Range(0.5f, 1f), Random.Range(0.3f, 0.8f), Random.Range(0.5f, 1f), 0.9f), 
						CreatureType.FlyingBeetle => new Color(0.2f, 0.15f, 0.1f, 1f), 
						CreatureType.NightmareBeetle => new Color(0.3f, 0.1f, 0.1f, 1f), 
						_ => Color.white, 
					});
					if (1 == 0)
					{
					}
					Color color = val3;
					component.material.color = color;
				}
			}
			Renderer component2 = val.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				if (1 == 0)
				{
				}
				Color val3 = (Color)(type switch
				{
					CreatureType.Butterfly => new Color(0.2f, 0.2f, 0.2f), 
					CreatureType.Firefly => new Color(0.1f, 0.1f, 0.1f), 
					CreatureType.FlyingBeetle => new Color(0.3f, 0.2f, 0.1f), 
					CreatureType.NightmareBeetle => new Color(0.4f, 0.1f, 0.1f), 
					_ => Color.gray, 
				});
				if (1 == 0)
				{
				}
				Color color2 = val3;
				component2.material.color = color2;
			}
		}

		private void CreateGroundAnimalVisual(GameObject parent, CreatureType type)
		{
			//IL_0020: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)1);
			val.transform.SetParent(parent.transform);
			val.transform.localPosition = Vector3.zero;
			val.transform.localScale = new Vector3(0.3f, 0.2f, 0.5f);
			val.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
			val2.transform.SetParent(parent.transform);
			val2.transform.localPosition = new Vector3(0f, 0.1f, 0.3f);
			val2.transform.localScale = Vector3.one * 0.2f;
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			for (int i = -1; i <= 1; i += 2)
			{
				for (int j = -1; j <= 1; j += 2)
				{
					GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)1);
					val3.transform.SetParent(parent.transform);
					val3.transform.localPosition = new Vector3((float)i * 0.15f, -0.1f, (float)j * 0.15f);
					val3.transform.localScale = new Vector3(0.05f, 0.1f, 0.05f);
					Object.Destroy((Object)(object)val3.GetComponent<Collider>());
				}
			}
			if (1 == 0)
			{
			}
			Color val4 = (Color)(type switch
			{
				CreatureType.Dog => new Color(0.6f, 0.4f, 0.2f), 
				CreatureType.Cat => new Color(0.8f, 0.6f, 0.4f), 
				CreatureType.Chicken => new Color(0.9f, 0.85f, 0.7f), 
				CreatureType.Deer => new Color(0.5f, 0.35f, 0.2f), 
				CreatureType.Wolf => new Color(0.4f, 0.4f, 0.4f), 
				CreatureType.Penguin => new Color(0.1f, 0.1f, 0.1f), 
				_ => Color.gray, 
			});
			if (1 == 0)
			{
			}
			Color color = val4;
			Renderer[] componentsInChildren = parent.GetComponentsInChildren<Renderer>();
			foreach (Renderer val5 in componentsInChildren)
			{
				val5.material.color = color;
			}
		}

		private void CreateSpiderVisual(GameObject parent, CreatureType type)
		{
			//IL_002f: 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_0094: 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_0129: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: 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_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			val.transform.SetParent(parent.transform);
			val.transform.localPosition = new Vector3(0f, 0f, -0.1f);
			val.transform.localScale = new Vector3(0.15f, 0.1f, 0.2f);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
			val2.transform.SetParent(parent.transform);
			val2.transform.localPosition = new Vector3(0f, 0f, 0.1f);
			val2.transform.localScale = new Vector3(0.1f, 0.08f, 0.1f);
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			for (int i = 0; i < 8; i++)
			{
				float num = ((i % 2 == 0) ? (-1f) : 1f);
				float num2 = ((float)(i / 2) - 1.5f) * 0.05f;
				GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)1);
				val3.transform.SetParent(parent.transform);
				val3.transform.localPosition = new Vector3(num * 0.12f, -0.02f, num2);
				val3.transform.localScale = new Vector3(0.01f, 0.08f, 0.01f);
				val3.transform.localRotation = Quaternion.Euler(0f, 0f, num * 45f);
				Object.Destroy((Object)(object)val3.GetComponent<Collider>());
			}
			if (1 == 0)
			{
			}
			Color val4 = (Color)(type switch
			{
				CreatureType.BrownSpider => new Color(0.4f, 0.25f, 0.15f), 
				CreatureType.GreenSpider => new Color(0.2f, 0.5f, 0.2f), 
				CreatureType.BlackSpider => new Color(0.1f, 0.1f, 0.1f), 
				_ => Color.gray, 
			});
			if (1 == 0)
			{
			}
			Color color = val4;
			Renderer[] componentsInChildren = parent.GetComponentsInChildren<Renderer>();
			foreach (Renderer val5 in componentsInChildren)
			{
				val5.material.color = color;
			}
		}

		private void AddGlowEffect(GameObject obj)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			Light val = obj.AddComponent<Light>();
			val.type = (LightType)2;
			val.color = new Color(0.8f, 1f, 0.3f);
			val.intensity = 0.8f;
			val.range = 4f;
			Renderer[] componentsInChildren = obj.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2.material != (Object)null)
				{
					val2.material.EnableKeyword("_EMISSION");
					val2.material.SetColor("_EmissionColor", new Color(0.5f, 0.8f, 0.2f) * 2f);
				}
			}
		}

		private void UpdateCreatures()
		{
			//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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.instance == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)Player.instance).transform.position;
			for (int num = ActiveCreatures.Count - 1; num >= 0; num--)
			{
				SmartAmbientCreature smartAmbientCreature = ActiveCreatures[num];
				if ((Object)(object)smartAmbientCreature == (Object)null || (Object)(object)((Component)smartAmbientCreature).gameObject == (Object)null)
				{
					ActiveCreatures.RemoveAt(num);
				}
				else
				{
					float num2 = Vector3.Distance(((Component)smartAmbientCreature).transform.position, position);
					if (num2 > DespawnRadius.Value)
					{
						ActiveCreatures.RemoveAt(num);
						Object.Destroy((Object)(object)((Component)smartAmbientCreature).gameObject);
					}
				}
			}
		}

		public void ClearAllCreatures()
		{
			foreach (SmartAmbientCreature activeCreature in ActiveCreatures)
			{
				if ((Object)(object)activeCreature != (Object)null && (Object)(object)((Component)activeCreature).gameObject != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)activeCreature).gameObject);
				}
			}
			ActiveCreatures.Clear();
			Log.LogInfo((object)"Cleared all ambient creatures");
		}

		private void OnDestroy()
		{
			ClearAllCreatures();
			CreatureAssetLoader.Unload();
		}

		public static void LogDebug(string message)
		{
			if (DebugMode.Value)
			{
				Log.LogInfo((object)("[DEBUG] " + message));
			}
		}
	}
	public class CreatureDefinition
	{
		public string PrefabName { get; }

		public SmartCreatureController.MovementMode MovementMode { get; }

		public float Speed { get; }

		public float Scale { get; }

		public bool HasGlow { get; }

		public CreatureDefinition(string prefabName, SmartCreatureController.MovementMode mode, float speed, float scale, bool hasGlow = false)
		{
			PrefabName = prefabName;
			MovementMode = mode;
			Speed = speed;
			Scale = scale;
			HasGlow = hasGlow;
		}
	}
	public class SmartAmbientCreature : MonoBehaviour
	{
		private SmartCreatureController controller;

		private Animator animator;

		private float animationPhase;

		public AmbientLifePlugin.CreatureType Type { get; private set; }

		public CreatureDefinition Definition { get; private set; }

		public void Initialize(AmbientLifePlugin.CreatureType type, CreatureDefinition definition)
		{
			Type = type;
			Definition = definition;
			controller = ((Component)this).GetComponent<SmartCreatureController>();
			animator = ((Component)this).GetComponent<Animator>();
			animationPhase = Random.value * (float)Math.PI * 2f;
		}

		private void Update()
		{
			UpdateVisualEffects();
			CheckPlayerProximity();
		}

		private void UpdateVisualEffects()
		{
			animationPhase += Time.deltaTime;
			switch (Definition.MovementMode)
			{
			case SmartCreatureController.MovementMode.Flying:
			case SmartCreatureController.MovementMode.Hovering:
				AnimateWings();
				break;
			case SmartCreatureController.MovementMode.Crawling:
				AnimateLegs();
				break;
			}
			if (Definition.HasGlow)
			{
				AnimateGlow();
			}
		}

		private void AnimateWings()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0097: 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)
			if ((Object)(object)animator != (Object)null)
			{
				return;
			}
			float num = ((Definition.MovementMode == SmartCreatureController.MovementMode.Hovering) ? 20f : 12f);
			float num2 = Mathf.Sin(animationPhase * num) * 40f;
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				if (((Object)val).name.Contains("Quad") || ((Object)val).name.ToLower().Contains("wing"))
				{
					float num3 = ((val.localPosition.x > 0f) ? 1f : (-1f));
					val.localRotation = Quaternion.Euler(num2 * num3, 90f, 0f);
				}
			}
		}

		private void AnimateLegs()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)animator != (Object)null)
			{
				return;
			}
			float num = animationPhase * 8f;
			int num2 = 0;
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				if (((Object)val).name.Contains("Capsule") && val.localPosition.y < 0f)
				{
					float num3 = ((num2 % 2 == 0) ? 0f : ((float)Math.PI));
					float num4 = Mathf.Sin(num + num3) * 15f;
					Quaternion localRotation = val.localRotation;
					val.localRotation = Quaternion.Euler(num4, 0f, ((Quaternion)(ref localRotation)).eulerAngles.z);
					num2++;
				}
			}
		}

		private void AnimateGlow()
		{
			Light component = ((Component)this).GetComponent<Light>();
			if ((Object)(object)component != (Object)null)
			{
				float num = (Mathf.Sin(animationPhase * 2f) + 1f) * 0.5f;
				component.intensity = 0.3f + num * 0.7f;
			}
		}

		private void CheckPlayerProximity()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)controller == (Object)null) && !((Object)(object)Player.instance == (Object)null))
			{
				float num = Vector3.Distance(((Component)this).transform.position, ((Component)Player.instance).transform.position);
				AmbientLifePlugin.CreatureType type = Type;
				if (1 == 0)
				{
				}
				float num2 = type switch
				{
					AmbientLifePlugin.CreatureType.Deer => 10f, 
					AmbientLifePlugin.CreatureType.Chicken => 5f, 
					AmbientLifePlugin.CreatureType.BrownSpider => 3f, 
					AmbientLifePlugin.CreatureType.GreenSpider => 3f, 
					AmbientLifePlugin.CreatureType.BlackSpider => 4f, 
					AmbientLifePlugin.CreatureType.Butterfly => 2f, 
					_ => 0f, 
				};
				if (1 == 0)
				{
				}
				float num3 = num2;
				if (num3 > 0f && num < num3)
				{
					controller.Flee(((Component)Player.instance).transform.position, num3 * 2f);
				}
			}
		}
	}
	public static class CreatureAssetLoader
	{
		public enum CreatureCategory
		{
			Spiders,
			Beetles,
			Wolves,
			SmallAnimals,
			Ambient
		}

		private static Dictionary<string, AssetBundle> loadedBundles = new Dictionary<string, AssetBundle>();

		private static Dictionary<string, GameObject> creaturePrefabs = new Dictionary<string, GameObject>();

		private static bool isInitialized = false;

		private const string BUNDLE_SPIDERS = "creatures_spiders";

		private const string BUNDLE_BEETLES = "creatures_beetles";

		private const string BUNDLE_WOLF = "creatures_wolf";

		private const string BUNDLE_TORTOISE = "creatures_tortoise";

		private const string BUNDLE_ANIMALS = "creatures_animals";

		public static readonly Dictionary<CreatureCategory, List<string>> CategoryPrefabs = new Dictionary<CreatureCategory, List<string>>
		{
			{
				CreatureCategory.Spiders,
				new List<string> { "spider", "spider_egg_1", "spider_egg_2", "spider_egg_3", "brown_spider", "green_spider", "black_spider" }
			},
			{
				CreatureCategory.Beetles,
				new List<string> { "Flying Beetle", "Nightmare Beetle" }
			},
			{
				CreatureCategory.Wolves,
				new List<string> { "Wolf_LRP", "Wolf_URP", "Wolf_HDRP" }
			},
			{
				CreatureCategory.SmallAnimals,
				new List<string> { "Dog", "Kitty", "Chicken", "Penguin", "Deer", "Tiger", "Horse" }
			},
			{
				CreatureCategory.Ambient,
				new List<string> { "Tortoise Boss" }
			}
		};

		public static int LoadedPrefabCount => creaturePrefabs.Count;

		public static int LoadedBundleCount => loadedBundles.Count;

		public static void Initialize()
		{
			if (!isInitialized)
			{
				string text = Path.Combine(AmbientLifePlugin.PluginPath, "Bundles");
				AmbientLifePlugin.Log.LogInfo((object)("Loading creature bundles from: " + text));
				if (!Directory.Exists(text))
				{
					AmbientLifePlugin.Log.LogWarning((object)"Bundles folder not found, creating...");
					Directory.CreateDirectory(text);
					return;
				}
				LoadBundle(text, "creatures_spiders");
				LoadBundle(text, "creatures_beetles");
				LoadBundle(text, "creatures_wolf");
				LoadBundle(text, "creatures_tortoise");
				LoadBundle(text, "creatures_animals");
				CachePrefabs();
				isInitialized = true;
				AmbientLifePlugin.Log.LogInfo((object)$"Loaded {creaturePrefabs.Count} creature prefabs");
			}
		}

		private static void LoadBundle(string basePath, string bundleName)
		{
			string text = Path.Combine(basePath, bundleName);
			if (!File.Exists(text))
			{
				AmbientLifePlugin.Log.LogWarning((object)("Bundle not found: " + bundleName));
				return;
			}
			try
			{
				AssetBundle val = AssetBundle.LoadFromFile(text);
				if ((Object)(object)val != (Object)null)
				{
					loadedBundles[bundleName] = val;
					AmbientLifePlugin.Log.LogInfo((object)("Loaded bundle: " + bundleName));
					string[] allAssetNames = val.GetAllAssetNames();
					string[] array = allAssetNames;
					foreach (string text2 in array)
					{
						AmbientLifePlugin.LogDebug("  Asset: " + text2);
					}
				}
				else
				{
					AmbientLifePlugin.Log.LogWarning((object)("Failed to load bundle: " + bundleName));
				}
			}
			catch (Exception ex)
			{
				AmbientLifePlugin.Log.LogError((object)("Error loading bundle " + bundleName + ": " + ex.Message));
			}
		}

		private static void CachePrefabs()
		{
			foreach (KeyValuePair<string, AssetBundle> loadedBundle in loadedBundles)
			{
				string key = loadedBundle.Key;
				AssetBundle value = loadedBundle.Value;
				try
				{
					GameObject[] array = value.LoadAllAssets<GameObject>();
					GameObject[] array2 = array;
					foreach (GameObject val in array2)
					{
						if ((Object)(object)val != (Object)null)
						{
							string key2 = ((Object)val).name.ToLowerInvariant();
							if (!creaturePrefabs.ContainsKey(key2))
							{
								creaturePrefabs[key2] = val;
								AmbientLifePlugin.LogDebug("Cached prefab: " + ((Object)val).name + " from " + key);
							}
						}
					}
				}
				catch (Exception ex)
				{
					AmbientLifePlugin.Log.LogError((object)("Error caching prefabs from " + key + ": " + ex.Message));
				}
			}
		}

		public static GameObject GetPrefab(string prefabName)
		{
			if (!isInitialized)
			{
				Initialize();
			}
			string text = prefabName.ToLowerInvariant();
			if (creaturePrefabs.TryGetValue(text, out var value))
			{
				return value;
			}
			foreach (KeyValuePair<string, GameObject> creaturePrefab in creaturePrefabs)
			{
				if (creaturePrefab.Key.Contains(text) || text.Contains(creaturePrefab.Key))
				{
					return creaturePrefab.Value;
				}
			}
			return null;
		}

		public static GameObject SpawnCreature(string prefabName, Vector3 position, Quaternion rotation)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab(prefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				AmbientLifePlugin.LogDebug("Prefab not found: " + prefabName + ", using procedural");
				return null;
			}
			GameObject val = null;
			try
			{
				val = Object.Instantiate<GameObject>(prefab, position, rotation);
				if ((Object)(object)val == (Object)null)
				{
					AmbientLifePlugin.Log.LogWarning((object)("Instantiate returned null for " + prefabName));
					return null;
				}
				((Object)val).name = "Ambient_" + prefabName;
				try
				{
					CleanMissingScripts(val);
					DisableDefaultComponents(val);
				}
				catch (Exception ex)
				{
					AmbientLifePlugin.LogDebug("Non-fatal error cleaning " + prefabName + ": " + ex.Message);
				}
				return val;
			}
			catch (Exception ex2)
			{
				AmbientLifePlugin.Log.LogError((object)("Error spawning " + prefabName + ": " + ex2.Message));
				if ((Object)(object)val != (Object)null)
				{
					try
					{
						Object.Destroy((Object)(object)val);
					}
					catch
					{
					}
				}
				return null;
			}
		}

		private static void DisableDefaultComponents(GameObject obj)
		{
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			NavMeshAgent component = obj.GetComponent<NavMeshAgent>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			MonoBehaviour[] components = obj.GetComponents<MonoBehaviour>();
			MonoBehaviour[] array = components;
			foreach (MonoBehaviour val in array)
			{
				try
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Type type = ((object)val).GetType();
					if (!(type == null))
					{
						string text = type.Name.ToLowerInvariant();
						string text2 = type.FullName?.ToLowerInvariant() ?? "";
						if (text2.Contains("ithappy") || text2.Contains("animals_free"))
						{
							Object.DestroyImmediate((Object)(object)val);
						}
						else if (text.Contains("ai") || text.Contains("controller") || text.Contains("agent") || text.Contains("enemy") || text.Contains("mover") || text.Contains("input"))
						{
							((Behaviour)val).enabled = false;
						}
					}
				}
				catch (Exception)
				{
					try
					{
						if ((Object)(object)val != (Object)null)
						{
							Object.DestroyImmediate((Object)(object)val);
						}
					}
					catch
					{
					}
				}
			}
			foreach (Transform item in obj.transform)
			{
				Transform val2 = item;
				DisableDefaultComponents(((Component)val2).gameObject);
			}
		}

		private static void CleanMissingScripts(GameObject obj)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			Component[] components = obj.GetComponents<Component>();
			Component[] array = components;
			foreach (Component val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
				}
			}
			foreach (Transform item in obj.transform)
			{
				Transform val2 = item;
				CleanMissingScripts(((Component)val2).gameObject);
			}
		}

		public static List<string> GetAvailablePrefabs()
		{
			if (!isInitialized)
			{
				Initialize();
			}
			return new List<string>(creaturePrefabs.Keys);
		}

		public static List<string> GetPrefabsForCategory(CreatureCategory category)
		{
			if (CategoryPrefabs.TryGetValue(category, out var value))
			{
				return value;
			}
			return new List<string>();
		}

		public static void Unload()
		{
			foreach (AssetBundle value in loadedBundles.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					value.Unload(true);
				}
			}
			loadedBundles.Clear();
			creaturePrefabs.Clear();
			isInitialized = false;
		}

		public static bool HasPrefab(string name)
		{
			if (!isInitialized)
			{
				Initialize();
			}
			return creaturePrefabs.ContainsKey(name.ToLowerInvariant());
		}
	}
	public class CreatureConfigUI : MonoBehaviour
	{
		private bool showUI = false;

		private Rect windowRect = new Rect(20f, 20f, 400f, 500f);

		private Vector2 scrollPosition = Vector2.zero;

		private GUIStyle windowStyle;

		private GUIStyle headerStyle;

		private GUIStyle toggleStyle;

		private GUIStyle sliderLabelStyle;

		private GUIStyle buttonStyle;

		private bool stylesInitialized = false;

		private KeyCode toggleKey = (KeyCode)289;

		private void Update()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(toggleKey))
			{
				showUI = !showUI;
			}
		}

		private void OnGUI()
		{
			//IL_001e: 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_003f: Expected O, but got Unknown
			//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)
			if (showUI)
			{
				InitStyles();
				windowRect = GUI.Window(9876, windowRect, new WindowFunction(DrawWindow), "Ambient Life Settings", windowStyle);
			}
		}

		private void InitStyles()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0047: 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_006f: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			if (!stylesInitialized)
			{
				windowStyle = new GUIStyle(GUI.skin.window);
				windowStyle.normal.background = MakeTex(2, 2, new Color(0.15f, 0.15f, 0.18f, 0.95f));
				windowStyle.padding = new RectOffset(10, 10, 25, 10);
				headerStyle = new GUIStyle(GUI.skin.label);
				headerStyle.fontSize = 14;
				headerStyle.fontStyle = (FontStyle)1;
				headerStyle.normal.textColor = new Color(0.9f, 0.85f, 0.6f);
				toggleStyle = new GUIStyle(GUI.skin.toggle);
				toggleStyle.normal.textColor = Color.white;
				toggleStyle.fontSize = 12;
				sliderLabelStyle = new GUIStyle(GUI.skin.label);
				sliderLabelStyle.fontSize = 11;
				sliderLabelStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f);
				buttonStyle = new GUIStyle(GUI.skin.button);
				buttonStyle.normal.background = MakeTex(2, 2, new Color(0.3f, 0.3f, 0.35f));
				buttonStyle.hover.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.45f));
				buttonStyle.normal.textColor = Color.white;
				stylesInitialized = true;
			}
		}

		private Texture2D MakeTex(int width, int height, Color col)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_002c: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private void DrawWindow(int windowID)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Press {toggleKey} to toggle this window", sliderLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label("General Settings", headerStyle, Array.Empty<GUILayoutOption>());
			AmbientLifePlugin.EnableAmbientLife.Value = GUILayout.Toggle(AmbientLifePlugin.EnableAmbientLife.Value, " Enable Ambient Life", toggleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Max Creatures: {AmbientLifePlugin.MaxCreatures.Value}", sliderLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
			AmbientLifePlugin.MaxCreatures.Value = (int)GUILayout.HorizontalSlider((float)AmbientLifePlugin.MaxCreatures.Value, 5f, 100f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Spawn Radius: {AmbientLifePlugin.SpawnRadius.Value:F0}m", sliderLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
			AmbientLifePlugin.SpawnRadius.Value = GUILayout.HorizontalSlider(AmbientLifePlugin.SpawnRadius.Value, 20f, 100f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(15f);
			GUILayout.Label("Creature Types", headerStyle, Array.Empty<GUILayoutOption>());
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(280f) });
			DrawCreatureCategory("Flying Insects", new(string, ConfigEntry<bool>)[2]
			{
				("Butterflies", AmbientLifePlugin.EnableButterflies),
				("Fireflies", AmbientLifePlugin.EnableFireflies)
			});
			DrawCreatureCategory("Beetles & Bugs", new(string, ConfigEntry<bool>)[2]
			{
				("Flying Beetles", AmbientLifePlugin.EnableBeetles),
				("Nightmare Beetles", AmbientLifePlugin.EnableNightmareBeetles)
			});
			DrawCreatureCategory("Spiders", new(string, ConfigEntry<bool>)[3]
			{
				("Brown Spiders", AmbientLifePlugin.EnableBrownSpiders),
				("Green Spiders", AmbientLifePlugin.EnableGreenSpiders),
				("Black Spiders", AmbientLifePlugin.EnableBlackSpiders)
			});
			DrawCreatureCategory("Ground Animals", new(string, ConfigEntry<bool>)[4]
			{
				("Dogs", AmbientLifePlugin.EnableDogs),
				("Cats", AmbientLifePlugin.EnableCats),
				("Chickens", AmbientLifePlugin.EnableChickens),
				("Deer", AmbientLifePlugin.EnableDeer)
			});
			DrawCreatureCategory("Other", new(string, ConfigEntry<bool>)[2]
			{
				("Wolves", AmbientLifePlugin.EnableWolves),
				("Penguins", AmbientLifePlugin.EnablePenguins)
			});
			GUILayout.EndScrollView();
			GUILayout.Space(10f);
			GUILayout.Label("Spawn Weights (Relative Density)", headerStyle, Array.Empty<GUILayoutOption>());
			DrawDensitySlider("Flying Insects", ref AmbientLifePlugin.DensityFlying);
			DrawDensitySlider("Ground Crawlers", ref AmbientLifePlugin.DensityCrawling);
			DrawDensitySlider("Ground Animals", ref AmbientLifePlugin.DensityAnimals);
			GUILayout.Space(10f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Active Creatures: {AmbientLifePlugin.ActiveCreatures.Count}", sliderLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Loaded Prefabs: {CreatureAssetLoader.LoadedPrefabCount}", sliderLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Reload Assets", buttonStyle, Array.Empty<GUILayoutOption>()))
			{
				CreatureAssetLoader.Unload();
				CreatureAssetLoader.Initialize();
			}
			if (GUILayout.Button("Clear All Creatures", buttonStyle, Array.Empty<GUILayoutOption>()))
			{
				AmbientLifePlugin.Instance.ClearAllCreatures();
			}
			if (GUILayout.Button("Close", buttonStyle, Array.Empty<GUILayoutOption>()))
			{
				showUI = false;
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, 25f));
		}

		private void DrawCreatureCategory(string categoryName, (string name, ConfigEntry<bool> config)[] creatures)
		{
			GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUILayout.Label(categoryName, sliderLabelStyle, Array.Empty<GUILayoutOption>());
			for (int i = 0; i < creatures.Length; i++)
			{
				(string, ConfigEntry<bool>) tuple = creatures[i];
				tuple.Item2.Value = GUILayout.Toggle(tuple.Item2.Value, " " + tuple.Item1, toggleStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUILayout.Space(5f);
		}

		private void DrawDensitySlider(string label, ref float density)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"{label}: {density:P0}", sliderLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
			density = GUILayout.HorizontalSlider(density, 0f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) });
			GUILayout.EndHorizontal();
		}
	}
	public class SmartCreatureController : MonoBehaviour
	{
		public enum MovementMode
		{
			Flying,
			Hovering,
			Crawling,
			WallCrawling
		}

		private Vector3 targetPosition;

		private Vector3 currentVelocity;

		private Vector3 surfaceNormal = Vector3.up;

		private float targetChangeTimer;

		private float obstacleCheckTimer;

		private bool isGrounded;

		private bool isOnWall;

		private bool isOnCeiling;

		private const float OBSTACLE_CHECK_INTERVAL = 0.1f;

		private const float GROUND_CHECK_DIST = 0.5f;

		private const float OBSTACLE_AVOID_DIST = 2f;

		private const float SURFACE_FOLLOW_DIST = 0.3f;

		private int groundLayer;

		private int buildingLayer;

		private int obstacleLayer;

		private LayerMask environmentMask;

		public MovementMode Mode { get; private set; }

		public float MoveSpeed { get; set; } = 2f;


		public float TurnSpeed { get; set; } = 3f;


		public float TargetChangeInterval { get; set; } = 3f;


		public float WanderRadius { get; set; } = 10f;


		public float PreferredHeight { get; set; } = 2f;


		public float MinHeight { get; set; } = 0.5f;


		public float MaxHeight { get; set; } = 20f;


		private void Awake()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			groundLayer = LayerMask.NameToLayer("Ground");
			buildingLayer = LayerMask.NameToLayer("Building");
			obstacleLayer = LayerMask.NameToLayer("Obstacle");
			environmentMask = LayerMask.op_Implicit(LayerMask.GetMask(new string[6] { "Ground", "Building", "Obstacle", "Default", "Machine", "Wall" }));
			if (LayerMask.op_Implicit(environmentMask) == 0)
			{
				environmentMask = LayerMask.op_Implicit(-5);
			}
		}

		public void Initialize(MovementMode mode, float speed, float wanderRadius)
		{
			Mode = mode;
			MoveSpeed = speed;
			WanderRadius = wanderRadius;
			SetupModeParameters();
			PickNewTarget();
		}

		private void SetupModeParameters()
		{
			switch (Mode)
			{
			case MovementMode.Flying:
				PreferredHeight = Random.Range(8f, 15f);
				MinHeight = 5f;
				MaxHeight = 25f;
				TurnSpeed = 2f;
				break;
			case MovementMode.Hovering:
				PreferredHeight = Random.Range(1f, 3f);
				MinHeight = 0.3f;
				MaxHeight = 5f;
				TurnSpeed = 4f;
				break;
			case MovementMode.Crawling:
				PreferredHeight = 0f;
				MinHeight = 0f;
				MaxHeight = 0.5f;
				TurnSpeed = 5f;
				break;
			case MovementMode.WallCrawling:
				PreferredHeight = 0f;
				MinHeight = 0f;
				MaxHeight = 0f;
				TurnSpeed = 4f;
				break;
			}
		}

		private void Update()
		{
			targetChangeTimer += Time.deltaTime;
			obstacleCheckTimer += Time.deltaTime;
			if (obstacleCheckTimer >= 0.1f)
			{
				obstacleCheckTimer = 0f;
				CheckEnvironment();
			}
			if (targetChangeTimer >= TargetChangeInterval)
			{
				targetChangeTimer = 0f;
				PickNewTarget();
			}
			switch (Mode)
			{
			case MovementMode.Flying:
				UpdateFlyingMovement();
				break;
			case MovementMode.Hovering:
				UpdateHoveringMovement();
				break;
			case MovementMode.Crawling:
				UpdateCrawlingMovement();
				break;
			case MovementMode.WallCrawling:
				UpdateWallCrawlingMovement();
				break;
			}
		}

		private void CheckEnvironment()
		{
			//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_0013: 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)
			RaycastHit val = default(RaycastHit);
			isGrounded = Physics.Raycast(((Component)this).transform.position, -surfaceNormal, ref val, 0.5f, LayerMask.op_Implicit(environmentMask));
			if (Mode == MovementMode.WallCrawling)
			{
				CheckForSurfaces();
			}
		}

		private void CheckForSurfaces()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//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_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)
			//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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0126: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[7]
			{
				-surfaceNormal,
				Vector3.down,
				Vector3.up,
				((Component)this).transform.forward,
				-((Component)this).transform.forward,
				((Component)this).transform.right,
				-((Component)this).transform.right
			};
			float num = float.MaxValue;
			Vector3 val = Vector3.up;
			bool flag = false;
			Vector3[] array2 = array;
			RaycastHit val3 = default(RaycastHit);
			foreach (Vector3 val2 in array2)
			{
				if (Physics.Raycast(((Component)this).transform.position, val2, ref val3, 0.6f, LayerMask.op_Implicit(environmentMask)) && ((RaycastHit)(ref val3)).distance < num)
				{
					num = ((RaycastHit)(ref val3)).distance;
					val = ((RaycastHit)(ref val3)).normal;
					flag = true;
				}
			}
			if (flag)
			{
				surfaceNormal = Vector3.Lerp(surfaceNormal, val, Time.deltaTime * 5f);
				isOnWall = Mathf.Abs(Vector3.Dot(surfaceNormal, Vector3.up)) < 0.5f;
				isOnCeiling = Vector3.Dot(surfaceNormal, Vector3.up) < -0.5f;
			}
		}

		private void PickNewTarget()
		{
			//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_009d: 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)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00c8: 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_0023: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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)
			Vector3 val = ((Component)this).transform.position;
			if ((Object)(object)Player.instance != (Object)null)
			{
				float num = Vector3.Distance(((Component)this).transform.position, ((Component)Player.instance).transform.position);
				if (num > AmbientLifePlugin.SpawnRadius.Value)
				{
					val = Vector3.Lerp(((Component)this).transform.position, ((Component)Player.instance).transform.position, 0.5f);
				}
			}
			Vector3 val2 = new Vector3(Random.Range(-1f, 1f), 0f, Random.Range(-1f, 1f));
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			float num2 = Random.Range(WanderRadius * 0.3f, WanderRadius);
			targetPosition = val + normalized * num2;
			switch (Mode)
			{
			case MovementMode.Flying:
			case MovementMode.Hovering:
				targetPosition.y = GetSafeHeight(targetPosition);
				break;
			case MovementMode.Crawling:
			case MovementMode.WallCrawling:
				targetPosition = GetGroundPosition(targetPosition);
				break;
			}
			if (!IsPathClear(((Component)this).transform.position, targetPosition))
			{
				targetPosition = FindAlternatePath();
			}
		}

		private float GetSafeHeight(Vector3 position)
		{
			//IL_0018: 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_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_0042: 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_0087: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			float num = PreferredHeight + Random.Range(-2f, 2f);
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(new Vector3(position.x, position.y + 100f, position.z), Vector3.down, ref val, 200f, LayerMask.op_Implicit(environmentMask)))
			{
				float y = ((RaycastHit)(ref val)).point.y;
				num = Mathf.Max(y + MinHeight, Mathf.Min(y + MaxHeight, y + num));
			}
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(position, Vector3.up, ref val2, MaxHeight, LayerMask.op_Implicit(environmentMask)))
			{
				num = Mathf.Min(num, ((RaycastHit)(ref val2)).point.y - 0.5f);
			}
			return num;
		}

		private Vector3 GetGroundPosition(Vector3 position)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0020: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			//IL_005f: 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)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(position.x, position.y + 10f, position.z);
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 100f, LayerMask.op_Implicit(environmentMask)))
			{
				return ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.3f;
			}
			return position;
		}

		private bool IsPathClear(Vector3 from, Vector3 to)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			float magnitude = ((Vector3)(ref val)).magnitude;
			return !Physics.Raycast(from, ((Vector3)(ref val)).normalized, magnitude, LayerMask.op_Implicit(environmentMask));
		}

		private Vector3 FindAlternatePath()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				float num = (float)i * 45f * ((float)Math.PI / 180f);
				((Vector3)(ref val))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num));
				Vector3 val2 = ((Component)this).transform.position + val * WanderRadius * 0.5f;
				if (Mode == MovementMode.Flying || Mode == MovementMode.Hovering)
				{
					val2.y = GetSafeHeight(val2);
				}
				else
				{
					val2 = GetGroundPosition(val2);
				}
				if (IsPathClear(((Component)this).transform.position, val2))
				{
					return val2;
				}
			}
			return ((Component)this).transform.position + Vector3.up * 0.5f;
		}

		private void UpdateFlyingMovement()
		{
			//IL_0002: 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_0026: 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_005f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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)
			//IL_003d: 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_004d: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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)
			Vector3 val = targetPosition - ((Component)this).transform.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 obstacleAvoidance = GetObstacleAvoidance();
			if (((Vector3)(ref obstacleAvoidance)).sqrMagnitude > 0.01f)
			{
				Vector3 val2 = normalized + obstacleAvoidance * 2f;
				normalized = ((Vector3)(ref val2)).normalized;
			}
			currentVelocity = Vector3.Lerp(currentVelocity, normalized * MoveSpeed, Time.deltaTime * TurnSpeed);
			Transform transform = ((Component)this).transform;
			transform.position += currentVelocity * Time.deltaTime;
			if (((Vector3)(ref currentVelocity)).sqrMagnitude > 0.01f)
			{
				Quaternion val3 = Quaternion.LookRotation(((Vector3)(ref currentVelocity)).normalized);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val3, Time.deltaTime * TurnSpeed);
			}
			float heightAboveGround = GetHeightAboveGround();
			if (heightAboveGround < MinHeight)
			{
				Transform transform2 = ((Component)this).transform;
				transform2.position += Vector3.up * (MinHeight - heightAboveGround) * Time.deltaTime * 5f;
			}
			else if (heightAboveGround > MaxHeight)
			{
				Transform transform3 = ((Component)this).transform;
				transform3.position -= Vector3.up * (heightAboveGround - MaxHeight) * Time.deltaTime * 5f;
			}
		}

		private void UpdateHoveringMovement()
		{
			//IL_0002: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bf: 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_00c9: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = targetPosition - ((Component)this).transform.position;
			Vector3 val2 = ((Vector3)(ref val)).normalized;
			float num = Mathf.Sin(Time.time * 3f + ((Component)this).transform.position.x) * 0.3f;
			float num2 = Mathf.Sin(Time.time * 2f + ((Component)this).transform.position.z) * 0.2f;
			Vector3 obstacleAvoidance = GetObstacleAvoidance();
			val2 += obstacleAvoidance;
			((Vector3)(ref val2)).Normalize();
			currentVelocity = Vector3.Lerp(currentVelocity, val2 * MoveSpeed, Time.deltaTime * TurnSpeed);
			Vector3 val3 = currentVelocity + new Vector3(num, num2, 0f);
			Transform transform = ((Component)this).transform;
			transform.position += val3 * Time.deltaTime;
			if (((Vector3)(ref currentVelocity)).sqrMagnitude > 0.01f)
			{
				Vector3 val4 = currentVelocity;
				val4.y *= 0.3f;
				if (((Vector3)(ref val4)).sqrMagnitude > 0.01f)
				{
					Quaternion val5 = Quaternion.LookRotation(((Vector3)(ref val4)).normalized);
					((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val5, Time.deltaTime * TurnSpeed);
				}
			}
			MaintainHeight();
		}

		private void UpdateCrawlingMovement()
		{
			//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_0012: 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_0020: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0132: 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_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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			Vector3 groundPosition = GetGroundPosition(((Component)this).transform.position);
			Vector3 groundPosition2 = GetGroundPosition(targetPosition);
			Vector3 val = groundPosition2 - groundPosition;
			val.y = 0f;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 obstacleAvoidance = GetObstacleAvoidance();
			obstacleAvoidance.y = 0f;
			if (((Vector3)(ref obstacleAvoidance)).sqrMagnitude > 0.01f)
			{
				Vector3 val2 = normalized + obstacleAvoidance;
				normalized = ((Vector3)(ref val2)).normalized;
			}
			currentVelocity = Vector3.Lerp(currentVelocity, normalized * MoveSpeed, Time.deltaTime * TurnSpeed);
			currentVelocity.y = 0f;
			Vector3 position = ((Component)this).transform.position + currentVelocity * Time.deltaTime;
			position = GetGroundPosition(position);
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, position, Time.deltaTime * 10f);
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(((Component)this).transform.position + Vector3.up * 0.5f, Vector3.down, ref val3, 2f, LayerMask.op_Implicit(environmentMask)))
			{
				Vector3 val4 = Vector3.Cross(((Component)this).transform.right, ((RaycastHit)(ref val3)).normal);
				if (((Vector3)(ref val4)).sqrMagnitude > 0.01f)
				{
					Quaternion val5 = Quaternion.LookRotation(val4, ((RaycastHit)(ref val3)).normal);
					((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val5, Time.deltaTime * TurnSpeed);
				}
			}
		}

		private void UpdateWallCrawlingMovement()
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0020: 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_0032: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0089: 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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00da: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0114: 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_00a0: 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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_016a: 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)
			//IL_0140: 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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			Vector3 normal = surfaceNormal;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)this).transform.position, -surfaceNormal, ref val, 0.6f, LayerMask.op_Implicit(environmentMask)))
			{
				position = ((RaycastHit)(ref val)).point;
				normal = ((RaycastHit)(ref val)).normal;
			}
			Vector3 val2 = targetPosition - ((Component)this).transform.position;
			Vector3 val3 = Vector3.ProjectOnPlane(val2, normal);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			Vector3 surfaceObstacleAvoidance = GetSurfaceObstacleAvoidance(normal);
			if (((Vector3)(ref surfaceObstacleAvoidance)).sqrMagnitude > 0.01f)
			{
				val3 = normalized + surfaceObstacleAvoidance;
				normalized = ((Vector3)(ref val3)).normalized;
			}
			currentVelocity = Vector3.Lerp(currentVelocity, normalized * MoveSpeed, Time.deltaTime * TurnSpeed);
			Vector3 val4 = ((Component)this).transform.position + currentVelocity * Time.deltaTime;
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(val4 + normal * 0.5f, -normal, ref val5, 1f, LayerMask.op_Implicit(environmentMask)))
			{
				val4 = ((RaycastHit)(ref val5)).point + ((RaycastHit)(ref val5)).normal * 0.3f;
				surfaceNormal = ((RaycastHit)(ref val5)).normal;
			}
			((Component)this).transform.position = val4;
			if (((Vector3)(ref currentVelocity)).sqrMagnitude > 0.01f)
			{
				Vector3 normalized2 = ((Vector3)(ref currentVelocity)).normalized;
				Quaternion val6 = Quaternion.LookRotation(normalized2, surfaceNormal);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val6, Time.deltaTime * TurnSpeed);
			}
		}

		private Vector3 GetObstacleAvoidance()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0044: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_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)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0126: 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_0130: 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_0195: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			int num = 8;
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / (float)num * 360f * ((float)Mat