Decompiled source of Biodiversity v0.2.5

BepInEx/plugins/Biodiversity/com.github.biodiversitylc.Biodiversity.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Biodiversity.Behaviours;
using Biodiversity.Creatures;
using Biodiversity.Creatures.Aloe.AnimatorStateMachineBehaviours;
using Biodiversity.Creatures.Aloe.BehaviourStates;
using Biodiversity.Creatures.Aloe.Types;
using Biodiversity.Creatures.Aloe.Types.Networking;
using Biodiversity.Creatures.CoilCrab;
using Biodiversity.Creatures.Critters.Prototax;
using Biodiversity.Items.DeveloperItems;
using Biodiversity.Patches;
using Biodiversity.Util;
using Biodiversity.Util.Animation;
using Biodiversity.Util.Assetloading;
using Biodiversity.Util.Attributes;
using Biodiversity.Util.Config;
using Biodiversity.Util.DataStructures;
using Biodiversity.Util.Lang;
using Biodiversity.Util.Scripts;
using Biodiversity.Util.SharedVariables;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using JetBrains.Annotations;
using LethalLevelLoader;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Animations.Rigging;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Pool;
using UnityEngine.ProBuilder;
using UnityEngine.Scripting;
using UnityEngine.VFX;
using UnityEngine.Video;
using com.github.biodiversitylc.Biodiversity.NetcodePatcher;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("LethalLevelLoader")]
[assembly: IgnoresAccessChecksTo("LethalLib")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("com.github.biodiversitylc.Biodiversity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+8ddde160ff63430bd1ae3c5189fc11a773c884e6")]
[assembly: AssemblyProduct("Biodiversity")]
[assembly: AssemblyTitle("com.github.biodiversitylc.Biodiversity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_FixedString<FixedString64Bytes>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<FixedString64Bytes>();
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<Vector3>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<Vector3>();
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<Quaternion>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<Quaternion>();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class EasyIK : MonoBehaviour
{
	[Header("IK properties")]
	public int numberOfJoints = 2;

	public Transform ikTarget;

	public int iterations = 10;

	public float tolerance = 0.05f;

	private Transform[] jointTransforms;

	private Vector3 startPosition;

	private Vector3[] jointPositions;

	private float[] boneLength;

	private float jointChainLength;

	private float distanceToTarget;

	private Quaternion[] startRotation;

	private Vector3[] jointStartDirection;

	private Quaternion ikTargetStartRot;

	private Quaternion lastJointStartRot;

	[Header("Pole target (3 joint chain)")]
	public Transform poleTarget;

	[Header("Debug")]
	public bool debugJoints = true;

	public bool localRotationAxis = false;

	[Range(0f, 1f)]
	public float gizmoSize = 0.05f;

	public bool poleDirection = false;

	public bool poleRotationAxis = false;

	public GameObject anotherObject;

	private void Awake()
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		jointChainLength = 0f;
		jointTransforms = (Transform[])(object)new Transform[numberOfJoints];
		jointPositions = (Vector3[])(object)new Vector3[numberOfJoints];
		boneLength = new float[numberOfJoints];
		jointStartDirection = (Vector3[])(object)new Vector3[numberOfJoints];
		startRotation = (Quaternion[])(object)new Quaternion[numberOfJoints];
		ikTargetStartRot = ikTarget.rotation;
		Transform val = ((Component)this).transform;
		for (int i = 0; i < jointTransforms.Length; i++)
		{
			jointTransforms[i] = val;
			if (i == jointTransforms.Length - 1)
			{
				lastJointStartRot = val.rotation;
				break;
			}
			boneLength[i] = Vector3.Distance(val.position, val.GetChild(0).position);
			jointChainLength += boneLength[i];
			jointStartDirection[i] = val.GetChild(0).position - val.position;
			startRotation[i] = val.rotation;
			val = val.GetChild(0);
		}
	}

	private void Start()
	{
	}

	private void PoleConstraint()
	{
		//IL_002a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bb: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: 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_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)
		if ((Object)(object)poleTarget != (Object)null && numberOfJoints < 4)
		{
			Vector3 val = jointPositions[2] - jointPositions[0];
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			val = poleTarget.position - jointPositions[0];
			Vector3 normalized2 = ((Vector3)(ref val)).normalized;
			val = jointPositions[1] - jointPositions[0];
			Vector3 normalized3 = ((Vector3)(ref val)).normalized;
			Vector3.OrthoNormalize(ref normalized, ref normalized2);
			Vector3.OrthoNormalize(ref normalized, ref normalized3);
			Quaternion val2 = Quaternion.FromToRotation(normalized3, normalized2);
			jointPositions[1] = val2 * (jointPositions[1] - jointPositions[0]) + jointPositions[0];
		}
	}

	private void Backward()
	{
		//IL_0054: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//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)
		for (int num = jointPositions.Length - 1; num >= 0; num--)
		{
			if (num == jointPositions.Length - 1)
			{
				jointPositions[num] = ((Component)ikTarget).transform.position;
			}
			else
			{
				Vector3[] array = jointPositions;
				int num2 = num;
				Vector3 val = jointPositions[num + 1];
				Vector3 val2 = jointPositions[num] - jointPositions[num + 1];
				array[num2] = val + ((Vector3)(ref val2)).normalized * boneLength[num];
			}
		}
	}

	private void Forward()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0059: 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_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < jointPositions.Length; i++)
		{
			if (i == 0)
			{
				jointPositions[i] = startPosition;
				continue;
			}
			Vector3[] array = jointPositions;
			int num = i;
			Vector3 val = jointPositions[i - 1];
			Vector3 val2 = jointPositions[i] - jointPositions[i - 1];
			array[num] = val + ((Vector3)(ref val2)).normalized * boneLength[i - 1];
		}
	}

	private void SolveIK()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: 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_0249: 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)
		for (int i = 0; i < jointTransforms.Length; i++)
		{
			jointPositions[i] = jointTransforms[i].position;
		}
		distanceToTarget = Vector3.Distance(jointPositions[0], ikTarget.position);
		if (distanceToTarget > jointChainLength)
		{
			Vector3 val = ikTarget.position - jointPositions[0];
			for (int j = 1; j < jointPositions.Length; j++)
			{
				jointPositions[j] = jointPositions[j - 1] + ((Vector3)(ref val)).normalized * boneLength[j - 1];
			}
		}
		else
		{
			float num = Vector3.Distance(jointPositions[jointPositions.Length - 1], ikTarget.position);
			float num2 = 0f;
			while (num > tolerance)
			{
				startPosition = jointPositions[0];
				Backward();
				Forward();
				num2 += 1f;
				if (num2 > (float)iterations)
				{
					break;
				}
			}
		}
		PoleConstraint();
		for (int k = 0; k < jointPositions.Length - 1; k++)
		{
			jointTransforms[k].position = jointPositions[k];
			Quaternion val2 = Quaternion.FromToRotation(jointStartDirection[k], jointPositions[k + 1] - jointPositions[k]);
			jointTransforms[k].rotation = val2 * startRotation[k] * anotherObject.transform.rotation;
		}
		Quaternion val3 = lastJointStartRot * Quaternion.Inverse(ikTargetStartRot);
		jointTransforms.Last().rotation = ikTarget.rotation * val3;
	}

	private void LateUpdate()
	{
		SolveIK();
	}

	private void OnDrawGizmos()
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if (debugJoints)
		{
			Transform val = ((Component)this).transform;
			Transform child = ((Component)this).transform.GetChild(0);
			for (int i = 0; i < numberOfJoints; i++)
			{
				Vector3 val2;
				if (i == numberOfJoints - 2)
				{
					float num = Vector3.Distance(val.position, child.position);
					Vector3 position = val.position;
					val2 = child.position - val.position;
					Vector3 pos = position + ((Vector3)(ref val2)).normalized * num / 2f;
					Vector3 up = Vector3.up;
					val2 = child.position - val.position;
					DrawWireCapsule(pos, Quaternion.FromToRotation(up, ((Vector3)(ref val2)).normalized), gizmoSize, num, Color.cyan);
					break;
				}
				float num2 = Vector3.Distance(val.position, child.position);
				Vector3 position2 = val.position;
				val2 = child.position - val.position;
				Vector3 pos2 = position2 + ((Vector3)(ref val2)).normalized * num2 / 2f;
				Vector3 up2 = Vector3.up;
				val2 = child.position - val.position;
				DrawWireCapsule(pos2, Quaternion.FromToRotation(up2, ((Vector3)(ref val2)).normalized), gizmoSize, num2, Color.cyan);
				val = val.GetChild(0);
				child = val.GetChild(0);
			}
		}
		if (localRotationAxis)
		{
			Transform val3 = ((Component)this).transform;
			for (int j = 0; j < numberOfJoints; j++)
			{
				if (j == numberOfJoints - 1)
				{
					drawHandle(val3);
					continue;
				}
				drawHandle(val3);
				val3 = val3.GetChild(0);
			}
		}
		Transform transform = ((Component)this).transform;
		Transform child2 = transform.GetChild(0);
		Transform child3 = child2.GetChild(0);
	}

	private void drawHandle(Transform debugJoint)
	{
	}

	public static void DrawWireCapsule(Vector3 _pos, Quaternion _rot, float _radius, float _height, Color _color = default(Color))
	{
	}
}
namespace Biodiversity
{
	public class BiodiversityConfig : BiodiverseConfigLoader<BiodiversityConfig>
	{
		private readonly HashSet<string> _enabledCreatures = new HashSet<string>();

