Decompiled source of TungTungTungSahur v1.0.0

TungTungTungSahur.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using TungTungTungSahur.Audio;
using TungTungTungSahur.Enemy;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TungTungTungSahur")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TungTungTungSahur")]
[assembly: AssemblyTitle("TungTungTungSahur")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 TungTungTungSahur
{
	internal sealed class MoonSelection
	{
		public LevelTypes VanillaLevelFlags { get; }

		public string[] CustomMoonNames { get; }

		private MoonSelection(LevelTypes vanillaLevelFlags, string[] customMoonNames)
		{
			//IL_0007: 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)
			VanillaLevelFlags = vanillaLevelFlags;
			CustomMoonNames = customMoonNames;
		}

		public static MoonSelection Parse(string configuredMoons)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_0092: Invalid comparison between Unknown and I4
			//IL_009a: 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_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)
			string[] array = (from moonName in configuredMoons.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select moonName.Trim() into moonName
				where moonName.Length > 0
				select moonName).ToArray();
			if (array.Length == 0)
			{
				throw new ArgumentException("The 'Moons' config is empty. Use 'All' or list at least one moon.", "configuredMoons");
			}
			LevelTypes val = (LevelTypes)1;
			List<string> list = new List<string>();
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (TryParseLevelType(text, out var levelType))
				{
					val = (LevelTypes)(((int)val == 1) ? levelType : (val | levelType));
				}
				else
				{
					list.Add(text);
				}
			}
			return new MoonSelection(val, list.ToArray());
		}

		private static bool TryParseLevelType(string moonName, out LevelTypes levelType)
		{
			string text = new string(moonName.Where(char.IsLetter).ToArray());
			if (!Enum.TryParse<LevelTypes>(text, ignoreCase: true, out levelType))
			{
				return Enum.TryParse<LevelTypes>(text + "Level", ignoreCase: true, out levelType);
			}
			return true;
		}
	}
	[BepInPlugin("TungTungTungSahur", "Tung Tung Tung Sahur", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "TungTungTungSahur";

		public const string PluginName = "Tung Tung Tung Sahur";

		public const string PluginVersion = "1.0.0";

		private static TungSahurConfig? settings;

		internal static ManualLogSource Log { get; private set; }

		internal static TungSahurConfig Settings => settings ?? throw new InvalidOperationException("Tung Tung Tung Sahur config was used before the plugin loaded it.");

		private void Awake()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			settings = new TungSahurConfig(((BaseUnityPlugin)this).Config);
			TungSahurSounds sounds = TungSahurSounds.Load(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? throw new InvalidOperationException("Could not resolve the plugin directory from '" + ((BaseUnityPlugin)this).Info.Location + "'."), "Sounds"), ((BaseUnityPlugin)this).Logger);
			TungSahurAI.UseSounds(sounds);
			EnemyType obj = TungSahurPrefabFactory.CreateEnemyType(Settings, sounds);
			MoonSelection moonSelection = MoonSelection.Parse(Settings.Moons.Value);
			Enemies.RegisterEnemy(obj, Settings.SpawnWeight.Value, moonSelection.VanillaLevelFlags, (SpawnType)0, moonSelection.CustomMoonNames, CreateBestiaryEntry(), TerminalUtils.CreateTerminalKeyword("tungsahur", false, (CompatibleNoun[])null, (TerminalNode)null, (TerminalKeyword)null, false));
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded. Spawn weight {2} on '{3}'. Tung tung tung...", "Tung Tung Tung Sahur", "1.0.0", Settings.SpawnWeight.Value, Settings.Moons.Value));
		}

		private static TerminalNode CreateBestiaryEntry()
		{
			TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)obj).hideFlags = (HideFlags)32;
			obj.creatureName = "Tung Tung Tung Sahur";
			obj.clearPreviousText = true;
			obj.maxCharactersToType = 35;
			obj.displayText = "TUNG TUNG TUNG SAHUR\n\nSigurd's danger level: 70%\n\nScientific name: Lignum vocans\n\nA tall, hollow log-like organism that carries a club of dense wood. It wanders interior corridors and announces itself by striking the floor in a slow rhythm of knocks when it notices a crew member.\n\nThe knocking is a call. Crew members who are still in its sight when the knocking stops are chased down at great speed and struck repeatedly. Breaking line of sight before the final knock appears to make it lose interest.\n\nIt is not durable. A few solid hits with a shovel will fell it.\n\n";
			return obj;
		}
	}
	internal sealed class TungSahurConfig
	{
		private const string SpawningSection = "Spawning";

		private const string BehaviourSection = "Behaviour";

		public ConfigEntry<int> SpawnWeight { get; }

		public ConfigEntry<string> Moons { get; }

		public ConfigEntry<int> MaxCount { get; }

		public ConfigEntry<float> PowerLevel { get; }

		public ConfigEntry<int> Health { get; }

		public ConfigEntry<int> HitDamage { get; }

		public ConfigEntry<float> RoamSpeed { get; }

		public ConfigEntry<float> ChaseSpeed { get; }

		public ConfigEntry<int> KnockCount { get; }

		public ConfigEntry<float> SecondsBetweenKnocks { get; }

		public ConfigEntry<int> SightRange { get; }

		public ConfigEntry<float> SecondsToLoseTarget { get; }

		public TungSahurConfig(ConfigFile configFile)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Expected O, but got Unknown
			SpawnWeight = configFile.Bind<int>("Spawning", "SpawnWeight", 35, new ConfigDescription("Spawn weight on each selected moon. Vanilla interior enemies range roughly from 1 to 100.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
			Moons = configFile.Bind<string>("Spawning", "Moons", "All", "Where it spawns. 'All', 'Vanilla', 'Modded', or a comma separated list of moon names (e.g. 'Experimentation, Titan, Rend'). Unknown names are treated as modded moon names.");
			MaxCount = configFile.Bind<int>("Spawning", "MaxCount", 2, new ConfigDescription("Maximum amount alive at the same time.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			PowerLevel = configFile.Bind<float>("Spawning", "PowerLevel", 2f, new ConfigDescription("How much of the moon's interior power budget one spawn uses.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			Health = configFile.Bind<int>("Behaviour", "Health", 4, new ConfigDescription("Shovel hits needed to kill it.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			HitDamage = configFile.Bind<int>("Behaviour", "HitDamage", 50, new ConfigDescription("Damage of one bat hit. Players have 100 health.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			RoamSpeed = configFile.Bind<float>("Behaviour", "RoamSpeed", 3.5f, new ConfigDescription("Walking speed while wandering the facility.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
			ChaseSpeed = configFile.Bind<float>("Behaviour", "ChaseSpeed", 8.5f, new ConfigDescription("Top speed while chasing a player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			KnockCount = configFile.Bind<int>("Behaviour", "KnockCount", 3, new ConfigDescription("How many 'tung' knocks it calls out before chasing a player who is still in sight.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 12), Array.Empty<object>()));
			SecondsBetweenKnocks = configFile.Bind<float>("Behaviour", "SecondsBetweenKnocks", 0.8f, new ConfigDescription("Time between each knock while calling.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 3f), Array.Empty<object>()));
			SightRange = configFile.Bind<int>("Behaviour", "SightRange", 22, new ConfigDescription("How far away it can spot players.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 80), Array.Empty<object>()));
			SecondsToLoseTarget = configFile.Bind<float>("Behaviour", "SecondsToLoseTarget", 6f, new ConfigDescription("How long a chased player must stay out of sight before it gives up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
		}
	}
}
namespace TungTungTungSahur.Enemy
{
	public sealed class TungSahurAI : EnemyAI
	{
		private enum BehaviourState
		{
			Roaming,
			Calling,
			Chasing
		}

		private const float SpotViewAngle = 55f;

		private const float ChaseViewAngle = 80f;

		private const int ProximityAwarenessRange = 4;

		private const float TooCloseDuringCallingDistance = 2.5f;

		private const float SecondsBeforeCallingAgain = 4f;

		private const float SecondsBetweenBonks = 1.2f;

		private const float SwingTriggerDistance = 1.9f;

		private const float ChaseAcceleration = 4f;

		private const float CallingTurnSpeedDegrees = 360f;

		private const float FootstepVolume = 0.45f;

		private const float KnockVolume = 1f;

		private const float BonkLaunchSpeed = 12f;

		private static TungSahurSounds? loadedSounds;

		private readonly AISearchRoutine roamingSearch = new AISearchRoutine();

		private TungSahurRig rig;

		private float roamSpeed;

		private float chaseSpeed;

		private float secondsBetweenKnocks;

		private int knockCount;

		private int sightRange;

		private float secondsToLoseTarget;

		private int hitDamage;

		private int lastLocallyObservedState = -1;

		private int knocksPlayedThisCall;

		private float secondsUntilNextKnock;

		private float secondsSinceLocalBonk = float.MaxValue;

		private Vector3 previousFramePosition;

		private float smoothedHorizontalSpeed;

		private float callingStartedTime;

		private float lastTimeTargetSeen;

		private float callingAllowedAfterTime;

		private BehaviourState CurrentState => (BehaviourState)base.currentBehaviourStateIndex;

		private float CallingDurationSeconds => (float)knockCount * secondsBetweenKnocks + 0.4f;

		private static TungSahurSounds Sounds => loadedSounds ?? throw new InvalidOperationException("Tung Tung Tung Sahur sounds were used before the plugin loaded them.");

		internal static void UseSounds(TungSahurSounds sounds)
		{
			loadedSounds = sounds;
		}

		public override void Awake()
		{
			((EnemyAI)this).Awake();
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Object)((Component)componentsInChildren[i]).gameObject).hideFlags = (HideFlags)0;
			}
		}

		public override void Start()
		{
			//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)
			((EnemyAI)this).Start();
			rig = ((Component)this).GetComponent<TungSahurRig>() ?? throw new InvalidOperationException("TungSahurAI requires a TungSahurRig on the same GameObject.");
			ApplyConfig(Plugin.Settings);
			ApplyGameAudioMixer();
			previousFramePosition = ((Component)this).transform.position;
			base.agent.speed = roamSpeed;
			if (((NetworkBehaviour)this).IsOwner)
			{
				BeginRoaming();
			}
		}

		private void ApplyConfig(TungSahurConfig settings)
		{
			base.enemyHP = settings.Health.Value;
			roamSpeed = settings.RoamSpeed.Value;
			chaseSpeed = settings.ChaseSpeed.Value;
			secondsBetweenKnocks = settings.SecondsBetweenKnocks.Value;
			knockCount = settings.KnockCount.Value;
			sightRange = settings.SightRange.Value;
			secondsToLoseTarget = settings.SecondsToLoseTarget.Value;
			hitDamage = settings.HitDamage.Value;
		}

		private void ApplyGameAudioMixer()
		{
			AudioMixerGroup val = VanillaAudioMixerLookup.FindEnemySfxMixerGroup();
			if (!((Object)(object)val == (Object)null))
			{
				base.creatureSFX.outputAudioMixerGroup = val;
				base.creatureVoice.outputAudioMixerGroup = val;
			}
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			float horizontalSpeed = MeasureHorizontalSpeed();
			if (base.isEnemyDead)
			{
				rig.Tick(0f, TungSahurPose.Dead, Time.deltaTime);
				return;
			}
			ReactToStateChangesLocally();
			UpdateLocalKnocking();
			UpdateLocalSwing();
			PlayFootstepIfDue();
			secondsSinceLocalBonk += Time.deltaTime;
			rig.Tick(horizontalSpeed, ChoosePose(), Time.deltaTime);
			if (((NetworkBehaviour)this).IsOwner)
			{
				UpdateOwnerMovement();
			}
		}

		private float MeasureHorizontalSpeed()
		{
			//IL_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - previousFramePosition;
			previousFramePosition = ((Component)this).transform.position;
			val.y = 0f;
			float num = ((Time.deltaTime > 0f) ? (((Vector3)(ref val)).magnitude / Time.deltaTime) : 0f);
			smoothedHorizontalSpeed = Mathf.Lerp(smoothedHorizontalSpeed, num, 1f - Mathf.Exp(-10f * Time.deltaTime));
			return smoothedHorizontalSpeed;
		}

		private TungSahurPose ChoosePose()
		{
			if (base.stunNormalizedTimer > 0f)
			{
				return TungSahurPose.Stunned;
			}
			return CurrentState switch
			{
				BehaviourState.Calling => TungSahurPose.Calling, 
				BehaviourState.Chasing => TungSahurPose.Chasing, 
				_ => TungSahurPose.Wandering, 
			};
		}

		private void ReactToStateChangesLocally()
		{
			if (base.currentBehaviourStateIndex == lastLocallyObservedState)
			{
				return;
			}
			lastLocallyObservedState = base.currentBehaviourStateIndex;
			switch (CurrentState)
			{
			case BehaviourState.Calling:
				knocksPlayedThisCall = 0;
				secondsUntilNextKnock = 0.35f;
				if ((Object)(object)Sounds.CallVoice != (Object)null)
				{
					PlayVoice(Sounds.CallVoice);
				}
				break;
			case BehaviourState.Chasing:
				PlayVoice(Sounds.ChaseCall);
				break;
			}
		}

		private void UpdateLocalKnocking()
		{
			if (CurrentState == BehaviourState.Calling && knocksPlayedThisCall < knockCount && !(base.stunNormalizedTimer > 0f))
			{
				secondsUntilNextKnock -= Time.deltaTime;
				if (!(secondsUntilNextKnock > 0f))
				{
					secondsUntilNextKnock = secondsBetweenKnocks;
					knocksPlayedThisCall++;
					rig.PlayKnock();
					PlaySfx(Sounds.Knock, 1f);
				}
			}
		}

		private void UpdateLocalSwing()
		{
			//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)
			if (CurrentState != BehaviourState.Chasing || rig.IsSwinging || base.stunNormalizedTimer > 0f)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isPlayerControlled && !val.isPlayerDead && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) < 1.9f)
				{
					rig.PlaySwing();
					break;
				}
			}
		}

		private void PlayFootstepIfDue()
		{
			if (rig.TryConsumeFootstep())
			{
				base.creatureSFX.PlayOneShot(Sounds.Footstep, 0.45f);
			}
		}

		private void UpdateOwnerMovement()
		{
			if (base.stunNormalizedTimer > 0f)
			{
				base.agent.speed = 0f;
				if ((Object)(object)base.stunnedByPlayer != (Object)null && CurrentState != BehaviourState.Chasing && ((EnemyAI)this).PlayerIsTargetable(base.stunnedByPlayer, false, false, true))
				{
					BeginChasing(base.stunnedByPlayer);
				}
				return;
			}
			switch (CurrentState)
			{
			case BehaviourState.Roaming:
				base.agent.speed = roamSpeed;
				break;
			case BehaviourState.Calling:
				base.agent.speed = 0f;
				TurnTowardsTarget();
				break;
			case BehaviourState.Chasing:
				base.agent.speed = Mathf.MoveTowards(Mathf.Max(base.agent.speed, roamSpeed), chaseSpeed, 4f * Time.deltaTime);
				break;
			}
		}

		private void TurnTowardsTarget()
		{
			//IL_001a: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)base.targetPlayer == (Object)null))
			{
				Vector3 val = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
				val.y = 0f;
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.001f))
				{
					((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(val), 360f * Time.deltaTime);
				}
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (!base.isEnemyDead && !StartOfRound.Instance.allPlayersDead && !(base.stunNormalizedTimer > 0f))
			{
				switch (CurrentState)
				{
				case BehaviourState.Roaming:
					DoRoamingInterval();
					break;
				case BehaviourState.Calling:
					DoCallingInterval();
					break;
				case BehaviourState.Chasing:
					DoChasingInterval();
					break;
				}
			}
		}

		private void DoRoamingInterval()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!roamingSearch.inProgress)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, roamingSearch);
			}
			if (!(Time.time < callingAllowedAfterTime))
			{
				PlayerControllerB val = FindClosestVisiblePlayer(55f);
				if ((Object)(object)val != (Object)null)
				{
					BeginCalling(val);
				}
			}
		}

		private void DoCallingInterval()
		{
			//IL_0031: 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)
			if ((Object)(object)base.targetPlayer == (Object)null || !((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false, true))
			{
				BeginRoaming();
			}
			else if (Vector3.Distance(((Component)base.targetPlayer).transform.position, ((Component)this).transform.position) < 2.5f)
			{
				BeginChasing(base.targetPlayer);
			}
			else if (!(Time.time - callingStartedTime < CallingDurationSeconds))
			{
				if (CanSeePlayer(base.targetPlayer, 80f))
				{
					BeginChasing(base.targetPlayer);
				}
				else
				{
					BeginRoaming();
				}
			}
		}

		private void DoChasingInterval()
		{
			if ((Object)(object)base.targetPlayer == (Object)null || !((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false, true))
			{
				BeginRoaming();
				return;
			}
			if (CanSeePlayer(base.targetPlayer, 80f))
			{
				lastTimeTargetSeen = Time.time;
			}
			else if (Time.time - lastTimeTargetSeen > secondsToLoseTarget)
			{
				BeginRoaming();
				return;
			}
			((EnemyAI)this).SetMovingTowardsTargetPlayer(base.targetPlayer);
		}

		private void BeginRoaming()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			base.targetPlayer = null;
			base.movingTowardsTargetPlayer = false;
			base.moveTowardsDestination = true;
			callingAllowedAfterTime = Time.time + 4f;
			base.agent.speed = roamSpeed;
			((EnemyAI)this).StartSearch(((Component)this).transform.position, roamingSearch);
			((EnemyAI)this).SwitchToBehaviourState(0);
		}

		private void BeginCalling(PlayerControllerB player)
		{
			base.targetPlayer = player;
			((EnemyAI)this).StopSearch(roamingSearch, false);
			base.movingTowardsTargetPlayer = false;
			base.moveTowardsDestination = false;
			if (base.agent.isOnNavMesh)
			{
				base.agent.ResetPath();
			}
			callingStartedTime = Time.time;
			((EnemyAI)this).SwitchToBehaviourState(1);
		}

		private void BeginChasing(PlayerControllerB player)
		{
			((EnemyAI)this).StopSearch(roamingSearch, false);
			base.moveTowardsDestination = true;
			lastTimeTargetSeen = Time.time;
			((EnemyAI)this).SetMovingTowardsTargetPlayer(player);
			((EnemyAI)this).SwitchToBehaviourState(2);
		}

		private PlayerControllerB? FindClosestVisiblePlayer(float viewAngle)
		{
			//IL_002e: 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)
			PlayerControllerB result = null;
			float num = float.MaxValue;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (CanSeePlayer(val, viewAngle))
				{
					float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
					if (num2 < num)
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}

		private bool CanSeePlayer(PlayerControllerB player, float viewAngle)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)this).PlayerIsTargetable(player, false, false, true))
			{
				return ((EnemyAI)this).CheckLineOfSightForPosition(((Component)player.gameplayCamera).transform.position, viewAngle, sightRange, 4f, (Transform)null);
			}
			return false;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_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_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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (CurrentState == BehaviourState.Chasing && !(secondsSinceLocalBonk < 1.2f))
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if (!((Object)(object)val == (Object)null))
				{
					secondsSinceLocalBonk = 0f;
					rig.PlaySwing();
					PlaySfx(Sounds.Bonk, 1f);
					Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
					Vector3 val3 = ((Vector3)(ref val2)).normalized + Vector3.up * 0.4f;
					val.DamagePlayer(hitDamage, true, true, (CauseOfDeath)1, 0, false, val3 * 12f);
					val.JumpToFearLevel(1f, true);
				}
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB? playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (base.isEnemyDead)
			{
				return;
			}
			base.enemyHP -= force;
			rig.PlayFlinch();
			if (((NetworkBehaviour)this).IsOwner)
			{
				if (base.enemyHP <= 0)
				{
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
				else if ((Object)(object)playerWhoHit != (Object)null && ((EnemyAI)this).PlayerIsTargetable(playerWhoHit, false, false, true))
				{
					BeginChasing(playerWhoHit);
				}
			}
		}

		public override void KillEnemy(bool destroy = false)
		{
			((EnemyAI)this).KillEnemy(destroy);
			if (!destroy)
			{
				((EnemyAI)this).StopSearch(roamingSearch, false);
				base.targetPlayer = null;
				base.movingTowardsTargetPlayer = false;
			}
		}

		private void PlaySfx(AudioClip clip, float volume)
		{
			base.creatureSFX.PlayOneShot(clip, volume);
			WalkieTalkie.TransmitOneShotAudio(base.creatureSFX, clip, volume);
		}

		private void PlayVoice(AudioClip clip)
		{
			base.creatureVoice.PlayOneShot(clip);
			WalkieTalkie.TransmitOneShotAudio(base.creatureVoice, clip, base.creatureVoice.volume);
		}
	}
	internal sealed class TungSahurModelBuilder
	{
		private const string HdrpLitShaderName = "HDRP/Lit";

		private const float BodyRadius = 0.375f;

		private const float BodyBottomHeight = 0.55f;

		private const float BodyTopHeight = 2.15f;

		private const float FaceEyeHeight = 1.86f;

		private readonly int modelLayer;

		private readonly Mesh cylinderMesh;

		private readonly Mesh sphereMesh;

		private readonly Mesh cubeMesh;

		private readonly Mesh capsuleMesh;

		private readonly Material barkMaterial;

		private readonly Material cutWoodMaterial;

		private readonly Material grainMaterial;

		private readonly Material limbMaterial;

		private readonly Material batMaterial;

		private readonly Material eyeWhiteMaterial;

		private readonly Material darkFeatureMaterial;

		public TungSahurModelBuilder(int modelLayer)
		{
			//IL_006d: 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_00c1: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			this.modelLayer = modelLayer;
			cylinderMesh = GetBuiltInPrimitiveMesh((PrimitiveType)2);
			sphereMesh = GetBuiltInPrimitiveMesh((PrimitiveType)0);
			cubeMesh = GetBuiltInPrimitiveMesh((PrimitiveType)3);
			capsuleMesh = GetBuiltInPrimitiveMesh((PrimitiveType)1);
			Shader shader = Shader.Find("HDRP/Lit") ?? throw new InvalidOperationException("Shader 'HDRP/Lit' was not found, the Tung Tung Tung Sahur model cannot be built.");
			barkMaterial = CreateMaterial(shader, "TungSahur_Bark", new Color(0.78f, 0.58f, 0.38f), 0.15f);
			cutWoodMaterial = CreateMaterial(shader, "TungSahur_CutWood", new Color(0.9f, 0.75f, 0.52f), 0.1f);
			grainMaterial = CreateMaterial(shader, "TungSahur_Grain", new Color(0.52f, 0.36f, 0.21f), 0.1f);
			limbMaterial = CreateMaterial(shader, "TungSahur_Limb", new Color(0.64f, 0.45f, 0.27f), 0.15f);
			batMaterial = CreateMaterial(shader, "TungSahur_Bat", new Color(0.42f, 0.27f, 0.14f), 0.35f);
			eyeWhiteMaterial = CreateMaterial(shader, "TungSahur_EyeWhite", new Color(0.95f, 0.95f, 0.92f), 0.75f);
			darkFeatureMaterial = CreateMaterial(shader, "TungSahur_DarkFeature", new Color(0.06f, 0.03f, 0.02f), 0.6f);
		}

		public TungSahurRig Build(GameObject enemyRoot, out Transform eye)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Transform modelRoot = CreatePivot("Model", enemyRoot.transform, Vector3.zero);
			BuildLogBody(modelRoot);
			eye = BuildFace(modelRoot);
			TungSahurRig tungSahurRig = enemyRoot.AddComponent<TungSahurRig>();
			tungSahurRig.modelRoot = modelRoot;
			tungSahurRig.leftLegPivot = BuildLeg(modelRoot, "LeftLeg", -0.17f);
			tungSahurRig.rightLegPivot = BuildLeg(modelRoot, "RightLeg", 0.17f);
			tungSahurRig.leftArmPivot = BuildArm(modelRoot, "LeftArm", -0.43f);
			tungSahurRig.batArmPivot = BuildArm(modelRoot, "BatArm", 0.43f);
			BuildBat(tungSahurRig.batArmPivot);
			return tungSahurRig;
		}

		private void BuildLogBody(Transform modelRoot)
		{
			//IL_002c: 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_0043: 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_0071: 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_008c: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00db: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.8000001f;
			float num2 = 0.55f + num;
			CreatePart("Log", modelRoot, cylinderMesh, barkMaterial, new Vector3(0f, num2, 0f), new Vector3(0.75f, num, 0.75f));
			CreatePart("CutTop", modelRoot, cylinderMesh, cutWoodMaterial, new Vector3(0f, 2.15f, 0f), new Vector3(0.68f, 0.012f, 0.68f));
			CreatePart("CutBottom", modelRoot, cylinderMesh, cutWoodMaterial, new Vector3(0f, 0.55f, 0f), new Vector3(0.68f, 0.012f, 0.68f));
			CreatePart("TopRing", modelRoot, cylinderMesh, grainMaterial, new Vector3(0f, 2.154f, 0f), new Vector3(0.36f, 0.012f, 0.36f));
			CreatePart("TopCore", modelRoot, cylinderMesh, cutWoodMaterial, new Vector3(0f, 2.158f, 0f), new Vector3(0.3f, 0.012f, 0.3f));
			(float, float, float)[] array = new(float, float, float)[7]
			{
				(50f, 1.25f, 0.05f),
				(95f, 1.45f, -0.02f),
				(140f, 1f, 0.15f),
				(180f, 1.4f, 0f),
				(220f, 1.15f, -0.1f),
				(265f, 1.45f, 0.03f),
				(310f, 1.05f, 0.12f)
			};
			Vector3 localPosition = default(Vector3);
			for (int i = 0; i < array.Length; i++)
			{
				(float, float, float) tuple = array[i];
				float item = tuple.Item1;
				float item2 = tuple.Item2;
				float item3 = tuple.Item3;
				float num3 = item * (MathF.PI / 180f);
				((Vector3)(ref localPosition))..ctor(Mathf.Sin(num3) * 0.375f, num2 + item3, Mathf.Cos(num3) * 0.375f);
				CreatePart("BarkGroove", modelRoot, cubeMesh, grainMaterial, localPosition, new Vector3(0.045f, item2, 0.03f), new Vector3(0f, item, 0f));
			}
		}

		private Transform BuildFace(Transform modelRoot)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0069: 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_00a2: 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_00af: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0156: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_0217: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[2] { -1f, 1f };
			foreach (float num in array)
			{
				float num2 = 0.14f * num;
				CreatePart("EyeWhite", modelRoot, sphereMesh, eyeWhiteMaterial, new Vector3(num2, 1.86f, 0.35f), new Vector3(0.2f, 0.23f, 0.1f));
				CreatePart("Pupil", modelRoot, sphereMesh, darkFeatureMaterial, new Vector3(num2, 1.85f, 0.398f), new Vector3(0.075f, 0.085f, 0.03f));
				CreatePart("Eyebrow", modelRoot, cubeMesh, darkFeatureMaterial, new Vector3(num2, 2f, 0.36f), new Vector3(0.17f, 0.035f, 0.04f), new Vector3(0f, 0f, -12f * num));
				CreatePart("MouthCorner", modelRoot, cubeMesh, darkFeatureMaterial, new Vector3(0.11f * num, 1.635f, 0.358f), new Vector3(0.06f, 0.03f, 0.04f), new Vector3(0f, 0f, 30f * num));
			}
			CreatePart("Nose", modelRoot, sphereMesh, limbMaterial, new Vector3(0f, 1.74f, 0.375f), new Vector3(0.07f, 0.09f, 0.07f));
			CreatePart("Mouth", modelRoot, cubeMesh, darkFeatureMaterial, new Vector3(0f, 1.62f, 0.365f), new Vector3(0.18f, 0.035f, 0.04f));
			return CreatePivot("Eye", modelRoot, new Vector3(0f, 1.86f, 0.42f));
		}

		private Transform BuildLeg(Transform modelRoot, string legName, float sideOffset)
		{
			//IL_000e: 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_004f: 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_005c: 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_0098: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Transform val = CreatePivot(legName, modelRoot, new Vector3(sideOffset, 0.58f, 0f));
			CreatePart("Thigh", val, cylinderMesh, limbMaterial, new Vector3(0f, -0.28f, 0f), new Vector3(0.11f, 0.28f, 0.11f));
			CreatePart("Foot", val, cubeMesh, limbMaterial, new Vector3(0f, -0.555f, 0.05f), new Vector3(0.14f, 0.05f, 0.22f));
			return val;
		}

		private Transform BuildArm(Transform modelRoot, string armName, float sideOffset)
		{
			//IL_000e: 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_004f: 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_005c: 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_0098: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Transform val = CreatePivot(armName, modelRoot, new Vector3(sideOffset, 1.7f, 0f));
			CreatePart("Arm", val, cylinderMesh, limbMaterial, new Vector3(0f, -0.34f, 0f), new Vector3(0.09f, 0.34f, 0.09f));
			CreatePart("Hand", val, sphereMesh, limbMaterial, new Vector3(0f, -0.7f, 0f), new Vector3(0.12f, 0.12f, 0.12f));
			return val;
		}

		private void BuildBat(Transform batArmPivot)
		{
			//IL_0016: 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_005d: 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_0078: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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)
			Transform val = CreatePivot("Bat", batArmPivot, new Vector3(0f, -0.7f, 0f));
			val.localRotation = Quaternion.Euler(-25f, 0f, 0f);
			CreatePart("Handle", val, cylinderMesh, batMaterial, new Vector3(0f, -0.15f, 0f), new Vector3(0.045f, 0.15f, 0.045f));
			CreatePart("Barrel", val, capsuleMesh, batMaterial, new Vector3(0f, -0.62f, 0f), new Vector3(0.12f, 0.38f, 0.12f));
		}

		private Transform CreatePivot(string pivotName, Transform parent, Vector3 localPosition)
		{
			//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_0012: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(pivotName)
			{
				layer = modelLayer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			return val.transform;
		}

		private void CreatePart(string partName, Transform parent, Mesh mesh, Material material, Vector3 localPosition, Vector3 localScale, Vector3 localEulerAngles = default(Vector3))
		{
			//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_0012: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_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)
			GameObject val = new GameObject(partName)
			{
				layer = modelLayer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localRotation = Quaternion.Euler(localEulerAngles);
			val.transform.localScale = localScale;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}

		private static Mesh GetBuiltInPrimitiveMesh(PrimitiveType primitiveType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(primitiveType);
			Mesh sharedMesh = obj.GetComponent<MeshFilter>().sharedMesh;
			Object.DestroyImmediate((Object)(object)obj);
			return sharedMesh;
		}

		private static Material CreateMaterial(Shader shader, string materialName, Color baseColor, float smoothness)
		{
			//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_000d: 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_001b: 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: Expected O, but got Unknown
			Material val = new Material(shader)
			{
				name = materialName,
				hideFlags = (HideFlags)32
			};
			val.SetColor("_BaseColor", baseColor);
			val.SetFloat("_Smoothness", smoothness);
			return val;
		}
	}
	internal static class TungSahurPrefabFactory
	{
		public const string EnemyName = "Tung Tung Tung Sahur";

		private const string PrefabName = "TungTungTungSahur";

		private const float CollisionHeight = 2.2f;

		public static EnemyType CreateEnemyType(TungSahurConfig settings, TungSahurSounds sounds)
		{
			//IL_0037: 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_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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			EnemyType val = ScriptableObject.CreateInstance<EnemyType>();
			((Object)val).name = "TungTungTungSahur";
			((Object)val).hideFlags = (HideFlags)32;
			val.enemyName = "Tung Tung Tung Sahur";
			val.probabilityCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
			{
				new Keyframe(0f, 0.4f),
				new Keyframe(0.5f, 1f),
				new Keyframe(1f, 1f)
			});
			val.numberSpawnedFalloff = AnimationCurve.Constant(0f, 1f, 1f);
			val.useNumberSpawnedFalloff = false;
			val.MaxCount = settings.MaxCount.Value;
			val.PowerLevel = settings.PowerLevel.Value;
			val.isOutsideEnemy = false;
			val.isDaytimeEnemy = false;
			val.canDie = true;
			val.canBeStunned = true;
			val.canBeDestroyed = true;
			val.destroyOnDeath = false;
			val.stunTimeMultiplier = 1.5f;
			val.doorSpeedMultiplier = 1.5f;
			val.hitBodySFX = sounds.Bonk;
			val.hitEnemyVoiceSFX = sounds.Knock;
			val.stunSFX = sounds.Knock;
			val.deathSFX = sounds.Death;
			val.enemyPrefab = CreatePrefab(val, sounds);
			return val;
		}

		private static GameObject CreatePrefab(EnemyType enemyType, TungSahurSounds sounds)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//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_0139: Expected O, but got Unknown
			//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_014c: Expected O, but got Unknown
			//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_015f: Expected O, but got Unknown
			int num = RequireLayer("Enemies");
			int scanNodeLayer = RequireLayer("ScanNode");
			GameObject val = NetworkPrefabs.CreateNetworkPrefab("TungTungTungSahur");
			val.layer = num;
			NavMeshAgent obj = val.AddComponent<NavMeshAgent>();
			obj.radius = 0.45f;
			obj.height = 2.2f;
			obj.speed = 3.5f;
			obj.acceleration = 20f;
			obj.angularSpeed = 400f;
			obj.stoppingDistance = 0f;
			obj.autoBraking = false;
			obj.obstacleAvoidanceType = (ObstacleAvoidanceType)1;
			new TungSahurModelBuilder(num).Build(val, out Transform eye);
			TungSahurAI tungSahurAI = val.AddComponent<TungSahurAI>();
			((EnemyAI)tungSahurAI).enemyType = enemyType;
			((EnemyAI)tungSahurAI).eye = eye;
			((EnemyAI)tungSahurAI).creatureSFX = CreateSpatialAudioSource(val, 40f);
			((EnemyAI)tungSahurAI).creatureVoice = CreateSpatialAudioSource(((Component)eye).gameObject, 55f);
			((EnemyAI)tungSahurAI).dieSFX = sounds.Death;
			((EnemyAI)tungSahurAI).enemyHP = 4;
			((EnemyAI)tungSahurAI).AIIntervalTime = 0.2f;
			((EnemyAI)tungSahurAI).updatePositionThreshold = 0.3f;
			((EnemyAI)tungSahurAI).syncMovementSpeed = 0.22f;
			((EnemyAI)tungSahurAI).exitVentAnimationTime = 1f;
			((EnemyAI)tungSahurAI).currentSearch = new AISearchRoutine();
			((EnemyAI)tungSahurAI).enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[3]
			{
				new EnemyBehaviourState
				{
					name = "Roaming"
				},
				new EnemyBehaviourState
				{
					name = "Calling"
				},
				new EnemyBehaviourState
				{
					name = "Chasing"
				}
			};
			((EnemyAI)tungSahurAI).currentBehaviourState = ((EnemyAI)tungSahurAI).enemyBehaviourStates[0];
			CreateCollisionDetector(val, (EnemyAI)(object)tungSahurAI, num);
			CreateScanNode(val, scanNodeLayer);
			return val;
		}

		private static AudioSource CreateSpatialAudioSource(GameObject owner, float maxDistance)
		{
			AudioSource obj = owner.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.dopplerLevel = 0f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = maxDistance;
			return obj;
		}

		private static void CreateCollisionDetector(GameObject enemyRoot, EnemyAI enemyAI, int enemiesLayer)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_001c: 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_004b: 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)
			GameObject val = new GameObject("Collision")
			{
				layer = enemiesLayer,
				tag = "Enemy"
			};
			val.transform.SetParent(enemyRoot.transform, false);
			CapsuleCollider obj = val.AddComponent<CapsuleCollider>();
			((Collider)obj).isTrigger = true;
			obj.center = new Vector3(0f, 1.1f, 0f);
			obj.height = 2.2f;
			obj.radius = 0.45f;
			Rigidbody obj2 = val.AddComponent<Rigidbody>();
			obj2.isKinematic = true;
			obj2.useGravity = false;
			val.AddComponent<EnemyAICollisionDetect>().mainScript = enemyAI;
		}

		private static void CreateScanNode(GameObject enemyRoot, int scanNodeLayer)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			GameObject val = new GameObject("ScanNode")
			{
				layer = scanNodeLayer
			};
			val.transform.SetParent(enemyRoot.transform, false);
			val.transform.localPosition = new Vector3(0f, 1.4f, 0f);
			BoxCollider obj = val.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.size = Vector3.one;
			ScanNodeProperties obj2 = val.AddComponent<ScanNodeProperties>();
			obj2.headerText = "Tung Tung Tung Sahur";
			obj2.subText = "Do not ignore the call.";
			obj2.nodeType = 1;
			obj2.minRange = 1;
			obj2.maxRange = 13;
			obj2.requiresLineOfSight = true;
			obj2.creatureScanID = -1;
		}

		private static int RequireLayer(string layerName)
		{
			int num = LayerMask.NameToLayer(layerName);
			if (num < 0)
			{
				throw new InvalidOperationException("Layer '" + layerName + "' does not exist; the game version is not supported.");
			}
			return num;
		}
	}
	internal enum TungSahurPose
	{
		Wandering,
		Calling,
		Chasing,
		Stunned,
		Dead
	}
	public sealed class TungSahurRig : MonoBehaviour
	{
		private const float KnockSlamSeconds = 0.07f;

		private const float KnockRecoverSeconds = 0.43f;

		private const float SwingStrikeSeconds = 0.12f;

		private const float SwingRecoverSeconds = 0.25f;

		private const float FlinchSeconds = 0.3f;

		private const float RaisedBatAngle = -160f;

		private const float KnockImpactAngle = -15f;

		private const float WalkCycleRadiansPerMeter = 2.6f;

		private const float PoseBlendSharpness = 12f;

		public Transform modelRoot;

		public Transform leftLegPivot;

		public Transform rightLegPivot;

		public Transform leftArmPivot;

		public Transform batArmPivot;

		public float armSideSpreadDegrees = 12f;

		private float walkCyclePhase;

		private bool footstepPending;

		private float secondsSinceKnockStarted = float.MaxValue;

		private float secondsSinceSwingStarted = float.MaxValue;

		private float secondsSinceFlinchStarted = float.MaxValue;

		private float deathProgress;

		private float blendedBatArmAngle;

		private float blendedLeftArmAngle;

		private float blendedLeanAngle;

		public bool IsSwinging => secondsSinceSwingStarted < 0.37f;

		public void PlayKnock()
		{
			secondsSinceKnockStarted = 0f;
		}

		public void PlaySwing()
		{
			secondsSinceSwingStarted = 0f;
		}

		public void PlayFlinch()
		{
			secondsSinceFlinchStarted = 0f;
		}

		public bool TryConsumeFootstep()
		{
			bool result = footstepPending;
			footstepPending = false;
			return result;
		}

		internal void Tick(float horizontalSpeed, TungSahurPose pose, float deltaTime)
		{
			secondsSinceKnockStarted += deltaTime;
			secondsSinceSwingStarted += deltaTime;
			secondsSinceFlinchStarted += deltaTime;
			float blendFactor = 1f - Mathf.Exp(-12f * deltaTime);
			if (pose == TungSahurPose.Dead)
			{
				AnimateDeath(deltaTime, blendFactor);
				return;
			}
			float strideStrength = AdvanceWalkCycle(horizontalSpeed, deltaTime);
			AnimateLegs(strideStrength);
			AnimateBody(pose, strideStrength, blendFactor);
			AnimateLeftArm(pose, strideStrength, blendFactor);
			AnimateBatArm(pose, blendFactor);
		}

		private float AdvanceWalkCycle(float horizontalSpeed, float deltaTime)
		{
			float num = Mathf.Sin(walkCyclePhase);
			walkCyclePhase += horizontalSpeed * 2.6f * deltaTime;
			float num2 = Mathf.Sin(walkCyclePhase);
			if (horizontalSpeed > 0.4f && Mathf.Sign(num) != Mathf.Sign(num2))
			{
				footstepPending = true;
			}
			return Mathf.Clamp(horizontalSpeed / 3.5f, 0f, 1.3f);
		}

		private void AnimateLegs(float strideStrength)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Sin(walkCyclePhase) * 35f * strideStrength;
			leftLegPivot.localRotation = Quaternion.Euler(num, 0f, 0f);
			rightLegPivot.localRotation = Quaternion.Euler(0f - num, 0f, 0f);
		}

		private void AnimateBody(TungSahurPose pose, float strideStrength, float blendFactor)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			float num = ((pose == TungSahurPose.Chasing) ? 12f : 0f);
			blendedLeanAngle = Mathf.Lerp(blendedLeanAngle, num, blendFactor);
			float num2 = ((secondsSinceFlinchStarted < 0.3f) ? (-15f * (1f - secondsSinceFlinchStarted / 0.3f)) : 0f);
			float num3 = Mathf.Sin(walkCyclePhase) * 3f * strideStrength;
			if (pose == TungSahurPose.Stunned)
			{
				num3 += Mathf.Sin(Time.time * 40f) * 4f;
			}
			float num4 = Mathf.Abs(Mathf.Sin(walkCyclePhase)) * 0.06f * strideStrength;
			modelRoot.localPosition = new Vector3(0f, num4, 0f);
			modelRoot.localRotation = Quaternion.Euler(blendedLeanAngle + num2, 0f, num3);
		}

		private void AnimateLeftArm(TungSahurPose pose, float strideStrength, float blendFactor)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			float num = pose switch
			{
				TungSahurPose.Calling => -75f, 
				TungSahurPose.Chasing => Mathf.Sin(walkCyclePhase) * 45f - 20f, 
				TungSahurPose.Stunned => -20f, 
				_ => (0f - Mathf.Sin(walkCyclePhase)) * 25f * strideStrength, 
			};
			blendedLeftArmAngle = Mathf.Lerp(blendedLeftArmAngle, num, blendFactor);
			leftArmPivot.localRotation = Quaternion.Euler(blendedLeftArmAngle, 0f, 0f - armSideSpreadDegrees);
		}

		private void AnimateBatArm(TungSahurPose pose, float blendFactor)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			float num = pose switch
			{
				TungSahurPose.Calling => -160f, 
				TungSahurPose.Chasing => -140f + Mathf.Sin(Time.time * 10f) * 10f, 
				TungSahurPose.Stunned => -40f, 
				_ => -15f, 
			};
			blendedBatArmAngle = Mathf.Lerp(blendedBatArmAngle, num, blendFactor);
			float num2 = blendedBatArmAngle;
			if (TryGetKnockAngle(out var knockAngle))
			{
				num2 = knockAngle;
			}
			if (TryGetSwingAngle(num, out var swingAngle))
			{
				num2 = swingAngle;
			}
			batArmPivot.localRotation = Quaternion.Euler(num2, 0f, armSideSpreadDegrees);
		}

		private bool TryGetKnockAngle(out float knockAngle)
		{
			float num = secondsSinceKnockStarted;
			if (num < 0.07f)
			{
				knockAngle = Mathf.Lerp(-160f, -15f, num / 0.07f);
				return true;
			}
			if (num < 0.5f)
			{
				float num2 = Mathf.SmoothStep(0f, 1f, (num - 0.07f) / 0.43f);
				knockAngle = Mathf.Lerp(-15f, -160f, num2);
				return true;
			}
			knockAngle = 0f;
			return false;
		}

		private bool TryGetSwingAngle(float restingAngle, out float swingAngle)
		{
			float num = secondsSinceSwingStarted;
			if (num < 0.12f)
			{
				swingAngle = Mathf.Lerp(-170f, -20f, num / 0.12f);
				return true;
			}
			if (num < 0.37f)
			{
				swingAngle = Mathf.Lerp(-20f, restingAngle, (num - 0.12f) / 0.25f);
				return true;
			}
			swingAngle = 0f;
			return false;
		}

		private void AnimateDeath(float deltaTime, float blendFactor)
		{
			//IL_0055: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			deathProgress = Mathf.Min(1f, deathProgress + deltaTime / 0.6f);
			float num = 1f - (1f - deathProgress) * (1f - deathProgress);
			modelRoot.localRotation = Quaternion.Euler(-90f * num, 0f, 0f);
			modelRoot.localPosition = new Vector3(0f, 0.35f * num, 0f);
			blendedBatArmAngle = Mathf.Lerp(blendedBatArmAngle, -10f, blendFactor);
			blendedLeftArmAngle = Mathf.Lerp(blendedLeftArmAngle, -10f, blendFactor);
			batArmPivot.localRotation = Quaternion.Euler(blendedBatArmAngle, 0f, armSideSpreadDegrees * 3f);
			leftArmPivot.localRotation = Quaternion.Euler(blendedLeftArmAngle, 0f, (0f - armSideSpreadDegrees) * 3f);
			leftLegPivot.localRotation = Quaternion.identity;
			rightLegPivot.localRotation = Quaternion.identity;
		}
	}
}
namespace TungTungTungSahur.Audio
{
	internal sealed class TungSahurSounds
	{
		private sealed class CustomSoundLoader
		{
			private readonly string customSoundsDirectory;

