Decompiled source of BiddyBlas v0.6.0

plugins/BiddyBlas/BiddyBlas.dll

Decompiled 10 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[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("BiddyBlas")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BiddyBlas")]
[assembly: AssemblyTitle("BiddyBlas")]
[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 BiddyBlas
{
	public class BiddyAI : EnemyAI
	{
		public const int Roam = 0;

		public const int AmbientScribDoon = 1;

		public const int AmbientDingDong = 2;

		public const int Vanish = 4;

		public const int SeenBase = 10;

		public const int MaxPlayerSlots = 64;

		private const float VanishTime = 3f;

		private const float FlashAt = 0.92f;

		public Transform model;

		private PlayerControllerB seer;

		private PlayerControllerB noticedBy;

		private float noticeTimer;

		private float ambientTimer;

		private float stateTimer;

		private float vanishTimer;

		private float idleBreakTimer;

		private float smoothSpeed;

		private float standingTime;

		private int localState = -1;

		private bool giftSpawned;

		private bool flashed;

		private Vector3 modelBaseLocal;

		private Vector3 lastPos;

		private Quaternion modelBaseRot;

		private HDAdditionalLightData glow;

		private static readonly float[] StepFrames = new float[8] { 1f, 16f, 31f, 46f, 60f, 74f, 90f, 105f };

		private AudioSource stepAudio;

		private float lastWalkFrame = -1f;

		private int surfaceIndex;

		private int lastStepClip = -1;

		internal static readonly List<BiddyAI> Active = new List<BiddyAI>();

		private bool Roaming => base.currentBehaviourStateIndex <= 2;

		public PlayerControllerB Spotter
		{
			get
			{
				if (!IsSeenState(base.currentBehaviourStateIndex))
				{
					return seer;
				}
				return StartOfRound.Instance.allPlayerScripts[base.currentBehaviourStateIndex - 10];
			}
		}

		public static bool IsSeenState(int s)
		{
			return s >= 10;
		}

		public override void Start()
		{
			//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_00b9: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)0;
			Active.Add(this);
			((EnemyAI)this).Start();
			modelBaseLocal = model.localPosition;
			stepAudio = ((Component)this).gameObject.AddComponent<AudioSource>();
			stepAudio.playOnAwake = false;
			stepAudio.spatialBlend = 1f;
			stepAudio.rolloffMode = (AudioRolloffMode)1;
			stepAudio.minDistance = 3f;
			stepAudio.maxDistance = 20f;
			stepAudio.dopplerLevel = 0f;
			stepAudio.outputAudioMixerGroup = BiddyAssets.SfxGroup;
			BiddyTalker.Attach(model, base.creatureVoice, ((Component)this).transform.right);
			modelBaseRot = model.localRotation;
			lastPos = ((Component)this).transform.position;
			ResetAmbientTimer();
			idleBreakTimer = Random.Range(6f, 14f);
			if (((NetworkBehaviour)this).IsOwner)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			}
			Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} spawned at {((Component)this).transform.position} (owner={((NetworkBehaviour)this).IsOwner})");
		}

		private void ResetAmbientTimer()
		{
			ambientTimer = Random.Range(Plugin.AmbientMinDelay.Value, Plugin.AmbientMaxDelay.Value);
		}

		public override void DoAIInterval()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			if (IsSeenState(base.currentBehaviourStateIndex))
			{
				stateTimer -= base.AIIntervalTime;
				if (stateTimer <= 0f)
				{
					stateTimer = 3f;
					((EnemyAI)this).SwitchToBehaviourState(4);
				}
				return;
			}
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			if ((uint)currentBehaviourStateIndex > 2u)
			{
				return;
			}
			if ((Object)(object)noticedBy == (Object)null)
			{
				noticedBy = FindSeer();
				if ((Object)(object)noticedBy != (Object)null)
				{
					noticeTimer = Plugin.SpotDelay.Value;
					Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} spotted by {noticedBy.playerUsername} at {((Component)this).transform.position}; scene in {noticeTimer:0.0}s t={Time.time:0.00}");
				}
			}
			else
			{
				noticeTimer -= base.AIIntervalTime;
			}
			if ((Object)(object)noticedBy != (Object)null && noticeTimer <= 0f)
			{
				PlayerControllerB val = ((noticedBy.isPlayerControlled && !noticedBy.isPlayerDead) ? noticedBy : FindSeer());
				noticedBy = null;
				if ((Object)(object)val != (Object)null)
				{
					BeginSeen(val);
					return;
				}
			}
			if (base.currentBehaviourStateIndex == 0 && (Object)(object)noticedBy == (Object)null)
			{
				ambientTimer -= base.AIIntervalTime;
				if (ambientTimer <= 0f)
				{
					int num = ((Random.value < 0.5f) ? 1 : 2);
					stateTimer = ((num == 1) ? BiddyAssets.ScribDoon : BiddyAssets.DingDong).length + 0.5f;
					((EnemyAI)this).SwitchToBehaviourState(num);
				}
			}
			else
			{
				stateTimer -= base.AIIntervalTime;
				if (stateTimer <= 0f)
				{
					ResetAmbientTimer();
					((EnemyAI)this).SwitchToBehaviourState(0);
				}
			}
			if (base.currentSearch == null || !base.currentSearch.inProgress)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			}
		}

		public override void OnDestroy()
		{
			Active.Remove(this);
			Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} despawned");
			((EnemyAI)this).OnDestroy();
		}

		private PlayerControllerB FindSeer()
		{
			//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_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_0068: Unknown result type (might be due to invalid IL or missing references)
			float value = Plugin.SightRange.Value;
			Vector3 position = base.eye.position;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isPlayerControlled && !val.isPlayerDead && val.isInsideFactory != base.isOutside && !(Vector3.Distance(((Component)val.gameplayCamera).transform.position, position) > value) && val.HasLineOfSightToPosition(position, 40f, (int)value, -1f, -1))
				{
					return val;
				}
			}
			return null;
		}

		internal void BeginSeen(PlayerControllerB p)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			seer = p;
			if (base.currentSearch != null)
			{
				((EnemyAI)this).StopSearch(base.currentSearch, true);
			}
			base.moveTowardsDestination = false;
			if (base.agent.isOnNavMesh)
			{
				base.agent.ResetPath();
			}
			base.agent.velocity = Vector3.zero;
			stateTimer = BiddyAssets.SeenClip.length - 0.7f;
			Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} seen by {p.playerUsername} at {((Component)this).transform.position} t={Time.time:0.00}");
			((EnemyAI)this).SwitchToBehaviourState(10 + Array.IndexOf(StartOfRound.Instance.allPlayerScripts, p));
		}

		private void SpawnGift()
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0049: 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_00bc: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			NavMeshHit val = default(NavMeshHit);
			if (NavMesh.SamplePosition(position, ref val, 2f, -1))
			{
				position = ((NavMeshHit)(ref val)).position;
			}
			GameObject obj = Object.Instantiate<GameObject>(BiddyAssets.GiftPrefab, position + Vector3.up * 0.4f, Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y, 0f), RoundManager.Instance.spawnedScrapContainer);
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			component.isInFactory = !base.isOutside;
			component.fallTime = 0f;
			NetworkObject component2 = obj.GetComponent<NetworkObject>();
			component2.Spawn(false);
			int value = Plugin.GiftValue.Value;
			component.SetScrapValue(value);
			RoundManager.Instance.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { NetworkObjectReference.op_Implicit(component2) }, new int[1] { value });
			Plugin.Log.LogInfo((object)$"peace offering left at {position}");
		}

		public override void Update()
		{
			//IL_0038: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bd: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (localState != base.currentBehaviourStateIndex)
			{
				OnEnterState(base.currentBehaviourStateIndex);
				localState = base.currentBehaviourStateIndex;
			}
			float deltaTime = Time.deltaTime;
			Vector3 val = ((Component)this).transform.position - lastPos;
			float num = ((Vector3)(ref val)).magnitude / Mathf.Max(deltaTime, 0.0001f);
			lastPos = ((Component)this).transform.position;
			smoothSpeed = Mathf.Lerp(smoothSpeed, num, Mathf.Clamp01(deltaTime * 8f));
			if (Roaming)
			{
				bool flag = smoothSpeed > 0.3f;
				base.creatureAnimator.SetBool("Walking", flag);
				AnimatorStateInfo currentAnimatorStateInfo = base.creatureAnimator.GetCurrentAnimatorStateInfo(0);
				if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Walk") && flag)
				{
					Footsteps(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime);
				}
				else
				{
					lastWalkFrame = -1f;
				}
				if (flag)
				{
					standingTime = 0f;
					if (!((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Walk") && !base.creatureAnimator.IsInTransition(0))
					{
						base.creatureAnimator.CrossFadeInFixedTime("Walk", 0.25f);
					}
				}
				else if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Idle"))
				{
					standingTime += deltaTime;
					idleBreakTimer -= deltaTime;
					if (idleBreakTimer <= 0f && standingTime > 1.5f)
					{
						idleBreakTimer = Random.Range(8f, 16f);
						base.creatureAnimator.CrossFadeInFixedTime((Random.value < 0.5f) ? "IdleBreak1" : "IdleBreak2", 0.3f);
					}
				}
			}
			else
			{
				base.creatureAnimator.SetBool("Walking", false);
			}
			if (IsSeenState(base.currentBehaviourStateIndex) && ((NetworkBehaviour)this).IsOwner && (Object)(object)seer != (Object)null)
			{
				Vector3 val2 = ((Component)seer).transform.position - ((Component)this).transform.position;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
				{
					((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(val2), 300f * deltaTime);
				}
			}
			if (base.currentBehaviourStateIndex != 4)
			{
				return;
			}
			AnimateVanish(deltaTime);
			if (((NetworkBehaviour)this).IsOwner && vanishTimer >= 3f && !giftSpawned)
			{
				giftSpawned = true;
				if (((NetworkBehaviour)this).IsServer)
				{
					SpawnGift();
				}
				((EnemyAI)this).KillEnemyOnOwnerClient(true);
			}
		}

		private void OnEnterState(int state)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			if (IsSeenState(state))
			{
				base.creatureVoice.Stop();
				PlayVoice(BiddyAssets.SeenClip);
				base.creatureAnimator.CrossFadeInFixedTime("Confident", 0.25f);
				if (Plugin.Cutscene.Value && (Object)(object)Spotter == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					BiddyCutscene.Play(this);
				}
				return;
			}
			switch (state)
			{
			case 1:
				PlayVoice(BiddyAssets.ScribDoon);
				Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} unseen line: scrib-doon at {((Component)this).transform.position} t={Time.time:0.0}");
				break;
			case 2:
				PlayVoice(BiddyAssets.DingDong);
				Plugin.Log.LogInfo((object)$"Biddy #{((NetworkBehaviour)this).NetworkObjectId} unseen line: ding-dong at {((Component)this).transform.position} t={Time.time:0.0}");
				break;
			case 4:
			{
				base.inSpecialAnimation = true;
				vanishTimer = 0f;
				base.creatureAnimator.CrossFadeInFixedTime("Laugh", 0.2f);
				GameObject val = new GameObject("BiddyGlow");
				val.transform.SetParent(model, false);
				val.transform.localPosition = new Vector3(0f, 0.7f, 0f);
				glow = GameObjectExtension.AddHDLight(val, (HDLightTypeAndShape)0);
				glow.SetColor(new Color(1f, 0.85f, 0.45f), -1f);
				glow.SetRange(8f);
				glow.EnableShadows(false);
				glow.SetIntensity(0f, (LightUnit)0);
				if (Object.op_Implicit((Object)(object)BiddyAssets.SpinUp))
				{
					base.creatureSFX.clip = BiddyAssets.SpinUp;
					base.creatureSFX.time = Mathf.Max(0f, 2.09f);
					base.creatureSFX.Play();
				}
				break;
			}
			case 3:
				break;
			}
		}

		private void Footsteps(float normalizedTime)
		{
			float num = (normalizedTime - Mathf.Floor(normalizedTime)) * 120f;
			if (lastWalkFrame >= 0f)
			{
				float[] stepFrames = StepFrames;
				foreach (float num2 in stepFrames)
				{
					bool num3;
					if (!(lastWalkFrame <= num))
					{
						if (num2 > lastWalkFrame)
						{
							goto IL_005d;
						}
						num3 = num2 <= num;
					}
					else
					{
						if (!(num2 > lastWalkFrame))
						{
							continue;
						}
						num3 = num2 <= num;
					}
					if (!num3)
					{
						continue;
					}
					goto IL_005d;
					IL_005d:
					Step();
					break;
				}
			}
			lastWalkFrame = num;
		}

		private void Step()
		{
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if (!Object.op_Implicit((Object)(object)stepAudio) || Plugin.FootstepVolume.Value <= 0f || (Object)(object)instance == (Object)null || instance.footstepSurfaces == null || instance.footstepSurfaces.Length == 0)
			{
				return;
			}
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)this).transform.position + Vector3.up, Vector3.down, ref val, 6f, instance.walkableSurfacesMask, (QueryTriggerInteraction)1))
			{
				for (int i = 0; i < instance.footstepSurfaces.Length; i++)
				{
					if (((Component)((RaycastHit)(ref val)).collider).CompareTag(instance.footstepSurfaces[i].surfaceTag))
					{
						surfaceIndex = i;
						break;
					}
				}
			}
			AudioClip[] clips = instance.footstepSurfaces[Mathf.Clamp(surfaceIndex, 0, instance.footstepSurfaces.Length - 1)].clips;
			if (clips != null && clips.Length != 0)
			{
				int num = Random.Range(0, clips.Length);
				if (num == lastStepClip && clips.Length > 1)
				{
					num = (num + 1) % clips.Length;
				}
				lastStepClip = num;
				stepAudio.pitch = Random.Range(0.93f, 1.07f);
				stepAudio.PlayOneShot(clips[num], Plugin.FootstepVolume.Value * Random.Range(0.8f, 1f));
			}
		}

		internal void PlayVoice(AudioClip clip)
		{
			base.creatureVoice.PlayOneShot(clip);
			WalkieTalkie.TransmitOneShotAudio(base.creatureVoice, clip, 1f);
		}

		private void AnimateVanish(float dt)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			vanishTimer += dt;
			float num = Mathf.Clamp01(vanishTimer / 3f);
			model.localPosition = modelBaseLocal + Vector3.up * (4f * num * num);
			model.localRotation = modelBaseRot * Quaternion.Euler(0f, 1500f * num * num * 3f / 2f + 90f * vanishTimer, 0f);
			if (Object.op_Implicit((Object)(object)glow))
			{
				glow.SetIntensity(Mathf.Lerp(0f, 3000f, num * num), (LightUnit)0);
			}
			if (num >= 0.92f && !flashed)
			{
				flashed = true;
				BiddyAssets.VanishFlash(model.position + Vector3.up * 0.7f);
				BiddyAssets.PlayAt(BiddyAssets.VanishPop, model.position + Vector3.up * 0.7f, 45f);
				((EnemyAI)this).EnableEnemyMesh(false, false, false);
				if (Object.op_Implicit((Object)(object)glow))
				{
					glow.SetIntensity(0f, (LightUnit)0);
				}
			}
		}
	}
	internal static class BiddyAssets
	{
		internal static EnemyType BiddyType;

		internal static GameObject BiddyPrefab;

		internal static Item GiftItem;

		internal static GameObject GiftPrefab;

		internal static Item PlushieItem;

		internal static GameObject PlushiePrefab;

		internal static AudioClip PlushieSqueeze;

		private const float PlushieScale = 0.26f;

		internal static AudioClip ScribDoon;

		internal static AudioClip DingDong;

		internal static AudioClip SeenClip;

		internal static AudioClip Taunt;

		internal static AudioClip MineBlast;

		internal static AudioClip SpinUp;

		internal static AudioClip VanishPop;

		internal const float SpinUpCutoff = 4.85f;

		internal static AudioMixerGroup SfxGroup;

		internal static GameObject FlashPrefab;

		internal static GameObject JceModel;

		internal static AudioClip JceTrickIn;

		internal static AudioClip JceTrickOut;

		internal static AudioClip JceStart;

		internal static AudioClip JceDash;

		internal static AudioClip JceAttack;

		internal static AudioClip JceSlow;

		internal static AudioClip JceRev;

		internal static AudioClip JceLanding;

		internal static AudioClip JceSheath;

		internal static AudioClip JceFinish;

		internal static AudioClip JceMusic;

		private static bool finished;

		private static readonly Dictionary<string, string> TexturePrefix = new Dictionary<string, string>
		{
			{ "MI_Carrot_Outfit", "T_Carrot_Outfit" },
			{ "MI_Carrot_Chains", "T_Carrot_Chains" },
			{ "MI_Carrot_Head", "T_Carrot_Head" },
			{ "MI_Carrot_Helmet", "T_Carrot_Acc_Helmet" },
			{ "MI_Carrot_Glass", "T_Carrot_Glass" },
			{ "MI_Yamato_Main", "T_Yamato_Main" },
			{ "MI_Yamato_Guard", "T_Yamato_Guard" }
		};

		private static readonly Dictionary<string, (Color color, float metal, float smooth, float glow)> BikeSurfaces = new Dictionary<string, (Color, float, float, float)>
		{
			["AluminumSmooth"] = (new Color(0.78f, 0.79f, 0.8f), 0.9f, 0.65f, 0f),
			["BrassSmooth"] = (new Color(0.55f, 0.43f, 0.26f), 1f, 0.5f, 0f),
			["HeatedNickelSmooth"] = (new Color(0.56f, 0.5f, 0.46f), 1f, 0.55f, 0f),
			["MagnesiumMatt"] = (new Color(0.5f, 0.5f, 0.52f), 1f, 0.35f, 0f),
			["NickelMattClean"] = (new Color(0.62f, 0.6f, 0.57f), 1f, 0.45f, 0f),
			["NickelMattDirty"] = (new Color(0.4f, 0.38f, 0.35f), 1f, 0.3f, 0f),
			["PanelSteelRough"] = (new Color(0.45f, 0.45f, 0.47f), 1f, 0.3f, 0f),
			["PaintedMetalBlack"] = (new Color(0.04f, 0.04f, 0.04f), 0.4f, 0.45f, 0f),
			["LeatherRough"] = (new Color(0.12f, 0.07f, 0.045f), 0f, 0.3f, 0f),
			["RubberRough"] = (new Color(0.02f, 0.02f, 0.02f), 0f, 0.2f, 0f),
			["Livery"] = (new Color(0.36f, 0.06f, 0.06f), 0.25f, 0.55f, 0f),
			["Headlight"] = (new Color(1f, 0.95f, 0.85f), 0f, 0.9f, 60f),
			["Heat"] = (new Color(1f, 0.3f, 0.05f), 0f, 0.5f, 2.5f),
			["Sign"] = (new Color(1f, 0.6f, 0.1f), 0f, 0.5f, 4f)
		};

		internal static float CleanMusicBoost = 1.86f;

		internal static void CreateEnemy()
		{
			//IL_0197: 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_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Expected O, but got Unknown
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Expected O, but got Unknown
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f2: Expected O, but got Unknown
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			AssetBundle bundle = Plugin.Bundle;
			ScribDoon = bundle.LoadAsset<AudioClip>("Biddy_ScribDoon");
			DingDong = bundle.LoadAsset<AudioClip>("Biddy_DingDong");
			SeenClip = bundle.LoadAsset<AudioClip>("Biddy_Seen");
			Taunt = bundle.LoadAsset<AudioClip>("Biddy_Taunt");
			JceTrickIn = bundle.LoadAsset<AudioClip>("JCE_TrickIn");
			JceTrickOut = bundle.LoadAsset<AudioClip>("JCE_TrickOut");
			JceStart = bundle.LoadAsset<AudioClip>("JCE_Start");
			JceDash = bundle.LoadAsset<AudioClip>("JCE_Dash");
			JceAttack = bundle.LoadAsset<AudioClip>("JCE_Attack");
			JceSlow = bundle.LoadAsset<AudioClip>("JCE_Slow");
			JceRev = bundle.LoadAsset<AudioClip>("JCE_Rev");
			JceLanding = bundle.LoadAsset<AudioClip>("JCE_Landing");
			JceSheath = bundle.LoadAsset<AudioClip>("JCE_Sheath");
			JceFinish = bundle.LoadAsset<AudioClip>("JCE_Finish");
			JceMusic = bundle.LoadAsset<AudioClip>("JCE_Music");
			float value = Plugin.ModelScale.Value;
			BiddyPrefab = NetworkPrefabs.CreateNetworkPrefab("BiddyBlasEnemy");
			NavMeshAgent obj = BiddyPrefab.AddComponent<NavMeshAgent>();
			obj.speed = Plugin.WalkSpeed.Value;
			obj.angularSpeed = 240f;
			obj.acceleration = 8f;
			obj.radius = 0.35f * value;
			obj.height = 1.3f * value;
			obj.obstacleAvoidanceType = (ObstacleAvoidanceType)1;
			BiddyAI biddyAI = BiddyPrefab.AddComponent<BiddyAI>();
			GameObject val = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("BiddyModel"), BiddyPrefab.transform);
			((Object)val).name = "Model";
			val.transform.localScale = Vector3.one * value;
			foreach (Renderer item in (from r in val.GetComponentsInChildren<Renderer>(true)
				where ((Object)r).name.StartsWith("Yamato")
				select r).ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			biddyAI.model = val.transform;
			JceModel = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("BiddyModel"));
			((Object)JceModel).name = "BiddyJceModel";
			JceModel.transform.localScale = Vector3.one * value;
			JceModel.SetActive(false);
			((Object)JceModel).hideFlags = (HideFlags)61;
			((EnemyAI)biddyAI).creatureAnimator = val.GetComponent<Animator>();
			Transform transform = new GameObject("Eye").transform;
			transform.SetParent(BiddyPrefab.transform, false);
			transform.localPosition = new Vector3(0f, 1.15f * value, 0.1f);
			((EnemyAI)biddyAI).eye = transform;
			GameObject val2 = new GameObject("Collision")
			{
				layer = 19
			};
			val2.transform.SetParent(BiddyPrefab.transform, false);
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = new Vector3(0.8f, 1.3f, 0.8f) * value;
			obj2.center = new Vector3(0f, 0.65f * value, 0f);
			val2.AddComponent<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)biddyAI;
			GameObject val3 = new GameObject("ScanNode")
			{
				layer = 22
			};
			val3.transform.SetParent(BiddyPrefab.transform, false);
			val3.transform.localPosition = new Vector3(0f, 0.8f * value, 0f);
			((Collider)val3.AddComponent<BoxCollider>()).isTrigger = true;
			ScanNodeProperties obj3 = val3.AddComponent<ScanNodeProperties>();
			obj3.headerText = "Biddy Blas";
			obj3.subText = "Galactic League legend (self-declared)";
			obj3.nodeType = 1;
			obj3.minRange = 1;
			obj3.maxRange = 30;
			obj3.requiresLineOfSight = true;
			GameObject val4 = new GameObject("Voice");
			val4.transform.SetParent(BiddyPrefab.transform, false);
			val4.transform.localPosition = new Vector3(0f, 1.1f * value, 0f);
			((EnemyAI)biddyAI).creatureVoice = MakeSource(val4, Plugin.VoiceRange.Value);
			val4.AddComponent<OccludeAudio>().useReverb = true;
			((EnemyAI)biddyAI).creatureSFX = MakeSource(BiddyPrefab, 40f);
			IEnumerable<string> source = new string[5] { "Roam", "AmbientScribDoon", "AmbientDingDong", "Unused", "Vanish" }.Concat(from i in Enumerable.Range(5, 5)
				select "Unused").Concat(from i in Enumerable.Range(0, 64)
				select "Seen" + i);
			((EnemyAI)biddyAI).enemyBehaviourStates = source.Select((Func<string, EnemyBehaviourState>)((string n) => new EnemyBehaviourState
			{
				name = n,
				parameterString = "Walking",
				boolValue = false
			})).ToArray();
			((EnemyAI)biddyAI).enemyHP = 3;
			((EnemyAI)biddyAI).AIIntervalTime = 0.2f;
			((EnemyAI)biddyAI).updatePositionThreshold = 0.4f;
			BiddyType = ScriptableObject.CreateInstance<EnemyType>();
			((Object)BiddyType).name = "BiddyBlas";
			BiddyType.enemyName = "Biddy Blas";
			BiddyType.enemyPrefab = BiddyPrefab;
			BiddyType.probabilityCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
			{
				new Keyframe(0f, 1f),
				new Keyframe(1f, 1f)
			});
			BiddyType.isDaytimeEnemy = false;
			BiddyType.useNumberSpawnedFalloff = false;
			BiddyType.numberSpawnedFalloff = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
			{
				new Keyframe(0f, 1f),
				new Keyframe(1f, 1f)
			});
			BiddyType.spawnInGroupsOf = 1;
			BiddyType.PowerLevel = 1f;
			BiddyType.MaxCount = 1;
			BiddyType.isOutsideEnemy = false;
			BiddyType.canBeStunned = false;
			BiddyType.canDie = false;
			BiddyType.destroyOnDeath = true;
			BiddyType.pushPlayerForce = 0f;
			BiddyType.pushPlayerDistance = 0f;
			BiddyType.SizeLimit = (NavSizeLimit)0;
			BiddyType.miscAnimations = (MiscAnimation[])(object)new MiscAnimation[0];
			BiddyType.audioClips = (AudioClip[])(object)new AudioClip[3] { ScribDoon, DingDong, SeenClip };
			((EnemyAI)biddyAI).enemyType = BiddyType;
			TerminalNode val5 = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)val5).name = "BiddyBlasFile";
			val5.creatureName = "Biddy Blas";
			val5.clearPreviousText = true;
			val5.maxCharactersToType = 35;
			val5.displayText = "BIDDY BLAS\n\nSigurd's danger level: Mostly to your ego\n\nA pilot of the Galactic League who insists, loudly and often, that he has never lost a race. Crews report muttering in empty hallways and the shuffle of small clawed feet where nobody should be.\n\nMerchandise: a Biddy plushie has turned up in several facilities. It squeaks. The Company will buy it.\n\n";
			TerminalKeyword val6 = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)val6).name = "BiddyBlasKeyword";
			val6.word = "biddy";
			Enemies.RegisterEnemy(BiddyType, Plugin.SpawnWeight.Value, (LevelTypes)(-1), val5, val6);
		}

		internal static void CreateGift()
		{
			//IL_0043: 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)
			GiftPrefab = NetworkPrefabs.CreateNetworkPrefab("BiddyPeaceOffering");
			GiftPrefab.GetComponent<NetworkObject>().AutoObjectParentSync = false;
			GiftPrefab.layer = 6;
			GiftPrefab.tag = "PhysicsProp";
			GiftPrefab.AddComponent<BoxCollider>().size = Vector3.one * 0.5f;
			GiftPrefab.AddComponent<MeshFilter>();
			GiftPrefab.AddComponent<MeshRenderer>();
			MakeSource(GiftPrefab, 25f);
			GiftItem = ScriptableObject.CreateInstance<Item>();
			((Object)GiftItem).name = "BiddyPeaceOffering";
			SetGiftItemFields();
			PeaceOfferingItem peaceOfferingItem = GiftPrefab.AddComponent<PeaceOfferingItem>();
			((GrabbableObject)peaceOfferingItem).itemProperties = GiftItem;
			((GrabbableObject)peaceOfferingItem).grabbable = true;
			((GrabbableObject)peaceOfferingItem).grabbableToEnemies = false;
			((GrabbableObject)peaceOfferingItem).customGrabTooltip = "Accept Biddy's Peace Offering : [E]";
			Items.RegisterItem(GiftItem);
		}

		internal static void CreatePlushie()
		{
			//IL_0067: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			PlushieSqueeze = Plugin.Bundle.LoadAsset<AudioClip>("Plushie_Squeeze");
			PlushiePrefab = NetworkPrefabs.CreateNetworkPrefab("BiddyPlushie");
			PlushiePrefab.GetComponent<NetworkObject>().AutoObjectParentSync = false;
			PlushiePrefab.layer = 6;
			PlushiePrefab.tag = "PhysicsProp";
			BoxCollider obj = PlushiePrefab.AddComponent<BoxCollider>();
			obj.size = new Vector3(0.22f, 0.36f, 0.22f);
			obj.center = new Vector3(0f, 0.18f, 0f);
			GameObject val = Object.Instantiate<GameObject>(Plugin.Bundle.LoadAsset<GameObject>("BiddyModel"), PlushiePrefab.transform);
			((Object)val).name = "Model";
			val.transform.localScale = Vector3.one * 0.26f;
			foreach (Renderer item in (from r in val.GetComponentsInChildren<Renderer>(true)
				where ((Object)r).name.StartsWith("Yamato")
				select r).ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				((Component)componentsInChildren[num]).gameObject.layer = 6;
			}
			GameObject val2 = new GameObject("ScanNode")
			{
				layer = 22
			};
			val2.transform.SetParent(PlushiePrefab.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0.2f, 0f);
			((Collider)val2.AddComponent<BoxCollider>()).isTrigger = true;
			ScanNodeProperties obj2 = val2.AddComponent<ScanNodeProperties>();
			obj2.headerText = "Biddy plushie";
			obj2.subText = "Value: ";
			obj2.nodeType = 2;
			obj2.minRange = 1;
			obj2.maxRange = 13;
			obj2.requiresLineOfSight = true;
			GameObject val3 = new GameObject("Squeak");
			val3.transform.SetParent(PlushiePrefab.transform, false);
			val3.transform.localPosition = new Vector3(0f, 0.25f, 0f);
			AudioSource val4 = MakeSource(val3, 30f);
			PlushieItem = ScriptableObject.CreateInstance<Item>();
			((Object)PlushieItem).name = "BiddyPlushie";
			SetPlushieItemFields();
			BiddyPlushie biddyPlushie = PlushiePrefab.AddComponent<BiddyPlushie>();
			((GrabbableObject)biddyPlushie).itemProperties = PlushieItem;
			((GrabbableObject)biddyPlushie).grabbable = true;
			((GrabbableObject)biddyPlushie).grabbableToEnemies = true;
			biddyPlushie.squeak = val4;
			BiddyTalker.Attach(val.transform, val4, PlushiePrefab.transform.right);
			Items.RegisterScrap(PlushieItem, Plugin.PlushieRarity.Value, (LevelTypes)(-1));
		}

		private static void SetPlushieItemFields()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: 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)
			Item plushieItem = PlushieItem;
			plushieItem.itemName = "Biddy plushie";
			plushieItem.spawnPrefab = PlushiePrefab;
			plushieItem.isScrap = true;
			plushieItem.minValue = Mathf.RoundToInt((float)Plugin.PlushieMinValue.Value / 0.4f);
			plushieItem.maxValue = Mathf.RoundToInt((float)Mathf.Max(Plugin.PlushieMinValue.Value, Plugin.PlushieMaxValue.Value) / 0.4f);
			plushieItem.weight = 1.04f;
			plushieItem.twoHanded = false;
			plushieItem.requiresBattery = false;
			plushieItem.isConductiveMetal = false;
			plushieItem.syncUseFunction = true;
			plushieItem.holdButtonUse = false;
			plushieItem.toolTips = new string[1] { "Squeeze : [LMB]" };
			plushieItem.restingRotation = Vector3.zero;
			plushieItem.verticalOffset = 0.02f;
			plushieItem.positionOffset = new Vector3(0.02f, 0.03f, -0.08f);
			plushieItem.rotationOffset = new Vector3(90f, 90f, 0f);
			plushieItem.canBeGrabbedBeforeGameStart = true;
		}

		internal static void SpawnPlushie(Vector3 pos, bool inFactory)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(PlushiePrefab, pos + Vector3.up * 0.3f, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), RoundManager.Instance.spawnedScrapContainer);
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			component.isInFactory = inFactory;
			component.fallTime = 0f;
			NetworkObject component2 = obj.GetComponent<NetworkObject>();
			component2.Spawn(false);
			int num = Random.Range(Plugin.PlushieMinValue.Value, Mathf.Max(Plugin.PlushieMinValue.Value, Plugin.PlushieMaxValue.Value) + 1);
			component.SetScrapValue(num);
			RoundManager.Instance.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { NetworkObjectReference.op_Implicit(component2) }, new int[1] { num });
			Plugin.Log.LogInfo((object)$"plushie spawned at {pos} worth {num}");
		}

		private static void SetGiftItemFields()
		{
			GiftItem.itemName = "Biddy's peace offering?";
			GiftItem.spawnPrefab = GiftPrefab;
			GiftItem.isScrap = true;
			GiftItem.minValue = (GiftItem.maxValue = Plugin.GiftValue.Value);
			GiftItem.syncGrabFunction = true;
			GiftItem.canBeGrabbedBeforeGameStart = true;
		}

		internal static void FinishWithGameAssets()
		{
			if (finished)
			{
				return;
			}
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			Item val = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && Object.op_Implicit((Object)(object)i.spawnPrefab) && Object.op_Implicit((Object)(object)i.spawnPrefab.GetComponent<GiftBoxItem>())));
			Item val2 = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && Object.op_Implicit((Object)(object)i.spawnPrefab) && Object.op_Implicit((Object)(object)i.spawnPrefab.GetComponent<StunGrenadeItem>())));
			Landmine val3 = (from m in StartOfRound.Instance.levels.SelectMany((SelectableLevel l) => (IEnumerable<SpawnableMapObject>)(((object)l.spawnableMapObjects) ?? ((object)new SpawnableMapObject[0])))
				select (!Object.op_Implicit((Object)(object)m.prefabToSpawn)) ? null : m.prefabToSpawn.GetComponentInChildren<Landmine>()).FirstOrDefault((Func<Landmine, bool>)((Landmine m) => Object.op_Implicit((Object)(object)m)));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"vanilla gift box not found; peace offering will be invisible");
				return;
			}
			FlashPrefab = (Object.op_Implicit((Object)(object)val2) ? val2.spawnPrefab.GetComponent<StunGrenadeItem>().stunGrenadeExplosion : null);
			ShipTeleporter val4 = StartOfRound.Instance.unlockablesList.unlockables.Select((UnlockableItem u) => (!Object.op_Implicit((Object)(object)u.prefabObject)) ? null : u.prefabObject.GetComponentInChildren<ShipTeleporter>(true)).FirstOrDefault((Func<ShipTeleporter, bool>)((ShipTeleporter t) => Object.op_Implicit((Object)(object)t) && t.isInverseTeleporter));
			SpinUp = (Object.op_Implicit((Object)(object)val4) ? val4.teleporterSpinSFX : null);
			Item val5 = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && Object.op_Implicit((Object)(object)i.spawnPrefab) && Object.op_Implicit((Object)(object)i.spawnPrefab.GetComponent<StunGrenadeItem>()) && i.itemName.ToLower().Contains("egg")));
			string value = Plugin.VanishSound.Value;
			if (!(value == "Flashbang"))
			{
				if (value == "TeleporterBeam")
				{
					VanishPop = (Object.op_Implicit((Object)(object)val4) ? val4.teleporterBeamUpSFX : null);
				}
				else
				{
					VanishPop = (Object.op_Implicit((Object)(object)val5) ? val5.spawnPrefab.GetComponent<StunGrenadeItem>().explodeSFX : null);
				}
			}
			else
			{
				VanishPop = (Object.op_Implicit((Object)(object)val2) ? val2.spawnPrefab.GetComponent<StunGrenadeItem>().explodeSFX : null);
			}
			MineBlast = (Object.op_Implicit((Object)(object)val3) ? val3.mineDetonate : null);
			AudioSource componentInChildren = val.spawnPrefab.GetComponentInChildren<AudioSource>();
			SfxGroup = ((componentInChildren != null) ? componentInChildren.outputAudioMixerGroup : null);
			FieldInfo[] fields = typeof(Item).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name != "itemId" && fieldInfo.Name != "name")
				{
					fieldInfo.SetValue(GiftItem, fieldInfo.GetValue(val));
				}
			}
			SetGiftItemFields();
			CopyGiftVisuals(val.spawnPrefab);
			Item obj = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && i.itemName == "Rubber Ducky")) ?? val;
			fields = typeof(Item).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo2 in fields)
			{
				if (fieldInfo2.Name != "itemId" && fieldInfo2.Name != "name")
				{
					fieldInfo2.SetValue(PlushieItem, fieldInfo2.GetValue(obj));
				}
			}
			SetPlushieItemFields();
			Material val6 = val.spawnPrefab.GetComponentsInChildren<Renderer>().SelectMany((Renderer r) => r.sharedMaterials).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "HDRP/Lit"));
			if ((Object)(object)val6 == (Object)null)
			{
				Plugin.Log.LogError((object)"no HDRP/Lit template material found");
			}
			else
			{
				ApplyMaterials(BiddyPrefab, val6);
				ApplyMaterials(JceModel, val6);
				ApplyMaterials(PlushiePrefab, val6);
				MakeDriveByTemplates(val6);
			}
			foreach (AudioSource item in BiddyPrefab.GetComponentsInChildren<AudioSource>(true).Concat(GiftPrefab.GetComponentsInChildren<AudioSource>(true)).Concat(PlushiePrefab.GetComponentsInChildren<AudioSource>(true)))
			{
				item.outputAudioMixerGroup = SfxGroup;
			}
			finished = true;
			Plugin.Log.LogInfo((object)($"finished with game assets (flash={(Object)(object)FlashPrefab != (Object)null}, mine sound={(Object)(object)MineBlast != (Object)null}, mixer={(Object)(object)SfxGroup != (Object)null}, " + string.Format("spin-up={0}, vanish={1}, jce sounds={2})", Object.op_Implicit((Object)(object)SpinUp) ? ((Object)SpinUp).name : "none", Object.op_Implicit((Object)(object)VanishPop) ? ((Object)VanishPop).name : "none", (Object)(object)JceAttack != (Object)null && (Object)(object)JceSheath != (Object)null)));
		}

		private static void CopyGiftVisuals(GameObject src)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_021b: 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)
			MeshFilter component = src.GetComponent<MeshFilter>();
			MeshRenderer component2 = src.GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2))
			{
				GiftPrefab.GetComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				((Renderer)GiftPrefab.GetComponent<MeshRenderer>()).sharedMaterials = ((Renderer)component2).sharedMaterials;
			}
			GiftPrefab.transform.localScale = src.transform.localScale;
			BoxCollider component3 = src.GetComponent<BoxCollider>();
			BoxCollider component4 = GiftPrefab.GetComponent<BoxCollider>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component4.center = component3.center;
				component4.size = component3.size;
			}
			foreach (Transform item in src.transform)
			{
				Transform val = item;
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, GiftPrefab.transform, false);
				((Object)val2).name = ((Object)val).name;
				Component[] componentsInChildren = val2.GetComponentsInChildren<Component>(true);
				foreach (Component val3 in componentsInChildren)
				{
					if (!(val3 is Transform) && !(val3 is MeshFilter) && !(val3 is Renderer) && !(val3 is Collider) && !(val3 is ScanNodeProperties) && !(val3 is ParticleSystem))
					{
						Object.DestroyImmediate((Object)(object)val3);
					}
				}
				ScanNodeProperties[] componentsInChildren2 = val2.GetComponentsInChildren<ScanNodeProperties>(true);
				foreach (ScanNodeProperties obj in componentsInChildren2)
				{
					obj.headerText = "Biddy's peace offering?";
					obj.subText = $"Value: ${Plugin.GiftValue.Value}";
				}
			}
			PeaceOfferingItem component5 = GiftPrefab.GetComponent<PeaceOfferingItem>();
			((GrabbableObject)component5).mainObjectRenderer = GiftPrefab.GetComponent<MeshRenderer>();
			if (!Object.op_Implicit((Object)(object)((Renderer)((GrabbableObject)component5).mainObjectRenderer).sharedMaterial))
			{
				((GrabbableObject)component5).mainObjectRenderer = ((IEnumerable<MeshRenderer>)GiftPrefab.GetComponentsInChildren<MeshRenderer>()).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => Object.op_Implicit((Object)(object)((Renderer)r).sharedMaterial)));
			}
			GrabbableObject component6 = src.GetComponent<GrabbableObject>();
			((GrabbableObject)component5).originalScale = component6.originalScale;
			((GrabbableObject)component5).floorYRot = component6.floorYRot;
		}

		private static void ApplyMaterials(GameObject root, Material template)
		{
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					string text = (Object.op_Implicit((Object)(object)sharedMaterials[j]) ? ((Object)sharedMaterials[j]).name.Replace(" (Instance)", "") : "");
					if (TexturePrefix.TryGetValue(text, out var value))
					{
						sharedMaterials[j] = MakeLit(template, text, value);
					}
				}
				val.sharedMaterials = sharedMaterials;
			}
		}

		internal static void ClearHideFlags(GameObject go)
		{
			Transform[] componentsInChildren = go.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Object)((Component)componentsInChildren[i]).gameObject).hideFlags = (HideFlags)0;
			}
		}

		private static void MakeDriveByTemplates(Material template)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			GameObject val = Plugin.Bundle.LoadAsset<GameObject>("BiddyBike");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"BiddyBike not in the asset bundle; no drive-by");
				return;
			}
			GameObject val2 = new GameObject("BiddyBikeTemplate");
			val2.SetActive(false);
			((Object)Object.Instantiate<GameObject>(val, val2.transform, false)).name = "Mesh";
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren)
			{
				obj.sharedMaterials = obj.sharedMaterials.Select((Material m) => BikeLit(template, Object.op_Implicit((Object)(object)m) ? ((Object)m).name.Replace(" (Instance)", "") : "")).ToArray();
				obj.shadowCastingMode = (ShadowCastingMode)1;
			}
			Transform[] componentsInChildren2 = val2.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Object)((Component)componentsInChildren2[i]).gameObject).hideFlags = (HideFlags)61;
			}
			BiddyDriveBy.BikeTemplate = val2;
			GameObject val3 = Object.Instantiate<GameObject>(Plugin.Bundle.LoadAsset<GameObject>("BiddyModel"));
			((Object)val3).name = "BiddyRiderTemplate";
			val3.SetActive(false);
			foreach (Renderer item in (from r in val3.GetComponentsInChildren<Renderer>(true)
				where ((Object)r).name.StartsWith("Yamato")
				select r).ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			ApplyMaterials(val3, template);
			componentsInChildren2 = val3.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Object)((Component)componentsInChildren2[i]).gameObject).hideFlags = (HideFlags)61;
			}
			BiddyDriveBy.RiderTemplate = val3;
		}

		private static Material BikeLit(Material template, string name)
		{
			//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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			string text = BikeSurfaces.Keys.FirstOrDefault((string k) => name.Contains(k));
			Color val;
			float num;
			float num2;
			float num3;
			if (text != null)
			{
				(val, num, num2, num3) = BikeSurfaces[text];
			}
			else
			{
				Color val2 = new Color(0.4f, 0.4f, 0.42f);
				float num4 = 0.6f;
				float num5 = 0.4f;
				num3 = 0f;
				num2 = num5;
				num = num4;
				val = val2;
			}
			Material val3 = new Material(template)
			{
				name = "BiddyBike_" + (text ?? "Other")
			};
			string[] shaderKeywords = val3.shaderKeywords;
			foreach (string text2 in shaderKeywords)
			{
				val3.DisableKeyword(text2);
			}
			shaderKeywords = new string[5] { "_BaseColorMap", "_NormalMap", "_MaskMap", "_DetailMap", "_EmissiveColorMap" };
			foreach (string text3 in shaderKeywords)
			{
				val3.SetTexture(text3, (Texture)null);
			}
			val3.SetColor("_BaseColor", val);
			val3.SetFloat("_Metallic", num);
			val3.SetFloat("_Smoothness", num2);
			val3.SetColor("_EmissiveColor", (num3 > 0f) ? (val * num3) : Color.black);
			HDMaterial.SetSurfaceType(val3, false);
			HDMaterial.ValidateMaterial(val3);
			return val3;
		}

		private static Material MakeLit(Material template, string name, string prefix)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			AssetBundle bundle = Plugin.Bundle;
			Material val = new Material(template)
			{
				name = name + "_HDRP"
			};
			string[] shaderKeywords = val.shaderKeywords;
			foreach (string text in shaderKeywords)
			{
				val.DisableKeyword(text);
			}
			val.SetColor("_BaseColor", Color.white);
			val.SetTexture("_BaseColorMap", (Texture)(object)bundle.LoadAsset<Texture2D>(prefix + "_D"));
			Texture2D val2 = bundle.LoadAsset<Texture2D>(prefix + "_N");
			val.SetTexture("_NormalMap", (Texture)(object)val2);
			val.SetFloat("_NormalScale", 1f);
			Texture2D val3 = bundle.LoadAsset<Texture2D>(prefix + "_Mask");
			val.SetTexture("_MaskMap", (Texture)(object)val3);
			val.SetFloat("_Metallic", 0f);
			val.SetFloat("_Smoothness", 0.4f);
			val.SetFloat("_MetallicRemapMin", 0f);
			val.SetFloat("_MetallicRemapMax", 1f);
			val.SetFloat("_SmoothnessRemapMin", 0f);
			val.SetFloat("_SmoothnessRemapMax", 1f);
			val.SetFloat("_AORemapMin", 0f);
			val.SetFloat("_AORemapMax", 1f);
			val.SetTexture("_DetailMap", (Texture)null);
			val.SetTexture("_EmissiveColorMap", (Texture)null);
			val.SetColor("_EmissiveColor", Color.black);
			if (name == "MI_Carrot_Glass")
			{
				val.SetColor("_BaseColor", new Color(0.6f, 0.7f, 0.75f, 0.35f));
				val.SetTexture("_MaskMap", (Texture)null);
				val.SetFloat("_Smoothness", 0.95f);
				HDMaterial.SetSurfaceType(val, true);
			}
			else
			{
				HDMaterial.SetSurfaceType(val, false);
			}
			HDMaterial.ValidateMaterial(val);
			return val;
		}

		internal static AudioSource MakeSource(GameObject go, float maxDistance)
		{
			AudioSource obj = go.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = maxDistance;
			obj.dopplerLevel = 0f;
			obj.outputAudioMixerGroup = SfxGroup;
			return obj;
		}

		internal static void PlayAt(AudioClip clip, Vector3 pos, float maxDistance = 40f, float volume = 1f, float skip = 0f)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0026: Expected O, but got Unknown
			//IL_0083: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)clip))
			{
				GameObject val = new GameObject("BiddySound");
				val.transform.position = pos;
				AudioSource val2 = MakeSource(val, maxDistance);
				if (skip > 0f)
				{
					val2.clip = clip;
					val2.volume = volume;
					val2.time = Mathf.Min(skip, clip.length - 0.01f);
					val2.Play();
				}
				else
				{
					val2.PlayOneShot(clip, volume);
					WalkieTalkie.TransmitOneShotAudio(val2, clip, volume);
				}
				Object.Destroy((Object)val, clip.length - skip + 0.5f);
			}
		}

		internal static void PlayMusic(AudioClip clip, float volume = 1f, bool roomEffects = false)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)clip))
			{
				GameObject val = new GameObject("BiddyMusic");
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.playOnAwake = false;
				val2.spatialBlend = 0f;
				AudioSource val3 = (Object.op_Implicit((Object)(object)SoundManager.Instance) ? SoundManager.Instance.musicSource : null);
				val2.outputAudioMixerGroup = (roomEffects ? SfxGroup : (Object.op_Implicit((Object)(object)val3) ? val3.outputAudioMixerGroup : null));
				val2.bypassListenerEffects = !roomEffects;
				val2.bypassReverbZones = !roomEffects;
				Plugin.Log.LogInfo((object)("music via " + (Object.op_Implicit((Object)(object)val2.outputAudioMixerGroup) ? (((Object)val2.outputAudioMixerGroup.audioMixer).name + "/" + ((Object)val2.outputAudioMixerGroup).name) : "master") + " (sfx was " + (Object.op_Implicit((Object)(object)SfxGroup) ? (((Object)SfxGroup.audioMixer).name + "/" + ((Object)SfxGroup).name) : "none") + ")"));
				val2.PlayOneShot(clip, roomEffects ? volume : (volume * CleanMusicBoost));
				Object.Destroy((Object)(object)val, clip.length + 0.5f);
			}
		}

		internal static void VanishFlash(Vector3 pos)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0094: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)FlashPrefab))
			{
				GameObject val = Object.Instantiate<GameObject>(FlashPrefab, pos, Quaternion.identity);
				AudioSource[] componentsInChildren = val.GetComponentsInChildren<AudioSource>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].mute = true;
				}
				HDAdditionalLightData[] componentsInChildren2 = val.GetComponentsInChildren<HDAdditionalLightData>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					componentsInChildren2[i].EnableShadows(false);
				}
				val.SetActive(true);
				Object.Destroy((Object)(object)val, 5f);
			}
			GameObject val2 = new GameObject("BiddyVanishFX");
			val2.transform.position = pos;
			val2.AddComponent<VanishBurst>();
			Object.Destroy((Object)val2, 3f);
		}

		internal static void BlinkFlash(Vector3 pos)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			GameObject val = new GameObject("BiddyBlinkFX");
			val.transform.position = pos;
			VanishBurst vanishBurst = val.AddComponent<VanishBurst>();
			vanishBurst.intensity = 2500f;
			vanishBurst.color = new Color(0.6f, 0.8f, 1f);
			Object.Destroy((Object)val, 3f);
		}
	}
	internal static class BiddyBlessing
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static HandleNamedMessageDelegate <>9__16_0;

			public static HandleNamedMessageDelegate <>9__16_1;

			public static HandleNamedMessageDelegate <>9__16_2;

			public static Func<(EnemyAI e, int rank, float d), bool> <>9__19_2;

			public static Func<(EnemyAI e, int rank, float d), int> <>9__19_3;

			public static Func<(EnemyAI e, int rank, float d), float> <>9__19_4;

			public static Func<(EnemyAI e, int rank, float d), EnemyAI> <>9__19_5;

			public static Func<ulong, bool> <>9__20_0;

			public static Func<ulong, bool> <>9__22_0;

			internal void <OnRoundAwake>b__16_0(ulong sender, FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				ulong enemyId = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
				int slot = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
				ServerStart(enemyId, slot);
			}

			internal void <OnRoundAwake>b__16_1(ulong sender, FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				ulong enemyId = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
				int slot = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
				OnStart(enemyId, slot);
			}

			internal void <OnRoundAwake>b__16_2(ulong sender, FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				ulong id = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
				JceScene.OnKill(FindEnemy(id));
			}

			internal bool <FindAttacker>b__19_2((EnemyAI e, int rank, float d) x)
			{
				if (x.rank >= 2)
				{
					return x.d < 30f;
				}
				return true;
			}

			internal int <FindAttacker>b__19_3((EnemyAI e, int rank, float d) x)
			{
				return x.rank;
			}

			internal float <FindAttacker>b__19_4((EnemyAI e, int rank, float d) x)
			{
				return x.d;
			}

			internal EnemyAI <FindAttacker>b__19_5((EnemyAI e, int rank, float d) x)
			{
				return x.e;
			}

			internal bool <ServerStart>b__20_0(ulong c)
			{
				return c != 0;
			}

			internal bool <ServerKillLater>b__22_0(ulong c)
			{
				return c != 0;
			}
		}

		private static float invincibleUntil;

		private const string MsgRequest = "BiddyBlas.JceRequest";

		private const string MsgStart = "BiddyBlas.JceStart";

		private const string MsgKill = "BiddyBlas.JceKill";

		private static readonly HashSet<ulong> serverBusy = new HashSet<ulong>();

		internal static bool Has { get; private set; }

		internal static bool Invincible => Time.time < invincibleUntil;

		private static PlayerControllerB Local
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		internal static void Grant(PlayerControllerB p)
		{
			if (Plugin.Blessing.Value && !((Object)(object)p == (Object)null) && !((Object)(object)p != (Object)(object)Local) && !p.isPlayerDead)
			{
				Has = true;
				Plugin.Log.LogInfo((object)("blessing granted to " + p.playerUsername));
			}
		}

		internal static void Clear(string why)
		{
			if (Has)
			{
				Has = false;
				Plugin.Log.LogInfo((object)("blessing cleared (" + why + ")"));
			}
		}

		internal static void ProtectFor(float seconds)
		{
			invincibleUntil = Mathf.Max(invincibleUntil, Time.time + seconds);
		}

		internal static void OnRoundAwake()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			Clear("new round");
			serverBusy.Clear();
			CustomMessagingManager val = (Object.op_Implicit((Object)(object)NetworkManager.Singleton) ? NetworkManager.Singleton.CustomMessagingManager : null);
			if (val == null)
			{
				Plugin.Log.LogError((object)"no CustomMessagingManager; Biddy's blessing can't sync");
				return;
			}
			object obj = <>c.<>9__16_0;
			if (obj == null)
			{
				HandleNamedMessageDelegate val2 = delegate(ulong sender, FastBufferReader r)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					ulong enemyId = default(ulong);
					((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
					int slot = default(int);
					((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
					ServerStart(enemyId, slot);
				};
				<>c.<>9__16_0 = val2;
				obj = (object)val2;
			}
			val.RegisterNamedMessageHandler("BiddyBlas.JceRequest", (HandleNamedMessageDelegate)obj);
			object obj2 = <>c.<>9__16_1;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val3 = delegate(ulong sender, FastBufferReader r)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					ulong enemyId = default(ulong);
					((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
					int slot = default(int);
					((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
					OnStart(enemyId, slot);
				};
				<>c.<>9__16_1 = val3;
				obj2 = (object)val3;
			}
			val.RegisterNamedMessageHandler("BiddyBlas.JceStart", (HandleNamedMessageDelegate)obj2);
			object obj3 = <>c.<>9__16_2;
			if (obj3 == null)
			{
				HandleNamedMessageDelegate val4 = delegate(ulong sender, FastBufferReader r)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					ulong id = default(ulong);
					((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
					JceScene.OnKill(FindEnemy(id));
				};
				<>c.<>9__16_2 = val4;
				obj3 = (object)val4;
			}
			val.RegisterNamedMessageHandler("BiddyBlas.JceKill", (HandleNamedMessageDelegate)obj3);
		}

		internal static bool TrySave(PlayerControllerB p, CauseOfDeath cause)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!Has || !Plugin.Blessing.Value || (Object)(object)p != (Object)(object)Local)
			{
				return false;
			}
			EnemyAI val = FindAttacker(p);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogInfo((object)$"lethal {cause} not from a monster; blessing kept");
				return false;
			}
			Has = false;
			Plugin.Log.LogInfo((object)$"blessing used: {p.playerUsername} saved from {val.enemyType.enemyName} #{((NetworkBehaviour)val).NetworkObjectId} ({cause})");
			((MonoBehaviour)StartOfRound.Instance).StartCoroutine(ReleaseNextFrame(val, p));
			p.enemyWaitingForBodyRagdoll = null;
			p.inSpecialInteractAnimation = false;
			p.inAnimationWithEnemy = null;
			p.snapToServerPosition = false;
			p.health = Plugin.BlessingHealth.Value;
			if (p.health >= 10 && p.criticallyInjured)
			{
				p.MakeCriticallyInjured(false);
			}
			HUDManager.Instance.UpdateHealthUI(p.health, false);
			HUDManager.Instance.SetCracksOnVisor((float)p.health);
			ProtectFor(11.719999f);
			int slot = Array.IndexOf(StartOfRound.Instance.allPlayerScripts, p);
			JceScene.Begin(val, p);
			if (NetworkManager.Singleton.IsServer)
			{
				ServerStart(((NetworkBehaviour)val).NetworkObjectId, slot);
			}
			else
			{
				Send("BiddyBlas.JceRequest", 0uL, ((NetworkBehaviour)val).NetworkObjectId, slot);
			}
			return true;
		}

		private static IEnumerator ReleaseNextFrame(EnemyAI enemy, PlayerControllerB p)
		{
			yield return null;
			if (Object.op_Implicit((Object)(object)enemy))
			{
				((MonoBehaviour)enemy).StopAllCoroutines();
				if ((Object)(object)enemy.inSpecialAnimationWithPlayer == (Object)(object)p)
				{
					enemy.CancelSpecialAnimationWithPlayer();
				}
				p.inSpecialInteractAnimation = false;
				p.inAnimationWithEnemy = null;
				p.snapToServerPosition = false;
			}
		}

		private static EnemyAI FindAttacker(PlayerControllerB p)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Type> types = new HashSet<Type>();
			StackFrame[] array = new StackTrace(1, fNeedFileInfo: false).GetFrames() ?? new StackFrame[0];
			for (int i = 0; i < array.Length; i++)
			{
				Type type = array[i].GetMethod()?.DeclaringType;
				while (type != null && !typeof(EnemyAI).IsAssignableFrom(type) && type.IsNested)
				{
					type = type.DeclaringType;
				}
				if (type != null && typeof(EnemyAI).IsAssignableFrom(type) && type != typeof(EnemyAI) && type != typeof(BiddyAI))
				{
					types.Add(type);
				}
			}
			if (types.Count == 0)
			{
				return null;
			}
			Vector3 pos = ((Component)p).transform.position;
			return (from e in RoundManager.Instance.SpawnedEnemies
				where Object.op_Implicit((Object)(object)e) && !e.isEnemyDead && types.Any((Type t) => t.IsInstanceOfType(e)) && !JceScene.IsCutting(e)
				select (e: e, rank: (!((Object)(object)e.inSpecialAnimationWithPlayer == (Object)(object)p)) ? (((Object)(object)e.targetPlayer == (Object)(object)p) ? 1 : 2) : 0, d: Vector3.Distance(((Component)e).transform.position, pos)) into x
				where x.rank < 2 || x.d < 30f
				orderby x.rank, x.d
				select x.e).FirstOrDefault();
		}

		private static void ServerStart(ulong enemyId, int slot)
		{
			EnemyAI val = FindEnemy(enemyId);
			if (!((Object)(object)val == (Object)null) && !val.isEnemyDead && serverBusy.Add(enemyId))
			{
				NetworkManager singleton = NetworkManager.Singleton;
				Send("BiddyBlas.JceStart", singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList(), enemyId, slot);
				OnStart(enemyId, slot);
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(ServerKillLater(enemyId));
			}
		}

		private static void OnStart(ulong enemyId, int slot)
		{
			EnemyAI val = FindEnemy(enemyId);
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			if (Object.op_Implicit((Object)(object)val) && slot >= 0 && slot < allPlayerScripts.Length)
			{
				JceScene.Begin(val, allPlayerScripts[slot]);
			}
		}

		private static IEnumerator ServerKillLater(ulong enemyId)
		{
			yield return (object)new WaitForSeconds(7.8199997f);
			serverBusy.Remove(enemyId);
			EnemyAI val = FindEnemy(enemyId);
			if (!((Object)(object)val == (Object)null) && !val.isEnemyDead)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				Send("BiddyBlas.JceKill", singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList(), enemyId, 0);
				JceScene.OnKill(val);
				Plugin.Log.LogInfo((object)$"Judgement Cut End: {val.enemyType.enemyName} #{enemyId} (canDie={val.enemyType.canDie})");
				if (val.enemyType.canDie)
				{
					val.KillEnemyServerRpc(false);
				}
				else if (val.enemyType.canBeDestroyed)
				{
					val.KillEnemyServerRpc(true);
				}
				else if (((NetworkBehaviour)val).NetworkObject.IsSpawned)
				{
					((NetworkBehaviour)val).NetworkObject.Despawn(true);
				}
			}
		}

		private static EnemyAI FindEnemy(ulong id)
		{
			if (!Object.op_Implicit((Object)(object)NetworkManager.Singleton) || !NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value) || !Object.op_Implicit((Object)(object)value))
			{
				return null;
			}
			return ((Component)value).GetComponent<EnemyAI>();
		}

		private unsafe static void Send(string msg, ulong client, ulong id, int slot)
		{
			//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_0023: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref slot, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(msg, client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private unsafe static void Send(string msg, IReadOnlyList<ulong> clients, ulong id, int slot)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0044: Unknown result type (might be due to invalid IL or missing references)
			if (clients.Count == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref slot, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(msg, clients, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	internal static class BlessingSavePatch
	{
		[HarmonyPriority(200)]
		private static bool Prefix(PlayerControllerB __instance, CauseOfDeath causeOfDeath, bool __runOriginal)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!__runOriginal)
			{
				return false;
			}
			if (!((NetworkBehaviour)__instance).IsOwner || __instance.isPlayerDead || !__instance.AllowPlayerDeath())
			{
				return true;
			}
			return !BiddyBlessing.TrySave(__instance, causeOfDeath);
		}

		private static void Postfix(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead)
			{
				BiddyBlessing.Clear("died");
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "ShipHasLeft")]
	internal static class BlessingDayEndPatch
	{
		private static void Postfix()
		{
			BiddyBlessing.Clear("ship left");
		}
	}
	public class BiddyCameo : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<int, AudioClip> <>9__9_0;

			public static Func<AudioClip, bool> <>9__9_1;

			public static HandleNamedMessageDelegate <>9__10_0;

			public static HandleNamedMessageDelegate <>9__10_1;

			public static Func<PlayerControllerB, bool> <>9__14_0;

			public static Func<ulong, bool> <>9__20_0;

			internal AudioClip <LoadAssets>b__9_0(int i)
			{
				return Plugin.Bundle.LoadAsset<AudioClip>("Cameo_VO" + i);
			}

			internal bool <LoadAssets>b__9_1(AudioClip c)
			{
				return Object.op_Implicit((Object)(object)c);
			}

			internal void <OnRoundAwake>b__10_0(ulong sender, FastBufferReader r)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				Vector3 pos = default(Vector3);
				((FastBufferReader)(ref r)).ReadValueSafe(ref pos);
				float yaw = default(float);
				((FastBufferReader)(ref r)).ReadValueSafe<float>(ref yaw, default(ForPrimitives));
				Show(pos, yaw);
			}

			internal void <OnRoundAwake>b__10_1(ulong sender, FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				int slot = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
				int line = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref line, default(ForPrimitives));
				Spotted(slot, line);
			}

			internal bool <TryShow>b__14_0(PlayerControllerB p)
			{
				if (p.isPlayerControlled)
				{
					return !p.isPlayerDead;
				}
				return false;
			}

			internal bool <Send>b__20_0(ulong c)
			{
				return c != 0;
			}
		}

		private const string MsgShow = "BiddyBlas.CameoShow";

		private const string MsgSpotted = "BiddyBlas.CameoSpotted";

		internal static AudioClip[] Lines;

		private bool rolledThisVisit;

		private bool scheduled;

		private float showAt;

		private float shownAt;

		private float nextTry;

		private static CameoPuppet puppet;

		private static bool AtCompany
		{
			get
			{
				if (Object.op_Implicit((Object)(object)StartOfRound.Instance) && Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
				{
					return StartOfRound.Instance.currentLevel.levelID == 3;
				}
				return false;
			}
		}

		private static int Mask => StartOfRound.Instance.collidersAndRoomMaskAndDefault;

		internal static void LoadAssets()
		{
			Lines = (from i in Enumerable.Range(1, 5)
				select Plugin.Bundle.LoadAsset<AudioClip>("Cameo_VO" + i) into c
				where Object.op_Implicit((Object)(object)c)
				select c).ToArray();
		}

		internal static void OnRoundAwake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			((Component)StartOfRound.Instance).gameObject.AddComponent<BiddyCameo>();
			CustomMessagingManager val = (Object.op_Implicit((Object)(object)NetworkManager.Singleton) ? NetworkManager.Singleton.CustomMessagingManager : null);
			if (val == null)
			{
				return;
			}
			object obj = <>c.<>9__10_0;
			if (obj == null)
			{
				HandleNamedMessageDelegate val2 = delegate(ulong sender, FastBufferReader r)
				{
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0015: Unknown result type (might be due to invalid IL or missing references)
					//IL_001b: Unknown result type (might be due to invalid IL or missing references)
					Vector3 pos = default(Vector3);
					((FastBufferReader)(ref r)).ReadValueSafe(ref pos);
					float yaw = default(float);
					((FastBufferReader)(ref r)).ReadValueSafe<float>(ref yaw, default(ForPrimitives));
					Show(pos, yaw);
				};
				<>c.<>9__10_0 = val2;
				obj = (object)val2;
			}
			val.RegisterNamedMessageHandler("BiddyBlas.CameoShow", (HandleNamedMessageDelegate)obj);
			object obj2 = <>c.<>9__10_1;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val3 = delegate(ulong sender, FastBufferReader r)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					int slot = default(int);
					((FastBufferReader)(ref r)).ReadValueSafe<int>(ref slot, default(ForPrimitives));
					int line = default(int);
					((FastBufferReader)(ref r)).ReadValueSafe<int>(ref line, default(ForPrimitives));
					Spotted(slot, line);
				};
				<>c.<>9__10_1 = val3;
				obj2 = (object)val3;
			}
			val.RegisterNamedMessageHandler("BiddyBlas.CameoSpotted", (HandleNamedMessageDelegate)obj2);
		}

		private void Update()
		{
			//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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)puppet) && (instance.inShipPhase || instance.shipIsLeaving || !instance.shipHasLanded))
			{
				Object.Destroy((Object)(object)((Component)puppet).gameObject);
			}
			if (!Object.op_Implicit((Object)(object)NetworkManager.Singleton) || !NetworkManager.Singleton.IsServer)
			{
				return;
			}
			if (instance.inShipPhase || !instance.shipHasLanded)
			{
				rolledThisVisit = (scheduled = false);
			}
			else
			{
				if (!AtCompany || instance.shipIsLeaving)
				{
					return;
				}
				if (!rolledThisVisit)
				{
					rolledThisVisit = true;
					if (Plugin.Cameo.Value && Random.value < Plugin.CameoChance.Value)
					{
						scheduled = true;
						showAt = Time.time + Random.Range(15f, 90f);
						Plugin.Log.LogInfo((object)$"company cameo this visit, in {showAt - Time.time:0} s");
					}
					return;
				}
				if (scheduled && Time.time >= showAt && Time.time >= nextTry)
				{
					if (TryShow())
					{
						scheduled = false;
					}
					else
					{
						nextTry = Time.time + 3f;
					}
				}
				if (!Object.op_Implicit((Object)(object)puppet) || puppet.caught || !(Time.time - shownAt > 1f))
				{
					return;
				}
				Vector3 target = ((Component)puppet).transform.position + Vector3.up * 0.9f * Plugin.ModelScale.Value;
				PlayerControllerB val = ((IEnumerable<PlayerControllerB>)instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead && p.HasLineOfSightToPosition(target, 40f, 25, -1f, -1)));
				if ((Object)(object)val != (Object)null)
				{
					int slot = Array.IndexOf(instance.allPlayerScripts, val);
					int line = Random.Range(0, Mathf.Max(1, Lines.Length));
					Send("BiddyBlas.CameoSpotted", delegate(FastBufferWriter w)
					{
						//IL_000a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0010: 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_0026: Unknown result type (might be due to invalid IL or missing references)
						((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref slot, default(ForPrimitives));
						((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref line, default(ForPrimitives));
					});
					Spotted(slot, line);
					Plugin.Log.LogInfo((object)("company cameo: caught by " + val.playerUsername));
				}
			}
		}

		internal static bool TryShow()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)puppet) || !AtCompany || (Object)(object)BiddyDriveBy.RiderTemplate == (Object)null)
			{
				return false;
			}
			DepositItemsDesk val = Object.FindObjectOfType<DepositItemsDesk>(true);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3 val2 = (Object.op_Implicit((Object)(object)val.deskObjectsContainer) ? ((Component)val.deskObjectsContainer).transform.position : ((Component)val).transform.position);
			List<PlayerControllerB> source = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead).ToList();
			if (!FloorAt(val2, out var y))
			{
				return false;
			}
			for (int num = 0; num < 80; num++)
			{
				if (!SpotNearCounter(val2, y, 2.5f, 7f, out var pos))
				{
					continue;
				}
				Vector3 eye = pos + Vector3.up * 0.9f * Plugin.ModelScale.Value;
				if (!source.Any((PlayerControllerB p) => Vector3.Distance(((Component)p).transform.position, pos) < 5f || p.HasLineOfSightToPosition(eye, 70f, 40, -1f, -1)))
				{
					Vector3 val3 = val2 - pos;
					val3.y = 0f;
					float num2;
					if (!(((Vector3)(ref val3)).sqrMagnitude > 0.01f))
					{
						num2 = 0f;
					}
					else
					{
						Quaternion val4 = Quaternion.LookRotation(val3);
						num2 = ((Quaternion)(ref val4)).eulerAngles.y;
					}
					float yaw = num2;
					Send("BiddyBlas.CameoShow", delegate(FastBufferWriter w)
					{
						//IL_0017: 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)
						((FastBufferWriter)(ref w)).WriteValueSafe(ref pos);
						((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref yaw, default(ForPrimitives));
					});
					Show(pos, yaw);
					Plugin.Log.LogInfo((object)$"company cameo: Biddy at the counter, {pos}");
					return true;
				}
			}
			return false;
		}

		internal static bool FloorAt(Vector3 counter, out float y)
		{
			//IL_0001: 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_000a: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005a: Unknown result type (might be due to invalid IL or missing references)
			y = counter.y;
			Vector3 val = counter + ToShip(counter) * 1.5f;
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(new Vector3(val.x, counter.y + 1f, val.z), Vector3.down, ref val2, 8f, Mask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			y = ((RaycastHit)(ref val2)).point.y;
			return true;
		}

		private static Vector3 ToShip(Vector3 counter)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = StartOfRound.Instance.middleOfShipNode.position - counter;
			val.y = 0f;
			return ((Vector3)(ref val)).normalized;
		}

		internal static bool SpotNearCounter(Vector3 counter, float floorY, float minDist, float maxDist, out Vector3 pos)
		{
			//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_000e: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0129: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			pos = default(Vector3);
			Vector3 val = ToShip(counter);
			Vector3 val2 = Quaternion.Euler(0f, Random.Range(-80f, 80f), 0f) * val;
			Vector3 val3 = counter + val2 * Random.Range(minDist, maxDist);
			RaycastHit val4 = default(RaycastHit);
			if (!Physics.Raycast(new Vector3(val3.x, floorY + 1.5f, val3.z), Vector3.down, ref val4, 3f, Mask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			if (Mathf.Abs(((RaycastHit)(ref val4)).point.y - floorY) > 0.6f)
			{
				return false;
			}
			pos = ((RaycastHit)(ref val4)).point;
			float value = Plugin.ModelScale.Value;
			if (Physics.CheckCapsule(pos + Vector3.up * (0.35f * value + 0.05f), pos + Vector3.up * 1.2f * value, 0.35f * value, Mask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			Vector3 val5 = pos + Vector3.up * 1f;
			Vector3 val6 = counter + val * 0.5f + Vector3.up * 0.3f;
			return !Physics.Linecast(val5, val6, Mask, (QueryTriggerInteraction)1);
		}

		private unsafe static void Send(string msg, Action<FastBufferWriter> write)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			List<ulong> list = singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList();
			if (list.Count == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
			try
			{
				write(val);
				singleton.CustomMessagingManager.SendNamedMessage(msg, (IReadOnlyList<ulong>)list, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Show(Vector3 pos, float yaw)
		{
			//IL_0020: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)puppet))
			{
				Object.Destroy((Object)(object)((Component)puppet).gameObject);
			}
			GameObject obj = Object.Instantiate<GameObject>(BiddyDriveBy.RiderTemplate, pos, Quaternion.Euler(0f, yaw, 0f));
			BiddyAssets.ClearHideFlags(obj);
			((Object)obj).name = "BiddyCameo";
			obj.transform.localScale = Vector3.one * Plugin.ModelScale.Value;
			obj.SetActive(true);
			puppet = obj.AddComponent<CameoPuppet>();
			BiddyCameo component = ((Component)StartOfRound.Instance).GetComponent<BiddyCameo>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.shownAt = Time.time;
			}
		}

		private static void Spotted(int slot, int line)
		{
			if (Object.op_Implicit((Object)(object)puppet) && !puppet.caught)
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				PlayerControllerB who = ((slot >= 0 && slot < allPlayerScripts.Length) ? allPlayerScripts[slot] : null);
				puppet.Caught(who, (Lines.Length != 0) ? Lines[line % Lines.Length] : null);
			}
		}
	}
	internal class CameoPuppet : MonoBehaviour
	{
		internal bool caught;

		private PlayerControllerB spotter;

		private AudioSource voice;

		private Animator anim;

		private float vanishAt;

		private void Start()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_004d: 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)
			if (!((Object)(object)voice != (Object)null))
			{
				anim = ((Component)this).GetComponent<Animator>();
				GameObject val = new GameObject("Voice");
				val.transform.SetParent(((Component)this).transform, false);
				val.transform.localPosition = new Vector3(0f, 1f, 0f);
				voice = BiddyAssets.MakeSource(val, 30f);
				BiddyTalker.Attach(((Component)this).transform, voice, ((Component)this).transform.right);
			}
		}

		internal void Caught(PlayerControllerB who, AudioClip line)
		{
			caught = true;
			spotter = who;
			if (Object.op_Implicit((Object)(object)anim))
			{
				anim.CrossFadeInFixedTime((Random.value < 0.5f) ? "Angry" : "React", 0.2f);
			}
			if ((Object)(object)voice == (Object)null)
			{
				Start();
			}