		[field: Header("Development")]
		[field: Tooltip("Whether to log more debug information to the console. 99% of people do NOT need to touch this.")]
		public bool VerboseLogging { get; private set; } = false;


		[field: NonSerialized]
		public string Language { get; private set; } = "en";


		[field: Tooltip("The stab is real.")]
		public bool StabIsReal { get; private set; } = false;


		internal BiodiversityConfig(ConfigFile configFile)
			: base(configFile)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			AcceptableValueList<string> val = ((LangParser.Languages != null) ? new AcceptableValueList<string>(LangParser.Languages.Keys.ToArray()) : new AcceptableValueList<string>(new string[4] { "en", "es", "de", "ru" }));
			Language = configFile.Bind<string>("General", "Language", Language, new ConfigDescription("What language should Biodiversity use (en, es, de, ru)?\nSome languages may also need FontPatcher(https://thunderstore.io/c/lethal-company/p/LeKAKiD/FontPatcher/)\\n", (AcceptableValueBase)(object)val, Array.Empty<object>())).Value;
		}

		internal void AddEnabledCreature(string creatureName)
		{
			BiodiversityPlugin.LogVerbose("Adding enabled creature: " + creatureName);
			_enabledCreatures.Add(creatureName);
		}

		internal bool IsCreatureEnabled(string creatureName)
		{
			return _enabledCreatures.Contains(creatureName);
		}
	}
	[BepInPlugin("com.github.biodiversitylc.Biodiversity", "Biodiversity", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BiodiversityPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static CachedList<Assembly> CachedAssemblies;

		private static readonly (string, string)[] SillyQuotes = new(string, string)[8]
		{
			("don't get me wrong, I love women", "Monty"),
			("i love MEN with BIG ARMS and STRONGMAN LEGS", "Monty"),
			("thumpy wumpy", "Monty"),
			("Your body should get split in two", "Wesley"),
			("death for you and your bloodline", "Monty"),
			("the fiend is watching... NOT VERY SIGMA!!", "Rolevote"),
			("we love fat bitches(gender neutral) and body representation for fat bitches(still gender neutral)", "TiltedHat"),
			("Aloehood is a spectrum", "Ccode")
		};

		public static BiodiversityPlugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static BiodiversityConfig Config { get; private set; }

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			Stopwatch stopwatch = Stopwatch.StartNew();
			Logger = Logger.CreateLogSource("com.github.biodiversitylc.Biodiversity");
			Instance = this;
			CachedAssemblies = new CachedList<Assembly>(() => AppDomain.CurrentDomain.GetAssemblies().ToList());
			Logger.LogDebug((object)"Creating base biodiversity config.");
			Config = new BiodiversityConfig(((BaseUnityPlugin)this).Config);
			LogVerbose("Creating Harmony instance...");
			_harmony = new Harmony("com.github.biodiversitylc.Biodiversity");
			LogVerbose("Applying essential Harmony patches...");
			try
			{
				_harmony.CreateClassProcessor(typeof(GameNetworkManagerPatch)).Patch();
				LogVerbose("Successfully patched GameNetworkManager.");
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Failed to apply GameNetworkManagerPatch: {arg}");
			}
			LangParser.Init();
			NetcodePatcher();
			LogVerbose("Setting up the language translations...");
			LangParser.SetLanguage(Config.Language);
			LogVerbose(LangParser.GetTranslation("lang.test"));
			stopwatch.Stop();
			Logger.LogInfo((object)string.Format("{0}:{1} has setup. ({2}ms)", "com.github.biodiversitylc.Biodiversity", "0.2.0", stopwatch.ElapsedMilliseconds));
		}

		internal void FinishLoading()
		{
			Stopwatch stopwatch = Stopwatch.StartNew();
			LogVerbose("Starting FinishLoading...");
			VanillaEnemies.Init();
			LogVerbose("Loading VideoClip bundle.");
			LoadBundle("biodiversity_video_clips");
			LogVerbose("Registering the silly little creatures and config stuff.");
			List<Type> list = Assembly.GetExecutingAssembly().GetLoadableTypes().Where(delegate(Type x)
			{
				Type baseType = x.BaseType;
				return (object)baseType != null && baseType.IsGenericType && x.BaseType.GetGenericTypeDefinition() == typeof(BiodiverseAIHandler<>);
			})
				.ToList();
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				Type type = list[i];
				string name = type.Name;
				DisableEnemyByDefaultAttribute customAttribute = type.GetCustomAttribute<DisableEnemyByDefaultAttribute>();
				bool flag = customAttribute == null;
				if (!((BaseUnityPlugin)this).Config.Bind<bool>("Creatures", name, flag, "Enable/disable the " + name).Value)
				{
					LogVerbose(name + " was skipped because it's disabled.");
					continue;
				}
				LogVerbose("Creating " + name);
				try
				{
					type.GetConstructor(Array.Empty<Type>())?.Invoke(Array.Empty<object>());
					Config.AddEnabledCreature(name.Replace("Handler", ""));
					num++;
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"Failed to instantiate creature handler {name}: {arg}");
				}
			}
			ApplyPatches();
			LogVerbose($"Sucessfully setup {num} silly creatures!");
			stopwatch.Stop();
			(string, string) tuple = SillyQuotes[Random.Range(0, SillyQuotes.Length)];
			Logger.LogInfo((object)("\"" + tuple.Item1 + "\" - " + tuple.Item2));
			LogVerbose(string.Format("{0}:{1} has loaded! ({2}ms)", "com.github.biodiversitylc.Biodiversity", "0.2.0", stopwatch.ElapsedMilliseconds));
		}

		private void ApplyPatches()
		{
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Expected O, but got Unknown
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Expected I4, but got Unknown
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Assembly> dictionary = new Dictionary<string, Assembly>();
			foreach (Assembly cachedAssembly in CachedAssemblies)
			{
				dictionary.TryAdd(cachedAssembly.GetName().Name, cachedAssembly);
			}
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type == typeof(GameNetworkManagerPatch))
				{
					continue;
				}
				CreaturePatchAttribute customAttribute = type.GetCustomAttribute<CreaturePatchAttribute>();
				if (customAttribute != null)
				{
					if (!Config.IsCreatureEnabled(customAttribute.CreatureName))
					{
						LogVerbose("Skipping patches in type '" + type.FullName + "' for creature '" + customAttribute.CreatureName + "' because its disabled in config.");
						continue;
					}
					LogVerbose("Patches in type '" + type.FullName + "' for creature '" + customAttribute.CreatureName + "' are ENABLED.");
				}
				List<ModConditionalPatch> list = type.GetCustomAttributes<ModConditionalPatch>(inherit: true).ToList();
				if (list.Any())
				{
					for (int j = 0; j < list.Count; j++)
					{
						ModConditionalPatch modConditionalPatch = list[j];
						string assemblyName = modConditionalPatch.AssemblyName;
						string targetClassName = modConditionalPatch.TargetClassName;
						string targetMethodName = modConditionalPatch.TargetMethodName;
						string localPatchMethodName = modConditionalPatch.LocalPatchMethodName;
						HarmonyPatchType patchType = modConditionalPatch.PatchType;
						if (!dictionary.TryGetValue(assemblyName, out var value))
						{
							continue;
						}
						LogVerbose("Mod " + assemblyName + " is installed! Patching " + targetClassName + "." + targetMethodName + " with " + localPatchMethodName);
						Type type2;
						try
						{
							type2 = value.GetType(targetClassName);
						}
						catch (Exception ex) when (((ex is ArgumentException || ex is FileNotFoundException || ex is FileLoadException || ex is BadImageFormatException) ? 1 : 0) != 0)
						{
							LogVerbose("Could not patch because an exception occurred while getting the target class '" + targetClassName + "': " + ex.Message);
							continue;
						}
						if (type2 == null)
						{
							LogVerbose("Could not patch because the target class '" + targetClassName + "' is null.");
							continue;
						}
						MethodInfo methodInfo = null;
						for (int k = 0; k < type2.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Length; k++)
						{
							MethodInfo methodInfo2 = type2.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[k];
							if (!(methodInfo2.Name != targetMethodName))
							{
								methodInfo = methodInfo2;
								break;
							}
						}
						if (methodInfo == null)
						{
							LogVerbose("Could not patch because the target method '" + targetMethodName + "' is null.");
							continue;
						}
						MethodInfo method;
						try
						{
							method = type.GetMethod(localPatchMethodName, BindingFlags.Static | BindingFlags.NonPublic);
						}
						catch (Exception ex2) when (((ex2 is AmbiguousMatchException || ex2 is ArgumentException) ? 1 : 0) != 0)
						{
							LogVerbose("Could not patch because an exception occured while getting the local patch method '" + localPatchMethodName + "': " + ex2.Message);
							continue;
						}
						if (method == null)
						{
							LogVerbose("Could not patch because the local patch method '" + localPatchMethodName + "' is null.");
							continue;
						}
						HarmonyMethod val = new HarmonyMethod(method);
						HarmonyPatchType val2 = patchType;
						HarmonyPatchType val3 = val2;
						switch (val3 - 1)
						{
						case 0:
							_harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							break;
						case 1:
							_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							break;
						case 2:
							_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
							break;
						case 3:
							_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null);
							break;
						default:
							Logger.LogError((object)("Could not patch because patch type '" + ((object)(HarmonyPatchType)(ref patchType)).ToString() + "' is incompatible."));
							break;
						}
						LogVerbose($"Successfully patched {targetClassName}.{targetMethodName} with {localPatchMethodName} as {patchType}");
					}
					continue;
				}
				object[] customAttributes = type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false);
				if (customAttributes.Length != 0)
				{
					try
					{
						_harmony.CreateClassProcessor(type).Patch();
					}
					catch (Exception arg)
					{
						Logger.LogError((object)$"Failed to apply Harmony patch(es) for type '{type.FullName}': {arg}");
					}
				}
			}
		}

		private static void NetcodePatcher()
		{
			try
			{
				IEnumerable<Type> loadableTypes = Assembly.GetExecutingAssembly().GetLoadableTypes();
				foreach (Type item in loadableTypes)
				{
					MethodInfo[] methods = item.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						if (!Attribute.IsDefined(methodInfo, typeof(RuntimeInitializeOnLoadMethodAttribute)))
						{
							continue;
						}
						if (methodInfo.ContainsGenericParameters)
						{
							Logger.LogWarning((object)("Skipping generic method " + item.FullName + "." + methodInfo.Name + " with [RuntimeInitializeOnLoadMethod] attribute."));
						}
						else
						{
							try
							{
								methodInfo.Invoke(null, null);
							}
							catch (Exception arg)
							{
								Logger.LogError((object)$"Error invoking method {item.FullName}.{methodInfo.Name}: {arg}");
							}
						}
					}
				}
			}
			catch (ReflectionTypeLoadException ex)
			{
				Logger.LogError((object)$"[NetcodePatcher] Error loading types from assembly: {ex}");
				foreach (Exception item2 in ex.LoaderExceptions.Where((Exception e) => e != null))
				{
					Logger.LogError((object)("[NetcodePatcher] Loader Exception: " + item2.Message));
				}
			}
		}

		internal ConfigFile CreateConfig(string configName)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			return new ConfigFile(Utility.CombinePaths(new string[2]
			{
				Paths.ConfigPath,
				"me.biodiversity." + configName + ".cfg"
			}), false, MetadataHelper.GetMetadata((object)this));
		}

		internal static AssetBundle LoadBundle(string assetBundleName)
		{
			AssetBundle val;
			try
			{
				val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException("Could not find assetbundle: " + assetBundleName), "AssetBundles", assetBundleName));
			}
			catch (Exception arg)
			{
				Logger.LogWarning((object)$"Could not load assetbundle: {arg}");
				return null;
			}
			LogVerbose("[AssetBundle Loading] " + assetBundleName + " contains these objects: " + string.Join(",", val.GetAllAssetNames()));
			return val;
		}

		internal static void LogVerbose(object message)
		{
			if (Config.VerboseLogging)
			{
				Logger.LogDebug(message);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.biodiversitylc.Biodiversity";

		public const string PLUGIN_NAME = "Biodiversity";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace Biodiversity.Patches
{
	[CreaturePatch("CoilCrab")]
	[HarmonyPatch(typeof(RoundManager))]
	internal static class CoilCrabRoundManagerPatch
	{
		[HarmonyPatch("PredictAllOutsideEnemies")]
		[HarmonyPrefix]
		internal static void CoilCrabSpawnWeights(RoundManager __instance)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Invalid comparison between Unknown and I4
			BiodiversityPlugin.LogVerbose("Setting Coil crab dynamic weights");
			string text = ((Object)__instance.currentLevel).name;
			if (!Enum.IsDefined(typeof(LevelTypes), text))
			{
				text = Compatibility.GetLLLNameOfLevel(text);
			}
			text = text.Remove(text.Length - "Level".Length);
			BiodiversityPlugin.LogVerbose("The name of the level (For the Coil-Crab debug): " + text);
			SpawnableEnemyWithRarity val = null;
			foreach (SpawnableEnemyWithRarity daytimeEnemy in __instance.currentLevel.DaytimeEnemies)
			{
				if (daytimeEnemy.enemyType.enemyName == "Coil Crab")
				{
					val = daytimeEnemy;
				}
			}
			if (val == null)
			{
				BiodiversityPlugin.LogVerbose("Coil crab was not added in the non-stormy config so the crab will not be enabled on this moon.");
			}
			if (val == null)
			{
				return;
			}
			if ((int)TimeOfDay.Instance.currentLevelWeather == 2)
			{
				if (BiodiverseAIHandler<CoilCrabHandler>.Instance.StormyWeights.ContainsKey(text))
				{
					val.rarity = BiodiverseAIHandler<CoilCrabHandler>.Instance.StormyWeights[text];
					return;
				}
				val.rarity = 0;
				BiodiversityPlugin.LogVerbose("Coil Crab dynamic weights were set to zero because the stormy weights did not include the current moon.");
			}
			else if (BiodiverseAIHandler<CoilCrabHandler>.Instance.Weights.ContainsKey(text))
			{
				val.rarity = BiodiverseAIHandler<CoilCrabHandler>.Instance.Weights[text];
			}
			else
			{
				val.rarity = 0;
				BiodiversityPlugin.LogVerbose("Coil Crab dynamic weights were set to zero because the non-stormy weights did not include the current moon.");
			}
		}
	}
	[CreaturePatch("CoilCrab")]
	[HarmonyPatch(typeof(StartOfRound))]
	internal class CoilCrabStartOfRoundPatch
	{
		[HarmonyPatch("SwitchMapMonitorPurpose")]
		[HarmonyPostfix]
		internal static void CoilCrabSounds()
		{
			foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
			{
				if (((Object)items).name == "ComedyMask")
				{
					BiodiverseAIHandler<CoilCrabHandler>.Instance.Assets.CoilShellItem.pocketSFX = items.pocketSFX;
					BiodiverseAIHandler<CoilCrabHandler>.Instance.Assets.CoilShellItem.grabSFX = items.grabSFX;
					BiodiversityPlugin.LogVerbose("Found the select sfx for the shovel.");
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal static class GameNetworkManagerPatch
	{
		internal static readonly HashSet<GameObject> NetworkPrefabsToRegister = new HashSet<GameObject>();

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void AddNetworkPrefabs()
		{
			BiodiversityPlugin.Instance.FinishLoading();
			if (NetworkPrefabsToRegister.Count > 0)
			{
				BiodiversityPlugin.LogVerbose($"Registering {NetworkPrefabsToRegister.Count} network prefabs...");
				foreach (GameObject item in NetworkPrefabsToRegister)
				{
					if (!((Object)(object)item == (Object)null))
					{
						NetworkManager.Singleton.AddNetworkPrefab(item);
						BiodiversityPlugin.LogVerbose("Registered " + ((Object)item).name + " as a network prefab.");
					}
				}
				BiodiversityPlugin.LogVerbose($"Successfully registered {NetworkPrefabsToRegister.Count} network prefabs.");
			}
			NetworkPrefabsToRegister.Clear();
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerControllerBPatch
	{
		[HarmonyPatch("TeleportPlayer")]
		[HarmonyPrefix]
		private static bool TeleportCalled(PlayerControllerB __instance, Vector3 pos, bool withRotation = false, float rot = 0f, bool allowInteractTrigger = false, bool enableController = true)
		{
			bool flag = false;
			if (TeleporterStatus.CancelTeleport && TeleporterStatus.Teleporting && (Object)(object)TeleporterStatus.PlayerGettingTeleported == (Object)(object)__instance)
			{
				flag = true;
				TeleporterStatus.CancelTeleport = false;
				__instance.isInElevator = TeleporterStatus.isInElevator.Value;
				__instance.isInHangarShipRoom = TeleporterStatus.isInHangarShipRoom.Value;
				__instance.isInsideFactory = TeleporterStatus.isInFactory.Value;
			}
			if (TeleporterStatus.CancelInverseTeleport && TeleporterStatus.TeleportingInverse && (Object)(object)TeleporterStatus.PlayerGettingInverseTeleported == (Object)(object)__instance)
			{
				flag = true;
				TeleporterStatus.CancelInverseTeleport = false;
				__instance.isInElevator = TeleporterStatus.isInElevatorInverse.Value;
				__instance.isInHangarShipRoom = TeleporterStatus.isInHangarShipRoomInverse.Value;
				__instance.isInsideFactory = TeleporterStatus.isInFactoryInverse.Value;
			}
			if (TeleporterStatus.Teleporting && (Object)(object)TeleporterStatus.PlayerGettingTeleported == (Object)(object)__instance)
			{
				BiodiversityPlugin.Logger.LogInfo((object)"Clearing teleport data");
				TeleporterStatus.Teleporting = false;
				TeleporterStatus.PlayerGettingTeleported = null;
				TeleporterStatus.currentTeleporter = null;
				TeleporterStatus.isInElevator = null;
				TeleporterStatus.isInHangarShipRoom = null;
				TeleporterStatus.isInFactory = null;
			}
			if (TeleporterStatus.TeleportingInverse && (Object)(object)TeleporterStatus.PlayerGettingInverseTeleported == (Object)(object)__instance)
			{
				BiodiversityPlugin.Logger.LogInfo((object)"Clearing inverse teleport data");
				TeleporterStatus.TeleportingInverse = false;
				TeleporterStatus.PlayerGettingInverseTeleported = null;
				TeleporterStatus.currentTeleporterInverse = null;
				TeleporterStatus.isInElevatorInverse = null;
				TeleporterStatus.isInHangarShipRoomInverse = null;
				TeleporterStatus.isInFactoryInverse = null;
			}
			return !flag;
		}
	}
	internal static class RoundManagerPatch
	{
		internal static readonly Dictionary<EnemyType, Func<bool>> SpawnRequirements = new Dictionary<EnemyType, Func<bool>>();

		private static bool CanEnemySpawn(EnemyType type)
		{
			if (SpawnRequirements.TryGetValue(type, out var value))
			{
				BiodiversityPlugin.LogVerbose("doing callback for " + type.enemyName);
				bool flag = value();
				if (!flag)
				{
					BiodiversityPlugin.LogVerbose("Callback for " + type.enemyName + " blocked the spawning!");
				}
				return flag;
			}
			return true;
		}

		[HarmonyPatch("SpawnRandomOutsideEnemy")]
		[HarmonyPatch("SpawnRandomDaytimeEnemy")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> ComplexSpawningRequirementsOutside(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			Label label = default(Label);
			return new CodeMatcher(instructions, generator).MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(RoundManager), "SpawnProbabilities"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Br, (object)null, (string)null)
			}).Advance(1).ThrowIfInvalid("failed to find spawn probability assignment")
				.CreateLabel(ref label)
				.Start()
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(EnemyType), "spawningDisabled"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
				})
				.ThrowIfInvalid("failed to find if condition")
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RoundManagerPatch), "CanEnemySpawn", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Brfalse, (object)label)
				})
				.InstructionEnumeration();
		}

		[HarmonyPatch("EnemyCannotBeSpawned")]
		[HarmonyPostfix]
		private static void ComplexSpawningRequirementsInside(RoundManager __instance, int enemyIndex, ref bool __result)
		{
			__result = __result && CanEnemySpawn(__instance.currentLevel.Enemies[enemyIndex].enemyType);
		}
	}
	[HarmonyPatch(typeof(ShipTeleporter))]
	internal static class ShipTeleporterPatch
	{
		[HarmonyPatch("PressTeleportButtonClientRpc")]
		[HarmonyPrefix]
		private static void ButtonPressed(ShipTeleporter __instance)
		{
			try
			{
				if (!__instance.isInverseTeleporter)
				{
					BiodiversityPlugin.Logger.LogInfo((object)"Recording teleport data.");
					TeleporterStatus.Teleporting = true;
					TeleporterStatus.PlayerGettingTeleported = StartOfRound.Instance.mapScreen.targetedPlayer;
					TeleporterStatus.currentTeleporter = __instance;
					TeleporterStatus.isInElevator = TeleporterStatus.PlayerGettingTeleported.isInElevator;
					TeleporterStatus.isInHangarShipRoom = TeleporterStatus.PlayerGettingTeleported.isInHangarShipRoom;
					TeleporterStatus.isInFactory = TeleporterStatus.PlayerGettingTeleported.isInsideFactory;
				}
				else
				{
					BiodiversityPlugin.Logger.LogInfo((object)"Recording inverse teleport data.");
					TeleporterStatus.TeleportingInverse = true;
					TeleporterStatus.PlayerGettingInverseTeleported = StartOfRound.Instance.mapScreen.targetedPlayer;
					TeleporterStatus.currentTeleporterInverse = __instance;
					TeleporterStatus.isInElevatorInverse = TeleporterStatus.PlayerGettingInverseTeleported.isInElevator;
					TeleporterStatus.isInHangarShipRoomInverse = TeleporterStatus.PlayerGettingInverseTeleported.isInHangarShipRoom;
					TeleporterStatus.isInFactoryInverse = TeleporterStatus.PlayerGettingInverseTeleported.isInsideFactory;
				}
			}
			catch
			{
				BiodiversityPlugin.LogVerbose("Teleport data failed to set.");
				BiodiversityPlugin.Logger.LogInfo((object)"Clearing all teleport data.");
				TeleporterStatus.Teleporting = false;
				TeleporterStatus.PlayerGettingTeleported = null;
				TeleporterStatus.currentTeleporter = null;
				TeleporterStatus.isInElevator = null;
				TeleporterStatus.isInHangarShipRoom = null;
				TeleporterStatus.isInFactory = null;
				TeleporterStatus.TeleportingInverse = false;
				TeleporterStatus.PlayerGettingInverseTeleported = null;
				TeleporterStatus.currentTeleporterInverse = null;
				TeleporterStatus.isInElevatorInverse = null;
				TeleporterStatus.isInHangarShipRoomInverse = null;
				TeleporterStatus.isInFactoryInverse = null;
			}
		}
	}
}
namespace Biodiversity.Items.DeveloperItems
{
	[Serializable]
	public class DeveloperScrapConfig : BiodiverseConfigLoader<DeveloperScrapConfig>
	{
		[field: Header("Developer Items Settings")]
		public GenericScrapItem RubberDuck { get; private set; } = new GenericScrapItem("NethersomeDuckItemData", "Nethersomes duck", "All:2", 1.05f);