			private readonly ManualLogSource logger;

			public CustomSoundLoader(string customSoundsDirectory, ManualLogSource logger)
			{
				this.customSoundsDirectory = customSoundsDirectory;
				this.logger = logger;
			}

			public AudioClip? TryLoad(string soundName)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				(string, AudioType)[] supportedCustomSoundFormats = SupportedCustomSoundFormats;
				for (int i = 0; i < supportedCustomSoundFormats.Length; i++)
				{
					(string, AudioType) tuple = supportedCustomSoundFormats[i];
					string item = tuple.Item1;
					AudioType item2 = tuple.Item2;
					string text = Path.Combine(customSoundsDirectory, soundName + item);
					if (File.Exists(text))
					{
						return LoadClip(text, item2);
					}
				}
				return null;
			}

			private AudioClip? LoadClip(string soundFilePath, AudioType audioType)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Invalid comparison between Unknown and I4
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(new Uri(soundFilePath).AbsoluteUri, audioType);
				try
				{
					UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
					Stopwatch stopwatch = Stopwatch.StartNew();
					while (!((AsyncOperation)val).isDone)
					{
						if (stopwatch.Elapsed > CustomSoundLoadTimeout)
						{
							logger.LogWarning((object)("Timed out loading custom sound '" + soundFilePath + "', using the built-in sound instead."));
							return null;
						}
					}
					if ((int)audioClip.result != 1)
					{
						logger.LogWarning((object)("Could not load custom sound '" + soundFilePath + "' (" + audioClip.error + "), using the built-in sound instead."));
						return null;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
					((Object)content).name = "TungSahur_Custom_" + Path.GetFileNameWithoutExtension(soundFilePath);
					((Object)content).hideFlags = (HideFlags)32;
					logger.LogInfo((object)("Loaded custom sound '" + Path.GetFileName(soundFilePath) + "'."));
					return content;
				}
				finally
				{
					((IDisposable)audioClip)?.Dispose();
				}
			}
		}

