Decompiled source of JupiterIncident v0.1.2

BepInEx/plugins/JupiterIncident/JupiterIncident.dll

Decompiled 3 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace JupiterIncident
{
	public class JimModel
	{
		public class Bone
		{
			public string Name;

			public int Parent;

			public Vector3 LocalPosition;

			public Quaternion LocalRotation;
		}

		public class Clip
		{
			public string Name;

			public float Fps;

			public int Frames;

			public bool Loop;

			public Vector3[] Positions;

			public Quaternion[] Rotations;

			public float Length
			{
				get
				{
					if (Frames <= 1)
					{
						return 0f;
					}
					return (float)(Frames - 1) / Fps;
				}
			}
		}

		public class Submesh
		{
			public bool Emissive;

			public Color Colour;

			public float EmissionStrength;
		}

		public string Name;

		public Mesh Mesh;

		public Texture2D Albedo;

		public List<Submesh> Submeshes = new List<Submesh>();

		public List<Bone> Bones = new List<Bone>();

		public Matrix4x4[] BindPoses;

		public Dictionary<string, Clip> Clips = new Dictionary<string, Clip>();

		public bool Skinned => Bones.Count > 0;

		public static JimModel Load(string path, string name)
		{
			//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_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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Expected O, but got Unknown
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			JimModel jimModel = new JimModel
			{
				Name = name
			};
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JIM1")
			{
				throw new InvalidDataException(path + " is not a JIM1 file");
			}
			int num = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = ReadV3(binaryReader);
			}
			for (int j = 0; j < num; j++)
			{
				array2[j] = ReadV3(binaryReader);
			}
			for (int k = 0; k < num; k++)
			{
				array3[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			BoneWeight[] array4 = null;
			if (binaryReader.ReadInt32() == 1)
			{
				array4 = (BoneWeight[])(object)new BoneWeight[num];
				for (int l = 0; l < num; l++)
				{
					int boneIndex = binaryReader.ReadInt32();
					int boneIndex2 = binaryReader.ReadInt32();
					int boneIndex3 = binaryReader.ReadInt32();
					int boneIndex4 = binaryReader.ReadInt32();
					BoneWeight[] array5 = array4;
					int num2 = l;
					BoneWeight val = default(BoneWeight);
					((BoneWeight)(ref val)).boneIndex0 = boneIndex;
					((BoneWeight)(ref val)).boneIndex1 = boneIndex2;
					((BoneWeight)(ref val)).boneIndex2 = boneIndex3;
					((BoneWeight)(ref val)).boneIndex3 = boneIndex4;
					((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
					array5[num2] = val;
				}
			}
			int num3 = binaryReader.ReadInt32();
			List<int[]> list = new List<int[]>();
			for (int m = 0; m < num3; m++)
			{
				Submesh submesh = new Submesh
				{
					Emissive = (binaryReader.ReadInt32() == 1)
				};
				submesh.Colour = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				submesh.EmissionStrength = binaryReader.ReadSingle();
				int num4 = binaryReader.ReadInt32();
				int[] array6 = new int[num4];
				for (int n = 0; n < num4; n++)
				{
					array6[n] = binaryReader.ReadInt32();
				}
				jimModel.Submeshes.Add(submesh);
				list.Add(array6);
			}
			int num5 = binaryReader.ReadInt32();
			jimModel.BindPoses = (Matrix4x4[])(object)new Matrix4x4[num5];
			for (int num6 = 0; num6 < num5; num6++)
			{
				Bone item = new Bone
				{
					Name = ReadStr(binaryReader),
					Parent = binaryReader.ReadInt32(),
					LocalPosition = ReadV3(binaryReader),
					LocalRotation = ReadQ(binaryReader)
				};
				Matrix4x4 val2 = default(Matrix4x4);
				for (int num7 = 0; num7 < 4; num7++)
				{
					for (int num8 = 0; num8 < 4; num8++)
					{
						((Matrix4x4)(ref val2))[num7, num8] = binaryReader.ReadSingle();
					}
				}
				jimModel.BindPoses[num6] = val2;
				jimModel.Bones.Add(item);
			}
			int num9 = binaryReader.ReadInt32();
			for (int num10 = 0; num10 < num9; num10++)
			{
				Clip clip = new Clip
				{
					Name = ReadStr(binaryReader),
					Fps = binaryReader.ReadSingle(),
					Frames = binaryReader.ReadInt32(),
					Loop = (binaryReader.ReadInt32() == 1)
				};
				int num11 = clip.Frames * num5;
				clip.Positions = (Vector3[])(object)new Vector3[num11];
				clip.Rotations = (Quaternion[])(object)new Quaternion[num11];
				for (int num12 = 0; num12 < num11; num12++)
				{
					clip.Positions[num12] = ReadV3(binaryReader);
					clip.Rotations[num12] = ReadQ(binaryReader);
				}
				jimModel.Clips[clip.Name] = clip;
			}
			Mesh val3 = new Mesh
			{
				name = name
			};
			if (num > 65000)
			{
				val3.indexFormat = (IndexFormat)1;
			}
			val3.vertices = array;
			val3.normals = array2;
			val3.uv = array3;
			if (array4 != null)
			{
				val3.boneWeights = array4;
				val3.bindposes = jimModel.BindPoses;
			}
			val3.subMeshCount = num3;
			for (int num13 = 0; num13 < num3; num13++)
			{
				val3.SetTriangles(list[num13], num13);
			}
			val3.RecalculateBounds();
			val3.RecalculateTangents();
			jimModel.Mesh = val3;
			return jimModel;
		}

		private static Vector3 ReadV3(BinaryReader r)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		private static Quaternion ReadQ(BinaryReader r)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		private static string ReadStr(BinaryReader r)
		{
			int count = r.ReadInt32();
			return Encoding.UTF8.GetString(r.ReadBytes(count));
		}
	}
	public static class ModAssets
	{
		public static JimModel Keys;

		public static JimModel BodyWatkins;

		public static JimModel BodyOAlgo;

		public static JimModel BodyWaldron;

		public static JimModel BlackBox;

		public static JimModel LaserGun;

		public static AudioClip BlackBoxRecording;

		public static AudioClip KeysCall;

		public static AudioClip LaserFire;

		public static AudioClip LaserEmpty;

		public static AudioClip DistressBeep;

		private static string dir;

		private static readonly Dictionary<string, Material[]> materialCache = new Dictionary<string, Material[]>();

		public static void Load(string assetDir, MonoBehaviour host)
		{
			dir = assetDir;
			Keys = LoadModel("keys");
			BodyWatkins = LoadModel("body_watkins");
			BodyOAlgo = LoadModel("body_oalgo");
			BodyWaldron = LoadModel("body_waldron");
			BlackBox = LoadModel("blackbox");
			LaserGun = LoadModel("lasergun");
			LaserFire = SoundSynth.LaserShot();
			LaserEmpty = SoundSynth.EmptyClick();
			DistressBeep = SoundSynth.DistressBeep();
			Runner.Run(LoadAudio("blackboxaudio.mp3", delegate(AudioClip c)
			{
				BlackBoxRecording = c;
			}));
			Runner.Run(LoadAudio("keys_species.mp3", delegate(AudioClip c)
			{
				KeysCall = c;
			}));
		}

		private static JimModel LoadModel(string name)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			try
			{
				JimModel jimModel = JimModel.Load(Path.Combine(dir, name + ".jim"), name);
				string path = Path.Combine(dir, name + "_albedo.png");
				if (File.Exists(path))
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
					{
						name = name + "_albedo"
					};
					ImageConversion.LoadImage(val, File.ReadAllBytes(path));
					((Texture)val).wrapMode = (TextureWrapMode)1;
					((Texture)val).filterMode = (FilterMode)1;
					((Texture)val).anisoLevel = 4;
					jimModel.Albedo = val;
				}
				Plugin.Log.LogInfo((object)$"Loaded model {name}: {jimModel.Mesh.vertexCount} verts, {jimModel.Bones.Count} bones, {jimModel.Clips.Count} clips");
				return jimModel;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to load model {name}: {arg}");
				return null;
			}
		}

		private static IEnumerator LoadAudio(string file, Action<AudioClip> done)
		{
			string text = Path.Combine(dir, file);
			if (!File.Exists(text))
			{
				Plugin.Log.LogError((object)("Missing audio file " + text));
				yield break;
			}
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(text).AbsoluteUri, (AudioType)13);
			try
			{
				((DownloadHandlerAudioClip)req.downloadHandler).streamAudio = false;
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogError((object)("Could not load " + file + ": " + req.error));
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(req);
				((Object)content).name = Path.GetFileNameWithoutExtension(file);
				done(content);
				Plugin.Log.LogInfo((object)$"Loaded audio {file} ({content.length:F1}s)");
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
		}

		public static Material[] MaterialsFor(JimModel model, float smoothness)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (model == null)
			{
				return (Material[])(object)new Material[0];
			}
			if (materialCache.TryGetValue(model.Name, out var value) && (Object)(object)value[0] != (Object)null)
			{
				return value;
			}
			Shader val = Shader.Find("HDRP/Lit");
			if ((Object)(object)val == (Object)null)
			{
				return (Material[])(object)new Material[0];
			}
			Material[] array = (Material[])(object)new Material[model.Submeshes.Count];
			for (int i = 0; i < array.Length; i++)
			{
				JimModel.Submesh submesh = model.Submeshes[i];
				Material val2 = new Material(val)
				{
					name = $"{model.Name}_{i}"
				};
				if ((Object)(object)model.Albedo != (Object)null)
				{
					val2.SetTexture("_BaseColorMap", (Texture)(object)model.Albedo);
					val2.SetColor("_BaseColor", Color.white);
				}
				else
				{
					val2.SetColor("_BaseColor", submesh.Colour);
				}
				val2.SetFloat("_Smoothness", smoothness);
				val2.SetFloat("_Metallic", 0f);
				if (submesh.Emissive)
				{
					val2.SetTexture("_BaseColorMap", (Texture)null);
					val2.SetColor("_BaseColor", submesh.Colour);
					Color linear = ((Color)(ref submesh.Colour)).linear;
					val2.SetColor("_EmissiveColor", linear * Mathf.Max(1f, submesh.EmissionStrength) * 4f);
					val2.SetColor("_EmissiveColorLDR", submesh.Colour);
					val2.SetFloat("_EmissiveIntensity", 1f);
				}
				try
				{
					HDMaterial.ValidateMaterial(val2);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("ValidateMaterial failed: " + ex.Message));
				}
				array[i] = val2;
			}
			materialCache[model.Name] = array;
			return array;
		}

		public static Material EmissiveUnlit(Color colour, float intensity)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(Shader.Find("HDRP/Unlit"))
			{
				name = "JI_Emissive"
			};
			val.SetColor("_UnlitColor", colour);
			val.SetColor("_EmissiveColor", ((Color)(ref colour)).linear * intensity);
			try
			{
				HDMaterial.ValidateMaterial(val);
			}
			catch
			{
			}
			return val;
		}
	}
	public static class SoundSynth
	{
		private const int Rate = 44100;

		public static AudioClip LaserShot()
		{
			int num = 19845;
			float[] array = new float[num];
			float num2 = 0f;
			float num3 = 0f;
			Random random = new Random(7);
			for (int i = 0; i < num; i++)
			{
				float num4 = (float)i / (float)num;
				float num5 = Mathf.Lerp(2400f, 160f, Mathf.Pow(num4, 0.55f));
				num2 += MathF.PI * 2f * num5 / 44100f;
				num3 += MathF.PI * 2f * num5 * 1.503f / 44100f;
				float num6 = Mathf.Exp((0f - num4) * 6f) * Mathf.Clamp01((float)i / 120f);
				float num7 = Mathf.Sin(num2) * 0.6f + Mathf.Sign(Mathf.Sin(num3)) * 0.18f;
				float num8 = ((float)random.NextDouble() * 2f - 1f) * 0.25f * Mathf.Exp((0f - num4) * 14f);
				array[i] = (num7 + num8) * num6 * 0.8f;
			}
			AudioClip obj = AudioClip.Create("JI_LaserShot", num, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static AudioClip DistressBeep()
		{
			int num = 33075;
			float[] array = new float[num];
			Random random = new Random(11);
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / 44100f;
				int num4 = (int)(num3 / 0.25f);
				float num5 = num3 - (float)num4 * 0.25f;
				float num6 = ((num5 < 0.14f) ? (Mathf.Clamp01(num5 * 400f) * Mathf.Clamp01((0.14f - num5) * 400f)) : 0f);
				float num7 = ((num4 == 2) ? 1180f : 1560f);
				num2 += MathF.PI * 2f * num7 / 44100f;
				float num8 = Mathf.Sign(Mathf.Sin(num2)) * 0.35f + Mathf.Sin(num2) * 0.35f;
				float num9 = ((float)random.NextDouble() * 2f - 1f) * 0.12f;
				array[i] = num8 * num6 + num9 * (0.3f + num6);
			}
			AudioClip obj = AudioClip.Create("JI_DistressBeep", num, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static AudioClip EmptyClick()
		{
			int num = 5292;
			float[] array = new float[num];
			Random random = new Random(3);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / (float)num;
				array[i] = (((float)random.NextDouble() * 2f - 1f) * 0.5f + Mathf.Sin((float)i * 0.35f) * 0.5f) * Mathf.Exp((0f - num2) * 30f);
			}
			AudioClip obj = AudioClip.Create("JI_EmptyClick", num, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}
	}
	public static class BlackBoxHud
	{
		public class HudDriver : MonoBehaviour
		{
			public AudioSource audio;

			public RectTransform[] bars;

			public RectTransform fill;

			public TextMeshProUGUI time;

			public Image rec;

			public CanvasGroup group;

			private float length = 58f;

			private float elapsed;

			private float fadeOut = -1f;

			private readonly float[] samples = new float[256];

			private readonly float[] levels = new float[64];

			public void Begin(AudioClip clip, float offset)
			{
				length = (((Object)(object)clip != (Object)null) ? clip.length : 58f);
				elapsed = Mathf.Min(offset, length);
				fadeOut = -1f;
				group.alpha = 1f;
				if ((Object)(object)clip != (Object)null)
				{
					audio.clip = clip;
					audio.time = Mathf.Min(elapsed, clip.length - 0.05f);
					audio.Play();
				}
			}

			public void End()
			{
				if ((Object)(object)audio != (Object)null)
				{
					audio.Stop();
				}
			}

			private void Update()
			{
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
				elapsed += Time.deltaTime;
				if (elapsed >= length && fadeOut < 0f)
				{
					fadeOut = 1.5f;
				}
				if (fadeOut >= 0f)
				{
					fadeOut -= Time.deltaTime;
					group.alpha = Mathf.Clamp01(fadeOut / 1.5f);
					if (fadeOut <= 0f)
					{
						((Component)this).gameObject.SetActive(false);
						return;
					}
				}
				float num = 0.05f;
				if (audio.isPlaying)
				{
					audio.GetOutputData(samples, 0);
					float num2 = 0f;
					for (int i = 0; i < samples.Length; i++)
					{
						num2 += samples[i] * samples[i];
					}
					num = Mathf.Sqrt(num2 / (float)samples.Length);
				}
				for (int j = 0; j < bars.Length; j++)
				{
					float num3 = Mathf.Clamp01(num * 18f * (0.4f + Mathf.PerlinNoise((float)j * 0.37f, Time.time * 7f))) * 40f + 3f;
					levels[j] = Mathf.Lerp(levels[j], num3, Time.deltaTime * 18f);
					bars[j].sizeDelta = new Vector2(6f, levels[j]);
				}
				float num4 = Mathf.Clamp01(elapsed / length);
				fill.sizeDelta = new Vector2(270f * num4, 6f);
				((TMP_Text)time).text = Fmt(elapsed) + " / " + Fmt(length);
				((Behaviour)rec).enabled = Time.time % 1f < 0.6f;
			}

			private static string Fmt(float s)
			{
				s = Mathf.Max(0f, s);
				return $"{(int)(s / 60f):00}:{(int)(s % 60f):00}";
			}
		}

		private static GameObject root;

		private static HudDriver driver;

		public static void Play(float offsetSeconds)
		{
			Build();
			root.SetActive(true);
			driver.Begin(ModAssets.BlackBoxRecording, Mathf.Max(0f, offsetSeconds));
		}

		public static void Stop()
		{
			if (!((Object)(object)root == (Object)null))
			{
				driver.End();
				root.SetActive(false);
			}
		}

		private static void Build()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: 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_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)root != (Object)null))
			{
				root = new GameObject("JI_BlackBoxHud");
				Object.DontDestroyOnLoad((Object)(object)root);
				Canvas obj = root.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 60;
				CanvasScaler obj2 = root.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				AudioSource val = root.AddComponent<AudioSource>();
				val.spatialBlend = 0f;
				val.playOnAwake = false;
				val.volume = 1f;
				if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.UIAudio != (Object)null)
				{
					val.outputAudioMixerGroup = HUDManager.Instance.UIAudio.outputAudioMixerGroup;
				}
				root.AddComponent<AudioHighPassFilter>().cutoffFrequency = 280f;
				root.AddComponent<AudioLowPassFilter>().cutoffFrequency = 5200f;
				root.AddComponent<AudioDistortionFilter>().distortionLevel = 0.12f;
				TMP_FontAsset font = (((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.chatText != (Object)null) ? ((TMP_Text)HUDManager.Instance.chatText).font : null);
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(1f, 0.52f, 0.1f);
				RectTransform val3 = Rect("Frame", root.transform, new Vector2(1f, 1f), new Vector2(-28f, -28f), new Vector2(434f, 132f));
				((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = new Color(1f, 0.52f, 0.1f, 0.7f);
				RectTransform val4 = Rect("Panel", (Transform)(object)val3, new Vector2(1f, 1f), new Vector2(-2f, -2f), new Vector2(430f, 128f));
				((Graphic)((Component)val4).gameObject.AddComponent<Image>()).color = new Color(0.01f, 0.012f, 0.01f, 1f);
				Image val5 = ((Component)Rect("Rec", (Transform)(object)val4, new Vector2(0f, 1f), new Vector2(18f, -18f), new Vector2(14f, 14f))).gameObject.AddComponent<Image>();
				((Graphic)val5).color = new Color(1f, 0.1f, 0.05f);
				Text("Title", (Transform)(object)val4, font, "MISSION RECORDER PLAYBACK", 20f, val2, new Vector2(40f, -8f), new Vector2(380f, 26f));
				Text("Sub", (Transform)(object)val4, font, "JUPITER-2011 // CREW AUDIO LOG", 13f, new Color(1f, 0.7f, 0.4f, 0.8f), new Vector2(40f, -32f), new Vector2(380f, 18f));
				TextMeshProUGUI val6 = Text("Time", (Transform)(object)val4, font, "00:00 / 00:58", 14f, val2, new Vector2(300f, -94f), new Vector2(120f, 20f));
				((TMP_Text)val6).alignment = (TextAlignmentOptions)516;
				RectTransform[] array = (RectTransform[])(object)new RectTransform[32];
				for (int i = 0; i < 32; i++)
				{
					RectTransform val7 = Rect("Bar" + i, (Transform)(object)val4, new Vector2(0f, 1f), new Vector2((float)(18 + i * 9), -84f), new Vector2(6f, 4f));
					val7.pivot = new Vector2(0.5f, 0f);
					((Graphic)((Component)val7).gameObject.AddComponent<Image>()).color = val2;
					array[i] = val7;
				}
				RectTransform val8 = Rect("Track", (Transform)(object)val4, new Vector2(0f, 1f), new Vector2(18f, -112f), new Vector2(270f, 6f));
				((Graphic)((Component)val8).gameObject.AddComponent<Image>()).color = new Color(1f, 0.52f, 0.1f, 0.25f);
				RectTransform val9 = Rect("Fill", (Transform)(object)val8, new Vector2(0f, 1f), Vector2.zero, new Vector2(0f, 6f));
				((Graphic)((Component)val9).gameObject.AddComponent<Image>()).color = val2;
				driver = root.AddComponent<HudDriver>();
				driver.audio = val;
				driver.bars = array;
				driver.fill = val9;
				driver.time = val6;
				driver.rec = val5;
				driver.group = ((Component)val3).gameObject.AddComponent<CanvasGroup>();
				root.SetActive(false);
			}
		}

		private static RectTransform Rect(string name, Transform parent, Vector2 anchor, Vector2 pos, Vector2 size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent(parent, false);
			Vector2 anchorMin = (val.anchorMax = anchor);
			val.anchorMin = anchorMin;
			val.pivot = ((anchor == new Vector2(1f, 1f)) ? new Vector2(1f, 1f) : new Vector2(0f, 1f));
			val.anchoredPosition = pos;
			val.sizeDelta = size;
			return val;
		}

		private static TextMeshProUGUI Text(string name, Transform parent, TMP_FontAsset font, string s, float size, Color c, Vector2 pos, Vector2 box)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)Rect(name, parent, new Vector2(0f, 1f), pos, box)).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val).font = font;
			}
			((TMP_Text)val).text = s;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = c;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).alignment = (TextAlignmentOptions)513;
			return val;
		}
	}
	public static class BloodScene
	{
		private static readonly List<GameObject> spawned = new List<GameObject>();

		private static Material poolMat;

		private static Material decalMat;

		private static bool searchedDecal;

		public static void Clear()
		{
			foreach (GameObject item in spawned)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			spawned.Clear();
		}

		public static void Paint(Vector3 bodyPos, Vector3 facing, int seed)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: 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_019b: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: 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_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			Random rng = new Random(seed);
			int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
			facing.y = 0f;
			facing = ((((Vector3)(ref facing)).sqrMagnitude > 0.01f) ? ((Vector3)(ref facing)).normalized : Vector3.forward);
			GameObject val = new GameObject("JI_BloodScene");
			spawned.Add(val);
			Floor(val, bodyPos + facing * 0.35f, R(1.1f, 1.4f), rng, collidersAndRoomMaskAndDefault, 1f);
			int num = 14 + rng.Next(8);
			for (int i = 0; i < num; i++)
			{
				float num2 = R(0f, MathF.PI * 2f);
				float num3 = R(0.9f, 3.8f);
				Vector3 around = bodyPos + new Vector3(Mathf.Cos(num2), 0f, Mathf.Sin(num2)) * num3;
				Floor(val, around, R(0.06f, 0.35f), rng, collidersAndRoomMaskAndDefault, 0.7f);
			}
			Vector3 val2 = Quaternion.Euler(0f, R(-50f, 50f), 0f) * facing;
			float num4 = R(2.5f, 4.5f);
			for (float num5 = 0.6f; num5 < num4; num5 += R(0.25f, 0.45f))
			{
				Vector3 val3 = Vector3.Cross(Vector3.up, val2) * R(-0.15f, 0.15f);
				Floor(val, bodyPos + val2 * num5 + val3, R(0.12f, 0.28f) * (1f - num5 / (num4 + 1f)), rng, collidersAndRoomMaskAndDefault, 0.4f);
			}
			Vector3 val4 = -facing;
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(bodyPos + Vector3.up * 0.7f, val4, ref val5, 2.5f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				Material val6 = DecalMaterial();
				int num6 = 4 + rng.Next(3);
				for (int j = 0; j < num6; j++)
				{
					Vector3 val7 = ((RaycastHit)(ref val5)).point + Vector3.up * R(-0.4f, 1f) + Vector3.Cross(Vector3.up, ((RaycastHit)(ref val5)).normal) * R(-0.9f, 0.9f);
					float num7 = R(0.6f, 1.5f);
					if ((Object)(object)val6 != (Object)null)
					{
						Decal(val, val7, -((RaycastHit)(ref val5)).normal, num7, val6, R(0f, 360f));
					}
					else
					{
						Patch(val, val7 + ((RaycastHit)(ref val5)).normal * 0.01f, ((RaycastHit)(ref val5)).normal, num7 * 0.5f, rng);
					}
				}
				if ((Object)(object)val6 != (Object)null)
				{
					Decal(val, ((RaycastHit)(ref val5)).point + Vector3.up * 0.6f, -((RaycastHit)(ref val5)).normal, 1.6f, val6, 90f, 2.2f);
				}
			}
			Material val8 = DecalMaterial();
			if ((Object)(object)val8 != (Object)null)
			{
				for (int k = 0; k < 5; k++)
				{
					float num8 = R(0f, MathF.PI * 2f);
					Vector3 pos = bodyPos + new Vector3(Mathf.Cos(num8), 0f, Mathf.Sin(num8)) * R(0.5f, 2.5f) + Vector3.up * 0.5f;
					Decal(val, pos, Vector3.down, R(0.8f, 1.8f), val8, R(0f, 360f));
				}
			}
			float R(float a, float b)
			{
				return a + (float)rng.NextDouble() * (b - a);
			}
		}

		private static void Floor(GameObject root, Vector3 around, float radius, Random rng, int mask, float lumpiness)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(around + Vector3.up * 1.2f, Vector3.down, ref val, 3f, mask, (QueryTriggerInteraction)1))
			{
				Patch(root, ((RaycastHit)(ref val)).point + ((RaycastHit)(ref val)).normal * 0.006f, ((RaycastHit)(ref val)).normal, radius, rng, lumpiness);
			}
		}

		private static void Patch(GameObject root, Vector3 pos, Vector3 normal, float radius, Random rng, float lumpiness = 0.7f)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[29];
			int[] array2 = new int[84];
			float num = (float)rng.NextDouble() * 6.28f;
			float num2 = (float)rng.NextDouble() * 6.28f;
			float num3 = (float)rng.NextDouble() * 6.28f;
			array[0] = Vector3.zero;
			for (int i = 0; i < 28; i++)
			{
				float num4 = MathF.PI * 2f * (float)i / 28f;
				float num5 = radius * (0.85f + lumpiness * (0.2f * Mathf.Sin(3f * num4 + num) + 0.12f * Mathf.Sin(5f * num4 + num2) + 0.07f * Mathf.Sin(11f * num4 + num3)));
				array[i + 1] = new Vector3(Mathf.Cos(num4) * num5, 0f, Mathf.Sin(num4) * num5);
				array2[i * 3] = 0;
				array2[i * 3 + 1] = (i + 1) % 28 + 1;
				array2[i * 3 + 2] = i + 1;
			}
			Mesh val = new Mesh
			{
				vertices = array,
				triangles = array2
			};
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject("JI_Blood");
			val2.transform.SetParent(root.transform, false);
			val2.transform.position = pos;
			val2.transform.rotation = Quaternion.FromToRotation(Vector3.up, normal) * Quaternion.Euler(0f, (float)rng.NextDouble() * 360f, 0f);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = PoolMaterial();
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		}

		private static void Decal(GameObject root, Vector3 pos, Vector3 projectDir, float size, Material mat, float spin, float stretch = 1f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("JI_BloodDecal");
			val.transform.SetParent(root.transform, false);
			val.transform.position = pos;
			val.transform.rotation = Quaternion.LookRotation(projectDir) * Quaternion.Euler(0f, 0f, spin);
			DecalProjector obj = val.AddComponent<DecalProjector>();
			obj.material = mat;
			obj.size = new Vector3(size, size * stretch, 1.2f);
			obj.pivot = Vector3.zero;
			obj.fadeFactor = 1f;
		}

		private static Material PoolMaterial()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)poolMat != (Object)null)
			{
				return poolMat;
			}
			poolMat = new Material(Shader.Find("HDRP/Lit"))
			{
				name = "JI_BloodPool"
			};
			poolMat.SetColor("_BaseColor", new Color(0.16f, 0.005f, 0.008f));
			poolMat.SetFloat("_Smoothness", 0.9f);
			poolMat.SetFloat("_Metallic", 0f);
			try
			{
				HDMaterial.ValidateMaterial(poolMat);
			}
			catch
			{
			}
			return poolMat;
		}

		private static Material DecalMaterial()
		{
			if (searchedDecal)
			{
				return decalMat;
			}
			searchedDecal = true;
			try
			{
				foreach (GameObject playerRagdoll in StartOfRound.Instance.playerRagdolls)
				{
					DeadBodyInfo val = (((Object)(object)playerRagdoll != (Object)null) ? playerRagdoll.GetComponent<DeadBodyInfo>() : null);
					if (val?.bodyBloodDecals != null)
					{
						DecalProjector val2 = (from g in val.bodyBloodDecals
							where (Object)(object)g != (Object)null
							select g.GetComponentInChildren<DecalProjector>(true)).FirstOrDefault((Func<DecalProjector, bool>)((DecalProjector p) => (Object)(object)p != (Object)null && (Object)(object)p.material != (Object)null));
						if ((Object)(object)val2 != (Object)null)
						{
							decalMat = val2.material;
							break;
						}
					}
				}
				if ((Object)(object)decalMat == (Object)null)
				{
					decalMat = (from p in Resources.FindObjectsOfTypeAll<DecalProjector>()
						select p.material).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && ((Object)m).name.ToLowerInvariant().Contains("blood")));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("No blood decal found: " + ex.Message));
			}
			Plugin.Log.LogInfo((object)("Blood decal material: " + (((Object)(object)decalMat != (Object)null) ? ((Object)decalMat).name : "none (using flat patches)")));
			return decalMat;
		}
	}
	[HarmonyPatch]
	internal static class Code2011
	{
		public static bool ForceNextLanding;

		private static bool running;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
		private static bool ParsePlayerSentence(Terminal __instance, ref TerminalNode __result)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.Code2011.Value)
			{
				return true;
			}
			string text = __instance.screenText.text;
			int num = Mathf.Clamp(__instance.textAdded, 0, text.Length);
			if (text.Substring(text.Length - num).Trim() != "2011")
			{
				return true;
			}
			StartOfRound instance = StartOfRound.Instance;
			string text2;
			if (!instance.inShipPhase || instance.travellingToNewLevel)
			{
				text2 = "Can't do that now. Use it while the ship is in orbit.";
			}
			else
			{
				text2 = "MISSION 2011 // JUPITER\n\nRouting to 85-Titan. Signal from the lost crew detected.\nLanding now...";
				Net.SendToHost(Net.Begin(Op.Code2011));
			}
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			val.displayText = "\n\n" + text2 + "\n\n";
			val.clearPreviousText = true;
			val.maxCharactersToType = 25;
			__result = val;
			return false;
		}

		public static void HostRequested()
		{
			if (!Net.IsHost || running)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			if (!instance.inShipPhase || instance.travellingToNewLevel)
			{
				return;
			}
			int num = -1;
			for (int i = 0; i < instance.levels.Length; i++)
			{
				if (JupiterEvent.IsTitan(instance.levels[i]))
				{
					num = i;
					break;
				}
			}
			if (num < 0)
			{
				Plugin.Log.LogWarning((object)"2011: no Titan in the moon list");
				return;
			}
			Plugin.Log.LogInfo((object)"2011 typed: flying to Titan and forcing the incident");
			ForceNextLanding = true;
			Runner.Run(FlyAndLand(instance, num));
		}

		private static IEnumerator FlyAndLand(StartOfRound sor, int titan)
		{
			running = true;
			if (sor.currentLevelID != titan)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				sor.ChangeLevelServerRpc(titan, val.groupCredits);
				float t = 0f;
				while (!sor.travellingToNewLevel && t < 3f)
				{
					t += Time.deltaTime;
					yield return null;
				}
				while (sor.travellingToNewLevel)
				{
					yield return null;
				}
			}
			yield return (object)new WaitForSeconds(1.5f);
			if (sor.inShipPhase && sor.currentLevelID == titan)
			{
				sor.StartGameServerRpc();
			}
			else
			{
				Plugin.Log.LogWarning((object)"2011: couldn't get to Titan");
			}
			running = false;
		}
	}
	public static class Content
	{
		public static Item BodyWatkins;

		public static Item BodyOAlgo;

		public static Item BodyWaldron;

		public static Item BlackBoxItem;

		public static Item LaserGunItem;

		public static EnemyType KeysType;

		public static readonly List<Item> AllItems = new List<Item>();

		public static readonly List<GameObject> NetworkPrefabList = new List<GameObject>();

		private static GameObject prefabParent;

		public const int LayerProps = 6;

		public const int LayerEnemies = 19;

		public const int LayerScanNode = 22;

		private static GameObject CreateNetworkPrefab(string name)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if ((Object)(object)prefabParent == (Object)null)
			{
				prefabParent = new GameObject("JupiterIncidentPrefabs")
				{
					hideFlags = (HideFlags)61
				};
				prefabParent.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)prefabParent);
			}
			GameObject val = new GameObject(name);
			val.transform.SetParent(prefabParent.transform);
			NetworkObject obj = val.AddComponent<NetworkObject>();
			uint num;
			using (MD5 mD = MD5.Create())
			{
				num = BitConverter.ToUInt32(mD.ComputeHash(Encoding.UTF8.GetBytes("JupiterIncident" + name)), 0);
			}
			typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(obj, num);
			NetworkPrefabList.Add(val);
			return val;
		}

		public static void RegisterNetworkPrefabs()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				return;
			}
			foreach (GameObject networkPrefab in NetworkPrefabList)
			{
				if (!singleton.NetworkConfig.Prefabs.Contains(networkPrefab))
				{
					singleton.AddNetworkPrefab(networkPrefab);
				}
			}
			Plugin.Log.LogInfo((object)$"Registered {NetworkPrefabList.Count} network prefabs");
		}

		public static void AddItemsToGame(StartOfRound sor)
		{
			foreach (Item allItem in AllItems)
			{
				if (!sor.allItemsList.itemsList.Contains(allItem))
				{
					sor.allItemsList.itemsList.Add(allItem);
				}
			}
		}

		public static void Register()
		{
			BodyWatkins = MakeItem<AstronautBodyItem>("Darren Watkins Jr.", "JI_BodyWatkins", ModAssets.BodyWatkins, 7101, ModConfig.BodyValue.Value, 1.35f, twoHanded: true, "HoldLung", new string[1] { "Drop : [G]" });
			BodyOAlgo = MakeItem<AstronautBodyItem>("Mateo O Algo", "JI_BodyOAlgo", ModAssets.BodyOAlgo, 7102, ModConfig.BodyValue.Value, 1.35f, twoHanded: true, "HoldLung", new string[1] { "Drop : [G]" });
			BodyWaldron = MakeItem<AstronautBodyItem>("Forrest Waldron", "JI_BodyWaldron", ModAssets.BodyWaldron, 7103, ModConfig.BodyValue.Value, 1.35f, twoHanded: true, "HoldLung", new string[1] { "Drop : [G]" });
			BlackBoxItem = MakeItem<BlackBoxItem>("Mission Black Box", "JI_BlackBox", ModAssets.BlackBox, 7104, ModConfig.BlackBoxValue.Value, 1.12f, twoHanded: false, null, new string[1] { "Drop : [G]" });
			BlackBoxItem.saveItemVariable = true;
			BlackBoxItem.isConductiveMetal = true;
			LaserGunItem = MakeItem<LaserGunItem>("Case Oh's Laser Gun", "JI_LaserGun", ModAssets.LaserGun, 7105, ModConfig.LaserGunValue.Value, 1.18f, twoHanded: false, null, new string[2] { "Fire : [LMB]", "Drop : [G]" });
			LaserGunItem.requiresBattery = true;
			LaserGunItem.batteryUsage = 1000f;
			LaserGunItem.automaticallySetUsingPower = false;
			LaserGunItem.isConductiveMetal = true;
			LaserGunItem.isDefensiveWeapon = true;
			LaserGunItem.holdButtonUse = false;
			LaserGunItem.itemIsTrigger = false;
			Item[] array = (Item[])(object)new Item[3] { BodyWatkins, BodyOAlgo, BodyWaldron };
			for (int i = 0; i < array.Length; i++)
			{
				array[i].itemSpawnsOnGround = false;
			}
			KeysType = MakeKeys();
			ApplyHoldOffsets();
		}

		public static void ApplyHoldOffsets()
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			Item[] array = (Item[])(object)new Item[3] { BodyWatkins, BodyOAlgo, BodyWaldron };
			foreach (Item val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.positionOffset = V3(ModConfig.BodyHoldPos.Value);
					val.rotationOffset = V3(ModConfig.BodyHoldRot.Value);
				}
			}
			if ((Object)(object)BlackBoxItem != (Object)null)
			{
				BlackBoxItem.positionOffset = V3(ModConfig.BoxHoldPos.Value);
				BlackBoxItem.rotationOffset = V3(ModConfig.BoxHoldRot.Value);
			}
			if ((Object)(object)LaserGunItem != (Object)null)
			{
				LaserGunItem.positionOffset = V3(ModConfig.GunHoldPos.Value);
				LaserGunItem.rotationOffset = V3(ModConfig.GunHoldRot.Value);
			}
		}

		private static Vector3 V3(string s)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			string[] p = (s ?? "").Split(',');
			return new Vector3(F(0), F(1), F(2));
			float F(int i)
			{
				if (p.Length <= i || !float.TryParse(p[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					return 0f;
				}
				return result;
			}
		}

		private static Item MakeItem<T>(string displayName, string prefabName, JimModel model, int id, int value, float weight, bool twoHanded, string grabAnim, string[] tips) where T : GrabbableObject
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01db: 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_0181: 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)
			Item val = ScriptableObject.CreateInstance<Item>();
			((Object)val).name = prefabName + "_Item";
			val.itemName = displayName;
			val.itemId = id;
			val.isScrap = true;
			val.minValue = value;
			val.maxValue = value;
			val.weight = weight;
			val.twoHanded = twoHanded;
			val.twoHandedAnimation = twoHanded;
			val.grabAnim = grabAnim;
			val.toolTips = tips;
			val.canBeGrabbedBeforeGameStart = true;
			val.itemSpawnsOnGround = true;
			val.spawnPositionTypes = new List<ItemGroup>();
			val.highestSalePercentage = 80;
			val.syncGrabFunction = false;
			val.syncUseFunction = false;
			val.allowDroppingAheadOfPlayer = true;
			val.canBeInspected = false;
			val.restingRotation = Vector3.zero;
			val.rotationOffset = Vector3.zero;
			val.positionOffset = Vector3.zero;
			val.meshVariants = (Mesh[])(object)new Mesh[0];
			val.materialVariants = (Material[])(object)new Material[0];
			val.clinkAudios = (AudioClip[])(object)new AudioClip[0];
			GameObject val2 = CreateNetworkPrefab(prefabName);
			val2.tag = "PhysicsProp";
			val2.layer = 6;
			Rigidbody obj = val2.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			val2.AddComponent<AudioSource>().playOnAwake = false;
			GameObject val3 = new GameObject("Mesh");
			val3.layer = 6;
			val3.transform.SetParent(val2.transform, false);
			MeshFilter val4 = val3.AddComponent<MeshFilter>();
			MeshRenderer mainObjectRenderer = val3.AddComponent<MeshRenderer>();
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(Vector3.zero, Vector3.one * 0.3f);
			if (model != null)
			{
				val4.sharedMesh = model.Mesh;
				bounds = model.Mesh.bounds;
				val3.AddComponent<MaterialBinder>().Init(model, 0.25f);
			}
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			obj2.center = ((Bounds)(ref bounds)).center;
			obj2.size = Vector3.Max(((Bounds)(ref bounds)).size, Vector3.one * 0.15f);
			val.verticalOffset = ((Bounds)(ref bounds)).extents.y - ((Bounds)(ref bounds)).center.y + 0.02f;
			T val5 = val2.AddComponent<T>();
			((GrabbableObject)val5).itemProperties = val;
			((GrabbableObject)val5).grabbable = true;
			((GrabbableObject)val5).mainObjectRenderer = mainObjectRenderer;
			((GrabbableObject)val5).grabbableToEnemies = true;
			AddScanNode(val2.transform, displayName, $"Value: ${value}", 2, value, Mathf.Max(((Bounds)(ref bounds)).extents.y, 0.3f));
			val.spawnPrefab = val2;
			AllItems.Add(val);
			return val;
		}

		public static ScanNodeProperties AddScanNode(Transform parent, string header, string sub, int type, int value, float height)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ScanNode");
			val.layer = 22;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = Vector3.up * height * 0.5f;
			try
			{
				val.tag = "DoNotSet";
			}
			catch
			{
			}
			BoxCollider obj2 = val.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = Vector3.one * 0.6f;
			Rigidbody obj3 = val.AddComponent<Rigidbody>();
			obj3.isKinematic = true;
			obj3.useGravity = false;
			ScanNodeProperties obj4 = val.AddComponent<ScanNodeProperties>();
			obj4.headerText = header;
			obj4.subText = sub;
			obj4.nodeType = type;
			obj4.scrapValue = value;
			obj4.minRange = 1;
			obj4.maxRange = ((type == 1) ? 30 : 20);
			obj4.requiresLineOfSight = true;
			obj4.creatureScanID = -1;
			return obj4;
		}

		public static void BorrowVanillaItemBits(StartOfRound sor)
		{
			List<Item> source = sor.allItemsList.itemsList.Where((Item i) => (Object)(object)i != (Object)null && !AllItems.Contains(i)).ToList();
			Item val = ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => i.isScrap && i.twoHanded && (Object)(object)i.itemIcon != (Object)null)) ?? ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i.itemIcon != (Object)null));
			Item val2 = ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => i.isScrap && !i.twoHanded && i.isConductiveMetal && (Object)(object)i.itemIcon != (Object)null)) ?? val;
			foreach (Item allItem in AllItems)
			{
				Item val3 = (allItem.twoHanded ? val : val2);
				if (!((Object)(object)val3 == (Object)null))
				{
					if ((Object)(object)allItem.itemIcon == (Object)null)
					{
						allItem.itemIcon = val3.itemIcon;
					}
					if ((Object)(object)allItem.grabSFX == (Object)null)
					{
						allItem.grabSFX = val3.grabSFX;
					}
					if ((Object)(object)allItem.dropSFX == (Object)null)
					{
						allItem.dropSFX = val3.dropSFX;
					}
					if ((Object)(object)allItem.pocketSFX == (Object)null)
					{
						allItem.pocketSFX = val3.pocketSFX;
					}
					if ((Object)(object)allItem.throwSFX == (Object)null)
					{
						allItem.throwSFX = val3.throwSFX;
					}
				}
			}
		}

		private static EnemyType MakeKeys()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Expected O, but got Unknown
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Expected O, but got Unknown
			EnemyType val = ScriptableObject.CreateInstance<EnemyType>();
			((Object)val).name = "JI_KeysType";
			val.enemyName = "Keys";
			val.canDie = true;
			val.canBeDestroyed = true;
			val.destroyOnDeath = false;
			val.canBeStunned = true;
			val.stunTimeMultiplier = 0.6f;
			val.doorSpeedMultiplier = 2f;
			val.MaxCount = 20;
			val.PowerLevel = 0f;
			val.isOutsideEnemy = false;
			val.disableAnimatorWhenFar = false;
			val.canSeeThroughFog = true;
			val.probabilityCurve = AnimationCurve.Constant(0f, 1f, 1f);
			val.numberSpawnedFalloff = AnimationCurve.Constant(0f, 1f, 1f);
			val.pushPlayerForce = 0.4f;
			val.pushPlayerDistance = 1.2f;
			val.loudnessMultiplier = 1f;
			val.timeToPlayAudio = 0.5f;
			GameObject val2 = CreateNetworkPrefab("JI_Keys");
			val2.tag = "Enemy";
			val2.layer = 19;
			Rigidbody obj = val2.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			NavMeshAgent val3 = val2.AddComponent<NavMeshAgent>();
			val3.speed = 3f;
			val3.angularSpeed = 420f;
			val3.acceleration = 22f;
			val3.stoppingDistance = 0.2f;
			val3.radius = 0.7f;
			val3.height = 2.4f;
			val3.autoBraking = true;
			val3.obstacleAvoidanceType = (ObstacleAvoidanceType)1;
			AudioSource val4 = val2.AddComponent<AudioSource>();
			Setup3D(val4, 45f);
			GameObject val5 = new GameObject("SFX");
			val5.transform.SetParent(val2.transform, false);
			AudioSource val6 = val5.AddComponent<AudioSource>();
			Setup3D(val6, 30f);
			GameObject val7 = new GameObject("Model")
			{
				layer = 19
			};
			val7.transform.SetParent(val2.transform, false);
			KeysAnimator keysAnimator = val7.AddComponent<KeysAnimator>();
			keysAnimator.Build(ModAssets.Keys);
			Transform transform = new GameObject("Eye").transform;
			transform.SetParent(val2.transform, false);
			transform.localPosition = new Vector3(0f, 2.05f, 0.35f);
			Transform transform2 = new GameObject("HoldPoint").transform;
			transform2.SetParent(val2.transform, false);
			transform2.localPosition = new Vector3(0f, 0.1f, 1.15f);
			transform2.localRotation = Quaternion.Euler(0f, 180f, 0f);
			GameObject val8 = new GameObject("Collision")
			{
				tag = "Enemy",
				layer = 19
			};
			val8.transform.SetParent(val2.transform, false);
			CapsuleCollider obj2 = val8.AddComponent<CapsuleCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.radius = 1f;
			obj2.height = 2.6f;
			obj2.center = new Vector3(0f, 1.3f, 0.15f);
			EnemyAICollisionDetect val9 = val8.AddComponent<EnemyAICollisionDetect>();
			AddScanNode(val2.transform, "Keys", "Jupiter native species", 1, 0, 3.6f);
			KeysAI keysAI = val2.AddComponent<KeysAI>();
			((EnemyAI)keysAI).enemyType = val;
			((EnemyAI)keysAI).agent = val3;
			((EnemyAI)keysAI).eye = transform;
			keysAI.holdPoint = transform2;
			((EnemyAI)keysAI).creatureVoice = val4;
			((EnemyAI)keysAI).creatureSFX = val6;
			keysAI.keysAnimator = keysAnimator;
			((EnemyAI)keysAI).enemyHP = ModConfig.KeysHealth.Value;
			((EnemyAI)keysAI).AIIntervalTime = 0.2f;
			((EnemyAI)keysAI).updatePositionThreshold = 0.25f;
			((EnemyAI)keysAI).syncMovementSpeed = 0.2f;
			((EnemyAI)keysAI).exitVentAnimationTime = 0f;
			((EnemyAI)keysAI).enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[1]
			{
				new EnemyBehaviourState
				{
					name = "Default"
				}
			};
			((EnemyAI)keysAI).currentBehaviourState = ((EnemyAI)keysAI).enemyBehaviourStates[0];
			((EnemyAI)keysAI).currentSearch = new AISearchRoutine();
			val9.mainScript = (EnemyAI)(object)keysAI;
			val.enemyPrefab = val2;
			return val;
		}

		private static void Setup3D(AudioSource s, float range)
		{
			s.playOnAwake = false;
			s.spatialBlend = 1f;
			s.rolloffMode = (AudioRolloffMode)1;
			s.minDistance = 3f;
			s.maxDistance = range;
			s.dopplerLevel = 0f;
		}
	}
	public class MaterialBinder : MonoBehaviour
	{
		public string modelName;

		public float smoothness = 0.3f;

		public void Init(JimModel model, float smooth)
		{
			modelName = model.Name;
			smoothness = smooth;
		}

		private void Awake()
		{
			Apply();
		}

		public void Apply()
		{
			JimModel jimModel = ModelByName(modelName);
			if (jimModel != null)
			{
				Material[] array = ModAssets.MaterialsFor(jimModel, smoothness);
				Renderer component = ((Component)this).GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null && array.Length != 0)
				{
					component.sharedMaterials = array;
				}
			}
		}

		private static JimModel ModelByName(string n)
		{
			JimModel[] array = new JimModel[6]
			{
				ModAssets.Keys,
				ModAssets.BodyWatkins,
				ModAssets.BodyOAlgo,
				ModAssets.BodyWaldron,
				ModAssets.BlackBox,
				ModAssets.LaserGun
			};
			foreach (JimModel jimModel in array)
			{
				if (jimModel != null && jimModel.Name == n)
				{
					return jimModel;
				}
			}
			return null;
		}
	}
	public static class DistressSignal
	{
		private class Marker
		{
			public AstronautBodyItem body;

			public RectTransform rt;

			public TextMeshProUGUI label;

			public CanvasGroup group;

			public AudioSource audio;
		}

		private const float Interval = 60f;

		private const float Duration = 10f;

		private const float BeepEvery = 2f;

		private static bool wasInside;

		private static float nextPing = float.MaxValue;

		private static float pingEnds = -1f;

		private static float nextBeep;

		private static GameObject root;

		private static TMP_FontAsset font;

		private static readonly List<Marker> markers = new List<Marker>();

		public static void Tick()
		{
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			bool flag = (Object)(object)val != (Object)null && !val.isPlayerDead && val.isInsideFactory && StartOfRound.Instance.shipHasLanded;
			float time = Time.time;
			if (flag && !wasInside)
			{
				StartPing(time);
			}
			else if (flag && time >= nextPing)
			{
				StartPing(time);
			}
			if (!flag)
			{
				nextPing = float.MaxValue;
			}
			wasInside = flag;
			if (!flag || !(time < pingEnds))
			{
				Hide();
			}
			else
			{
				Draw(val, time);
			}
		}

		private static void StartPing(float now)
		{
			nextPing = now + 60f;
			if (!Bodies().Any())
			{
				pingEnds = -1f;
				return;
			}
			pingEnds = now + 10f;
			nextBeep = now;
			if (JupiterEvent.VerboseKeys)
			{
				Plugin.Log.LogInfo((object)$"[distress] ping ({Bodies().Count()} bodies)");
			}
		}

		private static IEnumerable<AstronautBodyItem> Bodies()
		{
			return from b in Object.FindObjectsOfType<AstronautBodyItem>()
				where (Object)(object)b != (Object)null && !((GrabbableObject)b).hasBeenHeld && !((GrabbableObject)b).isHeld && !((GrabbableObject)b).isInShipRoom && !((GrabbableObject)b).isInElevator && ((Component)b).transform.position.y < -50f
				select b;
		}

		private static void Draw(PlayerControllerB local, float now)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_01f5: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			Build();
			root.SetActive(true);
			List<AstronautBodyItem> list = Bodies().ToList();
			while (markers.Count < list.Count)
			{
				markers.Add(NewMarker());
			}
			Camera gameplayCamera = local.gameplayCamera;
			bool flag = now >= nextBeep;
			if (flag)
			{
				nextBeep = now + 2f;
			}
			float num = pingEnds - now;
			float num2 = 0.65f + 0.35f * Mathf.Sin(now * 9f);
			float num3 = Mathf.Clamp01(num / 1.2f);
			Vector2 val3 = default(Vector2);
			for (int i = 0; i < markers.Count; i++)
			{
				Marker marker = markers[i];
				if (i >= list.Count)
				{
					((Component)marker.rt).gameObject.SetActive(false);
					continue;
				}
				AstronautBodyItem astronautBodyItem = (marker.body = list[i]);
				((Component)marker.rt).gameObject.SetActive(true);
				Vector3 val = ((Component)astronautBodyItem).transform.position + Vector3.up * 0.6f;
				Vector3 val2 = gameplayCamera.WorldToViewportPoint(val);
				bool flag2 = val2.z < 0f;
				((Vector2)(ref val3))..ctor(val2.x, val2.y);
				if (flag2)
				{
					((Vector2)(ref val3))..ctor(1f - val3.x, 1f - val3.y);
				}
				if (flag2 || val3.x < 0.04f || val3.x > 0.96f || val3.y < 0.06f || val3.y > 0.94f)
				{
					Vector2 val4 = val3 - new Vector2(0.5f, 0.5f);
					if (flag2 && ((Vector2)(ref val4)).sqrMagnitude < 0.0001f)
					{
						val4 = Vector2.down;
					}
					float num4 = Mathf.Min(0.44f / Mathf.Max(Mathf.Abs(val4.x), 0.0001f), 0.42f / Mathf.Max(Mathf.Abs(val4.y), 0.0001f));
					val3 = new Vector2(0.5f, 0.5f) + val4 * num4;
				}
				RectTransform rt = marker.rt;
				Vector2 anchorMin = (marker.rt.anchorMax = val3);
				rt.anchorMin = anchorMin;
				float num5 = Vector3.Distance(((Component)local).transform.position, ((Component)astronautBodyItem).transform.position);
				((TMP_Text)marker.label).text = $"DISTRESS SIGNAL\n{num5:F0}m";
				marker.group.alpha = num2 * num3;
				if ((Object)(object)marker.audio == (Object)null || (Object)(object)((Component)marker.audio).transform.parent != (Object)(object)((Component)astronautBodyItem).transform)
				{
					marker.audio = BeepSource(astronautBodyItem);
				}
				if (flag && (Object)(object)ModAssets.DistressBeep != (Object)null)
				{
					marker.audio.PlayOneShot(ModAssets.DistressBeep, 1f);
				}
			}
		}

		private static AudioSource BeepSource(AstronautBodyItem b)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)b).transform.Find("JI_DistressBeacon");
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).GetComponent<AudioSource>();
			}
			GameObject val2 = new GameObject("JI_DistressBeacon");
			val2.transform.SetParent(((Component)b).transform, false);
			val2.transform.localPosition = Vector3.up * 0.6f;
			AudioSource val3 = val2.AddComponent<AudioSource>();
			val3.spatialBlend = 1f;
			val3.rolloffMode = (AudioRolloffMode)1;
			val3.minDistance = 4f;
			val3.maxDistance = 70f;
			val3.dopplerLevel = 0f;
			val3.playOnAwake = false;
			if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.UIAudio != (Object)null)
			{
				val3.outputAudioMixerGroup = HUDManager.Instance.UIAudio.outputAudioMixerGroup;
			}
			val2.AddComponent<AudioLowPassFilter>().cutoffFrequency = 4200f;
			return val3;
		}

		private static void Hide()
		{
			if ((Object)(object)root != (Object)null && root.activeSelf)
			{
				root.SetActive(false);
			}
		}

		public static void Reset()
		{
			wasInside = false;
			nextPing = float.MaxValue;
			pingEnds = -1f;
			Hide();
		}

		private static void Build()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)root != (Object)null))
			{
				root = new GameObject("JI_DistressHud");
				Object.DontDestroyOnLoad((Object)(object)root);
				Canvas obj = root.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 55;
				CanvasScaler obj2 = root.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				font = (((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.chatText != (Object)null) ? ((TMP_Text)HUDManager.Instance.chatText).font : null);
			}
		}

		private static Marker NewMarker()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_005b: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.12f, 0.08f);
			GameObject val2 = new GameObject("Marker", new Type[1] { typeof(RectTransform) });
			RectTransform val3 = (RectTransform)val2.transform;
			((Transform)val3).SetParent(root.transform, false);
			val3.sizeDelta = new Vector2(200f, 90f);
			val3.pivot = new Vector2(0.5f, 0.5f);
			CanvasGroup val4 = val2.AddComponent<CanvasGroup>();
			val4.blocksRaycasts = false;
			GameObject val5 = new GameObject("Ring", new Type[1] { typeof(RectTransform) });
			RectTransform val6 = (RectTransform)val5.transform;
			((Transform)val6).SetParent((Transform)(object)val3, false);
			val6.sizeDelta = new Vector2(30f, 30f);
			val6.anchoredPosition = new Vector2(0f, 14f);
			((Transform)val6).localRotation = Quaternion.Euler(0f, 0f, 45f);
			((Graphic)val5.AddComponent<Image>()).color = new Color(val.r, val.g, val.b, 0.35f);
			GameObject val7 = new GameObject("Dot", new Type[1] { typeof(RectTransform) });
			RectTransform val8 = (RectTransform)val7.transform;
			((Transform)val8).SetParent((Transform)(object)val6, false);
			val8.sizeDelta = new Vector2(14f, 14f);
			((Graphic)val7.AddComponent<Image>()).color = val;
			GameObject val9 = new GameObject("Label", new Type[1] { typeof(RectTransform) });
			RectTransform val10 = (RectTransform)val9.transform;
			((Transform)val10).SetParent((Transform)(object)val3, false);
			val10.sizeDelta = new Vector2(220f, 44f);
			val10.anchoredPosition = new Vector2(0f, -22f);
			TextMeshProUGUI val11 = val9.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val11).font = font;
			}
			((TMP_Text)val11).fontSize = 22f;
			((TMP_Text)val11).fontStyle = (FontStyles)1;
			((Graphic)val11).color = new Color(1f, 0.25f, 0.2f);
			((TMP_Text)val11).outlineWidth = 0.2f;
			((TMP_Text)val11).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
			((TMP_Text)val11).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val11).enableWordWrapping = false;
			return new Marker
			{
				rt = val3,
				label = val11,
				group = val4
			};
		}
	}
	public class AstronautBodyItem : GrabbableObject
	{
		public override void Start()
		{
			//IL_000c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Start();
			if (((Component)this).transform.position.y < -50f && !base.isInShipRoom && !base.scrapPersistedThroughRounds)
			{
				try
				{
					BloodScene.Paint(((Component)this).transform.position, ((Component)this).transform.forward, (int)(((NetworkBehaviour)this).NetworkObjectId * 7919 % int.MaxValue));
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Blood scene failed: " + ex));
				}
			}
		}

		public override void LateUpdate()
		{
			((GrabbableObject)this).LateUpdate();
			if (!((Object)(object)base.mainObjectRenderer == (Object)null))
			{
				if (base.isHeld && !base.isPocketed && (Object)(object)base.playerHeldBy != (Object)null && (Object)(object)base.playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					((Renderer)base.mainObjectRenderer).enabled = false;
				}
				else if (!base.isPocketed)
				{
					((Renderer)base.mainObjectRenderer).enabled = true;
				}
			}
		}
	}
	public class BlackBoxItem : GrabbableObject
	{
		public bool played;

		private Light statusLight;

		private float blink;

		public override void Start()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0038: 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)
			((GrabbableObject)this).Start();
			GameObject val = new GameObject("StatusLight");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0.12f, 0.1f, 0.12f);
			statusLight = val.AddComponent<Light>();
			statusLight.type = (LightType)2;
			statusLight.color = new Color(1f, 0.08f, 0.04f);
			statusLight.range = 1.2f;
			statusLight.intensity = 0f;
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (!((Object)(object)statusLight == (Object)null))
			{
				blink += Time.deltaTime;
				bool flag = !played && blink % 1.2f < 0.15f;
				statusLight.intensity = (flag ? 6f : 0f);
			}
		}

		public override void GrabItem()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).GrabItem();
			if (!played && !JupiterEvent.BoxPlayed)
			{
				FastBufferWriter w = Net.Begin(Op.BoxPickedUp);
				ulong networkObjectId = ((NetworkBehaviour)this).NetworkObjectId;
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				Net.SendToHost(w);
			}
		}

		public override int GetItemDataToSave()
		{
			return played ? 1 : 0;
		}

		public override void LoadItemSaveData(int saveData)
		{
			played = saveData == 1;
		}
	}
	public class LaserGunItem : GrabbableObject
	{
		public const int HitId = 2011777;

		private const float Range = 100f;

		private static Material beamMaterial;

		public override void Start()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (base.insertedBattery == null || (base.insertedBattery.charge <= 0f && !base.insertedBattery.empty))
			{
				base.insertedBattery = new Battery(false, 1f);
			}
			((GrabbableObject)this).Start();
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!buttonDown || !((NetworkBehaviour)this).IsOwner || (Object)(object)base.playerHeldBy == (Object)null)
			{
				return;
			}
			float num = 1f / (float)Mathf.Max(1, ModConfig.LaserShots.Value);
			if (base.insertedBattery == null || base.insertedBattery.empty || base.insertedBattery.charge < num * 0.5f)
			{
				if ((Object)(object)ModAssets.LaserEmpty != (Object)null)
				{
					AudioSource.PlayClipAtPoint(ModAssets.LaserEmpty, ((Component)this).transform.position, 0.8f);
				}
				return;
			}
			base.insertedBattery.charge = Mathf.Max(0f, base.insertedBattery.charge - num);
			if (base.insertedBattery.charge < num * 0.5f)
			{
				base.insertedBattery.charge = 0f;
				base.insertedBattery.empty = true;
			}
			((GrabbableObject)this).SyncBatteryServerRpc((int)(base.insertedBattery.charge * 100f));
			Fire();
		}

		public void DebugFireAt(Vector3 target)
		{
			//IL_005d: 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)
			if (!((Object)(object)base.playerHeldBy == (Object)null) && base.insertedBattery != null && !base.insertedBattery.empty)
			{
				base.insertedBattery.charge = Mathf.Max(0f, base.insertedBattery.charge - 1f / (float)Mathf.Max(1, ModConfig.LaserShots.Value));
				Vector3 val = target - ((Component)base.playerHeldBy.gameplayCamera).transform.position;
				Fire(((Vector3)(ref val)).normalized);
			}
		}

		private void Fire(Vector3? aim = null)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009d: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_010e: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: 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_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB playerHeldBy = base.playerHeldBy;
			Transform transform = ((Component)playerHeldBy.gameplayCamera).transform;
			Vector3 position = transform.position;
			Vector3 val = (Vector3)(((??)aim) ?? transform.forward);
			Vector3 muzzle = position + val * 0.7f - transform.up * 0.18f + transform.right * 0.12f;
			Vector3 end = position + val * 100f;
			int hitPlayer = -1;
			int num = StartOfRound.Instance.collidersAndRoomMaskAndDefault | 0x80000 | 8;
			Collider[] array = Physics.OverlapSphere(position + val * 0.9f, 0.9f, 524288, (QueryTriggerInteraction)2);
			foreach (Collider val2 in array)
			{
				EnemyAICollisionDetect component = ((Component)val2).GetComponent<EnemyAICollisionDetect>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.mainScript == (Object)null) && !component.mainScript.isEnemyDead)
				{
					((IHittable)component).Hit(3, val, playerHeldBy, true, 2011777);
					SendShot(muzzle, val2.ClosestPoint(position), playerHeldBy, -1);
					return;
				}
			}
			foreach (RaycastHit item in from h in Physics.SphereCastAll(position, 0.25f, val, 100f, num, (QueryTriggerInteraction)2)
				where ((RaycastHit)(ref h)).distance > 0f
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (!((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)playerHeldBy).transform))
				{
					EnemyAICollisionDetect component2 = ((Component)((RaycastHit)(ref current)).collider).GetComponent<EnemyAICollisionDetect>();
					if ((Object)(object)component2 != (Object)null && (Object)(object)component2.mainScript != (Object)null && !component2.mainScript.isEnemyDead)
					{
						((IHittable)component2).Hit(3, val, playerHeldBy, true, 2011777);
						end = ((RaycastHit)(ref current)).point;
						break;
					}
					PlayerControllerB componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<PlayerControllerB>();
					if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)playerHeldBy && ((Component)((RaycastHit)(ref current)).collider).gameObject.layer == 3 && componentInParent.isPlayerControlled && !componentInParent.isPlayerDead)
					{
						hitPlayer = Net.PlayerIndex(componentInParent);
						end = ((RaycastHit)(ref current)).point;
						break;
					}
					if (!((RaycastHit)(ref current)).collider.isTrigger)
					{
						end = ((RaycastHit)(ref current)).point;
						break;
					}
				}
			}
			SendShot(muzzle, end, playerHeldBy, hitPlayer);
		}

		private void SendShot(Vector3 muzzle, Vector3 end, PlayerControllerB shooter, int hitPlayer)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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)
			Plugin.Log.LogInfo((object)$"Laser fired ({base.insertedBattery.charge * (float)ModConfig.LaserShots.Value:F0} shots left), hit player {hitPlayer}, end {end}");
			FastBufferWriter w = Net.Begin(Op.LaserFire);
			((FastBufferWriter)(ref w)).WriteValueSafe(ref muzzle);
			((FastBufferWriter)(ref w)).WriteValueSafe(ref end);
			int num = Net.PlayerIndex(shooter);
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref hitPlayer, default(ForPrimitives));
			if (Net.IsHost)
			{
				Net.SendToAll(w);
			}
			else
			{
				Net.SendToHost(w);
			}
		}

		public static void OnLaserFired(Vector3 from, Vector3 to, int shooter, int hitPlayer)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_006a: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ModAssets.LaserFire != (Object)null)
			{
				AudioSource.PlayClipAtPoint(ModAssets.LaserFire, from, 1f);
			}
			Runner.Run(Beam(from, to));
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if (hitPlayer >= 0 && (Object)(object)localPlayerController != (Object)null && (Object)(object)Net.Player(hitPlayer) == (Object)(object)localPlayerController && !localPlayerController.isPlayerDead)
			{
				int value = ModConfig.LaserDamageToPlayers.Value;
				Vector3 val = to - from;
				localPlayerController.DamagePlayer(value, true, true, (CauseOfDeath)13, 0, false, ((Vector3)(ref val)).normalized * 12f);
			}
		}

		private static IEnumerator Beam(Vector3 from, Vector3 to)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			if ((Object)(object)beamMaterial == (Object)null)
			{
				beamMaterial = ModAssets.EmissiveUnlit(new Color(0.1f, 1f, 0.85f), 40f);
			}
			GameObject go = new GameObject("JI_LaserBeam");
			LineRenderer lr = go.AddComponent<LineRenderer>();
			lr.positionCount = 2;
			lr.SetPosition(0, from);
			lr.SetPosition(1, to);
			((Renderer)lr).material = beamMaterial;
			lr.numCapVertices = 4;
			((Renderer)lr).shadowCastingMode = (ShadowCastingMode)0;
			Light flash = new GameObject("JI_LaserImpact").AddComponent<Light>();
			((Component)flash).transform.position = to;
			flash.type = (LightType)2;
			flash.color = new Color(0.2f, 1f, 0.9f);
			flash.range = 4f;
			float t = 0f;
			while (t < 0.28f)
			{
				float num = 1f - t / 0.28f;
				float startWidth = (lr.endWidth = 0.07f * num);
				lr.startWidth = startWidth;
				flash.intensity = 40f * num;
				t += Time.deltaTime;
				yield return null;
			}
			Object.Destroy((Object)(object)go);
			Object.Destroy((Object)(object)((Component)flash).gameObject);
		}
	}
	public static class JupiterEvent