		public DeveloperScrapConfig(ConfigFile cfg)
			: base(cfg)
		{
		}
	}
	public class RubberDuckBehaviour : PhysicsProp
	{
		[CompilerGenerated]
		private sealed class <ApplyItemSaveData>d__17 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public int loadedVariantIndex;

			public RubberDuckBehaviour <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ApplyItemSaveData>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!<>4__this._networkObject.Value.IsSpawned)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				<>4__this._variantIndex.Value = loadedVariantIndex;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[SerializeField]
		private Material[] materialVariants;

		[SerializeField]
		private AudioClip[] audioClipVariants;

		[SerializeField]
		private AudioSource audioSource;

		[SerializeField]
		private Animator animator;

		private bool _networkEventsSubscribed;

		private bool _loadedVariantFromSave;

		private CachedValue<NetworkObject> _networkObject;

		private readonly NetworkVariable<int> _variantIndex = new NetworkVariable<int>(-1, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		private void Awake()
		{
			_networkObject = new CachedValue<NetworkObject>((Func<NetworkObject>)((Component)this).GetComponent<NetworkObject>, eager: true);
		}

		private void OnEnable()
		{
			SubscribeToNetworkEvents();
		}

		private void OnDisable()
		{
			UnsubscribeFromNetworkEvents();
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			SubscribeToNetworkEvents();
			if (((NetworkBehaviour)this).IsServer)
			{
				Random.InitState(StartOfRound.Instance.randomMapSeed + Guid.NewGuid().GetHashCode());
				if (!_loadedVariantFromSave)
				{
					_variantIndex.Value = Random.Range(0, materialVariants.Length);
				}
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			PlayQuackServerRpc();
		}

		[ServerRpc(RequireOwnership = false)]
		private void PlayQuackServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4272959164u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4272959164u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					int clipIndex = Random.Range(0, audioClipVariants.Length);
					PlayQuackClientRpc(clipIndex);
				}
			}
		}

		[ClientRpc]
		private void PlayQuackClientRpc(int clipIndex)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(67466382u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clipIndex);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 67466382u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					AudioClip val3 = audioClipVariants[clipIndex];
					audioSource.Stop(true);
					animator.Play("Squeeze", -1, 0f);
					audioSource.PlayOneShot(val3);
					WalkieTalkie.TransmitOneShotAudio(audioSource, val3, audioSource.volume);
					RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, (audioSource.minDistance + audioSource.maxDistance) / 2f, 0.5f, 0, false, 0);
				}
			}
		}

		public override int GetItemDataToSave()
		{
			return _variantIndex.Value;
		}

		public override void LoadItemSaveData(int saveData)
		{
			_loadedVariantFromSave = true;
			((MonoBehaviour)this).StartCoroutine(ApplyItemSaveData(saveData));
		}

		[IteratorStateMachine(typeof(<ApplyItemSaveData>d__17))]
		private IEnumerator ApplyItemSaveData(int loadedVariantIndex)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ApplyItemSaveData>d__17(0)
			{
				<>4__this = this,
				loadedVariantIndex = loadedVariantIndex
			};
		}

		private void OnVariantIndexChanged(int oldValue, int newValue)
		{
			ApplyVariant(newValue);
		}

		private void ApplyVariant(int chosenVariantIndex)
		{
			if (materialVariants.Length != 0)
			{
				((Renderer)((GrabbableObject)this).mainObjectRenderer).material = materialVariants[chosenVariantIndex];
			}
			else
			{
				BiodiversityPlugin.Logger.LogError((object)$"Nethersome's rubber duck item: No material variants available with index: {chosenVariantIndex}.");
			}
		}

		private void SubscribeToNetworkEvents()
		{
			if (!_networkEventsSubscribed)
			{
				NetworkVariable<int> variantIndex = _variantIndex;
				variantIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Combine((Delegate?)(object)variantIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnVariantIndexChanged));
				_networkEventsSubscribed = true;
			}
		}

		private void UnsubscribeFromNetworkEvents()
		{
			if (_networkEventsSubscribed)
			{
				NetworkVariable<int> variantIndex = _variantIndex;
				variantIndex.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Remove((Delegate?)(object)variantIndex.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnVariantIndexChanged));
				_networkEventsSubscribed = false;
			}
		}

		protected override void __initializeVariables()
		{
			if (_variantIndex == null)
			{
				throw new Exception("RubberDuckBehaviour._variantIndex cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)_variantIndex).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_variantIndex, "_variantIndex");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)_variantIndex);
			((PhysicsProp)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_RubberDuckBehaviour()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(4272959164u, new RpcReceiveHandler(__rpc_handler_4272959164));
			NetworkManager.__rpc_func_table.Add(67466382u, new RpcReceiveHandler(__rpc_handler_67466382));
		}

		private static void __rpc_handler_4272959164(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RubberDuckBehaviour)(object)target).PlayQuackServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_67466382(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int clipIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref clipIndex);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((RubberDuckBehaviour)(object)target).PlayQuackClientRpc(clipIndex);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "RubberDuckBehaviour";
		}
	}
}
namespace Biodiversity.Items.Developeritems
{
	internal class DeveloperScrapAssets : BiodiverseAssetBundle<DeveloperScrapAssets>
	{
		[LoadFromBundle("NethersomeDuckItemData")]
		public Item RubberDuckAsset;

		public DeveloperScrapAssets(string bundle)
			: base(bundle)
		{
		}
	}
	[UsedImplicitly]
	internal class DeveloperScrapHandler : BiodiverseAIHandler<DeveloperScrapHandler>
	{
		internal DeveloperScrapAssets Assets { get; set; }

		internal DeveloperScrapConfig Config { get; set; }

		public DeveloperScrapHandler()
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			Assets = new DeveloperScrapAssets("developer_items");
			Config = new DeveloperScrapConfig(BiodiversityPlugin.Instance.CreateConfig("developer_scrap_items"));
			for (int i = 0; i < typeof(DeveloperScrapAssets).GetFields().Length; i++)
			{
				FieldInfo fieldInfo = typeof(DeveloperScrapAssets).GetFields()[i];
				LoadFromBundleAttribute customAttribute = fieldInfo.GetCustomAttribute<LoadFromBundleAttribute>();
				if (customAttribute == null)
				{
					continue;
				}
				for (int j = 0; j < typeof(DeveloperScrapConfig).GetProperties().Length; j++)
				{
					PropertyInfo propertyInfo = typeof(DeveloperScrapConfig).GetProperties()[j];
					if (!(propertyInfo.PropertyType != typeof(GenericScrapItem)))
					{
						GenericScrapItem genericScrapItem = (GenericScrapItem)propertyInfo.GetValue(Config);
						if (!(genericScrapItem.AssetName != customAttribute.BundleFile))
						{
							Item val = (Item)fieldInfo.GetValue(Assets);
							val.isScrap = true;
							val.weight = genericScrapItem.Weight;
							val.minValue = genericScrapItem.MinimumValue;
							val.maxValue = genericScrapItem.MaximumValue;
							BiodiverseAIHandler<DeveloperScrapHandler>.RegisterScrapWithConfig(genericScrapItem.Rarity, val);
						}
					}
				}
			}
		}
	}
}
namespace Biodiversity.Util
{
	internal static class ExtensionMethods
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static Vector3 Direction(this Vector3 from, Vector3 to)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			return ((Vector3)(ref val)).normalized;
		}

		internal static (int hours, int minutes) GetCurrentTime(this TimeOfDay timeOfDay)
		{
			int num = Mathf.FloorToInt(timeOfDay.normalizedTimeOfDay * 60f * (float)timeOfDay.numberOfHours + 360f);
			int item = Mathf.FloorToInt((float)(num / 60));
			return (item, num % 60);
		}

		internal static (int, int) ParseTimeString(this TimeOfDay timeOfDay, string timeString)
		{
			return (int.Parse(timeString.Split(":")[0]), int.Parse(timeString.Split(":")[1]));
		}

		internal static bool HasPassedTime(this TimeOfDay timeOfDay, (int, int) target)
		{
			return timeOfDay.HasPassedTime(timeOfDay.GetCurrentTime(), target);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static bool HasPassedTime(this TimeOfDay timeOfDay, (int, int) current, (int, int) target)
		{
			return target.Item1 <= current.Item1 && target.Item2 <= current.Item2;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ChangeNetworkVar<T>(NetworkVariable<T> networkVariable, T newValue) where T : IEquatable<T>
		{
			if (!EqualityComparer<T>.Default.Equals(networkVariable.Value, newValue))
			{
				networkVariable.Value = newValue;
			}
		}

		internal static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
		{
			if (assembly == null)
			{
				throw new ArgumentNullException("assembly");
			}
			try
			{
				return assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				return ex.Types.Where((Type t) => t != null);
			}
		}

		internal static bool IsHostReflection(object instance)
		{
			return (bool)instance.GetType().GetProperty("IsHost")?.GetValue(instance);
		}

		internal static bool IsServerReflection(object instance)
		{
			return (bool)instance.GetType().GetProperty("IsServer")?.GetValue(instance);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Color RGBToHSV(Color rgb, out float h, out float s, out float v)
		{
			//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			Color.RGBToHSV(rgb, ref h, ref s, ref v);
			return rgb;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Color HSVToRGB(float h, float s, float v)
		{
			//IL_0004: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return Color.HSVToRGB(h, s, v);
		}
	}
	internal static class PlayerUtil
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static PlayerControllerB GetPlayerFromClientId(int playerClientId)
		{
			return StartOfRound.Instance.allPlayerScripts[playerClientId];
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static bool IsPlayerDead(PlayerControllerB player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return true;
			}
			return player.isPlayerDead || !player.isPlayerControlled;
		}
	}
}
namespace Biodiversity.Util.SharedVariables
{
	public static class TeleporterStatus
	{
		public static PlayerControllerB PlayerGettingTeleported = null;

		public static bool Teleporting = true;

		public static ShipTeleporter currentTeleporter = null;

		public static bool? isInElevator = null;

		public static bool? isInHangarShipRoom = null;

		public static bool? isInFactory = null;

		public static PlayerControllerB PlayerGettingInverseTeleported = null;

		public static bool TeleportingInverse = true;

		public static ShipTeleporter currentTeleporterInverse = null;

		public static bool? isInElevatorInverse = null;

		public static bool? isInHangarShipRoomInverse = null;

		public static bool? isInFactoryInverse = null;

		public static bool CancelTeleport = false;

		public static bool CancelInverseTeleport = false;
	}
}
namespace Biodiversity.Util.Scripts
{
	internal class KeepY : MonoBehaviour
	{
		public float? StartingY = null;

		public void Init()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			StartingY = ((Component)this).transform.position.y;
		}

		public void LateUpdate()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (StartingY.HasValue)
			{
				((Component)this).transform.position = new Vector3(((Component)this).transform.position.x, StartingY.Value, ((Component)this).transform.position.z);
			}
		}
	}
	internal class SplineObject : MonoBehaviour
	{
		[SerializeField]
		private Transform startPoint;

		[SerializeField]
		private Transform Handle;

		[SerializeField]
		private Transform endPoint;

		[SerializeField]
		private Transform meta1;

		[SerializeField]
		private Transform meta2;

		private Transform point;

		[NonSerialized]
		public float interpolateAmount = 0f;

		[SerializeField]
		private bool Debug = false;

		private bool forward = true;

		private void Start()
		{
			point = ((Component)this).gameObject.transform;
		}

		private void Update()
		{
			if (Debug)
			{
				if (forward)
				{
					forward = !UpdateForward(0.3f, Time.deltaTime);
				}
				else
				{
					forward = UpdateBackward(0.3f, Time.deltaTime);
				}
			}
		}

		public bool UpdateForward(float speed, float delta)
		{
			//IL_001d: 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_0033: 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_0055: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			interpolateAmount += delta * speed;
			meta1.position = Vector3.Lerp(startPoint.position, Handle.position, interpolateAmount);
			meta2.position = Vector3.Lerp(Handle.position, endPoint.position, interpolateAmount);
			point.position = Vector3.Lerp(meta1.position, meta2.position, interpolateAmount);
			if (interpolateAmount >= 1f)
			{
				interpolateAmount = 1f;
				return true;
			}
			return false;
		}

		public bool UpdateBackward(float speed, float delta)
		{
			//IL_001d: 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_0033: 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_0055: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			interpolateAmount -= delta * speed;
			meta1.position = Vector3.Lerp(startPoint.position, Handle.position, interpolateAmount);
			meta2.position = Vector3.Lerp(Handle.position, endPoint.position, interpolateAmount);
			point.position = Vector3.Lerp(meta1.position, meta2.position, interpolateAmount);
			if (interpolateAmount <= 0f)
			{
				interpolateAmount = 0f;
				return true;
			}
			return false;
		}
	}
}
namespace Biodiversity.Util.Lang
{
	internal static class LangParser
	{
		internal static Dictionary<string, string> Languages { get; private set; }

