Decompiled source of TootForTat v1.0.0

TootForTat.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json.Linq;
using TootForTat.Annoyance;
using TootForTat.DebugTools;
using TootForTat.Haunting;
using TootForTat.Net;
using TootForTat.Trumpet;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[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("TootForTat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+04667e1f47ff8df5e36fed854146151e6510b989")]
[assembly: AssemblyProduct("TootForTat")]
[assembly: AssemblyTitle("TootForTat")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TootForTat
{
	[BepInPlugin("TootForTat", "TootForTat", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "TootForTat";

		public const string Name = "TootForTat";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static PluginConfig Cfg;

		internal static string PluginDir;

		private void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Cfg = new PluginConfig(((BaseUnityPlugin)this).Config);
			new Harmony("TootForTat").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"TootForTat 1.0.0 loaded. Toot responsibly.");
		}
	}
	internal sealed class PluginConfig
	{
		public readonly ConfigEntry<string> ItemWeights;

		public readonly ConfigEntry<float> ListenerRadius;

		public readonly ConfigEntry<bool> RequireSameArea;

		public readonly ConfigEntry<float> ExtraListenerFactor;

		public readonly ConfigEntry<float> MaxListenerMultiplier;

		public readonly ConfigEntry<float> MinSecondsBetweenCountedHonks;

		public readonly ConfigEntry<float> MarkThreshold;

		public readonly ConfigEntry<float> KillThreshold;

		public readonly ConfigEntry<float> ThresholdReductionPerPunishment;

		public readonly ConfigEntry<float> PassiveDecayPerMinute;

		public readonly ConfigEntry<float> PassiveDecayDelaySeconds;

		public readonly ConfigEntry<float> RoundEndKeepFactor;

		public readonly ConfigEntry<float> DeathKeepFactor;

		public readonly ConfigEntry<float> AloneRadius;

		public readonly ConfigEntry<float> FirstHauntDelaySeconds;

		public readonly ConfigEntry<int> Stage2AfterHaunts;

		public readonly ConfigEntry<int> Stage3AfterHaunts;

		public readonly ConfigEntry<float> Stage1CooldownMin;

		public readonly ConfigEntry<float> Stage1CooldownMax;

		public readonly ConfigEntry<float> Stage2CooldownMin;

		public readonly ConfigEntry<float> Stage2CooldownMax;

		public readonly ConfigEntry<float> Stage3CooldownMin;

		public readonly ConfigEntry<float> Stage3CooldownMax;

		public readonly ConfigEntry<int> AttractEnemiesFromStage;

		public readonly ConfigEntry<float> AttributionWindowSeconds;

		public readonly ConfigEntry<int> HauntsBeforeKill;

		public readonly ConfigEntry<float> KillChance;

		public readonly ConfigEntry<bool> AllowKillInShip;

		public readonly ConfigEntry<float> TrumpetScale;

		public readonly ConfigEntry<float> KillTrumpetScale;

		public readonly ConfigEntry<float> CorpseTrumpetSize;

		public readonly ConfigEntry<float> CorpseTrumpetLength;

		public readonly ConfigEntry<float> CorpseTrumpetHeight;

		public readonly ConfigEntry<float> Volume;

		public readonly ConfigEntry<float> MetalBoost;

		public readonly ConfigEntry<float> BlowShaftStretch;

		public readonly ConfigEntry<float> BlowBellGrow;

		public readonly ConfigEntry<bool> CorpseToots;

		public readonly ConfigEntry<bool> DebugEnabled;

		public readonly ConfigEntry<bool> CountSelfAsListener;

		public readonly ConfigEntry<bool> IgnoreAloneCheck;

		public readonly ConfigEntry<bool> LogGameInfo;

		private Dictionary<string, float> _weights;

		public PluginConfig(ConfigFile cfg)
		{
			ItemWeights = cfg.Bind<string>("Scoring", "ItemWeights", "Airhorn:1.0, Clown horn:0.7", "Items that count as annoying, as 'Item name:points per honk', comma separated. Only noisemaker items (horns etc.) are detected.");
			ListenerRadius = cfg.Bind<float>("Scoring", "ListenerRadius", 18f, "Other players within this distance (m) count as annoyed listeners.");
			RequireSameArea = cfg.Bind<bool>("Scoring", "RequireSameArea", true, "Listeners must be in the same area as the honker (both inside the facility or both outside).");
			ExtraListenerFactor = cfg.Bind<float>("Scoring", "ExtraListenerFactor", 0.2f, "Each listener beyond the first adds this much to the multiplier (2 listeners = 1.2x).");
			MaxListenerMultiplier = cfg.Bind<float>("Scoring", "MaxListenerMultiplier", 2f, "Upper limit for the listener multiplier.");
			MinSecondsBetweenCountedHonks = cfg.Bind<float>("Scoring", "MinSecondsBetweenCountedHonks", 0.3f, "Honks faster than this are not counted (anti macro spam).");
			MarkThreshold = cfg.Bind<float>("Scoring", "MarkThreshold", 12f, "Score at which a player gets marked: trumpets haunt them whenever they are alone. Marked scores no longer decay, but still grow.");
			KillThreshold = cfg.Bind<float>("Scoring", "KillThreshold", 30f, "Score at which the final trumpet comes immediately, even with others watching. 0 = never (only the haunting can end in the kill).");
			ThresholdReductionPerPunishment = cfg.Bind<float>("Scoring", "ThresholdReductionPerPunishment", 0f, "Repeat offenders: both thresholds shrink by this fraction per past punishment (0.1 = 10% lower each time).");
			PassiveDecayPerMinute = cfg.Bind<float>("Decay", "PassiveDecayPerMinute", 0.5f, "Score lost per minute while not honking (unmarked players only).");
			PassiveDecayDelaySeconds = cfg.Bind<float>("Decay", "PassiveDecayDelaySeconds", 120f, "Passive decay only starts this many seconds after the last counted honk.");
			RoundEndKeepFactor = cfg.Bind<float>("Decay", "RoundEndKeepFactor", 0.8f, "At the end of each round the score is multiplied by this (unmarked players only).");
			DeathKeepFactor = cfg.Bind<float>("Decay", "DeathKeepFactor", 0.85f, "When a player dies the score is multiplied by this (unmarked players only).");
			AloneRadius = cfg.Bind<float>("Haunting", "AloneRadius", 25f, "A marked player is only haunted when no other living player is within this distance (m).");
			FirstHauntDelaySeconds = cfg.Bind<float>("Haunting", "FirstHauntDelaySeconds", 30f, "Minimum delay after landing or getting marked before the first haunt.");
			Stage2AfterHaunts = cfg.Bind<int>("Haunting", "Stage2AfterHaunts", 4, "Haunts before trumpets come closer (stage 2).");
			Stage3AfterHaunts = cfg.Bind<int>("Haunting", "Stage3AfterHaunts", 8, "Haunts before trumpets get in your face (stage 3).");
			Stage1CooldownMin = cfg.Bind<float>("Haunting", "Stage1CooldownMin", 120f, "Seconds between haunts in stage 1 (min).");
			Stage1CooldownMax = cfg.Bind<float>("Haunting", "Stage1CooldownMax", 240f, "Seconds between haunts in stage 1 (max).");
			Stage2CooldownMin = cfg.Bind<float>("Haunting", "Stage2CooldownMin", 75f, "Seconds between haunts in stage 2 (min).");
			Stage2CooldownMax = cfg.Bind<float>("Haunting", "Stage2CooldownMax", 150f, "Seconds between haunts in stage 2 (max).");
			Stage3CooldownMin = cfg.Bind<float>("Haunting", "Stage3CooldownMin", 45f, "Seconds between haunts in stage 3 (min).");
			Stage3CooldownMax = cfg.Bind<float>("Haunting", "Stage3CooldownMax", 90f, "Seconds between haunts in stage 3 (max).");
			AttractEnemiesFromStage = cfg.Bind<int>("Haunting", "AttractEnemiesFromStage", 2, "From this stage on, trumpet blasts are audible to enemies. 0 = never.");
			AttributionWindowSeconds = cfg.Bind<float>("Haunting", "AttributionWindowSeconds", 25f, "If a marked player dies (from anything) within this many seconds after a haunt, the punishment counts as done.");
			HauntsBeforeKill = cfg.Bind<int>("Kill", "HauntsBeforeKill", 10, "Haunts a marked player must survive before the final trumpet can come.");
			KillChance = cfg.Bind<float>("Kill", "KillChance", 0.35f, "Once eligible, chance that a haunt opportunity becomes the kill instead.");
			AllowKillInShip = cfg.Bind<bool>("Kill", "AllowKillInShip", false, "Allow the kill while the player is inside the ship.");
			TrumpetScale = cfg.Bind<float>("Trumpet", "TrumpetScale", 4f, "Size of haunting trumpets (model is 0.58 m long at scale 1).");
			KillTrumpetScale = cfg.Bind<float>("Trumpet", "KillTrumpetScale", 5.5f, "Size of the trumpet that eats your head.");
			CorpseTrumpetSize = cfg.Bind<float>("Trumpet", "CorpseTrumpetSize", 1.8f, "Size of the trumpet that replaces the corpse's head, sitting on the neck with its bell (1 = 16 cm wide bell).");
			CorpseTrumpetLength = cfg.Bind<float>("Trumpet", "CorpseTrumpetLength", 0.5f, "Length of the corpse trumpet behind its bell, relative (1 = normal proportions, 0.5 = half as long). The bell keeps its shape.");
			CorpseTrumpetHeight = cfg.Bind<float>("Trumpet", "CorpseTrumpetHeight", 0f, "Moves the corpse trumpet along the neck, in metres: positive = further out, negative = deeper in. 0 = where the head was.");
			Volume = cfg.Bind<float>("Trumpet", "Volume", 1f, "Local volume multiplier for trumpet sounds (client side).");
			MetalBoost = cfg.Bind<float>("Trumpet", "MetalBoost", 0.5f, "Extra shininess for the metal parts (0 = model values).");
			BlowShaftStretch = cfg.Bind<float>("Trumpet", "BlowShaftStretch", 0.35f, "While blasting, the pipe into the bell grows by this fraction of the trumpet's length.");
			BlowBellGrow = cfg.Bind<float>("Trumpet", "BlowBellGrow", 0.6f, "While blasting, the bell gets this much wider (0.6 = +60%).");
			CorpseToots = cfg.Bind<bool>("Trumpet", "CorpseToots", true, "Trumpet corpses toot quietly when picked up or dropped.");
			DebugEnabled = cfg.Bind<bool>("Debug", "Enabled", false, "Host only: verbose logging and debug hotkeys (F5-F10, see the README). Leave off when playing for real.");
			CountSelfAsListener = cfg.Bind<bool>("Debug", "CountSelfAsListener", false, "Count yourself as a listener, so scoring can be tested alone.");
			IgnoreAloneCheck = cfg.Bind<bool>("Debug", "IgnoreAloneCheck", false, "Haunt even when other players are nearby.");
			LogGameInfo = cfg.Bind<bool>("Debug", "LogGameInfo", false, "Log ragdoll and item details on startup (for development).");
			ItemWeights.SettingChanged += delegate
			{
				_weights = null;
			};
		}

		public float WeightFor(string itemName)
		{
			if (_weights == null)
			{
				_weights = ParseWeights(ItemWeights.Value);
			}
			if (itemName == null || !_weights.TryGetValue(itemName.Trim(), out var value))
			{
				return 0f;
			}
			return value;
		}

		internal static Dictionary<string, float> ParseWeights(string raw)
		{
			Dictionary<string, float> dictionary = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase);
			string[] array = (raw ?? "").Split(',');
			foreach (string text in array)
			{
				int num = text.LastIndexOf(':');
				if (num > 0)
				{
					string text2 = text.Substring(0, num).Trim();
					if (float.TryParse(text.Substring(num + 1).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && text2.Length > 0)
					{
						dictionary[text2] = result;
					}
				}
			}
			return dictionary;
		}
	}
	internal sealed class TootClient : MonoBehaviour
	{
		private const string SpawnUp = "SpawnUp";

		private const string SpawnDown = "SpawnDown";

		private const string EventUp = "EventUp";

		private const string EventDown = "EventDown";

		private const string DeclineUp = "DeclineUp";

		private void Start()
		{
			NetChannel.Register("Haunt", OnHauntRequest);
			NetChannel.Register("SpawnDown", delegate(ulong sender, FastBufferReader r)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				if (sender == 0L)
				{
					TrumpetSpawner.Spawn(TrumpetSpawn.Read(r), isOrigin: false);
				}
			});
			NetChannel.Register("EventDown", delegate(ulong sender, FastBufferReader r)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				if (sender == 0L)
				{
					TrumpetSpawner.OnEvent(TrumpetEvent.Read(r));
				}
			});
			if (NetChannel.IsServer)
			{
				NetChannel.Register("SpawnUp", ServerOnSpawnUp);
				NetChannel.Register("EventUp", ServerOnEventUp);
				NetChannel.Register("DeclineUp", ServerOnDeclineUp);
			}
			TrumpetSpawner.SendEvent = delegate(TrumpetEvent e)
			{
				NetChannel.SendToServer("EventUp", delegate(ref FastBufferWriter w)
				{
					e.Write(ref w);
				});
			};
		}

		private void Update()
		{
			VictimLock.Tick();
		}

		private void OnDestroy()
		{
			VictimLock.Release();
			NetChannel.UnregisterAll();
			TrumpetSpawner.Clear();
			TrumpetSpawner.SendEvent = null;
		}

		private static void OnHauntRequest(ulong sender, FastBufferReader r)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if (sender != 0L)
			{
				return;
			}
			HauntRequest req = HauntRequest.Read(r);
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if ((Object)(object)val == (Object)null || val.isPlayerDead)
			{
				return;
			}
			string declineReason;
			List<TrumpetSpawn> list = HauntPlanner.Plan(req, val, out declineReason);
			if (declineReason != null)
			{
				Plugin.Log.LogDebug((object)$"Not now ({req.type}): {declineReason}.");
				HauntDecline d = new HauntDecline
				{
					hauntId = req.hauntId,
					player = (byte)val.playerClientId,
					reason = declineReason
				};
				NetChannel.SendToServer("DeclineUp", delegate(ref FastBufferWriter w)
				{
					d.Write(ref w);
				});
				return;
			}
			foreach (TrumpetSpawn item in list)
			{
				TrumpetSpawner.Spawn(item, isOrigin: true);
				TrumpetSpawn s = item;
				NetChannel.SendToServer("SpawnUp", delegate(ref FastBufferWriter w)
				{
					s.Write(ref w);
				});
			}
		}

		private static void ServerOnSpawnUp(ulong sender, FastBufferReader r)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			TrumpetSpawn msg = TrumpetSpawn.Read(r);
			PlayerControllerB val = PlayerOwnedBy(msg.player, sender);
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)TootHost.Instance != (Object)null)
				{
					TootHost.Instance.Director.OnSpawnReported(val, msg);
				}
				NetChannel.SendToAllExcept("SpawnDown", sender, delegate(ref FastBufferWriter w)
				{
					msg.Write(ref w);
				});
			}
		}

		private static void ServerOnEventUp(ulong sender, FastBufferReader r)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			TrumpetEvent msg = TrumpetEvent.Read(r);
			if (!((Object)(object)PlayerOwnedBy(msg.player, sender) == (Object)null))
			{
				NetChannel.SendToAllExcept("EventDown", sender, delegate(ref FastBufferWriter w)
				{
					msg.Write(ref w);
				});
			}
		}

		private static void ServerOnDeclineUp(ulong sender, FastBufferReader r)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			HauntDecline hauntDecline = HauntDecline.Read(r);
			PlayerControllerB val = PlayerOwnedBy(hauntDecline.player, sender);
			if ((Object)(object)val != (Object)null && (Object)(object)TootHost.Instance != (Object)null)
			{
				TootHost.Instance.Director.OnDeclined(val, hauntDecline.hauntId, hauntDecline.reason);
			}
		}

		private static PlayerControllerB PlayerOwnedBy(byte index, ulong clientId)
		{
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array == null || index >= array.Length)
			{
				return null;
			}
			PlayerControllerB val = array[index];
			if ((Object)(object)val == (Object)null || val.actualClientId != clientId)
			{
				Plugin.Log.LogWarning((object)$"Ignoring trumpet message for player {index} from client {clientId}.");
				return null;
			}
			return val;
		}
	}
	internal sealed class TootHost : MonoBehaviour
	{
		private bool[] _wasDead = new bool[0];

		private float _decayTimer;

		private float _directorTimer;

		public static TootHost Instance { get; private set; }

		public AnnoyanceService Annoyance { get; private set; }

		public HauntDirector Director { get; private set; }

		private void Awake()
		{
			Instance = this;
			Annoyance = new AnnoyanceService(SaveStore.Load());
			Director = new HauntDirector(Annoyance);
			Plugin.Log.LogInfo((object)"TootHost ready (this machine is the host).");
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Update()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.allPlayerScripts != null)
			{
				PollDeaths(instance.allPlayerScripts);
				_decayTimer += Time.deltaTime;
				if (_decayTimer >= 1f)
				{
					Annoyance.TickDecay(_decayTimer);
					_decayTimer = 0f;
				}
				_directorTimer += Time.deltaTime;
				if (_directorTimer >= 0.5f)
				{
					_directorTimer = 0f;
					Director.Tick();
				}
				if (Plugin.Cfg.DebugEnabled.Value)
				{
					DebugKeys.Poll(this);
				}
			}
		}

		private void PollDeaths(PlayerControllerB[] players)
		{
			if (_wasDead.Length != players.Length)
			{
				_wasDead = new bool[players.Length];
				for (int i = 0; i < players.Length; i++)
				{
					_wasDead[i] = (Object)(object)players[i] != (Object)null && players[i].isPlayerDead;
				}
				return;
			}
			for (int j = 0; j < players.Length; j++)
			{
				PlayerControllerB val = players[j];
				bool flag = (Object)(object)val != (Object)null && val.isPlayerDead;
				if (flag && !_wasDead[j])
				{
					OnPlayerDied(val);
				}
				_wasDead[j] = flag;
			}
		}

		private void OnPlayerDied(PlayerControllerB p)
		{
			PlayerRecord playerRecord = Annoyance.Get(p);
			if (playerRecord.marked)
			{
				Director.OnMarkedPlayerDied(p, playerRecord);
			}
			else
			{
				Annoyance.OnUnmarkedPlayerDied(p, playerRecord);
			}
		}

		public void OnRoundEnd()
		{
			Annoyance.OnRoundEnd();
		}

		public void Save()
		{
			SaveStore.Save(Annoyance.Data);
		}
	}
}
namespace TootForTat.Trumpet
{
	internal sealed class CorpseTrumpet : MonoBehaviour
	{
		private const float Stiffness = 140f;