		private static readonly TimeSpan CustomSoundLoadTimeout = TimeSpan.FromSeconds(10.0);

		private static readonly (string Extension, AudioType Type)[] SupportedCustomSoundFormats = new(string, AudioType)[3]
		{
			(".ogg", (AudioType)14),
			(".wav", (AudioType)20),
			(".mp3", (AudioType)13)
		};

		public AudioClip Knock { get; }

		public AudioClip Footstep { get; }

		public AudioClip Bonk { get; }

		public AudioClip ChaseCall { get; }

		public AudioClip Death { get; }

		public AudioClip? CallVoice { get; }

		private TungSahurSounds(AudioClip knock, AudioClip footstep, AudioClip bonk, AudioClip chaseCall, AudioClip death, AudioClip? callVoice)
		{
			Knock = knock;
			Footstep = footstep;
			Bonk = bonk;
			ChaseCall = chaseCall;
			Death = death;
			CallVoice = callVoice;
		}

		public static TungSahurSounds Load(string customSoundsDirectory, ManualLogSource logger)
		{
			Directory.CreateDirectory(customSoundsDirectory);
			CustomSoundLoader customSoundLoader = new CustomSoundLoader(customSoundsDirectory, logger);
			return new TungSahurSounds(customSoundLoader.TryLoad("knock") ?? WoodSoundSynthesizer.CreateKnock(), customSoundLoader.TryLoad("footstep") ?? WoodSoundSynthesizer.CreateFootstep(), customSoundLoader.TryLoad("bonk") ?? WoodSoundSynthesizer.CreateBonk(), customSoundLoader.TryLoad("chase") ?? WoodSoundSynthesizer.CreateChaseCall(), customSoundLoader.TryLoad("death") ?? WoodSoundSynthesizer.CreateDeath(), customSoundLoader.TryLoad("call"));
		}
	}
	internal static class VanillaAudioMixerLookup
	{
		private static AudioMixerGroup? cachedEnemySfxMixerGroup;

		public static AudioMixerGroup? FindEnemySfxMixerGroup()
		{
			if ((Object)(object)cachedEnemySfxMixerGroup != (Object)null)
			{
				return cachedEnemySfxMixerGroup;
			}
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return null;
			}
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			for (int i = 0; i < levels.Length; i++)
			{
				foreach (SpawnableEnemyWithRarity enemy in levels[i].Enemies)
				{
					GameObject val = enemy.enemyType?.enemyPrefab;
					EnemyAI val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<EnemyAI>() : null);
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2.creatureSFX != (Object)null && (Object)(object)val2.creatureSFX.outputAudioMixerGroup != (Object)null)
					{
						cachedEnemySfxMixerGroup = val2.creatureSFX.outputAudioMixerGroup;
						return cachedEnemySfxMixerGroup;
					}
				}
			}
			return null;
		}
	}
	internal static class WoodSoundSynthesizer
	{
		private const int SampleRate = 44100;

		private const float PeakAmplitude = 0.9f;

		public static AudioClip CreateKnock()
		{
			return ToClip("TungSahur_Knock", SynthesizeWoodHit(185f, 0.5f, 9f, 0.18f, 0.5f, 1));
		}

		public static AudioClip CreateFootstep()
		{
			return ToClip("TungSahur_Footstep", SynthesizeWoodHit(430f, 0.14f, 40f, 0.1f, 0.35f, 2));
		}

		public static AudioClip CreateBonk()
		{
			float[] array = SynthesizeWoodHit(105f, 0.45f, 12f, 0.6f, 0.9f, 3);
			MixInto(array, SynthesizeWoodHit(160f, 0.3f, 16f, 0.3f, 0.2f, 4), 0, 0.6f);
			Normalize(array);
			return ToClip("TungSahur_Bonk", array);
		}

		public static AudioClip CreateChaseCall()
		{
			float[] array = new float[SecondsToSamples(1.5f)];
			float[] array2 = new float[6] { 0f, 0.14f, 0.26f, 0.36f, 0.44f, 0.5f };
			for (int i = 0; i < array2.Length; i++)
			{
				float num = (float)i / (float)(array2.Length - 1);
				float[] source = SynthesizeWoodHit(Mathf.Lerp(185f, 245f, num), 0.4f, 11f, 0.18f, 0.5f, 10 + i);
				MixInto(array, source, SecondsToSamples(array2[i]), Mathf.Lerp(0.6f, 0.9f, num));
			}
			MixInto(array, SynthesizeWoodHit(120f, 0.85f, 6f, 0.45f, 0.8f, 20), SecondsToSamples(0.62f), 1.2f);
			Normalize(array);
			return ToClip("TungSahur_ChaseCall", array);
		}

		public static AudioClip CreateDeath()
		{
			return ToClip("TungSahur_Death", SynthesizeWoodHit(80f, 1.4f, 3.5f, 0.5f, 0.6f, 5));
		}

		private static float[] SynthesizeWoodHit(float fundamentalHz, float durationSeconds, float bodyDecayPerSecond, float pitchDropAmount, float transientLoudness, int noiseSeed)
		{
			float[] array = new float[SecondsToSamples(durationSeconds)];
			Random random = new Random(noiseSeed);
			double num = 0.0;
			for (int i = 0; i < array.Length; i++)
			{
				double num2 = (double)i / 44100.0;
				double num3 = (double)fundamentalHz * (1.0 + (double)pitchDropAmount * Math.Exp((0.0 - num2) * 35.0));
				num += Math.PI * 2.0 * num3 / 44100.0;
				double num4 = Math.Sin(num) * Math.Exp((0.0 - num2) * (double)bodyDecayPerSecond) + 0.45 * Math.Sin(num * 2.76) * Math.Exp((0.0 - num2) * (double)bodyDecayPerSecond * 2.0) + 0.22 * Math.Sin(num * 5.4) * Math.Exp((0.0 - num2) * (double)bodyDecayPerSecond * 3.4);
				double num5 = (double)transientLoudness * (random.NextDouble() * 2.0 - 1.0) * Math.Exp((0.0 - num2) * 500.0);
				double num6 = Math.Min(1.0, (double)i / 40.0);
				array[i] = (float)((num4 + num5) * num6);
			}
			Normalize(array);
			return array;
		}

		private static void MixInto(float[] destination, float[] source, int offsetSamples, float gain)
		{
			int num = Math.Min(source.Length, destination.Length - offsetSamples);
			for (int i = 0; i < num; i++)
			{
				destination[offsetSamples + i] += source[i] * gain;
			}
		}

		private static void Normalize(float[] samples)
		{
			float num = 0f;
			foreach (float value in samples)
			{
				num = Math.Max(num, Math.Abs(value));
			}
			if (!(num <= 0f))
			{
				float num2 = 0.9f / num;
				for (int j = 0; j < samples.Length; j++)
				{
					samples[j] *= num2;
				}
			}
		}

		private static int SecondsToSamples(float seconds)
		{
			return Mathf.CeilToInt(seconds * 44100f);
		}

		private static AudioClip ToClip(string clipName, float[] samples)
		{
			AudioClip obj = AudioClip.Create(clipName, samples.Length, 1, 44100, false);
			if (!obj.SetData(samples, 0))
			{
				throw new InvalidOperationException("Unity rejected the synthesized samples for '" + clipName + "'.");
			}
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
}