		private static Dictionary<string, object> LoadedLanguage { get; set; }

		internal static void Init()
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Biodiversity.Util.Lang.defs.json");
			if (stream == null)
			{
				BiodiversityPlugin.Logger.LogWarning((object)"Could not find Biodiversity.Util.Lang.defs.json, and therefore cannot do translations.");
				return;
			}
			using StreamReader streamReader = new StreamReader(stream);
			string text = streamReader.ReadToEnd();
			Languages = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
		}

		private static Dictionary<string, object> LoadLanguage(string id)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (directoryName == null)
			{
				BiodiversityPlugin.Logger.LogError((object)"Cannot determine the assembly directory path, and therefore cannot do translations.");
				return null;
			}
			using Stream stream = File.Open(Path.Combine(directoryName, "lang", id + ".json"), FileMode.Open);
			using StreamReader streamReader = new StreamReader(stream);
			string text = streamReader.ReadToEnd();
			return JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
		}

		internal static void SetLanguage(string id)
		{
			LoadedLanguage = LoadLanguage(id);
		}

		internal static string GetTranslation(string translation)
		{
			if (LoadedLanguage == null)
			{
				BiodiversityPlugin.Logger.LogDebug((object)("Cannot translate message due to translations not being loaded: " + translation));
				return GetTranslation("lang.missing").Replace("<translation_id>", translation);
			}
			if (LoadedLanguage.TryGetValue(translation, out var value))
			{
				return (string)value;
			}
			if (translation == "lang.missing")
			{
				BiodiversityPlugin.Logger.LogError((object)"LANG.MISSING IS MISSING!!!!!  THIS IS BAD!! VERY BAD!!");
				return "lang.missing; <translation_id>";
			}
			return GetTranslation("lang.missing").Replace("<translation_id>", translation);
		}

		internal static JArray GetTranslationSet(string translation)
		{
			//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_004b: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			if (LoadedLanguage == null)
			{
				BiodiversityPlugin.Logger.LogDebug((object)("Cannot translate message due to translations not being loaded: " + translation));
				JArray val = new JArray();
				val.Add(JToken.op_Implicit(GetTranslation("lang.missing").Replace("<translation_id>", translation)));
				return val;
			}
			if (LoadedLanguage.TryGetValue(translation, out var value))
			{
				BiodiversityPlugin.Logger.LogInfo((object)value.GetType());
				return (JArray)((value is JArray) ? value : null);
			}
			JArray val2 = new JArray();
			val2.Add(JToken.op_Implicit(GetTranslation("lang.missing").Replace("<translation_id>", translation)));
			return val2;
		}
	}
}
namespace Biodiversity.Util.Config
{
	[Serializable]
	public abstract class BiodiverseConfigLoader<T> where T : BiodiverseConfigLoader<T>
	{
		protected BiodiverseConfigLoader(ConfigFile configFile)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			string text = "Misc";
			Type typeFromHandle = typeof(T);
			configFile.SaveOnConfigSet = false;
			for (int i = 0; i < typeFromHandle.GetProperties().Length; i++)
			{
				PropertyInfo propertyInfo = typeFromHandle.GetProperties()[i];
				try
				{
					FieldInfo field = propertyInfo.DeclaringType.GetField("<" + propertyInfo.Name + ">k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field.GetCustomAttribute(typeof(NonSerializedAttribute)) != null)
					{
						continue;
					}
					HeaderAttribute val = (HeaderAttribute)field.GetCustomAttribute(typeof(HeaderAttribute));
					if (val != null)
					{
						text = val.header.Replace(" ", "");
					}
					string text2 = "This config option hasn't used [Tooltip] to set a description, so this default one will be here instead.";
					TooltipAttribute val2 = (TooltipAttribute)field.GetCustomAttribute(typeof(TooltipAttribute));
					if (val2 != null)
					{
						text2 = val2.tooltip;
					}
					RangeAttribute val3 = (RangeAttribute)field.GetCustomAttribute(typeof(RangeAttribute));
					ConfigDescription val4 = ((val3 == null) ? new ConfigDescription(text2, (AcceptableValueBase)null, Array.Empty<object>()) : ((propertyInfo.PropertyType == typeof(int)) ? new ConfigDescription(text2, (AcceptableValueBase)(object)new AcceptableValueRange<int>((int)val3.min, (int)val3.max), Array.Empty<object>()) : new ConfigDescription(text2, (AcceptableValueBase)(object)new AcceptableValueRange<float>(val3.min, val3.max), Array.Empty<object>())));
					if (propertyInfo.PropertyType == typeof(float))
					{
						propertyInfo.SetValue(this, configFile.Bind<float>(text, propertyInfo.Name, (float)propertyInfo.GetValue(this), val4).Value);
					}
					if (propertyInfo.PropertyType == typeof(int))
					{
						propertyInfo.SetValue(this, configFile.Bind<int>(text, propertyInfo.Name, (int)propertyInfo.GetValue(this), val4).Value);
					}
					if (propertyInfo.PropertyType == typeof(string))
					{
						propertyInfo.SetValue(this, configFile.Bind<string>(text, propertyInfo.Name, (string)propertyInfo.GetValue(this), val4).Value);
					}
					if (propertyInfo.PropertyType == typeof(bool))
					{
						propertyInfo.SetValue(this, configFile.Bind<bool>(text, propertyInfo.Name, (bool)propertyInfo.GetValue(this), val4).Value);
					}
					goto IL_02d3;
				}
				catch (Exception ex)
				{
					BiodiversityPlugin.Logger.LogError((object)("Exception while binding: " + propertyInfo.Name));
					BiodiversityPlugin.Logger.LogError((object)ex.ToString());
					goto IL_02d3;
				}
				IL_02d3:
				if (propertyInfo.PropertyType == typeof(EnemyRaritiesPerMoon))
				{
					EnemyRaritiesPerMoon enemyRaritiesPerMoon = (EnemyRaritiesPerMoon)propertyInfo.GetValue(this);
					enemyRaritiesPerMoon.Bind(configFile, propertyInfo.Name);
					propertyInfo.SetValue(this, enemyRaritiesPerMoon);
				}
				else if (propertyInfo.PropertyType == typeof(GenericScrapItem))
				{
					GenericScrapItem genericScrapItem = (GenericScrapItem)propertyInfo.GetValue(this);
					genericScrapItem.Bind(configFile, propertyInfo.Name);
					propertyInfo.SetValue(this, genericScrapItem);
				}
			}
			configFile.SaveOnConfigSet = true;
			configFile.Save();
		}
	}
	public class EnemyRaritiesPerMoon
	{
		public readonly Dictionary<LevelTypes, int> VanillaRarities = vanillaRarities ?? new Dictionary<LevelTypes, int>();

		public readonly Dictionary<string, int> ModdedRarities = moddedRarities ?? new Dictionary<string, int>();

		public int DefaultRarity { get; private set; }

		public EnemyRaritiesPerMoon(int defaultRarity, Dictionary<LevelTypes, int> vanillaRarities = null, Dictionary<string, int> moddedRarities = null)
		{
			DefaultRarity = defaultRarity;
			base..ctor();
		}

		public void Bind(ConfigFile file, string section)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			foreach (LevelTypes value in Enum.GetValues(typeof(LevelTypes)))
			{
				LevelTypes val = value;
				if ((int)val <= 1)
				{
					if ((int)val == -1 || (int)val == 1)
					{
						goto IL_004d;
					}
				}
				else if ((int)val == 1024 || (int)val == 15356)
				{
					goto IL_004d;
				}
				bool flag = false;
				goto IL_0053;
				IL_004d:
				flag = true;
				goto IL_0053;
				IL_0053:
				if (!flag)
				{
					VanillaRarities[val] = file.Bind<int>(section, ((object)(LevelTypes)(ref val)).ToString(), VanillaRarities.GetValueOrDefault(val, DefaultRarity), "Rarity for '" + ((object)(LevelTypes)(ref val)).ToString() + "' (vanilla)").Value;
				}
			}
			if (Chainloader.PluginInfos.ContainsKey("imabatby.lethallevelloader"))
			{
				BiodiversityPlugin.LogVerbose("binding modded moons from lethal level loader.");
				BindLLL(file, section);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private void BindLLL(ConfigFile file, string section)
		{
			BiodiversityPlugin.LogVerbose($"{PatchedContent.ExtendedMods.Count} mods");
			BiodiversityPlugin.LogVerbose(string.Join(", ", PatchedContent.AllLevelSceneNames) ?? "");
			for (int i = 0; i < PatchedContent.ExtendedMods.Count; i++)
			{
				ExtendedMod val = PatchedContent.ExtendedMods[i];
				if (!((Object)(object)PatchedContent.VanillaMod == (Object)(object)val))
				{
					for (int j = 0; j < val.ExtendedLevels.Count; j++)
					{
						ExtendedLevel val2 = val.ExtendedLevels[j];
						string numberlessPlanetName = val2.NumberlessPlanetName;
						ModdedRarities[numberlessPlanetName] = file.Bind<int>(section, numberlessPlanetName, ModdedRarities.GetValueOrDefault(numberlessPlanetName, DefaultRarity), "Rarity for '" + numberlessPlanetName + "' (modded)").Value;
					}
				}
			}
		}
	}
	public struct GenericScrapItem
	{
		private const string RarityTooltip = "Spawn weight (rarity) of the {0} scrap.";

		private const string WeightTooltip = "Weight of the {0} scrap.";

		private const string MinimumValueTooltip = "Minimum value that the {0} scrap can spawn with.";

		private const string MaximumValueTooltip = "Maximum value that the {0} scrap can spawn with.";

		private static readonly AcceptableValueRange<float> WeightRange = new AcceptableValueRange<float>(0f, 1000f);

		private static readonly AcceptableValueRange<int> MinimumValueRange = new AcceptableValueRange<int>(0, 1000);

		private static readonly AcceptableValueRange<int> MaximumValueRange = new AcceptableValueRange<int>(0, 1000);

		public string AssetName { get; private set; }

		public string ItemName { get; private set; }

		public string Rarity { get; private set; }

		public float Weight { get; private set; }

		public int MinimumValue { get; private set; }

		public int MaximumValue { get; private set; }

		public GenericScrapItem(string assetName, string itemName, string rarity = "All:2", float weight = 1f, int minimumValue = 20, int maximumValue = 60)
		{
			AssetName = assetName;
			ItemName = itemName;
			Rarity = rarity;
			Weight = weight;
			MinimumValue = minimumValue;
			MaximumValue = maximumValue;
		}

		public void Bind(ConfigFile file, string section)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			Rarity = file.Bind<string>(section, CleanConfigString(ItemName + " Rarity"), Rarity, new ConfigDescription($"Spawn weight (rarity) of the {ItemName} scrap.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			Weight = file.Bind<float>(section, CleanConfigString(ItemName + " Weight"), Weight, new ConfigDescription($"Weight of the {ItemName} scrap.", (AcceptableValueBase)(object)WeightRange, Array.Empty<object>())).Value;
			MinimumValue = file.Bind<int>(section, CleanConfigString(ItemName + " Minimum Value"), MinimumValue, new ConfigDescription($"Minimum value that the {ItemName} scrap can spawn with.", (AcceptableValueBase)(object)MinimumValueRange, Array.Empty<object>())).Value;
			MaximumValue = file.Bind<int>(section, CleanConfigString(ItemName + " Maximum Value"), MaximumValue, new ConfigDescription($"Maximum value that the {ItemName} scrap can spawn with.", (AcceptableValueBase)(object)MaximumValueRange, Array.Empty<object>())).Value;
		}

		private static string CleanConfigString(string str)
		{
			return Regex.Replace(str, "[\\n\\t\\\\\\\"'\\[\\]]", "");
		}
	}
}
namespace Biodiversity.Util.Attributes
{
	[AttributeUsage(AttributeTargets.Class)]
	public class CreaturePatchAttribute : Attribute
	{
		public string CreatureName { get; }

		public CreaturePatchAttribute(string creatureName)
		{
			CreatureName = creatureName;
			base..ctor();
		}
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class DisableEnemyByDefaultAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Field)]
	internal class LoadFromBundleAttribute : Attribute
	{
		public string BundleFile { get; private set; }

		public LoadFromBundleAttribute(string bundleFile)
		{
			BundleFile = bundleFile;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
	public class ModConditionalPatch : Attribute
	{
		public string AssemblyName { get; }

		public string TargetClassName { get; }

		public string TargetMethodName { get; }

		public string LocalPatchMethodName { get; }

		public HarmonyPatchType PatchType { get; }

		public ModConditionalPatch(string assemblyName, string targetClassName, string targetMethodName, string localPatchMethodName, HarmonyPatchType patchType)
		{
			//IL_0026: 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)
			AssemblyName = assemblyName;
			TargetClassName = targetClassName;
			TargetMethodName = targetMethodName;
			LocalPatchMethodName = localPatchMethodName;
			PatchType = patchType;
		}
	}
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	internal class StateAttribute : Attribute
	{
		internal object StateType { get; }

		internal StateAttribute(object stateType)
		{
			StateType = stateType;
		}
	}
}
namespace Biodiversity.Util.Assetloading
{
	internal abstract class BiodiverseAssetBundle<T> where T : BiodiverseAssetBundle<T>
	{
		protected BiodiverseAssetBundle(string filePath)
		{
			AssetBundle val = BiodiversityPlugin.LoadBundle(filePath);
			if ((Object)(object)val == (Object)null)
			{
				BiodiversityPlugin.Logger.LogError((object)("AssetBundle '" + filePath + "' failed to load. Cannot initialize " + typeof(T).Name + "."));
				return;
			}
			Type typeFromHandle = typeof(T);
			for (int i = 0; i < typeFromHandle.GetFields().Length; i++)
			{
				FieldInfo fieldInfo = typeFromHandle.GetFields()[i];
				LoadFromBundleAttribute loadFromBundleAttribute = (LoadFromBundleAttribute)fieldInfo.GetCustomAttribute(typeof(LoadFromBundleAttribute));
				if (loadFromBundleAttribute != null)
				{
					try
					{
						fieldInfo.SetValue(this, LoadAsset(val, loadFromBundleAttribute.BundleFile));
					}
					catch (ArgumentException ex)
					{
						BiodiversityPlugin.Logger.LogError((object)("Failed to load asset '" + loadFromBundleAttribute.BundleFile + "' from bundle '" + filePath + "': " + ex.Message));
					}
				}
			}
			Object[] array = val.LoadAllAssets();
			foreach (Object val2 in array)
			{
				GameObject val3 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
				if (val3 != null && (Object)(object)val3.GetComponent<NetworkObject>() != (Object)null && GameNetworkManagerPatch.NetworkPrefabsToRegister.Add(val3))
				{
					BiodiversityPlugin.LogVerbose("Adding NetworkPrefab '" + ((Object)val3).name + "' from bundle '" + filePath + "' to registration queue.");
				}
				AudioClip val4 = (AudioClip)(object)((val2 is AudioClip) ? val2 : null);
				if (val4 != null && !val4.preloadAudioData)
				{
					BiodiversityPlugin.Logger.LogWarning((object)("Loading Audio data for '" + ((Object)val4).name + "' because it does not have preloadAudioData enabled!"));
					val4.LoadAudioData();
				}
				VideoClip val5 = (VideoClip)(object)((val2 is VideoClip) ? val2 : null);
				if (val5 != null)
				{
					BiodiversityPlugin.Logger.LogWarning((object)("VideoClip: '" + ((Object)val5).name + "' is being loaded from '" + typeof(T).Name + "' instead of the dedicated video clip bundle. It will not work correctly."));
				}
			}
			val.Unload(false);
		}

		private static Object LoadAsset(AssetBundle bundle, string path)
		{
			Object val = bundle.LoadAsset<Object>(path);
			if (val == (Object)null)
			{
				throw new ArgumentException(path + " is not valid in the assetbundle!");
			}
			return val;
		}
	}
}
namespace Biodiversity.Util.Animation
{
	public class PrototaxBaseAnimationStateBehaviour : BaseAnimationStateBehaviour
	{
		protected PrototaxAI PrototaxAiInstance;

		internal void Initialize(PrototaxAI prototaxAiInstance)
		{
			PrototaxAiInstance = prototaxAiInstance;
		}
	}
	public abstract class BaseAnimationStateBehaviour : StateMachineBehaviour
	{
	}
}
namespace Biodiversity.Util.DataStructures
{
	public abstract class BehaviourState<TState, TEnemyAI> where TState : Enum where TEnemyAI : StateManagedAI<TState, TEnemyAI>
	{
		protected readonly TEnemyAI EnemyAIInstance;

		private readonly TState _stateType;

		private static readonly Dictionary<Type, TState> StateTypeCache = new Dictionary<Type, TState>();

		protected internal List<StateTransition<TState, TEnemyAI>> Transitions { get; protected set; } = new List<StateTransition<TState, TEnemyAI>>();


		protected BehaviourState(TEnemyAI enemyAiInstance)
		{
			EnemyAIInstance = enemyAiInstance ?? throw new ArgumentNullException("enemyAiInstance");
			_stateType = GetStateTypeFromAttribute();
		}

		private TState GetStateTypeFromAttribute()
		{
			Type type = GetType();
			if (StateTypeCache.TryGetValue(type, out var value))
			{
				return value;
			}
			StateAttribute customAttribute = type.GetCustomAttribute<StateAttribute>();
			if (customAttribute == null || !(customAttribute.StateType is TState val))
			{
				throw new InvalidOperationException("Class " + type.Name + " must have a valid StateAttribute.");
			}
			StateTypeCache[type] = val;
			return val;
		}

		internal virtual void OnStateEnter(ref StateData initData)
		{
			EnemyAIInstance.LogVerbose($"OnStateEnter called for {_stateType}.");
			if (initData == null)
			{
				initData = new StateData();
			}
		}

		internal virtual void UpdateBehaviour()
		{
		}

		internal virtual void AIIntervalBehaviour()
		{
		}

		internal virtual void LateUpdateBehaviour()
		{
		}

		internal virtual void OnStateExit()
		{
			EnemyAIInstance.LogVerbose($"OnStateExit called for {_stateType}.");
		}

		internal TState GetStateType()
		{
			return _stateType;
		}
	}
	public class PlayerTargetableConditions
	{
		private readonly List<Func<PlayerControllerB, bool>> _conditions = new List<Func<PlayerControllerB, bool>>(1)
		{
			(PlayerControllerB player) => !PlayerUtil.IsPlayerDead(player)
		};

		public void AddCondition(Func<PlayerControllerB, bool> condition)
		{
			_conditions.Add(condition);
		}

		public bool IsPlayerTargetable(PlayerControllerB player)
		{
			return (Object)(object)player != (Object)null && _conditions.All((Func<PlayerControllerB, bool> condition) => condition(player));
		}

		public bool IsPlayerTargetable(CachedNullable<PlayerControllerB> player)
		{
			return player.HasValue && _conditions.All((Func<PlayerControllerB, bool> condition) => condition(player.Value));
		}
	}
	public class StateData
	{
		private readonly Dictionary<string, object> _data = new Dictionary<string, object>();

		public void Add(string key, object value)
		{
			_data[key] = value;
		}

		public bool Remove(string key)
		{
			return _data.Remove(key);
		}

		public T Get<T>(string key)
		{
			if (_data.TryGetValue(key, out var value) && value is T result)
			{
				return result;
			}
			return default(T);
		}

		public bool TryGet<T>(string key, out T value)
		{
			if (_data.TryGetValue(key, out var value2) && value2 is T val)
			{
				value = val;
				return true;
			}
			value = default(T);
			return false;
		}

		public bool ContainsKey(string key)
		{
			return _data.ContainsKey(key);
		}

		public void Clear()
		{
			_data.Clear();
		}
	}
	public abstract class StateTransition<TState, TEnemyAI> where TState : Enum where TEnemyAI : StateManagedAI<TState, TEnemyAI>
	{
		protected readonly TEnemyAI EnemyAIInstance;

		protected StateTransition(TEnemyAI enemyAIInstance)
		{
			EnemyAIInstance = enemyAIInstance ?? throw new ArgumentNullException("enemyAIInstance");
		}

		internal abstract bool ShouldTransitionBeTaken();

		internal abstract TState NextState();

		internal virtual void OnTransition()
		{
		}

		internal virtual string GetTransitionDescription()
		{
			return "";
		}
	}
	public class BulkPopulateDictionary<TKey, TValue> : PerKeyCachedDictionary<TKey, TValue>
	{
		private readonly Action<Dictionary<TKey, CachedNullable<TValue>>> _populateFunction;

		private bool _isPopulated;

		public override TValue this[TKey key]
		{
			get
			{
				if (!_isPopulated)
				{
					_populateFunction(Cache);
					_isPopulated = true;
				}
				if (Cache.TryGetValue(key, out var value) && value.HasValue)
				{
					return value.Value;
				}
				throw new KeyNotFoundException($"The key '{key}' was not found in the dictionary.");
			}
		}

		public BulkPopulateDictionary(Action<Dictionary<TKey, CachedNullable<TValue>>> populateFunction)
			: base((Func<TKey, TValue>)((TKey _) => default(TValue)))
		{
			_populateFunction = populateFunction ?? throw new ArgumentNullException("populateFunction");
			_isPopulated = false;
		}

		public void Reset()
		{
			ResetAll();
			_isPopulated = false;
		}
	}
	public class CachedList<T> : IEnumerable<T>, IEnumerable
	{
		private readonly Func<List<T>> _computeListFunction;

		private readonly object _lock = new object();

		private List<T> _cachedList;

		private bool _hasValue;

		public List<T> Value
		{
			get
			{
				if (!_hasValue)
				{
					lock (_lock)
					{
						if (!_hasValue)
						{
							ComputeAndCacheListInternal();
						}
					}
				}
				return _cachedList ?? Enumerable.Empty<T>().ToList();
			}
		}

		public bool HasValue
		{
			get
			{
				lock (_lock)
				{
					return _hasValue;
				}
			}
		}

		public CachedList(Func<List<T>> computeListFunction)
		{
			_computeListFunction = computeListFunction ?? throw new ArgumentNullException("computeListFunction");
			_cachedList = null;
			_hasValue = false;
		}

		public void Reset()
		{
			lock (_lock)
			{
				_cachedList = null;
				_hasValue = false;
			}
		}

		private void ComputeAndCacheListInternal()
		{
			try
			{
				_cachedList = _computeListFunction();
				_hasValue = true;
			}
			catch
			{
				_hasValue = false;
				throw;
			}
		}

		public IEnumerator<T> GetEnumerator()
		{
			return Value.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public struct CachedNullable<T> : IEquatable<CachedNullable<T>>
	{
		private T _value;

		private bool _hasValue;

		public bool HasValue
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return _hasValue;
			}
			private set
			{
				_hasValue = value;
			}
		}

		public T Value
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return _value;
			}
		}

		internal CachedNullable(T value)
		{
			_value = default(T);
			_hasValue = false;
			Set(value);
		}

		public void Set(T newValue)
		{
			_value = newValue;
			_hasValue = !EqualityComparer<T>.Default.Equals(_value, default(T));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Reset()
		{
			_value = default(T);
			_hasValue = false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public T GetValueOrDefault()
		{
			return _hasValue ? _value : default(T);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public T GetValueOrDefault(T defaultValue)
		{
			return _hasValue ? _value : defaultValue;
		}

		public override string ToString()
		{
			return _hasValue ? (_value.ToString() ?? "null") : "No Value";
		}

		public override bool Equals(object obj)
		{
			return obj is CachedNullable<T> other && Equals(other);
		}

		public override int GetHashCode()
		{
			return _hasValue ? EqualityComparer<T>.Default.GetHashCode(_value) : 0;
		}

		public static bool operator ==(CachedNullable<T> left, CachedNullable<T> right)
		{
			return left.Equals(right);
		}

		public static bool operator !=(CachedNullable<T> left, CachedNullable<T> right)
		{
			return !left.Equals(right);
		}

		public static bool operator ==(CachedNullable<T> left, T right)
		{
			if (!left._hasValue)
			{
				return EqualityComparer<T>.Default.Equals(default(T), right);
			}
			return EqualityComparer<T>.Default.Equals(left._value, right);
		}

		public static bool operator !=(CachedNullable<T> left, T right)
		{
			return !(left == right);
		}

		public static bool operator ==(T left, CachedNullable<T> right)
		{
			return right == left;
		}

		public static bool operator !=(T left, CachedNullable<T> right)
		{
			return !(right == left);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public bool Equals(CachedNullable<T> other)
		{
			if (!_hasValue && !other._h