		private const float Damping = 5f;

		private const float Inertia = 55f;

		private const float MaxAngle = 40f;

		private const float NeckInBell = 0.02f;

		private const float TeleportDistance = 2f;

		private DeadBodyInfo _body;

		private Transform _bone;

		private Vector3 _localPos;

		private Quaternion _localRot;

		private TrumpetBehaviour _tb;

		private Vector2 _angle;

		private Vector2 _angVel;

		private Vector3 _lastPos;

		private Vector3 _lastVel;

		private int _frames;

		private bool _wasHeld;

		private float _nextToot;

		private readonly Random _rng = new Random();

		public static CorpseTrumpet Attach(DeadBodyInfo body, float size, float length, Vector3 blastVelocity)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00cb: 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_00d5: 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_0064: 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_006e: 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_00ef: 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_0103: 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_0085: 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_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_0099: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_013d: 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_0168: 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)
			//IL_016e: 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)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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_01ff: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: 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_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)body).transform;
			Transform val = Find(transform, "spine.004");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Corpse has no neck bone (spine.004), so no trumpet head.");
				return null;
			}
			Transform val2 = Find(transform, "springBone");
			Transform val3 = Find(transform, "springBone.002_end");
			Vector3 val4;
			Vector3 position;
			Vector3 val5;
			if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null)
			{
				val4 = val3.position - val2.position;
				if (((Vector3)(ref val4)).sqrMagnitude > 1E-06f)
				{
					position = val2.position;
					val4 = val3.position - val2.position;
					val5 = ((Vector3)(ref val4)).normalized;
					goto IL_0109;
				}
			}
			Transform val6 = Find(val, "spine.004_end");
			position = val.position;
			Vector3 val7;
			if ((Object)(object)val6 != (Object)null)
			{
				val4 = val6.position - val.position;
				if (((Vector3)(ref val4)).sqrMagnitude > 1E-06f)
				{
					val4 = val6.position - val.position;
					val7 = ((Vector3)(ref val4)).normalized;
					goto IL_0108;
				}
			}
			val7 = val.up;
			goto IL_0108;
			IL_0109:
			if ((Object)(object)val.parent != (Object)null)
			{
				Vector3 val8 = val.position - val.parent.position;
				if (((Vector3)(ref val8)).sqrMagnitude > 1E-06f && Vector3.Dot(val5, val8) < 0f)
				{
					if ((Object)(object)val3 != (Object)null && (Object)(object)val2 != (Object)null)
					{
						position = val3.position;
					}
					val5 = -val5;
				}
			}
			SkinnedMeshRenderer[] componentsInChildren = ((Component)transform).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val9 in componentsInChildren)
			{
				if (((Object)val9).name.StartsWith("Spring"))
				{
					((Renderer)val9).enabled = false;
				}
			}
			body.playAudioOnDeath = null;
			if (body.detachedHead)
			{
				Vector3 val10 = ((((Vector3)(ref blastVelocity)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref blastVelocity)).normalized : Vector3.up);
				float num = Mathf.Max(((Vector3)(ref body.detachedHeadVelocity)).magnitude, 0.03f);
				Plugin.Log.LogDebug((object)$"Corpse head velocity {body.detachedHeadVelocity} -> push {val10} x {num}");
				val4 = val10 + Vector3.up * 0.4f;
				body.detachedHeadVelocity = ((Vector3)(ref val4)).normalized * num;
			}
			ScanNodeProperties componentInChildren = ((Component)body).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.subText = "Cause of death: Tooted";
			}
			Vector3 val11 = Vector3.ProjectOnPlane(transform.forward, val5);
			if (((Vector3)(ref val11)).sqrMagnitude < 0.0001f)
			{
				val11 = Vector3.ProjectOnPlane(Vector3.up, val5);
			}
			Quaternion val12 = Quaternion.LookRotation(val5, ((Vector3)(ref val11)).normalized);
			GameObject val13 = new GameObject("TootForTat_CorpseTrumpet");
			val13.transform.SetParent(transform, false);
			val13.transform.localScale = Vector3.one / Mathf.Max(0.01f, Mathf.Abs(transform.lossyScale.x));
			val13.transform.SetPositionAndRotation(position, val12);
			TrumpetBehaviour trumpetBehaviour = TrumpetFactory.Create(position, val12, size, val13.transform);
			if ((Object)(object)trumpetBehaviour == (Object)null)
			{
				Object.Destroy((Object)(object)val13);
				return null;
			}
			trumpetBehaviour.LengthFactor = Mathf.Clamp(length, 0.2f, 2f);
			float num2 = HeadBottom(body, position, val5, size) + Plugin.Cfg.CorpseTrumpetHeight.Value;
			((Component)trumpetBehaviour).transform.localPosition = new Vector3(0f, 0f, num2);
			((Component)trumpetBehaviour).transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			trumpetBehaviour.UseLocalPose();
			((MonoBehaviour)trumpetBehaviour).StartCoroutine(trumpetBehaviour.PopIn(0.3f));
			CorpseTrumpet corpseTrumpet = val13.AddComponent<CorpseTrumpet>();
			corpseTrumpet._body = body;
			corpseTrumpet._bone = val;
			corpseTrumpet._tb = trumpetBehaviour;
			corpseTrumpet._localPos = Quaternion.Inverse(val.rotation) * (position - val.position);
			corpseTrumpet._localRot = Quaternion.Inverse(val.rotation) * val12;
			corpseTrumpet.Kick(320f);
			return corpseTrumpet;
			IL_0108:
			val5 = val7;
			goto IL_0109;
		}

		private static float HeadBottom(DeadBodyInfo body, Vector3 neck, Vector3 dir, float size)
		{
			//IL_0034: 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_002b: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0083: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00be: 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_00c2: 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)
			float result = 0.02f * size;
			Transform detachedHeadObject = body.detachedHeadObject;
			if ((Object)(object)detachedHeadObject == (Object)null)
			{
				return result;
			}
			SphereCollider component = ((Component)detachedHeadObject).GetComponent<SphereCollider>();
			Vector3 val = (((Object)(object)component != (Object)null) ? detachedHeadObject.TransformPoint(component.center) : detachedHeadObject.position);
			Vector3 lossyScale = detachedHeadObject.lossyScale;
			float num = (((Object)(object)component != (Object)null) ? (component.radius * Mathf.Max(new float[3]
			{
				Mathf.Abs(lossyScale.x),
				Mathf.Abs(lossyScale.y),
				Mathf.Abs(lossyScale.z)
			})) : 0.12f);
			float num2 = Vector3.Dot(val - neck, dir);
			float num3 = Mathf.Clamp(num2 - num, -0.05f, 0.25f);
			float num4 = Vector3.Distance(val, neck + dir * num2);
			if (Plugin.Cfg.DebugEnabled.Value)
			{
				Plugin.Log.LogInfo((object)$"[Debug] Corpse head: centre {num2:0.000} m along the neck ({num4:0.000} m off axis), radius {num:0.000} m -> bell opening at {num3:0.000} m");
			}
			return num3;
		}

		private void LateUpdate()
		{
			//IL_0026: 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_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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_005d: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_0072: 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_00a5: 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)
			//IL_00ac: 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_009e: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0170: 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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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_0193: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_bone == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float deltaTime = Time.deltaTime;
			Vector3 val = _bone.position + _bone.rotation * _localPos;
			Quaternion val2 = _bone.rotation * _localRot;
			if (deltaTime > 1E-05f)
			{
				if (_frames > 0)
				{
					Vector3 val3 = val - _lastPos;
					if (((Vector3)(ref val3)).sqrMagnitude > 4f)
					{
						_frames = 0;
					}
				}
				Vector3 val4 = ((_frames > 0) ? ((val - _lastPos) / deltaTime) : Vector3.zero);
				if (_frames >= 2)
				{
					Vector3 val5 = Vector3.ClampMagnitude((val4 - _lastVel) / deltaTime - Physics.gravity, 80f);
					Vector3 val6 = Quaternion.Inverse(val2) * val5;
					_angVel.x += val6.y * 55f * deltaTime;
					_angVel.y -= val6.x * 55f * deltaTime;
				}
				_lastVel = val4;
				_frames++;
				_angVel += (-140f * _angle - 5f * _angVel) * deltaTime;
				_angle = Vector2.ClampMagnitude(_angle + _angVel * deltaTime, 40f);
			}
			_lastPos = val;
			((Component)this).transform.SetPositionAndRotation(val, val2 * Quaternion.Euler(_angle.x, _angle.y, 0f));
			UpdateToots();
		}

		private void Kick(float degreesPerSecond)
		{
			//IL_001b: 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_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)
			float num = (float)_rng.NextDouble() * (float)Math.PI * 2f;
			_angVel += new Vector2(Mathf.Cos(num), Mathf.Sin(num)) * degreesPerSecond;
		}

		private void UpdateToots()
		{
			if ((Object)(object)_body == (Object)null || (Object)(object)_tb == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)_body.attachedTo != (Object)null;
			if (flag == _wasHeld)
			{
				return;
			}
			_wasHeld = flag;
			Kick(220f);
			if (Plugin.Cfg.CorpseToots.Value && !(Time.time < _nextToot))
			{
				_nextToot = Time.time + 0.8f;
				SoundBank.Sound sound = SoundBank.Blast(_rng);
				if (sound != null)
				{
					_tb.StartBlast(sound, sound.RandomPitch(_rng) * 1.7f, 0.3f);
				}
			}
		}

		private static Transform Find(Transform root, string name)
		{
			if (((Object)root).name == name)
			{
				return root;
			}
			for (int i = 0; i < root.childCount; i++)
			{
				Transform val = Find(root.GetChild(i), name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}
	}
	internal static class GlbLoader
	{
		public sealed class MaterialSlot
		{
			public int gltfMaterial;

			public Color linearColor;

			public float metallic;

			public float roughness;
		}

		public sealed class Result
		{
			public GameObject root;

			public readonly List<MaterialSlot> slots = new List<MaterialSlot>();

			public readonly Dictionary<Renderer, int[]> SlotOfRendererMaterial = new Dictionary<Renderer, int[]>();

			public int vertexCount;

			public int submeshCount;

			public int nodeCount;
		}

		private sealed class Context
		{
			private readonly JObject _g;

			private readonly byte[] _bin;

			private readonly Dictionary<(int, int), int> _slotIndex = new Dictionary<(int, int), int>();

			public Result result;

			public Context(JObject g, byte[] bin)
			{
				_g = g;
				_bin = bin;
			}

			public void BuildNode(int index, Transform parent)
			{
				//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_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				JObject val = (JObject)_g["nodes"][(object)index];
				GameObject val2 = new GameObject(((string)val["name"]) ?? ("node" + index));
				val2.transform.SetParent(parent, false);
				ApplyTransform(val, val2.transform);
				result.nodeCount++;
				int? num = (int?)val["mesh"];
				if (num.HasValue)
				{
					BuildMesh(num.Value, val2);
				}
				JToken obj = val["children"];
				JArray val3 = (JArray)(object)((obj is JArray) ? obj : null);
				if (val3 == null)
				{
					return;
				}
				foreach (JToken item in val3)
				{
					BuildNode((int)item, val2.transform);
				}
			}

			private static void ApplyTransform(JObject node, Transform t)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: 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_000b: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: 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_020e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0219: Unknown result type (might be due to invalid IL or missing references)
				//IL_0220: 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)
				//IL_022d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				//IL_023e: 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_00e2: 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_00f4: 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_0107: 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)
				Vector3 zero = Vector3.zero;
				Vector3 one = Vector3.one;
				Quaternion val = Quaternion.identity;
				JToken obj = node["matrix"];
				JArray val2 = (JArray)(object)((obj is JArray) ? obj : null);
				if (val2 != null)
				{
					float[] array = ((IEnumerable<JToken>)val2).Select((JToken v) => (float)v).ToArray();
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3))..ctor(array[0], array[1], array[2]);
					Vector3 val4 = default(Vector3);
					((Vector3)(ref val4))..ctor(array[4], array[5], array[6]);
					Vector3 val5 = default(Vector3);
					((Vector3)(ref val5))..ctor(array[8], array[9], array[10]);
					((Vector3)(ref zero))..ctor(array[12], array[13], array[14]);
					((Vector3)(ref one))..ctor(((Vector3)(ref val3)).magnitude, ((Vector3)(ref val4)).magnitude, ((Vector3)(ref val5)).magnitude);
					if (one.x > 0f && one.y > 0f && one.z > 0f)
					{
						val = Quaternion.LookRotation(val5 / one.z, val4 / one.y);
					}
				}
				else
				{
					JToken obj2 = node["translation"];
					JArray val6 = (JArray)(object)((obj2 is JArray) ? obj2 : null);
					if (val6 != null)
					{
						((Vector3)(ref zero))..ctor((float)val6[0], (float)val6[1], (float)val6[2]);
					}
					JToken obj3 = node["rotation"];
					JArray val7 = (JArray)(object)((obj3 is JArray) ? obj3 : null);
					if (val7 != null)
					{
						((Quaternion)(ref val))..ctor((float)val7[0], (float)val7[1], (float)val7[2], (float)val7[3]);
					}
					JToken obj4 = node["scale"];
					JArray val8 = (JArray)(object)((obj4 is JArray) ? obj4 : null);
					if (val8 != null)
					{
						((Vector3)(ref one))..ctor((float)val8[0], (float)val8[1], (float)val8[2]);
					}
				}
				t.localPosition = new Vector3(zero.x, zero.y, 0f - zero.z);
				t.localRotation = new Quaternion(0f - val.x, 0f - val.y, val.z, val.w);
				t.localScale = one;
			}

			private void BuildMesh(int meshIndex, GameObject go)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				//IL_0038: 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_0057: Expected O, but got Unknown
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: 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_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: 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_01a7: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0343: Unknown result type (might be due to invalid IL or missing references)
				//IL_0421: Expected O, but got Unknown
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0237: Unknown result type (might be due to invalid IL or missing references)
				//IL_0382: Unknown result type (might be due to invalid IL or missing references)
				//IL_039a: Unknown result type (might be due to invalid IL or missing references)
				//IL_039f: Unknown result type (might be due to invalid IL or missing references)
				JObject val = (JObject)_g["meshes"][(object)meshIndex];
				Dictionary<int, List<Corner>> dictionary = new Dictionary<int, List<Corner>>();
				List<int> list = new List<int>();
				foreach (JObject item in (JArray)val["primitives"])
				{
					JObject val2 = item;
					int num = ((int?)val2["mode"]) ?? 4;
					if (num != 4)
					{
						Plugin.Log.LogWarning((object)$"glTF mesh {meshIndex}: primitive mode {num} not supported, skipped");
						continue;
					}
					JObject val3 = (JObject)val2["attributes"];
					float[][] array = ReadVec((int)val3["POSITION"], 3);
					float[][] array2 = ((val3["COLOR_0"] != null) ? ReadVec((int)val3["COLOR_0"], -1) : null);
					int[] array3 = ((val2["indices"] != null) ? ReadIndices((int)val2["indices"]) : Enumerable.Range(0, array.Length).ToArray());
					int material = ((int?)val2["material"]) ?? (-1);
					Corner[] array4 = new Corner[array3.Length];
					for (int i = 0; i + 2 < array3.Length; i += 3)
					{
						int num2 = array3[i];
						int num3 = array3[i + 2];
						int num4 = array3[i + 1];
						Vector3 val4 = ToUnity(array[num2]);
						Vector3 val5 = ToUnity(array[num3]);
						Vector3 val6 = ToUnity(array[num4]);
						Vector3 faceNormal = Vector3.Cross(val5 - val4, val6 - val4);
						Color color = ((array2 != null) ? ToColor(array2[num2]) : Color.white);
						array4[i] = new Corner(val4, faceNormal, color);
						array4[i + 1] = new Corner(val5, faceNormal, color);
						array4[i + 2] = new Corner(val6, faceNormal, color);
					}
					SmoothNormals(array4);
					for (int j = 0; j + 2 < array4.Length; j += 3)
					{
						int num5 = SlotFor(material, array4[j].color);
						if (!dictionary.TryGetValue(num5, out var value))
						{
							value = (dictionary[num5] = new List<Corner>());
							list.Add(num5);
						}
						value.Add(array4[j]);
						value.Add(array4[j + 1]);
						value.Add(array4[j + 2]);
					}
				}
				if (list.Count == 0)
				{
					return;
				}
				List<Vector3> list3 = new List<Vector3>();
				List<Vector3> list4 = new List<Vector3>();
				List<int[]> list5 = new List<int[]>();
				foreach (int item2 in list)
				{
					List<Corner> list6 = dictionary[item2];
					List<int> list7 = new List<int>(list6.Count * 2);
					for (int k = 0; k < list6.Count; k++)
					{
						list7.Add(list3.Count);
						list3.Add(list6[k].pos);
						list4.Add(list6[k].normal);
					}
					for (int l = 0; l < list6.Count; l += 3)
					{
						for (int num6 = 2; num6 >= 0; num6--)
						{
							list7.Add(list3.Count);
							list3.Add(list6[l + num6].pos);
							list4.Add(-list6[l + num6].normal);
						}
					}
					list5.Add(list7.ToArray());
				}
				Mesh val7 = new Mesh
				{
					name = (((string)val["name"]) ?? ("mesh" + meshIndex))
				};
				if (list3.Count > 65000)
				{
					val7.indexFormat = (IndexFormat)1;
				}
				val7.SetVertices(list3);
				val7.SetNormals(list4);
				val7.subMeshCount = list5.Count;
				for (int m = 0; m < list5.Count; m++)
				{
					val7.SetTriangles(list5[m], m);
				}
				val7.RecalculateBounds();
				go.AddComponent<MeshFilter>().sharedMesh = val7;
				MeshRenderer key = go.AddComponent<MeshRenderer>();
				result.SlotOfRendererMaterial[(Renderer)(object)key] = list.ToArray();
				result.vertexCount += list3.Count;
				result.submeshCount += list5.Count;
			}

			private int SlotFor(int material, Color c)
			{
				//IL_0003: 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_00ba: 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_00bf: 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_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
				(int, int) key = (material, Quantize(c));
				if (_slotIndex.TryGetValue(key, out var value))
				{
					return value;
				}
				object obj;
				if (material < 0)
				{
					obj = null;
				}
				else
				{
					JToken obj2 = _g["materials"];
					obj = (object)(JObject)((obj2 != null) ? obj2[(object)material] : null);
				}
				JToken obj3 = ((obj != null) ? ((JObject)obj)["pbrMetallicRoughness"] : null);
				JObject val = (JObject)(object)((obj3 is JObject) ? obj3 : null);
				JToken obj4 = ((val != null) ? val["baseColorFactor"] : null);
				JArray val2 = (JArray)(object)((obj4 is JArray) ? obj4 : null);
				Color val3 = (Color)((val2 != null) ? new Color((float)val2[0], (float)val2[1], (float)val2[2], (float)val2[3]) : Color.white);
				MaterialSlot item = new MaterialSlot
				{
					gltfMaterial = material,
					linearColor = c * val3,
					metallic = (((float?)((val != null) ? val["metallicFactor"] : null)) ?? 1f),
					roughness = (((float?)((val != null) ? val["roughnessFactor"] : null)) ?? 1f)
				};
				value = result.slots.Count;
				result.slots.Add(item);
				_slotIndex[key] = value;
				return value;
			}

			private static int Quantize(Color c)
			{
				//IL_0000: 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_0028: Unknown result type (might be due to invalid IL or missing references)
				return (Mathf.RoundToInt(c.r * 63f) << 12) | (Mathf.RoundToInt(c.g * 63f) << 6) | Mathf.RoundToInt(c.b * 63f);
			}

			private static Vector3 ToUnity(float[] p)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3(p[0], p[1], 0f - p[2]);
			}

			private static Color ToColor(float[] c)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				return new Color(c[0], c[1], c[2], (c.Length > 3) ? c[3] : 1f);
			}

			private float[][] ReadVec(int accessorIndex, int expectedComponents)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				JObject val = (JObject)_g["accessors"][(object)accessorIndex];
				int num = (int)val["count"];
				string text = (string)val["type"];
				int num2 = text switch
				{
					"VEC4" => 4, 
					"VEC3" => 3, 
					"VEC2" => 2, 
					"SCALAR" => 1, 
					_ => throw new InvalidDataException("Unsupported accessor type " + text), 
				};
				if (expectedComponents > 0 && num2 != expectedComponents)
				{
					throw new InvalidDataException($"Accessor {accessorIndex}: expected {expectedComponents} components, got {num2}");
				}
				int ctype = (int)val["componentType"];
				bool valueOrDefault = (bool?)val["normalized"] == true;
				int num3 = ComponentSize(ctype);
				View(val, num2 * num3, out var start, out var stride);
				float[][] array = new float[num][];
				for (int i = 0; i < num; i++)
				{
					float[] array2 = new float[num2];
					for (int j = 0; j < num2; j++)
					{
						array2[j] = ReadComponent(start + i * stride + j * num3, ctype, valueOrDefault);
					}
					array[i] = array2;
				}
				return array;
			}

			private int[] ReadIndices(int accessorIndex)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				JObject val = (JObject)_g["accessors"][(object)accessorIndex];
				int num = (int)val["count"];
				int num2 = (int)val["componentType"];
				int elementSize = ComponentSize(num2);
				View(val, elementSize, out var start, out var stride);
				int[] array = new int[num];
				for (int i = 0; i < num; i++)
				{
					int num3 = start + i * stride;
					array[i] = num2 switch
					{
						5123 => BitConverter.ToUInt16(_bin, num3), 
						5121 => _bin[num3], 
						_ => (int)BitConverter.ToUInt32(_bin, num3), 
					};
				}
				return array;
			}

			private void View(JObject acc, int elementSize, out int start, out int stride)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				JObject val = (JObject)_g["bufferViews"][(object)(int)acc["bufferView"]];
				start = ((int?)val["byteOffset"]).GetValueOrDefault() + ((int?)acc["byteOffset"]).GetValueOrDefault();
				stride = ((int?)val["byteStride"]) ?? elementSize;
			}

			private float ReadComponent(int o, int ctype, bool normalized)
			{
				switch (ctype)
				{
				case 5126:
					return BitConverter.ToSingle(_bin, o);
				case 5121:
					if (!normalized)
					{
						return (int)_bin[o];
					}
					return (float)(int)_bin[o] / 255f;
				case 5123:
				{
					ushort num2 = BitConverter.ToUInt16(_bin, o);
					if (!normalized)
					{
						return (int)num2;
					}
					return (float)(int)num2 / 65535f;
				}
				case 5120:
				{
					sbyte b = (sbyte)_bin[o];
					if (!normalized)
					{
						return b;
					}
					return Mathf.Max((float)b / 127f, -1f);
				}
				case 5122:
				{
					short num = BitConverter.ToInt16(_bin, o);
					if (!normalized)
					{
						return num;
					}
					return Mathf.Max((float)num / 32767f, -1f);
				}
				case 5125:
					return BitConverter.ToUInt32(_bin, o);
				default:
					throw new InvalidDataException("Unsupported component type " + ctype);
				}
			}

			private static int ComponentSize(int ctype)
			{
				switch (ctype)
				{
				default:
					return 4;
				case 5122:
				case 5123:
					return 2;
				case 5120:
				case 5121:
					return 1;
				}
			}
		}

		private struct Corner
		{
			public Vector3 pos;

			public Vector3 faceNormal;

			public Vector3 normal;

			public Color color;

			public Corner(Vector3 pos, Vector3 faceNormal, Color color)
			{
				//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_0008: 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_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_001c: 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)
				this.pos = pos;
				this.faceNormal = faceNormal;
				normal = ((Vector3)(ref faceNormal)).normalized;
				this.color = color;
			}
		}

		private const float CreaseAngle = 50f;

		public static Result Load(byte[] glb, string name)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//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_0083: Unknown result type (might be due to invalid IL or missing references)
			ReadChunks(glb, out var json, out var bin);
			JObject obj = JObject.Parse(json);
			Context context = new Context(obj, bin);
			Result result = (context.result = new Result
			{
				root = new GameObject(name)
			});
			int valueOrDefault = ((int?)obj["scene"]).GetValueOrDefault();
			JToken obj2 = obj["scenes"];
			object obj3;
			if (obj2 == null)
			{
				obj3 = null;
			}
			else
			{
				JToken obj4 = obj2[(object)valueOrDefault];
				obj3 = ((obj4 != null) ? obj4[(object)"nodes"] : null);
			}
			? val = (JArray)obj3;
			if ((int)val == 0)
			{
				val = new JArray();
			}
			foreach (JToken item in (JArray)val)
			{
				context.BuildNode((int)item, result.root.transform);
			}
			return result;
		}

		private static void ReadChunks(byte[] glb, out string json, out byte[] bin)
		{
			if (glb.Length < 20 || BitConverter.ToUInt32(glb, 0) != 1179937895)
			{
				throw new InvalidDataException("Not a GLB file");
			}
			json = null;
			bin = null;
			int num;
			for (int i = 12; i + 8 <= glb.Length; i += 8 + num)
			{
				num = (int)BitConverter.ToUInt32(glb, i);
				switch (BitConverter.ToUInt32(glb, i + 4))
				{
				case 1313821514u:
					json = Encoding.UTF8.GetString(glb, i + 8, num);
					break;
				case 5130562u:
					bin = new byte[num];
					Buffer.BlockCopy(glb, i + 8, bin, 0, num);
					break;
				}
			}
			if (json == null || bin == null)
			{
				throw new InvalidDataException("GLB without JSON or BIN chunk");
			}
		}

		private static void SmoothNormals(Corner[] corners)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_00ae: 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_00b5: 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_00cb: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_012d: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Cos(0.87266463f);
			Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
			for (int i = 0; i < corners.Length; i++)
			{
				Vector3Int key = Vector3Int.RoundToInt(corners[i].pos * 100000f);
				if (!dictionary.TryGetValue(key, out var value))
				{
					value = (dictionary[key] = new List<int>(6));
				}
				value.Add(i);
			}
			Vector3[] array = (Vector3[])(object)new Vector3[corners.Length];
			foreach (List<int> value2 in dictionary.Values)
			{
				foreach (int item in value2)
				{
					Vector3 normalized = ((Vector3)(ref corners[item].faceNormal)).normalized;
					Vector3 val = Vector3.zero;
					foreach (int item2 in value2)
					{
						if (Vector3.Dot(normalized, ((Vector3)(ref corners[item2].faceNormal)).normalized) >= num)
						{
							val += corners[item2].faceNormal;
						}
					}
					array[item] = ((((Vector3)(ref val)).sqrMagnitude > 1E-20f) ? ((Vector3)(ref val)).normalized : normalized);
				}
			}
			for (int j = 0; j < corners.Length; j++)
			{
				corners[j].normal = array[j];
			}
		}
	}
	internal static class SoundBank
	{
		public sealed class Sound
		{
			public AudioClip clip;

			public AudioClip farClip;

			public float pitchMin;

			public float pitchMax;

			public float audibleLength;

			public float RandomPitch(Random rng)
			{
				return pitchMin + (float)rng.NextDouble() * (pitchMax - pitchMin);
			}
		}

		private static bool _initialized;

		private static readonly List<Sound> Blasts = new List<Sound>();

		private static readonly List<Sound> Kills = new List<Sound>();

		public static Sound ClownToot { get; private set; }

		public static AudioClip Inhale { get; private set; }

		public static AudioMixerGroup Mixer { get; private set; }

		private static Sound Make(AudioClip clip, AudioClip far, float pitchMin, float pitchMax)
		{
			if (!((Object)(object)clip == (Object)null))
			{
				return new Sound
				{
					clip = clip,
					farClip = far,
					pitchMin = pitchMin,
					pitchMax = pitchMax,
					audibleLength = AudibleLength(clip)
				};
			}
			return null;
		}

		private static float AudibleLength(AudioClip clip)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			try
			{
				if ((int)clip.loadState != 2)
				{
					clip.LoadAudioData();
				}
				float[] array = new float[clip.samples * clip.channels];
				if (array.Length != 0 && clip.GetData(array, 0))
				{
					float num = 0f;
					float[] array2 = array;
					foreach (float num2 in array2)
					{
						num = Mathf.Max(num, Mathf.Abs(num2));
					}
					if (num > 0f)
					{
						float num3 = num * 0.15f;
						int num4 = array.Length - 1;
						while (num4 > 0 && Mathf.Abs(array[num4]) < num3)
						{
							num4--;
						}
						return Mathf.Clamp((float)(num4 / clip.channels) / (float)clip.frequency, 0.1f, clip.length);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Could not analyse " + ((Object)clip).name + ": " + ex.Message));
			}
			return clip.length * 0.8f;
		}

		public static Sound Blast(Random rng)
		{
			EnsureInit();
			return Pick(Blasts, rng);
		}

		public static Sound Kill(Random rng)
		{
			EnsureInit();
			return Pick(Kills, rng) ?? Pick(Blasts, rng);
		}

		private static Sound Pick(List<Sound> list, Random rng)
		{
			if (list.Count != 0)
			{
				return list[rng.Next(list.Count)];
			}
			return null;
		}

		public static void EnsureInit()
		{
			if (!_initialized)
			{
				_initialized = true;
				List<Item> items = (((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.allItemsList != (Object)null) ? StartOfRound.Instance.allItemsList.itemsList : null);
				NoisemakerProp val = Noisemaker(items, "Airhorn");
				NoisemakerProp val2 = Noisemaker(items, "Clown horn");
				if ((Object)(object)val != (Object)null && (Object)(object)val.noiseAudio != (Object)null)
				{
					Mixer = val.noiseAudio.outputAudioMixerGroup;
				}
				LoadCustom("blast", Blasts);
				LoadCustom("kill", Kills);
				if (Blasts.Count == 0 && (Object)(object)val != (Object)null)
				{
					AddIfNotNull(Blasts, Make(val.noiseSFX.FirstOrDefault(), val.noiseSFXFar?.FirstOrDefault(), 0.55f, 0.7f));
				}
				if (Kills.Count == 0 && (Object)(object)val != (Object)null)
				{
					AddIfNotNull(Kills, Make(val.noiseSFX.FirstOrDefault(), val.noiseSFXFar?.FirstOrDefault(), 0.42f, 0.46f));
				}
				if ((Object)(object)val2 != (Object)null)
				{
					ClownToot = Make(val2.noiseSFX.FirstOrDefault(), null, 0.6f, 0.75f);
				}
				List<Sound> list = new List<Sound>();
				LoadCustom("inhale", list);
				Inhale = ((list.Count > 0) ? list[0].clip : ((Kills.Count > 0) ? Reverse(Kills[0].clip) : null));
				Plugin.Log.LogInfo((object)(string.Format("Trumpet sounds: {0} blast(s), {1} kill sound(s), mixer {2}. ", Blasts.Count, Kills.Count, ((Object)(object)Mixer != (Object)null) ? ((Object)Mixer).name : "-") + "Audible lengths: " + string.Join(", ", from s in Blasts.Concat(Kills)
					select $"{((Object)s.clip).name} {s.audibleLength:0.00}/{s.clip.length:0.00}s")));
			}
		}

		private static AudioClip Reverse(AudioClip clip)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			try
			{
				if ((int)clip.loadState != 2)
				{
					clip.LoadAudioData();
				}
				int channels = clip.channels;
				int samples = clip.samples;
				float[] array = new float[samples * channels];
				if (array.Length == 0 || !clip.GetData(array, 0))
				{
					return null;
				}
				float[] array2 = new float[array.Length];
				for (int i = 0; i < samples; i++)
				{
					for (int j = 0; j < channels; j++)
					{
						array2[(samples - 1 - i) * channels + j] = array[i * channels + j];
					}
				}
				AudioClip obj = AudioClip.Create(((Object)clip).name + "_reversed", samples, channels, clip.frequency, false);
				obj.SetData(array2, 0);
				return obj;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Could not reverse " + ((Object)clip).name + ": " + ex.Message));
				return null;
			}
		}

		private static void AddIfNotNull(List<Sound> list, Sound s)
		{
			if (s != null)
			{
				list.Add(s);
			}
		}

		private static NoisemakerProp Noisemaker(List<Item> items, string name)
		{
			Item val = items?.FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.itemName == name));
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val.spawnPrefab != (Object)null))
			{
				return null;
			}
			return val.spawnPrefab.GetComponent<NoisemakerProp>();
		}

		private static void LoadCustom(string prefix, List<Sound> into)
		{
			string path = Path.Combine(Plugin.PluginDir ?? "", "sounds");
			if (!Directory.Exists(path))
			{
				return;
			}
			foreach (string item in from f in Directory.GetFiles(path)
				where Path.GetFileName(f).StartsWith(prefix, StringComparison.OrdinalIgnoreCase)
				orderby f
				select f)
			{
				AudioClip val = LoadClip(item);
				if (!((Object)(object)val == (Object)null))
				{
					into.Add(Make(val, null, 0.95f, 1.05f));
					Plugin.Log.LogInfo((object)$"Loaded custom sound {Path.GetFileName(item)} ({val.length:0.00}s)");
				}
			}
		}

		private static AudioClip LoadClip(string file)
		{
			//IL_0037: 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_003c: 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)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Invalid comparison between Unknown and I4
			AudioType val;
			switch (Path.GetExtension(file).ToLowerInvariant())
			{
			case ".ogg":
				val = (AudioType)14;
				break;
			case ".wav":
				val = (AudioType)20;
				break;
			case ".mp3":
				val = (AudioType)13;
				break;
			default:
				return null;
			}
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(new Uri(file).AbsoluteUri, val);
			try
			{
				UnityWebRequestAsyncOperation val2 = audioClip.SendWebRequest();
				while (!((AsyncOperation)val2).isDone)
				{
				}
				if ((int)audioClip.result != 1)
				{
					Plugin.Log.LogWarning((object)("Could not load " + file + ": " + audioClip.error));
					return null;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
				((Object)content).name = Path.GetFileNameWithoutExtension(file);
				return content;
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
		}
	}
	internal sealed class TrumpetBehaviour : MonoBehaviour
	{
		public float Scale = 1f;

		public float LengthFactor = 1f;

		public Transform FaceTarget;

		public float FaceSpeed = 8f;

		public Transform FollowTarget;

		public Vector3 FollowOffset;

		public float FollowSharpness = 6f;

		public bool FollowInYawFrame = true;

		public Transform ClearanceFrom;

		public bool BlastsOnHead;

		private const float MinFollowDistance = 0.5f;

		private const float Gain = 1.8f;

		private float _scaleFactor = 0.001f;

		private float _fit = 1f;

		private bool _fitInitialized;

		private bool _localPose;

		private float _blow;

		private float _blowVel;

		private float _blastUntil;

		private Quaternion _baseRotation;

		private Transform[] _pistons;

		private Vector3[] _pistonRest;

		private float[] _pistonPhase;

		private AudioSource _near;

		private AudioSource _far;

		private AudioSource _fx;

		private TrumpetDeformer _deformer;

		private readonly Random _rng = new Random();

		public float ExtraShaft { get; set; }

		public float ExtraBell { get; set; }

		public float Tremble { get; set; }

		public bool IsBlasting => Time.time < _blastUntil;

		public Random Rng => _rng;

		private static float Loudness(float volume)
		{
			return Mathf.Clamp(volume * Plugin.Cfg.Volume.Value * 1.8f, 0f, 4f);
		}

		private void Awake()
		{
			//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)
			_baseRotation = ((Component)this).transform.rotation;
			_pistons = (from t in ((Component)this).GetComponentsInChildren<Transform>(true)
				where ((Object)t).name.StartsWith("piston")
				select t).ToArray();
			_pistonRest = _pistons.Select((Transform p) => p.localPosition).ToArray();
			_pistonPhase = _pistons.Select((Transform _) => (float)_rng.NextDouble() * 10f).ToArray();
			_near = MakeSource(3f, 50f, SoundBank.Mixer);
			_far = MakeSource(15f, 110f, null);
			Transform val = ((Component)this).transform.Find("Model");
			if ((Object)(object)val != (Object)null)
			{
				_deformer = new TrumpetDeformer(val);
			}
			ApplyScale();
		}

		private void OnDestroy()
		{
			_deformer?.Destroy();
		}

		private AudioSource MakeSource(float min, float max, AudioMixerGroup mixer)
		{
			AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = min;
			obj.maxDistance = max;
			obj.dopplerLevel = 0f;
			obj.outputAudioMixerGroup = mixer;
			return obj;
		}

		public void UseLocalPose()
		{
			//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)
			_localPose = true;
			_baseRotation = ((Component)this).transform.localRotation;
		}

		public void PlayClip(AudioClip clip, float pitch, float volume)
		{
			if (!((Object)(object)clip == (Object)null))
			{
				if ((Object)(object)_fx == (Object)null)
				{
					_fx = MakeSource(3f, 50f, SoundBank.Mixer);
				}
				_fx.pitch = Mathf.Max(0.1f, pitch);
				_fx.PlayOneShot(clip, Loudness(volume));
			}
		}

		public void FollowWithCurrentOffset(Transform target)
		{
			//IL_0009: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			FollowTarget = target;
			FollowOffset = Quaternion.Inverse(YawOf(target)) * (((Component)this).transform.position - target.position);
		}

		private static Quaternion YawOf(Transform t)
		{
			//IL_0006: 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)
			return Quaternion.Euler(0f, t.eulerAngles.y, 0f);
		}

		private void LateUpdate()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00a6: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0189: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: 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_00e8: 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_0103: 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_0064: 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_007e: 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_01b8: 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_0112: 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)
			float deltaTime = Time.deltaTime;
			if ((Object)(object)FollowTarget != (Object)null)
			{
				Vector3 val = FollowTarget.position + (FollowInYawFrame ? (YawOf(FollowTarget) * FollowOffset) : FollowOffset);
				((Component)this).transform.position = ((FollowSharpness <= 0f) ? val : Vector3.Lerp(((Component)this).transform.position, val, 1f - Mathf.Exp((0f - FollowSharpness) * deltaTime)));
			}
			Quaternion val2 = _baseRotation;
			if ((Object)(object)FaceTarget != (Object)null)
			{
				Vector3 val3 = FaceTarget.position - ((Component)this).transform.position;
				if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f)
				{
					Quaternion val4 = Quaternion.LookRotation(val3, Vector3.up);
					_baseRotation = ((FaceSpeed <= 0f) ? val4 : Quaternion.Slerp(_baseRotation, val4, 1f - Mathf.Exp((0f - FaceSpeed) * deltaTime)));
					val2 = _baseRotation;
				}
			}
			if ((Object)(object)ClearanceFrom != (Object)null)
			{
				UpdateClearance(deltaTime);
			}
			UpdateBlow(deltaTime);
			float num = Mathf.Abs(_blow) + Tremble;
			if (num > 0.001f)
			{
				float time = Time.time;
				Vector3 val5 = new Vector3(Mathf.Sin(time * 23f), Mathf.Sin(time * 31f + 1f), Mathf.Sin(time * 17f + 2f)) * (2.5f * num);
				val2 *= Quaternion.Euler(val5);
			}
			if (_localPose)
			{
				((Component)this).transform.localRotation = val2;
			}
			else
			{
				((Component)this).transform.rotation = val2;
			}
			ApplyScale();
			ApplyDeformation();
			AnimatePistons();
		}

		private void UpdateBlow(float dt)
		{
			bool isBlasting = IsBlasting;
			float num = (isBlasting ? 1f : 0f);
			float num2 = (isBlasting ? 140f : 260f);
			float num3 = (isBlasting ? 9f : 26f);
			int num4 = Mathf.CeilToInt(dt / 0.008f);
			float num5 = dt / (float)Mathf.Max(1, num4);
			for (int i = 0; i < num4; i++)
			{
				_blowVel += (num2 * (num - _blow) - num3 * _blowVel) * num5;
				_blow += _blowVel * num5;
			}
			if (!isBlasting && Mathf.Abs(_blow) < 0.002f && Mathf.Abs(_blowVel) < 0.05f)
			{
				_blow = 0f;
				_blowVel = 0f;
			}
		}

		private void UpdateClearance(float dt)
		{
			//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_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_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_00e4: 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_00f3: 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_0118: 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_0122: 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_0078: 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_0081: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			float num = (BlastsOnHead ? TrumpetSpace.RestLength(Scale, LengthFactor) : TrumpetSpace.BodyLength(Scale, LengthFactor));
			float radius = TrumpetSpace.CastRadius(Scale);
			Vector3 position = ClearanceFrom.position;
			Vector3 val = ((Component)this).transform.position - position;
			float num2 = ((Vector3)(ref val)).magnitude;
			float num5;
			if ((Object)(object)FollowTarget != (Object)null && num2 > 0.05f)
			{
				Vector3 val2 = val / num2;
				float num3 = TrumpetSpace.Free(position, val2, num2 + num + 0.2f, radius);
				float num4 = num3 - 0.2f - num * 0.3f;
				if (num4 < num2)
				{
					num2 = Mathf.Max(0.5f, num4);
					((Component)this).transform.position = position + val2 * num2;
				}
				num5 = (num3 - 0.2f - num2) / num;
			}
			else
			{
				Vector3 val3 = _baseRotation * Vector3.forward;
				float num6 = Mathf.Min(0.5f, num2 * 0.5f);
				num5 = (TrumpetSpace.Free(((Component)this).transform.position + val3 * num6, -val3, num6 + num + 0.2f, radius) - num6 - 0.2f) / num;
			}
			num5 = Mathf.Clamp(num5, 0.3f, 1f);
			if (!_fitInitialized)
			{
				_fit = num5;
				_fitInitialized = true;
			}
			else
			{
				float num7 = ((num5 < _fit) ? 14f : 3f);
				_fit = Mathf.Lerp(_fit, num5, 1f - Mathf.Exp((0f - num7) * dt));
			}
		}

		private void ApplyScale()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			float num = Scale * _scaleFactor * _fit;
			float num2 = 1f + 0.03f * Mathf.Abs(_blow) * Mathf.Sin(Time.time * 47f);
			((Component)this).transform.localScale = new Vector3(num * num2, num * num2, num);
		}

		private void ApplyDeformation()
		{
			if (_deformer != null)
			{
				float time = Time.time;
				bool isBlasting = IsBlasting;
				float num = (isBlasting ? (0.8f + 0.2f * Mathf.Sin(time * 6.3f)) : 1f);
				float num2 = (isBlasting ? (0.85f + 0.15f * Mathf.Sin(time * 9.7f + 1f)) : 1f);
				float num3 = Plugin.Cfg.BlowShaftStretch.Value * _blow * num + ExtraShaft;
				float num4 = 1f + Plugin.Cfg.BlowBellGrow.Value * _blow * num2 + ExtraBell;
				_deformer.RearScale = LengthFactor;
				_deformer.Apply(Mathf.Max(-0.08f, num3), Mathf.Max(0.8f, num4));
			}
		}

		private void AnimatePistons()
		{
			//IL_006a: 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)
			float num = Mathf.Clamp01(Mathf.Abs(_blow));
			for (int i = 0; i < _pistons.Length; i++)
			{
				if (!((Object)(object)_pistons[i] == (Object)null))
				{
					float num2 = 0f;
					if (num > 0.01f && Mathf.Sin(Time.time * 9f + _pistonPhase[i]) > 0.2f)
					{
						num2 = 0.012f * num;
					}
					_pistons[i].localPosition = _pistonRest[i] - new Vector3(0f, num2, 0f);
				}
			}
		}

		public void ShowInstantly()
		{
			_scaleFactor = 1f;
		}

		public IEnumerator PopIn(float duration)
		{
			for (float t = 0f; t < duration; t += Time.deltaTime)
			{
				float num = t / duration;
				float num2 = 1f + 2.9f * Mathf.Pow(num - 1f, 3f) + 1.9f * Mathf.Pow(num - 1f, 2f);
				_scaleFactor = Mathf.Max(0.001f, num2);
				yield return null;
			}
			_scaleFactor = 1f;
		}

		public IEnumerator ShrinkOut(float duration, bool destroy = true)
		{
			float start = _scaleFactor;
			for (float t = 0f; t < duration; t += Time.deltaTime)
			{
				float num = t / duration;
				_scaleFactor = Mathf.Lerp(start, 0.001f, num * num);
				yield return null;
			}
			_scaleFactor = 0.001f;
			if (destroy)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public IEnumerator Hold(float seconds)
		{
			yield return (object)new WaitForSeconds(seconds);
		}

		public float StartBlast(SoundBank.Sound sound, float pitch, float volume = 1f)
		{
			float num = 1.2f;
			float num2 = Loudness(volume);
			if (sound != null && (Object)(object)sound.clip != (Object)null)
			{
				pitch = Mathf.Max(0.1f, pitch);
				num = sound.audibleLength / pitch;
				_near.pitch = pitch;
				_near.PlayOneShot(sound.clip, num2);
				if ((Object)(object)sound.farClip != (Object)null)
				{
					_far.pitch = pitch;
					_far.PlayOneShot(sound.farClip, num2 * 0.8f);
				}
			}
			_blastUntil = Time.time + num;
			return num;
		}

		public IEnumerator Blast(SoundBank.Sound sound, float pitch, float volume = 1f)
		{
			float num = StartBlast(sound, pitch, volume);
			yield return (object)new WaitForSeconds(num);
		}

		public IEnumerator LoopBlast(float pause)
		{
			yield return PopIn(0.3f);
			while (true)
			{
				SoundBank.Sound sound = SoundBank.Blast(_rng);
				yield return Blast(sound, sound?.RandomPitch(_rng) ?? 1f);
				yield return Hold(pause);
			}
		}

		public IEnumerator BlastAndLinger(float linger)
		{
			yield return PopIn(0.3f);
			SoundBank.Sound sound = SoundBank.Blast(_rng);
			yield return Blast(sound, sound?.RandomPitch(_rng) ?? 1f);
			yield return Hold(linger);
			yield return ShrinkOut(0.35f);
		}
	}
	internal sealed class TrumpetDeformer
	{
		private sealed class Part
		{
			public Mesh mesh;

			public Vector3[] modelPos;

			public Vector3[] work;

			public Matrix4x4 modelToNode;
		}

		private const float ShaftStartFraction = 0.24f;

		internal const float BellStartFraction = 0.13f;

		private readonly List<Part> _parts = new List<Part>();

		private readonly float _xMax;

		private readonly float _x0;

		private readonly float _x1;

		private readonly float _length;

		private readonly Vector2 _bellAxis;

		private float _lastShaft;

		private float _lastBell = 1f;

		private float _lastRear = 1f;

		public float RearScale { get; set; } = 1f;

		public TrumpetDeformer(Transform modelRoot)
		{
			//IL_0070: 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_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_00f6: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_011c: 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_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_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter[] componentsInChildren = ((Component)modelRoot).GetComponentsInChildren<MeshFilter>(true);
			float num = float.MaxValue;
			float num2 = float.MinValue;
			MeshFilter[] array = componentsInChildren;
			foreach (MeshFilter val in array)
			{
				if ((Object)(object)val.sharedMesh == (Object)null)
				{
					continue;
				}
				Matrix4x4 val2 = RelativeMatrix(((Component)val).transform, modelRoot);
				Mesh val3 = Object.Instantiate<Mesh>(val.sharedMesh);
				((Object)val3).name = ((Object)val.sharedMesh).name;
				val3.MarkDynamic();
				val.sharedMesh = val3;
				Vector3[] vertices = val3.vertices;
				Part part = new Part
				{
					mesh = val3,
					modelPos = (Vector3[])(object)new Vector3[vertices.Length],
					work = (Vector3[])(object)new Vector3[vertices.Length],
					modelToNode = ((Matrix4x4)(ref val2)).inverse
				};
				for (int j = 0; j < vertices.Length; j++)
				{
					Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[j]);
					part.modelPos[j] = val4;
					if (val4.x < num)
					{
						num = val4.x;
					}
					if (val4.x > num2)
					{
						num2 = val4.x;
					}
				}
				_parts.Add(part);
			}
			_xMax = num2;
			_length = Mathf.Max(0.001f, num2 - num);
			_x0 = num2 - _length * 0.24f;
			_x1 = num2 - _length * 0.13f;
			float num3 = 0f;
			float num4 = 0f;
			int num5 = 0;
			foreach (Part part2 in _parts)
			{
				Vector3[] modelPos = part2.modelPos;
				foreach (Vector3 val5 in modelPos)
				{
					if (val5.x > num2 - _length * 0.008f)
					{
						num3 += val5.y;
						num4 += val5.z;
						num5++;
					}
				}
			}
			_bellAxis = (Vector2)((num5 > 0) ? new Vector2(num3 / (float)num5, num4 / (float)num5) : Vector2.zero);
		}

		public void Apply(float shaftStretch, float bellScale)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_01aa: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: 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_01d9: 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_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			float rearScale = RearScale;
			if (Mathf.Abs(shaftStretch - _lastShaft) < 0.0001f && Mathf.Abs(bellScale - _lastBell) < 0.0001f && Mathf.Abs(rearScale - _lastRear) < 0.0001f)
			{
				return;
			}
			_lastShaft = shaftStretch;
			_lastBell = bellScale;
			_lastRear = rearScale;
			float num = shaftStretch * _length;
			float num2 = _xMax - _x1;
			float num3 = Mathf.Max(0.001f, _x1 - _x0);
			float num4 = 1f + 0.4f * (bellScale - 1f);
			float num5 = 1f + num / num3;
			float num6 = _xMax - num2 * num4;
			float num7 = num6 - num3 * num5;
			foreach (Part part in _parts)
			{
				Vector3[] modelPos = part.modelPos;
				Vector3[] work = part.work;
				for (int i = 0; i < modelPos.Length; i++)
				{
					Vector3 val = modelPos[i];
					float num8;
					if (!(val.x >= _x1))
					{
						num8 = ((!(val.x >= _x0)) ? (num7 - (_x0 - val.x)) : (num6 - (_x1 - val.x) * num5));
					}
					else
					{
						num8 = _xMax - (_xMax - val.x) * num4;
						float num9 = (val.x - _x1) / num2;
						float num10 = 1f + (bellScale - 1f) * num9 * Mathf.Sqrt(num9);
						val.y = _bellAxis.x + (val.y - _bellAxis.x) * num10;
						val.z = _bellAxis.y + (val.z - _bellAxis.y) * num10;
					}
					if (num8 < num6)
					{
						num8 = num6 - (num6 - num8) * rearScale;
					}
					val.x = num8;
					work[i] = ((Matrix4x4)(ref part.modelToNode)).MultiplyPoint3x4(val);
				}
				part.mesh.vertices = work;
				part.mesh.RecalculateBounds();
			}
		}

		public void Destroy()
		{
			foreach (Part part in _parts)
			{
				if ((Object)(object)part.mesh != (Object)null)
				{
					Object.Destroy((Object)(object)part.mesh);
				}
			}
			_parts.Clear();
		}

		private static Matrix4x4 RelativeMatrix(Transform node, Transform root)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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)
			//IL_000b: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.identity;
			Transform val2 = node;
			while ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)root)
			{
				val = Matrix4x4.TRS(val2.localPosition, val2.localRotation, val2.localScale) * val;
				val2 = val2.parent;
			}
			return val;
		}
	}
	internal static class TrumpetFactory
	{
		private static GameObject _template;

		private static bool _failed;

		private static readonly string[] TexturesToClear = new string[8] { "_BaseColorMap", "_NormalMap", "_MaskMap", "_DetailMap", "_EmissiveColorMap", "_BentNormalMap", "_CoatMaskMap", "_SpecularColorMap" };

		private static readonly string[] KeywordsToClear = new string[6] { "_NORMALMAP", "_MASKMAP", "_DETAIL_MAP", "_EMISSIVE_COLOR_MAP", "_BENTNORMALMAP", "_SPECULARCOLORMAP" };

		public static float ModelLength { get; private set; } = 0.58f;

		public static float BellRadius { get; private set; } = 0.08f;

		public static TrumpetBehaviour Create(Vector3 position, Quaternion rotation, float scale, Transform parent = null)
		{
			//IL_0013: 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)
			if (!EnsureTemplate())
			{
				return null;
			}
			SoundBank.EnsureInit();
			GameObject obj = Object.Instantiate<GameObject>(_template, position, rotation, parent);
			((Object)obj).name = "TootForTat_Trumpet";
			TrumpetBehaviour trumpetBehaviour = obj.AddComponent<TrumpetBehaviour>();
			trumpetBehaviour.Scale = scale;
			obj.SetActive(true);
			return trumpetBehaviour;
		}

		public static Transform MovingParentFor(PlayerControllerB player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return null;
			}
			if ((Object)(object)player.physicsParent != (Object)null)
			{
				return player.physicsParent;
			}
			if ((player.isInElevator || player.isInHangarShipRoom) && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				return StartOfRound.Instance.elevatorTransform;
			}
			return null;
		}

		private static bool EnsureTemplate()
		{
			if ((Object)(object)_template != (Object)null)
			{
				return true;
			}
			if (_failed)
			{
				return false;
			}
			try
			{
				_template = BuildTemplate();
				return true;
			}
			catch (Exception ex)
			{
				_failed = true;
				Plugin.Log.LogError((object)("Could not build the trumpet model: